ibmtr.c 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965
  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. #include <linux/sched.h>
  109. #ifdef PCMCIA /* required for ibmtr_cs.c to build */
  110. #undef MODULE /* yes, really */
  111. #undef ENABLE_PAGING
  112. #else
  113. #define ENABLE_PAGING 1
  114. #endif
  115. /* changes the output format of driver initialization */
  116. #define TR_VERBOSE 0
  117. /* some 95 OS send many non UI frame; this allow removing the warning */
  118. #define TR_FILTERNONUI 1
  119. #include <linux/ioport.h>
  120. #include <linux/netdevice.h>
  121. #include <linux/ip.h>
  122. #include <linux/trdevice.h>
  123. #include <linux/ibmtr.h>
  124. #include <net/checksum.h>
  125. #include <asm/io.h>
  126. #define DPRINTK(format, args...) printk("%s: " format, dev->name , ## args)
  127. #define DPRINTD(format, args...) DummyCall("%s: " format, dev->name , ## args)
  128. /* version and credits */
  129. #ifndef PCMCIA
  130. static char version[] __devinitdata =
  131. "\nibmtr.c: v1.3.57 8/ 7/94 Peter De Schrijver and Mark Swanson\n"
  132. " v2.1.125 10/20/98 Paul Norton <pnorton@ieee.org>\n"
  133. " v2.2.0 12/30/98 Joel Sloan <jjs@c-me.com>\n"
  134. " v2.2.1 02/08/00 Mike Sullivan <sullivam@us.ibm.com>\n"
  135. " v2.2.2 07/27/00 Burt Silverman <burts@us.ibm.com>\n"
  136. " v2.4.0 03/01/01 Mike Sullivan <sullivan@us.ibm.com>\n";
  137. #endif
  138. /* this allows displaying full adapter information */
  139. static char *channel_def[] __devinitdata = { "ISA", "MCA", "ISA P&P" };
  140. static char pcchannelid[] __devinitdata = {
  141. 0x05, 0x00, 0x04, 0x09,
  142. 0x04, 0x03, 0x04, 0x0f,
  143. 0x03, 0x06, 0x03, 0x01,
  144. 0x03, 0x01, 0x03, 0x00,
  145. 0x03, 0x09, 0x03, 0x09,
  146. 0x03, 0x00, 0x02, 0x00
  147. };
  148. static char mcchannelid[] __devinitdata = {
  149. 0x04, 0x0d, 0x04, 0x01,
  150. 0x05, 0x02, 0x05, 0x03,
  151. 0x03, 0x06, 0x03, 0x03,
  152. 0x05, 0x08, 0x03, 0x04,
  153. 0x03, 0x05, 0x03, 0x01,
  154. 0x03, 0x08, 0x02, 0x00
  155. };
  156. static char __devinit *adapter_def(char type)
  157. {
  158. switch (type) {
  159. case 0xF: return "PC Adapter | PC Adapter II | Adapter/A";
  160. case 0xE: return "16/4 Adapter | 16/4 Adapter/A (long)";
  161. case 0xD: return "16/4 Adapter/A (short) | 16/4 ISA-16 Adapter";
  162. case 0xC: return "Auto 16/4 Adapter";
  163. default: return "adapter (unknown type)";
  164. };
  165. };
  166. #define TRC_INIT 0x01 /* Trace initialization & PROBEs */
  167. #define TRC_INITV 0x02 /* verbose init trace points */
  168. static unsigned char ibmtr_debug_trace = 0;
  169. static int ibmtr_probe1(struct net_device *dev, int ioaddr);
  170. static unsigned char get_sram_size(struct tok_info *adapt_info);
  171. static int trdev_init(struct net_device *dev);
  172. static int tok_open(struct net_device *dev);
  173. static int tok_init_card(struct net_device *dev);
  174. static void tok_open_adapter(unsigned long dev_addr);
  175. static void open_sap(unsigned char type, struct net_device *dev);
  176. static void tok_set_multicast_list(struct net_device *dev);
  177. static netdev_tx_t tok_send_packet(struct sk_buff *skb,
  178. struct net_device *dev);
  179. static int tok_close(struct net_device *dev);
  180. static irqreturn_t tok_interrupt(int irq, void *dev_id);
  181. static void initial_tok_int(struct net_device *dev);
  182. static void tr_tx(struct net_device *dev);
  183. static void tr_rx(struct net_device *dev);
  184. static void ibmtr_reset_timer(struct timer_list*tmr,struct net_device *dev);
  185. static void tok_rerun(unsigned long dev_addr);
  186. static void ibmtr_readlog(struct net_device *dev);
  187. static int ibmtr_change_mtu(struct net_device *dev, int mtu);
  188. static void find_turbo_adapters(int *iolist);
  189. static int ibmtr_portlist[IBMTR_MAX_ADAPTERS+1] __devinitdata = {
  190. 0xa20, 0xa24, 0, 0, 0
  191. };
  192. static int __devinitdata turbo_io[IBMTR_MAX_ADAPTERS] = {0};
  193. static int __devinitdata turbo_irq[IBMTR_MAX_ADAPTERS] = {0};
  194. static int __devinitdata turbo_searched = 0;
  195. #ifndef PCMCIA
  196. static __u32 ibmtr_mem_base __devinitdata = 0xd0000;
  197. #endif
  198. static void __devinit PrtChanID(char *pcid, short stride)
  199. {
  200. short i, j;
  201. for (i = 0, j = 0; i < 24; i++, j += stride)
  202. printk("%1x", ((int) pcid[j]) & 0x0f);
  203. printk("\n");
  204. }
  205. static void __devinit HWPrtChanID(void __iomem *pcid, short stride)
  206. {
  207. short i, j;
  208. for (i = 0, j = 0; i < 24; i++, j += stride)
  209. printk("%1x", ((int) readb(pcid + j)) & 0x0f);
  210. printk("\n");
  211. }
  212. /* We have to ioremap every checked address, because isa_readb is
  213. * going away.
  214. */
  215. static void __devinit find_turbo_adapters(int *iolist)
  216. {
  217. int ram_addr;
  218. int index=0;
  219. void __iomem *chanid;
  220. int found_turbo=0;
  221. unsigned char *tchanid, ctemp;
  222. int i, j;
  223. unsigned long jif;
  224. void __iomem *ram_mapped ;
  225. if (turbo_searched == 1) return;
  226. turbo_searched=1;
  227. for (ram_addr=0xC0000; ram_addr < 0xE0000; ram_addr+=0x2000) {
  228. __u32 intf_tbl=0;
  229. found_turbo=1;
  230. ram_mapped = ioremap((u32)ram_addr,0x1fff) ;
  231. if (ram_mapped==NULL)
  232. continue ;
  233. chanid=(CHANNEL_ID + ram_mapped);
  234. tchanid=pcchannelid;
  235. ctemp=readb(chanid) & 0x0f;
  236. if (ctemp != *tchanid) continue;
  237. for (i=2,j=1; i<=46; i=i+2,j++) {
  238. if ((readb(chanid+i) & 0x0f) != tchanid[j]){
  239. found_turbo=0;
  240. break;
  241. }
  242. }
  243. if (!found_turbo) continue;
  244. writeb(0x90, ram_mapped+0x1E01);
  245. for(i=2; i<0x0f; i++) {
  246. writeb(0x00, ram_mapped+0x1E01+i);
  247. }
  248. writeb(0x00, ram_mapped+0x1E01);
  249. for(jif=jiffies+TR_BUSY_INTERVAL; time_before_eq(jiffies,jif););
  250. intf_tbl=ntohs(readw(ram_mapped+ACA_OFFSET+ACA_RW+WRBR_EVEN));
  251. if (intf_tbl) {
  252. #if IBMTR_DEBUG_MESSAGES
  253. printk("ibmtr::find_turbo_adapters, Turbo found at "
  254. "ram_addr %x\n",ram_addr);
  255. printk("ibmtr::find_turbo_adapters, interface_table ");
  256. for(i=0; i<6; i++) {
  257. printk("%x:",readb(ram_addr+intf_tbl+i));
  258. }
  259. printk("\n");
  260. #endif
  261. turbo_io[index]=ntohs(readw(ram_mapped+intf_tbl+4));
  262. turbo_irq[index]=readb(ram_mapped+intf_tbl+3);
  263. outb(0, turbo_io[index] + ADAPTRESET);
  264. for(jif=jiffies+TR_RST_TIME;time_before_eq(jiffies,jif););
  265. outb(0, turbo_io[index] + ADAPTRESETREL);
  266. index++;
  267. continue;
  268. }
  269. #if IBMTR_DEBUG_MESSAGES
  270. printk("ibmtr::find_turbo_adapters, ibmtr card found at"
  271. " %x but not a Turbo model\n",ram_addr);
  272. #endif
  273. iounmap(ram_mapped) ;
  274. } /* for */
  275. for(i=0; i<IBMTR_MAX_ADAPTERS; i++) {
  276. if(!turbo_io[i]) break;
  277. for (j=0; j<IBMTR_MAX_ADAPTERS; j++) {
  278. if ( iolist[j] && iolist[j] != turbo_io[i]) continue;
  279. iolist[j]=turbo_io[i];
  280. break;
  281. }
  282. }
  283. }
  284. static void ibmtr_cleanup_card(struct net_device *dev)
  285. {
  286. if (dev->base_addr) {
  287. outb(0,dev->base_addr+ADAPTRESET);
  288. schedule_timeout_uninterruptible(TR_RST_TIME); /* wait 50ms */
  289. outb(0,dev->base_addr+ADAPTRESETREL);
  290. }
  291. #ifndef PCMCIA
  292. free_irq(dev->irq, dev);
  293. release_region(dev->base_addr, IBMTR_IO_EXTENT);
  294. {
  295. struct tok_info *ti = netdev_priv(dev);
  296. iounmap(ti->mmio);
  297. iounmap(ti->sram_virt);
  298. }
  299. #endif
  300. }
  301. /****************************************************************************
  302. * ibmtr_probe(): Routine specified in the network device structure
  303. * to probe for an IBM Token Ring Adapter. Routine outline:
  304. * I. Interrogate hardware to determine if an adapter exists
  305. * and what the speeds and feeds are
  306. * II. Setup data structures to control execution based upon
  307. * adapter characteristics.
  308. *
  309. * We expect ibmtr_probe to be called once for each device entry
  310. * which references it.
  311. ****************************************************************************/
  312. static int __devinit ibmtr_probe(struct net_device *dev)
  313. {
  314. int i;
  315. int base_addr = dev->base_addr;
  316. if (base_addr && base_addr <= 0x1ff) /* Don't probe at all. */
  317. return -ENXIO;
  318. if (base_addr > 0x1ff) { /* Check a single specified location. */
  319. if (!ibmtr_probe1(dev, base_addr)) return 0;
  320. return -ENODEV;
  321. }
  322. find_turbo_adapters(ibmtr_portlist);
  323. for (i = 0; ibmtr_portlist[i]; i++) {
  324. int ioaddr = ibmtr_portlist[i];
  325. if (!ibmtr_probe1(dev, ioaddr)) return 0;
  326. }
  327. return -ENODEV;
  328. }
  329. int __devinit ibmtr_probe_card(struct net_device *dev)
  330. {
  331. int err = ibmtr_probe(dev);
  332. if (!err) {
  333. err = register_netdev(dev);
  334. if (err)
  335. ibmtr_cleanup_card(dev);
  336. }
  337. return err;
  338. }
  339. /*****************************************************************************/
  340. static int __devinit ibmtr_probe1(struct net_device *dev, int PIOaddr)
  341. {
  342. unsigned char segment, intr=0, irq=0, i, j, cardpresent=NOTOK, temp=0;
  343. void __iomem * t_mmio = NULL;
  344. struct tok_info *ti = netdev_priv(dev);
  345. void __iomem *cd_chanid;
  346. unsigned char *tchanid, ctemp;
  347. #ifndef PCMCIA
  348. unsigned char t_irq=0;
  349. unsigned long timeout;
  350. static int version_printed;
  351. #endif
  352. /* Query the adapter PIO base port which will return
  353. * indication of where MMIO was placed. We also have a
  354. * coded interrupt number.
  355. */
  356. segment = inb(PIOaddr);
  357. if (segment < 0x40 || segment > 0xe0) {
  358. /* Out of range values so we'll assume non-existent IO device
  359. * but this is not necessarily a problem, esp if a turbo
  360. * adapter is being used. */
  361. #if IBMTR_DEBUG_MESSAGES
  362. DPRINTK("ibmtr_probe1(): unhappy that inb(0x%X) == 0x%X, "
  363. "Hardware Problem?\n",PIOaddr,segment);
  364. #endif
  365. return -ENODEV;
  366. }
  367. /*
  368. * Compute the linear base address of the MMIO area
  369. * as LINUX doesn't care about segments
  370. */
  371. t_mmio = ioremap(((__u32) (segment & 0xfc) << 11) + 0x80000,2048);
  372. if (!t_mmio) {
  373. DPRINTK("Cannot remap mmiobase memory area") ;
  374. return -ENODEV ;
  375. }
  376. intr = segment & 0x03; /* low bits is coded interrupt # */
  377. if (ibmtr_debug_trace & TRC_INIT)
  378. DPRINTK("PIOaddr: %4hx seg/intr: %2x mmio base: %p intr: %d\n"
  379. , PIOaddr, (int) segment, t_mmio, (int) intr);
  380. /*
  381. * Now we will compare expected 'channelid' strings with
  382. * what we is there to learn of ISA/MCA or not TR card
  383. */
  384. #ifdef PCMCIA
  385. iounmap(t_mmio);
  386. t_mmio = ti->mmio; /*BMS to get virtual address */
  387. irq = ti->irq; /*BMS to display the irq! */
  388. #endif
  389. cd_chanid = (CHANNEL_ID + t_mmio); /* for efficiency */
  390. tchanid = pcchannelid;
  391. cardpresent = TR_ISA; /* try ISA */
  392. /* Suboptimize knowing first byte different */
  393. ctemp = readb(cd_chanid) & 0x0f;
  394. if (ctemp != *tchanid) { /* NOT ISA card, try MCA */
  395. tchanid = mcchannelid;
  396. cardpresent = TR_MCA;
  397. if (ctemp != *tchanid) /* Neither ISA nor MCA */
  398. cardpresent = NOTOK;
  399. }
  400. if (cardpresent != NOTOK) {
  401. /* Know presumed type, try rest of ID */
  402. for (i = 2, j = 1; i <= 46; i = i + 2, j++) {
  403. if( (readb(cd_chanid+i)&0x0f) == tchanid[j]) continue;
  404. /* match failed, not TR card */
  405. cardpresent = NOTOK;
  406. break;
  407. }
  408. }
  409. /*
  410. * If we have an ISA board check for the ISA P&P version,
  411. * as it has different IRQ settings
  412. */
  413. if (cardpresent == TR_ISA && (readb(AIPFID + t_mmio) == 0x0e))
  414. cardpresent = TR_ISAPNP;
  415. if (cardpresent == NOTOK) { /* "channel_id" did not match, report */
  416. if (!(ibmtr_debug_trace & TRC_INIT)) {
  417. #ifndef PCMCIA
  418. iounmap(t_mmio);
  419. #endif
  420. return -ENODEV;
  421. }
  422. DPRINTK( "Channel ID string not found for PIOaddr: %4hx\n",
  423. PIOaddr);
  424. DPRINTK("Expected for ISA: ");
  425. PrtChanID(pcchannelid, 1);
  426. DPRINTK(" found: ");
  427. /* BMS Note that this can be misleading, when hardware is flaky, because you
  428. are reading it a second time here. So with my flaky hardware, I'll see my-
  429. self in this block, with the HW ID matching the ISA ID exactly! */
  430. HWPrtChanID(cd_chanid, 2);
  431. DPRINTK("Expected for MCA: ");
  432. PrtChanID(mcchannelid, 1);
  433. }
  434. /* Now, setup some of the pl0 buffers for this driver.. */
  435. /* If called from PCMCIA, it is already set up, so no need to
  436. waste the memory, just use the existing structure */
  437. #ifndef PCMCIA
  438. ti->mmio = t_mmio;
  439. for (i = 0; i < IBMTR_MAX_ADAPTERS; i++) {
  440. if (turbo_io[i] != PIOaddr)
  441. continue;
  442. #if IBMTR_DEBUG_MESSAGES
  443. printk("ibmtr::tr_probe1, setting PIOaddr %x to Turbo\n",
  444. PIOaddr);
  445. #endif
  446. ti->turbo = 1;
  447. t_irq = turbo_irq[i];
  448. }
  449. #endif /* !PCMCIA */
  450. ti->readlog_pending = 0;
  451. init_waitqueue_head(&ti->wait_for_reset);
  452. /* if PCMCIA, the card can be recognized as either TR_ISA or TR_ISAPNP
  453. * depending which card is inserted. */
  454. #ifndef PCMCIA
  455. switch (cardpresent) {
  456. case TR_ISA:
  457. if (intr == 0) irq = 9; /* irq2 really is irq9 */
  458. if (intr == 1) irq = 3;
  459. if (intr == 2) irq = 6;
  460. if (intr == 3) irq = 7;
  461. ti->adapter_int_enable = PIOaddr + ADAPTINTREL;
  462. break;
  463. case TR_MCA:
  464. if (intr == 0) irq = 9;
  465. if (intr == 1) irq = 3;
  466. if (intr == 2) irq = 10;
  467. if (intr == 3) irq = 11;
  468. ti->global_int_enable = 0;
  469. ti->adapter_int_enable = 0;
  470. ti->sram_phys=(__u32)(inb(PIOaddr+ADAPTRESETREL) & 0xfe) << 12;
  471. break;
  472. case TR_ISAPNP:
  473. if (!t_irq) {
  474. if (intr == 0) irq = 9;
  475. if (intr == 1) irq = 3;
  476. if (intr == 2) irq = 10;
  477. if (intr == 3) irq = 11;
  478. } else
  479. irq=t_irq;
  480. timeout = jiffies + TR_SPIN_INTERVAL;
  481. while (!readb(ti->mmio + ACA_OFFSET + ACA_RW + RRR_EVEN)){
  482. if (!time_after(jiffies, timeout)) continue;
  483. DPRINTK( "Hardware timeout during initialization.\n");
  484. iounmap(t_mmio);
  485. return -ENODEV;
  486. }
  487. ti->sram_phys =
  488. ((__u32)readb(ti->mmio+ACA_OFFSET+ACA_RW+RRR_EVEN)<<12);
  489. ti->adapter_int_enable = PIOaddr + ADAPTINTREL;
  490. break;
  491. } /*end switch (cardpresent) */
  492. #endif /*not PCMCIA */
  493. if (ibmtr_debug_trace & TRC_INIT) { /* just report int */
  494. DPRINTK("irq=%d", irq);
  495. printk(", sram_phys=0x%x", ti->sram_phys);
  496. if(ibmtr_debug_trace&TRC_INITV){ /* full chat in verbose only */
  497. DPRINTK(", ti->mmio=%p", ti->mmio);
  498. printk(", segment=%02X", segment);
  499. }
  500. printk(".\n");
  501. }
  502. /* Get hw address of token ring card */
  503. j = 0;
  504. for (i = 0; i < 0x18; i = i + 2) {
  505. /* technical reference states to do this */
  506. temp = readb(ti->mmio + AIP + i) & 0x0f;
  507. ti->hw_address[j] = temp;
  508. if (j & 1)
  509. dev->dev_addr[(j / 2)] =
  510. ti->hw_address[j]+ (ti->hw_address[j - 1] << 4);
  511. ++j;
  512. }
  513. /* get Adapter type: 'F' = Adapter/A, 'E' = 16/4 Adapter II,... */
  514. ti->adapter_type = readb(ti->mmio + AIPADAPTYPE);
  515. /* get Data Rate: F=4Mb, E=16Mb, D=4Mb & 16Mb ?? */
  516. ti->data_rate = readb(ti->mmio + AIPDATARATE);
  517. /* Get Early Token Release support?: F=no, E=4Mb, D=16Mb, C=4&16Mb */
  518. ti->token_release = readb(ti->mmio + AIPEARLYTOKEN);
  519. /* How much shared RAM is on adapter ? */
  520. if (ti->turbo) {
  521. ti->avail_shared_ram=127;
  522. } else {
  523. ti->avail_shared_ram = get_sram_size(ti);/*in 512 byte units */
  524. }
  525. /* We need to set or do a bunch of work here based on previous results*/
  526. /* Support paging? What sizes?: F=no, E=16k, D=32k, C=16 & 32k */
  527. ti->shared_ram_paging = readb(ti->mmio + AIPSHRAMPAGE);
  528. /* Available DHB 4Mb size: F=2048, E=4096, D=4464 */
  529. switch (readb(ti->mmio + AIP4MBDHB)) {
  530. case 0xe: ti->dhb_size4mb = 4096; break;
  531. case 0xd: ti->dhb_size4mb = 4464; break;
  532. default: ti->dhb_size4mb = 2048; break;
  533. }
  534. /* Available DHB 16Mb size: F=2048, E=4096, D=8192, C=16384, B=17960 */
  535. switch (readb(ti->mmio + AIP16MBDHB)) {
  536. case 0xe: ti->dhb_size16mb = 4096; break;
  537. case 0xd: ti->dhb_size16mb = 8192; break;
  538. case 0xc: ti->dhb_size16mb = 16384; break;
  539. case 0xb: ti->dhb_size16mb = 17960; break;
  540. default: ti->dhb_size16mb = 2048; break;
  541. }
  542. /* We must figure out how much shared memory space this adapter
  543. * will occupy so that if there are two adapters we can fit both
  544. * in. Given a choice, we will limit this adapter to 32K. The
  545. * maximum space will will use for two adapters is 64K so if the
  546. * adapter we are working on demands 64K (it also doesn't support
  547. * paging), then only one adapter can be supported.
  548. */
  549. /*
  550. * determine how much of total RAM is mapped into PC space
  551. */
  552. ti->mapped_ram_size= /*sixteen to onehundredtwentyeight 512byte blocks*/
  553. 1<< ((readb(ti->mmio+ACA_OFFSET+ACA_RW+RRR_ODD) >> 2 & 0x03) + 4);
  554. ti->page_mask = 0;
  555. if (ti->turbo) ti->page_mask=0xf0;
  556. else if (ti->shared_ram_paging == 0xf); /* No paging in adapter */
  557. else {
  558. #ifdef ENABLE_PAGING
  559. unsigned char pg_size = 0;
  560. /* BMS: page size: PCMCIA, use configuration register;
  561. ISAPNP, use LANAIDC config tool from www.ibm.com */
  562. switch (ti->shared_ram_paging) {
  563. case 0xf:
  564. break;
  565. case 0xe:
  566. ti->page_mask = (ti->mapped_ram_size == 32) ? 0xc0 : 0;
  567. pg_size = 32; /* 16KB page size */
  568. break;
  569. case 0xd:
  570. ti->page_mask = (ti->mapped_ram_size == 64) ? 0x80 : 0;
  571. pg_size = 64; /* 32KB page size */
  572. break;
  573. case 0xc:
  574. switch (ti->mapped_ram_size) {
  575. case 32:
  576. ti->page_mask = 0xc0;
  577. pg_size = 32;
  578. break;
  579. case 64:
  580. ti->page_mask = 0x80;
  581. pg_size = 64;
  582. break;
  583. }
  584. break;
  585. default:
  586. DPRINTK("Unknown shared ram paging info %01X\n",
  587. ti->shared_ram_paging);
  588. iounmap(t_mmio);
  589. return -ENODEV;
  590. break;
  591. } /*end switch shared_ram_paging */
  592. if (ibmtr_debug_trace & TRC_INIT)
  593. DPRINTK("Shared RAM paging code: %02X, "
  594. "mapped RAM size: %dK, shared RAM size: %dK, "
  595. "page mask: %02X\n:",
  596. ti->shared_ram_paging, ti->mapped_ram_size / 2,
  597. ti->avail_shared_ram / 2, ti->page_mask);
  598. #endif /*ENABLE_PAGING */
  599. }
  600. #ifndef PCMCIA
  601. /* finish figuring the shared RAM address */
  602. if (cardpresent == TR_ISA) {
  603. static __u32 ram_bndry_mask[] =
  604. { 0xffffe000, 0xffffc000, 0xffff8000, 0xffff0000 };
  605. __u32 new_base, rrr_32, chk_base, rbm;
  606. rrr_32=readb(ti->mmio+ACA_OFFSET+ACA_RW+RRR_ODD) >> 2 & 0x03;
  607. rbm = ram_bndry_mask[rrr_32];
  608. new_base = (ibmtr_mem_base + (~rbm)) & rbm;/* up to boundary */
  609. chk_base = new_base + (ti->mapped_ram_size << 9);
  610. if (chk_base > (ibmtr_mem_base + IBMTR_SHARED_RAM_SIZE)) {
  611. DPRINTK("Shared RAM for this adapter (%05x) exceeds "
  612. "driver limit (%05x), adapter not started.\n",
  613. chk_base, ibmtr_mem_base + IBMTR_SHARED_RAM_SIZE);
  614. iounmap(t_mmio);
  615. return -ENODEV;
  616. } else { /* seems cool, record what we have figured out */
  617. ti->sram_base = new_base >> 12;
  618. ibmtr_mem_base = chk_base;
  619. }
  620. }
  621. else ti->sram_base = ti->sram_phys >> 12;
  622. /* The PCMCIA has already got the interrupt line and the io port,
  623. so no chance of anybody else getting it - MLP */
  624. if (request_irq(dev->irq = irq, &tok_interrupt, 0, "ibmtr", dev) != 0) {
  625. DPRINTK("Could not grab irq %d. Halting Token Ring driver.\n",
  626. irq);
  627. iounmap(t_mmio);
  628. return -ENODEV;
  629. }
  630. /*?? Now, allocate some of the PIO PORTs for this driver.. */
  631. /* record PIOaddr range as busy */
  632. if (!request_region(PIOaddr, IBMTR_IO_EXTENT, "ibmtr")) {
  633. DPRINTK("Could not grab PIO range. Halting driver.\n");
  634. free_irq(dev->irq, dev);
  635. iounmap(t_mmio);
  636. return -EBUSY;
  637. }
  638. if (!version_printed++) {
  639. printk(version);
  640. }
  641. #endif /* !PCMCIA */
  642. DPRINTK("%s %s found\n",
  643. channel_def[cardpresent - 1], adapter_def(ti->adapter_type));
  644. DPRINTK("using irq %d, PIOaddr %hx, %dK shared RAM.\n",
  645. irq, PIOaddr, ti->mapped_ram_size / 2);
  646. DPRINTK("Hardware address : %pM\n", dev->dev_addr);
  647. if (ti->page_mask)
  648. DPRINTK("Shared RAM paging enabled. "
  649. "Page size: %uK Shared Ram size %dK\n",
  650. ((ti->page_mask^0xff)+1) >>2, ti->avail_shared_ram / 2);
  651. else
  652. DPRINTK("Shared RAM paging disabled. ti->page_mask %x\n",
  653. ti->page_mask);
  654. /* Calculate the maximum DHB we can use */
  655. /* two cases where avail_shared_ram doesn't equal mapped_ram_size:
  656. 1. avail_shared_ram is 127 but mapped_ram_size is 128 (typical)
  657. 2. user has configured adapter for less than avail_shared_ram
  658. but is not using paging (she should use paging, I believe)
  659. */
  660. if (!ti->page_mask) {
  661. ti->avail_shared_ram=
  662. min(ti->mapped_ram_size,ti->avail_shared_ram);
  663. }
  664. switch (ti->avail_shared_ram) {
  665. case 16: /* 8KB shared RAM */
  666. ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)2048);
  667. ti->rbuf_len4 = 1032;
  668. ti->rbuf_cnt4=2;
  669. ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)2048);
  670. ti->rbuf_len16 = 1032;
  671. ti->rbuf_cnt16=2;
  672. break;
  673. case 32: /* 16KB shared RAM */
  674. ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)4464);
  675. ti->rbuf_len4 = 1032;
  676. ti->rbuf_cnt4=4;
  677. ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)4096);
  678. ti->rbuf_len16 = 1032; /*1024 usable */
  679. ti->rbuf_cnt16=4;
  680. break;
  681. case 64: /* 32KB shared RAM */
  682. ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)4464);
  683. ti->rbuf_len4 = 1032;
  684. ti->rbuf_cnt4=6;
  685. ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)10240);
  686. ti->rbuf_len16 = 1032;
  687. ti->rbuf_cnt16=6;
  688. break;
  689. case 127: /* 63.5KB shared RAM */
  690. ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)4464);
  691. ti->rbuf_len4 = 1032;
  692. ti->rbuf_cnt4=6;
  693. ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)16384);
  694. ti->rbuf_len16 = 1032;
  695. ti->rbuf_cnt16=16;
  696. break;
  697. case 128: /* 64KB shared RAM */
  698. ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)4464);
  699. ti->rbuf_len4 = 1032;
  700. ti->rbuf_cnt4=6;
  701. ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)17960);
  702. ti->rbuf_len16 = 1032;
  703. ti->rbuf_cnt16=16;
  704. break;
  705. default:
  706. ti->dhb_size4mb = 2048;
  707. ti->rbuf_len4 = 1032;
  708. ti->rbuf_cnt4=2;
  709. ti->dhb_size16mb = 2048;
  710. ti->rbuf_len16 = 1032;
  711. ti->rbuf_cnt16=2;
  712. break;
  713. }
  714. /* this formula is not smart enough for the paging case
  715. ti->rbuf_cnt<x> = (ti->avail_shared_ram * BLOCKSZ - ADAPT_PRIVATE -
  716. ARBLENGTH - SSBLENGTH - DLC_MAX_SAP * SAPLENGTH -
  717. DLC_MAX_STA * STALENGTH - ti->dhb_size<x>mb * NUM_DHB -
  718. SRBLENGTH - ASBLENGTH) / ti->rbuf_len<x>;
  719. */
  720. ti->maxmtu16 = (ti->rbuf_len16 - 8) * ti->rbuf_cnt16 - TR_HLEN;
  721. ti->maxmtu4 = (ti->rbuf_len4 - 8) * ti->rbuf_cnt4 - TR_HLEN;
  722. /*BMS assuming 18 bytes of Routing Information (usually works) */
  723. DPRINTK("Maximum Receive Internet Protocol MTU 16Mbps: %d, 4Mbps: %d\n",
  724. ti->maxmtu16, ti->maxmtu4);
  725. dev->base_addr = PIOaddr; /* set the value for device */
  726. dev->mem_start = ti->sram_base << 12;
  727. dev->mem_end = dev->mem_start + (ti->mapped_ram_size << 9) - 1;
  728. trdev_init(dev);
  729. return 0; /* Return 0 to indicate we have found a Token Ring card. */
  730. } /*ibmtr_probe1() */
  731. /*****************************************************************************/
  732. /* query the adapter for the size of shared RAM */
  733. /* the function returns the RAM size in units of 512 bytes */
  734. static unsigned char __devinit get_sram_size(struct tok_info *adapt_info)
  735. {
  736. unsigned char avail_sram_code;
  737. static unsigned char size_code[] = { 0, 16, 32, 64, 127, 128 };
  738. /* Adapter gives
  739. 'F' -- use RRR bits 3,2
  740. 'E' -- 8kb 'D' -- 16kb
  741. 'C' -- 32kb 'A' -- 64KB
  742. 'B' - 64KB less 512 bytes at top
  743. (WARNING ... must zero top bytes in INIT */
  744. avail_sram_code = 0xf - readb(adapt_info->mmio + AIPAVAILSHRAM);
  745. if (avail_sram_code) return size_code[avail_sram_code];
  746. else /* for code 'F', must compute size from RRR(3,2) bits */
  747. return 1 <<
  748. ((readb(adapt_info->mmio+ACA_OFFSET+ACA_RW+RRR_ODD)>>2&3)+4);
  749. }
  750. /*****************************************************************************/
  751. static const struct net_device_ops trdev_netdev_ops = {
  752. .ndo_open = tok_open,
  753. .ndo_stop = tok_close,
  754. .ndo_start_xmit = tok_send_packet,
  755. .ndo_set_multicast_list = tok_set_multicast_list,
  756. .ndo_change_mtu = ibmtr_change_mtu,
  757. };
  758. static int __devinit trdev_init(struct net_device *dev)
  759. {
  760. struct tok_info *ti = netdev_priv(dev);
  761. SET_PAGE(ti->srb_page);
  762. ti->open_failure = NO ;
  763. dev->netdev_ops = &trdev_netdev_ops;
  764. return 0;
  765. }
  766. /*****************************************************************************/
  767. static int tok_init_card(struct net_device *dev)
  768. {
  769. struct tok_info *ti;
  770. short PIOaddr;
  771. unsigned long i;
  772. PIOaddr = dev->base_addr;
  773. ti = netdev_priv(dev);
  774. /* Special processing for first interrupt after reset */
  775. ti->do_tok_int = FIRST_INT;
  776. /* Reset adapter */
  777. writeb(~INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_EVEN);
  778. outb(0, PIOaddr + ADAPTRESET);
  779. schedule_timeout_uninterruptible(TR_RST_TIME); /* wait 50ms */
  780. outb(0, PIOaddr + ADAPTRESETREL);
  781. #ifdef ENABLE_PAGING
  782. if (ti->page_mask)
  783. writeb(SRPR_ENABLE_PAGING,ti->mmio+ACA_OFFSET+ACA_RW+SRPR_EVEN);
  784. #endif
  785. writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
  786. i = sleep_on_timeout(&ti->wait_for_reset, 4 * HZ);
  787. return i? 0 : -EAGAIN;
  788. }
  789. /*****************************************************************************/
  790. static int tok_open(struct net_device *dev)
  791. {
  792. struct tok_info *ti = netdev_priv(dev);
  793. int i;
  794. /*the case we were left in a failure state during a previous open */
  795. if (ti->open_failure == YES) {
  796. DPRINTK("Last time you were disconnected, how about now?\n");
  797. printk("You can't insert with an ICS connector half-cocked.\n");
  798. }
  799. ti->open_status = CLOSED; /* CLOSED or OPEN */
  800. ti->sap_status = CLOSED; /* CLOSED or OPEN */
  801. ti->open_failure = NO; /* NO or YES */
  802. ti->open_mode = MANUAL; /* MANUAL or AUTOMATIC */
  803. ti->sram_phys &= ~1; /* to reverse what we do in tok_close */
  804. /* init the spinlock */
  805. spin_lock_init(&ti->lock);
  806. init_timer(&ti->tr_timer);
  807. i = tok_init_card(dev);
  808. if (i) return i;
  809. while (1){
  810. tok_open_adapter((unsigned long) dev);
  811. i= interruptible_sleep_on_timeout(&ti->wait_for_reset, 25 * HZ);
  812. /* sig catch: estimate opening adapter takes more than .5 sec*/
  813. if (i>(245*HZ)/10) break; /* fancier than if (i==25*HZ) */
  814. if (i==0) break;
  815. if (ti->open_status == OPEN && ti->sap_status==OPEN) {
  816. netif_start_queue(dev);
  817. DPRINTK("Adapter is up and running\n");
  818. return 0;
  819. }
  820. i=schedule_timeout_interruptible(TR_RETRY_INTERVAL);
  821. /* wait 30 seconds */
  822. if(i!=0) break; /*prob. a signal, like the i>24*HZ case above */
  823. }
  824. outb(0, dev->base_addr + ADAPTRESET);/* kill pending interrupts*/
  825. DPRINTK("TERMINATED via signal\n"); /*BMS useful */
  826. return -EAGAIN;
  827. }
  828. /*****************************************************************************/
  829. #define COMMAND_OFST 0
  830. #define OPEN_OPTIONS_OFST 8
  831. #define NUM_RCV_BUF_OFST 24
  832. #define RCV_BUF_LEN_OFST 26
  833. #define DHB_LENGTH_OFST 28
  834. #define NUM_DHB_OFST 30
  835. #define DLC_MAX_SAP_OFST 32
  836. #define DLC_MAX_STA_OFST 33
  837. static void tok_open_adapter(unsigned long dev_addr)
  838. {
  839. struct net_device *dev = (struct net_device *) dev_addr;
  840. struct tok_info *ti;
  841. int i;
  842. ti = netdev_priv(dev);
  843. SET_PAGE(ti->init_srb_page);
  844. writeb(~SRB_RESP_INT, ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_ODD);
  845. for (i = 0; i < sizeof(struct dir_open_adapter); i++)
  846. writeb(0, ti->init_srb + i);
  847. writeb(DIR_OPEN_ADAPTER, ti->init_srb + COMMAND_OFST);
  848. writew(htons(OPEN_PASS_BCON_MAC), ti->init_srb + OPEN_OPTIONS_OFST);
  849. if (ti->ring_speed == 16) {
  850. writew(htons(ti->dhb_size16mb), ti->init_srb + DHB_LENGTH_OFST);
  851. writew(htons(ti->rbuf_cnt16), ti->init_srb + NUM_RCV_BUF_OFST);
  852. writew(htons(ti->rbuf_len16), ti->init_srb + RCV_BUF_LEN_OFST);
  853. } else {
  854. writew(htons(ti->dhb_size4mb), ti->init_srb + DHB_LENGTH_OFST);
  855. writew(htons(ti->rbuf_cnt4), ti->init_srb + NUM_RCV_BUF_OFST);
  856. writew(htons(ti->rbuf_len4), ti->init_srb + RCV_BUF_LEN_OFST);
  857. }
  858. writeb(NUM_DHB, /* always 2 */ ti->init_srb + NUM_DHB_OFST);
  859. writeb(DLC_MAX_SAP, ti->init_srb + DLC_MAX_SAP_OFST);
  860. writeb(DLC_MAX_STA, ti->init_srb + DLC_MAX_STA_OFST);
  861. ti->srb = ti->init_srb; /* We use this one in the interrupt handler */
  862. ti->srb_page = ti->init_srb_page;
  863. DPRINTK("Opening adapter: Xmit bfrs: %d X %d, Rcv bfrs: %d X %d\n",
  864. readb(ti->init_srb + NUM_DHB_OFST),
  865. ntohs(readw(ti->init_srb + DHB_LENGTH_OFST)),
  866. ntohs(readw(ti->init_srb + NUM_RCV_BUF_OFST)),
  867. ntohs(readw(ti->init_srb + RCV_BUF_LEN_OFST)));
  868. writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
  869. writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  870. }
  871. /*****************************************************************************/
  872. static void open_sap(unsigned char type, struct net_device *dev)
  873. {
  874. int i;
  875. struct tok_info *ti = netdev_priv(dev);
  876. SET_PAGE(ti->srb_page);
  877. for (i = 0; i < sizeof(struct dlc_open_sap); i++)
  878. writeb(0, ti->srb + i);
  879. #define MAX_I_FIELD_OFST 14
  880. #define SAP_VALUE_OFST 16
  881. #define SAP_OPTIONS_OFST 17
  882. #define STATION_COUNT_OFST 18
  883. writeb(DLC_OPEN_SAP, ti->srb + COMMAND_OFST);
  884. writew(htons(MAX_I_FIELD), ti->srb + MAX_I_FIELD_OFST);
  885. writeb(SAP_OPEN_IND_SAP | SAP_OPEN_PRIORITY, ti->srb+ SAP_OPTIONS_OFST);
  886. writeb(SAP_OPEN_STATION_CNT, ti->srb + STATION_COUNT_OFST);
  887. writeb(type, ti->srb + SAP_VALUE_OFST);
  888. writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  889. }
  890. /*****************************************************************************/
  891. static void tok_set_multicast_list(struct net_device *dev)
  892. {
  893. struct tok_info *ti = netdev_priv(dev);
  894. struct dev_mc_list *mclist;
  895. unsigned char address[4];
  896. int i;
  897. /*BMS the next line is CRUCIAL or you may be sad when you */
  898. /*BMS ifconfig tr down or hot unplug a PCMCIA card ??hownowbrowncow*/
  899. if (/*BMSHELPdev->start == 0 ||*/ ti->open_status != OPEN) return;
  900. address[0] = address[1] = address[2] = address[3] = 0;
  901. mclist = dev->mc_list;
  902. for (i = 0; i < dev->mc_count; i++) {
  903. address[0] |= mclist->dmi_addr[2];
  904. address[1] |= mclist->dmi_addr[3];
  905. address[2] |= mclist->dmi_addr[4];
  906. address[3] |= mclist->dmi_addr[5];
  907. mclist = mclist->next;
  908. }
  909. SET_PAGE(ti->srb_page);
  910. for (i = 0; i < sizeof(struct srb_set_funct_addr); i++)
  911. writeb(0, ti->srb + i);
  912. #define FUNCT_ADDRESS_OFST 6
  913. writeb(DIR_SET_FUNC_ADDR, ti->srb + COMMAND_OFST);
  914. for (i = 0; i < 4; i++)
  915. writeb(address[i], ti->srb + FUNCT_ADDRESS_OFST + i);
  916. writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  917. #if TR_VERBOSE
  918. DPRINTK("Setting functional address: ");
  919. for (i=0;i<4;i++) printk("%02X ", address[i]);
  920. printk("\n");
  921. #endif
  922. }
  923. /*****************************************************************************/
  924. #define STATION_ID_OFST 4
  925. static netdev_tx_t tok_send_packet(struct sk_buff *skb,
  926. struct net_device *dev)
  927. {
  928. struct tok_info *ti;
  929. unsigned long flags;
  930. ti = netdev_priv(dev);
  931. netif_stop_queue(dev);
  932. /* lock against other CPUs */
  933. spin_lock_irqsave(&(ti->lock), flags);
  934. /* Save skb; we'll need it when the adapter asks for the data */
  935. ti->current_skb = skb;
  936. SET_PAGE(ti->srb_page);
  937. writeb(XMIT_UI_FRAME, ti->srb + COMMAND_OFST);
  938. writew(ti->exsap_station_id, ti->srb + STATION_ID_OFST);
  939. writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  940. spin_unlock_irqrestore(&(ti->lock), flags);
  941. dev->trans_start = jiffies;
  942. return NETDEV_TX_OK;
  943. }
  944. /*****************************************************************************/
  945. static int tok_close(struct net_device *dev)
  946. {
  947. struct tok_info *ti = netdev_priv(dev);
  948. /* Important for PCMCIA hot unplug, otherwise, we'll pull the card, */
  949. /* unloading the module from memory, and then if a timer pops, ouch */
  950. del_timer_sync(&ti->tr_timer);
  951. outb(0, dev->base_addr + ADAPTRESET);
  952. ti->sram_phys |= 1;
  953. ti->open_status = CLOSED;
  954. netif_stop_queue(dev);
  955. DPRINTK("Adapter is closed.\n");
  956. return 0;
  957. }
  958. /*****************************************************************************/
  959. #define RETCODE_OFST 2
  960. #define OPEN_ERROR_CODE_OFST 6
  961. #define ASB_ADDRESS_OFST 8
  962. #define SRB_ADDRESS_OFST 10
  963. #define ARB_ADDRESS_OFST 12
  964. #define SSB_ADDRESS_OFST 14
  965. static char *printphase[]= {"Lobe media test","Physical insertion",
  966. "Address verification","Roll call poll","Request Parameters"};
  967. static char *printerror[]={"Function failure","Signal loss","Reserved",
  968. "Frequency error","Timeout","Ring failure","Ring beaconing",
  969. "Duplicate node address",
  970. "Parameter request-retry count exceeded","Remove received",
  971. "IMPL force received","Duplicate modifier",
  972. "No monitor detected","Monitor contention failed for RPL"};
  973. static void __iomem *map_address(struct tok_info *ti, unsigned index, __u8 *page)
  974. {
  975. if (ti->page_mask) {
  976. *page = (index >> 8) & ti->page_mask;
  977. index &= ~(ti->page_mask << 8);
  978. }
  979. return ti->sram_virt + index;
  980. }
  981. static void dir_open_adapter (struct net_device *dev)
  982. {
  983. struct tok_info *ti = netdev_priv(dev);
  984. unsigned char ret_code;
  985. __u16 err;
  986. ti->srb = map_address(ti,
  987. ntohs(readw(ti->init_srb + SRB_ADDRESS_OFST)),
  988. &ti->srb_page);
  989. ti->ssb = map_address(ti,
  990. ntohs(readw(ti->init_srb + SSB_ADDRESS_OFST)),
  991. &ti->ssb_page);
  992. ti->arb = map_address(ti,
  993. ntohs(readw(ti->init_srb + ARB_ADDRESS_OFST)),
  994. &ti->arb_page);
  995. ti->asb = map_address(ti,
  996. ntohs(readw(ti->init_srb + ASB_ADDRESS_OFST)),
  997. &ti->asb_page);
  998. ti->current_skb = NULL;
  999. ret_code = readb(ti->init_srb + RETCODE_OFST);
  1000. err = ntohs(readw(ti->init_srb + OPEN_ERROR_CODE_OFST));
  1001. if (!ret_code) {
  1002. ti->open_status = OPEN; /* TR adapter is now available */
  1003. if (ti->open_mode == AUTOMATIC) {
  1004. DPRINTK("Adapter reopened.\n");
  1005. }
  1006. writeb(~SRB_RESP_INT, ti->mmio+ACA_OFFSET+ACA_RESET+ISRP_ODD);
  1007. open_sap(EXTENDED_SAP, dev);
  1008. return;
  1009. }
  1010. ti->open_failure = YES;
  1011. if (ret_code == 7){
  1012. if (err == 0x24) {
  1013. if (!ti->auto_speedsave) {
  1014. DPRINTK("Open failed: Adapter speed must match "
  1015. "ring speed if Automatic Ring Speed Save is "
  1016. "disabled.\n");
  1017. ti->open_action = FAIL;
  1018. }else
  1019. DPRINTK("Retrying open to adjust to "
  1020. "ring speed, ");
  1021. } else if (err == 0x2d) {
  1022. DPRINTK("Physical Insertion: No Monitor Detected, ");
  1023. printk("retrying after %ds delay...\n",
  1024. TR_RETRY_INTERVAL/HZ);
  1025. } else if (err == 0x11) {
  1026. DPRINTK("Lobe Media Function Failure (0x11), ");
  1027. printk(" retrying after %ds delay...\n",
  1028. TR_RETRY_INTERVAL/HZ);
  1029. } else {
  1030. char **prphase = printphase;
  1031. char **prerror = printerror;
  1032. int pnr = err / 16 - 1;
  1033. int enr = err % 16 - 1;
  1034. DPRINTK("TR Adapter misc open failure, error code = ");
  1035. if (pnr < 0 || pnr >= ARRAY_SIZE(printphase) ||
  1036. enr < 0 ||
  1037. enr >= ARRAY_SIZE(printerror))
  1038. printk("0x%x, invalid Phase/Error.", err);
  1039. else
  1040. printk("0x%x, Phase: %s, Error: %s\n", err,
  1041. prphase[pnr], prerror[enr]);
  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)
  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\n", dev,irq);
  1070. #endif
  1071. ti = netdev_priv(dev);
  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. dev->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 = netdev_priv(dev);
  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) != 0;
  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 = netdev_priv(dev);
  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. dev->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 = netdev_priv(dev);
  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. dev->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. u8 saddr[6];
  1586. u8 daddr[6];
  1587. int i;
  1588. for (i = 0 ; i < 6 ; i++)
  1589. saddr[i] = readb(trhhdr + SADDR_OFST + i);
  1590. for (i = 0 ; i < 6 ; i++)
  1591. daddr[i] = readb(trhhdr + DADDR_OFST + i);
  1592. DPRINTK("Probably non-IP frame received.\n");
  1593. DPRINTK("ssap: %02X dsap: %02X "
  1594. "saddr: %pM daddr: %pM\n",
  1595. readb(llc + SSAP_OFST), readb(llc + DSAP_OFST),
  1596. saddr, daddr);
  1597. }
  1598. #endif
  1599. /*BMS handle the case she comes in with few hops but leaves with many */
  1600. skb_size=length-lan_hdr_len+sizeof(struct trh_hdr)+sizeof(struct trllc);
  1601. if (!(skb = dev_alloc_skb(skb_size))) {
  1602. DPRINTK("out of memory. frame dropped.\n");
  1603. dev->stats.rx_dropped++;
  1604. SET_PAGE(ti->asb_page);
  1605. writeb(DATA_LOST, ti->asb + offsetof(struct asb_rec, ret_code));
  1606. writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  1607. return;
  1608. }
  1609. /*BMS again, if she comes in with few but leaves with many */
  1610. skb_reserve(skb, sizeof(struct trh_hdr) - lan_hdr_len);
  1611. skb_put(skb, length);
  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. dev->stats.rx_bytes += skb->len;
  1655. dev->stats.rx_packets++;
  1656. skb->protocol = tr_type_trans(skb, dev);
  1657. if (IPv4_p) {
  1658. skb->csum = chksum;
  1659. skb->ip_summed = CHECKSUM_COMPLETE;
  1660. }
  1661. netif_rx(skb);
  1662. } /*tr_rx */
  1663. /*****************************************************************************/
  1664. static void ibmtr_reset_timer(struct timer_list *tmr, struct net_device *dev)
  1665. {
  1666. tmr->expires = jiffies + TR_RETRY_INTERVAL;
  1667. tmr->data = (unsigned long) dev;
  1668. tmr->function = tok_rerun;
  1669. init_timer(tmr);
  1670. add_timer(tmr);
  1671. }
  1672. /*****************************************************************************/
  1673. static void tok_rerun(unsigned long dev_addr)
  1674. {
  1675. struct net_device *dev = (struct net_device *)dev_addr;
  1676. struct tok_info *ti = netdev_priv(dev);
  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 = netdev_priv(dev);
  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. static int ibmtr_change_mtu(struct net_device *dev, int mtu)
  1703. {
  1704. struct tok_info *ti = netdev_priv(dev);
  1705. if (ti->ring_speed == 16 && mtu > ti->maxmtu16)
  1706. return -EINVAL;
  1707. if (ti->ring_speed == 4 && mtu > ti->maxmtu4)
  1708. return -EINVAL;
  1709. dev->mtu = mtu;
  1710. return 0;
  1711. }
  1712. /*****************************************************************************/
  1713. #ifdef MODULE
  1714. /* 3COM 3C619C supports 8 interrupts, 32 I/O ports */
  1715. static struct net_device *dev_ibmtr[IBMTR_MAX_ADAPTERS];
  1716. static int io[IBMTR_MAX_ADAPTERS] = { 0xa20, 0xa24 };
  1717. static int irq[IBMTR_MAX_ADAPTERS];
  1718. static int mem[IBMTR_MAX_ADAPTERS];
  1719. MODULE_LICENSE("GPL");
  1720. module_param_array(io, int, NULL, 0);
  1721. module_param_array(irq, int, NULL, 0);
  1722. module_param_array(mem, int, NULL, 0);
  1723. static int __init ibmtr_init(void)
  1724. {
  1725. int i;
  1726. int count=0;
  1727. find_turbo_adapters(io);
  1728. for (i = 0; i < IBMTR_MAX_ADAPTERS && io[i]; i++) {
  1729. struct net_device *dev;
  1730. irq[i] = 0;
  1731. mem[i] = 0;
  1732. dev = alloc_trdev(sizeof(struct tok_info));
  1733. if (dev == NULL) {
  1734. if (i == 0)
  1735. return -ENOMEM;
  1736. break;
  1737. }
  1738. dev->base_addr = io[i];
  1739. dev->irq = irq[i];
  1740. dev->mem_start = mem[i];
  1741. if (ibmtr_probe_card(dev)) {
  1742. free_netdev(dev);
  1743. continue;
  1744. }
  1745. dev_ibmtr[i] = dev;
  1746. count++;
  1747. }
  1748. if (count) return 0;
  1749. printk("ibmtr: register_netdev() returned non-zero.\n");
  1750. return -EIO;
  1751. }
  1752. module_init(ibmtr_init);
  1753. static void __exit ibmtr_cleanup(void)
  1754. {
  1755. int i;
  1756. for (i = 0; i < IBMTR_MAX_ADAPTERS; i++){
  1757. if (!dev_ibmtr[i])
  1758. continue;
  1759. unregister_netdev(dev_ibmtr[i]);
  1760. ibmtr_cleanup_card(dev_ibmtr[i]);
  1761. free_netdev(dev_ibmtr[i]);
  1762. }
  1763. }
  1764. module_exit(ibmtr_cleanup);
  1765. #endif