Commit a3bc508d authored by Dimitris Lampridis's avatar Dimitris Lampridis Committed by Vaibhav Gupta

Support Kernel version 5.10.65

Update APIs wherever needed to supposrt linux v5.10.65 as well.
Signed-off-by: 's avatarVaibhav Gupta <vaibhav.gupta@cern.ch>
parent 99ff49e8
...@@ -7,10 +7,15 @@ ...@@ -7,10 +7,15 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/memory.h> #include <linux/memory.h>
#include <linux/fmc.h> #include <linux/fmc.h>
#include <linux/slab.h>
#include <linux/ipmi/fru.h> #include <linux/ipmi/fru.h>
#include "fmc-internal.h" #include "fmc-internal.h"
#include "fmc-compat.h" #include "fmc-compat.h"
#if KERNEL_VERSION(4, 6, 0) <= LINUX_VERSION_CODE
#include <linux/nvmem-consumer.h>
#endif
#define FRU_EEPROM_NAME "fru_eeprom" #define FRU_EEPROM_NAME "fru_eeprom"
/** /**
...@@ -18,11 +23,14 @@ ...@@ -18,11 +23,14 @@
*/ */
#define FMC_EEPROM_TYPE_DEFAULT "24c02" #define FMC_EEPROM_TYPE_DEFAULT "24c02"
/** #if KERNEL_VERSION(4, 6, 0) <= LINUX_VERSION_CODE
* Setup function for the AT24C02 EEPROM. What we need to do here is to const struct property_entry at24_24c02[AT24_NUM_PROPERTIES] = {
* quickly validate the EEPROM content. The EEPROM should contain a valid PROPERTY_ENTRY_U32("size", 256),
* FRU. PROPERTY_ENTRY_U32("pagesize", 8),
*/ PROPERTY_ENTRY_U32("address-width", 16),
{ }
};
#else
static void fmc_slot_eeprom_setup(struct memory_accessor *macc, void *context) static void fmc_slot_eeprom_setup(struct memory_accessor *macc, void *context)
{ {
struct fmc_slot *slot = context; struct fmc_slot *slot = context;
...@@ -39,9 +47,10 @@ static const struct at24_platform_data at24_24c02 = { ...@@ -39,9 +47,10 @@ static const struct at24_platform_data at24_24c02 = {
.flags = 0, .flags = 0,
.setup = fmc_slot_eeprom_setup, .setup = fmc_slot_eeprom_setup,
}; };
#endif /* KERNEL_VERSION(4, 6, 0) <= LINUX_VERSION_CODE */
/** /**
* Initialize I2C EEPROM info with standad values * Initialize I2C EEPROM info with standard values
*/ */
static void fmc_slot_eeprom_init(struct fmc_slot *slot, static void fmc_slot_eeprom_init(struct fmc_slot *slot,
struct i2c_board_info *info, struct i2c_board_info *info,
...@@ -49,7 +58,11 @@ static void fmc_slot_eeprom_init(struct fmc_slot *slot, ...@@ -49,7 +58,11 @@ static void fmc_slot_eeprom_init(struct fmc_slot *slot,
{ {
strncpy(info->type, name, I2C_NAME_SIZE - 1); strncpy(info->type, name, I2C_NAME_SIZE - 1);
info->addr = FMC_EEPROM_ADDR_SPACE; info->addr = FMC_EEPROM_ADDR_SPACE;
#if KERNEL_VERSION(4, 6, 0) <= LINUX_VERSION_CODE
info->properties = slot->at24_data;
#else
info->platform_data = &slot->at24_data; info->platform_data = &slot->at24_data;
#endif
} }
static void fmc_slot_eeprom_init_default(struct fmc_slot *slot, static void fmc_slot_eeprom_init_default(struct fmc_slot *slot,
...@@ -57,8 +70,12 @@ static void fmc_slot_eeprom_init_default(struct fmc_slot *slot, ...@@ -57,8 +70,12 @@ static void fmc_slot_eeprom_init_default(struct fmc_slot *slot,
{ {
memset(info, 0, sizeof(*info)); memset(info, 0, sizeof(*info));
fmc_slot_eeprom_init(slot, info, FMC_EEPROM_TYPE_DEFAULT); fmc_slot_eeprom_init(slot, info, FMC_EEPROM_TYPE_DEFAULT);
#if KERNEL_VERSION(4, 6, 0) > LINUX_VERSION_CODE
memcpy(&slot->at24_data, &at24_24c02, sizeof(slot->at24_data)); memcpy(&slot->at24_data, &at24_24c02, sizeof(slot->at24_data));
slot->at24_data.context = slot; slot->at24_data.context = slot;
#else
memcpy(slot->at24_data, &at24_24c02, sizeof(slot->at24_data));
#endif
} }
/** /**
...@@ -71,13 +88,41 @@ static void fmc_slot_eeprom_init_default(struct fmc_slot *slot, ...@@ -71,13 +88,41 @@ static void fmc_slot_eeprom_init_default(struct fmc_slot *slot,
ssize_t fmc_slot_eeprom_read(struct fmc_slot *slot, ssize_t fmc_slot_eeprom_read(struct fmc_slot *slot,
void *buf, off_t offset, size_t count) void *buf, off_t offset, size_t count)
{ {
int err = 0;
#if KERNEL_VERSION(4, 6, 0) <= LINUX_VERSION_CODE
int idx;
size_t len;
struct nvmem_device *nvmem;
char *nvmem_name;
/*
* TODO Check if index can be anything else than zero and,
* if yes, how to get the proper value.
*/
idx = 0;
len = strlen(dev_name(&slot->eeprom->dev)) + 2;
nvmem_name = kzalloc(len, GFP_KERNEL);
if (nvmem_name) {
snprintf(nvmem_name, len, "%s%d",
dev_name(&slot->eeprom->dev), idx);
nvmem = nvmem_device_get(&slot->dev, nvmem_name);
if (nvmem) {
err = nvmem_device_read(nvmem, offset, count, buf);
#if KERNEL_VERSION(5, 1, 0) <= LINUX_VERSION_CODE
nvmem_device_put(nvmem);
#endif
}
kfree(nvmem_name);
}
#else
/* /*
* TODO if we export this function, do we have to lock it when we * TODO if we export this function, do we have to lock it when we
* use it? Think about it * use it? Think about it
*/ */
if (!slot->macc || !slot->macc->read) if (!slot->macc || !slot->macc->read)
return -ENODEV; return -ENODEV;
return slot->macc->read(slot->macc, buf, offset, count); err = slot->macc->read(slot->macc, buf, offset, count);
#endif
return err;
} }
EXPORT_SYMBOL(fmc_slot_eeprom_read); EXPORT_SYMBOL(fmc_slot_eeprom_read);
...@@ -162,7 +207,9 @@ void fmc_slot_eeprom_del(struct fmc_slot *slot) ...@@ -162,7 +207,9 @@ void fmc_slot_eeprom_del(struct fmc_slot *slot)
sysfs_remove_link(&slot->dev.kobj, FRU_EEPROM_NAME); sysfs_remove_link(&slot->dev.kobj, FRU_EEPROM_NAME);
i2c_unregister_device(slot->eeprom); i2c_unregister_device(slot->eeprom);
slot->eeprom = NULL; slot->eeprom = NULL;
#if KERNEL_VERSION(4, 6, 0) > LINUX_VERSION_CODE
slot->macc = NULL; slot->macc = NULL;
#endif
} }
/** /**
...@@ -207,19 +254,25 @@ int fmc_slot_eeprom_type_set(struct fmc_slot *slot, const char *type) ...@@ -207,19 +254,25 @@ int fmc_slot_eeprom_type_set(struct fmc_slot *slot, const char *type)
memset(&i2c_info, 0, sizeof(i2c_info)); memset(&i2c_info, 0, sizeof(i2c_info));
#if KERNEL_VERSION(4, 6, 0) > LINUX_VERSION_CODE
memset(&slot->at24_data, 0, sizeof(slot->at24_data)); memset(&slot->at24_data, 0, sizeof(slot->at24_data));
#else
memset(slot->at24_data, 0, sizeof(slot->at24_data));
#endif
len = (len * 1024) / 8; len = (len * 1024) / 8;
/* /*
* For sizes between 1K and 16K the EEPROM uses part of the device * For sizes between 1K and 16K the EEPROM uses part of the device
* address as internal memory address * address as internal memory address
*/ */
if (len > 4096) /* 32K 4KiB */ if (len > 131072) /* 1024K 128KiB */
slot->at24_data.flags = AT24_FLAG_ADDR16;
else if (len > 131072) /* 1024K 128KiB */
return -EINVAL; return -EINVAL;
fmc_slot_eeprom_init(slot, &i2c_info, type); fmc_slot_eeprom_init(slot, &i2c_info, type);
#if KERNEL_VERSION(4, 6, 0) > LINUX_VERSION_CODE
if (len > 4096) /* 32K 4KiB */
slot->at24_data.flags = AT24_FLAG_ADDR16;
slot->at24_data.byte_len = len; slot->at24_data.byte_len = len;
slot->at24_data.page_size = 1; /* 1Byte page to play safe */ slot->at24_data.page_size = 1; /* 1Byte page to play safe */
slot->at24_data.setup = fmc_slot_eeprom_setup; slot->at24_data.setup = fmc_slot_eeprom_setup;
...@@ -229,7 +282,15 @@ int fmc_slot_eeprom_type_set(struct fmc_slot *slot, const char *type) ...@@ -229,7 +282,15 @@ int fmc_slot_eeprom_type_set(struct fmc_slot *slot, const char *type)
i2c_info.type, i2c_info.addr, i2c_info.type, i2c_info.addr,
slot->at24_data.byte_len, slot->at24_data.page_size, slot->at24_data.byte_len, slot->at24_data.page_size,
slot->at24_data.flags); slot->at24_data.flags);
#else
slot->at24_data[0] = PROPERTY_ENTRY_U32("size", len);
slot->at24_data[1] = PROPERTY_ENTRY_U32("pagesize", 1);
if (len > 4096) /* 32K 4KiB */
slot->at24_data[2] = PROPERTY_ENTRY_U32("address-width", 16);
dev_dbg(&slot->dev, "%s 0x%x %d\n",
i2c_info.type, i2c_info.addr, len);
#endif
return fmc_slot_eeprom_replace(slot, &i2c_info); return fmc_slot_eeprom_replace(slot, &i2c_info);
} }
EXPORT_SYMBOL(fmc_slot_eeprom_type_set); EXPORT_SYMBOL(fmc_slot_eeprom_type_set);
......
...@@ -5,12 +5,6 @@ ...@@ -5,12 +5,6 @@
*/ */
#include <linux/version.h> #include <linux/version.h>
#if KERNEL_VERSION(3, 11, 0) > LINUX_VERSION_CODE
/*
* On kernel 3.11 and greater this is included
*/
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/ipmi/fru.h> #include <linux/ipmi/fru.h>
...@@ -77,5 +71,3 @@ char *fru_get_part_number(struct fru_common_header *header) ...@@ -77,5 +71,3 @@ char *fru_get_part_number(struct fru_common_header *header)
return __fru_alloc_get_tl(header, 3); return __fru_alloc_get_tl(header, 3);
} }
EXPORT_SYMBOL(fru_get_part_number); EXPORT_SYMBOL(fru_get_part_number);
#endif
...@@ -11,13 +11,13 @@ ...@@ -11,13 +11,13 @@
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/version.h> #include <linux/version.h>
#if KERNEL_VERSION(5, 1, 0) > LINUX_VERSION_CODE
#if KERNEL_VERSION(3, 10, 0) <= LINUX_VERSION_CODE #if KERNEL_VERSION(3, 10, 0) <= LINUX_VERSION_CODE
#include <linux/platform_data/at24.h> #include <linux/platform_data/at24.h>
#else #else
#include <linux/i2c/at24.h> #include <linux/i2c/at24.h>
#endif #endif
#endif
#ifndef _LINUX_FMC_H #ifndef _LINUX_FMC_H
#define _LINUX_FMC_H #define _LINUX_FMC_H
...@@ -86,8 +86,13 @@ struct fmc_slot { ...@@ -86,8 +86,13 @@ struct fmc_slot {
struct i2c_client *eeprom; struct i2c_client *eeprom;
#if KERNEL_VERSION(4, 6, 0) <= LINUX_VERSION_CODE
#define AT24_NUM_PROPERTIES 4
struct property_entry at24_data[AT24_NUM_PROPERTIES];
#else
struct memory_accessor *macc; struct memory_accessor *macc;
struct at24_platform_data at24_data; struct at24_platform_data at24_data;
#endif
}; };
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment