/**************************************************************** * This driver can only be compiled as a module and it * can only be loaded ONCE per system. There is no * support yet for multiple cards with one driver. * Check the README for a suggestion to experiment with. * * This driver does not support probing. To change irq * or io port at runtime enter the following: * insmod rl2mod irq=x io=y * This isn't necessary for PC Cards or PCI cards * * *****************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef KERNEL_VERSION #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) <<8) + (c)) #endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0) #include #endif #ifdef CONFIG_PCI #include #endif #ifdef PCCARD #include #include #include #include #include #include #include #include #include #endif /* PCCARD */ #include #include #include #ifdef CONFIG_NET_RADIO /* If wireless extension exist in the kernel */ #include #endif /* CONFIG_NET_RADIO */ #include "lld.h" #include "proxcfg.h" #include "lls.h" #include "version.h" /**************************************************************** * some version dependent stuff * * *****************************************************************/ #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,59) #define DEV_FREE_SKB(skb) dev_kfree_skb(skb, FREE_WRITE); #else #define DEV_FREE_SKB(skb) dev_kfree_skb(skb); #endif #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,23) #define test_and_set_bit(val, addr) set_bit(val, addr) #define copy_to_user memcpy_tofs #define copy_from_user memcpy_fromfs #endif /**************************************************************** * some LLD structures for use by send routine * * *****************************************************************/ #ifdef BUFFER static struct LLS_Buffers { struct LLDTxPacketDescriptor txDesc; struct LLDTxFragmentList txFragList; struct sk_buff *save_skbuff_ptr; } bfr_list[LLDMAXSEND]; int ring; #else static struct LLDTxPacketDescriptor txDesc; /* save pointer for release in LLSSendComplete */ static struct sk_buff *saveptr; static struct LLDTxFragmentList txFragList; #endif /* BUFFER */ #ifdef PCCARD /**************************************************************** * PC CARD declarations. The code is towards the end * * *****************************************************************/ /* Parameters that can be set with 'insmod' */ /* The old way: bit map of interrupts to choose from */ /* This means pick from 15, 14, 12, 11, 10, 9, 7, 5, 4, and 3 */ static u_int irq_mask = 0xdeb8; /* Newer, simpler way of listing specific interrupts */ static int irq_list[4] = { -1 }; MODULE_PARM(irq_mask, "i"); MODULE_PARM(irq_list, "1-4i"); /* All the PCMCIA modules use PCMCIA_DEBUG to control debugging. If you do not define PCMCIA_DEBUG at all, all the debug code will be left out. If you compile with PCMCIA_DEBUG=0, the debug code will be present but disabled -- but it can then be enabled for specific modules at load time with a 'pc_debug=#' option to insmod. */ #ifdef PCMCIA_DEBUG static int pc_debug = PCMCIA_DEBUG; MODULE_PARM(pc_debug, "i"); #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args); static char *versionpc = "adapted from dummy_cs.c 1.9 1998/07/16 23:44:06 (David Hinds)"; #else #define DEBUG(n, args...) #endif /* PCMCIA_DEBUG */ /*====================================================================*/ /* The event() function is this driver's Card Services event handler. It will be called by Card Services when an appropriate card status event is received. The config() and release() entry points are used to configure or release a socket, in response to card insertion and ejection events. They are invoked from the event handler. */ static void rl2_config(dev_link_t *link); static void rl2_release(u_long arg); static int rl2_event(event_t event, int priority, event_callback_args_t *args); /* The attach() and detach() entry points are used to create and destroy "instances" of the driver, where each instance represents everything needed to manage one actual PCMCIA card. */ static dev_link_t *rl2_attach(void); static void rl2_detach(dev_link_t *); /* You'll also need to prototype all the functions that will actually be used to talk to your device. See 'pcmem_cs' for a good example of a fully self-sufficient driver; the other drivers rely more or less on other parts of the kernel. */ /* The dev_info variable is the "key" that is used to match up this device driver with appropriate cards, through the card configuration database. */ static dev_info_t dev_info = "rlmod"; /* A linked list of "instances" of the dummy device. Each actual PCMCIA card corresponds to one device instance, and is described by one dev_link_t structure (defined in ds.h). You may not want to use a linked list for this -- for example, the memory card driver uses an array of dev_link_t pointers, where minor device numbers are used to derive the corresponding array index. */ static dev_link_t *dev_list = NULL; /* A dev_link_t structure has fields for most things that are needed to keep track of a socket, but there will usually be some device specific information that also needs to be kept track of. The 'priv' pointer in a dev_link_t structure can be used to point to a device-specific private data structure, like this. A driver needs to provide a dev_node_t structure for each device on a card. In some cases, there is only one device per card (for example, ethernet cards, modems). In other cases, there may be many actual or logical devices (SCSI adapters, memory cards with multiple partitions). The dev_node_t structures need to be kept in a linked list starting at the 'dev' field of a dev_link_t structure. We allocate them in the card's private data structure, because they generally shouldn't be allocated dynamically. In this case, we also provide a flag to indicate if a device is "stopped" due to a power management event, or card ejection. The device IO routines can use a flag like this to throttle IO to a card that is not ready to accept it. */ typedef struct local_info_t { dev_node_t node; int stop; } local_info_t; #endif /* PCCARD */ /**************************************************************** ***************************************************************** * LLS Routines Required by the LLD * * ***************************************************************** *****************************************************************/ void LLSReceiveLookAhead (unsigned_8 *Buffer, unsigned_16 Length, unsigned_16 Status, unsigned_16 RSSI) { struct LLDRxPacketDescriptor rxDesc; struct sk_buff *skb; struct net_local *lp = thisRangeLan.priv; int i; #ifdef WIRELESS_EXT lp->wstats.qual.level = RSSI; #endif /* WIRELESS_EXT */ /* allocate the buffer for the kernel */ skb=dev_alloc_skb(Length); if(skb==NULL) { lp->stats.rx_dropped++; return; } /* prepare a 1-item fragment list for LLD */ rxDesc.LLDRxFragCount = 1; rxDesc.LLDRxFragList[0].FSDataLen = Length; rxDesc.LLDRxFragList[0].FSDataPtr = skb->data; /* retrieve whole packet from LLD */ LLDReceive(&rxDesc,0,Length); /* load up the other elements for the kernel */ skb->len=Length; skb->dev=&thisRangeLan; skb->protocol=eth_type_trans(skb,&thisRangeLan); /* increments the stats count */ lp->stats.rx_packets++; #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0) lp->stats.rx_bytes += Length; #endif /* tell linux we have a packet*/ netif_rx(skb); } unsigned_16 LLSSendComplete (struct LLDTxPacketDescriptor *PktDesc) { struct net_local *lp = thisRangeLan.priv; int i; #ifdef BUFFER i = PktDesc->LLDTxdriverWS[1]; if (bfr_list[i].txDesc.LLDTxdriverWS[0] == CLEAR) {RL2DEBUG("buffer wasn't used!\n");} else { /* note the successful transmission */ lp->attempted_tx_packets++; #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0) lp->stats.tx_bytes += bfr_list[i].save_skbuff_ptr->len; #endif /* free up the kernel buffer and the buffer structure element */ DEV_FREE_SKB(bfr_list[i].save_skbuff_ptr); bfr_list[i].txDesc.LLDTxdriverWS[0] = CLEAR; /* send completed, free up the resources */ /* only check for equality, though. Otherwise, rl2_start_xmit */ /* can be reentrant, i.e., don't want to set tbusy=0 if _start_xmit */ /* needs it =1. */ if(LLDMAXSEND-1 == outcount--) { thisRangeLan.tbusy = CLEAR; mark_bh(NET_BH); } } #else /* note the successful transmission */ lp->attempted_tx_packets++; #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0) lp->stats.tx_bytes += bfr_list[i].save_skbuff_ptr->len; #endif /* free the SKB and let upper layer know we sent the packet */ DEV_FREE_SKB(saveptr); thisRangeLan.tbusy = CLEAR; mark_bh(NET_BH); #endif } unsigned_8 LLSRegisterInterrupt (unsigned_8 IntNum, void (*CallBackFunc) ()) { unsigned_16 interruptStatus; if (CardType != SYMPCI) { if(request_irq(IntNum, &rl2_interrupt, 0, thisRangeLan.name, &thisRangeLan)) { return FAILURE; } } #ifdef CONFIG_PCI else { if(request_irq(IntNum, &rl2_interrupt, SA_SHIRQ, thisRangeLan.name, &thisRangeLan)) { return FAILURE; } /* sometimes the card warm boots without the interrupt having been reset this forces it. Otherwise it can be annoying to reload the module once in a while. */ interruptStatus = _inpw(LLDIOAddress2+INTERRUPT_REGISTER); _outpw(LLDIOAddress2+INTERRUPT_REGISTER, interruptStatus | INTERRUPT_CLEAR); } #endif /* CONFIG_PCI */ return SUCCESS; } unsigned_8 LLSDeRegisterInterrupt (unsigned_8 IntNum) { free_irq(thisRangeLan.irq, &thisRangeLan); return SUCCESS; } unsigned_16 LLSGetCurrentTime (void) { /* just system ticks for use by the CLLD. The library assumes HZ =100. This should fix it if you've changed HZ for your system */ return(jiffies*LIB_HZ/HZ); } unsigned_32 LLSGetCurrentTimeLONG (void) { /* just system ticks for use by the CLLD. The library assumes HZ =100. This should fix it if you've changed HZ for your system */ return(jiffies*LIB_HZ/HZ); } void LLSRawReceiveLookAhead (unsigned_8 Buffer[], unsigned int Length) { /* for processing raw packetized-command responses from the card */ LLDRawProcess (Buffer, Length); } /**************************************************************** * These 3 LLS routines shouldn't be called but are * included since the linker will expect them * * *****************************************************************/ unsigned_16 LLSRawSendComplete (unsigned_8 *Buffer) { RL2DEBUG("%s: RawSendComplete\n", thisRangeLan.name); } void LLSPingReceiveLookAhead (unsigned_8 *Buffer, unsigned_16 Length, unsigned_16 Status, unsigned_16 RSSI) { int i; RL2DEBUG("%s: PingReceiveLookAhead, Length=%d, Status=%d\n", thisRangeLan.name, Length, Status); printk("%s: Ping response from: ", thisRangeLan.name); for(i=6;i<11;i++) printk("%2.2x:", Buffer[i]); printk("%2.2x\n", Buffer[i]); } unsigned_16 LLSSendProximPktComplete (struct LLDTxPacketDescriptor FAR *PktDesc, unsigned_8 Status) { RL2DEBUG("%s: LLSSendProximPktComplete, %d\n", thisRangeLan.name, Status); } /**************************************************************** ***************************************************************** * Linux-required routines start here. These routines * will make use of the LLD routines in CLLD and do * the kernel registration, init, close, etc. * * ***************************************************************** *****************************************************************/ static int rl2_ioctl(struct device *dev, struct ifreq *rq, int cmd) { #ifdef WIRELESS_EXT /* If wireless extension exist in the kernel */ struct iwreq * wrq = (struct iwreq *) rq; #endif /* WIRELESS_EXT */ struct rl2_ioctl_info *ioc = (struct rl2_ioctl_info *) &rq->ifr_data; int i, ret = 0; /* support proxcfg to be backward compatible */ if (cmd == SIOCDEVPRIVATE) { switch(ioc->cmd) { case SET_LLDRESET: if(!suser()) return -EPERM; LLDNeedReset = SET; break; case SET_NODETYPE: if(!suser()) return -EPERM; LLDNodeType = (unsigned_8) *ioc->data; printk(KERN_NOTICE "%s: Node type changed: %s.\n", thisRangeLan.name, nodetypes[LLDNodeType]); break; case GET_NODETYPE: *ioc->data = LLDNodeType; break; case SET_DOMAIN: if(!suser()) return -EPERM; LLDDomain = (unsigned_8) *ioc->data; printk(KERN_NOTICE "%s: Domain changed: %d.\n", thisRangeLan.name, LLDDomain); break; case GET_DOMAIN: *ioc->data = LLDDomain; break; case SET_SECID: if(!suser()) return -EPERM; if(!HomeRF) printk(KERN_NOTICE "%s: Set Security ID: ", thisRangeLan.name); else printk(KERN_NOTICE "%s: Set Network ID: ", thisRangeLan.name); if(LLDSendSetSecurityID(ioc->data)) printk("failed.\n"); else printk("successful.\n"); break; case SET_CHANNEL: if(!suser()) return -EPERM; LLDChannel = (unsigned_8) *ioc->data; printk(KERN_NOTICE "%s: Channel changed: %d.\n", thisRangeLan.name, LLDChannel); break; case GET_CHANNEL: *ioc->data = LLDChannel; break; case SET_SUBCHANNEL: if(!suser()) return -EPERM; LLDSubChannel = (unsigned_8) *ioc->data; printk(KERN_NOTICE "%s: Subchannel changed: %d.\n", thisRangeLan.name, LLDSubChannel); break; case GET_SUBCHANNEL: *ioc->data = LLDSubChannel; break; case SET_MASTERNAME: if(!suser()) return -EPERM; strcpy(LLDMSTAName, ioc->data); printk(KERN_NOTICE "%s: Master name changed: %s.\n", thisRangeLan.name, LLDMSTAName); break; case GET_MASTERNAME: strcpy(ioc->data, LLDMSTAName); break; case SET_ROAM_CONFIG: if(!suser()) return -EPERM; LLDRoamConfig(LLDRoamConfiguration=(unsigned_8) *ioc->data); printk(KERN_NOTICE "%s: Roam configuration changed: %s.\n", thisRangeLan.name, roamtypes[LLDRoamConfiguration]); break; case GET_ROAM_CONFIG: *ioc->data = LLDRoamConfiguration; break; case SET_MAC_OPT: if(!suser()) return -EPERM; LLDMacOptimize(LLDMacOptimizeVal=(unsigned_8) *ioc->data); printk(KERN_NOTICE "%s: MAC Optimize changed: %s.\n", thisRangeLan.name, macconfigtypes[LLDMacOptimizeVal]); break; case GET_MAC_OPT: *ioc->data = LLDMacOptimizeVal; break; case SET_DEBUG: if(!suser()) return -EPERM; if (rl2_debug = (unsigned_8) *ioc->data) { RL2DEBUG("%s: Debugging enabled.\n", thisRangeLan.name); } else { RL2DEBUG("%s: This notice doesn't show.\n", thisRangeLan.name); printk(KERN_INFO "%s: Debugging disabled.\n", thisRangeLan.name); } break; case GET_DEBUG: *ioc->data = rl2_debug; break; case SET_PEER_TO_PEER: if(!suser()) return -EPERM; LLDPeerToPeerFlag = (unsigned_8) *ioc->data; printk(KERN_NOTICE "%s: Peer to Peer: ", thisRangeLan.name); if(LLDPeerToPeerFlag) printk("enabled\n"); else printk("disabled\n"); break; case GET_PEER_TO_PEER: *ioc->data = LLDPeerToPeerFlag; break; case SET_DISABLE_ROAM: if(!suser()) return -EPERM; LLDRoamingFlag = (unsigned_8) *ioc->data; printk(KERN_NOTICE "%s: Roaming: ", thisRangeLan.name); if(LLDRoamingFlag) printk("disabled\n"); else printk("enabled\n"); break; case GET_DISABLE_ROAM: *ioc->data = LLDRoamingFlag; break; case SET_ITO: if(!suser()) return -EPERM; LLDInactivityTimeOut = ((unsigned_8) *ioc->data)/5; LLDTicksToSniff = 0; if (!LLDInactivityTimeOut) LLDTicksToSniff = ((unsigned_16) *ioc->data) * POLL_FREQ; printk(KERN_NOTICE "%s: Inactivity Timeout changed: %d seconds.\n", thisRangeLan.name, LLDInactivityTimeOut*5 + (LLDTicksToSniff/POLL_FREQ)); break; case GET_ITO: *ioc->data = LLDInactivityTimeOut*5 + (LLDTicksToSniff/POLL_FREQ); break; case GET_SYNCSTATE: *ioc->data = LLDSyncState; break; case GET_MSTASYNCNAME: strcpy(ioc->data, LLDMSTASyncName); break; case GET_MSTAADDR: copy_to_user(ioc->data, LLDMSTAAddr, 6); break; case GET_MSTASYNCCHANNEL: *ioc->data = LLDMSTASyncChannel; break; case GET_MSTASYNCSUBCHANNEL: *ioc->data = LLDMSTASyncSubChannel; break; case GET_DRIVERVERSION: strcpy(ioc->data, DriverVersionString); break; case GET_ADDR: copy_to_user(ioc->data, LLDNodeAddress, 6); break; case GET_ROMVERSION: strcpy(ioc->data, LLDROMVersion); break; case GET_CC: if(GetCountryCode()) ret = -EIO; ioc->data[0] = LLDCCVal1; ioc->data[1] = LLDCCVal2; break; case SET_NODE_OVERRIDE: if(!suser()) return -EPERM; if (ioc->data[0] != 0xFF) { NodeOverrideFlag = SET; printk(KERN_NOTICE "%s: Node Override: ", thisRangeLan.name); ioc->data[0] |= 0x02; for(i=0;i<5;i++) { thisRangeLan.dev_addr[i] = LLDNodeAddress[i] = ioc->data[i]; printk("%2.2x:", thisRangeLan.dev_addr[i]); } thisRangeLan.dev_addr[i] = LLDNodeAddress[i] = ioc->data[i]; printk("%2.2x\n", thisRangeLan.dev_addr[i]); } else { NodeOverrideFlag = CLEAR; printk(KERN_NOTICE "%s: Node Override cleared.\n", thisRangeLan.name); } break; case SET_HOP_PERIOD: if(!suser()) return -EPERM; LLDHopPeriod = ((unsigned_8) *ioc->data & 0x03) + (LLDHopPeriod & 0xFC); printk(KERN_NOTICE "%s: Hop Period: %s.\n", thisRangeLan.name, hoptypes[LLDHopPeriod]); break; case GET_HOP_PERIOD: *ioc->data = LLDHopPeriod & 0x03; break; case SET_BFREQ: if(!suser()) return -EPERM; LLDBFreq = (unsigned_8) *ioc->data; printk(KERN_NOTICE "%s: Beacon Frequency: %d.\n", thisRangeLan.name, LLDBFreq); break; case GET_BFREQ: *ioc->data = LLDBFreq; break; case SET_BRIDGING: if(!suser()) return -EPERM; LLDBridgeFlag = (unsigned_8) *ioc->data; printk(KERN_NOTICE "%s: bridging: ", thisRangeLan.name); if(LLDBridgeFlag) printk("enabled\n"); else printk("disabled\n"); break; case GET_BRIDGING: *ioc->data = LLDBridgeFlag; break; case GET_PROTO_MODE: *ioc->data = HomeRF; break; case GET_CARD_NAME: *ioc->data = CardType; break; case GET_CARD_CONFIG: *ioc->data = 0; break; case SEND_PROX_PING: if(!suser()) return -EPERM; /* 0x4, 0x00 means outgoing ping */ /* ioc->data is the destination MAC */ /* Buffer length is max 1484 */ LLDSendProximPacket( &LLDProxPkt, Buffer, 1484, ioc->data, 0x4, 0x00); break; case START_AP_SEARCH: if(!suser()) return -EPERM; LLDMakeAPList(LLDDomain); break; case STOP_AP_SEARCH: if(!suser()) return -EPERM; LLDStopAPSearch(LLDDomain); break; case AP_LIST: if(!suser()) return -EPERM; LLDPrintAPList((struct MastersList *) ioc->data); break; default: ret = -EOPNOTSUPP; /* case RL2NODETABLE: if(!suser()) return -EPERM; rl2_ioctl_printnodes(); break; case RL2ROAM: if(!suser()) return -EPERM; LLDRoam(); break; */ } } #ifdef WIRELESS_EXT /* If wireless extension exist in the kernel */ /* support wireless extensions to the kernel */ else { switch(cmd) { /* we'll set a name that identifies the card */ case SIOCGIWNAME: if (SYMPCI) { strcpy(wrq->u.name, "Sym/4110"); return 0; } if (LLDMicroISA) { strcpy(wrq->u.name, "RL2/6330"); return 0; } else if (LLDOEM) { strcpy(wrq->u.name, "RL2/6300"); return 0; } if (LLDOnePieceFlag) { strcpy(wrq->u.name, "RL2/7400 Sym/4400"); return 0; } else if (LLDPCMCIA) { strcpy(wrq->u.name, "RL2/7200"); return 0; } else if (SYMPNPISA) { strcpy(wrq->u.name, "Sym/4100"); return 0; } else if (PROX6333) { strcpy(wrq->u.name, "RL2/6333"); return 0; } else if (PROX6334) { strcpy(wrq->u.name, "HRF/6334"); return 0; } else if (PROX6335) { strcpy(wrq->u.name, "S/HRF 6335"); return 0; } strcpy(wrq->u.name, "RL2/7100"); break; /* This domain in RangeLAN2-speak */ /* Set it if SU */ case SIOCSIWNWID: if(!suser()) { ret = -EPERM; break; } #if WIRELESS_EXT > 8 if (wrq->u.nwid.disabled) { ret = -EOPNOTSUPP; break; } if (wrq->u.nwid.value<16 && wrq->u.nwid.value>=0) { LLDDomain = wrq->u.nwid.value; LLDNeedReset = SET; } else ret = -EINVAL; #else /* WIRELESS_EXT */ if (wrq->u.nwid.on == 0) { ret = -EOPNOTSUPP; break; } if (wrq->u.nwid.nwid<16 && wrq->u.nwid.nwid>=0) { LLDDomain = wrq->u.nwid.nwid; LLDNeedReset = SET; } else ret = -EINVAL; #endif /* WIRELESS_EXT */ break; /* get domain */ case SIOCGIWNWID: #if WIRELESS_EXT > 8 wrq->u.nwid.value = LLDDomain; wrq->u.nwid.disabled = CLEAR; #else wrq->u.nwid.nwid = LLDDomain; wrq->u.nwid.on = SET; #endif break; #if WIRELESS_EXT > 8 case SIOCSIWMODE: switch(wrq->u.mode) { case IW_MODE_MASTER: LLDNodeType = 2; break; case IW_MODE_INFRA: LLDNodeType = 0; /* Set the adapter as a station */ break; case IW_MODE_SECOND: LLDNodeType = 1; default: ret = -EINVAL; } break; case SIOCGIWMODE: if(LLDNodeType == 2) wrq->u.mode = IW_MODE_INFRA; else if(LLDNodeType == 1) wrq->u.mode = IW_MODE_MASTER; else wrq->u.mode = IW_MODE_SECOND; break; #endif /* WIRELESS_EXT > 8 */ /* this is channel in RangeLAN2-speak */ /* set it if SU */ case SIOCSIWFREQ: if(!suser()) return -EPERM; if (wrq->u.freq.m<16 && wrq->u.freq.m>0) { LLDChannel = (wrq->u.freq.m); LLDNeedReset = SET; } else ret = -EINVAL; break; /* get channel */ case SIOCGIWFREQ: wrq->u.freq.e = 0; wrq->u.freq.m = LLDChannel; break; case SIOCSIPSUBC: if(!suser()) return -EPERM; break; case SIOCGIPSUBC: break; case SIOCGIWRANGE: /* Basic checking... */ if(wrq->u.data.pointer != (caddr_t) 0) { struct iw_range range; /* Verify the user buffer */ ret = verify_area(VERIFY_WRITE, wrq->u.data.pointer, sizeof(struct iw_range)); if(ret) break; /* Set the length (useless : its constant...) */ wrq->u.data.length = sizeof(struct iw_range); /* Set information in the range struct */ range.throughput = 1.6 * 1024 * 1024; /* don't argue on this ! */ range.min_nwid = 0; range.max_nwid = 15; /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable) */ range.num_channels = 15; range.num_frequency = 0; range.sensitivity = 0; range.max_qual.qual = 2; range.max_qual.level = 255; range.max_qual.noise = 0; /* Copy structure to the user buffer */ copy_to_user(wrq->u.data.pointer, &range, sizeof(struct iw_range)); } break; case SIOCGIWPRIV: /* Basic checking... */ if(wrq->u.data.pointer != (caddr_t) 0) { struct iw_priv_args priv[] = { /* cmd, set_args, get_args, name */ { SIOCSIPSUBC, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "setsubchan" }, { SIOCGIPSUBC, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "getsubchan" }, { SIOCSIPSTNT, IW_PRIV_TYPE_BYTE | 16, 0, "sethisto" }, { SIOCGIPSTNT, 0, IW_PRIV_TYPE_INT | 16, "gethisto" } }; /* Verify the user buffer */ ret = verify_area(VERIFY_WRITE, wrq->u.data.pointer, sizeof(priv)); if(ret) break; /* Set the number of ioctl available */ wrq->u.data.length = 4; /* Copy structure to the user buffer */ copy_to_user(wrq->u.data.pointer, (u_char *) priv, sizeof(priv)); } break; default: ret = -EOPNOTSUPP; } } #endif /* WIRELESS_EXT */ /* make sure we get messages from the card if it isn't up'd */ if (!poll_on) LLDPoll(); return ret; } /**************************************************************** * rl2_polltime () * routine to yield some time to LLDPoll * * *****************************************************************/ void rl2_polltime(unsigned long d) { if(poll_on) { LLDPoll(); init_timer(&poll_timer); poll_timer.function=rl2_polltime; if (LLDNeedReset) poll_timer.expires=jiffies + POLL_FREQ + 1*HZ; else poll_timer.expires=jiffies + POLL_FREQ; add_timer(&poll_timer); } } void rl2_sched_interrupt(void) { if (CardType == SYMPCI) { #ifdef CONFIG_PCI unsigned_16 interruptStatus; interruptStatus = _inpw(LLDIOAddress2+INTERRUPT_REGISTER); if(interruptStatus & INTERRUPT_STATUS) { _outpw(LLDIOAddress2+INTERRUPT_REGISTER, interruptStatus | INTERRUPT_CLEAR); } #endif /* CONFIG_PCI */ } RL2DEBUG("going to ISR\n"); LLDIsr(); thisRangeLan.interrupt = CLEAR; /* tell the kernel to start listening */ /* to our interrupts again */ enable_irq(thisRangeLan.irq); return; } static void rl2_interrupt(int irq, void *dev_id, struct pt_regs *regs) { struct device *dev = dev_id; if (dev == NULL || dev->irq != irq) { printk (KERN_ERR "%s: irq %d for unknown device.\n", dev->name, irq); return; } /* check for re-entrancy and then call LLDIsr() */ if(test_and_set_bit(CLEAR, (void*)&thisRangeLan.interrupt)) printk(KERN_DEBUG "%s: reentrant IRQ\n", thisRangeLan.name); /* process the interrupt */ thisRangeLan.interrupt = SET; queue_task(&LLSISR_Sched, &tq_immediate); mark_bh(IMMEDIATE_BH); /* tell the kernel to ignore our interrupt */ /* so that the bottom half has a chance to run */ disable_irq(irq); return; } static int rl2_start_xmit(struct sk_buff *skb, struct device *dev) { struct net_local *lp = dev->priv; int i, tmp, result; /* check if we've flagged ourselves as busy. Upper layers shouldn't call us if we're busy unless concerned we are dead. */ /* LLD will restart itself so we'll ignore upper layer when it kicks us */ if(dev->tbusy) { RL2DEBUG("%s: called when tbusy was set.\n", thisRangeLan.name); return -EBUSY; } /* This checks if the system thinks we've missed the tx-done (LLSSendComplete) signal. If this happens it's either impatient or CLLD has a bug. */ if (skb == NULL ) { RL2DEBUG("%s: called with skb = NULL.\n", thisRangeLan.name); #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0) dev_tint(dev); #endif return 0; } if(skb->len <= 0 || dev == NULL) { RL2DEBUG("%s: null device\n", thisRangeLan.name); return 0; } /* set us as busy and also check if it was busy */ if(test_and_set_bit(CLEAR, (void*)&dev->tbusy)) { RL2DEBUG("%s: Transmitter access conflict.\n", thisRangeLan.name); if (skb != NULL) DEV_FREE_SKB(skb); return 0; } #ifdef BUFFER /* find the first free buffer pointer */ for (i=0 ; istats.tx_dropped++; DEV_FREE_SKB(skb); return 0; } i = ring; bfr_list[i].txDesc.LLDTxdriverWS[0] = SET; /* save the buffer pointer to free in LLSSendComplete */ bfr_list[i].save_skbuff_ptr = skb; /*fill in the info for transmit decriptor*/ bfr_list[i].txFragList.LLDTxFragList[0].FSDataPtr = skb->data; bfr_list[i].txDesc.LLDTxDataLength = bfr_list[i].txFragList.LLDTxFragList[0].FSDataLen = skb->len; /* give packet over to LLD for transmission */ if (bfr_list[i].txDesc.LLDTxdriverWS[0]==CLEAR) printk ("Clear going into LLDSend!!!\n"); result = LLDSend(&bfr_list[i].txDesc); if (outcount > LLDMAXSEND-1) {RL2DEBUG("max outcount exceeded = %d\n", outcount);} /* check for max buffering. */ if (outcount++ < LLDMAXSEND-1) { dev->tbusy = CLEAR; mark_bh(NET_BH); } /* we're trying to be very careful here. LLSSendComplete() */ /* is looking for outcount to be = to LLDMAXSEND-1 to set tbusy=CLEAR */ /* We want to be sure that doesn't happen until it's ok here. */ /* so don't increment outcount until we're cool on tbusy or we */ /* we might cause reentrancy. */ #else /* save the skb for release in LLSSendComplete */ saveptr = skb; /* point frag list to our static structure that has 1 fragments */ txFragList.LLDTxFragmentCount = 1; txDesc.LLDTxFragmentListPtr = &txFragList; txFragList.LLDTxFragList[0].FSDataPtr = skb->data; /* fill in the length for transmit decriptor */ txDesc.LLDTxDataLength = skb->len; txDesc.LLDImmediateDataLength = 0; txFragList.LLDTxFragList[0].FSDataLen = skb->len; result = LLDSend(&txDesc); #endif /* return codes aren't used by LLDSend() as Linux expects but but we'll check anyway. 0 means it took it (not that it was sent). 1 means it was queued (delayed). 0xff means there was an error but I don't belive LLDSend() will return that to us (keep in mind LLDSend() gets call within CLLD also. */ if(result==1) {RL2DEBUG("%s: send delayed\n", thisRangeLan.name);} else if(result) { lp->stats.tx_errors++; RL2DEBUG("%s: LLDsend transmit failure!!\n", thisRangeLan.name); } return 0; } static struct enet_statistics *rl2_get_stats(struct device *dev) { struct net_local *lp = dev->priv; int clld_dropped, i; clld_dropped = (int) (LLDOutSyncDrp + LLDTimedQDrp + LLDFailureDrp); clld_dropped += (int) (LLDOutSyncQDrp + LLDNoReEntrantDrp + LLDSendDisabledDrp); RL2DEBUG("%d, %d, %d\n", LLDOutSyncDrp, LLDTimedQDrp, LLDFailureDrp); RL2DEBUG("%d, %d, %d\n", LLDOutSyncQDrp, LLDNoReEntrantDrp, LLDSendDisabledDrp); RL2DEBUG("%d, %d\n", LLDNeedResetCnt, LLDSyncState); RL2DEBUG("%d, %d\n", outcount, thisRangeLan.tbusy); #ifdef BUFFER for (i=0; istats.tx_packets = lp->attempted_tx_packets - clld_dropped; lp->stats.tx_errors = clld_dropped; return &(lp->stats); } #ifdef WIRELESS_EXT /* If wireless extension exist in the kernel */ /***************************************************************** Get wireless statistics Called by /proc/net/wireless... *****************************************************************/ static struct iw_statistics *rl2_get_wireless_stats(struct device * dev) { struct net_local *lp = dev->priv; if ( (lp->wstats.status = LLDSyncState) ) lp->wstats.status = 1; /* Copy data to wireless stuff */ if ( (lp->wstats.qual.qual = LLDSyncState) ) if (LLDTxMode) lp->wstats.qual.qual = 2; else lp->wstats.qual.qual = 1; lp->wstats.qual.noise = 0; lp->wstats.qual.updated = 0; lp->wstats.discard.nwid = 0L; lp->wstats.discard.code = 0L; lp->wstats.discard.misc = 0L; return &(lp->wstats); } #endif /* WIRELESS_EXT */ /****************************************************************/ /* Init Failure (reason) Codes for rl2_probe(), i.e, LLDInit()*/ /* 0 - Successful Initialization */ /* 1 - Error resetting the RFNC */ /* 2 - Error setting the interrupt vector */ /* 3 - Error sending the initialize command */ /* 4 - Error getting the ROM version */ /* 5 - Error getting the global address */ /* 6 - Error setting the local address */ /* 7 - Error setting the inactivity time out */ /* 8 - Error unknown */ /* 9 - Error setting security ID */ /* 10 - Error sending configure MAC */ /* 11 - Error sending set roaming parameters command*/ /* 12 - Error sending multicast command */ /* 13 - Error in card and socket services */ /* 14 - Error configuring socket - improper card seating*/ /* 15 - Error configuring socket - power imporperly supplied*/ /* 16 - Error configuring socket - no PCMCIA bus ready signal*/ /****************************************************************/ static int rl2_probe(struct device *dev) { int inival,i; unsigned_32 flags; unsigned_32 rndval; /* If it's a PC Card, card services already got the window for us. Just use it. */ if (LLDPCMCIA) { dev->base_addr = LLDIOAddress1; dev->irq = LLDIntLine1; } else { /* this should be code to probe for cards */ /* We don't support it and supposedly it's bad to */ /* autoprobe in a module. */ if(dev->base_addr == 0) { printk(KERN_WARNING "%s: RangeLan can't autoprobe\n",dev->name); return -ENODEV; } /* check if this io region is used. */ if (check_region(dev->base_addr, LLDIORange1)) return -ENODEV; /* request the resources and register the region */ request_region(dev->base_addr, LLDIORange1, thisRangeLan.name); LLDIOAddress1 = dev->base_addr; if (CardType == SYMPCI) { /* register PCI region */ if (check_region(LLDIOAddress2, LLDIORange2)) { release_region(dev->base_addr, LLDIORange1); return -ENODEV; } /* request the resources and register the region */ request_region(LLDIOAddress2, LLDIORange2, thisRangeLan.name); } LLDIntLine1 = dev->irq; } /* randomize channel and subchannel. This is for Symphony where you don't know how your next door neighbor set up theirs. Override to your desired value with ioctl */ get_random_bytes(&rndval, 4); LLDChannel = rndval%16; get_random_bytes(&rndval, 4); LLDSubChannel = rndval%16; /* Set the driver version */ strcpy(DriverVersionString, RL2VERSION); /* LLDInit() brings up the card with all default values or values that are preset. It returns error codes as commented above. */ inival = LLDInit(); if(inival) { printk(KERN_WARNING "%s: %s.\n",dev->name,error_codes[inival]); release_region(dev->base_addr, LLDIORange1); if (CardType == SYMPCI) release_region(LLDIOAddress2, LLDIORange2); return -ENODEV; } /* print info to logs since we initialized properly */ printk(version); printk("rlmod.o: Linux port by Paul Chinn (loomer@1000klub.com).\n"); #ifdef BUFFER printk("%s: %s, buffers enabled, ", #else printk("%s: %s, no buffers, ", #endif dev->name, card_types[CardType]); printk("fw: %s.\n%s: ", LLDROMVersion, dev->name); for(i=0;i<5;i++) { dev->dev_addr[i] = LLDNodeAddress[i]; printk("%2.2x:", dev->dev_addr[i]); } dev->dev_addr[i] = LLDNodeAddress[i]; printk("%2.2x, ", dev->dev_addr[i]); printk("IO: %#3.3lx-%x, ", dev->base_addr, LLDIORange1-1); if(CardType==SYMPCI) printk("extra PCI IO: %#3.3lx, ", LLDIOAddress2); printk("irq %d.\n", dev->irq); if (LLDPCMCIA) printk("%s: Parts from dummy_cs.c 1.9 1998/07/16 23:44:06 (David Hinds).\n", dev->name); /* Initialize the private space in the device structure. */ if (dev->priv == NULL) { dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL); if (dev->priv == NULL) return -ENOMEM; } memset(dev->priv, 0, sizeof(struct net_local)); /* register some routines with the kernel */ dev->open = &rl2_open; dev->stop = &rl2_close; dev->hard_start_xmit = &rl2_start_xmit; dev->get_stats = rl2_get_stats; /* dev->set_multicast_list = &set_multicast_list; */ dev->do_ioctl = rl2_ioctl; #ifdef WIRELESS_EXT /* If wireless extension exist in the kernel */ dev->get_wireless_stats = rl2_get_wireless_stats; printk("%s: Wireless extensions enabled\n",dev->name); #endif ether_setup(dev); /* all done */ return 0; } int rl2_init() { /* CLLD does it's own resets. If this gets called, CLLD */ /* may have crashed. */ printk("%s: rl2_init was called.\n", thisRangeLan.name); return 1; } void rl2_CleanModuleVars(void) { /* stop the poll timer for LLDPoll() */ del_timer(&poll_timer); /* free kernel memory that isn't freed otherwise. */ if (thisRangeLan.priv) kfree_s(thisRangeLan.priv, sizeof(struct net_local)); /* unregister the driver from the kernel */ unregister_netdev(&thisRangeLan); /* free the resources. */ free_irq(thisRangeLan.irq, &thisRangeLan); release_region(thisRangeLan.base_addr, LLDIORange1); release_region(LLDIOAddress2, LLDIORange2); } void cleanup_module(void) { #ifdef PCCARD if(LLDPCMCIA) { DEBUG(0, "dummy_cs: unloading\n"); unregister_pcmcia_driver(&dev_info); while (dev_list != NULL) { if (dev_list->state & DEV_CONFIG) rl2_release((u_long)dev_list); rl2_detach(dev_list); } } #endif /* PCCARD */ rl2_CleanModuleVars(); } int rl2_PreRL2Probe(void) { int result = 0; if (!LLDPCMCIA) { /* Parameters that can be set with 'insmod' */ thisRangeLan.base_addr = io; thisRangeLan.irq = irq; } #ifdef CONFIG_PCI #ifndef PCIBIOS_SUCCESSFUL #define PCIBIOS_SUCCESSFUL 0x00 #endif /*PCIBOIS_SUCCESSFUL */ if (CardType == SYMPCI) { if (pcibios_present()) { unsigned char bus, function; int index, result; for (index=0; index < PROXIM_MAX_DEV; index++) { result = pcibios_find_device(PROXIM_VENDOR, PROXIM_ID, index, &bus, &function); if (result != PCIBIOS_SUCCESSFUL) break; /* found a card */ { #if LINUX_VERSION_CODE > KERNEL_VERSION(2,3,0) struct pci_dev *pdev = pci_find_slot(bus, function); LLDIOAddress2 = pdev->resource[1].start; thisRangeLan.base_addr = pdev->resource[3].start; LLDIORange1 = 16; thisRangeLan.irq = pdev->irq; #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,55) struct pci_dev *pdev = pci_find_slot(bus, function); LLDIOAddress2 = pdev->base_address[1] & PCI_BASE_ADDRESS_IO_MASK; thisRangeLan.base_addr = pdev->base_address[3] & PCI_BASE_ADDRESS_IO_MASK; LLDIORange1 = 16; /* PCI minimum */ thisRangeLan.irq = pdev->irq; #else u32 pci_ioaddr; u8 pci_irq_line; pcibios_read_config_byte(bus, function, PCI_INTERRUPT_LINE, &pci_irq_line); pcibios_read_config_dword(bus, function, PCI_BASE_ADDRESS_3, &pci_ioaddr); thisRangeLan.base_addr = pci_ioaddr & ~3; LLDIORange1 = 16; /* PCI minimum */ pcibios_read_config_dword(bus, function, PCI_BASE_ADDRESS_1, &pci_ioaddr); LLDIOAddress2 = pci_ioaddr & ~3; thisRangeLan.irq = pci_irq_line; #endif } } if (result != PCIBIOS_SUCCESSFUL) { printk(KERN_WARNING "rlmod.o pci error: %d\n", result); return -ENODEV; } if (index == 0) return -ENODEV; } else return -ENODEV; } #endif /* CONFIG_PCI */ /* set up for queue LLDIsr () and nasty busy loop */ /* The busy loop isn't as bad as it sounds = only on init */ LLSISR_Sched.routine = (void *) &rl2_sched_interrupt; LLSISR_Sched.data = 0; /* Register the device with the kernel. Note that thisRangeLan has */ /* rl2_probe as a paramter. register_netdev calls it. rl2_probe /* does the initialization stuff. */ if (result = register_netdev(&thisRangeLan) != 0) return result; return 0; } int init_module(void) { /* set the card type */ switch (CardType) { case RL2ISA: /* RangeLAN2 ISA - set as default */ LLDPCMCIA = CLEAR; LLDOEM = CLEAR; LLDMicroISA = CLEAR; break; case RL2MISA: /* RangeLAN2 630x series Mini ISA */ LLDPCMCIA = CLEAR; LLDOEM = SET; LLDMicroISA = CLEAR; break; case RL2UISA: /* RangeLAN2 633x series Micro design-in module */ LLDPCMCIA = CLEAR; LLDOEM = SET; LLDMicroISA = SET; break; case RL2PCCARD: /* RangeLAN2 and Symphony PC Cards */ #ifdef PCCARD LLDPCMCIA = SET; LLDOEM = CLEAR; LLDMicroISA = CLEAR; #else printk(KERN_WARNING "rlmod.o: PC Card support not compiled into this module.\n"); return -EINVAL; #endif /* PCCARD */ break; case SYMPNPISA: /* Symphony PnP ISA Card */ LLDPCMCIA = CLEAR; LLDOEM = SET; LLDMicroISA = SET; break; case SYMPCI: /* Symphony PCI Card */ #ifdef CONFIG_PCI LLDPCMCIA = CLEAR; LLDOEM = SET; LLDMicroISA = SET; #else printk(KERN_WARNING "rlmod.o: PCI support not compiled into this module.\n"); return -EINVAL; #endif /* CONFIG_PCI */ break; case PROX6333: /* 6333 Micro Jr Card */ LLDPCMCIA = CLEAR; LLDOEM = SET; LLDMicroISA = SET; break; case PROX6334: /* 6334 Micro Jr Card */ LLDPCMCIA = CLEAR; LLDOEM = SET; LLDMicroISA = SET; break; case PROX6335: /* 6335 Micro Jr Card */ LLDPCMCIA = CLEAR; LLDOEM = SET; LLDMicroISA = SET; break; default: /* invalid setting */ printk(KERN_WARNING "rlmod.o: Can't init RangeLan, Invalid card type.\n"); return -ENODEV; break; } if(LLDPCMCIA) { #ifdef PCCARD servinfo_t serv; DEBUG(0, "%s\n", versionpc); CardServices(GetCardServicesInfo, &serv); if (serv.Revision != CS_RELEASE_CODE) { printk(KERN_NOTICE "rlmod: Card Services release " "does not match!\n"); return -1; } register_pcmcia_driver(&dev_info, &rl2_attach, &rl2_detach); #endif /* PCCARD */ return 0; } else return rl2_PreRL2Probe(); } static int rl2_open(struct device *dev) { struct net_local *lp = dev->priv; int i; /* start the polling timer */ poll_on = 1; init_timer(&poll_timer); poll_timer.expires=POLL_FREQ; poll_timer.function=rl2_polltime; add_timer(&poll_timer); #ifdef BUFFER outcount = ring = 0; /* initialize our pre-defined buffers for CLLD */ for (i=0 ; i= KERNEL_VERSION(2,2,0) lp->stats.rx_bytes = lp->stats.tx_bytes = 0; #endif lp->stats.rx_packets = lp->attempted_tx_packets = 0; lp->stats.rx_dropped = lp->stats.tx_dropped = 0; lp->stats.rx_errors = lp->stats.tx_errors = 0; lp->stats.multicast = 0; /* init some stuff in our kernel device structure */ dev->tbusy = 0; dev->interrupt = 0; dev->start = 1; /* flag the module as 'in use' */ MOD_INC_USE_COUNT; /* reset the card to be sure it's active */ LLDNeedReset = SET; /* what are we checking here? I think if this fails, the driver hasn't been initialized. */ /* if(LLDReset()) return -ENODEV; */ return 0; } static int rl2_close(struct device *dev) { /* flag the module as 'not in use' */ MOD_DEC_USE_COUNT; /* shut down the poll timer */ del_timer(&poll_timer); poll_on = 0; /* stop the card. */ LLDStop(); /* tell the kernel the device isn't running */ dev->start = 0; return 0; } /**************************************************************** ***************************************************************** * The following stuff is all called from rl2_ioctl() * * ***************************************************************** *****************************************************************/ void rl2_ioctl_nodeinfo(void) {/* printk(KERN_INFO "%s d=%d CardType=%d ",nodetypes[LLDNodeType], LLDDomain, CardType); if(LLDNodeType != MASTER) { if(LLDSyncState) printk("Synced to %s, c/s=%d/%d\n", LLDMSTASyncName,LLDMSTASyncChannel,LLDMSTASyncSubChannel); else printk("Out of Sync\n"); } else printk("Name=%s c/s=%d/%d\n", LLDMSTAName, LLDChannel, LLDSubChannel); */} void rl2_ioctl_printnodes(void) {/* unsigned_8 link; int i; printk("rl2_ioctl: Displaying NodeTable:\n"); link = MRUNodeEntry; while(link != 0xff) { for(i=0;i<6;i++) printk("%2.2x:",NodeTable[link].Address[i]); if(NodeTable[link].BridgeState) { printk(" via "); for(i=0;i<6;i++) printk("%2.2x:",NodeTable[link].Route[i]); printk("t/o in %d secs", ( BRIDGETIMEOUT - (LLSGetCurrentTime() - NodeTable[link].BridgeStartTime) ) / TPS); } printk("\n"); link = NodeTable[link].TimeLink; } */} #ifdef PCCARD /*====================================================================== The initial developer of the original dummy_cs code is David A. Hinds . Portions created by David A. Hinds are Copyright (C) 1998 David A. Hinds. All Rights Reserved. ======================================================================*/ /*====================================================================*/ static void cs_error(client_handle_t handle, int func, int ret) { error_info_t err = { func, ret }; CardServices(ReportError, handle, &err); } /*====================================================================== rl2_attach() creates an "instance" of the driver, allocating local data structures for one device. 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 *rl2_attach(void) { client_reg_t client_reg; dev_link_t *link; local_info_t *local; int ret, i; DEBUG(0, "rlmod_attach()\n"); /* Initialize the dev_link_t structure */ link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL); memset(link, 0, sizeof(struct dev_link_t)); link->release.function = &rl2_release; link->release.data = (u_long)link; /* Interrupt setup */ link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 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 = NULL; /* General socket configuration defaults can go here. In this client, we assume very little, and rely on the CIS for almost everything. In most clients, many details (i.e., number, sizes, and attributes of IO windows) are fixed by the nature of the device, and can be hard-wired here. */ link->conf.Attributes = 0; link->conf.Vcc = 50; link->conf.IntType = INT_MEMORY_AND_IO; /* Allocate space for private device-specific data */ local = kmalloc(sizeof(local_info_t), GFP_KERNEL); memset(local, 0, sizeof(local_info_t)); link->priv = local; /* Register with Card Services */ link->next = dev_list; dev_list = link; client_reg.dev_info = &dev_info; client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE; client_reg.EventMask = 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 = &rl2_event; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; ret = CardServices(RegisterClient, &link->handle, &client_reg); if (ret != 0) { cs_error(link->handle, RegisterClient, ret); rl2_detach(link); return NULL; } if ( (rl2_PreRL2Probe()) ) { /* 1 means bad card */ cs_error(link->handle, RegisterClient, 1); link->open = 0; link->state = 0; rl2_detach(link); CardServices(EjectCard, &link->handle); return NULL; } sprintf(link->dev->dev_name, thisRangeLan.name); return link; } /* rl2_attach */ /*====================================================================== 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 rl2_detach(dev_link_t *link) { dev_link_t **linkp; DEBUG(0, "rlmod_detach(0x%p)\n", link); /* Locate device structure */ for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) if (*linkp == link) break; if (*linkp == NULL) return; /* 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) { #ifdef PCMCIA_DEBUG printk(KERN_DEBUG "rlmod: detach postponed, '%s' " "still locked\n", link->dev->dev_name); #endif link->state |= DEV_STALE_LINK; return; } /* Break the link with Card Services */ if (link->handle) CardServices(DeregisterClient, link->handle); /* Unlink device structure, free pieces */ *linkp = link->next; if (link->priv) { kfree_s(link->priv, sizeof(local_info_t)); } kfree_s(link, sizeof(struct dev_link_t)); } /* rl2_detach */ /*====================================================================== rl2_config() is scheduled to run after a CARD_INSERTION event is received, to configure the PCMCIA socket, and to make the device available to the system. ======================================================================*/ #define CS_CHECK(fn, args...) \ while ((last_ret=CardServices(last_fn=(fn),args))!=0) goto cs_failed #define CFG_CHECK(fn, args...) \ if (CardServices(fn, args) != 0) goto next_entry static void rl2_config(dev_link_t *link) { client_handle_t handle; tuple_t tuple; cisparse_t parse; local_info_t *dev; int last_fn, last_ret; u_char buf[64]; win_req_t req; memreq_t map; handle = link->handle; dev = link->priv; DEBUG(0, "rlmod_config(0x%p)\n", link); /* This reads the card's CONFIG tuple to find its configuration registers. */ tuple.DesiredTuple = CISTPL_CONFIG; tuple.Attributes = 0; tuple.TupleData = buf; tuple.TupleDataMax = sizeof(buf); tuple.TupleOffset = 0; CS_CHECK(GetFirstTuple, handle, &tuple); CS_CHECK(GetTupleData, handle, &tuple); CS_CHECK(ParseTuple, handle, &tuple, &parse); link->conf.ConfigBase = parse.config.base; link->conf.Present = parse.config.rmask[0]; /* Configure card */ link->state |= DEV_CONFIG; /* In this loop, we scan the CIS for configuration table entries, each of which describes a valid card configuration, including voltage, IO window, memory window, and interrupt settings. We make no assumptions about the card to be configured: we use just the information available in the CIS. In an ideal world, this would work for any PCMCIA card, but it requires a complete and accurate CIS. In practice, a driver usually "knows" most of these things without consulting the CIS, and most client drivers will only use the CIS to fill in implementation-defined details. */ tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; CS_CHECK(GetFirstTuple, handle, &tuple); while (1) { cistpl_cftable_entry_t dflt = { 0 }; cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); CFG_CHECK(GetTupleData, handle, &tuple); CFG_CHECK(ParseTuple, handle, &tuple, &parse); if (cfg->index == 0) goto next_entry; link->conf.ConfigIndex = cfg->index; /* Does this card need audio output? */ if (cfg->flags & CISTPL_CFTABLE_AUDIO) { link->conf.Attributes |= CONF_ENABLE_SPKR; link->conf.Status = CCSR_AUDIO_ENA; } /* Use power settings for Vcc and Vpp if present */ /* Note that the CIS values need to be rescaled */ if (cfg->vcc.present & (1<conf.Vcc = cfg->vcc.param[CISTPL_POWER_VNOM]/10000; else if (dflt.vcc.present & (1<conf.Vcc = dflt.vcc.param[CISTPL_POWER_VNOM]/10000; if (cfg->vpp1.present & (1<conf.Vpp1 = link->conf.Vpp2 = cfg->vpp1.param[CISTPL_POWER_VNOM]/10000; else if (dflt.vpp1.present & (1<conf.Vpp1 = link->conf.Vpp2 = dflt.vpp1.param[CISTPL_POWER_VNOM]/10000; /* Do we need to allocate an interrupt? */ if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1) link->conf.Attributes |= CONF_ENABLE_IRQ; /* IO window settings */ link->io.NumPorts1 = link->io.NumPorts2 = 0; if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io; link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; /* Tuples are broken for this param so force IOCS16 */ /* if (!(io->flags & CISTPL_IO_8BIT)) link->io.Attributes1 = IO_DATA_PATH_WIDTH_16; if (!(io->flags & CISTPL_IO_16BIT)) link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; */ link->io.BasePort1 = io->win[0].base; link->io.NumPorts1 = io->win[0].len; if (io->nwin > 1) { link->io.Attributes2 = link->io.Attributes1; link->io.BasePort2 = io->win[1].base; link->io.NumPorts2 = io->win[1].len; } } /* This reserves IO space but doesn't actually enable it */ CFG_CHECK(RequestIO, link->handle, &link->io); /* Now set up a common memory window, if needed. There is room in the dev_link_t structure for one memory window handle, but if the base addresses need to be saved, or if multiple windows are needed, the info should go in the private data structure for this device. Note that the memory window base is a physical address, and needs to be mapped to virtual space with ioremap() before it is used. */ /* if ((cfg->mem.nwin > 0) || (dflt.mem.nwin > 0)) { */ if (1) { /* set up access to the attributes memory */ cistpl_mem_t *mem = (cfg->mem.nwin) ? &cfg->mem : &dflt.mem; req.Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_AM|WIN_ENABLE; /* req.Base = mem->win[0].host_addr; req.Size = mem->win[0].len; */ req.Base = 0; req.Size = LLSMemorySize1; req.AccessSpeed = 0; link->win = (window_handle_t)link->handle; CFG_CHECK(RequestWindow, &link->win, &req); map.Page = 0; map.CardOffset = mem->win[0].card_addr; CFG_CHECK(MapMemPage, link->win, &map); /* Contributed by Shinji Sumimoto */ #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,108) req.Base = (long)ioremap(req.Base, 0x4000); #endif /* If we got this far, we're cool! */ } break; next_entry: if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg; CS_CHECK(GetNextTuple, handle, &tuple); } /* Allocate an interrupt line. Note that this does not assign a handler to the interrupt, unless the 'Handler' member of the irq structure is initialized. */ if (link->conf.Attributes & CONF_ENABLE_IRQ) CS_CHECK(RequestIRQ, link->handle, &link->irq); /* This actually configures the PCMCIA socket -- setting up the I/O windows and the interrupt mapping, and putting the card and host interface into "Memory and IO" mode. */ CS_CHECK(RequestConfiguration, link->handle, &link->conf); /* At this point, the dev_node_t structure(s) need to be initialized and arranged in a linked list at link->dev. */ dev->node.major = dev->node.minor = 0; link->dev = &dev->node; /* Declare some values for rl2_probe */ LLDIOAddress1 = link->io.BasePort1; LLDIntLine1 = link->irq.AssignedIRQ; LLDMemoryAddress1 = req.Base; /* Finally, report what we've done */ printk(KERN_INFO "rlmod.o: index 0x%02x: Vcc %d.%d", link->conf.ConfigIndex, link->conf.Vcc/10, link->conf.Vcc%10); if (link->conf.Vpp1) printk(", Vpp %d.%d", link->conf.Vpp1/10, link->conf.Vpp1%10); /* if (link->conf.Attributes & CONF_ENABLE_IRQ) printk(", irq %d", link->irq.AssignedIRQ); if (link->io.NumPorts1) printk(", io 0x%04x-0x%04x", link->io.BasePort1, link->io.BasePort1+link->io.NumPorts1-1); if (link->io.NumPorts2) printk(" & 0x%04x-0x%04x", link->io.BasePort2, link->io.BasePort2+link->io.NumPorts2-1); */ if (link->win) printk(", mem 0x%06lx-0x%06lx", req.Base, req.Base+req.Size-1); printk("\n"); link->state &= ~DEV_CONFIG_PENDING; return; cs_failed: cs_error(link->handle, last_fn, last_ret); rl2_release((u_long)link); } /* rl2_config */ /*====================================================================== After a card is removed, rl2_release() will unregister the device, and release the PCMCIA configuration. If the device is still open, this will be postponed until it is closed. ======================================================================*/ static void rl2_release(u_long arg) { dev_link_t *link = (dev_link_t *)arg; DEBUG(0, "rl2_release(0x%p)\n", link); /* If the device is currently in use, we won't release until it is actually closed, because until then, we can't be sure that no one will try to access the device or its data structures. */ if (link->open) { DEBUG(1, "rlmod: release postponed, '%s' still open\n", link->dev->dev_name); link->state |= DEV_STALE_CONFIG; return; } /* Unlink the device chain */ link->dev = NULL; /* In a normal driver, additional code may be needed to release other kernel data structures associated with this device. */ /* Don't bother checking to see if these succeed or not */ if (link->win) CardServices(ReleaseWindow, link->win); CardServices(ReleaseConfiguration, link->handle); if (link->io.NumPorts1) CardServices(ReleaseIO, link->handle, &link->io); if (link->irq.AssignedIRQ) CardServices(ReleaseIRQ, link->handle, &link->irq); link->state &= ~DEV_CONFIG; if (link->state & DEV_STALE_LINK) rl2_detach(link); } /* rl2_release */ /*====================================================================== The card status event handler. Mostly, this schedules other stuff to run after an event is received. When a CARD_REMOVAL event is received, we immediately set a private flag to block future accesses to this device. All the functions that actually access the device should check this flag to make sure the card is still present. ======================================================================*/ static int rl2_event(event_t event, int priority, event_callback_args_t *args) { dev_link_t *link = args->client_data; DEBUG(1, "rl2_event(0x%06x)\n", event); switch (event) { case CS_EVENT_CARD_REMOVAL: PCMCIACardInserted = CLEAR; link->state &= ~DEV_PRESENT; if (link->state & DEV_CONFIG) { ((local_info_t *)link->priv)->stop = 1; link->release.expires = RUN_AT(HZ/20); add_timer(&link->release); } break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; rl2_config(link); break; case CS_EVENT_PM_SUSPEND: rl2_close(&thisRangeLan); link->state |= DEV_SUSPEND; /* Fall through... */ case CS_EVENT_RESET_PHYSICAL: /* Mark the device as stopped, to block IO until later */ ((local_info_t *)link->priv)->stop = 1; if (link->state & DEV_CONFIG) CardServices(ReleaseConfiguration, link->handle); break; case CS_EVENT_PM_RESUME: link->state &= ~DEV_SUSPEND; if (link->state & DEV_CONFIG) CardServices(RequestConfiguration, link->handle, &link->conf); ((local_info_t *)link->priv)->stop = 0; /* In a normal driver, additional code may go here to restore the device state and restart IO. */ rl2_open(&thisRangeLan); break; case CS_EVENT_CARD_RESET: if (link->state & DEV_CONFIG) CardServices(RequestConfiguration, link->handle, &link->conf); ((local_info_t *)link->priv)->stop = 0; /* In a normal driver, additional code may go here to restore the device state and restart IO. */ rl2_open(&thisRangeLan); break; } return 0; } /* rl2_event */ /*====================================================================*/ #endif