]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/net/spider_net.c
Merge branch 'upstream-linus' of master.kernel.org:/pub/scm/linux/kernel/git/jgarzik...
[linux-2.6-omap-h63xx.git] / drivers / net / spider_net.c
index 572c7546e158033acea6ee9f2adff61652fe540f..bf6ff39e02bbc035e2da03992be4c3661d07fa1c 100644 (file)
@@ -367,21 +367,20 @@ spider_net_free_rx_chain_contents(struct spider_net_card *card)
 }
 
 /**
- * spider_net_prepare_rx_descr - reinitializes a rx descriptor
+ * spider_net_prepare_rx_descr - Reinitialize RX descriptor
  * @card: card structure
  * @descr: descriptor to re-init
  *
- * return 0 on succes, <0 on failure
+ * Return 0 on succes, <0 on failure.
  *
- * allocates a new rx skb, iommu-maps it and attaches it to the descriptor.
- * Activate the descriptor state-wise
+ * Allocates a new rx skb, iommu-maps it and attaches it to the
+ * descriptor. Mark the descriptor as activated, ready-to-use.
  */
 static int
 spider_net_prepare_rx_descr(struct spider_net_card *card,
                            struct spider_net_descr *descr)
 {
        dma_addr_t buf;
-       int error = 0;
        int offset;
        int bufsize;
 
@@ -409,7 +408,7 @@ spider_net_prepare_rx_descr(struct spider_net_card *card,
                (SPIDER_NET_RXBUF_ALIGN - 1);
        if (offset)
                skb_reserve(descr->skb, SPIDER_NET_RXBUF_ALIGN - offset);
-       /* io-mmu-map the skb */
+       /* iommu-map the skb */
        buf = pci_map_single(card->pdev, descr->skb->data,
                        SPIDER_NET_MAX_FRAME, PCI_DMA_FROMDEVICE);
        descr->buf_addr = buf;
@@ -420,11 +419,16 @@ spider_net_prepare_rx_descr(struct spider_net_card *card,
                card->spider_stats.rx_iommu_map_error++;
                descr->dmac_cmd_status = SPIDER_NET_DESCR_NOT_IN_USE;
        } else {
+               descr->next_descr_addr = 0;
+               wmb();
                descr->dmac_cmd_status = SPIDER_NET_DESCR_CARDOWNED |
                                         SPIDER_NET_DMAC_NOINTR_COMPLETE;
+
+               wmb();
+               descr->prev->next_descr_addr = descr->bus_addr;
        }
 
-       return error;
+       return 0;
 }
 
 /**
@@ -488,10 +492,10 @@ spider_net_refill_rx_chain(struct spider_net_card *card)
 }
 
 /**
- * spider_net_alloc_rx_skbs - allocates rx skbs in rx descriptor chains
+ * spider_net_alloc_rx_skbs - Allocates rx skbs in rx descriptor chains
  * @card: card structure
  *
- * returns 0 on success, <0 on failure
+ * Returns 0 on success, <0 on failure.
  */
 static int
 spider_net_alloc_rx_skbs(struct spider_net_card *card)
@@ -502,16 +506,16 @@ spider_net_alloc_rx_skbs(struct spider_net_card *card)
        result = -ENOMEM;
 
        chain = &card->rx_chain;
-       /* put at least one buffer into the chain. if this fails,
-        * we've got a problem. if not, spider_net_refill_rx_chain
-        * will do the rest at the end of this function */
+       /* Put at least one buffer into the chain. if this fails,
+        * we've got a problem. If not, spider_net_refill_rx_chain
+        * will do the rest at the end of this function. */
        if (spider_net_prepare_rx_descr(card, chain->head))
                goto error;
        else
                chain->head = chain->head->next;
 
-       /* this will allocate the rest of the rx buffers; if not, it's
-        * business as usual later on */
+       /* This will allocate the rest of the rx buffers;
+        * if not, it's business as usual later on. */
        spider_net_refill_rx_chain(card);
        spider_net_enable_rxdmac(card);
        return 0;
@@ -910,16 +914,13 @@ spider_net_do_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  * spider_net_pass_skb_up - takes an skb from a descriptor and passes it on
  * @descr: descriptor to process
  * @card: card structure
- * @napi: whether caller is in NAPI context
  *
- * returns 1 on success, 0 if no packet was passed to the stack
- *
- * iommu-unmaps the skb, fills out skb structure and passes the data to the
- * stack. The descriptor state is not changed.
+ * Fills out skb structure and passes the data to the stack.
+ * The descriptor state is not changed.
  */
-static int
+static void
 spider_net_pass_skb_up(struct spider_net_descr *descr,
-                      struct spider_net_card *card, int napi)
+                      struct spider_net_card *card)
 {
        struct sk_buff *skb;
        struct net_device *netdev;
@@ -927,23 +928,8 @@ spider_net_pass_skb_up(struct spider_net_descr *descr,
 
        data_status = descr->data_status;
        data_error = descr->data_error;
-
        netdev = card->netdev;
 
-       /* unmap descriptor */
-       pci_unmap_single(card->pdev, descr->buf_addr, SPIDER_NET_MAX_FRAME,
-                       PCI_DMA_FROMDEVICE);
-
-       /* the cases we'll throw away the packet immediately */
-       if (data_error & SPIDER_NET_DESTROY_RX_FLAGS) {
-               if (netif_msg_rx_err(card))
-                       pr_err("error in received descriptor found, "
-                              "data_status=x%08x, data_error=x%08x\n",
-                              data_status, data_error);
-               card->spider_stats.rx_desc_error++;
-               return 0;
-       }
-
        skb = descr->skb;
        skb->dev = netdev;
        skb_put(skb, descr->valid_size);
@@ -972,57 +958,72 @@ spider_net_pass_skb_up(struct spider_net_descr *descr,
        }
 
        /* pass skb up to stack */
-       if (napi)
-               netif_receive_skb(skb);
-       else
-               netif_rx_ni(skb);
+       netif_receive_skb(skb);
 
        /* update netdevice statistics */
        card->netdev_stats.rx_packets++;
        card->netdev_stats.rx_bytes += skb->len;
+}
 
-       return 1;
+#ifdef DEBUG
+static void show_rx_chain(struct spider_net_card *card)
+{
+       struct spider_net_descr_chain *chain = &card->rx_chain;
+       struct spider_net_descr *start= chain->tail;
+       struct spider_net_descr *descr= start;
+       int status;
+
+       int cnt = 0;
+       int cstat = spider_net_get_descr_status(descr);
+       printk(KERN_INFO "RX chain tail at descr=%ld\n",
+            (start - card->descr) - card->tx_chain.num_desc);
+       status = cstat;
+       do
+       {
+               status = spider_net_get_descr_status(descr);
+               if (cstat != status) {
+                       printk(KERN_INFO "Have %d descrs with stat=x%08x\n", cnt, cstat);
+                       cstat = status;
+                       cnt = 0;
+               }
+               cnt ++;
+               descr = descr->next;
+       } while (descr != start);
+       printk(KERN_INFO "Last %d descrs with stat=x%08x\n", cnt, cstat);
 }
+#endif
 
 /**
  * spider_net_decode_one_descr - processes an rx descriptor
  * @card: card structure
- * @napi: whether caller is in NAPI context
  *
- * returns 1 if a packet has been sent to the stack, otherwise 0
+ * Returns 1 if a packet has been sent to the stack, otherwise 0
  *
- * processes an rx descriptor by iommu-unmapping the data buffer and passing
+ * Processes an rx descriptor by iommu-unmapping the data buffer and passing
  * the packet up to the stack. This function is called in softirq
  * context, e.g. either bottom half from interrupt or NAPI polling context
  */
 static int
-spider_net_decode_one_descr(struct spider_net_card *card, int napi)
+spider_net_decode_one_descr(struct spider_net_card *card)
 {
        struct spider_net_descr_chain *chain = &card->rx_chain;
        struct spider_net_descr *descr = chain->tail;
        int status;
-       int result;
 
        status = spider_net_get_descr_status(descr);
 
-       if (status == SPIDER_NET_DESCR_CARDOWNED) {
-               /* nothing in the descriptor yet */
-               result=0;
-               goto out;
-       }
-
-       if (status == SPIDER_NET_DESCR_NOT_IN_USE) {
-               /* not initialized yet, the ring must be empty */
-               spider_net_refill_rx_chain(card);
-               spider_net_enable_rxdmac(card);
-               result=0;
-               goto out;
-       }
+       /* Nothing in the descriptor, or ring must be empty */
+       if ((status == SPIDER_NET_DESCR_CARDOWNED) ||
+           (status == SPIDER_NET_DESCR_NOT_IN_USE))
+               return 0;
 
        /* descriptor definitively used -- move on tail */
        chain->tail = descr->next;
 
-       result = 0;
+       /* unmap descriptor */
+       pci_unmap_single(card->pdev, descr->buf_addr,
+                       SPIDER_NET_MAX_FRAME, PCI_DMA_FROMDEVICE);
+
        if ( (status == SPIDER_NET_DESCR_RESPONSE_ERROR) ||
             (status == SPIDER_NET_DESCR_PROTECTION_ERROR) ||
             (status == SPIDER_NET_DESCR_FORCE_END) ) {
@@ -1030,30 +1031,55 @@ spider_net_decode_one_descr(struct spider_net_card *card, int napi)
                        pr_err("%s: dropping RX descriptor with state %d\n",
                               card->netdev->name, status);
                card->netdev_stats.rx_dropped++;
-               pci_unmap_single(card->pdev, descr->buf_addr,
-                               SPIDER_NET_MAX_FRAME, PCI_DMA_FROMDEVICE);
-               dev_kfree_skb_irq(descr->skb);
-               goto refill;
+               goto bad_desc;
        }
 
        if ( (status != SPIDER_NET_DESCR_COMPLETE) &&
             (status != SPIDER_NET_DESCR_FRAME_END) ) {
                if (netif_msg_rx_err(card))
-                       pr_err("%s: RX descriptor with state %d\n",
+                       pr_err("%s: RX descriptor with unkown state %d\n",
                               card->netdev->name, status);
                card->spider_stats.rx_desc_unk_state++;
-               goto refill;
+               goto bad_desc;
        }
 
-       /* ok, we've got a packet in descr */
-       result = spider_net_pass_skb_up(descr, card, napi);
-refill:
+       /* The cases we'll throw away the packet immediately */
+       if (descr->data_error & SPIDER_NET_DESTROY_RX_FLAGS) {
+               if (netif_msg_rx_err(card))
+                       pr_err("%s: error in received descriptor found, "
+                              "data_status=x%08x, data_error=x%08x\n",
+                              card->netdev->name,
+                              descr->data_status, descr->data_error);
+               goto bad_desc;
+       }
+
+       if (descr->dmac_cmd_status & 0xfefe) {
+               pr_err("%s: bad status, cmd_status=x%08x\n",
+                              card->netdev->name,
+                              descr->dmac_cmd_status);
+               pr_err("buf_addr=x%08x\n", descr->buf_addr);
+               pr_err("buf_size=x%08x\n", descr->buf_size);
+               pr_err("next_descr_addr=x%08x\n", descr->next_descr_addr);
+               pr_err("result_size=x%08x\n", descr->result_size);
+               pr_err("valid_size=x%08x\n", descr->valid_size);
+               pr_err("data_status=x%08x\n", descr->data_status);
+               pr_err("data_error=x%08x\n", descr->data_error);
+               pr_err("bus_addr=x%08x\n", descr->bus_addr);
+               pr_err("which=%ld\n", descr - card->rx_chain.ring);
+
+               card->spider_stats.rx_desc_error++;
+               goto bad_desc;
+       }
+
+       /* Ok, we've got a packet in descr */
+       spider_net_pass_skb_up(descr, card);
        descr->dmac_cmd_status = SPIDER_NET_DESCR_NOT_IN_USE;
-       /* change the descriptor state: */
-       if (!napi)
-               spider_net_refill_rx_chain(card);
-out:
-       return result;
+       return 1;
+
+bad_desc:
+       dev_kfree_skb_irq(descr->skb);
+       descr->dmac_cmd_status = SPIDER_NET_DESCR_NOT_IN_USE;
+       return 0;
 }
 
 /**
@@ -1079,7 +1105,7 @@ spider_net_poll(struct net_device *netdev, int *budget)
        packets_to_do = min(*budget, netdev->quota);
 
        while (packets_to_do) {
-               if (spider_net_decode_one_descr(card, 1)) {
+               if (spider_net_decode_one_descr(card)) {
                        packets_done++;
                        packets_to_do--;
                } else {
@@ -1092,6 +1118,7 @@ spider_net_poll(struct net_device *netdev, int *budget)
        netdev->quota -= packets_done;
        *budget -= packets_done;
        spider_net_refill_rx_chain(card);
+       spider_net_enable_rxdmac(card);
 
        /* if all packets are in the stack, enable interrupts and return 0 */
        /* if not, return 1 */
@@ -1627,7 +1654,6 @@ int
 spider_net_open(struct net_device *netdev)
 {
        struct spider_net_card *card = netdev_priv(netdev);
-       struct spider_net_descr *descr;
        int result;
 
        result = spider_net_init_chain(card, &card->tx_chain);
@@ -1639,13 +1665,6 @@ spider_net_open(struct net_device *netdev)
        if (result)
                goto alloc_rx_failed;
 
-       /* Make a ring of of bus addresses */
-       descr = card->rx_chain.ring;
-       do {
-               descr->next_descr_addr = descr->next->bus_addr;
-               descr = descr->next;
-       } while (descr != card->rx_chain.ring);
-
        /* Allocate rx skbs */
        if (spider_net_alloc_rx_skbs(card))
                goto alloc_skbs_failed;