blob: a0f3df8572d67c311e27e52dca754414bab8cb0f [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
Jakub Kicinskie3f28472017-06-27 00:50:26 -0700110 err = pci_enable_sriov(pdev, num_vfs);
Simon Horman758238f2017-06-23 22:12:04 +0200111 if (err) {
Jakub Kicinskie3f28472017-06-27 00:50:26 -0700112 dev_warn(&pdev->dev, "Failed to enable PCI SR-IOV: %d\n", err);
Simon Horman758238f2017-06-23 22:12:04 +0200113 goto err_unlock;
Jakub Kicinski0bc38272017-02-19 11:58:14 -0800114 }
115
Jakub Kicinskie3f28472017-06-27 00:50:26 -0700116 err = nfp_app_sriov_enable(pf->app, num_vfs);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800117 if (err) {
Jakub Kicinskie3f28472017-06-27 00:50:26 -0700118 dev_warn(&pdev->dev,
119 "App specific PCI SR-IOV configuration failed: %d\n",
120 err);
121 goto err_sriov_disable;
Jakub Kicinski63461a02017-02-09 09:17:38 -0800122 }
123
124 pf->num_vfs = num_vfs;
125
126 dev_dbg(&pdev->dev, "Created %d VFs.\n", pf->num_vfs);
127
Simon Horman758238f2017-06-23 22:12:04 +0200128 mutex_unlock(&pf->lock);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800129 return num_vfs;
Simon Horman758238f2017-06-23 22:12:04 +0200130
Jakub Kicinskie3f28472017-06-27 00:50:26 -0700131err_sriov_disable:
132 pci_disable_sriov(pdev);
Simon Horman758238f2017-06-23 22:12:04 +0200133err_unlock:
134 mutex_unlock(&pf->lock);
135 return err;
Jakub Kicinski63461a02017-02-09 09:17:38 -0800136#endif
137 return 0;
138}
139
Jakub Kicinskie3f28472017-06-27 00:50:26 -0700140static int nfp_pcie_sriov_disable(struct pci_dev *pdev)
Jakub Kicinski63461a02017-02-09 09:17:38 -0800141{
142#ifdef CONFIG_PCI_IOV
143 struct nfp_pf *pf = pci_get_drvdata(pdev);
144
Jakub Kicinskie3f28472017-06-27 00:50:26 -0700145 mutex_lock(&pf->lock);
146
Jakub Kicinski63461a02017-02-09 09:17:38 -0800147 /* If the VFs are assigned we cannot shut down SR-IOV without
148 * causing issues, so just leave the hardware available but
149 * disabled
150 */
151 if (pci_vfs_assigned(pdev)) {
152 dev_warn(&pdev->dev, "Disabling while VFs assigned - VFs will not be deallocated\n");
Jakub Kicinskie3f28472017-06-27 00:50:26 -0700153 mutex_unlock(&pf->lock);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800154 return -EPERM;
155 }
156
Simon Horman758238f2017-06-23 22:12:04 +0200157 nfp_app_sriov_disable(pf->app);
158
Jakub Kicinski63461a02017-02-09 09:17:38 -0800159 pf->num_vfs = 0;
160
161 pci_disable_sriov(pdev);
162 dev_dbg(&pdev->dev, "Removed VFs.\n");
Jakub Kicinskie3f28472017-06-27 00:50:26 -0700163
164 mutex_unlock(&pf->lock);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800165#endif
166 return 0;
167}
168
169static int nfp_pcie_sriov_configure(struct pci_dev *pdev, int num_vfs)
170{
171 if (num_vfs == 0)
172 return nfp_pcie_sriov_disable(pdev);
173 else
174 return nfp_pcie_sriov_enable(pdev, num_vfs);
175}
176
177/**
178 * nfp_net_fw_find() - Find the correct firmware image for netdev mode
179 * @pdev: PCI Device structure
180 * @pf: NFP PF Device structure
181 *
182 * Return: firmware if found and requested successfully.
183 */
184static const struct firmware *
185nfp_net_fw_find(struct pci_dev *pdev, struct nfp_pf *pf)
186{
187 const struct firmware *fw = NULL;
188 struct nfp_eth_table_port *port;
189 const char *fw_model;
190 char fw_name[256];
191 int spc, err = 0;
192 int i, j;
193
194 if (!pf->eth_tbl) {
195 dev_err(&pdev->dev, "Error: can't identify media config\n");
196 return NULL;
197 }
198
Jakub Kicinski9baa4882017-06-08 20:56:12 -0700199 fw_model = nfp_hwinfo_lookup(pf->hwinfo, "assembly.partno");
Jakub Kicinski63461a02017-02-09 09:17:38 -0800200 if (!fw_model) {
201 dev_err(&pdev->dev, "Error: can't read part number\n");
202 return NULL;
203 }
204
205 spc = ARRAY_SIZE(fw_name);
206 spc -= snprintf(fw_name, spc, "netronome/nic_%s", fw_model);
207
208 for (i = 0; spc > 0 && i < pf->eth_tbl->count; i += j) {
209 port = &pf->eth_tbl->ports[i];
210 j = 1;
211 while (i + j < pf->eth_tbl->count &&
212 port->speed == port[j].speed)
213 j++;
214
215 spc -= snprintf(&fw_name[ARRAY_SIZE(fw_name) - spc], spc,
216 "_%dx%d", j, port->speed / 1000);
217 }
218
219 if (spc <= 0)
220 return NULL;
221
222 spc -= snprintf(&fw_name[ARRAY_SIZE(fw_name) - spc], spc, ".nffw");
223 if (spc <= 0)
224 return NULL;
225
226 err = request_firmware(&fw, fw_name, &pdev->dev);
227 if (err)
228 return NULL;
229
230 dev_info(&pdev->dev, "Loading FW image: %s\n", fw_name);
231
232 return fw;
233}
234
235/**
236 * nfp_net_fw_load() - Load the firmware image
237 * @pdev: PCI Device structure
238 * @pf: NFP PF Device structure
239 * @nsp: NFP SP handle
240 *
241 * Return: -ERRNO, 0 for no firmware loaded, 1 for firmware loaded
242 */
243static int
244nfp_fw_load(struct pci_dev *pdev, struct nfp_pf *pf, struct nfp_nsp *nsp)
245{
246 const struct firmware *fw;
247 u16 interface;
248 int err;
249
250 interface = nfp_cpp_interface(pf->cpp);
251 if (NFP_CPP_INTERFACE_UNIT_of(interface) != 0) {
252 /* Only Unit 0 should reset or load firmware */
253 dev_info(&pdev->dev, "Firmware will be loaded by partner\n");
254 return 0;
255 }
256
257 fw = nfp_net_fw_find(pdev, pf);
258 if (!fw)
259 return 0;
260
261 dev_info(&pdev->dev, "Soft-reset, loading FW image\n");
262 err = nfp_nsp_device_soft_reset(nsp);
263 if (err < 0) {
264 dev_err(&pdev->dev, "Failed to soft reset the NFP: %d\n",
265 err);
266 goto exit_release_fw;
267 }
268
269 err = nfp_nsp_load_fw(nsp, fw);
270
271 if (err < 0) {
272 dev_err(&pdev->dev, "FW loading failed: %d\n", err);
273 goto exit_release_fw;
274 }
275
276 dev_info(&pdev->dev, "Finished loading FW image\n");
277
278exit_release_fw:
279 release_firmware(fw);
280
281 return err < 0 ? err : 1;
282}
283
Jakub Kicinskia9c83f72017-02-19 11:58:08 -0800284static int nfp_nsp_init(struct pci_dev *pdev, struct nfp_pf *pf)
285{
286 struct nfp_nsp *nsp;
287 int err;
288
289 nsp = nfp_nsp_open(pf->cpp);
290 if (IS_ERR(nsp)) {
291 err = PTR_ERR(nsp);
292 dev_err(&pdev->dev, "Failed to access the NSP: %d\n", err);
293 return err;
294 }
295
296 err = nfp_nsp_wait(nsp);
297 if (err < 0)
298 goto exit_close_nsp;
299
300 pf->eth_tbl = __nfp_eth_read_ports(pf->cpp, nsp);
301
David Bruneczeefbde72017-05-28 17:53:00 -0700302 pf->nspi = __nfp_nsp_identify(nsp);
303 if (pf->nspi)
304 dev_info(&pdev->dev, "BSP: %s\n", pf->nspi->version);
David Brunecz010e2f92017-04-22 20:17:54 -0700305
Jakub Kicinskia9c83f72017-02-19 11:58:08 -0800306 err = nfp_fw_load(pdev, pf, nsp);
307 if (err < 0) {
Jakub Kicinski47eaa232017-05-31 08:06:51 -0700308 kfree(pf->nspi);
Jakub Kicinskia9c83f72017-02-19 11:58:08 -0800309 kfree(pf->eth_tbl);
310 dev_err(&pdev->dev, "Failed to load FW\n");
311 goto exit_close_nsp;
312 }
313
314 pf->fw_loaded = !!err;
315 err = 0;
316
317exit_close_nsp:
318 nfp_nsp_close(nsp);
319
320 return err;
321}
322
Jakub Kicinski63461a02017-02-09 09:17:38 -0800323static void nfp_fw_unload(struct nfp_pf *pf)
324{
325 struct nfp_nsp *nsp;
326 int err;
327
328 nsp = nfp_nsp_open(pf->cpp);
329 if (IS_ERR(nsp)) {
330 nfp_err(pf->cpp, "Reset failed, can't open NSP\n");
331 return;
332 }
333
334 err = nfp_nsp_device_soft_reset(nsp);
335 if (err < 0)
336 dev_warn(&pf->pdev->dev, "Couldn't unload firmware: %d\n", err);
337 else
338 dev_info(&pf->pdev->dev, "Firmware safely unloaded\n");
339
340 nfp_nsp_close(nsp);
341}
342
343static int nfp_pci_probe(struct pci_dev *pdev,
344 const struct pci_device_id *pci_id)
345{
Simon Horman1851f93f2017-05-26 01:03:32 -0700346 struct devlink *devlink;
Jakub Kicinski63461a02017-02-09 09:17:38 -0800347 struct nfp_pf *pf;
348 int err;
349
350 err = pci_enable_device(pdev);
351 if (err < 0)
352 return err;
353
354 pci_set_master(pdev);
355
356 err = dma_set_mask_and_coherent(&pdev->dev,
357 DMA_BIT_MASK(NFP_NET_MAX_DMA_BITS));
358 if (err)
359 goto err_pci_disable;
360
361 err = pci_request_regions(pdev, nfp_driver_name);
362 if (err < 0) {
363 dev_err(&pdev->dev, "Unable to reserve pci resources.\n");
364 goto err_pci_disable;
365 }
366
Simon Horman1851f93f2017-05-26 01:03:32 -0700367 devlink = devlink_alloc(&nfp_devlink_ops, sizeof(*pf));
368 if (!devlink) {
Jakub Kicinski63461a02017-02-09 09:17:38 -0800369 err = -ENOMEM;
370 goto err_rel_regions;
371 }
Simon Horman1851f93f2017-05-26 01:03:32 -0700372 pf = devlink_priv(devlink);
Jakub Kicinskid4e7f092017-05-22 10:59:24 -0700373 INIT_LIST_HEAD(&pf->vnics);
Jakub Kicinski3eb3b742017-05-22 10:59:31 -0700374 INIT_LIST_HEAD(&pf->ports);
Jakub Kicinski346cfe82017-05-26 01:03:31 -0700375 mutex_init(&pf->lock);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800376 pci_set_drvdata(pdev, pf);
377 pf->pdev = pdev;
378
379 pf->cpp = nfp_cpp_from_nfp6000_pcie(pdev);
380 if (IS_ERR_OR_NULL(pf->cpp)) {
381 err = PTR_ERR(pf->cpp);
382 if (err >= 0)
383 err = -ENOMEM;
384 goto err_disable_msix;
385 }
386
Jakub Kicinski9baa4882017-06-08 20:56:12 -0700387 pf->hwinfo = nfp_hwinfo_read(pf->cpp);
388
Jakub Kicinski64db09e2017-02-19 11:58:09 -0800389 dev_info(&pdev->dev, "Assembly: %s%s%s-%s CPLD: %s\n",
Jakub Kicinski9baa4882017-06-08 20:56:12 -0700390 nfp_hwinfo_lookup(pf->hwinfo, "assembly.vendor"),
391 nfp_hwinfo_lookup(pf->hwinfo, "assembly.partno"),
392 nfp_hwinfo_lookup(pf->hwinfo, "assembly.serial"),
393 nfp_hwinfo_lookup(pf->hwinfo, "assembly.revision"),
394 nfp_hwinfo_lookup(pf->hwinfo, "cpld.version"));
Jakub Kicinski64db09e2017-02-19 11:58:09 -0800395
Simon Horman1851f93f2017-05-26 01:03:32 -0700396 err = devlink_register(devlink, &pdev->dev);
Jakub Kicinskia9c83f72017-02-19 11:58:08 -0800397 if (err)
Jakub Kicinski9baa4882017-06-08 20:56:12 -0700398 goto err_hwinfo_free;
Jakub Kicinski63461a02017-02-09 09:17:38 -0800399
Simon Horman1851f93f2017-05-26 01:03:32 -0700400 err = nfp_nsp_init(pdev, pf);
401 if (err)
402 goto err_devlink_unreg;
403
Jakub Kicinski0be40e62017-06-08 20:56:13 -0700404 pf->mip = nfp_mip_open(pf->cpp);
405 pf->rtbl = __nfp_rtsym_table_read(pf->cpp, pf->mip);
Jakub Kicinskiaf4fa7e2017-06-08 20:56:11 -0700406
Jakub Kicinski651e1f22017-05-28 17:52:54 -0700407 err = nfp_pcie_sriov_read_nfd_limit(pf);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800408 if (err)
409 goto err_fw_unload;
410
Jakub Kicinski0dc78622017-06-27 00:50:25 -0700411 pf->num_vfs = pci_num_vf(pdev);
412 if (pf->num_vfs > pf->limit_vfs) {
413 dev_err(&pdev->dev,
414 "Error: %d VFs already enabled, but loaded FW can only support %d\n",
415 pf->num_vfs, pf->limit_vfs);
416 goto err_fw_unload;
417 }
418
Jakub Kicinski651e1f22017-05-28 17:52:54 -0700419 err = nfp_net_pci_probe(pf);
420 if (err)
421 goto err_sriov_unlimit;
422
David Bruneczeefbde72017-05-28 17:53:00 -0700423 err = nfp_hwmon_register(pf);
424 if (err) {
425 dev_err(&pdev->dev, "Failed to register hwmon info\n");
426 goto err_net_remove;
427 }
428
Jakub Kicinski63461a02017-02-09 09:17:38 -0800429 return 0;
430
David Bruneczeefbde72017-05-28 17:53:00 -0700431err_net_remove:
432 nfp_net_pci_remove(pf);
Jakub Kicinski651e1f22017-05-28 17:52:54 -0700433err_sriov_unlimit:
434 pci_sriov_set_totalvfs(pf->pdev, 0);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800435err_fw_unload:
Jakub Kicinskiaf4fa7e2017-06-08 20:56:11 -0700436 kfree(pf->rtbl);
Jakub Kicinski0be40e62017-06-08 20:56:13 -0700437 nfp_mip_close(pf->mip);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800438 if (pf->fw_loaded)
439 nfp_fw_unload(pf);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800440 kfree(pf->eth_tbl);
David Bruneczeefbde72017-05-28 17:53:00 -0700441 kfree(pf->nspi);
Simon Horman1851f93f2017-05-26 01:03:32 -0700442err_devlink_unreg:
443 devlink_unregister(devlink);
Jakub Kicinski9baa4882017-06-08 20:56:12 -0700444err_hwinfo_free:
445 kfree(pf->hwinfo);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800446 nfp_cpp_free(pf->cpp);
447err_disable_msix:
448 pci_set_drvdata(pdev, NULL);
Jakub Kicinski346cfe82017-05-26 01:03:31 -0700449 mutex_destroy(&pf->lock);
Simon Horman1851f93f2017-05-26 01:03:32 -0700450 devlink_free(devlink);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800451err_rel_regions:
452 pci_release_regions(pdev);
453err_pci_disable:
454 pci_disable_device(pdev);
455
456 return err;
457}
458
459static void nfp_pci_remove(struct pci_dev *pdev)
460{
461 struct nfp_pf *pf = pci_get_drvdata(pdev);
Simon Horman1851f93f2017-05-26 01:03:32 -0700462 struct devlink *devlink;
463
David Bruneczeefbde72017-05-28 17:53:00 -0700464 nfp_hwmon_unregister(pf);
465
Simon Horman1851f93f2017-05-26 01:03:32 -0700466 devlink = priv_to_devlink(pf);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800467
Jakub Kicinskie3f28472017-06-27 00:50:26 -0700468 nfp_net_pci_remove(pf);
469
Jakub Kicinski63461a02017-02-09 09:17:38 -0800470 nfp_pcie_sriov_disable(pdev);
Jakub Kicinski651e1f22017-05-28 17:52:54 -0700471 pci_sriov_set_totalvfs(pf->pdev, 0);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800472
Simon Horman1851f93f2017-05-26 01:03:32 -0700473 devlink_unregister(devlink);
474
Jakub Kicinskiaf4fa7e2017-06-08 20:56:11 -0700475 kfree(pf->rtbl);
Jakub Kicinski0be40e62017-06-08 20:56:13 -0700476 nfp_mip_close(pf->mip);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800477 if (pf->fw_loaded)
478 nfp_fw_unload(pf);
479
480 pci_set_drvdata(pdev, NULL);
Jakub Kicinski9baa4882017-06-08 20:56:12 -0700481 kfree(pf->hwinfo);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800482 nfp_cpp_free(pf->cpp);
483
484 kfree(pf->eth_tbl);
David Bruneczeefbde72017-05-28 17:53:00 -0700485 kfree(pf->nspi);
Jakub Kicinski346cfe82017-05-26 01:03:31 -0700486 mutex_destroy(&pf->lock);
Simon Horman1851f93f2017-05-26 01:03:32 -0700487 devlink_free(devlink);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800488 pci_release_regions(pdev);
489 pci_disable_device(pdev);
490}
491
492static struct pci_driver nfp_pci_driver = {
493 .name = nfp_driver_name,
494 .id_table = nfp_pci_device_ids,
495 .probe = nfp_pci_probe,
496 .remove = nfp_pci_remove,
497 .sriov_configure = nfp_pcie_sriov_configure,
498};
499
Jakub Kicinski2633beb2017-02-09 09:17:28 -0800500static int __init nfp_main_init(void)
501{
502 int err;
503
504 pr_info("%s: NFP PCIe Driver, Copyright (C) 2014-2017 Netronome Systems\n",
505 nfp_driver_name);
506
507 nfp_net_debugfs_create();
508
Jakub Kicinski63461a02017-02-09 09:17:38 -0800509 err = pci_register_driver(&nfp_pci_driver);
510 if (err < 0)
511 goto err_destroy_debugfs;
512
Jakub Kicinski2633beb2017-02-09 09:17:28 -0800513 err = pci_register_driver(&nfp_netvf_pci_driver);
514 if (err)
Jakub Kicinski63461a02017-02-09 09:17:38 -0800515 goto err_unreg_pf;
Jakub Kicinski2633beb2017-02-09 09:17:28 -0800516
517 return err;
518
Jakub Kicinski63461a02017-02-09 09:17:38 -0800519err_unreg_pf:
520 pci_unregister_driver(&nfp_pci_driver);
Jakub Kicinski2633beb2017-02-09 09:17:28 -0800521err_destroy_debugfs:
522 nfp_net_debugfs_destroy();
523 return err;
524}
525
526static void __exit nfp_main_exit(void)
527{
528 pci_unregister_driver(&nfp_netvf_pci_driver);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800529 pci_unregister_driver(&nfp_pci_driver);
Jakub Kicinski2633beb2017-02-09 09:17:28 -0800530 nfp_net_debugfs_destroy();
531}
532
533module_init(nfp_main_init);
534module_exit(nfp_main_exit);
535
Jakub Kicinski63461a02017-02-09 09:17:38 -0800536MODULE_FIRMWARE("netronome/nic_AMDA0081-0001_1x40.nffw");
537MODULE_FIRMWARE("netronome/nic_AMDA0081-0001_4x10.nffw");
538MODULE_FIRMWARE("netronome/nic_AMDA0096-0001_2x10.nffw");
539MODULE_FIRMWARE("netronome/nic_AMDA0097-0001_2x40.nffw");
540MODULE_FIRMWARE("netronome/nic_AMDA0097-0001_4x10_1x40.nffw");
541MODULE_FIRMWARE("netronome/nic_AMDA0097-0001_8x10.nffw");
542MODULE_FIRMWARE("netronome/nic_AMDA0099-0001_2x10.nffw");
543MODULE_FIRMWARE("netronome/nic_AMDA0099-0001_2x25.nffw");
544
Jakub Kicinski2633beb2017-02-09 09:17:28 -0800545MODULE_AUTHOR("Netronome Systems <oss-drivers@netronome.com>");
546MODULE_LICENSE("GPL");
547MODULE_DESCRIPTION("The Netronome Flow Processor (NFP) driver.");