]> err.no Git - linux-2.6/blobdiff - drivers/net/cxgb3/sge.c
virtio: fix net driver loop case where we fail to restart
[linux-2.6] / drivers / net / cxgb3 / sge.c
index 58a5f60521ed87194db262b5a2577e7df90c02d7..c15e43a8543b983f82b0517010979d5eb782bbf8 100644 (file)
@@ -79,7 +79,7 @@ enum {
 };
 
 struct tx_desc {
-       u64 flit[TX_DESC_FLITS];
+       __be64 flit[TX_DESC_FLITS];
 };
 
 struct rx_desc {
@@ -544,7 +544,7 @@ static void *alloc_ring(struct pci_dev *pdev, size_t nelem, size_t elem_size,
  *     as HW contexts, packet buffers, and descriptor rings.  Traffic to the
  *     queue set must be quiesced prior to calling this.
  */
-void t3_free_qset(struct adapter *adapter, struct sge_qset *q)
+static void t3_free_qset(struct adapter *adapter, struct sge_qset *q)
 {
        int i;
        struct pci_dev *pdev = adapter->pdev;
@@ -591,9 +591,6 @@ void t3_free_qset(struct adapter *adapter, struct sge_qset *q)
                                  q->rspq.desc, q->rspq.phys_addr);
        }
 
-       if (q->netdev)
-               q->netdev->atalk_ptr = NULL;
-
        memset(q, 0, sizeof(*q));
 }
 
@@ -907,8 +904,8 @@ static void write_wr_hdr_sgl(unsigned int ndesc, struct sk_buff *skb,
                             const struct sge_txq *q,
                             const struct sg_ent *sgl,
                             unsigned int flits, unsigned int sgl_flits,
-                            unsigned int gen, unsigned int wr_hi,
-                            unsigned int wr_lo)
+                            unsigned int gen, __be32 wr_hi,
+                            __be32 wr_lo)
 {
        struct work_request_hdr *wrp = (struct work_request_hdr *)d;
        struct tx_sw_desc *sd = &q->sdesc[pidx];
@@ -1074,7 +1071,7 @@ int t3_eth_xmit(struct sk_buff *skb, struct net_device *dev)
        unsigned int ndesc, pidx, credits, gen, compl;
        const struct port_info *pi = netdev_priv(dev);
        struct adapter *adap = pi->adapter;
-       struct sge_qset *qs = dev2qset(dev);
+       struct sge_qset *qs = pi->qs;
        struct sge_txq *q = &qs->txq[TXQ_ETH];
 
        /*
@@ -1182,8 +1179,8 @@ int t3_eth_xmit(struct sk_buff *skb, struct net_device *dev)
  *
  *     Writes a packet as immediate data into a Tx descriptor.  The packet
  *     contains a work request at its beginning.  We must write the packet
- *     carefully so the SGE doesn't read accidentally before it's written in
- *     its entirety.
+ *     carefully so the SGE doesn't read it accidentally before it's written
+ *     in its entirety.
  */
 static inline void write_imm(struct tx_desc *d, struct sk_buff *skb,
                             unsigned int len, unsigned int gen)
@@ -1191,7 +1188,11 @@ static inline void write_imm(struct tx_desc *d, struct sk_buff *skb,
        struct work_request_hdr *from = (struct work_request_hdr *)skb->data;
        struct work_request_hdr *to = (struct work_request_hdr *)d;
 
-       memcpy(&to[1], &from[1], len - sizeof(*from));
+       if (likely(!skb->data_len))
+               memcpy(&to[1], &from[1], len - sizeof(*from));
+       else
+               skb_copy_bits(skb, sizeof(*from), &to[1], len - sizeof(*from));
+
        to->wr_hi = from->wr_hi | htonl(F_WR_SOP | F_WR_EOP |
                                        V_WR_BCNTLFLT(len & 7));
        wmb();
@@ -1261,7 +1262,7 @@ static inline void reclaim_completed_tx_imm(struct sge_txq *q)
 
 static inline int immediate(const struct sk_buff *skb)
 {
-       return skb->len <= WR_LEN && !skb->data_len;
+       return skb->len <= WR_LEN;
 }
 
 /**
@@ -1326,13 +1327,12 @@ static void restart_ctrlq(unsigned long data)
        struct sk_buff *skb;
        struct sge_qset *qs = (struct sge_qset *)data;
        struct sge_txq *q = &qs->txq[TXQ_CTRL];
-       const struct port_info *pi = netdev_priv(qs->netdev);
-       struct adapter *adap = pi->adapter;
 
        spin_lock(&q->lock);
       again:reclaim_completed_tx_imm(q);
 
-       while (q->in_use < q->size && (skb = __skb_dequeue(&q->sendq)) != NULL) {
+       while (q->in_use < q->size &&
+              (skb = __skb_dequeue(&q->sendq)) != NULL) {
 
                write_imm(&q->desc[q->pidx], skb, skb->len, q->gen);
 
@@ -1354,7 +1354,7 @@ static void restart_ctrlq(unsigned long data)
        }
 
        spin_unlock(&q->lock);
-       t3_write_reg(adap, A_SG_KDOORBELL,
+       t3_write_reg(qs->adap, A_SG_KDOORBELL,
                     F_SELEGRCNTX | V_EGRCNTX(q->cntxt_id));
 }
 
@@ -1468,12 +1468,13 @@ static void write_ofld_wr(struct adapter *adap, struct sk_buff *skb,
  */
 static inline unsigned int calc_tx_descs_ofld(const struct sk_buff *skb)
 {
-       unsigned int flits, cnt = skb_shinfo(skb)->nr_frags;
+       unsigned int flits, cnt;
 
-       if (skb->len <= WR_LEN && cnt == 0)
+       if (skb->len <= WR_LEN)
                return 1;       /* packet fits as immediate data */
 
        flits = skb_transport_offset(skb) / 8;  /* headers */
+       cnt = skb_shinfo(skb)->nr_frags;
        if (skb->tail != skb->transport_header)
                cnt++;
        return flits_to_desc(flits + sgl_len(cnt));
@@ -1638,8 +1639,7 @@ static inline void offload_enqueue(struct sge_rspq *q, struct sk_buff *skb)
        else {
                struct sge_qset *qs = rspq_to_qset(q);
 
-               if (__netif_rx_schedule_prep(qs->netdev))
-                       __netif_rx_schedule(qs->netdev);
+               napi_schedule(&qs->napi);
                q->rx_head = skb;
        }
        q->rx_tail = skb;
@@ -1675,34 +1675,30 @@ static inline void deliver_partial_bundle(struct t3cdev *tdev,
  *     receive handler.  Batches need to be of modest size as we do prefetches
  *     on the packets in each.
  */
-static int ofld_poll(struct net_device *dev, int *budget)
+static int ofld_poll(struct napi_struct *napi, int budget)
 {
-       const struct port_info *pi = netdev_priv(dev);
-       struct adapter *adapter = pi->adapter;
-       struct sge_qset *qs = dev2qset(dev);
+       struct sge_qset *qs = container_of(napi, struct sge_qset, napi);
        struct sge_rspq *q = &qs->rspq;
-       int work_done, limit = min(*budget, dev->quota), avail = limit;
+       struct adapter *adapter = qs->adap;
+       int work_done = 0;
 
-       while (avail) {
+       while (work_done < budget) {
                struct sk_buff *head, *tail, *skbs[RX_BUNDLE_SIZE];
                int ngathered;
 
                spin_lock_irq(&q->lock);
                head = q->rx_head;
                if (!head) {
-                       work_done = limit - avail;
-                       *budget -= work_done;
-                       dev->quota -= work_done;
-                       __netif_rx_complete(dev);
+                       napi_complete(napi);
                        spin_unlock_irq(&q->lock);
-                       return 0;
+                       return work_done;
                }
 
                tail = q->rx_tail;
                q->rx_head = q->rx_tail = NULL;
                spin_unlock_irq(&q->lock);
 
-               for (ngathered = 0; avail && head; avail--) {
+               for (ngathered = 0; work_done < budget && head; work_done++) {
                        prefetch(head->data);
                        skbs[ngathered] = head;
                        head = head->next;
@@ -1724,10 +1720,8 @@ static int ofld_poll(struct net_device *dev, int *budget)
                }
                deliver_partial_bundle(&adapter->tdev, q, skbs, ngathered);
        }
-       work_done = limit - avail;
-       *budget -= work_done;
-       dev->quota -= work_done;
-       return 1;
+
+       return work_done;
 }
 
 /**
@@ -2071,50 +2065,47 @@ static inline int is_pure_response(const struct rsp_desc *r)
 
 /**
  *     napi_rx_handler - the NAPI handler for Rx processing
- *     @dev: the net device
+ *     @napi: the napi instance
  *     @budget: how many packets we can process in this round
  *
  *     Handler for new data events when using NAPI.
  */
-static int napi_rx_handler(struct net_device *dev, int *budget)
+static int napi_rx_handler(struct napi_struct *napi, int budget)
 {
-       const struct port_info *pi = netdev_priv(dev);
-       struct adapter *adap = pi->adapter;
-       struct sge_qset *qs = dev2qset(dev);
-       int effective_budget = min(*budget, dev->quota);
+       struct sge_qset *qs = container_of(napi, struct sge_qset, napi);
+       struct adapter *adap = qs->adap;
+       int work_done = process_responses(adap, qs, budget);
 
-       int work_done = process_responses(adap, qs, effective_budget);
-       *budget -= work_done;
-       dev->quota -= work_done;
+       if (likely(work_done < budget)) {
+               napi_complete(napi);
 
-       if (work_done >= effective_budget)
-               return 1;
-
-       netif_rx_complete(dev);
-
-       /*
-        * Because we don't atomically flush the following write it is
-        * possible that in very rare cases it can reach the device in a way
-        * that races with a new response being written plus an error interrupt
-        * causing the NAPI interrupt handler below to return unhandled status
-        * to the OS.  To protect against this would require flushing the write
-        * and doing both the write and the flush with interrupts off.  Way too
-        * expensive and unjustifiable given the rarity of the race.
-        *
-        * The race cannot happen at all with MSI-X.
-        */
-       t3_write_reg(adap, A_SG_GTS, V_RSPQ(qs->rspq.cntxt_id) |
-                    V_NEWTIMER(qs->rspq.next_holdoff) |
-                    V_NEWINDEX(qs->rspq.cidx));
-       return 0;
+               /*
+                * Because we don't atomically flush the following
+                * write it is possible that in very rare cases it can
+                * reach the device in a way that races with a new
+                * response being written plus an error interrupt
+                * causing the NAPI interrupt handler below to return
+                * unhandled status to the OS.  To protect against
+                * this would require flushing the write and doing
+                * both the write and the flush with interrupts off.
+                * Way too expensive and unjustifiable given the
+                * rarity of the race.
+                *
+                * The race cannot happen at all with MSI-X.
+                */
+               t3_write_reg(adap, A_SG_GTS, V_RSPQ(qs->rspq.cntxt_id) |
+                            V_NEWTIMER(qs->rspq.next_holdoff) |
+                            V_NEWINDEX(qs->rspq.cidx));
+       }
+       return work_done;
 }
 
 /*
  * Returns true if the device is already scheduled for polling.
  */
-static inline int napi_is_scheduled(struct net_device *dev)
+static inline int napi_is_scheduled(struct napi_struct *napi)
 {
-       return test_bit(__LINK_STATE_RX_SCHED, &dev->state);
+       return test_bit(NAPI_STATE_SCHED, &napi->state);
 }
 
 /**
@@ -2197,8 +2188,7 @@ static inline int handle_responses(struct adapter *adap, struct sge_rspq *q)
                             V_NEWTIMER(q->holdoff_tmr) | V_NEWINDEX(q->cidx));
                return 0;
        }
-       if (likely(__netif_rx_schedule_prep(qs->netdev)))
-               __netif_rx_schedule(qs->netdev);
+       napi_schedule(&qs->napi);
        return 1;
 }
 
@@ -2209,8 +2199,7 @@ static inline int handle_responses(struct adapter *adap, struct sge_rspq *q)
 irqreturn_t t3_sge_intr_msix(int irq, void *cookie)
 {
        struct sge_qset *qs = cookie;
-       const struct port_info *pi = netdev_priv(qs->netdev);
-       struct adapter *adap = pi->adapter;
+       struct adapter *adap = qs->adap;
        struct sge_rspq *q = &qs->rspq;
 
        spin_lock(&q->lock);
@@ -2226,16 +2215,14 @@ irqreturn_t t3_sge_intr_msix(int irq, void *cookie)
  * The MSI-X interrupt handler for an SGE response queue for the NAPI case
  * (i.e., response queue serviced by NAPI polling).
  */
-irqreturn_t t3_sge_intr_msix_napi(int irq, void *cookie)
+static irqreturn_t t3_sge_intr_msix_napi(int irq, void *cookie)
 {
        struct sge_qset *qs = cookie;
-       const struct port_info *pi = netdev_priv(qs->netdev);
-       struct adapter *adap = pi->adapter;
        struct sge_rspq *q = &qs->rspq;
 
        spin_lock(&q->lock);
 
-       if (handle_responses(adap, q) < 0)
+       if (handle_responses(qs->adap, q) < 0)
                q->unhandled_irqs++;
        spin_unlock(&q->lock);
        return IRQ_HANDLED;
@@ -2278,11 +2265,13 @@ static irqreturn_t t3_intr_msi(int irq, void *cookie)
        return IRQ_HANDLED;
 }
 
-static int rspq_check_napi(struct net_device *dev, struct sge_rspq *q)
+static int rspq_check_napi(struct sge_qset *qs)
 {
-       if (!napi_is_scheduled(dev) && is_new_response(&q->desc[q->cidx], q)) {
-               if (likely(__netif_rx_schedule_prep(dev)))
-                       __netif_rx_schedule(dev);
+       struct sge_rspq *q = &qs->rspq;
+
+       if (!napi_is_scheduled(&qs->napi) &&
+           is_new_response(&q->desc[q->cidx], q)) {
+               napi_schedule(&qs->napi);
                return 1;
        }
        return 0;
@@ -2295,7 +2284,7 @@ static int rspq_check_napi(struct net_device *dev, struct sge_rspq *q)
  * one SGE response queue per port in this mode and protect all response
  * queues with queue 0's lock.
  */
-irqreturn_t t3_intr_msi_napi(int irq, void *cookie)
+static irqreturn_t t3_intr_msi_napi(int irq, void *cookie)
 {
        int new_packets;
        struct adapter *adap = cookie;
@@ -2303,10 +2292,9 @@ irqreturn_t t3_intr_msi_napi(int irq, void *cookie)
 
        spin_lock(&q->lock);
 
-       new_packets = rspq_check_napi(adap->sge.qs[0].netdev, q);
+       new_packets = rspq_check_napi(&adap->sge.qs[0]);
        if (adap->params.nports == 2)
-               new_packets += rspq_check_napi(adap->sge.qs[1].netdev,
-                                              &adap->sge.qs[1].rspq);
+               new_packets += rspq_check_napi(&adap->sge.qs[1]);
        if (!new_packets && t3_slow_intr_handler(adap) == 0)
                q->unhandled_irqs++;
 
@@ -2409,9 +2397,9 @@ static irqreturn_t t3b_intr(int irq, void *cookie)
 static irqreturn_t t3b_intr_napi(int irq, void *cookie)
 {
        u32 map;
-       struct net_device *dev;
        struct adapter *adap = cookie;
-       struct sge_rspq *q0 = &adap->sge.qs[0].rspq;
+       struct sge_qset *qs0 = &adap->sge.qs[0];
+       struct sge_rspq *q0 = &qs0->rspq;
 
        t3_write_reg(adap, A_PL_CLI, 0);
        map = t3_read_reg(adap, A_SG_DATA_INTR);
@@ -2424,18 +2412,11 @@ static irqreturn_t t3b_intr_napi(int irq, void *cookie)
        if (unlikely(map & F_ERRINTR))
                t3_slow_intr_handler(adap);
 
-       if (likely(map & 1)) {
-               dev = adap->sge.qs[0].netdev;
-
-               if (likely(__netif_rx_schedule_prep(dev)))
-                       __netif_rx_schedule(dev);
-       }
-       if (map & 2) {
-               dev = adap->sge.qs[1].netdev;
+       if (likely(map & 1))
+               napi_schedule(&qs0->napi);
 
-               if (likely(__netif_rx_schedule_prep(dev)))
-                       __netif_rx_schedule(dev);
-       }
+       if (map & 2)
+               napi_schedule(&adap->sge.qs[1].napi);
 
        spin_unlock(&q0->lock);
        return IRQ_HANDLED;
@@ -2450,7 +2431,7 @@ static irqreturn_t t3b_intr_napi(int irq, void *cookie)
  *     (MSI-X, MSI, or legacy) and whether NAPI will be used to service the
  *     response queues.
  */
-intr_handler_t t3_intr_handler(struct adapter *adap, int polling)
+irq_handler_t t3_intr_handler(struct adapter *adap, int polling)
 {
        if (adap->flags & USING_MSIX)
                return polling ? t3_sge_intr_msix_napi : t3_sge_intr_msix;
@@ -2482,6 +2463,10 @@ void t3_sge_err_intr_handler(struct adapter *adapter)
                         "(0x%x)\n", (v >> S_RSPQ0DISABLED) & 0xff);
        }
 
+       if (status & (F_HIPIODRBDROPERR | F_LOPIODRBDROPERR))
+               CH_ALERT(adapter, "SGE dropped %s priority doorbell\n",
+                        status & F_HIPIODRBDROPERR ? "high" : "lo");
+
        t3_write_reg(adapter, A_SG_INT_CAUSE, status);
        if (status & (F_RSPQCREDITOVERFOW | F_RSPQDISABLED))
                t3_fatal_err(adapter);
@@ -2514,8 +2499,7 @@ static void sge_timer_cb(unsigned long data)
 {
        spinlock_t *lock;
        struct sge_qset *qs = (struct sge_qset *)data;
-       const struct port_info *pi = netdev_priv(qs->netdev);
-       struct adapter *adap = pi->adapter;
+       struct adapter *adap = qs->adap;
 
        if (spin_trylock(&qs->txq[TXQ_ETH].lock)) {
                reclaim_completed_tx(adap, &qs->txq[TXQ_ETH]);
@@ -2526,9 +2510,9 @@ static void sge_timer_cb(unsigned long data)
                spin_unlock(&qs->txq[TXQ_OFLD].lock);
        }
        lock = (adap->flags & USING_MSIX) ? &qs->rspq.lock :
-           &adap->sge.qs[0].rspq.lock;
+                                           &adap->sge.qs[0].rspq.lock;
        if (spin_trylock_irq(lock)) {
-               if (!napi_is_scheduled(qs->netdev)) {
+               if (!napi_is_scheduled(&qs->napi)) {
                        u32 status = t3_read_reg(adap, A_SG_RSPQ_FL_STATUS);
 
                        if (qs->fl[0].credits < qs->fl[0].size)
@@ -2562,12 +2546,9 @@ static void sge_timer_cb(unsigned long data)
  */
 void t3_update_qset_coalesce(struct sge_qset *qs, const struct qset_params *p)
 {
-       if (!qs->netdev)
-               return;
-
        qs->rspq.holdoff_tmr = max(p->coalesce_usecs * 10, 1U);/* can't be 0 */
        qs->rspq.polling = p->polling;
-       qs->netdev->poll = p->polling ? napi_rx_handler : ofld_poll;
+       qs->napi.poll = p->polling ? napi_rx_handler : ofld_poll;
 }
 
 /**
@@ -2587,7 +2568,7 @@ void t3_update_qset_coalesce(struct sge_qset *qs, const struct qset_params *p)
  */
 int t3_sge_alloc_qset(struct adapter *adapter, unsigned int id, int nports,
                      int irq_vec_idx, const struct qset_params *p,
-                     int ntxq, struct net_device *netdev)
+                     int ntxq, struct net_device *dev)
 {
        int i, ret = -ENOMEM;
        struct sge_qset *q = &adapter->sge.qs[id];
@@ -2708,16 +2689,10 @@ int t3_sge_alloc_qset(struct adapter *adapter, unsigned int id, int nports,
        }
 
        spin_unlock(&adapter->sge.reg_lock);
-       q->netdev = netdev;
-       t3_update_qset_coalesce(q, p);
 
-       /*
-        * We use atalk_ptr as a backpointer to a qset.  In case a device is
-        * associated with multiple queue sets only the first one sets
-        * atalk_ptr.
-        */
-       if (netdev->atalk_ptr == NULL)
-               netdev->atalk_ptr = q;
+       q->adap = adapter;
+       q->netdev = dev;
+       t3_update_qset_coalesce(q, p);
 
        refill_fl(adapter, &q->fl[0], q->fl[0].size, GFP_KERNEL);
        refill_fl(adapter, &q->fl[1], q->fl[1].size, GFP_KERNEL);