Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/pci Start porting to NetBSD. (WIP, incomplete)



details:   https://anonhg.NetBSD.org/src/rev/f309cda7ba85
branches:  trunk
changeset: 1006335:f309cda7ba85
user:      sevan <sevan%NetBSD.org@localhost>
date:      Sat Jan 11 21:05:45 2020 +0000

description:
Start porting to NetBSD. (WIP, incomplete)

diffstat:

 sys/dev/pci/if_rge.c    |  174 ++++++++++++++++++++++++++++-------------------
 sys/dev/pci/if_rgereg.h |    9 +-
 2 files changed, 109 insertions(+), 74 deletions(-)

diffs (truncated from 487 to 300 lines):

diff -r 09501142fa61 -r f309cda7ba85 sys/dev/pci/if_rge.c
--- a/sys/dev/pci/if_rge.c      Sat Jan 11 20:56:50 2020 +0000
+++ b/sys/dev/pci/if_rge.c      Sat Jan 11 21:05:45 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_rge.c,v 1.1 2020/01/11 20:56:51 sevan Exp $ */
+/*     $NetBSD: if_rge.c,v 1.2 2020/01/11 21:05:45 sevan Exp $ */
 /*     $OpenBSD: if_rge.c,v 1.2 2020/01/02 09:00:45 kevlo Exp $        */
 
 /*
@@ -17,8 +17,13 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#include "bpfilter.h"
-#include "vlan.h"
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: if_rge.c,v 1.2 2020/01/11 21:05:45 sevan Exp $");
+
+/* #include "bpfilter.h" Sevan */
+/* #include "vlan.h" Sevan */
+
+#include <sys/types.h>
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -31,16 +36,20 @@
 #include <sys/endian.h>
 
 #include <net/if.h>
+
+#include <net/if_dl.h>
+#include <net/if_ether.h>
+
 #include <net/if_media.h>
 
 #include <netinet/in.h>
-#include <netinet/if_ether.h>
+#include <net/if_ether.h>
 
 #if NBPFILTER > 0
 #include <net/bpf.h>
 #endif
 
-#include <machine/bus.h>
+#include <sys/bus.h>
 #include <machine/intr.h>
 
 #include <dev/mii/mii.h>
@@ -51,12 +60,23 @@
 
 #include <dev/pci/if_rgereg.h>
 
-int            rge_match(struct device *, void *, void *);
-void           rge_attach(struct device *, struct device *, void *);
+#ifdef __NetBSD__
+#define letoh32        htole32
+#define nitems(x)      __arraycount(x)
+#define MBUF_LIST_INITIALIZER()        { NULL, NULL, 0 }
+struct mbuf_list {
+       struct mbuf     *ml_head;
+       struct mbuf     *ml_tail;
+       u_int   ml_len;
+};
+#endif
+
+static int             rge_match(device_t, cfdata_t, void *);
+static void            rge_attach(device_t, device_t, void *); 
 int            rge_intr(void *);
 int            rge_encap(struct rge_softc *, struct mbuf *, int);
-int            rge_ioctl(struct ifnet *, u_long, caddr_t);
-void           rge_start(struct ifqueue *);
+int            rge_ioctl(struct ifnet *, u_long, void *);
+void           rge_start(struct ifnet *);
 void           rge_watchdog(struct ifnet *);
 int            rge_init(struct ifnet *);
 void           rge_stop(struct ifnet *);
@@ -112,33 +132,42 @@
        RTL8125_MAC_CFG3_MCU
 };
 
-struct cfattach rge_ca = {
-       sizeof(struct rge_softc), rge_match, rge_attach
-};
+CFATTACH_DECL_NEW(rge, sizeof(struct rge_softc), rge_match, rge_attach,
+               NULL, NULL); /* Sevan - detach function? */
+
+extern struct cfdriver rge_cd;
 
-struct cfdriver rge_cd = {
-       NULL, "rge", DV_IFNET
+static const struct {
+       pci_vendor_id_t         vendor;
+       pci_product_id_t        product;
+}rge_devices[] = {
+       { PCI_VENDOR_REALTEK, PCI_PRODUCT_REALTEK_E3000 },
+       { PCI_VENDOR_REALTEK, PCI_PRODUCT_REALTEK_RT8125 },
 };
 
-const struct pci_matchid rge_devices[] = {
-       { PCI_VENDOR_REALTEK, PCI_PRODUCT_REALTEK_E3000 },
-       { PCI_VENDOR_REALTEK, PCI_PRODUCT_REALTEK_RTL8125 }
-};
+static int
+rge_match(device_t parent, cfdata_t match, void *aux)
+{
+       struct pci_attach_args *pa =aux;
+       int n;
 
-int
-rge_match(struct device *parent, void *match, void *aux)
-{
-       return (pci_matchbyid((struct pci_attach_args *)aux, rge_devices,
-           nitems(rge_devices)));
+       for (n =0; n < __arraycount(rge_devices); n++) {
+               if (PCI_VENDOR(pa->pa_id) == rge_devices[n].vendor &&
+                   PCI_PRODUCT(pa->pa_id) == rge_devices[n].product)
+                       return 1;
+       }
+
+       return 0;
 }
 
 void
-rge_attach(struct device *parent, struct device *self, void *aux)
+rge_attach(device_t parent, device_t self, void *aux)
 {
        struct rge_softc *sc = (struct rge_softc *)self;
        struct pci_attach_args *pa = aux;
        pci_chipset_tag_t pc = pa->pa_pc;
        pci_intr_handle_t ih;
+       char intrbuf[PCI_INTRSTR_LEN];
        const char *intrstr = NULL;
        struct ifnet *ifp;
        pcireg_t reg;
@@ -153,13 +182,13 @@
         */
        if (pci_mapreg_map(pa, RGE_PCI_BAR2, PCI_MAPREG_TYPE_MEM |
            PCI_MAPREG_MEM_TYPE_64BIT, 0, &sc->rge_btag, &sc->rge_bhandle,
-           NULL, &sc->rge_bsize, 0)) {
+           NULL, &sc->rge_bsize)) {
                if (pci_mapreg_map(pa, RGE_PCI_BAR1, PCI_MAPREG_TYPE_MEM |
                    PCI_MAPREG_MEM_TYPE_32BIT, 0, &sc->rge_btag,
-                   &sc->rge_bhandle, NULL, &sc->rge_bsize, 0)) {
+                   &sc->rge_bhandle, NULL, &sc->rge_bsize)) {
                        if (pci_mapreg_map(pa, RGE_PCI_BAR0, PCI_MAPREG_TYPE_IO,
                            0, &sc->rge_btag, &sc->rge_bhandle, NULL,
-                           &sc->rge_bsize, 0)) {
+                           &sc->rge_bsize)) {
                                printf(": can't map mem or i/o space\n");
                                return;
                        }
@@ -169,14 +198,14 @@
        /* 
         * Allocate interrupt.
         */
-       if (pci_intr_map_msi(pa, &ih) == 0)
+       if (pci_intr_map(pa, &ih) == 0)
                sc->rge_flags |= RGE_FLAG_MSI;
        else if (pci_intr_map(pa, &ih) != 0) {
                printf(": couldn't map interrupt\n");
                return;
        }
-       intrstr = pci_intr_string(pc, ih);
-       sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET | IPL_MPSAFE, rge_intr,
+       intrstr = pci_intr_string(pc, ih, intrbuf, sizeof(intrbuf));
+       sc->sc_ih = pci_intr_establish_xname(pc, ih, IPL_NET, rge_intr,
            sc, sc->sc_dev.dv_xname);
        if (sc->sc_ih == NULL) {
                printf(": couldn't establish interrupt");
@@ -212,12 +241,11 @@
         */
        if (pci_get_capability(pa->pa_pc, pa->pa_tag, PCI_CAP_PCIEXPRESS,
            &offset, NULL)) {
-               /* Disable PCIe ASPM and ECPM. */
+               /* Disable PCIe ASPM. */
                reg = pci_conf_read(pa->pa_pc, pa->pa_tag,
-                   offset + PCI_PCIE_LCSR);
-               reg &= ~(PCI_PCIE_LCSR_ASPM_L0S | PCI_PCIE_LCSR_ASPM_L1 |
-                   PCI_PCIE_LCSR_ECPM);
-               pci_conf_write(pa->pa_pc, pa->pa_tag, offset + PCI_PCIE_LCSR,
+                   offset + PCIE_LCSR);
+               reg &= ~(PCIE_LCSR_ASPM_L0S | PCIE_LCSR_ASPM_L1 );
+               pci_conf_write(pa->pa_pc, pa->pa_tag, offset + PCIE_LCSR,
                    reg);
        }
 
@@ -227,7 +255,7 @@
        rge_get_macaddr(sc, eaddr);
        printf(", address %s\n", ether_sprintf(eaddr));
 
-       memcpy(sc->sc_arpcom.ac_enaddr, eaddr, ETHER_ADDR_LEN);
+       memcpy(sc->sc_enaddr, eaddr, ETHER_ADDR_LEN);
 
        rge_set_phy_power(sc, 1);
        rge_phy_config(sc);
@@ -235,19 +263,22 @@
        if (rge_allocmem(sc))
                return;
 
-       ifp = &sc->sc_arpcom.ac_if;
+       ifp = &sc->sc_ec.ec_if;
        ifp->if_softc = sc;
        strlcpy(ifp->if_xname, sc->sc_dev.dv_xname, IFNAMSIZ);
        ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
-       ifp->if_xflags = IFXF_MPSAFE;
+#ifdef RGE_MPSAFE
+       ifp->if_xflags = IFEF_MPSAFE;
+#endif
        ifp->if_ioctl = rge_ioctl;
-       ifp->if_qstart = rge_start;
+       ifp->if_start = rge_start;
        ifp->if_watchdog = rge_watchdog;
        IFQ_SET_MAXLEN(&ifp->if_snd, RGE_TX_LIST_CNT);
-       ifp->if_hardmtu = RGE_JUMBO_MTU;
+       ifp->if_mtu = RGE_JUMBO_MTU;
 
-       ifp->if_capabilities = IFCAP_VLAN_MTU | IFCAP_CSUM_IPv4 |
-           IFCAP_CSUM_TCPv4 | IFCAP_CSUM_UDPv4;
+       ifp->if_capabilities = ETHERCAP_VLAN_MTU | IFCAP_CSUM_IPv4_Rx |
+           IFCAP_CSUM_IPv4_Tx |IFCAP_CSUM_TCPv4_Rx | IFCAP_CSUM_TCPv4_Tx|
+           IFCAP_CSUM_UDPv4_Rx | IFCAP_CSUM_UDPv4_Tx;
 
 #if NVLAN > 0
        ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING;
@@ -265,14 +296,14 @@
        sc->sc_media.ifm_media = sc->sc_media.ifm_cur->ifm_media;
 
        if_attach(ifp);
-       ether_ifattach(ifp);
+       ether_ifattach(ifp, eaddr);
 }
 
 int
 rge_intr(void *arg)
 {
        struct rge_softc *sc = arg;
-       struct ifnet *ifp = &sc->sc_arpcom.ac_if;
+       struct ifnet *ifp = &sc->sc_ec.ec_if;
        uint32_t status;
        int claimed = 0, rx, tx;
 
@@ -307,9 +338,9 @@
                }
 
                if (status & RGE_ISR_SYSTEM_ERR) {
-                       KERNEL_LOCK();
+                       KERNEL_LOCK(1, NULL);
                        rge_init(ifp);
-                       KERNEL_UNLOCK();
+                       KERNEL_UNLOCK_ONE(NULL);
                        claimed = 1;
                }
        }
@@ -360,7 +391,7 @@
         * take affect.
         */
        if ((m->m_pkthdr.csum_flags &
-           (M_IPV4_CSUM_OUT | M_TCP_CSUM_OUT | M_UDP_CSUM_OUT)) != 0) {
+           (M_CSUM_IPv4 | M_CSUM_TCPv4 | M_CSUM_UDPv4)) != 0) {
                cflags |= RGE_TDEXTSTS_IPCSUM;
                if (m->m_pkthdr.csum_flags & M_TCP_CSUM_OUT)
                        cflags |= RGE_TDEXTSTS_TCPCSUM;
@@ -439,7 +470,7 @@
 }
 
 int
-rge_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
+rge_ioctl(struct ifnet *ifp, u_long cmd, void *data)
 {
        struct rge_softc *sc = ifp->if_softc;
        struct ifreq *ifr = (struct ifreq *)data;
@@ -469,14 +500,14 @@
                error = ifmedia_ioctl(ifp, ifr, &sc->sc_media, cmd);
                break;
        case SIOCSIFMTU:
-               if (ifr->ifr_mtu > ifp->if_hardmtu) {
+               if (ifr->ifr_mtu > ifp->if_mtu) {
                        error = EINVAL;
                        break;
                }
                ifp->if_mtu = ifr->ifr_mtu;
                break;
        default:
-               error = ether_ioctl(ifp, &sc->sc_arpcom, cmd, data);
+               error = ether_ioctl(ifp, cmd, data);
        }
 
        if (error == ENETRESET) {
@@ -490,7 +521,7 @@
 }
 
 void
-rge_start(struct ifqueue *ifq)
+rge_start(struct ifnet *ifq)
 {
        struct ifnet *ifp = ifq->ifq_if;
        struct rge_softc *sc = ifp->if_softc;
@@ -498,6 +529,9 @@
        int free, idx, used;
        int queued = 0;



Home | Main Index | Thread Index | Old Index