Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/pci Use pci_compatible_match().



details:   https://anonhg.NetBSD.org/src/rev/fb9f2f618a7a
branches:  trunk
changeset: 379064:fb9f2f618a7a
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sat May 08 00:27:02 2021 +0000

description:
Use pci_compatible_match().

diffstat:

 sys/dev/pci/if_bwfm_pci.c |   25 +--
 sys/dev/pci/if_bwi_pci.c  |   65 +++++++---
 sys/dev/pci/if_cas.c      |   49 +++-----
 sys/dev/pci/if_dge.c      |   71 +++++-------
 sys/dev/pci/if_et.c       |   35 ++---
 sys/dev/pci/if_fxp_pci.c  |  260 ++++++++++++++++++++++++---------------------
 sys/dev/pci/if_iwi.c      |   32 +++--
 sys/dev/pci/if_iwn.c      |  179 ++++++++++++++++++++++---------
 sys/dev/pci/if_jme.c      |   56 +++------
 sys/dev/pci/if_kse.c      |   22 ++-
 sys/dev/pci/if_malo_pci.c |   27 ++--
 sys/dev/pci/if_msk.c      |  152 +++++++++++++++----------
 sys/dev/pci/if_mtd_pci.c  |   22 +--
 sys/dev/pci/if_rge.c      |   24 +--
 sys/dev/pci/if_sk.c       |   62 +++++-----
 sys/dev/pci/if_tlp_pci.c  |  158 ++++++++++++++-------------
 sys/dev/pci/if_vr.c       |   50 +++-----
 17 files changed, 681 insertions(+), 608 deletions(-)

diffs (truncated from 1938 to 300 lines):

diff -r 324307c52402 -r fb9f2f618a7a sys/dev/pci/if_bwfm_pci.c
--- a/sys/dev/pci/if_bwfm_pci.c Sat May 08 00:08:43 2021 +0000
+++ b/sys/dev/pci/if_bwfm_pci.c Sat May 08 00:27:02 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_bwfm_pci.c,v 1.9 2020/05/30 15:55:47 jdolecek Exp $ */
+/*     $NetBSD: if_bwfm_pci.c,v 1.10 2021/05/08 00:27:02 thorpej Exp $ */
 /*     $OpenBSD: if_bwfm_pci.c,v 1.18 2018/02/08 05:00:38 patrick Exp $        */
 /*
  * Copyright (c) 2010-2016 Broadcom Corporation
@@ -366,12 +366,14 @@ static const struct bwfm_firmware_select
        BWFM_FW_ENTRY_END
 };
 
-static const struct bwfm_pci_matchid {
-       pci_vendor_id_t         bwfm_vendor;
-       pci_product_id_t        bwfm_product;
-} bwfm_pci_devices[] = {
-       { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM43602 },
-       { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM4350 },
+static const struct device_compatible_entry compat_data[] = {
+       { .id = PCI_ID_CODE(PCI_VENDOR_BROADCOM,
+               PCI_PRODUCT_BROADCOM_BCM43602), },
+
+       { .id = PCI_ID_CODE(PCI_VENDOR_BROADCOM,
+               PCI_PRODUCT_BROADCOM_BCM4350), },
+
+       PCI_COMPAT_EOL
 };
 
 static struct mbuf *
@@ -397,14 +399,7 @@ bwfm_pci_match(device_t parent, cfdata_t
 {
        struct pci_attach_args *pa = aux;
 
-       if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_BROADCOM)
-               return 0;
-
-       for (size_t i = 0; i < __arraycount(bwfm_pci_devices); i++)
-               if (PCI_PRODUCT(pa->pa_id) == bwfm_pci_devices[i].bwfm_product)
-                       return 1;
-
-       return 0;
+       return pci_compatible_match(pa, compat_data);
 }
 
 void
diff -r 324307c52402 -r fb9f2f618a7a sys/dev/pci/if_bwi_pci.c
--- a/sys/dev/pci/if_bwi_pci.c  Sat May 08 00:08:43 2021 +0000
+++ b/sys/dev/pci/if_bwi_pci.c  Sat May 08 00:27:02 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_bwi_pci.c,v 1.16 2018/12/09 11:14:02 jdolecek Exp $ */
+/*     $NetBSD: if_bwi_pci.c,v 1.17 2021/05/08 00:27:02 thorpej Exp $  */
 /*     $OpenBSD: if_bwi_pci.c,v 1.6 2008/02/14 22:10:02 brad Exp $ */
 
 /*
@@ -24,7 +24,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_bwi_pci.c,v 1.16 2018/12/09 11:14:02 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_bwi_pci.c,v 1.17 2021/05/08 00:27:02 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/callout.h>
@@ -74,31 +74,52 @@ struct bwi_pci_softc {
 CFATTACH_DECL_NEW(bwi_pci, sizeof(struct bwi_pci_softc),
     bwi_pci_match, bwi_pci_attach, bwi_pci_detach, NULL);
 
+static const struct device_compatible_entry compat_data[] = {
+       { .id = PCI_ID_CODE(PCI_VENDOR_BROADCOM,
+               PCI_PRODUCT_BROADCOM_BCM4303), },
+
+       { .id = PCI_ID_CODE(PCI_VENDOR_BROADCOM,
+               PCI_PRODUCT_BROADCOM_BCM4306), },
+
+       { .id = PCI_ID_CODE(PCI_VENDOR_BROADCOM,
+               PCI_PRODUCT_BROADCOM_BCM4306_2), },
+
+       { .id = PCI_ID_CODE(PCI_VENDOR_BROADCOM,
+               PCI_PRODUCT_BROADCOM_BCM4307), },
+
+       { .id = PCI_ID_CODE(PCI_VENDOR_BROADCOM,
+               PCI_PRODUCT_BROADCOM_BCM4309), },
+
+       { .id = PCI_ID_CODE(PCI_VENDOR_BROADCOM,
+               PCI_PRODUCT_BROADCOM_BCM4311), },
+
+       { .id = PCI_ID_CODE(PCI_VENDOR_BROADCOM,
+               PCI_PRODUCT_BROADCOM_BCM4312), },
+
+       { .id = PCI_ID_CODE(PCI_VENDOR_BROADCOM,
+               PCI_PRODUCT_BROADCOM_BCM4318), },
+
+       { .id = PCI_ID_CODE(PCI_VENDOR_BROADCOM,
+               PCI_PRODUCT_BROADCOM_BCM4319), },
+
+       { .id = PCI_ID_CODE(PCI_VENDOR_BROADCOM,
+               PCI_PRODUCT_BROADCOM_BCM4322), },
+
+       { .id = PCI_ID_CODE(PCI_VENDOR_BROADCOM,
+               PCI_PRODUCT_BROADCOM_BCM43XG), },
+
+       { .id = PCI_ID_CODE(PCI_VENDOR_BROADCOM,
+               PCI_PRODUCT_BROADCOM_BCM4328), },
+
+       PCI_COMPAT_EOL
+};
+
 static int
 bwi_pci_match(device_t parent, cfdata_t match, void *aux)
 {
        struct pci_attach_args *pa = aux;
 
-       if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_BROADCOM)
-               return (0);
-
-       switch (PCI_PRODUCT(pa->pa_id)) {
-       case PCI_PRODUCT_BROADCOM_BCM4303:
-       case PCI_PRODUCT_BROADCOM_BCM4306:
-       case PCI_PRODUCT_BROADCOM_BCM4306_2:
-       case PCI_PRODUCT_BROADCOM_BCM4307:
-       case PCI_PRODUCT_BROADCOM_BCM4309:
-       case PCI_PRODUCT_BROADCOM_BCM4311:
-       case PCI_PRODUCT_BROADCOM_BCM4312:
-       case PCI_PRODUCT_BROADCOM_BCM4318:
-       case PCI_PRODUCT_BROADCOM_BCM4319:
-       case PCI_PRODUCT_BROADCOM_BCM4322:
-       case PCI_PRODUCT_BROADCOM_BCM43XG:
-       case PCI_PRODUCT_BROADCOM_BCM4328:
-               return (1);
-       }
-
-       return (0);
+       return pci_compatible_match(pa, compat_data);
 }
 
 static void
diff -r 324307c52402 -r fb9f2f618a7a sys/dev/pci/if_cas.c
--- a/sys/dev/pci/if_cas.c      Sat May 08 00:08:43 2021 +0000
+++ b/sys/dev/pci/if_cas.c      Sat May 08 00:27:02 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_cas.c,v 1.44 2020/09/15 08:33:40 mrg Exp $  */
+/*     $NetBSD: if_cas.c,v 1.45 2021/05/08 00:27:02 thorpej Exp $      */
 /*     $OpenBSD: if_cas.c,v 1.29 2009/11/29 16:19:38 kettenis Exp $    */
 
 /*
@@ -44,7 +44,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_cas.c,v 1.44 2020/09/15 08:33:40 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_cas.c,v 1.45 2021/05/08 00:27:02 thorpej Exp $");
 
 #ifndef _MODULE
 #include "opt_inet.h"
@@ -163,14 +163,16 @@ int               cas_intr(void *);
 #define        DPRINTF(sc, x)  /* nothing */
 #endif
 
-static const struct cas_pci_dev {
-       uint16_t cpd_vendor;
-       uint16_t cpd_device;
-       int cpd_variant;
-} cas_pci_devlist[] = {
-       { PCI_VENDOR_SUN, PCI_PRODUCT_SUN_CASSINI, CAS_CAS },
-       { PCI_VENDOR_NS, PCI_PRODUCT_NS_SATURN, CAS_SATURN },
-       { 0, 0, 0 }
+static const struct device_compatible_entry compat_data[] = {
+       { .id = PCI_ID_CODE(PCI_VENDOR_SUN,
+               PCI_PRODUCT_SUN_CASSINI),
+         .value = CAS_CAS },
+
+       { .id = PCI_ID_CODE(PCI_VENDOR_NS,
+               PCI_PRODUCT_NS_SATURN),
+         .value = CAS_SATURN },
+
+       PCI_COMPAT_EOL
 };
 
 #define        CAS_LOCAL_MAC_ADDRESS   "local-mac-address"
@@ -182,15 +184,8 @@ int
 cas_match(device_t parent, cfdata_t cf, void *aux)
 {
        struct pci_attach_args *pa = aux;
-       int i;
 
-       for (i = 0; cas_pci_devlist[i].cpd_vendor != 0; i++) {
-               if ((PCI_VENDOR(pa->pa_id) == cas_pci_devlist[i].cpd_vendor) &&
-                   (PCI_PRODUCT(pa->pa_id) == cas_pci_devlist[i].cpd_device))
-                       return 1;
-       }
-
-       return 0;
+       return pci_compatible_match(pa, compat_data);
 }
 
 #define        PROMHDR_PTR_DATA        0x18
@@ -403,8 +398,8 @@ void
 cas_attach(device_t parent, device_t self, void *aux)
 {
        struct pci_attach_args *pa = aux;
+       const struct device_compatible_entry *dce;
        struct cas_softc *sc = device_private(self);
-       int i;
        prop_data_t data;
        uint8_t enaddr[ETHER_ADDR_LEN];
 
@@ -417,19 +412,11 @@ cas_attach(device_t parent, device_t sel
        else
                sc->sc_dmatag = pa->pa_dmat;
 
-       sc->sc_variant = CAS_UNKNOWN;
-       for (i = 0; cas_pci_devlist[i].cpd_vendor != 0; i++) {
-               if ((PCI_VENDOR(pa->pa_id) == cas_pci_devlist[i].cpd_vendor) &&
-                   (PCI_PRODUCT(pa->pa_id) == cas_pci_devlist[i].cpd_device)) {
-                       sc->sc_variant = cas_pci_devlist[i].cpd_variant;
-                       break;
-               }
-       }
+       dce = pci_compatible_lookup(pa, compat_data);
+       KASSERT(dce != NULL);
+       sc->sc_variant = (u_int)dce->value;
+
        aprint_debug_dev(sc->sc_dev, "variant = %d\n", sc->sc_variant);
-       if (sc->sc_variant == CAS_UNKNOWN) {
-               aprint_error_dev(sc->sc_dev, "unknown adaptor\n");
-               return;
-       }
 
 #define PCI_CAS_BASEADDR       0x10
        if (pci_mapreg_map(pa, PCI_CAS_BASEADDR, PCI_MAPREG_TYPE_MEM, 0,
diff -r 324307c52402 -r fb9f2f618a7a sys/dev/pci/if_dge.c
--- a/sys/dev/pci/if_dge.c      Sat May 08 00:08:43 2021 +0000
+++ b/sys/dev/pci/if_dge.c      Sat May 08 00:27:02 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_dge.c,v 1.58 2020/03/01 15:11:31 thorpej Exp $ */
+/*     $NetBSD: if_dge.c,v 1.59 2021/05/08 00:27:02 thorpej Exp $ */
 
 /*
  * Copyright (c) 2004, SUNET, Swedish University Computer Network.
@@ -80,7 +80,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_dge.c,v 1.58 2020/03/01 15:11:31 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_dge.c,v 1.59 2021/05/08 00:27:02 thorpej Exp $");
 
 
 
@@ -647,49 +647,41 @@ static char (*dge_txseg_evcnt_names)[DGE
 /*
  * Devices supported by this driver.
  */
-static const struct dge_product {
-       pci_vendor_id_t dgep_vendor;
-       pci_product_id_t dgep_product;
-       const char *dgep_name;
-       int dgep_flags;
+struct dge_product {
+       const char *name;
+       int flags;
 #define DGEP_F_10G_LR    0x01
 #define DGEP_F_10G_SR    0x02
-} dge_products[] = {
-       { PCI_VENDOR_INTEL,  PCI_PRODUCT_INTEL_82597EX,
-         "Intel i82597EX 10GbE-LR Ethernet",
-         DGEP_F_10G_LR },
+};
 
-       { PCI_VENDOR_INTEL,  PCI_PRODUCT_INTEL_82597EX_SR,
-         "Intel i82597EX 10GbE-SR Ethernet",
-         DGEP_F_10G_SR },
+static const struct dge_product i82597EX_lr = {
+       .name = "Intel i82597EX 10GbE-LR Ethernet",
+       .flags = DGEP_F_10G_LR
+};
 
-       { 0,        0,
-         NULL,
-         0 },
+static const struct dge_product i82597EX_sr = {
+       .name = "Intel i82597EX 10GbE-SR Ethernet",
+       .flags = DGEP_F_10G_SR
 };
 
-static const struct dge_product *
-dge_lookup(const struct pci_attach_args *pa)
-{
-       const struct dge_product *dgep;
+static const struct device_compatible_entry compat_data[] = {
+       { .id = PCI_ID_CODE(PCI_VENDOR_INTEL,
+               PCI_PRODUCT_INTEL_82597EX),
+         .data = &i82597EX_lr },
 
-       for (dgep = dge_products; dgep->dgep_name != NULL; dgep++) {
-               if (PCI_VENDOR(pa->pa_id) == dgep->dgep_vendor &&
-                   PCI_PRODUCT(pa->pa_id) == dgep->dgep_product)
-                       return dgep;
-               }
-       return NULL;



Home | Main Index | Thread Index | Old Index