.. | .. |
---|
1 | | -/* |
---|
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 | | - */ |
---|
| 1 | +// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) |
---|
| 2 | +/* Copyright (C) 2015-2018 Netronome Systems, Inc. */ |
---|
33 | 3 | |
---|
34 | 4 | /* |
---|
35 | 5 | * nfp6000_pcie.c |
---|
.. | .. |
---|
138 | 108 | |
---|
139 | 109 | /* The number of explicit BARs to reserve. |
---|
140 | 110 | * Minimum is 0, maximum is 4 on the NFP6000. |
---|
| 111 | + * The NFP3800 can have only one per PF. |
---|
141 | 112 | */ |
---|
142 | 113 | #define NFP_PCIE_EXPLICIT_BARS 2 |
---|
143 | 114 | |
---|
.. | .. |
---|
369 | 340 | switch (maptype) { |
---|
370 | 341 | case NFP_PCIE_BAR_PCIE2CPP_MapType_TARGET: |
---|
371 | 342 | bartok = -1; |
---|
372 | | - /* FALLTHROUGH */ |
---|
| 343 | + fallthrough; |
---|
373 | 344 | case NFP_PCIE_BAR_PCIE2CPP_MapType_BULK: |
---|
374 | 345 | baract = NFP_CPP_ACTION_RW; |
---|
375 | 346 | if (act == 0) |
---|
376 | 347 | act = NFP_CPP_ACTION_RW; |
---|
377 | | - /* FALLTHROUGH */ |
---|
| 348 | + fallthrough; |
---|
378 | 349 | case NFP_PCIE_BAR_PCIE2CPP_MapType_FIXED: |
---|
379 | 350 | break; |
---|
380 | 351 | default: |
---|
.. | .. |
---|
589 | 560 | NFP_PCIE_BAR_PCIE2CPP_MapType_EXPLICIT3), |
---|
590 | 561 | }; |
---|
591 | 562 | char status_msg[196] = {}; |
---|
| 563 | + int i, err, bars_free; |
---|
592 | 564 | struct nfp_bar *bar; |
---|
593 | | - int i, bars_free; |
---|
594 | 565 | int expl_groups; |
---|
595 | 566 | char *msg, *end; |
---|
596 | 567 | |
---|
.. | .. |
---|
640 | 611 | /* Configure, and lock, BAR0.0 for General Target use (MSI-X SRAM) */ |
---|
641 | 612 | bar = &nfp->bar[0]; |
---|
642 | 613 | if (nfp_bar_resource_len(bar) >= NFP_PCI_MIN_MAP_SIZE) |
---|
643 | | - bar->iomem = ioremap_nocache(nfp_bar_resource_start(bar), |
---|
| 614 | + bar->iomem = ioremap(nfp_bar_resource_start(bar), |
---|
644 | 615 | nfp_bar_resource_len(bar)); |
---|
645 | 616 | if (bar->iomem) { |
---|
646 | | - msg += snprintf(msg, end - msg, "0.0: General/MSI-X SRAM, "); |
---|
| 617 | + int pf; |
---|
| 618 | + |
---|
| 619 | + msg += scnprintf(msg, end - msg, "0.0: General/MSI-X SRAM, "); |
---|
647 | 620 | atomic_inc(&bar->refcnt); |
---|
648 | 621 | bars_free--; |
---|
649 | 622 | |
---|
.. | .. |
---|
651 | 624 | |
---|
652 | 625 | nfp->expl.data = bar->iomem + NFP_PCIE_SRAM + 0x1000; |
---|
653 | 626 | |
---|
654 | | - if (nfp->pdev->device == PCI_DEVICE_ID_NETRONOME_NFP4000 || |
---|
655 | | - nfp->pdev->device == PCI_DEVICE_ID_NETRONOME_NFP6000) { |
---|
656 | | - nfp->iomem.csr = bar->iomem + NFP_PCIE_BAR(0); |
---|
657 | | - } else { |
---|
658 | | - int pf = nfp->pdev->devfn & 7; |
---|
659 | | - |
---|
| 627 | + switch (nfp->pdev->device) { |
---|
| 628 | + case PCI_DEVICE_ID_NETRONOME_NFP3800: |
---|
| 629 | + pf = nfp->pdev->devfn & 7; |
---|
660 | 630 | nfp->iomem.csr = bar->iomem + NFP_PCIE_BAR(pf); |
---|
| 631 | + break; |
---|
| 632 | + case PCI_DEVICE_ID_NETRONOME_NFP4000: |
---|
| 633 | + case PCI_DEVICE_ID_NETRONOME_NFP5000: |
---|
| 634 | + case PCI_DEVICE_ID_NETRONOME_NFP6000: |
---|
| 635 | + nfp->iomem.csr = bar->iomem + NFP_PCIE_BAR(0); |
---|
| 636 | + break; |
---|
| 637 | + default: |
---|
| 638 | + dev_err(nfp->dev, "Unsupported device ID: %04hx!\n", |
---|
| 639 | + nfp->pdev->device); |
---|
| 640 | + err = -EINVAL; |
---|
| 641 | + goto err_unmap_bar0; |
---|
661 | 642 | } |
---|
662 | 643 | nfp->iomem.em = bar->iomem + NFP_PCIE_EM; |
---|
663 | 644 | } |
---|
664 | 645 | |
---|
665 | | - if (nfp->pdev->device == PCI_DEVICE_ID_NETRONOME_NFP4000 || |
---|
666 | | - nfp->pdev->device == PCI_DEVICE_ID_NETRONOME_NFP6000) |
---|
667 | | - expl_groups = 4; |
---|
668 | | - else |
---|
| 646 | + switch (nfp->pdev->device) { |
---|
| 647 | + case PCI_DEVICE_ID_NETRONOME_NFP3800: |
---|
669 | 648 | expl_groups = 1; |
---|
| 649 | + break; |
---|
| 650 | + case PCI_DEVICE_ID_NETRONOME_NFP4000: |
---|
| 651 | + case PCI_DEVICE_ID_NETRONOME_NFP5000: |
---|
| 652 | + case PCI_DEVICE_ID_NETRONOME_NFP6000: |
---|
| 653 | + expl_groups = 4; |
---|
| 654 | + break; |
---|
| 655 | + default: |
---|
| 656 | + dev_err(nfp->dev, "Unsupported device ID: %04hx!\n", |
---|
| 657 | + nfp->pdev->device); |
---|
| 658 | + err = -EINVAL; |
---|
| 659 | + goto err_unmap_bar0; |
---|
| 660 | + } |
---|
670 | 661 | |
---|
671 | 662 | /* Configure, and lock, BAR0.1 for PCIe XPB (MSI-X PBA) */ |
---|
672 | 663 | bar = &nfp->bar[1]; |
---|
673 | | - msg += snprintf(msg, end - msg, "0.1: PCIe XPB/MSI-X PBA, "); |
---|
| 664 | + msg += scnprintf(msg, end - msg, "0.1: PCIe XPB/MSI-X PBA, "); |
---|
674 | 665 | atomic_inc(&bar->refcnt); |
---|
675 | 666 | bars_free--; |
---|
676 | 667 | |
---|
.. | .. |
---|
686 | 677 | } |
---|
687 | 678 | |
---|
688 | 679 | bar = &nfp->bar[4 + i]; |
---|
689 | | - bar->iomem = ioremap_nocache(nfp_bar_resource_start(bar), |
---|
| 680 | + bar->iomem = ioremap(nfp_bar_resource_start(bar), |
---|
690 | 681 | nfp_bar_resource_len(bar)); |
---|
691 | 682 | if (bar->iomem) { |
---|
692 | | - msg += snprintf(msg, end - msg, |
---|
693 | | - "0.%d: Explicit%d, ", 4 + i, i); |
---|
| 683 | + msg += scnprintf(msg, end - msg, |
---|
| 684 | + "0.%d: Explicit%d, ", 4 + i, i); |
---|
694 | 685 | atomic_inc(&bar->refcnt); |
---|
695 | 686 | bars_free--; |
---|
696 | 687 | |
---|
.. | .. |
---|
711 | 702 | dev_info(nfp->dev, "%sfree: %d/%d\n", status_msg, bars_free, nfp->bars); |
---|
712 | 703 | |
---|
713 | 704 | return 0; |
---|
| 705 | + |
---|
| 706 | +err_unmap_bar0: |
---|
| 707 | + if (nfp->bar[0].iomem) |
---|
| 708 | + iounmap(nfp->bar[0].iomem); |
---|
| 709 | + return err; |
---|
714 | 710 | } |
---|
715 | 711 | |
---|
716 | 712 | static void disable_bars(struct nfp6000_pcie *nfp) |
---|
.. | .. |
---|
862 | 858 | priv->iomem = priv->bar->iomem + priv->bar_offset; |
---|
863 | 859 | else |
---|
864 | 860 | /* Must have been too big. Sub-allocate. */ |
---|
865 | | - priv->iomem = ioremap_nocache(priv->phys, priv->size); |
---|
| 861 | + priv->iomem = ioremap(priv->phys, priv->size); |
---|
866 | 862 | |
---|
867 | 863 | if (IS_ERR_OR_NULL(priv->iomem)) { |
---|
868 | 864 | dev_err(nfp->dev, "Can't ioremap() a %d byte region of BAR %d\n", |
---|
.. | .. |
---|
1251 | 1247 | static int nfp6000_read_serial(struct device *dev, u8 *serial) |
---|
1252 | 1248 | { |
---|
1253 | 1249 | struct pci_dev *pdev = to_pci_dev(dev); |
---|
1254 | | - int pos; |
---|
1255 | | - u32 reg; |
---|
| 1250 | + u64 dsn; |
---|
1256 | 1251 | |
---|
1257 | | - pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_DSN); |
---|
1258 | | - if (!pos) { |
---|
| 1252 | + dsn = pci_get_dsn(pdev); |
---|
| 1253 | + if (!dsn) { |
---|
1259 | 1254 | dev_err(dev, "can't find PCIe Serial Number Capability\n"); |
---|
1260 | 1255 | return -EINVAL; |
---|
1261 | 1256 | } |
---|
1262 | 1257 | |
---|
1263 | | - pci_read_config_dword(pdev, pos + 4, ®); |
---|
1264 | | - put_unaligned_be16(reg >> 16, serial + 4); |
---|
1265 | | - pci_read_config_dword(pdev, pos + 8, ®); |
---|
1266 | | - put_unaligned_be32(reg, serial); |
---|
| 1258 | + put_unaligned_be32((u32)(dsn >> 32), serial); |
---|
| 1259 | + put_unaligned_be16((u16)(dsn >> 16), serial + 4); |
---|
1267 | 1260 | |
---|
1268 | 1261 | return 0; |
---|
1269 | 1262 | } |
---|
.. | .. |
---|
1271 | 1264 | static int nfp6000_get_interface(struct device *dev) |
---|
1272 | 1265 | { |
---|
1273 | 1266 | struct pci_dev *pdev = to_pci_dev(dev); |
---|
1274 | | - int pos; |
---|
1275 | | - u32 reg; |
---|
| 1267 | + u64 dsn; |
---|
1276 | 1268 | |
---|
1277 | | - pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_DSN); |
---|
1278 | | - if (!pos) { |
---|
| 1269 | + dsn = pci_get_dsn(pdev); |
---|
| 1270 | + if (!dsn) { |
---|
1279 | 1271 | dev_err(dev, "can't find PCIe Serial Number Capability\n"); |
---|
1280 | 1272 | return -EINVAL; |
---|
1281 | 1273 | } |
---|
1282 | 1274 | |
---|
1283 | | - pci_read_config_dword(pdev, pos + 4, ®); |
---|
1284 | | - |
---|
1285 | | - return reg & 0xffff; |
---|
| 1275 | + return dsn & 0xffff; |
---|
1286 | 1276 | } |
---|
1287 | 1277 | |
---|
1288 | 1278 | static const struct nfp_cpp_operations nfp6000_pcie_ops = { |
---|
.. | .. |
---|
1327 | 1317 | |
---|
1328 | 1318 | /* Finished with card initialization. */ |
---|
1329 | 1319 | dev_info(&pdev->dev, |
---|
1330 | | - "Netronome Flow Processor NFP4000/NFP6000 PCIe Card Probe\n"); |
---|
| 1320 | + "Netronome Flow Processor NFP4000/NFP5000/NFP6000 PCIe Card Probe\n"); |
---|
1331 | 1321 | pcie_print_link_status(pdev); |
---|
1332 | 1322 | |
---|
1333 | 1323 | nfp = kzalloc(sizeof(*nfp), GFP_KERNEL); |
---|