Skip to content

Commit

Permalink
drivers: [FEATURE] allow card serial number to be string
Browse files Browse the repository at this point in the history
  • Loading branch information
martinspinler committed May 30, 2024
1 parent 574a844 commit 4b65672
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
6 changes: 5 additions & 1 deletion drivers/kernel/drivers/nfb/boot/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,11 @@ int nfb_boot_attach(struct nfb_device *nfb, void **priv)

fdt_offset = fdt_path_offset(nfb->fdt, "/board");
fdt_setprop_string(nfb->fdt, fdt_offset, "board-name", nfb->pci_name);
fdt_setprop_u32(nfb->fdt, fdt_offset, "serial-number", nfb->serial);
if (nfb->serial_str) {
fdt_setprop_string(nfb->fdt, fdt_offset, "serial-number-string", nfb->serial_str);
} else {
fdt_setprop_string(nfb->fdt, fdt_offset, "serial-number", nfb->serial);
}

dev_info(&nfb->pci->dev, "nfb_boot: Attached successfully\n");

Expand Down
11 changes: 10 additions & 1 deletion drivers/kernel/drivers/nfb/boot/nfb-pmci.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ static struct regmap_config m10bmc_pmci_regmap_config = {

int nfb_pmci_attach(struct nfb_boot *boot)
{
char * pmci_bom_info, *snc;
char * pmci_bom_info, *snc, *snc_end;

struct nfb_device *nfb = boot->nfb;
struct pmci_device *pmci;
Expand Down Expand Up @@ -362,6 +362,15 @@ int nfb_pmci_attach(struct nfb_boot *boot)
if ((snc = strstr(pmci_bom_info, "\nSN,"))) {
if (sscanf(snc, "\nSN,%d\n", &sn) == 1) {
boot->nfb->serial = sn;
} else {
snc_end = strstr(snc+1, "\n");
if (snc_end) {
snc_end[0] = 0;
snc += strlen("\nSN,");
while (isspace(snc[0]))
snc += 1;
boot->nfb->serial_str = kstrdup(snc, GFP_KERNEL);
}
}
}
kfree(pmci_bom_info);
Expand Down
3 changes: 3 additions & 0 deletions drivers/kernel/drivers/nfb/char.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ struct spinlock open_lock;
static ssize_t nfb_char_get_serial(struct device *dev, struct device_attribute *attr, char *buf)
{
struct nfb_device *nfb = dev_get_drvdata(dev);
if (nfb->serial_str) {
return scnprintf(buf, PAGE_SIZE, "%s\n", nfb->serial_str);
}
return scnprintf(buf, PAGE_SIZE, "%lld\n", nfb->serial);
}
static ssize_t nfb_char_get_cardname(struct device *dev, struct device_attribute *attr, char *buf)
Expand Down
2 changes: 2 additions & 0 deletions drivers/kernel/drivers/nfb/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ struct nfb_device *nfb_create(void)
*/
void nfb_destroy(struct nfb_device *nfb)
{
if (nfb->serial_str)
kfree(nfb->serial_str);
kfree(nfb);
}

Expand Down
1 change: 1 addition & 0 deletions drivers/kernel/drivers/nfb/nfb.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ struct nfb_lock_item {
struct nfb_device {
struct pci_dev *pci; /* Associated PCI device (master) */
int minor; /* Minor number assigned to this device (used for X in /dev/nfbX) */
const char *serial_str; /* String version of serial number. If is NULL, the 'serial' member should be used. */
uint64_t serial; /* Card serial number */
uint64_t dsn; /* FPGA chip unique identifier */
enum nfb_device_status status;
Expand Down

0 comments on commit 4b65672

Please sign in to comment.