ibmtr.c 61 KB

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