BXE: use separate lists for 9ns and BSD stuff
[akaros.git] / kern / drivers / net / bxe / bxe_dev.c
index 11e87ed..0e1fecb 100644 (file)
 /* We're required to print out stats at some point.  Here are a couple from
  * igbe, as an example. */
 
+spinlock_t bxe_adapter_tq_lock = SPINLOCK_INITIALIZER;
+TAILQ_HEAD(bxe_adapter_tq, bxe_adapter);
+struct bxe_adapter_tq bxe_adapter_tq = TAILQ_HEAD_INITIALIZER(bxe_adapter_tq);
+
 static char *statistics[Nstatistics] = {
        "CRC Error",
        "Alignment Error",
 };
 
-/* Most 9ns drivers have some form of helper to read from the IO space, whether
- * that's PIO or MMIO. */
-static inline uint32_t csr32r(struct bxe_adapter *c, uintptr_t reg)
-{
-       return read_mmreg32((uintptr_t) (c->mmio + (reg / 4)));
-}
-
-static inline void csr32w(struct bxe_adapter *c, uintptr_t reg, uint32_t val)
-{
-       write_mmreg32((uintptr_t) (c->mmio + (reg / 4)), val);
-}
-
 static long bxeifstat(struct ether *edev, void *a, long n, uint32_t offset)
 {
        struct bxe_adapter *ctlr;
@@ -258,6 +250,10 @@ static void bxeattach(struct ether *edev)
 
        ctlr = edev->ctlr;
        ctlr->edev = edev;      /* point back to Ether* */
+
+       /* not sure if we'll need/want any of the 9ns stuff */
+       return;
+
        qlock(&ctlr->alock);
        /* TODO: make sure we haven't attached already.  If so, just return */
 
@@ -308,7 +304,16 @@ static int bxereset(struct bxe_adapter *ctlr)
 {
        int ctrl, i, pause, r, swdpio, txcw;
 
-       run_once(qlock_init(&bxe_prev_mtx));
+       /* despite the name, we attach at reset time.  BXE attach has a lot of
+        * mmio mappings that have to happen at boot (in akaros), instead of during
+        * devether's attach (at runtime) */
+extern int bxe_attach(struct bxe_adapter *sc);
+       bxe_attach(ctlr);
+
+       /* normally done during BSD's ifconfig */
+extern void bxe_init(void *xsc);
+       bxe_init(ctlr);
+
 //     if (igbedetach(ctlr))
 //             return -1;
 
@@ -320,8 +325,6 @@ static void bxepci(void)
        int cls, id;
        struct pci_device *pcidev;
        struct bxe_adapter *ctlr;
-       void *mem;
-       uintptr_t mmio_paddr;
 
        STAILQ_FOREACH(pcidev, &pci_devices, all_dev) {
                /* This checks that pcidev is a Network Controller for Ethernet */
@@ -337,14 +340,8 @@ static void bxepci(void)
                           pcidev->ven_id, pcidev->dev_id,
                           pcidev->bus, pcidev->dev, pcidev->func);
 
-               /* Assuming MMIO */
-               mmio_paddr = pcidev->bar[0].mmio_base32 ? pcidev->bar[0].mmio_base32 :
-                       pcidev->bar[0].mmio_base64;
-               mem = (void *)vmap_pmem_nocache(mmio_paddr, pcidev->bar[0].mmio_sz);
-               if (mem == NULL) {
-                       printd("bxe: can't map %p\n", pcidev->bar[0].mmio_base32);
-                       continue;
-               }
+               /* MMIO, pci_bus_master, etc, are all done in bxe_attach */
+
                cls = pcidev_read8(pcidev, PCI_CLSZ_REG);
                switch (cls) {
                        default:
@@ -361,29 +358,27 @@ static void bxepci(void)
                        case 0x10:
                                break;
                }
+
                ctlr = kzmalloc(sizeof(struct bxe_adapter), 0);
-               if (ctlr == NULL) {
-                       vunmap_vmem((uintptr_t) mem, pcidev->bar[0].mmio_sz);
+               if (ctlr == NULL)
                        error(Enomem);
-               }
+
                spinlock_init_irqsave(&ctlr->imlock);
                spinlock_init_irqsave(&ctlr->tlock);
                qlock_init(&ctlr->alock);
                qlock_init(&ctlr->slock);
                rendez_init(&ctlr->rrendez);
 
-               //ctlr->pci = pcidev;
-               ctlr->mmio = mem;
-               /* TODO: save 'mem' somewhere in the ctrl */
+               ctlr->pcidev = pcidev;
                
                if (bxereset(ctlr)) {
                        kfree(ctlr);
-                       vunmap_vmem((uintptr_t) mem, pcidev->bar[0].mmio_sz);
                        continue;
                }
-               pci_set_bus_master(pcidev);
 
-               /* TODO Maybe ctlr add to list of devices */
+               spin_lock(&bxe_adapter_tq_lock);
+               TAILQ_INSERT_TAIL(&bxe_adapter_tq, ctlr, link9ns);
+               spin_unlock(&bxe_adapter_tq_lock);
        }
 }
 
@@ -393,39 +388,31 @@ static int bxepnp(struct ether *edev)
 {
        struct bxe_adapter *ctlr;
 
+       run_once(qlock_init(&bxe_prev_mtx));
        /* Allocs ctlrs for all PCI devices matching our IDs, does various PCI and
         * MMIO/port setup */
        run_once(bxepci());
 
-
-return -1;
-
-       /* Any adapter matches if no edev->port is supplied, otherwise the ports
-        * must match. */
-       for (;;) {      // check all ctlrs
-               ctlr = (void*)0xdeadbeef;
-               /* only want inactive ones */
-               //if (ctlr->active)
-               //      continue;
-               // well, oop.s
-               /*
-               if (edev->port == 0 || edev->port == ctlr->port) {
-                       ctlr->active = 1;
-                       break;
-               }
-               */
+       spin_lock(&bxe_adapter_tq_lock);
+       TAILQ_FOREACH(ctlr, &bxe_adapter_tq, link9ns) {
+               /* just take the first inactive ctlr on the list */
+               if (ctlr->active)
+                       continue;
+               ctlr->active = 1;
+               break;
        }
+       spin_unlock(&bxe_adapter_tq_lock);
        if (ctlr == NULL)
                return -1;
 
        edev->ctlr = ctlr;
-       //edev->port = ctlr->port;
-       //      edev->irq = ctlr->pci->irqline;
-       //edev->tbdf = MKBUS(BusPCI, ctlr->pci->bus, ctlr->pci->dev, ctlr->pci->func);
+       //edev->port = ctlr->port;      /* might just remove this from devether */
+       edev->irq = ctlr->pcidev->irqline;
+       edev->tbdf = MKBUS(BusPCI, ctlr->pcidev->bus, ctlr->pcidev->dev,
+                          ctlr->pcidev->func);
        edev->netif.mbps = 1000;
-       /* ea is the eth addr */
-       //memmove(edev->ea, ctlr->ra, Eaddrlen);
-
+       memmove(edev->ea, ctlr->link_params.mac_addr, Eaddrlen);
+       
        /*
         * Linkage to the generic ethernet driver.
         */
@@ -439,7 +426,6 @@ return -1;
        edev->netif.promiscuous = bxepromiscuous;
        edev->netif.multicast = bxemulticast;
 
-       register_irq(edev->irq, bxeinterrupt, edev, edev->tbdf);
        return 0;
 }