blob: dd769eceb33d3a91ebb237aa4ccdb8b2de84ff0d [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
Jakub Kicinski1680a372017-07-26 11:09:48 -0700177static const struct firmware *
178nfp_net_fw_request(struct pci_dev *pdev, struct nfp_pf *pf, const char *name)
179{
180 const struct firmware *fw = NULL;
181 int err;
182
183 err = request_firmware_direct(&fw, name, &pdev->dev);
184 nfp_info(pf->cpp, " %s: %s\n",
185 name, err ? "not found" : "found, loading...");
186 if (err)
187 return NULL;
188
189 return fw;
190}
191
Jakub Kicinski63461a02017-02-09 09:17:38 -0800192/**
193 * nfp_net_fw_find() - Find the correct firmware image for netdev mode
194 * @pdev: PCI Device structure
195 * @pf: NFP PF Device structure
196 *
197 * Return: firmware if found and requested successfully.
198 */
199static const struct firmware *
200nfp_net_fw_find(struct pci_dev *pdev, struct nfp_pf *pf)
201{
Jakub Kicinski63461a02017-02-09 09:17:38 -0800202 struct nfp_eth_table_port *port;
Jakub Kicinski1680a372017-07-26 11:09:48 -0700203 const struct firmware *fw;
Jakub Kicinski63461a02017-02-09 09:17:38 -0800204 const char *fw_model;
205 char fw_name[256];
Jakub Kicinski9511f292017-07-26 11:09:47 -0700206 const u8 *serial;
Jakub Kicinski9511f292017-07-26 11:09:47 -0700207 u16 interface;
Jakub Kicinski1680a372017-07-26 11:09:48 -0700208 int spc, i, j;
209
210 nfp_info(pf->cpp, "Looking for firmware file in order of priority:\n");
Jakub Kicinski63461a02017-02-09 09:17:38 -0800211
Jakub Kicinski9511f292017-07-26 11:09:47 -0700212 /* First try to find a firmware image specific for this device */
213 interface = nfp_cpp_interface(pf->cpp);
214 nfp_cpp_serial(pf->cpp, &serial);
215 sprintf(fw_name, "netronome/serial-%pMF-%02hhx-%02hhx.nffw",
216 serial, interface >> 8, interface & 0xff);
Jakub Kicinski1680a372017-07-26 11:09:48 -0700217 fw = nfp_net_fw_request(pdev, pf, fw_name);
218 if (fw)
219 return fw;
Jakub Kicinski9511f292017-07-26 11:09:47 -0700220
221 /* Then try the PCI name */
222 sprintf(fw_name, "netronome/pci-%s.nffw", pci_name(pdev));
Jakub Kicinski1680a372017-07-26 11:09:48 -0700223 fw = nfp_net_fw_request(pdev, pf, fw_name);
224 if (fw)
225 return fw;
Jakub Kicinski9511f292017-07-26 11:09:47 -0700226
227 /* Finally try the card type and media */
Jakub Kicinski63461a02017-02-09 09:17:38 -0800228 if (!pf->eth_tbl) {
229 dev_err(&pdev->dev, "Error: can't identify media config\n");
230 return NULL;
231 }
232
Jakub Kicinski9baa4882017-06-08 20:56:12 -0700233 fw_model = nfp_hwinfo_lookup(pf->hwinfo, "assembly.partno");
Jakub Kicinski63461a02017-02-09 09:17:38 -0800234 if (!fw_model) {
235 dev_err(&pdev->dev, "Error: can't read part number\n");
236 return NULL;
237 }
238
239 spc = ARRAY_SIZE(fw_name);
240 spc -= snprintf(fw_name, spc, "netronome/nic_%s", fw_model);
241
242 for (i = 0; spc > 0 && i < pf->eth_tbl->count; i += j) {
243 port = &pf->eth_tbl->ports[i];
244 j = 1;
245 while (i + j < pf->eth_tbl->count &&
246 port->speed == port[j].speed)
247 j++;
248
249 spc -= snprintf(&fw_name[ARRAY_SIZE(fw_name) - spc], spc,
250 "_%dx%d", j, port->speed / 1000);
251 }
252
253 if (spc <= 0)
254 return NULL;
255
256 spc -= snprintf(&fw_name[ARRAY_SIZE(fw_name) - spc], spc, ".nffw");
257 if (spc <= 0)
258 return NULL;
259
Jakub Kicinski1680a372017-07-26 11:09:48 -0700260 return nfp_net_fw_request(pdev, pf, fw_name);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800261}
262
263/**
264 * nfp_net_fw_load() - Load the firmware image
265 * @pdev: PCI Device structure
266 * @pf: NFP PF Device structure
267 * @nsp: NFP SP handle
268 *
269 * Return: -ERRNO, 0 for no firmware loaded, 1 for firmware loaded
270 */
271static int
272nfp_fw_load(struct pci_dev *pdev, struct nfp_pf *pf, struct nfp_nsp *nsp)
273{
274 const struct firmware *fw;
275 u16 interface;
276 int err;
277
278 interface = nfp_cpp_interface(pf->cpp);
279 if (NFP_CPP_INTERFACE_UNIT_of(interface) != 0) {
280 /* Only Unit 0 should reset or load firmware */
281 dev_info(&pdev->dev, "Firmware will be loaded by partner\n");
282 return 0;
283 }
284
285 fw = nfp_net_fw_find(pdev, pf);
286 if (!fw)
287 return 0;
288
289 dev_info(&pdev->dev, "Soft-reset, loading FW image\n");
290 err = nfp_nsp_device_soft_reset(nsp);
291 if (err < 0) {
292 dev_err(&pdev->dev, "Failed to soft reset the NFP: %d\n",
293 err);
294 goto exit_release_fw;
295 }
296
297 err = nfp_nsp_load_fw(nsp, fw);
298
299 if (err < 0) {
300 dev_err(&pdev->dev, "FW loading failed: %d\n", err);
301 goto exit_release_fw;
302 }
303
304 dev_info(&pdev->dev, "Finished loading FW image\n");
305
306exit_release_fw:
307 release_firmware(fw);
308
309 return err < 0 ? err : 1;
310}
311
Jakub Kicinskia9c83f72017-02-19 11:58:08 -0800312static int nfp_nsp_init(struct pci_dev *pdev, struct nfp_pf *pf)
313{
314 struct nfp_nsp *nsp;
315 int err;
316
317 nsp = nfp_nsp_open(pf->cpp);
318 if (IS_ERR(nsp)) {
319 err = PTR_ERR(nsp);
320 dev_err(&pdev->dev, "Failed to access the NSP: %d\n", err);
321 return err;
322 }
323
324 err = nfp_nsp_wait(nsp);
325 if (err < 0)
326 goto exit_close_nsp;
327
328 pf->eth_tbl = __nfp_eth_read_ports(pf->cpp, nsp);
329
David Bruneczeefbde72017-05-28 17:53:00 -0700330 pf->nspi = __nfp_nsp_identify(nsp);
331 if (pf->nspi)
332 dev_info(&pdev->dev, "BSP: %s\n", pf->nspi->version);
David Brunecz010e2f92017-04-22 20:17:54 -0700333
Jakub Kicinskia9c83f72017-02-19 11:58:08 -0800334 err = nfp_fw_load(pdev, pf, nsp);
335 if (err < 0) {
Jakub Kicinski47eaa232017-05-31 08:06:51 -0700336 kfree(pf->nspi);
Jakub Kicinskia9c83f72017-02-19 11:58:08 -0800337 kfree(pf->eth_tbl);
338 dev_err(&pdev->dev, "Failed to load FW\n");
339 goto exit_close_nsp;
340 }
341
342 pf->fw_loaded = !!err;
343 err = 0;
344
345exit_close_nsp:
346 nfp_nsp_close(nsp);
347
348 return err;
349}
350
Jakub Kicinski63461a02017-02-09 09:17:38 -0800351static void nfp_fw_unload(struct nfp_pf *pf)
352{
353 struct nfp_nsp *nsp;
354 int err;
355
356 nsp = nfp_nsp_open(pf->cpp);
357 if (IS_ERR(nsp)) {
358 nfp_err(pf->cpp, "Reset failed, can't open NSP\n");
359 return;
360 }
361
362 err = nfp_nsp_device_soft_reset(nsp);
363 if (err < 0)
364 dev_warn(&pf->pdev->dev, "Couldn't unload firmware: %d\n", err);
365 else
366 dev_info(&pf->pdev->dev, "Firmware safely unloaded\n");
367
368 nfp_nsp_close(nsp);
369}
370
371static int nfp_pci_probe(struct pci_dev *pdev,
372 const struct pci_device_id *pci_id)
373{
Simon Horman1851f93f2017-05-26 01:03:32 -0700374 struct devlink *devlink;
Jakub Kicinski63461a02017-02-09 09:17:38 -0800375 struct nfp_pf *pf;
376 int err;
377
378 err = pci_enable_device(pdev);
379 if (err < 0)
380 return err;
381
382 pci_set_master(pdev);
383
384 err = dma_set_mask_and_coherent(&pdev->dev,
385 DMA_BIT_MASK(NFP_NET_MAX_DMA_BITS));
386 if (err)
387 goto err_pci_disable;
388
389 err = pci_request_regions(pdev, nfp_driver_name);
390 if (err < 0) {
391 dev_err(&pdev->dev, "Unable to reserve pci resources.\n");
392 goto err_pci_disable;
393 }
394
Simon Horman1851f93f2017-05-26 01:03:32 -0700395 devlink = devlink_alloc(&nfp_devlink_ops, sizeof(*pf));
396 if (!devlink) {
Jakub Kicinski63461a02017-02-09 09:17:38 -0800397 err = -ENOMEM;
398 goto err_rel_regions;
399 }
Simon Horman1851f93f2017-05-26 01:03:32 -0700400 pf = devlink_priv(devlink);
Jakub Kicinskid4e7f092017-05-22 10:59:24 -0700401 INIT_LIST_HEAD(&pf->vnics);
Jakub Kicinski3eb3b742017-05-22 10:59:31 -0700402 INIT_LIST_HEAD(&pf->ports);
Jakub Kicinski346cfe82017-05-26 01:03:31 -0700403 mutex_init(&pf->lock);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800404 pci_set_drvdata(pdev, pf);
405 pf->pdev = pdev;
406
Jakub Kicinski6d48ceb2017-06-27 00:50:27 -0700407 pf->wq = alloc_workqueue("nfp-%s", 0, 2, pci_name(pdev));
408 if (!pf->wq) {
409 err = -ENOMEM;
410 goto err_pci_priv_unset;
411 }
412
Jakub Kicinski63461a02017-02-09 09:17:38 -0800413 pf->cpp = nfp_cpp_from_nfp6000_pcie(pdev);
414 if (IS_ERR_OR_NULL(pf->cpp)) {
415 err = PTR_ERR(pf->cpp);
416 if (err >= 0)
417 err = -ENOMEM;
418 goto err_disable_msix;
419 }
420
Jakub Kicinski9baa4882017-06-08 20:56:12 -0700421 pf->hwinfo = nfp_hwinfo_read(pf->cpp);
422
Jakub Kicinski64db09e2017-02-19 11:58:09 -0800423 dev_info(&pdev->dev, "Assembly: %s%s%s-%s CPLD: %s\n",
Jakub Kicinski9baa4882017-06-08 20:56:12 -0700424 nfp_hwinfo_lookup(pf->hwinfo, "assembly.vendor"),
425 nfp_hwinfo_lookup(pf->hwinfo, "assembly.partno"),
426 nfp_hwinfo_lookup(pf->hwinfo, "assembly.serial"),
427 nfp_hwinfo_lookup(pf->hwinfo, "assembly.revision"),
428 nfp_hwinfo_lookup(pf->hwinfo, "cpld.version"));
Jakub Kicinski64db09e2017-02-19 11:58:09 -0800429
Simon Horman1851f93f2017-05-26 01:03:32 -0700430 err = devlink_register(devlink, &pdev->dev);
Jakub Kicinskia9c83f72017-02-19 11:58:08 -0800431 if (err)
Jakub Kicinski9baa4882017-06-08 20:56:12 -0700432 goto err_hwinfo_free;
Jakub Kicinski63461a02017-02-09 09:17:38 -0800433
Simon Horman1851f93f2017-05-26 01:03:32 -0700434 err = nfp_nsp_init(pdev, pf);
435 if (err)
436 goto err_devlink_unreg;
437
Jakub Kicinski0be40e62017-06-08 20:56:13 -0700438 pf->mip = nfp_mip_open(pf->cpp);
439 pf->rtbl = __nfp_rtsym_table_read(pf->cpp, pf->mip);
Jakub Kicinskiaf4fa7e2017-06-08 20:56:11 -0700440
Jakub Kicinski651e1f22017-05-28 17:52:54 -0700441 err = nfp_pcie_sriov_read_nfd_limit(pf);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800442 if (err)
443 goto err_fw_unload;
444
Jakub Kicinski0dc78622017-06-27 00:50:25 -0700445 pf->num_vfs = pci_num_vf(pdev);
446 if (pf->num_vfs > pf->limit_vfs) {
447 dev_err(&pdev->dev,
448 "Error: %d VFs already enabled, but loaded FW can only support %d\n",
449 pf->num_vfs, pf->limit_vfs);
450 goto err_fw_unload;
451 }
452
Jakub Kicinski651e1f22017-05-28 17:52:54 -0700453 err = nfp_net_pci_probe(pf);
454 if (err)
455 goto err_sriov_unlimit;
456
David Bruneczeefbde72017-05-28 17:53:00 -0700457 err = nfp_hwmon_register(pf);
458 if (err) {
459 dev_err(&pdev->dev, "Failed to register hwmon info\n");
460 goto err_net_remove;
461 }
462
Jakub Kicinski63461a02017-02-09 09:17:38 -0800463 return 0;
464
David Bruneczeefbde72017-05-28 17:53:00 -0700465err_net_remove:
466 nfp_net_pci_remove(pf);
Jakub Kicinski651e1f22017-05-28 17:52:54 -0700467err_sriov_unlimit:
468 pci_sriov_set_totalvfs(pf->pdev, 0);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800469err_fw_unload:
Jakub Kicinskiaf4fa7e2017-06-08 20:56:11 -0700470 kfree(pf->rtbl);
Jakub Kicinski0be40e62017-06-08 20:56:13 -0700471 nfp_mip_close(pf->mip);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800472 if (pf->fw_loaded)
473 nfp_fw_unload(pf);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800474 kfree(pf->eth_tbl);
David Bruneczeefbde72017-05-28 17:53:00 -0700475 kfree(pf->nspi);
Simon Horman1851f93f2017-05-26 01:03:32 -0700476err_devlink_unreg:
477 devlink_unregister(devlink);
Jakub Kicinski9baa4882017-06-08 20:56:12 -0700478err_hwinfo_free:
479 kfree(pf->hwinfo);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800480 nfp_cpp_free(pf->cpp);
481err_disable_msix:
Jakub Kicinski6d48ceb2017-06-27 00:50:27 -0700482 destroy_workqueue(pf->wq);
483err_pci_priv_unset:
Jakub Kicinski63461a02017-02-09 09:17:38 -0800484 pci_set_drvdata(pdev, NULL);
Jakub Kicinski346cfe82017-05-26 01:03:31 -0700485 mutex_destroy(&pf->lock);
Simon Horman1851f93f2017-05-26 01:03:32 -0700486 devlink_free(devlink);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800487err_rel_regions:
488 pci_release_regions(pdev);
489err_pci_disable:
490 pci_disable_device(pdev);
491
492 return err;
493}
494
495static void nfp_pci_remove(struct pci_dev *pdev)
496{
497 struct nfp_pf *pf = pci_get_drvdata(pdev);
Simon Horman1851f93f2017-05-26 01:03:32 -0700498 struct devlink *devlink;
499
David Bruneczeefbde72017-05-28 17:53:00 -0700500 nfp_hwmon_unregister(pf);
501
Simon Horman1851f93f2017-05-26 01:03:32 -0700502 devlink = priv_to_devlink(pf);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800503
Jakub Kicinskie3f28472017-06-27 00:50:26 -0700504 nfp_net_pci_remove(pf);
505
Jakub Kicinski63461a02017-02-09 09:17:38 -0800506 nfp_pcie_sriov_disable(pdev);
Jakub Kicinski651e1f22017-05-28 17:52:54 -0700507 pci_sriov_set_totalvfs(pf->pdev, 0);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800508
Simon Horman1851f93f2017-05-26 01:03:32 -0700509 devlink_unregister(devlink);
510
Jakub Kicinskiaf4fa7e2017-06-08 20:56:11 -0700511 kfree(pf->rtbl);
Jakub Kicinski0be40e62017-06-08 20:56:13 -0700512 nfp_mip_close(pf->mip);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800513 if (pf->fw_loaded)
514 nfp_fw_unload(pf);
515
Jakub Kicinski6d48ceb2017-06-27 00:50:27 -0700516 destroy_workqueue(pf->wq);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800517 pci_set_drvdata(pdev, NULL);
Jakub Kicinski9baa4882017-06-08 20:56:12 -0700518 kfree(pf->hwinfo);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800519 nfp_cpp_free(pf->cpp);
520
521 kfree(pf->eth_tbl);
David Bruneczeefbde72017-05-28 17:53:00 -0700522 kfree(pf->nspi);
Jakub Kicinski346cfe82017-05-26 01:03:31 -0700523 mutex_destroy(&pf->lock);
Simon Horman1851f93f2017-05-26 01:03:32 -0700524 devlink_free(devlink);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800525 pci_release_regions(pdev);
526 pci_disable_device(pdev);
527}
528
529static struct pci_driver nfp_pci_driver = {
530 .name = nfp_driver_name,
531 .id_table = nfp_pci_device_ids,
532 .probe = nfp_pci_probe,
533 .remove = nfp_pci_remove,
534 .sriov_configure = nfp_pcie_sriov_configure,
535};
536
Jakub Kicinski2633beb2017-02-09 09:17:28 -0800537static int __init nfp_main_init(void)
538{
539 int err;
540
541 pr_info("%s: NFP PCIe Driver, Copyright (C) 2014-2017 Netronome Systems\n",
542 nfp_driver_name);
543
544 nfp_net_debugfs_create();
545
Jakub Kicinski63461a02017-02-09 09:17:38 -0800546 err = pci_register_driver(&nfp_pci_driver);
547 if (err < 0)
548 goto err_destroy_debugfs;
549
Jakub Kicinski2633beb2017-02-09 09:17:28 -0800550 err = pci_register_driver(&nfp_netvf_pci_driver);
551 if (err)
Jakub Kicinski63461a02017-02-09 09:17:38 -0800552 goto err_unreg_pf;
Jakub Kicinski2633beb2017-02-09 09:17:28 -0800553
554 return err;
555
Jakub Kicinski63461a02017-02-09 09:17:38 -0800556err_unreg_pf:
557 pci_unregister_driver(&nfp_pci_driver);
Jakub Kicinski2633beb2017-02-09 09:17:28 -0800558err_destroy_debugfs:
559 nfp_net_debugfs_destroy();
560 return err;
561}
562
563static void __exit nfp_main_exit(void)
564{
565 pci_unregister_driver(&nfp_netvf_pci_driver);
Jakub Kicinski63461a02017-02-09 09:17:38 -0800566 pci_unregister_driver(&nfp_pci_driver);
Jakub Kicinski2633beb2017-02-09 09:17:28 -0800567 nfp_net_debugfs_destroy();
568}
569
570module_init(nfp_main_init);
571module_exit(nfp_main_exit);
572
Jakub Kicinski63461a02017-02-09 09:17:38 -0800573MODULE_FIRMWARE("netronome/nic_AMDA0081-0001_1x40.nffw");
574MODULE_FIRMWARE("netronome/nic_AMDA0081-0001_4x10.nffw");
575MODULE_FIRMWARE("netronome/nic_AMDA0096-0001_2x10.nffw");
576MODULE_FIRMWARE("netronome/nic_AMDA0097-0001_2x40.nffw");
577MODULE_FIRMWARE("netronome/nic_AMDA0097-0001_4x10_1x40.nffw");
578MODULE_FIRMWARE("netronome/nic_AMDA0097-0001_8x10.nffw");
579MODULE_FIRMWARE("netronome/nic_AMDA0099-0001_2x10.nffw");
580MODULE_FIRMWARE("netronome/nic_AMDA0099-0001_2x25.nffw");
581
Jakub Kicinski2633beb2017-02-09 09:17:28 -0800582MODULE_AUTHOR("Netronome Systems <oss-drivers@netronome.com>");
583MODULE_LICENSE("GPL");
584MODULE_DESCRIPTION("The Netronome Flow Processor (NFP) driver.");