zhubr

Untitled

Jun 12th, 2021 (edited)
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 5.55 KB | None | 0 0
  1. --- 8139too.c.orig  2021-06-07 23:26:50.000000000 +0300
  2. +++ 8139too.c   2021-06-12 19:23:47.908493342 +0300
  3. @@ -140,6 +140,10 @@
  4.          }
  5.  #endif
  6.  
  7. +#define TUNE8139_TX_WORK_IN_IRQ 0
  8. +#define TUNE8139_TX_WORK_IN_POLL 1
  9. +#define TUNE8139_LOOP_IN_IRQ 0
  10. +#define TUNE8139_LOOP_IN_POLL 0
  11.  
  12.  /* A few user-configurable values. */
  13.  /* media options */
  14. @@ -604,6 +608,7 @@
  15.     unsigned int        watchdog_fired : 1;
  16.     unsigned int        default_port : 4; /* Last dev->if_port value. */
  17.     unsigned int        have_thread : 1;
  18. +   int         poll_active;
  19.  
  20.     spinlock_t      lock;
  21.     spinlock_t      rx_lock;
  22. @@ -1398,6 +1403,7 @@
  23.     RTL_W32_F (MAC0 + 4, le16_to_cpu (*(__le16 *) (dev->dev_addr + 4)));
  24.  
  25.     tp->cur_rx = 0;
  26. +   tp->poll_active = 0;
  27.  
  28.     /* init Rx ring buffer DMA address */
  29.     RTL_W32_F (RxBuf, tp->rx_ring_dma);
  30. @@ -2123,24 +2129,85 @@
  31.     }
  32.  }
  33.  
  34. +static void rtl8139_tx_and_stuff(struct net_device *dev, struct rtl8139_private *tp, u16 status, int do_schedule)
  35. +{
  36. +   void __iomem *ioaddr = tp->mmio_addr;
  37. +   int link_changed = 0; /* avoid bogus "uninit" warning */
  38. +   u16 ackstat;
  39. +
  40. +   /* Acknowledge all of the current interrupt sources ASAP, but
  41. +      an first get an additional status bit from CSCR. */
  42. +   if (unlikely(status & RxUnderrun))
  43. +       link_changed = RTL_R16 (CSCR) & CSCR_LinkChangeBit;
  44. +
  45. +   ackstat = status & ~(RxAckBits | TxErr);
  46. +   if (ackstat)
  47. +       RTL_W16 (IntrStatus, ackstat);
  48. +
  49. +   /* Process interrupts in poll routine.
  50. +      If not running start it now. */
  51. +   if (do_schedule && !tp->poll_active){ // zhubr
  52. +       if (napi_schedule_prep(&tp->napi)) {
  53. +           tp->poll_active = 1;
  54. +           RTL_W16_F (IntrMask, rtl8139_norx_intr_mask);
  55. +           __napi_schedule(&tp->napi);
  56. +       }
  57. +   }
  58. +
  59. +   /* Check uncommon events with one test. */
  60. +   if (unlikely(status & (PCIErr | PCSTimeout | RxUnderrun | RxErr)))
  61. +       rtl8139_weird_interrupt (dev, tp, ioaddr,
  62. +                    status, link_changed);
  63. +
  64. +   if (status & (TxOK | TxErr)) {
  65. +       rtl8139_tx_interrupt (dev, tp, ioaddr);
  66. +       if (status & TxErr)
  67. +           RTL_W16 (IntrStatus, TxErr);
  68. +   }
  69. +}
  70. +
  71.  static int rtl8139_poll(struct napi_struct *napi, int budget)
  72.  {
  73.     struct rtl8139_private *tp = container_of(napi, struct rtl8139_private, napi);
  74.     struct net_device *dev = tp->dev;
  75.     void __iomem *ioaddr = tp->mmio_addr;
  76. +   u32 status;
  77.     int work_done;
  78.  
  79.     spin_lock(&tp->rx_lock);
  80.     work_done = 0;
  81. -   if (likely(RTL_R16(IntrStatus) & RxAckBits))
  82. +   status = RTL_R16(IntrStatus);
  83. +#if (TUNE8139_TX_WORK_IN_POLL)
  84. +   if (status & (PCIErr | PCSTimeout | RxUnderrun | RxErr | TxOK | TxErr)) { // zhubr
  85. +       unsigned long flags;
  86. +#if (TUNE8139_LOOP_IN_POLL)
  87. +       int boguscnt = max(NUM_TX_DESC, 4 /* Implying PCIErr, PCSTimeout, RxUnderrun, RxErr */);
  88. +#endif
  89. +       spin_lock_irqsave(&tp->lock, flags);
  90. +       status = RTL_R16(IntrStatus);
  91. +#if (TUNE8139_LOOP_IN_POLL)
  92. +       while ((boguscnt > 0) && (status & (PCIErr | PCSTimeout | RxUnderrun | RxErr | TxOK | TxErr))) {
  93. +#endif
  94. +           rtl8139_tx_and_stuff(dev, tp, status, 0);
  95. +#if (TUNE8139_LOOP_IN_POLL)
  96. +           status = RTL_R16 (IntrStatus);
  97. +           boguscnt--;
  98. +       }
  99. +#endif
  100. +       spin_unlock_irqrestore(&tp->lock, flags);
  101. +   }
  102. +#endif
  103. +   if (likely(status & RxAckBits))
  104.         work_done += rtl8139_rx(dev, tp, budget);
  105.  
  106.     if (work_done < budget) {
  107.         unsigned long flags;
  108.  
  109.         spin_lock_irqsave(&tp->lock, flags);
  110. -       if (napi_complete_done(napi, work_done))
  111. +       if (napi_complete_done(napi, work_done)) {
  112.             RTL_W16_F(IntrMask, rtl8139_intr_mask);
  113. +           tp->poll_active = 0;
  114. +       }
  115.         spin_unlock_irqrestore(&tp->lock, flags);
  116.     }
  117.     spin_unlock(&tp->rx_lock);
  118. @@ -2155,10 +2222,11 @@
  119.     struct net_device *dev = (struct net_device *) dev_instance;
  120.     struct rtl8139_private *tp = netdev_priv(dev);
  121.     void __iomem *ioaddr = tp->mmio_addr;
  122. -   u16 status, ackstat;
  123. -   int link_changed = 0; /* avoid bogus "uninit" warning */
  124. +   u16 status;
  125.     int handled = 0;
  126. -
  127. +#if (TUNE8139_LOOP_IN_IRQ && (TUNE8139_TX_WORK_IN_IRQ || !TUNE8139_TX_WORK_IN_POLL))
  128. +   int boguscnt = max(NUM_TX_DESC, 4 /* Implying PCIErr, PCSTimeout, RxUnderrun, RxErr */);
  129. +#endif
  130.     spin_lock (&tp->lock);
  131.     status = RTL_R16 (IntrStatus);
  132.  
  133. @@ -2178,34 +2246,31 @@
  134.         goto out;
  135.     }
  136.  
  137. -   /* Acknowledge all of the current interrupt sources ASAP, but
  138. -      an first get an additional status bit from CSCR. */
  139. -   if (unlikely(status & RxUnderrun))
  140. -       link_changed = RTL_R16 (CSCR) & CSCR_LinkChangeBit;
  141. -
  142. -   ackstat = status & ~(RxAckBits | TxErr);
  143. -   if (ackstat)
  144. -       RTL_W16 (IntrStatus, ackstat);
  145. -
  146. -   /* Receive packets are processed by poll routine.
  147. -      If not running start it now. */
  148. -   if (status & RxAckBits){
  149. +#if (TUNE8139_TX_WORK_IN_IRQ || !TUNE8139_TX_WORK_IN_POLL)
  150. +#if (TUNE8139_LOOP_IN_IRQ)
  151. +   do {
  152. +#endif
  153. +       rtl8139_tx_and_stuff(dev, tp, status, (status & RxAckBits)); // zhubr
  154. +#if (TUNE8139_LOOP_IN_IRQ)
  155. +       boguscnt--;
  156. +       status = RTL_R16 (IntrStatus);
  157. +   } while ((boguscnt > 0) && ((status & ~RxAckBits) || ((status & RxAckBits) && !tp->poll_active)));
  158. +#endif
  159. +#else
  160. +   if (!tp->poll_active){ // zhubr
  161.         if (napi_schedule_prep(&tp->napi)) {
  162. -           RTL_W16_F (IntrMask, rtl8139_norx_intr_mask);
  163. +           tp->poll_active = 1;
  164. +           RTL_W16_F (IntrMask,
  165. +#if (TUNE8139_TX_WORK_IN_IRQ)
  166. +               rtl8139_norx_intr_mask
  167. +#else
  168. +               0
  169. +#endif
  170. +           );
  171.             __napi_schedule(&tp->napi);
  172.         }
  173.     }
  174. -
  175. -   /* Check uncommon events with one test. */
  176. -   if (unlikely(status & (PCIErr | PCSTimeout | RxUnderrun | RxErr)))
  177. -       rtl8139_weird_interrupt (dev, tp, ioaddr,
  178. -                    status, link_changed);
  179. -
  180. -   if (status & (TxOK | TxErr)) {
  181. -       rtl8139_tx_interrupt (dev, tp, ioaddr);
  182. -       if (status & TxErr)
  183. -           RTL_W16 (IntrStatus, TxErr);
  184. -   }
  185. +#endif
  186.   out:
  187.     spin_unlock (&tp->lock);
  188.  
  189.  
Add Comment
Please, Sign In to add comment