NAPI_HOWTO.txt
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:26k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. HISTORY:
  2. February 16/2002 -- revision 0.2.1:
  3. COR typo corrected
  4. February 10/2002 -- revision 0.2:
  5. some spell checking ;->
  6. January 12/2002 -- revision 0.1
  7. This is still work in progress so may change.
  8. To keep up to date please watch this space.
  9. Introduction to NAPI
  10. ====================
  11. NAPI is a proven (www.cyberus.ca/~hadi/usenix-paper.tgz) technique
  12. to improve network performance on Linux. For more details please
  13. read that paper.
  14. NAPI provides a "inherent mitigation" which is bound by system capacity
  15. as can be seen from the following data collected by Robert on Gigabit 
  16. ethernet (e1000):
  17.  Psize    Ipps       Tput     Rxint     Txint    Done     Ndone
  18.  ---------------------------------------------------------------
  19.    60    890000     409362        17     27622        7     6823
  20.   128    758150     464364        21      9301       10     7738
  21.   256    445632     774646        42     15507       21    12906
  22.   512    232666     994445    241292     19147   241192     1062
  23.  1024    119061    1000003    872519     19258   872511        0
  24.  1440     85193    1000003    946576     19505   946569        0
  25.  
  26. Legend:
  27. "Ipps" stands for input packets per second. 
  28. "Tput" == packets out of total 1M that made it out.
  29. "txint" == transmit completion interrupts seen
  30. "Done" == The number of times that the poll() managed to pull all
  31. packets out of the rx ring. Note from this that the lower the
  32. load the more we could clean up the rxring
  33. "Ndone" == is the converse of "Done". Note again, that the higher
  34. the load the more times we couldnt clean up the rxring.
  35. Observe that:
  36. when the NIC receives 890Kpackets/sec only 17 rx interrupts are generated. 
  37. The system cant handle the processing at 1 interrupt/packet at that load level. 
  38. At lower rates on the other hand, rx interrupts go up and therefore the
  39. interrupt/packet ratio goes up (as observable from that table). So there is
  40. possibility that under low enough input, you get one poll call for each
  41. input packet caused by a single interrupt each time. And if the system 
  42. cant handle interrupt per packet ratio of 1, then it will just have to 
  43. chug along ....
  44. 0) Prerequisites:
  45. ==================
  46. A driver MAY continue using the old 2.4 technique for interfacing
  47. to the network stack and not benefit from the NAPI changes.
  48. NAPI additions to the kernel do not break backward compatibility.
  49. NAPI, however, requires the following features to be available:
  50. A) DMA ring or enough RAM to store packets in software devices.
  51. B) Ability to turn off interrupts or maybe events that send packets up 
  52. the stack.
  53. NAPI processes packet events in what is known as dev->poll() method.
  54. Typically, only packet receive events are processed in dev->poll(). 
  55. The rest of the events MAY be processed by the regular interrupt handler 
  56. to reduce processing latency (justified also because there are not that 
  57. many of them).
  58. Note, however, NAPI does not enforce that dev->poll() only processes 
  59. receive events. 
  60. Tests with the tulip driver indicated slightly increased latency if
  61. all of the interrupt handler is moved to dev->poll(). Also MII handling
  62. gets a little trickier.
  63. The example used in this document is to move the receive processing only
  64. to dev->poll(); this is shown with the patch for the tulip driver.
  65. For an example of code that moves all the interrupt driver to 
  66. dev->poll() look at the ported e1000 code.
  67. There are caveats that might force you to go with moving everything to 
  68. dev->poll(). Different NICs work differently depending on their status/event 
  69. acknowledgement setup. 
  70. There are two types of event register ACK mechanisms.
  71. I)  what is known as Clear-on-read (COR).
  72. when you read the status/event register, it clears everything!
  73. The natsemi and sunbmac NICs are known to do this.
  74. In this case your only choice is to move all to dev->poll()
  75. II) Clear-on-write (COW)
  76.  i) you clear the status by writting a 1 in the bit-location you want.
  77. These are the majority of the NICs and work the best with NAPI.
  78. Put only receive events in dev->poll(); leave the rest in
  79. the old interrupt handler.
  80.  ii) whatever you write in the status register clears every thing ;->
  81. Cant seem to find any supported by Linux which do this. If
  82. someone knows such a chip email us please.
  83. Move all to dev->poll()
  84. C) Ability to detect new work correctly.
  85. NAPI works by shutting down event interrupts when theres work and
  86. turning them on when theres none. 
  87. New packets might show up in the small window while interrupts were being 
  88. re-enabled (refer to appendix 2).  A packet might sneak in during the period 
  89. we are enabling interrupts. We only get to know about such a packet when the 
  90. next new packet arrives and generates an interrupt. 
  91. Essentially, there is a small window of opportunity for a race condition
  92. which for clarity we'll refer to as the "rotting packet".
  93. This is a very important topic and appendix 2 is dedicated for more 
  94. discussion.
  95. Locking rules and environmental guarantees
  96. ==========================================
  97. -Guarantee: Only one CPU at any time can call dev->poll(); this is because
  98. only one CPU can pick the initial interrupt and hence the initial
  99. netif_rx_schedule(dev);
  100. - The core layer invokes devices to send packets in a round robin format.
  101. This implies receive is totaly lockless because of the guarantee only that 
  102. one CPU is executing it.
  103. -  contention can only be the result of some other CPU accessing the rx
  104. ring. This happens only in close() and suspend() (when these methods
  105. try to clean the rx ring); 
  106. ****guarantee: driver authors need not worry about this; synchronization 
  107. is taken care for them by the top net layer.
  108. -local interrupts are enabled (if you dont move all to dev->poll()). For 
  109. example link/MII and txcomplete continue functioning just same old way. 
  110. This improves the latency of processing these events. It is also assumed that 
  111. the receive interrupt is the largest cause of noise. Note this might not 
  112. always be true. 
  113. [according to Manfred Spraul, the winbond insists on sending one 
  114. txmitcomplete interrupt for each packet (although this can be mitigated)].
  115. For these broken drivers, move all to dev->poll().
  116. For the rest of this text, we'll assume that dev->poll() only
  117. processes receive events.
  118. new methods introduce by NAPI
  119. =============================
  120. a) netif_rx_schedule(dev)
  121. Called by an IRQ handler to schedule a poll for device
  122. b) netif_rx_schedule_prep(dev)
  123. puts the device in a state which allows for it to be added to the
  124. CPU polling list if it is up and running. You can look at this as
  125. the first half of  netif_rx_schedule(dev) above; the second half
  126. being c) below.
  127. c) __netif_rx_schedule(dev)
  128. Add device to the poll list for this CPU; assuming that _prep above
  129. has already been called and returned 1.
  130. d) netif_rx_reschedule(dev, undo)
  131. Called to reschedule polling for device specifically for some
  132. deficient hardware. Read Appendix 2 for more details.
  133. e) netif_rx_complete(dev)
  134. Remove interface from the CPU poll list: it must be in the poll list
  135. on current cpu. This primitive is called by dev->poll(), when
  136. it completes its work. The device cannot be out of poll list at this
  137. call, if it is then clearly it is a BUG(). You'll know ;->
  138. All these above nethods are used below. So keep reading for clarity.
  139. Device driver changes to be made when porting NAPI
  140. ==================================================
  141. Below we describe what kind of changes are required for NAPI to work.
  142. 1) introduction of dev->poll() method 
  143. =====================================
  144. This is the method that is invoked by the network core when it requests
  145. for new packets from the driver. A driver is allowed to send upto
  146. dev->quota packets by the current CPU before yielding to the network
  147. subsystem (so other devices can also get opportunity to send to the stack).
  148. dev->poll() prototype looks as follows:
  149. int my_poll(struct net_device *dev, int *budget)
  150. budget is the remaining number of packets the network subsystem on the
  151. current CPU can send up the stack before yielding to other system tasks.
  152. *Each driver is responsible for decrementing budget by the total number of
  153. packets sent.
  154. Total number of packets cannot exceed dev->quota.
  155. dev->poll() method is invoked by the top layer, the driver just sends if it 
  156. can to the stack the packet quantity requested.
  157. more on dev->poll() below after the interrupt changes are explained.
  158. 2) registering dev->poll() method
  159. ===================================
  160. dev->poll should be set in the dev->probe() method. 
  161. e.g:
  162. dev->open = my_open;
  163. .
  164. .
  165. /* two new additions */
  166. /* first register my poll method */
  167. dev->poll = my_poll;
  168. /* next register my weight/quanta; can be overriden in /proc */
  169. dev->weight = 16;
  170. .
  171. .
  172. dev->stop = my_close;
  173. 3) scheduling dev->poll()
  174. =============================
  175. This involves modifying the interrupt handler and the code
  176. path which takes the packet off the NIC and sends them to the 
  177. stack.
  178. it's important at this point to introduce the classical D Becker 
  179. interrupt processor:
  180. ------------------
  181. static void
  182. netdevice_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  183. {
  184. struct net_device *dev = (struct net_device *)dev_instance;
  185. struct my_private *tp = (struct my_private *)dev->priv;
  186. int work_count = my_work_count;
  187.         status = read_interrupt_status_reg();
  188.         if (status == 0)
  189.                 return;         /* Shared IRQ: not us */
  190.         if (status == 0xffff)
  191.                 return;         /* Hot unplug */
  192.         if (status & error)
  193. do_some_error_handling()
  194.         
  195. do {
  196. acknowledge_ints_ASAP();
  197. if (status & link_interrupt) {
  198. spin_lock(&tp->link_lock);
  199. do_some_link_stat_stuff();
  200. spin_unlock(&tp->link_lock);
  201. }
  202. if (status & rx_interrupt) {
  203. receive_packets(dev);
  204. }
  205. if (status & rx_nobufs) {
  206. make_rx_buffs_avail();
  207. }
  208. if (status & tx_related) {
  209. spin_lock(&tp->lock);
  210. tx_ring_free(dev);
  211. if (tx_died)
  212. restart_tx();
  213. spin_unlock(&tp->lock);
  214. }
  215. status = read_interrupt_status_reg();
  216. } while (!(status & error) || more_work_to_be_done);
  217. }
  218. ----------------------------------------------------------------------
  219. We now change this to what is shown below to NAPI-enable it:
  220. ----------------------------------------------------------------------
  221. static void
  222. netdevice_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  223. {
  224. struct net_device *dev = (struct net_device *)dev_instance;
  225. struct my_private *tp = (struct my_private *)dev->priv;
  226.         status = read_interrupt_status_reg();
  227.         if (status == 0)
  228.                 return;         /* Shared IRQ: not us */
  229.         if (status == 0xffff)
  230.                 return;         /* Hot unplug */
  231.         if (status & error)
  232. do_some_error_handling();
  233.         
  234. do {
  235. /************************ start note *********************************/
  236. acknowledge_ints_ASAP();  // dont ack rx and rxnobuff here
  237. /************************ end note *********************************/
  238. if (status & link_interrupt) {
  239. spin_lock(&tp->link_lock);
  240. do_some_link_stat_stuff();
  241. spin_unlock(&tp->link_lock);
  242. }
  243. /************************ start note *********************************/
  244. if (status & rx_interrupt || (status & rx_nobuffs)) {
  245. if (netif_rx_schedule_prep(dev)) {
  246. /* disable interrupts caused 
  247.          * by arriving packets */
  248. disable_rx_and_rxnobuff_ints();
  249. /* tell system we have work to be done. */
  250. __netif_rx_schedule(dev);
  251. } else {
  252. printk("driver bug! interrupt while in polln");
  253. /* FIX by disabling interrupts  */
  254. disable_rx_and_rxnobuff_ints();
  255. }
  256. }
  257. /************************ end note note *********************************/
  258. if (status & tx_related) {
  259. spin_lock(&tp->lock);
  260. tx_ring_free(dev);
  261. if (tx_died)
  262. restart_tx();
  263. spin_unlock(&tp->lock);
  264. }
  265. status = read_interrupt_status_reg();
  266. /************************ start note *********************************/
  267. } while (!(status & error) || more_work_to_be_done(status));
  268. /************************ end note note *********************************/
  269. }
  270. ---------------------------------------------------------------------
  271. We note several things from above:
  272. I) Any interrupt source which is caused by arriving packets is now
  273. turned off when it occurs. Depending on the hardware, there could be
  274. several reasons that arriving packets would cause interrupts; these are the
  275. interrupt sources we wish to avoid. The two common ones are a) a packet 
  276. arriving (rxint) b) a packet arriving and finding no DMA buffers available
  277. (rxnobuff) .
  278. This means also acknowledge_ints_ASAP() will not clear the status
  279. register for those two items above; clearing is done in the place where 
  280. proper work is done within NAPI; at the poll() and refill_rx_ring() 
  281. discussed further below.
  282. netif_rx_schedule_prep() returns 1 if device is in running state and
  283. gets successfully added to the core poll list. If we get a zero value
  284. we can _almost_ assume are already added to the list (instead of not running. 
  285. Logic based on the fact that you shouldnt get interrupt if not running)
  286. We rectify this by disabling rx and rxnobuf interrupts.
  287. II) that receive_packets(dev) and make_rx_buffs_avail() may have dissapeared.
  288. These functionalities are still around actually......
  289. infact, receive_packets(dev) is very close to my_poll() and 
  290. make_rx_buffs_avail() is invoked from my_poll()
  291. 4) converting receive_packets() to dev->poll()
  292. ===============================================
  293. We need to convert the classical D Becker receive_packets(dev) to my_poll()
  294. First the typical receive_packets() below:
  295. -------------------------------------------------------------------
  296. /* this is called by interrupt handler */
  297. static void receive_packets (struct net_device *dev)
  298. {
  299. struct my_private *tp = (struct my_private *)dev->priv;
  300. rx_ring = tp->rx_ring;
  301. cur_rx = tp->cur_rx;
  302. int entry = cur_rx % RX_RING_SIZE;
  303. int received = 0;
  304. int rx_work_limit = tp->dirty_rx + RX_RING_SIZE - tp->cur_rx;
  305. while (rx_ring_not_empty) {
  306. u32 rx_status;
  307. unsigned int rx_size;
  308. unsigned int pkt_size;
  309. struct sk_buff *skb;
  310.                 /* read size+status of next frame from DMA ring buffer */
  311. /* the number 16 and 4 are just examples */
  312.                 rx_status = le32_to_cpu (*(u32 *) (rx_ring + ring_offset));
  313.                 rx_size = rx_status >> 16;
  314.                 pkt_size = rx_size - 4;
  315. /* process errors */
  316.                 if ((rx_size > (MAX_ETH_FRAME_SIZE+4)) ||
  317.                     (!(rx_status & RxStatusOK))) {
  318.                         netdrv_rx_err (rx_status, dev, tp, ioaddr);
  319.                         return;
  320.                 }
  321.                 if (--rx_work_limit < 0)
  322.                         break;
  323. /* grab a skb */
  324.                 skb = dev_alloc_skb (pkt_size + 2);
  325.                 if (skb) {
  326. .
  327. .
  328. netif_rx (skb);
  329. .
  330. .
  331.                 } else {  /* OOM */
  332. /*seems very driver specific ... some just pass
  333. whatever is on the ring already. */
  334.                 }
  335. /* move to the next skb on the ring */
  336. entry = (++tp->cur_rx) % RX_RING_SIZE;
  337. received++ ;
  338.         }
  339. /* store current ring pointer state */
  340.         tp->cur_rx = cur_rx;
  341.         /* Refill the Rx ring buffers if they are needed */
  342. refill_rx_ring();
  343. .
  344. .
  345. }
  346. -------------------------------------------------------------------
  347. We change it to a new one below; note the additional parameter in
  348. the call.
  349. -------------------------------------------------------------------
  350. /* this is called by the network core */
  351. static void my_poll (struct net_device *dev, int *budget)
  352. {
  353. struct my_private *tp = (struct my_private *)dev->priv;
  354. rx_ring = tp->rx_ring;
  355. cur_rx = tp->cur_rx;
  356. int entry = cur_rx % RX_BUF_LEN;
  357. /* maximum packets to send to the stack */
  358. /************************ note note *********************************/
  359. int rx_work_limit = dev->quota;
  360. /************************ end note note *********************************/
  361.     do {  // outer beggining loop starts here
  362. clear_rx_status_register_bit();
  363. while (rx_ring_not_empty) {
  364. u32 rx_status;
  365. unsigned int rx_size;
  366. unsigned int pkt_size;
  367. struct sk_buff *skb;
  368.                 /* read size+status of next frame from DMA ring buffer */
  369. /* the number 16 and 4 are just examples */
  370.                 rx_status = le32_to_cpu (*(u32 *) (rx_ring + ring_offset));
  371.                 rx_size = rx_status >> 16;
  372.                 pkt_size = rx_size - 4;
  373. /* process errors */
  374.                 if ((rx_size > (MAX_ETH_FRAME_SIZE+4)) ||
  375.                     (!(rx_status & RxStatusOK))) {
  376.                         netdrv_rx_err (rx_status, dev, tp, ioaddr);
  377.                         return;
  378.                 }
  379. /************************ note note *********************************/
  380.                 if (--rx_work_limit < 0) { /* we got packets, but no quota */
  381. /* store current ring pointer state */
  382. tp->cur_rx = cur_rx;
  383. /* Refill the Rx ring buffers if they are needed */
  384. refill_rx_ring(dev);
  385.                         goto not_done;
  386. }
  387. /**********************  end note **********************************/
  388. /* grab a skb */
  389.                 skb = dev_alloc_skb (pkt_size + 2);
  390.                 if (skb) {
  391. .
  392. .
  393. /************************ note note *********************************/
  394. netif_receive_skb (skb);
  395. /**********************  end note **********************************/
  396. .
  397. .
  398.                 } else {  /* OOM */
  399. /*seems very driver specific ... common is just pass
  400. whatever is on the ring already. */
  401.                 }
  402. /* move to the next skb on the ring */
  403. entry = (++tp->cur_rx) % RX_RING_SIZE;
  404. received++ ;
  405.         }
  406. /* store current ring pointer state */
  407.         tp->cur_rx = cur_rx;
  408.         /* Refill the Rx ring buffers if they are needed */
  409. refill_rx_ring(dev);
  410. /* no packets on ring; but new ones can arrive since we last 
  411.    checked  */
  412. status = read_interrupt_status_reg();
  413. if (rx status is not set) {
  414.                         /* If something arrives in this narrow window,
  415. an interrupt will be generated */
  416.                         goto done;
  417. }
  418. /* done! at least thats what it looks like ;->
  419. if new packets came in after our last check on status bits
  420. they'll be caught by the while check and we go back and clear them 
  421. since we havent exceeded our quota */
  422.     } while (rx_status_is_set); 
  423. done:
  424. /************************ note note *********************************/
  425.         dev->quota -= received;
  426.         *budget -= received;
  427.         /* If RX ring is not full we are out of memory. */
  428.         if (tp->rx_buffers[tp->dirty_rx % RX_RING_SIZE].skb == NULL)
  429.                 goto oom;
  430. /* we are happy/done, no more packets on ring; put us back
  431. to where we can start processing interrupts again */
  432.         netif_rx_complete(dev);
  433. enable_rx_and_rxnobuf_ints();
  434.        /* The last op happens after poll completion. Which means the following:
  435.         * 1. it can race with disabling irqs in irq handler (which are done to 
  436. * schedule polls)
  437.         * 2. it can race with dis/enabling irqs in other poll threads
  438.         * 3. if an irq raised after the begining of the outer  beginning 
  439.         * loop(marked in the code above), it will be immediately
  440.         * triggered here.
  441.         *
  442.         * Summarizing: the logic may results in some redundant irqs both
  443.         * due to races in masking and due to too late acking of already
  444.         * processed irqs. The good news: no events are ever lost.
  445.         */
  446.         return 0;   /* done */
  447. not_done:
  448.         if (tp->cur_rx - tp->dirty_rx > RX_RING_SIZE/2 ||
  449.             tp->rx_buffers[tp->dirty_rx % RX_RING_SIZE].skb == NULL)
  450.                 refill_rx_ring(dev);
  451.         if (!received) {
  452.                 printk("received==0n");
  453.                 received = 1;
  454.         }
  455.         dev->quota -= received;
  456.         *budget -= received;
  457.         return 1;  /* not_done */
  458. oom:
  459.         /* Start timer, stop polling, but do not enable rx interrupts. */
  460. start_poll_timer(dev);
  461.         return 0;  /* we'll take it from here so tell core "done"*/
  462. /************************ End note note *********************************/
  463. }
  464. -------------------------------------------------------------------
  465. From above we note that:
  466. 0) rx_work_limit = dev->quota 
  467. 1) refill_rx_ring() is in charge of clearing the bit for rxnobuff when
  468. it does the work.
  469. 2) We have a done and not_done state.
  470. 3) instead of netif_rx() we call netif_receive_skb() to pass the skb.
  471. 4) we have a new way of handling oom condition
  472. 5) A new outer for (;;) loop has been added. This serves the purpose of
  473. ensuring that if a new packet has come in, after we are all set and done,
  474. and we have not exceeded our quota that we continue sending packets up.
  475.  
  476. -----------------------------------------------------------
  477. Poll timer code will need to do the following:
  478. a) 
  479.         if (tp->cur_rx - tp->dirty_rx > RX_RING_SIZE/2 ||
  480.             tp->rx_buffers[tp->dirty_rx % RX_RING_SIZE].skb == NULL) 
  481.                 refill_rx_ring(dev);
  482.         /* If RX ring is not full we are still out of memory.
  483.    Restart the timer again. Else we re-add ourselves 
  484.            to the master poll list.
  485.          */
  486.         if (tp->rx_buffers[tp->dirty_rx % RX_RING_SIZE].skb == NULL)
  487.                 restart_timer();
  488. else netif_rx_schedule(dev);  /* we are back on the poll list */
  489. 5) dev->close() and dev->suspend() issues
  490. ==========================================
  491. The driver writter neednt worry about this. The top net layer takes
  492. care of it.
  493. 6) Adding new Stats to /proc 
  494. =============================
  495. In order to debug some of the new features, we introduce new stats
  496. that need to be collected.
  497. TODO: Fill this later.
  498. APPENDIX 1: discussion on using ethernet HW FC
  499. ==============================================
  500. Most chips with FC only send a pause packet when they run out of Rx buffers.
  501. Since packets are pulled off the DMA ring by a softirq in NAPI,
  502. if the system is slow in grabbing them and we have a high input
  503. rate (faster than the system's capacity to remove packets), then theoretically
  504. there will only be one rx interrupt for all packets during a given packetstorm.
  505. Under low load, we might have a single interrupt per packet.
  506. FC should be programmed to apply in the case when the system cant pull out
  507. packets fast enough i.e send a pause only when you run out of rx buffers.
  508. Note FC in itself is a good solution but we have found it to not be
  509. much of a commodity feature (both in NICs and switches) and hence falls
  510. under the same category as using NIC based mitigation. Also experiments
  511. indicate that its much harder to resolve the resource allocation
  512. issue (aka lazy receiving that NAPI offers) and hence quantify its usefullness
  513. proved harder. In any case, FC works even better with NAPI but is not
  514. necessary.
  515. APPENDIX 2: the "rotting packet" race-window avoidance scheme 
  516. =============================================================
  517. There are two types of associations seen here
  518. 1) status/int which honors level triggered IRQ
  519. If a status bit for receive or rxnobuff is set and the corresponding 
  520. interrupt-enable bit is not on, then no interrupts will be generated. However, 
  521. as soon as the "interrupt-enable" bit is unmasked, an immediate interrupt is 
  522. generated.  [assuming the status bit was not turned off].
  523. Generally the concept of level triggered IRQs in association with a status and
  524. interrupt-enable CSR register set is used to avoid the race.
  525. If we take the example of the tulip:
  526. "pending work" is indicated by the status bit(CSR5 in tulip).
  527. the corresponding interrupt bit (CSR7 in tulip) might be turned off (but
  528. the CSR5 will continue to be turned on with new packet arrivals even if
  529. we clear it the first time)
  530. Very important is the fact that if we turn on the interrupt bit on when
  531. status is set that an immediate irq is triggered.
  532.  
  533. If we cleared the rx ring and proclaimed there was "no more work
  534. to be done" and then went on to do a few other things;  then when we enable
  535. interrupts, there is a possibility that a new packet might sneak in during
  536. this phase. It helps to look at the pseudo code for the tulip poll
  537. routine:
  538. --------------------------
  539.         do {
  540.                 ACK;
  541.                 while (ring_is_not_empty()) {
  542.                         work-work-work
  543.                         if quota is exceeded: exit, no touching irq status/mask
  544.                 }
  545.                 /* No packets, but new can arrive while we are doing this*/
  546.                 CSR5 := read
  547.                 if (CSR5 is not set) {
  548.                         /* If something arrives in this narrow window here,
  549.                         *  where the comments are ;-> irq will be generated */
  550.                         unmask irqs;
  551.                         exit poll;
  552.                 }
  553.         } while (rx_status_is_set);
  554. ------------------------
  555. CSR5 bit of interest is only the rx status. 
  556. If you look at the last if statement: 
  557. you just finished grabbing all the packets from the rx ring .. you check if
  558. status bit says theres more packets just in ... it says none; you then
  559. enable rx interrupts again; if a new packet just came in during this check,
  560. we are counting that CSR5 will be set in that small window of opportunity
  561. and that by re-enabling interrupts, we would actually triger an interrupt
  562. to register the new packet for processing.
  563. [The above description nay be very verbose, if you have better wording 
  564. that will make this more understandable, please suggest it.]
  565. 2) non-capable hardware
  566. These do not generally respect level triggered IRQs. Normally,
  567. irqs may be lost while being masked and the only way to leave poll is to do
  568. a double check for new input after netif_rx_complete() is invoked
  569. and re-enable polling (after seeing this new input).
  570. Sample code:
  571. ---------
  572. .
  573. .
  574. restart_poll:
  575. while (ring_is_not_empty()) {
  576. work-work-work
  577. if quota is exceeded: exit, not touching irq status/mask
  578. }
  579. .
  580. .
  581. .
  582. enable_rx_interrupts()
  583. netif_rx_complete(dev);
  584. if (ring_has_new_packet() && netif_rx_reschedule(dev, received)) {
  585. disable_rx_and_rxnobufs()
  586. goto restart_poll
  587. } while (rx_status_is_set);
  588. ---------
  589. Basically netif_rx_complete() removes us from the poll list, but because a
  590. new packet which will never be caught due to the possibility of a race
  591. might come in, we attempt to re-add ourselves to the poll list. 
  592. --------------------------------------------------------------------
  593. relevant sites:
  594. ==================
  595. ftp://robur.slu.se/pub/Linux/net-development/NAPI/
  596. --------------------------------------------------------------------
  597. TODO: Write net-skeleton.c driver.
  598. -------------------------------------------------------------
  599. Authors:
  600. ========
  601. Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
  602. Jamal Hadi Salim <hadi@cyberus.ca>
  603. Robert Olsson <Robert.Olsson@data.slu.se>
  604. Acknowledgements:
  605. ================
  606. People who made this document better:
  607. Lennert Buytenhek <buytenh@gnu.org>
  608. Andrew Morton  <akpm@zip.com.au>
  609. Manfred Spraul <manfred@colorfullife.com>
  610. Donald Becker <becker@scyld.com>
  611. Jeff Garzik