blob: d47adb4c86d6b3d6ddc94f0358d2d91d13c5d83a [file] [log] [blame]
Jakub Kicinski2633beb2017-02-09 09:17:28 -08001/*
2 * Copyright (C) 2015-2017 Netronome Systems, Inc.
3 *
4 * This software is dual licensed under the GNU General License Version 2,
5 * June 1991 as shown in the file COPYING in the top-level directory of this
6 * source tree or the BSD 2-Clause License provided below. You have the
7 * option to license this software under the complete terms of either license.
8 *
9 * The BSD 2-Clause License:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * 1. Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * 2. Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 */
33
34/*
35 * nfp_main.c
36 * Authors: Jakub Kicinski <jakub.kicinski@netronome.com>
37 * Alejandro Lucero <alejandro.lucero@netronome.com>
38 * Jason McMullan <jason.mcmullan@netronome.com>
39 * Rolf Neugebauer <rolf.neugebauer@netronome.com>
40 */
41
42#include <linux/kernel.h>
43#include <linux/module.h>
Jakub Kicinski346cfe82017-05-26 01:03:31 -070044#include <linux/mutex.h>
Jakub Kicinski2633beb2017-02-09 09:17:28 -080045#include <linux/pci.h>
46#include <linux/firmware.h>
47#include <linux/vermagic.h>
Simon Horman1851f93f2017-05-26 01:03:32 -070048#include <net/devlink.h>
Jakub Kicinski2633beb2017-02-09 09:17:28 -080049
Jakub Kicinski63461a02017-02-09 09:17:38 -080050#include "nfpcore/nfp.h"
51#include "nfpcore/nfp_cpp.h"
Jakub Kicinski0bc38272017-02-19 11:58:14 -080052#include "nfpcore/nfp_nffw.h"
Jakub Kicinskice22f5a2017-04-04 16:12:30 -070053#include "nfpcore/nfp_nsp.h"
Jakub Kicinski63461a02017-02-09 09:17:38 -080054
55#include "nfpcore/nfp6000_pcie.h"
56
Simon Horman758238f2017-06-23 22:12:04 +020057#include "nfp_app.h"
Jakub Kicinski2633beb2017-02-09 09:17:28 -080058#include "nfp_main.h"
59#include "nfp_net.h"
60
61static const char nfp_driver_name[] = "nfp";
62const char nfp_driver_version[] = VERMAGIC_STRING;
63
Jakub Kicinski63461a02017-02-09 09:17:38 -080064static const struct pci_device_id nfp_pci_device_ids[] = {
Simon Horman3b473522017-02-17 08:57:54 +010065 { PCI_VENDOR_ID_NETRONOME, PCI_DEVICE_ID_NETRONOME_NFP6000,
Jakub Kicinski63461a02017-02-09 09:17:38 -080066 PCI_VENDOR_ID_NETRONOME, PCI_ANY_ID,
67 PCI_ANY_ID, 0,
68 },
Simon Horman3b473522017-02-17 08:57:54 +010069 { PCI_VENDOR_ID_NETRONOME, PCI_DEVICE_ID_NETRONOME_NFP4000,
Jakub Kicinski63461a02017-02-09 09:17:38 -080070 PCI_VENDOR_ID_NETRONOME, PCI_ANY_ID,
71 PCI_ANY_ID, 0,
72 },
73 { 0, } /* Required last entry. */
74};
75MODULE_DEVICE_TABLE(pci, nfp_pci_device_ids);
76
Jakub Kicinski651e1f22017-05-28 17:52:54 -070077static int nfp_pcie_sriov_read_nfd_limit(struct nfp_pf *pf)
Jakub Kicinski0bc38272017-02-19 11:58:14 -080078{
Jakub Kicinski0bc38272017-02-19 11:58:14 -080079 int err;
80
Jakub Kicinskiaf4fa7e2017-06-08 20:56:11 -070081 pf->limit_vfs = nfp_rtsym_read_le(pf->rtbl, "nfd_vf_cfg_max_vfs", &err);
Jakub Kicinski0bc38272017-02-19 11:58:14 -080082 if (!err)
Jakub Kicinski651e1f22017-05-28 17:52:54 -070083 return pci_sriov_set_totalvfs(pf->pdev, pf->limit_vfs);
Jakub Kicinski0bc38272017-02-19 11:58:14 -080084
85 pf->limit_vfs = ~0;
Jakub Kicinski651e1f22017-05-28 17:52:54 -070086 pci_sriov_set_totalvfs(pf->pdev, 0); /* 0 is unset */
Jakub Kicinski0bc38272017-02-19 11:58:14 -080087 /* Allow any setting for backwards compatibility if symbol not found */
Jakub Kicinski651e1f22017-05-28 17:52:54 -070088 if (err == -ENOENT)
89 return 0;
90
91 nfp_warn(pf->cpp, "Warning: VF limit read failed: %d\n", err);
92 return err;
Jakub Kicinski0bc38272017-02-19 11:58:14 -080093}
94
Jakub Kicinski63461a02017-02-09 09:17:38 -080095static int nfp_pcie_sriov_enable(struct pci_dev *pdev, int num_vfs)
96{
97#ifdef CONFIG_PCI_IOV
98 struct nfp_pf *pf = pci_get_drvdata(pdev);
99 int err;
100
Simon Horman758238f2017-06-23 22:12:04 +0200101 mutex_lock(&pf->lock);
102
Jakub Kicinski0bc38272017-02-19 11:58:14 -0800103 if (num_vfs > pf->limit_vfs) {
104 nfp_info(pf->cpp, "Firmware limits number of VFs to %u\n",
105 pf->limit_vfs);
Simon Horman758238f2017-06-23 22:12:04 +0200106 err = -EINVAL;
107 goto err_unlock;
108 }
109
110 err = nfp_app_sriov_enable(pf->app, num_vfs);
111 if (err) {
112 dev_warn(&pdev->dev, "App specific PCI sriov configuration failed: %d\n",
113 err);
114 goto err_unlock;
Jakub Kicinski0bc38272017-02-19 11:58:14 -0800115 }
116
Jakub Kicinski63461a02017-02-09 09:17:38 -0800117 err = pci_enable_sriov(pdev, num_vfs);
118 if (err) {
119 dev_warn(&pdev->dev, "Failed to enable PCI sriov: %d\n", err);
Simon Horman758238f2017-06-23 22:12:04 +0200120 goto err_app_sriov_disable;
Jakub Kicinski63461a02017-02-09 09:17:38 -0800121 }
122
123 pf->num_vfs = num_vfs;
124
125 dev_dbg(&pdev->dev, "Created %d VFs.\n", pf->num_vfs);
126
Simon Horman758238f2017-06-23 22:12:04 +0200127 mutex_unlock(&pf->lock);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800128 return num_vfs;
Simon Horman758238f2017-06-23 22:12:04 +0200129
130err_app_sriov_disable:
131 nfp_app_sriov_disable(pf->app);
132err_unlock:
133 mutex_unlock(&pf->lock);
134 return err;
Jakub Kicinski63461a02017-02-09 09:17:38 -0800135#endif
136 return 0;
137}
138
Simon Horman758238f2017-06-23 22:12:04 +0200139static int __nfp_pcie_sriov_disable(struct pci_dev *pdev)
Jakub Kicinski63461a02017-02-09 09:17:38 -0800140{
141#ifdef CONFIG_PCI_IOV
142 struct nfp_pf *pf = pci_get_drvdata(pdev);
143
144 /* If the VFs are assigned we cannot shut down SR-IOV without
145 * causing issues, so just leave the hardware available but
146 * disabled
147 */
148 if (pci_vfs_assigned(pdev)) {
149 dev_warn(&pdev->dev, "Disabling while VFs assigned - VFs will not be deallocated\n");
150 return -EPERM;
151 }
152
Simon Horman758238f2017-06-23 22:12:04 +0200153 nfp_app_sriov_disable(pf->app);
154
Jakub Kicinski63461a02017-02-09 09:17:38 -0800155 pf->num_vfs = 0;
156
157 pci_disable_sriov(pdev);
158 dev_dbg(&pdev->dev, "Removed VFs.\n");
159#endif
160 return 0;
161}
162
Simon Horman758238f2017-06-23 22:12:04 +0200163static int nfp_pcie_sriov_disable(struct pci_dev *pdev)
164{
165 struct nfp_pf *pf = pci_get_drvdata(pdev);
166 int err;
167
168 mutex_lock(&pf->lock);
169 err = __nfp_pcie_sriov_disable(pdev);
170 mutex_unlock(&pf->lock);
171
172 return err;
173}
174
Jakub Kicinski63461a02017-02-09 09:17:38 -0800175static int nfp_pcie_sriov_configure(struct pci_dev *pdev, int num_vfs)
176{
177 if (num_vfs == 0)
178 return nfp_pcie_sriov_disable(pdev);
179 else
180 return nfp_pcie_sriov_enable(pdev, num_vfs);
181}
182
183/**
184 * nfp_net_fw_find() - Find the correct firmware image for netdev mode
185 * @pdev: PCI Device structure
186 * @pf: NFP PF Device structure
187 *
188 * Return: firmware if found and requested successfully.
189 */
190static const struct firmware *
191nfp_net_fw_find(struct pci_dev *pdev, struct nfp_pf *pf)
192{
193 const struct firmware *fw = NULL;
194 struct nfp_eth_table_port *port;
195 const char *fw_model;
196 char fw_name[256];
197 int spc, err = 0;
198 int i, j;
199
200 if (!pf->eth_tbl) {
201 dev_err(&pdev->dev, "Error: can't identify media config\n");
202 return NULL;
203 }
204
Jakub Kicinski9baa4882017-06-08 20:56:12 -0700205 fw_model = nfp_hwinfo_lookup(pf->hwinfo, "assembly.partno");
Jakub Kicinski63461a02017-02-09 09:17:38 -0800206 if (!fw_model) {
207 dev_err(&pdev->dev, "Error: can't read part number\n");
208 return NULL;
209 }
210
211 spc = ARRAY_SIZE(fw_name);
212 spc -= snprintf(fw_name, spc, "netronome/nic_%s", fw_model);
213
214 for (i = 0; spc > 0 && i < pf->eth_tbl->count; i += j) {
215 port = &pf->eth_tbl->ports[i];
216 j = 1;
217 while (i + j < pf->eth_tbl->count &&
218 port->speed == port[j].speed)
219 j++;
220
221 spc -= snprintf(&fw_name[ARRAY_SIZE(fw_name) - spc], spc,
222 "_%dx%d", j, port->speed / 1000);
223 }
224
225 if (spc <= 0)
226 return NULL;
227
228 spc -= snprintf(&fw_name[ARRAY_SIZE(fw_name) - spc], spc, ".nffw");
229 if (spc <= 0)
230 return NULL;
231
232 err = request_firmware(&fw, fw_name, &pdev->dev);
233 if (err)
234 return NULL;
235
236 dev_info(&pdev->dev, "Loading FW image: %s\n", fw_name);
237
238 return fw;
239}
240
241/**
242 * nfp_net_fw_load() - Load the firmware image
243 * @pdev: PCI Device structure
244 * @pf: NFP PF Device structure
245 * @nsp: NFP SP handle
246 *
247 * Return: -ERRNO, 0 for no firmware loaded, 1 for firmware loaded
248 */
249static int
250nfp_fw_load(struct pci_dev *pdev, struct nfp_pf *pf, struct nfp_nsp *nsp)
251{
252 const struct firmware *fw;
253 u16 interface;
254 int err;
255
256 interface = nfp_cpp_interface(pf->cpp);
257 if (NFP_CPP_INTERFACE_UNIT_of(interface) != 0) {
258 /* Only Unit 0 should reset or load firmware */
259 dev_info(&pdev->dev, "Firmware will be loaded by partner\n");
260 return 0;
261 }
262
263 fw = nfp_net_fw_find(pdev, pf);
264 if (!fw)
265 return 0;
266
267 dev_info(&pdev->dev, "Soft-reset, loading FW image\n");
268 err = nfp_nsp_device_soft_reset(nsp);
269 if (err < 0) {
270 dev_err(&pdev->dev, "Failed to soft reset the NFP: %d\n",
271 err);
272 goto exit_release_fw;
273 }
274
275 err = nfp_nsp_load_fw(nsp, fw);
276
277 if (err < 0) {
278 dev_err(&pdev->dev, "FW loading failed: %d\n", err);
279 goto exit_release_fw;
280 }
281
282 dev_info(&pdev->dev, "Finished loading FW image\n");
283
284exit_release_fw:
285 release_firmware(fw);
286
287 return err < 0 ? err : 1;
288}
289
Jakub Kicinskia9c83f72017-02-19 11:58:08 -0800290static int nfp_nsp_init(struct pci_dev *pdev, struct nfp_pf *pf)
291{
292 struct nfp_nsp *nsp;
293 int err;
294
295 nsp = nfp_nsp_open(pf->cpp);
296 if (IS_ERR(nsp)) {
297 err = PTR_ERR(nsp);
298 dev_err(&pdev->dev, "Failed to access the NSP: %d\n", err);
299 return err;
300 }
301
302 err = nfp_nsp_wait(nsp);
303 if (err < 0)
304 goto exit_close_nsp;
305
306 pf->eth_tbl = __nfp_eth_read_ports(pf->cpp, nsp);
307
David Bruneczeefbde72017-05-28 17:53:00 -0700308 pf->nspi = __nfp_nsp_identify(nsp);
309 if (pf->nspi)
310 dev_info(&pdev->dev, "BSP: %s\n", pf->nspi->version);
David Brunecz010e2f92017-04-22 20:17:54 -0700311
Jakub Kicinskia9c83f72017-02-19 11:58:08 -0800312 err = nfp_fw_load(pdev, pf, nsp);
313 if (err < 0) {
Jakub Kicinski47eaa232017-05-31 08:06:51 -0700314 kfree(pf->nspi);
Jakub Kicinskia9c83f72017-02-19 11:58:08 -0800315 kfree(pf->eth_tbl);
316 dev_err(&pdev->dev, "Failed to load FW\n");
317 goto exit_close_nsp;
318 }
319
320 pf->fw_loaded = !!err;
321 err = 0;
322
323exit_close_nsp:
324 nfp_nsp_close(nsp);
325
326 return err;
327}
328
Jakub Kicinski63461a02017-02-09 09:17:38 -0800329static void nfp_fw_unload(struct nfp_pf *pf)
330{
331 struct nfp_nsp *nsp;
332 int err;
333
334 nsp = nfp_nsp_open(pf->cpp);
335 if (IS_ERR(nsp)) {
336 nfp_err(pf->cpp, "Reset failed, can't open NSP\n");
337 return;
338 }
339
340 err = nfp_nsp_device_soft_reset(nsp);
341 if (err < 0)
342 dev_warn(&pf->pdev->dev, "Couldn't unload firmware: %d\n", err);
343 else
344 dev_info(&pf->pdev->dev, "Firmware safely unloaded\n");
345
346 nfp_nsp_close(nsp);
347}
348
349static int nfp_pci_probe(struct pci_dev *pdev,
350 const struct pci_device_id *pci_id)
351{
Simon Horman1851f93f2017-05-26 01:03:32 -0700352 struct devlink *devlink;
Jakub Kicinski63461a02017-02-09 09:17:38 -0800353 struct nfp_pf *pf;
354 int err;
355
356 err = pci_enable_device(pdev);
357 if (err < 0)
358 return err;
359
360 pci_set_master(pdev);
361
362 err = dma_set_mask_and_coherent(&pdev->dev,
363 DMA_BIT_MASK(NFP_NET_MAX_DMA_BITS));
364 if (err)
365 goto err_pci_disable;
366
367 err = pci_request_regions(pdev, nfp_driver_name);
368 if (err < 0) {
369 dev_err(&pdev->dev, "Unable to reserve pci resources.\n");
370 goto err_pci_disable;
371 }
372
Simon Horman1851f93f2017-05-26 01:03:32 -0700373 devlink = devlink_alloc(&nfp_devlink_ops, sizeof(*pf));
374 if (!devlink) {
Jakub Kicinski63461a02017-02-09 09:17:38 -0800375 err = -ENOMEM;
376 goto err_rel_regions;
377 }
Simon Horman1851f93f2017-05-26 01:03:32 -0700378 pf = devlink_priv(devlink);
Jakub Kicinskid4e7f092017-05-22 10:59:24 -0700379 INIT_LIST_HEAD(&pf->vnics);
Jakub Kicinski3eb3b742017-05-22 10:59:31 -0700380 INIT_LIST_HEAD(&pf->ports);
Jakub Kicinski346cfe82017-05-26 01:03:31 -0700381 mutex_init(&pf->lock);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800382 pci_set_drvdata(pdev, pf);
383 pf->pdev = pdev;
384
385 pf->cpp = nfp_cpp_from_nfp6000_pcie(pdev);
386 if (IS_ERR_OR_NULL(pf->cpp)) {
387 err = PTR_ERR(pf->cpp);
388 if (err >= 0)
389 err = -ENOMEM;
390 goto err_disable_msix;
391 }
392
Jakub Kicinski9baa4882017-06-08 20:56:12 -0700393 pf->hwinfo = nfp_hwinfo_read(pf->cpp);
394
Jakub Kicinski64db09e2017-02-19 11:58:09 -0800395 dev_info(&pdev->dev, "Assembly: %s%s%s-%s CPLD: %s\n",
Jakub Kicinski9baa4882017-06-08 20:56:12 -0700396 nfp_hwinfo_lookup(pf->hwinfo, "assembly.vendor"),
397 nfp_hwinfo_lookup(pf->hwinfo, "assembly.partno"),
398 nfp_hwinfo_lookup(pf->hwinfo, "assembly.serial"),
399 nfp_hwinfo_lookup(pf->hwinfo, "assembly.revision"),
400 nfp_hwinfo_lookup(pf->hwinfo, "cpld.version"));
Jakub Kicinski64db09e2017-02-19 11:58:09 -0800401
Simon Horman1851f93f2017-05-26 01:03:32 -0700402 err = devlink_register(devlink, &pdev->dev);
Jakub Kicinskia9c83f72017-02-19 11:58:08 -0800403 if (err)
Jakub Kicinski9baa4882017-06-08 20:56:12 -0700404 goto err_hwinfo_free;
Jakub Kicinski63461a02017-02-09 09:17:38 -0800405
Simon Horman1851f93f2017-05-26 01:03:32 -0700406 err = nfp_nsp_init(pdev, pf);
407 if (err)
408 goto err_devlink_unreg;
409
Jakub Kicinski0be40e62017-06-08 20:56:13 -0700410 pf->mip = nfp_mip_open(pf->cpp);
411 pf->rtbl = __nfp_rtsym_table_read(pf->cpp, pf->mip);
Jakub Kicinskiaf4fa7e2017-06-08 20:56:11 -0700412
Jakub Kicinski651e1f22017-05-28 17:52:54 -0700413 err = nfp_pcie_sriov_read_nfd_limit(pf);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800414 if (err)
415 goto err_fw_unload;
416
Jakub Kicinski0dc78622017-06-27 00:50:25 -0700417 pf->num_vfs = pci_num_vf(pdev);
418 if (pf->num_vfs > pf->limit_vfs) {
419 dev_err(&pdev->dev,
420 "Error: %d VFs already enabled, but loaded FW can only support %d\n",
421 pf->num_vfs, pf->limit_vfs);
422 goto err_fw_unload;
423 }
424
Jakub Kicinski651e1f22017-05-28 17:52:54 -0700425 err = nfp_net_pci_probe(pf);
426 if (err)
427 goto err_sriov_unlimit;
428
David Bruneczeefbde72017-05-28 17:53:00 -0700429 err = nfp_hwmon_register(pf);
430 if (err) {
431 dev_err(&pdev->dev, "Failed to register hwmon info\n");
432 goto err_net_remove;
433 }
434
Jakub Kicinski63461a02017-02-09 09:17:38 -0800435 return 0;
436
David Bruneczeefbde72017-05-28 17:53:00 -0700437err_net_remove:
438 nfp_net_pci_remove(pf);
Jakub Kicinski651e1f22017-05-28 17:52:54 -0700439err_sriov_unlimit:
440 pci_sriov_set_totalvfs(pf->pdev, 0);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800441err_fw_unload:
Jakub Kicinskiaf4fa7e2017-06-08 20:56:11 -0700442 kfree(pf->rtbl);
Jakub Kicinski0be40e62017-06-08 20:56:13 -0700443 nfp_mip_close(pf->mip);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800444 if (pf->fw_loaded)
445 nfp_fw_unload(pf);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800446 kfree(pf->eth_tbl);
David Bruneczeefbde72017-05-28 17:53:00 -0700447 kfree(pf->nspi);
Simon Horman1851f93f2017-05-26 01:03:32 -0700448err_devlink_unreg:
449 devlink_unregister(devlink);
Jakub Kicinski9baa4882017-06-08 20:56:12 -0700450err_hwinfo_free:
451 kfree(pf->hwinfo);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800452 nfp_cpp_free(pf->cpp);
453err_disable_msix:
454 pci_set_drvdata(pdev, NULL);
Jakub Kicinski346cfe82017-05-26 01:03:31 -0700455 mutex_destroy(&pf->lock);
Simon Horman1851f93f2017-05-26 01:03:32 -0700456 devlink_free(devlink);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800457err_rel_regions:
458 pci_release_regions(pdev);
459err_pci_disable:
460 pci_disable_device(pdev);
461
462 return err;
463}
464
465static void nfp_pci_remove(struct pci_dev *pdev)
466{
467 struct nfp_pf *pf = pci_get_drvdata(pdev);
Simon Horman1851f93f2017-05-26 01:03:32 -0700468 struct devlink *devlink;
469
David Bruneczeefbde72017-05-28 17:53:00 -0700470 nfp_hwmon_unregister(pf);
471
Simon Horman1851f93f2017-05-26 01:03:32 -0700472 devlink = priv_to_devlink(pf);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800473
Jakub Kicinski63461a02017-02-09 09:17:38 -0800474 nfp_pcie_sriov_disable(pdev);
Jakub Kicinski651e1f22017-05-28 17:52:54 -0700475 pci_sriov_set_totalvfs(pf->pdev, 0);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800476
Simon Horman758238f2017-06-23 22:12:04 +0200477 nfp_net_pci_remove(pf);
478
Simon Horman1851f93f2017-05-26 01:03:32 -0700479 devlink_unregister(devlink);
480
Jakub Kicinskiaf4fa7e2017-06-08 20:56:11 -0700481 kfree(pf->rtbl);
Jakub Kicinski0be40e62017-06-08 20:56:13 -0700482 nfp_mip_close(pf->mip);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800483 if (pf->fw_loaded)
484 nfp_fw_unload(pf);
485
486 pci_set_drvdata(pdev, NULL);
Jakub Kicinski9baa4882017-06-08 20:56:12 -0700487 kfree(pf->hwinfo);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800488 nfp_cpp_free(pf->cpp);
489
490 kfree(pf->eth_tbl);
David Bruneczeefbde72017-05-28 17:53:00 -0700491 kfree(pf->nspi);
Jakub Kicinski346cfe82017-05-26 01:03:31 -0700492 mutex_destroy(&pf->lock);
Simon Horman1851f93f2017-05-26 01:03:32 -0700493 devlink_free(devlink);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800494 pci_release_regions(pdev);
495 pci_disable_device(pdev);
496}
497
498static struct pci_driver nfp_pci_driver = {
499 .name = nfp_driver_name,
500 .id_table = nfp_pci_device_ids,
501 .probe = nfp_pci_probe,
502 .remove = nfp_pci_remove,
503 .sriov_configure = nfp_pcie_sriov_configure,
504};
505
Jakub Kicinski2633beb2017-02-09 09:17:28 -0800506static int __init nfp_main_init(void)
507{
508 int err;
509
510 pr_info("%s: NFP PCIe Driver, Copyright (C) 2014-2017 Netronome Systems\n",
511 nfp_driver_name);
512
513 nfp_net_debugfs_create();
514
Jakub Kicinski63461a02017-02-09 09:17:38 -0800515 err = pci_register_driver(&nfp_pci_driver);
516 if (err < 0)
517 goto err_destroy_debugfs;
518
Jakub Kicinski2633beb2017-02-09 09:17:28 -0800519 err = pci_register_driver(&nfp_netvf_pci_driver);
520 if (err)
Jakub Kicinski63461a02017-02-09 09:17:38 -0800521 goto err_unreg_pf;
Jakub Kicinski2633beb2017-02-09 09:17:28 -0800522
523 return err;
524
Jakub Kicinski63461a02017-02-09 09:17:38 -0800525err_unreg_pf:
526 pci_unregister_driver(&nfp_pci_driver);
Jakub Kicinski2633beb2017-02-09 09:17:28 -0800527err_destroy_debugfs:
528 nfp_net_debugfs_destroy();
529 return err;
530}
531
532static void __exit nfp_main_exit(void)
533{
534 pci_unregister_driver(&nfp_netvf_pci_driver);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800535 pci_unregister_driver(&nfp_pci_driver);
Jakub Kicinski2633beb2017-02-09 09:17:28 -0800536 nfp_net_debugfs_destroy();
537}
538
539module_init(nfp_main_init);
540module_exit(nfp_main_exit);
541
Jakub Kicinski63461a02017-02-09 09:17:38 -0800542MODULE_FIRMWARE("netronome/nic_AMDA0081-0001_1x40.nffw");
543MODULE_FIRMWARE("netronome/nic_AMDA0081-0001_4x10.nffw");
544MODULE_FIRMWARE("netronome/nic_AMDA0096-0001_2x10.nffw");
545MODULE_FIRMWARE("netronome/nic_AMDA0097-0001_2x40.nffw");
546MODULE_FIRMWARE("netronome/nic_AMDA0097-0001_4x10_1x40.nffw");
547MODULE_FIRMWARE("netronome/nic_AMDA0097-0001_8x10.nffw");
548MODULE_FIRMWARE("netronome/nic_AMDA0099-0001_2x10.nffw");
549MODULE_FIRMWARE("netronome/nic_AMDA0099-0001_2x25.nffw");
550
Jakub Kicinski2633beb2017-02-09 09:17:28 -0800551MODULE_AUTHOR("Netronome Systems <oss-drivers@netronome.com>");
552MODULE_LICENSE("GPL");
553MODULE_DESCRIPTION("The Netronome Flow Processor (NFP) driver.");