olympic.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:66k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  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/config.h>
  80. #include <linux/module.h>
  81. #include <linux/kernel.h>
  82. #include <linux/sched.h>
  83. #include <linux/errno.h>
  84. #include <linux/timer.h>
  85. #include <linux/in.h>
  86. #include <linux/ioport.h>
  87. #include <linux/string.h>
  88. #include <linux/proc_fs.h>
  89. #include <linux/ptrace.h>
  90. #include <linux/skbuff.h>
  91. #include <linux/interrupt.h>
  92. #include <linux/delay.h>
  93. #include <linux/netdevice.h>
  94. #include <linux/trdevice.h>
  95. #include <linux/stddef.h>
  96. #include <linux/init.h>
  97. #include <linux/pci.h>
  98. #include <linux/spinlock.h>
  99. #include <net/checksum.h>
  100. #include <asm/io.h>
  101. #include <asm/system.h>
  102. #include <asm/bitops.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[] __devinitdata = 
  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 paramters */
  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_PARM(ringspeed, "1-" __MODULE_STRING(OLYMPIC_MAX_ADAPTERS) "i");
  140. /* Packet buffer size */
  141. static int pkt_buf_sz[OLYMPIC_MAX_ADAPTERS] = {0,} ;
  142. MODULE_PARM(pkt_buf_sz, "1-" __MODULE_STRING(OLYMPIC_MAX_ADAPTERS) "i") ; 
  143. /* Message Level */
  144. static int message_level[OLYMPIC_MAX_ADAPTERS] = {0,} ; 
  145. MODULE_PARM(message_level, "1-" __MODULE_STRING(OLYMPIC_MAX_ADAPTERS) "i") ; 
  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_PARM(network_monitor, "1-" __MODULE_STRING(OLYMPIC_MAX_ADAPTERS) "i");
  154. static struct pci_device_id olympic_pci_tbl[] __devinitdata = {
  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 int olympic_xmit(struct sk_buff *skb, struct net_device *dev);
  163. static int olympic_close(struct net_device *dev);
  164. static void olympic_set_rx_mode(struct net_device *dev);
  165. static void olympic_freemem(struct net_device *dev) ;  
  166. static void olympic_interrupt(int irq, void *dev_id, struct pt_regs *regs);
  167. static struct net_device_stats * olympic_get_stats(struct net_device *dev);
  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 int olympic_proc_info(char *buffer, char **start, off_t offset, int length, int *eof, void *data) ; 
  174. static int __devinit olympic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  175. {
  176. struct net_device *dev ; 
  177. struct olympic_private *olympic_priv;
  178. static int card_no = -1 ;
  179. int i ; 
  180. card_no++ ; 
  181. if ((i = pci_enable_device(pdev))) {
  182. return i ; 
  183. }
  184. pci_set_master(pdev);
  185. if ((i = pci_request_regions(pdev,"olympic"))) { 
  186. return i ; 
  187. } ; 
  188.  
  189. dev = alloc_trdev(sizeof(struct olympic_private)) ; 
  190. if (!dev) {
  191. pci_release_regions(pdev) ; 
  192. return -ENOMEM ; 
  193. }
  194. olympic_priv = dev->priv ;
  195. init_waitqueue_head(&olympic_priv->srb_wait);
  196. init_waitqueue_head(&olympic_priv->trb_wait);
  197. #if OLYMPIC_DEBUG  
  198. printk(KERN_INFO "pci_device: %p, dev:%p, dev->priv: %pn", pdev, dev, dev->priv);
  199. #endif
  200. dev->irq=pdev->irq;
  201. dev->base_addr=pci_resource_start(pdev, 0);
  202. dev->init=NULL; /* Must be NULL otherwise we get called twice */
  203. olympic_priv->olympic_card_name = (char *)pdev->name ; 
  204. olympic_priv->olympic_mmio = ioremap(pci_resource_start(pdev,1),256);
  205. olympic_priv->olympic_lap = ioremap(pci_resource_start(pdev,2),2048);
  206. olympic_priv->pdev = pdev ; 
  207. if ((pkt_buf_sz[card_no] < 100) || (pkt_buf_sz[card_no] > 18000) )
  208. olympic_priv->pkt_buf_sz = PKT_BUF_SZ ; 
  209. else
  210. olympic_priv->pkt_buf_sz = pkt_buf_sz[card_no] ; 
  211. dev->mtu = olympic_priv->pkt_buf_sz - TR_HLEN ; 
  212. olympic_priv->olympic_ring_speed = ringspeed[card_no] ; 
  213. olympic_priv->olympic_message_level = message_level[card_no] ; 
  214. olympic_priv->olympic_network_monitor = network_monitor[card_no];
  215. if((i = olympic_init(dev))) {
  216. iounmap(olympic_priv->olympic_mmio) ; 
  217. iounmap(olympic_priv->olympic_lap) ; 
  218. kfree(dev) ; 
  219. pci_release_regions(pdev) ; 
  220. return i ; 
  221. }
  222. dev->open=&olympic_open;
  223. dev->hard_start_xmit=&olympic_xmit;
  224. dev->change_mtu=&olympic_change_mtu;
  225. dev->stop=&olympic_close;
  226. dev->do_ioctl=NULL;
  227. dev->set_multicast_list=&olympic_set_rx_mode;
  228. dev->get_stats=&olympic_get_stats ;
  229. dev->set_mac_address=&olympic_set_mac_address ;  
  230. SET_MODULE_OWNER(dev) ; 
  231. pci_set_drvdata(pdev,dev) ; 
  232. register_netdev(dev) ; 
  233. printk("Olympic: %s registered as: %sn",olympic_priv->olympic_card_name,dev->name);
  234. if (olympic_priv->olympic_network_monitor) { /* Must go after register_netdev as we need the device name */ 
  235. char proc_name[20] ; 
  236. strcpy(proc_name,"net/olympic_") ; 
  237. strcat(proc_name,dev->name) ; 
  238. create_proc_read_entry(proc_name,0,0,olympic_proc_info,(void *)dev) ; 
  239. printk("Olympic: Network Monitor information: /proc/%sn",proc_name); 
  240. }
  241. return  0 ;
  242. }
  243. static int __devinit olympic_init(struct net_device *dev)
  244. {
  245.      struct olympic_private *olympic_priv;
  246. u8 *olympic_mmio, *init_srb,*adapter_addr;
  247. unsigned long t; 
  248. unsigned int uaa_addr;
  249.      olympic_priv=(struct olympic_private *)dev->priv;
  250. olympic_mmio=olympic_priv->olympic_mmio;
  251. printk("%s n", version);
  252. printk("%s. I/O at %hx, MMIO at %p, LAP at %p, using irq %dn", olympic_priv->olympic_card_name, (unsigned int) dev->base_addr,olympic_priv->olympic_mmio, olympic_priv->olympic_lap, dev->irq);
  253. writel(readl(olympic_mmio+BCTL) | BCTL_SOFTRESET,olympic_mmio+BCTL);
  254. t=jiffies;
  255. while((readl(olympic_mmio+BCTL)) & BCTL_SOFTRESET) {
  256. schedule();
  257. if(jiffies-t > 40*HZ) {
  258. printk(KERN_ERR "IBM PCI tokenring card not responding.n");
  259. return -ENODEV;
  260. }
  261. }
  262. spin_lock_init(&olympic_priv->olympic_lock) ; 
  263. /* Needed for cardbus */
  264. if(!(readl(olympic_mmio+BCTL) & BCTL_MODE_INDICATOR)) {
  265. writel(readl(olympic_priv->olympic_mmio+FERMASK)|FERMASK_INT_BIT, olympic_mmio+FERMASK);
  266. }
  267. #if OLYMPIC_DEBUG
  268. printk("BCTL: %xn",readl(olympic_mmio+BCTL));
  269. printk("GPR: %xn",readw(olympic_mmio+GPR));
  270. printk("SISRMASK: %xn",readl(olympic_mmio+SISR_MASK));
  271. #endif
  272. /* Aaaahhh, You have got to be real careful setting GPR, the card
  273.    holds the previous values from flash memory, including autosense 
  274.            and ring speed */
  275. writel(readl(olympic_mmio+BCTL)|BCTL_MIMREB,olympic_mmio+BCTL);
  276. if (olympic_priv->olympic_ring_speed  == 0) { /* Autosense */
  277. writew(readw(olympic_mmio+GPR)|GPR_AUTOSENSE,olympic_mmio+GPR);
  278. if (olympic_priv->olympic_message_level) 
  279. printk(KERN_INFO "%s: Ringspeed autosense mode onn",olympic_priv->olympic_card_name);
  280. } else if (olympic_priv->olympic_ring_speed == 16) {
  281. if (olympic_priv->olympic_message_level) 
  282. printk(KERN_INFO "%s: Trying to open at 16 Mbps as requestedn", olympic_priv->olympic_card_name);
  283. writew(GPR_16MBPS, olympic_mmio+GPR);
  284. } else if (olympic_priv->olympic_ring_speed == 4) {
  285. if (olympic_priv->olympic_message_level) 
  286. printk(KERN_INFO "%s: Trying to open at 4 Mbps as requestedn", olympic_priv->olympic_card_name) ; 
  287. writew(0, olympic_mmio+GPR);
  288. writew(readw(olympic_mmio+GPR)|GPR_NEPTUNE_BF,olympic_mmio+GPR);
  289. #if OLYMPIC_DEBUG
  290. printk("GPR = %xn",readw(olympic_mmio + GPR) ) ; 
  291. #endif
  292. /* Solo has been paused to meet the Cardbus power
  293.  * specs if the adapter is cardbus. Check to 
  294.  * see its been paused and then restart solo. The
  295.  * adapter should set the pause bit within 1 second.
  296.  */
  297. if(!(readl(olympic_mmio+BCTL) & BCTL_MODE_INDICATOR)) { 
  298. t=jiffies;
  299. while (!readl(olympic_mmio+CLKCTL) & CLKCTL_PAUSE) { 
  300. schedule() ; 
  301. if(jiffies-t > 2*HZ) { 
  302. printk(KERN_ERR "IBM Cardbus tokenring adapter not responsing.n") ; 
  303. return -ENODEV;
  304. }
  305. }
  306. writel(readl(olympic_mmio+CLKCTL) & ~CLKCTL_PAUSE, olympic_mmio+CLKCTL) ; 
  307. }
  308. /* start solo init */
  309. writel((1<<15),olympic_mmio+SISR_MASK_SUM);
  310. t=jiffies;
  311. while(!((readl(olympic_mmio+SISR_RR)) & SISR_SRB_REPLY)) {
  312. schedule();
  313. if(jiffies-t > 15*HZ) {
  314. printk(KERN_ERR "IBM PCI tokenring card not responding.n");
  315. return -ENODEV;
  316. }
  317. }
  318. writel(readw(olympic_mmio+LAPWWO),olympic_mmio+LAPA);
  319. #if OLYMPIC_DEBUG
  320. printk("LAPWWO: %x, LAPA: %xn",readl(olympic_mmio+LAPWWO), readl(olympic_mmio+LAPA));
  321. #endif
  322. init_srb=olympic_priv->olympic_lap + ((readw(olympic_mmio+LAPWWO)) & (~0xf800));
  323. #if OLYMPIC_DEBUG
  324. {
  325. int i;
  326. printk("init_srb(%p): ",init_srb);
  327. for(i=0;i<20;i++)
  328. printk("%x ",readb(init_srb+i));
  329. printk("n");
  330. }
  331. #endif
  332. if(readw(init_srb+6)) {
  333. printk(KERN_INFO "tokenring card intialization failed. errorcode : %xn",readw(init_srb+6));
  334. return -ENODEV;
  335. }
  336. if (olympic_priv->olympic_message_level) {
  337. if ( readb(init_srb +2) & 0x40) { 
  338. printk(KERN_INFO "Olympic: Adapter is FDX capable.n") ;
  339. } else { 
  340. printk(KERN_INFO "Olympic: Adapter cannot do FDX.n");
  341. }
  342. }
  343.   
  344. uaa_addr=swab16(readw(init_srb+8));
  345. #if OLYMPIC_DEBUG
  346. printk("UAA resides at %xn",uaa_addr);
  347. #endif
  348. writel(uaa_addr,olympic_mmio+LAPA);
  349. adapter_addr=olympic_priv->olympic_lap + (uaa_addr & (~0xf800));
  350. #if OLYMPIC_DEBUG
  351. printk("adapter address: %02x:%02x:%02x:%02x:%02x:%02xn",
  352. readb(adapter_addr), readb(adapter_addr+1),readb(adapter_addr+2),
  353. readb(adapter_addr+3),readb(adapter_addr+4),readb(adapter_addr+5));
  354. #endif
  355. memcpy_fromio(&dev->dev_addr[0], adapter_addr,6);
  356. olympic_priv->olympic_addr_table_addr = swab16(readw(init_srb + 12)); 
  357. olympic_priv->olympic_parms_addr = swab16(readw(init_srb + 14)); 
  358. return 0;
  359. }
  360. static int olympic_open(struct net_device *dev) 
  361. {
  362. struct olympic_private *olympic_priv=(struct olympic_private *)dev->priv;
  363. u8 *olympic_mmio=olympic_priv->olympic_mmio,*init_srb;
  364. unsigned long flags, t;
  365. char open_error[255] ; 
  366. int i, open_finished = 1 ;
  367. DECLARE_WAITQUEUE(wait,current) ; 
  368. if(request_irq(dev->irq, &olympic_interrupt, SA_SHIRQ , "olympic", dev)) {
  369. return -EAGAIN;
  370. }
  371. #if OLYMPIC_DEBUG
  372. printk("BMCTL: %xn",readl(olympic_mmio+BMCTL_SUM));
  373. printk("pending ints: %xn",readl(olympic_mmio+SISR_RR));
  374. #endif
  375. writel(SISR_MI,olympic_mmio+SISR_MASK_SUM);
  376. writel(SISR_MI | SISR_SRB_REPLY, olympic_mmio+SISR_MASK); /* more ints later, doesn't stop arb cmd interrupt */
  377. writel(LISR_LIE,olympic_mmio+LISR); /* more ints later */
  378. /* adapter is closed, so SRB is pointed to by LAPWWO */
  379. writel(readw(olympic_mmio+LAPWWO),olympic_mmio+LAPA);
  380. init_srb=olympic_priv->olympic_lap + ((readw(olympic_mmio+LAPWWO)) & (~0xf800));
  381. #if OLYMPIC_DEBUG
  382. printk("LAPWWO: %x, LAPA: %xn",readw(olympic_mmio+LAPWWO), readl(olympic_mmio+LAPA));
  383. printk("SISR Mask = %04xn", readl(olympic_mmio+SISR_MASK));
  384. printk("Before the open command n");
  385. #endif
  386. do {
  387. int i;
  388. for(i=0;i<SRB_COMMAND_SIZE;i+=4)
  389. writel(0,init_srb+i);
  390. if(SRB_COMMAND_SIZE & 2)
  391. writew(0,init_srb+(SRB_COMMAND_SIZE & ~3));
  392. if(SRB_COMMAND_SIZE & 1)
  393. writeb(0,init_srb+(SRB_COMMAND_SIZE & ~1));
  394. writeb(SRB_OPEN_ADAPTER,init_srb) ;  /* open */
  395. writeb(OLYMPIC_CLEAR_RET_CODE,init_srb+2);
  396. /* If Network Monitor, instruct card to copy MAC frames through the ARB */
  397. if (olympic_priv->olympic_network_monitor) 
  398. writew(swab16(OPEN_ADAPTER_ENABLE_FDX | OPEN_ADAPTER_PASS_ADC_MAC | OPEN_ADAPTER_PASS_ATT_MAC | OPEN_ADAPTER_PASS_BEACON), init_srb+8);
  399. else
  400. writew(swab16(OPEN_ADAPTER_ENABLE_FDX), init_srb+8);
  401. /* Test OR of first 3 bytes as its totally possible for 
  402.  * someone to set the first 2 bytes to be zero, although this 
  403.  * is an error, the first byte must have bit 6 set to 1  */
  404. if (olympic_priv->olympic_laa[0] | olympic_priv->olympic_laa[1] | olympic_priv->olympic_laa[2]) {
  405. writeb(olympic_priv->olympic_laa[0],init_srb+12);
  406. writeb(olympic_priv->olympic_laa[1],init_srb+13);
  407. writeb(olympic_priv->olympic_laa[2],init_srb+14);
  408. writeb(olympic_priv->olympic_laa[3],init_srb+15);
  409. writeb(olympic_priv->olympic_laa[4],init_srb+16);
  410. writeb(olympic_priv->olympic_laa[5],init_srb+17);
  411. memcpy(dev->dev_addr,olympic_priv->olympic_laa,dev->addr_len) ;  
  412. writeb(1,init_srb+30);
  413. spin_lock_irqsave(&olympic_priv->olympic_lock,flags);
  414. olympic_priv->srb_queued=1;
  415. writel(LISR_SRB_CMD,olympic_mmio+LISR_SUM);
  416. spin_unlock_irqrestore(&olympic_priv->olympic_lock,flags);
  417. t = jiffies ; 
  418. add_wait_queue(&olympic_priv->srb_wait,&wait) ;
  419. set_current_state(TASK_INTERRUPTIBLE) ; 
  420.  
  421.   while(olympic_priv->srb_queued) {        
  422. schedule() ; 
  423.          if(signal_pending(current)) {            
  424. printk(KERN_WARNING "%s: Signal received in open.n",
  425.                  dev->name);
  426.              printk(KERN_WARNING "SISR=%x LISR=%xn",
  427.                  readl(olympic_mmio+SISR),
  428.                  readl(olympic_mmio+LISR));
  429.              olympic_priv->srb_queued=0;
  430.              break;
  431.          }
  432. if ((jiffies-t) > 10*HZ) { 
  433. printk(KERN_WARNING "%s: SRB timed out. n",dev->name) ; 
  434. olympic_priv->srb_queued=0;
  435. break ; 
  436. set_current_state(TASK_INTERRUPTIBLE) ; 
  437.      }
  438. remove_wait_queue(&olympic_priv->srb_wait,&wait) ; 
  439. set_current_state(TASK_RUNNING) ; 
  440. olympic_priv->srb_queued = 0 ; 
  441. #if OLYMPIC_DEBUG
  442. printk("init_srb(%p): ",init_srb);
  443. for(i=0;i<20;i++)
  444. printk("%02x ",readb(init_srb+i));
  445. printk("n");
  446. #endif
  447. /* If we get the same return response as we set, the interrupt wasn't raised and the open
  448.                  * timed out.
  449.  */
  450. if(readb(init_srb+2)== OLYMPIC_CLEAR_RET_CODE) {
  451. printk(KERN_WARNING "%s: Adapter Open time out or error.n", dev->name) ; 
  452. return -EIO ; 
  453. }
  454. if(readb(init_srb+2)!=0) {
  455. if (readb(init_srb+2) == 0x07) {  
  456. if (!olympic_priv->olympic_ring_speed && open_finished) { /* Autosense , first time around */
  457. printk(KERN_WARNING "%s: Retrying at different ring speed n", dev->name); 
  458. open_finished = 0 ;  
  459. } else {
  460. strcpy(open_error, open_maj_error[(readb(init_srb+7) & 0xf0) >> 4]) ; 
  461. strcat(open_error," - ") ; 
  462. strcat(open_error, open_min_error[(readb(init_srb+7) & 0x0f)]) ;
  463. if (!olympic_priv->olympic_ring_speed && ((readb(init_srb+7) & 0x0f) == 0x0d)) { 
  464. printk(KERN_WARNING "%s: Tried to autosense ring speed with no monitors presentn",dev->name);
  465. printk(KERN_WARNING "%s: Please try again with a specified ring speed n",dev->name);
  466. free_irq(dev->irq, dev);
  467. return -EIO ;
  468. }
  469. printk(KERN_WARNING "%s: %sn",dev->name,open_error);
  470. free_irq(dev->irq,dev) ; 
  471. return -EIO ; 
  472.  
  473. } /* if autosense && open_finished */
  474. } else if (init_srb[2] == 0x32) {
  475. printk(KERN_WARNING "%s: Invalid LAA: %02x:%02x:%02x:%02x:%02x:%02xn",
  476. dev->name, 
  477. olympic_priv->olympic_laa[0],
  478. olympic_priv->olympic_laa[1],
  479. olympic_priv->olympic_laa[2],
  480. olympic_priv->olympic_laa[3],
  481. olympic_priv->olympic_laa[4],
  482. olympic_priv->olympic_laa[5]) ; 
  483. free_irq(dev->irq,dev) ; 
  484. return -EIO ; 
  485. } else {  
  486. printk(KERN_WARNING "%s: Bad OPEN response: %xn", dev->name,init_srb[2]);
  487. free_irq(dev->irq, dev);
  488. return -EIO;
  489. } else 
  490. open_finished = 1 ; 
  491. } while (!(open_finished)) ; /* Will only loop if ring speed mismatch re-open attempted && autosense is on */
  492. if (readb(init_srb+18) & (1<<3)) 
  493. if (olympic_priv->olympic_message_level) 
  494. printk(KERN_INFO "%s: Opened in FDX Moden",dev->name);
  495. if (readb(init_srb+18) & (1<<1))
  496. olympic_priv->olympic_ring_speed = 100 ; 
  497. else if (readb(init_srb+18) & 1)
  498. olympic_priv->olympic_ring_speed = 16 ; 
  499. else
  500. olympic_priv->olympic_ring_speed = 4 ; 
  501. if (olympic_priv->olympic_message_level) 
  502. printk(KERN_INFO "%s: Opened in %d Mbps moden",dev->name, olympic_priv->olympic_ring_speed);
  503. olympic_priv->asb = swab16(readw(init_srb+8));
  504. olympic_priv->srb = swab16(readw(init_srb+10));
  505. olympic_priv->arb = swab16(readw(init_srb+12));
  506. olympic_priv->trb = swab16(readw(init_srb+16));
  507. olympic_priv->olympic_receive_options = 0x01 ; 
  508. olympic_priv->olympic_copy_all_options = 0 ; 
  509. /* setup rx ring */
  510. writel((3<<16),olympic_mmio+BMCTL_RWM); /* Ensure end of frame generated interrupts */ 
  511. writel(BMCTL_RX_DIS|3,olympic_mmio+BMCTL_RWM); /* Yes, this the enables RX channel */
  512. for(i=0;i<OLYMPIC_RX_RING_SIZE;i++) {
  513. struct sk_buff *skb;
  514. skb=dev_alloc_skb(olympic_priv->pkt_buf_sz);
  515. if(skb == NULL)
  516. break;
  517. skb->dev = dev;
  518. olympic_priv->olympic_rx_ring[i].buffer = cpu_to_le32(pci_map_single(olympic_priv->pdev, 
  519.   skb->data,olympic_priv->pkt_buf_sz, PCI_DMA_FROMDEVICE)) ; 
  520. olympic_priv->olympic_rx_ring[i].res_length = cpu_to_le32(olympic_priv->pkt_buf_sz); 
  521. olympic_priv->rx_ring_skb[i]=skb;
  522. }
  523. if (i==0) {
  524. printk(KERN_WARNING "%s: Not enough memory to allocate rx buffers. Adapter disabledn",dev->name);
  525. free_irq(dev->irq, dev);
  526. return -EIO;
  527. }
  528. olympic_priv->rx_ring_dma_addr = pci_map_single(olympic_priv->pdev,olympic_priv->olympic_rx_ring, 
  529.  sizeof(struct olympic_rx_desc) * OLYMPIC_RX_RING_SIZE, PCI_DMA_TODEVICE);
  530. writel(olympic_priv->rx_ring_dma_addr, olympic_mmio+RXDESCQ);
  531. writel(olympic_priv->rx_ring_dma_addr, olympic_mmio+RXCDA);
  532. writew(i, olympic_mmio+RXDESCQCNT);
  533. olympic_priv->rx_status_ring_dma_addr = pci_map_single(olympic_priv->pdev, olympic_priv->olympic_rx_status_ring, 
  534. sizeof(struct olympic_rx_status) * OLYMPIC_RX_RING_SIZE, PCI_DMA_FROMDEVICE);
  535. writel(olympic_priv->rx_status_ring_dma_addr, olympic_mmio+RXSTATQ);
  536. writel(olympic_priv->rx_status_ring_dma_addr, olympic_mmio+RXCSA);
  537.   olympic_priv->rx_ring_last_received = OLYMPIC_RX_RING_SIZE - 1; /* last processed rx status */
  538. olympic_priv->rx_status_last_received = OLYMPIC_RX_RING_SIZE - 1;  
  539. writew(i, olympic_mmio+RXSTATQCNT);
  540. #if OLYMPIC_DEBUG 
  541. printk("# of rx buffers: %d, RXENQ: %xn",i, readw(olympic_mmio+RXENQ));
  542. printk("RXCSA: %x, rx_status_ring[0]: %pn",readl(olympic_mmio+RXCSA),&olympic_priv->olympic_rx_status_ring[0]);
  543. printk(" stat_ring[1]: %p, stat_ring[2]: %p, stat_ring[3]: %pn", &(olympic_priv->olympic_rx_status_ring[1]), &(olympic_priv->olympic_rx_status_ring[2]), &(olympic_priv->olympic_rx_status_ring[3]) );
  544. printk(" stat_ring[4]: %p, stat_ring[5]: %p, stat_ring[6]: %pn", &(olympic_priv->olympic_rx_status_ring[4]), &(olympic_priv->olympic_rx_status_ring[5]), &(olympic_priv->olympic_rx_status_ring[6]) );
  545. printk(" stat_ring[7]: %pn", &(olympic_priv->olympic_rx_status_ring[7])  );
  546. printk("RXCDA: %x, rx_ring[0]: %pn",readl(olympic_mmio+RXCDA),&olympic_priv->olympic_rx_ring[0]);
  547. printk("Rx_ring_dma_addr = %08x, rx_status_dma_addr =
  548. %08xn",olympic_priv->rx_ring_dma_addr,olympic_priv->rx_status_ring_dma_addr) ; 
  549. #endif
  550. writew((((readw(olympic_mmio+RXENQ)) & 0x8000) ^ 0x8000) | i,olympic_mmio+RXENQ);
  551. #if OLYMPIC_DEBUG 
  552. printk("# of rx buffers: %d, RXENQ: %xn",i, readw(olympic_mmio+RXENQ));
  553. printk("RXCSA: %x, rx_ring[0]: %pn",readl(olympic_mmio+RXCSA),&olympic_priv->olympic_rx_status_ring[0]);
  554. printk("RXCDA: %x, rx_ring[0]: %pn",readl(olympic_mmio+RXCDA),&olympic_priv->olympic_rx_ring[0]);
  555. #endif 
  556. writel(SISR_RX_STATUS | SISR_RX_NOBUF,olympic_mmio+SISR_MASK_SUM);
  557. /* setup tx ring */
  558. writel(BMCTL_TX1_DIS,olympic_mmio+BMCTL_RWM); /* Yes, this enables TX channel 1 */
  559. for(i=0;i<OLYMPIC_TX_RING_SIZE;i++) 
  560. olympic_priv->olympic_tx_ring[i].buffer=0xdeadbeef;
  561. olympic_priv->free_tx_ring_entries=OLYMPIC_TX_RING_SIZE;
  562. olympic_priv->tx_ring_dma_addr = pci_map_single(olympic_priv->pdev,olympic_priv->olympic_tx_ring,
  563.  sizeof(struct olympic_tx_desc) * OLYMPIC_TX_RING_SIZE,PCI_DMA_TODEVICE) ; 
  564. writel(olympic_priv->tx_ring_dma_addr, olympic_mmio+TXDESCQ_1);
  565. writel(olympic_priv->tx_ring_dma_addr, olympic_mmio+TXCDA_1);
  566. writew(OLYMPIC_TX_RING_SIZE, olympic_mmio+TXDESCQCNT_1);
  567. olympic_priv->tx_status_ring_dma_addr = pci_map_single(olympic_priv->pdev, olympic_priv->olympic_tx_status_ring,
  568. sizeof(struct olympic_tx_status) * OLYMPIC_TX_RING_SIZE, PCI_DMA_FROMDEVICE);
  569. writel(olympic_priv->tx_status_ring_dma_addr,olympic_mmio+TXSTATQ_1);
  570. writel(olympic_priv->tx_status_ring_dma_addr,olympic_mmio+TXCSA_1);
  571. writew(OLYMPIC_TX_RING_SIZE,olympic_mmio+TXSTATQCNT_1);
  572. olympic_priv->tx_ring_free=0; /* next entry in tx ring to use */
  573. olympic_priv->tx_ring_last_status=OLYMPIC_TX_RING_SIZE-1; /* last processed tx status */
  574. writel(0xffffffff, olympic_mmio+EISR_RWM) ; /* clean the eisr */
  575. writel(0,olympic_mmio+EISR) ; 
  576. writel(EISR_MASK_OPTIONS,olympic_mmio+EISR_MASK) ; /* enables most of the TX error interrupts */
  577. writel(SISR_TX1_EOF | SISR_ADAPTER_CHECK | SISR_ARB_CMD | SISR_TRB_REPLY | SISR_ASB_FREE | SISR_ERR,olympic_mmio+SISR_MASK_SUM);
  578. #if OLYMPIC_DEBUG 
  579. printk("BMCTL: %xn",readl(olympic_mmio+BMCTL_SUM));
  580. printk("SISR MASK: %xn",readl(olympic_mmio+SISR_MASK));
  581. #endif
  582. if (olympic_priv->olympic_network_monitor) { 
  583. u8 *oat ; 
  584. u8 *opt ; 
  585. oat = (u8 *)(olympic_priv->olympic_lap + olympic_priv->olympic_addr_table_addr) ; 
  586. opt = (u8 *)(olympic_priv->olympic_lap + olympic_priv->olympic_parms_addr) ; 
  587. printk("%s: Node Address: %02x:%02x:%02x:%02x:%02x:%02xn",dev->name, 
  588. readb(oat+offsetof(struct olympic_adapter_addr_table,node_addr)), 
  589. readb(oat+offsetof(struct olympic_adapter_addr_table,node_addr)+1),
  590. readb(oat+offsetof(struct olympic_adapter_addr_table,node_addr)+2),
  591. readb(oat+offsetof(struct olympic_adapter_addr_table,node_addr)+3),
  592. readb(oat+offsetof(struct olympic_adapter_addr_table,node_addr)+4),
  593. readb(oat+offsetof(struct olympic_adapter_addr_table,node_addr)+5));
  594. printk("%s: Functional Address: %02x:%02x:%02x:%02xn",dev->name, 
  595. readb(oat+offsetof(struct olympic_adapter_addr_table,func_addr)), 
  596. readb(oat+offsetof(struct olympic_adapter_addr_table,func_addr)+1),
  597. readb(oat+offsetof(struct olympic_adapter_addr_table,func_addr)+2),
  598. readb(oat+offsetof(struct olympic_adapter_addr_table,func_addr)+3));
  599. printk("%s: NAUN Address: %02x:%02x:%02x:%02x:%02x:%02xn",dev->name, 
  600. readb(opt+offsetof(struct olympic_parameters_table, up_node_addr)),
  601. readb(opt+offsetof(struct olympic_parameters_table, up_node_addr)+1),
  602. readb(opt+offsetof(struct olympic_parameters_table, up_node_addr)+2),
  603. readb(opt+offsetof(struct olympic_parameters_table, up_node_addr)+3),
  604. readb(opt+offsetof(struct olympic_parameters_table, up_node_addr)+4),
  605. readb(opt+offsetof(struct olympic_parameters_table, up_node_addr)+5));
  606. }
  607. netif_start_queue(dev);
  608. return 0;
  609. }
  610. /*
  611.  * When we enter the rx routine we do not know how many frames have been 
  612.  * queued on the rx channel.  Therefore we start at the next rx status
  613.  * position and travel around the receive ring until we have completed
  614.  * all the frames.
  615.  *
  616.  * This means that we may process the frame before we receive the end
  617.  * of frame interrupt. This is why we always test the status instead
  618.  * of blindly processing the next frame.
  619.  *
  620.  * We also remove the last 4 bytes from the packet as well, these are
  621.  * just token ring trailer info and upset protocols that don't check 
  622.  * their own length, i.e. SNA. 
  623.  *
  624.  */
  625. static void olympic_rx(struct net_device *dev)
  626. {
  627. struct olympic_private *olympic_priv=(struct olympic_private *)dev->priv;
  628. u8 *olympic_mmio=olympic_priv->olympic_mmio;
  629. struct olympic_rx_status *rx_status;
  630. struct olympic_rx_desc *rx_desc ; 
  631. int rx_ring_last_received,length, buffer_cnt, cpy_length, frag_len;
  632. struct sk_buff *skb, *skb2;
  633. int i;
  634. rx_status=&(olympic_priv->olympic_rx_status_ring[(olympic_priv->rx_status_last_received + 1) & (OLYMPIC_RX_RING_SIZE - 1)]) ; 
  635.  
  636. while (rx_status->status_buffercnt) { 
  637.                 u32 l_status_buffercnt;
  638. olympic_priv->rx_status_last_received++ ;
  639. olympic_priv->rx_status_last_received &= (OLYMPIC_RX_RING_SIZE -1);
  640. #if OLYMPIC_DEBUG
  641. printk("rx status: %x rx len: %x n", le32_to_cpu(rx_status->status_buffercnt), le32_to_cpu(rx_status->fragmentcnt_framelen));
  642. #endif
  643. length = le32_to_cpu(rx_status->fragmentcnt_framelen) & 0xffff;
  644. buffer_cnt = le32_to_cpu(rx_status->status_buffercnt) & 0xffff; 
  645. i = buffer_cnt ; /* Need buffer_cnt later for rxenq update */ 
  646. frag_len = le32_to_cpu(rx_status->fragmentcnt_framelen) >> 16; 
  647. #if OLYMPIC_DEBUG 
  648. printk("length: %x, frag_len: %x, buffer_cnt: %xn", length, frag_len, buffer_cnt);
  649. #endif
  650.                 l_status_buffercnt = le32_to_cpu(rx_status->status_buffercnt);
  651. if(l_status_buffercnt & 0xC0000000) {
  652. if (l_status_buffercnt & 0x3B000000) {
  653. if (olympic_priv->olympic_message_level) {
  654. if (l_status_buffercnt & (1<<29))  /* Rx Frame Truncated */
  655. printk(KERN_WARNING "%s: Rx Frame Truncated n",dev->name);
  656. if (l_status_buffercnt & (1<<28)) /*Rx receive overrun */
  657. printk(KERN_WARNING "%s: Rx Frame Receive overrun n",dev->name);
  658. if (l_status_buffercnt & (1<<27)) /* No receive buffers */
  659. printk(KERN_WARNING "%s: No receive buffers n",dev->name);
  660. if (l_status_buffercnt & (1<<25)) /* Receive frame error detect */
  661. printk(KERN_WARNING "%s: Receive frame error detect n",dev->name);
  662. if (l_status_buffercnt & (1<<24)) /* Received Error Detect */
  663. printk(KERN_WARNING "%s: Received Error Detect n",dev->name);
  664. olympic_priv->rx_ring_last_received += i ; 
  665. olympic_priv->rx_ring_last_received &= (OLYMPIC_RX_RING_SIZE -1) ; 
  666. olympic_priv->olympic_stats.rx_errors++;  
  667. } else {
  668. if (buffer_cnt == 1) {
  669. skb = dev_alloc_skb(max_t(int, olympic_priv->pkt_buf_sz,length)) ; 
  670. } else {
  671. skb = dev_alloc_skb(length) ; 
  672. }
  673. if (skb == NULL) {
  674. printk(KERN_WARNING "%s: Not enough memory to copy packet to upper layers. n",dev->name) ;
  675. olympic_priv->olympic_stats.rx_dropped++ ; 
  676. /* Update counters even though we don't transfer the frame */
  677. olympic_priv->rx_ring_last_received += i ; 
  678. olympic_priv->rx_ring_last_received &= (OLYMPIC_RX_RING_SIZE -1) ;  
  679. } else  {
  680. skb->dev = dev ; 
  681. /* Optimise based upon number of buffers used. 
  682.            If only one buffer is used we can simply swap the buffers around.
  683.            If more than one then we must use the new buffer and copy the information
  684.            first. Ideally all frames would be in a single buffer, this can be tuned by
  685.                                        altering the buffer size. If the length of the packet is less than
  686.    1500 bytes we're going to copy it over anyway to stop packets getting
  687.    dropped from sockets with buffers smaller than our pkt_buf_sz. */
  688.   if (buffer_cnt==1) {
  689. olympic_priv->rx_ring_last_received++ ; 
  690. olympic_priv->rx_ring_last_received &= (OLYMPIC_RX_RING_SIZE -1);
  691. rx_ring_last_received = olympic_priv->rx_ring_last_received ;
  692. if (length > 1500) { 
  693. skb2=olympic_priv->rx_ring_skb[rx_ring_last_received] ; 
  694. /* unmap buffer */
  695. pci_unmap_single(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_put(skb2,length-4);
  699. skb2->protocol = tr_type_trans(skb2,dev);
  700. olympic_priv->olympic_rx_ring[rx_ring_last_received].buffer = 
  701. cpu_to_le32(pci_map_single(olympic_priv->pdev, skb->data, 
  702. olympic_priv->pkt_buf_sz, PCI_DMA_FROMDEVICE));
  703. olympic_priv->olympic_rx_ring[rx_ring_last_received].res_length = 
  704. cpu_to_le32(olympic_priv->pkt_buf_sz); 
  705. olympic_priv->rx_ring_skb[rx_ring_last_received] = skb ; 
  706. netif_rx(skb2) ; 
  707. } else { 
  708. pci_dma_sync_single(olympic_priv->pdev,
  709. le32_to_cpu(olympic_priv->olympic_rx_ring[rx_ring_last_received].buffer),
  710. olympic_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE) ; 
  711. memcpy(skb_put(skb,length-4),olympic_priv->rx_ring_skb[rx_ring_last_received]->data,length-4) ; 
  712. skb->protocol = tr_type_trans(skb,dev) ; 
  713. netif_rx(skb) ; 
  714. } else {
  715. do { /* Walk the buffers */ 
  716. olympic_priv->rx_ring_last_received++ ; 
  717. olympic_priv->rx_ring_last_received &= (OLYMPIC_RX_RING_SIZE -1);
  718. rx_ring_last_received = olympic_priv->rx_ring_last_received ; 
  719. pci_dma_sync_single(olympic_priv->pdev,
  720. le32_to_cpu(olympic_priv->olympic_rx_ring[rx_ring_last_received].buffer),
  721. olympic_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE) ; 
  722. rx_desc = &(olympic_priv->olympic_rx_ring[rx_ring_last_received]);
  723. cpy_length = (i == 1 ? frag_len : le32_to_cpu(rx_desc->res_length)); 
  724. memcpy(skb_put(skb, cpy_length), olympic_priv->rx_ring_skb[rx_ring_last_received]->data, cpy_length) ;
  725. } while (--i) ; 
  726. skb_trim(skb,skb->len-4) ; 
  727. skb->protocol = tr_type_trans(skb,dev);
  728. netif_rx(skb) ; 
  729. dev->last_rx = jiffies ; 
  730. olympic_priv->olympic_stats.rx_packets++ ; 
  731. olympic_priv->olympic_stats.rx_bytes += length ; 
  732. } /* if skb == null */
  733. } /* If status & 0x3b */
  734. } else { /*if buffercnt & 0xC */
  735. olympic_priv->rx_ring_last_received += i ; 
  736. olympic_priv->rx_ring_last_received &= (OLYMPIC_RX_RING_SIZE - 1) ; 
  737. rx_status->fragmentcnt_framelen = 0 ; 
  738. rx_status->status_buffercnt = 0 ; 
  739. rx_status = &(olympic_priv->olympic_rx_status_ring[(olympic_priv->rx_status_last_received+1) & (OLYMPIC_RX_RING_SIZE -1) ]);
  740. writew((((readw(olympic_mmio+RXENQ)) & 0x8000) ^ 0x8000) |  buffer_cnt , olympic_mmio+RXENQ); 
  741. } /* while */
  742. }
  743. static void olympic_freemem(struct net_device *dev) 
  744. struct olympic_private *olympic_priv=(struct olympic_private *)dev->priv;
  745. int i;
  746. for(i=0;i<OLYMPIC_RX_RING_SIZE;i++) {
  747. dev_kfree_skb_irq(olympic_priv->rx_ring_skb[olympic_priv->rx_status_last_received]);
  748. if (olympic_priv->olympic_rx_ring[olympic_priv->rx_status_last_received].buffer != 0xdeadbeef) {
  749. pci_unmap_single(olympic_priv->pdev, 
  750. le32_to_cpu(olympic_priv->olympic_rx_ring[olympic_priv->rx_status_last_received].buffer),
  751. olympic_priv->pkt_buf_sz, PCI_DMA_FROMDEVICE);
  752. }
  753. olympic_priv->rx_status_last_received++;
  754. olympic_priv->rx_status_last_received&=OLYMPIC_RX_RING_SIZE-1;
  755. }
  756. /* unmap rings */
  757. pci_unmap_single(olympic_priv->pdev, olympic_priv->rx_status_ring_dma_addr, 
  758. sizeof(struct olympic_rx_status) * OLYMPIC_RX_RING_SIZE, PCI_DMA_FROMDEVICE);
  759. pci_unmap_single(olympic_priv->pdev, olympic_priv->rx_ring_dma_addr,
  760. sizeof(struct olympic_rx_desc) * OLYMPIC_RX_RING_SIZE, PCI_DMA_TODEVICE);
  761. pci_unmap_single(olympic_priv->pdev, olympic_priv->tx_status_ring_dma_addr, 
  762. sizeof(struct olympic_tx_status) * OLYMPIC_TX_RING_SIZE, PCI_DMA_FROMDEVICE);
  763. pci_unmap_single(olympic_priv->pdev, olympic_priv->tx_ring_dma_addr, 
  764. sizeof(struct olympic_tx_desc) * OLYMPIC_TX_RING_SIZE, PCI_DMA_TODEVICE);
  765. return ; 
  766. }
  767.  
  768. static void olympic_interrupt(int irq, void *dev_id, struct pt_regs *regs) 
  769. {
  770. struct net_device *dev= (struct net_device *)dev_id;
  771. struct olympic_private *olympic_priv=(struct olympic_private *)dev->priv;
  772. u8 *olympic_mmio=olympic_priv->olympic_mmio;
  773. u32 sisr;
  774. u8 *adapter_check_area ; 
  775. /* 
  776.  *  Read sisr but don't reset it yet. 
  777.  *  The indication bit may have been set but the interrupt latch
  778.  *  bit may not be set, so we'd lose the interrupt later. 
  779.  */ 
  780. sisr=readl(olympic_mmio+SISR) ; 
  781. if (!(sisr & SISR_MI)) /* Interrupt isn't for us */ 
  782. return ;
  783. sisr=readl(olympic_mmio+SISR_RR) ;  /* Read & Reset sisr */ 
  784. spin_lock(&olympic_priv->olympic_lock);
  785. /* Hotswap gives us this on removal */
  786. if (sisr == 0xffffffff) { 
  787. printk(KERN_WARNING "%s: Hotswap adapter removal.n",dev->name) ; 
  788. olympic_freemem(dev) ; 
  789. free_irq(dev->irq, dev) ;
  790. dev->stop = NULL ;  
  791. spin_unlock(&olympic_priv->olympic_lock) ; 
  792. return ;
  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=%08xn",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. olympic_freemem(dev) ; 
  803. free_irq(dev->irq, dev) ;
  804. dev->stop = NULL ;  
  805. spin_unlock(&olympic_priv->olympic_lock) ; 
  806. return ;
  807. } /* SISR_ERR */
  808. if(sisr & SISR_SRB_REPLY) {
  809. if(olympic_priv->srb_queued==1) {
  810. wake_up_interruptible(&olympic_priv->srb_wait);
  811. } else if (olympic_priv->srb_queued==2) { 
  812. olympic_srb_bh(dev) ; 
  813. }
  814. olympic_priv->srb_queued=0;
  815. } /* SISR_SRB_REPLY */
  816. /* We shouldn't ever miss the Tx interrupt, but the you never know, hence the loop to ensure
  817.    we get all tx completions. */
  818. if (sisr & SISR_TX1_EOF) {
  819. while(olympic_priv->olympic_tx_status_ring[(olympic_priv->tx_ring_last_status + 1) & (OLYMPIC_TX_RING_SIZE-1)].status) { 
  820. olympic_priv->tx_ring_last_status++;
  821. olympic_priv->tx_ring_last_status &= (OLYMPIC_TX_RING_SIZE-1);
  822. olympic_priv->free_tx_ring_entries++;
  823. olympic_priv->olympic_stats.tx_bytes += olympic_priv->tx_ring_skb[olympic_priv->tx_ring_last_status]->len;
  824. olympic_priv->olympic_stats.tx_packets++ ; 
  825. pci_unmap_single(olympic_priv->pdev, 
  826. le32_to_cpu(olympic_priv->olympic_tx_ring[olympic_priv->tx_ring_last_status].buffer), 
  827. olympic_priv->tx_ring_skb[olympic_priv->tx_ring_last_status]->len,PCI_DMA_TODEVICE);
  828. dev_kfree_skb_irq(olympic_priv->tx_ring_skb[olympic_priv->tx_ring_last_status]);
  829. olympic_priv->olympic_tx_ring[olympic_priv->tx_ring_last_status].buffer=0xdeadbeef;
  830. olympic_priv->olympic_tx_status_ring[olympic_priv->tx_ring_last_status].status=0;
  831. }
  832. netif_wake_queue(dev);
  833. } /* SISR_TX1_EOF */
  834. if (sisr & SISR_RX_STATUS) {
  835. olympic_rx(dev);
  836. } /* SISR_RX_STATUS */
  837. if (sisr & SISR_ADAPTER_CHECK) {
  838. netif_stop_queue(dev);
  839. printk(KERN_WARNING "%s: Adapter Check Interrupt Raised, 8 bytes of information follow:n", dev->name);
  840. writel(readl(olympic_mmio+LAPWWC),olympic_mmio+LAPA);
  841. adapter_check_area = olympic_priv->olympic_lap + ((readl(olympic_mmio+LAPWWC)) & (~0xf800)) ;
  842. printk(KERN_WARNING "%s: Bytes %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02xn",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)) ; 
  843. olympic_freemem(dev) ;
  844. free_irq(dev->irq, dev) ;
  845. dev->stop = NULL ;  
  846. spin_unlock(&olympic_priv->olympic_lock) ; 
  847. return ; 
  848. } /* SISR_ADAPTER_CHECK */
  849. if (sisr & SISR_ASB_FREE) {
  850. /* Wake up anything that is waiting for the asb response */  
  851. if (olympic_priv->asb_queued) {
  852. olympic_asb_bh(dev) ; 
  853. }
  854. } /* SISR_ASB_FREE */
  855. if (sisr & SISR_ARB_CMD) {
  856. olympic_arb_cmd(dev) ; 
  857. } /* SISR_ARB_CMD */
  858. if (sisr & SISR_TRB_REPLY) {
  859. /* Wake up anything that is waiting for the trb response */
  860. if (olympic_priv->trb_queued) {
  861. wake_up_interruptible(&olympic_priv->trb_wait);
  862. }
  863. olympic_priv->trb_queued = 0 ; 
  864. } /* SISR_TRB_REPLY */
  865. if (sisr & SISR_RX_NOBUF) {
  866. /* According to the documentation, we don't have to do anything, but trapping it keeps it out of
  867.                           /var/log/messages.  */
  868. } /* SISR_RX_NOBUF */
  869. } else { 
  870. printk(KERN_WARNING "%s: Unexpected interrupt: %xn",dev->name, sisr);
  871. printk(KERN_WARNING "%s: SISR_MASK: %xn",dev->name, readl(olympic_mmio+SISR_MASK)) ;
  872. } /* One if the interrupts we want */
  873. writel(SISR_MI,olympic_mmio+SISR_MASK_SUM);
  874. spin_unlock(&olympic_priv->olympic_lock) ; 
  875. }
  876. static int olympic_xmit(struct sk_buff *skb, struct net_device *dev) 
  877. {
  878. struct olympic_private *olympic_priv=(struct olympic_private *)dev->priv;
  879. u8 *olympic_mmio=olympic_priv->olympic_mmio;
  880. unsigned long flags ; 
  881. spin_lock_irqsave(&olympic_priv->olympic_lock, flags);
  882. netif_stop_queue(dev);
  883. if(olympic_priv->free_tx_ring_entries) {
  884. olympic_priv->olympic_tx_ring[olympic_priv->tx_ring_free].buffer = 
  885. cpu_to_le32(pci_map_single(olympic_priv->pdev, skb->data, skb->len,PCI_DMA_TODEVICE));
  886. olympic_priv->olympic_tx_ring[olympic_priv->tx_ring_free].status_length = cpu_to_le32(skb->len | (0x80000000));
  887. olympic_priv->tx_ring_skb[olympic_priv->tx_ring_free]=skb;
  888. olympic_priv->free_tx_ring_entries--;
  889.          olympic_priv->tx_ring_free++;
  890.          olympic_priv->tx_ring_free &= (OLYMPIC_TX_RING_SIZE-1);
  891. writew((((readw(olympic_mmio+TXENQ_1)) & 0x8000) ^ 0x8000) | 1,olympic_mmio+TXENQ_1);
  892. netif_wake_queue(dev);
  893. spin_unlock_irqrestore(&olympic_priv->olympic_lock,flags);
  894. return 0;
  895. } else {
  896. spin_unlock_irqrestore(&olympic_priv->olympic_lock,flags);
  897. return 1;
  898. }
  899. static int olympic_close(struct net_device *dev) 
  900. {
  901. struct olympic_private *olympic_priv=(struct olympic_private *)dev->priv;
  902.      u8 *olympic_mmio=olympic_priv->olympic_mmio,*srb;
  903. unsigned long t,flags;
  904. DECLARE_WAITQUEUE(wait,current) ; 
  905. netif_stop_queue(dev);
  906. writel(olympic_priv->srb,olympic_mmio+LAPA);
  907. srb=olympic_priv->olympic_lap + (olympic_priv->srb & (~0xf800));
  908.      writeb(SRB_CLOSE_ADAPTER,srb+0);
  909. writeb(0,srb+1);
  910. writeb(OLYMPIC_CLEAR_RET_CODE,srb+2);
  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. t = jiffies ; 
  916. add_wait_queue(&olympic_priv->srb_wait,&wait) ;
  917. set_current_state(TASK_INTERRUPTIBLE) ; 
  918. while(olympic_priv->srb_queued) {
  919. schedule() ; 
  920.          if(signal_pending(current)) {            
  921. printk(KERN_WARNING "%s: SRB timed out.n",dev->name);
  922.              printk(KERN_WARNING "SISR=%x MISR=%xn",readl(olympic_mmio+SISR),readl(olympic_mmio+LISR));
  923.              olympic_priv->srb_queued=0;
  924.              break;
  925.          }
  926. if ((jiffies-t) > 60*HZ) { 
  927. printk(KERN_WARNING "%s: SRB timed out. May not be fatal. n",dev->name) ; 
  928. olympic_priv->srb_queued=0;
  929. break ; 
  930. set_current_state(TASK_INTERRUPTIBLE) ; 
  931.      }
  932. remove_wait_queue(&olympic_priv->srb_wait,&wait) ; 
  933. set_current_state(TASK_RUNNING) ; 
  934. olympic_priv->rx_status_last_received++;
  935. olympic_priv->rx_status_last_received&=OLYMPIC_RX_RING_SIZE-1;
  936. olympic_freemem(dev) ; 
  937. /* reset tx/rx fifo's and busmaster logic */
  938. writel(readl(olympic_mmio+BCTL)|(3<<13),olympic_mmio+BCTL);
  939. udelay(1);
  940. writel(readl(olympic_mmio+BCTL)&~(3<<13),olympic_mmio+BCTL);
  941. #if OLYMPIC_DEBUG
  942. {
  943. int i ; 
  944. printk("srb(%p): ",srb);
  945. for(i=0;i<4;i++)
  946. printk("%x ",readb(srb+i));
  947. printk("n");
  948. }
  949. #endif
  950. free_irq(dev->irq,dev);
  951. return 0;
  952. }
  953. static void olympic_set_rx_mode(struct net_device *dev) 
  954. {
  955. struct olympic_private *olympic_priv = (struct olympic_private *) dev->priv ; 
  956.     u8 *olympic_mmio = olympic_priv->olympic_mmio ; 
  957. u8 options = 0; 
  958. u8 *srb;
  959. struct dev_mc_list *dmi ; 
  960. unsigned char dev_mc_address[4] ; 
  961. int i ; 
  962. writel(olympic_priv->srb,olympic_mmio+LAPA);
  963. srb=olympic_priv->olympic_lap + (olympic_priv->srb & (~0xf800));
  964. options = olympic_priv->olympic_copy_all_options; 
  965. if (dev->flags&IFF_PROMISC)  
  966. options |= 0x61 ;
  967. else
  968. options &= ~0x61 ; 
  969. /* Only issue the srb if there is a change in options */
  970. if ((options ^ olympic_priv->olympic_copy_all_options)) { 
  971. /* Now to issue the srb command to alter the copy.all.options */
  972. writeb(SRB_MODIFY_RECEIVE_OPTIONS,srb);
  973. writeb(0,srb+1);
  974. writeb(OLYMPIC_CLEAR_RET_CODE,srb+2);
  975. writeb(0,srb+3);
  976. writeb(olympic_priv->olympic_receive_options,srb+4);
  977. writeb(options,srb+5);
  978. olympic_priv->srb_queued=2; /* Can't sleep, use srb_bh */
  979. writel(LISR_SRB_CMD,olympic_mmio+LISR_SUM);
  980. olympic_priv->olympic_copy_all_options = options ;
  981. return ;  
  982. /* Set the functional addresses we need for multicast */
  983. dev_mc_address[0] = dev_mc_address[1] = dev_mc_address[2] = dev_mc_address[3] = 0 ; 
  984. for (i=0,dmi=dev->mc_list;i < dev->mc_count; i++,dmi = dmi->next) { 
  985. dev_mc_address[0] |= dmi->dmi_addr[2] ; 
  986. dev_mc_address[1] |= dmi->dmi_addr[3] ; 
  987. dev_mc_address[2] |= dmi->dmi_addr[4] ; 
  988. dev_mc_address[3] |= dmi->dmi_addr[5] ; 
  989. }
  990. writeb(SRB_SET_FUNC_ADDRESS,srb+0);
  991. writeb(0,srb+1);
  992. writeb(OLYMPIC_CLEAR_RET_CODE,srb+2);
  993. writeb(0,srb+3);
  994. writeb(0,srb+4);
  995. writeb(0,srb+5);
  996. writeb(dev_mc_address[0],srb+6);
  997. writeb(dev_mc_address[1],srb+7);
  998. writeb(dev_mc_address[2],srb+8);
  999. writeb(dev_mc_address[3],srb+9);
  1000. olympic_priv->srb_queued = 2 ;
  1001. writel(LISR_SRB_CMD,olympic_mmio+LISR_SUM);
  1002. }
  1003. static void olympic_srb_bh(struct net_device *dev) 
  1004. struct olympic_private *olympic_priv = (struct olympic_private *) dev->priv ; 
  1005.     u8 *olympic_mmio = olympic_priv->olympic_mmio ; 
  1006. u8 *srb;
  1007. writel(olympic_priv->srb,olympic_mmio+LAPA);
  1008. srb=olympic_priv->olympic_lap + (olympic_priv->srb & (~0xf800));
  1009. switch (readb(srb)) { 
  1010. /* SRB_MODIFY_RECEIVE_OPTIONS i.e. set_multicast_list options (promiscuous) 
  1011.                  * At some point we should do something if we get an error, such as
  1012.                  * resetting the IFF_PROMISC flag in dev
  1013.  */
  1014. case SRB_MODIFY_RECEIVE_OPTIONS:
  1015. switch (readb(srb+2)) { 
  1016. case 0x01:
  1017. printk(KERN_WARNING "%s: Unrecognized srb commandn",dev->name) ; 
  1018. break ; 
  1019. case 0x04:
  1020. printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!n",dev->name);
  1021. break ; 
  1022. default:
  1023. if (olympic_priv->olympic_message_level) 
  1024. printk(KERN_WARNING "%s: Receive Options Modified to %x,%xn",dev->name,olympic_priv->olympic_copy_all_options, olympic_priv->olympic_receive_options) ; 
  1025. break ; 
  1026. } /* switch srb[2] */ 
  1027. break ;
  1028. /* SRB_SET_GROUP_ADDRESS - Multicast group setting 
  1029.                  */
  1030. case SRB_SET_GROUP_ADDRESS:
  1031. switch (readb(srb+2)) { 
  1032. case 0x00:
  1033. break ; 
  1034. case 0x01:
  1035. printk(KERN_WARNING "%s: Unrecognized srb command n",dev->name) ; 
  1036. break ;
  1037. case 0x04:
  1038. printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!n",dev->name); 
  1039. break ;
  1040. case 0x3c:
  1041. printk(KERN_WARNING "%s: Group/Functional address indicator bits not set correctlyn",dev->name) ; 
  1042. break ;
  1043. case 0x3e: /* If we ever implement individual multicast addresses, will need to deal with this */
  1044. printk(KERN_WARNING "%s: Group address registers fulln",dev->name) ; 
  1045. break ;  
  1046. case 0x55:
  1047. printk(KERN_INFO "%s: Group Address already set.n",dev->name) ; 
  1048. break ;
  1049. default:
  1050. break ; 
  1051. } /* switch srb[2] */ 
  1052. break ; 
  1053. /* SRB_RESET_GROUP_ADDRESS - Remove a multicast address from group list
  1054.    */
  1055. case SRB_RESET_GROUP_ADDRESS:
  1056. switch (readb(srb+2)) { 
  1057. case 0x00:
  1058. break ; 
  1059. case 0x01:
  1060. printk(KERN_WARNING "%s: Unrecognized srb command n",dev->name) ; 
  1061. break ; 
  1062. case 0x04:
  1063. printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!n",dev->name) ; 
  1064. break ; 
  1065. case 0x39: /* Must deal with this if individual multicast addresses used */
  1066. printk(KERN_INFO "%s: Group address not found n",dev->name); 
  1067. break ;
  1068. default:
  1069. break ; 
  1070. } /* switch srb[2] */
  1071. break ; 
  1072. /* SRB_SET_FUNC_ADDRESS - Called by the set_rx_mode 
  1073.  */
  1074. case SRB_SET_FUNC_ADDRESS:
  1075. switch (readb(srb+2)) { 
  1076. case 0x00:
  1077. if (olympic_priv->olympic_message_level)
  1078. printk(KERN_INFO "%s: Functional Address Mask Set n",dev->name) ; 
  1079. break ;
  1080. case 0x01:
  1081. printk(KERN_WARNING "%s: Unrecognized srb command n",dev->name) ; 
  1082. break ; 
  1083. case 0x04:
  1084. printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!n",dev->name) ; 
  1085. break ; 
  1086. default:
  1087. break ; 
  1088. } /* switch srb[2] */
  1089. break ; 
  1090. /* SRB_READ_LOG - Read and reset the adapter error counters
  1091.    */
  1092. case SRB_READ_LOG:
  1093. switch (readb(srb+2)) { 
  1094. case 0x00: 
  1095. if (olympic_priv->olympic_message_level) 
  1096. printk(KERN_INFO "%s: Read Log issuedn",dev->name) ; 
  1097. break ; 
  1098. case 0x01:
  1099. printk(KERN_WARNING "%s: Unrecognized srb command n",dev->name) ; 
  1100. break ; 
  1101. case 0x04:
  1102. printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!n",dev->name) ; 
  1103. break ; 
  1104. } /* switch srb[2] */
  1105. break ; 
  1106. /* SRB_READ_SR_COUNTERS - Read and reset the source routing bridge related counters */
  1107. case SRB_READ_SR_COUNTERS:
  1108. switch (readb(srb+2)) { 
  1109. case 0x00: 
  1110. if (olympic_priv->olympic_message_level) 
  1111. printk(KERN_INFO "%s: Read Source Routing Counters issuedn",dev->name) ; 
  1112. break ; 
  1113. case 0x01:
  1114. printk(KERN_WARNING "%s: Unrecognized srb command n",dev->name) ; 
  1115. break ; 
  1116. case 0x04:
  1117. printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!n",dev->name) ; 
  1118. break ; 
  1119. default:
  1120. break ; 
  1121. } /* switch srb[2] */
  1122. break ;
  1123.  
  1124. default:
  1125. printk(KERN_WARNING "%s: Unrecognized srb bh return value.n",dev->name);
  1126. break ; 
  1127. } /* switch srb[0] */
  1128. static struct net_device_stats * olympic_get_stats(struct net_device *dev)
  1129. {
  1130. struct olympic_private *olympic_priv ;
  1131. olympic_priv=(struct olympic_private *) dev->priv;
  1132. return (struct net_device_stats *) &olympic_priv->olympic_stats; 
  1133. }
  1134. static int olympic_set_mac_address (struct net_device *dev, void *addr) 
  1135. {
  1136. struct sockaddr *saddr = addr ; 
  1137. struct olympic_private *olympic_priv = (struct olympic_private *)dev->priv ; 
  1138. if (netif_running(dev)) { 
  1139. printk(KERN_WARNING "%s: Cannot set mac/laa address while card is openn", dev->name) ; 
  1140. return -EIO ; 
  1141. }
  1142. memcpy(olympic_priv->olympic_laa, saddr->sa_data,dev->addr_len) ; 
  1143. if (olympic_priv->olympic_message_level) { 
  1144.   printk(KERN_INFO "%s: MAC/LAA Set to  = %x.%x.%x.%x.%x.%xn",dev->name, olympic_priv->olympic_laa[0],
  1145. olympic_priv->olympic_laa[1], olympic_priv->olympic_laa[2],
  1146. olympic_priv->olympic_laa[3], olympic_priv->olympic_laa[4],
  1147. olympic_priv->olympic_laa[5]);
  1148. return 0 ; 
  1149. }
  1150. static void olympic_arb_cmd(struct net_device *dev)
  1151. {
  1152. struct olympic_private *olympic_priv = (struct olympic_private *) dev->priv;
  1153.      u8 *olympic_mmio=olympic_priv->olympic_mmio;
  1154. u8 *arb_block, *asb_block, *srb  ; 
  1155. u8 header_len ; 
  1156. u16 frame_len, buffer_len ;
  1157. struct sk_buff *mac_frame ;  
  1158. u8 *buf_ptr ;
  1159. u8 *frame_data ;  
  1160. u16 buff_off ; 
  1161. u16 lan_status = 0, lan_status_diff  ; /* Initialize to stop compiler warning */
  1162. u8 fdx_prot_error ; 
  1163. u16 next_ptr;
  1164. int i ; 
  1165. arb_block = (u8 *)(olympic_priv->olympic_lap + olympic_priv->arb) ; 
  1166. asb_block = (u8 *)(olympic_priv->olympic_lap + olympic_priv->asb) ; 
  1167. srb = (u8 *)(olympic_priv->olympic_lap + olympic_priv->srb) ; 
  1168. if (readb(arb_block+0) == ARB_RECEIVE_DATA) { /* Receive.data, MAC frames */
  1169. header_len = readb(arb_block+8) ; /* 802.5 Token-Ring Header Length */
  1170. frame_len = swab16(readw(arb_block + 10)) ; 
  1171. buff_off = swab16(readw(arb_block + 6)) ;
  1172. buf_ptr = olympic_priv->olympic_lap + buff_off ; 
  1173. #if OLYMPIC_DEBUG
  1174. {
  1175. int i;
  1176. frame_data = buf_ptr+offsetof(struct mac_receive_buffer,frame_data) ; 
  1177. for (i=0 ;  i < 14 ; i++) { 
  1178. printk("Loc %d = %02xn",i,readb(frame_data + i)); 
  1179. }
  1180. 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))); 
  1181. }
  1182. #endif 
  1183. mac_frame = dev_alloc_skb(frame_len) ; 
  1184. if (!mac_frame) {
  1185. printk(KERN_WARNING "%s: Memory squeeze, dropping frame.n", dev->name);
  1186. goto drop_frame;
  1187. }
  1188. /* Walk the buffer chain, creating the frame */
  1189. do {
  1190. frame_data = buf_ptr+offsetof(struct mac_receive_buffer,frame_data) ; 
  1191. buffer_len = swab16(readw(buf_ptr+offsetof(struct mac_receive_buffer,buffer_length))); 
  1192. memcpy_fromio(skb_put(mac_frame, buffer_len), frame_data , buffer_len ) ;
  1193. next_ptr=readw(buf_ptr+offsetof(struct mac_receive_buffer,next)); 
  1194. } while (next_ptr && (buf_ptr=olympic_priv->olympic_lap + ntohs(next_ptr)));
  1195. if (olympic_priv->olympic_network_monitor) { 
  1196. struct trh_hdr *mac_hdr ; 
  1197. printk(KERN_WARNING "%s: Received MAC Frame, details: n",dev->name) ;
  1198. mac_hdr = (struct trh_hdr *)mac_frame->data ; 
  1199. printk(KERN_WARNING "%s: MAC Frame Dest. Addr: %02x:%02x:%02x:%02x:%02x:%02x n", dev->name , mac_hdr->daddr[0], mac_hdr->daddr[1], mac_hdr->daddr[2], mac_hdr->daddr[3], mac_hdr->daddr[4], mac_hdr->daddr[5]) ; 
  1200. printk(KERN_WARNING "%s: MAC Frame Srce. Addr: %02x:%02x:%02x:%02x:%02x:%02x n", dev->name , mac_hdr->saddr[0], mac_hdr->saddr[1], mac_hdr->saddr[2], mac_hdr->saddr[3], mac_hdr->saddr[4], mac_hdr->saddr[5]) ; 
  1201. }
  1202. mac_frame->dev = dev ; 
  1203. mac_frame->protocol = tr_type_trans(mac_frame,dev);
  1204. netif_rx(mac_frame) ; 
  1205. dev->last_rx = jiffies;
  1206. drop_frame:
  1207. /* Now tell the card we have dealt with the received frame */
  1208. /* Set LISR Bit 1 */
  1209. writel(LISR_ARB_FREE,olympic_priv->olympic_mmio + LISR_SUM);
  1210. /* Is the ASB free ? */ 
  1211. if (readb(asb_block + 2) != 0xff) { 
  1212. olympic_priv->asb_queued = 1 ; 
  1213. writel(LISR_ASB_FREE_REQ,olympic_priv->olympic_mmio+LISR_SUM); 
  1214. return ; 
  1215. /* Drop out and wait for the bottom half to be run */
  1216. }
  1217. writeb(ASB_RECEIVE_DATA,asb_block); /* Receive data */
  1218. writeb(OLYMPIC_CLEAR_RET_CODE,asb_block+2); /* Necessary ?? */
  1219. writeb(readb(arb_block+6),asb_block+6); /* Must send the address back to the adapter */
  1220. writeb(readb(arb_block+7),asb_block+7); /* To let it know we have dealt with the data */
  1221. writel(LISR_ASB_REPLY | LISR_ASB_FREE_REQ,olympic_priv->olympic_mmio+LISR_SUM);
  1222. olympic_priv->asb_queued = 2 ; 
  1223. return ; 
  1224. } else if (readb(arb_block) == ARB_LAN_CHANGE_STATUS) { /* Lan.change.status */
  1225. lan_status = swab16(readw(arb_block+6));
  1226. fdx_prot_error = readb(arb_block+8) ; 
  1227. /* Issue ARB Free */
  1228. writel(LISR_ARB_FREE,olympic_priv->olympic_mmio+LISR_SUM);
  1229. lan_status_diff = olympic_priv->olympic_lan_status ^ lan_status ; 
  1230. if (lan_status_diff & (LSC_LWF | LSC_ARW | LSC_FPE | LSC_RR) ) { 
  1231. if (lan_status_diff & LSC_LWF) 
  1232. printk(KERN_WARNING "%s: Short circuit detected on the loben",dev->name);
  1233. if (lan_status_diff & LSC_ARW) 
  1234. printk(KERN_WARNING "%s: Auto removal errorn",dev->name);
  1235. if (lan_status_diff & LSC_FPE)
  1236. printk(KERN_WARNING "%s: FDX Protocol Errorn",dev->name);
  1237. if (lan_status_diff & LSC_RR) 
  1238. printk(KERN_WARNING "%s: Force remove MAC frame receivedn",dev->name);
  1239. /* Adapter has been closed by the hardware */
  1240. /* reset tx/rx fifo's and busmaster logic */
  1241. writel(readl(olympic_mmio+BCTL)|(3<<13),olympic_mmio+BCTL);
  1242. udelay(1);
  1243. writel(readl(olympic_mmio+BCTL)&~(3<<13),olympic_mmio+BCTL);
  1244. netif_stop_queue(dev);
  1245. olympic_priv->srb = readw(olympic_priv->olympic_lap + LAPWWO) ; 
  1246. for(i=0;i<OLYMPIC_RX_RING_SIZE;i++) {
  1247. dev_kfree_skb_irq(olympic_priv->rx_ring_skb[olympic_priv->rx_status_last_received]);
  1248. if (olympic_priv->olympic_rx_ring[olympic_priv->rx_status_last_received].buffer != 0xdeadbeef) {
  1249. pci_unmap_single(olympic_priv->pdev, 
  1250. le32_to_cpu(olympic_priv->olympic_rx_ring[olympic_priv->rx_status_last_received].buffer),
  1251. olympic_priv->pkt_buf_sz, PCI_DMA_FROMDEVICE);
  1252. }
  1253. olympic_priv->rx_status_last_received++;
  1254. olympic_priv->rx_status_last_received&=OLYMPIC_RX_RING_SIZE-1;
  1255. }
  1256. /* unmap rings */
  1257. pci_unmap_single(olympic_priv->pdev, olympic_priv->rx_status_ring_dma_addr, 
  1258. sizeof(struct olympic_rx_status) * OLYMPIC_RX_RING_SIZE, PCI_DMA_FROMDEVICE);
  1259. pci_unmap_single(olympic_priv->pdev, olympic_priv->rx_ring_dma_addr,
  1260. sizeof(struct olympic_rx_desc) * OLYMPIC_RX_RING_SIZE, PCI_DMA_TODEVICE);
  1261. pci_unmap_single(olympic_priv->pdev, olympic_priv->tx_status_ring_dma_addr, 
  1262. sizeof(struct olympic_tx_status) * OLYMPIC_TX_RING_SIZE, PCI_DMA_FROMDEVICE);
  1263. pci_unmap_single(olympic_priv->pdev, olympic_priv->tx_ring_dma_addr, 
  1264. sizeof(struct olympic_tx_desc) * OLYMPIC_TX_RING_SIZE, PCI_DMA_TODEVICE);
  1265. free_irq(dev->irq,dev);
  1266. dev->stop=NULL;
  1267. printk(KERN_WARNING "%s: Adapter has been closed n", dev->name) ; 
  1268. } /* If serious error */
  1269. if (olympic_priv->olympic_message_level) { 
  1270. if (lan_status_diff & LSC_SIG_LOSS) 
  1271. printk(KERN_WARNING "%s: No receive signal detected n", dev->name) ; 
  1272. if (lan_status_diff & LSC_HARD_ERR)
  1273. printk(KERN_INFO "%s: Beaconing n",dev->name);
  1274. if (lan_status_diff & LSC_SOFT_ERR)
  1275. printk(KERN_WARNING "%s: Adapter transmitted Soft Error Report Mac Frame n",dev->name);
  1276. if (lan_status_diff & LSC_TRAN_BCN) 
  1277. printk(KERN_INFO "%s: We are tranmitting the beacon, aaahn",dev->name);
  1278. if (lan_status_diff & LSC_SS) 
  1279. printk(KERN_INFO "%s: Single Station on the ring n", dev->name);
  1280. if (lan_status_diff & LSC_RING_REC)
  1281. printk(KERN_INFO "%s: Ring recovery ongoingn",dev->name);
  1282. if (lan_status_diff & LSC_FDX_MODE)
  1283. printk(KERN_INFO "%s: Operating in FDX moden",dev->name);
  1284. if (lan_status_diff & LSC_CO) { 
  1285. if (olympic_priv->olympic_message_level) 
  1286. printk(KERN_INFO "%s: Counter Overflow n", dev->name);
  1287. /* Issue READ.LOG command */
  1288. writeb(SRB_READ_LOG, srb);
  1289. writeb(0,srb+1);
  1290. writeb(OLYMPIC_CLEAR_RET_CODE,srb+2);
  1291. writeb(0,srb+3);
  1292. writeb(0,srb+4);
  1293. writeb(0,srb+5);
  1294. olympic_priv->srb_queued=2; /* Can't sleep, use srb_bh */
  1295. writel(LISR_SRB_CMD,olympic_mmio+LISR_SUM);
  1296. }
  1297. if (lan_status_diff & LSC_SR_CO) { 
  1298. if (olympic_priv->olympic_message_level)
  1299. printk(KERN_INFO "%s: Source routing counters overflown", dev->name);
  1300. /* Issue a READ.SR.COUNTERS */
  1301. writeb(SRB_READ_SR_COUNTERS,srb);
  1302. writeb(0,srb+1);
  1303. writeb(OLYMPIC_CLEAR_RET_CODE,srb+2);
  1304. writeb(0,srb+3);
  1305. olympic_priv->srb_queued=2; /* Can't sleep, use srb_bh */
  1306. writel(LISR_SRB_CMD,olympic_mmio+LISR_SUM);
  1307. }
  1308. olympic_priv->olympic_lan_status = lan_status ; 
  1309. }  /* Lan.change.status */
  1310. else
  1311. printk(KERN_WARNING "%s: Unknown arb command n", dev->name);
  1312. }
  1313. static void olympic_asb_bh(struct net_device *dev) 
  1314. {
  1315. struct olympic_private *olympic_priv = (struct olympic_private *) dev->priv ; 
  1316. u8 *arb_block, *asb_block ; 
  1317. arb_block = (u8 *)(olympic_priv->olympic_lap + olympic_priv->arb) ; 
  1318. asb_block = (u8 *)(olympic_priv->olympic_lap + olympic_priv->asb) ; 
  1319. if (olympic_priv->asb_queued == 1) {   /* Dropped through the first time */
  1320. writeb(ASB_RECEIVE_DATA,asb_block); /* Receive data */
  1321. writeb(OLYMPIC_CLEAR_RET_CODE,asb_block+2); /* Necessary ?? */
  1322. writeb(readb(arb_block+6),asb_block+6); /* Must send the address back to the adapter */
  1323. writeb(readb(arb_block+7),asb_block+7); /* To let it know we have dealt with the data */
  1324. writel(LISR_ASB_REPLY | LISR_ASB_FREE_REQ,olympic_priv->olympic_mmio+LISR_SUM);
  1325. olympic_priv->asb_queued = 2 ; 
  1326. return ; 
  1327. }
  1328. if (olympic_priv->asb_queued == 2) { 
  1329. switch (readb(asb_block+2)) {
  1330. case 0x01:
  1331. printk(KERN_WARNING "%s: Unrecognized command code n", dev->name);
  1332. break ;
  1333. case 0x26:
  1334. printk(KERN_WARNING "%s: Unrecognized buffer address n", dev->name);
  1335. break ;
  1336. case 0xFF:
  1337. /* Valid response, everything should be ok again */
  1338. break ;
  1339. default:
  1340. printk(KERN_WARNING "%s: Invalid return code in asbn",dev->name);
  1341. break ;
  1342. }
  1343. }
  1344. olympic_priv->asb_queued = 0 ; 
  1345. }
  1346.  
  1347. static int olympic_change_mtu(struct net_device *dev, int mtu) 
  1348. {
  1349. struct olympic_private *olympic_priv = (struct olympic_private *) dev->priv;
  1350. u16 max_mtu ; 
  1351. if (olympic_priv->olympic_ring_speed == 4)
  1352. max_mtu = 4500 ; 
  1353. else
  1354. max_mtu = 18000 ; 
  1355. if (mtu > max_mtu)
  1356. return -EINVAL ; 
  1357. if (mtu < 100) 
  1358. return -EINVAL ; 
  1359. dev->mtu = mtu ; 
  1360. olympic_priv->pkt_buf_sz = mtu + TR_HLEN ; 
  1361. return 0 ; 
  1362. }
  1363. static int olympic_proc_info(char *buffer, char **start, off_t offset, int length, int *eof, void *data)
  1364. {
  1365. struct net_device *dev = (struct net_device *)data ; 
  1366. struct olympic_private *olympic_priv=(struct olympic_private *)dev->priv;
  1367. u8 *oat = (u8 *)(olympic_priv->olympic_lap + olympic_priv->olympic_addr_table_addr) ; 
  1368. u8 *opt = (u8 *)(olympic_priv->olympic_lap + olympic_priv->olympic_parms_addr) ; 
  1369. int size = 0 ; 
  1370. int len=0;
  1371. off_t begin=0;
  1372. off_t pos=0;
  1373. size = sprintf(buffer, 
  1374. "IBM Pit/Pit-Phy/Olympic Chipset Token Ring Adapter %sn",dev->name);
  1375. size += sprintf(buffer+size, "n%6s: Adapter Address   : Node Address      : Functional Addrn",
  1376.      dev->name); 
  1377. size += sprintf(buffer+size, "%6s: %02x:%02x:%02x:%02x:%02x:%02x : %02x:%02x:%02x:%02x:%02x:%02x : %02x:%02x:%02x:%02xn",
  1378.    dev->name,
  1379.            dev->dev_addr[0],
  1380.    dev->dev_addr[1],
  1381.    dev->dev_addr[2],
  1382.      dev->dev_addr[3],
  1383.    dev->dev_addr[4],
  1384.    dev->dev_addr[5],
  1385.    readb(oat+offsetof(struct olympic_adapter_addr_table,node_addr)), 
  1386.    readb(oat+offsetof(struct olympic_adapter_addr_table,node_addr)+1),
  1387.    readb(oat+offsetof(struct olympic_adapter_addr_table,node_addr)+2),
  1388.    readb(oat+offsetof(struct olympic_adapter_addr_table,node_addr)+3),
  1389.    readb(oat+offsetof(struct olympic_adapter_addr_table,node_addr)+4),
  1390.    readb(oat+offsetof(struct olympic_adapter_addr_table,node_addr)+5),
  1391.    readb(oat+offsetof(struct olympic_adapter_addr_table,func_addr)), 
  1392.    readb(oat+offsetof(struct olympic_adapter_addr_table,func_addr)+1),
  1393.    readb(oat+offsetof(struct olympic_adapter_addr_table,func_addr)+2),
  1394.    readb(oat+offsetof(struct olympic_adapter_addr_table,func_addr)+3));
  1395.  
  1396. size += sprintf(buffer+size, "n%6s: Token Ring Parameters Table:n", dev->name);
  1397. size += sprintf(buffer+size, "%6s: Physical Addr : Up Node Address   : Poll Address      : AccPri : Auth Src : Att Code :n",
  1398.   dev->name) ; 
  1399.    
  1400. size += sprintf(buffer+size, "%6s: %02x:%02x:%02x:%02x   : %02x:%02x:%02x:%02x:%02x:%02x : %02x:%02x:%02x:%02x:%02x:%02x : %04x   : %04x     :  %04x    :n",
  1401.   dev->name,
  1402.   readb(opt+offsetof(struct olympic_parameters_table, phys_addr)),
  1403.   readb(opt+offsetof(struct olympic_parameters_table, phys_addr)+1),
  1404.   readb(opt+offsetof(struct olympic_parameters_table, phys_addr)+2),
  1405.   readb(opt+offsetof(struct olympic_parameters_table, phys_addr)+3),
  1406.   readb(opt+offsetof(struct olympic_parameters_table, up_node_addr)),
  1407.   readb(opt+offsetof(struct olympic_parameters_table, up_node_addr)+1),
  1408.   readb(opt+offsetof(struct olympic_parameters_table, up_node_addr)+2),
  1409.   readb(opt+offsetof(struct olympic_parameters_table, up_node_addr)+3),
  1410.   readb(opt+offsetof(struct olympic_parameters_table, up_node_addr)+4),
  1411.   readb(opt+offsetof(struct olympic_parameters_table, up_node_addr)+5),
  1412.   readb(opt+offsetof(struct olympic_parameters_table, poll_addr)),
  1413.   readb(opt+offsetof(struct olympic_parameters_table, poll_addr)+1),
  1414.   readb(opt+offsetof(struct olympic_parameters_table, poll_addr)+2),
  1415.   readb(opt+offsetof(struct olympic_parameters_table, poll_addr)+3),
  1416.   readb(opt+offsetof(struct olympic_parameters_table, poll_addr)+4),
  1417.   readb(opt+offsetof(struct olympic_parameters_table, poll_addr)+5),
  1418.   swab16(readw(opt+offsetof(struct olympic_parameters_table, acc_priority))),
  1419.   swab16(readw(opt+offsetof(struct olympic_parameters_table, auth_source_class))),
  1420.   swab16(readw(opt+offsetof(struct olympic_parameters_table, att_code))));
  1421. size += sprintf(buffer+size, "%6s: Source Address    : Bcn T : Maj. V : Lan St : Lcl Rg : Mon Err : Frame Correl : n",
  1422.   dev->name) ; 
  1423. size += sprintf(buffer+size, "%6s: %02x:%02x:%02x:%02x:%02x:%02x : %04x  : %04x   : %04x   : %04x   : %04x    :     %04x     : n",
  1424.   dev->name,
  1425.   readb(opt+offsetof(struct olympic_parameters_table, source_addr)),
  1426.   readb(opt+offsetof(struct olympic_parameters_table, source_addr)+1),
  1427.   readb(opt+offsetof(struct olympic_parameters_table, source_addr)+2),
  1428.   readb(opt+offsetof(struct olympic_parameters_table, source_addr)+3),
  1429.   readb(opt+offsetof(struct olympic_parameters_table, source_addr)+4),
  1430.   readb(opt+offsetof(struct olympic_parameters_table, source_addr)+5),
  1431.   swab16(readw(opt+offsetof(struct olympic_parameters_table, beacon_type))),
  1432.   swab16(readw(opt+offsetof(struct olympic_parameters_table, major_vector))),
  1433.   swab16(readw(opt+offsetof(struct olympic_parameters_table, lan_status))),
  1434.   swab16(readw(opt+offsetof(struct olympic_parameters_table, local_ring))),
  1435.   swab16(readw(opt+offsetof(struct olympic_parameters_table, mon_error))),
  1436.   swab16(readw(opt+offsetof(struct olympic_parameters_table, frame_correl))));
  1437. size += sprintf(buffer+size, "%6s: Beacon Details :  Tx  :  Rx  : NAUN Node Address : NAUN Node Phys : n",
  1438.   dev->name) ; 
  1439. size += sprintf(buffer+size, "%6s:                :  %02x  :  %02x  : %02x:%02x:%02x:%02x:%02x:%02x : %02x:%02x:%02x:%02x    : n",
  1440.   dev->name,
  1441.   swab16(readw(opt+offsetof(struct olympic_parameters_table, beacon_transmit))),
  1442.   swab16(readw(opt+offsetof(struct olympic_parameters_table, beacon_receive))),
  1443.   readb(opt+offsetof(struct olympic_parameters_table, beacon_naun)),
  1444.   readb(opt+offsetof(struct olympic_parameters_table, beacon_naun)+1),
  1445.   readb(opt+offsetof(struct olympic_parameters_table, beacon_naun)+2),
  1446.   readb(opt+offsetof(struct olympic_parameters_table, beacon_naun)+3),
  1447.   readb(opt+offsetof(struct olympic_parameters_table, beacon_naun)+4),
  1448.   readb(opt+offsetof(struct olympic_parameters_table, beacon_naun)+5),
  1449.   readb(opt+offsetof(struct olympic_parameters_table, beacon_phys)),
  1450.   readb(opt+offsetof(struct olympic_parameters_table, beacon_phys)+1),
  1451.   readb(opt+offsetof(struct olympic_parameters_table, beacon_phys)+2),
  1452.   readb(opt+offsetof(struct olympic_parameters_table, beacon_phys)+3));
  1453. len=size;
  1454. pos=begin+size;
  1455. if (pos<offset) {
  1456. len=0;
  1457. begin=pos;
  1458. }
  1459. *start=buffer+(offset-begin); /* Start of wanted data */
  1460. len-=(offset-begin); /* Start slop */
  1461. if(len>length)
  1462. len=length; /* Ending slop */
  1463. return len;
  1464. }
  1465. static void __devexit olympic_remove_one(struct pci_dev *pdev) 
  1466. {
  1467. struct net_device *dev = pci_get_drvdata(pdev) ; 
  1468. struct olympic_private *olympic_priv=(struct olympic_private *)dev->priv;
  1469. if (olympic_priv->olympic_network_monitor) { 
  1470. char proc_name[20] ; 
  1471. strcpy(proc_name,"net/olympic_") ; 
  1472. strcat(proc_name,dev->name) ;
  1473. remove_proc_entry(proc_name,NULL); 
  1474. }
  1475. unregister_trdev(dev) ; 
  1476. iounmap(olympic_priv->olympic_mmio) ; 
  1477. iounmap(olympic_priv->olympic_lap) ; 
  1478. pci_release_regions(pdev) ;
  1479. pci_set_drvdata(pdev,NULL) ;  
  1480. kfree(dev) ; 
  1481. }
  1482. static struct pci_driver olympic_driver = { 
  1483. name: "olympic",
  1484. id_table: olympic_pci_tbl,
  1485. probe: olympic_probe,
  1486. remove: __devexit_p(olympic_remove_one),
  1487. };
  1488. static int __init olympic_pci_init(void) 
  1489. {
  1490. return pci_module_init (&olympic_driver) ; 
  1491. }
  1492. static void __exit olympic_pci_cleanup(void)
  1493. {
  1494. return pci_unregister_driver(&olympic_driver) ; 
  1495. }
  1496. module_init(olympic_pci_init) ; 
  1497. module_exit(olympic_pci_cleanup) ; 
  1498. MODULE_LICENSE("GPL");