ibmtr.c 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982
  1. /* ibmtr.c: A shared-memory IBM Token Ring 16/4 driver for linux
  2. *
  3. * Written 1993 by Mark Swanson and Peter De Schrijver.
  4. * This software may be used and distributed according to the terms
  5. * of the GNU General Public License, incorporated herein by reference.
  6. *
  7. * This device driver should work with Any IBM Token Ring Card that does
  8. * not use DMA.
  9. *
  10. * I used Donald Becker's (becker@scyld.com) device driver work
  11. * as a base for most of my initial work.
  12. *
  13. * Changes by Peter De Schrijver
  14. * (Peter.Deschrijver@linux.cc.kuleuven.ac.be) :
  15. *
  16. * + changed name to ibmtr.c in anticipation of other tr boards.
  17. * + changed reset code and adapter open code.
  18. * + added SAP open code.
  19. * + a first attempt to write interrupt, transmit and receive routines.
  20. *
  21. * Changes by David W. Morris (dwm@shell.portal.com) :
  22. * 941003 dwm: - Restructure tok_probe for multiple adapters, devices.
  23. * + Add comments, misc reorg for clarity.
  24. * + Flatten interrupt handler levels.
  25. *
  26. * Changes by Farzad Farid (farzy@zen.via.ecp.fr)
  27. * and Pascal Andre (andre@chimay.via.ecp.fr) (March 9 1995) :
  28. * + multi ring support clean up.
  29. * + RFC1042 compliance enhanced.
  30. *
  31. * Changes by Pascal Andre (andre@chimay.via.ecp.fr) (September 7 1995) :
  32. * + bug correction in tr_tx
  33. * + removed redundant information display
  34. * + some code reworking
  35. *
  36. * Changes by Michel Lespinasse (walken@via.ecp.fr),
  37. * Yann Doussot (doussot@via.ecp.fr) and Pascal Andre (andre@via.ecp.fr)
  38. * (February 18, 1996) :
  39. * + modified shared memory and mmio access port the driver to
  40. * alpha platform (structure access -> readb/writeb)
  41. *
  42. * Changes by Steve Kipisz (bungy@ibm.net or kipisz@vnet.ibm.com)
  43. * (January 18 1996):
  44. * + swapped WWOR and WWCR in ibmtr.h
  45. * + moved some init code from tok_probe into trdev_init. The
  46. * PCMCIA code can call trdev_init to complete initializing
  47. * the driver.
  48. * + added -DPCMCIA to support PCMCIA
  49. * + detecting PCMCIA Card Removal in interrupt handler. If
  50. * ISRP is FF, then a PCMCIA card has been removed
  51. * 10/2000 Burt needed a new method to avoid crashing the OS
  52. *
  53. * Changes by Paul Norton (pnorton@cts.com) :
  54. * + restructured the READ.LOG logic to prevent the transmit SRB
  55. * from being rudely overwritten before the transmit cycle is
  56. * complete. (August 15 1996)
  57. * + completed multiple adapter support. (November 20 1996)
  58. * + implemented csum_partial_copy in tr_rx and increased receive
  59. * buffer size and count. Minor fixes. (March 15, 1997)
  60. *
  61. * Changes by Christopher Turcksin <wabbit@rtfc.demon.co.uk>
  62. * + Now compiles ok as a module again.
  63. *
  64. * Changes by Paul Norton (pnorton@ieee.org) :
  65. * + moved the header manipulation code in tr_tx and tr_rx to
  66. * net/802/tr.c. (July 12 1997)
  67. * + add retry and timeout on open if cable disconnected. (May 5 1998)
  68. * + lifted 2000 byte mtu limit. now depends on shared-RAM size.
  69. * May 25 1998)
  70. * + can't allocate 2k recv buff at 8k shared-RAM. (20 October 1998)
  71. *
  72. * Changes by Joel Sloan (jjs@c-me.com) :
  73. * + disable verbose debug messages by default - to enable verbose
  74. * debugging, edit the IBMTR_DEBUG_MESSAGES define below
  75. *
  76. * Changes by Mike Phillips <phillim@amtrak.com> :
  77. * + Added extra #ifdef's to work with new PCMCIA Token Ring Code.
  78. * The PCMCIA code now just sets up the card so it can be recognized
  79. * by ibmtr_probe. Also checks allocated memory vs. on-board memory
  80. * for correct figure to use.
  81. *
  82. * Changes by Tim Hockin (thockin@isunix.it.ilstu.edu) :
  83. * + added spinlocks for SMP sanity (10 March 1999)
  84. *
  85. * Changes by Jochen Friedrich to enable RFC1469 Option 2 multicasting
  86. * i.e. using functional address C0 00 00 04 00 00 to transmit and
  87. * receive multicast packets.
  88. *
  89. * Changes by Mike Sullivan (based on original sram patch by Dave Grothe
  90. * to support windowing into on adapter shared ram.
  91. * i.e. Use LANAID to setup a PnP configuration with 16K RAM. Paging
  92. * will shift this 16K window over the entire available shared RAM.
  93. *
  94. * Changes by Peter De Schrijver (p2@mind.be) :
  95. * + fixed a problem with PCMCIA card removal
  96. *
  97. * Change by Mike Sullivan et al.:
  98. * + added turbo card support. No need to use lanaid to configure
  99. * the adapter into isa compatiblity mode.
  100. *
  101. * Changes by Burt Silverman to allow the computer to behave nicely when
  102. * a cable is pulled or not in place, or a PCMCIA card is removed hot.
  103. */
  104. /* change the define of IBMTR_DEBUG_MESSAGES to a nonzero value
  105. in the event that chatty debug messages are desired - jjs 12/30/98 */
  106. #define IBMTR_DEBUG_MESSAGES 0
  107. #include <linux/module.h>
  108. #ifdef PCMCIA /* required for ibmtr_cs.c to build */
  109. #undef MODULE /* yes, really */
  110. #undef ENABLE_PAGING
  111. #else
  112. #define ENABLE_PAGING 1
  113. #endif
  114. #define FALSE 0
  115. #define TRUE (!FALSE)
  116. /* changes the output format of driver initialization */
  117. #define TR_VERBOSE 0
  118. /* some 95 OS send many non UI frame; this allow removing the warning */
  119. #define TR_FILTERNONUI 1
  120. #include <linux/ioport.h>
  121. #include <linux/netdevice.h>
  122. #include <linux/ip.h>
  123. #include <linux/trdevice.h>
  124. #include <linux/ibmtr.h>
  125. #include <net/checksum.h>
  126. #include <asm/io.h>
  127. #define DPRINTK(format, args...) printk("%s: " format, dev->name , ## args)
  128. #define DPRINTD(format, args...) DummyCall("%s: " format, dev->name , ## args)
  129. /* version and credits */
  130. #ifndef PCMCIA
  131. static char version[] __initdata =
  132. "\nibmtr.c: v1.3.57 8/ 7/94 Peter De Schrijver and Mark Swanson\n"
  133. " v2.1.125 10/20/98 Paul Norton <pnorton@ieee.org>\n"
  134. " v2.2.0 12/30/98 Joel Sloan <jjs@c-me.com>\n"
  135. " v2.2.1 02/08/00 Mike Sullivan <sullivam@us.ibm.com>\n"
  136. " v2.2.2 07/27/00 Burt Silverman <burts@us.ibm.com>\n"
  137. " v2.4.0 03/01/01 Mike Sullivan <sullivan@us.ibm.com>\n";
  138. #endif
  139. /* this allows displaying full adapter information */
  140. static char *channel_def[] __devinitdata = { "ISA", "MCA", "ISA P&P" };
  141. static char pcchannelid[] __devinitdata = {
  142. 0x05, 0x00, 0x04, 0x09,
  143. 0x04, 0x03, 0x04, 0x0f,
  144. 0x03, 0x06, 0x03, 0x01,
  145. 0x03, 0x01, 0x03, 0x00,
  146. 0x03, 0x09, 0x03, 0x09,
  147. 0x03, 0x00, 0x02, 0x00
  148. };
  149. static char mcchannelid[] __devinitdata = {
  150. 0x04, 0x0d, 0x04, 0x01,
  151. 0x05, 0x02, 0x05, 0x03,
  152. 0x03, 0x06, 0x03, 0x03,
  153. 0x05, 0x08, 0x03, 0x04,
  154. 0x03, 0x05, 0x03, 0x01,
  155. 0x03, 0x08, 0x02, 0x00
  156. };
  157. static char __devinit *adapter_def(char type)
  158. {
  159. switch (type) {
  160. case 0xF: return "PC Adapter | PC Adapter II | Adapter/A";
  161. case 0xE: return "16/4 Adapter | 16/4 Adapter/A (long)";
  162. case 0xD: return "16/4 Adapter/A (short) | 16/4 ISA-16 Adapter";
  163. case 0xC: return "Auto 16/4 Adapter";
  164. default: return "adapter (unknown type)";
  165. };
  166. };
  167. #define TRC_INIT 0x01 /* Trace initialization & PROBEs */
  168. #define TRC_INITV 0x02 /* verbose init trace points */
  169. static unsigned char ibmtr_debug_trace = 0;
  170. static int ibmtr_probe(struct net_device *dev);
  171. static int ibmtr_probe1(struct net_device *dev, int ioaddr);
  172. static unsigned char get_sram_size(struct tok_info *adapt_info);
  173. static int trdev_init(struct net_device *dev);
  174. static int tok_open(struct net_device *dev);
  175. static int tok_init_card(struct net_device *dev);
  176. static void tok_open_adapter(unsigned long dev_addr);
  177. static void open_sap(unsigned char type, struct net_device *dev);
  178. static void tok_set_multicast_list(struct net_device *dev);
  179. static int tok_send_packet(struct sk_buff *skb, struct net_device *dev);
  180. static int tok_close(struct net_device *dev);
  181. static irqreturn_t tok_interrupt(int irq, void *dev_id, struct pt_regs *regs);
  182. static void initial_tok_int(struct net_device *dev);
  183. static void tr_tx(struct net_device *dev);
  184. static void tr_rx(struct net_device *dev);
  185. static void ibmtr_reset_timer(struct timer_list*tmr,struct net_device *dev);
  186. static void tok_rerun(unsigned long dev_addr);
  187. static void ibmtr_readlog(struct net_device *dev);
  188. static struct net_device_stats *tok_get_stats(struct net_device *dev);
  189. static int ibmtr_change_mtu(struct net_device *dev, int mtu);
  190. static void find_turbo_adapters(int *iolist);
  191. static int ibmtr_portlist[IBMTR_MAX_ADAPTERS+1] __devinitdata = {
  192. 0xa20, 0xa24, 0, 0, 0
  193. };
  194. static int __devinitdata turbo_io[IBMTR_MAX_ADAPTERS] = {0};
  195. static int __devinitdata turbo_irq[IBMTR_MAX_ADAPTERS] = {0};
  196. static int __devinitdata turbo_searched = 0;
  197. #ifndef PCMCIA
  198. static __u32 ibmtr_mem_base __initdata = 0xd0000;
  199. #endif
  200. static void __devinit PrtChanID(char *pcid, short stride)
  201. {
  202. short i, j;
  203. for (i = 0, j = 0; i < 24; i++, j += stride)
  204. printk("%1x", ((int) pcid[j]) & 0x0f);
  205. printk("\n");
  206. }
  207. static void __devinit HWPrtChanID(void __iomem *pcid, short stride)
  208. {
  209. short i, j;
  210. for (i = 0, j = 0; i < 24; i++, j += stride)
  211. printk("%1x", ((int) readb(pcid + j)) & 0x0f);
  212. printk("\n");
  213. }
  214. /* We have to ioremap every checked address, because isa_readb is
  215. * going away.
  216. */
  217. static void __devinit find_turbo_adapters(int *iolist)
  218. {
  219. int ram_addr;
  220. int index=0;
  221. void __iomem *chanid;
  222. int found_turbo=0;
  223. unsigned char *tchanid, ctemp;
  224. int i, j;
  225. unsigned long jif;
  226. void __iomem *ram_mapped ;
  227. if (turbo_searched == 1) return;
  228. turbo_searched=1;
  229. for (ram_addr=0xC0000; ram_addr < 0xE0000; ram_addr+=0x2000) {
  230. __u32 intf_tbl=0;
  231. found_turbo=1;
  232. ram_mapped = ioremap((u32)ram_addr,0x1fff) ;
  233. if (ram_mapped==NULL)
  234. continue ;
  235. chanid=(CHANNEL_ID + ram_mapped);
  236. tchanid=pcchannelid;
  237. ctemp=readb(chanid) & 0x0f;
  238. if (ctemp != *tchanid) continue;
  239. for (i=2,j=1; i<=46; i=i+2,j++) {
  240. if ((readb(chanid+i) & 0x0f) != tchanid[j]){
  241. found_turbo=0;
  242. break;
  243. }
  244. }
  245. if (!found_turbo) continue;
  246. writeb(0x90, ram_mapped+0x1E01);
  247. for(i=2; i<0x0f; i++) {
  248. writeb(0x00, ram_mapped+0x1E01+i);
  249. }
  250. writeb(0x00, ram_mapped+0x1E01);
  251. for(jif=jiffies+TR_BUSY_INTERVAL; time_before_eq(jiffies,jif););
  252. intf_tbl=ntohs(readw(ram_mapped+ACA_OFFSET+ACA_RW+WRBR_EVEN));
  253. if (intf_tbl) {
  254. #if IBMTR_DEBUG_MESSAGES
  255. printk("ibmtr::find_turbo_adapters, Turbo found at "
  256. "ram_addr %x\n",ram_addr);
  257. printk("ibmtr::find_turbo_adapters, interface_table ");
  258. for(i=0; i<6; i++) {
  259. printk("%x:",readb(ram_addr+intf_tbl+i));
  260. }
  261. printk("\n");
  262. #endif
  263. turbo_io[index]=ntohs(readw(ram_mapped+intf_tbl+4));
  264. turbo_irq[index]=readb(ram_mapped+intf_tbl+3);
  265. outb(0, turbo_io[index] + ADAPTRESET);
  266. for(jif=jiffies+TR_RST_TIME;time_before_eq(jiffies,jif););
  267. outb(0, turbo_io[index] + ADAPTRESETREL);
  268. index++;
  269. continue;
  270. }
  271. #if IBMTR_DEBUG_MESSAGES
  272. printk("ibmtr::find_turbo_adapters, ibmtr card found at"
  273. " %x but not a Turbo model\n",ram_addr);
  274. #endif
  275. iounmap(ram_mapped) ;
  276. } /* for */
  277. for(i=0; i<IBMTR_MAX_ADAPTERS; i++) {
  278. if(!turbo_io[i]) break;
  279. for (j=0; j<IBMTR_MAX_ADAPTERS; j++) {
  280. if ( iolist[j] && iolist[j] != turbo_io[i]) continue;
  281. iolist[j]=turbo_io[i];
  282. break;
  283. }
  284. }
  285. }
  286. static void ibmtr_cleanup_card(struct net_device *dev)
  287. {
  288. if (dev->base_addr) {
  289. outb(0,dev->base_addr+ADAPTRESET);
  290. schedule_timeout(TR_RST_TIME); /* wait 50ms */
  291. outb(0,dev->base_addr+ADAPTRESETREL);
  292. }
  293. #ifndef PCMCIA
  294. free_irq(dev->irq, dev);
  295. release_region(dev->base_addr, IBMTR_IO_EXTENT);
  296. {
  297. struct tok_info *ti = (struct tok_info *) dev->priv;
  298. iounmap(ti->mmio);
  299. iounmap(ti->sram_virt);
  300. }
  301. #endif
  302. }
  303. int ibmtr_probe_card(struct net_device *dev)
  304. {
  305. int err = ibmtr_probe(dev);
  306. if (!err) {
  307. err = register_netdev(dev);
  308. if (err)
  309. ibmtr_cleanup_card(dev);
  310. }
  311. return err;
  312. }
  313. /****************************************************************************
  314. * ibmtr_probe(): Routine specified in the network device structure
  315. * to probe for an IBM Token Ring Adapter. Routine outline:
  316. * I. Interrogate hardware to determine if an adapter exists
  317. * and what the speeds and feeds are
  318. * II. Setup data structures to control execution based upon
  319. * adapter characteristics.
  320. *
  321. * We expect ibmtr_probe to be called once for each device entry
  322. * which references it.
  323. ****************************************************************************/
  324. static int ibmtr_probe(struct net_device *dev)
  325. {
  326. int i;
  327. int base_addr = dev->base_addr;
  328. if (base_addr && base_addr <= 0x1ff) /* Don't probe at all. */
  329. return -ENXIO;
  330. if (base_addr > 0x1ff) { /* Check a single specified location. */
  331. if (!ibmtr_probe1(dev, base_addr)) return 0;
  332. return -ENODEV;
  333. }
  334. find_turbo_adapters(ibmtr_portlist);
  335. for (i = 0; ibmtr_portlist[i]; i++) {
  336. int ioaddr = ibmtr_portlist[i];
  337. if (!ibmtr_probe1(dev, ioaddr)) return 0;
  338. }
  339. return -ENODEV;
  340. }
  341. /*****************************************************************************/
  342. static int __devinit ibmtr_probe1(struct net_device *dev, int PIOaddr)
  343. {
  344. unsigned char segment, intr=0, irq=0, i, j, cardpresent=NOTOK, temp=0;
  345. void __iomem * t_mmio = NULL;
  346. struct tok_info *ti = dev->priv;
  347. void __iomem *cd_chanid;
  348. unsigned char *tchanid, ctemp;
  349. #ifndef PCMCIA
  350. unsigned char t_irq=0;
  351. unsigned long timeout;
  352. static int version_printed;
  353. #endif
  354. /* Query the adapter PIO base port which will return
  355. * indication of where MMIO was placed. We also have a
  356. * coded interrupt number.
  357. */
  358. segment = inb(PIOaddr);
  359. if (segment < 0x40 || segment > 0xe0) {
  360. /* Out of range values so we'll assume non-existent IO device
  361. * but this is not necessarily a problem, esp if a turbo
  362. * adapter is being used. */
  363. #if IBMTR_DEBUG_MESSAGES
  364. DPRINTK("ibmtr_probe1(): unhappy that inb(0x%X) == 0x%X, "
  365. "Hardware Problem?\n",PIOaddr,segment);
  366. #endif
  367. return -ENODEV;
  368. }
  369. /*
  370. * Compute the linear base address of the MMIO area
  371. * as LINUX doesn't care about segments
  372. */
  373. t_mmio = ioremap(((__u32) (segment & 0xfc) << 11) + 0x80000,2048);
  374. if (!t_mmio) {
  375. DPRINTK("Cannot remap mmiobase memory area") ;
  376. return -ENODEV ;
  377. }
  378. intr = segment & 0x03; /* low bits is coded interrupt # */
  379. if (ibmtr_debug_trace & TRC_INIT)
  380. DPRINTK("PIOaddr: %4hx seg/intr: %2x mmio base: %p intr: %d\n"
  381. , PIOaddr, (int) segment, t_mmio, (int) intr);
  382. /*
  383. * Now we will compare expected 'channelid' strings with
  384. * what we is there to learn of ISA/MCA or not TR card
  385. */
  386. #ifdef PCMCIA
  387. iounmap(t_mmio);
  388. t_mmio = ti->mmio; /*BMS to get virtual address */
  389. irq = ti->irq; /*BMS to display the irq! */
  390. #endif
  391. cd_chanid = (CHANNEL_ID + t_mmio); /* for efficiency */
  392. tchanid = pcchannelid;
  393. cardpresent = TR_ISA; /* try ISA */
  394. /* Suboptimize knowing first byte different */
  395. ctemp = readb(cd_chanid) & 0x0f;
  396. if (ctemp != *tchanid) { /* NOT ISA card, try MCA */
  397. tchanid = mcchannelid;
  398. cardpresent = TR_MCA;
  399. if (ctemp != *tchanid) /* Neither ISA nor MCA */
  400. cardpresent = NOTOK;
  401. }
  402. if (cardpresent != NOTOK) {
  403. /* Know presumed type, try rest of ID */
  404. for (i = 2, j = 1; i <= 46; i = i + 2, j++) {
  405. if( (readb(cd_chanid+i)&0x0f) == tchanid[j]) continue;
  406. /* match failed, not TR card */
  407. cardpresent = NOTOK;
  408. break;
  409. }
  410. }
  411. /*
  412. * If we have an ISA board check for the ISA P&P version,
  413. * as it has different IRQ settings
  414. */
  415. if (cardpresent == TR_ISA && (readb(AIPFID + t_mmio) == 0x0e))
  416. cardpresent = TR_ISAPNP;
  417. if (cardpresent == NOTOK) { /* "channel_id" did not match, report */
  418. if (!(ibmtr_debug_trace & TRC_INIT)) {
  419. #ifndef PCMCIA
  420. iounmap(t_mmio);
  421. #endif
  422. return -ENODEV;
  423. }
  424. DPRINTK( "Channel ID string not found for PIOaddr: %4hx\n",
  425. PIOaddr);
  426. DPRINTK("Expected for ISA: ");
  427. PrtChanID(pcchannelid, 1);
  428. DPRINTK(" found: ");
  429. /* BMS Note that this can be misleading, when hardware is flaky, because you
  430. are reading it a second time here. So with my flaky hardware, I'll see my-
  431. self in this block, with the HW ID matching the ISA ID exactly! */
  432. HWPrtChanID(cd_chanid, 2);
  433. DPRINTK("Expected for MCA: ");
  434. PrtChanID(mcchannelid, 1);
  435. }
  436. /* Now, setup some of the pl0 buffers for this driver.. */
  437. /* If called from PCMCIA, it is already set up, so no need to
  438. waste the memory, just use the existing structure */
  439. #ifndef PCMCIA
  440. ti->mmio = t_mmio;
  441. for (i = 0; i < IBMTR_MAX_ADAPTERS; i++) {
  442. if (turbo_io[i] != PIOaddr)
  443. continue;
  444. #if IBMTR_DEBUG_MESSAGES
  445. printk("ibmtr::tr_probe1, setting PIOaddr %x to Turbo\n",
  446. PIOaddr);
  447. #endif
  448. ti->turbo = 1;
  449. t_irq = turbo_irq[i];
  450. }
  451. #endif /* !PCMCIA */
  452. ti->readlog_pending = 0;
  453. init_waitqueue_head(&ti->wait_for_reset);
  454. /* if PCMCIA, the card can be recognized as either TR_ISA or TR_ISAPNP
  455. * depending which card is inserted. */
  456. #ifndef PCMCIA
  457. switch (cardpresent) {
  458. case TR_ISA:
  459. if (intr == 0) irq = 9; /* irq2 really is irq9 */
  460. if (intr == 1) irq = 3;
  461. if (intr == 2) irq = 6;
  462. if (intr == 3) irq = 7;
  463. ti->adapter_int_enable = PIOaddr + ADAPTINTREL;
  464. break;
  465. case TR_MCA:
  466. if (intr == 0) irq = 9;
  467. if (intr == 1) irq = 3;
  468. if (intr == 2) irq = 10;
  469. if (intr == 3) irq = 11;
  470. ti->global_int_enable = 0;
  471. ti->adapter_int_enable = 0;
  472. ti->sram_phys=(__u32)(inb(PIOaddr+ADAPTRESETREL) & 0xfe) << 12;
  473. break;
  474. case TR_ISAPNP:
  475. if (!t_irq) {
  476. if (intr == 0) irq = 9;
  477. if (intr == 1) irq = 3;
  478. if (intr == 2) irq = 10;
  479. if (intr == 3) irq = 11;
  480. } else
  481. irq=t_irq;
  482. timeout = jiffies + TR_SPIN_INTERVAL;
  483. while (!readb(ti->mmio + ACA_OFFSET + ACA_RW + RRR_EVEN)){
  484. if (!time_after(jiffies, timeout)) continue;
  485. DPRINTK( "Hardware timeout during initialization.\n");
  486. iounmap(t_mmio);
  487. kfree(ti);
  488. return -ENODEV;
  489. }
  490. ti->sram_phys =
  491. ((__u32)readb(ti->mmio+ACA_OFFSET+ACA_RW+RRR_EVEN)<<12);
  492. ti->adapter_int_enable = PIOaddr + ADAPTINTREL;
  493. break;
  494. } /*end switch (cardpresent) */
  495. #endif /*not PCMCIA */
  496. if (ibmtr_debug_trace & TRC_INIT) { /* just report int */
  497. DPRINTK("irq=%d", irq);
  498. printk(", sram_phys=0x%x", ti->sram_phys);
  499. if(ibmtr_debug_trace&TRC_INITV){ /* full chat in verbose only */
  500. DPRINTK(", ti->mmio=%p", ti->mmio);
  501. printk(", segment=%02X", segment);
  502. }
  503. printk(".\n");
  504. }
  505. /* Get hw address of token ring card */
  506. j = 0;
  507. for (i = 0; i < 0x18; i = i + 2) {
  508. /* technical reference states to do this */
  509. temp = readb(ti->mmio + AIP + i) & 0x0f;
  510. ti->hw_address[j] = temp;
  511. if (j & 1)
  512. dev->dev_addr[(j / 2)] =
  513. ti->hw_address[j]+ (ti->hw_address[j - 1] << 4);
  514. ++j;
  515. }
  516. /* get Adapter type: 'F' = Adapter/A, 'E' = 16/4 Adapter II,... */
  517. ti->adapter_type = readb(ti->mmio + AIPADAPTYPE);
  518. /* get Data Rate: F=4Mb, E=16Mb, D=4Mb & 16Mb ?? */
  519. ti->data_rate = readb(ti->mmio + AIPDATARATE);
  520. /* Get Early Token Release support?: F=no, E=4Mb, D=16Mb, C=4&16Mb */
  521. ti->token_release = readb(ti->mmio + AIPEARLYTOKEN);
  522. /* How much shared RAM is on adapter ? */
  523. if (ti->turbo) {
  524. ti->avail_shared_ram=127;
  525. } else {
  526. ti->avail_shared_ram = get_sram_size(ti);/*in 512 byte units */
  527. }
  528. /* We need to set or do a bunch of work here based on previous results*/
  529. /* Support paging? What sizes?: F=no, E=16k, D=32k, C=16 & 32k */
  530. ti->shared_ram_paging = readb(ti->mmio + AIPSHRAMPAGE);
  531. /* Available DHB 4Mb size: F=2048, E=4096, D=4464 */
  532. switch (readb(ti->mmio + AIP4MBDHB)) {
  533. case 0xe: ti->dhb_size4mb = 4096; break;
  534. case 0xd: ti->dhb_size4mb = 4464; break;
  535. default: ti->dhb_size4mb = 2048; break;
  536. }
  537. /* Available DHB 16Mb size: F=2048, E=4096, D=8192, C=16384, B=17960 */
  538. switch (readb(ti->mmio + AIP16MBDHB)) {
  539. case 0xe: ti->dhb_size16mb = 4096; break;
  540. case 0xd: ti->dhb_size16mb = 8192; break;
  541. case 0xc: ti->dhb_size16mb = 16384; break;
  542. case 0xb: ti->dhb_size16mb = 17960; break;
  543. default: ti->dhb_size16mb = 2048; break;
  544. }
  545. /* We must figure out how much shared memory space this adapter
  546. * will occupy so that if there are two adapters we can fit both
  547. * in. Given a choice, we will limit this adapter to 32K. The
  548. * maximum space will will use for two adapters is 64K so if the
  549. * adapter we are working on demands 64K (it also doesn't support
  550. * paging), then only one adapter can be supported.
  551. */
  552. /*
  553. * determine how much of total RAM is mapped into PC space
  554. */
  555. ti->mapped_ram_size= /*sixteen to onehundredtwentyeight 512byte blocks*/
  556. 1<< ((readb(ti->mmio+ACA_OFFSET+ACA_RW+RRR_ODD) >> 2 & 0x03) + 4);
  557. ti->page_mask = 0;
  558. if (ti->turbo) ti->page_mask=0xf0;
  559. else if (ti->shared_ram_paging == 0xf); /* No paging in adapter */
  560. else {
  561. #ifdef ENABLE_PAGING
  562. unsigned char pg_size = 0;
  563. /* BMS: page size: PCMCIA, use configuration register;
  564. ISAPNP, use LANAIDC config tool from www.ibm.com */
  565. switch (ti->shared_ram_paging) {
  566. case 0xf:
  567. break;
  568. case 0xe:
  569. ti->page_mask = (ti->mapped_ram_size == 32) ? 0xc0 : 0;
  570. pg_size = 32; /* 16KB page size */
  571. break;
  572. case 0xd:
  573. ti->page_mask = (ti->mapped_ram_size == 64) ? 0x80 : 0;
  574. pg_size = 64; /* 32KB page size */
  575. break;
  576. case 0xc:
  577. switch (ti->mapped_ram_size) {
  578. case 32:
  579. ti->page_mask = 0xc0;
  580. pg_size = 32;
  581. break;
  582. case 64:
  583. ti->page_mask = 0x80;
  584. pg_size = 64;
  585. break;
  586. }
  587. break;
  588. default:
  589. DPRINTK("Unknown shared ram paging info %01X\n",
  590. ti->shared_ram_paging);
  591. iounmap(t_mmio);
  592. kfree(ti);
  593. return -ENODEV;
  594. break;
  595. } /*end switch shared_ram_paging */
  596. if (ibmtr_debug_trace & TRC_INIT)
  597. DPRINTK("Shared RAM paging code: %02X, "
  598. "mapped RAM size: %dK, shared RAM size: %dK, "
  599. "page mask: %02X\n:",
  600. ti->shared_ram_paging, ti->mapped_ram_size / 2,
  601. ti->avail_shared_ram / 2, ti->page_mask);
  602. #endif /*ENABLE_PAGING */
  603. }
  604. #ifndef PCMCIA
  605. /* finish figuring the shared RAM address */
  606. if (cardpresent == TR_ISA) {
  607. static __u32 ram_bndry_mask[] =
  608. { 0xffffe000, 0xffffc000, 0xffff8000, 0xffff0000 };
  609. __u32 new_base, rrr_32, chk_base, rbm;
  610. rrr_32=readb(ti->mmio+ACA_OFFSET+ACA_RW+RRR_ODD) >> 2 & 0x03;
  611. rbm = ram_bndry_mask[rrr_32];
  612. new_base = (ibmtr_mem_base + (~rbm)) & rbm;/* up to boundary */
  613. chk_base = new_base + (ti->mapped_ram_size << 9);
  614. if (chk_base > (ibmtr_mem_base + IBMTR_SHARED_RAM_SIZE)) {
  615. DPRINTK("Shared RAM for this adapter (%05x) exceeds "
  616. "driver limit (%05x), adapter not started.\n",
  617. chk_base, ibmtr_mem_base + IBMTR_SHARED_RAM_SIZE);
  618. iounmap(t_mmio);
  619. kfree(ti);
  620. return -ENODEV;
  621. } else { /* seems cool, record what we have figured out */
  622. ti->sram_base = new_base >> 12;
  623. ibmtr_mem_base = chk_base;
  624. }
  625. }
  626. else ti->sram_base = ti->sram_phys >> 12;
  627. /* The PCMCIA has already got the interrupt line and the io port,
  628. so no chance of anybody else getting it - MLP */
  629. if (request_irq(dev->irq = irq, &tok_interrupt, 0, "ibmtr", dev) != 0) {
  630. DPRINTK("Could not grab irq %d. Halting Token Ring driver.\n",
  631. irq);
  632. iounmap(t_mmio);
  633. kfree(ti);
  634. return -ENODEV;
  635. }
  636. /*?? Now, allocate some of the PIO PORTs for this driver.. */
  637. /* record PIOaddr range as busy */
  638. if (!request_region(PIOaddr, IBMTR_IO_EXTENT, "ibmtr")) {
  639. DPRINTK("Could not grab PIO range. Halting driver.\n");
  640. free_irq(dev->irq, dev);
  641. iounmap(t_mmio);
  642. kfree(ti);
  643. return -EBUSY;
  644. }
  645. if (!version_printed++) {
  646. printk(version);
  647. }
  648. #endif /* !PCMCIA */
  649. DPRINTK("%s %s found\n",
  650. channel_def[cardpresent - 1], adapter_def(ti->adapter_type));
  651. DPRINTK("using irq %d, PIOaddr %hx, %dK shared RAM.\n",
  652. irq, PIOaddr, ti->mapped_ram_size / 2);
  653. DPRINTK("Hardware address : %02X:%02X:%02X:%02X:%02X:%02X\n",
  654. dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
  655. dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
  656. if (ti->page_mask)
  657. DPRINTK("Shared RAM paging enabled. "
  658. "Page size: %uK Shared Ram size %dK\n",
  659. ((ti->page_mask^0xff)+1) >>2, ti->avail_shared_ram / 2);
  660. else
  661. DPRINTK("Shared RAM paging disabled. ti->page_mask %x\n",
  662. ti->page_mask);
  663. /* Calculate the maximum DHB we can use */
  664. /* two cases where avail_shared_ram doesn't equal mapped_ram_size:
  665. 1. avail_shared_ram is 127 but mapped_ram_size is 128 (typical)
  666. 2. user has configured adapter for less than avail_shared_ram
  667. but is not using paging (she should use paging, I believe)
  668. */
  669. if (!ti->page_mask) {
  670. ti->avail_shared_ram=
  671. min(ti->mapped_ram_size,ti->avail_shared_ram);
  672. }
  673. switch (ti->avail_shared_ram) {
  674. case 16: /* 8KB shared RAM */
  675. ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)2048);
  676. ti->rbuf_len4 = 1032;
  677. ti->rbuf_cnt4=2;
  678. ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)2048);
  679. ti->rbuf_len16 = 1032;
  680. ti->rbuf_cnt16=2;
  681. break;
  682. case 32: /* 16KB shared RAM */
  683. ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)4464);
  684. ti->rbuf_len4 = 1032;
  685. ti->rbuf_cnt4=4;
  686. ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)4096);
  687. ti->rbuf_len16 = 1032; /*1024 usable */
  688. ti->rbuf_cnt16=4;
  689. break;
  690. case 64: /* 32KB shared RAM */
  691. ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)4464);
  692. ti->rbuf_len4 = 1032;
  693. ti->rbuf_cnt4=6;
  694. ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)10240);
  695. ti->rbuf_len16 = 1032;
  696. ti->rbuf_cnt16=6;
  697. break;
  698. case 127: /* 63.5KB shared RAM */
  699. ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)4464);
  700. ti->rbuf_len4 = 1032;
  701. ti->rbuf_cnt4=6;
  702. ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)16384);
  703. ti->rbuf_len16 = 1032;
  704. ti->rbuf_cnt16=16;
  705. break;
  706. case 128: /* 64KB shared RAM */
  707. ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)4464);
  708. ti->rbuf_len4 = 1032;
  709. ti->rbuf_cnt4=6;
  710. ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)17960);
  711. ti->rbuf_len16 = 1032;
  712. ti->rbuf_cnt16=16;
  713. break;
  714. default:
  715. ti->dhb_size4mb = 2048;
  716. ti->rbuf_len4 = 1032;
  717. ti->rbuf_cnt4=2;
  718. ti->dhb_size16mb = 2048;
  719. ti->rbuf_len16 = 1032;
  720. ti->rbuf_cnt16=2;
  721. break;
  722. }
  723. /* this formula is not smart enough for the paging case
  724. ti->rbuf_cnt<x> = (ti->avail_shared_ram * BLOCKSZ - ADAPT_PRIVATE -
  725. ARBLENGTH - SSBLENGTH - DLC_MAX_SAP * SAPLENGTH -
  726. DLC_MAX_STA * STALENGTH - ti->dhb_size<x>mb * NUM_DHB -
  727. SRBLENGTH - ASBLENGTH) / ti->rbuf_len<x>;
  728. */
  729. ti->maxmtu16 = (ti->rbuf_len16 - 8) * ti->rbuf_cnt16 - TR_HLEN;
  730. ti->maxmtu4 = (ti->rbuf_len4 - 8) * ti->rbuf_cnt4 - TR_HLEN;
  731. /*BMS assuming 18 bytes of Routing Information (usually works) */
  732. DPRINTK("Maximum Receive Internet Protocol MTU 16Mbps: %d, 4Mbps: %d\n",
  733. ti->maxmtu16, ti->maxmtu4);
  734. dev->base_addr = PIOaddr; /* set the value for device */
  735. dev->mem_start = ti->sram_base << 12;
  736. dev->mem_end = dev->mem_start + (ti->mapped_ram_size << 9) - 1;
  737. trdev_init(dev);
  738. return 0; /* Return 0 to indicate we have found a Token Ring card. */
  739. } /*ibmtr_probe1() */
  740. /*****************************************************************************/
  741. /* query the adapter for the size of shared RAM */
  742. /* the function returns the RAM size in units of 512 bytes */
  743. static unsigned char __devinit get_sram_size(struct tok_info *adapt_info)
  744. {
  745. unsigned char avail_sram_code;
  746. static unsigned char size_code[] = { 0, 16, 32, 64, 127, 128 };
  747. /* Adapter gives
  748. 'F' -- use RRR bits 3,2
  749. 'E' -- 8kb 'D' -- 16kb
  750. 'C' -- 32kb 'A' -- 64KB
  751. 'B' - 64KB less 512 bytes at top
  752. (WARNING ... must zero top bytes in INIT */
  753. avail_sram_code = 0xf - readb(adapt_info->mmio + AIPAVAILSHRAM);
  754. if (avail_sram_code) return size_code[avail_sram_code];
  755. else /* for code 'F', must compute size from RRR(3,2) bits */
  756. return 1 <<
  757. ((readb(adapt_info->mmio+ACA_OFFSET+ACA_RW+RRR_ODD)>>2&3)+4);
  758. }
  759. /*****************************************************************************/
  760. static int __devinit trdev_init(struct net_device *dev)
  761. {
  762. struct tok_info *ti = (struct tok_info *) dev->priv;
  763. SET_PAGE(ti->srb_page);
  764. ti->open_failure = NO ;
  765. dev->open = tok_open;
  766. dev->stop = tok_close;
  767. dev->hard_start_xmit = tok_send_packet;
  768. dev->get_stats = tok_get_stats;
  769. dev->set_multicast_list = tok_set_multicast_list;
  770. dev->change_mtu = ibmtr_change_mtu;
  771. return 0;
  772. }
  773. /*****************************************************************************/
  774. static int tok_init_card(struct net_device *dev)
  775. {
  776. struct tok_info *ti;
  777. short PIOaddr;
  778. unsigned long i;
  779. PIOaddr = dev->base_addr;
  780. ti = (struct tok_info *) dev->priv;
  781. /* Special processing for first interrupt after reset */
  782. ti->do_tok_int = FIRST_INT;
  783. /* Reset adapter */
  784. writeb(~INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_EVEN);
  785. outb(0, PIOaddr + ADAPTRESET);
  786. current->state=TASK_UNINTERRUPTIBLE;
  787. schedule_timeout(TR_RST_TIME); /* wait 50ms */
  788. outb(0, PIOaddr + ADAPTRESETREL);
  789. #ifdef ENABLE_PAGING
  790. if (ti->page_mask)
  791. writeb(SRPR_ENABLE_PAGING,ti->mmio+ACA_OFFSET+ACA_RW+SRPR_EVEN);
  792. #endif
  793. writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
  794. i = sleep_on_timeout(&ti->wait_for_reset, 4 * HZ);
  795. return i? 0 : -EAGAIN;
  796. }
  797. /*****************************************************************************/
  798. static int tok_open(struct net_device *dev)
  799. {
  800. struct tok_info *ti = (struct tok_info *) dev->priv;
  801. int i;
  802. /*the case we were left in a failure state during a previous open */
  803. if (ti->open_failure == YES) {
  804. DPRINTK("Last time you were disconnected, how about now?\n");
  805. printk("You can't insert with an ICS connector half-cocked.\n");
  806. }
  807. ti->open_status = CLOSED; /* CLOSED or OPEN */
  808. ti->sap_status = CLOSED; /* CLOSED or OPEN */
  809. ti->open_failure = NO; /* NO or YES */
  810. ti->open_mode = MANUAL; /* MANUAL or AUTOMATIC */
  811. ti->sram_phys &= ~1; /* to reverse what we do in tok_close */
  812. /* init the spinlock */
  813. spin_lock_init(&ti->lock);
  814. init_timer(&ti->tr_timer);
  815. i = tok_init_card(dev);
  816. if (i) return i;
  817. while (1){
  818. tok_open_adapter((unsigned long) dev);
  819. i= interruptible_sleep_on_timeout(&ti->wait_for_reset, 25 * HZ);
  820. /* sig catch: estimate opening adapter takes more than .5 sec*/
  821. if (i>(245*HZ)/10) break; /* fancier than if (i==25*HZ) */
  822. if (i==0) break;
  823. if (ti->open_status == OPEN && ti->sap_status==OPEN) {
  824. netif_start_queue(dev);
  825. DPRINTK("Adapter is up and running\n");
  826. return 0;
  827. }
  828. current->state=TASK_INTERRUPTIBLE;
  829. i=schedule_timeout(TR_RETRY_INTERVAL); /* wait 30 seconds */
  830. if(i!=0) break; /*prob. a signal, like the i>24*HZ case above */
  831. }
  832. outb(0, dev->base_addr + ADAPTRESET);/* kill pending interrupts*/
  833. DPRINTK("TERMINATED via signal\n"); /*BMS useful */
  834. return -EAGAIN;
  835. }
  836. /*****************************************************************************/
  837. #define COMMAND_OFST 0
  838. #define OPEN_OPTIONS_OFST 8
  839. #define NUM_RCV_BUF_OFST 24
  840. #define RCV_BUF_LEN_OFST 26
  841. #define DHB_LENGTH_OFST 28
  842. #define NUM_DHB_OFST 30
  843. #define DLC_MAX_SAP_OFST 32
  844. #define DLC_MAX_STA_OFST 33
  845. static void tok_open_adapter(unsigned long dev_addr)
  846. {
  847. struct net_device *dev = (struct net_device *) dev_addr;
  848. struct tok_info *ti;
  849. int i;
  850. ti = (struct tok_info *) dev->priv;
  851. SET_PAGE(ti->init_srb_page);
  852. writeb(~SRB_RESP_INT, ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_ODD);
  853. for (i = 0; i < sizeof(struct dir_open_adapter); i++)
  854. writeb(0, ti->init_srb + i);
  855. writeb(DIR_OPEN_ADAPTER, ti->init_srb + COMMAND_OFST);
  856. writew(htons(OPEN_PASS_BCON_MAC), ti->init_srb + OPEN_OPTIONS_OFST);
  857. if (ti->ring_speed == 16) {
  858. writew(htons(ti->dhb_size16mb), ti->init_srb + DHB_LENGTH_OFST);
  859. writew(htons(ti->rbuf_cnt16), ti->init_srb + NUM_RCV_BUF_OFST);
  860. writew(htons(ti->rbuf_len16), ti->init_srb + RCV_BUF_LEN_OFST);
  861. } else {
  862. writew(htons(ti->dhb_size4mb), ti->init_srb + DHB_LENGTH_OFST);
  863. writew(htons(ti->rbuf_cnt4), ti->init_srb + NUM_RCV_BUF_OFST);
  864. writew(htons(ti->rbuf_len4), ti->init_srb + RCV_BUF_LEN_OFST);
  865. }
  866. writeb(NUM_DHB, /* always 2 */ ti->init_srb + NUM_DHB_OFST);
  867. writeb(DLC_MAX_SAP, ti->init_srb + DLC_MAX_SAP_OFST);
  868. writeb(DLC_MAX_STA, ti->init_srb + DLC_MAX_STA_OFST);
  869. ti->srb = ti->init_srb; /* We use this one in the interrupt handler */
  870. ti->srb_page = ti->init_srb_page;
  871. DPRINTK("Opening adapter: Xmit bfrs: %d X %d, Rcv bfrs: %d X %d\n",
  872. readb(ti->init_srb + NUM_DHB_OFST),
  873. ntohs(readw(ti->init_srb + DHB_LENGTH_OFST)),
  874. ntohs(readw(ti->init_srb + NUM_RCV_BUF_OFST)),
  875. ntohs(readw(ti->init_srb + RCV_BUF_LEN_OFST)));
  876. writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
  877. writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  878. }
  879. /*****************************************************************************/
  880. static void open_sap(unsigned char type, struct net_device *dev)
  881. {
  882. int i;
  883. struct tok_info *ti = (struct tok_info *) dev->priv;
  884. SET_PAGE(ti->srb_page);
  885. for (i = 0; i < sizeof(struct dlc_open_sap); i++)
  886. writeb(0, ti->srb + i);
  887. #define MAX_I_FIELD_OFST 14
  888. #define SAP_VALUE_OFST 16
  889. #define SAP_OPTIONS_OFST 17
  890. #define STATION_COUNT_OFST 18
  891. writeb(DLC_OPEN_SAP, ti->srb + COMMAND_OFST);
  892. writew(htons(MAX_I_FIELD), ti->srb + MAX_I_FIELD_OFST);
  893. writeb(SAP_OPEN_IND_SAP | SAP_OPEN_PRIORITY, ti->srb+ SAP_OPTIONS_OFST);
  894. writeb(SAP_OPEN_STATION_CNT, ti->srb + STATION_COUNT_OFST);
  895. writeb(type, ti->srb + SAP_VALUE_OFST);
  896. writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  897. }
  898. /*****************************************************************************/
  899. static void tok_set_multicast_list(struct net_device *dev)
  900. {
  901. struct tok_info *ti = (struct tok_info *) dev->priv;
  902. struct dev_mc_list *mclist;
  903. unsigned char address[4];
  904. int i;
  905. /*BMS the next line is CRUCIAL or you may be sad when you */
  906. /*BMS ifconfig tr down or hot unplug a PCMCIA card ??hownowbrowncow*/
  907. if (/*BMSHELPdev->start == 0 ||*/ ti->open_status != OPEN) return;
  908. address[0] = address[1] = address[2] = address[3] = 0;
  909. mclist = dev->mc_list;
  910. for (i = 0; i < dev->mc_count; i++) {
  911. address[0] |= mclist->dmi_addr[2];
  912. address[1] |= mclist->dmi_addr[3];
  913. address[2] |= mclist->dmi_addr[4];
  914. address[3] |= mclist->dmi_addr[5];
  915. mclist = mclist->next;
  916. }
  917. SET_PAGE(ti->srb_page);
  918. for (i = 0; i < sizeof(struct srb_set_funct_addr); i++)
  919. writeb(0, ti->srb + i);
  920. #define FUNCT_ADDRESS_OFST 6
  921. writeb(DIR_SET_FUNC_ADDR, ti->srb + COMMAND_OFST);
  922. for (i = 0; i < 4; i++)
  923. writeb(address[i], ti->srb + FUNCT_ADDRESS_OFST + i);
  924. writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  925. #if TR_VERBOSE
  926. DPRINTK("Setting functional address: ");
  927. for (i=0;i<4;i++) printk("%02X ", address[i]);
  928. printk("\n");
  929. #endif
  930. }
  931. /*****************************************************************************/
  932. #define STATION_ID_OFST 4
  933. static int tok_send_packet(struct sk_buff *skb, struct net_device *dev)
  934. {
  935. struct tok_info *ti;
  936. unsigned long flags;
  937. ti = (struct tok_info *) dev->priv;
  938. netif_stop_queue(dev);
  939. /* lock against other CPUs */
  940. spin_lock_irqsave(&(ti->lock), flags);
  941. /* Save skb; we'll need it when the adapter asks for the data */
  942. ti->current_skb = skb;
  943. SET_PAGE(ti->srb_page);
  944. writeb(XMIT_UI_FRAME, ti->srb + COMMAND_OFST);
  945. writew(ti->exsap_station_id, ti->srb + STATION_ID_OFST);
  946. writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  947. spin_unlock_irqrestore(&(ti->lock), flags);
  948. dev->trans_start = jiffies;
  949. return 0;
  950. }
  951. /*****************************************************************************/
  952. static int tok_close(struct net_device *dev)
  953. {
  954. struct tok_info *ti = (struct tok_info *) dev->priv;
  955. /* Important for PCMCIA hot unplug, otherwise, we'll pull the card, */
  956. /* unloading the module from memory, and then if a timer pops, ouch */
  957. del_timer_sync(&ti->tr_timer);
  958. outb(0, dev->base_addr + ADAPTRESET);
  959. ti->sram_phys |= 1;
  960. ti->open_status = CLOSED;
  961. netif_stop_queue(dev);
  962. DPRINTK("Adapter is closed.\n");
  963. return 0;
  964. }
  965. /*****************************************************************************/
  966. #define RETCODE_OFST 2
  967. #define OPEN_ERROR_CODE_OFST 6
  968. #define ASB_ADDRESS_OFST 8
  969. #define SRB_ADDRESS_OFST 10
  970. #define ARB_ADDRESS_OFST 12
  971. #define SSB_ADDRESS_OFST 14
  972. static char *printphase[]= {"Lobe media test","Physical insertion",
  973. "Address verification","Roll call poll","Request Parameters"};
  974. static char *printerror[]={"Function failure","Signal loss","Reserved",
  975. "Frequency error","Timeout","Ring failure","Ring beaconing",
  976. "Duplicate node address",
  977. "Parameter request-retry count exceeded","Remove received",
  978. "IMPL force received","Duplicate modifier",
  979. "No monitor detected","Monitor contention failed for RPL"};
  980. static void __iomem *map_address(struct tok_info *ti, unsigned index, __u8 *page)
  981. {
  982. if (ti->page_mask) {
  983. *page = (index >> 8) & ti->page_mask;
  984. index &= ~(ti->page_mask << 8);
  985. }
  986. return ti->sram_virt + index;
  987. }
  988. static void dir_open_adapter (struct net_device *dev)
  989. {
  990. struct tok_info *ti = (struct tok_info *) dev->priv;
  991. unsigned char ret_code;
  992. __u16 err;
  993. ti->srb = map_address(ti,
  994. ntohs(readw(ti->init_srb + SRB_ADDRESS_OFST)),
  995. &ti->srb_page);
  996. ti->ssb = map_address(ti,
  997. ntohs(readw(ti->init_srb + SSB_ADDRESS_OFST)),
  998. &ti->ssb_page);
  999. ti->arb = map_address(ti,
  1000. ntohs(readw(ti->init_srb + ARB_ADDRESS_OFST)),
  1001. &ti->arb_page);
  1002. ti->asb = map_address(ti,
  1003. ntohs(readw(ti->init_srb + ASB_ADDRESS_OFST)),
  1004. &ti->asb_page);
  1005. ti->current_skb = NULL;
  1006. ret_code = readb(ti->init_srb + RETCODE_OFST);
  1007. err = ntohs(readw(ti->init_srb + OPEN_ERROR_CODE_OFST));
  1008. if (!ret_code) {
  1009. ti->open_status = OPEN; /* TR adapter is now available */
  1010. if (ti->open_mode == AUTOMATIC) {
  1011. DPRINTK("Adapter reopened.\n");
  1012. }
  1013. writeb(~SRB_RESP_INT, ti->mmio+ACA_OFFSET+ACA_RESET+ISRP_ODD);
  1014. open_sap(EXTENDED_SAP, dev);
  1015. return;
  1016. }
  1017. ti->open_failure = YES;
  1018. if (ret_code == 7){
  1019. if (err == 0x24) {
  1020. if (!ti->auto_speedsave) {
  1021. DPRINTK("Open failed: Adapter speed must match "
  1022. "ring speed if Automatic Ring Speed Save is "
  1023. "disabled.\n");
  1024. ti->open_action = FAIL;
  1025. }else
  1026. DPRINTK("Retrying open to adjust to "
  1027. "ring speed, ");
  1028. } else if (err == 0x2d) {
  1029. DPRINTK("Physical Insertion: No Monitor Detected, ");
  1030. printk("retrying after %ds delay...\n",
  1031. TR_RETRY_INTERVAL/HZ);
  1032. } else if (err == 0x11) {
  1033. DPRINTK("Lobe Media Function Failure (0x11), ");
  1034. printk(" retrying after %ds delay...\n",
  1035. TR_RETRY_INTERVAL/HZ);
  1036. } else {
  1037. char **prphase = printphase;
  1038. char **prerror = printerror;
  1039. DPRINTK("TR Adapter misc open failure, error code = ");
  1040. printk("0x%x, Phase: %s, Error: %s\n",
  1041. err, prphase[err/16 -1], prerror[err%16 -1]);
  1042. printk(" retrying after %ds delay...\n",
  1043. TR_RETRY_INTERVAL/HZ);
  1044. }
  1045. } else DPRINTK("open failed: ret_code = %02X..., ", ret_code);
  1046. if (ti->open_action != FAIL) {
  1047. if (ti->open_mode==AUTOMATIC){
  1048. ti->open_action = REOPEN;
  1049. ibmtr_reset_timer(&(ti->tr_timer), dev);
  1050. return;
  1051. }
  1052. wake_up(&ti->wait_for_reset);
  1053. return;
  1054. }
  1055. DPRINTK("FAILURE, CAPUT\n");
  1056. }
  1057. /******************************************************************************/
  1058. static irqreturn_t tok_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  1059. {
  1060. unsigned char status;
  1061. /* unsigned char status_even ; */
  1062. struct tok_info *ti;
  1063. struct net_device *dev;
  1064. #ifdef ENABLE_PAGING
  1065. unsigned char save_srpr;
  1066. #endif
  1067. dev = dev_id;
  1068. #if TR_VERBOSE
  1069. DPRINTK("Int from tok_driver, dev : %p irq%d regs=%p\n", dev,irq,regs);
  1070. #endif
  1071. ti = (struct tok_info *) dev->priv;
  1072. if (ti->sram_phys & 1)
  1073. return IRQ_NONE; /* PCMCIA card extraction flag */
  1074. spin_lock(&(ti->lock));
  1075. #ifdef ENABLE_PAGING
  1076. save_srpr = readb(ti->mmio + ACA_OFFSET + ACA_RW + SRPR_EVEN);
  1077. #endif
  1078. /* Disable interrupts till processing is finished */
  1079. writeb((~INT_ENABLE), ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_EVEN);
  1080. /* Reset interrupt for ISA boards */
  1081. if (ti->adapter_int_enable)
  1082. outb(0, ti->adapter_int_enable);
  1083. else /* used for PCMCIA cards */
  1084. outb(0, ti->global_int_enable);
  1085. if (ti->do_tok_int == FIRST_INT){
  1086. initial_tok_int(dev);
  1087. #ifdef ENABLE_PAGING
  1088. writeb(save_srpr, ti->mmio + ACA_OFFSET + ACA_RW + SRPR_EVEN);
  1089. #endif
  1090. spin_unlock(&(ti->lock));
  1091. return IRQ_HANDLED;
  1092. }
  1093. /* Begin interrupt handler HERE inline to avoid the extra
  1094. levels of logic and call depth for the original solution. */
  1095. status = readb(ti->mmio + ACA_OFFSET + ACA_RW + ISRP_ODD);
  1096. /*BMSstatus_even = readb (ti->mmio + ACA_OFFSET + ACA_RW + ISRP_EVEN) */
  1097. /*BMSdebugprintk("tok_interrupt: ISRP_ODD = 0x%x ISRP_EVEN = 0x%x\n", */
  1098. /*BMS status,status_even); */
  1099. if (status & ADAP_CHK_INT) {
  1100. int i;
  1101. void __iomem *check_reason;
  1102. __u8 check_reason_page = 0;
  1103. check_reason = map_address(ti,
  1104. ntohs(readw(ti->mmio+ ACA_OFFSET+ACA_RW + WWCR_EVEN)),
  1105. &check_reason_page);
  1106. SET_PAGE(check_reason_page);
  1107. DPRINTK("Adapter check interrupt\n");
  1108. DPRINTK("8 reason bytes follow: ");
  1109. for (i = 0; i < 8; i++, check_reason++)
  1110. printk("%02X ", (int) readb(check_reason));
  1111. printk("\n");
  1112. writeb(~ADAP_CHK_INT, ti->mmio+ ACA_OFFSET+ACA_RESET+ ISRP_ODD);
  1113. status = readb(ti->mmio + ACA_OFFSET + ACA_RW + ISRA_EVEN);
  1114. DPRINTK("ISRA_EVEN == 0x02%x\n",status);
  1115. ti->open_status = CLOSED;
  1116. ti->sap_status = CLOSED;
  1117. ti->open_mode = AUTOMATIC;
  1118. netif_carrier_off(dev);
  1119. netif_stop_queue(dev);
  1120. ti->open_action = RESTART;
  1121. outb(0, dev->base_addr + ADAPTRESET);
  1122. ibmtr_reset_timer(&(ti->tr_timer), dev);/*BMS try to reopen*/
  1123. spin_unlock(&(ti->lock));
  1124. return IRQ_HANDLED;
  1125. }
  1126. if (readb(ti->mmio + ACA_OFFSET + ACA_RW + ISRP_EVEN)
  1127. & (TCR_INT | ERR_INT | ACCESS_INT)) {
  1128. DPRINTK("adapter error: ISRP_EVEN : %02x\n",
  1129. (int)readb(ti->mmio+ ACA_OFFSET + ACA_RW + ISRP_EVEN));
  1130. writeb(~(TCR_INT | ERR_INT | ACCESS_INT),
  1131. ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_EVEN);
  1132. status= readb(ti->mmio+ ACA_OFFSET + ACA_RW + ISRA_EVEN);/*BMS*/
  1133. DPRINTK("ISRA_EVEN == 0x02%x\n",status);/*BMS*/
  1134. writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
  1135. #ifdef ENABLE_PAGING
  1136. writeb(save_srpr, ti->mmio + ACA_OFFSET + ACA_RW + SRPR_EVEN);
  1137. #endif
  1138. spin_unlock(&(ti->lock));
  1139. return IRQ_HANDLED;
  1140. }
  1141. if (status & SRB_RESP_INT) { /* SRB response */
  1142. SET_PAGE(ti->srb_page);
  1143. #if TR_VERBOSE
  1144. DPRINTK("SRB resp: cmd=%02X rsp=%02X\n",
  1145. readb(ti->srb), readb(ti->srb + RETCODE_OFST));
  1146. #endif
  1147. switch (readb(ti->srb)) { /* SRB command check */
  1148. case XMIT_DIR_FRAME:{
  1149. unsigned char xmit_ret_code;
  1150. xmit_ret_code = readb(ti->srb + RETCODE_OFST);
  1151. if (xmit_ret_code == 0xff) break;
  1152. DPRINTK("error on xmit_dir_frame request: %02X\n",
  1153. xmit_ret_code);
  1154. if (ti->current_skb) {
  1155. dev_kfree_skb_irq(ti->current_skb);
  1156. ti->current_skb = NULL;
  1157. }
  1158. /*dev->tbusy = 0;*/
  1159. netif_wake_queue(dev);
  1160. if (ti->readlog_pending)
  1161. ibmtr_readlog(dev);
  1162. break;
  1163. }
  1164. case XMIT_UI_FRAME:{
  1165. unsigned char xmit_ret_code;
  1166. xmit_ret_code = readb(ti->srb + RETCODE_OFST);
  1167. if (xmit_ret_code == 0xff) break;
  1168. DPRINTK("error on xmit_ui_frame request: %02X\n",
  1169. xmit_ret_code);
  1170. if (ti->current_skb) {
  1171. dev_kfree_skb_irq(ti->current_skb);
  1172. ti->current_skb = NULL;
  1173. }
  1174. netif_wake_queue(dev);
  1175. if (ti->readlog_pending)
  1176. ibmtr_readlog(dev);
  1177. break;
  1178. }
  1179. case DIR_OPEN_ADAPTER:
  1180. dir_open_adapter(dev);
  1181. break;
  1182. case DLC_OPEN_SAP:
  1183. if (readb(ti->srb + RETCODE_OFST)) {
  1184. DPRINTK("open_sap failed: ret_code = %02X, "
  1185. "retrying\n",
  1186. (int) readb(ti->srb + RETCODE_OFST));
  1187. ti->open_action = REOPEN;
  1188. ibmtr_reset_timer(&(ti->tr_timer), dev);
  1189. break;
  1190. }
  1191. ti->exsap_station_id = readw(ti->srb + STATION_ID_OFST);
  1192. ti->sap_status = OPEN;/* TR adapter is now available */
  1193. if (ti->open_mode==MANUAL){
  1194. wake_up(&ti->wait_for_reset);
  1195. break;
  1196. }
  1197. netif_wake_queue(dev);
  1198. netif_carrier_on(dev);
  1199. break;
  1200. case DIR_INTERRUPT:
  1201. case DIR_MOD_OPEN_PARAMS:
  1202. case DIR_SET_GRP_ADDR:
  1203. case DIR_SET_FUNC_ADDR:
  1204. case DLC_CLOSE_SAP:
  1205. if (readb(ti->srb + RETCODE_OFST))
  1206. DPRINTK("error on %02X: %02X\n",
  1207. (int) readb(ti->srb + COMMAND_OFST),
  1208. (int) readb(ti->srb + RETCODE_OFST));
  1209. break;
  1210. case DIR_READ_LOG:
  1211. if (readb(ti->srb + RETCODE_OFST)){
  1212. DPRINTK("error on dir_read_log: %02X\n",
  1213. (int) readb(ti->srb + RETCODE_OFST));
  1214. netif_wake_queue(dev);
  1215. break;
  1216. }
  1217. #if IBMTR_DEBUG_MESSAGES
  1218. #define LINE_ERRORS_OFST 0
  1219. #define INTERNAL_ERRORS_OFST 1
  1220. #define BURST_ERRORS_OFST 2
  1221. #define AC_ERRORS_OFST 3
  1222. #define ABORT_DELIMITERS_OFST 4
  1223. #define LOST_FRAMES_OFST 6
  1224. #define RECV_CONGEST_COUNT_OFST 7
  1225. #define FRAME_COPIED_ERRORS_OFST 8
  1226. #define FREQUENCY_ERRORS_OFST 9
  1227. #define TOKEN_ERRORS_OFST 10
  1228. DPRINTK("Line errors %02X, Internal errors %02X, "
  1229. "Burst errors %02X\n" "A/C errors %02X, "
  1230. "Abort delimiters %02X, Lost frames %02X\n"
  1231. "Receive congestion count %02X, "
  1232. "Frame copied errors %02X\nFrequency errors %02X, "
  1233. "Token errors %02X\n",
  1234. (int) readb(ti->srb + LINE_ERRORS_OFST),
  1235. (int) readb(ti->srb + INTERNAL_ERRORS_OFST),
  1236. (int) readb(ti->srb + BURST_ERRORS_OFST),
  1237. (int) readb(ti->srb + AC_ERRORS_OFST),
  1238. (int) readb(ti->srb + ABORT_DELIMITERS_OFST),
  1239. (int) readb(ti->srb + LOST_FRAMES_OFST),
  1240. (int) readb(ti->srb + RECV_CONGEST_COUNT_OFST),
  1241. (int) readb(ti->srb + FRAME_COPIED_ERRORS_OFST),
  1242. (int) readb(ti->srb + FREQUENCY_ERRORS_OFST),
  1243. (int) readb(ti->srb + TOKEN_ERRORS_OFST));
  1244. #endif
  1245. netif_wake_queue(dev);
  1246. break;
  1247. default:
  1248. DPRINTK("Unknown command %02X encountered\n",
  1249. (int) readb(ti->srb));
  1250. } /* end switch SRB command check */
  1251. writeb(~SRB_RESP_INT, ti->mmio+ ACA_OFFSET+ACA_RESET+ ISRP_ODD);
  1252. } /* if SRB response */
  1253. if (status & ASB_FREE_INT) { /* ASB response */
  1254. SET_PAGE(ti->asb_page);
  1255. #if TR_VERBOSE
  1256. DPRINTK("ASB resp: cmd=%02X\n", readb(ti->asb));
  1257. #endif
  1258. switch (readb(ti->asb)) { /* ASB command check */
  1259. case REC_DATA:
  1260. case XMIT_UI_FRAME:
  1261. case XMIT_DIR_FRAME:
  1262. break;
  1263. default:
  1264. DPRINTK("unknown command in asb %02X\n",
  1265. (int) readb(ti->asb));
  1266. } /* switch ASB command check */
  1267. if (readb(ti->asb + 2) != 0xff) /* checks ret_code */
  1268. DPRINTK("ASB error %02X in cmd %02X\n",
  1269. (int) readb(ti->asb + 2), (int) readb(ti->asb));
  1270. writeb(~ASB_FREE_INT, ti->mmio+ ACA_OFFSET+ACA_RESET+ ISRP_ODD);
  1271. } /* if ASB response */
  1272. #define STATUS_OFST 6
  1273. #define NETW_STATUS_OFST 6
  1274. if (status & ARB_CMD_INT) { /* ARB response */
  1275. SET_PAGE(ti->arb_page);
  1276. #if TR_VERBOSE
  1277. DPRINTK("ARB resp: cmd=%02X\n", readb(ti->arb));
  1278. #endif
  1279. switch (readb(ti->arb)) { /* ARB command check */
  1280. case DLC_STATUS:
  1281. DPRINTK("DLC_STATUS new status: %02X on station %02X\n",
  1282. ntohs(readw(ti->arb + STATUS_OFST)),
  1283. ntohs(readw(ti->arb+ STATION_ID_OFST)));
  1284. break;
  1285. case REC_DATA:
  1286. tr_rx(dev);
  1287. break;
  1288. case RING_STAT_CHANGE:{
  1289. unsigned short ring_status;
  1290. ring_status= ntohs(readw(ti->arb + NETW_STATUS_OFST));
  1291. if (ibmtr_debug_trace & TRC_INIT)
  1292. DPRINTK("Ring Status Change...(0x%x)\n",
  1293. ring_status);
  1294. if(ring_status& (REMOVE_RECV|AUTO_REMOVAL|LOBE_FAULT)){
  1295. netif_stop_queue(dev);
  1296. netif_carrier_off(dev);
  1297. DPRINTK("Remove received, or Auto-removal error"
  1298. ", or Lobe fault\n");
  1299. DPRINTK("We'll try to reopen the closed adapter"
  1300. " after a %d second delay.\n",
  1301. TR_RETRY_INTERVAL/HZ);
  1302. /*I was confused: I saw the TR reopening but */
  1303. /*forgot:with an RJ45 in an RJ45/ICS adapter */
  1304. /*but adapter not in the ring, the TR will */
  1305. /* open, and then soon close and come here. */
  1306. ti->open_mode = AUTOMATIC;
  1307. ti->open_status = CLOSED; /*12/2000 BMS*/
  1308. ti->open_action = REOPEN;
  1309. ibmtr_reset_timer(&(ti->tr_timer), dev);
  1310. } else if (ring_status & LOG_OVERFLOW) {
  1311. if(netif_queue_stopped(dev))
  1312. ti->readlog_pending = 1;
  1313. else
  1314. ibmtr_readlog(dev);
  1315. }
  1316. break;
  1317. }
  1318. case XMIT_DATA_REQ:
  1319. tr_tx(dev);
  1320. break;
  1321. default:
  1322. DPRINTK("Unknown command %02X in arb\n",
  1323. (int) readb(ti->arb));
  1324. break;
  1325. } /* switch ARB command check */
  1326. writeb(~ARB_CMD_INT, ti->mmio+ ACA_OFFSET+ACA_RESET + ISRP_ODD);
  1327. writeb(ARB_FREE, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  1328. } /* if ARB response */
  1329. if (status & SSB_RESP_INT) { /* SSB response */
  1330. unsigned char retcode;
  1331. SET_PAGE(ti->ssb_page);
  1332. #if TR_VERBOSE
  1333. DPRINTK("SSB resp: cmd=%02X rsp=%02X\n",
  1334. readb(ti->ssb), readb(ti->ssb + 2));
  1335. #endif
  1336. switch (readb(ti->ssb)) { /* SSB command check */
  1337. case XMIT_DIR_FRAME:
  1338. case XMIT_UI_FRAME:
  1339. retcode = readb(ti->ssb + 2);
  1340. if (retcode && (retcode != 0x22))/* checks ret_code */
  1341. DPRINTK("xmit ret_code: %02X xmit error code: "
  1342. "%02X\n",
  1343. (int)retcode, (int)readb(ti->ssb + 6));
  1344. else
  1345. ti->tr_stats.tx_packets++;
  1346. break;
  1347. case XMIT_XID_CMD:
  1348. DPRINTK("xmit xid ret_code: %02X\n",
  1349. (int) readb(ti->ssb + 2));
  1350. default:
  1351. DPRINTK("Unknown command %02X in ssb\n",
  1352. (int) readb(ti->ssb));
  1353. } /* SSB command check */
  1354. writeb(~SSB_RESP_INT, ti->mmio+ ACA_OFFSET+ACA_RESET+ ISRP_ODD);
  1355. writeb(SSB_FREE, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  1356. } /* if SSB response */
  1357. #ifdef ENABLE_PAGING
  1358. writeb(save_srpr, ti->mmio + ACA_OFFSET + ACA_RW + SRPR_EVEN);
  1359. #endif
  1360. writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
  1361. spin_unlock(&(ti->lock));
  1362. return IRQ_HANDLED;
  1363. } /*tok_interrupt */
  1364. /*****************************************************************************/
  1365. #define INIT_STATUS_OFST 1
  1366. #define INIT_STATUS_2_OFST 2
  1367. #define ENCODED_ADDRESS_OFST 8
  1368. static void initial_tok_int(struct net_device *dev)
  1369. {
  1370. __u32 encoded_addr, hw_encoded_addr;
  1371. struct tok_info *ti;
  1372. unsigned char init_status; /*BMS 12/2000*/
  1373. ti = (struct tok_info *) dev->priv;
  1374. ti->do_tok_int = NOT_FIRST;
  1375. /* we assign the shared-ram address for ISA devices */
  1376. writeb(ti->sram_base, ti->mmio + ACA_OFFSET + ACA_RW + RRR_EVEN);
  1377. #ifndef PCMCIA
  1378. ti->sram_virt = ioremap(((__u32)ti->sram_base << 12), ti->avail_shared_ram);
  1379. #endif
  1380. ti->init_srb = map_address(ti,
  1381. ntohs(readw(ti->mmio + ACA_OFFSET + WRBR_EVEN)),
  1382. &ti->init_srb_page);
  1383. if (ti->page_mask && ti->avail_shared_ram == 127) {
  1384. void __iomem *last_512;
  1385. __u8 last_512_page=0;
  1386. int i;
  1387. last_512 = map_address(ti, 0xfe00, &last_512_page);
  1388. /* initialize high section of ram (if necessary) */
  1389. SET_PAGE(last_512_page);
  1390. for (i = 0; i < 512; i++)
  1391. writeb(0, last_512 + i);
  1392. }
  1393. SET_PAGE(ti->init_srb_page);
  1394. #if TR_VERBOSE
  1395. {
  1396. int i;
  1397. DPRINTK("ti->init_srb_page=0x%x\n", ti->init_srb_page);
  1398. DPRINTK("init_srb(%p):", ti->init_srb );
  1399. for (i = 0; i < 20; i++)
  1400. printk("%02X ", (int) readb(ti->init_srb + i));
  1401. printk("\n");
  1402. }
  1403. #endif
  1404. hw_encoded_addr = readw(ti->init_srb + ENCODED_ADDRESS_OFST);
  1405. encoded_addr = ntohs(hw_encoded_addr);
  1406. init_status= /*BMS 12/2000 check for shallow mode possibility (Turbo)*/
  1407. readb(ti->init_srb+offsetof(struct srb_init_response,init_status));
  1408. /*printk("Initial interrupt: init_status= 0x%02x\n",init_status);*/
  1409. ti->ring_speed = init_status & 0x01 ? 16 : 4;
  1410. DPRINTK("Initial interrupt : %d Mbps, shared RAM base %08x.\n",
  1411. ti->ring_speed, (unsigned int)dev->mem_start);
  1412. ti->auto_speedsave=readb(ti->init_srb+INIT_STATUS_2_OFST)&4?TRUE:FALSE;
  1413. if (ti->open_mode == MANUAL) wake_up(&ti->wait_for_reset);
  1414. else tok_open_adapter((unsigned long)dev);
  1415. } /*initial_tok_int() */
  1416. /*****************************************************************************/
  1417. #define CMD_CORRELATE_OFST 1
  1418. #define DHB_ADDRESS_OFST 6
  1419. #define FRAME_LENGTH_OFST 6
  1420. #define HEADER_LENGTH_OFST 8
  1421. #define RSAP_VALUE_OFST 9
  1422. static void tr_tx(struct net_device *dev)
  1423. {
  1424. struct tok_info *ti = (struct tok_info *) dev->priv;
  1425. struct trh_hdr *trhdr = (struct trh_hdr *) ti->current_skb->data;
  1426. unsigned int hdr_len;
  1427. __u32 dhb=0,dhb_base;
  1428. void __iomem *dhbuf = NULL;
  1429. unsigned char xmit_command;
  1430. int i,dhb_len=0x4000,src_len,src_offset;
  1431. struct trllc *llc;
  1432. struct srb_xmit xsrb;
  1433. __u8 dhb_page = 0;
  1434. __u8 llc_ssap;
  1435. SET_PAGE(ti->asb_page);
  1436. if (readb(ti->asb+RETCODE_OFST) != 0xFF) DPRINTK("ASB not free !!!\n");
  1437. /* in providing the transmit interrupts, is telling us it is ready for
  1438. data and providing a shared memory address for us to stuff with data.
  1439. Here we compute the effective address where we will place data.
  1440. */
  1441. SET_PAGE(ti->arb_page);
  1442. dhb=dhb_base=ntohs(readw(ti->arb + DHB_ADDRESS_OFST));
  1443. if (ti->page_mask) {
  1444. dhb_page = (dhb_base >> 8) & ti->page_mask;
  1445. dhb=dhb_base & ~(ti->page_mask << 8);
  1446. }
  1447. dhbuf = ti->sram_virt + dhb;
  1448. /* Figure out the size of the 802.5 header */
  1449. if (!(trhdr->saddr[0] & 0x80)) /* RIF present? */
  1450. hdr_len = sizeof(struct trh_hdr) - TR_MAXRIFLEN;
  1451. else
  1452. hdr_len = ((ntohs(trhdr->rcf) & TR_RCF_LEN_MASK) >> 8)
  1453. + sizeof(struct trh_hdr) - TR_MAXRIFLEN;
  1454. llc = (struct trllc *) (ti->current_skb->data + hdr_len);
  1455. llc_ssap = llc->ssap;
  1456. SET_PAGE(ti->srb_page);
  1457. memcpy_fromio(&xsrb, ti->srb, sizeof(xsrb));
  1458. SET_PAGE(ti->asb_page);
  1459. xmit_command = xsrb.command;
  1460. writeb(xmit_command, ti->asb + COMMAND_OFST);
  1461. writew(xsrb.station_id, ti->asb + STATION_ID_OFST);
  1462. writeb(llc_ssap, ti->asb + RSAP_VALUE_OFST);
  1463. writeb(xsrb.cmd_corr, ti->asb + CMD_CORRELATE_OFST);
  1464. writeb(0, ti->asb + RETCODE_OFST);
  1465. if ((xmit_command == XMIT_XID_CMD) || (xmit_command == XMIT_TEST_CMD)) {
  1466. writew(htons(0x11), ti->asb + FRAME_LENGTH_OFST);
  1467. writeb(0x0e, ti->asb + HEADER_LENGTH_OFST);
  1468. SET_PAGE(dhb_page);
  1469. writeb(AC, dhbuf);
  1470. writeb(LLC_FRAME, dhbuf + 1);
  1471. for (i = 0; i < TR_ALEN; i++)
  1472. writeb((int) 0x0FF, dhbuf + i + 2);
  1473. for (i = 0; i < TR_ALEN; i++)
  1474. writeb(0, dhbuf + i + TR_ALEN + 2);
  1475. writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  1476. return;
  1477. }
  1478. /*
  1479. * the token ring packet is copied from sk_buff to the adapter
  1480. * buffer identified in the command data received with the interrupt.
  1481. */
  1482. writeb(hdr_len, ti->asb + HEADER_LENGTH_OFST);
  1483. writew(htons(ti->current_skb->len), ti->asb + FRAME_LENGTH_OFST);
  1484. src_len=ti->current_skb->len;
  1485. src_offset=0;
  1486. dhb=dhb_base;
  1487. while(1) {
  1488. if (ti->page_mask) {
  1489. dhb_page=(dhb >> 8) & ti->page_mask;
  1490. dhb=dhb & ~(ti->page_mask << 8);
  1491. dhb_len=0x4000-dhb; /* remaining size of this page */
  1492. }
  1493. dhbuf = ti->sram_virt + dhb;
  1494. SET_PAGE(dhb_page);
  1495. if (src_len > dhb_len) {
  1496. memcpy_toio(dhbuf,&ti->current_skb->data[src_offset],
  1497. dhb_len);
  1498. src_len -= dhb_len;
  1499. src_offset += dhb_len;
  1500. dhb_base+=dhb_len;
  1501. dhb=dhb_base;
  1502. continue;
  1503. }
  1504. memcpy_toio(dhbuf, &ti->current_skb->data[src_offset], src_len);
  1505. break;
  1506. }
  1507. writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  1508. ti->tr_stats.tx_bytes += ti->current_skb->len;
  1509. dev_kfree_skb_irq(ti->current_skb);
  1510. ti->current_skb = NULL;
  1511. netif_wake_queue(dev);
  1512. if (ti->readlog_pending)
  1513. ibmtr_readlog(dev);
  1514. } /*tr_tx */
  1515. /*****************************************************************************/
  1516. #define RECEIVE_BUFFER_OFST 6
  1517. #define LAN_HDR_LENGTH_OFST 8
  1518. #define DLC_HDR_LENGTH_OFST 9
  1519. #define DSAP_OFST 0
  1520. #define SSAP_OFST 1
  1521. #define LLC_OFST 2
  1522. #define PROTID_OFST 3
  1523. #define ETHERTYPE_OFST 6
  1524. static void tr_rx(struct net_device *dev)
  1525. {
  1526. struct tok_info *ti = (struct tok_info *) dev->priv;
  1527. __u32 rbuffer;
  1528. void __iomem *rbuf, *rbufdata, *llc;
  1529. __u8 rbuffer_page = 0;
  1530. unsigned char *data;
  1531. unsigned int rbuffer_len, lan_hdr_len, hdr_len, ip_len, length;
  1532. unsigned char dlc_hdr_len;
  1533. struct sk_buff *skb;
  1534. unsigned int skb_size = 0;
  1535. int IPv4_p = 0;
  1536. unsigned int chksum = 0;
  1537. struct iphdr *iph;
  1538. struct arb_rec_req rarb;
  1539. SET_PAGE(ti->arb_page);
  1540. memcpy_fromio(&rarb, ti->arb, sizeof(rarb));
  1541. rbuffer = ntohs(rarb.rec_buf_addr) ;
  1542. rbuf = map_address(ti, rbuffer, &rbuffer_page);
  1543. SET_PAGE(ti->asb_page);
  1544. if (readb(ti->asb + RETCODE_OFST) !=0xFF) DPRINTK("ASB not free !!!\n");
  1545. writeb(REC_DATA, ti->asb + COMMAND_OFST);
  1546. writew(rarb.station_id, ti->asb + STATION_ID_OFST);
  1547. writew(rarb.rec_buf_addr, ti->asb + RECEIVE_BUFFER_OFST);
  1548. lan_hdr_len = rarb.lan_hdr_len;
  1549. if (lan_hdr_len > sizeof(struct trh_hdr)) {
  1550. DPRINTK("Linux cannot handle greater than 18 bytes RIF\n");
  1551. return;
  1552. } /*BMS I added this above just to be very safe */
  1553. dlc_hdr_len = readb(ti->arb + DLC_HDR_LENGTH_OFST);
  1554. hdr_len = lan_hdr_len + sizeof(struct trllc) + sizeof(struct iphdr);
  1555. SET_PAGE(rbuffer_page);
  1556. llc = rbuf + offsetof(struct rec_buf, data) + lan_hdr_len;
  1557. #if TR_VERBOSE
  1558. DPRINTK("offsetof data: %02X lan_hdr_len: %02X\n",
  1559. (__u32) offsetof(struct rec_buf, data), (unsigned int) lan_hdr_len);
  1560. DPRINTK("llc: %08X rec_buf_addr: %04X dev->mem_start: %lX\n",
  1561. llc, ntohs(rarb.rec_buf_addr), dev->mem_start);
  1562. DPRINTK("dsap: %02X, ssap: %02X, llc: %02X, protid: %02X%02X%02X, "
  1563. "ethertype: %04X\n",
  1564. (int) readb(llc + DSAP_OFST), (int) readb(llc + SSAP_OFST),
  1565. (int) readb(llc + LLC_OFST), (int) readb(llc + PROTID_OFST),
  1566. (int) readb(llc+PROTID_OFST+1),(int)readb(llc+PROTID_OFST + 2),
  1567. (int) ntohs(readw(llc + ETHERTYPE_OFST)));
  1568. #endif
  1569. if (readb(llc + offsetof(struct trllc, llc)) != UI_CMD) {
  1570. SET_PAGE(ti->asb_page);
  1571. writeb(DATA_LOST, ti->asb + RETCODE_OFST);
  1572. ti->tr_stats.rx_dropped++;
  1573. writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  1574. return;
  1575. }
  1576. length = ntohs(rarb.frame_len);
  1577. if (readb(llc + DSAP_OFST) == EXTENDED_SAP &&
  1578. readb(llc + SSAP_OFST) == EXTENDED_SAP &&
  1579. length >= hdr_len) IPv4_p = 1;
  1580. #if TR_VERBOSE
  1581. #define SADDR_OFST 8
  1582. #define DADDR_OFST 2
  1583. if (!IPv4_p) {
  1584. void __iomem *trhhdr = rbuf + offsetof(struct rec_buf, data);
  1585. DPRINTK("Probably non-IP frame received.\n");
  1586. DPRINTK("ssap: %02X dsap: %02X "
  1587. "saddr: %02X:%02X:%02X:%02X:%02X:%02X "
  1588. "daddr: %02X:%02X:%02X:%02X:%02X:%02X\n",
  1589. readb(llc + SSAP_OFST), readb(llc + DSAP_OFST),
  1590. readb(trhhdr+SADDR_OFST), readb(trhhdr+ SADDR_OFST+1),
  1591. readb(trhhdr+SADDR_OFST+2), readb(trhhdr+SADDR_OFST+3),
  1592. readb(trhhdr+SADDR_OFST+4), readb(trhhdr+SADDR_OFST+5),
  1593. readb(trhhdr+DADDR_OFST), readb(trhhdr+DADDR_OFST + 1),
  1594. readb(trhhdr+DADDR_OFST+2), readb(trhhdr+DADDR_OFST+3),
  1595. readb(trhhdr+DADDR_OFST+4), readb(trhhdr+DADDR_OFST+5));
  1596. }
  1597. #endif
  1598. /*BMS handle the case she comes in with few hops but leaves with many */
  1599. skb_size=length-lan_hdr_len+sizeof(struct trh_hdr)+sizeof(struct trllc);
  1600. if (!(skb = dev_alloc_skb(skb_size))) {
  1601. DPRINTK("out of memory. frame dropped.\n");
  1602. ti->tr_stats.rx_dropped++;
  1603. SET_PAGE(ti->asb_page);
  1604. writeb(DATA_LOST, ti->asb + offsetof(struct asb_rec, ret_code));
  1605. writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  1606. return;
  1607. }
  1608. /*BMS again, if she comes in with few but leaves with many */
  1609. skb_reserve(skb, sizeof(struct trh_hdr) - lan_hdr_len);
  1610. skb_put(skb, length);
  1611. skb->dev = dev;
  1612. data = skb->data;
  1613. rbuffer_len = ntohs(readw(rbuf + offsetof(struct rec_buf, buf_len)));
  1614. rbufdata = rbuf + offsetof(struct rec_buf, data);
  1615. if (IPv4_p) {
  1616. /* Copy the headers without checksumming */
  1617. memcpy_fromio(data, rbufdata, hdr_len);
  1618. /* Watch for padded packets and bogons */
  1619. iph= (struct iphdr *)(data+ lan_hdr_len + sizeof(struct trllc));
  1620. ip_len = ntohs(iph->tot_len) - sizeof(struct iphdr);
  1621. length -= hdr_len;
  1622. if ((ip_len <= length) && (ip_len > 7))
  1623. length = ip_len;
  1624. data += hdr_len;
  1625. rbuffer_len -= hdr_len;
  1626. rbufdata += hdr_len;
  1627. }
  1628. /* Copy the payload... */
  1629. #define BUFFER_POINTER_OFST 2
  1630. #define BUFFER_LENGTH_OFST 6
  1631. for (;;) {
  1632. if (ibmtr_debug_trace&TRC_INITV && length < rbuffer_len)
  1633. DPRINTK("CURIOUS, length=%d < rbuffer_len=%d\n",
  1634. length,rbuffer_len);
  1635. if (IPv4_p)
  1636. chksum=csum_partial_copy_nocheck((void*)rbufdata,
  1637. data,length<rbuffer_len?length:rbuffer_len,chksum);
  1638. else
  1639. memcpy_fromio(data, rbufdata, rbuffer_len);
  1640. rbuffer = ntohs(readw(rbuf+BUFFER_POINTER_OFST)) ;
  1641. if (!rbuffer)
  1642. break;
  1643. rbuffer -= 2;
  1644. length -= rbuffer_len;
  1645. data += rbuffer_len;
  1646. rbuf = map_address(ti, rbuffer, &rbuffer_page);
  1647. SET_PAGE(rbuffer_page);
  1648. rbuffer_len = ntohs(readw(rbuf + BUFFER_LENGTH_OFST));
  1649. rbufdata = rbuf + offsetof(struct rec_buf, data);
  1650. }
  1651. SET_PAGE(ti->asb_page);
  1652. writeb(0, ti->asb + offsetof(struct asb_rec, ret_code));
  1653. writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  1654. ti->tr_stats.rx_bytes += skb->len;
  1655. ti->tr_stats.rx_packets++;
  1656. skb->protocol = tr_type_trans(skb, dev);
  1657. if (IPv4_p) {
  1658. skb->csum = chksum;
  1659. skb->ip_summed = 1;
  1660. }
  1661. netif_rx(skb);
  1662. dev->last_rx = jiffies;
  1663. } /*tr_rx */
  1664. /*****************************************************************************/
  1665. static void ibmtr_reset_timer(struct timer_list *tmr, struct net_device *dev)
  1666. {
  1667. tmr->expires = jiffies + TR_RETRY_INTERVAL;
  1668. tmr->data = (unsigned long) dev;
  1669. tmr->function = tok_rerun;
  1670. init_timer(tmr);
  1671. add_timer(tmr);
  1672. }
  1673. /*****************************************************************************/
  1674. void tok_rerun(unsigned long dev_addr){
  1675. struct net_device *dev = (struct net_device *)dev_addr;
  1676. struct tok_info *ti = (struct tok_info *) dev->priv;
  1677. if ( ti->open_action == RESTART){
  1678. ti->do_tok_int = FIRST_INT;
  1679. outb(0, dev->base_addr + ADAPTRESETREL);
  1680. #ifdef ENABLE_PAGING
  1681. if (ti->page_mask)
  1682. writeb(SRPR_ENABLE_PAGING,
  1683. ti->mmio + ACA_OFFSET + ACA_RW + SRPR_EVEN);
  1684. #endif
  1685. writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
  1686. } else
  1687. tok_open_adapter(dev_addr);
  1688. }
  1689. /*****************************************************************************/
  1690. static void ibmtr_readlog(struct net_device *dev)
  1691. {
  1692. struct tok_info *ti;
  1693. ti = (struct tok_info *) dev->priv;
  1694. ti->readlog_pending = 0;
  1695. SET_PAGE(ti->srb_page);
  1696. writeb(DIR_READ_LOG, ti->srb);
  1697. writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
  1698. writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  1699. netif_stop_queue(dev);
  1700. }
  1701. /*****************************************************************************/
  1702. /* tok_get_stats(): Basically a scaffold routine which will return
  1703. the address of the tr_statistics structure associated with
  1704. this device -- the tr.... structure is an ethnet look-alike
  1705. so at least for this iteration may suffice. */
  1706. static struct net_device_stats *tok_get_stats(struct net_device *dev)
  1707. {
  1708. struct tok_info *toki;
  1709. toki = (struct tok_info *) dev->priv;
  1710. return (struct net_device_stats *) &toki->tr_stats;
  1711. }
  1712. /*****************************************************************************/
  1713. static int ibmtr_change_mtu(struct net_device *dev, int mtu)
  1714. {
  1715. struct tok_info *ti = (struct tok_info *) dev->priv;
  1716. if (ti->ring_speed == 16 && mtu > ti->maxmtu16)
  1717. return -EINVAL;
  1718. if (ti->ring_speed == 4 && mtu > ti->maxmtu4)
  1719. return -EINVAL;
  1720. dev->mtu = mtu;
  1721. return 0;
  1722. }
  1723. /*****************************************************************************/
  1724. #ifdef MODULE
  1725. /* 3COM 3C619C supports 8 interrupts, 32 I/O ports */
  1726. static struct net_device *dev_ibmtr[IBMTR_MAX_ADAPTERS];
  1727. static int io[IBMTR_MAX_ADAPTERS] = { 0xa20, 0xa24 };
  1728. static int irq[IBMTR_MAX_ADAPTERS];
  1729. static int mem[IBMTR_MAX_ADAPTERS];
  1730. MODULE_LICENSE("GPL");
  1731. module_param_array(io, int, NULL, 0);
  1732. module_param_array(irq, int, NULL, 0);
  1733. module_param_array(mem, int, NULL, 0);
  1734. static int __init ibmtr_init(void)
  1735. {
  1736. int i;
  1737. int count=0;
  1738. find_turbo_adapters(io);
  1739. for (i = 0; io[i] && (i < IBMTR_MAX_ADAPTERS); i++) {
  1740. struct net_device *dev;
  1741. irq[i] = 0;
  1742. mem[i] = 0;
  1743. dev = alloc_trdev(sizeof(struct tok_info));
  1744. if (dev == NULL) {
  1745. if (i == 0)
  1746. return -ENOMEM;
  1747. break;
  1748. }
  1749. dev->base_addr = io[i];
  1750. dev->irq = irq[i];
  1751. dev->mem_start = mem[i];
  1752. if (ibmtr_probe_card(dev)) {
  1753. free_netdev(dev);
  1754. continue;
  1755. }
  1756. dev_ibmtr[i] = dev;
  1757. count++;
  1758. }
  1759. if (count) return 0;
  1760. printk("ibmtr: register_netdev() returned non-zero.\n");
  1761. return -EIO;
  1762. }
  1763. module_init(ibmtr_init);
  1764. static void __exit ibmtr_cleanup(void)
  1765. {
  1766. int i;
  1767. for (i = 0; i < IBMTR_MAX_ADAPTERS; i++){
  1768. if (!dev_ibmtr[i])
  1769. continue;
  1770. unregister_netdev(dev_ibmtr[i]);
  1771. ibmtr_cleanup_card(dev_ibmtr[i]);
  1772. free_netdev(dev_ibmtr[i]);
  1773. }
  1774. }
  1775. module_exit(ibmtr_cleanup);
  1776. #endif