Enabling FPGA device support in PDDF (#13477)

Why I did it
To enable FPGA support in PDDF.

How I did it
Added FPGAI2C and FPGAPCI in the build path for the PDDF debian package
Added the support for FPGA access APIs in the drivers of fan, xcvr, led etc.
Added the FPGA device creation support in PDDF utils and parsers

How to verify it
These changes can be verified on some platform using such FPGAs. For testing purpose, we took Dell S5232f platform and brought it up using PDDF. In doing so, FPGA devices are created using PDDF and optics eeproms were accessed using common FPGA drivers. Below are some of the logs.
This commit is contained in:
FuzailBrcm 2023-03-15 06:23:35 +05:30 committed by GitHub
parent 8bd6a8891c
commit f822373e53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 1124 additions and 527 deletions

View File

@ -27,8 +27,8 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/version.h> #include <linux/version.h>
#include <linux/i2c.h> #include <linux/i2c.h>
#include "../../../../../pddf/i2c/modules/include/pddf_led_defs.h" #include "pddf_led_defs.h"
#include "../../../../../pddf/i2c/modules/include/pddf_client_defs.h" #include "pddf_client_defs.h"
#define DEBUG 0 #define DEBUG 0
LED_OPS_DATA sys_led_ops_data[1]={0}; LED_OPS_DATA sys_led_ops_data[1]={0};

View File

@ -22,8 +22,8 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/hwmon-sysfs.h> #include <linux/hwmon-sysfs.h>
#include "../../../../../pddf/i2c/modules/include/pddf_led_defs.h" #include "../../../ra-b6510-32c/modules/driver/pddf_led_defs.h"
#include "../../../../../pddf/i2c/modules/include/pddf_client_defs.h" #include "../../../ra-b6510-32c/modules/driver//pddf_client_defs.h"
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/slab.h> #include <linux/slab.h>

View File

@ -330,6 +330,106 @@ int fan_cpld_client_read(FAN_DATA_ATTR *udata)
return status; return status;
} }
int fan_cpld_client_write(FAN_DATA_ATTR *udata, uint32_t val)
{
int status = 0;
if (udata->len==1)
{
status = board_i2c_cpld_write(udata->devaddr, udata->offset, val);
}
else
{
/* Get the I2C client for the CPLD */
struct i2c_client *client_ptr=NULL;
client_ptr = (struct i2c_client *)get_device_table(udata->devname);
if (client_ptr)
{
if (udata->len==2)
{
uint8_t val_lsb = val & 0xFF;
uint8_t val_hsb = (val >> 8) & 0xFF;
/* TODO: Check this logic for LE and BE */
status = i2c_smbus_write_byte_data(client_ptr, udata->offset, val_lsb);
if (status==0) status = i2c_smbus_write_byte_data(client_ptr, udata->offset+1, val_hsb);
}
else
printk(KERN_ERR "PDDF_FAN: Doesn't support block CPLD write yet");
}
else
printk(KERN_ERR "Unable to get the client handle for %s\n", udata->devname);
}
return status;
}
int fan_fpgai2c_client_read(FAN_DATA_ATTR *udata)
{
int status = -1;
if (udata!=NULL)
{
if (udata->len==1)
{
status = board_i2c_fpga_read(udata->devaddr , udata->offset);
/*printk(KERN_ERR "### Reading offset 0x%x from 0x%x device ... val 0x%x\n", udata->offset, udata->devaddr, status);*/
}
else
{
/* Get the I2C client for the FPGAI2C */
struct i2c_client *client_ptr=NULL;
client_ptr = (struct i2c_client *)get_device_table(udata->devname);
if (client_ptr)
{
if (udata->len==2)
{
status = i2c_smbus_read_word_swapped(client_ptr, udata->offset);
}
else
printk(KERN_ERR "PDDF_FAN: Doesn't support block FPGAI2C read yet");
}
else
printk(KERN_ERR "Unable to get the client handle for %s\n", udata->devname);
}
}
return status;
}
int fan_fpgai2c_client_write(FAN_DATA_ATTR *udata, uint32_t val)
{
int status = 0;
if (udata->len==1)
{
status = board_i2c_fpga_write(udata->devaddr, udata->offset, val);
}
else
{
/* Get the I2C client for the FPGAI2C */
struct i2c_client *client_ptr=NULL;
client_ptr = (struct i2c_client *)get_device_table(udata->devname);
if (client_ptr)
{
if (udata->len==2)
{
uint8_t val_lsb = val & 0xFF;
uint8_t val_hsb = (val >> 8) & 0xFF;
/* TODO: Check this logic for LE and BE */
status = i2c_smbus_write_byte_data(client_ptr, udata->offset, val_lsb);
if (status==0) status = i2c_smbus_write_byte_data(client_ptr, udata->offset+1, val_hsb);
}
else
printk(KERN_ERR "PDDF_FAN: Doesn't support block FPGAI2C write yet");
}
else
printk(KERN_ERR "Unable to get the client handle for %s\n", udata->devname);
}
return status;
}
int sonic_i2c_get_fan_present_default(void *client, FAN_DATA_ATTR *udata, void *info) int sonic_i2c_get_fan_present_default(void *client, FAN_DATA_ATTR *udata, void *info)
{ {
@ -341,6 +441,10 @@ int sonic_i2c_get_fan_present_default(void *client, FAN_DATA_ATTR *udata, void *
{ {
val = fan_cpld_client_read(udata); val = fan_cpld_client_read(udata);
} }
else if (strcmp(udata->devtype, "fpgai2c") == 0)
{
val = fan_fpgai2c_client_read(udata);
}
else else
{ {
val = i2c_smbus_read_byte_data((struct i2c_client *)client, udata->offset); val = i2c_smbus_read_byte_data((struct i2c_client *)client, udata->offset);
@ -365,6 +469,10 @@ int sonic_i2c_get_fan_rpm_default(void *client, FAN_DATA_ATTR *udata, void *info
{ {
val = fan_cpld_client_read(udata); val = fan_cpld_client_read(udata);
} }
else if (strcmp(udata->devtype, "fpgai2c") == 0)
{
val = fan_fpgai2c_client_read(udata);
}
else else
{ {
if (udata->len == 1) if (udata->len == 1)
@ -395,17 +503,25 @@ int sonic_i2c_get_fan_rpm_default(void *client, FAN_DATA_ATTR *udata, void *info
int sonic_i2c_get_fan_direction_default(void *client, FAN_DATA_ATTR *udata, void *info) int sonic_i2c_get_fan_direction_default(void *client, FAN_DATA_ATTR *udata, void *info)
{ {
int status = 0; int status = 0;
uint32_t val = 0; int val = 0;
struct fan_attr_info *painfo = (struct fan_attr_info *)info; struct fan_attr_info *painfo = (struct fan_attr_info *)info;
if (strcmp(udata->devtype, "cpld") == 0) if (strcmp(udata->devtype, "cpld") == 0)
{ {
val = fan_cpld_client_read(udata); val = fan_cpld_client_read(udata);
} }
else if (strcmp(udata->devtype, "fpgai2c") == 0)
{
val = fan_fpgai2c_client_read(udata);
}
else else
{ {
val = i2c_smbus_read_byte_data((struct i2c_client *)client, udata->offset); val = i2c_smbus_read_byte_data((struct i2c_client *)client, udata->offset);
} }
if (val < 0)
status = val;
else
painfo->val.intval = ((val & udata->mask) == udata->cmpval); painfo->val.intval = ((val & udata->mask) == udata->cmpval);
return status; return status;
@ -415,7 +531,7 @@ int sonic_i2c_get_fan_direction_default(void *client, FAN_DATA_ATTR *udata, void
int sonic_i2c_set_fan_pwm_default(struct i2c_client *client, FAN_DATA_ATTR *udata, void *info) int sonic_i2c_set_fan_pwm_default(struct i2c_client *client, FAN_DATA_ATTR *udata, void *info)
{ {
int status = 0; int status = 0;
uint32_t val = 0; int val = 0;
struct fan_attr_info *painfo = (struct fan_attr_info *)info; struct fan_attr_info *painfo = (struct fan_attr_info *)info;
val = painfo->val.intval & udata->mask; val = painfo->val.intval & udata->mask;
@ -427,44 +543,23 @@ int sonic_i2c_set_fan_pwm_default(struct i2c_client *client, FAN_DATA_ATTR *udat
if (strcmp(udata->devtype, "cpld") == 0) if (strcmp(udata->devtype, "cpld") == 0)
{ {
if (udata->len==1) status = fan_cpld_client_write(udata, val);
{
status = board_i2c_cpld_write(udata->devaddr , udata->offset, val);
} }
else else if (strcmp(udata->devtype, "fpgai2c") == 0)
{ {
/* Get the I2C client for the CPLD */ status = fan_fpgai2c_client_write(udata, val);
struct i2c_client *client_ptr=NULL;
client_ptr = (struct i2c_client *)get_device_table(udata->devname);
if (client_ptr)
{
if (udata->len==2)
{
uint8_t val_lsb = val & 0xFF;
uint8_t val_hsb = (val >> 8) & 0xFF;
/* TODO: Check this logic for LE and BE */
i2c_smbus_write_byte_data(client, udata->offset, val_lsb);
i2c_smbus_write_byte_data(client, udata->offset+1, val_hsb);
}
else
printk(KERN_ERR "PDDF_FAN: Doesn't support block CPLD write yet");
}
else
printk(KERN_ERR "Unable to get the client handle for %s\n", udata->devname);
}
} }
else else
{ {
if (udata->len == 1) if (udata->len == 1)
i2c_smbus_write_byte_data(client, udata->offset, val); status = i2c_smbus_write_byte_data(client, udata->offset, val);
else if (udata->len == 2) else if (udata->len == 2)
{ {
uint8_t val_lsb = val & 0xFF; uint8_t val_lsb = val & 0xFF;
uint8_t val_hsb = (val >> 8) & 0xFF; uint8_t val_hsb = (val >> 8) & 0xFF;
/* TODO: Check this logic for LE and BE */ /* TODO: Check this logic for LE and BE */
i2c_smbus_write_byte_data(client, udata->offset, val_lsb); status = i2c_smbus_write_byte_data(client, udata->offset, val_lsb);
i2c_smbus_write_byte_data(client, udata->offset+1, val_hsb); if (status == 0) status = i2c_smbus_write_byte_data(client, udata->offset+1, val_hsb);
} }
else else
{ {
@ -486,6 +581,10 @@ int sonic_i2c_get_fan_pwm_default(void *client, FAN_DATA_ATTR *udata, void *info
{ {
val = fan_cpld_client_read(udata); val = fan_cpld_client_read(udata);
} }
else if (strcmp(udata->devtype, "fpgai2c") == 0)
{
val = fan_fpgai2c_client_read(udata);
}
else else
{ {
if (udata->len == 1) if (udata->len == 1)
@ -520,6 +619,10 @@ int sonic_i2c_get_fan_fault_default(void *client, FAN_DATA_ATTR *udata, void *in
{ {
val = fan_cpld_client_read(udata); val = fan_cpld_client_read(udata);
} }
else if (strcmp(udata->devtype, "fpgai2c") == 0)
{
val = fan_fpgai2c_client_read(udata);
}
else else
{ {
val = i2c_smbus_read_byte_data((struct i2c_client *)client, udata->offset); val = i2c_smbus_read_byte_data((struct i2c_client *)client, udata->offset);

View File

@ -88,4 +88,6 @@ typedef struct FAN_PDATA
extern int board_i2c_cpld_read(unsigned short cpld_addr, u8 reg); extern int board_i2c_cpld_read(unsigned short cpld_addr, u8 reg);
extern int board_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); extern int board_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value);
extern int board_i2c_fpga_read(unsigned short cpld_addr, u8 reg);
extern int board_i2c_fpga_write(unsigned short cpld_addr, u8 reg, u8 value);
#endif #endif

View File

@ -33,6 +33,7 @@ struct kobject *cur_state_kobj=NULL;
* space JSON data file * space JSON data file
*****************************************/ *****************************************/
#define NAME_SIZE 32 #define NAME_SIZE 32
#define VALUE_SIZE 5
typedef enum { typedef enum {
STATUS_LED_COLOR_GREEN, STATUS_LED_COLOR_GREEN,
STATUS_LED_COLOR_GREEN_BLINK, STATUS_LED_COLOR_GREEN_BLINK,
@ -42,20 +43,24 @@ typedef enum {
STATUS_LED_COLOR_AMBER_BLINK, STATUS_LED_COLOR_AMBER_BLINK,
STATUS_LED_COLOR_BLUE, STATUS_LED_COLOR_BLUE,
STATUS_LED_COLOR_BLUE_BLINK, STATUS_LED_COLOR_BLUE_BLINK,
STATUS_LED_COLOR_YELLOW,
STATUS_LED_COLOR_YELLOW_BLINK,
STATUS_LED_COLOR_OFF, STATUS_LED_COLOR_OFF,
MAX_LED_STATUS MAX_LED_STATUS
}LED_STATUS; }LED_STATUS;
char* LED_STATUS_STR[] = { char* LED_STATUS_STR[] = {
"STATUS_LED_COLOR_GREEN", "green",
"STATUS_LED_COLOR_GREEN_BLINK", "green_blink",
"STATUS_LED_COLOR_RED", "red",
"STATUS_LED_COLOR_RED_BLINK", "red_blink",
"STATUS_LED_COLOR_AMBER", "amber",
"STATUS_LED_COLOR_AMBER_BLINK", "amber_blink",
"STATUS_LED_COLOR_BLUE", "blue",
"STATUS_LED_COLOR_BLUE_BLINK", "blue_blink",
"STATUS_LED_COLOR_OFF" "yellow",
"yellow_blink",
"off"
}; };
@ -71,7 +76,10 @@ typedef struct
int swpld_addr; int swpld_addr;
int swpld_addr_offset; int swpld_addr_offset;
MASK_BITS bits; MASK_BITS bits;
unsigned short value; u8 reg_values[VALUE_SIZE];
char value[NAME_SIZE];
char attr_devtype[NAME_SIZE];
char attr_devname[NAME_SIZE];
} LED_DATA; } LED_DATA;
typedef struct typedef struct
@ -88,6 +96,8 @@ typedef struct
LED_DATA data[MAX_LED_STATUS]; LED_DATA data[MAX_LED_STATUS];
int swpld_addr; int swpld_addr;
int swpld_addr_offset; int swpld_addr_offset;
char attr_devtype[NAME_SIZE];
char attr_devname[NAME_SIZE];
} LED_OPS_DATA; } LED_OPS_DATA;
typedef enum{ typedef enum{

View File

@ -16,6 +16,7 @@
* A pddf kernel module to manage various LEDs of a switch * A pddf kernel module to manage various LEDs of a switch
*/ */
#define __STDC_WANT_LIB_EXT1__ 1
#include <linux/kobject.h> #include <linux/kobject.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/sysfs.h> #include <linux/sysfs.h>
@ -49,6 +50,9 @@ int num_fantrays = 0;
extern int board_i2c_cpld_read(unsigned short cpld_addr, u8 reg); extern int board_i2c_cpld_read(unsigned short cpld_addr, u8 reg);
extern int board_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); extern int board_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value);
extern int board_i2c_fpga_read(unsigned short cpld_addr, u8 reg);
extern int board_i2c_fpga_write(unsigned short cpld_addr, u8 reg, u8 value);
extern ssize_t show_pddf_data(struct device *dev, struct device_attribute *da, char *buf); extern ssize_t show_pddf_data(struct device *dev, struct device_attribute *da, char *buf);
extern ssize_t store_pddf_data(struct device *dev, struct device_attribute *da, const char *buf, size_t count); extern ssize_t store_pddf_data(struct device *dev, struct device_attribute *da, const char *buf, size_t count);
@ -58,7 +62,6 @@ static LED_STATUS find_state_index(const char* state_str) {
while (*ptr && *ptr!= '\n' && *ptr !='\0') ptr++; while (*ptr && *ptr!= '\n' && *ptr !='\0') ptr++;
*ptr='\0'; *ptr='\0';
for ( index = 0; index < MAX_LED_STATUS; index++) { for ( index = 0; index < MAX_LED_STATUS; index++) {
/*int rc = strcmp(state_str, LED_STATUS_STR[index]) ;*/
if (strcmp(state_str, LED_STATUS_STR[index]) == 0 ) { if (strcmp(state_str, LED_STATUS_STR[index]) == 0 ) {
return index; return index;
} }
@ -115,7 +118,6 @@ static LED_OPS_DATA* find_led_ops_data(struct device_attribute *da)
LED_TYPE led_type; LED_TYPE led_type;
if(!ptr || strlen(ptr->device_name) == 0 ) return (NULL); if(!ptr || strlen(ptr->device_name) == 0 ) return (NULL);
if((led_type=get_dev_type(ptr->device_name)) == LED_TYPE_MAX) { if((led_type=get_dev_type(ptr->device_name)) == LED_TYPE_MAX) {
printk(KERN_ERR "PDDF_LED ERROR *%s Unsupported Led Type\n", __func__); printk(KERN_ERR "PDDF_LED ERROR *%s Unsupported Led Type\n", __func__);
return (NULL); return (NULL);
@ -138,13 +140,15 @@ static void print_led_data(LED_OPS_DATA *ptr, LED_STATUS state)
pddf_dbg(LED, KERN_INFO "Print %s index:%d num_psus:%d num_fantrays:%d ADDR=%p\n", pddf_dbg(LED, KERN_INFO "Print %s index:%d num_psus:%d num_fantrays:%d ADDR=%p\n",
ptr->device_name, ptr->index, num_psus, num_fantrays, ptr); ptr->device_name, ptr->index, num_psus, num_fantrays, ptr);
pddf_dbg(LED, KERN_INFO "\tindex: %d\n", ptr->index); pddf_dbg(LED, KERN_INFO "\tindex: %d\n", ptr->index);
pddf_dbg(LED, KERN_INFO "\tdevtype/devname: %s:%s\n", ptr->attr_devtype, ptr->attr_devname);
pddf_dbg(LED, KERN_INFO "\tcur_state: %d; %s \n", ptr->cur_state.state, ptr->cur_state.color); pddf_dbg(LED, KERN_INFO "\tcur_state: %d; %s \n", ptr->cur_state.state, ptr->cur_state.color);
for (i = 0; i< MAX_LED_STATUS; i++) { for (i = 0; i< MAX_LED_STATUS; i++) {
if(ptr->data[i].swpld_addr && (i == state || state == -1)) { if(ptr->data[i].swpld_addr && (i == state || state == -1)) {
pddf_dbg(LED, KERN_INFO "\t\t[%s]: addr/offset:0x%x;0x%x color:%s; value:%x; mask_bits: 0x%x; pos:%d\n", pddf_dbg(LED, KERN_INFO "\t\t[%s]: addr/offset:0x%x;0x%x color:%s; value:[%s][0x%x][0x%x] mask_bits: 0x%x;"
LED_STATUS_STR[i], "pos:%d attr_devtype:%s attr_devname:%s\n",LED_STATUS_STR[i], ptr->data[i].swpld_addr,
ptr->data[i].swpld_addr, ptr->data[i].swpld_addr_offset, ptr->data[i].swpld_addr_offset, LED_STATUS_STR[i], ptr->data[i].value,
LED_STATUS_STR[i], ptr->data[i].value, ptr->data[i].bits.mask_bits, ptr->data[i].bits.pos); ptr->data[i].reg_values[0], ptr->data[i].reg_values[1], ptr->data[i].bits.mask_bits,
ptr->data[i].bits.pos, ptr->data[i].attr_devtype, ptr->data[i].attr_devname);
} }
} }
} }
@ -157,55 +161,77 @@ ssize_t get_status_led(struct device_attribute *da)
LED_OPS_DATA* ops_ptr=find_led_ops_data(da); LED_OPS_DATA* ops_ptr=find_led_ops_data(da);
uint32_t color_val=0, sys_val=0; uint32_t color_val=0, sys_val=0;
int state=0; int state=0;
int cpld_type=0;
int j;
if (!ops_ptr) { if (!ops_ptr) {
pddf_dbg(LED, KERN_ERR "ERROR %s: Cannot find LED Ptr", __func__); pddf_dbg(LED, KERN_ERR "ERROR %s: Cannot find LED Ptr", __func__);
return (-1); return (-1);
} }
if (ops_ptr->swpld_addr == 0x0) { if (ops_ptr->swpld_addr == 0x0) {
pddf_dbg(LED, KERN_ERR "ERROR %s: device: %s %d not configured\n", __func__, pddf_dbg(LED, KERN_ERR "ERROR %s: device: %s %d not configured\n", __func__,
temp_data_ptr->device_name, temp_data_ptr->index); temp_data_ptr->device_name, temp_data_ptr->index);
return (-1); return (-1);
} }
if (strcmp(ops_ptr->attr_devtype, "cpld") == 0) {
cpld_type = 1;
sys_val = board_i2c_cpld_read(ops_ptr->swpld_addr, ops_ptr->swpld_addr_offset); sys_val = board_i2c_cpld_read(ops_ptr->swpld_addr, ops_ptr->swpld_addr_offset);
if (sys_val < 0) } else if (strcmp(ops_ptr->attr_devtype, "fpgai2c") == 0) {
sys_val = board_i2c_fpga_read(ops_ptr->swpld_addr, ops_ptr->swpld_addr_offset);
} else {
pddf_dbg(LED, KERN_ERR "ERROR %s: %s %d devtype:%s 0x%x:0x%x not configured\n",__func__,
ops_ptr->device_name, ops_ptr->index, ops_ptr->attr_devtype, ops_ptr->swpld_addr, ops_ptr->swpld_addr_offset);
return (-1);
}
if (sys_val < 0) {
pddf_dbg(LED, KERN_ERR "ERROR %s: %s %d devtype:%s 0x%x:0x%x read failed\n",__func__,
ops_ptr->device_name, ops_ptr->index, ops_ptr->attr_devtype, ops_ptr->swpld_addr, ops_ptr->swpld_addr_offset);
return sys_val; return sys_val;
}
strcpy(temp_data.cur_state.color, "None"); strcpy(temp_data.cur_state.color, "None");
for (state=0; state<MAX_LED_STATUS; state++) { for (state=0; state<MAX_LED_STATUS; state++) {
color_val = (sys_val & ~ops_ptr->data[state].bits.mask_bits); color_val = (sys_val & ~ops_ptr->data[state].bits.mask_bits);
if ((color_val ^ (ops_ptr->data[state].value<<ops_ptr->data[state].bits.pos))==0) { for (j = 0; j < VALUE_SIZE && ops_ptr->data[state].reg_values[j] != 0xff; j++) {
if ((color_val ^ (ops_ptr->data[state].reg_values[j] << ops_ptr->data[state].bits.pos)) == 0) {
strcpy(temp_data.cur_state.color, LED_STATUS_STR[state]); strcpy(temp_data.cur_state.color, LED_STATUS_STR[state]);
break;
} }
} }
#if DEBUG > 1 }
pddf_dbg(LED, KERN_ERR "Get : %s:%d addr/offset:0x%x; 0x%x value=0x%x [%s]\n", #if DEBUG
ops_ptr->device_name, ops_ptr->index, pddf_dbg(LED, KERN_ERR "Get : %s:%d addr/offset:0x%x; 0x%x devtype:%s;%s value=0x%x [%s]\n",
ops_ptr->swpld_addr, ops_ptr->swpld_addr_offset, sys_val, ops_ptr->device_name, ops_ptr->index, ops_ptr->swpld_addr, ops_ptr->swpld_addr_offset,
temp_data.cur_state.color); ops_ptr->attr_devtype, cpld_type? "cpld": "fpgai2c", sys_val, temp_data.cur_state.color);
#endif #endif
return(ret); return(ret);
} }
ssize_t set_status_led(struct device_attribute *da) ssize_t set_status_led(struct device_attribute *da)
{ {
int ret=0; int ret=0;
uint32_t sys_val=0, new_val=0; uint32_t sys_val=0, new_val=0, read_val=0;
LED_STATUS cur_state = MAX_LED_STATUS; LED_STATUS cur_state = MAX_LED_STATUS;
struct pddf_data_attribute *_ptr = (struct pddf_data_attribute *)da; struct pddf_data_attribute *_ptr = (struct pddf_data_attribute *)da;
LED_OPS_DATA* temp_data_ptr=(LED_OPS_DATA*)_ptr->addr; LED_OPS_DATA* temp_data_ptr=(LED_OPS_DATA*)_ptr->addr;
LED_OPS_DATA* ops_ptr=find_led_ops_data(da); LED_OPS_DATA* ops_ptr=find_led_ops_data(da);
char* _buf=temp_data_ptr->cur_state.color; char* _buf=temp_data_ptr->cur_state.color;
int cpld_type = 0;
if (!ops_ptr) { if (!ops_ptr) {
pddf_dbg(LED, KERN_ERR "PDDF_LED ERROR %s: Cannot find LED Ptr", __func__); pddf_dbg(LED, KERN_ERR "PDDF_LED ERROR %s: Cannot find LED Ptr", __func__);
return (-1); return (-1);
} }
if (ops_ptr->swpld_addr == 0x0) { if (ops_ptr->swpld_addr == 0x0) {
pddf_dbg(LED, KERN_ERR "PDDF_LED ERROR %s: device: %s %d not configured\n", pddf_dbg(LED, KERN_ERR "PDDF_LED ERROR %s: device: %s %d not configured\n",
__func__, ops_ptr->device_name, ops_ptr->index); __func__, ops_ptr->device_name, ops_ptr->index);
return (-1); return (-1);
} }
pddf_dbg(LED, KERN_ERR "%s: Set [%s;%d] color[%s]\n", __func__, pddf_dbg(LED, KERN_ERR "%s: Set [%s;%d] color[%s]\n", __func__,
temp_data_ptr->device_name, temp_data_ptr->index, temp_data_ptr->device_name, temp_data_ptr->index,
temp_data_ptr->cur_state.color); temp_data_ptr->cur_state.color);
@ -217,30 +243,47 @@ ssize_t set_status_led(struct device_attribute *da)
} }
if (ops_ptr->data[cur_state].swpld_addr != 0x0) { if (ops_ptr->data[cur_state].swpld_addr != 0x0) {
if (strcmp(ops_ptr->data[cur_state].attr_devtype, "cpld") == 0) {
cpld_type = 1;
sys_val = board_i2c_cpld_read(ops_ptr->swpld_addr, ops_ptr->swpld_addr_offset); sys_val = board_i2c_cpld_read(ops_ptr->swpld_addr, ops_ptr->swpld_addr_offset);
} else if (strcmp(ops_ptr->data[cur_state].attr_devtype, "fpgai2c") == 0) {
sys_val = board_i2c_fpga_read(ops_ptr->swpld_addr, ops_ptr->swpld_addr_offset);
} else {
pddf_dbg(LED, KERN_ERR "ERROR %s: %s %d devtype:%s not configured\n",__func__,
ops_ptr->device_name, ops_ptr->index, ops_ptr->attr_devtype);
return (-1);
}
if (sys_val < 0) if (sys_val < 0)
return sys_val; return sys_val;
new_val = (sys_val & ops_ptr->data[cur_state].bits.mask_bits) | new_val = (sys_val & ops_ptr->data[cur_state].bits.mask_bits) |
(ops_ptr->data[cur_state].value << ops_ptr->data[cur_state].bits.pos); (ops_ptr->data[cur_state].reg_values[0] << ops_ptr->data[cur_state].bits.pos);
} else { } else {
pddf_dbg(LED, KERN_ERR "ERROR %s: %s %d state %d; %s not configured\n",__func__, pddf_dbg(LED, KERN_ERR "ERROR %s: %s %d devtype:%s state %d; %s not configured\n",__func__,
ops_ptr->device_name, ops_ptr->index, cur_state, _buf); ops_ptr->device_name, ops_ptr->index, ops_ptr->attr_devtype, cur_state, _buf);
return (-1); return (-1);
} }
board_i2c_cpld_write(ops_ptr->swpld_addr, ops_ptr->swpld_addr_offset, new_val); if (strcmp(ops_ptr->data[cur_state].attr_devtype, "cpld") == 0) {
pddf_dbg(LED, KERN_INFO "Set color:%s; 0x%x:0x%x sys_val:0x%x new_val:0x%x read:0x%x\n", ret = board_i2c_cpld_write(ops_ptr->swpld_addr, ops_ptr->swpld_addr_offset, new_val);
LED_STATUS_STR[cur_state], read_val = board_i2c_cpld_read(ops_ptr->swpld_addr, ops_ptr->swpld_addr_offset);
ops_ptr->swpld_addr, ops_ptr->swpld_addr_offset, } else if (strcmp(ops_ptr->data[cur_state].attr_devtype, "fpgai2c") == 0) {
sys_val, new_val, ret = board_i2c_fpga_write(ops_ptr->swpld_addr, ops_ptr->swpld_addr_offset, (uint8_t)new_val);
ret = board_i2c_cpld_read(ops_ptr->swpld_addr, ops_ptr->swpld_addr_offset)); read_val = board_i2c_fpga_read(ops_ptr->swpld_addr, ops_ptr->swpld_addr_offset);
if (ret < 0) } else {
{ pddf_dbg(LED, KERN_ERR "ERROR %s: %s %d devtype:%s not configured\n",__func__,
pddf_dbg(LED, KERN_ERR "PDDF_LED ERROR %s: Error %d in reading from cpld(0x%x) offset 0x%x\n", __FUNCTION__, ret, ops_ptr->swpld_addr, ops_ptr->swpld_addr_offset); ops_ptr->device_name, ops_ptr->index, ops_ptr->attr_devtype);
return ret; return (-1);
} }
#if DEBUG
pddf_dbg(LED, KERN_INFO "Set color:%s; 0x%x:0x%x sys_val:0x%x new_val:0x%x devtype:%s w_ret:0x%x read:0x%x devtype:%s\n",
LED_STATUS_STR[cur_state], ops_ptr->swpld_addr, ops_ptr->swpld_addr_offset, sys_val, new_val,
cpld_type? "cpld":"fpgai2c", ret, read_val, ops_ptr->data[cur_state].attr_devtype);
#endif
return(ret); return(ret);
} }
@ -339,14 +382,18 @@ static int load_led_ops_data(struct device_attribute *da, LED_STATUS state)
LED_OPS_DATA* ptr = (LED_OPS_DATA*)_ptr->addr; LED_OPS_DATA* ptr = (LED_OPS_DATA*)_ptr->addr;
LED_TYPE led_type; LED_TYPE led_type;
LED_OPS_DATA* ops_ptr = NULL; LED_OPS_DATA* ops_ptr = NULL;
int i = 0;
char *token = NULL, *value_ptr = NULL;
if(!ptr || strlen(ptr->device_name)==0 ) { if(!ptr || strlen(ptr->device_name)==0 ) {
pddf_dbg(LED, KERN_INFO "SYSTEM_LED: load_led_ops_data return -1 device_name:%s\n", ptr? ptr->device_name:"NULL"); pddf_dbg(LED, KERN_INFO "SYSTEM_LED: load_led_ops_data return -1 device_name:%s\n", ptr? ptr->device_name:"NULL");
return(-1); return(-1);
} }
if(ptr->device_name) if(ptr->device_name)
{ {
pddf_dbg(LED, KERN_INFO "[%s]: load_led_ops_data: index=%d addr=0x%x;0x%x valu=0x%x\n", pddf_dbg(LED, KERN_INFO "[%s]: load_led_ops_data: index=%d addr=0x%x;0x%x devtype:%s devname=%s valu=%s\n",
ptr->device_name, ptr->index, ptr->swpld_addr, ptr->swpld_addr_offset, ptr->data[0].value); ptr->device_name, ptr->index, ptr->swpld_addr, ptr->swpld_addr_offset, ptr->attr_devtype, ptr->attr_devname, ptr->data[0].value);
} }
if((led_type=get_dev_type(ptr->device_name))==LED_TYPE_MAX) { if((led_type=get_dev_type(ptr->device_name))==LED_TYPE_MAX) {
pddf_dbg(LED, KERN_ERR "PDDF_LED ERROR *%s Unsupported Led Type\n", __func__); pddf_dbg(LED, KERN_ERR "PDDF_LED ERROR *%s Unsupported Led Type\n", __func__);
@ -365,6 +412,26 @@ static int load_led_ops_data(struct device_attribute *da, LED_STATUS state)
ops_ptr->data[state].swpld_addr_offset = ptr->swpld_addr_offset; ops_ptr->data[state].swpld_addr_offset = ptr->swpld_addr_offset;
ops_ptr->swpld_addr = ptr->swpld_addr; ops_ptr->swpld_addr = ptr->swpld_addr;
ops_ptr->swpld_addr_offset = ptr->swpld_addr_offset; ops_ptr->swpld_addr_offset = ptr->swpld_addr_offset;
memcpy(ops_ptr->data[state].attr_devtype, ptr->attr_devtype, sizeof(ops_ptr->data[state].attr_devtype));
memcpy(ops_ptr->data[state].attr_devname, ptr->attr_devname, sizeof(ops_ptr->data[state].attr_devname));
memcpy(ops_ptr->attr_devtype, ptr->attr_devtype, sizeof(ops_ptr->attr_devtype));
memcpy(ops_ptr->attr_devname, ptr->attr_devname, sizeof(ops_ptr->attr_devname));
#ifdef __STDC_LIB_EXT1__
memset_s(ops_ptr->data[state].reg_values, sizeof(ops_ptr->data[state].reg_values), 0xff, sizeof(ops_ptr->data[state].reg_values));
#else
memset(ops_ptr->data[state].reg_values, 0xff, sizeof(ops_ptr->data[state].reg_values));
#endif
value_ptr = kzalloc(sizeof(ops_ptr->data[state].value), GFP_KERNEL);
if (value_ptr) {
memcpy(value_ptr, ops_ptr->data[state].value, sizeof(ops_ptr->data[state].value));
while((token = strsep((char**)&value_ptr,";")) != NULL && i < VALUE_SIZE) {
if (kstrtou8(token, 16, &ops_ptr->data[state].reg_values[i])) {
pddf_dbg(LED, KERN_ERR "load_led_ops_data: [%s] conversion error\n", token);
}
i++;
}
kfree(value_ptr);
}
print_led_data(dev_list[led_type]+ptr->index, state); print_led_data(dev_list[led_type]+ptr->index, state);
@ -400,15 +467,7 @@ ssize_t dev_operation(struct device *dev, struct device_attribute *da, const cha
#if DEBUG #if DEBUG
pddf_dbg(LED, KERN_INFO "dev_operation [%s]\n", buf); pddf_dbg(LED, KERN_INFO "dev_operation [%s]\n", buf);
#endif #endif
if(strstr(buf, "STATUS_LED_COLOR")!= NULL) { if(strncmp(buf, "show", strlen("show")) == 0) {
LED_STATUS index = find_state_index(buf);
if (index < MAX_LED_STATUS ) {
load_led_ops_data(da, index);
} else {
printk(KERN_ERR "PDDF_ERROR %s: Invalid state for dev_ops %s", __FUNCTION__, buf);
}
}
else if(strncmp(buf, "show", strlen("show"))==0 ) {
show_led_ops_data(da); show_led_ops_data(da);
} }
else if(strncmp(buf, "verify", strlen("verify")) == 0) { else if(strncmp(buf, "verify", strlen("verify")) == 0) {
@ -421,7 +480,12 @@ ssize_t dev_operation(struct device *dev, struct device_attribute *da, const cha
set_status_led(da); set_status_led(da);
} }
else { else {
printk(KERN_ERR "PDDF_ERROR %s: Invalid value for dev_ops %s", __FUNCTION__, buf); LED_STATUS index = find_state_index(buf);
if (index < MAX_LED_STATUS) {
load_led_ops_data(da, index);
} else {
printk(KERN_ERR "PDDF_ERROR: %s: Invalid value for dev_ops %s\n", __FUNCTION__, buf);
}
} }
return (count); return (count);
} }
@ -534,6 +598,10 @@ struct attribute_group attr_group_platform={
**************************************************************************/ **************************************************************************/
PDDF_LED_DATA_ATTR(dev, device_name, S_IWUSR|S_IRUGO, show_pddf_data, PDDF_LED_DATA_ATTR(dev, device_name, S_IWUSR|S_IRUGO, show_pddf_data,
store_pddf_data, PDDF_CHAR, NAME_SIZE, (void*)&temp_data.device_name); store_pddf_data, PDDF_CHAR, NAME_SIZE, (void*)&temp_data.device_name);
PDDF_LED_DATA_ATTR(dev, attr_devtype, S_IWUSR|S_IRUGO, show_pddf_data,
store_pddf_data, PDDF_CHAR, NAME_SIZE, (void*)&temp_data.attr_devtype);
PDDF_LED_DATA_ATTR(dev, attr_devname, S_IWUSR|S_IRUGO, show_pddf_data,
store_pddf_data, PDDF_CHAR, NAME_SIZE, (void*)&temp_data.attr_devname);
PDDF_LED_DATA_ATTR(dev, index, S_IWUSR|S_IRUGO, show_pddf_data, PDDF_LED_DATA_ATTR(dev, index, S_IWUSR|S_IRUGO, show_pddf_data,
store_pddf_data, PDDF_INT_DEC, sizeof(int), (void*)&temp_data.index); store_pddf_data, PDDF_INT_DEC, sizeof(int), (void*)&temp_data.index);
PDDF_LED_DATA_ATTR(dev, swpld_addr, S_IWUSR|S_IRUGO, show_pddf_data, PDDF_LED_DATA_ATTR(dev, swpld_addr, S_IWUSR|S_IRUGO, show_pddf_data,
@ -545,12 +613,15 @@ PDDF_LED_DATA_ATTR(dev, dev_ops , S_IWUSR, NULL,
struct attribute* attrs_dev[] = { struct attribute* attrs_dev[] = {
&pddf_dev_dev_attr_device_name.dev_attr.attr, &pddf_dev_dev_attr_device_name.dev_attr.attr,
&pddf_dev_dev_attr_attr_devtype.dev_attr.attr,
&pddf_dev_dev_attr_attr_devname.dev_attr.attr,
&pddf_dev_dev_attr_index.dev_attr.attr, &pddf_dev_dev_attr_index.dev_attr.attr,
&pddf_dev_dev_attr_swpld_addr.dev_attr.attr, &pddf_dev_dev_attr_swpld_addr.dev_attr.attr,
&pddf_dev_dev_attr_swpld_addr_offset.dev_attr.attr, &pddf_dev_dev_attr_swpld_addr_offset.dev_attr.attr,
&pddf_dev_dev_attr_dev_ops.dev_attr.attr, &pddf_dev_dev_attr_dev_ops.dev_attr.attr,
NULL, NULL,
}; };
struct attribute_group attr_group_dev = { struct attribute_group attr_group_dev = {
.attrs = attrs_dev, .attrs = attrs_dev,
}; };
@ -562,7 +633,7 @@ struct attribute_group attr_group_dev={
PDDF_LED_DATA_ATTR(name, bits, S_IWUSR|S_IRUGO, show_pddf_data, \ PDDF_LED_DATA_ATTR(name, bits, S_IWUSR|S_IRUGO, show_pddf_data, \
store_bits_data, PDDF_CHAR, NAME_SIZE, func.bits.bits); \ store_bits_data, PDDF_CHAR, NAME_SIZE, func.bits.bits); \
PDDF_LED_DATA_ATTR(name, value, S_IWUSR|S_IRUGO, show_pddf_data, \ PDDF_LED_DATA_ATTR(name, value, S_IWUSR|S_IRUGO, show_pddf_data, \
store_pddf_data, PDDF_USHORT, sizeof(unsigned short), func.value); \ store_pddf_data, PDDF_CHAR, NAME_SIZE, func.value); \
struct attribute* attrs_##name[]={ \ struct attribute* attrs_##name[]={ \
&pddf_dev_##name##_attr_bits.dev_attr.attr, \ &pddf_dev_##name##_attr_bits.dev_attr.attr, \
&pddf_dev_##name##_attr_value.dev_attr.attr, \ &pddf_dev_##name##_attr_value.dev_attr.attr, \
@ -585,6 +656,7 @@ struct attribute* attrs_cur_state[]={
&pddf_dev_cur_state_attr_color.dev_attr.attr, &pddf_dev_cur_state_attr_color.dev_attr.attr,
NULL, NULL,
}; };
struct attribute_group attr_group_cur_state={ struct attribute_group attr_group_cur_state={
.attrs = attrs_cur_state, .attrs = attrs_cur_state,
}; };

View File

@ -383,7 +383,7 @@ int psu_init(void)
} }
EXPORT_SYMBOL(psu_init); EXPORT_SYMBOL(psu_init);
void __exit psu_exit(void) void psu_exit(void)
{ {
pddf_dbg(PSU, "GENERIC_PSU_DRIVER.. exit\n"); pddf_dbg(PSU, "GENERIC_PSU_DRIVER.. exit\n");
if (pddf_psu_ops.pre_exit) (pddf_psu_ops.pre_exit)(); if (pddf_psu_ops.pre_exit) (pddf_psu_ops.pre_exit)();

View File

@ -40,6 +40,10 @@
extern XCVR_SYSFS_ATTR_OPS xcvr_ops[]; extern XCVR_SYSFS_ATTR_OPS xcvr_ops[];
extern void *get_device_table(char *name); extern void *get_device_table(char *name);
extern int (*ptr_fpgapci_read)(uint32_t);
extern int (*ptr_fpgapci_write)(uint32_t, uint32_t);
int get_xcvr_module_attr_data(struct i2c_client *client, struct device *dev, int get_xcvr_module_attr_data(struct i2c_client *client, struct device *dev,
struct device_attribute *da); struct device_attribute *da);
@ -146,6 +150,148 @@ int xcvr_i2c_cpld_write(XCVR_ATTR *info, uint32_t val)
return status; return status;
} }
int xcvr_i2c_fpga_read(XCVR_ATTR *info)
{
int status = -1;
int retry = 10;
if (info!=NULL)
{
/* Get the I2C client for the CPLD */
struct i2c_client *client_ptr=NULL;
client_ptr = (struct i2c_client *)get_device_table(info->devname);
if (client_ptr)
{
if (info->len==1)
{
while(retry)
{
status = i2c_smbus_read_byte_data(client_ptr , info->offset);
if (unlikely(status < 0))
{
msleep(60);
retry--;
continue;
}
break;
}
}
else if (info->len==2)
{
retry = 10;
while(retry)
{
status = i2c_smbus_read_word_swapped(client_ptr, info->offset);
if (unlikely(status < 0))
{
msleep(60);
retry--;
continue;
}
break;
}
}
else
printk(KERN_ERR "PDDF_XCVR: Doesn't support block FPGAI2C read yet");
}
else
printk(KERN_ERR "Unable to get the client handle for %s\n", info->devname);
}
return status;
}
int xcvr_i2c_fpga_write(XCVR_ATTR *info, uint32_t val)
{
int status = 0;
unsigned int val_mask = 0, dnd_value = 0;
uint32_t reg;
struct i2c_client *client_ptr = NULL;
val_mask = BIT_INDEX(info->mask);
/* Get the I2C client for the CPLD */
client_ptr = (struct i2c_client *)get_device_table(info->devname);
if (client_ptr)
{
if (info->len == 1)
status = i2c_smbus_read_byte_data(client_ptr, info->offset);
else if (info->len == 2)
status = i2c_smbus_read_word_swapped(client_ptr, info->offset);
else
{
printk(KERN_ERR "PDDF_XCVR: Doesn't support block FPGAI2C read yet");
status = -1;
}
}
else
{
printk(KERN_ERR "Unable to get the client handle for %s\n", info->devname);
status = -1;
}
if (status < 0)
return status;
else
{
msleep(60);
dnd_value = status & ~val_mask;
if (((val == 1) && (info->cmpval != 0)) || ((val == 0) && (info->cmpval == 0)))
reg = dnd_value | val_mask;
else
reg = dnd_value;
if (info->len == 1)
status = i2c_smbus_write_byte_data(client_ptr, info->offset, (uint8_t)reg);
else if (info->len == 2)
status = i2c_smbus_write_word_swapped(client_ptr, info->offset, (uint16_t)reg);
else
{
printk(KERN_ERR "PDDF_XCVR: Doesn't support block FPGAI2C write yet");
status = -1;
}
}
return status;
}
int xcvr_fpgapci_read(XCVR_ATTR *info)
{
int reg_val= 0;
uint32_t offset = 0;
if (ptr_fpgapci_read == NULL) {
printk(KERN_ERR "PDDF_XCVR: Doesn't support FPGAPCI read yet");
return (-1);
}
offset = info->devaddr + info->offset;
reg_val = ptr_fpgapci_read(offset);
return reg_val;
}
int xcvr_fpgapci_write(XCVR_ATTR *info, uint32_t val)
{
int status= 0;
uint32_t reg, val_mask = 0, dnd_value = 0, reg_val;
uint32_t offset = 0;
if (ptr_fpgapci_read == NULL || ptr_fpgapci_write == NULL) {
printk(KERN_ERR "PDDF_XCVR: Doesn't support FPGAPCI read or write yet");
return (-1);
}
offset = info->devaddr + info->offset;
val_mask = BIT_INDEX(info->mask);
reg_val = ptr_fpgapci_read(offset);
dnd_value = reg_val & ~val_mask;
if (((val == 1) && (info->cmpval != 0)) || ((val == 0) && (info->cmpval == 0)))
reg = dnd_value | val_mask;
else
reg = dnd_value;
status = ptr_fpgapci_write(offset, reg);
return status;
}
int sonic_i2c_get_mod_pres(struct i2c_client *client, XCVR_ATTR *info, struct xcvr_data *data) int sonic_i2c_get_mod_pres(struct i2c_client *client, XCVR_ATTR *info, struct xcvr_data *data)
{ {
@ -164,6 +310,31 @@ int sonic_i2c_get_mod_pres(struct i2c_client *client, XCVR_ATTR *info, struct xc
sfp_dbg(KERN_INFO "\nMod presence :0x%x, reg_value = 0x%x, devaddr=0x%x, mask=0x%x, offset=0x%x\n", modpres, status, info->devaddr, info->mask, info->offset); sfp_dbg(KERN_INFO "\nMod presence :0x%x, reg_value = 0x%x, devaddr=0x%x, mask=0x%x, offset=0x%x\n", modpres, status, info->devaddr, info->mask, info->offset);
} }
} }
else if ( strcmp(info->devtype, "fpgai2c") == 0)
{
status = xcvr_i2c_fpga_read(info);
if (status < 0)
return status;
else
{
modpres = ((status & BIT_INDEX(info->mask)) == info->cmpval) ? 1 : 0;
sfp_dbg(KERN_INFO "\nMod presence :0x%x, reg_value = 0x%x, devaddr=0x%x, mask=0x%x, offset=0x%x\n", modpres, status, info->devaddr, info->mask, info->offset);
}
}
else if ( strcmp(info->devtype, "fpgapci") == 0)
{
status = xcvr_fpgapci_read(info);
if (status < 0)
return status;
else
{
modpres = ((status & BIT_INDEX(info->mask)) == info->cmpval) ? 1 : 0;
sfp_dbg(KERN_INFO "\nMod presence :0x%x, status= 0x%x, devaddr=0x%x, mask=0x%x, offset=0x%x\n", modpres, status, info->devaddr, info->mask, info->offset);
}
}
else if(strcmp(info->devtype, "eeprom") == 0) else if(strcmp(info->devtype, "eeprom") == 0)
{ {
/* get client client for eeprom - Not Applicable */ /* get client client for eeprom - Not Applicable */
@ -189,6 +360,30 @@ int sonic_i2c_get_mod_reset(struct i2c_client *client, XCVR_ATTR *info, struct x
sfp_dbg(KERN_INFO "\nMod Reset :0x%x, reg_value = 0x%x\n", modreset, status); sfp_dbg(KERN_INFO "\nMod Reset :0x%x, reg_value = 0x%x\n", modreset, status);
} }
} }
else if ( strcmp(info->devtype, "fpgai2c") == 0)
{
status = xcvr_i2c_fpga_read(info);
if (status < 0)
return status;
else
{
modreset = ((status & BIT_INDEX(info->mask)) == info->cmpval) ? 1 : 0;
sfp_dbg(KERN_INFO "\nMod reset :0x%x, reg_value = 0x%x, devaddr=0x%x, mask=0x%x, offset=0x%x\n", modpres, status, info->devaddr, info->mask, info->offset);
}
}
else if ( strcmp(info->devtype, "fpgapci") == 0)
{
status = xcvr_fpgapci_read(info);
sfp_dbg(KERN_INFO "\n[%s] status=%x\n", __FUNCTION__, status);
if (status < 0)
return status;
else
{
modreset = ((status & BIT_INDEX(info->mask)) == info->cmpval) ? 1 : 0;
sfp_dbg(KERN_INFO "\nMod reset :0x%x, reg_value = 0x%x, devaddr=0x%x, mask=0x%x, offset=0x%x\n", modreset, status, info->devaddr, info->mask, info->offset);
}
}
else if(strcmp(info->devtype, "eeprom") == 0) else if(strcmp(info->devtype, "eeprom") == 0)
{ {
/* get client client for eeprom - Not Applicable */ /* get client client for eeprom - Not Applicable */
@ -214,6 +409,31 @@ int sonic_i2c_get_mod_intr_status(struct i2c_client *client, XCVR_ATTR *info, st
sfp_dbg(KERN_INFO "\nModule Interrupt :0x%x, reg_value = 0x%x\n", mod_intr, status); sfp_dbg(KERN_INFO "\nModule Interrupt :0x%x, reg_value = 0x%x\n", mod_intr, status);
} }
} }
else if ( strcmp(info->devtype, "fpgai2c") == 0)
{
status = xcvr_i2c_fpga_read(info);
if (status < 0)
return status;
else
{
mod_intr = ((status & BIT_INDEX(info->mask)) == info->cmpval) ? 1 : 0;
sfp_dbg(KERN_INFO "\nModule Interrupt :0x%x, reg_value = 0x%x, devaddr=0x%x, mask=0x%x, offset=0x%x\n", modpres, status, info->devaddr, info->mask, info->offset);
}
}
else if ( strcmp(info->devtype, "fpgapci") == 0)
{
status = xcvr_fpgapci_read(info);
sfp_dbg(KERN_INFO "\n[%s] status=%x\n", __FUNCTION__, status);
if (status < 0)
return status;
else
{
mod_intr = ((status & BIT_INDEX(info->mask)) == info->cmpval) ? 1 : 0;
sfp_dbg(KERN_INFO "\nModule Interrupt :0x%x, reg_value = 0x%x, devaddr=0x%x, mask=0x%x, offset=0x%x\n", mod_intr, status, info->devaddr, info->mask, info->offset);
}
}
else if(strcmp(info->devtype, "eeprom") == 0) else if(strcmp(info->devtype, "eeprom") == 0)
{ {
/* get client client for eeprom - Not Applicable */ /* get client client for eeprom - Not Applicable */
@ -240,6 +460,30 @@ int sonic_i2c_get_mod_lpmode(struct i2c_client *client, XCVR_ATTR *info, struct
sfp_dbg(KERN_INFO "\nModule LPmode :0x%x, reg_value = 0x%x\n", lpmode, status); sfp_dbg(KERN_INFO "\nModule LPmode :0x%x, reg_value = 0x%x\n", lpmode, status);
} }
} }
else if ( strcmp(info->devtype, "fpgai2c") == 0)
{
status = xcvr_i2c_fpga_read(info);
if (status < 0)
return status;
else
{
lpmode = ((status & BIT_INDEX(info->mask)) == info->cmpval) ? 1 : 0;
sfp_dbg(KERN_INFO "\nModule LPmode :0x%x, reg_value = 0x%x, devaddr=0x%x, mask=0x%x, offset=0x%x\n", modpres, status, info->devaddr, info->mask, info->offset);
}
}
else if ( strcmp(info->devtype, "fpgapci") == 0)
{
status = xcvr_fpgapci_read(info);
sfp_dbg(KERN_INFO "\n[%s] status=%x\n", __FUNCTION__, status);
if (status < 0)
return status;
else
{
lpmode = ((status & BIT_INDEX(info->mask)) == info->cmpval) ? 1 : 0;
sfp_dbg(KERN_INFO "\nlpmode :0x%x, reg_val = 0x%x, op=0x%x, mask=0x%x, offset=0x%x\n", lpmode, status, status & BIT_INDEX(info->mask), info->mask, info->offset);
}
}
else if (strcmp(info->devtype, "eeprom") == 0) else if (strcmp(info->devtype, "eeprom") == 0)
{ {
/* get client client for eeprom - Not Applicable */ /* get client client for eeprom - Not Applicable */
@ -266,6 +510,18 @@ int sonic_i2c_get_mod_rxlos(struct i2c_client *client, XCVR_ATTR *info, struct x
sfp_dbg(KERN_INFO "\nModule RxLOS :0x%x, reg_value = 0x%x\n", rxlos, status); sfp_dbg(KERN_INFO "\nModule RxLOS :0x%x, reg_value = 0x%x\n", rxlos, status);
} }
} }
else if ( strcmp(info->devtype, "fpgai2c") == 0)
{
status = xcvr_i2c_fpga_read(info);
if (status < 0)
return status;
else
{
rxlos = ((status & BIT_INDEX(info->mask)) == info->cmpval) ? 1 : 0;
sfp_dbg(KERN_INFO "\nModule RxLOS :0x%x, reg_value = 0x%x, devaddr=0x%x, mask=0x%x, offset=0x%x\n", modpres, status, info->devaddr, info->mask, info->offset);
}
}
data->rxlos = rxlos; data->rxlos = rxlos;
return 0; return 0;
@ -287,6 +543,18 @@ int sonic_i2c_get_mod_txdisable(struct i2c_client *client, XCVR_ATTR *info, stru
sfp_dbg(KERN_INFO "\nModule TxDisable :0x%x, reg_value = 0x%x\n", txdis, status); sfp_dbg(KERN_INFO "\nModule TxDisable :0x%x, reg_value = 0x%x\n", txdis, status);
} }
} }
else if ( strcmp(info->devtype, "fpgai2c") == 0)
{
status = xcvr_i2c_fpga_read(info);
if (status < 0)
return status;
else
{
txdis = ((status & BIT_INDEX(info->mask)) == info->cmpval) ? 1 : 0;
sfp_dbg(KERN_INFO "\nModule TxDisable :0x%x, reg_value = 0x%x, devaddr=0x%x, mask=0x%x, offset=0x%x\n", modpres, status, info->devaddr, info->mask, info->offset);
}
}
data->txdisable = txdis; data->txdisable = txdis;
return 0; return 0;
@ -309,6 +577,18 @@ int sonic_i2c_get_mod_txfault(struct i2c_client *client, XCVR_ATTR *info, struct
} }
} }
else if ( strcmp(info->devtype, "fpgai2c") == 0)
{
status = xcvr_i2c_fpga_read(info);
if (status < 0)
return status;
else
{
txflt = ((status & BIT_INDEX(info->mask)) == info->cmpval) ? 1 : 0;
sfp_dbg(KERN_INFO "\nModule Txfault :0x%x, reg_value = 0x%x, devaddr=0x%x, mask=0x%x, offset=0x%x\n", modpres, status, info->devaddr, info->mask, info->offset);
}
}
data->txfault = txflt; data->txfault = txflt;
return 0; return 0;
@ -322,6 +602,14 @@ int sonic_i2c_set_mod_reset(struct i2c_client *client, XCVR_ATTR *info, struct x
{ {
status = xcvr_i2c_cpld_write(info, data->reset); status = xcvr_i2c_cpld_write(info, data->reset);
} }
else if (strcmp(info->devtype, "fpgai2c") == 0)
{
status = xcvr_i2c_fpga_write(info, data->reset);
}
else if (strcmp(info->devtype, "fpgapci") == 0)
{
status = xcvr_fpgapci_write(info, data->reset);
}
else else
{ {
printk(KERN_ERR "Error: Invalid device type (%s) to set xcvr reset\n", info->devtype); printk(KERN_ERR "Error: Invalid device type (%s) to set xcvr reset\n", info->devtype);
@ -339,6 +627,14 @@ int sonic_i2c_set_mod_lpmode(struct i2c_client *client, XCVR_ATTR *info, struct
{ {
status = xcvr_i2c_cpld_write(info, data->lpmode); status = xcvr_i2c_cpld_write(info, data->lpmode);
} }
else if (strcmp(info->devtype, "fpgai2c") == 0)
{
status = xcvr_i2c_fpga_write(info, data->lpmode);
}
else if (strcmp(info->devtype, "fpgapci") == 0)
{
status = xcvr_fpgapci_write(info, data->lpmode);
}
else else
{ {
printk(KERN_ERR "Error: Invalid device type (%s) to set xcvr lpmode\n", info->devtype); printk(KERN_ERR "Error: Invalid device type (%s) to set xcvr lpmode\n", info->devtype);
@ -356,6 +652,10 @@ int sonic_i2c_set_mod_txdisable(struct i2c_client *client, XCVR_ATTR *info, stru
{ {
status = xcvr_i2c_cpld_write(info, data->txdisable); status = xcvr_i2c_cpld_write(info, data->txdisable);
} }
else if (strcmp(info->devtype, "fpgai2c") == 0)
{
status = xcvr_i2c_fpga_write(info, data->txdisable);
}
else else
{ {
printk(KERN_ERR "Error: Invalid device type (%s) to set xcvr txdisable\n", info->devtype); printk(KERN_ERR "Error: Invalid device type (%s) to set xcvr txdisable\n", info->devtype);

View File

@ -278,7 +278,7 @@ int xcvr_init(void)
} }
EXPORT_SYMBOL(xcvr_init); EXPORT_SYMBOL(xcvr_init);
void __exit xcvr_exit(void) void xcvr_exit(void)
{ {
pddf_dbg(XCVR, "PDDF XCVR DRIVER.. exit\n"); pddf_dbg(XCVR, "PDDF XCVR DRIVER.. exit\n");
if (pddf_xcvr_ops.pre_exit) (pddf_xcvr_ops.pre_exit)(); if (pddf_xcvr_ops.pre_exit) (pddf_xcvr_ops.pre_exit)();
@ -288,9 +288,9 @@ void __exit xcvr_exit(void)
} }
EXPORT_SYMBOL(xcvr_exit); EXPORT_SYMBOL(xcvr_exit);
module_init(xcvr_init);
module_exit(xcvr_exit);
MODULE_AUTHOR("Broadcom"); MODULE_AUTHOR("Broadcom");
MODULE_DESCRIPTION("Driver for transceiver operations"); MODULE_DESCRIPTION("Driver for transceiver operations");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
module_init(xcvr_init);
module_exit(xcvr_exit);

View File

@ -203,7 +203,9 @@ def config_pddf_utils():
if not os.path.exists(SONIC_PLATFORM_BSP_WHL_PKG_BK): if not os.path.exists(SONIC_PLATFORM_BSP_WHL_PKG_BK):
# bsp 2.0 classes are installed. Take a backup and copy pddf 2.0 whl pkg # bsp 2.0 classes are installed. Take a backup and copy pddf 2.0 whl pkg
log_os_system('mv '+SONIC_PLATFORM_BSP_WHL_PKG+' '+SONIC_PLATFORM_BSP_WHL_PKG_BK, 1) log_os_system('mv '+SONIC_PLATFORM_BSP_WHL_PKG+' '+SONIC_PLATFORM_BSP_WHL_PKG_BK, 1)
log_os_system('sync', 1)
shutil.copy(SONIC_PLATFORM_PDDF_WHL_PKG, SONIC_PLATFORM_BSP_WHL_PKG) shutil.copy(SONIC_PLATFORM_PDDF_WHL_PKG, SONIC_PLATFORM_BSP_WHL_PKG)
log_os_system('sync', 1)
# uninstall the existing bsp whl pkg # uninstall the existing bsp whl pkg
status, output = log_os_system("pip3 uninstall sonic-platform -y &> /dev/null", 1) status, output = log_os_system("pip3 uninstall sonic-platform -y &> /dev/null", 1)
if status: if status:
@ -328,6 +330,7 @@ def create_pddf_log_files():
log_os_system("sudo touch /var/log/pddf/cpldmux.txt", 1) log_os_system("sudo touch /var/log/pddf/cpldmux.txt", 1)
log_os_system("sudo touch /var/log/pddf/client.txt", 1) log_os_system("sudo touch /var/log/pddf/client.txt", 1)
log_os_system("sudo touch /var/log/pddf/mux.txt", 1) log_os_system("sudo touch /var/log/pddf/mux.txt", 1)
log_os_system("sudo touch /var/log/pddf/fpgapci.txt", 1)
def driver_install(): def driver_install():
global FORCE global FORCE

View File

@ -18,19 +18,6 @@ PLATFORM_KEY = 'DEVICE_METADATA.localhost.platform'
dirname = os.path.dirname(os.path.realpath(__file__)) dirname = os.path.dirname(os.path.realpath(__file__))
color_map = {
"STATUS_LED_COLOR_GREEN" : "green",
"STATUS_LED_COLOR_RED" : "red",
"STATUS_LED_COLOR_AMBER" : "amber",
"STATUS_LED_COLOR_BLUE" : "blue",
"STATUS_LED_COLOR_GREEN_BLINK" : "blinking green",
"STATUS_LED_COLOR_RED_BLINK" : "blinking red",
"STATUS_LED_COLOR_AMBER_BLINK" : "blinking amber",
"STATUS_LED_COLOR_BLUE_BLINK" : "blinking blue",
"STATUS_LED_COLOR_OFF" : "off"
}
class PddfParse(): class PddfParse():
def __init__(self): def __init__(self):
if not os.path.exists("/usr/share/sonic/platform"): if not os.path.exists("/usr/share/sonic/platform"):
@ -128,7 +115,7 @@ class PddfParse():
except IOError: except IOError:
return ("Error") return ("Error")
return (color_map[color]) return (color)
################################################################################################################### ###################################################################################################################
# CREATE DEFS # CREATE DEFS
@ -262,6 +249,30 @@ class PddfParse():
return create_ret.append(ret) return create_ret.append(ret)
def create_fpgai2c_device(self, dev, ops):
create_ret = []
ret = 0
if dev['i2c']['topo_info']['dev_type'] in self.data['PLATFORM']['pddf_dev_types']['FPGAI2C']:
ret = self.create_device(dev['i2c']['topo_info'], "pddf/devices/fpgai2c", ops)
if ret!=0:
return create_ret.append(ret)
cmd= "echo '%s' > /sys/kernel/pddf/devices/fpgai2c/i2c_name"%(dev['dev_info']['device_name'])
ret = self.runcmd(cmd)
if ret!=0:
return create_ret.append(ret)
cmd= "echo 'add' > /sys/kernel/pddf/devices/fpgai2c/dev_ops"
ret = self.runcmd(cmd)
if ret!=0:
return create_ret.append(ret)
else:
cmd= "echo %s 0x%x > /sys/bus/i2c/devices/i2c-%d/new_device" % (dev['i2c']['topo_info']['dev_type'], int(dev['i2c']['topo_info']['dev_addr'], 0), int(dev['i2c']['topo_info']['parent_bus'], 0))
ret = self.runcmd(cmd)
if ret!=0:
return create_ret.append(ret)
return create_ret.append(ret)
def create_cpldmux_device(self, dev, ops): def create_cpldmux_device(self, dev, ops):
create_ret = [] create_ret = []
ret = 0 ret = 0
@ -436,7 +447,19 @@ class PddfParse():
return create_ret.append(ret) return create_ret.append(ret)
################################################################################################################### def create_fpgapci_device(self, dev, ops):
create_ret = []
ret = 0
ret = self.create_device(dev['i2c']['dev_attr'], "pddf/devices/fpgapci", ops)
if ret!=0:
return create_ret.append(ret)
cmd = "echo 'fpgapci_init' > /sys/kernel/pddf/devices/fpgapci/dev_ops"
ret = self.runcmd(cmd)
return create_ret.append(ret)
#################################################################################################################################
# DELETE DEFS # DELETE DEFS
################################################################################################################### ###################################################################################################################
def delete_eeprom_device(self, dev, ops): def delete_eeprom_device(self, dev, ops):
@ -494,6 +517,16 @@ class PddfParse():
int(dev['i2c']['topo_info']['dev_addr'], 0), int(dev['i2c']['topo_info']['parent_bus'], 0)) int(dev['i2c']['topo_info']['dev_addr'], 0), int(dev['i2c']['topo_info']['parent_bus'], 0))
self.runcmd(cmd) self.runcmd(cmd)
def delete_fpgai2c_device(self, dev, ops):
if dev['i2c']['topo_info']['dev_type'] in self.data['PLATFORM']['pddf_dev_types']['FPGAI2C']:
cmd= "echo '%s' > /sys/kernel/pddf/devices/fpgai2c/i2c_name"%(dev['dev_info']['device_name'])
self.runcmd(cmd)
cmd= "echo 'delete' > /sys/kernel/pddf/devices/fpgai2c/dev_ops"
self.runcmd(cmd)
else:
cmd= "echo 0x%x > /sys/bus/i2c/devices/i2c-%d/delete_device" % (int(dev['i2c']['topo_info']['dev_addr'], 0), int(dev['i2c']['topo_info']['parent_bus'], 0))
self.runcmd(cmd)
def delete_cpldmux_device(self, dev, ops): def delete_cpldmux_device(self, dev, ops):
if dev['i2c']['topo_info']['dev_type'] in self.data['PLATFORM']['pddf_dev_types']['CPLDMUX']: if dev['i2c']['topo_info']['dev_type'] in self.data['PLATFORM']['pddf_dev_types']['CPLDMUX']:
cmd = "echo '%s' > /sys/kernel/pddf/devices/cpldmux/i2c_name" % (dev['dev_info']['device_name']) cmd = "echo '%s' > /sys/kernel/pddf/devices/cpldmux/i2c_name" % (dev['dev_info']['device_name'])
@ -534,7 +567,9 @@ class PddfParse():
self.delete_psu_i2c_device(dev, ops) self.delete_psu_i2c_device(dev, ops)
return return
################################################################################################################### def delete_fpgapci_device(self, dev, ops):
return
#################################################################################################################################
# SHOW ATTRIBIUTES DEFS # SHOW ATTRIBIUTES DEFS
################################################################################################################### ###################################################################################################################
def is_led_device_configured(self, device_name, attr_name): def is_led_device_configured(self, device_name, attr_name):
@ -991,6 +1026,21 @@ class PddfParse():
'/sys/kernel/pddf/devices/cpld/error'] '/sys/kernel/pddf/devices/cpld/error']
self.add_list_sysfs_obj(self.sysfs_obj, KEY, extra_list) self.add_list_sysfs_obj(self.sysfs_obj, KEY, extra_list)
def show_fpgai2c_device(self, dev, ops):
KEY ='fpgai2c'
if dev['i2c']['topo_info']['dev_type'] in self.data['PLATFORM']['pddf_dev_types']['FPGAI2C']:
if not KEY in self.sysfs_obj:
self.sysfs_obj[KEY] = []
self.sysfs_device(dev['i2c']['topo_info'], "pddf/devices/fpgai2c", self.sysfs_obj, KEY)
sysfs_path = "/sys/kernel/pddf/devices/fpgai2c/dev_ops"
if not sysfs_path in self.sysfs_obj[KEY]:
self.sysfs_obj[KEY].append(sysfs_path)
extra_list = ['/sys/kernel/pddf/devices/fpgai2c/i2c_type',
'/sys/kernel/pddf/devices/fpgai2c/i2c_name',
'/sys/kernel/pddf/devices/fpgai2c/error']
self.add_list_sysfs_obj(self.sysfs_obj, KEY, extra_list)
def show_led_platform_device(self, key, ops): def show_led_platform_device(self, key, ops):
if ops['attr'] == 'all' or ops['attr'] == 'PLATFORM': if ops['attr'] == 'all' or ops['attr'] == 'PLATFORM':
KEY = 'platform' KEY = 'platform'
@ -1006,21 +1056,36 @@ class PddfParse():
if not KEY in self.sysfs_obj: if not KEY in self.sysfs_obj:
self.sysfs_obj[KEY] = [] self.sysfs_obj[KEY] = []
path="pddf/devices/led" path="pddf/devices/led"
for attr in self.data[key]['i2c']['attr_list']:
self.sysfs_attr('device_name', self.data[key]['dev_info']['device_name'], path, self.sysfs_obj, KEY) self.sysfs_attr('device_name', self.data[key]['dev_info']['device_name'], path, self.sysfs_obj, KEY)
self.sysfs_attr('swpld_addr', self.data[key]['dev_info']['device_name'], path, self.sysfs_obj, KEY) self.sysfs_attr('swpld_addr', self.data[key]['dev_info']['device_name'], path, self.sysfs_obj, KEY)
self.sysfs_attr('swpld_addr_offset',self.data[key]['dev_info']['device_name'], self.sysfs_attr('swpld_addr_offset', self.data[key]['dev_info']['device_name'], path, self.sysfs_obj, KEY)
path,self.sysfs_obj, KEY) state_attr_path="pddf/devices/led/state_attr"
self.sysfs_device(self.data[key]['dev_attr'], path, self.sysfs_obj, KEY) self.sysfs_attr('bits', self.data[key]['dev_info']['device_name'], state_attr_path, self.sysfs_obj, KEY)
for attr_key in attr.keys(): self.sysfs_attr('value', self.data[key]['dev_info']['device_name'], state_attr_path, self.sysfs_obj, KEY)
attr_path = "pddf/devices/led/" + attr['attr_name']
if (attr_key != 'attr_name' and attr_key != 'swpld_addr' and attr_key != 'swpld_addr_offset'):
self.sysfs_attr(attr_key, attr[attr_key], attr_path, self.sysfs_obj, KEY)
sysfs_path="/sys/kernel/pddf/devices/led/dev_ops" sysfs_path="/sys/kernel/pddf/devices/led/dev_ops"
if not sysfs_path in self.sysfs_obj[KEY]: if not sysfs_path in self.sysfs_obj[KEY]:
self.sysfs_obj[KEY].append(sysfs_path) self.sysfs_obj[KEY].append(sysfs_path)
list=['/sys/kernel/pddf/devices/led/cur_state/color'] extra_list=['/sys/kernel/pddf/devices/led/cur_state/color']
self.add_list_sysfs_obj(self.sysfs_obj, KEY, list) self.add_list_sysfs_obj(self.sysfs_obj, KEY, extra_list)
def show_fpgapci_device(self, dev, ops):
KEY ='fpgapci'
if dev['dev_info']['device_type'] in self.data['PLATFORM']['pddf_dev_types']['FPGAPCIE']:
if not KEY in self.sysfs_obj:
self.sysfs_obj[KEY] = []
sysfs_path = "/sys/kernel/pddf/devices/fpgapci"
if not sysfs_path in self.sysfs_obj[KEY]:
self.sysfs_obj[KEY].append(sysfs_path)
extra_list = ['/sys/kernel/pddf/devices/fpgapci/vendor_id',
'/sys/kernel/pddf/devices/fpgapci/virt_bus',
'/sys/kernel/pddf/devices/fpgapci/device_id',
'/sys/kernel/pddf/devices/fpgapci/data_base_offset',
'/sys/kernel/pddf/devices/fpgapci/data_size',
'/sys/kernel/pddf/devices/fpgapci/i2c_ch_base_offset',
'/sys/kernel/pddf/devices/fpgapci/i2c_ch_size',
'/sys/kernel/pddf/devices/fpgapci/virt_i2c_ch']
self.add_list_sysfs_obj(self.sysfs_obj, KEY, extra_list)
def validate_xcvr_device(self, dev, ops): def validate_xcvr_device(self, dev, ops):
@ -1077,6 +1142,13 @@ class PddfParse():
ret_val = "cpld success" ret_val = "cpld success"
print(ret_val) print(ret_val)
def validate_fpgai2c_device(self, dev, ops):
devtype_list = ['i2c_fpga']
ret_val = "fpgai2c failed"
if dev['i2c']['topo_info']['dev_type'] in devtype_list:
ret_val = "fpgai2c success"
print(ret_val)
def validate_sysstatus_device(self, dev, ops): def validate_sysstatus_device(self, dev, ops):
dev_attribs = ['board_info', 'cpld1_version', 'power_module_status', 'system_reset5', dev_attribs = ['board_info', 'cpld1_version', 'power_module_status', 'system_reset5',
@ -1530,7 +1602,28 @@ class PddfParse():
val.extend(ret) val.extend(ret)
return val return val
def fpgapci_parse(self, dev, ops):
val = []
ret = getattr(self, ops['cmd']+"_fpgapci_device")(dev, ops)
if ret:
if str(ret[0]).isdigit():
if ret[0]!=0:
# in case if 'create' functions
print("{}_fpgapci_device() cmd failed".format(ops['cmd']))
return ret
else:
val.extend(ret)
for bus in dev['i2c']['channel']:
ret = self.dev_parse(self.data[bus['dev']], ops)
if ret:
if str(ret[0]).isdigit():
if ret[0]!=0:
# in case if 'create' functions
return ret
else:
val.extend(ret)
return val
# 'create' and 'show_attr' ops returns an array # 'create' and 'show_attr' ops returns an array
# 'delete', 'show' and 'validate' ops return None # 'delete', 'show' and 'validate' ops return None
@ -1542,6 +1635,9 @@ class PddfParse():
else: else:
return self.cpu_parse(dev, ops) return self.cpu_parse(dev, ops)
if attr['device_type'] == 'FPGAPCIE':
return self.fpgapci_parse(dev, ops)
if attr['device_type'] == 'EEPROM': if attr['device_type'] == 'EEPROM':
return self.eeprom_parse(dev, ops) return self.eeprom_parse(dev, ops)
@ -1568,6 +1664,9 @@ class PddfParse():
attr['device_type'] == 'QSFP-DD': attr['device_type'] == 'QSFP-DD':
return self.optic_parse(dev, ops) return self.optic_parse(dev, ops)
if attr['device_type'] == 'FPGAI2C':
return self.fpgai2c_parse(dev, ops)
if attr['device_type'] == 'CPLD': if attr['device_type'] == 'CPLD':
return self.cpld_parse(dev, ops) return self.cpld_parse(dev, ops)
@ -1589,7 +1688,8 @@ class PddfParse():
return False, "[FAILED]: Invalid color" return False, "[FAILED]: Invalid color"
def create_attr(self, key, value, path): def create_attr(self, key, value, path, exceptions=[]):
if key not in exceptions:
cmd = "echo '%s' > /sys/kernel/%s/%s" % (value, path, key) cmd = "echo '%s' > /sys/kernel/%s/%s" % (value, path, key)
self.runcmd(cmd) self.runcmd(cmd)
@ -1602,14 +1702,21 @@ class PddfParse():
def create_led_device(self, key, ops): def create_led_device(self, key, ops):
if ops['attr']=='all' or ops['attr']==self.data[key]['dev_info']['device_name']: if ops['attr']=='all' or ops['attr']==self.data[key]['dev_info']['device_name']:
path = "pddf/devices/led" path = "pddf/devices/led"
ops_state = ""
if 'bmc' in self.data[key]:
return
for attr in self.data[key]['i2c']['attr_list']: for attr in self.data[key]['i2c']['attr_list']:
self.create_attr('device_name', self.data[key]['dev_info']['device_name'], path) self.create_attr('device_name', self.data[key]['dev_info']['device_name'], path)
self.create_device(self.data[key]['dev_attr'], path, ops) self.create_attr('index', self.data[key]['dev_attr']['index'], path)
#attr_devtype and attr_devname are optional in json file.
#if attr_devtype is not defined, it means it is "cpld"
if 'attr_devtype' not in attr.keys():
self.create_attr('attr_devtype', 'cpld', path)
for attr_key in attr.keys(): for attr_key in attr.keys():
if (attr_key == 'swpld_addr_offset' or attr_key == 'swpld_addr'): if (attr_key == 'swpld_addr_offset' or attr_key == 'swpld_addr' or \
attr_key == 'attr_devtype' or attr_key == 'attr_devname' ):
self.create_attr(attr_key, attr[attr_key], path) self.create_attr(attr_key, attr[attr_key], path)
elif (attr_key != 'attr_name' and attr_key != 'descr' and elif (attr_key != 'attr_name' and attr_key != 'descr' and attr_key != 'state'):
attr_key != 'attr_devtype' and attr_key != 'attr_devname'):
state_path = path+'/state_attr' state_path = path+'/state_attr'
self.create_attr(attr_key, attr[attr_key],state_path) self.create_attr(attr_key, attr[attr_key],state_path)
cmd="echo '" + attr['attr_name']+"' > /sys/kernel/pddf/devices/led/dev_ops" cmd="echo '" + attr['attr_name']+"' > /sys/kernel/pddf/devices/led/dev_ops"