olympic.c 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750
  1. /*
  2. * olympic.c (c) 1999 Peter De Schrijver All Rights Reserved
  3. * 1999/2000 Mike Phillips (mikep@linuxtr.net)
  4. *
  5. * Linux driver for IBM PCI tokenring cards based on the Pit/Pit-Phy/Olympic
  6. * chipset.
  7. *
  8. * Base Driver Skeleton:
  9. * Written 1993-94 by Donald Becker.
  10. *
  11. * Copyright 1993 United States Government as represented by the
  12. * Director, National Security Agency.
  13. *
  14. * Thanks to Erik De Cock, Adrian Bridgett and Frank Fiene for their
  15. * assistance and perserverance with the testing of this driver.
  16. *
  17. * This software may be used and distributed according to the terms
  18. * of the GNU General Public License, incorporated herein by reference.
  19. *
  20. * 4/27/99 - Alpha Release 0.1.0
  21. * First release to the public
  22. *
  23. * 6/8/99 - Official Release 0.2.0
  24. * Merged into the kernel code
  25. * 8/18/99 - Updated driver for 2.3.13 kernel to use new pci
  26. * resource. Driver also reports the card name returned by
  27. * the pci resource.
  28. * 1/11/00 - Added spinlocks for smp
  29. * 2/23/00 - Updated to dev_kfree_irq
  30. * 3/10/00 - Fixed FDX enable which triggered other bugs also
  31. * squashed.
  32. * 5/20/00 - Changes to handle Olympic on LinuxPPC. Endian changes.
  33. * The odd thing about the changes is that the fix for
  34. * endian issues with the big-endian data in the arb, asb...
  35. * was to always swab() the bytes, no matter what CPU.
  36. * That's because the read[wl]() functions always swap the
  37. * bytes on the way in on PPC.
  38. * Fixing the hardware descriptors was another matter,
  39. * because they weren't going through read[wl](), there all
  40. * the results had to be in memory in le32 values. kdaaker
  41. *
  42. * 12/23/00 - Added minimal Cardbus support (Thanks Donald).
  43. *
  44. * 03/09/01 - Add new pci api, dev_base_lock, general clean up.
  45. *
  46. * 03/27/01 - Add new dma pci (Thanks to Kyle Lucke) and alloc_trdev
  47. * Change proc_fs behaviour, now one entry per adapter.
  48. *
  49. * 04/09/01 - Couple of bug fixes to the dma unmaps and ejecting the
  50. * adapter when live does not take the system down with it.
  51. *
  52. * 06/02/01 - Clean up, copy skb for small packets
  53. *
  54. * 06/22/01 - Add EISR error handling routines
  55. *
  56. * 07/19/01 - Improve bad LAA reporting, strip out freemem
  57. * into a separate function, its called from 3
  58. * different places now.
  59. * 02/09/02 - Replaced sleep_on.
  60. * 03/01/02 - Replace access to several registers from 32 bit to
  61. * 16 bit. Fixes alignment errors on PPC 64 bit machines.
  62. * Thanks to Al Trautman for this one.
  63. * 03/10/02 - Fix BUG in arb_cmd. Bug was there all along but was
  64. * silently ignored until the error checking code
  65. * went into version 1.0.0
  66. * 06/04/02 - Add correct start up sequence for the cardbus adapters.
  67. * Required for strict compliance with pci power mgmt specs.
  68. * To Do:
  69. *
  70. * Wake on lan
  71. *
  72. * If Problems do Occur
  73. * Most problems can be rectified by either closing and opening the interface
  74. * (ifconfig down and up) or rmmod and insmod'ing the driver (a bit difficult
  75. * if compiled into the kernel).
  76. */
  77. /* Change OLYMPIC_DEBUG to 1 to get verbose, and I mean really verbose, messages */
  78. #define OLYMPIC_DEBUG 0
  79. #include <linux/module.h>
  80. #include <linux/kernel.h>
  81. #include <linux/errno.h>
  82. #include <linux/timer.h>
  83. #include <linux/in.h>
  84. #include <linux/ioport.h>
  85. #include <linux/seq_file.h>
  86. #include <linux/string.h>
  87. #include <linux/proc_fs.h>
  88. #include <linux/ptrace.h>
  89. #include <linux/skbuff.h>
  90. #include <linux/interrupt.h>
  91. #include <linux/delay.h>
  92. #include <linux/netdevice.h>
  93. #include <linux/trdevice.h>
  94. #include <linux/stddef.h>
  95. #include <linux/init.h>
  96. #include <linux/pci.h>
  97. #include <linux/spinlock.h>
  98. #include <linux/bitops.h>
  99. #include <linux/jiffies.h>
  100. #include <net/checksum.h>
  101. #include <net/net_namespace.h>
  102. #include <asm/io.h>
  103. #include "olympic.h"
  104. /* I've got to put some intelligence into the version number so that Peter and I know
  105. * which version of the code somebody has got.
  106. * Version Number = a.b.c.d where a.b.c is the level of code and d is the latest author.
  107. * So 0.0.1.pds = Peter, 0.0.1.mlp = Mike
  108. *
  109. * Official releases will only have an a.b.c version number format.
  110. */
  111. static char version[] =
  112. "Olympic.c v1.0.5 6/04/02 - Peter De Schrijver & Mike Phillips" ;
  113. static char *open_maj_error[] = {"No error", "Lobe Media Test", "Physical Insertion",
  114. "Address Verification", "Neighbor Notification (Ring Poll)",
  115. "Request Parameters","FDX Registration Request",
  116. "FDX Duplicate Address Check", "Station registration Query Wait",
  117. "Unknown stage"};
  118. static char *open_min_error[] = {"No error", "Function Failure", "Signal Lost", "Wire Fault",
  119. "Ring Speed Mismatch", "Timeout","Ring Failure","Ring Beaconing",
  120. "Duplicate Node Address","Request Parameters","Remove Received",
  121. "Reserved", "Reserved", "No Monitor Detected for RPL",
  122. "Monitor Contention failer for RPL", "FDX Protocol Error"};
  123. /* Module parameters */
  124. MODULE_AUTHOR("Mike Phillips <mikep@linuxtr.net>") ;
  125. MODULE_DESCRIPTION("Olympic PCI/Cardbus Chipset Driver") ;
  126. /* Ring Speed 0,4,16,100
  127. * 0 = Autosense
  128. * 4,16 = Selected speed only, no autosense
  129. * This allows the card to be the first on the ring
  130. * and become the active monitor.
  131. * 100 = Nothing at present, 100mbps is autodetected
  132. * if FDX is turned on. May be implemented in the future to
  133. * fail if 100mpbs is not detected.
  134. *
  135. * WARNING: Some hubs will allow you to insert
  136. * at the wrong speed
  137. */
  138. static int ringspeed[OLYMPIC_MAX_ADAPTERS] = {0,} ;
  139. module_param_array(ringspeed, int, NULL, 0);
  140. /* Packet buffer size */
  141. static int pkt_buf_sz[OLYMPIC_MAX_ADAPTERS] = {0,} ;
  142. module_param_array(pkt_buf_sz, int, NULL, 0) ;
  143. /* Message Level */
  144. static int message_level[OLYMPIC_MAX_ADAPTERS] = {0,} ;
  145. module_param_array(message_level, int, NULL, 0) ;
  146. /* Change network_monitor to receive mac frames through the arb channel.
  147. * Will also create a /proc/net/olympic_tr%d entry, where %d is the tr
  148. * device, i.e. tr0, tr1 etc.
  149. * Intended to be used to create a ring-error reporting network module
  150. * i.e. it will give you the source address of beaconers on the ring
  151. */
  152. static int network_monitor[OLYMPIC_MAX_ADAPTERS] = {0,};
  153. module_param_array(network_monitor, int, NULL, 0);
  154. static DEFINE_PCI_DEVICE_TABLE(olympic_pci_tbl) = {
  155. {PCI_VENDOR_ID_IBM,PCI_DEVICE_ID_IBM_TR_WAKE,PCI_ANY_ID,PCI_ANY_ID,},
  156. { } /* Terminating Entry */
  157. };
  158. MODULE_DEVICE_TABLE(pci,olympic_pci_tbl) ;
  159. static int olympic_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
  160. static int olympic_init(struct net_device *dev);
  161. static int olympic_open(struct net_device *dev);
  162. static netdev_tx_t olympic_xmit(struct sk_buff *skb,
  163. struct net_device *dev);
  164. static int olympic_close(struct net_device *dev);
  165. static void olympic_set_rx_mode(struct net_device *dev);
  166. static void olympic_freemem(struct net_device *dev) ;
  167. static irqreturn_t olympic_interrupt(int irq, void *dev_id);
  168. static int olympic_set_mac_address(struct net_device *dev, void *addr) ;
  169. static void olympic_arb_cmd(struct net_device *dev);
  170. static int olympic_change_mtu(struct net_device *dev, int mtu);
  171. static void olympic_srb_bh(struct net_device *dev) ;
  172. static void olympic_asb_bh(struct net_device *dev) ;
  173. static const struct file_operations olympic_proc_ops;
  174. static const struct net_device_ops olympic_netdev_ops = {
  175. .ndo_open = olympic_open,
  176. .ndo_stop = olympic_close,
  177. .ndo_start_xmit = olympic_xmit,
  178. .ndo_change_mtu = olympic_change_mtu,
  179. .ndo_set_rx_mode = olympic_set_rx_mode,
  180. .ndo_set_mac_address = olympic_set_mac_address,
  181. };
  182. static int __devinit olympic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  183. {
  184. struct net_device *dev ;
  185. struct olympic_private *olympic_priv;
  186. static int card_no = -1 ;
  187. int i ;
  188. card_no++ ;
  189. if ((i = pci_enable_device(pdev))) {
  190. return i ;
  191. }
  192. pci_set_master(pdev);
  193. if ((i = pci_request_regions(pdev,"olympic"))) {
  194. goto op_disable_dev;
  195. }
  196. dev = alloc_trdev(sizeof(struct olympic_private)) ;
  197. if (!dev) {
  198. i = -ENOMEM;
  199. goto op_release_dev;
  200. }
  201. olympic_priv = netdev_priv(dev) ;
  202. spin_lock_init(&olympic_priv->olympic_lock) ;
  203. init_waitqueue_head(&olympic_priv->srb_wait);
  204. init_waitqueue_head(&olympic_priv->trb_wait);
  205. #if OLYMPIC_DEBUG
  206. printk(KERN_INFO "pci_device: %p, dev:%p, dev->priv: %p\n", pdev, dev, netdev_priv(dev));
  207. #endif
  208. dev->irq=pdev->irq;
  209. dev->base_addr=pci_resource_start(pdev, 0);
  210. olympic_priv->olympic_card_name = pci_name(pdev);
  211. olympic_priv->pdev = pdev;
  212. olympic_priv->olympic_mmio = ioremap(pci_resource_start(pdev,1),256);
  213. olympic_priv->olympic_lap = ioremap(pci_resource_start(pdev,2),2048);
  214. if (!olympic_priv->olympic_mmio || !olympic_priv->olympic_lap) {
  215. goto op_free_iomap;
  216. }
  217. if ((pkt_buf_sz[card_no] < 100) || (pkt_buf_sz[card_no] > 18000) )
  218. olympic_priv->pkt_buf_sz = PKT_BUF_SZ ;
  219. else
  220. olympic_priv->pkt_buf_sz = pkt_buf_sz[card_no] ;
  221. dev->mtu = olympic_priv->pkt_buf_sz - TR_HLEN ;
  222. olympic_priv->olympic_ring_speed = ringspeed[card_no] ;
  223. olympic_priv->olympic_message_level = message_level[card_no] ;
  224. olympic_priv->olympic_network_monitor = network_monitor[card_no];
  225. if ((i = olympic_init(dev))) {
  226. goto op_free_iomap;
  227. }
  228. dev->netdev_ops = &olympic_netdev_ops;
  229. SET_NETDEV_DEV(dev, &pdev->dev);
  230. pci_set_drvdata(pdev,dev) ;
  231. register_netdev(dev) ;
  232. printk("Olympic: %s registered as: %s\n",olympic_priv->olympic_card_name,dev->name);
  233. if (olympic_priv->olympic_network_monitor) { /* Must go after register_netdev as we need the device name */
  234. char proc_name[20] ;
  235. strcpy(proc_name,"olympic_") ;
  236. strcat(proc_name,dev->name) ;
  237. proc_create_data(proc_name, 0, init_net.proc_net, &olympic_proc_ops, dev);
  238. printk("Olympic: Network Monitor information: /proc/%s\n",proc_name);
  239. }
  240. return 0 ;
  241. op_free_iomap:
  242. if (olympic_priv->olympic_mmio)
  243. iounmap(olympic_priv->olympic_mmio);
  244. if (olympic_priv->olympic_lap)
  245. iounmap(olympic_priv->olympic_lap);
  246. free_netdev(dev);
  247. op_release_dev:
  248. pci_release_regions(pdev);
  249. op_disable_dev:
  250. pci_disable_device(pdev);
  251. return i;
  252. }
  253. static int olympic_init(struct net_device *dev)
  254. {
  255. struct olympic_private *olympic_priv;
  256. u8 __iomem *olympic_mmio, *init_srb,*adapter_addr;
  257. unsigned long t;
  258. unsigned int uaa_addr;
  259. olympic_priv=netdev_priv(dev);
  260. olympic_mmio=olympic_priv->olympic_mmio;
  261. printk("%s\n", version);
  262. printk("%s. I/O at %hx, MMIO at %p, LAP at %p, using irq %d\n", olympic_priv->olympic_card_name, (unsigned int) dev->base_addr,olympic_priv->olympic_mmio, olympic_priv->olympic_lap, dev->irq);
  263. writel(readl(olympic_mmio+BCTL) | BCTL_SOFTRESET,olympic_mmio+BCTL);
  264. t=jiffies;
  265. while((readl(olympic_mmio+BCTL)) & BCTL_SOFTRESET) {
  266. schedule();
  267. if(time_after(jiffies, t + 40*HZ)) {
  268. printk(KERN_ERR "IBM PCI tokenring card not responding.\n");
  269. return -ENODEV;
  270. }
  271. }
  272. /* Needed for cardbus */
  273. if(!(readl(olympic_mmio+BCTL) & BCTL_MODE_INDICATOR)) {
  274. writel(readl(olympic_priv->olympic_mmio+FERMASK)|FERMASK_INT_BIT, olympic_mmio+FERMASK);
  275. }
  276. #if OLYMPIC_DEBUG
  277. printk("BCTL: %x\n",readl(olympic_mmio+BCTL));
  278. printk("GPR: %x\n",readw(olympic_mmio+GPR));
  279. printk("SISRMASK: %x\n",readl(olympic_mmio+SISR_MASK));
  280. #endif
  281. /* Aaaahhh, You have got to be real careful setting GPR, the card
  282. holds the previous values from flash memory, including autosense
  283. and ring speed */
  284. writel(readl(olympic_mmio+BCTL)|BCTL_MIMREB,olympic_mmio+BCTL);
  285. if (olympic_priv->olympic_ring_speed == 0) { /* Autosense */
  286. writew(readw(olympic_mmio+GPR)|GPR_AUTOSENSE,olympic_mmio+GPR);
  287. if (olympic_priv->olympic_message_level)
  288. printk(KERN_INFO "%s: Ringspeed autosense mode on\n",olympic_priv->olympic_card_name);
  289. } else if (olympic_priv->olympic_ring_speed == 16) {
  290. if (olympic_priv->olympic_message_level)
  291. printk(KERN_INFO "%s: Trying to open at 16 Mbps as requested\n", olympic_priv->olympic_card_name);
  292. writew(GPR_16MBPS, olympic_mmio+GPR);
  293. } else if (olympic_priv->olympic_ring_speed == 4) {
  294. if (olympic_priv->olympic_message_level)
  295. printk(KERN_INFO "%s: Trying to open at 4 Mbps as requested\n", olympic_priv->olympic_card_name) ;
  296. writew(0, olympic_mmio+GPR);
  297. }
  298. writew(readw(olympic_mmio+GPR)|GPR_NEPTUNE_BF,olympic_mmio+GPR);
  299. #if OLYMPIC_DEBUG
  300. printk("GPR = %x\n",readw(olympic_mmio + GPR) ) ;
  301. #endif
  302. /* Solo has been paused to meet the Cardbus power
  303. * specs if the adapter is cardbus. Check to
  304. * see its been paused and then restart solo. The
  305. * adapter should set the pause bit within 1 second.
  306. */
  307. if(!(readl(olympic_mmio+BCTL) & BCTL_MODE_INDICATOR)) {
  308. t=jiffies;
  309. while (!(readl(olympic_mmio+CLKCTL) & CLKCTL_PAUSE)) {
  310. schedule() ;
  311. if(time_after(jiffies, t + 2*HZ)) {
  312. printk(KERN_ERR "IBM Cardbus tokenring adapter not responsing.\n") ;
  313. return -ENODEV;
  314. }
  315. }
  316. writel(readl(olympic_mmio+CLKCTL) & ~CLKCTL_PAUSE, olympic_mmio+CLKCTL) ;
  317. }
  318. /* start solo init */
  319. writel((1<<15),olympic_mmio+SISR_MASK_SUM);
  320. t=jiffies;
  321. while(!((readl(olympic_mmio+SISR_RR)) & SISR_SRB_REPLY)) {
  322. schedule();
  323. if(time_after(jiffies, t + 15*HZ)) {
  324. printk(KERN_ERR "IBM PCI tokenring card not responding.\n");
  325. return -ENODEV;
  326. }
  327. }
  328. writel(readw(olympic_mmio+LAPWWO),olympic_mmio+LAPA);
  329. #if OLYMPIC_DEBUG
  330. printk("LAPWWO: %x, LAPA: %x\n",readl(olympic_mmio+LAPWWO), readl(olympic_mmio+LAPA));
  331. #endif
  332. init_srb=olympic_priv->olympic_lap + ((readw(olympic_mmio+LAPWWO)) & (~0xf800));
  333. #if OLYMPIC_DEBUG
  334. {
  335. int i;
  336. printk("init_srb(%p): ",init_srb);
  337. for(i=0;i<20;i++)
  338. printk("%x ",readb(init_srb+i));
  339. printk("\n");
  340. }
  341. #endif
  342. if(readw(init_srb+6)) {
  343. printk(KERN_INFO "tokenring card initialization failed. errorcode : %x\n",readw(init_srb+6));
  344. return -ENODEV;
  345. }
  346. if (olympic_priv->olympic_message_level) {
  347. if ( readb(init_srb +2) & 0x40) {
  348. printk(KERN_INFO "Olympic: Adapter is FDX capable.\n") ;
  349. } else {
  350. printk(KERN_INFO "Olympic: Adapter cannot do FDX.\n");
  351. }
  352. }
  353. uaa_addr=swab16(readw(init_srb+8));
  354. #if OLYMPIC_DEBUG
  355. printk("UAA resides at %x\n",uaa_addr);
  356. #endif
  357. writel(uaa_addr,olympic_mmio+LAPA);
  358. adapter_addr=olympic_priv->olympic_lap + (uaa_addr & (~0xf800));
  359. memcpy_fromio(&dev->dev_addr[0], adapter_addr,6);
  360. #if OLYMPIC_DEBUG
  361. printk("adapter address: %pM\n", dev->dev_addr);
  362. #endif
  363. olympic_priv->olympic_addr_table_addr = swab16(readw(init_srb + 12));
  364. olympic_priv->olympic_parms_addr = swab16(readw(init_srb + 14));
  365. return 0;
  366. }
  367. static int olympic_open(struct net_device *dev)
  368. {
  369. struct olympic_private *olympic_priv=netdev_priv(dev);
  370. u8 __iomem *olympic_mmio=olympic_priv->olympic_mmio,*init_srb;
  371. unsigned long flags, t;
  372. int i, open_finished = 1 ;
  373. u8 resp, err;
  374. DECLARE_WAITQUEUE(wait,current) ;
  375. olympic_init(dev);
  376. if (request_irq(dev->irq, olympic_interrupt, IRQF_SHARED , "olympic",
  377. dev))
  378. return -EAGAIN;
  379. #if OLYMPIC_DEBUG
  380. printk("BMCTL: %x\n",readl(olympic_mmio+BMCTL_SUM));
  381. printk("pending ints: %x\n",readl(olympic_mmio+SISR_RR));
  382. #endif
  383. writel(SISR_MI,olympic_mmio+SISR_MASK_SUM);
  384. writel(SISR_MI | SISR_SRB_REPLY, olympic_mmio+SISR_MASK); /* more ints later, doesn't stop arb cmd interrupt */
  385. writel(LISR_LIE,olympic_mmio+LISR); /* more ints later */
  386. /* adapter is closed, so SRB is pointed to by LAPWWO */
  387. writel(readw(olympic_mmio+LAPWWO),olympic_mmio+LAPA);
  388. init_srb=olympic_priv->olympic_lap + ((readw(olympic_mmio+LAPWWO)) & (~0xf800));
  389. #if OLYMPIC_DEBUG
  390. printk("LAPWWO: %x, LAPA: %x\n",readw(olympic_mmio+LAPWWO), readl(olympic_mmio+LAPA));
  391. printk("SISR Mask = %04x\n", readl(olympic_mmio+SISR_MASK));
  392. printk("Before the open command\n");
  393. #endif
  394. do {
  395. memset_io(init_srb,0,SRB_COMMAND_SIZE);
  396. writeb(SRB_OPEN_ADAPTER,init_srb) ; /* open */
  397. writeb(OLYMPIC_CLEAR_RET_CODE,init_srb+2);
  398. /* If Network Monitor, instruct card to copy MAC frames through the ARB */
  399. if (olympic_priv->olympic_network_monitor)
  400. writew(swab16(OPEN_ADAPTER_ENABLE_FDX | OPEN_ADAPTER_PASS_ADC_MAC | OPEN_ADAPTER_PASS_ATT_MAC | OPEN_ADAPTER_PASS_BEACON), init_srb+8);
  401. else
  402. writew(swab16(OPEN_ADAPTER_ENABLE_FDX), init_srb+8);
  403. /* Test OR of first 3 bytes as its totally possible for
  404. * someone to set the first 2 bytes to be zero, although this
  405. * is an error, the first byte must have bit 6 set to 1 */
  406. if (olympic_priv->olympic_laa[0] | olympic_priv->olympic_laa[1] | olympic_priv->olympic_laa[2]) {
  407. writeb(olympic_priv->olympic_laa[0],init_srb+12);
  408. writeb(olympic_priv->olympic_laa[1],init_srb+13);
  409. writeb(olympic_priv->olympic_laa[2],init_srb+14);
  410. writeb(olympic_priv->olympic_laa[3],init_srb+15);
  411. writeb(olympic_priv->olympic_laa[4],init_srb+16);
  412. writeb(olympic_priv->olympic_laa[5],init_srb+17);
  413. memcpy(dev->dev_addr,olympic_priv->olympic_laa,dev->addr_len) ;
  414. }
  415. writeb(1,init_srb+30);
  416. spin_lock_irqsave(&olympic_priv->olympic_lock,flags);
  417. olympic_priv->srb_queued=1;
  418. writel(LISR_SRB_CMD,olympic_mmio+LISR_SUM);
  419. spin_unlock_irqrestore(&olympic_priv->olympic_lock,flags);
  420. t = jiffies ;
  421. add_wait_queue(&olympic_priv->srb_wait,&wait) ;
  422. set_current_state(TASK_INTERRUPTIBLE) ;
  423. while(olympic_priv->srb_queued) {
  424. schedule() ;
  425. if(signal_pending(current)) {
  426. printk(KERN_WARNING "%s: Signal received in open.\n",
  427. dev->name);
  428. printk(KERN_WARNING "SISR=%x LISR=%x\n",
  429. readl(olympic_mmio+SISR),
  430. readl(olympic_mmio+LISR));
  431. olympic_priv->srb_queued=0;
  432. break;
  433. }
  434. if (time_after(jiffies, t + 10*HZ)) {
  435. printk(KERN_WARNING "%s: SRB timed out.\n",dev->name);
  436. olympic_priv->srb_queued=0;
  437. break ;
  438. }
  439. set_current_state(TASK_INTERRUPTIBLE) ;
  440. }
  441. remove_wait_queue(&olympic_priv->srb_wait,&wait) ;
  442. set_current_state(TASK_RUNNING) ;
  443. olympic_priv->srb_queued = 0 ;
  444. #if OLYMPIC_DEBUG
  445. printk("init_srb(%p): ",init_srb);
  446. for(i=0;i<20;i++)
  447. printk("%02x ",readb(init_srb+i));
  448. printk("\n");
  449. #endif
  450. /* If we get the same return response as we set, the interrupt wasn't raised and the open
  451. * timed out.
  452. */
  453. switch (resp = readb(init_srb+2)) {
  454. case OLYMPIC_CLEAR_RET_CODE:
  455. printk(KERN_WARNING "%s: Adapter Open time out or error.\n", dev->name) ;
  456. goto out;
  457. case 0:
  458. open_finished = 1;
  459. break;
  460. case 0x07:
  461. if (!olympic_priv->olympic_ring_speed && open_finished) { /* Autosense , first time around */
  462. printk(KERN_WARNING "%s: Retrying at different ring speed\n", dev->name);
  463. open_finished = 0 ;
  464. continue;
  465. }
  466. err = readb(init_srb+7);
  467. if (!olympic_priv->olympic_ring_speed && ((err & 0x0f) == 0x0d)) {
  468. printk(KERN_WARNING "%s: Tried to autosense ring speed with no monitors present\n",dev->name);
  469. printk(KERN_WARNING "%s: Please try again with a specified ring speed\n",dev->name);
  470. } else {
  471. printk(KERN_WARNING "%s: %s - %s\n", dev->name,
  472. open_maj_error[(err & 0xf0) >> 4],
  473. open_min_error[(err & 0x0f)]);
  474. }
  475. goto out;
  476. case 0x32:
  477. printk(KERN_WARNING "%s: Invalid LAA: %pM\n",
  478. dev->name, olympic_priv->olympic_laa);
  479. goto out;
  480. default:
  481. printk(KERN_WARNING "%s: Bad OPEN response: %x\n", dev->name, resp);
  482. goto out;
  483. }
  484. } while (!(open_finished)) ; /* Will only loop if ring speed mismatch re-open attempted && autosense is on */
  485. if (readb(init_srb+18) & (1<<3))
  486. if (olympic_priv->olympic_message_level)
  487. printk(KERN_INFO "%s: Opened in FDX Mode\n",dev->name);
  488. if (readb(init_srb+18) & (1<<1))
  489. olympic_priv->olympic_ring_speed = 100 ;
  490. else if (readb(init_srb+18) & 1)
  491. olympic_priv->olympic_ring_speed = 16 ;
  492. else
  493. olympic_priv->olympic_ring_speed = 4 ;
  494. if (olympic_priv->olympic_message_level)
  495. printk(KERN_INFO "%s: Opened in %d Mbps mode\n",dev->name, olympic_priv->olympic_ring_speed);
  496. olympic_priv->asb = swab16(readw(init_srb+8));
  497. olympic_priv->srb = swab16(readw(init_srb+10));
  498. olympic_priv->arb = swab16(readw(init_srb+12));
  499. olympic_priv->trb = swab16(readw(init_srb+16));
  500. olympic_priv->olympic_receive_options = 0x01 ;
  501. olympic_priv->olympic_copy_all_options = 0 ;
  502. /* setup rx ring */
  503. writel((3<<16),olympic_mmio+BMCTL_RWM); /* Ensure end of frame generated interrupts */
  504. writel(BMCTL_RX_DIS|3,olympic_mmio+BMCTL_RWM); /* Yes, this the enables RX channel */
  505. for(i=0;i<OLYMPIC_RX_RING_SIZE;i++) {
  506. struct sk_buff *skb;
  507. skb=dev_alloc_skb(olympic_priv->pkt_buf_sz);
  508. if(skb == NULL)
  509. break;
  510. skb->dev = dev;
  511. olympic_priv->olympic_rx_ring[i].buffer = cpu_to_le32(pci_map_single(olympic_priv->pdev,
  512. skb->data,olympic_priv->pkt_buf_sz, PCI_DMA_FROMDEVICE)) ;
  513. olympic_priv->olympic_rx_ring[i].res_length = cpu_to_le32(olympic_priv->pkt_buf_sz);
  514. olympic_priv->rx_ring_skb[i]=skb;
  515. }
  516. if (i==0) {
  517. printk(KERN_WARNING "%s: Not enough memory to allocate rx buffers. Adapter disabled\n",dev->name);
  518. goto out;
  519. }
  520. olympic_priv->rx_ring_dma_addr = pci_map_single(olympic_priv->pdev,olympic_priv->olympic_rx_ring,
  521. sizeof(struct olympic_rx_desc) * OLYMPIC_RX_RING_SIZE, PCI_DMA_TODEVICE);
  522. writel(olympic_priv->rx_ring_dma_addr, olympic_mmio+RXDESCQ);
  523. writel(olympic_priv->rx_ring_dma_addr, olympic_mmio+RXCDA);
  524. writew(i, olympic_mmio+RXDESCQCNT);
  525. olympic_priv->rx_status_ring_dma_addr = pci_map_single(olympic_priv->pdev, olympic_priv->olympic_rx_status_ring,
  526. sizeof(struct olympic_rx_status) * OLYMPIC_RX_RING_SIZE, PCI_DMA_FROMDEVICE);
  527. writel(olympic_priv->rx_status_ring_dma_addr, olympic_mmio+RXSTATQ);
  528. writel(olympic_priv->rx_status_ring_dma_addr, olympic_mmio+RXCSA);
  529. olympic_priv->rx_ring_last_received = OLYMPIC_RX_RING_SIZE - 1; /* last processed rx status */
  530. olympic_priv->rx_status_last_received = OLYMPIC_RX_RING_SIZE - 1;
  531. writew(i, olympic_mmio+RXSTATQCNT);
  532. #if OLYMPIC_DEBUG
  533. printk("# of rx buffers: %d, RXENQ: %x\n",i, readw(olympic_mmio+RXENQ));
  534. printk("RXCSA: %x, rx_status_ring[0]: %p\n",readl(olympic_mmio+RXCSA),&olympic_priv->olympic_rx_status_ring[0]);
  535. printk(" stat_ring[1]: %p, stat_ring[2]: %p, stat_ring[3]: %p\n", &(olympic_priv->olympic_rx_status_ring[1]), &(olympic_priv->olympic_rx_status_ring[2]), &(olympic_priv->olympic_rx_status_ring[3]) );
  536. printk(" stat_ring[4]: %p, stat_ring[5]: %p, stat_ring[6]: %p\n", &(olympic_priv->olympic_rx_status_ring[4]), &(olympic_priv->olympic_rx_status_ring[5]), &(olympic_priv->olympic_rx_status_ring[6]) );
  537. printk(" stat_ring[7]: %p\n", &(olympic_priv->olympic_rx_status_ring[7]) );
  538. printk("RXCDA: %x, rx_ring[0]: %p\n",readl(olympic_mmio+RXCDA),&olympic_priv->olympic_rx_ring[0]);
  539. printk("Rx_ring_dma_addr = %08x, rx_status_dma_addr = %08x\n",
  540. olympic_priv->rx_ring_dma_addr,olympic_priv->rx_status_ring_dma_addr) ;
  541. #endif
  542. writew((((readw(olympic_mmio+RXENQ)) & 0x8000) ^ 0x8000) | i,olympic_mmio+RXENQ);
  543. #if OLYMPIC_DEBUG
  544. printk("# of rx buffers: %d, RXENQ: %x\n",i, readw(olympic_mmio+RXENQ));
  545. printk("RXCSA: %x, rx_ring[0]: %p\n",readl(olympic_mmio+RXCSA),&olympic_priv->olympic_rx_status_ring[0]);
  546. printk("RXCDA: %x, rx_ring[0]: %p\n",readl(olympic_mmio+RXCDA),&olympic_priv->olympic_rx_ring[0]);
  547. #endif
  548. writel(SISR_RX_STATUS | SISR_RX_NOBUF,olympic_mmio+SISR_MASK_SUM);
  549. /* setup tx ring */
  550. writel(BMCTL_TX1_DIS,olympic_mmio+BMCTL_RWM); /* Yes, this enables TX channel 1 */
  551. for(i=0;i<OLYMPIC_TX_RING_SIZE;i++)
  552. olympic_priv->olympic_tx_ring[i].buffer=cpu_to_le32(0xdeadbeef);
  553. olympic_priv->free_tx_ring_entries=OLYMPIC_TX_RING_SIZE;
  554. olympic_priv->tx_ring_dma_addr = pci_map_single(olympic_priv->pdev,olympic_priv->olympic_tx_ring,
  555. sizeof(struct olympic_tx_desc) * OLYMPIC_TX_RING_SIZE,PCI_DMA_TODEVICE) ;
  556. writel(olympic_priv->tx_ring_dma_addr, olympic_mmio+TXDESCQ_1);
  557. writel(olympic_priv->tx_ring_dma_addr, olympic_mmio+TXCDA_1);
  558. writew(OLYMPIC_TX_RING_SIZE, olympic_mmio+TXDESCQCNT_1);
  559. olympic_priv->tx_status_ring_dma_addr = pci_map_single(olympic_priv->pdev, olympic_priv->olympic_tx_status_ring,
  560. sizeof(struct olympic_tx_status) * OLYMPIC_TX_RING_SIZE, PCI_DMA_FROMDEVICE);
  561. writel(olympic_priv->tx_status_ring_dma_addr,olympic_mmio+TXSTATQ_1);
  562. writel(olympic_priv->tx_status_ring_dma_addr,olympic_mmio+TXCSA_1);
  563. writew(OLYMPIC_TX_RING_SIZE,olympic_mmio+TXSTATQCNT_1);
  564. olympic_priv->tx_ring_free=0; /* next entry in tx ring to use */
  565. olympic_priv->tx_ring_last_status=OLYMPIC_TX_RING_SIZE-1; /* last processed tx status */
  566. writel(0xffffffff, olympic_mmio+EISR_RWM) ; /* clean the eisr */
  567. writel(0,olympic_mmio+EISR) ;
  568. writel(EISR_MASK_OPTIONS,olympic_mmio+EISR_MASK) ; /* enables most of the TX error interrupts */
  569. writel(SISR_TX1_EOF | SISR_ADAPTER_CHECK | SISR_ARB_CMD | SISR_TRB_REPLY | SISR_ASB_FREE | SISR_ERR,olympic_mmio+SISR_MASK_SUM);
  570. #if OLYMPIC_DEBUG
  571. printk("BMCTL: %x\n",readl(olympic_mmio+BMCTL_SUM));
  572. printk("SISR MASK: %x\n",readl(olympic_mmio+SISR_MASK));
  573. #endif
  574. if (olympic_priv->olympic_network_monitor) {
  575. u8 __iomem *oat;
  576. u8 __iomem *opt;
  577. u8 addr[6];
  578. oat = (olympic_priv->olympic_lap + olympic_priv->olympic_addr_table_addr);
  579. opt = (olympic_priv->olympic_lap + olympic_priv->olympic_parms_addr);
  580. for (i = 0; i < 6; i++)
  581. addr[i] = readb(oat+offsetof(struct olympic_adapter_addr_table,node_addr)+i);
  582. printk("%s: Node Address: %pM\n", dev->name, addr);
  583. printk("%s: Functional Address: %02x:%02x:%02x:%02x\n",dev->name,
  584. readb(oat+offsetof(struct olympic_adapter_addr_table,func_addr)),
  585. readb(oat+offsetof(struct olympic_adapter_addr_table,func_addr)+1),
  586. readb(oat+offsetof(struct olympic_adapter_addr_table,func_addr)+2),
  587. readb(oat+offsetof(struct olympic_adapter_addr_table,func_addr)+3));
  588. for (i = 0; i < 6; i++)
  589. addr[i] = readb(opt+offsetof(struct olympic_parameters_table, up_node_addr)+i);
  590. printk("%s: NAUN Address: %pM\n", dev->name, addr);
  591. }
  592. netif_start_queue(dev);
  593. return 0;
  594. out:
  595. free_irq(dev->irq, dev);
  596. return -EIO;
  597. }
  598. /*
  599. * When we enter the rx routine we do not know how many frames have been
  600. * queued on the rx channel. Therefore we start at the next rx status
  601. * position and travel around the receive ring until we have completed
  602. * all the frames.
  603. *
  604. * This means that we may process the frame before we receive the end
  605. * of frame interrupt. This is why we always test the status instead
  606. * of blindly processing the next frame.
  607. *
  608. * We also remove the last 4 bytes from the packet as well, these are
  609. * just token ring trailer info and upset protocols that don't check
  610. * their own length, i.e. SNA.
  611. *
  612. */
  613. static void olympic_rx(struct net_device *dev)
  614. {
  615. struct olympic_private *olympic_priv=netdev_priv(dev);
  616. u8 __iomem *olympic_mmio=olympic_priv->olympic_mmio;
  617. struct olympic_rx_status *rx_status;
  618. struct olympic_rx_desc *rx_desc ;
  619. int rx_ring_last_received,length, buffer_cnt, cpy_length, frag_len;
  620. struct sk_buff *skb, *skb2;
  621. int i;
  622. rx_status=&(olympic_priv->olympic_rx_status_ring[(olympic_priv->rx_status_last_received + 1) & (OLYMPIC_RX_RING_SIZE - 1)]) ;
  623. while (rx_status->status_buffercnt) {
  624. u32 l_status_buffercnt;
  625. olympic_priv->rx_status_last_received++ ;
  626. olympic_priv->rx_status_last_received &= (OLYMPIC_RX_RING_SIZE -1);
  627. #if OLYMPIC_DEBUG
  628. printk("rx status: %x rx len: %x\n", le32_to_cpu(rx_status->status_buffercnt), le32_to_cpu(rx_status->fragmentcnt_framelen));
  629. #endif
  630. length = le32_to_cpu(rx_status->fragmentcnt_framelen) & 0xffff;
  631. buffer_cnt = le32_to_cpu(rx_status->status_buffercnt) & 0xffff;
  632. i = buffer_cnt ; /* Need buffer_cnt later for rxenq update */
  633. frag_len = le32_to_cpu(rx_status->fragmentcnt_framelen) >> 16;
  634. #if OLYMPIC_DEBUG
  635. printk("length: %x, frag_len: %x, buffer_cnt: %x\n", length, frag_len, buffer_cnt);
  636. #endif
  637. l_status_buffercnt = le32_to_cpu(rx_status->status_buffercnt);
  638. if(l_status_buffercnt & 0xC0000000) {
  639. if (l_status_buffercnt & 0x3B000000) {
  640. if (olympic_priv->olympic_message_level) {
  641. if (l_status_buffercnt & (1<<29)) /* Rx Frame Truncated */
  642. printk(KERN_WARNING "%s: Rx Frame Truncated\n",dev->name);
  643. if (l_status_buffercnt & (1<<28)) /*Rx receive overrun */
  644. printk(KERN_WARNING "%s: Rx Frame Receive overrun\n",dev->name);
  645. if (l_status_buffercnt & (1<<27)) /* No receive buffers */
  646. printk(KERN_WARNING "%s: No receive buffers\n",dev->name);
  647. if (l_status_buffercnt & (1<<25)) /* Receive frame error detect */
  648. printk(KERN_WARNING "%s: Receive frame error detect\n",dev->name);
  649. if (l_status_buffercnt & (1<<24)) /* Received Error Detect */
  650. printk(KERN_WARNING "%s: Received Error Detect\n",dev->name);
  651. }
  652. olympic_priv->rx_ring_last_received += i ;
  653. olympic_priv->rx_ring_last_received &= (OLYMPIC_RX_RING_SIZE -1) ;
  654. dev->stats.rx_errors++;
  655. } else {
  656. if (buffer_cnt == 1) {
  657. skb = dev_alloc_skb(max_t(int, olympic_priv->pkt_buf_sz,length)) ;
  658. } else {
  659. skb = dev_alloc_skb(length) ;
  660. }
  661. if (skb == NULL) {
  662. printk(KERN_WARNING "%s: Not enough memory to copy packet to upper layers.\n",dev->name) ;
  663. dev->stats.rx_dropped++;
  664. /* Update counters even though we don't transfer the frame */
  665. olympic_priv->rx_ring_last_received += i ;
  666. olympic_priv->rx_ring_last_received &= (OLYMPIC_RX_RING_SIZE -1) ;
  667. } else {
  668. /* Optimise based upon number of buffers used.
  669. If only one buffer is used we can simply swap the buffers around.
  670. If more than one then we must use the new buffer and copy the information
  671. first. Ideally all frames would be in a single buffer, this can be tuned by
  672. altering the buffer size. If the length of the packet is less than
  673. 1500 bytes we're going to copy it over anyway to stop packets getting
  674. dropped from sockets with buffers smaller than our pkt_buf_sz. */
  675. if (buffer_cnt==1) {
  676. olympic_priv->rx_ring_last_received++ ;
  677. olympic_priv->rx_ring_last_received &= (OLYMPIC_RX_RING_SIZE -1);
  678. rx_ring_last_received = olympic_priv->rx_ring_last_received ;
  679. if (length > 1500) {
  680. skb2=olympic_priv->rx_ring_skb[rx_ring_last_received] ;
  681. /* unmap buffer */
  682. pci_unmap_single(olympic_priv->pdev,
  683. le32_to_cpu(olympic_priv->olympic_rx_ring[rx_ring_last_received].buffer),
  684. olympic_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE) ;
  685. skb_put(skb2,length-4);
  686. skb2->protocol = tr_type_trans(skb2,dev);
  687. olympic_priv->olympic_rx_ring[rx_ring_last_received].buffer =
  688. cpu_to_le32(pci_map_single(olympic_priv->pdev, skb->data,
  689. olympic_priv->pkt_buf_sz, PCI_DMA_FROMDEVICE));
  690. olympic_priv->olympic_rx_ring[rx_ring_last_received].res_length =
  691. cpu_to_le32(olympic_priv->pkt_buf_sz);
  692. olympic_priv->rx_ring_skb[rx_ring_last_received] = skb ;
  693. netif_rx(skb2) ;
  694. } else {
  695. pci_dma_sync_single_for_cpu(olympic_priv->pdev,
  696. le32_to_cpu(olympic_priv->olympic_rx_ring[rx_ring_last_received].buffer),
  697. olympic_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE) ;
  698. skb_copy_from_linear_data(olympic_priv->rx_ring_skb[rx_ring_last_received],
  699. skb_put(skb,length - 4),
  700. length - 4);
  701. pci_dma_sync_single_for_device(olympic_priv->pdev,
  702. le32_to_cpu(olympic_priv->olympic_rx_ring[rx_ring_last_received].buffer),
  703. olympic_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE) ;
  704. skb->protocol = tr_type_trans(skb,dev) ;
  705. netif_rx(skb) ;
  706. }
  707. } else {
  708. do { /* Walk the buffers */
  709. olympic_priv->rx_ring_last_received++ ;
  710. olympic_priv->rx_ring_last_received &= (OLYMPIC_RX_RING_SIZE -1);
  711. rx_ring_last_received = olympic_priv->rx_ring_last_received ;
  712. pci_dma_sync_single_for_cpu(olympic_priv->pdev,
  713. le32_to_cpu(olympic_priv->olympic_rx_ring[rx_ring_last_received].buffer),
  714. olympic_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE) ;
  715. rx_desc = &(olympic_priv->olympic_rx_ring[rx_ring_last_received]);
  716. cpy_length = (i == 1 ? frag_len : le32_to_cpu(rx_desc->res_length));
  717. skb_copy_from_linear_data(olympic_priv->rx_ring_skb[rx_ring_last_received],
  718. skb_put(skb, cpy_length),
  719. cpy_length);
  720. pci_dma_sync_single_for_device(olympic_priv->pdev,
  721. le32_to_cpu(olympic_priv->olympic_rx_ring[rx_ring_last_received].buffer),
  722. olympic_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE) ;
  723. } while (--i) ;
  724. skb_trim(skb,skb->len-4) ;
  725. skb->protocol = tr_type_trans(skb,dev);
  726. netif_rx(skb) ;
  727. }
  728. dev->stats.rx_packets++ ;
  729. dev->stats.rx_bytes += length ;
  730. } /* if skb == null */
  731. } /* If status & 0x3b */
  732. } else { /*if buffercnt & 0xC */
  733. olympic_priv->rx_ring_last_received += i ;
  734. olympic_priv->rx_ring_last_received &= (OLYMPIC_RX_RING_SIZE - 1) ;
  735. }
  736. rx_status->fragmentcnt_framelen = 0 ;
  737. rx_status->status_buffercnt = 0 ;
  738. rx_status = &(olympic_priv->olympic_rx_status_ring[(olympic_priv->rx_status_last_received+1) & (OLYMPIC_RX_RING_SIZE -1) ]);
  739. writew((((readw(olympic_mmio+RXENQ)) & 0x8000) ^ 0x8000) | buffer_cnt , olympic_mmio+RXENQ);
  740. } /* while */
  741. }
  742. static void olympic_freemem(struct net_device *dev)
  743. {
  744. struct olympic_private *olympic_priv=netdev_priv(dev);
  745. int i;
  746. for(i=0;i<OLYMPIC_RX_RING_SIZE;i++) {
  747. if (olympic_priv->rx_ring_skb[olympic_priv->rx_status_last_received] != NULL) {
  748. dev_kfree_skb_irq(olympic_priv->rx_ring_skb[olympic_priv->rx_status_last_received]);
  749. olympic_priv->rx_ring_skb[olympic_priv->rx_status_last_received] = NULL;
  750. }
  751. if (olympic_priv->olympic_rx_ring[olympic_priv->rx_status_last_received].buffer != cpu_to_le32(0xdeadbeef)) {
  752. pci_unmap_single(olympic_priv->pdev,
  753. le32_to_cpu(olympic_priv->olympic_rx_ring[olympic_priv->rx_status_last_received].buffer),
  754. olympic_priv->pkt_buf_sz, PCI_DMA_FROMDEVICE);
  755. }
  756. olympic_priv->rx_status_last_received++;
  757. olympic_priv->rx_status_last_received&=OLYMPIC_RX_RING_SIZE-1;
  758. }
  759. /* unmap rings */
  760. pci_unmap_single(olympic_priv->pdev, olympic_priv->rx_status_ring_dma_addr,
  761. sizeof(struct olympic_rx_status) * OLYMPIC_RX_RING_SIZE, PCI_DMA_FROMDEVICE);
  762. pci_unmap_single(olympic_priv->pdev, olympic_priv->rx_ring_dma_addr,
  763. sizeof(struct olympic_rx_desc) * OLYMPIC_RX_RING_SIZE, PCI_DMA_TODEVICE);
  764. pci_unmap_single(olympic_priv->pdev, olympic_priv->tx_status_ring_dma_addr,
  765. sizeof(struct olympic_tx_status) * OLYMPIC_TX_RING_SIZE, PCI_DMA_FROMDEVICE);
  766. pci_unmap_single(olympic_priv->pdev, olympic_priv->tx_ring_dma_addr,
  767. sizeof(struct olympic_tx_desc) * OLYMPIC_TX_RING_SIZE, PCI_DMA_TODEVICE);
  768. return ;
  769. }
  770. static irqreturn_t olympic_interrupt(int irq, void *dev_id)
  771. {
  772. struct net_device *dev= (struct net_device *)dev_id;
  773. struct olympic_private *olympic_priv=netdev_priv(dev);
  774. u8 __iomem *olympic_mmio=olympic_priv->olympic_mmio;
  775. u32 sisr;
  776. u8 __iomem *adapter_check_area ;
  777. /*
  778. * Read sisr but don't reset it yet.
  779. * The indication bit may have been set but the interrupt latch
  780. * bit may not be set, so we'd lose the interrupt later.
  781. */
  782. sisr=readl(olympic_mmio+SISR) ;
  783. if (!(sisr & SISR_MI)) /* Interrupt isn't for us */
  784. return IRQ_NONE;
  785. sisr=readl(olympic_mmio+SISR_RR) ; /* Read & Reset sisr */
  786. spin_lock(&olympic_priv->olympic_lock);
  787. /* Hotswap gives us this on removal */
  788. if (sisr == 0xffffffff) {
  789. printk(KERN_WARNING "%s: Hotswap adapter removal.\n",dev->name) ;
  790. spin_unlock(&olympic_priv->olympic_lock) ;
  791. return IRQ_NONE;
  792. }
  793. if (sisr & (SISR_SRB_REPLY | SISR_TX1_EOF | SISR_RX_STATUS | SISR_ADAPTER_CHECK |
  794. SISR_ASB_FREE | SISR_ARB_CMD | SISR_TRB_REPLY | SISR_RX_NOBUF | SISR_ERR)) {
  795. /* If we ever get this the adapter is seriously dead. Only a reset is going to
  796. * bring it back to life. We're talking pci bus errors and such like :( */
  797. if((sisr & SISR_ERR) && (readl(olympic_mmio+EISR) & EISR_MASK_OPTIONS)) {
  798. printk(KERN_ERR "Olympic: EISR Error, EISR=%08x\n",readl(olympic_mmio+EISR)) ;
  799. printk(KERN_ERR "The adapter must be reset to clear this condition.\n") ;
  800. printk(KERN_ERR "Please report this error to the driver maintainer and/\n") ;
  801. printk(KERN_ERR "or the linux-tr mailing list.\n") ;
  802. wake_up_interruptible(&olympic_priv->srb_wait);
  803. spin_unlock(&olympic_priv->olympic_lock) ;
  804. return IRQ_HANDLED;
  805. } /* SISR_ERR */
  806. if(sisr & SISR_SRB_REPLY) {
  807. if(olympic_priv->srb_queued==1) {
  808. wake_up_interruptible(&olympic_priv->srb_wait);
  809. } else if (olympic_priv->srb_queued==2) {
  810. olympic_srb_bh(dev) ;
  811. }
  812. olympic_priv->srb_queued=0;
  813. } /* SISR_SRB_REPLY */
  814. /* We shouldn't ever miss the Tx interrupt, but the you never know, hence the loop to ensure
  815. we get all tx completions. */
  816. if (sisr & SISR_TX1_EOF) {
  817. while(olympic_priv->olympic_tx_status_ring[(olympic_priv->tx_ring_last_status + 1) & (OLYMPIC_TX_RING_SIZE-1)].status) {
  818. olympic_priv->tx_ring_last_status++;
  819. olympic_priv->tx_ring_last_status &= (OLYMPIC_TX_RING_SIZE-1);
  820. olympic_priv->free_tx_ring_entries++;
  821. dev->stats.tx_bytes += olympic_priv->tx_ring_skb[olympic_priv->tx_ring_last_status]->len;
  822. dev->stats.tx_packets++ ;
  823. pci_unmap_single(olympic_priv->pdev,
  824. le32_to_cpu(olympic_priv->olympic_tx_ring[olympic_priv->tx_ring_last_status].buffer),
  825. olympic_priv->tx_ring_skb[olympic_priv->tx_ring_last_status]->len,PCI_DMA_TODEVICE);
  826. dev_kfree_skb_irq(olympic_priv->tx_ring_skb[olympic_priv->tx_ring_last_status]);
  827. olympic_priv->olympic_tx_ring[olympic_priv->tx_ring_last_status].buffer=cpu_to_le32(0xdeadbeef);
  828. olympic_priv->olympic_tx_status_ring[olympic_priv->tx_ring_last_status].status=0;
  829. }
  830. netif_wake_queue(dev);
  831. } /* SISR_TX1_EOF */
  832. if (sisr & SISR_RX_STATUS) {
  833. olympic_rx(dev);
  834. } /* SISR_RX_STATUS */
  835. if (sisr & SISR_ADAPTER_CHECK) {
  836. netif_stop_queue(dev);
  837. printk(KERN_WARNING "%s: Adapter Check Interrupt Raised, 8 bytes of information follow:\n", dev->name);
  838. writel(readl(olympic_mmio+LAPWWC),olympic_mmio+LAPA);
  839. adapter_check_area = olympic_priv->olympic_lap + ((readl(olympic_mmio+LAPWWC)) & (~0xf800)) ;
  840. printk(KERN_WARNING "%s: Bytes %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",dev->name, readb(adapter_check_area+0), readb(adapter_check_area+1), readb(adapter_check_area+2), readb(adapter_check_area+3), readb(adapter_check_area+4), readb(adapter_check_area+5), readb(adapter_check_area+6), readb(adapter_check_area+7)) ;
  841. spin_unlock(&olympic_priv->olympic_lock) ;
  842. return IRQ_HANDLED;
  843. } /* SISR_ADAPTER_CHECK */
  844. if (sisr & SISR_ASB_FREE) {
  845. /* Wake up anything that is waiting for the asb response */
  846. if (olympic_priv->asb_queued) {
  847. olympic_asb_bh(dev) ;
  848. }
  849. } /* SISR_ASB_FREE */
  850. if (sisr & SISR_ARB_CMD) {
  851. olympic_arb_cmd(dev) ;
  852. } /* SISR_ARB_CMD */
  853. if (sisr & SISR_TRB_REPLY) {
  854. /* Wake up anything that is waiting for the trb response */
  855. if (olympic_priv->trb_queued) {
  856. wake_up_interruptible(&olympic_priv->trb_wait);
  857. }
  858. olympic_priv->trb_queued = 0 ;
  859. } /* SISR_TRB_REPLY */
  860. if (sisr & SISR_RX_NOBUF) {
  861. /* According to the documentation, we don't have to do anything, but trapping it keeps it out of
  862. /var/log/messages. */
  863. } /* SISR_RX_NOBUF */
  864. } else {
  865. printk(KERN_WARNING "%s: Unexpected interrupt: %x\n",dev->name, sisr);
  866. printk(KERN_WARNING "%s: SISR_MASK: %x\n",dev->name, readl(olympic_mmio+SISR_MASK)) ;
  867. } /* One if the interrupts we want */
  868. writel(SISR_MI,olympic_mmio+SISR_MASK_SUM);
  869. spin_unlock(&olympic_priv->olympic_lock) ;
  870. return IRQ_HANDLED;
  871. }
  872. static netdev_tx_t olympic_xmit(struct sk_buff *skb,
  873. struct net_device *dev)
  874. {
  875. struct olympic_private *olympic_priv=netdev_priv(dev);
  876. u8 __iomem *olympic_mmio=olympic_priv->olympic_mmio;
  877. unsigned long flags ;
  878. spin_lock_irqsave(&olympic_priv->olympic_lock, flags);
  879. netif_stop_queue(dev);
  880. if(olympic_priv->free_tx_ring_entries) {
  881. olympic_priv->olympic_tx_ring[olympic_priv->tx_ring_free].buffer =
  882. cpu_to_le32(pci_map_single(olympic_priv->pdev, skb->data, skb->len,PCI_DMA_TODEVICE));
  883. olympic_priv->olympic_tx_ring[olympic_priv->tx_ring_free].status_length = cpu_to_le32(skb->len | (0x80000000));
  884. olympic_priv->tx_ring_skb[olympic_priv->tx_ring_free]=skb;
  885. olympic_priv->free_tx_ring_entries--;
  886. olympic_priv->tx_ring_free++;
  887. olympic_priv->tx_ring_free &= (OLYMPIC_TX_RING_SIZE-1);
  888. writew((((readw(olympic_mmio+TXENQ_1)) & 0x8000) ^ 0x8000) | 1,olympic_mmio+TXENQ_1);
  889. netif_wake_queue(dev);
  890. spin_unlock_irqrestore(&olympic_priv->olympic_lock,flags);
  891. return NETDEV_TX_OK;
  892. } else {
  893. spin_unlock_irqrestore(&olympic_priv->olympic_lock,flags);
  894. return NETDEV_TX_BUSY;
  895. }
  896. }
  897. static int olympic_close(struct net_device *dev)
  898. {
  899. struct olympic_private *olympic_priv=netdev_priv(dev);
  900. u8 __iomem *olympic_mmio=olympic_priv->olympic_mmio,*srb;
  901. unsigned long t,flags;
  902. DECLARE_WAITQUEUE(wait,current) ;
  903. netif_stop_queue(dev);
  904. writel(olympic_priv->srb,olympic_mmio+LAPA);
  905. srb=olympic_priv->olympic_lap + (olympic_priv->srb & (~0xf800));
  906. writeb(SRB_CLOSE_ADAPTER,srb+0);
  907. writeb(0,srb+1);
  908. writeb(OLYMPIC_CLEAR_RET_CODE,srb+2);
  909. add_wait_queue(&olympic_priv->srb_wait,&wait) ;
  910. set_current_state(TASK_INTERRUPTIBLE) ;
  911. spin_lock_irqsave(&olympic_priv->olympic_lock,flags);
  912. olympic_priv->srb_queued=1;
  913. writel(LISR_SRB_CMD,olympic_mmio+LISR_SUM);
  914. spin_unlock_irqrestore(&olympic_priv->olympic_lock,flags);
  915. while(olympic_priv->srb_queued) {
  916. t = schedule_timeout_interruptible(60*HZ);
  917. if(signal_pending(current)) {
  918. printk(KERN_WARNING "%s: SRB timed out.\n",dev->name);
  919. printk(KERN_WARNING "SISR=%x MISR=%x\n",readl(olympic_mmio+SISR),readl(olympic_mmio+LISR));
  920. olympic_priv->srb_queued=0;
  921. break;
  922. }
  923. if (t == 0) {
  924. printk(KERN_WARNING "%s: SRB timed out. May not be fatal.\n",dev->name);
  925. }
  926. olympic_priv->srb_queued=0;
  927. }
  928. remove_wait_queue(&olympic_priv->srb_wait,&wait) ;
  929. olympic_priv->rx_status_last_received++;
  930. olympic_priv->rx_status_last_received&=OLYMPIC_RX_RING_SIZE-1;
  931. olympic_freemem(dev) ;
  932. /* reset tx/rx fifo's and busmaster logic */
  933. writel(readl(olympic_mmio+BCTL)|(3<<13),olympic_mmio+BCTL);
  934. udelay(1);
  935. writel(readl(olympic_mmio+BCTL)&~(3<<13),olympic_mmio+BCTL);
  936. #if OLYMPIC_DEBUG
  937. {
  938. int i ;
  939. printk("srb(%p): ",srb);
  940. for(i=0;i<4;i++)
  941. printk("%x ",readb(srb+i));
  942. printk("\n");
  943. }
  944. #endif
  945. free_irq(dev->irq,dev);
  946. return 0;
  947. }
  948. static void olympic_set_rx_mode(struct net_device *dev)
  949. {
  950. struct olympic_private *olympic_priv = netdev_priv(dev);
  951. u8 __iomem *olympic_mmio = olympic_priv->olympic_mmio ;
  952. u8 options = 0;
  953. u8 __iomem *srb;
  954. struct netdev_hw_addr *ha;
  955. unsigned char dev_mc_address[4] ;
  956. writel(olympic_priv->srb,olympic_mmio+LAPA);
  957. srb=olympic_priv->olympic_lap + (olympic_priv->srb & (~0xf800));
  958. options = olympic_priv->olympic_copy_all_options;
  959. if (dev->flags&IFF_PROMISC)
  960. options |= 0x61 ;
  961. else
  962. options &= ~0x61 ;
  963. /* Only issue the srb if there is a change in options */
  964. if ((options ^ olympic_priv->olympic_copy_all_options)) {
  965. /* Now to issue the srb command to alter the copy.all.options */
  966. writeb(SRB_MODIFY_RECEIVE_OPTIONS,srb);
  967. writeb(0,srb+1);
  968. writeb(OLYMPIC_CLEAR_RET_CODE,srb+2);
  969. writeb(0,srb+3);
  970. writeb(olympic_priv->olympic_receive_options,srb+4);
  971. writeb(options,srb+5);
  972. olympic_priv->srb_queued=2; /* Can't sleep, use srb_bh */
  973. writel(LISR_SRB_CMD,olympic_mmio+LISR_SUM);
  974. olympic_priv->olympic_copy_all_options = options ;
  975. return ;
  976. }
  977. /* Set the functional addresses we need for multicast */
  978. dev_mc_address[0] = dev_mc_address[1] = dev_mc_address[2] = dev_mc_address[3] = 0 ;
  979. netdev_for_each_mc_addr(ha, dev) {
  980. dev_mc_address[0] |= ha->addr[2];
  981. dev_mc_address[1] |= ha->addr[3];
  982. dev_mc_address[2] |= ha->addr[4];
  983. dev_mc_address[3] |= ha->addr[5];
  984. }
  985. writeb(SRB_SET_FUNC_ADDRESS,srb+0);
  986. writeb(0,srb+1);
  987. writeb(OLYMPIC_CLEAR_RET_CODE,srb+2);
  988. writeb(0,srb+3);
  989. writeb(0,srb+4);
  990. writeb(0,srb+5);
  991. writeb(dev_mc_address[0],srb+6);
  992. writeb(dev_mc_address[1],srb+7);
  993. writeb(dev_mc_address[2],srb+8);
  994. writeb(dev_mc_address[3],srb+9);
  995. olympic_priv->srb_queued = 2 ;
  996. writel(LISR_SRB_CMD,olympic_mmio+LISR_SUM);
  997. }
  998. static void olympic_srb_bh(struct net_device *dev)
  999. {
  1000. struct olympic_private *olympic_priv = netdev_priv(dev);
  1001. u8 __iomem *olympic_mmio = olympic_priv->olympic_mmio ;
  1002. u8 __iomem *srb;
  1003. writel(olympic_priv->srb,olympic_mmio+LAPA);
  1004. srb=olympic_priv->olympic_lap + (olympic_priv->srb & (~0xf800));
  1005. switch (readb(srb)) {
  1006. /* SRB_MODIFY_RECEIVE_OPTIONS i.e. set_multicast_list options (promiscuous)
  1007. * At some point we should do something if we get an error, such as
  1008. * resetting the IFF_PROMISC flag in dev
  1009. */
  1010. case SRB_MODIFY_RECEIVE_OPTIONS:
  1011. switch (readb(srb+2)) {
  1012. case 0x01:
  1013. printk(KERN_WARNING "%s: Unrecognized srb command\n",dev->name) ;
  1014. break ;
  1015. case 0x04:
  1016. printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n",dev->name);
  1017. break ;
  1018. default:
  1019. if (olympic_priv->olympic_message_level)
  1020. printk(KERN_WARNING "%s: Receive Options Modified to %x,%x\n",dev->name,olympic_priv->olympic_copy_all_options, olympic_priv->olympic_receive_options) ;
  1021. break ;
  1022. } /* switch srb[2] */
  1023. break ;
  1024. /* SRB_SET_GROUP_ADDRESS - Multicast group setting
  1025. */
  1026. case SRB_SET_GROUP_ADDRESS:
  1027. switch (readb(srb+2)) {
  1028. case 0x00:
  1029. break ;
  1030. case 0x01:
  1031. printk(KERN_WARNING "%s: Unrecognized srb command\n",dev->name);
  1032. break ;
  1033. case 0x04:
  1034. printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n",dev->name);
  1035. break ;
  1036. case 0x3c:
  1037. printk(KERN_WARNING "%s: Group/Functional address indicator bits not set correctly\n",dev->name) ;
  1038. break ;
  1039. case 0x3e: /* If we ever implement individual multicast addresses, will need to deal with this */
  1040. printk(KERN_WARNING "%s: Group address registers full\n",dev->name) ;
  1041. break ;
  1042. case 0x55:
  1043. printk(KERN_INFO "%s: Group Address already set.\n",dev->name) ;
  1044. break ;
  1045. default:
  1046. break ;
  1047. } /* switch srb[2] */
  1048. break ;
  1049. /* SRB_RESET_GROUP_ADDRESS - Remove a multicast address from group list
  1050. */
  1051. case SRB_RESET_GROUP_ADDRESS:
  1052. switch (readb(srb+2)) {
  1053. case 0x00:
  1054. break ;
  1055. case 0x01:
  1056. printk(KERN_WARNING "%s: Unrecognized srb command\n",dev->name);
  1057. break ;
  1058. case 0x04:
  1059. printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n",dev->name) ;
  1060. break ;
  1061. case 0x39: /* Must deal with this if individual multicast addresses used */
  1062. printk(KERN_INFO "%s: Group address not found\n",dev->name);
  1063. break ;
  1064. default:
  1065. break ;
  1066. } /* switch srb[2] */
  1067. break ;
  1068. /* SRB_SET_FUNC_ADDRESS - Called by the set_rx_mode
  1069. */
  1070. case SRB_SET_FUNC_ADDRESS:
  1071. switch (readb(srb+2)) {
  1072. case 0x00:
  1073. if (olympic_priv->olympic_message_level)
  1074. printk(KERN_INFO "%s: Functional Address Mask Set\n",dev->name);
  1075. break ;
  1076. case 0x01:
  1077. printk(KERN_WARNING "%s: Unrecognized srb command\n",dev->name);
  1078. break ;
  1079. case 0x04:
  1080. printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n",dev->name) ;
  1081. break ;
  1082. default:
  1083. break ;
  1084. } /* switch srb[2] */
  1085. break ;
  1086. /* SRB_READ_LOG - Read and reset the adapter error counters
  1087. */
  1088. case SRB_READ_LOG:
  1089. switch (readb(srb+2)) {
  1090. case 0x00:
  1091. if (olympic_priv->olympic_message_level)
  1092. printk(KERN_INFO "%s: Read Log issued\n",dev->name) ;
  1093. break ;
  1094. case 0x01:
  1095. printk(KERN_WARNING "%s: Unrecognized srb command\n",dev->name);
  1096. break ;
  1097. case 0x04:
  1098. printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n",dev->name) ;
  1099. break ;
  1100. } /* switch srb[2] */
  1101. break ;
  1102. /* SRB_READ_SR_COUNTERS - Read and reset the source routing bridge related counters */
  1103. case SRB_READ_SR_COUNTERS:
  1104. switch (readb(srb+2)) {
  1105. case 0x00:
  1106. if (olympic_priv->olympic_message_level)
  1107. printk(KERN_INFO "%s: Read Source Routing Counters issued\n",dev->name) ;
  1108. break ;
  1109. case 0x01:
  1110. printk(KERN_WARNING "%s: Unrecognized srb command\n",dev->name);
  1111. break ;
  1112. case 0x04:
  1113. printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n",dev->name) ;
  1114. break ;
  1115. default:
  1116. break ;
  1117. } /* switch srb[2] */
  1118. break ;
  1119. default:
  1120. printk(KERN_WARNING "%s: Unrecognized srb bh return value.\n",dev->name);
  1121. break ;
  1122. } /* switch srb[0] */
  1123. }
  1124. static int olympic_set_mac_address (struct net_device *dev, void *addr)
  1125. {
  1126. struct sockaddr *saddr = addr ;
  1127. struct olympic_private *olympic_priv = netdev_priv(dev);
  1128. if (netif_running(dev)) {
  1129. printk(KERN_WARNING "%s: Cannot set mac/laa address while card is open\n", dev->name) ;
  1130. return -EIO ;
  1131. }
  1132. memcpy(olympic_priv->olympic_laa, saddr->sa_data,dev->addr_len) ;
  1133. if (olympic_priv->olympic_message_level) {
  1134. printk(KERN_INFO "%s: MAC/LAA Set to = %x.%x.%x.%x.%x.%x\n",dev->name, olympic_priv->olympic_laa[0],
  1135. olympic_priv->olympic_laa[1], olympic_priv->olympic_laa[2],
  1136. olympic_priv->olympic_laa[3], olympic_priv->olympic_laa[4],
  1137. olympic_priv->olympic_laa[5]);
  1138. }
  1139. return 0 ;
  1140. }
  1141. static void olympic_arb_cmd(struct net_device *dev)
  1142. {
  1143. struct olympic_private *olympic_priv = netdev_priv(dev);
  1144. u8 __iomem *olympic_mmio=olympic_priv->olympic_mmio;
  1145. u8 __iomem *arb_block, *asb_block, *srb ;
  1146. u8 header_len ;
  1147. u16 frame_len, buffer_len ;
  1148. struct sk_buff *mac_frame ;
  1149. u8 __iomem *buf_ptr ;
  1150. u8 __iomem *frame_data ;
  1151. u16 buff_off ;
  1152. u16 lan_status = 0, lan_status_diff ; /* Initialize to stop compiler warning */
  1153. u8 fdx_prot_error ;
  1154. u16 next_ptr;
  1155. arb_block = (olympic_priv->olympic_lap + olympic_priv->arb) ;
  1156. asb_block = (olympic_priv->olympic_lap + olympic_priv->asb) ;
  1157. srb = (olympic_priv->olympic_lap + olympic_priv->srb) ;
  1158. if (readb(arb_block+0) == ARB_RECEIVE_DATA) { /* Receive.data, MAC frames */
  1159. header_len = readb(arb_block+8) ; /* 802.5 Token-Ring Header Length */
  1160. frame_len = swab16(readw(arb_block + 10)) ;
  1161. buff_off = swab16(readw(arb_block + 6)) ;
  1162. buf_ptr = olympic_priv->olympic_lap + buff_off ;
  1163. #if OLYMPIC_DEBUG
  1164. {
  1165. int i;
  1166. frame_data = buf_ptr+offsetof(struct mac_receive_buffer,frame_data) ;
  1167. for (i=0 ; i < 14 ; i++) {
  1168. printk("Loc %d = %02x\n",i,readb(frame_data + i));
  1169. }
  1170. printk("next %04x, fs %02x, len %04x\n",readw(buf_ptr+offsetof(struct mac_receive_buffer,next)), readb(buf_ptr+offsetof(struct mac_receive_buffer,frame_status)), readw(buf_ptr+offsetof(struct mac_receive_buffer,buffer_length)));
  1171. }
  1172. #endif
  1173. mac_frame = dev_alloc_skb(frame_len) ;
  1174. if (!mac_frame) {
  1175. printk(KERN_WARNING "%s: Memory squeeze, dropping frame.\n", dev->name);
  1176. goto drop_frame;
  1177. }
  1178. /* Walk the buffer chain, creating the frame */
  1179. do {
  1180. frame_data = buf_ptr+offsetof(struct mac_receive_buffer,frame_data) ;
  1181. buffer_len = swab16(readw(buf_ptr+offsetof(struct mac_receive_buffer,buffer_length)));
  1182. memcpy_fromio(skb_put(mac_frame, buffer_len), frame_data , buffer_len ) ;
  1183. next_ptr=readw(buf_ptr+offsetof(struct mac_receive_buffer,next));
  1184. } while (next_ptr && (buf_ptr=olympic_priv->olympic_lap + swab16(next_ptr)));
  1185. mac_frame->protocol = tr_type_trans(mac_frame, dev);
  1186. if (olympic_priv->olympic_network_monitor) {
  1187. struct trh_hdr *mac_hdr;
  1188. printk(KERN_WARNING "%s: Received MAC Frame, details:\n",dev->name);
  1189. mac_hdr = tr_hdr(mac_frame);
  1190. printk(KERN_WARNING "%s: MAC Frame Dest. Addr: %pM\n",
  1191. dev->name, mac_hdr->daddr);
  1192. printk(KERN_WARNING "%s: MAC Frame Srce. Addr: %pM\n",
  1193. dev->name, mac_hdr->saddr);
  1194. }
  1195. netif_rx(mac_frame);
  1196. drop_frame:
  1197. /* Now tell the card we have dealt with the received frame */
  1198. /* Set LISR Bit 1 */
  1199. writel(LISR_ARB_FREE,olympic_priv->olympic_mmio + LISR_SUM);
  1200. /* Is the ASB free ? */
  1201. if (readb(asb_block + 2) != 0xff) {
  1202. olympic_priv->asb_queued = 1 ;
  1203. writel(LISR_ASB_FREE_REQ,olympic_priv->olympic_mmio+LISR_SUM);
  1204. return ;
  1205. /* Drop out and wait for the bottom half to be run */
  1206. }
  1207. writeb(ASB_RECEIVE_DATA,asb_block); /* Receive data */
  1208. writeb(OLYMPIC_CLEAR_RET_CODE,asb_block+2); /* Necessary ?? */
  1209. writeb(readb(arb_block+6),asb_block+6); /* Must send the address back to the adapter */
  1210. writeb(readb(arb_block+7),asb_block+7); /* To let it know we have dealt with the data */
  1211. writel(LISR_ASB_REPLY | LISR_ASB_FREE_REQ,olympic_priv->olympic_mmio+LISR_SUM);
  1212. olympic_priv->asb_queued = 2 ;
  1213. return ;
  1214. } else if (readb(arb_block) == ARB_LAN_CHANGE_STATUS) { /* Lan.change.status */
  1215. lan_status = swab16(readw(arb_block+6));
  1216. fdx_prot_error = readb(arb_block+8) ;
  1217. /* Issue ARB Free */
  1218. writel(LISR_ARB_FREE,olympic_priv->olympic_mmio+LISR_SUM);
  1219. lan_status_diff = olympic_priv->olympic_lan_status ^ lan_status ;
  1220. if (lan_status_diff & (LSC_LWF | LSC_ARW | LSC_FPE | LSC_RR) ) {
  1221. if (lan_status_diff & LSC_LWF)
  1222. printk(KERN_WARNING "%s: Short circuit detected on the lobe\n",dev->name);
  1223. if (lan_status_diff & LSC_ARW)
  1224. printk(KERN_WARNING "%s: Auto removal error\n",dev->name);
  1225. if (lan_status_diff & LSC_FPE)
  1226. printk(KERN_WARNING "%s: FDX Protocol Error\n",dev->name);
  1227. if (lan_status_diff & LSC_RR)
  1228. printk(KERN_WARNING "%s: Force remove MAC frame received\n",dev->name);
  1229. /* Adapter has been closed by the hardware */
  1230. /* reset tx/rx fifo's and busmaster logic */
  1231. writel(readl(olympic_mmio+BCTL)|(3<<13),olympic_mmio+BCTL);
  1232. udelay(1);
  1233. writel(readl(olympic_mmio+BCTL)&~(3<<13),olympic_mmio+BCTL);
  1234. netif_stop_queue(dev);
  1235. olympic_priv->srb = readw(olympic_priv->olympic_lap + LAPWWO) ;
  1236. printk(KERN_WARNING "%s: Adapter has been closed\n", dev->name);
  1237. } /* If serious error */
  1238. if (olympic_priv->olympic_message_level) {
  1239. if (lan_status_diff & LSC_SIG_LOSS)
  1240. printk(KERN_WARNING "%s: No receive signal detected\n", dev->name);
  1241. if (lan_status_diff & LSC_HARD_ERR)
  1242. printk(KERN_INFO "%s: Beaconing\n",dev->name);
  1243. if (lan_status_diff & LSC_SOFT_ERR)
  1244. printk(KERN_WARNING "%s: Adapter transmitted Soft Error Report Mac Frame\n",dev->name);
  1245. if (lan_status_diff & LSC_TRAN_BCN)
  1246. printk(KERN_INFO "%s: We are transmitting the beacon, aaah\n",dev->name);
  1247. if (lan_status_diff & LSC_SS)
  1248. printk(KERN_INFO "%s: Single Station on the ring\n", dev->name);
  1249. if (lan_status_diff & LSC_RING_REC)
  1250. printk(KERN_INFO "%s: Ring recovery ongoing\n",dev->name);
  1251. if (lan_status_diff & LSC_FDX_MODE)
  1252. printk(KERN_INFO "%s: Operating in FDX mode\n",dev->name);
  1253. }
  1254. if (lan_status_diff & LSC_CO) {
  1255. if (olympic_priv->olympic_message_level)
  1256. printk(KERN_INFO "%s: Counter Overflow\n", dev->name);
  1257. /* Issue READ.LOG command */
  1258. writeb(SRB_READ_LOG, srb);
  1259. writeb(0,srb+1);
  1260. writeb(OLYMPIC_CLEAR_RET_CODE,srb+2);
  1261. writeb(0,srb+3);
  1262. writeb(0,srb+4);
  1263. writeb(0,srb+5);
  1264. olympic_priv->srb_queued=2; /* Can't sleep, use srb_bh */
  1265. writel(LISR_SRB_CMD,olympic_mmio+LISR_SUM);
  1266. }
  1267. if (lan_status_diff & LSC_SR_CO) {
  1268. if (olympic_priv->olympic_message_level)
  1269. printk(KERN_INFO "%s: Source routing counters overflow\n", dev->name);
  1270. /* Issue a READ.SR.COUNTERS */
  1271. writeb(SRB_READ_SR_COUNTERS,srb);
  1272. writeb(0,srb+1);
  1273. writeb(OLYMPIC_CLEAR_RET_CODE,srb+2);
  1274. writeb(0,srb+3);
  1275. olympic_priv->srb_queued=2; /* Can't sleep, use srb_bh */
  1276. writel(LISR_SRB_CMD,olympic_mmio+LISR_SUM);
  1277. }
  1278. olympic_priv->olympic_lan_status = lan_status ;
  1279. } /* Lan.change.status */
  1280. else
  1281. printk(KERN_WARNING "%s: Unknown arb command\n", dev->name);
  1282. }
  1283. static void olympic_asb_bh(struct net_device *dev)
  1284. {
  1285. struct olympic_private *olympic_priv = netdev_priv(dev);
  1286. u8 __iomem *arb_block, *asb_block ;
  1287. arb_block = (olympic_priv->olympic_lap + olympic_priv->arb) ;
  1288. asb_block = (olympic_priv->olympic_lap + olympic_priv->asb) ;
  1289. if (olympic_priv->asb_queued == 1) { /* Dropped through the first time */
  1290. writeb(ASB_RECEIVE_DATA,asb_block); /* Receive data */
  1291. writeb(OLYMPIC_CLEAR_RET_CODE,asb_block+2); /* Necessary ?? */
  1292. writeb(readb(arb_block+6),asb_block+6); /* Must send the address back to the adapter */
  1293. writeb(readb(arb_block+7),asb_block+7); /* To let it know we have dealt with the data */
  1294. writel(LISR_ASB_REPLY | LISR_ASB_FREE_REQ,olympic_priv->olympic_mmio+LISR_SUM);
  1295. olympic_priv->asb_queued = 2 ;
  1296. return ;
  1297. }
  1298. if (olympic_priv->asb_queued == 2) {
  1299. switch (readb(asb_block+2)) {
  1300. case 0x01:
  1301. printk(KERN_WARNING "%s: Unrecognized command code\n", dev->name);
  1302. break ;
  1303. case 0x26:
  1304. printk(KERN_WARNING "%s: Unrecognized buffer address\n", dev->name);
  1305. break ;
  1306. case 0xFF:
  1307. /* Valid response, everything should be ok again */
  1308. break ;
  1309. default:
  1310. printk(KERN_WARNING "%s: Invalid return code in asb\n",dev->name);
  1311. break ;
  1312. }
  1313. }
  1314. olympic_priv->asb_queued = 0 ;
  1315. }
  1316. static int olympic_change_mtu(struct net_device *dev, int mtu)
  1317. {
  1318. struct olympic_private *olympic_priv = netdev_priv(dev);
  1319. u16 max_mtu ;
  1320. if (olympic_priv->olympic_ring_speed == 4)
  1321. max_mtu = 4500 ;
  1322. else
  1323. max_mtu = 18000 ;
  1324. if (mtu > max_mtu)
  1325. return -EINVAL ;
  1326. if (mtu < 100)
  1327. return -EINVAL ;
  1328. dev->mtu = mtu ;
  1329. olympic_priv->pkt_buf_sz = mtu + TR_HLEN ;
  1330. return 0 ;
  1331. }
  1332. static int olympic_proc_show(struct seq_file *m, void *v)
  1333. {
  1334. struct net_device *dev = m->private;
  1335. struct olympic_private *olympic_priv=netdev_priv(dev);
  1336. u8 __iomem *oat = (olympic_priv->olympic_lap + olympic_priv->olympic_addr_table_addr) ;
  1337. u8 __iomem *opt = (olympic_priv->olympic_lap + olympic_priv->olympic_parms_addr) ;
  1338. u8 addr[6];
  1339. u8 addr2[6];
  1340. int i;
  1341. seq_printf(m,
  1342. "IBM Pit/Pit-Phy/Olympic Chipset Token Ring Adapter %s\n",dev->name);
  1343. seq_printf(m, "\n%6s: Adapter Address : Node Address : Functional Addr\n",
  1344. dev->name);
  1345. for (i = 0 ; i < 6 ; i++)
  1346. addr[i] = readb(oat+offsetof(struct olympic_adapter_addr_table,node_addr) + i);
  1347. seq_printf(m, "%6s: %pM : %pM : %02x:%02x:%02x:%02x\n",
  1348. dev->name,
  1349. dev->dev_addr, addr,
  1350. readb(oat+offsetof(struct olympic_adapter_addr_table,func_addr)),
  1351. readb(oat+offsetof(struct olympic_adapter_addr_table,func_addr)+1),
  1352. readb(oat+offsetof(struct olympic_adapter_addr_table,func_addr)+2),
  1353. readb(oat+offsetof(struct olympic_adapter_addr_table,func_addr)+3));
  1354. seq_printf(m, "\n%6s: Token Ring Parameters Table:\n", dev->name);
  1355. seq_printf(m, "%6s: Physical Addr : Up Node Address : Poll Address : AccPri : Auth Src : Att Code :\n",
  1356. dev->name) ;
  1357. for (i = 0 ; i < 6 ; i++)
  1358. addr[i] = readb(opt+offsetof(struct olympic_parameters_table, up_node_addr) + i);
  1359. for (i = 0 ; i < 6 ; i++)
  1360. addr2[i] = readb(opt+offsetof(struct olympic_parameters_table, poll_addr) + i);
  1361. seq_printf(m, "%6s: %02x:%02x:%02x:%02x : %pM : %pM : %04x : %04x : %04x :\n",
  1362. dev->name,
  1363. readb(opt+offsetof(struct olympic_parameters_table, phys_addr)),
  1364. readb(opt+offsetof(struct olympic_parameters_table, phys_addr)+1),
  1365. readb(opt+offsetof(struct olympic_parameters_table, phys_addr)+2),
  1366. readb(opt+offsetof(struct olympic_parameters_table, phys_addr)+3),
  1367. addr, addr2,
  1368. swab16(readw(opt+offsetof(struct olympic_parameters_table, acc_priority))),
  1369. swab16(readw(opt+offsetof(struct olympic_parameters_table, auth_source_class))),
  1370. swab16(readw(opt+offsetof(struct olympic_parameters_table, att_code))));
  1371. seq_printf(m, "%6s: Source Address : Bcn T : Maj. V : Lan St : Lcl Rg : Mon Err : Frame Correl : \n",
  1372. dev->name) ;
  1373. for (i = 0 ; i < 6 ; i++)
  1374. addr[i] = readb(opt+offsetof(struct olympic_parameters_table, source_addr) + i);
  1375. seq_printf(m, "%6s: %pM : %04x : %04x : %04x : %04x : %04x : %04x : \n",
  1376. dev->name, addr,
  1377. swab16(readw(opt+offsetof(struct olympic_parameters_table, beacon_type))),
  1378. swab16(readw(opt+offsetof(struct olympic_parameters_table, major_vector))),
  1379. swab16(readw(opt+offsetof(struct olympic_parameters_table, lan_status))),
  1380. swab16(readw(opt+offsetof(struct olympic_parameters_table, local_ring))),
  1381. swab16(readw(opt+offsetof(struct olympic_parameters_table, mon_error))),
  1382. swab16(readw(opt+offsetof(struct olympic_parameters_table, frame_correl))));
  1383. seq_printf(m, "%6s: Beacon Details : Tx : Rx : NAUN Node Address : NAUN Node Phys : \n",
  1384. dev->name) ;
  1385. for (i = 0 ; i < 6 ; i++)
  1386. addr[i] = readb(opt+offsetof(struct olympic_parameters_table, beacon_naun) + i);
  1387. seq_printf(m, "%6s: : %02x : %02x : %pM : %02x:%02x:%02x:%02x : \n",
  1388. dev->name,
  1389. swab16(readw(opt+offsetof(struct olympic_parameters_table, beacon_transmit))),
  1390. swab16(readw(opt+offsetof(struct olympic_parameters_table, beacon_receive))),
  1391. addr,
  1392. readb(opt+offsetof(struct olympic_parameters_table, beacon_phys)),
  1393. readb(opt+offsetof(struct olympic_parameters_table, beacon_phys)+1),
  1394. readb(opt+offsetof(struct olympic_parameters_table, beacon_phys)+2),
  1395. readb(opt+offsetof(struct olympic_parameters_table, beacon_phys)+3));
  1396. return 0;
  1397. }
  1398. static int olympic_proc_open(struct inode *inode, struct file *file)
  1399. {
  1400. return single_open(file, olympic_proc_show, PDE(inode)->data);
  1401. }
  1402. static const struct file_operations olympic_proc_ops = {
  1403. .open = olympic_proc_open,
  1404. .read = seq_read,
  1405. .llseek = seq_lseek,
  1406. .release = single_release,
  1407. };
  1408. static void __devexit olympic_remove_one(struct pci_dev *pdev)
  1409. {
  1410. struct net_device *dev = pci_get_drvdata(pdev) ;
  1411. struct olympic_private *olympic_priv=netdev_priv(dev);
  1412. if (olympic_priv->olympic_network_monitor) {
  1413. char proc_name[20] ;
  1414. strcpy(proc_name,"olympic_") ;
  1415. strcat(proc_name,dev->name) ;
  1416. remove_proc_entry(proc_name,init_net.proc_net);
  1417. }
  1418. unregister_netdev(dev) ;
  1419. iounmap(olympic_priv->olympic_mmio) ;
  1420. iounmap(olympic_priv->olympic_lap) ;
  1421. pci_release_regions(pdev) ;
  1422. pci_set_drvdata(pdev,NULL) ;
  1423. free_netdev(dev) ;
  1424. }
  1425. static struct pci_driver olympic_driver = {
  1426. .name = "olympic",
  1427. .id_table = olympic_pci_tbl,
  1428. .probe = olympic_probe,
  1429. .remove = __devexit_p(olympic_remove_one),
  1430. };
  1431. static int __init olympic_pci_init(void)
  1432. {
  1433. return pci_register_driver(&olympic_driver) ;
  1434. }
  1435. static void __exit olympic_pci_cleanup(void)
  1436. {
  1437. pci_unregister_driver(&olympic_driver) ;
  1438. }
  1439. module_init(olympic_pci_init) ;
  1440. module_exit(olympic_pci_cleanup) ;
  1441. MODULE_LICENSE("GPL");