olympic.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:64k
源码类别:

嵌入式Linux

开发平台:

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