wavelan_cs.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:137k
- /* Copy addresses from the lp structure */
- for(i = 0; i < lp->spy_number; i++)
- {
- memcpy(address[i].sa_data, lp->spy_address[i],
- WAVELAN_ADDR_SIZE);
- address[i].sa_family = ARPHRD_ETHER;
- }
- /* Copy addresses to the user buffer */
- if(copy_to_user(wrq->u.data.pointer, address,
- sizeof(struct sockaddr) * lp->spy_number))
- {
- ret = -EFAULT;
- break;
- }
- /* Copy stats to the user buffer (just after) */
- if(copy_to_user(wrq->u.data.pointer +
- (sizeof(struct sockaddr) * lp->spy_number),
- lp->spy_stat, sizeof(iw_qual) * lp->spy_number))
- {
- ret = -EFAULT;
- break;
- }
- /* Reset updated flags */
- for(i = 0; i < lp->spy_number; i++)
- lp->spy_stat[i].updated = 0x0;
- } /* if(pointer != NULL) */
- break;
- #endif /* WIRELESS_SPY */
- /* ------------------ PRIVATE IOCTL ------------------ */
- case SIOCSIPQTHR:
- if(!capable(CAP_NET_ADMIN))
- {
- ret = -EPERM;
- break;
- }
- psa.psa_quality_thr = *(wrq->u.name) & 0x0F;
- psa_write(dev, (char *)&psa.psa_quality_thr - (char *)&psa,
- (unsigned char *)&psa.psa_quality_thr, 1);
- /* update the Wavelan checksum */
- update_psa_checksum(dev);
- mmc_out(base, mmwoff(0, mmw_quality_thr), psa.psa_quality_thr);
- break;
- case SIOCGIPQTHR:
- psa_read(dev, (char *)&psa.psa_quality_thr - (char *)&psa,
- (unsigned char *)&psa.psa_quality_thr, 1);
- *(wrq->u.name) = psa.psa_quality_thr & 0x0F;
- break;
- #ifdef WAVELAN_ROAMING
- case SIOCSIPROAM:
- /* Note : should check if user == root */
- if(do_roaming && (*wrq->u.name)==0)
- wv_roam_cleanup(dev);
- else if(do_roaming==0 && (*wrq->u.name)!=0)
- wv_roam_init(dev);
- do_roaming = (*wrq->u.name);
-
- break;
- case SIOCGIPROAM:
- *(wrq->u.name) = do_roaming;
- break;
- #endif /* WAVELAN_ROAMING */
- #ifdef HISTOGRAM
- case SIOCSIPHISTO:
- /* Verif if the user is root */
- if(!capable(CAP_NET_ADMIN))
- {
- ret = -EPERM;
- }
- /* Check the number of intervals */
- if(wrq->u.data.length > 16)
- {
- ret = -E2BIG;
- break;
- }
- lp->his_number = wrq->u.data.length;
- /* If there is some addresses to copy */
- if(lp->his_number > 0)
- {
- /* Copy interval ranges to the driver */
- if(copy_from_user(lp->his_range, wrq->u.data.pointer,
- sizeof(char) * lp->his_number))
- {
- ret = -EFAULT;
- break;
- }
- /* Reset structure... */
- memset(lp->his_sum, 0x00, sizeof(long) * 16);
- }
- break;
- case SIOCGIPHISTO:
- /* Set the number of intervals */
- wrq->u.data.length = lp->his_number;
- /* Give back the distribution statistics */
- if((lp->his_number > 0) && (wrq->u.data.pointer != (caddr_t) 0))
- {
- /* Copy data to the user buffer */
- if(copy_to_user(wrq->u.data.pointer, lp->his_sum,
- sizeof(long) * lp->his_number))
- ret = -EFAULT;
- } /* if(pointer != NULL) */
- break;
- #endif /* HISTOGRAM */
- /* ------------------- OTHER IOCTL ------------------- */
- default:
- ret = -EOPNOTSUPP;
- }
- /* ReEnable interrupts & restore flags */
- wv_splx(lp, &flags);
- #ifdef DEBUG_IOCTL_TRACE
- printk(KERN_DEBUG "%s: <-wavelan_ioctl()n", dev->name);
- #endif
- return ret;
- }
- /*------------------------------------------------------------------*/
- /*
- * Get wireless statistics
- * Called by /proc/net/wireless...
- */
- static iw_stats *
- wavelan_get_wireless_stats(device * dev)
- {
- ioaddr_t base = dev->base_addr;
- net_local * lp = (net_local *) dev->priv;
- mmr_t m;
- iw_stats * wstats;
- unsigned long flags;
- #ifdef DEBUG_IOCTL_TRACE
- printk(KERN_DEBUG "%s: ->wavelan_get_wireless_stats()n", dev->name);
- #endif
- /* Disable interrupts & save flags */
- wv_splhi(lp, &flags);
- wstats = &lp->wstats;
- /* Get data from the mmc */
- mmc_out(base, mmwoff(0, mmw_freeze), 1);
- mmc_read(base, mmroff(0, mmr_dce_status), &m.mmr_dce_status, 1);
- mmc_read(base, mmroff(0, mmr_wrong_nwid_l), &m.mmr_wrong_nwid_l, 2);
- mmc_read(base, mmroff(0, mmr_thr_pre_set), &m.mmr_thr_pre_set, 4);
- mmc_out(base, mmwoff(0, mmw_freeze), 0);
- /* Copy data to wireless stuff */
- wstats->status = m.mmr_dce_status & MMR_DCE_STATUS;
- wstats->qual.qual = m.mmr_sgnl_qual & MMR_SGNL_QUAL;
- wstats->qual.level = m.mmr_signal_lvl & MMR_SIGNAL_LVL;
- wstats->qual.noise = m.mmr_silence_lvl & MMR_SILENCE_LVL;
- wstats->qual.updated = (((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 7) |
- ((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 6) |
- ((m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) >> 5));
- wstats->discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
- wstats->discard.code = 0L;
- wstats->discard.misc = 0L;
- /* ReEnable interrupts & restore flags */
- wv_splx(lp, &flags);
- #ifdef DEBUG_IOCTL_TRACE
- printk(KERN_DEBUG "%s: <-wavelan_get_wireless_stats()n", dev->name);
- #endif
- return &lp->wstats;
- }
- #endif /* WIRELESS_EXT */
- /************************* PACKET RECEPTION *************************/
- /*
- * This part deal with receiving the packets.
- * The interrupt handler get an interrupt when a packet has been
- * successfully received and called this part...
- */
- /*------------------------------------------------------------------*/
- /*
- * Calculate the starting address of the frame pointed to by the receive
- * frame pointer and verify that the frame seem correct
- * (called by wv_packet_rcv())
- */
- static inline int
- wv_start_of_frame(device * dev,
- int rfp, /* end of frame */
- int wrap) /* start of buffer */
- {
- ioaddr_t base = dev->base_addr;
- int rp;
- int len;
- rp = (rfp - 5 + RX_SIZE) % RX_SIZE;
- outb(rp & 0xff, PIORL(base));
- outb(((rp >> 8) & PIORH_MASK), PIORH(base));
- len = inb(PIOP(base));
- len |= inb(PIOP(base)) << 8;
- /* Sanity checks on size */
- /* Frame too big */
- if(len > MAXDATAZ + 100)
- {
- #ifdef DEBUG_RX_ERROR
- printk(KERN_INFO "%s: wv_start_of_frame: Received frame too large, rfp %d len 0x%xn",
- dev->name, rfp, len);
- #endif
- return(-1);
- }
-
- /* Frame too short */
- if(len < 7)
- {
- #ifdef DEBUG_RX_ERROR
- printk(KERN_INFO "%s: wv_start_of_frame: Received null frame, rfp %d len 0x%xn",
- dev->name, rfp, len);
- #endif
- return(-1);
- }
-
- /* Wrap around buffer */
- if(len > ((wrap - (rfp - len) + RX_SIZE) % RX_SIZE)) /* magic formula ! */
- {
- #ifdef DEBUG_RX_ERROR
- printk(KERN_INFO "%s: wv_start_of_frame: wrap around buffer, wrap %d rfp %d len 0x%xn",
- dev->name, wrap, rfp, len);
- #endif
- return(-1);
- }
- return((rp - len + RX_SIZE) % RX_SIZE);
- } /* wv_start_of_frame */
- /*------------------------------------------------------------------*/
- /*
- * This routine does the actual copy of data (including the ethernet
- * header structure) from the WaveLAN card to an sk_buff chain that
- * will be passed up to the network interface layer. NOTE: We
- * currently don't handle trailer protocols (neither does the rest of
- * the network interface), so if that is needed, it will (at least in
- * part) be added here. The contents of the receive ring buffer are
- * copied to a message chain that is then passed to the kernel.
- *
- * Note: if any errors occur, the packet is "dropped on the floor"
- * (called by wv_packet_rcv())
- */
- static inline void
- wv_packet_read(device * dev,
- int fd_p,
- int sksize)
- {
- net_local * lp = (net_local *) dev->priv;
- struct sk_buff * skb;
- #ifdef DEBUG_RX_TRACE
- printk(KERN_DEBUG "%s: ->wv_packet_read(0x%X, %d)n",
- dev->name, fd_p, sksize);
- #endif
- /* Allocate some buffer for the new packet */
- if((skb = dev_alloc_skb(sksize+2)) == (struct sk_buff *) NULL)
- {
- #ifdef DEBUG_RX_ERROR
- printk(KERN_INFO "%s: wv_packet_read(): could not alloc_skb(%d, GFP_ATOMIC)n",
- dev->name, sksize);
- #endif
- lp->stats.rx_dropped++;
- /*
- * Not only do we want to return here, but we also need to drop the
- * packet on the floor to clear the interrupt.
- */
- return;
- }
- skb->dev = dev;
- skb_reserve(skb, 2);
- fd_p = read_ringbuf(dev, fd_p, (char *) skb_put(skb, sksize), sksize);
- skb->protocol = eth_type_trans(skb, dev);
- #ifdef DEBUG_RX_INFO
- wv_packet_info(skb->mac.raw, sksize, dev->name, "wv_packet_read");
- #endif /* DEBUG_RX_INFO */
-
- /* Statistics gathering & stuff associated.
- * It seem a bit messy with all the define, but it's really simple... */
- if(
- #ifdef WIRELESS_SPY
- (lp->spy_number > 0) ||
- #endif /* WIRELESS_SPY */
- #ifdef HISTOGRAM
- (lp->his_number > 0) ||
- #endif /* HISTOGRAM */
- #ifdef WAVELAN_ROAMING
- (do_roaming) ||
- #endif /* WAVELAN_ROAMING */
- 0)
- {
- u_char stats[3]; /* Signal level, Noise level, Signal quality */
- /* read signal level, silence level and signal quality bytes */
- fd_p = read_ringbuf(dev, (fd_p + 4) % RX_SIZE + RX_BASE,
- stats, 3);
- #ifdef DEBUG_RX_INFO
- printk(KERN_DEBUG "%s: wv_packet_read(): Signal level %d/63, Silence level %d/63, signal quality %d/16n",
- dev->name, stats[0] & 0x3F, stats[1] & 0x3F, stats[2] & 0x0F);
- #endif
- #ifdef WAVELAN_ROAMING
- if(do_roaming)
- if(WAVELAN_BEACON(skb->data))
- wl_roam_gather(dev, skb->data, stats);
- #endif /* WAVELAN_ROAMING */
-
- #ifdef WIRELESS_SPY
- wl_spy_gather(dev, skb->mac.raw + WAVELAN_ADDR_SIZE, stats);
- #endif /* WIRELESS_SPY */
- #ifdef HISTOGRAM
- wl_his_gather(dev, stats);
- #endif /* HISTOGRAM */
- }
- /*
- * Hand the packet to the Network Module
- */
- netif_rx(skb);
- /* Keep stats up to date */
- dev->last_rx = jiffies;
- lp->stats.rx_packets++;
- lp->stats.rx_bytes += sksize;
- #ifdef DEBUG_RX_TRACE
- printk(KERN_DEBUG "%s: <-wv_packet_read()n", dev->name);
- #endif
- return;
- }
- /*------------------------------------------------------------------*/
- /*
- * This routine is called by the interrupt handler to initiate a
- * packet transfer from the card to the network interface layer above
- * this driver. This routine checks if a buffer has been successfully
- * received by the WaveLAN card. If so, the routine wv_packet_read is
- * called to do the actual transfer of the card's data including the
- * ethernet header into a packet consisting of an sk_buff chain.
- * (called by wavelan_interrupt())
- * Note : the spinlock is already grabbed for us and irq are disabled.
- */
- static inline void
- wv_packet_rcv(device * dev)
- {
- ioaddr_t base = dev->base_addr;
- net_local * lp = (net_local *) dev->priv;
- int newrfp;
- int rp;
- int len;
- int f_start;
- int status;
- int i593_rfp;
- int stat_ptr;
- u_char c[4];
- #ifdef DEBUG_RX_TRACE
- printk(KERN_DEBUG "%s: ->wv_packet_rcv()n", dev->name);
- #endif
- /* Get the new receive frame pointer from the i82593 chip */
- outb(CR0_STATUS_2 | OP0_NOP, LCCR(base));
- i593_rfp = inb(LCSR(base));
- i593_rfp |= inb(LCSR(base)) << 8;
- i593_rfp %= RX_SIZE;
- /* Get the new receive frame pointer from the WaveLAN card.
- * It is 3 bytes more than the increment of the i82593 receive
- * frame pointer, for each packet. This is because it includes the
- * 3 roaming bytes added by the mmc.
- */
- newrfp = inb(RPLL(base));
- newrfp |= inb(RPLH(base)) << 8;
- newrfp %= RX_SIZE;
- #ifdef DEBUG_RX_INFO
- printk(KERN_DEBUG "%s: wv_packet_rcv(): i593_rfp %d stop %d newrfp %d lp->rfp %dn",
- dev->name, i593_rfp, lp->stop, newrfp, lp->rfp);
- #endif
- #ifdef DEBUG_RX_ERROR
- /* If no new frame pointer... */
- if(lp->overrunning || newrfp == lp->rfp)
- printk(KERN_INFO "%s: wv_packet_rcv(): no new frame: i593_rfp %d stop %d newrfp %d lp->rfp %dn",
- dev->name, i593_rfp, lp->stop, newrfp, lp->rfp);
- #endif
- /* Read all frames (packets) received */
- while(newrfp != lp->rfp)
- {
- /* A frame is composed of the packet, followed by a status word,
- * the length of the frame (word) and the mmc info (SNR & qual).
- * It's because the length is at the end that we can only scan
- * frames backward. */
- /* Find the first frame by skipping backwards over the frames */
- rp = newrfp; /* End of last frame */
- while(((f_start = wv_start_of_frame(dev, rp, newrfp)) != lp->rfp) &&
- (f_start != -1))
- rp = f_start;
- /* If we had a problem */
- if(f_start == -1)
- {
- #ifdef DEBUG_RX_ERROR
- printk(KERN_INFO "wavelan_cs: cannot find start of frame ");
- printk(" i593_rfp %d stop %d newrfp %d lp->rfp %dn",
- i593_rfp, lp->stop, newrfp, lp->rfp);
- #endif
- lp->rfp = rp; /* Get to the last usable frame */
- continue;
- }
- /* f_start point to the beggining of the first frame received
- * and rp to the beggining of the next one */
- /* Read status & length of the frame */
- stat_ptr = (rp - 7 + RX_SIZE) % RX_SIZE;
- stat_ptr = read_ringbuf(dev, stat_ptr, c, 4);
- status = c[0] | (c[1] << 8);
- len = c[2] | (c[3] << 8);
- /* Check status */
- if((status & RX_RCV_OK) != RX_RCV_OK)
- {
- lp->stats.rx_errors++;
- if(status & RX_NO_SFD)
- lp->stats.rx_frame_errors++;
- if(status & RX_CRC_ERR)
- lp->stats.rx_crc_errors++;
- if(status & RX_OVRRUN)
- lp->stats.rx_over_errors++;
- #ifdef DEBUG_RX_FAIL
- printk(KERN_DEBUG "%s: wv_packet_rcv(): packet not received ok, status = 0x%xn",
- dev->name, status);
- #endif
- }
- else
- /* Read the packet and transmit to Linux */
- wv_packet_read(dev, f_start, len - 2);
- /* One frame has been processed, skip it */
- lp->rfp = rp;
- }
- /*
- * Update the frame stop register, but set it to less than
- * the full 8K to allow space for 3 bytes of signal strength
- * per packet.
- */
- lp->stop = (i593_rfp + RX_SIZE - ((RX_SIZE / 64) * 3)) % RX_SIZE;
- outb(OP0_SWIT_TO_PORT_1 | CR0_CHNL, LCCR(base));
- outb(CR1_STOP_REG_UPDATE | (lp->stop >> RX_SIZE_SHIFT), LCCR(base));
- outb(OP1_SWIT_TO_PORT_0, LCCR(base));
- #ifdef DEBUG_RX_TRACE
- printk(KERN_DEBUG "%s: <-wv_packet_rcv()n", dev->name);
- #endif
- }
- /*********************** PACKET TRANSMISSION ***********************/
- /*
- * This part deal with sending packet through the wavelan
- * We copy the packet to the send buffer and then issue the send
- * command to the i82593. The result of this operation will be
- * checked in wavelan_interrupt()
- */
- /*------------------------------------------------------------------*/
- /*
- * This routine fills in the appropriate registers and memory
- * locations on the WaveLAN card and starts the card off on
- * the transmit.
- * (called in wavelan_packet_xmit())
- */
- static inline void
- wv_packet_write(device * dev,
- void * buf,
- short length)
- {
- net_local * lp = (net_local *) dev->priv;
- ioaddr_t base = dev->base_addr;
- unsigned long flags;
- int clen = length;
- register u_short xmtdata_base = TX_BASE;
- #ifdef DEBUG_TX_TRACE
- printk(KERN_DEBUG "%s: ->wv_packet_write(%d)n", dev->name, length);
- #endif
- wv_splhi(lp, &flags);
- /* Check if we need some padding */
- if(clen < ETH_ZLEN)
- clen = ETH_ZLEN;
- /* Write the length of data buffer followed by the buffer */
- outb(xmtdata_base & 0xff, PIORL(base));
- outb(((xmtdata_base >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
- outb(clen & 0xff, PIOP(base)); /* lsb */
- outb(clen >> 8, PIOP(base)); /* msb */
- /* Send the data */
- outsb(PIOP(base), buf, clen);
- /* Indicate end of transmit chain */
- outb(OP0_NOP, PIOP(base));
- /* josullvn@cs.cmu.edu: need to send a second NOP for alignment... */
- outb(OP0_NOP, PIOP(base));
- /* Reset the transmit DMA pointer */
- hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
- hacr_write(base, HACR_DEFAULT);
- /* Send the transmit command */
- wv_82593_cmd(dev, "wv_packet_write(): transmit",
- OP0_TRANSMIT, SR0_NO_RESULT);
- /* Make sure the watchdog will keep quiet for a while */
- dev->trans_start = jiffies;
- /* Keep stats up to date */
- lp->stats.tx_bytes += length;
- wv_splx(lp, &flags);
- #ifdef DEBUG_TX_INFO
- wv_packet_info((u_char *) buf, length, dev->name, "wv_packet_write");
- #endif /* DEBUG_TX_INFO */
- #ifdef DEBUG_TX_TRACE
- printk(KERN_DEBUG "%s: <-wv_packet_write()n", dev->name);
- #endif
- }
- /*------------------------------------------------------------------*/
- /*
- * This routine is called when we want to send a packet (NET3 callback)
- * In this routine, we check if the harware is ready to accept
- * the packet. We also prevent reentrance. Then, we call the function
- * to send the packet...
- */
- static int
- wavelan_packet_xmit(struct sk_buff * skb,
- device * dev)
- {
- net_local * lp = (net_local *)dev->priv;
- unsigned long flags;
- #ifdef DEBUG_TX_TRACE
- printk(KERN_DEBUG "%s: ->wavelan_packet_xmit(0x%X)n", dev->name,
- (unsigned) skb);
- #endif
- /*
- * Block a timer-based transmit from overlapping a previous transmit.
- * In other words, prevent reentering this routine.
- */
- netif_stop_queue(dev);
- /* If somebody has asked to reconfigure the controller,
- * we can do it now */
- if(lp->reconfig_82593)
- {
- wv_splhi(lp, &flags); /* Disable interrupts */
- wv_82593_config(dev);
- wv_splx(lp, &flags); /* Re-enable interrupts */
- /* Note : the configure procedure was totally synchronous,
- * so the Tx buffer is now free */
- }
- #ifdef DEBUG_TX_ERROR
- if (skb->next)
- printk(KERN_INFO "skb has nextn");
- #endif
- wv_packet_write(dev, skb->data, skb->len);
- dev_kfree_skb(skb);
- #ifdef DEBUG_TX_TRACE
- printk(KERN_DEBUG "%s: <-wavelan_packet_xmit()n", dev->name);
- #endif
- return(0);
- }
- /********************** HARDWARE CONFIGURATION **********************/
- /*
- * This part do the real job of starting and configuring the hardware.
- */
- /*------------------------------------------------------------------*/
- /*
- * Routine to initialize the Modem Management Controller.
- * (called by wv_hw_config())
- */
- static inline int
- wv_mmc_init(device * dev)
- {
- ioaddr_t base = dev->base_addr;
- psa_t psa;
- mmw_t m;
- int configured;
- int i; /* Loop counter */
- #ifdef DEBUG_CONFIG_TRACE
- printk(KERN_DEBUG "%s: ->wv_mmc_init()n", dev->name);
- #endif
- /* Read the parameter storage area */
- psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
- /*
- * Check the first three octets of the MAC addr for the manufacturer's code.
- * Note: If you get the error message below, you've got a
- * non-NCR/AT&T/Lucent PCMCIA cards, see wavelan_cs.h for detail on
- * how to configure your card...
- */
- for(i = 0; i < (sizeof(MAC_ADDRESSES) / sizeof(char) / 3); i++)
- if((psa.psa_univ_mac_addr[0] == MAC_ADDRESSES[i][0]) &&
- (psa.psa_univ_mac_addr[1] == MAC_ADDRESSES[i][1]) &&
- (psa.psa_univ_mac_addr[2] == MAC_ADDRESSES[i][2]))
- break;
- /* If we have not found it... */
- if(i == (sizeof(MAC_ADDRESSES) / sizeof(char) / 3))
- {
- #ifdef DEBUG_CONFIG_ERRORS
- printk(KERN_WARNING "%s: wv_mmc_init(): Invalid MAC address: %02X:%02X:%02X:...n",
- dev->name, psa.psa_univ_mac_addr[0],
- psa.psa_univ_mac_addr[1], psa.psa_univ_mac_addr[2]);
- #endif
- return FALSE;
- }
- /* Get the MAC address */
- memcpy(&dev->dev_addr[0], &psa.psa_univ_mac_addr[0], WAVELAN_ADDR_SIZE);
- #ifdef USE_PSA_CONFIG
- configured = psa.psa_conf_status & 1;
- #else
- configured = 0;
- #endif
- /* Is the PSA is not configured */
- if(!configured)
- {
- /* User will be able to configure NWID after (with iwconfig) */
- psa.psa_nwid[0] = 0;
- psa.psa_nwid[1] = 0;
- /* As NWID is not set : no NWID checking */
- psa.psa_nwid_select = 0;
- /* Disable encryption */
- psa.psa_encryption_select = 0;
- /* Set to standard values
- * 0x04 for AT,
- * 0x01 for MCA,
- * 0x04 for PCMCIA and 2.00 card (AT&T 407-024689/E document)
- */
- if (psa.psa_comp_number & 1)
- psa.psa_thr_pre_set = 0x01;
- else
- psa.psa_thr_pre_set = 0x04;
- psa.psa_quality_thr = 0x03;
- /* It is configured */
- psa.psa_conf_status |= 1;
- #ifdef USE_PSA_CONFIG
- /* Write the psa */
- psa_write(dev, (char *)psa.psa_nwid - (char *)&psa,
- (unsigned char *)psa.psa_nwid, 4);
- psa_write(dev, (char *)&psa.psa_thr_pre_set - (char *)&psa,
- (unsigned char *)&psa.psa_thr_pre_set, 1);
- psa_write(dev, (char *)&psa.psa_quality_thr - (char *)&psa,
- (unsigned char *)&psa.psa_quality_thr, 1);
- psa_write(dev, (char *)&psa.psa_conf_status - (char *)&psa,
- (unsigned char *)&psa.psa_conf_status, 1);
- /* update the Wavelan checksum */
- update_psa_checksum(dev);
- #endif /* USE_PSA_CONFIG */
- }
- /* Zero the mmc structure */
- memset(&m, 0x00, sizeof(m));
- /* Copy PSA info to the mmc */
- m.mmw_netw_id_l = psa.psa_nwid[1];
- m.mmw_netw_id_h = psa.psa_nwid[0];
-
- if(psa.psa_nwid_select & 1)
- m.mmw_loopt_sel = 0x00;
- else
- m.mmw_loopt_sel = MMW_LOOPT_SEL_DIS_NWID;
- memcpy(&m.mmw_encr_key, &psa.psa_encryption_key,
- sizeof(m.mmw_encr_key));
- if(psa.psa_encryption_select)
- m.mmw_encr_enable = MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE;
- else
- m.mmw_encr_enable = 0;
- m.mmw_thr_pre_set = psa.psa_thr_pre_set & 0x3F;
- m.mmw_quality_thr = psa.psa_quality_thr & 0x0F;
- /*
- * Set default modem control parameters.
- * See NCR document 407-0024326 Rev. A.
- */
- m.mmw_jabber_enable = 0x01;
- m.mmw_anten_sel = MMW_ANTEN_SEL_ALG_EN;
- m.mmw_ifs = 0x20;
- m.mmw_mod_delay = 0x04;
- m.mmw_jam_time = 0x38;
- m.mmw_des_io_invert = 0;
- m.mmw_freeze = 0;
- m.mmw_decay_prm = 0;
- m.mmw_decay_updat_prm = 0;
- /* Write all info to mmc */
- mmc_write(base, 0, (u_char *)&m, sizeof(m));
- /* The following code start the modem of the 2.00 frequency
- * selectable cards at power on. It's not strictly needed for the
- * following boots...
- * The original patch was by Joe Finney for the PCMCIA driver, but
- * I've cleaned it a bit and add documentation.
- * Thanks to Loeke Brederveld from Lucent for the info.
- */
- /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable)
- * (does it work for everybody ? - especially old cards...) */
- /* Note : WFREQSEL verify that it is able to read from EEprom
- * a sensible frequency (address 0x00) + that MMR_FEE_STATUS_ID
- * is 0xA (Xilinx version) or 0xB (Ariadne version).
- * My test is more crude but do work... */
- if(!(mmc_in(base, mmroff(0, mmr_fee_status)) &
- (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
- {
- /* We must download the frequency parameters to the
- * synthetisers (from the EEprom - area 1)
- * Note : as the EEprom is auto decremented, we set the end
- * if the area... */
- m.mmw_fee_addr = 0x0F;
- m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
- mmc_write(base, (char *)&m.mmw_fee_ctrl - (char *)&m,
- (unsigned char *)&m.mmw_fee_ctrl, 2);
- /* Wait until the download is finished */
- fee_wait(base, 100, 100);
- #ifdef DEBUG_CONFIG_INFO
- /* The frequency was in the last word downloaded... */
- mmc_read(base, (char *)&m.mmw_fee_data_l - (char *)&m,
- (unsigned char *)&m.mmw_fee_data_l, 2);
- /* Print some info for the user */
- printk(KERN_DEBUG "%s: Wavelan 2.00 recognised (frequency select) : Current frequency = %ldn",
- dev->name,
- ((m.mmw_fee_data_h << 4) |
- (m.mmw_fee_data_l >> 4)) * 5 / 2 + 24000L);
- #endif
- /* We must now download the power adjust value (gain) to
- * the synthetisers (from the EEprom - area 7 - DAC) */
- m.mmw_fee_addr = 0x61;
- m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
- mmc_write(base, (char *)&m.mmw_fee_ctrl - (char *)&m,
- (unsigned char *)&m.mmw_fee_ctrl, 2);
- /* Wait until the download is finished */
- } /* if 2.00 card */
- #ifdef DEBUG_CONFIG_TRACE
- printk(KERN_DEBUG "%s: <-wv_mmc_init()n", dev->name);
- #endif
- return TRUE;
- }
- /*------------------------------------------------------------------*/
- /*
- * Routine to gracefully turn off reception, and wait for any commands
- * to complete.
- * (called in wv_ru_start() and wavelan_close() and wavelan_event())
- */
- static int
- wv_ru_stop(device * dev)
- {
- ioaddr_t base = dev->base_addr;
- net_local * lp = (net_local *) dev->priv;
- unsigned long flags;
- int status;
- int spin;
- #ifdef DEBUG_CONFIG_TRACE
- printk(KERN_DEBUG "%s: ->wv_ru_stop()n", dev->name);
- #endif
- wv_splhi(lp, &flags);
- /* First, send the LAN controller a stop receive command */
- wv_82593_cmd(dev, "wv_graceful_shutdown(): stop-rcv",
- OP0_STOP_RCV, SR0_NO_RESULT);
- /* Then, spin until the receive unit goes idle */
- spin = 300;
- do
- {
- udelay(10);
- outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
- status = inb(LCSR(base));
- }
- while(((status & SR3_RCV_STATE_MASK) != SR3_RCV_IDLE) && (spin-- > 0));
- /* Now, spin until the chip finishes executing its current command */
- do
- {
- udelay(10);
- outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
- status = inb(LCSR(base));
- }
- while(((status & SR3_EXEC_STATE_MASK) != SR3_EXEC_IDLE) && (spin-- > 0));
- wv_splx(lp, &flags);
- /* If there was a problem */
- if(spin <= 0)
- {
- #ifdef DEBUG_CONFIG_ERROR
- printk(KERN_INFO "%s: wv_ru_stop(): The chip doesn't want to stop...n",
- dev->name);
- #endif
- return FALSE;
- }
- #ifdef DEBUG_CONFIG_TRACE
- printk(KERN_DEBUG "%s: <-wv_ru_stop()n", dev->name);
- #endif
- return TRUE;
- } /* wv_ru_stop */
- /*------------------------------------------------------------------*/
- /*
- * This routine starts the receive unit running. First, it checks if
- * the card is actually ready. Then the card is instructed to receive
- * packets again.
- * (called in wv_hw_reset() & wavelan_open())
- */
- static int
- wv_ru_start(device * dev)
- {
- ioaddr_t base = dev->base_addr;
- net_local * lp = (net_local *) dev->priv;
- unsigned long flags;
- #ifdef DEBUG_CONFIG_TRACE
- printk(KERN_DEBUG "%s: ->wv_ru_start()n", dev->name);
- #endif
- /*
- * We need to start from a quiescent state. To do so, we could check
- * if the card is already running, but instead we just try to shut
- * it down. First, we disable reception (in case it was already enabled).
- */
- if(!wv_ru_stop(dev))
- return FALSE;
- wv_splhi(lp, &flags);
- /* Now we know that no command is being executed. */
- /* Set the receive frame pointer and stop pointer */
- lp->rfp = 0;
- outb(OP0_SWIT_TO_PORT_1 | CR0_CHNL, LCCR(base));
- /* Reset ring management. This sets the receive frame pointer to 1 */
- outb(OP1_RESET_RING_MNGMT, LCCR(base));
- #if 0
- /* XXX the i82593 manual page 6-4 seems to indicate that the stop register
- should be set as below */
- /* outb(CR1_STOP_REG_UPDATE|((RX_SIZE - 0x40)>> RX_SIZE_SHIFT),LCCR(base));*/
- #elif 0
- /* but I set it 0 instead */
- lp->stop = 0;
- #else
- /* but I set it to 3 bytes per packet less than 8K */
- lp->stop = (0 + RX_SIZE - ((RX_SIZE / 64) * 3)) % RX_SIZE;
- #endif
- outb(CR1_STOP_REG_UPDATE | (lp->stop >> RX_SIZE_SHIFT), LCCR(base));
- outb(OP1_INT_ENABLE, LCCR(base));
- outb(OP1_SWIT_TO_PORT_0, LCCR(base));
- /* Reset receive DMA pointer */
- hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
- hacr_write_slow(base, HACR_DEFAULT);
- /* Receive DMA on channel 1 */
- wv_82593_cmd(dev, "wv_ru_start(): rcv-enable",
- CR0_CHNL | OP0_RCV_ENABLE, SR0_NO_RESULT);
- #ifdef DEBUG_I82593_SHOW
- {
- int status;
- int opri;
- int spin = 10000;
- /* spin until the chip starts receiving */
- do
- {
- outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
- status = inb(LCSR(base));
- if(spin-- <= 0)
- break;
- }
- while(((status & SR3_RCV_STATE_MASK) != SR3_RCV_ACTIVE) &&
- ((status & SR3_RCV_STATE_MASK) != SR3_RCV_READY));
- printk(KERN_DEBUG "rcv status is 0x%x [i:%d]n",
- (status & SR3_RCV_STATE_MASK), i);
- }
- #endif
- wv_splx(lp, &flags);
- #ifdef DEBUG_CONFIG_TRACE
- printk(KERN_DEBUG "%s: <-wv_ru_start()n", dev->name);
- #endif
- return TRUE;
- }
- /*------------------------------------------------------------------*/
- /*
- * This routine does a standard config of the WaveLAN controller (i82593).
- * In the ISA driver, this is integrated in wavelan_hardware_reset()
- * (called by wv_hw_config(), wv_82593_reconfig() & wavelan_packet_xmit())
- */
- static int
- wv_82593_config(device * dev)
- {
- ioaddr_t base = dev->base_addr;
- net_local * lp = (net_local *) dev->priv;
- struct i82593_conf_block cfblk;
- int ret = TRUE;
- #ifdef DEBUG_CONFIG_TRACE
- printk(KERN_DEBUG "%s: ->wv_82593_config()n", dev->name);
- #endif
- /* Create & fill i82593 config block
- *
- * Now conform to Wavelan document WCIN085B
- */
- memset(&cfblk, 0x00, sizeof(struct i82593_conf_block));
- cfblk.d6mod = FALSE; /* Run in i82593 advanced mode */
- cfblk.fifo_limit = 5; /* = 56 B rx and 40 B tx fifo thresholds */
- cfblk.forgnesi = FALSE; /* 0=82C501, 1=AMD7992B compatibility */
- cfblk.fifo_32 = 1;
- cfblk.throttle_enb = FALSE;
- cfblk.contin = TRUE; /* enable continuous mode */
- cfblk.cntrxint = FALSE; /* enable continuous mode receive interrupts */
- cfblk.addr_len = WAVELAN_ADDR_SIZE;
- cfblk.acloc = TRUE; /* Disable source addr insertion by i82593 */
- cfblk.preamb_len = 0; /* 2 bytes preamble (SFD) */
- cfblk.loopback = FALSE;
- cfblk.lin_prio = 0; /* conform to 802.3 backoff algoritm */
- cfblk.exp_prio = 5; /* conform to 802.3 backoff algoritm */
- cfblk.bof_met = 1; /* conform to 802.3 backoff algoritm */
- cfblk.ifrm_spc = 0x20; /* 32 bit times interframe spacing */
- cfblk.slottim_low = 0x20; /* 32 bit times slot time */
- cfblk.slottim_hi = 0x0;
- cfblk.max_retr = 15;
- cfblk.prmisc = ((lp->promiscuous) ? TRUE: FALSE); /* Promiscuous mode */
- cfblk.bc_dis = FALSE; /* Enable broadcast reception */
- cfblk.crs_1 = TRUE; /* Transmit without carrier sense */
- cfblk.nocrc_ins = FALSE; /* i82593 generates CRC */
- cfblk.crc_1632 = FALSE; /* 32-bit Autodin-II CRC */
- cfblk.crs_cdt = FALSE; /* CD not to be interpreted as CS */
- cfblk.cs_filter = 0; /* CS is recognized immediately */
- cfblk.crs_src = FALSE; /* External carrier sense */
- cfblk.cd_filter = 0; /* CD is recognized immediately */
- cfblk.min_fr_len = ETH_ZLEN >> 2; /* Minimum frame length 64 bytes */
- cfblk.lng_typ = FALSE; /* Length field > 1500 = type field */
- cfblk.lng_fld = TRUE; /* Disable 802.3 length field check */
- cfblk.rxcrc_xf = TRUE; /* Don't transfer CRC to memory */
- cfblk.artx = TRUE; /* Disable automatic retransmission */
- cfblk.sarec = TRUE; /* Disable source addr trig of CD */
- cfblk.tx_jabber = TRUE; /* Disable jabber jam sequence */
- cfblk.hash_1 = FALSE; /* Use bits 0-5 in mc address hash */
- cfblk.lbpkpol = TRUE; /* Loopback pin active high */
- cfblk.fdx = FALSE; /* Disable full duplex operation */
- cfblk.dummy_6 = 0x3f; /* all ones */
- cfblk.mult_ia = FALSE; /* No multiple individual addresses */
- cfblk.dis_bof = FALSE; /* Disable the backoff algorithm ?! */
- cfblk.dummy_1 = TRUE; /* set to 1 */
- cfblk.tx_ifs_retrig = 3; /* Hmm... Disabled */
- #ifdef MULTICAST_ALL
- cfblk.mc_all = (lp->allmulticast ? TRUE: FALSE); /* Allow all multicasts */
- #else
- cfblk.mc_all = FALSE; /* No multicast all mode */
- #endif
- cfblk.rcv_mon = 0; /* Monitor mode disabled */
- cfblk.frag_acpt = TRUE; /* Do not accept fragments */
- cfblk.tstrttrs = FALSE; /* No start transmission threshold */
- cfblk.fretx = TRUE; /* FIFO automatic retransmission */
- cfblk.syncrqs = FALSE; /* Synchronous DRQ deassertion... */
- cfblk.sttlen = TRUE; /* 6 byte status registers */
- cfblk.rx_eop = TRUE; /* Signal EOP on packet reception */
- cfblk.tx_eop = TRUE; /* Signal EOP on packet transmission */
- cfblk.rbuf_size = RX_SIZE>>11; /* Set receive buffer size */
- cfblk.rcvstop = TRUE; /* Enable Receive Stop Register */
- #ifdef DEBUG_I82593_SHOW
- {
- u_char *c = (u_char *) &cfblk;
- int i;
- printk(KERN_DEBUG "wavelan_cs: config block:");
- for(i = 0; i < sizeof(struct i82593_conf_block); i++,c++)
- {
- if((i % 16) == 0) printk("n" KERN_DEBUG);
- printk("%02x ", *c);
- }
- printk("n");
- }
- #endif
- /* Copy the config block to the i82593 */
- outb(TX_BASE & 0xff, PIORL(base));
- outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
- outb(sizeof(struct i82593_conf_block) & 0xff, PIOP(base)); /* lsb */
- outb(sizeof(struct i82593_conf_block) >> 8, PIOP(base)); /* msb */
- outsb(PIOP(base), (char *) &cfblk, sizeof(struct i82593_conf_block));
- /* reset transmit DMA pointer */
- hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
- hacr_write(base, HACR_DEFAULT);
- if(!wv_82593_cmd(dev, "wv_82593_config(): configure",
- OP0_CONFIGURE, SR0_CONFIGURE_DONE))
- ret = FALSE;
- /* Initialize adapter's ethernet MAC address */
- outb(TX_BASE & 0xff, PIORL(base));
- outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
- outb(WAVELAN_ADDR_SIZE, PIOP(base)); /* byte count lsb */
- outb(0, PIOP(base)); /* byte count msb */
- outsb(PIOP(base), &dev->dev_addr[0], WAVELAN_ADDR_SIZE);
- /* reset transmit DMA pointer */
- hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
- hacr_write(base, HACR_DEFAULT);
- if(!wv_82593_cmd(dev, "wv_82593_config(): ia-setup",
- OP0_IA_SETUP, SR0_IA_SETUP_DONE))
- ret = FALSE;
- #ifdef WAVELAN_ROAMING
- /* If roaming is enabled, join the "Beacon Request" multicast group... */
- /* But only if it's not in there already! */
- if(do_roaming)
- dev_mc_add(dev,WAVELAN_BEACON_ADDRESS, WAVELAN_ADDR_SIZE, 1);
- #endif /* WAVELAN_ROAMING */
- /* If any multicast address to set */
- if(lp->mc_count)
- {
- struct dev_mc_list * dmi;
- int addrs_len = WAVELAN_ADDR_SIZE * lp->mc_count;
- #ifdef DEBUG_CONFIG_INFO
- printk(KERN_DEBUG "%s: wv_hw_config(): set %d multicast addresses:n",
- dev->name, lp->mc_count);
- for(dmi=dev->mc_list; dmi; dmi=dmi->next)
- printk(KERN_DEBUG " %02x:%02x:%02x:%02x:%02x:%02xn",
- dmi->dmi_addr[0], dmi->dmi_addr[1], dmi->dmi_addr[2],
- dmi->dmi_addr[3], dmi->dmi_addr[4], dmi->dmi_addr[5] );
- #endif
- /* Initialize adapter's ethernet multicast addresses */
- outb(TX_BASE & 0xff, PIORL(base));
- outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
- outb(addrs_len & 0xff, PIOP(base)); /* byte count lsb */
- outb((addrs_len >> 8), PIOP(base)); /* byte count msb */
- for(dmi=dev->mc_list; dmi; dmi=dmi->next)
- outsb(PIOP(base), dmi->dmi_addr, dmi->dmi_addrlen);
- /* reset transmit DMA pointer */
- hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
- hacr_write(base, HACR_DEFAULT);
- if(!wv_82593_cmd(dev, "wv_82593_config(): mc-setup",
- OP0_MC_SETUP, SR0_MC_SETUP_DONE))
- ret = FALSE;
- lp->mc_count = dev->mc_count; /* remember to avoid repeated reset */
- }
- /* Job done, clear the flag */
- lp->reconfig_82593 = FALSE;
- #ifdef DEBUG_CONFIG_TRACE
- printk(KERN_DEBUG "%s: <-wv_82593_config()n", dev->name);
- #endif
- return(ret);
- }
- /*------------------------------------------------------------------*/
- /*
- * Read the Access Configuration Register, perform a software reset,
- * and then re-enable the card's software.
- *
- * If I understand correctly : reset the pcmcia interface of the
- * wavelan.
- * (called by wv_config())
- */
- static inline int
- wv_pcmcia_reset(device * dev)
- {
- int i;
- conf_reg_t reg = { 0, CS_READ, CISREG_COR, 0 };
- dev_link_t * link = ((net_local *) dev->priv)->link;
- #ifdef DEBUG_CONFIG_TRACE
- printk(KERN_DEBUG "%s: ->wv_pcmcia_reset()n", dev->name);
- #endif
- i = CardServices(AccessConfigurationRegister, link->handle, ®);
- if(i != CS_SUCCESS)
- {
- cs_error(link->handle, AccessConfigurationRegister, i);
- return FALSE;
- }
-
- #ifdef DEBUG_CONFIG_INFO
- printk(KERN_DEBUG "%s: wavelan_pcmcia_reset(): Config reg is 0x%xn",
- dev->name, (u_int) reg.Value);
- #endif
- reg.Action = CS_WRITE;
- reg.Value = reg.Value | COR_SW_RESET;
- i = CardServices(AccessConfigurationRegister, link->handle, ®);
- if(i != CS_SUCCESS)
- {
- cs_error(link->handle, AccessConfigurationRegister, i);
- return FALSE;
- }
-
- reg.Action = CS_WRITE;
- reg.Value = COR_LEVEL_IRQ | COR_CONFIG;
- i = CardServices(AccessConfigurationRegister, link->handle, ®);
- if(i != CS_SUCCESS)
- {
- cs_error(link->handle, AccessConfigurationRegister, i);
- return FALSE;
- }
- #ifdef DEBUG_CONFIG_TRACE
- printk(KERN_DEBUG "%s: <-wv_pcmcia_reset()n", dev->name);
- #endif
- return TRUE;
- }
- /*------------------------------------------------------------------*/
- /*
- * wavelan_hw_config() is called after a CARD_INSERTION event is
- * received, to configure the wavelan hardware.
- * Note that the reception will be enabled in wavelan->open(), so the
- * device is configured but idle...
- * Performs the following actions:
- * 1. A pcmcia software reset (using wv_pcmcia_reset())
- * 2. A power reset (reset DMA)
- * 3. Reset the LAN controller
- * 4. Initialize the radio modem (using wv_mmc_init)
- * 5. Configure LAN controller (using wv_82593_config)
- * 6. Perform a diagnostic on the LAN controller
- * (called by wavelan_event() & wv_hw_reset())
- */
- static int
- wv_hw_config(device * dev)
- {
- net_local * lp = (net_local *) dev->priv;
- ioaddr_t base = dev->base_addr;
- unsigned long flags;
- int ret = FALSE;
- #ifdef DEBUG_CONFIG_TRACE
- printk(KERN_DEBUG "%s: ->wv_hw_config()n", dev->name);
- #endif
- #ifdef STRUCT_CHECK
- if(wv_structuct_check() != (char *) NULL)
- {
- printk(KERN_WARNING "%s: wv_hw_config: structure/compiler botch: "%s"n",
- dev->name, wv_structuct_check());
- return FALSE;
- }
- #endif /* STRUCT_CHECK == 1 */
- /* Reset the pcmcia interface */
- if(wv_pcmcia_reset(dev) == FALSE)
- return FALSE;
- /* Disable interrupts */
- wv_splhi(lp, &flags);
- /* Disguised goto ;-) */
- do
- {
- /* Power UP the module + reset the modem + reset host adapter
- * (in fact, reset DMA channels) */
- hacr_write_slow(base, HACR_RESET);
- hacr_write(base, HACR_DEFAULT);
- /* Check if the module has been powered up... */
- if(hasr_read(base) & HASR_NO_CLK)
- {
- #ifdef DEBUG_CONFIG_ERRORS
- printk(KERN_WARNING "%s: wv_hw_config(): modem not connected or not a wavelan cardn",
- dev->name);
- #endif
- break;
- }
- /* initialize the modem */
- if(wv_mmc_init(dev) == FALSE)
- {
- #ifdef DEBUG_CONFIG_ERRORS
- printk(KERN_WARNING "%s: wv_hw_config(): Can't configure the modemn",
- dev->name);
- #endif
- break;
- }
- /* reset the LAN controller (i82593) */
- outb(OP0_RESET, LCCR(base));
- mdelay(1); /* A bit crude ! */
- /* Initialize the LAN controller */
- if(wv_82593_config(dev) == FALSE)
- {
- #ifdef DEBUG_CONFIG_ERRORS
- printk(KERN_INFO "%s: wv_hw_config(): i82593 init failedn",
- dev->name);
- #endif
- break;
- }
- /* Diagnostic */
- if(wv_diag(dev) == FALSE)
- {
- #ifdef DEBUG_CONFIG_ERRORS
- printk(KERN_INFO "%s: wv_hw_config(): i82593 diagnostic failedn",
- dev->name);
- #endif
- break;
- }
- /*
- * insert code for loopback test here
- */
- /* The device is now configured */
- lp->configured = 1;
- ret = TRUE;
- }
- while(0);
- /* Re-enable interrupts */
- wv_splx(lp, &flags);
- #ifdef DEBUG_CONFIG_TRACE
- printk(KERN_DEBUG "%s: <-wv_hw_config()n", dev->name);
- #endif
- return(ret);
- }
- /*------------------------------------------------------------------*/
- /*
- * Totally reset the wavelan and restart it.
- * Performs the following actions:
- * 1. Call wv_hw_config()
- * 2. Start the LAN controller's receive unit
- * (called by wavelan_event(), wavelan_watchdog() and wavelan_open())
- */
- static inline void
- wv_hw_reset(device * dev)
- {
- net_local * lp = (net_local *) dev->priv;
- #ifdef DEBUG_CONFIG_TRACE
- printk(KERN_DEBUG "%s: ->wv_hw_reset()n", dev->name);
- #endif
- lp->nresets++;
- lp->configured = 0;
-
- /* Call wv_hw_config() for most of the reset & init stuff */
- if(wv_hw_config(dev) == FALSE)
- return;
- /* start receive unit */
- wv_ru_start(dev);
- #ifdef DEBUG_CONFIG_TRACE
- printk(KERN_DEBUG "%s: <-wv_hw_reset()n", dev->name);
- #endif
- }
- /*------------------------------------------------------------------*/
- /*
- * wv_pcmcia_config() is called after a CARD_INSERTION event is
- * received, to configure the PCMCIA socket, and to make the ethernet
- * device available to the system.
- * (called by wavelan_event())
- */
- static inline int
- wv_pcmcia_config(dev_link_t * link)
- {
- client_handle_t handle;
- tuple_t tuple;
- cisparse_t parse;
- struct net_device * dev;
- int i;
- u_char buf[64];
- win_req_t req;
- memreq_t mem;
- handle = link->handle;
- dev = (device *) link->priv;
- #ifdef DEBUG_CONFIG_TRACE
- printk(KERN_DEBUG "->wv_pcmcia_config(0x%p)n", link);
- #endif
- /*
- * This reads the card's CONFIG tuple to find its configuration
- * registers.
- */
- do
- {
- tuple.Attributes = 0;
- tuple.DesiredTuple = CISTPL_CONFIG;
- i = CardServices(GetFirstTuple, handle, &tuple);
- if(i != CS_SUCCESS)
- break;
- tuple.TupleData = (cisdata_t *)buf;
- tuple.TupleDataMax = 64;
- tuple.TupleOffset = 0;
- i = CardServices(GetTupleData, handle, &tuple);
- if(i != CS_SUCCESS)
- break;
- i = CardServices(ParseTuple, handle, &tuple, &parse);
- if(i != CS_SUCCESS)
- break;
- link->conf.ConfigBase = parse.config.base;
- link->conf.Present = parse.config.rmask[0];
- }
- while(0);
- if(i != CS_SUCCESS)
- {
- cs_error(link->handle, ParseTuple, i);
- link->state &= ~DEV_CONFIG_PENDING;
- return FALSE;
- }
-
- /* Configure card */
- link->state |= DEV_CONFIG;
- do
- {
- i = CardServices(RequestIO, link->handle, &link->io);
- if(i != CS_SUCCESS)
- {
- cs_error(link->handle, RequestIO, i);
- break;
- }
- /*
- * Now allocate an interrupt line. Note that this does not
- * actually assign a handler to the interrupt.
- */
- i = CardServices(RequestIRQ, link->handle, &link->irq);
- if(i != CS_SUCCESS)
- {
- cs_error(link->handle, RequestIRQ, i);
- break;
- }
- /*
- * This actually configures the PCMCIA socket -- setting up
- * the I/O windows and the interrupt mapping.
- */
- link->conf.ConfigIndex = 1;
- i = CardServices(RequestConfiguration, link->handle, &link->conf);
- if(i != CS_SUCCESS)
- {
- cs_error(link->handle, RequestConfiguration, i);
- break;
- }
- /*
- * Allocate a small memory window. Note that the dev_link_t
- * structure provides space for one window handle -- if your
- * device needs several windows, you'll need to keep track of
- * the handles in your private data structure, link->priv.
- */
- req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
- req.Base = req.Size = 0;
- req.AccessSpeed = mem_speed;
- link->win = (window_handle_t)link->handle;
- i = CardServices(RequestWindow, &link->win, &req);
- if(i != CS_SUCCESS)
- {
- cs_error(link->handle, RequestWindow, i);
- break;
- }
- dev->rmem_start = dev->mem_start =
- (u_long)ioremap(req.Base, req.Size);
- dev->rmem_end = dev->mem_end = dev->mem_start + req.Size;
- mem.CardOffset = 0; mem.Page = 0;
- i = CardServices(MapMemPage, link->win, &mem);
- if(i != CS_SUCCESS)
- {
- cs_error(link->handle, MapMemPage, i);
- break;
- }
- /* Feed device with this info... */
- dev->irq = link->irq.AssignedIRQ;
- dev->base_addr = link->io.BasePort1;
- netif_start_queue(dev);
- #ifdef DEBUG_CONFIG_INFO
- printk(KERN_DEBUG "wv_pcmcia_config: MEMSTART 0x%x IRQ %d IOPORT 0x%xn",
- (u_int) dev->mem_start, dev->irq, (u_int) dev->base_addr);
- #endif
- i = register_netdev(dev);
- if(i != 0)
- {
- #ifdef DEBUG_CONFIG_ERRORS
- printk(KERN_INFO "wv_pcmcia_config(): register_netdev() failedn");
- #endif
- break;
- }
- }
- while(0); /* Humm... Disguised goto !!! */
- link->state &= ~DEV_CONFIG_PENDING;
- /* If any step failed, release any partially configured state */
- if(i != 0)
- {
- wv_pcmcia_release((u_long) link);
- return FALSE;
- }
- strcpy(((net_local *) dev->priv)->node.dev_name, dev->name);
- link->dev = &((net_local *) dev->priv)->node;
- #ifdef DEBUG_CONFIG_TRACE
- printk(KERN_DEBUG "<-wv_pcmcia_config()n");
- #endif
- return TRUE;
- }
- /*------------------------------------------------------------------*/
- /*
- * After a card is removed, wv_pcmcia_release() will unregister the net
- * device, and release the PCMCIA configuration. If the device is
- * still open, this will be postponed until it is closed.
- */
- static void
- wv_pcmcia_release(u_long arg) /* Address of the interface struct */
- {
- dev_link_t * link = (dev_link_t *) arg;
- device * dev = (device *) link->priv;
- #ifdef DEBUG_CONFIG_TRACE
- printk(KERN_DEBUG "%s: -> wv_pcmcia_release(0x%p)n", dev->name, link);
- #endif
- /* If the device is currently in use, we won't release until it is
- * actually closed. */
- if(link->open)
- {
- #ifdef DEBUG_CONFIG_INFO
- printk(KERN_DEBUG "%s: wv_pcmcia_release: release postponed, device still openn",
- dev->name);
- #endif
- link->state |= DEV_STALE_CONFIG;
- return;
- }
- /* Don't bother checking to see if these succeed or not */
- iounmap((u_char *)dev->mem_start);
- CardServices(ReleaseWindow, link->win);
- CardServices(ReleaseConfiguration, link->handle);
- CardServices(ReleaseIO, link->handle, &link->io);
- CardServices(ReleaseIRQ, link->handle, &link->irq);
- link->state &= ~(DEV_CONFIG | DEV_STALE_CONFIG);
- #ifdef DEBUG_CONFIG_TRACE
- printk(KERN_DEBUG "%s: <- wv_pcmcia_release()n", dev->name);
- #endif
- } /* wv_pcmcia_release */
- /*------------------------------------------------------------------*/
- /*
- * Sometimes, wavelan_detach can't be performed following a call from
- * cardmgr (device still open, pcmcia_release not done) and the device
- * is put in a STALE_LINK state and remains in memory.
- *
- * This function run through our current list of device and attempt
- * another time to remove them. We hope that since last time the
- * device has properly been closed.
- *
- * (called by wavelan_attach() & cleanup_module())
- */
- static void
- wv_flush_stale_links(void)
- {
- dev_link_t * link; /* Current node in linked list */
- dev_link_t * next; /* Next node in linked list */
- #ifdef DEBUG_CONFIG_TRACE
- printk(KERN_DEBUG "-> wv_flush_stale_links(0x%p)n", dev_list);
- #endif
- /* Go through the list */
- for (link = dev_list; link; link = next)
- {
- next = link->next;
- /* Check if in need of being removed */
- if((link->state & DEV_STALE_LINK) ||
- (! (link->state & DEV_PRESENT)))
- wavelan_detach(link);
- }
- #ifdef DEBUG_CONFIG_TRACE
- printk(KERN_DEBUG "<- wv_flush_stale_links()n");
- #endif
- }
- /************************ INTERRUPT HANDLING ************************/
- /*
- * This function is the interrupt handler for the WaveLAN card. This
- * routine will be called whenever:
- * 1. A packet is received.
- * 2. A packet has successfully been transferred and the unit is
- * ready to transmit another packet.
- * 3. A command has completed execution.
- */
- static void
- wavelan_interrupt(int irq,
- void * dev_id,
- struct pt_regs * regs)
- {
- device * dev;
- net_local * lp;
- ioaddr_t base;
- int status0;
- u_int tx_status;
- if((dev = (device *)dev_id) == (device *) NULL)
- {
- #ifdef DEBUG_INTERRUPT_ERROR
- printk(KERN_WARNING "wavelan_interrupt(): irq %d for unknown device.n",
- irq);
- #endif
- return;
- }
- #ifdef DEBUG_INTERRUPT_TRACE
- printk(KERN_DEBUG "%s: ->wavelan_interrupt()n", dev->name);
- #endif
- lp = (net_local *) dev->priv;
- base = dev->base_addr;
- #ifdef DEBUG_INTERRUPT_INFO
- /* Check state of our spinlock (it should be cleared) */
- if(spin_is_locked(&lp->spinlock))
- printk(KERN_DEBUG
- "%s: wavelan_interrupt(): spinlock is already locked !!!n",
- dev->name);
- #endif
- /* Prevent reentrancy. We need to do that because we may have
- * multiple interrupt handler running concurently.
- * It is safe because wv_splhi() disable interrupts before aquiring
- * the spinlock. */
- spin_lock(&lp->spinlock);
- /* Treat all pending interrupts */
- while(1)
- {
- /* ---------------- INTERRUPT CHECKING ---------------- */
- /*
- * Look for the interrupt and verify the validity
- */
- outb(CR0_STATUS_0 | OP0_NOP, LCCR(base));
- status0 = inb(LCSR(base));
- #ifdef DEBUG_INTERRUPT_INFO
- printk(KERN_DEBUG "status0 0x%x [%s => 0x%x]", status0,
- (status0&SR0_INTERRUPT)?"int":"no int",status0&~SR0_INTERRUPT);
- if(status0&SR0_INTERRUPT)
- {
- printk(" [%s => %d]n", (status0 & SR0_CHNL) ? "chnl" :
- ((status0 & SR0_EXECUTION) ? "cmd" :
- ((status0 & SR0_RECEPTION) ? "recv" : "unknown")),
- (status0 & SR0_EVENT_MASK));
- }
- else
- printk("n");
- #endif
- /* Return if no actual interrupt from i82593 (normal exit) */
- if(!(status0 & SR0_INTERRUPT))
- break;
- /* If interrupt is both Rx and Tx or none...
- * This code in fact is there to catch the spurious interrupt
- * when you remove the wavelan pcmcia card from the socket */
- if(((status0 & SR0_BOTH_RX_TX) == SR0_BOTH_RX_TX) ||
- ((status0 & SR0_BOTH_RX_TX) == 0x0))
- {
- #ifdef DEBUG_INTERRUPT_INFO
- printk(KERN_INFO "%s: wv_interrupt(): bogus interrupt (or from dead card) : %Xn",
- dev->name, status0);
- #endif
- /* Acknowledge the interrupt */
- outb(CR0_INT_ACK | OP0_NOP, LCCR(base));
- break;
- }
- /* ----------------- RECEIVING PACKET ----------------- */
- /*
- * When the wavelan signal the reception of a new packet,
- * we call wv_packet_rcv() to copy if from the buffer and
- * send it to NET3
- */
- if(status0 & SR0_RECEPTION)
- {
- #ifdef DEBUG_INTERRUPT_INFO
- printk(KERN_DEBUG "%s: wv_interrupt(): receiven", dev->name);
- #endif
- if((status0 & SR0_EVENT_MASK) == SR0_STOP_REG_HIT)
- {
- #ifdef DEBUG_INTERRUPT_ERROR
- printk(KERN_INFO "%s: wv_interrupt(): receive buffer overflown",
- dev->name);
- #endif
- lp->stats.rx_over_errors++;
- lp->overrunning = 1;
- }
- /* Get the packet */
- wv_packet_rcv(dev);
- lp->overrunning = 0;
- /* Acknowledge the interrupt */
- outb(CR0_INT_ACK | OP0_NOP, LCCR(base));
- continue;
- }
- /* ---------------- COMMAND COMPLETION ---------------- */
- /*
- * Interrupts issued when the i82593 has completed a command.
- * Most likely : transmission done
- */
- /* If a transmission has been done */
- if((status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_DONE ||
- (status0 & SR0_EVENT_MASK) == SR0_RETRANSMIT_DONE ||
- (status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_NO_CRC_DONE)
- {
- #ifdef DEBUG_TX_ERROR
- if((status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_NO_CRC_DONE)
- printk(KERN_INFO "%s: wv_interrupt(): packet transmitted without CRC.n",
- dev->name);
- #endif
- /* Get transmission status */
- tx_status = inb(LCSR(base));
- tx_status |= (inb(LCSR(base)) << 8);
- #ifdef DEBUG_INTERRUPT_INFO
- printk(KERN_DEBUG "%s: wv_interrupt(): transmission donen",
- dev->name);
- {
- u_int rcv_bytes;
- u_char status3;
- rcv_bytes = inb(LCSR(base));
- rcv_bytes |= (inb(LCSR(base)) << 8);
- status3 = inb(LCSR(base));
- printk(KERN_DEBUG "tx_status 0x%02x rcv_bytes 0x%02x status3 0x%xn",
- tx_status, rcv_bytes, (u_int) status3);
- }
- #endif
- /* Check for possible errors */
- if((tx_status & TX_OK) != TX_OK)
- {
- lp->stats.tx_errors++;
- if(tx_status & TX_FRTL)
- {
- #ifdef DEBUG_TX_ERROR
- printk(KERN_INFO "%s: wv_interrupt(): frame too longn",
- dev->name);
- #endif
- }
- if(tx_status & TX_UND_RUN)
- {
- #ifdef DEBUG_TX_FAIL
- printk(KERN_DEBUG "%s: wv_interrupt(): DMA underrunn",
- dev->name);
- #endif
- lp->stats.tx_aborted_errors++;
- }
- if(tx_status & TX_LOST_CTS)
- {
- #ifdef DEBUG_TX_FAIL
- printk(KERN_DEBUG "%s: wv_interrupt(): no CTSn", dev->name);
- #endif
- lp->stats.tx_carrier_errors++;
- }
- if(tx_status & TX_LOST_CRS)
- {
- #ifdef DEBUG_TX_FAIL
- printk(KERN_DEBUG "%s: wv_interrupt(): no carriern",
- dev->name);
- #endif
- lp->stats.tx_carrier_errors++;
- }
- if(tx_status & TX_HRT_BEAT)
- {
- #ifdef DEBUG_TX_FAIL
- printk(KERN_DEBUG "%s: wv_interrupt(): heart beatn", dev->name);
- #endif
- lp->stats.tx_heartbeat_errors++;
- }
- if(tx_status & TX_DEFER)
- {
- #ifdef DEBUG_TX_FAIL
- printk(KERN_DEBUG "%s: wv_interrupt(): channel jammedn",
- dev->name);
- #endif
- }
- /* Ignore late collisions since they're more likely to happen
- * here (the WaveLAN design prevents the LAN controller from
- * receiving while it is transmitting). We take action only when
- * the maximum retransmit attempts is exceeded.
- */
- if(tx_status & TX_COLL)
- {
- if(tx_status & TX_MAX_COL)
- {
- #ifdef DEBUG_TX_FAIL
- printk(KERN_DEBUG "%s: wv_interrupt(): channel congestionn",
- dev->name);
- #endif
- if(!(tx_status & TX_NCOL_MASK))
- {
- lp->stats.collisions += 0x10;
- }
- }
- }
- } /* if(!(tx_status & TX_OK)) */
- lp->stats.collisions += (tx_status & TX_NCOL_MASK);
- lp->stats.tx_packets++;
- netif_wake_queue(dev);
- outb(CR0_INT_ACK | OP0_NOP, LCCR(base)); /* Acknowledge the interrupt */
- }
- else /* if interrupt = transmit done or retransmit done */
- {
- #ifdef DEBUG_INTERRUPT_ERROR
- printk(KERN_INFO "wavelan_cs: unknown interrupt, status0 = %02xn",
- status0);
- #endif
- outb(CR0_INT_ACK | OP0_NOP, LCCR(base)); /* Acknowledge the interrupt */
- }
- } /* while(1) */
- spin_unlock(&lp->spinlock);
- #ifdef DEBUG_INTERRUPT_TRACE
- printk(KERN_DEBUG "%s: <-wavelan_interrupt()n", dev->name);
- #endif
- } /* wv_interrupt */
- /*------------------------------------------------------------------*/
- /*
- * Watchdog: when we start a transmission, a timer is set for us in the
- * kernel. If the transmission completes, this timer is disabled. If
- * the timer expires, we are called and we try to unlock the hardware.
- *
- * Note : This watchdog is move clever than the one in the ISA driver,
- * because it try to abort the current command before reseting
- * everything...
- * On the other hand, it's a bit simpler, because we don't have to
- * deal with the multiple Tx buffers...
- */
- static void
- wavelan_watchdog(device * dev)
- {
- net_local * lp = (net_local *) dev->priv;
- ioaddr_t base = dev->base_addr;
- unsigned long flags;
- int aborted = FALSE;
- #ifdef DEBUG_INTERRUPT_TRACE
- printk(KERN_DEBUG "%s: ->wavelan_watchdog()n", dev->name);
- #endif
- #ifdef DEBUG_INTERRUPT_ERROR
- printk(KERN_INFO "%s: wavelan_watchdog: watchdog timer expiredn",
- dev->name);
- #endif
- wv_splhi(lp, &flags);
- /* Ask to abort the current command */
- outb(OP0_ABORT, LCCR(base));
- /* Wait for the end of the command (a bit hackish) */
- if(wv_82593_cmd(dev, "wavelan_watchdog(): abort",
- OP0_NOP | CR0_STATUS_3, SR0_EXECUTION_ABORTED))
- aborted = TRUE;
- /* Release spinlock here so that wv_hw_reset() can grab it */
- wv_splx(lp, &flags);
- /* Check if we were successful in aborting it */
- if(!aborted)
- {
- /* It seem that it wasn't enough */
- #ifdef DEBUG_INTERRUPT_ERROR
- printk(KERN_INFO "%s: wavelan_watchdog: abort failed, trying resetn",
- dev->name);
- #endif
- wv_hw_reset(dev);
- }
- #ifdef DEBUG_PSA_SHOW
- {
- psa_t psa;
- psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
- wv_psa_show(&psa);
- }
- #endif
- #ifdef DEBUG_MMC_SHOW
- wv_mmc_show(dev);
- #endif
- #ifdef DEBUG_I82593_SHOW
- wv_ru_show(dev);
- #endif
- /* We are no more waiting for something... */
- netif_wake_queue(dev);
- #ifdef DEBUG_INTERRUPT_TRACE
- printk(KERN_DEBUG "%s: <-wavelan_watchdog()n", dev->name);
- #endif
- }
- /********************* CONFIGURATION CALLBACKS *********************/
- /*
- * Here are the functions called by the pcmcia package (cardmgr) and
- * linux networking (NET3) for initialization, configuration and
- * deinstallations of the Wavelan Pcmcia Hardware.
- */
- /*------------------------------------------------------------------*/
- /*
- * Configure and start up the WaveLAN PCMCIA adaptor.
- * Called by NET3 when it "open" the device.
- */
- static int
- wavelan_open(device * dev)
- {
- dev_link_t * link = ((net_local *) dev->priv)->link;
- net_local * lp = (net_local *)dev->priv;
- ioaddr_t base = dev->base_addr;
- #ifdef DEBUG_CALLBACK_TRACE
- printk(KERN_DEBUG "%s: ->wavelan_open(dev=0x%x)n", dev->name,
- (unsigned int) dev);
- #endif
- /* Check if the modem is powered up (wavelan_close() power it down */
- if(hasr_read(base) & HASR_NO_CLK)
- {
- /* Power up (power up time is 250us) */
- hacr_write(base, HACR_DEFAULT);
- /* Check if the module has been powered up... */
- if(hasr_read(base) & HASR_NO_CLK)
- {
- #ifdef DEBUG_CONFIG_ERRORS
- printk(KERN_WARNING "%s: wavelan_open(): modem not connectedn",
- dev->name);
- #endif
- return FALSE;
- }
- }
- /* Start reception and declare the driver ready */
- if(!lp->configured)
- return FALSE;
- if(!wv_ru_start(dev))
- wv_hw_reset(dev); /* If problem : reset */
- netif_start_queue(dev);
- /* Mark the device as used */
- link->open++;
- MOD_INC_USE_COUNT;
- #ifdef WAVELAN_ROAMING
- if(do_roaming)
- wv_roam_init(dev);
- #endif /* WAVELAN_ROAMING */
- #ifdef DEBUG_CALLBACK_TRACE
- printk(KERN_DEBUG "%s: <-wavelan_open()n", dev->name);
- #endif
- return 0;
- }
- /*------------------------------------------------------------------*/
- /*
- * Shutdown the WaveLAN PCMCIA adaptor.
- * Called by NET3 when it "close" the device.
- */
- static int
- wavelan_close(device * dev)
- {
- dev_link_t * link = ((net_local *) dev->priv)->link;
- ioaddr_t base = dev->base_addr;
- #ifdef DEBUG_CALLBACK_TRACE
- printk(KERN_DEBUG "%s: ->wavelan_close(dev=0x%x)n", dev->name,
- (unsigned int) dev);
- #endif
- /* If the device isn't open, then nothing to do */
- if(!link->open)
- {
- #ifdef DEBUG_CONFIG_INFO
- printk(KERN_DEBUG "%s: wavelan_close(): device not openn", dev->name);
- #endif
- return 0;
- }
- #ifdef WAVELAN_ROAMING
- /* Cleanup of roaming stuff... */
- if(do_roaming)
- wv_roam_cleanup(dev);
- #endif /* WAVELAN_ROAMING */
- link->open--;
- MOD_DEC_USE_COUNT;
- /* If the card is still present */
- if(netif_running(dev))
- {
- netif_stop_queue(dev);
- /* Stop receiving new messages and wait end of transmission */
- wv_ru_stop(dev);
- /* Power down the module */
- hacr_write(base, HACR_DEFAULT & (~HACR_PWR_STAT));
- }
- else
- /* The card is no more there (flag is activated in wv_pcmcia_release) */
- if(link->state & DEV_STALE_CONFIG)
- wv_pcmcia_release((u_long)link);
- #ifdef DEBUG_CALLBACK_TRACE
- printk(KERN_DEBUG "%s: <-wavelan_close()n", dev->name);
- #endif
- return 0;
- }
- /*------------------------------------------------------------------*/
- /*
- * wavelan_attach() creates an "instance" of the driver, allocating
- * local data structures for one device (one interface). The device
- * is registered with Card Services.
- *
- * The dev_link structure is initialized, but we don't actually
- * configure the card at this point -- we wait until we receive a
- * card insertion event.
- */
- static dev_link_t *
- wavelan_attach(void)
- {
- client_reg_t client_reg; /* Register with cardmgr */
- dev_link_t * link; /* Info for cardmgr */
- device * dev; /* Interface generic data */
- net_local * lp; /* Interface specific data */
- int i, ret;
- #ifdef DEBUG_CALLBACK_TRACE
- printk(KERN_DEBUG "-> wavelan_attach()n");
- #endif
- /* Perform some cleanup */
- wv_flush_stale_links();
- /* Initialize the dev_link_t structure */
- link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
- if (!link) return NULL;
- memset(link, 0, sizeof(struct dev_link_t));
- /* Unused for the Wavelan */
- link->release.function = &wv_pcmcia_release;
- link->release.data = (u_long) link;
- /* The io structure describes IO port mapping */
- link->io.NumPorts1 = 8;
- link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
- link->io.IOAddrLines = 3;
- /* Interrupt setup */
- link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
- link->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_LEVEL_ID;
- if (irq_list[0] == -1)
- link->irq.IRQInfo2 = irq_mask;
- else
- for (i = 0; i < 4; i++)
- link->irq.IRQInfo2 |= 1 << irq_list[i];
- link->irq.Handler = wavelan_interrupt;
- /* General socket configuration */
- link->conf.Attributes = CONF_ENABLE_IRQ;
- link->conf.Vcc = 50;
- link->conf.IntType = INT_MEMORY_AND_IO;
- /* Chain drivers */
- link->next = dev_list;
- dev_list = link;
- /* Allocate the generic data structure */
- dev = kmalloc(sizeof(struct net_device), GFP_KERNEL);
- if (!dev) {
- kfree(link);
- return NULL;
- }
- memset(dev, 0x00, sizeof(struct net_device));
- link->priv = link->irq.Instance = dev;
- /* Allocate the wavelan-specific data structure. */
- dev->priv = lp = (net_local *) kmalloc(sizeof(net_local), GFP_KERNEL);
- if (!lp) {
- kfree(link);
- kfree(dev);
- return NULL;
- }
- memset(lp, 0x00, sizeof(net_local));
- /* Init specific data */
- lp->configured = 0;
- lp->reconfig_82593 = FALSE;
- lp->nresets = 0;
- /* Multicast stuff */
- lp->promiscuous = 0;
- lp->allmulticast = 0;
- lp->mc_count = 0;
- /* Init spinlock */
- spin_lock_init(&lp->spinlock);
- /* back links */
- lp->link = link;
- lp->dev = dev;
- /* Standard setup for generic data */
- ether_setup(dev);
- /* wavelan NET3 callbacks */
- dev->open = &wavelan_open;
- dev->stop = &wavelan_close;
- dev->hard_start_xmit = &wavelan_packet_xmit;
- dev->get_stats = &wavelan_get_stats;
- dev->set_multicast_list = &wavelan_set_multicast_list;
- #ifdef SET_MAC_ADDRESS
- dev->set_mac_address = &wavelan_set_mac_address;
- #endif /* SET_MAC_ADDRESS */
- /* Set the watchdog timer */
- dev->tx_timeout = &wavelan_watchdog;
- dev->watchdog_timeo = WATCHDOG_JIFFIES;
- #ifdef WIRELESS_EXT /* If wireless extension exist in the kernel */
- dev->do_ioctl = wavelan_ioctl; /* wireless extensions */
- dev->get_wireless_stats = wavelan_get_wireless_stats;
- #endif
- /* Other specific data */
- dev->mtu = WAVELAN_MTU;
- /* Register with Card Services */
- client_reg.dev_info = &dev_info;
- client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
- client_reg.EventMask =
- CS_EVENT_REGISTRATION_COMPLETE |
- CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
- CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
- CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
- client_reg.event_handler = &wavelan_event;
- client_reg.Version = 0x0210;
- client_reg.event_callback_args.client_data = link;
- #ifdef DEBUG_CONFIG_INFO
- printk(KERN_DEBUG "wavelan_attach(): almost done, calling CardServicesn");
- #endif
- ret = CardServices(RegisterClient, &link->handle, &client_reg);
- if(ret != 0)
- {
- cs_error(link->handle, RegisterClient, ret);
- wavelan_detach(link);
- return NULL;
- }
- #ifdef DEBUG_CALLBACK_TRACE
- printk(KERN_DEBUG "<- wavelan_attach()n");
- #endif
- return link;
- }
- /*------------------------------------------------------------------*/
- /*
- * This deletes a driver "instance". The device is de-registered with
- * Card Services. If it has been released, all local data structures
- * are freed. Otherwise, the structures will be freed when the device
- * is released.
- */
- static void
- wavelan_detach(dev_link_t * link)
- {
- #ifdef DEBUG_CALLBACK_TRACE
- printk(KERN_DEBUG "-> wavelan_detach(0x%p)n", link);
- #endif
- /*
- * If the device is currently configured and active, we won't
- * actually delete it yet. Instead, it is marked so that when the
- * release() function is called, that will trigger a proper
- * detach().
- */
- if(link->state & DEV_CONFIG)
- {
- /* Some others haven't done their job : give them another chance */
- wv_pcmcia_release((u_long) link);
- if(link->state & DEV_STALE_CONFIG)
- {
- #ifdef DEBUG_CONFIG_INFO
- printk(KERN_DEBUG "wavelan_detach: detach postponed,"
- " '%s' still lockedn", link->dev->dev_name);
- #endif
- link->state |= DEV_STALE_LINK;
- return;
- }
- }
- /* Break the link with Card Services */
- if(link->handle)
- CardServices(DeregisterClient, link->handle);
-
- /* Remove the interface data from the linked list */
- if(dev_list == link)
- dev_list = link->next;
- else
- {
- dev_link_t * prev = dev_list;
- while((prev != (dev_link_t *) NULL) && (prev->next != link))
- prev = prev->next;
- if(prev == (dev_link_t *) NULL)
- {
- #ifdef DEBUG_CONFIG_ERRORS
- printk(KERN_WARNING "wavelan_detach : Attempting to remove a nonexistent device.n");
- #endif
- return;
- }
- prev->next = link->next;
- }
- /* Free pieces */
- if(link->priv)
- {
- device * dev = (device *) link->priv;
- /* Remove ourselves from the kernel list of ethernet devices */
- /* Warning : can't be called from interrupt, timer or wavelan_close() */
- if(link->dev != NULL)
- unregister_netdev(dev);
- link->dev = NULL;
- if(dev->priv)
- {
- /* Sound strange, but safe... */
- ((net_local *) dev->priv)->link = (dev_link_t *) NULL;
- ((net_local *) dev->priv)->dev = (device *) NULL;
- kfree(dev->priv);
- }
- kfree(link->priv);
- }
- kfree(link);
- #ifdef DEBUG_CALLBACK_TRACE
- printk(KERN_DEBUG "<- wavelan_detach()n");
- #endif
- }
- /*------------------------------------------------------------------*/
- /*
- * The card status event handler. Mostly, this schedules other stuff
- * to run after an event is received. A CARD_REMOVAL event also sets
- * some flags to discourage the net drivers from trying to talk to the
- * card any more.
- */
- static int
- wavelan_event(event_t event, /* The event received */
- int priority,
- event_callback_args_t * args)
- {
- dev_link_t * link = (dev_link_t *) args->client_data;
- device * dev = (device *) link->priv;
- #ifdef DEBUG_CALLBACK_TRACE
- printk(KERN_DEBUG "->wavelan_event(): %sn",
- ((event == CS_EVENT_REGISTRATION_COMPLETE)?"registration complete" :
- ((event == CS_EVENT_CARD_REMOVAL) ? "card removal" :
- ((event == CS_EVENT_CARD_INSERTION) ? "card insertion" :
- ((event == CS_EVENT_PM_SUSPEND) ? "pm suspend" :
- ((event == CS_EVENT_RESET_PHYSICAL) ? "physical reset" :
- ((event == CS_EVENT_PM_RESUME) ? "pm resume" :
- ((event == CS_EVENT_CARD_RESET) ? "card reset" :
- "unknown"))))))));
- #endif
- switch(event)
- {
- case CS_EVENT_REGISTRATION_COMPLETE:
- #ifdef DEBUG_CONFIG_INFO
- printk(KERN_DEBUG "wavelan_cs: registration completen");
- #endif
- break;
- case CS_EVENT_CARD_REMOVAL:
- /* Oups ! The card is no more there */
- link->state &= ~DEV_PRESENT;
- if(link->state & DEV_CONFIG)
- {
- /* Accept no more transmissions */
- netif_device_detach(dev);
- /* Release the card */
- wv_pcmcia_release((u_long) link);
- }
- break;
- case CS_EVENT_CARD_INSERTION:
- /* Reset and configure the card */
- link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
- if(wv_pcmcia_config(link) &&
- wv_hw_config(dev))
- wv_init_info(dev);
- else
- dev->irq = 0;
- break;
- case CS_EVENT_PM_SUSPEND:
- /* NB: wavelan_close will be called, but too late, so we are
- * obliged to close nicely the wavelan here. David, could you
- * close the device before suspending them ? And, by the way,
- * could you, on resume, add a "route add -net ..." after the
- * ifconfig up ? Thanks... */
- /* Stop receiving new messages and wait end of transmission */
- wv_ru_stop(dev);
- /* Power down the module */
- hacr_write(dev->base_addr, HACR_DEFAULT & (~HACR_PWR_STAT));
- /* The card is now suspended */
- link->state |= DEV_SUSPEND;
- /* Fall through... */
- case CS_EVENT_RESET_PHYSICAL:
- if(link->state & DEV_CONFIG)
- {
- if(link->open)
- netif_device_detach(dev);
- CardServices(ReleaseConfiguration, link->handle);
- }
- break;
- case CS_EVENT_PM_RESUME:
- link->state &= ~DEV_SUSPEND;
- /* Fall through... */
- case CS_EVENT_CARD_RESET:
- if(link->state & DEV_CONFIG)
- {
- CardServices(RequestConfiguration, link->handle, &link->conf);
- if(link->open) /* If RESET -> True, If RESUME -> False ? */
- {
- wv_hw_reset(dev);
- netif_device_attach(dev);
- }
- }
- break;
- }
- #ifdef DEBUG_CALLBACK_TRACE
- printk(KERN_DEBUG "<-wavelan_event()n");
- #endif
- return 0;
- }
- /****************************** MODULE ******************************/
- /*
- * Module entry points : insertion & removal
- */
- /*------------------------------------------------------------------*/
- /*
- * Module insertion : initialisation of the module.
- * Register the card with cardmgr...
- */
- static int __init
- init_wavelan_cs(void)
- {
- servinfo_t serv;
- #ifdef DEBUG_MODULE_TRACE
- printk(KERN_DEBUG "-> init_wavelan_cs()n");
- #ifdef DEBUG_VERSION_SHOW
- printk(KERN_DEBUG "%s", version);
- #endif
- #endif
- CardServices(GetCardServicesInfo, &serv);
- if(serv.Revision != CS_RELEASE_CODE)
- {
- #ifdef DEBUG_CONFIG_ERRORS
- printk(KERN_WARNING "init_wavelan_cs: Card Services release does not match!n");
- #endif
- return -1;
- }
- register_pccard_driver(&dev_info, &wavelan_attach, &wavelan_detach);
- #ifdef DEBUG_MODULE_TRACE
- printk(KERN_DEBUG "<- init_wavelan_cs()n");
- #endif
- return 0;
- }
- /*------------------------------------------------------------------*/
- /*
- * Module removal
- */
- static void __exit
- exit_wavelan_cs(void)
- {
- #ifdef DEBUG_MODULE_TRACE
- printk(KERN_DEBUG "-> cleanup_module()n");
- #endif
- #ifdef DEBUG_BASIC_SHOW
- printk(KERN_NOTICE "wavelan_cs: unloadingn");
- #endif
- /* Do some cleanup of the device list */
- wv_flush_stale_links();
- /* If there remain some devices... */
- #ifdef DEBUG_CONFIG_ERRORS
- if(dev_list != NULL)
- {
- /* Honestly, if this happen we are in a deep s**t */
- printk(KERN_INFO "wavelan_cs: devices remaining when removing modulen");
- printk(KERN_INFO "Please flush your disks and reboot NOW !n");
- }
- #endif
- unregister_pccard_driver(&dev_info);
- #ifdef DEBUG_MODULE_TRACE
- printk(KERN_DEBUG "<- cleanup_module()n");
- #endif
- }
- module_init(init_wavelan_cs);
- module_exit(exit_wavelan_cs);
- /* Note : Modules parameters are in wavelan_cs.h - Jean II */