Skip to content

Commit

Permalink
[pddf]: Update PDDF kernel modules with 5.10 kernel and fix some comp…
Browse files Browse the repository at this point in the history
…ilation (#9582)

- Why I did it
There were compilation errors and warnings like,

/usr/src/linux-headers-5.10.0-8-2-common/scripts/Makefile.build:69: You cannot use subdir-y/m to visit a module Makefile. Use obj-y/m instead.

fatal error: linux/platform_data/pca954x.h: No such file or directory

hwmon_device_register() is deprecated. Please convert the driver to use hwmon_device_register_with_info().

If PDDF kernel module compilation fails, the PDDF debian package was not detecting the break.

- How I did it
Modified the code with new kernel 5.10 APIs.
Modified the Makefiles to use 'obj-m' instead of 'subdir-y'

- How to verify it
PDDF is supported on Accton platform. Load the build on AS7326 setup and check the 'dmesg'
  • Loading branch information
FuzailBrcm authored Jan 3, 2022
1 parent b965333 commit 93247a6
Show file tree
Hide file tree
Showing 29 changed files with 317 additions and 304 deletions.
2 changes: 1 addition & 1 deletion platform/pddf/i2c/Makefile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
subdir-m := modules
obj-m := modules/
10 changes: 8 additions & 2 deletions platform/pddf/i2c/debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ PACKAGE_PRE_NAME := sonic-platform-pddf
KVERSION ?= $(shell uname -r)
KERNEL_SRC := /lib/modules/$(KVERSION)
MOD_SRC_DIR:= $(shell pwd)
MODULE_DIRS:= client cpld cpld/driver cpldmux cpldmux/driver fan fan/driver fan/vendor_api mux gpio led psu psu/driver sysstatus xcvr xcvr/driver
MODULE_DIRS:= client cpld cpld/driver cpldmux cpldmux/driver fan fan/driver mux gpio led psu psu/driver sysstatus xcvr xcvr/driver
MODULE_DIR:= modules
UTILS_DIR := utils
SERVICE_DIR := service
Expand All @@ -35,8 +35,10 @@ clean:
make -C $(KERNEL_SRC)/build M=$(MOD_SRC_DIR) clean

build:
set -e; \
make modules -C $(KERNEL_SRC)/build M=$(MOD_SRC_DIR); \
$(PYTHON) $(MOD_SRC_DIR)/setup.py build; \
set +e

binary: binary-arch binary-indep
# Nothing to do
Expand All @@ -50,11 +52,15 @@ binary-indep:
dh_installdirs -p$(PACKAGE_PRE_NAME) $(KERNEL_SRC)/$(INSTALL_MOD_DIR); \
dh_installdirs -p$(PACKAGE_PRE_NAME) usr/local/bin; \
# Custom package commands
set -e; \
(for mod in $(MODULE_DIRS); do \
cp $(MOD_SRC_DIR)/$(MODULE_DIR)/$${mod}/*.ko debian/$(PACKAGE_PRE_NAME)/$(KERNEL_SRC)/$(INSTALL_MOD_DIR); \
done) ; \
# Need to take a backup of symvers file for compilation of custom modules in various platforms
cp $(MOD_SRC_DIR)/Module.symvers $(MOD_SRC_DIR)/Module.symvers.PDDF; \
cp -r $(MOD_SRC_DIR)/$(UTILS_DIR)/* debian/$(PACKAGE_PRE_NAME)/usr/local/bin/; \
$(PYTHON) $(MOD_SRC_DIR)/setup.py install --root=$(MOD_SRC_DIR)/debian/$(PACKAGE_PRE_NAME) --install-layout=deb;
$(PYTHON) $(MOD_SRC_DIR)/setup.py install --root=$(MOD_SRC_DIR)/debian/$(PACKAGE_PRE_NAME) --install-layout=deb; \
set +e

# Resuming debhelper scripts
dh_testroot
Expand Down
2 changes: 1 addition & 1 deletion platform/pddf/i2c/modules/Makefile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
subdir-m := client cpld cpldmux xcvr mux gpio psu fan led sysstatus
obj-m := client/ cpld/ cpldmux/ xcvr/ mux/ gpio/ psu/ fan/ led/ sysstatus/
6 changes: 3 additions & 3 deletions platform/pddf/i2c/modules/cpld/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
subdir-m := driver
obj-m := pddf_cpld_module.o
obj-m := driver/
obj-m += pddf_cpld_module.o

CFLAGS_$(obj-m):= -I$(M)/modules/include
ccflags-y:= -I$(M)/modules/include
61 changes: 59 additions & 2 deletions platform/pddf/i2c/modules/cpld/driver/pddf_cpld_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,58 @@ static struct mutex list_lock;

struct cpld_client_node {
struct i2c_client *client;
char name[CPLD_CLIENT_NAME_LEN];
struct list_head list;
};

int board_i2c_cpld_read_new(unsigned short cpld_addr, char *name, u8 reg)
{
struct list_head *list_node = NULL;
struct cpld_client_node *cpld_node = NULL;
int ret = -EPERM;

mutex_lock(&list_lock);

list_for_each(list_node, &cpld_client_list)
{
cpld_node = list_entry(list_node, struct cpld_client_node, list);

if ((cpld_node->client->addr == cpld_addr) && (strncmp(cpld_node->name, name, strlen(name)) == 0)) {
ret = i2c_smbus_read_byte_data(cpld_node->client, reg);
break;
}
}

mutex_unlock(&list_lock);

return ret;
}
EXPORT_SYMBOL(board_i2c_cpld_read_new);

int board_i2c_cpld_write_new(unsigned short cpld_addr, char *name, u8 reg, u8 value)
{
struct list_head *list_node = NULL;
struct cpld_client_node *cpld_node = NULL;
int ret = -EIO;

mutex_lock(&list_lock);

list_for_each(list_node, &cpld_client_list)
{
cpld_node = list_entry(list_node, struct cpld_client_node, list);

if ((cpld_node->client->addr == cpld_addr) && (strncmp(cpld_node->name, name, strlen(name)) == 0)){
ret = i2c_smbus_write_byte_data(cpld_node->client, reg, value);
break;
}
}

mutex_unlock(&list_lock);

return ret;
}
EXPORT_SYMBOL(board_i2c_cpld_write_new);

int board_i2c_cpld_read(unsigned short cpld_addr, u8 reg)
{
struct list_head *list_node = NULL;
Expand Down Expand Up @@ -128,7 +177,9 @@ static void board_i2c_cpld_add_client(struct i2c_client *client)
}

node->client = client;

strcpy(node->name, (char *)client->dev.platform_data);
dev_dbg(&client->dev, "Adding %s to the cpld client list\n", node->name);

mutex_lock(&list_lock);
list_add(&node->list, &cpld_client_list);
mutex_unlock(&list_lock);
Expand Down Expand Up @@ -188,8 +239,14 @@ static int board_i2c_cpld_probe(struct i2c_client *client,

static int board_i2c_cpld_remove(struct i2c_client *client)
{
sysfs_remove_group(&client->dev.kobj, &cpld_attribute_group);
/* Platform data is just a char string */
char *platdata = (char *)client->dev.platform_data;
sysfs_remove_group(&client->dev.kobj, &cpld_attribute_group);
board_i2c_cpld_remove_client(client);
if (platdata)
{
kfree(platdata);
}

return 0;
}
Expand Down
19 changes: 12 additions & 7 deletions platform/pddf/i2c/modules/cpld/pddf_cpld_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ EXPORT_SYMBOL(pddf_cpld_data);

static ssize_t do_device_operation(struct device *dev, struct device_attribute *da, const char *buf, size_t count);
static ssize_t store_pddf_cpld_data(struct device *dev, struct device_attribute *da, const char *buf, size_t count);
ssize_t show_pddf_cpld_data(struct device *dev, struct device_attribute *da, char *buf);
static ssize_t show_pddf_cpld_data(struct device *dev, struct device_attribute *da, char *buf);

extern void *get_device_table(char *name);
extern void delete_device_table(char *name);
Expand Down Expand Up @@ -77,9 +77,8 @@ static ssize_t store_pddf_cpld_data(struct device *dev, struct device_attribute

return count;
}
EXPORT_SYMBOL(store_pddf_cpld_data);

ssize_t show_pddf_cpld_data(struct device *dev, struct device_attribute *da, char *buf)
static ssize_t show_pddf_cpld_data(struct device *dev, struct device_attribute *da, char *buf)
{
int ret = 0;
PDDF_ATTR *ptr = (PDDF_ATTR *)da;
Expand All @@ -91,7 +90,6 @@ ssize_t show_pddf_cpld_data(struct device *dev, struct device_attribute *da, cha

return ret;
}
EXPORT_SYMBOL(show_pddf_cpld_data);

static ssize_t do_device_operation(struct device *dev, struct device_attribute *da, const char *buf, size_t count)
{
Expand All @@ -100,24 +98,27 @@ static ssize_t do_device_operation(struct device *dev, struct device_attribute *
struct i2c_adapter *adapter;
static struct i2c_board_info board_info;
struct i2c_client *client_ptr;
char *pddf_cpld_name = NULL;

if (strncmp(buf, "add", strlen(buf)-1)==0)
{
adapter = i2c_get_adapter(device_ptr->parent_bus);

if (strncmp(device_ptr->dev_type, "i2c_cpld", strlen("i2c_cpld"))==0)
{
pddf_cpld_name = (char *)kzalloc(CPLD_CLIENT_NAME_LEN, GFP_KERNEL);
if (pddf_cpld_name != NULL) strcpy(pddf_cpld_name, device_ptr->i2c_name);

board_info = (struct i2c_board_info) {
.platform_data = (void *)NULL,
.platform_data = (void *)pddf_cpld_name,
};

board_info.addr = device_ptr->dev_addr;
strcpy(board_info.type, device_ptr->dev_type);

/*pddf_dbg(KERN_ERR "Creating a client %s on 0x%x, platform_data 0x%x\n", board_info.type, board_info.addr, board_info.platform_data);*/
client_ptr = i2c_new_client_device(adapter, &board_info);

if (client_ptr != NULL) {
if (!IS_ERR(client_ptr)) {
i2c_put_adapter(adapter);
pddf_dbg(CPLD, KERN_ERR "Created %s client: 0x%p\n", device_ptr->i2c_name, (void *)client_ptr);
add_device_table(device_ptr->i2c_name, (void*)client_ptr);
Expand Down Expand Up @@ -152,8 +153,12 @@ static ssize_t do_device_operation(struct device *dev, struct device_attribute *
{
printk(KERN_ERR "PDDF_ERROR: %s: Invalid value for dev_ops %s", __FUNCTION__, buf);
}
goto clear_data;

free_data:
if (board_info.platform_data)
kfree(board_info.platform_data);
clear_data:
/*TODO: free the device_ptr->data is dynamically allocated*/
memset(device_ptr, 0 , sizeof(NEW_DEV_ATTR));

Expand Down
6 changes: 3 additions & 3 deletions platform/pddf/i2c/modules/cpldmux/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
subdir-m := driver
obj-m := pddf_cpldmux_module.o
obj-m := driver/
obj-m += pddf_cpldmux_module.o

CFLAGS_$(obj-m):= -I$(M)/modules/include
ccflags-y:= -I$(M)/modules/include
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <linux/slab.h>
#include <linux/list.h>
#include <linux/dmi.h>
#include <linux/platform_data/pca954x.h>
#include <linux/i2c-mux.h>
#include <linux/platform_device.h>
#include "pddf_client_defs.h"
Expand Down
6 changes: 3 additions & 3 deletions platform/pddf/i2c/modules/fan/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
subdir-m := driver
obj-m := pddf_fan_module.o
obj-m := driver/
obj-m += pddf_fan_module.o

CFLAGS_$(obj-m):= -I$(M)/modules/include
ccflags-y:= -I$(M)/modules/include
49 changes: 32 additions & 17 deletions platform/pddf/i2c/modules/fan/driver/pddf_fan_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,20 @@ int fan_update_hw(struct device *dev, struct fan_attr_info *info, FAN_DATA_ATTR
{
status = (sysfs_attr_data->pre_set)(client, udata, info);
if (status!=0)
printk(KERN_ERR "%s: pre_set function fails for %s attribute\n", __FUNCTION__, udata->aname);
dev_warn(&client->dev, "%s: pre_set function fails for %s attribute. ret %d\n", __FUNCTION__, udata->aname, status);
}
if (sysfs_attr_data->do_set != NULL)
{
status = (sysfs_attr_data->do_set)(client, udata, info);
if (status!=0)
printk(KERN_ERR "%s: do_set function fails for %s attribute\n", __FUNCTION__, udata->aname);
dev_warn(&client->dev, "%s: do_set function fails for %s attribute. ret %d\n", __FUNCTION__, udata->aname, status);

}
if (sysfs_attr_data->post_set != NULL)
{
status = (sysfs_attr_data->post_set)(client, udata, info);
if (status!=0)
printk(KERN_ERR "%s: post_set function fails for %s attribute\n", __FUNCTION__, udata->aname);
dev_warn(&client->dev, "%s: post_set function fails for %s attribute. ret %d\n", __FUNCTION__, udata->aname, status);
}

mutex_unlock(&info->update_lock);
Expand All @@ -104,20 +104,20 @@ int fan_update_attr(struct device *dev, struct fan_attr_info *info, FAN_DATA_ATT
{
status = (sysfs_attr_data->pre_get)(client, udata, info);
if (status!=0)
printk(KERN_ERR "%s: pre_get function fails for %s attribute\n", __FUNCTION__, udata->aname);
dev_warn(&client->dev, "%s: pre_get function fails for %s attribute. ret %d\n", __FUNCTION__, udata->aname, status);
}
if (sysfs_attr_data->do_get != NULL)
{
status = (sysfs_attr_data->do_get)(client, udata, info);
if (status!=0)
printk(KERN_ERR "%s: do_get function fails for %s attribute\n", __FUNCTION__, udata->aname);
dev_warn(&client->dev, "%s: do_get function fails for %s attribute. ret %d\n", __FUNCTION__, udata->aname, status);

}
if (sysfs_attr_data->post_get != NULL)
{
status = (sysfs_attr_data->post_get)(client, udata, info);
if (status!=0)
printk(KERN_ERR "%s: post_get function fails for %s attribute\n", __FUNCTION__, udata->aname);
dev_warn(&client->dev, "%s: post_get function fails for %s attribute.ret %d\n", __FUNCTION__, udata->aname, status);
}


Expand Down Expand Up @@ -346,7 +346,10 @@ int sonic_i2c_get_fan_present_default(void *client, FAN_DATA_ATTR *udata, void *
val = i2c_smbus_read_byte_data((struct i2c_client *)client, udata->offset);
}

painfo->val.intval = ((val & udata->mask) == udata->cmpval);
if (val < 0)
status = val;
else
painfo->val.intval = ((val & udata->mask) == udata->cmpval);


return status;
Expand All @@ -355,7 +358,7 @@ int sonic_i2c_get_fan_present_default(void *client, FAN_DATA_ATTR *udata, void *
int sonic_i2c_get_fan_rpm_default(void *client, FAN_DATA_ATTR *udata, void *info)
{
int status = 0;
uint32_t val = 0;
int val = 0;
struct fan_attr_info *painfo = (struct fan_attr_info *)info;

if (strcmp(udata->devtype, "cpld") == 0)
Expand All @@ -375,10 +378,15 @@ int sonic_i2c_get_fan_rpm_default(void *client, FAN_DATA_ATTR *udata, void *info
}
}

if (udata->is_divisor)
painfo->val.intval = udata->mult / (val >> 3);
if (val < 0)
status = val;
else
painfo->val.intval = udata->mult * val;
{
if (udata->is_divisor)
painfo->val.intval = udata->mult / (val >> 3);
else
painfo->val.intval = udata->mult * val;
}

return status;
}
Expand Down Expand Up @@ -471,7 +479,7 @@ int sonic_i2c_set_fan_pwm_default(struct i2c_client *client, FAN_DATA_ATTR *udat
int sonic_i2c_get_fan_pwm_default(void *client, FAN_DATA_ATTR *udata, void *info)
{
int status = 0;
uint32_t val = 0;
int val = 0;
struct fan_attr_info *painfo = (struct fan_attr_info *)info;

if (strcmp(udata->devtype, "cpld") == 0)
Expand All @@ -491,15 +499,20 @@ int sonic_i2c_get_fan_pwm_default(void *client, FAN_DATA_ATTR *udata, void *info
}
}

val = val & udata->mask;
painfo->val.intval = val;
if (val < 0)
status = val;
else
{
val = val & udata->mask;
painfo->val.intval = val;
}
return status;
}

int sonic_i2c_get_fan_fault_default(void *client, FAN_DATA_ATTR *udata, void *info)
{
int status = 0;
uint32_t val = 0;
int val = 0;
struct fan_attr_info *painfo = (struct fan_attr_info *)info;

/*Assuming fan fault to be denoted by 1 byte only*/
Expand All @@ -512,8 +525,10 @@ int sonic_i2c_get_fan_fault_default(void *client, FAN_DATA_ATTR *udata, void *in
val = i2c_smbus_read_byte_data((struct i2c_client *)client, udata->offset);
}

val = val & udata->mask;
painfo->val.intval = val;
if (val < 0)
status = val;
else
painfo->val.intval = ((val & udata->mask) == udata->cmpval);
return status;
}

Expand Down
2 changes: 1 addition & 1 deletion platform/pddf/i2c/modules/fan/driver/pddf_fan_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ static int pddf_fan_probe(struct i2c_client *client,
goto exit_free;
}

data->hwmon_dev = hwmon_device_register(&client->dev);
data->hwmon_dev = hwmon_device_register_with_info(&client->dev, client->name, NULL, NULL, NULL);
if (IS_ERR(data->hwmon_dev)) {
status = PTR_ERR(data->hwmon_dev);
goto exit_remove;
Expand Down
4 changes: 2 additions & 2 deletions platform/pddf/i2c/modules/fan/pddf_fan_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ static ssize_t do_device_operation(struct device *dev, struct device_attribute *
board_info = i2c_get_fan_board_info(fdata, cdata);

/* Populate the platform data for fan */
client_ptr = i2c_new_device(adapter, board_info);
client_ptr = i2c_new_client_device(adapter, board_info);

if(client_ptr != NULL)
if(!IS_ERR(client_ptr))
{
i2c_put_adapter(adapter);
pddf_dbg(FAN, KERN_ERR "Created a %s client: 0x%p\n", cdata->i2c_name, (void *)client_ptr);
Expand Down
2 changes: 1 addition & 1 deletion platform/pddf/i2c/modules/gpio/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

obj-m := pddf_gpio_module.o

CFLAGS_$(obj-m):= -I$(M)/modules/include
ccflags-y := -I$(M)/modules/include
Loading

0 comments on commit 93247a6

Please sign in to comment.