aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/cxgb3/sge.c
diff options
context:
space:
mode:
authorStephen Hemminger <shemminger@linux-foundation.org>2007-10-03 19:41:36 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-10-10 19:47:45 -0400
commitbea3348eef27e6044b6161fd04c3152215f96411 (patch)
treef0990b263e5ce42505d290a4c346fe990bcd4c33 /drivers/net/cxgb3/sge.c
parentdde4e47e8fe333a5649a3fa0e7db1fa7c08d6158 (diff)
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net device, and some have a single interrupt doorbell for several queues. In either case, it's easier to support layouts like that if the structure representing the poll is independant from the net device itself. The signature of the ->poll() call back goes from: int foo_poll(struct net_device *dev, int *budget) to int foo_poll(struct napi_struct *napi, int budget) The caller is returned the number of RX packets processed (or the number of "NAPI credits" consumed if you want to get abstract). The callee no longer messes around bumping dev->quota, *budget, etc. because that is all handled in the caller upon return. The napi_struct is to be embedded in the device driver private data structures. Furthermore, it is the driver's responsibility to disable all NAPI instances in it's ->stop() device close handler. Since the napi_struct is privatized into the driver's private data structures, only the driver knows how to get at all of the napi_struct instances it may have per-device. With lots of help and suggestions from Rusty Russell, Roland Dreier, Michael Chan, Jeff Garzik, and Jamal Hadi Salim. Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra, Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan. [ Ported to current tree and all drivers converted. Integrated Stephen's follow-on kerneldoc additions, and restored poll_list handling to the old style to fix mutual exclusion issues. -DaveM ] Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/cxgb3/sge.c')
-rw-r--r--drivers/net/cxgb3/sge.c170
1 files changed, 68 insertions, 102 deletions
diff --git a/drivers/net/cxgb3/sge.c b/drivers/net/cxgb3/sge.c
index 58a5f60521ed..069c1aca8a6b 100644
--- a/drivers/net/cxgb3/sge.c
+++ b/drivers/net/cxgb3/sge.c
@@ -591,9 +591,6 @@ void t3_free_qset(struct adapter *adapter, struct sge_qset *q)
591 q->rspq.desc, q->rspq.phys_addr); 591 q->rspq.desc, q->rspq.phys_addr);
592 } 592 }
593 593
594 if (q->netdev)
595 q->netdev->atalk_ptr = NULL;
596
597 memset(q, 0, sizeof(*q)); 594 memset(q, 0, sizeof(*q));
598} 595}
599 596
@@ -1074,7 +1071,7 @@ int t3_eth_xmit(struct sk_buff *skb, struct net_device *dev)
1074 unsigned int ndesc, pidx, credits, gen, compl; 1071 unsigned int ndesc, pidx, credits, gen, compl;
1075 const struct port_info *pi = netdev_priv(dev); 1072 const struct port_info *pi = netdev_priv(dev);
1076 struct adapter *adap = pi->adapter; 1073 struct adapter *adap = pi->adapter;
1077 struct sge_qset *qs = dev2qset(dev); 1074 struct sge_qset *qs = pi->qs;
1078 struct sge_txq *q = &qs->txq[TXQ_ETH]; 1075 struct sge_txq *q = &qs->txq[TXQ_ETH];
1079 1076
1080 /* 1077 /*
@@ -1326,13 +1323,12 @@ static void restart_ctrlq(unsigned long data)
1326 struct sk_buff *skb; 1323 struct sk_buff *skb;
1327 struct sge_qset *qs = (struct sge_qset *)data; 1324 struct sge_qset *qs = (struct sge_qset *)data;
1328 struct sge_txq *q = &qs->txq[TXQ_CTRL]; 1325 struct sge_txq *q = &qs->txq[TXQ_CTRL];
1329 const struct port_info *pi = netdev_priv(qs->netdev);
1330 struct adapter *adap = pi->adapter;
1331 1326
1332 spin_lock(&q->lock); 1327 spin_lock(&q->lock);
1333 again:reclaim_completed_tx_imm(q); 1328 again:reclaim_completed_tx_imm(q);
1334 1329
1335 while (q->in_use < q->size && (skb = __skb_dequeue(&q->sendq)) != NULL) { 1330 while (q->in_use < q->size &&
1331 (skb = __skb_dequeue(&q->sendq)) != NULL) {
1336 1332
1337 write_imm(&q->desc[q->pidx], skb, skb->len, q->gen); 1333 write_imm(&q->desc[q->pidx], skb, skb->len, q->gen);
1338 1334
@@ -1354,7 +1350,7 @@ static void restart_ctrlq(unsigned long data)
1354 } 1350 }
1355 1351
1356 spin_unlock(&q->lock); 1352 spin_unlock(&q->lock);
1357 t3_write_reg(adap, A_SG_KDOORBELL, 1353 t3_write_reg(qs->adap, A_SG_KDOORBELL,
1358 F_SELEGRCNTX | V_EGRCNTX(q->cntxt_id)); 1354 F_SELEGRCNTX | V_EGRCNTX(q->cntxt_id));
1359} 1355}
1360 1356
@@ -1638,8 +1634,7 @@ static inline void offload_enqueue(struct sge_rspq *q, struct sk_buff *skb)
1638 else { 1634 else {
1639 struct sge_qset *qs = rspq_to_qset(q); 1635 struct sge_qset *qs = rspq_to_qset(q);
1640 1636
1641 if (__netif_rx_schedule_prep(qs->netdev)) 1637 napi_schedule(&qs->napi);
1642 __netif_rx_schedule(qs->netdev);
1643 q->rx_head = skb; 1638 q->rx_head = skb;
1644 } 1639 }
1645 q->rx_tail = skb; 1640 q->rx_tail = skb;
@@ -1675,34 +1670,30 @@ static inline void deliver_partial_bundle(struct t3cdev *tdev,
1675 * receive handler. Batches need to be of modest size as we do prefetches 1670 * receive handler. Batches need to be of modest size as we do prefetches
1676 * on the packets in each. 1671 * on the packets in each.
1677 */ 1672 */
1678static int ofld_poll(struct net_device *dev, int *budget) 1673static int ofld_poll(struct napi_struct *napi, int budget)
1679{ 1674{
1680 const struct port_info *pi = netdev_priv(dev); 1675 struct sge_qset *qs = container_of(napi, struct sge_qset, napi);
1681 struct adapter *adapter = pi->adapter;
1682 struct sge_qset *qs = dev2qset(dev);
1683 struct sge_rspq *q = &qs->rspq; 1676 struct sge_rspq *q = &qs->rspq;
1684 int work_done, limit = min(*budget, dev->quota), avail = limit; 1677 struct adapter *adapter = qs->adap;
1678 int work_done = 0;
1685 1679
1686 while (avail) { 1680 while (work_done < budget) {
1687 struct sk_buff *head, *tail, *skbs[RX_BUNDLE_SIZE]; 1681 struct sk_buff *head, *tail, *skbs[RX_BUNDLE_SIZE];
1688 int ngathered; 1682 int ngathered;
1689 1683
1690 spin_lock_irq(&q->lock); 1684 spin_lock_irq(&q->lock);
1691 head = q->rx_head; 1685 head = q->rx_head;
1692 if (!head) { 1686 if (!head) {
1693 work_done = limit - avail; 1687 napi_complete(napi);
1694 *budget -= work_done;
1695 dev->quota -= work_done;
1696 __netif_rx_complete(dev);
1697 spin_unlock_irq(&q->lock); 1688 spin_unlock_irq(&q->lock);
1698 return 0; 1689 return work_done;
1699 } 1690 }
1700 1691
1701 tail = q->rx_tail; 1692 tail = q->rx_tail;
1702 q->rx_head = q->rx_tail = NULL; 1693 q->rx_head = q->rx_tail = NULL;
1703 spin_unlock_irq(&q->lock); 1694 spin_unlock_irq(&q->lock);
1704 1695
1705 for (ngathered = 0; avail && head; avail--) { 1696 for (ngathered = 0; work_done < budget && head; work_done++) {
1706 prefetch(head->data); 1697 prefetch(head->data);
1707 skbs[ngathered] = head; 1698 skbs[ngathered] = head;
1708 head = head->next; 1699 head = head->next;
@@ -1724,10 +1715,8 @@ static int ofld_poll(struct net_device *dev, int *budget)
1724 } 1715 }
1725 deliver_partial_bundle(&adapter->tdev, q, skbs, ngathered); 1716 deliver_partial_bundle(&adapter->tdev, q, skbs, ngathered);
1726 } 1717 }
1727 work_done = limit - avail; 1718
1728 *budget -= work_done; 1719 return work_done;
1729 dev->quota -= work_done;
1730 return 1;
1731} 1720}
1732 1721
1733/** 1722/**
@@ -2071,50 +2060,47 @@ static inline int is_pure_response(const struct rsp_desc *r)
2071 2060
2072/** 2061/**
2073 * napi_rx_handler - the NAPI handler for Rx processing 2062 * napi_rx_handler - the NAPI handler for Rx processing
2074 * @dev: the net device 2063 * @napi: the napi instance
2075 * @budget: how many packets we can process in this round 2064 * @budget: how many packets we can process in this round
2076 * 2065 *
2077 * Handler for new data events when using NAPI. 2066 * Handler for new data events when using NAPI.
2078 */ 2067 */
2079static int napi_rx_handler(struct net_device *dev, int *budget) 2068static int napi_rx_handler(struct napi_struct *napi, int budget)
2080{ 2069{
2081 const struct port_info *pi = netdev_priv(dev); 2070 struct sge_qset *qs = container_of(napi, struct sge_qset, napi);
2082 struct adapter *adap = pi->adapter; 2071 struct adapter *adap = qs->adap;
2083 struct sge_qset *qs = dev2qset(dev); 2072 int work_done = process_responses(adap, qs, budget);
2084 int effective_budget = min(*budget, dev->quota);
2085
2086 int work_done = process_responses(adap, qs, effective_budget);
2087 *budget -= work_done;
2088 dev->quota -= work_done;
2089 2073
2090 if (work_done >= effective_budget) 2074 if (likely(work_done < budget)) {
2091 return 1; 2075 napi_complete(napi);
2092
2093 netif_rx_complete(dev);
2094 2076
2095 /* 2077 /*
2096 * Because we don't atomically flush the following write it is 2078 * Because we don't atomically flush the following
2097 * possible that in very rare cases it can reach the device in a way 2079 * write it is possible that in very rare cases it can
2098 * that races with a new response being written plus an error interrupt 2080 * reach the device in a way that races with a new
2099 * causing the NAPI interrupt handler below to return unhandled status 2081 * response being written plus an error interrupt
2100 * to the OS. To protect against this would require flushing the write 2082 * causing the NAPI interrupt handler below to return
2101 * and doing both the write and the flush with interrupts off. Way too 2083 * unhandled status to the OS. To protect against
2102 * expensive and unjustifiable given the rarity of the race. 2084 * this would require flushing the write and doing
2103 * 2085 * both the write and the flush with interrupts off.
2104 * The race cannot happen at all with MSI-X. 2086 * Way too expensive and unjustifiable given the
2105 */ 2087 * rarity of the race.
2106 t3_write_reg(adap, A_SG_GTS, V_RSPQ(qs->rspq.cntxt_id) | 2088 *
2107 V_NEWTIMER(qs->rspq.next_holdoff) | 2089 * The race cannot happen at all with MSI-X.
2108 V_NEWINDEX(qs->rspq.cidx)); 2090 */
2109 return 0; 2091 t3_write_reg(adap, A_SG_GTS, V_RSPQ(qs->rspq.cntxt_id) |
2092 V_NEWTIMER(qs->rspq.next_holdoff) |
2093 V_NEWINDEX(qs->rspq.cidx));
2094 }
2095 return work_done;
2110} 2096}
2111 2097
2112/* 2098/*
2113 * Returns true if the device is already scheduled for polling. 2099 * Returns true if the device is already scheduled for polling.
2114 */ 2100 */
2115static inline int napi_is_scheduled(struct net_device *dev) 2101static inline int napi_is_scheduled(struct napi_struct *napi)
2116{ 2102{
2117 return test_bit(__LINK_STATE_RX_SCHED, &dev->state); 2103 return test_bit(NAPI_STATE_SCHED, &napi->state);
2118} 2104}
2119 2105
2120/** 2106/**
@@ -2197,8 +2183,7 @@ static inline int handle_responses(struct adapter *adap, struct sge_rspq *q)
2197 V_NEWTIMER(q->holdoff_tmr) | V_NEWINDEX(q->cidx)); 2183 V_NEWTIMER(q->holdoff_tmr) | V_NEWINDEX(q->cidx));
2198 return 0; 2184 return 0;
2199 } 2185 }
2200 if (likely(__netif_rx_schedule_prep(qs->netdev))) 2186 napi_schedule(&qs->napi);
2201 __netif_rx_schedule(qs->netdev);
2202 return 1; 2187 return 1;
2203} 2188}
2204 2189
@@ -2209,8 +2194,7 @@ static inline int handle_responses(struct adapter *adap, struct sge_rspq *q)
2209irqreturn_t t3_sge_intr_msix(int irq, void *cookie) 2194irqreturn_t t3_sge_intr_msix(int irq, void *cookie)
2210{ 2195{
2211 struct sge_qset *qs = cookie; 2196 struct sge_qset *qs = cookie;
2212 const struct port_info *pi = netdev_priv(qs->netdev); 2197 struct adapter *adap = qs->adap;
2213 struct adapter *adap = pi->adapter;
2214 struct sge_rspq *q = &qs->rspq; 2198 struct sge_rspq *q = &qs->rspq;
2215 2199
2216 spin_lock(&q->lock); 2200 spin_lock(&q->lock);
@@ -2229,13 +2213,11 @@ irqreturn_t t3_sge_intr_msix(int irq, void *cookie)
2229irqreturn_t t3_sge_intr_msix_napi(int irq, void *cookie) 2213irqreturn_t t3_sge_intr_msix_napi(int irq, void *cookie)
2230{ 2214{
2231 struct sge_qset *qs = cookie; 2215 struct sge_qset *qs = cookie;
2232 const struct port_info *pi = netdev_priv(qs->netdev);
2233 struct adapter *adap = pi->adapter;
2234 struct sge_rspq *q = &qs->rspq; 2216 struct sge_rspq *q = &qs->rspq;
2235 2217
2236 spin_lock(&q->lock); 2218 spin_lock(&q->lock);
2237 2219
2238 if (handle_responses(adap, q) < 0) 2220 if (handle_responses(qs->adap, q) < 0)
2239 q->unhandled_irqs++; 2221 q->unhandled_irqs++;
2240 spin_unlock(&q->lock); 2222 spin_unlock(&q->lock);
2241 return IRQ_HANDLED; 2223 return IRQ_HANDLED;
@@ -2278,11 +2260,13 @@ static irqreturn_t t3_intr_msi(int irq, void *cookie)
2278 return IRQ_HANDLED; 2260 return IRQ_HANDLED;
2279} 2261}
2280 2262
2281static int rspq_check_napi(struct net_device *dev, struct sge_rspq *q) 2263static int rspq_check_napi(struct sge_qset *qs)
2282{ 2264{
2283 if (!napi_is_scheduled(dev) && is_new_response(&q->desc[q->cidx], q)) { 2265 struct sge_rspq *q = &qs->rspq;
2284 if (likely(__netif_rx_schedule_prep(dev))) 2266
2285 __netif_rx_schedule(dev); 2267 if (!napi_is_scheduled(&qs->napi) &&
2268 is_new_response(&q->desc[q->cidx], q)) {
2269 napi_schedule(&qs->napi);
2286 return 1; 2270 return 1;
2287 } 2271 }
2288 return 0; 2272 return 0;
@@ -2303,10 +2287,9 @@ irqreturn_t t3_intr_msi_napi(int irq, void *cookie)
2303 2287
2304 spin_lock(&q->lock); 2288 spin_lock(&q->lock);
2305 2289
2306 new_packets = rspq_check_napi(adap->sge.qs[0].netdev, q); 2290 new_packets = rspq_check_napi(&adap->sge.qs[0]);
2307 if (adap->params.nports == 2) 2291 if (adap->params.nports == 2)
2308 new_packets += rspq_check_napi(adap->sge.qs[1].netdev, 2292 new_packets += rspq_check_napi(&adap->sge.qs[1]);
2309 &adap->sge.qs[1].rspq);
2310 if (!new_packets && t3_slow_intr_handler(adap) == 0) 2293 if (!new_packets && t3_slow_intr_handler(adap) == 0)
2311 q->unhandled_irqs++; 2294 q->unhandled_irqs++;
2312 2295
@@ -2409,9 +2392,9 @@ static irqreturn_t t3b_intr(int irq, void *cookie)
2409static irqreturn_t t3b_intr_napi(int irq, void *cookie) 2392static irqreturn_t t3b_intr_napi(int irq, void *cookie)
2410{ 2393{
2411 u32 map; 2394 u32 map;
2412 struct net_device *dev;
2413 struct adapter *adap = cookie; 2395 struct adapter *adap = cookie;
2414 struct sge_rspq *q0 = &adap->sge.qs[0].rspq; 2396 struct sge_qset *qs0 = &adap->sge.qs[0];
2397 struct sge_rspq *q0 = &qs0->rspq;
2415 2398
2416 t3_write_reg(adap, A_PL_CLI, 0); 2399 t3_write_reg(adap, A_PL_CLI, 0);
2417 map = t3_read_reg(adap, A_SG_DATA_INTR); 2400 map = t3_read_reg(adap, A_SG_DATA_INTR);
@@ -2424,18 +2407,11 @@ static irqreturn_t t3b_intr_napi(int irq, void *cookie)
2424 if (unlikely(map & F_ERRINTR)) 2407 if (unlikely(map & F_ERRINTR))
2425 t3_slow_intr_handler(adap); 2408 t3_slow_intr_handler(adap);
2426 2409
2427 if (likely(map & 1)) { 2410 if (likely(map & 1))
2428 dev = adap->sge.qs[0].netdev; 2411 napi_schedule(&qs0->napi);
2429
2430 if (likely(__netif_rx_schedule_prep(dev)))
2431 __netif_rx_schedule(dev);
2432 }
2433 if (map & 2) {
2434 dev = adap->sge.qs[1].netdev;
2435 2412
2436 if (likely(__netif_rx_schedule_prep(dev))) 2413 if (map & 2)
2437 __netif_rx_schedule(dev); 2414 napi_schedule(&adap->sge.qs[1].napi);
2438 }
2439 2415
2440 spin_unlock(&q0->lock); 2416 spin_unlock(&q0->lock);
2441 return IRQ_HANDLED; 2417 return IRQ_HANDLED;
@@ -2514,8 +2490,7 @@ static void sge_timer_cb(unsigned long data)
2514{ 2490{
2515 spinlock_t *lock; 2491 spinlock_t *lock;
2516 struct sge_qset *qs = (struct sge_qset *)data; 2492 struct sge_qset *qs = (struct sge_qset *)data;
2517 const struct port_info *pi = netdev_priv(qs->netdev); 2493 struct adapter *adap = qs->adap;
2518 struct adapter *adap = pi->adapter;
2519 2494
2520 if (spin_trylock(&qs->txq[TXQ_ETH].lock)) { 2495 if (spin_trylock(&qs->txq[TXQ_ETH].lock)) {
2521 reclaim_completed_tx(adap, &qs->txq[TXQ_ETH]); 2496 reclaim_completed_tx(adap, &qs->txq[TXQ_ETH]);
@@ -2526,9 +2501,9 @@ static void sge_timer_cb(unsigned long data)
2526 spin_unlock(&qs->txq[TXQ_OFLD].lock); 2501 spin_unlock(&qs->txq[TXQ_OFLD].lock);
2527 } 2502 }
2528 lock = (adap->flags & USING_MSIX) ? &qs->rspq.lock : 2503 lock = (adap->flags & USING_MSIX) ? &qs->rspq.lock :
2529 &adap->sge.qs[0].rspq.lock; 2504 &adap->sge.qs[0].rspq.lock;
2530 if (spin_trylock_irq(lock)) { 2505 if (spin_trylock_irq(lock)) {
2531 if (!napi_is_scheduled(qs->netdev)) { 2506 if (!napi_is_scheduled(&qs->napi)) {
2532 u32 status = t3_read_reg(adap, A_SG_RSPQ_FL_STATUS); 2507 u32 status = t3_read_reg(adap, A_SG_RSPQ_FL_STATUS);
2533 2508
2534 if (qs->fl[0].credits < qs->fl[0].size) 2509 if (qs->fl[0].credits < qs->fl[0].size)
@@ -2562,12 +2537,9 @@ static void sge_timer_cb(unsigned long data)
2562 */ 2537 */
2563void t3_update_qset_coalesce(struct sge_qset *qs, const struct qset_params *p) 2538void t3_update_qset_coalesce(struct sge_qset *qs, const struct qset_params *p)
2564{ 2539{
2565 if (!qs->netdev)
2566 return;
2567
2568 qs->rspq.holdoff_tmr = max(p->coalesce_usecs * 10, 1U);/* can't be 0 */ 2540 qs->rspq.holdoff_tmr = max(p->coalesce_usecs * 10, 1U);/* can't be 0 */
2569 qs->rspq.polling = p->polling; 2541 qs->rspq.polling = p->polling;
2570 qs->netdev->poll = p->polling ? napi_rx_handler : ofld_poll; 2542 qs->napi.poll = p->polling ? napi_rx_handler : ofld_poll;
2571} 2543}
2572 2544
2573/** 2545/**
@@ -2587,7 +2559,7 @@ void t3_update_qset_coalesce(struct sge_qset *qs, const struct qset_params *p)
2587 */ 2559 */
2588int t3_sge_alloc_qset(struct adapter *adapter, unsigned int id, int nports, 2560int t3_sge_alloc_qset(struct adapter *adapter, unsigned int id, int nports,
2589 int irq_vec_idx, const struct qset_params *p, 2561 int irq_vec_idx, const struct qset_params *p,
2590 int ntxq, struct net_device *netdev) 2562 int ntxq, struct net_device *dev)
2591{ 2563{
2592 int i, ret = -ENOMEM; 2564 int i, ret = -ENOMEM;
2593 struct sge_qset *q = &adapter->sge.qs[id]; 2565 struct sge_qset *q = &adapter->sge.qs[id];
@@ -2708,16 +2680,10 @@ int t3_sge_alloc_qset(struct adapter *adapter, unsigned int id, int nports,
2708 } 2680 }
2709 2681
2710 spin_unlock(&adapter->sge.reg_lock); 2682 spin_unlock(&adapter->sge.reg_lock);
2711 q->netdev = netdev;
2712 t3_update_qset_coalesce(q, p);
2713 2683
2714 /* 2684 q->adap = adapter;
2715 * We use atalk_ptr as a backpointer to a qset. In case a device is 2685 q->netdev = dev;
2716 * associated with multiple queue sets only the first one sets 2686 t3_update_qset_coalesce(q, p);
2717 * atalk_ptr.
2718 */
2719 if (netdev->atalk_ptr == NULL)
2720 netdev->atalk_ptr = q;
2721 2687
2722 refill_fl(adapter, &q->fl[0], q->fl[0].size, GFP_KERNEL); 2688 refill_fl(adapter, &q->fl[0], q->fl[0].size, GFP_KERNEL);
2723 refill_fl(adapter, &q->fl[1], q->fl[1].size, GFP_KERNEL); 2689 refill_fl(adapter, &q->fl[1], q->fl[1].size, GFP_KERNEL);