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

Linux/Unix编程

开发平台:

Unix_Linux

  1.   /* Copy addresses from the lp structure */
  2.   for(i = 0; i < lp->spy_number; i++)
  3.     {
  4.       memcpy(address[i].sa_data, lp->spy_address[i],
  5.      WAVELAN_ADDR_SIZE);
  6.       address[i].sa_family = ARPHRD_ETHER;
  7.     }
  8.   /* Copy addresses to the user buffer */
  9.   if(copy_to_user(wrq->u.data.pointer, address,
  10.        sizeof(struct sockaddr) * lp->spy_number))
  11.     {
  12.       ret = -EFAULT;
  13.       break;
  14.     }
  15.   /* Copy stats to the user buffer (just after) */
  16.   if(copy_to_user(wrq->u.data.pointer +
  17.        (sizeof(struct sockaddr) * lp->spy_number),
  18.        lp->spy_stat, sizeof(iw_qual) * lp->spy_number))
  19.     {
  20.       ret = -EFAULT;
  21.       break;
  22.     }
  23.   /* Reset updated flags */
  24.   for(i = 0; i < lp->spy_number; i++)
  25.     lp->spy_stat[i].updated = 0x0;
  26. } /* if(pointer != NULL) */
  27.       break;
  28. #endif /* WIRELESS_SPY */
  29.       /* ------------------ PRIVATE IOCTL ------------------ */
  30.     case SIOCSIPQTHR:
  31.       if(!capable(CAP_NET_ADMIN))
  32. {
  33.   ret = -EPERM;
  34.   break;
  35. }
  36.       psa.psa_quality_thr = *(wrq->u.name) & 0x0F;
  37.       psa_write(dev, (char *)&psa.psa_quality_thr - (char *)&psa,
  38.        (unsigned char *)&psa.psa_quality_thr, 1);
  39.       /* update the Wavelan checksum */
  40.       update_psa_checksum(dev);
  41.       mmc_out(base, mmwoff(0, mmw_quality_thr), psa.psa_quality_thr);
  42.       break;
  43.     case SIOCGIPQTHR:
  44.       psa_read(dev, (char *)&psa.psa_quality_thr - (char *)&psa,
  45.        (unsigned char *)&psa.psa_quality_thr, 1);
  46.       *(wrq->u.name) = psa.psa_quality_thr & 0x0F;
  47.       break;
  48. #ifdef WAVELAN_ROAMING
  49.     case SIOCSIPROAM:
  50.       /* Note : should check if user == root */
  51.       if(do_roaming && (*wrq->u.name)==0)
  52. wv_roam_cleanup(dev);
  53.       else if(do_roaming==0 && (*wrq->u.name)!=0)
  54. wv_roam_init(dev);
  55.       do_roaming = (*wrq->u.name);
  56.   
  57.       break;
  58.     case SIOCGIPROAM:
  59.       *(wrq->u.name) = do_roaming;
  60.       break;
  61. #endif /* WAVELAN_ROAMING */
  62. #ifdef HISTOGRAM
  63.     case SIOCSIPHISTO:
  64.       /* Verif if the user is root */
  65.       if(!capable(CAP_NET_ADMIN))
  66. {
  67.   ret = -EPERM;
  68. }
  69.       /* Check the number of intervals */
  70.       if(wrq->u.data.length > 16)
  71. {
  72.   ret = -E2BIG;
  73.   break;
  74. }
  75.       lp->his_number = wrq->u.data.length;
  76.       /* If there is some addresses to copy */
  77.       if(lp->his_number > 0)
  78. {
  79.   /* Copy interval ranges to the driver */
  80.   if(copy_from_user(lp->his_range, wrq->u.data.pointer,
  81.  sizeof(char) * lp->his_number))
  82.     {
  83.       ret = -EFAULT;
  84.       break;
  85.     }
  86.   /* Reset structure... */
  87.   memset(lp->his_sum, 0x00, sizeof(long) * 16);
  88. }
  89.       break;
  90.     case SIOCGIPHISTO:
  91.       /* Set the number of intervals */
  92.       wrq->u.data.length = lp->his_number;
  93.       /* Give back the distribution statistics */
  94.       if((lp->his_number > 0) && (wrq->u.data.pointer != (caddr_t) 0))
  95. {
  96.   /* Copy data to the user buffer */
  97.   if(copy_to_user(wrq->u.data.pointer, lp->his_sum,
  98.        sizeof(long) * lp->his_number))
  99.     ret = -EFAULT;
  100. } /* if(pointer != NULL) */
  101.       break;
  102. #endif /* HISTOGRAM */
  103.       /* ------------------- OTHER IOCTL ------------------- */
  104.     default:
  105.       ret = -EOPNOTSUPP;
  106.     }
  107.   /* ReEnable interrupts & restore flags */
  108.   wv_splx(lp, &flags);
  109. #ifdef DEBUG_IOCTL_TRACE
  110.   printk(KERN_DEBUG "%s: <-wavelan_ioctl()n", dev->name);
  111. #endif
  112.   return ret;
  113. }
  114. /*------------------------------------------------------------------*/
  115. /*
  116.  * Get wireless statistics
  117.  * Called by /proc/net/wireless...
  118.  */
  119. static iw_stats *
  120. wavelan_get_wireless_stats(device * dev)
  121. {
  122.   ioaddr_t base = dev->base_addr;
  123.   net_local * lp = (net_local *) dev->priv;
  124.   mmr_t m;
  125.   iw_stats * wstats;
  126.   unsigned long flags;
  127. #ifdef DEBUG_IOCTL_TRACE
  128.   printk(KERN_DEBUG "%s: ->wavelan_get_wireless_stats()n", dev->name);
  129. #endif
  130.   /* Disable interrupts & save flags */
  131.   wv_splhi(lp, &flags);
  132.   wstats = &lp->wstats;
  133.   /* Get data from the mmc */
  134.   mmc_out(base, mmwoff(0, mmw_freeze), 1);
  135.   mmc_read(base, mmroff(0, mmr_dce_status), &m.mmr_dce_status, 1);
  136.   mmc_read(base, mmroff(0, mmr_wrong_nwid_l), &m.mmr_wrong_nwid_l, 2);
  137.   mmc_read(base, mmroff(0, mmr_thr_pre_set), &m.mmr_thr_pre_set, 4);
  138.   mmc_out(base, mmwoff(0, mmw_freeze), 0);
  139.   /* Copy data to wireless stuff */
  140.   wstats->status = m.mmr_dce_status & MMR_DCE_STATUS;
  141.   wstats->qual.qual = m.mmr_sgnl_qual & MMR_SGNL_QUAL;
  142.   wstats->qual.level = m.mmr_signal_lvl & MMR_SIGNAL_LVL;
  143.   wstats->qual.noise = m.mmr_silence_lvl & MMR_SILENCE_LVL;
  144.   wstats->qual.updated = (((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 7) |
  145.   ((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 6) |
  146.   ((m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) >> 5));
  147.   wstats->discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
  148.   wstats->discard.code = 0L;
  149.   wstats->discard.misc = 0L;
  150.   /* ReEnable interrupts & restore flags */
  151.   wv_splx(lp, &flags);
  152. #ifdef DEBUG_IOCTL_TRACE
  153.   printk(KERN_DEBUG "%s: <-wavelan_get_wireless_stats()n", dev->name);
  154. #endif
  155.   return &lp->wstats;
  156. }
  157. #endif /* WIRELESS_EXT */
  158. /************************* PACKET RECEPTION *************************/
  159. /*
  160.  * This part deal with receiving the packets.
  161.  * The interrupt handler get an interrupt when a packet has been
  162.  * successfully received and called this part...
  163.  */
  164. /*------------------------------------------------------------------*/
  165. /*
  166.  * Calculate the starting address of the frame pointed to by the receive
  167.  * frame pointer and verify that the frame seem correct
  168.  * (called by wv_packet_rcv())
  169.  */
  170. static inline int
  171. wv_start_of_frame(device * dev,
  172.   int rfp, /* end of frame */
  173.   int wrap) /* start of buffer */
  174. {
  175.   ioaddr_t base = dev->base_addr;
  176.   int rp;
  177.   int len;
  178.   rp = (rfp - 5 + RX_SIZE) % RX_SIZE;
  179.   outb(rp & 0xff, PIORL(base));
  180.   outb(((rp >> 8) & PIORH_MASK), PIORH(base));
  181.   len = inb(PIOP(base));
  182.   len |= inb(PIOP(base)) << 8;
  183.   /* Sanity checks on size */
  184.   /* Frame too big */
  185.   if(len > MAXDATAZ + 100)
  186.     {
  187. #ifdef DEBUG_RX_ERROR
  188.       printk(KERN_INFO "%s: wv_start_of_frame: Received frame too large, rfp %d len 0x%xn",
  189.      dev->name, rfp, len);
  190. #endif
  191.       return(-1);
  192.     }
  193.   
  194.   /* Frame too short */
  195.   if(len < 7)
  196.     {
  197. #ifdef DEBUG_RX_ERROR
  198.       printk(KERN_INFO "%s: wv_start_of_frame: Received null frame, rfp %d len 0x%xn",
  199.      dev->name, rfp, len);
  200. #endif
  201.       return(-1);
  202.     }
  203.   
  204.   /* Wrap around buffer */
  205.   if(len > ((wrap - (rfp - len) + RX_SIZE) % RX_SIZE)) /* magic formula ! */
  206.     {
  207. #ifdef DEBUG_RX_ERROR
  208.       printk(KERN_INFO "%s: wv_start_of_frame: wrap around buffer, wrap %d rfp %d len 0x%xn",
  209.      dev->name, wrap, rfp, len);
  210. #endif
  211.       return(-1);
  212.     }
  213.   return((rp - len + RX_SIZE) % RX_SIZE);
  214. } /* wv_start_of_frame */
  215. /*------------------------------------------------------------------*/
  216. /*
  217.  * This routine does the actual copy of data (including the ethernet
  218.  * header structure) from the WaveLAN card to an sk_buff chain that
  219.  * will be passed up to the network interface layer. NOTE: We
  220.  * currently don't handle trailer protocols (neither does the rest of
  221.  * the network interface), so if that is needed, it will (at least in
  222.  * part) be added here.  The contents of the receive ring buffer are
  223.  * copied to a message chain that is then passed to the kernel.
  224.  *
  225.  * Note: if any errors occur, the packet is "dropped on the floor"
  226.  * (called by wv_packet_rcv())
  227.  */
  228. static inline void
  229. wv_packet_read(device * dev,
  230.        int fd_p,
  231.        int sksize)
  232. {
  233.   net_local * lp = (net_local *) dev->priv;
  234.   struct sk_buff * skb;
  235. #ifdef DEBUG_RX_TRACE
  236.   printk(KERN_DEBUG "%s: ->wv_packet_read(0x%X, %d)n",
  237.  dev->name, fd_p, sksize);
  238. #endif
  239.   /* Allocate some buffer for the new packet */
  240.   if((skb = dev_alloc_skb(sksize+2)) == (struct sk_buff *) NULL)
  241.     {
  242. #ifdef DEBUG_RX_ERROR
  243.       printk(KERN_INFO "%s: wv_packet_read(): could not alloc_skb(%d, GFP_ATOMIC)n",
  244.      dev->name, sksize);
  245. #endif
  246.       lp->stats.rx_dropped++;
  247.       /*
  248.        * Not only do we want to return here, but we also need to drop the
  249.        * packet on the floor to clear the interrupt.
  250.        */
  251.       return;
  252.     }
  253.   skb->dev = dev;
  254.   skb_reserve(skb, 2);
  255.   fd_p = read_ringbuf(dev, fd_p, (char *) skb_put(skb, sksize), sksize);
  256.   skb->protocol = eth_type_trans(skb, dev);
  257. #ifdef DEBUG_RX_INFO
  258.   wv_packet_info(skb->mac.raw, sksize, dev->name, "wv_packet_read");
  259. #endif /* DEBUG_RX_INFO */
  260.      
  261.   /* Statistics gathering & stuff associated.
  262.    * It seem a bit messy with all the define, but it's really simple... */
  263.   if(
  264. #ifdef WIRELESS_SPY
  265.      (lp->spy_number > 0) ||
  266. #endif /* WIRELESS_SPY */
  267. #ifdef HISTOGRAM
  268.      (lp->his_number > 0) ||
  269. #endif /* HISTOGRAM */
  270. #ifdef WAVELAN_ROAMING
  271.      (do_roaming) ||
  272. #endif /* WAVELAN_ROAMING */
  273.      0)
  274.     {
  275.       u_char stats[3]; /* Signal level, Noise level, Signal quality */
  276.       /* read signal level, silence level and signal quality bytes */
  277.       fd_p = read_ringbuf(dev, (fd_p + 4) % RX_SIZE + RX_BASE,
  278.   stats, 3);
  279. #ifdef DEBUG_RX_INFO
  280.       printk(KERN_DEBUG "%s: wv_packet_read(): Signal level %d/63, Silence level %d/63, signal quality %d/16n",
  281.      dev->name, stats[0] & 0x3F, stats[1] & 0x3F, stats[2] & 0x0F);
  282. #endif
  283. #ifdef WAVELAN_ROAMING
  284.       if(do_roaming)
  285. if(WAVELAN_BEACON(skb->data))
  286.   wl_roam_gather(dev, skb->data, stats);
  287. #endif /* WAVELAN_ROAMING */
  288.   
  289. #ifdef WIRELESS_SPY
  290.       wl_spy_gather(dev, skb->mac.raw + WAVELAN_ADDR_SIZE, stats);
  291. #endif /* WIRELESS_SPY */
  292. #ifdef HISTOGRAM
  293.       wl_his_gather(dev, stats);
  294. #endif /* HISTOGRAM */
  295.     }
  296.   /*
  297.    * Hand the packet to the Network Module
  298.    */
  299.   netif_rx(skb);
  300.   /* Keep stats up to date */
  301.   dev->last_rx = jiffies;
  302.   lp->stats.rx_packets++;
  303.   lp->stats.rx_bytes += sksize;
  304. #ifdef DEBUG_RX_TRACE
  305.   printk(KERN_DEBUG "%s: <-wv_packet_read()n", dev->name);
  306. #endif
  307.   return;
  308. }
  309. /*------------------------------------------------------------------*/
  310. /*
  311.  * This routine is called by the interrupt handler to initiate a
  312.  * packet transfer from the card to the network interface layer above
  313.  * this driver.  This routine checks if a buffer has been successfully
  314.  * received by the WaveLAN card.  If so, the routine wv_packet_read is
  315.  * called to do the actual transfer of the card's data including the
  316.  * ethernet header into a packet consisting of an sk_buff chain.
  317.  * (called by wavelan_interrupt())
  318.  * Note : the spinlock is already grabbed for us and irq are disabled.
  319.  */
  320. static inline void
  321. wv_packet_rcv(device * dev)
  322. {
  323.   ioaddr_t base = dev->base_addr;
  324.   net_local * lp = (net_local *) dev->priv;
  325.   int newrfp;
  326.   int rp;
  327.   int len;
  328.   int f_start;
  329.   int status;
  330.   int i593_rfp;
  331.   int stat_ptr;
  332.   u_char c[4];
  333. #ifdef DEBUG_RX_TRACE
  334.   printk(KERN_DEBUG "%s: ->wv_packet_rcv()n", dev->name);
  335. #endif
  336.   /* Get the new receive frame pointer from the i82593 chip */
  337.   outb(CR0_STATUS_2 | OP0_NOP, LCCR(base));
  338.   i593_rfp = inb(LCSR(base));
  339.   i593_rfp |= inb(LCSR(base)) << 8;
  340.   i593_rfp %= RX_SIZE;
  341.   /* Get the new receive frame pointer from the WaveLAN card.
  342.    * It is 3 bytes more than the increment of the i82593 receive
  343.    * frame pointer, for each packet. This is because it includes the
  344.    * 3 roaming bytes added by the mmc.
  345.    */
  346.   newrfp = inb(RPLL(base));
  347.   newrfp |= inb(RPLH(base)) << 8;
  348.   newrfp %= RX_SIZE;
  349. #ifdef DEBUG_RX_INFO
  350.   printk(KERN_DEBUG "%s: wv_packet_rcv(): i593_rfp %d stop %d newrfp %d lp->rfp %dn",
  351.  dev->name, i593_rfp, lp->stop, newrfp, lp->rfp);
  352. #endif
  353. #ifdef DEBUG_RX_ERROR
  354.   /* If no new frame pointer... */
  355.   if(lp->overrunning || newrfp == lp->rfp)
  356.     printk(KERN_INFO "%s: wv_packet_rcv(): no new frame: i593_rfp %d stop %d newrfp %d lp->rfp %dn",
  357.    dev->name, i593_rfp, lp->stop, newrfp, lp->rfp);
  358. #endif
  359.   /* Read all frames (packets) received */
  360.   while(newrfp != lp->rfp)
  361.     {
  362.       /* A frame is composed of the packet, followed by a status word,
  363.        * the length of the frame (word) and the mmc info (SNR & qual).
  364.        * It's because the length is at the end that we can only scan
  365.        * frames backward. */
  366.       /* Find the first frame by skipping backwards over the frames */
  367.       rp = newrfp; /* End of last frame */
  368.       while(((f_start = wv_start_of_frame(dev, rp, newrfp)) != lp->rfp) &&
  369.     (f_start != -1))
  370.   rp = f_start;
  371.       /* If we had a problem */
  372.       if(f_start == -1)
  373. {
  374. #ifdef DEBUG_RX_ERROR
  375.   printk(KERN_INFO "wavelan_cs: cannot find start of frame ");
  376.   printk(" i593_rfp %d stop %d newrfp %d lp->rfp %dn",
  377.  i593_rfp, lp->stop, newrfp, lp->rfp);
  378. #endif
  379.   lp->rfp = rp; /* Get to the last usable frame */
  380.   continue;
  381. }
  382.       /* f_start point to the beggining of the first frame received
  383.        * and rp to the beggining of the next one */
  384.       /* Read status & length of the frame */
  385.       stat_ptr = (rp - 7 + RX_SIZE) % RX_SIZE;
  386.       stat_ptr = read_ringbuf(dev, stat_ptr, c, 4);
  387.       status = c[0] | (c[1] << 8);
  388.       len = c[2] | (c[3] << 8);
  389.       /* Check status */
  390.       if((status & RX_RCV_OK) != RX_RCV_OK)
  391. {
  392.   lp->stats.rx_errors++;
  393.   if(status & RX_NO_SFD)
  394.     lp->stats.rx_frame_errors++;
  395.   if(status & RX_CRC_ERR)
  396.     lp->stats.rx_crc_errors++;
  397.   if(status & RX_OVRRUN)
  398.     lp->stats.rx_over_errors++;
  399. #ifdef DEBUG_RX_FAIL
  400.   printk(KERN_DEBUG "%s: wv_packet_rcv(): packet not received ok, status = 0x%xn",
  401.  dev->name, status);
  402. #endif
  403. }
  404.       else
  405. /* Read the packet and transmit to Linux */
  406. wv_packet_read(dev, f_start, len - 2);
  407.       /* One frame has been processed, skip it */
  408.       lp->rfp = rp;
  409.     }
  410.   /*
  411.    * Update the frame stop register, but set it to less than
  412.    * the full 8K to allow space for 3 bytes of signal strength
  413.    * per packet.
  414.    */
  415.   lp->stop = (i593_rfp + RX_SIZE - ((RX_SIZE / 64) * 3)) % RX_SIZE;
  416.   outb(OP0_SWIT_TO_PORT_1 | CR0_CHNL, LCCR(base));
  417.   outb(CR1_STOP_REG_UPDATE | (lp->stop >> RX_SIZE_SHIFT), LCCR(base));
  418.   outb(OP1_SWIT_TO_PORT_0, LCCR(base));
  419. #ifdef DEBUG_RX_TRACE
  420.   printk(KERN_DEBUG "%s: <-wv_packet_rcv()n", dev->name);
  421. #endif
  422. }
  423. /*********************** PACKET TRANSMISSION ***********************/
  424. /*
  425.  * This part deal with sending packet through the wavelan
  426.  * We copy the packet to the send buffer and then issue the send
  427.  * command to the i82593. The result of this operation will be
  428.  * checked in wavelan_interrupt()
  429.  */
  430. /*------------------------------------------------------------------*/
  431. /*
  432.  * This routine fills in the appropriate registers and memory
  433.  * locations on the WaveLAN card and starts the card off on
  434.  * the transmit.
  435.  * (called in wavelan_packet_xmit())
  436.  */
  437. static inline void
  438. wv_packet_write(device * dev,
  439. void * buf,
  440. short length)
  441. {
  442.   net_local * lp = (net_local *) dev->priv;
  443.   ioaddr_t base = dev->base_addr;
  444.   unsigned long flags;
  445.   int clen = length;
  446.   register u_short xmtdata_base = TX_BASE;
  447. #ifdef DEBUG_TX_TRACE
  448.   printk(KERN_DEBUG "%s: ->wv_packet_write(%d)n", dev->name, length);
  449. #endif
  450.   wv_splhi(lp, &flags);
  451.   /* Check if we need some padding */
  452.   if(clen < ETH_ZLEN)
  453.     clen = ETH_ZLEN;
  454.   /* Write the length of data buffer followed by the buffer */
  455.   outb(xmtdata_base & 0xff, PIORL(base));
  456.   outb(((xmtdata_base >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
  457.   outb(clen & 0xff, PIOP(base)); /* lsb */
  458.   outb(clen >> 8, PIOP(base));   /* msb */
  459.   /* Send the data */
  460.   outsb(PIOP(base), buf, clen);
  461.   /* Indicate end of transmit chain */
  462.   outb(OP0_NOP, PIOP(base));
  463.   /* josullvn@cs.cmu.edu: need to send a second NOP for alignment... */
  464.   outb(OP0_NOP, PIOP(base));
  465.   /* Reset the transmit DMA pointer */
  466.   hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
  467.   hacr_write(base, HACR_DEFAULT);
  468.   /* Send the transmit command */
  469.   wv_82593_cmd(dev, "wv_packet_write(): transmit",
  470.        OP0_TRANSMIT, SR0_NO_RESULT);
  471.   /* Make sure the watchdog will keep quiet for a while */
  472.   dev->trans_start = jiffies;
  473.   /* Keep stats up to date */
  474.   lp->stats.tx_bytes += length;
  475.   wv_splx(lp, &flags);
  476. #ifdef DEBUG_TX_INFO
  477.   wv_packet_info((u_char *) buf, length, dev->name, "wv_packet_write");
  478. #endif /* DEBUG_TX_INFO */
  479. #ifdef DEBUG_TX_TRACE
  480.   printk(KERN_DEBUG "%s: <-wv_packet_write()n", dev->name);
  481. #endif
  482. }
  483. /*------------------------------------------------------------------*/
  484. /*
  485.  * This routine is called when we want to send a packet (NET3 callback)
  486.  * In this routine, we check if the harware is ready to accept
  487.  * the packet. We also prevent reentrance. Then, we call the function
  488.  * to send the packet...
  489.  */
  490. static int
  491. wavelan_packet_xmit(struct sk_buff * skb,
  492.     device * dev)
  493. {
  494.   net_local * lp = (net_local *)dev->priv;
  495.   unsigned long flags;
  496. #ifdef DEBUG_TX_TRACE
  497.   printk(KERN_DEBUG "%s: ->wavelan_packet_xmit(0x%X)n", dev->name,
  498.  (unsigned) skb);
  499. #endif
  500.   /*
  501.    * Block a timer-based transmit from overlapping a previous transmit.
  502.    * In other words, prevent reentering this routine.
  503.    */
  504.   netif_stop_queue(dev);
  505.   /* If somebody has asked to reconfigure the controller,
  506.    * we can do it now */
  507.   if(lp->reconfig_82593)
  508.     {
  509.       wv_splhi(lp, &flags); /* Disable interrupts */
  510.       wv_82593_config(dev);
  511.       wv_splx(lp, &flags); /* Re-enable interrupts */
  512.       /* Note : the configure procedure was totally synchronous,
  513.        * so the Tx buffer is now free */
  514.     }
  515. #ifdef DEBUG_TX_ERROR
  516. if (skb->next)
  517. printk(KERN_INFO "skb has nextn");
  518. #endif
  519.   wv_packet_write(dev, skb->data, skb->len);
  520.   dev_kfree_skb(skb);
  521. #ifdef DEBUG_TX_TRACE
  522.   printk(KERN_DEBUG "%s: <-wavelan_packet_xmit()n", dev->name);
  523. #endif
  524.   return(0);
  525. }
  526. /********************** HARDWARE CONFIGURATION **********************/
  527. /*
  528.  * This part do the real job of starting and configuring the hardware.
  529.  */
  530. /*------------------------------------------------------------------*/
  531. /*
  532.  * Routine to initialize the Modem Management Controller.
  533.  * (called by wv_hw_config())
  534.  */
  535. static inline int
  536. wv_mmc_init(device * dev)
  537. {
  538.   ioaddr_t base = dev->base_addr;
  539.   psa_t psa;
  540.   mmw_t m;
  541.   int configured;
  542.   int i; /* Loop counter */
  543. #ifdef DEBUG_CONFIG_TRACE
  544.   printk(KERN_DEBUG "%s: ->wv_mmc_init()n", dev->name);
  545. #endif
  546.   /* Read the parameter storage area */
  547.   psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
  548.   /*
  549.    * Check the first three octets of the MAC addr for the manufacturer's code.
  550.    * Note: If you get the error message below, you've got a
  551.    * non-NCR/AT&T/Lucent PCMCIA cards, see wavelan_cs.h for detail on
  552.    * how to configure your card...
  553.    */
  554.   for(i = 0; i < (sizeof(MAC_ADDRESSES) / sizeof(char) / 3); i++)
  555.     if((psa.psa_univ_mac_addr[0] == MAC_ADDRESSES[i][0]) &&
  556.        (psa.psa_univ_mac_addr[1] == MAC_ADDRESSES[i][1]) &&
  557.        (psa.psa_univ_mac_addr[2] == MAC_ADDRESSES[i][2]))
  558.       break;
  559.   /* If we have not found it... */
  560.   if(i == (sizeof(MAC_ADDRESSES) / sizeof(char) / 3))
  561.     {
  562. #ifdef DEBUG_CONFIG_ERRORS
  563.       printk(KERN_WARNING "%s: wv_mmc_init(): Invalid MAC address: %02X:%02X:%02X:...n",
  564.      dev->name, psa.psa_univ_mac_addr[0],
  565.      psa.psa_univ_mac_addr[1], psa.psa_univ_mac_addr[2]);
  566. #endif
  567.       return FALSE;
  568.     }
  569.   /* Get the MAC address */
  570.   memcpy(&dev->dev_addr[0], &psa.psa_univ_mac_addr[0], WAVELAN_ADDR_SIZE);
  571. #ifdef USE_PSA_CONFIG
  572.   configured = psa.psa_conf_status & 1;
  573. #else
  574.   configured = 0;
  575. #endif
  576.   /* Is the PSA is not configured */
  577.   if(!configured)
  578.     {
  579.       /* User will be able to configure NWID after (with iwconfig) */
  580.       psa.psa_nwid[0] = 0;
  581.       psa.psa_nwid[1] = 0;
  582.       /* As NWID is not set : no NWID checking */
  583.       psa.psa_nwid_select = 0;
  584.       /* Disable encryption */
  585.       psa.psa_encryption_select = 0;
  586.       /* Set to standard values
  587.        * 0x04 for AT,
  588.        * 0x01 for MCA,
  589.        * 0x04 for PCMCIA and 2.00 card (AT&T 407-024689/E document)
  590.        */
  591.       if (psa.psa_comp_number & 1)
  592. psa.psa_thr_pre_set = 0x01;
  593.       else
  594. psa.psa_thr_pre_set = 0x04;
  595.       psa.psa_quality_thr = 0x03;
  596.       /* It is configured */
  597.       psa.psa_conf_status |= 1;
  598. #ifdef USE_PSA_CONFIG
  599.       /* Write the psa */
  600.       psa_write(dev, (char *)psa.psa_nwid - (char *)&psa,
  601. (unsigned char *)psa.psa_nwid, 4);
  602.       psa_write(dev, (char *)&psa.psa_thr_pre_set - (char *)&psa,
  603. (unsigned char *)&psa.psa_thr_pre_set, 1);
  604.       psa_write(dev, (char *)&psa.psa_quality_thr - (char *)&psa,
  605. (unsigned char *)&psa.psa_quality_thr, 1);
  606.       psa_write(dev, (char *)&psa.psa_conf_status - (char *)&psa,
  607. (unsigned char *)&psa.psa_conf_status, 1);
  608.       /* update the Wavelan checksum */
  609.       update_psa_checksum(dev);
  610. #endif /* USE_PSA_CONFIG */
  611.     }
  612.   /* Zero the mmc structure */
  613.   memset(&m, 0x00, sizeof(m));
  614.   /* Copy PSA info to the mmc */
  615.   m.mmw_netw_id_l = psa.psa_nwid[1];
  616.   m.mmw_netw_id_h = psa.psa_nwid[0];
  617.   
  618.   if(psa.psa_nwid_select & 1)
  619.     m.mmw_loopt_sel = 0x00;
  620.   else
  621.     m.mmw_loopt_sel = MMW_LOOPT_SEL_DIS_NWID;
  622.   memcpy(&m.mmw_encr_key, &psa.psa_encryption_key, 
  623.  sizeof(m.mmw_encr_key));
  624.   if(psa.psa_encryption_select)
  625.     m.mmw_encr_enable = MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE;
  626.   else
  627.     m.mmw_encr_enable = 0;
  628.   m.mmw_thr_pre_set = psa.psa_thr_pre_set & 0x3F;
  629.   m.mmw_quality_thr = psa.psa_quality_thr & 0x0F;
  630.   /*
  631.    * Set default modem control parameters.
  632.    * See NCR document 407-0024326 Rev. A.
  633.    */
  634.   m.mmw_jabber_enable = 0x01;
  635.   m.mmw_anten_sel = MMW_ANTEN_SEL_ALG_EN;
  636.   m.mmw_ifs = 0x20;
  637.   m.mmw_mod_delay = 0x04;
  638.   m.mmw_jam_time = 0x38;
  639.   m.mmw_des_io_invert = 0;
  640.   m.mmw_freeze = 0;
  641.   m.mmw_decay_prm = 0;
  642.   m.mmw_decay_updat_prm = 0;
  643.   /* Write all info to mmc */
  644.   mmc_write(base, 0, (u_char *)&m, sizeof(m));
  645.   /* The following code start the modem of the 2.00 frequency
  646.    * selectable cards at power on. It's not strictly needed for the
  647.    * following boots...
  648.    * The original patch was by Joe Finney for the PCMCIA driver, but
  649.    * I've cleaned it a bit and add documentation.
  650.    * Thanks to Loeke Brederveld from Lucent for the info.
  651.    */
  652.   /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable)
  653.    * (does it work for everybody ? - especially old cards...) */
  654.   /* Note : WFREQSEL verify that it is able to read from EEprom
  655.    * a sensible frequency (address 0x00) + that MMR_FEE_STATUS_ID
  656.    * is 0xA (Xilinx version) or 0xB (Ariadne version).
  657.    * My test is more crude but do work... */
  658.   if(!(mmc_in(base, mmroff(0, mmr_fee_status)) &
  659.        (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
  660.     {
  661.       /* We must download the frequency parameters to the
  662.        * synthetisers (from the EEprom - area 1)
  663.        * Note : as the EEprom is auto decremented, we set the end
  664.        * if the area... */
  665.       m.mmw_fee_addr = 0x0F;
  666.       m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
  667.       mmc_write(base, (char *)&m.mmw_fee_ctrl - (char *)&m,
  668. (unsigned char *)&m.mmw_fee_ctrl, 2);
  669.       /* Wait until the download is finished */
  670.       fee_wait(base, 100, 100);
  671. #ifdef DEBUG_CONFIG_INFO
  672.       /* The frequency was in the last word downloaded... */
  673.       mmc_read(base, (char *)&m.mmw_fee_data_l - (char *)&m,
  674.        (unsigned char *)&m.mmw_fee_data_l, 2);
  675.       /* Print some info for the user */
  676.       printk(KERN_DEBUG "%s: Wavelan 2.00 recognised (frequency select) : Current frequency = %ldn",
  677.      dev->name,
  678.      ((m.mmw_fee_data_h << 4) |
  679.       (m.mmw_fee_data_l >> 4)) * 5 / 2 + 24000L);
  680. #endif
  681.       /* We must now download the power adjust value (gain) to
  682.        * the synthetisers (from the EEprom - area 7 - DAC) */
  683.       m.mmw_fee_addr = 0x61;
  684.       m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
  685.       mmc_write(base, (char *)&m.mmw_fee_ctrl - (char *)&m,
  686. (unsigned char *)&m.mmw_fee_ctrl, 2);
  687.       /* Wait until the download is finished */
  688.     } /* if 2.00 card */
  689. #ifdef DEBUG_CONFIG_TRACE
  690.   printk(KERN_DEBUG "%s: <-wv_mmc_init()n", dev->name);
  691. #endif
  692.   return TRUE;
  693. }
  694. /*------------------------------------------------------------------*/
  695. /*
  696.  * Routine to gracefully turn off reception, and wait for any commands
  697.  * to complete.
  698.  * (called in wv_ru_start() and wavelan_close() and wavelan_event())
  699.  */
  700. static int
  701. wv_ru_stop(device * dev)
  702. {
  703.   ioaddr_t base = dev->base_addr;
  704.   net_local * lp = (net_local *) dev->priv;
  705.   unsigned long flags;
  706.   int status;
  707.   int spin;
  708. #ifdef DEBUG_CONFIG_TRACE
  709.   printk(KERN_DEBUG "%s: ->wv_ru_stop()n", dev->name);
  710. #endif
  711.   wv_splhi(lp, &flags);
  712.   /* First, send the LAN controller a stop receive command */
  713.   wv_82593_cmd(dev, "wv_graceful_shutdown(): stop-rcv",
  714.        OP0_STOP_RCV, SR0_NO_RESULT);
  715.   /* Then, spin until the receive unit goes idle */
  716.   spin = 300;
  717.   do
  718.     {
  719.       udelay(10);
  720.       outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
  721.       status = inb(LCSR(base));
  722.     }
  723.   while(((status & SR3_RCV_STATE_MASK) != SR3_RCV_IDLE) && (spin-- > 0));
  724.   /* Now, spin until the chip finishes executing its current command */
  725.   do
  726.     {
  727.       udelay(10);
  728.       outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
  729.       status = inb(LCSR(base));
  730.     }
  731.   while(((status & SR3_EXEC_STATE_MASK) != SR3_EXEC_IDLE) && (spin-- > 0));
  732.   wv_splx(lp, &flags);
  733.   /* If there was a problem */
  734.   if(spin <= 0)
  735.     {
  736. #ifdef DEBUG_CONFIG_ERROR
  737.       printk(KERN_INFO "%s: wv_ru_stop(): The chip doesn't want to stop...n",
  738.      dev->name);
  739. #endif
  740.       return FALSE;
  741.     }
  742. #ifdef DEBUG_CONFIG_TRACE
  743.   printk(KERN_DEBUG "%s: <-wv_ru_stop()n", dev->name);
  744. #endif
  745.   return TRUE;
  746. } /* wv_ru_stop */
  747. /*------------------------------------------------------------------*/
  748. /*
  749.  * This routine starts the receive unit running.  First, it checks if
  750.  * the card is actually ready. Then the card is instructed to receive
  751.  * packets again.
  752.  * (called in wv_hw_reset() & wavelan_open())
  753.  */
  754. static int
  755. wv_ru_start(device * dev)
  756. {
  757.   ioaddr_t base = dev->base_addr;
  758.   net_local * lp = (net_local *) dev->priv;
  759.   unsigned long flags;
  760. #ifdef DEBUG_CONFIG_TRACE
  761.   printk(KERN_DEBUG "%s: ->wv_ru_start()n", dev->name);
  762. #endif
  763.   /*
  764.    * We need to start from a quiescent state. To do so, we could check
  765.    * if the card is already running, but instead we just try to shut
  766.    * it down. First, we disable reception (in case it was already enabled).
  767.    */
  768.   if(!wv_ru_stop(dev))
  769.     return FALSE;
  770.   wv_splhi(lp, &flags);
  771.   /* Now we know that no command is being executed. */
  772.   /* Set the receive frame pointer and stop pointer */
  773.   lp->rfp = 0;
  774.   outb(OP0_SWIT_TO_PORT_1 | CR0_CHNL, LCCR(base));
  775.   /* Reset ring management.  This sets the receive frame pointer to 1 */
  776.   outb(OP1_RESET_RING_MNGMT, LCCR(base));
  777. #if 0
  778.   /* XXX the i82593 manual page 6-4 seems to indicate that the stop register
  779.      should be set as below */
  780.   /* outb(CR1_STOP_REG_UPDATE|((RX_SIZE - 0x40)>> RX_SIZE_SHIFT),LCCR(base));*/
  781. #elif 0
  782.   /* but I set it 0 instead */
  783.   lp->stop = 0;
  784. #else
  785.   /* but I set it to 3 bytes per packet less than 8K */
  786.   lp->stop = (0 + RX_SIZE - ((RX_SIZE / 64) * 3)) % RX_SIZE;
  787. #endif
  788.   outb(CR1_STOP_REG_UPDATE | (lp->stop >> RX_SIZE_SHIFT), LCCR(base));
  789.   outb(OP1_INT_ENABLE, LCCR(base));
  790.   outb(OP1_SWIT_TO_PORT_0, LCCR(base));
  791.   /* Reset receive DMA pointer */
  792.   hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
  793.   hacr_write_slow(base, HACR_DEFAULT);
  794.   /* Receive DMA on channel 1 */
  795.   wv_82593_cmd(dev, "wv_ru_start(): rcv-enable",
  796.        CR0_CHNL | OP0_RCV_ENABLE, SR0_NO_RESULT);
  797. #ifdef DEBUG_I82593_SHOW
  798.   {
  799.     int status;
  800.     int opri;
  801.     int spin = 10000;
  802.     /* spin until the chip starts receiving */
  803.     do
  804.       {
  805. outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
  806. status = inb(LCSR(base));
  807. if(spin-- <= 0)
  808.   break;
  809.       }
  810.     while(((status & SR3_RCV_STATE_MASK) != SR3_RCV_ACTIVE) &&
  811.   ((status & SR3_RCV_STATE_MASK) != SR3_RCV_READY));
  812.     printk(KERN_DEBUG "rcv status is 0x%x [i:%d]n",
  813.    (status & SR3_RCV_STATE_MASK), i);
  814.   }
  815. #endif
  816.   wv_splx(lp, &flags);
  817. #ifdef DEBUG_CONFIG_TRACE
  818.   printk(KERN_DEBUG "%s: <-wv_ru_start()n", dev->name);
  819. #endif
  820.   return TRUE;
  821. }
  822. /*------------------------------------------------------------------*/
  823. /*
  824.  * This routine does a standard config of the WaveLAN controller (i82593).
  825.  * In the ISA driver, this is integrated in wavelan_hardware_reset()
  826.  * (called by wv_hw_config(), wv_82593_reconfig() & wavelan_packet_xmit())
  827.  */
  828. static int
  829. wv_82593_config(device * dev)
  830. {
  831.   ioaddr_t base = dev->base_addr;
  832.   net_local * lp = (net_local *) dev->priv;
  833.   struct i82593_conf_block cfblk;
  834.   int ret = TRUE;
  835. #ifdef DEBUG_CONFIG_TRACE
  836.   printk(KERN_DEBUG "%s: ->wv_82593_config()n", dev->name);
  837. #endif
  838.   /* Create & fill i82593 config block
  839.    *
  840.    * Now conform to Wavelan document WCIN085B
  841.    */
  842.   memset(&cfblk, 0x00, sizeof(struct i82593_conf_block));
  843.   cfblk.d6mod = FALSE;   /* Run in i82593 advanced mode */
  844.   cfblk.fifo_limit = 5;         /* = 56 B rx and 40 B tx fifo thresholds */
  845.   cfblk.forgnesi = FALSE;       /* 0=82C501, 1=AMD7992B compatibility */
  846.   cfblk.fifo_32 = 1;
  847.   cfblk.throttle_enb = FALSE;
  848.   cfblk.contin = TRUE;          /* enable continuous mode */
  849.   cfblk.cntrxint = FALSE;       /* enable continuous mode receive interrupts */
  850.   cfblk.addr_len = WAVELAN_ADDR_SIZE;
  851.   cfblk.acloc = TRUE;           /* Disable source addr insertion by i82593 */
  852.   cfblk.preamb_len = 0;         /* 2 bytes preamble (SFD) */
  853.   cfblk.loopback = FALSE;
  854.   cfblk.lin_prio = 0;    /* conform to 802.3 backoff algoritm */
  855.   cfblk.exp_prio = 5;         /* conform to 802.3 backoff algoritm */
  856.   cfblk.bof_met = 1;         /* conform to 802.3 backoff algoritm */
  857.   cfblk.ifrm_spc = 0x20; /* 32 bit times interframe spacing */
  858.   cfblk.slottim_low = 0x20; /* 32 bit times slot time */
  859.   cfblk.slottim_hi = 0x0;
  860.   cfblk.max_retr = 15;
  861.   cfblk.prmisc = ((lp->promiscuous) ? TRUE: FALSE); /* Promiscuous mode */
  862.   cfblk.bc_dis = FALSE;         /* Enable broadcast reception */
  863.   cfblk.crs_1 = TRUE; /* Transmit without carrier sense */
  864.   cfblk.nocrc_ins = FALSE; /* i82593 generates CRC */
  865.   cfblk.crc_1632 = FALSE; /* 32-bit Autodin-II CRC */
  866.   cfblk.crs_cdt = FALSE; /* CD not to be interpreted as CS */
  867.   cfblk.cs_filter = 0;   /* CS is recognized immediately */
  868.   cfblk.crs_src = FALSE; /* External carrier sense */
  869.   cfblk.cd_filter = 0;   /* CD is recognized immediately */
  870.   cfblk.min_fr_len = ETH_ZLEN >> 2;     /* Minimum frame length 64 bytes */
  871.   cfblk.lng_typ = FALSE; /* Length field > 1500 = type field */
  872.   cfblk.lng_fld = TRUE;  /* Disable 802.3 length field check */
  873.   cfblk.rxcrc_xf = TRUE; /* Don't transfer CRC to memory */
  874.   cfblk.artx = TRUE; /* Disable automatic retransmission */
  875.   cfblk.sarec = TRUE; /* Disable source addr trig of CD */
  876.   cfblk.tx_jabber = TRUE; /* Disable jabber jam sequence */
  877.   cfblk.hash_1 = FALSE;  /* Use bits 0-5 in mc address hash */
  878.   cfblk.lbpkpol = TRUE;  /* Loopback pin active high */
  879.   cfblk.fdx = FALSE; /* Disable full duplex operation */
  880.   cfblk.dummy_6 = 0x3f;  /* all ones */
  881.   cfblk.mult_ia = FALSE; /* No multiple individual addresses */
  882.   cfblk.dis_bof = FALSE; /* Disable the backoff algorithm ?! */
  883.   cfblk.dummy_1 = TRUE;  /* set to 1 */
  884.   cfblk.tx_ifs_retrig = 3; /* Hmm... Disabled */
  885. #ifdef MULTICAST_ALL
  886.   cfblk.mc_all = (lp->allmulticast ? TRUE: FALSE); /* Allow all multicasts */
  887. #else
  888.   cfblk.mc_all = FALSE; /* No multicast all mode */
  889. #endif
  890.   cfblk.rcv_mon = 0; /* Monitor mode disabled */
  891.   cfblk.frag_acpt = TRUE; /* Do not accept fragments */
  892.   cfblk.tstrttrs = FALSE; /* No start transmission threshold */
  893.   cfblk.fretx = TRUE; /* FIFO automatic retransmission */
  894.   cfblk.syncrqs = FALSE;  /* Synchronous DRQ deassertion... */
  895.   cfblk.sttlen = TRUE;   /* 6 byte status registers */
  896.   cfblk.rx_eop = TRUE;   /* Signal EOP on packet reception */
  897.   cfblk.tx_eop = TRUE;   /* Signal EOP on packet transmission */
  898.   cfblk.rbuf_size = RX_SIZE>>11; /* Set receive buffer size */
  899.   cfblk.rcvstop = TRUE;  /* Enable Receive Stop Register */
  900. #ifdef DEBUG_I82593_SHOW
  901.   {
  902.     u_char *c = (u_char *) &cfblk;
  903.     int i;
  904.     printk(KERN_DEBUG "wavelan_cs: config block:");
  905.     for(i = 0; i < sizeof(struct i82593_conf_block); i++,c++)
  906.       {
  907. if((i % 16) == 0) printk("n" KERN_DEBUG);
  908. printk("%02x ", *c);
  909.       }
  910.     printk("n");
  911.   }
  912. #endif
  913.   /* Copy the config block to the i82593 */
  914.   outb(TX_BASE & 0xff, PIORL(base));
  915.   outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
  916.   outb(sizeof(struct i82593_conf_block) & 0xff, PIOP(base));    /* lsb */
  917.   outb(sizeof(struct i82593_conf_block) >> 8, PIOP(base)); /* msb */
  918.   outsb(PIOP(base), (char *) &cfblk, sizeof(struct i82593_conf_block));
  919.   /* reset transmit DMA pointer */
  920.   hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
  921.   hacr_write(base, HACR_DEFAULT);
  922.   if(!wv_82593_cmd(dev, "wv_82593_config(): configure",
  923.    OP0_CONFIGURE, SR0_CONFIGURE_DONE))
  924.     ret = FALSE;
  925.   /* Initialize adapter's ethernet MAC address */
  926.   outb(TX_BASE & 0xff, PIORL(base));
  927.   outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
  928.   outb(WAVELAN_ADDR_SIZE, PIOP(base)); /* byte count lsb */
  929.   outb(0, PIOP(base)); /* byte count msb */
  930.   outsb(PIOP(base), &dev->dev_addr[0], WAVELAN_ADDR_SIZE);
  931.   /* reset transmit DMA pointer */
  932.   hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
  933.   hacr_write(base, HACR_DEFAULT);
  934.   if(!wv_82593_cmd(dev, "wv_82593_config(): ia-setup",
  935.    OP0_IA_SETUP, SR0_IA_SETUP_DONE))
  936.     ret = FALSE;
  937. #ifdef WAVELAN_ROAMING
  938.     /* If roaming is enabled, join the "Beacon Request" multicast group... */
  939.     /* But only if it's not in there already! */
  940.   if(do_roaming)
  941.     dev_mc_add(dev,WAVELAN_BEACON_ADDRESS, WAVELAN_ADDR_SIZE, 1);
  942. #endif /* WAVELAN_ROAMING */
  943.   /* If any multicast address to set */
  944.   if(lp->mc_count)
  945.     {
  946.       struct dev_mc_list * dmi;
  947.       int addrs_len = WAVELAN_ADDR_SIZE * lp->mc_count;
  948. #ifdef DEBUG_CONFIG_INFO
  949.       printk(KERN_DEBUG "%s: wv_hw_config(): set %d multicast addresses:n",
  950.      dev->name, lp->mc_count);
  951.       for(dmi=dev->mc_list; dmi; dmi=dmi->next)
  952. printk(KERN_DEBUG " %02x:%02x:%02x:%02x:%02x:%02xn",
  953.        dmi->dmi_addr[0], dmi->dmi_addr[1], dmi->dmi_addr[2],
  954.        dmi->dmi_addr[3], dmi->dmi_addr[4], dmi->dmi_addr[5] );
  955. #endif
  956.       /* Initialize adapter's ethernet multicast addresses */
  957.       outb(TX_BASE & 0xff, PIORL(base));
  958.       outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
  959.       outb(addrs_len & 0xff, PIOP(base)); /* byte count lsb */
  960.       outb((addrs_len >> 8), PIOP(base)); /* byte count msb */
  961.       for(dmi=dev->mc_list; dmi; dmi=dmi->next)
  962. outsb(PIOP(base), dmi->dmi_addr, dmi->dmi_addrlen);
  963.       /* reset transmit DMA pointer */
  964.       hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
  965.       hacr_write(base, HACR_DEFAULT);
  966.       if(!wv_82593_cmd(dev, "wv_82593_config(): mc-setup",
  967.        OP0_MC_SETUP, SR0_MC_SETUP_DONE))
  968. ret = FALSE;
  969.       lp->mc_count = dev->mc_count; /* remember to avoid repeated reset */
  970.     }
  971.   /* Job done, clear the flag */
  972.   lp->reconfig_82593 = FALSE;
  973. #ifdef DEBUG_CONFIG_TRACE
  974.   printk(KERN_DEBUG "%s: <-wv_82593_config()n", dev->name);
  975. #endif
  976.   return(ret);
  977. }
  978. /*------------------------------------------------------------------*/
  979. /*
  980.  * Read the Access Configuration Register, perform a software reset,
  981.  * and then re-enable the card's software.
  982.  *
  983.  * If I understand correctly : reset the pcmcia interface of the
  984.  * wavelan.
  985.  * (called by wv_config())
  986.  */
  987. static inline int
  988. wv_pcmcia_reset(device * dev)
  989. {
  990.   int i;
  991.   conf_reg_t reg = { 0, CS_READ, CISREG_COR, 0 };
  992.   dev_link_t * link = ((net_local *) dev->priv)->link;
  993. #ifdef DEBUG_CONFIG_TRACE
  994.   printk(KERN_DEBUG "%s: ->wv_pcmcia_reset()n", dev->name);
  995. #endif
  996.   i = CardServices(AccessConfigurationRegister, link->handle, &reg);
  997.   if(i != CS_SUCCESS)
  998.     {
  999.       cs_error(link->handle, AccessConfigurationRegister, i);
  1000.       return FALSE;
  1001.     }
  1002.       
  1003. #ifdef DEBUG_CONFIG_INFO
  1004.   printk(KERN_DEBUG "%s: wavelan_pcmcia_reset(): Config reg is 0x%xn",
  1005.  dev->name, (u_int) reg.Value);
  1006. #endif
  1007.   reg.Action = CS_WRITE;
  1008.   reg.Value = reg.Value | COR_SW_RESET;
  1009.   i = CardServices(AccessConfigurationRegister, link->handle, &reg);
  1010.   if(i != CS_SUCCESS)
  1011.     {
  1012.       cs_error(link->handle, AccessConfigurationRegister, i);
  1013.       return FALSE;
  1014.     }
  1015.       
  1016.   reg.Action = CS_WRITE;
  1017.   reg.Value = COR_LEVEL_IRQ | COR_CONFIG;
  1018.   i = CardServices(AccessConfigurationRegister, link->handle, &reg);
  1019.   if(i != CS_SUCCESS)
  1020.     {
  1021.       cs_error(link->handle, AccessConfigurationRegister, i);
  1022.       return FALSE;
  1023.     }
  1024. #ifdef DEBUG_CONFIG_TRACE
  1025.   printk(KERN_DEBUG "%s: <-wv_pcmcia_reset()n", dev->name);
  1026. #endif
  1027.   return TRUE;
  1028. }
  1029. /*------------------------------------------------------------------*/
  1030. /*
  1031.  * wavelan_hw_config() is called after a CARD_INSERTION event is
  1032.  * received, to configure the wavelan hardware.
  1033.  * Note that the reception will be enabled in wavelan->open(), so the
  1034.  * device is configured but idle...
  1035.  * Performs the following actions:
  1036.  *  1. A pcmcia software reset (using wv_pcmcia_reset())
  1037.  * 2. A power reset (reset DMA)
  1038.  * 3. Reset the LAN controller
  1039.  * 4. Initialize the radio modem (using wv_mmc_init)
  1040.  * 5. Configure LAN controller (using wv_82593_config)
  1041.  * 6. Perform a diagnostic on the LAN controller
  1042.  * (called by wavelan_event() & wv_hw_reset())
  1043.  */
  1044. static int
  1045. wv_hw_config(device * dev)
  1046. {
  1047.   net_local * lp = (net_local *) dev->priv;
  1048.   ioaddr_t base = dev->base_addr;
  1049.   unsigned long flags;
  1050.   int ret = FALSE;
  1051. #ifdef DEBUG_CONFIG_TRACE
  1052.   printk(KERN_DEBUG "%s: ->wv_hw_config()n", dev->name);
  1053. #endif
  1054. #ifdef STRUCT_CHECK
  1055.   if(wv_structuct_check() != (char *) NULL)
  1056.     {
  1057.       printk(KERN_WARNING "%s: wv_hw_config: structure/compiler botch: "%s"n",
  1058.      dev->name, wv_structuct_check());
  1059.       return FALSE;
  1060.     }
  1061. #endif /* STRUCT_CHECK == 1 */
  1062.   /* Reset the pcmcia interface */
  1063.   if(wv_pcmcia_reset(dev) == FALSE)
  1064.     return FALSE;
  1065.   /* Disable interrupts */
  1066.   wv_splhi(lp, &flags);
  1067.   /* Disguised goto ;-) */
  1068.   do
  1069.     {
  1070.       /* Power UP the module + reset the modem + reset host adapter
  1071.        * (in fact, reset DMA channels) */
  1072.       hacr_write_slow(base, HACR_RESET);
  1073.       hacr_write(base, HACR_DEFAULT);
  1074.       /* Check if the module has been powered up... */
  1075.       if(hasr_read(base) & HASR_NO_CLK)
  1076. {
  1077. #ifdef DEBUG_CONFIG_ERRORS
  1078.   printk(KERN_WARNING "%s: wv_hw_config(): modem not connected or not a wavelan cardn",
  1079.  dev->name);
  1080. #endif
  1081.   break;
  1082. }
  1083.       /* initialize the modem */
  1084.       if(wv_mmc_init(dev) == FALSE)
  1085. {
  1086. #ifdef DEBUG_CONFIG_ERRORS
  1087.   printk(KERN_WARNING "%s: wv_hw_config(): Can't configure the modemn",
  1088.  dev->name);
  1089. #endif
  1090.   break;
  1091. }
  1092.       /* reset the LAN controller (i82593) */
  1093.       outb(OP0_RESET, LCCR(base));
  1094.       mdelay(1); /* A bit crude ! */
  1095.       /* Initialize the LAN controller */
  1096.       if(wv_82593_config(dev) == FALSE)
  1097. {
  1098. #ifdef DEBUG_CONFIG_ERRORS
  1099.   printk(KERN_INFO "%s: wv_hw_config(): i82593 init failedn",
  1100.  dev->name);
  1101. #endif
  1102.   break;
  1103. }
  1104.       /* Diagnostic */
  1105.       if(wv_diag(dev) == FALSE)
  1106. {
  1107. #ifdef DEBUG_CONFIG_ERRORS
  1108.   printk(KERN_INFO "%s: wv_hw_config(): i82593 diagnostic failedn",
  1109.  dev->name);
  1110. #endif
  1111.   break;
  1112. }
  1113.       /* 
  1114.        * insert code for loopback test here
  1115.        */
  1116.       /* The device is now configured */
  1117.       lp->configured = 1;
  1118.       ret = TRUE;
  1119.     }
  1120.   while(0);
  1121.   /* Re-enable interrupts */
  1122.   wv_splx(lp, &flags);
  1123. #ifdef DEBUG_CONFIG_TRACE
  1124.   printk(KERN_DEBUG "%s: <-wv_hw_config()n", dev->name);
  1125. #endif
  1126.   return(ret);
  1127. }
  1128. /*------------------------------------------------------------------*/
  1129. /*
  1130.  * Totally reset the wavelan and restart it.
  1131.  * Performs the following actions:
  1132.  *  1. Call wv_hw_config()
  1133.  * 2. Start the LAN controller's receive unit
  1134.  * (called by wavelan_event(), wavelan_watchdog() and wavelan_open())
  1135.  */
  1136. static inline void
  1137. wv_hw_reset(device * dev)
  1138. {
  1139.   net_local * lp = (net_local *) dev->priv;
  1140. #ifdef DEBUG_CONFIG_TRACE
  1141.   printk(KERN_DEBUG "%s: ->wv_hw_reset()n", dev->name);
  1142. #endif
  1143.   lp->nresets++;
  1144.   lp->configured = 0;
  1145.   
  1146.   /* Call wv_hw_config() for most of the reset & init stuff */
  1147.   if(wv_hw_config(dev) == FALSE)
  1148.     return;
  1149.   /* start receive unit */
  1150.   wv_ru_start(dev);
  1151. #ifdef DEBUG_CONFIG_TRACE
  1152.   printk(KERN_DEBUG "%s: <-wv_hw_reset()n", dev->name);
  1153. #endif
  1154. }
  1155. /*------------------------------------------------------------------*/
  1156. /*
  1157.  * wv_pcmcia_config() is called after a CARD_INSERTION event is
  1158.  * received, to configure the PCMCIA socket, and to make the ethernet
  1159.  * device available to the system.
  1160.  * (called by wavelan_event())
  1161.  */
  1162. static inline int
  1163. wv_pcmcia_config(dev_link_t * link)
  1164. {
  1165.   client_handle_t handle;
  1166.   tuple_t tuple;
  1167.   cisparse_t parse;
  1168.   struct net_device * dev;
  1169.   int i;
  1170.   u_char buf[64];
  1171.   win_req_t req;
  1172.   memreq_t mem;
  1173.   handle = link->handle;
  1174.   dev = (device *) link->priv;
  1175. #ifdef DEBUG_CONFIG_TRACE
  1176.   printk(KERN_DEBUG "->wv_pcmcia_config(0x%p)n", link);
  1177. #endif
  1178.   /*
  1179.    * This reads the card's CONFIG tuple to find its configuration
  1180.    * registers.
  1181.    */
  1182.   do
  1183.     {
  1184.       tuple.Attributes = 0;
  1185.       tuple.DesiredTuple = CISTPL_CONFIG;
  1186.       i = CardServices(GetFirstTuple, handle, &tuple);
  1187.       if(i != CS_SUCCESS)
  1188. break;
  1189.       tuple.TupleData = (cisdata_t *)buf;
  1190.       tuple.TupleDataMax = 64;
  1191.       tuple.TupleOffset = 0;
  1192.       i = CardServices(GetTupleData, handle, &tuple);
  1193.       if(i != CS_SUCCESS)
  1194. break;
  1195.       i = CardServices(ParseTuple, handle, &tuple, &parse);
  1196.       if(i != CS_SUCCESS)
  1197. break;
  1198.       link->conf.ConfigBase = parse.config.base;
  1199.       link->conf.Present = parse.config.rmask[0];
  1200.     }
  1201.   while(0);
  1202.   if(i != CS_SUCCESS)
  1203.     {
  1204.       cs_error(link->handle, ParseTuple, i);
  1205.       link->state &= ~DEV_CONFIG_PENDING;
  1206.       return FALSE;
  1207.     }
  1208.     
  1209.   /* Configure card */
  1210.   link->state |= DEV_CONFIG;
  1211.   do
  1212.     {
  1213.       i = CardServices(RequestIO, link->handle, &link->io);
  1214.       if(i != CS_SUCCESS)
  1215. {
  1216.   cs_error(link->handle, RequestIO, i);
  1217.   break;
  1218. }
  1219.       /*
  1220.        * Now allocate an interrupt line.  Note that this does not
  1221.        * actually assign a handler to the interrupt.
  1222.        */
  1223.       i = CardServices(RequestIRQ, link->handle, &link->irq);
  1224.       if(i != CS_SUCCESS)
  1225. {
  1226.   cs_error(link->handle, RequestIRQ, i);
  1227.   break;
  1228. }
  1229.       /*
  1230.        * This actually configures the PCMCIA socket -- setting up
  1231.        * the I/O windows and the interrupt mapping.
  1232.        */
  1233.       link->conf.ConfigIndex = 1;
  1234.       i = CardServices(RequestConfiguration, link->handle, &link->conf);
  1235.       if(i != CS_SUCCESS)
  1236. {
  1237.   cs_error(link->handle, RequestConfiguration, i);
  1238.   break;
  1239. }
  1240.       /*
  1241.        * Allocate a small memory window.  Note that the dev_link_t
  1242.        * structure provides space for one window handle -- if your
  1243.        * device needs several windows, you'll need to keep track of
  1244.        * the handles in your private data structure, link->priv.
  1245.        */
  1246.       req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
  1247.       req.Base = req.Size = 0;
  1248.       req.AccessSpeed = mem_speed;
  1249.       link->win = (window_handle_t)link->handle;
  1250.       i = CardServices(RequestWindow, &link->win, &req);
  1251.       if(i != CS_SUCCESS)
  1252. {
  1253.   cs_error(link->handle, RequestWindow, i);
  1254.   break;
  1255. }
  1256.       dev->rmem_start = dev->mem_start =
  1257.   (u_long)ioremap(req.Base, req.Size);
  1258.       dev->rmem_end = dev->mem_end = dev->mem_start + req.Size;
  1259.       mem.CardOffset = 0; mem.Page = 0;
  1260.       i = CardServices(MapMemPage, link->win, &mem);
  1261.       if(i != CS_SUCCESS)
  1262. {
  1263.   cs_error(link->handle, MapMemPage, i);
  1264.   break;
  1265. }
  1266.       /* Feed device with this info... */
  1267.       dev->irq = link->irq.AssignedIRQ;
  1268.       dev->base_addr = link->io.BasePort1;
  1269.       netif_start_queue(dev);
  1270. #ifdef DEBUG_CONFIG_INFO
  1271.       printk(KERN_DEBUG "wv_pcmcia_config: MEMSTART 0x%x IRQ %d IOPORT 0x%xn",
  1272.      (u_int) dev->mem_start, dev->irq, (u_int) dev->base_addr);
  1273. #endif
  1274.       i = register_netdev(dev);
  1275.       if(i != 0)
  1276. {
  1277. #ifdef DEBUG_CONFIG_ERRORS
  1278.   printk(KERN_INFO "wv_pcmcia_config(): register_netdev() failedn");
  1279. #endif
  1280.   break;
  1281. }
  1282.     }
  1283.   while(0); /* Humm... Disguised goto !!! */
  1284.   link->state &= ~DEV_CONFIG_PENDING;
  1285.   /* If any step failed, release any partially configured state */
  1286.   if(i != 0)
  1287.     {
  1288.       wv_pcmcia_release((u_long) link);
  1289.       return FALSE;
  1290.     }
  1291.   strcpy(((net_local *) dev->priv)->node.dev_name, dev->name);
  1292.   link->dev = &((net_local *) dev->priv)->node;
  1293. #ifdef DEBUG_CONFIG_TRACE
  1294.   printk(KERN_DEBUG "<-wv_pcmcia_config()n");
  1295. #endif
  1296.   return TRUE;
  1297. }
  1298. /*------------------------------------------------------------------*/
  1299. /*
  1300.  * After a card is removed, wv_pcmcia_release() will unregister the net
  1301.  * device, and release the PCMCIA configuration.  If the device is
  1302.  * still open, this will be postponed until it is closed.
  1303.  */
  1304. static void
  1305. wv_pcmcia_release(u_long arg) /* Address of the interface struct */
  1306. {
  1307.   dev_link_t * link = (dev_link_t *) arg;
  1308.   device * dev = (device *) link->priv;
  1309. #ifdef DEBUG_CONFIG_TRACE
  1310.   printk(KERN_DEBUG "%s: -> wv_pcmcia_release(0x%p)n", dev->name, link);
  1311. #endif
  1312.   /* If the device is currently in use, we won't release until it is
  1313.    * actually closed. */
  1314.   if(link->open)
  1315.     {
  1316. #ifdef DEBUG_CONFIG_INFO
  1317.       printk(KERN_DEBUG "%s: wv_pcmcia_release: release postponed, device still openn",
  1318.      dev->name);
  1319. #endif
  1320.       link->state |= DEV_STALE_CONFIG;
  1321.       return;
  1322.     }
  1323.   /* Don't bother checking to see if these succeed or not */
  1324.   iounmap((u_char *)dev->mem_start);
  1325.   CardServices(ReleaseWindow, link->win);
  1326.   CardServices(ReleaseConfiguration, link->handle);
  1327.   CardServices(ReleaseIO, link->handle, &link->io);
  1328.   CardServices(ReleaseIRQ, link->handle, &link->irq);
  1329.   link->state &= ~(DEV_CONFIG | DEV_STALE_CONFIG);
  1330. #ifdef DEBUG_CONFIG_TRACE
  1331.   printk(KERN_DEBUG "%s: <- wv_pcmcia_release()n", dev->name);
  1332. #endif
  1333. } /* wv_pcmcia_release */
  1334. /*------------------------------------------------------------------*/
  1335. /*
  1336.  * Sometimes, wavelan_detach can't be performed following a call from
  1337.  * cardmgr (device still open, pcmcia_release not done) and the device
  1338.  * is put in a STALE_LINK state and remains in memory.
  1339.  *
  1340.  * This function run through our current list of device and attempt
  1341.  * another time to remove them. We hope that since last time the
  1342.  * device has properly been closed.
  1343.  *
  1344.  * (called by wavelan_attach() & cleanup_module())
  1345.  */
  1346. static void
  1347. wv_flush_stale_links(void)
  1348. {
  1349.   dev_link_t * link; /* Current node in linked list */
  1350.   dev_link_t * next; /* Next node in linked list */
  1351. #ifdef DEBUG_CONFIG_TRACE
  1352.   printk(KERN_DEBUG "-> wv_flush_stale_links(0x%p)n", dev_list);
  1353. #endif
  1354.   /* Go through the list */
  1355.   for (link = dev_list; link; link = next)
  1356.     {
  1357.       next = link->next;
  1358.       /* Check if in need of being removed */
  1359.       if((link->state & DEV_STALE_LINK) ||
  1360.  (! (link->state & DEV_PRESENT)))
  1361. wavelan_detach(link);
  1362.     }
  1363. #ifdef DEBUG_CONFIG_TRACE
  1364.   printk(KERN_DEBUG "<- wv_flush_stale_links()n");
  1365. #endif
  1366. }
  1367. /************************ INTERRUPT HANDLING ************************/
  1368. /*
  1369.  * This function is the interrupt handler for the WaveLAN card. This
  1370.  * routine will be called whenever: 
  1371.  * 1. A packet is received.
  1372.  * 2. A packet has successfully been transferred and the unit is
  1373.  *    ready to transmit another packet.
  1374.  * 3. A command has completed execution.
  1375.  */
  1376. static void
  1377. wavelan_interrupt(int irq,
  1378.   void * dev_id,
  1379.   struct pt_regs * regs)
  1380. {
  1381.   device * dev;
  1382.   net_local * lp;
  1383.   ioaddr_t base;
  1384.   int status0;
  1385.   u_int tx_status;
  1386.   if((dev = (device *)dev_id) == (device *) NULL)
  1387.     {
  1388. #ifdef DEBUG_INTERRUPT_ERROR
  1389.       printk(KERN_WARNING "wavelan_interrupt(): irq %d for unknown device.n",
  1390.      irq);
  1391. #endif
  1392.       return;
  1393.     }
  1394. #ifdef DEBUG_INTERRUPT_TRACE
  1395.   printk(KERN_DEBUG "%s: ->wavelan_interrupt()n", dev->name);
  1396. #endif
  1397.   lp = (net_local *) dev->priv;
  1398.   base = dev->base_addr;
  1399. #ifdef DEBUG_INTERRUPT_INFO
  1400.   /* Check state of our spinlock (it should be cleared) */
  1401.   if(spin_is_locked(&lp->spinlock))
  1402.     printk(KERN_DEBUG
  1403.    "%s: wavelan_interrupt(): spinlock is already locked !!!n",
  1404.    dev->name);
  1405. #endif
  1406.   /* Prevent reentrancy. We need to do that because we may have
  1407.    * multiple interrupt handler running concurently.
  1408.    * It is safe because wv_splhi() disable interrupts before aquiring
  1409.    * the spinlock. */
  1410.   spin_lock(&lp->spinlock);
  1411.   /* Treat all pending interrupts */
  1412.   while(1)
  1413.     {
  1414.       /* ---------------- INTERRUPT CHECKING ---------------- */
  1415.       /*
  1416.        * Look for the interrupt and verify the validity
  1417.        */
  1418.       outb(CR0_STATUS_0 | OP0_NOP, LCCR(base));
  1419.       status0 = inb(LCSR(base));
  1420. #ifdef DEBUG_INTERRUPT_INFO
  1421.       printk(KERN_DEBUG "status0 0x%x [%s => 0x%x]", status0, 
  1422.      (status0&SR0_INTERRUPT)?"int":"no int",status0&~SR0_INTERRUPT);
  1423.       if(status0&SR0_INTERRUPT)
  1424. {
  1425.   printk(" [%s => %d]n", (status0 & SR0_CHNL) ? "chnl" :
  1426.  ((status0 & SR0_EXECUTION) ? "cmd" :
  1427.   ((status0 & SR0_RECEPTION) ? "recv" : "unknown")),
  1428.  (status0 & SR0_EVENT_MASK));
  1429. }
  1430.       else
  1431. printk("n");
  1432. #endif
  1433.       /* Return if no actual interrupt from i82593 (normal exit) */
  1434.       if(!(status0 & SR0_INTERRUPT))
  1435. break;
  1436.       /* If interrupt is both Rx and Tx or none...
  1437.        * This code in fact is there to catch the spurious interrupt
  1438.        * when you remove the wavelan pcmcia card from the socket */
  1439.       if(((status0 & SR0_BOTH_RX_TX) == SR0_BOTH_RX_TX) ||
  1440.  ((status0 & SR0_BOTH_RX_TX) == 0x0))
  1441. {
  1442. #ifdef DEBUG_INTERRUPT_INFO
  1443.   printk(KERN_INFO "%s: wv_interrupt(): bogus interrupt (or from dead card) : %Xn",
  1444.  dev->name, status0);
  1445. #endif
  1446.   /* Acknowledge the interrupt */
  1447.   outb(CR0_INT_ACK | OP0_NOP, LCCR(base));
  1448.   break;
  1449. }
  1450.       /* ----------------- RECEIVING PACKET ----------------- */
  1451.       /*
  1452.        * When the wavelan signal the reception of a new packet,
  1453.        * we call wv_packet_rcv() to copy if from the buffer and
  1454.        * send it to NET3
  1455.        */
  1456.       if(status0 & SR0_RECEPTION)
  1457. {
  1458. #ifdef DEBUG_INTERRUPT_INFO
  1459.   printk(KERN_DEBUG "%s: wv_interrupt(): receiven", dev->name);
  1460. #endif
  1461.   if((status0 & SR0_EVENT_MASK) == SR0_STOP_REG_HIT)
  1462.     {
  1463. #ifdef DEBUG_INTERRUPT_ERROR
  1464.       printk(KERN_INFO "%s: wv_interrupt(): receive buffer overflown",
  1465.      dev->name);
  1466. #endif
  1467.       lp->stats.rx_over_errors++;
  1468.       lp->overrunning = 1;
  1469.            }
  1470.   /* Get the packet */
  1471.   wv_packet_rcv(dev);
  1472.   lp->overrunning = 0;
  1473.   /* Acknowledge the interrupt */
  1474.   outb(CR0_INT_ACK | OP0_NOP, LCCR(base));
  1475.   continue;
  1476.      }
  1477.       /* ---------------- COMMAND COMPLETION ---------------- */
  1478.       /*
  1479.        * Interrupts issued when the i82593 has completed a command.
  1480.        * Most likely : transmission done
  1481.        */
  1482.       /* If a transmission has been done */
  1483.       if((status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_DONE ||
  1484.  (status0 & SR0_EVENT_MASK) == SR0_RETRANSMIT_DONE ||
  1485.  (status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_NO_CRC_DONE)
  1486. {
  1487. #ifdef DEBUG_TX_ERROR
  1488.   if((status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_NO_CRC_DONE)
  1489.     printk(KERN_INFO "%s: wv_interrupt(): packet transmitted without CRC.n",
  1490.    dev->name);
  1491. #endif
  1492.   /* Get transmission status */
  1493.   tx_status = inb(LCSR(base));
  1494.   tx_status |= (inb(LCSR(base)) << 8);
  1495. #ifdef DEBUG_INTERRUPT_INFO
  1496.   printk(KERN_DEBUG "%s: wv_interrupt(): transmission donen",
  1497.  dev->name);
  1498.   {
  1499.     u_int rcv_bytes;
  1500.     u_char status3;
  1501.     rcv_bytes = inb(LCSR(base));
  1502.     rcv_bytes |= (inb(LCSR(base)) << 8);
  1503.     status3 = inb(LCSR(base));
  1504.     printk(KERN_DEBUG "tx_status 0x%02x rcv_bytes 0x%02x status3 0x%xn",
  1505.    tx_status, rcv_bytes, (u_int) status3);
  1506.   }
  1507. #endif
  1508.   /* Check for possible errors */
  1509.   if((tx_status & TX_OK) != TX_OK)
  1510.     {
  1511.       lp->stats.tx_errors++;
  1512.       if(tx_status & TX_FRTL)
  1513. {
  1514. #ifdef DEBUG_TX_ERROR
  1515.   printk(KERN_INFO "%s: wv_interrupt(): frame too longn",
  1516.  dev->name);
  1517. #endif
  1518. }
  1519.       if(tx_status & TX_UND_RUN)
  1520. {
  1521. #ifdef DEBUG_TX_FAIL
  1522.   printk(KERN_DEBUG "%s: wv_interrupt(): DMA underrunn",
  1523.  dev->name);
  1524. #endif
  1525.   lp->stats.tx_aborted_errors++;
  1526. }
  1527.       if(tx_status & TX_LOST_CTS)
  1528. {
  1529. #ifdef DEBUG_TX_FAIL
  1530.   printk(KERN_DEBUG "%s: wv_interrupt(): no CTSn", dev->name);
  1531. #endif
  1532.   lp->stats.tx_carrier_errors++;
  1533. }
  1534.       if(tx_status & TX_LOST_CRS)
  1535. {
  1536. #ifdef DEBUG_TX_FAIL
  1537.   printk(KERN_DEBUG "%s: wv_interrupt(): no carriern",
  1538.  dev->name);
  1539. #endif
  1540.   lp->stats.tx_carrier_errors++;
  1541. }
  1542.       if(tx_status & TX_HRT_BEAT)
  1543. {
  1544. #ifdef DEBUG_TX_FAIL
  1545.   printk(KERN_DEBUG "%s: wv_interrupt(): heart beatn", dev->name);
  1546. #endif
  1547.   lp->stats.tx_heartbeat_errors++;
  1548. }
  1549.       if(tx_status & TX_DEFER)
  1550. {
  1551. #ifdef DEBUG_TX_FAIL
  1552.   printk(KERN_DEBUG "%s: wv_interrupt(): channel jammedn",
  1553.  dev->name);
  1554. #endif
  1555. }
  1556.       /* Ignore late collisions since they're more likely to happen
  1557.        * here (the WaveLAN design prevents the LAN controller from
  1558.        * receiving while it is transmitting). We take action only when
  1559.        * the maximum retransmit attempts is exceeded.
  1560.        */
  1561.       if(tx_status & TX_COLL)
  1562. {
  1563.   if(tx_status & TX_MAX_COL)
  1564.     {
  1565. #ifdef DEBUG_TX_FAIL
  1566.       printk(KERN_DEBUG "%s: wv_interrupt(): channel congestionn",
  1567.      dev->name);
  1568. #endif
  1569.       if(!(tx_status & TX_NCOL_MASK))
  1570. {
  1571.   lp->stats.collisions += 0x10;
  1572. }
  1573.     }
  1574. }
  1575.     } /* if(!(tx_status & TX_OK)) */
  1576.   lp->stats.collisions += (tx_status & TX_NCOL_MASK);
  1577.   lp->stats.tx_packets++;
  1578.   netif_wake_queue(dev);
  1579.   outb(CR0_INT_ACK | OP0_NOP, LCCR(base)); /* Acknowledge the interrupt */
  1580.      } 
  1581.       else /* if interrupt = transmit done or retransmit done */
  1582. {
  1583. #ifdef DEBUG_INTERRUPT_ERROR
  1584.   printk(KERN_INFO "wavelan_cs: unknown interrupt, status0 = %02xn",
  1585.  status0);
  1586. #endif
  1587.   outb(CR0_INT_ACK | OP0_NOP, LCCR(base)); /* Acknowledge the interrupt */
  1588.      }
  1589.     } /* while(1) */
  1590.   spin_unlock(&lp->spinlock);
  1591. #ifdef DEBUG_INTERRUPT_TRACE
  1592.   printk(KERN_DEBUG "%s: <-wavelan_interrupt()n", dev->name);
  1593. #endif
  1594. } /* wv_interrupt */
  1595. /*------------------------------------------------------------------*/
  1596. /*
  1597.  * Watchdog: when we start a transmission, a timer is set for us in the
  1598.  * kernel.  If the transmission completes, this timer is disabled. If
  1599.  * the timer expires, we are called and we try to unlock the hardware.
  1600.  *
  1601.  * Note : This watchdog is move clever than the one in the ISA driver,
  1602.  * because it try to abort the current command before reseting
  1603.  * everything...
  1604.  * On the other hand, it's a bit simpler, because we don't have to
  1605.  * deal with the multiple Tx buffers...
  1606.  */
  1607. static void
  1608. wavelan_watchdog(device * dev)
  1609. {
  1610.   net_local * lp = (net_local *) dev->priv;
  1611.   ioaddr_t base = dev->base_addr;
  1612.   unsigned long flags;
  1613.   int aborted = FALSE;
  1614. #ifdef DEBUG_INTERRUPT_TRACE
  1615.   printk(KERN_DEBUG "%s: ->wavelan_watchdog()n", dev->name);
  1616. #endif
  1617. #ifdef DEBUG_INTERRUPT_ERROR
  1618.   printk(KERN_INFO "%s: wavelan_watchdog: watchdog timer expiredn",
  1619.  dev->name);
  1620. #endif
  1621.   wv_splhi(lp, &flags);
  1622.   /* Ask to abort the current command */
  1623.   outb(OP0_ABORT, LCCR(base));
  1624.   /* Wait for the end of the command (a bit hackish) */
  1625.   if(wv_82593_cmd(dev, "wavelan_watchdog(): abort",
  1626.   OP0_NOP | CR0_STATUS_3, SR0_EXECUTION_ABORTED))
  1627.     aborted = TRUE;
  1628.   /* Release spinlock here so that wv_hw_reset() can grab it */
  1629.   wv_splx(lp, &flags);
  1630.   /* Check if we were successful in aborting it */
  1631.   if(!aborted)
  1632.     {
  1633.       /* It seem that it wasn't enough */
  1634. #ifdef DEBUG_INTERRUPT_ERROR
  1635.       printk(KERN_INFO "%s: wavelan_watchdog: abort failed, trying resetn",
  1636.      dev->name);
  1637. #endif
  1638.       wv_hw_reset(dev);
  1639.     }
  1640. #ifdef DEBUG_PSA_SHOW
  1641.   {
  1642.     psa_t psa;
  1643.     psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
  1644.     wv_psa_show(&psa);
  1645.   }
  1646. #endif
  1647. #ifdef DEBUG_MMC_SHOW
  1648.   wv_mmc_show(dev);
  1649. #endif
  1650. #ifdef DEBUG_I82593_SHOW
  1651.   wv_ru_show(dev);
  1652. #endif
  1653.   /* We are no more waiting for something... */
  1654.   netif_wake_queue(dev);
  1655. #ifdef DEBUG_INTERRUPT_TRACE
  1656.   printk(KERN_DEBUG "%s: <-wavelan_watchdog()n", dev->name);
  1657. #endif
  1658. }
  1659. /********************* CONFIGURATION CALLBACKS *********************/
  1660. /*
  1661.  * Here are the functions called by the pcmcia package (cardmgr) and
  1662.  * linux networking (NET3) for initialization, configuration and
  1663.  * deinstallations of the Wavelan Pcmcia Hardware.
  1664.  */
  1665. /*------------------------------------------------------------------*/
  1666. /*
  1667.  * Configure and start up the WaveLAN PCMCIA adaptor.
  1668.  * Called by NET3 when it "open" the device.
  1669.  */
  1670. static int
  1671. wavelan_open(device * dev)
  1672. {
  1673.   dev_link_t * link = ((net_local *) dev->priv)->link;
  1674.   net_local * lp = (net_local *)dev->priv;
  1675.   ioaddr_t base = dev->base_addr;
  1676. #ifdef DEBUG_CALLBACK_TRACE
  1677.   printk(KERN_DEBUG "%s: ->wavelan_open(dev=0x%x)n", dev->name,
  1678.  (unsigned int) dev);
  1679. #endif
  1680.   /* Check if the modem is powered up (wavelan_close() power it down */
  1681.   if(hasr_read(base) & HASR_NO_CLK)
  1682.     {
  1683.       /* Power up (power up time is 250us) */
  1684.       hacr_write(base, HACR_DEFAULT);
  1685.       /* Check if the module has been powered up... */
  1686.       if(hasr_read(base) & HASR_NO_CLK)
  1687. {
  1688. #ifdef DEBUG_CONFIG_ERRORS
  1689.   printk(KERN_WARNING "%s: wavelan_open(): modem not connectedn",
  1690.  dev->name);
  1691. #endif
  1692.   return FALSE;
  1693. }
  1694.     }
  1695.   /* Start reception and declare the driver ready */
  1696.   if(!lp->configured)
  1697.     return FALSE;
  1698.   if(!wv_ru_start(dev))
  1699.     wv_hw_reset(dev); /* If problem : reset */
  1700.   netif_start_queue(dev);
  1701.   /* Mark the device as used */
  1702.   link->open++;
  1703.   MOD_INC_USE_COUNT;
  1704. #ifdef WAVELAN_ROAMING
  1705.   if(do_roaming)
  1706.     wv_roam_init(dev);
  1707. #endif /* WAVELAN_ROAMING */
  1708. #ifdef DEBUG_CALLBACK_TRACE
  1709.   printk(KERN_DEBUG "%s: <-wavelan_open()n", dev->name);
  1710. #endif
  1711.   return 0;
  1712. }
  1713. /*------------------------------------------------------------------*/
  1714. /*
  1715.  * Shutdown the WaveLAN PCMCIA adaptor.
  1716.  * Called by NET3 when it "close" the device.
  1717.  */
  1718. static int
  1719. wavelan_close(device * dev)
  1720. {
  1721.   dev_link_t * link = ((net_local *) dev->priv)->link;
  1722.   ioaddr_t base = dev->base_addr;
  1723. #ifdef DEBUG_CALLBACK_TRACE
  1724.   printk(KERN_DEBUG "%s: ->wavelan_close(dev=0x%x)n", dev->name,
  1725.  (unsigned int) dev);
  1726. #endif
  1727.   /* If the device isn't open, then nothing to do */
  1728.   if(!link->open)
  1729.     {
  1730. #ifdef DEBUG_CONFIG_INFO
  1731.       printk(KERN_DEBUG "%s: wavelan_close(): device not openn", dev->name);
  1732. #endif
  1733.       return 0;
  1734.     }
  1735. #ifdef WAVELAN_ROAMING
  1736.   /* Cleanup of roaming stuff... */
  1737.   if(do_roaming)
  1738.     wv_roam_cleanup(dev);
  1739. #endif /* WAVELAN_ROAMING */
  1740.   link->open--;
  1741.   MOD_DEC_USE_COUNT;
  1742.   /* If the card is still present */
  1743.   if(netif_running(dev))
  1744.     {
  1745.       netif_stop_queue(dev);
  1746.       /* Stop receiving new messages and wait end of transmission */
  1747.       wv_ru_stop(dev);
  1748.       /* Power down the module */
  1749.       hacr_write(base, HACR_DEFAULT & (~HACR_PWR_STAT));
  1750.     }
  1751.   else
  1752.     /* The card is no more there (flag is activated in wv_pcmcia_release) */
  1753.     if(link->state & DEV_STALE_CONFIG)
  1754.       wv_pcmcia_release((u_long)link);
  1755. #ifdef DEBUG_CALLBACK_TRACE
  1756.   printk(KERN_DEBUG "%s: <-wavelan_close()n", dev->name);
  1757. #endif
  1758.   return 0;
  1759. }
  1760. /*------------------------------------------------------------------*/
  1761. /*
  1762.  * wavelan_attach() creates an "instance" of the driver, allocating
  1763.  * local data structures for one device (one interface).  The device
  1764.  * is registered with Card Services.
  1765.  *
  1766.  * The dev_link structure is initialized, but we don't actually
  1767.  * configure the card at this point -- we wait until we receive a
  1768.  * card insertion event.
  1769.  */
  1770. static dev_link_t *
  1771. wavelan_attach(void)
  1772. {
  1773.   client_reg_t client_reg; /* Register with cardmgr */
  1774.   dev_link_t * link; /* Info for cardmgr */
  1775.   device * dev; /* Interface generic data */
  1776.   net_local * lp; /* Interface specific data */
  1777.   int i, ret;
  1778. #ifdef DEBUG_CALLBACK_TRACE
  1779.   printk(KERN_DEBUG "-> wavelan_attach()n");
  1780. #endif
  1781.   /* Perform some cleanup */
  1782.   wv_flush_stale_links();
  1783.   /* Initialize the dev_link_t structure */
  1784.   link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
  1785.   if (!link) return NULL;
  1786.   memset(link, 0, sizeof(struct dev_link_t));
  1787.   /* Unused for the Wavelan */
  1788.   link->release.function = &wv_pcmcia_release;
  1789.   link->release.data = (u_long) link;
  1790.   /* The io structure describes IO port mapping */
  1791.   link->io.NumPorts1 = 8;
  1792.   link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
  1793.   link->io.IOAddrLines = 3;
  1794.   /* Interrupt setup */
  1795.   link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
  1796.   link->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_LEVEL_ID;
  1797.   if (irq_list[0] == -1)
  1798.     link->irq.IRQInfo2 = irq_mask;
  1799.   else
  1800.     for (i = 0; i < 4; i++)
  1801.       link->irq.IRQInfo2 |= 1 << irq_list[i];
  1802.   link->irq.Handler = wavelan_interrupt;
  1803.   /* General socket configuration */
  1804.   link->conf.Attributes = CONF_ENABLE_IRQ;
  1805.   link->conf.Vcc = 50;
  1806.   link->conf.IntType = INT_MEMORY_AND_IO;
  1807.   /* Chain drivers */
  1808.   link->next = dev_list;
  1809.   dev_list = link;
  1810.   /* Allocate the generic data structure */
  1811.   dev = kmalloc(sizeof(struct net_device), GFP_KERNEL);
  1812.   if (!dev) {
  1813.       kfree(link);
  1814.       return NULL;
  1815.   }
  1816.   memset(dev, 0x00, sizeof(struct net_device));
  1817.   link->priv = link->irq.Instance = dev;
  1818.   /* Allocate the wavelan-specific data structure. */
  1819.   dev->priv = lp = (net_local *) kmalloc(sizeof(net_local), GFP_KERNEL);
  1820.   if (!lp) {
  1821.       kfree(link);
  1822.       kfree(dev);
  1823.       return NULL;
  1824.   }
  1825.   memset(lp, 0x00, sizeof(net_local));
  1826.   /* Init specific data */
  1827.   lp->configured = 0;
  1828.   lp->reconfig_82593 = FALSE;
  1829.   lp->nresets = 0;
  1830.   /* Multicast stuff */
  1831.   lp->promiscuous = 0;
  1832.   lp->allmulticast = 0;
  1833.   lp->mc_count = 0;
  1834.   /* Init spinlock */
  1835.   spin_lock_init(&lp->spinlock);
  1836.   /* back links */
  1837.   lp->link = link;
  1838.   lp->dev = dev;
  1839.   /* Standard setup for generic data */
  1840.   ether_setup(dev);
  1841.   /* wavelan NET3 callbacks */
  1842.   dev->open = &wavelan_open;
  1843.   dev->stop = &wavelan_close;
  1844.   dev->hard_start_xmit = &wavelan_packet_xmit;
  1845.   dev->get_stats = &wavelan_get_stats;
  1846.   dev->set_multicast_list = &wavelan_set_multicast_list;
  1847. #ifdef SET_MAC_ADDRESS
  1848.   dev->set_mac_address = &wavelan_set_mac_address;
  1849. #endif /* SET_MAC_ADDRESS */
  1850.   /* Set the watchdog timer */
  1851.   dev->tx_timeout = &wavelan_watchdog;
  1852.   dev->watchdog_timeo = WATCHDOG_JIFFIES;
  1853. #ifdef WIRELESS_EXT /* If wireless extension exist in the kernel */
  1854.   dev->do_ioctl = wavelan_ioctl; /* wireless extensions */
  1855.   dev->get_wireless_stats = wavelan_get_wireless_stats;
  1856. #endif
  1857.   /* Other specific data */
  1858.   dev->mtu = WAVELAN_MTU;
  1859.   /* Register with Card Services */
  1860.   client_reg.dev_info = &dev_info;
  1861.   client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
  1862.   client_reg.EventMask = 
  1863.     CS_EVENT_REGISTRATION_COMPLETE |
  1864.     CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
  1865.     CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
  1866.     CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
  1867.   client_reg.event_handler = &wavelan_event;
  1868.   client_reg.Version = 0x0210;
  1869.   client_reg.event_callback_args.client_data = link;
  1870. #ifdef DEBUG_CONFIG_INFO
  1871.   printk(KERN_DEBUG "wavelan_attach(): almost done, calling CardServicesn");
  1872. #endif
  1873.   ret = CardServices(RegisterClient, &link->handle, &client_reg);
  1874.   if(ret != 0)
  1875.     {
  1876.       cs_error(link->handle, RegisterClient, ret);
  1877.       wavelan_detach(link);
  1878.       return NULL;
  1879.     }
  1880. #ifdef DEBUG_CALLBACK_TRACE
  1881.   printk(KERN_DEBUG "<- wavelan_attach()n");
  1882. #endif
  1883.   return link;
  1884. }
  1885. /*------------------------------------------------------------------*/
  1886. /*
  1887.  * This deletes a driver "instance".  The device is de-registered with
  1888.  * Card Services.  If it has been released, all local data structures
  1889.  * are freed.  Otherwise, the structures will be freed when the device
  1890.  * is released.
  1891.  */
  1892. static void
  1893. wavelan_detach(dev_link_t * link)
  1894. {
  1895. #ifdef DEBUG_CALLBACK_TRACE
  1896.   printk(KERN_DEBUG "-> wavelan_detach(0x%p)n", link);
  1897. #endif
  1898.   /*
  1899.    * If the device is currently configured and active, we won't
  1900.    * actually delete it yet.  Instead, it is marked so that when the
  1901.    * release() function is called, that will trigger a proper
  1902.    * detach().
  1903.    */
  1904.   if(link->state & DEV_CONFIG)
  1905.     {
  1906.       /* Some others haven't done their job : give them another chance */
  1907.       wv_pcmcia_release((u_long) link);
  1908.       if(link->state & DEV_STALE_CONFIG)
  1909. {
  1910. #ifdef DEBUG_CONFIG_INFO
  1911.   printk(KERN_DEBUG "wavelan_detach: detach postponed,"
  1912.  " '%s' still lockedn", link->dev->dev_name);
  1913. #endif
  1914.   link->state |= DEV_STALE_LINK;
  1915.   return;
  1916. }
  1917.     }
  1918.   /* Break the link with Card Services */
  1919.   if(link->handle)
  1920.     CardServices(DeregisterClient, link->handle);
  1921.     
  1922.   /* Remove the interface data from the linked list */
  1923.   if(dev_list == link)
  1924.     dev_list = link->next;
  1925.   else
  1926.     {
  1927.       dev_link_t * prev = dev_list;
  1928.       while((prev != (dev_link_t *) NULL) && (prev->next != link))
  1929. prev = prev->next;
  1930.       if(prev == (dev_link_t *) NULL)
  1931. {
  1932. #ifdef DEBUG_CONFIG_ERRORS
  1933.   printk(KERN_WARNING "wavelan_detach : Attempting to remove a nonexistent device.n");
  1934. #endif
  1935.   return;
  1936. }
  1937.       prev->next = link->next;
  1938.     }
  1939.   /* Free pieces */
  1940.   if(link->priv)
  1941.     {
  1942.       device * dev = (device *) link->priv;
  1943.       /* Remove ourselves from the kernel list of ethernet devices */
  1944.       /* Warning : can't be called from interrupt, timer or wavelan_close() */
  1945.       if(link->dev != NULL)
  1946. unregister_netdev(dev);
  1947.       link->dev = NULL;
  1948.       if(dev->priv)
  1949. {
  1950.   /* Sound strange, but safe... */
  1951.   ((net_local *) dev->priv)->link = (dev_link_t *) NULL;
  1952.   ((net_local *) dev->priv)->dev = (device *) NULL;
  1953.   kfree(dev->priv);
  1954. }
  1955.       kfree(link->priv);
  1956.     }
  1957.   kfree(link);
  1958. #ifdef DEBUG_CALLBACK_TRACE
  1959.   printk(KERN_DEBUG "<- wavelan_detach()n");
  1960. #endif
  1961. }
  1962. /*------------------------------------------------------------------*/
  1963. /*
  1964.  * The card status event handler. Mostly, this schedules other stuff
  1965.  * to run after an event is received. A CARD_REMOVAL event also sets
  1966.  * some flags to discourage the net drivers from trying to talk to the
  1967.  * card any more.
  1968.  */
  1969. static int
  1970. wavelan_event(event_t event, /* The event received */
  1971.       int priority,
  1972.       event_callback_args_t * args)
  1973. {
  1974.   dev_link_t * link = (dev_link_t *) args->client_data;
  1975.   device * dev = (device *) link->priv;
  1976. #ifdef DEBUG_CALLBACK_TRACE
  1977.   printk(KERN_DEBUG "->wavelan_event(): %sn",
  1978.  ((event == CS_EVENT_REGISTRATION_COMPLETE)?"registration complete" :
  1979.   ((event == CS_EVENT_CARD_REMOVAL) ? "card removal" :
  1980.    ((event == CS_EVENT_CARD_INSERTION) ? "card insertion" :
  1981.     ((event == CS_EVENT_PM_SUSPEND) ? "pm suspend" :
  1982.      ((event == CS_EVENT_RESET_PHYSICAL) ? "physical reset" :
  1983.       ((event == CS_EVENT_PM_RESUME) ? "pm resume" :
  1984.        ((event == CS_EVENT_CARD_RESET) ? "card reset" :
  1985. "unknown"))))))));
  1986. #endif
  1987.     switch(event)
  1988.       {
  1989.       case CS_EVENT_REGISTRATION_COMPLETE:
  1990. #ifdef DEBUG_CONFIG_INFO
  1991. printk(KERN_DEBUG "wavelan_cs: registration completen");
  1992. #endif
  1993. break;
  1994.       case CS_EVENT_CARD_REMOVAL:
  1995. /* Oups ! The card is no more there */
  1996. link->state &= ~DEV_PRESENT;
  1997. if(link->state & DEV_CONFIG)
  1998.   {
  1999.     /* Accept no more transmissions */
  2000.     netif_device_detach(dev);
  2001.     /* Release the card */
  2002.     wv_pcmcia_release((u_long) link);
  2003.   }
  2004. break;
  2005.       case CS_EVENT_CARD_INSERTION:
  2006. /* Reset and configure the card */
  2007. link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
  2008. if(wv_pcmcia_config(link) &&
  2009.    wv_hw_config(dev))
  2010.   wv_init_info(dev);
  2011. else
  2012.   dev->irq = 0;
  2013. break;
  2014.       case CS_EVENT_PM_SUSPEND:
  2015. /* NB: wavelan_close will be called, but too late, so we are
  2016.  * obliged to close nicely the wavelan here. David, could you
  2017.  * close the device before suspending them ? And, by the way,
  2018.  * could you, on resume, add a "route add -net ..." after the
  2019.  * ifconfig up ? Thanks... */
  2020. /* Stop receiving new messages and wait end of transmission */
  2021. wv_ru_stop(dev);
  2022. /* Power down the module */
  2023. hacr_write(dev->base_addr, HACR_DEFAULT & (~HACR_PWR_STAT));
  2024. /* The card is now suspended */
  2025. link->state |= DEV_SUSPEND;
  2026. /* Fall through... */
  2027.       case CS_EVENT_RESET_PHYSICAL:
  2028.      if(link->state & DEV_CONFIG)
  2029.   {
  2030.            if(link->open)
  2031.       netif_device_detach(dev);
  2032.            CardServices(ReleaseConfiguration, link->handle);
  2033.   }
  2034. break;
  2035.       case CS_EVENT_PM_RESUME:
  2036. link->state &= ~DEV_SUSPEND;
  2037. /* Fall through... */
  2038.       case CS_EVENT_CARD_RESET:
  2039. if(link->state & DEV_CONFIG)
  2040.   {
  2041.            CardServices(RequestConfiguration, link->handle, &link->conf);
  2042.            if(link->open) /* If RESET -> True, If RESUME -> False ? */
  2043.       {
  2044. wv_hw_reset(dev);
  2045. netif_device_attach(dev);
  2046.       }
  2047.   }
  2048. break;
  2049.     }
  2050. #ifdef DEBUG_CALLBACK_TRACE
  2051.   printk(KERN_DEBUG "<-wavelan_event()n");
  2052. #endif
  2053.   return 0;
  2054. }
  2055. /****************************** MODULE ******************************/
  2056. /*
  2057.  * Module entry points : insertion & removal
  2058.  */
  2059. /*------------------------------------------------------------------*/
  2060. /*
  2061.  * Module insertion : initialisation of the module.
  2062.  * Register the card with cardmgr...
  2063.  */
  2064. static int __init
  2065. init_wavelan_cs(void)
  2066. {
  2067.   servinfo_t serv;
  2068. #ifdef DEBUG_MODULE_TRACE
  2069.   printk(KERN_DEBUG "-> init_wavelan_cs()n");
  2070. #ifdef DEBUG_VERSION_SHOW
  2071.   printk(KERN_DEBUG "%s", version);
  2072. #endif
  2073. #endif
  2074.   CardServices(GetCardServicesInfo, &serv);
  2075.   if(serv.Revision != CS_RELEASE_CODE)
  2076.     {
  2077. #ifdef DEBUG_CONFIG_ERRORS
  2078.       printk(KERN_WARNING "init_wavelan_cs: Card Services release does not match!n");
  2079. #endif
  2080.       return -1;
  2081.     }
  2082.   register_pccard_driver(&dev_info, &wavelan_attach, &wavelan_detach);
  2083. #ifdef DEBUG_MODULE_TRACE
  2084.   printk(KERN_DEBUG "<- init_wavelan_cs()n");
  2085. #endif
  2086.   return 0;
  2087. }
  2088. /*------------------------------------------------------------------*/
  2089. /*
  2090.  * Module removal
  2091.  */
  2092. static void __exit
  2093. exit_wavelan_cs(void)
  2094. {
  2095. #ifdef DEBUG_MODULE_TRACE
  2096.   printk(KERN_DEBUG "-> cleanup_module()n");
  2097. #endif
  2098. #ifdef DEBUG_BASIC_SHOW
  2099.   printk(KERN_NOTICE "wavelan_cs: unloadingn");
  2100. #endif
  2101.   /* Do some cleanup of the device list */
  2102.   wv_flush_stale_links();
  2103.   /* If there remain some devices... */
  2104. #ifdef DEBUG_CONFIG_ERRORS
  2105.   if(dev_list != NULL)
  2106.     {
  2107.       /* Honestly, if this happen we are in a deep s**t */
  2108.       printk(KERN_INFO "wavelan_cs: devices remaining when removing modulen");
  2109.       printk(KERN_INFO "Please flush your disks and reboot NOW !n");
  2110.     }
  2111. #endif
  2112.   unregister_pccard_driver(&dev_info);
  2113. #ifdef DEBUG_MODULE_TRACE
  2114.   printk(KERN_DEBUG "<- cleanup_module()n");
  2115. #endif
  2116. }
  2117. module_init(init_wavelan_cs);
  2118. module_exit(exit_wavelan_cs);
  2119. /* Note : Modules parameters are in wavelan_cs.h - Jean II */