Skip to content

Commit 9baa488

Browse files
Jakub Kicinskidavem330
authored andcommitted
nfp: remove automatic caching of HWInfo
Make callers take care of managing life time of HWInfo. Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent af4fa7e commit 9baa488

File tree

8 files changed

+54
-79
lines changed

8 files changed

+54
-79
lines changed

drivers/net/ethernet/netronome/nfp/nfp_app_nic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ int nfp_app_nic_vnic_init(struct nfp_app *app, struct nfp_net *nn,
8080
if (err)
8181
return err < 0 ? err : 0;
8282

83-
nfp_net_get_mac_addr(nn, app->cpp, id);
83+
nfp_net_get_mac_addr(app->pf, nn, id);
8484

8585
return 0;
8686
}

drivers/net/ethernet/netronome/nfp/nfp_main.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ nfp_net_fw_find(struct pci_dev *pdev, struct nfp_pf *pf)
170170
return NULL;
171171
}
172172

173-
fw_model = nfp_hwinfo_lookup(pf->cpp, "assembly.partno");
173+
fw_model = nfp_hwinfo_lookup(pf->hwinfo, "assembly.partno");
174174
if (!fw_model) {
175175
dev_err(&pdev->dev, "Error: can't read part number\n");
176176
return NULL;
@@ -358,16 +358,18 @@ static int nfp_pci_probe(struct pci_dev *pdev,
358358
goto err_disable_msix;
359359
}
360360

361+
pf->hwinfo = nfp_hwinfo_read(pf->cpp);
362+
361363
dev_info(&pdev->dev, "Assembly: %s%s%s-%s CPLD: %s\n",
362-
nfp_hwinfo_lookup(pf->cpp, "assembly.vendor"),
363-
nfp_hwinfo_lookup(pf->cpp, "assembly.partno"),
364-
nfp_hwinfo_lookup(pf->cpp, "assembly.serial"),
365-
nfp_hwinfo_lookup(pf->cpp, "assembly.revision"),
366-
nfp_hwinfo_lookup(pf->cpp, "cpld.version"));
364+
nfp_hwinfo_lookup(pf->hwinfo, "assembly.vendor"),
365+
nfp_hwinfo_lookup(pf->hwinfo, "assembly.partno"),
366+
nfp_hwinfo_lookup(pf->hwinfo, "assembly.serial"),
367+
nfp_hwinfo_lookup(pf->hwinfo, "assembly.revision"),
368+
nfp_hwinfo_lookup(pf->hwinfo, "cpld.version"));
367369

368370
err = devlink_register(devlink, &pdev->dev);
369371
if (err)
370-
goto err_cpp_free;
372+
goto err_hwinfo_free;
371373

372374
err = nfp_nsp_init(pdev, pf);
373375
if (err)
@@ -403,7 +405,8 @@ static int nfp_pci_probe(struct pci_dev *pdev,
403405
kfree(pf->nspi);
404406
err_devlink_unreg:
405407
devlink_unregister(devlink);
406-
err_cpp_free:
408+
err_hwinfo_free:
409+
kfree(pf->hwinfo);
407410
nfp_cpp_free(pf->cpp);
408411
err_disable_msix:
409412
pci_set_drvdata(pdev, NULL);
@@ -438,6 +441,7 @@ static void nfp_pci_remove(struct pci_dev *pdev)
438441
nfp_fw_unload(pf);
439442

440443
pci_set_drvdata(pdev, NULL);
444+
kfree(pf->hwinfo);
441445
nfp_cpp_free(pf->cpp);
442446

443447
kfree(pf->eth_tbl);

drivers/net/ethernet/netronome/nfp/nfp_main.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ struct pci_dev;
5454
struct nfp_cpp;
5555
struct nfp_cpp_area;
5656
struct nfp_eth_table;
57+
struct nfp_hwinfo;
5758
struct nfp_net;
5859
struct nfp_nsp_identify;
5960
struct nfp_rtsym_table;
@@ -72,6 +73,7 @@ struct nfp_rtsym_table;
7273
* @fw_loaded: Is the firmware loaded?
7374
* @ctrl_vnic: Pointer to the control vNIC if available
7475
* @rtbl: RTsym table
76+
* @hwinfo: HWInfo table
7577
* @eth_tbl: NSP ETH table
7678
* @nspi: NSP identification info
7779
* @hwmon_dev: pointer to hwmon device
@@ -104,6 +106,7 @@ struct nfp_pf {
104106
struct nfp_net *ctrl_vnic;
105107

106108
struct nfp_rtsym_table *rtbl;
109+
struct nfp_hwinfo *hwinfo;
107110
struct nfp_eth_table *eth_tbl;
108111
struct nfp_nsp_identify *nspi;
109112

@@ -133,7 +136,7 @@ void nfp_hwmon_unregister(struct nfp_pf *pf);
133136
struct nfp_eth_table_port *
134137
nfp_net_find_port(struct nfp_eth_table *eth_tbl, unsigned int id);
135138
void
136-
nfp_net_get_mac_addr(struct nfp_net *nn, struct nfp_cpp *cpp, unsigned int id);
139+
nfp_net_get_mac_addr(struct nfp_pf *pf, struct nfp_net *nn, unsigned int id);
137140

138141
bool nfp_ctrl_tx(struct nfp_net *nn, struct sk_buff *skb);
139142

drivers/net/ethernet/netronome/nfp/nfp_net_main.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@
6363

6464
#define NFP_PF_CSR_SLICE_SIZE (32 * 1024)
6565

66-
static int nfp_is_ready(struct nfp_cpp *cpp)
66+
static int nfp_is_ready(struct nfp_pf *pf)
6767
{
6868
const char *cp;
6969
long state;
7070
int err;
7171

72-
cp = nfp_hwinfo_lookup(cpp, "board.state");
72+
cp = nfp_hwinfo_lookup(pf->hwinfo, "board.state");
7373
if (!cp)
7474
return 0;
7575

@@ -134,15 +134,15 @@ static u8 __iomem *nfp_net_map_area(struct nfp_cpp *cpp,
134134

135135
/**
136136
* nfp_net_get_mac_addr() - Get the MAC address.
137+
* @pf: NFP PF handle
137138
* @nn: NFP Network structure
138-
* @cpp: NFP CPP handle
139139
* @id: NFP port id
140140
*
141141
* First try to get the MAC address from NSP ETH table. If that
142142
* fails try HWInfo. As a last resort generate a random address.
143143
*/
144144
void
145-
nfp_net_get_mac_addr(struct nfp_net *nn, struct nfp_cpp *cpp, unsigned int id)
145+
nfp_net_get_mac_addr(struct nfp_pf *pf, struct nfp_net *nn, unsigned int id)
146146
{
147147
struct nfp_eth_table_port *eth_port;
148148
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)
159159

160160
snprintf(name, sizeof(name), "eth%d.mac", id);
161161

162-
mac_str = nfp_hwinfo_lookup(cpp, name);
162+
mac_str = nfp_hwinfo_lookup(pf->hwinfo, name);
163163
if (!mac_str) {
164164
dev_warn(dp->dev, "Can't lookup MAC address. Generate\n");
165165
eth_hw_addr_random(dp->netdev);
@@ -713,7 +713,7 @@ int nfp_net_pci_probe(struct nfp_pf *pf)
713713
INIT_WORK(&pf->port_refresh_work, nfp_net_refresh_vnics);
714714

715715
/* Verify that the board has completed initialization */
716-
if (!nfp_is_ready(pf->cpp)) {
716+
if (!nfp_is_ready(pf)) {
717717
nfp_err(pf->cpp, "NFP is not ready for NIC operation.\n");
718718
return -EINVAL;
719719
}

drivers/net/ethernet/netronome/nfp/nfpcore/nfp.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@
4646

4747
/* Implemented in nfp_hwinfo.c */
4848

49-
const char *nfp_hwinfo_lookup(struct nfp_cpp *cpp, const char *lookup);
49+
struct nfp_hwinfo;
50+
struct nfp_hwinfo *nfp_hwinfo_read(struct nfp_cpp *cpp);
51+
const char *nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup);
5052

5153
/* Implemented in nfp_nsp.c, low level functions */
5254

drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cpp.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,6 @@ u32 nfp_cpp_model(struct nfp_cpp *cpp);
222222
u16 nfp_cpp_interface(struct nfp_cpp *cpp);
223223
int nfp_cpp_serial(struct nfp_cpp *cpp, const u8 **serial);
224224

225-
void *nfp_hwinfo_cache(struct nfp_cpp *cpp);
226-
void nfp_hwinfo_cache_set(struct nfp_cpp *cpp, void *val);
227-
228225
struct nfp_cpp_area *nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp,
229226
u32 cpp_id,
230227
const char *name,

drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ struct nfp_cpp_resource {
7676
* @serial: chip serial number
7777
* @imb_cat_table: CPP Mapping Table
7878
*
79-
* Following fields can be used only in probe() or with rtnl held:
80-
* @hwinfo: HWInfo database fetched from the device
81-
*
8279
* Following fields use explicit locking:
8380
* @resource_list: NFP CPP resource list
8481
* @resource_lock: protects @resource_list
@@ -106,8 +103,6 @@ struct nfp_cpp {
106103

107104
struct mutex area_cache_mutex;
108105
struct list_head area_cache_list;
109-
110-
void *hwinfo;
111106
};
112107

113108
/* Element of the area_cache_list */
@@ -231,8 +226,6 @@ void nfp_cpp_free(struct nfp_cpp *cpp)
231226
if (cpp->op->free)
232227
cpp->op->free(cpp);
233228

234-
kfree(cpp->hwinfo);
235-
236229
device_unregister(&cpp->dev);
237230

238231
kfree(cpp);
@@ -273,16 +266,6 @@ int nfp_cpp_serial(struct nfp_cpp *cpp, const u8 **serial)
273266
return sizeof(cpp->serial);
274267
}
275268

276-
void *nfp_hwinfo_cache(struct nfp_cpp *cpp)
277-
{
278-
return cpp->hwinfo;
279-
}
280-
281-
void nfp_hwinfo_cache_set(struct nfp_cpp *cpp, void *val)
282-
{
283-
cpp->hwinfo = val;
284-
}
285-
286269
/**
287270
* nfp_cpp_area_alloc_with_name() - allocate a new CPP area
288271
* @cpp: CPP device handle

drivers/net/ethernet/netronome/nfp/nfpcore/nfp_hwinfo.c

Lines changed: 28 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ hwinfo_db_validate(struct nfp_cpp *cpp, struct nfp_hwinfo *db, u32 len)
178178
return hwinfo_db_walk(cpp, db, size);
179179
}
180180

181-
static int hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size)
181+
static struct nfp_hwinfo *
182+
hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size)
182183
{
183184
struct nfp_hwinfo *header;
184185
struct nfp_resource *res;
@@ -196,109 +197,94 @@ static int hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size)
196197
nfp_resource_release(res);
197198

198199
if (*cpp_size < HWINFO_SIZE_MIN)
199-
return -ENOENT;
200+
return NULL;
200201
} else if (PTR_ERR(res) == -ENOENT) {
201202
/* Try getting the HWInfo table from the 'classic' location */
202203
cpp_id = NFP_CPP_ISLAND_ID(NFP_CPP_TARGET_MU,
203204
NFP_CPP_ACTION_RW, 0, 1);
204205
cpp_addr = 0x30000;
205206
*cpp_size = 0x0e000;
206207
} else {
207-
return PTR_ERR(res);
208+
return NULL;
208209
}
209210

210211
db = kmalloc(*cpp_size + 1, GFP_KERNEL);
211212
if (!db)
212-
return -ENOMEM;
213+
return NULL;
213214

214215
err = nfp_cpp_read(cpp, cpp_id, cpp_addr, db, *cpp_size);
215-
if (err != *cpp_size) {
216-
kfree(db);
217-
return err < 0 ? err : -EIO;
218-
}
216+
if (err != *cpp_size)
217+
goto exit_free;
219218

220219
header = (void *)db;
221-
if (nfp_hwinfo_is_updating(header)) {
222-
kfree(db);
223-
return -EBUSY;
224-
}
220+
if (nfp_hwinfo_is_updating(header))
221+
goto exit_free;
225222

226223
if (le32_to_cpu(header->version) != NFP_HWINFO_VERSION_2) {
227224
nfp_err(cpp, "Unknown HWInfo version: 0x%08x\n",
228225
le32_to_cpu(header->version));
229-
kfree(db);
230-
return -EINVAL;
226+
goto exit_free;
231227
}
232228

233229
/* NULL-terminate for safety */
234230
db[*cpp_size] = '\0';
235231

236-
nfp_hwinfo_cache_set(cpp, db);
237-
238-
return 0;
232+
return (void *)db;
233+
exit_free:
234+
kfree(db);
235+
return NULL;
239236
}
240237

241-
static int hwinfo_fetch(struct nfp_cpp *cpp, size_t *hwdb_size)
238+
static struct nfp_hwinfo *hwinfo_fetch(struct nfp_cpp *cpp, size_t *hwdb_size)
242239
{
243240
const unsigned long wait_until = jiffies + HWINFO_WAIT * HZ;
241+
struct nfp_hwinfo *db;
244242
int err;
245243

246244
for (;;) {
247245
const unsigned long start_time = jiffies;
248246

249-
err = hwinfo_try_fetch(cpp, hwdb_size);
250-
if (!err)
251-
return 0;
247+
db = hwinfo_try_fetch(cpp, hwdb_size);
248+
if (db)
249+
return db;
252250

253251
err = msleep_interruptible(100);
254252
if (err || time_after(start_time, wait_until)) {
255253
nfp_err(cpp, "NFP access error\n");
256-
return -EIO;
254+
return NULL;
257255
}
258256
}
259257
}
260258

261-
static int nfp_hwinfo_load(struct nfp_cpp *cpp)
259+
struct nfp_hwinfo *nfp_hwinfo_read(struct nfp_cpp *cpp)
262260
{
263261
struct nfp_hwinfo *db;
264262
size_t hwdb_size = 0;
265263
int err;
266264

267-
err = hwinfo_fetch(cpp, &hwdb_size);
268-
if (err)
269-
return err;
265+
db = hwinfo_fetch(cpp, &hwdb_size);
266+
if (!db)
267+
return NULL;
270268

271-
db = nfp_hwinfo_cache(cpp);
272269
err = hwinfo_db_validate(cpp, db, hwdb_size);
273270
if (err) {
274271
kfree(db);
275-
nfp_hwinfo_cache_set(cpp, NULL);
276-
return err;
272+
return NULL;
277273
}
278274

279-
return 0;
275+
return db;
280276
}
281277

282278
/**
283279
* nfp_hwinfo_lookup() - Find a value in the HWInfo table by name
284-
* @cpp: NFP CPP handle
280+
* @hwinfo: NFP HWinfo table
285281
* @lookup: HWInfo name to search for
286282
*
287283
* Return: Value of the HWInfo name, or NULL
288284
*/
289-
const char *nfp_hwinfo_lookup(struct nfp_cpp *cpp, const char *lookup)
285+
const char *nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup)
290286
{
291287
const char *key, *val, *end;
292-
struct nfp_hwinfo *hwinfo;
293-
int err;
294-
295-
hwinfo = nfp_hwinfo_cache(cpp);
296-
if (!hwinfo) {
297-
err = nfp_hwinfo_load(cpp);
298-
if (err)
299-
return NULL;
300-
hwinfo = nfp_hwinfo_cache(cpp);
301-
}
302288

303289
if (!hwinfo || !lookup)
304290
return NULL;

0 commit comments

Comments
 (0)