ibmtr.c 61 KB

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