Skip to content

Commit a7ed37a

Browse files
lotus-nexthoplouis-nexthop
authored andcommitted
[PDDF] Add multi PCIE FPGA controlled PSU (sonic-net#22767)
* IGNORE THIS COMMIT: Multiple FPGAs w/ I2C IP block (PR sonic-net#22748) * [PDDF] Add multi PCIE FPGA controlled PSU * IGNORE THIS COMMIT: Remove PDDF_DATA_ATTR_VAL and use client device table (PR sonic-net#22748) * [PDDF] Remove attr_bdf for MultiFPGA PSU * IGNORE THIS COMMIT: Remove multifpgapcisystem_parse() in pddfapi.py (PR sonic-net#22748) * no-op commit to retrigger workflow * IGNORE THIS COMMIT: Parse multifpgapciesystem appropriately (PR sonic-net#22748) --------- Co-authored-by: Louis Maliyam <louis@nexthop.ai>
1 parent 83b955b commit a7ed37a

4 files changed

Lines changed: 42 additions & 5 deletions

File tree

platform/pddf/i2c/modules/client/pddf_client_module.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ ssize_t store_pddf_data(struct device *dev, struct device_attribute *da, const c
179179
*(int *)(ptr->addr) = num;
180180
break;
181181
case PDDF_USHORT:
182-
ret = kstrtoint(buf,16,&num);
182+
ret = kstrtouint(buf,16,&num);
183183
if (ret==0)
184184
*(unsigned short *)(ptr->addr) = (unsigned short)num;
185185
break;
186186
case PDDF_UINT32:
187-
ret = kstrtoint(buf,16,&num);
187+
ret = kstrtouint(buf,16,&num);
188188
if (ret==0)
189189
*(uint32_t *)(ptr->addr) = (uint32_t)num;
190190
break;

platform/pddf/i2c/modules/include/pddf_psu_defs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ typedef struct PSU_DATA_ATTR
4646
int b;
4747
int r;
4848
void *access_data;
49-
5049
}PSU_DATA_ATTR;
5150

5251
typedef struct PSU_SYSFS_ATTR_DATA

platform/pddf/i2c/modules/psu/driver/pddf_psu_api.c

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/delay.h>
3030
#include <linux/dmi.h>
3131
#include <linux/kobject.h>
32+
#include "pddf_multifpgapci_defs.h"
3233
#include "pddf_psu_defs.h"
3334
#include "pddf_psu_driver.h"
3435

@@ -40,6 +41,7 @@
4041
#define psu_dbg(...)
4142
#endif
4243

44+
extern void* get_device_table(char *name);
4345

4446
#define PSU_REG_VOUT_MODE 0x20
4547

@@ -442,6 +444,22 @@ ssize_t psu_store_default(struct device *dev, struct device_attribute *da, const
442444
return count;
443445
}
444446

447+
int psu_multifpgapci_read(PSU_DATA_ATTR *adata, int *output) {
448+
struct pci_dev *pci_dev = NULL;
449+
450+
if (ptr_multifpgapci_readpci == NULL) {
451+
printk(KERN_ERR "PDDF_PSU: pddf_multifpgapci_module is not loaded");
452+
return -1;
453+
}
454+
455+
pci_dev = (struct pci_dev *)get_device_table(adata->devname);
456+
if (pci_dev == NULL) {
457+
printk(KERN_ERR "PDDF_PSU: Unable to get pci_dev of %s for %s\n", adata->devname, adata->aname);
458+
return -1;
459+
}
460+
return ptr_multifpgapci_readpci(pci_dev, adata->offset, output);
461+
}
462+
445463
int sonic_i2c_get_psu_byte_default(void *client, PSU_DATA_ATTR *adata, void *data)
446464
{
447465
int status = 0;
@@ -454,8 +472,24 @@ int sonic_i2c_get_psu_byte_default(void *client, PSU_DATA_ATTR *adata, void *dat
454472
val = board_i2c_cpld_read(adata->devaddr , adata->offset);
455473
if (val < 0)
456474
return val;
457-
padata->val.intval = ((val & adata->mask) == adata->cmpval);
458-
psu_dbg(KERN_ERR "%s: byte_value = 0x%x\n", __FUNCTION__, padata->val.intval);
475+
}
476+
else if (strncmp(adata->devtype, "multifpgapci", strlen("multifpgapci")) == 0)
477+
{
478+
status = psu_multifpgapci_read(adata, &val);
479+
if (status)
480+
goto ret;
481+
}
482+
else
483+
{
484+
printk(KERN_ERR "%s: Unexpected devtype = ", __FUNCTION__, adata->devtype);
485+
}
486+
487+
padata->val.intval = ((val & adata->mask) == adata->cmpval);
488+
psu_dbg(KERN_ERR "%s: byte_value = 0x%x\n", __FUNCTION__, padata->val.intval);
489+
490+
ret:
491+
if (status) {
492+
printk(KERN_ERR "%s: Error status = %d", __FUNCTION__, status);
459493
}
460494

461495
return status;

platform/pddf/i2c/modules/psu/pddf_psu_module.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ static ssize_t do_device_operation(struct device *dev, struct device_attribute *
172172
if (strncmp(buf, "add", strlen(buf)-1)==0)
173173
{
174174
adapter = i2c_get_adapter(cdata->parent_bus);
175+
if (!adapter) {
176+
printk(KERN_ERR "PDDF_ERROR: %s: Failed to get i2c adapter for bus %d\n", __FUNCTION__, cdata->parent_bus);
177+
goto clear_data;
178+
}
175179
board_info = i2c_get_psu_board_info(pdata, cdata);
176180

177181
/* Populate the platform data for psu */

0 commit comments

Comments
 (0)