Advertisement
Guest User

irq work

a guest
Sep 1st, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.31 KB | None | 0 0
  1. static void enc28j60_irq_work_handler(struct work_struct *work)
  2. {
  3.     struct enc28j60_net *priv =
  4.         container_of(work, struct enc28j60_net, irq_work);
  5.     struct net_device *ndev = priv->netdev;
  6.     int intflags, loop;
  7.  
  8.     if (netif_msg_intr(priv))
  9.         printk(KERN_DEBUG DRV_NAME ": %s() enter\n", __func__);
  10.     /* disable further interrupts */
  11.     locked_reg_bfclr(priv, EIE, EIE_INTIE);
  12.  
  13.     do {
  14.         loop = 0;
  15.         intflags = locked_regb_read(priv, EIR);
  16.         /* DMA interrupt handler (not currently used) */
  17.         if ((intflags & EIR_DMAIF) != 0) {
  18.             loop++;
  19.             if (netif_msg_intr(priv))
  20.                 printk(KERN_DEBUG DRV_NAME
  21.                     ": intDMA(%d)\n", loop);
  22.             locked_reg_bfclr(priv, EIR, EIR_DMAIF);
  23.         }
  24.         /* LINK changed handler */
  25.         if ((intflags & EIR_LINKIF) != 0) {
  26.             loop++;
  27.             if (netif_msg_intr(priv))
  28.                 printk(KERN_DEBUG DRV_NAME
  29.                     ": intLINK(%d)\n", loop);
  30.             enc28j60_check_link_status(ndev);
  31.             /* read PHIR to clear the flag */
  32.             enc28j60_phy_read(priv, PHIR);
  33.         }
  34.         /* TX complete handler */
  35.         if ((intflags & EIR_TXIF) != 0) {
  36.             bool err = false;
  37.             loop++;
  38.             if (netif_msg_intr(priv))
  39.                 printk(KERN_DEBUG DRV_NAME
  40.                     ": intTX(%d)\n", loop);
  41.             priv->tx_retry_count = 0;
  42.             if (locked_regb_read(priv, ESTAT) & ESTAT_TXABRT) {
  43.                 if (netif_msg_tx_err(priv))
  44.                     dev_err(&ndev->dev,
  45.                         "Tx Error (aborted)\n");
  46.                 err = true;
  47.             }
  48.             if (netif_msg_tx_done(priv)) {
  49.                 u8 tsv[TSV_SIZE];
  50.                 enc28j60_read_tsv(priv, tsv);
  51.                 enc28j60_dump_tsv(priv, "Tx Done", tsv);
  52.             }
  53.             enc28j60_tx_clear(ndev, err);
  54.             locked_reg_bfclr(priv, EIR, EIR_TXIF);
  55.         }
  56.         /* TX Error handler */
  57.         if ((intflags & EIR_TXERIF) != 0) {
  58.             u8 tsv[TSV_SIZE];
  59.  
  60.             loop++;
  61.             if (netif_msg_intr(priv))
  62.                 printk(KERN_DEBUG DRV_NAME
  63.                     ": intTXErr(%d)\n", loop);
  64.             locked_reg_bfclr(priv, ECON1, ECON1_TXRTS);
  65.             enc28j60_read_tsv(priv, tsv);
  66.             if (netif_msg_tx_err(priv))
  67.                 enc28j60_dump_tsv(priv, "Tx Error", tsv);
  68.             /* Reset TX logic */
  69.             mutex_lock(&priv->lock);
  70.             nolock_reg_bfset(priv, ECON1, ECON1_TXRST);
  71.             nolock_reg_bfclr(priv, ECON1, ECON1_TXRST);
  72.             nolock_txfifo_init(priv, TXSTART_INIT, TXEND_INIT);
  73.             mutex_unlock(&priv->lock);
  74.             /* Transmit Late collision check for retransmit */
  75.             if (TSV_GETBIT(tsv, TSV_TXLATECOLLISION)) {
  76.                 if (netif_msg_tx_err(priv))
  77.                     printk(KERN_DEBUG DRV_NAME
  78.                         ": LateCollision TXErr (%d)\n",
  79.                         priv->tx_retry_count);
  80.                 if (priv->tx_retry_count++ < MAX_TX_RETRYCOUNT)
  81.                     locked_reg_bfset(priv, ECON1,
  82.                                ECON1_TXRTS);
  83.                 else
  84.                     enc28j60_tx_clear(ndev, true);
  85.             } else
  86.                 enc28j60_tx_clear(ndev, true);
  87.             locked_reg_bfclr(priv, EIR, EIR_TXERIF);
  88.         }
  89.         /* RX Error handler */
  90.         if ((intflags & EIR_RXERIF) != 0) {
  91.             loop++;
  92.             if (netif_msg_intr(priv))
  93.                 printk(KERN_DEBUG DRV_NAME
  94.                     ": intRXErr(%d)\n", loop);
  95.             /* Check free FIFO space to flag RX overrun */
  96.             if (enc28j60_get_free_rxfifo(priv) <= 0) {
  97.                 if (netif_msg_rx_err(priv))
  98.                     printk(KERN_DEBUG DRV_NAME
  99.                         ": RX Overrun\n");
  100.                 ndev->stats.rx_dropped++;
  101.             }
  102.             locked_reg_bfclr(priv, EIR, EIR_RXERIF);
  103.         }
  104.         /* RX handler */
  105.         if (enc28j60_rx_interrupt(ndev))
  106.             loop++;
  107.     } while (loop);
  108.  
  109.     /* re-enable interrupts */
  110.     locked_reg_bfset(priv, EIE, EIE_INTIE);
  111.     if (netif_msg_intr(priv))
  112.         printk(KERN_DEBUG DRV_NAME ": %s() exit\n", __func__);
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement