forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/net/ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c
....@@ -1,35 +1,5 @@
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. */
333
344 /*
355 * nfp6000_pcie.c
....@@ -138,6 +108,7 @@
138108
139109 /* The number of explicit BARs to reserve.
140110 * Minimum is 0, maximum is 4 on the NFP6000.
111
+ * The NFP3800 can have only one per PF.
141112 */
142113 #define NFP_PCIE_EXPLICIT_BARS 2
143114
....@@ -369,12 +340,12 @@
369340 switch (maptype) {
370341 case NFP_PCIE_BAR_PCIE2CPP_MapType_TARGET:
371342 bartok = -1;
372
- /* FALLTHROUGH */
343
+ fallthrough;
373344 case NFP_PCIE_BAR_PCIE2CPP_MapType_BULK:
374345 baract = NFP_CPP_ACTION_RW;
375346 if (act == 0)
376347 act = NFP_CPP_ACTION_RW;
377
- /* FALLTHROUGH */
348
+ fallthrough;
378349 case NFP_PCIE_BAR_PCIE2CPP_MapType_FIXED:
379350 break;
380351 default:
....@@ -589,8 +560,8 @@
589560 NFP_PCIE_BAR_PCIE2CPP_MapType_EXPLICIT3),
590561 };
591562 char status_msg[196] = {};
563
+ int i, err, bars_free;
592564 struct nfp_bar *bar;
593
- int i, bars_free;
594565 int expl_groups;
595566 char *msg, *end;
596567
....@@ -640,10 +611,12 @@
640611 /* Configure, and lock, BAR0.0 for General Target use (MSI-X SRAM) */
641612 bar = &nfp->bar[0];
642613 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),
644615 nfp_bar_resource_len(bar));
645616 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, ");
647620 atomic_inc(&bar->refcnt);
648621 bars_free--;
649622
....@@ -651,26 +624,44 @@
651624
652625 nfp->expl.data = bar->iomem + NFP_PCIE_SRAM + 0x1000;
653626
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;
660630 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;
661642 }
662643 nfp->iomem.em = bar->iomem + NFP_PCIE_EM;
663644 }
664645
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:
669648 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
+ }
670661
671662 /* Configure, and lock, BAR0.1 for PCIe XPB (MSI-X PBA) */
672663 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, ");
674665 atomic_inc(&bar->refcnt);
675666 bars_free--;
676667
....@@ -686,11 +677,11 @@
686677 }
687678
688679 bar = &nfp->bar[4 + i];
689
- bar->iomem = ioremap_nocache(nfp_bar_resource_start(bar),
680
+ bar->iomem = ioremap(nfp_bar_resource_start(bar),
690681 nfp_bar_resource_len(bar));
691682 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);
694685 atomic_inc(&bar->refcnt);
695686 bars_free--;
696687
....@@ -711,6 +702,11 @@
711702 dev_info(nfp->dev, "%sfree: %d/%d\n", status_msg, bars_free, nfp->bars);
712703
713704 return 0;
705
+
706
+err_unmap_bar0:
707
+ if (nfp->bar[0].iomem)
708
+ iounmap(nfp->bar[0].iomem);
709
+ return err;
714710 }
715711
716712 static void disable_bars(struct nfp6000_pcie *nfp)
....@@ -862,7 +858,7 @@
862858 priv->iomem = priv->bar->iomem + priv->bar_offset;
863859 else
864860 /* Must have been too big. Sub-allocate. */
865
- priv->iomem = ioremap_nocache(priv->phys, priv->size);
861
+ priv->iomem = ioremap(priv->phys, priv->size);
866862
867863 if (IS_ERR_OR_NULL(priv->iomem)) {
868864 dev_err(nfp->dev, "Can't ioremap() a %d byte region of BAR %d\n",
....@@ -1251,19 +1247,16 @@
12511247 static int nfp6000_read_serial(struct device *dev, u8 *serial)
12521248 {
12531249 struct pci_dev *pdev = to_pci_dev(dev);
1254
- int pos;
1255
- u32 reg;
1250
+ u64 dsn;
12561251
1257
- pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_DSN);
1258
- if (!pos) {
1252
+ dsn = pci_get_dsn(pdev);
1253
+ if (!dsn) {
12591254 dev_err(dev, "can't find PCIe Serial Number Capability\n");
12601255 return -EINVAL;
12611256 }
12621257
1263
- pci_read_config_dword(pdev, pos + 4, &reg);
1264
- put_unaligned_be16(reg >> 16, serial + 4);
1265
- pci_read_config_dword(pdev, pos + 8, &reg);
1266
- put_unaligned_be32(reg, serial);
1258
+ put_unaligned_be32((u32)(dsn >> 32), serial);
1259
+ put_unaligned_be16((u16)(dsn >> 16), serial + 4);
12671260
12681261 return 0;
12691262 }
....@@ -1271,18 +1264,15 @@
12711264 static int nfp6000_get_interface(struct device *dev)
12721265 {
12731266 struct pci_dev *pdev = to_pci_dev(dev);
1274
- int pos;
1275
- u32 reg;
1267
+ u64 dsn;
12761268
1277
- pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_DSN);
1278
- if (!pos) {
1269
+ dsn = pci_get_dsn(pdev);
1270
+ if (!dsn) {
12791271 dev_err(dev, "can't find PCIe Serial Number Capability\n");
12801272 return -EINVAL;
12811273 }
12821274
1283
- pci_read_config_dword(pdev, pos + 4, &reg);
1284
-
1285
- return reg & 0xffff;
1275
+ return dsn & 0xffff;
12861276 }
12871277
12881278 static const struct nfp_cpp_operations nfp6000_pcie_ops = {
....@@ -1327,7 +1317,7 @@
13271317
13281318 /* Finished with card initialization. */
13291319 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");
13311321 pcie_print_link_status(pdev);
13321322
13331323 nfp = kzalloc(sizeof(*nfp), GFP_KERNEL);