ibmtr.c 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963
  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 compatibility 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 const __u32 ram_bndry_mask[] = {
  604. 0xffffe000, 0xffffc000, 0xffff8000, 0xffff0000
  605. };
  606. __u32 new_base, rrr_32, chk_base, rbm;
  607. rrr_32=readb(ti->mmio+ACA_OFFSET+ACA_RW+RRR_ODD) >> 2 & 0x03;
  608. rbm = ram_bndry_mask[rrr_32];
  609. new_base = (ibmtr_mem_base + (~rbm)) & rbm;/* up to boundary */
  610. chk_base = new_base + (ti->mapped_ram_size << 9);
  611. if (chk_base > (ibmtr_mem_base + IBMTR_SHARED_RAM_SIZE)) {
  612. DPRINTK("Shared RAM for this adapter (%05x) exceeds "
  613. "driver limit (%05x), adapter not started.\n",
  614. chk_base, ibmtr_mem_base + IBMTR_SHARED_RAM_SIZE);
  615. iounmap(t_mmio);
  616. return -ENODEV;
  617. } else { /* seems cool, record what we have figured out */
  618. ti->sram_base = new_base >> 12;
  619. ibmtr_mem_base = chk_base;
  620. }
  621. }
  622. else ti->sram_base = ti->sram_phys >> 12;
  623. /* The PCMCIA has already got the interrupt line and the io port,
  624. so no chance of anybody else getting it - MLP */
  625. if (request_irq(dev->irq = irq, tok_interrupt, 0, "ibmtr", dev) != 0) {
  626. DPRINTK("Could not grab irq %d. Halting Token Ring driver.\n",
  627. irq);
  628. iounmap(t_mmio);
  629. return -ENODEV;
  630. }
  631. /*?? Now, allocate some of the PIO PORTs for this driver.. */
  632. /* record PIOaddr range as busy */
  633. if (!request_region(PIOaddr, IBMTR_IO_EXTENT, "ibmtr")) {
  634. DPRINTK("Could not grab PIO range. Halting driver.\n");
  635. free_irq(dev->irq, dev);
  636. iounmap(t_mmio);
  637. return -EBUSY;
  638. }
  639. if (!version_printed++) {
  640. printk(version);
  641. }
  642. #endif /* !PCMCIA */
  643. DPRINTK("%s %s found\n",
  644. channel_def[cardpresent - 1], adapter_def(ti->adapter_type));
  645. DPRINTK("using irq %d, PIOaddr %hx, %dK shared RAM.\n",
  646. irq, PIOaddr, ti->mapped_ram_size / 2);
  647. DPRINTK("Hardware address : %pM\n", dev->dev_addr);
  648. if (ti->page_mask)
  649. DPRINTK("Shared RAM paging enabled. "
  650. "Page size: %uK Shared Ram size %dK\n",
  651. ((ti->page_mask^0xff)+1) >>2, ti->avail_shared_ram / 2);
  652. else
  653. DPRINTK("Shared RAM paging disabled. ti->page_mask %x\n",
  654. ti->page_mask);
  655. /* Calculate the maximum DHB we can use */
  656. /* two cases where avail_shared_ram doesn't equal mapped_ram_size:
  657. 1. avail_shared_ram is 127 but mapped_ram_size is 128 (typical)
  658. 2. user has configured adapter for less than avail_shared_ram
  659. but is not using paging (she should use paging, I believe)
  660. */
  661. if (!ti->page_mask) {
  662. ti->avail_shared_ram=
  663. min(ti->mapped_ram_size,ti->avail_shared_ram);
  664. }
  665. switch (ti->avail_shared_ram) {
  666. case 16: /* 8KB shared RAM */
  667. ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)2048);
  668. ti->rbuf_len4 = 1032;
  669. ti->rbuf_cnt4=2;
  670. ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)2048);
  671. ti->rbuf_len16 = 1032;
  672. ti->rbuf_cnt16=2;
  673. break;
  674. case 32: /* 16KB shared RAM */
  675. ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)4464);
  676. ti->rbuf_len4 = 1032;
  677. ti->rbuf_cnt4=4;
  678. ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)4096);
  679. ti->rbuf_len16 = 1032; /*1024 usable */
  680. ti->rbuf_cnt16=4;
  681. break;
  682. case 64: /* 32KB shared RAM */
  683. ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)4464);
  684. ti->rbuf_len4 = 1032;
  685. ti->rbuf_cnt4=6;
  686. ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)10240);
  687. ti->rbuf_len16 = 1032;
  688. ti->rbuf_cnt16=6;
  689. break;
  690. case 127: /* 63.5KB shared RAM */
  691. ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)4464);
  692. ti->rbuf_len4 = 1032;
  693. ti->rbuf_cnt4=6;
  694. ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)16384);
  695. ti->rbuf_len16 = 1032;
  696. ti->rbuf_cnt16=16;
  697. break;
  698. case 128: /* 64KB shared RAM */
  699. ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)4464);
  700. ti->rbuf_len4 = 1032;
  701. ti->rbuf_cnt4=6;
  702. ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)17960);
  703. ti->rbuf_len16 = 1032;
  704. ti->rbuf_cnt16=16;
  705. break;
  706. default:
  707. ti->dhb_size4mb = 2048;
  708. ti->rbuf_len4 = 1032;
  709. ti->rbuf_cnt4=2;
  710. ti->dhb_size16mb = 2048;
  711. ti->rbuf_len16 = 1032;
  712. ti->rbuf_cnt16=2;
  713. break;
  714. }
  715. /* this formula is not smart enough for the paging case
  716. ti->rbuf_cnt<x> = (ti->avail_shared_ram * BLOCKSZ - ADAPT_PRIVATE -
  717. ARBLENGTH - SSBLENGTH - DLC_MAX_SAP * SAPLENGTH -
  718. DLC_MAX_STA * STALENGTH - ti->dhb_size<x>mb * NUM_DHB -
  719. SRBLENGTH - ASBLENGTH) / ti->rbuf_len<x>;
  720. */
  721. ti->maxmtu16 = (ti->rbuf_len16 - 8) * ti->rbuf_cnt16 - TR_HLEN;
  722. ti->maxmtu4 = (ti->rbuf_len4 - 8) * ti->rbuf_cnt4 - TR_HLEN;
  723. /*BMS assuming 18 bytes of Routing Information (usually works) */
  724. DPRINTK("Maximum Receive Internet Protocol MTU 16Mbps: %d, 4Mbps: %d\n",
  725. ti->maxmtu16, ti->maxmtu4);
  726. dev->base_addr = PIOaddr; /* set the value for device */
  727. dev->mem_start = ti->sram_base << 12;
  728. dev->mem_end = dev->mem_start + (ti->mapped_ram_size << 9) - 1;
  729. trdev_init(dev);
  730. return 0; /* Return 0 to indicate we have found a Token Ring card. */
  731. } /*ibmtr_probe1() */
  732. /*****************************************************************************/
  733. /* query the adapter for the size of shared RAM */
  734. /* the function returns the RAM size in units of 512 bytes */
  735. static unsigned char __devinit get_sram_size(struct tok_info *adapt_info)
  736. {
  737. unsigned char avail_sram_code;
  738. static unsigned char size_code[] = { 0, 16, 32, 64, 127, 128 };
  739. /* Adapter gives
  740. 'F' -- use RRR bits 3,2
  741. 'E' -- 8kb 'D' -- 16kb
  742. 'C' -- 32kb 'A' -- 64KB
  743. 'B' - 64KB less 512 bytes at top
  744. (WARNING ... must zero top bytes in INIT */
  745. avail_sram_code = 0xf - readb(adapt_info->mmio + AIPAVAILSHRAM);
  746. if (avail_sram_code) return size_code[avail_sram_code];
  747. else /* for code 'F', must compute size from RRR(3,2) bits */
  748. return 1 <<
  749. ((readb(adapt_info->mmio+ACA_OFFSET+ACA_RW+RRR_ODD)>>2&3)+4);
  750. }
  751. /*****************************************************************************/
  752. static const struct net_device_ops trdev_netdev_ops = {
  753. .ndo_open = tok_open,
  754. .ndo_stop = tok_close,
  755. .ndo_start_xmit = tok_send_packet,
  756. .ndo_set_multicast_list = tok_set_multicast_list,
  757. .ndo_change_mtu = ibmtr_change_mtu,
  758. };
  759. static int __devinit trdev_init(struct net_device *dev)
  760. {
  761. struct tok_info *ti = netdev_priv(dev);
  762. SET_PAGE(ti->srb_page);
  763. ti->open_failure = NO ;
  764. dev->netdev_ops = &trdev_netdev_ops;
  765. return 0;
  766. }
  767. /*****************************************************************************/
  768. static int tok_init_card(struct net_device *dev)
  769. {
  770. struct tok_info *ti;
  771. short PIOaddr;
  772. unsigned long i;
  773. PIOaddr = dev->base_addr;
  774. ti = netdev_priv(dev);
  775. /* Special processing for first interrupt after reset */
  776. ti->do_tok_int = FIRST_INT;
  777. /* Reset adapter */
  778. writeb(~INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_EVEN);
  779. outb(0, PIOaddr + ADAPTRESET);
  780. schedule_timeout_uninterruptible(TR_RST_TIME); /* wait 50ms */
  781. outb(0, PIOaddr + ADAPTRESETREL);
  782. #ifdef ENABLE_PAGING
  783. if (ti->page_mask)
  784. writeb(SRPR_ENABLE_PAGING,ti->mmio+ACA_OFFSET+ACA_RW+SRPR_EVEN);
  785. #endif
  786. writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
  787. i = sleep_on_timeout(&ti->wait_for_reset, 4 * HZ);
  788. return i? 0 : -EAGAIN;
  789. }
  790. /*****************************************************************************/
  791. static int tok_open(struct net_device *dev)
  792. {
  793. struct tok_info *ti = netdev_priv(dev);
  794. int i;
  795. /*the case we were left in a failure state during a previous open */
  796. if (ti->open_failure == YES) {
  797. DPRINTK("Last time you were disconnected, how about now?\n");
  798. printk("You can't insert with an ICS connector half-cocked.\n");
  799. }
  800. ti->open_status = CLOSED; /* CLOSED or OPEN */
  801. ti->sap_status = CLOSED; /* CLOSED or OPEN */
  802. ti->open_failure = NO; /* NO or YES */
  803. ti->open_mode = MANUAL; /* MANUAL or AUTOMATIC */
  804. ti->sram_phys &= ~1; /* to reverse what we do in tok_close */
  805. /* init the spinlock */
  806. spin_lock_init(&ti->lock);
  807. init_timer(&ti->tr_timer);
  808. i = tok_init_card(dev);
  809. if (i) return i;
  810. while (1){
  811. tok_open_adapter((unsigned long) dev);
  812. i= interruptible_sleep_on_timeout(&ti->wait_for_reset, 25 * HZ);
  813. /* sig catch: estimate opening adapter takes more than .5 sec*/
  814. if (i>(245*HZ)/10) break; /* fancier than if (i==25*HZ) */
  815. if (i==0) break;
  816. if (ti->open_status == OPEN && ti->sap_status==OPEN) {
  817. netif_start_queue(dev);
  818. DPRINTK("Adapter is up and running\n");
  819. return 0;
  820. }
  821. i=schedule_timeout_interruptible(TR_RETRY_INTERVAL);
  822. /* wait 30 seconds */
  823. if(i!=0) break; /*prob. a signal, like the i>24*HZ case above */
  824. }
  825. outb(0, dev->base_addr + ADAPTRESET);/* kill pending interrupts*/
  826. DPRINTK("TERMINATED via signal\n"); /*BMS useful */
  827. return -EAGAIN;
  828. }
  829. /*****************************************************************************/
  830. #define COMMAND_OFST 0
  831. #define OPEN_OPTIONS_OFST 8
  832. #define NUM_RCV_BUF_OFST 24
  833. #define RCV_BUF_LEN_OFST 26
  834. #define DHB_LENGTH_OFST 28
  835. #define NUM_DHB_OFST 30
  836. #define DLC_MAX_SAP_OFST 32
  837. #define DLC_MAX_STA_OFST 33
  838. static void tok_open_adapter(unsigned long dev_addr)
  839. {
  840. struct net_device *dev = (struct net_device *) dev_addr;
  841. struct tok_info *ti;
  842. int i;
  843. ti = netdev_priv(dev);
  844. SET_PAGE(ti->init_srb_page);
  845. writeb(~SRB_RESP_INT, ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_ODD);
  846. for (i = 0; i < sizeof(struct dir_open_adapter); i++)
  847. writeb(0, ti->init_srb + i);
  848. writeb(DIR_OPEN_ADAPTER, ti->init_srb + COMMAND_OFST);
  849. writew(htons(OPEN_PASS_BCON_MAC), ti->init_srb + OPEN_OPTIONS_OFST);
  850. if (ti->ring_speed == 16) {
  851. writew(htons(ti->dhb_size16mb), ti->init_srb + DHB_LENGTH_OFST);
  852. writew(htons(ti->rbuf_cnt16), ti->init_srb + NUM_RCV_BUF_OFST);
  853. writew(htons(ti->rbuf_len16), ti->init_srb + RCV_BUF_LEN_OFST);
  854. } else {
  855. writew(htons(ti->dhb_size4mb), ti->init_srb + DHB_LENGTH_OFST);
  856. writew(htons(ti->rbuf_cnt4), ti->init_srb + NUM_RCV_BUF_OFST);
  857. writew(htons(ti->rbuf_len4), ti->init_srb + RCV_BUF_LEN_OFST);
  858. }
  859. writeb(NUM_DHB, /* always 2 */ ti->init_srb + NUM_DHB_OFST);
  860. writeb(DLC_MAX_SAP, ti->init_srb + DLC_MAX_SAP_OFST);
  861. writeb(DLC_MAX_STA, ti->init_srb + DLC_MAX_STA_OFST);
  862. ti->srb = ti->init_srb; /* We use this one in the interrupt handler */
  863. ti->srb_page = ti->init_srb_page;
  864. DPRINTK("Opening adapter: Xmit bfrs: %d X %d, Rcv bfrs: %d X %d\n",
  865. readb(ti->init_srb + NUM_DHB_OFST),
  866. ntohs(readw(ti->init_srb + DHB_LENGTH_OFST)),
  867. ntohs(readw(ti->init_srb + NUM_RCV_BUF_OFST)),
  868. ntohs(readw(ti->init_srb + RCV_BUF_LEN_OFST)));
  869. writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
  870. writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  871. }
  872. /*****************************************************************************/
  873. static void open_sap(unsigned char type, struct net_device *dev)
  874. {
  875. int i;
  876. struct tok_info *ti = netdev_priv(dev);
  877. SET_PAGE(ti->srb_page);
  878. for (i = 0; i < sizeof(struct dlc_open_sap); i++)
  879. writeb(0, ti->srb + i);
  880. #define MAX_I_FIELD_OFST 14
  881. #define SAP_VALUE_OFST 16
  882. #define SAP_OPTIONS_OFST 17
  883. #define STATION_COUNT_OFST 18
  884. writeb(DLC_OPEN_SAP, ti->srb + COMMAND_OFST);
  885. writew(htons(MAX_I_FIELD), ti->srb + MAX_I_FIELD_OFST);
  886. writeb(SAP_OPEN_IND_SAP | SAP_OPEN_PRIORITY, ti->srb+ SAP_OPTIONS_OFST);
  887. writeb(SAP_OPEN_STATION_CNT, ti->srb + STATION_COUNT_OFST);
  888. writeb(type, ti->srb + SAP_VALUE_OFST);
  889. writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  890. }
  891. /*****************************************************************************/
  892. static void tok_set_multicast_list(struct net_device *dev)
  893. {
  894. struct tok_info *ti = netdev_priv(dev);
  895. struct netdev_hw_addr *ha;
  896. unsigned char address[4];
  897. int i;
  898. /*BMS the next line is CRUCIAL or you may be sad when you */
  899. /*BMS ifconfig tr down or hot unplug a PCMCIA card ??hownowbrowncow*/
  900. if (/*BMSHELPdev->start == 0 ||*/ ti->open_status != OPEN) return;
  901. address[0] = address[1] = address[2] = address[3] = 0;
  902. netdev_for_each_mc_addr(ha, dev) {
  903. address[0] |= ha->addr[2];
  904. address[1] |= ha->addr[3];
  905. address[2] |= ha->addr[4];
  906. address[3] |= ha->addr[5];
  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. return NETDEV_TX_OK;
  941. }
  942. /*****************************************************************************/
  943. static int tok_close(struct net_device *dev)
  944. {
  945. struct tok_info *ti = netdev_priv(dev);
  946. /* Important for PCMCIA hot unplug, otherwise, we'll pull the card, */
  947. /* unloading the module from memory, and then if a timer pops, ouch */
  948. del_timer_sync(&ti->tr_timer);
  949. outb(0, dev->base_addr + ADAPTRESET);
  950. ti->sram_phys |= 1;
  951. ti->open_status = CLOSED;
  952. netif_stop_queue(dev);
  953. DPRINTK("Adapter is closed.\n");
  954. return 0;
  955. }
  956. /*****************************************************************************/
  957. #define RETCODE_OFST 2
  958. #define OPEN_ERROR_CODE_OFST 6
  959. #define ASB_ADDRESS_OFST 8
  960. #define SRB_ADDRESS_OFST 10
  961. #define ARB_ADDRESS_OFST 12
  962. #define SSB_ADDRESS_OFST 14
  963. static char *printphase[]= {"Lobe media test","Physical insertion",
  964. "Address verification","Roll call poll","Request Parameters"};
  965. static char *printerror[]={"Function failure","Signal loss","Reserved",
  966. "Frequency error","Timeout","Ring failure","Ring beaconing",
  967. "Duplicate node address",
  968. "Parameter request-retry count exceeded","Remove received",
  969. "IMPL force received","Duplicate modifier",
  970. "No monitor detected","Monitor contention failed for RPL"};
  971. static void __iomem *map_address(struct tok_info *ti, unsigned index, __u8 *page)
  972. {
  973. if (ti->page_mask) {
  974. *page = (index >> 8) & ti->page_mask;
  975. index &= ~(ti->page_mask << 8);
  976. }
  977. return ti->sram_virt + index;
  978. }
  979. static void dir_open_adapter (struct net_device *dev)
  980. {
  981. struct tok_info *ti = netdev_priv(dev);
  982. unsigned char ret_code;
  983. __u16 err;
  984. ti->srb = map_address(ti,
  985. ntohs(readw(ti->init_srb + SRB_ADDRESS_OFST)),
  986. &ti->srb_page);
  987. ti->ssb = map_address(ti,
  988. ntohs(readw(ti->init_srb + SSB_ADDRESS_OFST)),
  989. &ti->ssb_page);
  990. ti->arb = map_address(ti,
  991. ntohs(readw(ti->init_srb + ARB_ADDRESS_OFST)),
  992. &ti->arb_page);
  993. ti->asb = map_address(ti,
  994. ntohs(readw(ti->init_srb + ASB_ADDRESS_OFST)),
  995. &ti->asb_page);
  996. ti->current_skb = NULL;
  997. ret_code = readb(ti->init_srb + RETCODE_OFST);
  998. err = ntohs(readw(ti->init_srb + OPEN_ERROR_CODE_OFST));
  999. if (!ret_code) {
  1000. ti->open_status = OPEN; /* TR adapter is now available */
  1001. if (ti->open_mode == AUTOMATIC) {
  1002. DPRINTK("Adapter reopened.\n");
  1003. }
  1004. writeb(~SRB_RESP_INT, ti->mmio+ACA_OFFSET+ACA_RESET+ISRP_ODD);
  1005. open_sap(EXTENDED_SAP, dev);
  1006. return;
  1007. }
  1008. ti->open_failure = YES;
  1009. if (ret_code == 7){
  1010. if (err == 0x24) {
  1011. if (!ti->auto_speedsave) {
  1012. DPRINTK("Open failed: Adapter speed must match "
  1013. "ring speed if Automatic Ring Speed Save is "
  1014. "disabled.\n");
  1015. ti->open_action = FAIL;
  1016. }else
  1017. DPRINTK("Retrying open to adjust to "
  1018. "ring speed, ");
  1019. } else if (err == 0x2d) {
  1020. DPRINTK("Physical Insertion: No Monitor Detected, ");
  1021. printk("retrying after %ds delay...\n",
  1022. TR_RETRY_INTERVAL/HZ);
  1023. } else if (err == 0x11) {
  1024. DPRINTK("Lobe Media Function Failure (0x11), ");
  1025. printk(" retrying after %ds delay...\n",
  1026. TR_RETRY_INTERVAL/HZ);
  1027. } else {
  1028. char **prphase = printphase;
  1029. char **prerror = printerror;
  1030. int pnr = err / 16 - 1;
  1031. int enr = err % 16 - 1;
  1032. DPRINTK("TR Adapter misc open failure, error code = ");
  1033. if (pnr < 0 || pnr >= ARRAY_SIZE(printphase) ||
  1034. enr < 0 ||
  1035. enr >= ARRAY_SIZE(printerror))
  1036. printk("0x%x, invalid Phase/Error.", err);
  1037. else
  1038. printk("0x%x, Phase: %s, Error: %s\n", err,
  1039. prphase[pnr], prerror[enr]);
  1040. printk(" retrying after %ds delay...\n",
  1041. TR_RETRY_INTERVAL/HZ);
  1042. }
  1043. } else DPRINTK("open failed: ret_code = %02X..., ", ret_code);
  1044. if (ti->open_action != FAIL) {
  1045. if (ti->open_mode==AUTOMATIC){
  1046. ti->open_action = REOPEN;
  1047. ibmtr_reset_timer(&(ti->tr_timer), dev);
  1048. return;
  1049. }
  1050. wake_up(&ti->wait_for_reset);
  1051. return;
  1052. }
  1053. DPRINTK("FAILURE, CAPUT\n");
  1054. }
  1055. /******************************************************************************/
  1056. static irqreturn_t tok_interrupt(int irq, void *dev_id)
  1057. {
  1058. unsigned char status;
  1059. /* unsigned char status_even ; */
  1060. struct tok_info *ti;
  1061. struct net_device *dev;
  1062. #ifdef ENABLE_PAGING
  1063. unsigned char save_srpr;
  1064. #endif
  1065. dev = dev_id;
  1066. #if TR_VERBOSE
  1067. DPRINTK("Int from tok_driver, dev : %p irq%d\n", dev,irq);
  1068. #endif
  1069. ti = netdev_priv(dev);
  1070. if (ti->sram_phys & 1)
  1071. return IRQ_NONE; /* PCMCIA card extraction flag */
  1072. spin_lock(&(ti->lock));
  1073. #ifdef ENABLE_PAGING
  1074. save_srpr = readb(ti->mmio + ACA_OFFSET + ACA_RW + SRPR_EVEN);
  1075. #endif
  1076. /* Disable interrupts till processing is finished */
  1077. writeb((~INT_ENABLE), ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_EVEN);
  1078. /* Reset interrupt for ISA boards */
  1079. if (ti->adapter_int_enable)
  1080. outb(0, ti->adapter_int_enable);
  1081. else /* used for PCMCIA cards */
  1082. outb(0, ti->global_int_enable);
  1083. if (ti->do_tok_int == FIRST_INT){
  1084. initial_tok_int(dev);
  1085. #ifdef ENABLE_PAGING
  1086. writeb(save_srpr, ti->mmio + ACA_OFFSET + ACA_RW + SRPR_EVEN);
  1087. #endif
  1088. spin_unlock(&(ti->lock));
  1089. return IRQ_HANDLED;
  1090. }
  1091. /* Begin interrupt handler HERE inline to avoid the extra
  1092. levels of logic and call depth for the original solution. */
  1093. status = readb(ti->mmio + ACA_OFFSET + ACA_RW + ISRP_ODD);
  1094. /*BMSstatus_even = readb (ti->mmio + ACA_OFFSET + ACA_RW + ISRP_EVEN) */
  1095. /*BMSdebugprintk("tok_interrupt: ISRP_ODD = 0x%x ISRP_EVEN = 0x%x\n", */
  1096. /*BMS status,status_even); */
  1097. if (status & ADAP_CHK_INT) {
  1098. int i;
  1099. void __iomem *check_reason;
  1100. __u8 check_reason_page = 0;
  1101. check_reason = map_address(ti,
  1102. ntohs(readw(ti->mmio+ ACA_OFFSET+ACA_RW + WWCR_EVEN)),
  1103. &check_reason_page);
  1104. SET_PAGE(check_reason_page);
  1105. DPRINTK("Adapter check interrupt\n");
  1106. DPRINTK("8 reason bytes follow: ");
  1107. for (i = 0; i < 8; i++, check_reason++)
  1108. printk("%02X ", (int) readb(check_reason));
  1109. printk("\n");
  1110. writeb(~ADAP_CHK_INT, ti->mmio+ ACA_OFFSET+ACA_RESET+ ISRP_ODD);
  1111. status = readb(ti->mmio + ACA_OFFSET + ACA_RW + ISRA_EVEN);
  1112. DPRINTK("ISRA_EVEN == 0x02%x\n",status);
  1113. ti->open_status = CLOSED;
  1114. ti->sap_status = CLOSED;
  1115. ti->open_mode = AUTOMATIC;
  1116. netif_carrier_off(dev);
  1117. netif_stop_queue(dev);
  1118. ti->open_action = RESTART;
  1119. outb(0, dev->base_addr + ADAPTRESET);
  1120. ibmtr_reset_timer(&(ti->tr_timer), dev);/*BMS try to reopen*/
  1121. spin_unlock(&(ti->lock));
  1122. return IRQ_HANDLED;
  1123. }
  1124. if (readb(ti->mmio + ACA_OFFSET + ACA_RW + ISRP_EVEN)
  1125. & (TCR_INT | ERR_INT | ACCESS_INT)) {
  1126. DPRINTK("adapter error: ISRP_EVEN : %02x\n",
  1127. (int)readb(ti->mmio+ ACA_OFFSET + ACA_RW + ISRP_EVEN));
  1128. writeb(~(TCR_INT | ERR_INT | ACCESS_INT),
  1129. ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_EVEN);
  1130. status= readb(ti->mmio+ ACA_OFFSET + ACA_RW + ISRA_EVEN);/*BMS*/
  1131. DPRINTK("ISRA_EVEN == 0x02%x\n",status);/*BMS*/
  1132. writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
  1133. #ifdef ENABLE_PAGING
  1134. writeb(save_srpr, ti->mmio + ACA_OFFSET + ACA_RW + SRPR_EVEN);
  1135. #endif
  1136. spin_unlock(&(ti->lock));
  1137. return IRQ_HANDLED;
  1138. }
  1139. if (status & SRB_RESP_INT) { /* SRB response */
  1140. SET_PAGE(ti->srb_page);
  1141. #if TR_VERBOSE
  1142. DPRINTK("SRB resp: cmd=%02X rsp=%02X\n",
  1143. readb(ti->srb), readb(ti->srb + RETCODE_OFST));
  1144. #endif
  1145. switch (readb(ti->srb)) { /* SRB command check */
  1146. case XMIT_DIR_FRAME:{
  1147. unsigned char xmit_ret_code;
  1148. xmit_ret_code = readb(ti->srb + RETCODE_OFST);
  1149. if (xmit_ret_code == 0xff) break;
  1150. DPRINTK("error on xmit_dir_frame request: %02X\n",
  1151. xmit_ret_code);
  1152. if (ti->current_skb) {
  1153. dev_kfree_skb_irq(ti->current_skb);
  1154. ti->current_skb = NULL;
  1155. }
  1156. /*dev->tbusy = 0;*/
  1157. netif_wake_queue(dev);
  1158. if (ti->readlog_pending)
  1159. ibmtr_readlog(dev);
  1160. break;
  1161. }
  1162. case XMIT_UI_FRAME:{
  1163. unsigned char xmit_ret_code;
  1164. xmit_ret_code = readb(ti->srb + RETCODE_OFST);
  1165. if (xmit_ret_code == 0xff) break;
  1166. DPRINTK("error on xmit_ui_frame request: %02X\n",
  1167. xmit_ret_code);
  1168. if (ti->current_skb) {
  1169. dev_kfree_skb_irq(ti->current_skb);
  1170. ti->current_skb = NULL;
  1171. }
  1172. netif_wake_queue(dev);
  1173. if (ti->readlog_pending)
  1174. ibmtr_readlog(dev);
  1175. break;
  1176. }
  1177. case DIR_OPEN_ADAPTER:
  1178. dir_open_adapter(dev);
  1179. break;
  1180. case DLC_OPEN_SAP:
  1181. if (readb(ti->srb + RETCODE_OFST)) {
  1182. DPRINTK("open_sap failed: ret_code = %02X, "
  1183. "retrying\n",
  1184. (int) readb(ti->srb + RETCODE_OFST));
  1185. ti->open_action = REOPEN;
  1186. ibmtr_reset_timer(&(ti->tr_timer), dev);
  1187. break;
  1188. }
  1189. ti->exsap_station_id = readw(ti->srb + STATION_ID_OFST);
  1190. ti->sap_status = OPEN;/* TR adapter is now available */
  1191. if (ti->open_mode==MANUAL){
  1192. wake_up(&ti->wait_for_reset);
  1193. break;
  1194. }
  1195. netif_wake_queue(dev);
  1196. netif_carrier_on(dev);
  1197. break;
  1198. case DIR_INTERRUPT:
  1199. case DIR_MOD_OPEN_PARAMS:
  1200. case DIR_SET_GRP_ADDR:
  1201. case DIR_SET_FUNC_ADDR:
  1202. case DLC_CLOSE_SAP:
  1203. if (readb(ti->srb + RETCODE_OFST))
  1204. DPRINTK("error on %02X: %02X\n",
  1205. (int) readb(ti->srb + COMMAND_OFST),
  1206. (int) readb(ti->srb + RETCODE_OFST));
  1207. break;
  1208. case DIR_READ_LOG:
  1209. if (readb(ti->srb + RETCODE_OFST)){
  1210. DPRINTK("error on dir_read_log: %02X\n",
  1211. (int) readb(ti->srb + RETCODE_OFST));
  1212. netif_wake_queue(dev);
  1213. break;
  1214. }
  1215. #if IBMTR_DEBUG_MESSAGES
  1216. #define LINE_ERRORS_OFST 0
  1217. #define INTERNAL_ERRORS_OFST 1
  1218. #define BURST_ERRORS_OFST 2
  1219. #define AC_ERRORS_OFST 3
  1220. #define ABORT_DELIMITERS_OFST 4
  1221. #define LOST_FRAMES_OFST 6
  1222. #define RECV_CONGEST_COUNT_OFST 7
  1223. #define FRAME_COPIED_ERRORS_OFST 8
  1224. #define FREQUENCY_ERRORS_OFST 9
  1225. #define TOKEN_ERRORS_OFST 10
  1226. DPRINTK("Line errors %02X, Internal errors %02X, "
  1227. "Burst errors %02X\n" "A/C errors %02X, "
  1228. "Abort delimiters %02X, Lost frames %02X\n"
  1229. "Receive congestion count %02X, "
  1230. "Frame copied errors %02X\nFrequency errors %02X, "
  1231. "Token errors %02X\n",
  1232. (int) readb(ti->srb + LINE_ERRORS_OFST),
  1233. (int) readb(ti->srb + INTERNAL_ERRORS_OFST),
  1234. (int) readb(ti->srb + BURST_ERRORS_OFST),
  1235. (int) readb(ti->srb + AC_ERRORS_OFST),
  1236. (int) readb(ti->srb + ABORT_DELIMITERS_OFST),
  1237. (int) readb(ti->srb + LOST_FRAMES_OFST),
  1238. (int) readb(ti->srb + RECV_CONGEST_COUNT_OFST),
  1239. (int) readb(ti->srb + FRAME_COPIED_ERRORS_OFST),
  1240. (int) readb(ti->srb + FREQUENCY_ERRORS_OFST),
  1241. (int) readb(ti->srb + TOKEN_ERRORS_OFST));
  1242. #endif
  1243. netif_wake_queue(dev);
  1244. break;
  1245. default:
  1246. DPRINTK("Unknown command %02X encountered\n",
  1247. (int) readb(ti->srb));
  1248. } /* end switch SRB command check */
  1249. writeb(~SRB_RESP_INT, ti->mmio+ ACA_OFFSET+ACA_RESET+ ISRP_ODD);
  1250. } /* if SRB response */
  1251. if (status & ASB_FREE_INT) { /* ASB response */
  1252. SET_PAGE(ti->asb_page);
  1253. #if TR_VERBOSE
  1254. DPRINTK("ASB resp: cmd=%02X\n", readb(ti->asb));
  1255. #endif
  1256. switch (readb(ti->asb)) { /* ASB command check */
  1257. case REC_DATA:
  1258. case XMIT_UI_FRAME:
  1259. case XMIT_DIR_FRAME:
  1260. break;
  1261. default:
  1262. DPRINTK("unknown command in asb %02X\n",
  1263. (int) readb(ti->asb));
  1264. } /* switch ASB command check */
  1265. if (readb(ti->asb + 2) != 0xff) /* checks ret_code */
  1266. DPRINTK("ASB error %02X in cmd %02X\n",
  1267. (int) readb(ti->asb + 2), (int) readb(ti->asb));
  1268. writeb(~ASB_FREE_INT, ti->mmio+ ACA_OFFSET+ACA_RESET+ ISRP_ODD);
  1269. } /* if ASB response */
  1270. #define STATUS_OFST 6
  1271. #define NETW_STATUS_OFST 6
  1272. if (status & ARB_CMD_INT) { /* ARB response */
  1273. SET_PAGE(ti->arb_page);
  1274. #if TR_VERBOSE
  1275. DPRINTK("ARB resp: cmd=%02X\n", readb(ti->arb));
  1276. #endif
  1277. switch (readb(ti->arb)) { /* ARB command check */
  1278. case DLC_STATUS:
  1279. DPRINTK("DLC_STATUS new status: %02X on station %02X\n",
  1280. ntohs(readw(ti->arb + STATUS_OFST)),
  1281. ntohs(readw(ti->arb+ STATION_ID_OFST)));
  1282. break;
  1283. case REC_DATA:
  1284. tr_rx(dev);
  1285. break;
  1286. case RING_STAT_CHANGE:{
  1287. unsigned short ring_status;
  1288. ring_status= ntohs(readw(ti->arb + NETW_STATUS_OFST));
  1289. if (ibmtr_debug_trace & TRC_INIT)
  1290. DPRINTK("Ring Status Change...(0x%x)\n",
  1291. ring_status);
  1292. if(ring_status& (REMOVE_RECV|AUTO_REMOVAL|LOBE_FAULT)){
  1293. netif_stop_queue(dev);
  1294. netif_carrier_off(dev);
  1295. DPRINTK("Remove received, or Auto-removal error"
  1296. ", or Lobe fault\n");
  1297. DPRINTK("We'll try to reopen the closed adapter"
  1298. " after a %d second delay.\n",
  1299. TR_RETRY_INTERVAL/HZ);
  1300. /*I was confused: I saw the TR reopening but */
  1301. /*forgot:with an RJ45 in an RJ45/ICS adapter */
  1302. /*but adapter not in the ring, the TR will */
  1303. /* open, and then soon close and come here. */
  1304. ti->open_mode = AUTOMATIC;
  1305. ti->open_status = CLOSED; /*12/2000 BMS*/
  1306. ti->open_action = REOPEN;
  1307. ibmtr_reset_timer(&(ti->tr_timer), dev);
  1308. } else if (ring_status & LOG_OVERFLOW) {
  1309. if(netif_queue_stopped(dev))
  1310. ti->readlog_pending = 1;
  1311. else
  1312. ibmtr_readlog(dev);
  1313. }
  1314. break;
  1315. }
  1316. case XMIT_DATA_REQ:
  1317. tr_tx(dev);
  1318. break;
  1319. default:
  1320. DPRINTK("Unknown command %02X in arb\n",
  1321. (int) readb(ti->arb));
  1322. break;
  1323. } /* switch ARB command check */
  1324. writeb(~ARB_CMD_INT, ti->mmio+ ACA_OFFSET+ACA_RESET + ISRP_ODD);
  1325. writeb(ARB_FREE, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  1326. } /* if ARB response */
  1327. if (status & SSB_RESP_INT) { /* SSB response */
  1328. unsigned char retcode;
  1329. SET_PAGE(ti->ssb_page);
  1330. #if TR_VERBOSE
  1331. DPRINTK("SSB resp: cmd=%02X rsp=%02X\n",
  1332. readb(ti->ssb), readb(ti->ssb + 2));
  1333. #endif
  1334. switch (readb(ti->ssb)) { /* SSB command check */
  1335. case XMIT_DIR_FRAME:
  1336. case XMIT_UI_FRAME:
  1337. retcode = readb(ti->ssb + 2);
  1338. if (retcode && (retcode != 0x22))/* checks ret_code */
  1339. DPRINTK("xmit ret_code: %02X xmit error code: "
  1340. "%02X\n",
  1341. (int)retcode, (int)readb(ti->ssb + 6));
  1342. else
  1343. dev->stats.tx_packets++;
  1344. break;
  1345. case XMIT_XID_CMD:
  1346. DPRINTK("xmit xid ret_code: %02X\n",
  1347. (int) readb(ti->ssb + 2));
  1348. default:
  1349. DPRINTK("Unknown command %02X in ssb\n",
  1350. (int) readb(ti->ssb));
  1351. } /* SSB command check */
  1352. writeb(~SSB_RESP_INT, ti->mmio+ ACA_OFFSET+ACA_RESET+ ISRP_ODD);
  1353. writeb(SSB_FREE, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  1354. } /* if SSB response */
  1355. #ifdef ENABLE_PAGING
  1356. writeb(save_srpr, ti->mmio + ACA_OFFSET + ACA_RW + SRPR_EVEN);
  1357. #endif
  1358. writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
  1359. spin_unlock(&(ti->lock));
  1360. return IRQ_HANDLED;
  1361. } /*tok_interrupt */
  1362. /*****************************************************************************/
  1363. #define INIT_STATUS_OFST 1
  1364. #define INIT_STATUS_2_OFST 2
  1365. #define ENCODED_ADDRESS_OFST 8
  1366. static void initial_tok_int(struct net_device *dev)
  1367. {
  1368. __u32 encoded_addr, hw_encoded_addr;
  1369. struct tok_info *ti;
  1370. unsigned char init_status; /*BMS 12/2000*/
  1371. ti = netdev_priv(dev);
  1372. ti->do_tok_int = NOT_FIRST;
  1373. /* we assign the shared-ram address for ISA devices */
  1374. writeb(ti->sram_base, ti->mmio + ACA_OFFSET + ACA_RW + RRR_EVEN);
  1375. #ifndef PCMCIA
  1376. ti->sram_virt = ioremap(((__u32)ti->sram_base << 12), ti->avail_shared_ram);
  1377. #endif
  1378. ti->init_srb = map_address(ti,
  1379. ntohs(readw(ti->mmio + ACA_OFFSET + WRBR_EVEN)),
  1380. &ti->init_srb_page);
  1381. if (ti->page_mask && ti->avail_shared_ram == 127) {
  1382. void __iomem *last_512;
  1383. __u8 last_512_page=0;
  1384. int i;
  1385. last_512 = map_address(ti, 0xfe00, &last_512_page);
  1386. /* initialize high section of ram (if necessary) */
  1387. SET_PAGE(last_512_page);
  1388. for (i = 0; i < 512; i++)
  1389. writeb(0, last_512 + i);
  1390. }
  1391. SET_PAGE(ti->init_srb_page);
  1392. #if TR_VERBOSE
  1393. {
  1394. int i;
  1395. DPRINTK("ti->init_srb_page=0x%x\n", ti->init_srb_page);
  1396. DPRINTK("init_srb(%p):", ti->init_srb );
  1397. for (i = 0; i < 20; i++)
  1398. printk("%02X ", (int) readb(ti->init_srb + i));
  1399. printk("\n");
  1400. }
  1401. #endif
  1402. hw_encoded_addr = readw(ti->init_srb + ENCODED_ADDRESS_OFST);
  1403. encoded_addr = ntohs(hw_encoded_addr);
  1404. init_status= /*BMS 12/2000 check for shallow mode possibility (Turbo)*/
  1405. readb(ti->init_srb+offsetof(struct srb_init_response,init_status));
  1406. /*printk("Initial interrupt: init_status= 0x%02x\n",init_status);*/
  1407. ti->ring_speed = init_status & 0x01 ? 16 : 4;
  1408. DPRINTK("Initial interrupt : %d Mbps, shared RAM base %08x.\n",
  1409. ti->ring_speed, (unsigned int)dev->mem_start);
  1410. ti->auto_speedsave = (readb(ti->init_srb+INIT_STATUS_2_OFST) & 4) != 0;
  1411. if (ti->open_mode == MANUAL) wake_up(&ti->wait_for_reset);
  1412. else tok_open_adapter((unsigned long)dev);
  1413. } /*initial_tok_int() */
  1414. /*****************************************************************************/
  1415. #define CMD_CORRELATE_OFST 1
  1416. #define DHB_ADDRESS_OFST 6
  1417. #define FRAME_LENGTH_OFST 6
  1418. #define HEADER_LENGTH_OFST 8
  1419. #define RSAP_VALUE_OFST 9
  1420. static void tr_tx(struct net_device *dev)
  1421. {
  1422. struct tok_info *ti = netdev_priv(dev);
  1423. struct trh_hdr *trhdr = (struct trh_hdr *) ti->current_skb->data;
  1424. unsigned int hdr_len;
  1425. __u32 dhb=0,dhb_base;
  1426. void __iomem *dhbuf = NULL;
  1427. unsigned char xmit_command;
  1428. int i,dhb_len=0x4000,src_len,src_offset;
  1429. struct trllc *llc;
  1430. struct srb_xmit xsrb;
  1431. __u8 dhb_page = 0;
  1432. __u8 llc_ssap;
  1433. SET_PAGE(ti->asb_page);
  1434. if (readb(ti->asb+RETCODE_OFST) != 0xFF) DPRINTK("ASB not free !!!\n");
  1435. /* in providing the transmit interrupts, is telling us it is ready for
  1436. data and providing a shared memory address for us to stuff with data.
  1437. Here we compute the effective address where we will place data.
  1438. */
  1439. SET_PAGE(ti->arb_page);
  1440. dhb=dhb_base=ntohs(readw(ti->arb + DHB_ADDRESS_OFST));
  1441. if (ti->page_mask) {
  1442. dhb_page = (dhb_base >> 8) & ti->page_mask;
  1443. dhb=dhb_base & ~(ti->page_mask << 8);
  1444. }
  1445. dhbuf = ti->sram_virt + dhb;
  1446. /* Figure out the size of the 802.5 header */
  1447. if (!(trhdr->saddr[0] & 0x80)) /* RIF present? */
  1448. hdr_len = sizeof(struct trh_hdr) - TR_MAXRIFLEN;
  1449. else
  1450. hdr_len = ((ntohs(trhdr->rcf) & TR_RCF_LEN_MASK) >> 8)
  1451. + sizeof(struct trh_hdr) - TR_MAXRIFLEN;
  1452. llc = (struct trllc *) (ti->current_skb->data + hdr_len);
  1453. llc_ssap = llc->ssap;
  1454. SET_PAGE(ti->srb_page);
  1455. memcpy_fromio(&xsrb, ti->srb, sizeof(xsrb));
  1456. SET_PAGE(ti->asb_page);
  1457. xmit_command = xsrb.command;
  1458. writeb(xmit_command, ti->asb + COMMAND_OFST);
  1459. writew(xsrb.station_id, ti->asb + STATION_ID_OFST);
  1460. writeb(llc_ssap, ti->asb + RSAP_VALUE_OFST);
  1461. writeb(xsrb.cmd_corr, ti->asb + CMD_CORRELATE_OFST);
  1462. writeb(0, ti->asb + RETCODE_OFST);
  1463. if ((xmit_command == XMIT_XID_CMD) || (xmit_command == XMIT_TEST_CMD)) {
  1464. writew(htons(0x11), ti->asb + FRAME_LENGTH_OFST);
  1465. writeb(0x0e, ti->asb + HEADER_LENGTH_OFST);
  1466. SET_PAGE(dhb_page);
  1467. writeb(AC, dhbuf);
  1468. writeb(LLC_FRAME, dhbuf + 1);
  1469. for (i = 0; i < TR_ALEN; i++)
  1470. writeb((int) 0x0FF, dhbuf + i + 2);
  1471. for (i = 0; i < TR_ALEN; i++)
  1472. writeb(0, dhbuf + i + TR_ALEN + 2);
  1473. writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  1474. return;
  1475. }
  1476. /*
  1477. * the token ring packet is copied from sk_buff to the adapter
  1478. * buffer identified in the command data received with the interrupt.
  1479. */
  1480. writeb(hdr_len, ti->asb + HEADER_LENGTH_OFST);
  1481. writew(htons(ti->current_skb->len), ti->asb + FRAME_LENGTH_OFST);
  1482. src_len=ti->current_skb->len;
  1483. src_offset=0;
  1484. dhb=dhb_base;
  1485. while(1) {
  1486. if (ti->page_mask) {
  1487. dhb_page=(dhb >> 8) & ti->page_mask;
  1488. dhb=dhb & ~(ti->page_mask << 8);
  1489. dhb_len=0x4000-dhb; /* remaining size of this page */
  1490. }
  1491. dhbuf = ti->sram_virt + dhb;
  1492. SET_PAGE(dhb_page);
  1493. if (src_len > dhb_len) {
  1494. memcpy_toio(dhbuf,&ti->current_skb->data[src_offset],
  1495. dhb_len);
  1496. src_len -= dhb_len;
  1497. src_offset += dhb_len;
  1498. dhb_base+=dhb_len;
  1499. dhb=dhb_base;
  1500. continue;
  1501. }
  1502. memcpy_toio(dhbuf, &ti->current_skb->data[src_offset], src_len);
  1503. break;
  1504. }
  1505. writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  1506. dev->stats.tx_bytes += ti->current_skb->len;
  1507. dev_kfree_skb_irq(ti->current_skb);
  1508. ti->current_skb = NULL;
  1509. netif_wake_queue(dev);
  1510. if (ti->readlog_pending)
  1511. ibmtr_readlog(dev);
  1512. } /*tr_tx */
  1513. /*****************************************************************************/
  1514. #define RECEIVE_BUFFER_OFST 6
  1515. #define LAN_HDR_LENGTH_OFST 8
  1516. #define DLC_HDR_LENGTH_OFST 9
  1517. #define DSAP_OFST 0
  1518. #define SSAP_OFST 1
  1519. #define LLC_OFST 2
  1520. #define PROTID_OFST 3
  1521. #define ETHERTYPE_OFST 6
  1522. static void tr_rx(struct net_device *dev)
  1523. {
  1524. struct tok_info *ti = netdev_priv(dev);
  1525. __u32 rbuffer;
  1526. void __iomem *rbuf, *rbufdata, *llc;
  1527. __u8 rbuffer_page = 0;
  1528. unsigned char *data;
  1529. unsigned int rbuffer_len, lan_hdr_len, hdr_len, ip_len, length;
  1530. unsigned char dlc_hdr_len;
  1531. struct sk_buff *skb;
  1532. unsigned int skb_size = 0;
  1533. int IPv4_p = 0;
  1534. unsigned int chksum = 0;
  1535. struct iphdr *iph;
  1536. struct arb_rec_req rarb;
  1537. SET_PAGE(ti->arb_page);
  1538. memcpy_fromio(&rarb, ti->arb, sizeof(rarb));
  1539. rbuffer = ntohs(rarb.rec_buf_addr) ;
  1540. rbuf = map_address(ti, rbuffer, &rbuffer_page);
  1541. SET_PAGE(ti->asb_page);
  1542. if (readb(ti->asb + RETCODE_OFST) !=0xFF) DPRINTK("ASB not free !!!\n");
  1543. writeb(REC_DATA, ti->asb + COMMAND_OFST);
  1544. writew(rarb.station_id, ti->asb + STATION_ID_OFST);
  1545. writew(rarb.rec_buf_addr, ti->asb + RECEIVE_BUFFER_OFST);
  1546. lan_hdr_len = rarb.lan_hdr_len;
  1547. if (lan_hdr_len > sizeof(struct trh_hdr)) {
  1548. DPRINTK("Linux cannot handle greater than 18 bytes RIF\n");
  1549. return;
  1550. } /*BMS I added this above just to be very safe */
  1551. dlc_hdr_len = readb(ti->arb + DLC_HDR_LENGTH_OFST);
  1552. hdr_len = lan_hdr_len + sizeof(struct trllc) + sizeof(struct iphdr);
  1553. SET_PAGE(rbuffer_page);
  1554. llc = rbuf + offsetof(struct rec_buf, data) + lan_hdr_len;
  1555. #if TR_VERBOSE
  1556. DPRINTK("offsetof data: %02X lan_hdr_len: %02X\n",
  1557. (__u32) offsetof(struct rec_buf, data), (unsigned int) lan_hdr_len);
  1558. DPRINTK("llc: %08X rec_buf_addr: %04X dev->mem_start: %lX\n",
  1559. llc, ntohs(rarb.rec_buf_addr), dev->mem_start);
  1560. DPRINTK("dsap: %02X, ssap: %02X, llc: %02X, protid: %02X%02X%02X, "
  1561. "ethertype: %04X\n",
  1562. (int) readb(llc + DSAP_OFST), (int) readb(llc + SSAP_OFST),
  1563. (int) readb(llc + LLC_OFST), (int) readb(llc + PROTID_OFST),
  1564. (int) readb(llc+PROTID_OFST+1),(int)readb(llc+PROTID_OFST + 2),
  1565. (int) ntohs(readw(llc + ETHERTYPE_OFST)));
  1566. #endif
  1567. if (readb(llc + offsetof(struct trllc, llc)) != UI_CMD) {
  1568. SET_PAGE(ti->asb_page);
  1569. writeb(DATA_LOST, ti->asb + RETCODE_OFST);
  1570. dev->stats.rx_dropped++;
  1571. writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  1572. return;
  1573. }
  1574. length = ntohs(rarb.frame_len);
  1575. if (readb(llc + DSAP_OFST) == EXTENDED_SAP &&
  1576. readb(llc + SSAP_OFST) == EXTENDED_SAP &&
  1577. length >= hdr_len) IPv4_p = 1;
  1578. #if TR_VERBOSE
  1579. #define SADDR_OFST 8
  1580. #define DADDR_OFST 2
  1581. if (!IPv4_p) {
  1582. void __iomem *trhhdr = rbuf + offsetof(struct rec_buf, data);
  1583. u8 saddr[6];
  1584. u8 daddr[6];
  1585. int i;
  1586. for (i = 0 ; i < 6 ; i++)
  1587. saddr[i] = readb(trhhdr + SADDR_OFST + i);
  1588. for (i = 0 ; i < 6 ; i++)
  1589. daddr[i] = readb(trhhdr + DADDR_OFST + i);
  1590. DPRINTK("Probably non-IP frame received.\n");
  1591. DPRINTK("ssap: %02X dsap: %02X "
  1592. "saddr: %pM daddr: %pM\n",
  1593. readb(llc + SSAP_OFST), readb(llc + DSAP_OFST),
  1594. saddr, daddr);
  1595. }
  1596. #endif
  1597. /*BMS handle the case she comes in with few hops but leaves with many */
  1598. skb_size=length-lan_hdr_len+sizeof(struct trh_hdr)+sizeof(struct trllc);
  1599. if (!(skb = dev_alloc_skb(skb_size))) {
  1600. DPRINTK("out of memory. frame dropped.\n");
  1601. dev->stats.rx_dropped++;
  1602. SET_PAGE(ti->asb_page);
  1603. writeb(DATA_LOST, ti->asb + offsetof(struct asb_rec, ret_code));
  1604. writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  1605. return;
  1606. }
  1607. /*BMS again, if she comes in with few but leaves with many */
  1608. skb_reserve(skb, sizeof(struct trh_hdr) - lan_hdr_len);
  1609. skb_put(skb, length);
  1610. data = skb->data;
  1611. rbuffer_len = ntohs(readw(rbuf + offsetof(struct rec_buf, buf_len)));
  1612. rbufdata = rbuf + offsetof(struct rec_buf, data);
  1613. if (IPv4_p) {
  1614. /* Copy the headers without checksumming */
  1615. memcpy_fromio(data, rbufdata, hdr_len);
  1616. /* Watch for padded packets and bogons */
  1617. iph= (struct iphdr *)(data+ lan_hdr_len + sizeof(struct trllc));
  1618. ip_len = ntohs(iph->tot_len) - sizeof(struct iphdr);
  1619. length -= hdr_len;
  1620. if ((ip_len <= length) && (ip_len > 7))
  1621. length = ip_len;
  1622. data += hdr_len;
  1623. rbuffer_len -= hdr_len;
  1624. rbufdata += hdr_len;
  1625. }
  1626. /* Copy the payload... */
  1627. #define BUFFER_POINTER_OFST 2
  1628. #define BUFFER_LENGTH_OFST 6
  1629. for (;;) {
  1630. if (ibmtr_debug_trace&TRC_INITV && length < rbuffer_len)
  1631. DPRINTK("CURIOUS, length=%d < rbuffer_len=%d\n",
  1632. length,rbuffer_len);
  1633. if (IPv4_p)
  1634. chksum=csum_partial_copy_nocheck((void*)rbufdata,
  1635. data,length<rbuffer_len?length:rbuffer_len,chksum);
  1636. else
  1637. memcpy_fromio(data, rbufdata, rbuffer_len);
  1638. rbuffer = ntohs(readw(rbuf+BUFFER_POINTER_OFST)) ;
  1639. if (!rbuffer)
  1640. break;
  1641. rbuffer -= 2;
  1642. length -= rbuffer_len;
  1643. data += rbuffer_len;
  1644. rbuf = map_address(ti, rbuffer, &rbuffer_page);
  1645. SET_PAGE(rbuffer_page);
  1646. rbuffer_len = ntohs(readw(rbuf + BUFFER_LENGTH_OFST));
  1647. rbufdata = rbuf + offsetof(struct rec_buf, data);
  1648. }
  1649. SET_PAGE(ti->asb_page);
  1650. writeb(0, ti->asb + offsetof(struct asb_rec, ret_code));
  1651. writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  1652. dev->stats.rx_bytes += skb->len;
  1653. dev->stats.rx_packets++;
  1654. skb->protocol = tr_type_trans(skb, dev);
  1655. if (IPv4_p) {
  1656. skb->csum = chksum;
  1657. skb->ip_summed = CHECKSUM_COMPLETE;
  1658. }
  1659. netif_rx(skb);
  1660. } /*tr_rx */
  1661. /*****************************************************************************/
  1662. static void ibmtr_reset_timer(struct timer_list *tmr, struct net_device *dev)
  1663. {
  1664. tmr->expires = jiffies + TR_RETRY_INTERVAL;
  1665. tmr->data = (unsigned long) dev;
  1666. tmr->function = tok_rerun;
  1667. init_timer(tmr);
  1668. add_timer(tmr);
  1669. }
  1670. /*****************************************************************************/
  1671. static void tok_rerun(unsigned long dev_addr)
  1672. {
  1673. struct net_device *dev = (struct net_device *)dev_addr;
  1674. struct tok_info *ti = netdev_priv(dev);
  1675. if ( ti->open_action == RESTART){
  1676. ti->do_tok_int = FIRST_INT;
  1677. outb(0, dev->base_addr + ADAPTRESETREL);
  1678. #ifdef ENABLE_PAGING
  1679. if (ti->page_mask)
  1680. writeb(SRPR_ENABLE_PAGING,
  1681. ti->mmio + ACA_OFFSET + ACA_RW + SRPR_EVEN);
  1682. #endif
  1683. writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
  1684. } else
  1685. tok_open_adapter(dev_addr);
  1686. }
  1687. /*****************************************************************************/
  1688. static void ibmtr_readlog(struct net_device *dev)
  1689. {
  1690. struct tok_info *ti;
  1691. ti = netdev_priv(dev);
  1692. ti->readlog_pending = 0;
  1693. SET_PAGE(ti->srb_page);
  1694. writeb(DIR_READ_LOG, ti->srb);
  1695. writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
  1696. writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  1697. netif_stop_queue(dev);
  1698. }
  1699. /*****************************************************************************/
  1700. static int ibmtr_change_mtu(struct net_device *dev, int mtu)
  1701. {
  1702. struct tok_info *ti = netdev_priv(dev);
  1703. if (ti->ring_speed == 16 && mtu > ti->maxmtu16)
  1704. return -EINVAL;
  1705. if (ti->ring_speed == 4 && mtu > ti->maxmtu4)
  1706. return -EINVAL;
  1707. dev->mtu = mtu;
  1708. return 0;
  1709. }
  1710. /*****************************************************************************/
  1711. #ifdef MODULE
  1712. /* 3COM 3C619C supports 8 interrupts, 32 I/O ports */
  1713. static struct net_device *dev_ibmtr[IBMTR_MAX_ADAPTERS];
  1714. static int io[IBMTR_MAX_ADAPTERS] = { 0xa20, 0xa24 };
  1715. static int irq[IBMTR_MAX_ADAPTERS];
  1716. static int mem[IBMTR_MAX_ADAPTERS];
  1717. MODULE_LICENSE("GPL");
  1718. module_param_array(io, int, NULL, 0);
  1719. module_param_array(irq, int, NULL, 0);
  1720. module_param_array(mem, int, NULL, 0);
  1721. static int __init ibmtr_init(void)
  1722. {
  1723. int i;
  1724. int count=0;
  1725. find_turbo_adapters(io);
  1726. for (i = 0; i < IBMTR_MAX_ADAPTERS && io[i]; i++) {
  1727. struct net_device *dev;
  1728. irq[i] = 0;
  1729. mem[i] = 0;
  1730. dev = alloc_trdev(sizeof(struct tok_info));
  1731. if (dev == NULL) {
  1732. if (i == 0)
  1733. return -ENOMEM;
  1734. break;
  1735. }
  1736. dev->base_addr = io[i];
  1737. dev->irq = irq[i];
  1738. dev->mem_start = mem[i];
  1739. if (ibmtr_probe_card(dev)) {
  1740. free_netdev(dev);
  1741. continue;
  1742. }
  1743. dev_ibmtr[i] = dev;
  1744. count++;
  1745. }
  1746. if (count) return 0;
  1747. printk("ibmtr: register_netdev() returned non-zero.\n");
  1748. return -EIO;
  1749. }
  1750. module_init(ibmtr_init);
  1751. static void __exit ibmtr_cleanup(void)
  1752. {
  1753. int i;
  1754. for (i = 0; i < IBMTR_MAX_ADAPTERS; i++){
  1755. if (!dev_ibmtr[i])
  1756. continue;
  1757. unregister_netdev(dev_ibmtr[i]);
  1758. ibmtr_cleanup_card(dev_ibmtr[i]);
  1759. free_netdev(dev_ibmtr[i]);
  1760. }
  1761. }
  1762. module_exit(ibmtr_cleanup);
  1763. #endif