strace: Remove the ability to write to Qstrace
[akaros.git] / kern / drivers / net / etherigbe.c
index 14ca78e..3bcf79f 100644 (file)
@@ -467,7 +467,6 @@ enum {                                      /* Td status */
 enum {
        Nrd             = 256,          /* multiple of 8 */
        Ntd             = 64,           /* multiple of 8 */
-       Nrb             = 1024,         /* private receive buffers per Ctlr */
        Rbsz            = 2048,
 };
 
@@ -486,7 +485,6 @@ struct ctlr {
        void*   alloc;                  /* receive/transmit descriptors */
        int     nrd;
        int     ntd;
-       int     nrb;                    /* how many this Ctlr has in the pool */
 
        int*    nic;
        spinlock_t      imlock;
@@ -548,10 +546,6 @@ static inline void csr32w(struct ctlr *c, uintptr_t reg, uint32_t val)
 static struct ctlr* igbectlrhead;
 static struct ctlr* igbectlrtail;
 
-/* lock for igberpool (free receive Blocks) */
-static spinlock_t igberblock = SPINLOCK_INITIALIZER_IRQSAVE;
-static struct block* igberbpool;       /* receive Blocks for all igbe controllers */
-
 static char* statistics[Nstatistics] = {
        "CRC Error",
        "Alignment Error",
@@ -645,7 +639,7 @@ igbeifstat(struct ether* edev, void* a, long n, uint32_t offset)
        p = kzmalloc(READSTR, 0);
        if(p == NULL) {
                qunlock(&ctlr->slock);
-               error(Enomem);
+               error(ENOMEM, ERROR_FIXME);
        }
        l = 0;
        for(i = 0; i < Nstatistics; i++){
@@ -736,7 +730,7 @@ igbectl(struct ether* edev, void* buf, long n)
        struct cmdtab *ct;
 
        if((ctlr = edev->ctlr) == NULL)
-               error(Enonexist);
+               error(ENODEV, ERROR_FIXME);
 
        cb = parsecmd(buf, n);
        if(waserror()){
@@ -749,7 +743,7 @@ igbectl(struct ether* edev, void* buf, long n)
        case CMrdtr:
                v = strtol(cb->f[1], &p, 0);
                if(v < 0 || p == cb->f[1] || v > 0xFFFF)
-                       error(Ebadarg);
+                       error(EINVAL, ERROR_FIXME);
                ctlr->rdtr = v;
                csr32w(ctlr, Rdtr, Fpd|v);
                break;
@@ -807,35 +801,6 @@ igbemulticast(void* arg, uint8_t* addr, int add)
        csr32w(ctlr, Mta+x*4, ctlr->mta[x]);
 }
 
-static struct block*
-igberballoc(void)
-{
-       struct block *bp;
-
-       ilock(&igberblock);
-       if((bp = igberbpool) != NULL){
-               igberbpool = bp->next;
-               bp->next = NULL;
-               /* _xinc(&bp->ref);     prevent bp from being freed */
-       }
-       iunlock(&igberblock);
-
-       return bp;
-}
-
-static void
-igberbfree(struct block* bp)
-{
-       bp->rp = bp->lim - Rbsz;
-       bp->wp = bp->rp;
-       bp->flag &= ~(Bipck | Budpck | Btcpck | Bpktck);
-
-       ilock(&igberblock);
-       bp->next = igberbpool;
-       igberbpool = bp;
-       iunlock(&igberblock);
-}
-
 static void
 igbeim(struct ctlr* ctlr, int im)
 {
@@ -1089,7 +1054,7 @@ igbereplenish(struct ctlr* ctlr)
        while(NEXT_RING(rdt, ctlr->nrd) != ctlr->rdh){
                rd = &ctlr->rdba[rdt];
                if(ctlr->rb[rdt] == NULL){
-                       bp = igberballoc();
+                       bp = block_alloc(Rbsz, MEM_ATOMIC);
                        if(bp == NULL){
                                /* needs to be a safe print for interrupt level */
                                printk("#l%d: igbereplenish: no available buffers\n",
@@ -1264,14 +1229,7 @@ igbeattach(struct ether* edev)
        ctlr->tb = NULL;
        ctlr->rb = NULL;
        ctlr->alloc = NULL;
-       ctlr->nrb = 0;
        if(waserror()){
-               while(ctlr->nrb > 0){
-                       bp = igberballoc();
-                       bp->free = NULL;
-                       freeb(bp);
-                       ctlr->nrb--;
-               }
                kfree(ctlr->tb);
                ctlr->tb = NULL;
                kfree(ctlr->rb);
@@ -1287,7 +1245,7 @@ igbeattach(struct ether* edev)
        ctlr->alloc = kzmalloc(ctlr->nrd * sizeof(Rd) + ctlr->ntd * sizeof(Td) + 127, 0);
        if(ctlr->alloc == NULL) {
                printd("igbe: can't allocate ctlr->alloc\n");
-               error(Enomem);
+               error(ENOMEM, ERROR_FIXME);
        }
        ctlr->rdba = (Rd*)ROUNDUP((uintptr_t)ctlr->alloc, 128);
        ctlr->tdba = (Td*)(ctlr->rdba+ctlr->nrd);
@@ -1296,22 +1254,15 @@ igbeattach(struct ether* edev)
        ctlr->tb = kzmalloc(ctlr->ntd * sizeof(struct block *), 0);
        if (ctlr->rb == NULL || ctlr->tb == NULL) {
                printd("igbe: can't allocate ctlr->rb or ctlr->tb\n");
-               error(Enomem);
-       }
-
-       for(ctlr->nrb = 0; ctlr->nrb < Nrb; ctlr->nrb++){
-               if((bp = allocb(Rbsz)) == NULL)
-                       break;
-               bp->free = igberbfree;
-               freeb(bp);
+               error(ENOMEM, ERROR_FIXME);
        }
 
        /* the ktasks should free these names, if they ever exit */
-       name = kmalloc(KNAMELEN, KMALLOC_WAIT);
+       name = kmalloc(KNAMELEN, MEM_WAIT);
        snprintf(name, KNAMELEN, "#l%dlproc", edev->ctlrno);
        ktask(name, igbelproc, edev);
 
-       name = kmalloc(KNAMELEN, KMALLOC_WAIT);
+       name = kmalloc(KNAMELEN, MEM_WAIT);
        snprintf(name, KNAMELEN, "#l%drproc", edev->ctlrno);
        ktask(name, igberproc, edev);
 
@@ -2020,7 +1971,7 @@ igbepci(void)
                       pcidev->ven_id, pcidev->dev_id,
                       pcidev->bus, pcidev->dev, pcidev->func);
 
-               mmio_paddr = pcidev->bar[0].mmio_base32 ? pcidev->bar[0].mmio_base32 : 
+               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){
@@ -2046,7 +1997,7 @@ igbepci(void)
                ctlr = kzmalloc(sizeof(struct ctlr), 0);
                if(ctlr == NULL) {
                        vunmap_vmem((uintptr_t)mem, pcidev->bar[0].mmio_sz);
-                       error(Enomem);
+                       error(ENOMEM, ERROR_FIXME);
                }
                spinlock_init_irqsave(&ctlr->imlock);
                spinlock_init_irqsave(&ctlr->tlock);
@@ -2102,25 +2053,24 @@ igbepnp(struct ether* edev)
        edev->ctlr = ctlr;
        edev->port = ctlr->port;
        edev->irq = ctlr->pci->irqline;
-       edev->netif.mbps = 1000;
+       edev->tbdf = pci_to_tbdf(ctlr->pci);
+       edev->mbps = 1000;
        memmove(edev->ea, ctlr->ra, Eaddrlen);
 
        /*
         * Linkage to the generic ethernet driver.
         */
-       edev->tbdf = MKBUS(BusPCI, ctlr->pci->bus, ctlr->pci->dev,
-                          ctlr->pci->func);
        edev->attach = igbeattach;
        edev->transmit = igbetransmit;
-       edev->interrupt = igbeinterrupt;
        edev->ifstat = igbeifstat;
        edev->ctl = igbectl;
        edev->shutdown = igbeshutdown;
 
-       edev->netif.arg = edev;
-       edev->netif.promiscuous = igbepromiscuous;
-       edev->netif.multicast = igbemulticast;
+       edev->arg = edev;
+       edev->promiscuous = igbepromiscuous;
+       edev->multicast = igbemulticast;
 
+       register_irq(edev->irq, igbeinterrupt, edev, edev->tbdf);
        return 0;
 }