Commit 9baa4885 authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller

nfp: remove automatic caching of HWInfo

Make callers take care of managing life time of HWInfo.
Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent af4fa7ea
...@@ -80,7 +80,7 @@ int nfp_app_nic_vnic_init(struct nfp_app *app, struct nfp_net *nn, ...@@ -80,7 +80,7 @@ int nfp_app_nic_vnic_init(struct nfp_app *app, struct nfp_net *nn,
if (err) if (err)
return err < 0 ? err : 0; return err < 0 ? err : 0;
nfp_net_get_mac_addr(nn, app->cpp, id); nfp_net_get_mac_addr(app->pf, nn, id);
return 0; return 0;
} }
...@@ -170,7 +170,7 @@ nfp_net_fw_find(struct pci_dev *pdev, struct nfp_pf *pf) ...@@ -170,7 +170,7 @@ nfp_net_fw_find(struct pci_dev *pdev, struct nfp_pf *pf)
return NULL; return NULL;
} }
fw_model = nfp_hwinfo_lookup(pf->cpp, "assembly.partno"); fw_model = nfp_hwinfo_lookup(pf->hwinfo, "assembly.partno");
if (!fw_model) { if (!fw_model) {
dev_err(&pdev->dev, "Error: can't read part number\n"); dev_err(&pdev->dev, "Error: can't read part number\n");
return NULL; return NULL;
...@@ -358,16 +358,18 @@ static int nfp_pci_probe(struct pci_dev *pdev, ...@@ -358,16 +358,18 @@ static int nfp_pci_probe(struct pci_dev *pdev,
goto err_disable_msix; goto err_disable_msix;
} }
pf->hwinfo = nfp_hwinfo_read(pf->cpp);
dev_info(&pdev->dev, "Assembly: %s%s%s-%s CPLD: %s\n", dev_info(&pdev->dev, "Assembly: %s%s%s-%s CPLD: %s\n",
nfp_hwinfo_lookup(pf->cpp, "assembly.vendor"), nfp_hwinfo_lookup(pf->hwinfo, "assembly.vendor"),
nfp_hwinfo_lookup(pf->cpp, "assembly.partno"), nfp_hwinfo_lookup(pf->hwinfo, "assembly.partno"),
nfp_hwinfo_lookup(pf->cpp, "assembly.serial"), nfp_hwinfo_lookup(pf->hwinfo, "assembly.serial"),
nfp_hwinfo_lookup(pf->cpp, "assembly.revision"), nfp_hwinfo_lookup(pf->hwinfo, "assembly.revision"),
nfp_hwinfo_lookup(pf->cpp, "cpld.version")); nfp_hwinfo_lookup(pf->hwinfo, "cpld.version"));
err = devlink_register(devlink, &pdev->dev); err = devlink_register(devlink, &pdev->dev);
if (err) if (err)
goto err_cpp_free; goto err_hwinfo_free;
err = nfp_nsp_init(pdev, pf); err = nfp_nsp_init(pdev, pf);
if (err) if (err)
...@@ -403,7 +405,8 @@ static int nfp_pci_probe(struct pci_dev *pdev, ...@@ -403,7 +405,8 @@ static int nfp_pci_probe(struct pci_dev *pdev,
kfree(pf->nspi); kfree(pf->nspi);
err_devlink_unreg: err_devlink_unreg:
devlink_unregister(devlink); devlink_unregister(devlink);
err_cpp_free: err_hwinfo_free:
kfree(pf->hwinfo);
nfp_cpp_free(pf->cpp); nfp_cpp_free(pf->cpp);
err_disable_msix: err_disable_msix:
pci_set_drvdata(pdev, NULL); pci_set_drvdata(pdev, NULL);
...@@ -438,6 +441,7 @@ static void nfp_pci_remove(struct pci_dev *pdev) ...@@ -438,6 +441,7 @@ static void nfp_pci_remove(struct pci_dev *pdev)
nfp_fw_unload(pf); nfp_fw_unload(pf);
pci_set_drvdata(pdev, NULL); pci_set_drvdata(pdev, NULL);
kfree(pf->hwinfo);
nfp_cpp_free(pf->cpp); nfp_cpp_free(pf->cpp);
kfree(pf->eth_tbl); kfree(pf->eth_tbl);
......
...@@ -54,6 +54,7 @@ struct pci_dev; ...@@ -54,6 +54,7 @@ struct pci_dev;
struct nfp_cpp; struct nfp_cpp;
struct nfp_cpp_area; struct nfp_cpp_area;
struct nfp_eth_table; struct nfp_eth_table;
struct nfp_hwinfo;
struct nfp_net; struct nfp_net;
struct nfp_nsp_identify; struct nfp_nsp_identify;
struct nfp_rtsym_table; struct nfp_rtsym_table;
...@@ -72,6 +73,7 @@ struct nfp_rtsym_table; ...@@ -72,6 +73,7 @@ struct nfp_rtsym_table;
* @fw_loaded: Is the firmware loaded? * @fw_loaded: Is the firmware loaded?
* @ctrl_vnic: Pointer to the control vNIC if available * @ctrl_vnic: Pointer to the control vNIC if available
* @rtbl: RTsym table * @rtbl: RTsym table
* @hwinfo: HWInfo table
* @eth_tbl: NSP ETH table * @eth_tbl: NSP ETH table
* @nspi: NSP identification info * @nspi: NSP identification info
* @hwmon_dev: pointer to hwmon device * @hwmon_dev: pointer to hwmon device
...@@ -104,6 +106,7 @@ struct nfp_pf { ...@@ -104,6 +106,7 @@ struct nfp_pf {
struct nfp_net *ctrl_vnic; struct nfp_net *ctrl_vnic;
struct nfp_rtsym_table *rtbl; struct nfp_rtsym_table *rtbl;
struct nfp_hwinfo *hwinfo;
struct nfp_eth_table *eth_tbl; struct nfp_eth_table *eth_tbl;
struct nfp_nsp_identify *nspi; struct nfp_nsp_identify *nspi;
...@@ -133,7 +136,7 @@ void nfp_hwmon_unregister(struct nfp_pf *pf); ...@@ -133,7 +136,7 @@ void nfp_hwmon_unregister(struct nfp_pf *pf);
struct nfp_eth_table_port * struct nfp_eth_table_port *
nfp_net_find_port(struct nfp_eth_table *eth_tbl, unsigned int id); nfp_net_find_port(struct nfp_eth_table *eth_tbl, unsigned int id);
void void
nfp_net_get_mac_addr(struct nfp_net *nn, struct nfp_cpp *cpp, unsigned int id); nfp_net_get_mac_addr(struct nfp_pf *pf, struct nfp_net *nn, unsigned int id);
bool nfp_ctrl_tx(struct nfp_net *nn, struct sk_buff *skb); bool nfp_ctrl_tx(struct nfp_net *nn, struct sk_buff *skb);
......
...@@ -63,13 +63,13 @@ ...@@ -63,13 +63,13 @@
#define NFP_PF_CSR_SLICE_SIZE (32 * 1024) #define NFP_PF_CSR_SLICE_SIZE (32 * 1024)
static int nfp_is_ready(struct nfp_cpp *cpp) static int nfp_is_ready(struct nfp_pf *pf)
{ {
const char *cp; const char *cp;
long state; long state;
int err; int err;
cp = nfp_hwinfo_lookup(cpp, "board.state"); cp = nfp_hwinfo_lookup(pf->hwinfo, "board.state");
if (!cp) if (!cp)
return 0; return 0;
...@@ -134,15 +134,15 @@ static u8 __iomem *nfp_net_map_area(struct nfp_cpp *cpp, ...@@ -134,15 +134,15 @@ static u8 __iomem *nfp_net_map_area(struct nfp_cpp *cpp,
/** /**
* nfp_net_get_mac_addr() - Get the MAC address. * nfp_net_get_mac_addr() - Get the MAC address.
* @pf: NFP PF handle
* @nn: NFP Network structure * @nn: NFP Network structure
* @cpp: NFP CPP handle
* @id: NFP port id * @id: NFP port id
* *
* First try to get the MAC address from NSP ETH table. If that * First try to get the MAC address from NSP ETH table. If that
* fails try HWInfo. As a last resort generate a random address. * fails try HWInfo. As a last resort generate a random address.
*/ */
void void
nfp_net_get_mac_addr(struct nfp_net *nn, struct nfp_cpp *cpp, unsigned int id) nfp_net_get_mac_addr(struct nfp_pf *pf, struct nfp_net *nn, unsigned int id)
{ {
struct nfp_eth_table_port *eth_port; struct nfp_eth_table_port *eth_port;
struct nfp_net_dp *dp = &nn->dp; struct nfp_net_dp *dp = &nn->dp;
...@@ -159,7 +159,7 @@ nfp_net_get_mac_addr(struct nfp_net *nn, struct nfp_cpp *cpp, unsigned int id) ...@@ -159,7 +159,7 @@ nfp_net_get_mac_addr(struct nfp_net *nn, struct nfp_cpp *cpp, unsigned int id)
snprintf(name, sizeof(name), "eth%d.mac", id); snprintf(name, sizeof(name), "eth%d.mac", id);
mac_str = nfp_hwinfo_lookup(cpp, name); mac_str = nfp_hwinfo_lookup(pf->hwinfo, name);
if (!mac_str) { if (!mac_str) {
dev_warn(dp->dev, "Can't lookup MAC address. Generate\n"); dev_warn(dp->dev, "Can't lookup MAC address. Generate\n");
eth_hw_addr_random(dp->netdev); eth_hw_addr_random(dp->netdev);
...@@ -713,7 +713,7 @@ int nfp_net_pci_probe(struct nfp_pf *pf) ...@@ -713,7 +713,7 @@ int nfp_net_pci_probe(struct nfp_pf *pf)
INIT_WORK(&pf->port_refresh_work, nfp_net_refresh_vnics); INIT_WORK(&pf->port_refresh_work, nfp_net_refresh_vnics);
/* Verify that the board has completed initialization */ /* Verify that the board has completed initialization */
if (!nfp_is_ready(pf->cpp)) { if (!nfp_is_ready(pf)) {
nfp_err(pf->cpp, "NFP is not ready for NIC operation.\n"); nfp_err(pf->cpp, "NFP is not ready for NIC operation.\n");
return -EINVAL; return -EINVAL;
} }
......
...@@ -46,7 +46,9 @@ ...@@ -46,7 +46,9 @@
/* Implemented in nfp_hwinfo.c */ /* Implemented in nfp_hwinfo.c */
const char *nfp_hwinfo_lookup(struct nfp_cpp *cpp, const char *lookup); struct nfp_hwinfo;
struct nfp_hwinfo *nfp_hwinfo_read(struct nfp_cpp *cpp);
const char *nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup);
/* Implemented in nfp_nsp.c, low level functions */ /* Implemented in nfp_nsp.c, low level functions */
......
...@@ -222,9 +222,6 @@ u32 nfp_cpp_model(struct nfp_cpp *cpp); ...@@ -222,9 +222,6 @@ u32 nfp_cpp_model(struct nfp_cpp *cpp);
u16 nfp_cpp_interface(struct nfp_cpp *cpp); u16 nfp_cpp_interface(struct nfp_cpp *cpp);
int nfp_cpp_serial(struct nfp_cpp *cpp, const u8 **serial); int nfp_cpp_serial(struct nfp_cpp *cpp, const u8 **serial);
void *nfp_hwinfo_cache(struct nfp_cpp *cpp);
void nfp_hwinfo_cache_set(struct nfp_cpp *cpp, void *val);
struct nfp_cpp_area *nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, struct nfp_cpp_area *nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp,
u32 cpp_id, u32 cpp_id,
const char *name, const char *name,
......
...@@ -76,9 +76,6 @@ struct nfp_cpp_resource { ...@@ -76,9 +76,6 @@ struct nfp_cpp_resource {
* @serial: chip serial number * @serial: chip serial number
* @imb_cat_table: CPP Mapping Table * @imb_cat_table: CPP Mapping Table
* *
* Following fields can be used only in probe() or with rtnl held:
* @hwinfo: HWInfo database fetched from the device
*
* Following fields use explicit locking: * Following fields use explicit locking:
* @resource_list: NFP CPP resource list * @resource_list: NFP CPP resource list
* @resource_lock: protects @resource_list * @resource_lock: protects @resource_list
...@@ -106,8 +103,6 @@ struct nfp_cpp { ...@@ -106,8 +103,6 @@ struct nfp_cpp {
struct mutex area_cache_mutex; struct mutex area_cache_mutex;
struct list_head area_cache_list; struct list_head area_cache_list;
void *hwinfo;
}; };
/* Element of the area_cache_list */ /* Element of the area_cache_list */
...@@ -231,8 +226,6 @@ void nfp_cpp_free(struct nfp_cpp *cpp) ...@@ -231,8 +226,6 @@ void nfp_cpp_free(struct nfp_cpp *cpp)
if (cpp->op->free) if (cpp->op->free)
cpp->op->free(cpp); cpp->op->free(cpp);
kfree(cpp->hwinfo);
device_unregister(&cpp->dev); device_unregister(&cpp->dev);
kfree(cpp); kfree(cpp);
...@@ -273,16 +266,6 @@ int nfp_cpp_serial(struct nfp_cpp *cpp, const u8 **serial) ...@@ -273,16 +266,6 @@ int nfp_cpp_serial(struct nfp_cpp *cpp, const u8 **serial)
return sizeof(cpp->serial); return sizeof(cpp->serial);
} }
void *nfp_hwinfo_cache(struct nfp_cpp *cpp)
{
return cpp->hwinfo;
}
void nfp_hwinfo_cache_set(struct nfp_cpp *cpp, void *val)
{
cpp->hwinfo = val;
}
/** /**
* nfp_cpp_area_alloc_with_name() - allocate a new CPP area * nfp_cpp_area_alloc_with_name() - allocate a new CPP area
* @cpp: CPP device handle * @cpp: CPP device handle
......
...@@ -178,7 +178,8 @@ hwinfo_db_validate(struct nfp_cpp *cpp, struct nfp_hwinfo *db, u32 len) ...@@ -178,7 +178,8 @@ hwinfo_db_validate(struct nfp_cpp *cpp, struct nfp_hwinfo *db, u32 len)
return hwinfo_db_walk(cpp, db, size); return hwinfo_db_walk(cpp, db, size);
} }
static int hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size) static struct nfp_hwinfo *
hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size)
{ {
struct nfp_hwinfo *header; struct nfp_hwinfo *header;
struct nfp_resource *res; struct nfp_resource *res;
...@@ -196,7 +197,7 @@ static int hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size) ...@@ -196,7 +197,7 @@ static int hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size)
nfp_resource_release(res); nfp_resource_release(res);
if (*cpp_size < HWINFO_SIZE_MIN) if (*cpp_size < HWINFO_SIZE_MIN)
return -ENOENT; return NULL;
} else if (PTR_ERR(res) == -ENOENT) { } else if (PTR_ERR(res) == -ENOENT) {
/* Try getting the HWInfo table from the 'classic' location */ /* Try getting the HWInfo table from the 'classic' location */
cpp_id = NFP_CPP_ISLAND_ID(NFP_CPP_TARGET_MU, cpp_id = NFP_CPP_ISLAND_ID(NFP_CPP_TARGET_MU,
...@@ -204,101 +205,86 @@ static int hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size) ...@@ -204,101 +205,86 @@ static int hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size)
cpp_addr = 0x30000; cpp_addr = 0x30000;
*cpp_size = 0x0e000; *cpp_size = 0x0e000;
} else { } else {
return PTR_ERR(res); return NULL;
} }
db = kmalloc(*cpp_size + 1, GFP_KERNEL); db = kmalloc(*cpp_size + 1, GFP_KERNEL);
if (!db) if (!db)
return -ENOMEM; return NULL;
err = nfp_cpp_read(cpp, cpp_id, cpp_addr, db, *cpp_size); err = nfp_cpp_read(cpp, cpp_id, cpp_addr, db, *cpp_size);
if (err != *cpp_size) { if (err != *cpp_size)
kfree(db); goto exit_free;
return err < 0 ? err : -EIO;
}
header = (void *)db; header = (void *)db;
if (nfp_hwinfo_is_updating(header)) { if (nfp_hwinfo_is_updating(header))
kfree(db); goto exit_free;
return -EBUSY;
}
if (le32_to_cpu(header->version) != NFP_HWINFO_VERSION_2) { if (le32_to_cpu(header->version) != NFP_HWINFO_VERSION_2) {
nfp_err(cpp, "Unknown HWInfo version: 0x%08x\n", nfp_err(cpp, "Unknown HWInfo version: 0x%08x\n",
le32_to_cpu(header->version)); le32_to_cpu(header->version));
kfree(db); goto exit_free;
return -EINVAL;
} }
/* NULL-terminate for safety */ /* NULL-terminate for safety */
db[*cpp_size] = '\0'; db[*cpp_size] = '\0';
nfp_hwinfo_cache_set(cpp, db); return (void *)db;
exit_free:
return 0; kfree(db);
return NULL;
} }
static int hwinfo_fetch(struct nfp_cpp *cpp, size_t *hwdb_size) static struct nfp_hwinfo *hwinfo_fetch(struct nfp_cpp *cpp, size_t *hwdb_size)
{ {
const unsigned long wait_until = jiffies + HWINFO_WAIT * HZ; const unsigned long wait_until = jiffies + HWINFO_WAIT * HZ;
struct nfp_hwinfo *db;
int err; int err;
for (;;) { for (;;) {
const unsigned long start_time = jiffies; const unsigned long start_time = jiffies;
err = hwinfo_try_fetch(cpp, hwdb_size); db = hwinfo_try_fetch(cpp, hwdb_size);
if (!err) if (db)
return 0; return db;
err = msleep_interruptible(100); err = msleep_interruptible(100);
if (err || time_after(start_time, wait_until)) { if (err || time_after(start_time, wait_until)) {
nfp_err(cpp, "NFP access error\n"); nfp_err(cpp, "NFP access error\n");
return -EIO; return NULL;
} }
} }
} }
static int nfp_hwinfo_load(struct nfp_cpp *cpp) struct nfp_hwinfo *nfp_hwinfo_read(struct nfp_cpp *cpp)
{ {
struct nfp_hwinfo *db; struct nfp_hwinfo *db;
size_t hwdb_size = 0; size_t hwdb_size = 0;
int err; int err;
err = hwinfo_fetch(cpp, &hwdb_size); db = hwinfo_fetch(cpp, &hwdb_size);
if (err) if (!db)
return err; return NULL;
db = nfp_hwinfo_cache(cpp);
err = hwinfo_db_validate(cpp, db, hwdb_size); err = hwinfo_db_validate(cpp, db, hwdb_size);
if (err) { if (err) {
kfree(db); kfree(db);
nfp_hwinfo_cache_set(cpp, NULL); return NULL;
return err;
} }
return 0; return db;
} }
/** /**
* nfp_hwinfo_lookup() - Find a value in the HWInfo table by name * nfp_hwinfo_lookup() - Find a value in the HWInfo table by name
* @cpp: NFP CPP handle * @hwinfo: NFP HWinfo table
* @lookup: HWInfo name to search for * @lookup: HWInfo name to search for
* *
* Return: Value of the HWInfo name, or NULL * Return: Value of the HWInfo name, or NULL
*/ */
const char *nfp_hwinfo_lookup(struct nfp_cpp *cpp, const char *lookup) const char *nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup)
{ {
const char *key, *val, *end; const char *key, *val, *end;
struct nfp_hwinfo *hwinfo;
int err;
hwinfo = nfp_hwinfo_cache(cpp);
if (!hwinfo) {
err = nfp_hwinfo_load(cpp);
if (err)
return NULL;
hwinfo = nfp_hwinfo_cache(cpp);
}
if (!hwinfo || !lookup) if (!hwinfo || !lookup)
return NULL; return NULL;
......
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