]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/net/ps3_gelic_net.c
IB/ehca: Support more than 4k QPs for userspace and kernelspace
[linux-2.6-omap-h63xx.git] / drivers / net / ps3_gelic_net.c
index 08d25066f051228cad0807dae76b8fa7ea7a1fa5..e565039184369b22b25dc486ff4f8a945c92e26e 100644 (file)
@@ -290,7 +290,8 @@ static void gelic_net_release_rx_chain(struct gelic_net_card *card)
                        descr->buf_addr = 0;
                        dev_kfree_skb_any(descr->skb);
                        descr->skb = NULL;
-                       descr->dmac_cmd_status = GELIC_NET_DESCR_NOT_IN_USE;
+                       gelic_net_set_descr_status(descr,
+                                                  GELIC_NET_DESCR_NOT_IN_USE);
                }
                descr = descr->next;
        } while (descr != card->rx_chain.head);
@@ -374,7 +375,7 @@ static void gelic_net_release_tx_descr(struct gelic_net_card *card,
        descr->skb = NULL;
 
        /* set descr status */
-       descr->dmac_cmd_status = GELIC_NET_DMAC_CMDSTAT_NOT_IN_USE;
+       gelic_net_set_descr_status(descr, GELIC_NET_DESCR_NOT_IN_USE);
 }
 
 /**
@@ -403,26 +404,29 @@ static void gelic_net_release_tx_chain(struct gelic_net_card *card, int stop)
                                         "%s: forcing end of tx descriptor " \
                                         "with status %x\n",
                                         __func__, status);
-                       card->netdev_stats.tx_dropped++;
+                       card->netdev->stats.tx_dropped++;
                        break;
 
                case GELIC_NET_DESCR_COMPLETE:
-                       card->netdev_stats.tx_packets++;
-                       card->netdev_stats.tx_bytes +=
-                               tx_chain->tail->skb->len;
+                       if (tx_chain->tail->skb) {
+                               card->netdev->stats.tx_packets++;
+                               card->netdev->stats.tx_bytes +=
+                                       tx_chain->tail->skb->len;
+                       }
                        break;
 
                case GELIC_NET_DESCR_CARDOWNED:
                        /* pending tx request */
                default:
                        /* any other value (== GELIC_NET_DESCR_NOT_IN_USE) */
-                       goto out;
+                       if (!stop)
+                               goto out;
                }
                gelic_net_release_tx_descr(card, tx_chain->tail);
-               release = 1;
+               release ++;
        }
 out:
-       if (!stop && release)
+       if (!stop && (2 < release))
                netif_wake_queue(card->netdev);
 }
 
@@ -552,7 +556,6 @@ static int gelic_net_stop(struct net_device *netdev)
 {
        struct gelic_net_card *card = netdev_priv(netdev);
 
-       netif_poll_disable(netdev);
        netif_stop_queue(netdev);
 
        /* turn off DMA, force end */
@@ -659,19 +662,21 @@ static int gelic_net_prepare_tx_descr_v(struct gelic_net_card *card,
 {
        dma_addr_t buf[2];
        unsigned int vlan_len;
+       struct gelic_net_descr *sec_descr = descr->next;
 
        if (skb->len < GELIC_NET_VLAN_POS)
                return -EINVAL;
 
-       memcpy(&descr->vlan, skb->data, GELIC_NET_VLAN_POS);
+       vlan_len = GELIC_NET_VLAN_POS;
+       memcpy(&descr->vlan, skb->data, vlan_len);
        if (card->vlan_index != -1) {
+               /* internal vlan tag used */
                descr->vlan.h_vlan_proto = htons(ETH_P_8021Q); /* vlan 0x8100*/
                descr->vlan.h_vlan_TCI = htons(card->vlan_id[card->vlan_index]);
-               vlan_len = GELIC_NET_VLAN_POS + VLAN_HLEN; /* VLAN_HLEN=4 */
-       } else
-               vlan_len = GELIC_NET_VLAN_POS; /* no vlan tag */
+               vlan_len += VLAN_HLEN; /* added for above two lines */
+       }
 
-       /* first descr */
+       /* map data area */
        buf[0] = dma_map_single(ctodev(card), &descr->vlan,
                             vlan_len, DMA_TO_DEVICE);
 
@@ -682,20 +687,6 @@ static int gelic_net_prepare_tx_descr_v(struct gelic_net_card *card,
                return -ENOMEM;
        }
 
-       descr->buf_addr = buf[0];
-       descr->buf_size = vlan_len;
-       descr->skb = skb; /* not used */
-       descr->data_status = 0;
-       gelic_net_set_txdescr_cmdstat(descr, skb, 1); /* not the frame end */
-
-       /* second descr */
-       card->tx_chain.head = card->tx_chain.head->next;
-       descr->next_descr_addr = descr->next->bus_addr;
-       descr = descr->next;
-       if (gelic_net_get_descr_status(descr) != GELIC_NET_DESCR_NOT_IN_USE)
-               /* XXX will be removed */
-               dev_err(ctodev(card), "descr is not free!\n");
-
        buf[1] = dma_map_single(ctodev(card), skb->data + GELIC_NET_VLAN_POS,
                             skb->len - GELIC_NET_VLAN_POS,
                             DMA_TO_DEVICE);
@@ -710,13 +701,24 @@ static int gelic_net_prepare_tx_descr_v(struct gelic_net_card *card,
                return -ENOMEM;
        }
 
-       descr->buf_addr = buf[1];
-       descr->buf_size = skb->len - GELIC_NET_VLAN_POS;
-       descr->skb = skb;
+       /* first descr */
+       descr->buf_addr = buf[0];
+       descr->buf_size = vlan_len;
+       descr->skb = NULL; /* not used */
        descr->data_status = 0;
-       descr->next_descr_addr = 0; /* terminate hw descr */
-       gelic_net_set_txdescr_cmdstat(descr, skb, 0);
+       descr->next_descr_addr = descr->next->bus_addr;
+       gelic_net_set_txdescr_cmdstat(descr, skb, 1); /* not the frame end */
 
+       /* second descr */
+       sec_descr->buf_addr = buf[1];
+       sec_descr->buf_size = skb->len - GELIC_NET_VLAN_POS;
+       sec_descr->skb = skb;
+       sec_descr->data_status = 0;
+       sec_descr->next_descr_addr = 0; /* terminate hw descr */
+       gelic_net_set_txdescr_cmdstat(sec_descr, skb, 0);
+
+       /* bump free descriptor pointer */
+       card->tx_chain.head = sec_descr->next;
        return 0;
 }
 
@@ -729,7 +731,7 @@ static int gelic_net_prepare_tx_descr_v(struct gelic_net_card *card,
 static int gelic_net_kick_txdma(struct gelic_net_card *card,
                                struct gelic_net_descr *descr)
 {
-       int status = -ENXIO;
+       int status = 0;
        int count = 10;
 
        if (card->tx_dma_progress)
@@ -763,47 +765,62 @@ static int gelic_net_kick_txdma(struct gelic_net_card *card,
 static int gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
 {
        struct gelic_net_card *card = netdev_priv(netdev);
-       struct gelic_net_descr *descr = NULL;
+       struct gelic_net_descr *descr;
        int result;
        unsigned long flags;
 
        spin_lock_irqsave(&card->tx_dma_lock, flags);
 
        gelic_net_release_tx_chain(card, 0);
-       if (!skb)
-               goto kick;
+
        descr = gelic_net_get_next_tx_descr(card);
        if (!descr) {
+               /*
+                * no more descriptors free
+                */
                netif_stop_queue(netdev);
                spin_unlock_irqrestore(&card->tx_dma_lock, flags);
                return NETDEV_TX_BUSY;
        }
-       result = gelic_net_prepare_tx_descr_v(card, descr, skb);
-
-       if (result)
-               goto error;
 
-       card->tx_chain.head = card->tx_chain.head->next;
-
-       if (descr->prev)
-               descr->prev->next_descr_addr = descr->bus_addr;
-kick:
+       result = gelic_net_prepare_tx_descr_v(card, descr, skb);
+       if (result) {
+               /*
+                * DMA map failed.  As chanses are that failure
+                * would continue, just release skb and return
+                */
+               card->netdev->stats.tx_dropped++;
+               dev_kfree_skb_any(skb);
+               spin_unlock_irqrestore(&card->tx_dma_lock, flags);
+               return NETDEV_TX_OK;
+       }
+       /*
+        * link this prepared descriptor to previous one
+        * to achieve high performance
+        */
+       descr->prev->next_descr_addr = descr->bus_addr;
        /*
         * as hardware descriptor is modified in the above lines,
         * ensure that the hardware sees it
         */
        wmb();
-       if (gelic_net_kick_txdma(card, card->tx_chain.tail))
-               goto error;
+       if (gelic_net_kick_txdma(card, descr)) {
+               /*
+                * kick failed.
+                * release descriptors which were just prepared
+                */
+               card->netdev->stats.tx_dropped++;
+               gelic_net_release_tx_descr(card, descr);
+               gelic_net_release_tx_descr(card, descr->next);
+               card->tx_chain.tail = descr->next->next;
+               dev_info(ctodev(card), "%s: kick failure\n", __func__);
+       } else {
+               /* OK, DMA started/reserved */
+               netdev->trans_start = jiffies;
+       }
 
-       netdev->trans_start = jiffies;
        spin_unlock_irqrestore(&card->tx_dma_lock, flags);
        return NETDEV_TX_OK;
-
-error:
-       card->netdev_stats.tx_dropped++;
-       spin_unlock_irqrestore(&card->tx_dma_lock, flags);
-       return NETDEV_TX_LOCKED;
 }
 
 /**
@@ -854,8 +871,8 @@ static void gelic_net_pass_skb_up(struct gelic_net_descr *descr,
                skb->ip_summed = CHECKSUM_NONE;
 
        /* update netdevice statistics */
-       card->netdev_stats.rx_packets++;
-       card->netdev_stats.rx_bytes += skb->len;
+       card->netdev->stats.rx_packets++;
+       card->netdev->stats.rx_bytes += skb->len;
 
        /* pass skb up to stack */
        netif_receive_skb(skb);
@@ -895,38 +912,67 @@ static int gelic_net_decode_one_descr(struct gelic_net_card *card)
            (status == GELIC_NET_DESCR_FORCE_END)) {
                dev_info(ctodev(card), "dropping RX descriptor with state %x\n",
                         status);
-               card->netdev_stats.rx_dropped++;
+               card->netdev->stats.rx_dropped++;
                goto refill;
        }
 
-       if ((status != GELIC_NET_DESCR_COMPLETE) &&
-           (status != GELIC_NET_DESCR_FRAME_END)) {
+       if (status == GELIC_NET_DESCR_BUFFER_FULL) {
+               /*
+                * Buffer full would occur if and only if
+                * the frame length was longer than the size of this
+                * descriptor's buffer.  If the frame length was equal
+                * to or shorter than buffer'size, FRAME_END condition
+                * would occur.
+                * Anyway this frame was longer than the MTU,
+                * just drop it.
+                */
+               dev_info(ctodev(card), "overlength frame\n");
+               goto refill;
+       }
+       /*
+        * descriptoers any other than FRAME_END here should
+        * be treated as error.
+        */
+       if (status != GELIC_NET_DESCR_FRAME_END) {
                dev_dbg(ctodev(card), "RX descriptor with state %x\n",
                        status);
                goto refill;
        }
 
        /* ok, we've got a packet in descr */
-       gelic_net_pass_skb_up(descr, card); /* 1: skb_up sccess */
-
+       gelic_net_pass_skb_up(descr, card);
 refill:
-       descr->next_descr_addr = 0; /* unlink the descr */
+       /*
+        * So that always DMAC can see the end
+        * of the descriptor chain to avoid
+        * from unwanted DMAC overrun.
+        */
+       descr->next_descr_addr = 0;
 
        /* change the descriptor state: */
        gelic_net_set_descr_status(descr, GELIC_NET_DESCR_NOT_IN_USE);
 
-       /* refill one desc
-        * FIXME: this can fail, but for now, just leave this
-        * descriptor without skb
+       /*
+        * this call can fail, but for now, just leave this
+        * decriptor without skb
         */
        gelic_net_prepare_rx_descr(card, descr);
+
        chain->head = descr;
        chain->tail = descr->next;
+
+       /*
+        * Set this descriptor the end of the chain.
+        */
        descr->prev->next_descr_addr = descr->bus_addr;
 
+       /*
+        * If dmac chain was met, DMAC stopped.
+        * thus re-enable it
+        */
        if (dmac_chain_ended) {
-               gelic_net_enable_rxdmac(card);
-               dev_dbg(ctodev(card), "reenable rx dma\n");
+               card->rx_dma_restart_required = 1;
+               dev_dbg(ctodev(card), "reenable rx dma scheduled\n");
        }
 
        return 1;
@@ -968,20 +1014,6 @@ static int gelic_net_poll(struct net_device *netdev, int *budget)
        } else
                return 1;
 }
-
-/**
- * gelic_net_get_stats - get interface statistics
- * @netdev: interface device structure
- *
- * returns the interface statistics residing in the gelic_net_card struct
- */
-static struct net_device_stats *gelic_net_get_stats(struct net_device *netdev)
-{
-       struct gelic_net_card *card = netdev_priv(netdev);
-
-       return &card->netdev_stats;
-}
-
 /**
  * gelic_net_change_mtu - changes the MTU of an interface
  * @netdev: interface device structure
@@ -1016,6 +1048,11 @@ static irqreturn_t gelic_net_interrupt(int irq, void *ptr)
        if (!status)
                return IRQ_NONE;
 
+       if (card->rx_dma_restart_required) {
+               card->rx_dma_restart_required = 0;
+               gelic_net_enable_rxdmac(card);
+       }
+
        if (status & GELIC_NET_RXINT) {
                gelic_net_rx_irq_off(card);
                netif_rx_schedule(netdev);
@@ -1024,9 +1061,10 @@ static irqreturn_t gelic_net_interrupt(int irq, void *ptr)
        if (status & GELIC_NET_TXINT) {
                spin_lock_irqsave(&card->tx_dma_lock, flags);
                card->tx_dma_progress = 0;
+               gelic_net_release_tx_chain(card, 0);
+               /* kick outstanding tx descriptor if any */
+               gelic_net_kick_txdma(card, card->tx_chain.tail);
                spin_unlock_irqrestore(&card->tx_dma_lock, flags);
-               /* start pending DMA */
-               gelic_net_xmit(NULL, netdev);
        }
        return IRQ_HANDLED;
 }
@@ -1068,7 +1106,7 @@ static int gelic_net_open_device(struct gelic_net_card *card)
        }
 
        result = request_irq(card->netdev->irq, gelic_net_interrupt,
-                            IRQF_DISABLED, "gelic network", card->netdev);
+                            IRQF_DISABLED, card->netdev->name, card->netdev);
 
        if (result) {
                dev_info(ctodev(card), "%s:%d: request_irq failed (%d)\n",
@@ -1107,7 +1145,7 @@ static int gelic_net_open(struct net_device *netdev)
                        card->descr, GELIC_NET_TX_DESCRIPTORS))
                goto alloc_tx_failed;
        if (gelic_net_init_chain(card, &card->rx_chain,
-                                card->descr + GELIC_NET_RX_DESCRIPTORS,
+                                card->descr + GELIC_NET_TX_DESCRIPTORS,
                                 GELIC_NET_RX_DESCRIPTORS))
                goto alloc_rx_failed;
 
@@ -1129,7 +1167,6 @@ static int gelic_net_open(struct net_device *netdev)
 
        netif_start_queue(netdev);
        netif_carrier_on(netdev);
-       netif_poll_enable(netdev);
 
        return 0;
 
@@ -1141,7 +1178,6 @@ alloc_tx_failed:
        return -ENOMEM;
 }
 
-#ifdef GELIC_NET_ETHTOOL
 static void gelic_net_get_drvinfo (struct net_device *netdev,
                                   struct ethtool_drvinfo *info)
 {
@@ -1261,7 +1297,6 @@ static struct ethtool_ops gelic_net_ethtool_ops = {
        .get_rx_csum    = gelic_net_get_rx_csum,
        .set_rx_csum    = gelic_net_set_rx_csum,
 };
-#endif
 
 /**
  * gelic_net_tx_timeout_task - task scheduled by the watchdog timeout
@@ -1320,7 +1355,6 @@ static void gelic_net_setup_netdev_ops(struct net_device *netdev)
        netdev->open = &gelic_net_open;
        netdev->stop = &gelic_net_stop;
        netdev->hard_start_xmit = &gelic_net_xmit;
-       netdev->get_stats = &gelic_net_get_stats;
        netdev->set_multicast_list = &gelic_net_set_multi;
        netdev->change_mtu = &gelic_net_change_mtu;
        /* tx watchdog */
@@ -1329,9 +1363,7 @@ static void gelic_net_setup_netdev_ops(struct net_device *netdev)
        /* NAPI */
        netdev->poll = &gelic_net_poll;
        netdev->weight = GELIC_NET_NAPI_WEIGHT;
-#ifdef GELIC_NET_ETHTOOL
        netdev->ethtool_ops = &gelic_net_ethtool_ops;
-#endif
 }
 
 /**