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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * This file is subject to the terms and conditions of the GNU General Public
  3.  * License.  See the file "COPYING" in the main directory of this archive
  4.  * for more details.
  5.  *
  6.  * Driver for SGI's IOC3 based Ethernet cards as found in the PCI card.
  7.  *
  8.  * Copyright (C) 1999, 2000, 2001 Ralf Baechle
  9.  * Copyright (C) 1995, 1999, 2000, 2001 by Silicon Graphics, Inc.
  10.  *
  11.  * References:
  12.  *  o IOC3 ASIC specification 4.51, 1996-04-18
  13.  *  o IEEE 802.3 specification, 2000 edition
  14.  *  o DP38840A Specification, National Semiconductor, March 1997
  15.  *
  16.  * To do:
  17.  *
  18.  *  o Handle allocation failures in ioc3_alloc_skb() more gracefully.
  19.  *  o Handle allocation failures in ioc3_init_rings().
  20.  *  o Use prefetching for large packets.  What is a good lower limit for
  21.  *    prefetching?
  22.  *  o We're probably allocating a bit too much memory.
  23.  *  o Use hardware checksums.
  24.  *  o Convert to using a IOC3 meta driver.
  25.  *  o Which PHYs might possibly be attached to the IOC3 in real live,
  26.  *    which workarounds are required for them?  Do we ever have Lucent's?
  27.  *  o For the 2.5 branch kill the mii-tool ioctls.
  28.  */
  29. #include <linux/config.h>
  30. #include <linux/init.h>
  31. #include <linux/delay.h>
  32. #include <linux/kernel.h>
  33. #include <linux/mm.h>
  34. #include <linux/errno.h>
  35. #include <linux/module.h>
  36. #include <linux/pci.h>
  37. #include <linux/crc32.h>
  38. #ifdef CONFIG_SERIAL
  39. #include <linux/serial.h>
  40. #include <asm/serial.h>
  41. #define IOC3_BAUD (22000000 / (3*16))
  42. #define IOC3_COM_FLAGS (ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST)
  43. #endif
  44. #include <linux/netdevice.h>
  45. #include <linux/etherdevice.h>
  46. #include <linux/ethtool.h>
  47. #include <linux/skbuff.h>
  48. #include <linux/dp83840.h>
  49. #include <asm/byteorder.h>
  50. #include <asm/io.h>
  51. #include <asm/pgtable.h>
  52. #include <asm/uaccess.h>
  53. #include <asm/sn/types.h>
  54. #include <asm/sn/sn0/addrs.h>
  55. #include <asm/sn/sn0/hubni.h>
  56. #include <asm/sn/sn0/hubio.h>
  57. #include <asm/sn/klconfig.h>
  58. #include <asm/sn/ioc3.h>
  59. #include <asm/sn/sn0/ip27.h>
  60. #include <asm/pci/bridge.h>
  61. /*
  62.  * 64 RX buffers.  This is tunable in the range of 16 <= x < 512.  The
  63.  * value must be a power of two.
  64.  */
  65. #define RX_BUFFS 64
  66. /* Timer state engine. */
  67. enum ioc3_timer_state {
  68. arbwait  = 0, /* Waiting for auto negotiation to complete.          */
  69. lupwait  = 1, /* Auto-neg complete, awaiting link-up status.        */
  70. ltrywait = 2, /* Forcing try of all modes, from fastest to slowest. */
  71. asleep   = 3, /* Time inactive.                                     */
  72. };
  73. /* Private per NIC data of the driver.  */
  74. struct ioc3_private {
  75. struct ioc3 *regs;
  76. int phy;
  77. unsigned long *rxr; /* pointer to receiver ring */
  78. struct ioc3_etxd *txr;
  79. struct sk_buff *rx_skbs[512];
  80. struct sk_buff *tx_skbs[128];
  81. struct net_device_stats stats;
  82. int rx_ci; /* RX consumer index */
  83. int rx_pi; /* RX producer index */
  84. int tx_ci; /* TX consumer index */
  85. int tx_pi; /* TX producer index */
  86. int txqlen;
  87. u32 emcr, ehar_h, ehar_l;
  88. spinlock_t ioc3_lock;
  89. struct net_device *dev;
  90. /* Members used by autonegotiation  */
  91. struct timer_list ioc3_timer;
  92. enum ioc3_timer_state timer_state; /* State of auto-neg timer.    */
  93. unsigned int timer_ticks; /* Number of clicks at each state  */
  94. unsigned short sw_bmcr; /* sw copy of MII config register  */
  95. unsigned short sw_bmsr; /* sw copy of MII status register  */
  96. unsigned short sw_physid1; /* sw copy of PHYSID1    */
  97. unsigned short sw_physid2; /* sw copy of PHYSID2    */
  98. unsigned short sw_advertise; /* sw copy of ADVERTISE    */
  99. unsigned short sw_lpa; /* sw copy of LPA    */
  100. unsigned short sw_csconfig; /* sw copy of CSCONFIG    */
  101. };
  102. static int ioc3_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  103. static void ioc3_set_multicast_list(struct net_device *dev);
  104. static int ioc3_start_xmit(struct sk_buff *skb, struct net_device *dev);
  105. static void ioc3_timeout(struct net_device *dev);
  106. static inline unsigned int ioc3_hash(const unsigned char *addr);
  107. static inline void ioc3_stop(struct ioc3_private *ip);
  108. static void ioc3_init(struct ioc3_private *ip);
  109. static const char ioc3_str[] = "IOC3 Ethernet";
  110. /* We use this to acquire receive skb's that we can DMA directly into. */
  111. #define ALIGNED_RX_SKB_ADDR(addr) 
  112. ((((unsigned long)(addr) + (128 - 1)) & ~(128 - 1)) - (unsigned long)(addr))
  113. #define ioc3_alloc_skb(__length, __gfp_flags) 
  114. ({ struct sk_buff *__skb; 
  115. __skb = alloc_skb((__length) + 128, (__gfp_flags)); 
  116. if (__skb) { 
  117. int __offset = ALIGNED_RX_SKB_ADDR(__skb->data); 
  118. if(__offset) 
  119. skb_reserve(__skb, __offset); 
  120. __skb; 
  121. })
  122. /* BEWARE: The IOC3 documentation documents the size of rx buffers as
  123.    1644 while it's actually 1664.  This one was nasty to track down ...  */
  124. #define RX_OFFSET 10
  125. #define RX_BUF_ALLOC_SIZE (1664 + RX_OFFSET + 128)
  126. /* DMA barrier to separate cached and uncached accesses.  */
  127. #define BARRIER()
  128. __asm__("sync" ::: "memory")
  129. #define IOC3_SIZE 0x100000
  130. #define ioc3_r(reg)
  131. ({
  132. u32 __res;
  133. __res = ioc3->reg;
  134. __res;
  135. })
  136. #define ioc3_w(reg,val)
  137. do {
  138. (ioc3->reg = (val));
  139. } while(0)
  140. static inline u32
  141. mcr_pack(u32 pulse, u32 sample)
  142. {
  143. return (pulse << 10) | (sample << 2);
  144. }
  145. static int
  146. nic_wait(struct ioc3 *ioc3)
  147. {
  148. u32 mcr;
  149.         do {
  150.                 mcr = ioc3_r(mcr);
  151.         } while (!(mcr & 2));
  152.         return mcr & 1;
  153. }
  154. static int
  155. nic_reset(struct ioc3 *ioc3)
  156. {
  157.         int presence;
  158. ioc3_w(mcr, mcr_pack(500, 65));
  159. presence = nic_wait(ioc3);
  160. ioc3_w(mcr, mcr_pack(0, 500));
  161. nic_wait(ioc3);
  162.         return presence;
  163. }
  164. static inline int
  165. nic_read_bit(struct ioc3 *ioc3)
  166. {
  167. int result;
  168. ioc3_w(mcr, mcr_pack(6, 13));
  169. result = nic_wait(ioc3);
  170. ioc3_w(mcr, mcr_pack(0, 100));
  171. nic_wait(ioc3);
  172. return result;
  173. }
  174. static inline void
  175. nic_write_bit(struct ioc3 *ioc3, int bit)
  176. {
  177. if (bit)
  178. ioc3_w(mcr, mcr_pack(6, 110));
  179. else
  180. ioc3_w(mcr, mcr_pack(80, 30));
  181. nic_wait(ioc3);
  182. }
  183. /*
  184.  * Read a byte from an iButton device
  185.  */
  186. static u32
  187. nic_read_byte(struct ioc3 *ioc3)
  188. {
  189. u32 result = 0;
  190. int i;
  191. for (i = 0; i < 8; i++)
  192. result = (result >> 1) | (nic_read_bit(ioc3) << 7);
  193. return result;
  194. }
  195. /*
  196.  * Write a byte to an iButton device
  197.  */
  198. static void
  199. nic_write_byte(struct ioc3 *ioc3, int byte)
  200. {
  201. int i, bit;
  202. for (i = 8; i; i--) {
  203. bit = byte & 1;
  204. byte >>= 1;
  205. nic_write_bit(ioc3, bit);
  206. }
  207. }
  208. static u64
  209. nic_find(struct ioc3 *ioc3, int *last)
  210. {
  211. int a, b, index, disc;
  212. u64 address = 0;
  213. nic_reset(ioc3);
  214. /* Search ROM.  */
  215. nic_write_byte(ioc3, 0xf0);
  216. /* Algorithm from ``Book of iButton Standards''.  */
  217. for (index = 0, disc = 0; index < 64; index++) {
  218. a = nic_read_bit(ioc3);
  219. b = nic_read_bit(ioc3);
  220. if (a && b) {
  221. printk("NIC search failed (not fatal).n");
  222. *last = 0;
  223. return 0;
  224. }
  225. if (!a && !b) {
  226. if (index == *last) {
  227. address |= 1UL << index;
  228. } else if (index > *last) {
  229. address &= ~(1UL << index);
  230. disc = index;
  231. } else if ((address & (1UL << index)) == 0)
  232. disc = index;
  233. nic_write_bit(ioc3, address & (1UL << index));
  234. continue;
  235. } else {
  236. if (a)
  237. address |= 1UL << index;
  238. else
  239. address &= ~(1UL << index);
  240. nic_write_bit(ioc3, a);
  241. continue;
  242. }
  243. }
  244. *last = disc;
  245. return address;
  246. }
  247. static int nic_init(struct ioc3 *ioc3)
  248. {
  249. const char *type;
  250. u8 crc;
  251. u8 serial[6];
  252. int save = 0, i;
  253. type = "unknown";
  254. while (1) {
  255. u64 reg;
  256. reg = nic_find(ioc3, &save);
  257. switch (reg & 0xff) {
  258. case 0x91:
  259. type = "DS1981U";
  260. break;
  261. default:
  262. if (save == 0) {
  263. /* Let the caller try again.  */
  264. return -1;
  265. }
  266. continue;
  267. }
  268. nic_reset(ioc3);
  269. /* Match ROM.  */
  270. nic_write_byte(ioc3, 0x55);
  271. for (i = 0; i < 8; i++)
  272. nic_write_byte(ioc3, (reg >> (i << 3)) & 0xff);
  273. reg >>= 8; /* Shift out type.  */
  274. for (i = 0; i < 6; i++) {
  275. serial[i] = reg & 0xff;
  276. reg >>= 8;
  277. }
  278. crc = reg & 0xff;
  279. break;
  280. }
  281. printk("Found %s NIC", type);
  282. if (type != "unknown") {
  283. printk (" registration number %02x:%02x:%02x:%02x:%02x:%02x,"
  284. " CRC %02x", serial[0], serial[1], serial[2],
  285. serial[3], serial[4], serial[5], crc);
  286. }
  287. printk(".n");
  288. return 0;
  289. }
  290. /*
  291.  * Read the NIC (Number-In-a-Can) device used to store the MAC address on
  292.  * SN0 / SN00 nodeboards and PCI cards.
  293.  */
  294. static void ioc3_get_eaddr_nic(struct ioc3_private *ip)
  295. {
  296. struct ioc3 *ioc3 = ip->regs;
  297. u8 nic[14];
  298. int tries = 2; /* There may be some problem with the battery?  */
  299. int i;
  300. ioc3_w(gpcr_s, (1 << 21));
  301. while (tries--) {
  302. if (!nic_init(ioc3))
  303. break;
  304. udelay(500);
  305. }
  306. if (tries < 0) {
  307. printk("Failed to read MAC addressn");
  308. return;
  309. }
  310. /* Read Memory.  */
  311. nic_write_byte(ioc3, 0xf0);
  312. nic_write_byte(ioc3, 0x00);
  313. nic_write_byte(ioc3, 0x00);
  314. for (i = 13; i >= 0; i--)
  315. nic[i] = nic_read_byte(ioc3);
  316. for (i = 2; i < 8; i++)
  317. ip->dev->dev_addr[i - 2] = nic[i];
  318. }
  319. #if defined(CONFIG_IA64_SGI_SN1) || defined(CONFIG_IA64_SGI_SN2)
  320. /*
  321.  * Get the ether-address on SN1 nodes
  322.  */
  323. static void ioc3_get_eaddr_sn(struct ioc3_private *ip)
  324. {
  325. int ibrick_mac_addr_get(nasid_t, char *);
  326. struct ioc3 *ioc3 = ip->regs;
  327. nasid_t nasid_of_ioc3;
  328. char io7eaddr[20];
  329. long mac;
  330. int err_val;
  331. /*
  332.  * err_val = ibrick_mac_addr_get(get_nasid(), io7eaddr );
  333.  * 
  334.  * BAD!!  The above call uses get_nasid() and assumes that
  335.  * the ioc3 pointed to by struct ioc3 is hooked up to the
  336.  * cbrick that we're running on.  The proper way to make this call
  337.  * is to figure out which nasid the ioc3 is connected to
  338.  * and use that to call ibrick_mac_addr_get.  Below is
  339.  * a hack to do just that.
  340.  */
  341. /*
  342.  * Get the nasid of the ioc3 from the ioc3's base addr.
  343.  * FIXME: the 8 at the end assumes we're in memory mode, 
  344.  * not node mode (for that, we'd change it to a 9).
  345.  * Is there a call to extract this info from a physical
  346.  * addr somewhere in an sn header file already?  If so,
  347.  * we should probably use that, or restructure this routine
  348.  * to use pci_dev and generic numa nodeid getting stuff.
  349.  */
  350. nasid_of_ioc3 = (((unsigned long)ioc3 >> 33) & ~(-1 << 8));
  351. err_val = ibrick_mac_addr_get(nasid_of_ioc3, io7eaddr );
  352. if (err_val) {
  353. /* Couldn't read the eeprom; try OSLoadOptions. */
  354. printk("WARNING: ibrick_mac_addr_get failed: %dn", err_val);
  355. /* this is where we hardwire the mac address
  356.    * 1st ibrick had 08:00:69:11:34:75
  357.    * 2nd ibrick had 08:00:69:11:35:35
  358.    *
  359.    * Eagan Machines:
  360.    *      mankato1 08:00:69:11:BE:95
  361.    *      warroad  08:00:69:11:bd:60
  362.    *      duron    08:00:69:11:34:60
  363.    *
  364.    * an easy way to get the mac address is to hook
  365.    * up an ip35, then from L1 do 'cti serial'
  366.    * and then look for MAC line XXX THIS DOESN"T QUITE WORK!!
  367.    */
  368. printk("ioc3_get_eaddr: setting ethernet address to:n -----> ");
  369. ip->dev->dev_addr[0] = 0x8;
  370. ip->dev->dev_addr[1] = 0x0;
  371. ip->dev->dev_addr[2] = 0x69;
  372. ip->dev->dev_addr[3] = 0x11;
  373. ip->dev->dev_addr[4] = 0x34;
  374. ip->dev->dev_addr[5] = 0x60;
  375. }
  376. else {
  377. long simple_strtol(const char *,char **,unsigned int);
  378. mac = simple_strtol(io7eaddr, (char **)0, 16);
  379. ip->dev->dev_addr[0] = (mac >> 40) & 0xff;
  380. ip->dev->dev_addr[1] = (mac >> 32) & 0xff;
  381. ip->dev->dev_addr[2] = (mac >> 24) & 0xff;
  382. ip->dev->dev_addr[3] = (mac >> 16) & 0xff;
  383. ip->dev->dev_addr[4] = (mac >> 8) & 0xff;
  384. ip->dev->dev_addr[5] = mac & 0xff;
  385. }
  386. }
  387. #endif
  388. /*
  389.  * Ok, this is hosed by design.  It's necessary to know what machine the
  390.  * NIC is in in order to know how to read the NIC address.  We also have
  391.  * to know if it's a PCI card or a NIC in on the node board ...
  392.  */
  393. static void ioc3_get_eaddr(struct ioc3_private *ip)
  394. {
  395. void (*do_get_eaddr)(struct ioc3_private *ip) = NULL;
  396. int i;
  397. /*
  398.  * We should also use this code for PCI cards, no matter what host
  399.  * machine but how to know that we're a PCI card?
  400.  */
  401. #ifdef CONFIG_SGI_IP27
  402. do_get_eaddr = ioc3_get_eaddr_nic;
  403. #endif
  404. #if defined(CONFIG_IA64_SGI_SN1) || defined(CONFIG_IA64_SGI_SN2)
  405. do_get_eaddr = ioc3_get_eaddr_sn;
  406. #endif
  407. if (!do_get_eaddr) {
  408. printk(KERN_ERR "Don't know how to read MAC address of this "
  409.        "IOC3 NICn");
  410. return;
  411. }
  412. printk("Ethernet address is ");
  413. for (i = 0; i < 6; i++) {
  414. printk("%02x", ip->dev->dev_addr[i]);
  415. if (i < 7)
  416. printk(":");
  417. }
  418. printk(".n");
  419. }
  420. /*
  421.  * Caller must hold the ioc3_lock ever for MII readers.  This is also
  422.  * used to protect the transmitter side but it's low contention.
  423.  */
  424. static u16 mii_read(struct ioc3_private *ip, int reg)
  425. {
  426. struct ioc3 *ioc3 = ip->regs;
  427. int phy = ip->phy;
  428. while (ioc3->micr & MICR_BUSY);
  429. ioc3->micr = (phy << MICR_PHYADDR_SHIFT) | reg | MICR_READTRIG;
  430. while (ioc3->micr & MICR_BUSY);
  431. return ioc3->midr_r & MIDR_DATA_MASK;
  432. }
  433. static void mii_write(struct ioc3_private *ip, int reg, u16 data)
  434. {
  435. struct ioc3 *ioc3 = ip->regs;
  436. int phy = ip->phy;
  437. while (ioc3->micr & MICR_BUSY);
  438. ioc3->midr_w = data;
  439. ioc3->micr = (phy << MICR_PHYADDR_SHIFT) | reg;
  440. while (ioc3->micr & MICR_BUSY);
  441. }
  442. static int ioc3_mii_init(struct ioc3_private *ip);
  443. static struct net_device_stats *ioc3_get_stats(struct net_device *dev)
  444. {
  445. struct ioc3_private *ip = dev->priv;
  446. struct ioc3 *ioc3 = ip->regs;
  447. ip->stats.collisions += (ioc3->etcdc & ETCDC_COLLCNT_MASK);
  448. return &ip->stats;
  449. }
  450. static inline void
  451. ioc3_rx(struct ioc3_private *ip)
  452. {
  453. struct sk_buff *skb, *new_skb;
  454. struct ioc3 *ioc3 = ip->regs;
  455. int rx_entry, n_entry, len;
  456. struct ioc3_erxbuf *rxb;
  457. unsigned long *rxr;
  458. u32 w0, err;
  459. rxr = (unsigned long *) ip->rxr; /* Ring base */
  460. rx_entry = ip->rx_ci; /* RX consume index */
  461. n_entry = ip->rx_pi;
  462. skb = ip->rx_skbs[rx_entry];
  463. rxb = (struct ioc3_erxbuf *) (skb->data - RX_OFFSET);
  464. w0 = be32_to_cpu(rxb->w0);
  465. while (w0 & ERXBUF_V) {
  466. err = be32_to_cpu(rxb->err); /* It's valid ...  */
  467. if (err & ERXBUF_GOODPKT) {
  468. len = ((w0 >> ERXBUF_BYTECNT_SHIFT) & 0x7ff) - 4;
  469. skb_trim(skb, len);
  470. skb->protocol = eth_type_trans(skb, ip->dev);
  471. new_skb = ioc3_alloc_skb(RX_BUF_ALLOC_SIZE, GFP_ATOMIC);
  472. if (!new_skb) {
  473. /* Ouch, drop packet and just recycle packet
  474.    to keep the ring filled.  */
  475. ip->stats.rx_dropped++;
  476. new_skb = skb;
  477. goto next;
  478. }
  479. netif_rx(skb);
  480. ip->rx_skbs[rx_entry] = NULL; /* Poison  */
  481. new_skb->dev = ip->dev;
  482. /* Because we reserve afterwards. */
  483. skb_put(new_skb, (1664 + RX_OFFSET));
  484. rxb = (struct ioc3_erxbuf *) new_skb->data;
  485. skb_reserve(new_skb, RX_OFFSET);
  486. ip->dev->last_rx = jiffies;
  487. ip->stats.rx_packets++; /* Statistics */
  488. ip->stats.rx_bytes += len;
  489. } else {
  490.   /* The frame is invalid and the skb never
  491.                            reached the network layer so we can just
  492.                            recycle it.  */
  493.   new_skb = skb;
  494.   ip->stats.rx_errors++;
  495. }
  496. if (err & ERXBUF_CRCERR) /* Statistics */
  497. ip->stats.rx_crc_errors++;
  498. if (err & ERXBUF_FRAMERR)
  499. ip->stats.rx_frame_errors++;
  500. next:
  501. ip->rx_skbs[n_entry] = new_skb;
  502. rxr[n_entry] = cpu_to_be32((0xa5UL << 56) |
  503.                          ((unsigned long) rxb & TO_PHYS_MASK));
  504. rxb->w0 = 0; /* Clear valid flag */
  505. n_entry = (n_entry + 1) & 511; /* Update erpir */
  506. /* Now go on to the next ring entry.  */
  507. rx_entry = (rx_entry + 1) & 511;
  508. skb = ip->rx_skbs[rx_entry];
  509. rxb = (struct ioc3_erxbuf *) (skb->data - RX_OFFSET);
  510. w0 = be32_to_cpu(rxb->w0);
  511. }
  512. ioc3->erpir = (n_entry << 3) | ERPIR_ARM;
  513. ip->rx_pi = n_entry;
  514. ip->rx_ci = rx_entry;
  515. }
  516. static inline void
  517. ioc3_tx(struct ioc3_private *ip)
  518. {
  519. unsigned long packets, bytes;
  520. struct ioc3 *ioc3 = ip->regs;
  521. int tx_entry, o_entry;
  522. struct sk_buff *skb;
  523. u32 etcir;
  524. spin_lock(&ip->ioc3_lock);
  525. etcir = ioc3->etcir;
  526. tx_entry = (etcir >> 7) & 127;
  527. o_entry = ip->tx_ci;
  528. packets = 0;
  529. bytes = 0;
  530. while (o_entry != tx_entry) {
  531. packets++;
  532. skb = ip->tx_skbs[o_entry];
  533. bytes += skb->len;
  534. dev_kfree_skb_irq(skb);
  535. ip->tx_skbs[o_entry] = NULL;
  536. o_entry = (o_entry + 1) & 127; /* Next */
  537. etcir = ioc3->etcir; /* More pkts sent?  */
  538. tx_entry = (etcir >> 7) & 127;
  539. }
  540. ip->stats.tx_packets += packets;
  541. ip->stats.tx_bytes += bytes;
  542. ip->txqlen -= packets;
  543. if (ip->txqlen < 128)
  544. netif_wake_queue(ip->dev);
  545. ip->tx_ci = o_entry;
  546. spin_unlock(&ip->ioc3_lock);
  547. }
  548. /*
  549.  * Deal with fatal IOC3 errors.  This condition might be caused by a hard or
  550.  * software problems, so we should try to recover
  551.  * more gracefully if this ever happens.  In theory we might be flooded
  552.  * with such error interrupts if something really goes wrong, so we might
  553.  * also consider to take the interface down.
  554.  */
  555. static void
  556. ioc3_error(struct ioc3_private *ip, u32 eisr)
  557. {
  558. struct net_device *dev = ip->dev;
  559. unsigned char *iface = dev->name;
  560. if (eisr & EISR_RXOFLO)
  561. printk(KERN_ERR "%s: RX overflow.n", iface);
  562. if (eisr & EISR_RXBUFOFLO)
  563. printk(KERN_ERR "%s: RX buffer overflow.n", iface);
  564. if (eisr & EISR_RXMEMERR)
  565. printk(KERN_ERR "%s: RX PCI error.n", iface);
  566. if (eisr & EISR_RXPARERR)
  567. printk(KERN_ERR "%s: RX SSRAM parity error.n", iface);
  568. if (eisr & EISR_TXBUFUFLO)
  569. printk(KERN_ERR "%s: TX buffer underflow.n", iface);
  570. if (eisr & EISR_TXMEMERR)
  571. printk(KERN_ERR "%s: TX PCI error.n", iface);
  572. ioc3_stop(ip);
  573. ioc3_init(ip);
  574. ioc3_mii_init(ip);
  575. dev->trans_start = jiffies;
  576. netif_wake_queue(dev);
  577. }
  578. /* The interrupt handler does all of the Rx thread work and cleans up
  579.    after the Tx thread.  */
  580. static void ioc3_interrupt(int irq, void *_dev, struct pt_regs *regs)
  581. {
  582. struct net_device *dev = (struct net_device *)_dev;
  583. struct ioc3_private *ip = dev->priv;
  584. struct ioc3 *ioc3 = ip->regs;
  585. const u32 enabled = EISR_RXTIMERINT | EISR_RXOFLO | EISR_RXBUFOFLO |
  586.                     EISR_RXMEMERR | EISR_RXPARERR | EISR_TXBUFUFLO |
  587.                     EISR_TXEXPLICIT | EISR_TXMEMERR;
  588. u32 eisr;
  589. eisr = ioc3->eisr & enabled;
  590. while (eisr) {
  591. ioc3->eisr = eisr;
  592. ioc3->eisr; /* Flush */
  593. if (eisr & (EISR_RXOFLO | EISR_RXBUFOFLO | EISR_RXMEMERR |
  594.             EISR_RXPARERR | EISR_TXBUFUFLO | EISR_TXMEMERR))
  595. ioc3_error(ip, eisr);
  596. if (eisr & EISR_RXTIMERINT)
  597. ioc3_rx(ip);
  598. if (eisr & EISR_TXEXPLICIT)
  599. ioc3_tx(ip);
  600. eisr = ioc3->eisr & enabled;
  601. }
  602. }
  603. /*
  604.  * Auto negotiation.  The scheme is very simple.  We have a timer routine that
  605.  * keeps watching the auto negotiation process as it progresses.  The DP83840
  606.  * is first told to start doing it's thing, we set up the time and place the
  607.  * timer state machine in it's initial state.
  608.  *
  609.  * Here the timer peeks at the DP83840 status registers at each click to see
  610.  * if the auto negotiation has completed, we assume here that the DP83840 PHY
  611.  * will time out at some point and just tell us what (didn't) happen.  For
  612.  * complete coverage we only allow so many of the ticks at this level to run,
  613.  * when this has expired we print a warning message and try another strategy.
  614.  * This "other" strategy is to force the interface into various speed/duplex
  615.  * configurations and we stop when we see a link-up condition before the
  616.  * maximum number of "peek" ticks have occurred.
  617.  *
  618.  * Once a valid link status has been detected we configure the IOC3 to speak
  619.  * the most efficient protocol we could get a clean link for.  The priority
  620.  * for link configurations, highest first is:
  621.  *
  622.  *     100 Base-T Full Duplex
  623.  *     100 Base-T Half Duplex
  624.  *     10 Base-T Full Duplex
  625.  *     10 Base-T Half Duplex
  626.  *
  627.  * We start a new timer now, after a successful auto negotiation status has
  628.  * been detected.  This timer just waits for the link-up bit to get set in
  629.  * the BMCR of the DP83840.  When this occurs we print a kernel log message
  630.  * describing the link type in use and the fact that it is up.
  631.  *
  632.  * If a fatal error of some sort is signalled and detected in the interrupt
  633.  * service routine, and the chip is reset, or the link is ifconfig'd down
  634.  * and then back up, this entire process repeats itself all over again.
  635.  */
  636. static int ioc3_try_next_permutation(struct ioc3_private *ip)
  637. {
  638. ip->sw_bmcr = mii_read(ip, MII_BMCR);
  639. /* Downgrade from full to half duplex.  Only possible via ethtool.  */
  640. if (ip->sw_bmcr & BMCR_FULLDPLX) {
  641. ip->sw_bmcr &= ~BMCR_FULLDPLX;
  642. mii_write(ip, MII_BMCR, ip->sw_bmcr);
  643. return 0;
  644. }
  645. /* Downgrade from 100 to 10. */
  646. if (ip->sw_bmcr & BMCR_SPEED100) {
  647. ip->sw_bmcr &= ~BMCR_SPEED100;
  648. mii_write(ip, MII_BMCR, ip->sw_bmcr);
  649. return 0;
  650. }
  651. /* We've tried everything. */
  652. return -1;
  653. }
  654. static void
  655. ioc3_display_link_mode(struct ioc3_private *ip)
  656. {
  657. char *tmode = "";
  658. ip->sw_lpa = mii_read(ip, MII_LPA);
  659. if (ip->sw_lpa & (LPA_100HALF | LPA_100FULL)) {
  660. if (ip->sw_lpa & LPA_100FULL)
  661. tmode = "100Mb/s, Full Duplex";
  662. else
  663. tmode = "100Mb/s, Half Duplex";
  664. } else {
  665. if (ip->sw_lpa & LPA_10FULL)
  666. tmode = "10Mb/s, Full Duplex";
  667. else
  668. tmode = "10Mb/s, Half Duplex";
  669. }
  670. printk(KERN_INFO "%s: Link is up at %s.n", ip->dev->name, tmode);
  671. }
  672. static void
  673. ioc3_display_forced_link_mode(struct ioc3_private *ip)
  674. {
  675. char *speed = "", *duplex = "";
  676. ip->sw_bmcr = mii_read(ip, MII_BMCR);
  677. if (ip->sw_bmcr & BMCR_SPEED100)
  678. speed = "100Mb/s, ";
  679. else
  680. speed = "10Mb/s, ";
  681. if (ip->sw_bmcr & BMCR_FULLDPLX)
  682. duplex = "Full Duplex.n";
  683. else
  684. duplex = "Half Duplex.n";
  685. printk(KERN_INFO "%s: Link has been forced up at %s%s", ip->dev->name,
  686.        speed, duplex);
  687. }
  688. static int ioc3_set_link_modes(struct ioc3_private *ip)
  689. {
  690. struct ioc3 *ioc3 = ip->regs;
  691. int full;
  692. /*
  693.  * All we care about is making sure the bigmac tx_cfg has a
  694.  * proper duplex setting.
  695.  */
  696. if (ip->timer_state == arbwait) {
  697. ip->sw_lpa = mii_read(ip, MII_LPA);
  698. if (!(ip->sw_lpa & (LPA_10HALF | LPA_10FULL |
  699.                     LPA_100HALF | LPA_100FULL)))
  700. goto no_response;
  701. if (ip->sw_lpa & LPA_100FULL)
  702. full = 1;
  703. else if (ip->sw_lpa & LPA_100HALF)
  704. full = 0;
  705. else if (ip->sw_lpa & LPA_10FULL)
  706. full = 1;
  707. else
  708. full = 0;
  709. } else {
  710. /* Forcing a link mode. */
  711. ip->sw_bmcr = mii_read(ip, MII_BMCR);
  712. if (ip->sw_bmcr & BMCR_FULLDPLX)
  713. full = 1;
  714. else
  715. full = 0;
  716. }
  717. if (full)
  718. ip->emcr |= EMCR_DUPLEX;
  719. else
  720. ip->emcr &= ~EMCR_DUPLEX;
  721. ioc3->emcr = ip->emcr;
  722. ioc3->emcr;
  723. return 0;
  724. no_response:
  725. return 1;
  726. }
  727. static int is_lucent_phy(struct ioc3_private *ip)
  728. {
  729. unsigned short mr2, mr3;
  730. int ret = 0;
  731. mr2 = mii_read(ip, MII_PHYSID1);
  732. mr3 = mii_read(ip, MII_PHYSID2);
  733. if ((mr2 & 0xffff) == 0x0180 && ((mr3 & 0xffff) >> 10) == 0x1d) {
  734. ret = 1;
  735. }
  736. return ret;
  737. }
  738. static void ioc3_timer(unsigned long data)
  739. {
  740. struct ioc3_private *ip = (struct ioc3_private *) data;
  741. int restart_timer = 0;
  742. ip->timer_ticks++;
  743. switch (ip->timer_state) {
  744. case arbwait:
  745. /*
  746.  * Only allow for 5 ticks, thats 10 seconds and much too
  747.  * long to wait for arbitration to complete.
  748.  */
  749. if (ip->timer_ticks >= 10) {
  750. /* Enter force mode. */
  751. do_force_mode:
  752. ip->sw_bmcr = mii_read(ip, MII_BMCR);
  753. printk(KERN_NOTICE "%s: Auto-Negotiation unsuccessful,"
  754.        " trying force link moden", ip->dev->name);
  755. ip->sw_bmcr = BMCR_SPEED100;
  756. mii_write(ip, MII_BMCR, ip->sw_bmcr);
  757. if (!is_lucent_phy(ip)) {
  758. /*
  759.  * OK, seems we need do disable the transceiver
  760.  * for the first tick to make sure we get an
  761.  * accurate link state at the second tick.
  762.  */
  763. ip->sw_csconfig = mii_read(ip, MII_CSCONFIG);
  764. ip->sw_csconfig &= ~(CSCONFIG_TCVDISAB);
  765. mii_write(ip, MII_CSCONFIG, ip->sw_csconfig);
  766. }
  767. ip->timer_state = ltrywait;
  768. ip->timer_ticks = 0;
  769. restart_timer = 1;
  770. } else {
  771. /* Anything interesting happen? */
  772. ip->sw_bmsr = mii_read(ip, MII_BMSR);
  773. if (ip->sw_bmsr & BMSR_ANEGCOMPLETE) {
  774. int ret;
  775. /* Just what we've been waiting for... */
  776. ret = ioc3_set_link_modes(ip);
  777. if (ret) {
  778. /* Ooops, something bad happened, go to
  779.  * force mode.
  780.  *
  781.  * XXX Broken hubs which don't support
  782.  * XXX 802.3u auto-negotiation make this
  783.  * XXX happen as well.
  784.  */
  785. goto do_force_mode;
  786. }
  787. /*
  788.  * Success, at least so far, advance our state
  789.  * engine.
  790.  */
  791. ip->timer_state = lupwait;
  792. restart_timer = 1;
  793. } else {
  794. restart_timer = 1;
  795. }
  796. }
  797. break;
  798. case lupwait:
  799. /*
  800.  * Auto negotiation was successful and we are awaiting a
  801.  * link up status.  I have decided to let this timer run
  802.  * forever until some sort of error is signalled, reporting
  803.  * a message to the user at 10 second intervals.
  804.  */
  805. ip->sw_bmsr = mii_read(ip, MII_BMSR);
  806. if (ip->sw_bmsr & BMSR_LSTATUS) {
  807. /*
  808.  * Wheee, it's up, display the link mode in use and put
  809.  * the timer to sleep.
  810.  */
  811. ioc3_display_link_mode(ip);
  812. ip->timer_state = asleep;
  813. restart_timer = 0;
  814. } else {
  815. if (ip->timer_ticks >= 10) {
  816. printk(KERN_NOTICE "%s: Auto negotiation successful, link still "
  817.        "not completely up.n", ip->dev->name);
  818. ip->timer_ticks = 0;
  819. restart_timer = 1;
  820. } else {
  821. restart_timer = 1;
  822. }
  823. }
  824. break;
  825. case ltrywait:
  826. /*
  827.  * Making the timeout here too long can make it take
  828.  * annoyingly long to attempt all of the link mode
  829.  * permutations, but then again this is essentially
  830.  * error recovery code for the most part.
  831.  */
  832. ip->sw_bmsr = mii_read(ip, MII_BMSR);
  833. ip->sw_csconfig = mii_read(ip, MII_CSCONFIG);
  834. if (ip->timer_ticks == 1) {
  835. if (!is_lucent_phy(ip)) {
  836. /*
  837.  * Re-enable transceiver, we'll re-enable the
  838.  * transceiver next tick, then check link state
  839.  * on the following tick.
  840.  */
  841. ip->sw_csconfig |= CSCONFIG_TCVDISAB;
  842. mii_write(ip, MII_CSCONFIG, ip->sw_csconfig);
  843. }
  844. restart_timer = 1;
  845. break;
  846. }
  847. if (ip->timer_ticks == 2) {
  848. if (!is_lucent_phy(ip)) {
  849. ip->sw_csconfig &= ~(CSCONFIG_TCVDISAB);
  850. mii_write(ip, MII_CSCONFIG, ip->sw_csconfig);
  851. }
  852. restart_timer = 1;
  853. break;
  854. }
  855. if (ip->sw_bmsr & BMSR_LSTATUS) {
  856. /* Force mode selection success. */
  857. ioc3_display_forced_link_mode(ip);
  858. ioc3_set_link_modes(ip);  /* XXX error? then what? */
  859. ip->timer_state = asleep;
  860. restart_timer = 0;
  861. } else {
  862. if (ip->timer_ticks >= 4) { /* 6 seconds or so... */
  863. int ret;
  864. ret = ioc3_try_next_permutation(ip);
  865. if (ret == -1) {
  866. /*
  867.  * Aieee, tried them all, reset the
  868.  * chip and try all over again.
  869.  */
  870. printk(KERN_NOTICE "%s: Link down, "
  871.        "cable problem?n",
  872.        ip->dev->name);
  873. ioc3_init(ip);
  874. return;
  875. }
  876. if (!is_lucent_phy(ip)) {
  877. ip->sw_csconfig = mii_read(ip,
  878.                     MII_CSCONFIG);
  879. ip->sw_csconfig |= CSCONFIG_TCVDISAB;
  880. mii_write(ip, MII_CSCONFIG,
  881.           ip->sw_csconfig);
  882. }
  883. ip->timer_ticks = 0;
  884. restart_timer = 1;
  885. } else {
  886. restart_timer = 1;
  887. }
  888. }
  889. break;
  890. case asleep:
  891. default:
  892. /* Can't happens.... */
  893. printk(KERN_ERR "%s: Aieee, link timer is asleep but we got "
  894.        "one anyways!n", ip->dev->name);
  895. restart_timer = 0;
  896. ip->timer_ticks = 0;
  897. ip->timer_state = asleep; /* foo on you */
  898. break;
  899. };
  900. if (restart_timer) {
  901. ip->ioc3_timer.expires = jiffies + ((12 * HZ)/10); /* 1.2s */
  902. add_timer(&ip->ioc3_timer);
  903. }
  904. }
  905. static void
  906. ioc3_start_auto_negotiation(struct ioc3_private *ip, struct ethtool_cmd *ep)
  907. {
  908. int timeout;
  909. /* Read all of the registers we are interested in now. */
  910. ip->sw_bmsr      = mii_read(ip, MII_BMSR);
  911. ip->sw_bmcr      = mii_read(ip, MII_BMCR);
  912. ip->sw_physid1   = mii_read(ip, MII_PHYSID1);
  913. ip->sw_physid2   = mii_read(ip, MII_PHYSID2);
  914. /* XXX Check BMSR_ANEGCAPABLE, should not be necessary though. */
  915. ip->sw_advertise = mii_read(ip, MII_ADVERTISE);
  916. if (ep == NULL || ep->autoneg == AUTONEG_ENABLE) {
  917. /* Advertise everything we can support. */
  918. if (ip->sw_bmsr & BMSR_10HALF)
  919. ip->sw_advertise |= ADVERTISE_10HALF;
  920. else
  921. ip->sw_advertise &= ~ADVERTISE_10HALF;
  922. if (ip->sw_bmsr & BMSR_10FULL)
  923. ip->sw_advertise |= ADVERTISE_10FULL;
  924. else
  925. ip->sw_advertise &= ~ADVERTISE_10FULL;
  926. if (ip->sw_bmsr & BMSR_100HALF)
  927. ip->sw_advertise |= ADVERTISE_100HALF;
  928. else
  929. ip->sw_advertise &= ~ADVERTISE_100HALF;
  930. if (ip->sw_bmsr & BMSR_100FULL)
  931. ip->sw_advertise |= ADVERTISE_100FULL;
  932. else
  933. ip->sw_advertise &= ~ADVERTISE_100FULL;
  934. mii_write(ip, MII_ADVERTISE, ip->sw_advertise);
  935. /*
  936.  * XXX Currently no IOC3 card I know off supports 100BaseT4,
  937.  * XXX and this is because the DP83840 does not support it,
  938.  * XXX changes XXX would need to be made to the tx/rx logic in
  939.  * XXX the driver as well so I completely skip checking for it
  940.  * XXX in the BMSR for now.
  941.  */
  942. #ifdef AUTO_SWITCH_DEBUG
  943. ASD(("%s: Advertising [ ", ip->dev->name));
  944. if (ip->sw_advertise & ADVERTISE_10HALF)
  945. ASD(("10H "));
  946. if (ip->sw_advertise & ADVERTISE_10FULL)
  947. ASD(("10F "));
  948. if (ip->sw_advertise & ADVERTISE_100HALF)
  949. ASD(("100H "));
  950. if (ip->sw_advertise & ADVERTISE_100FULL)
  951. ASD(("100F "));
  952. #endif
  953. /* Enable Auto-Negotiation, this is usually on already... */
  954. ip->sw_bmcr |= BMCR_ANENABLE;
  955. mii_write(ip, MII_BMCR, ip->sw_bmcr);
  956. /* Restart it to make sure it is going. */
  957. ip->sw_bmcr |= BMCR_ANRESTART;
  958. mii_write(ip, MII_BMCR, ip->sw_bmcr);
  959. /* BMCR_ANRESTART self clears when the process has begun. */
  960. timeout = 64;  /* More than enough. */
  961. while (--timeout) {
  962. ip->sw_bmcr = mii_read(ip, MII_BMCR);
  963. if (!(ip->sw_bmcr & BMCR_ANRESTART))
  964. break; /* got it. */
  965. udelay(10);
  966. }
  967. if (!timeout) {
  968. printk(KERN_ERR "%s: IOC3 would not start auto "
  969.        "negotiation BMCR=0x%04xn",
  970.        ip->dev->name, ip->sw_bmcr);
  971. printk(KERN_NOTICE "%s: Performing force link "
  972.        "detection.n", ip->dev->name);
  973. goto force_link;
  974. } else {
  975. ip->timer_state = arbwait;
  976. }
  977. } else {
  978. force_link:
  979. /*
  980.  * Force the link up, trying first a particular mode.  Either
  981.  * we are here at the request of ethtool or because the IOC3
  982.  * would not start to autoneg.
  983.  */
  984. /*
  985.  * Disable auto-negotiation in BMCR, enable the duplex and
  986.  * speed setting, init the timer state machine, and fire it off.
  987.  */
  988. if (ep == NULL || ep->autoneg == AUTONEG_ENABLE) {
  989. ip->sw_bmcr = BMCR_SPEED100;
  990. } else {
  991. if (ep->speed == SPEED_100)
  992. ip->sw_bmcr = BMCR_SPEED100;
  993. else
  994. ip->sw_bmcr = 0;
  995. if (ep->duplex == DUPLEX_FULL)
  996. ip->sw_bmcr |= BMCR_FULLDPLX;
  997. }
  998. mii_write(ip, MII_BMCR, ip->sw_bmcr);
  999. if (!is_lucent_phy(ip)) {
  1000. /*
  1001.  * OK, seems we need do disable the transceiver for the
  1002.  * first tick to make sure we get an accurate link
  1003.  * state at the second tick.
  1004.  */
  1005. ip->sw_csconfig = mii_read(ip, MII_CSCONFIG);
  1006. ip->sw_csconfig &= ~(CSCONFIG_TCVDISAB);
  1007. mii_write(ip, MII_CSCONFIG, ip->sw_csconfig);
  1008. }
  1009. ip->timer_state = ltrywait;
  1010. }
  1011. del_timer(&ip->ioc3_timer);
  1012. ip->timer_ticks = 0;
  1013. ip->ioc3_timer.expires = jiffies + (12 * HZ)/10;  /* 1.2 sec. */
  1014. ip->ioc3_timer.data = (unsigned long) ip;
  1015. ip->ioc3_timer.function = &ioc3_timer;
  1016. add_timer(&ip->ioc3_timer);
  1017. }
  1018. static int ioc3_mii_init(struct ioc3_private *ip)
  1019. {
  1020. int i, found;
  1021. u16 word;
  1022. found = 0;
  1023. spin_lock_irq(&ip->ioc3_lock);
  1024. for (i = 0; i < 32; i++) {
  1025. ip->phy = i;
  1026. word = mii_read(ip, 2);
  1027. if ((word != 0xffff) && (word != 0x0000)) {
  1028. found = 1;
  1029. break; /* Found a PHY */
  1030. }
  1031. }
  1032. if (!found) {
  1033. spin_unlock_irq(&ip->ioc3_lock);
  1034. return -ENODEV;
  1035. }
  1036. ioc3_start_auto_negotiation(ip, NULL); // XXX ethtool
  1037. spin_unlock_irq(&ip->ioc3_lock);
  1038. return 0;
  1039. }
  1040. static inline void
  1041. ioc3_clean_rx_ring(struct ioc3_private *ip)
  1042. {
  1043. struct sk_buff *skb;
  1044. int i;
  1045. for (i = ip->rx_ci; i & 15; i++) {
  1046. ip->rx_skbs[ip->rx_pi] = ip->rx_skbs[ip->rx_ci];
  1047. ip->rxr[ip->rx_pi++] = ip->rxr[ip->rx_ci++];
  1048. }
  1049. ip->rx_pi &= 511;
  1050. ip->rx_ci &= 511;
  1051. for (i = ip->rx_ci; i != ip->rx_pi; i = (i+1) & 511) {
  1052. struct ioc3_erxbuf *rxb;
  1053. skb = ip->rx_skbs[i];
  1054. rxb = (struct ioc3_erxbuf *) (skb->data - RX_OFFSET);
  1055. rxb->w0 = 0;
  1056. }
  1057. }
  1058. static inline void
  1059. ioc3_clean_tx_ring(struct ioc3_private *ip)
  1060. {
  1061. struct sk_buff *skb;
  1062. int i;
  1063. for (i=0; i < 128; i++) {
  1064. skb = ip->tx_skbs[i];
  1065. if (skb) {
  1066. ip->tx_skbs[i] = NULL;
  1067. dev_kfree_skb_any(skb);
  1068. }
  1069. ip->txr[i].cmd = 0;
  1070. }
  1071. ip->tx_pi = 0;
  1072. ip->tx_ci = 0;
  1073. }
  1074. static void
  1075. ioc3_free_rings(struct ioc3_private *ip)
  1076. {
  1077. struct sk_buff *skb;
  1078. int rx_entry, n_entry;
  1079. if (ip->txr) {
  1080. ioc3_clean_tx_ring(ip);
  1081. free_pages((unsigned long)ip->txr, 2);
  1082. ip->txr = NULL;
  1083. }
  1084. if (ip->rxr) {
  1085. n_entry = ip->rx_ci;
  1086. rx_entry = ip->rx_pi;
  1087. while (n_entry != rx_entry) {
  1088. skb = ip->rx_skbs[n_entry];
  1089. if (skb)
  1090. dev_kfree_skb_any(skb);
  1091. n_entry = (n_entry + 1) & 511;
  1092. }
  1093. free_page((unsigned long)ip->rxr);
  1094. ip->rxr = NULL;
  1095. }
  1096. }
  1097. static void
  1098. ioc3_alloc_rings(struct net_device *dev, struct ioc3_private *ip,
  1099.  struct ioc3 *ioc3)
  1100. {
  1101. struct ioc3_erxbuf *rxb;
  1102. unsigned long *rxr;
  1103. int i;
  1104. if (ip->rxr == NULL) {
  1105. /* Allocate and initialize rx ring.  4kb = 512 entries  */
  1106. ip->rxr = (unsigned long *) get_free_page(GFP_ATOMIC);
  1107. rxr = (unsigned long *) ip->rxr;
  1108. if (!rxr)
  1109. printk("ioc3_alloc_rings(): get_free_page() failed!n");
  1110. /* Now the rx buffers.  The RX ring may be larger but
  1111.    we only allocate 16 buffers for now.  Need to tune
  1112.    this for performance and memory later.  */
  1113. for (i = 0; i < RX_BUFFS; i++) {
  1114. struct sk_buff *skb;
  1115. skb = ioc3_alloc_skb(RX_BUF_ALLOC_SIZE, GFP_ATOMIC);
  1116. if (!skb) {
  1117. show_free_areas();
  1118. continue;
  1119. }
  1120. ip->rx_skbs[i] = skb;
  1121. skb->dev = dev;
  1122. /* Because we reserve afterwards. */
  1123. skb_put(skb, (1664 + RX_OFFSET));
  1124. rxb = (struct ioc3_erxbuf *) skb->data;
  1125. rxr[i] = cpu_to_be64((0xa5UL << 56) |
  1126.                 ((unsigned long) rxb & TO_PHYS_MASK));
  1127. skb_reserve(skb, RX_OFFSET);
  1128. }
  1129. ip->rx_ci = 0;
  1130. ip->rx_pi = RX_BUFFS;
  1131. }
  1132. if (ip->txr == NULL) {
  1133. /* Allocate and initialize tx rings.  16kb = 128 bufs.  */
  1134. ip->txr = (struct ioc3_etxd *)__get_free_pages(GFP_KERNEL, 2);
  1135. if (!ip->txr)
  1136. printk("ioc3_alloc_rings(): get_free_page() failed!n");
  1137. ip->tx_pi = 0;
  1138. ip->tx_ci = 0;
  1139. }
  1140. }
  1141. static void
  1142. ioc3_init_rings(struct net_device *dev, struct ioc3_private *ip,
  1143.         struct ioc3 *ioc3)
  1144. {
  1145. unsigned long ring;
  1146. ioc3_free_rings(ip);
  1147. ioc3_alloc_rings(dev, ip, ioc3);
  1148. ioc3_clean_rx_ring(ip);
  1149. ioc3_clean_tx_ring(ip);
  1150. /* Now the rx ring base, consume & produce registers.  */
  1151. ring = (0xa5UL << 56) | ((unsigned long)ip->rxr & TO_PHYS_MASK);
  1152. ioc3->erbr_h = ring >> 32;
  1153. ioc3->erbr_l = ring & 0xffffffff;
  1154. ioc3->ercir  = (ip->rx_ci << 3);
  1155. ioc3->erpir  = (ip->rx_pi << 3) | ERPIR_ARM;
  1156. ring = (0xa5UL << 56) | ((unsigned long)ip->txr & TO_PHYS_MASK);
  1157. ip->txqlen = 0; /* nothing queued  */
  1158. /* Now the tx ring base, consume & produce registers.  */
  1159. ioc3->etbr_h = ring >> 32;
  1160. ioc3->etbr_l = ring & 0xffffffff;
  1161. ioc3->etpir  = (ip->tx_pi << 7);
  1162. ioc3->etcir  = (ip->tx_ci << 7);
  1163. ioc3->etcir; /* Flush */
  1164. }
  1165. static inline void
  1166. ioc3_ssram_disc(struct ioc3_private *ip)
  1167. {
  1168. struct ioc3 *ioc3 = ip->regs;
  1169. volatile u32 *ssram0 = &ioc3->ssram[0x0000];
  1170. volatile u32 *ssram1 = &ioc3->ssram[0x4000];
  1171. unsigned int pattern = 0x5555;
  1172. /* Assume the larger size SSRAM and enable parity checking */
  1173. ioc3->emcr |= (EMCR_BUFSIZ | EMCR_RAMPAR);
  1174. *ssram0 = pattern;
  1175. *ssram1 = ~pattern & IOC3_SSRAM_DM;
  1176. if ((*ssram0 & IOC3_SSRAM_DM) != pattern ||
  1177.     (*ssram1 & IOC3_SSRAM_DM) != (~pattern & IOC3_SSRAM_DM)) {
  1178. /* set ssram size to 64 KB */
  1179. ip->emcr = EMCR_RAMPAR;
  1180. ioc3->emcr &= ~EMCR_BUFSIZ;
  1181. } else {
  1182. ip->emcr = EMCR_BUFSIZ | EMCR_RAMPAR;
  1183. }
  1184. }
  1185. static void ioc3_init(struct ioc3_private *ip)
  1186. {
  1187. struct net_device *dev = ip->dev;
  1188. struct ioc3 *ioc3 = ip->regs;
  1189. del_timer(&ip->ioc3_timer); /* Kill if running */
  1190. ioc3->emcr = EMCR_RST; /* Reset */
  1191. ioc3->emcr; /* Flush WB */
  1192. udelay(4); /* Give it time ... */
  1193. ioc3->emcr = 0;
  1194. ioc3->emcr;
  1195. /* Misc registers  */
  1196. ioc3->erbar = 0;
  1197. ioc3->etcsr = (17<<ETCSR_IPGR2_SHIFT) | (11<<ETCSR_IPGR1_SHIFT) | 21;
  1198. ioc3->etcdc; /* Clear on read */
  1199. ioc3->ercsr = 15; /* RX low watermark  */
  1200. ioc3->ertr = 0; /* Interrupt immediately */
  1201. ioc3->emar_h = (dev->dev_addr[5] << 8) | dev->dev_addr[4];
  1202. ioc3->emar_l = (dev->dev_addr[3] << 24) | (dev->dev_addr[2] << 16) |
  1203.                (dev->dev_addr[1] <<  8) | dev->dev_addr[0];
  1204. ioc3->ehar_h = ip->ehar_h;
  1205. ioc3->ehar_l = ip->ehar_l;
  1206. ioc3->ersr = 42; /* XXX should be random */
  1207. ioc3_init_rings(ip->dev, ip, ioc3);
  1208. ip->emcr |= ((RX_OFFSET / 2) << EMCR_RXOFF_SHIFT) | EMCR_TXDMAEN |
  1209.              EMCR_TXEN | EMCR_RXDMAEN | EMCR_RXEN;
  1210. ioc3->emcr = ip->emcr;
  1211. ioc3->eier = EISR_RXTIMERINT | EISR_RXOFLO | EISR_RXBUFOFLO |
  1212.              EISR_RXMEMERR | EISR_RXPARERR | EISR_TXBUFUFLO |
  1213.              EISR_TXEXPLICIT | EISR_TXMEMERR;
  1214. ioc3->eier;
  1215. }
  1216. static inline void ioc3_stop(struct ioc3_private *ip)
  1217. {
  1218. struct ioc3 *ioc3 = ip->regs;
  1219. ioc3->emcr = 0; /* Shutup */
  1220. ioc3->eier = 0; /* Disable interrupts */
  1221. ioc3->eier; /* Flush */
  1222. }
  1223. static int
  1224. ioc3_open(struct net_device *dev)
  1225. {
  1226. struct ioc3_private *ip = dev->priv;
  1227. if (request_irq(dev->irq, ioc3_interrupt, SA_SHIRQ, ioc3_str, dev)) {
  1228. printk(KERN_ERR "%s: Can't get irq %dn", dev->name, dev->irq);
  1229. return -EAGAIN;
  1230. }
  1231. ip->ehar_h = 0;
  1232. ip->ehar_l = 0;
  1233. ioc3_init(ip);
  1234. netif_start_queue(dev);
  1235. return 0;
  1236. }
  1237. static int
  1238. ioc3_close(struct net_device *dev)
  1239. {
  1240. struct ioc3_private *ip = dev->priv;
  1241. del_timer(&ip->ioc3_timer);
  1242. netif_stop_queue(dev);
  1243. ioc3_stop(ip);
  1244. free_irq(dev->irq, dev);
  1245. ioc3_free_rings(ip);
  1246. return 0;
  1247. }
  1248. /*
  1249.  * MENET cards have four IOC3 chips, which are attached to two sets of
  1250.  * PCI slot resources each: the primary connections are on slots
  1251.  * 0..3 and the secondaries are on 4..7
  1252.  *
  1253.  * All four ethernets are brought out to connectors; six serial ports
  1254.  * (a pair from each of the first three IOC3s) are brought out to
  1255.  * MiniDINs; all other subdevices are left swinging in the wind, leave
  1256.  * them disabled.
  1257.  */
  1258. static inline int ioc3_is_menet(struct pci_dev *pdev)
  1259. {
  1260. struct pci_dev *dev;
  1261. return pdev->bus->parent == NULL
  1262.        && (dev = pci_find_slot(pdev->bus->number, PCI_DEVFN(0, 0)))
  1263.        && dev->vendor == PCI_VENDOR_ID_SGI
  1264.        && dev->device == PCI_DEVICE_ID_SGI_IOC3
  1265.        && (dev = pci_find_slot(pdev->bus->number, PCI_DEVFN(1, 0)))
  1266.        && dev->vendor == PCI_VENDOR_ID_SGI
  1267.        && dev->device == PCI_DEVICE_ID_SGI_IOC3
  1268.        && (dev = pci_find_slot(pdev->bus->number, PCI_DEVFN(2, 0)))
  1269.        && dev->vendor == PCI_VENDOR_ID_SGI
  1270.        && dev->device == PCI_DEVICE_ID_SGI_IOC3;
  1271. }
  1272. static void inline ioc3_serial_probe(struct pci_dev *pdev,
  1273. struct ioc3 *ioc3)
  1274. {
  1275. struct serial_struct req;
  1276. /*
  1277.  * We need to recognice and treat the fourth MENET serial as it
  1278.  * does not have an SuperIO chip attached to it, therefore attempting
  1279.  * to access it will result in bus errors.  We call something an
  1280.  * MENET if PCI slot 0, 1, 2 and 3 of a master PCI bus all have an IOC3
  1281.  * in it.  This is paranoid but we want to avoid blowing up on a
  1282.  * showhorn PCI box that happens to have 4 IOC3 cards in it so it's
  1283.  * not paranoid enough ...
  1284.  */
  1285. if (ioc3_is_menet(pdev) && PCI_SLOT(pdev->devfn) == 3)
  1286. return;
  1287. /* Register to interrupt zero because we share the interrupt with
  1288.    the serial driver which we don't properly support yet.  */
  1289. memset(&req, 0, sizeof(req));
  1290. req.irq             = 0;
  1291. req.flags           = IOC3_COM_FLAGS;
  1292. req.io_type         = SERIAL_IO_MEM;
  1293. req.iomem_reg_shift = 0;
  1294. req.baud_base       = IOC3_BAUD;
  1295. req.iomem_base      = (unsigned char *) &ioc3->sregs.uarta;
  1296. register_serial(&req);
  1297. req.iomem_base      = (unsigned char *) &ioc3->sregs.uartb;
  1298. register_serial(&req);
  1299. }
  1300. static int __devinit ioc3_probe(struct pci_dev *pdev,
  1301.                         const struct pci_device_id *ent)
  1302. {
  1303. struct net_device *dev = NULL;
  1304. struct ioc3_private *ip;
  1305. struct ioc3 *ioc3;
  1306. unsigned long ioc3_base, ioc3_size;
  1307. u32 vendor, model, rev;
  1308. int err;
  1309. dev = alloc_etherdev(sizeof(struct ioc3_private));
  1310. if (!dev)
  1311. return -ENOMEM;
  1312. err = pci_request_regions(pdev, "ioc3");
  1313. if (err)
  1314. goto out_free;
  1315. SET_MODULE_OWNER(dev);
  1316. ip = dev->priv;
  1317. ip->dev = dev;
  1318. dev->irq = pdev->irq;
  1319. ioc3_base = pci_resource_start(pdev, 0);
  1320. ioc3_size = pci_resource_len(pdev, 0);
  1321. ioc3 = (struct ioc3 *) ioremap(ioc3_base, ioc3_size);
  1322. if (!ioc3) {
  1323. printk(KERN_CRIT "ioc3eth(%s): ioremap failed, goodbye.n",
  1324.        pdev->slot_name);
  1325. err = -ENOMEM;
  1326. goto out_res;
  1327. }
  1328. ip->regs = ioc3;
  1329. #ifdef CONFIG_SERIAL
  1330. ioc3_serial_probe(pdev, ioc3);
  1331. #endif
  1332. spin_lock_init(&ip->ioc3_lock);
  1333. ioc3_stop(ip);
  1334. ioc3_init(ip);
  1335. init_timer(&ip->ioc3_timer);
  1336. ioc3_mii_init(ip);
  1337. if (ip->phy == -1) {
  1338. printk(KERN_CRIT "ioc3-eth(%s): Didn't find a PHY, goodbye.n",
  1339.        pdev->slot_name);
  1340. err = -ENODEV;
  1341. goto out_stop;
  1342. }
  1343. ioc3_ssram_disc(ip);
  1344. ioc3_get_eaddr(ip);
  1345. /* The IOC3-specific entries in the device structure. */
  1346. dev->open = ioc3_open;
  1347. dev->hard_start_xmit = ioc3_start_xmit;
  1348. dev->tx_timeout = ioc3_timeout;
  1349. dev->watchdog_timeo = 5 * HZ;
  1350. dev->stop = ioc3_close;
  1351. dev->get_stats = ioc3_get_stats;
  1352. dev->do_ioctl = ioc3_ioctl;
  1353. dev->set_multicast_list = ioc3_set_multicast_list;
  1354. err = register_netdev(dev);
  1355. if (err)
  1356. goto out_stop;
  1357. vendor = (ip->sw_physid1 << 12) | (ip->sw_physid2 >> 4);
  1358. model  = (ip->sw_physid2 >> 4) & 0x3f;
  1359. rev    = ip->sw_physid2 & 0xf;
  1360. printk(KERN_INFO "%s: Using PHY %d, vendor 0x%x, model %d, "
  1361.        "rev %d.n", dev->name, ip->phy, vendor, model, rev);
  1362. printk(KERN_INFO "%s: IOC3 SSRAM has %d kbyte.n", dev->name,
  1363.        ip->emcr & EMCR_BUFSIZ ? 128 : 64);
  1364. return 0;
  1365. out_stop:
  1366. ioc3_stop(ip);
  1367. free_irq(dev->irq, dev);
  1368. ioc3_free_rings(ip);
  1369. out_res:
  1370. pci_release_regions(pdev);
  1371. out_free:
  1372. kfree(dev);
  1373. return err;
  1374. }
  1375. static void __devexit ioc3_remove_one (struct pci_dev *pdev)
  1376. {
  1377. struct net_device *dev = pci_get_drvdata(pdev);
  1378. struct ioc3_private *ip = dev->priv;
  1379. struct ioc3 *ioc3 = ip->regs;
  1380. iounmap(ioc3);
  1381. pci_release_regions(pdev);
  1382. kfree(dev);
  1383. }
  1384. static struct pci_device_id ioc3_pci_tbl[] __devinitdata = {
  1385. { PCI_VENDOR_ID_SGI, PCI_DEVICE_ID_SGI_IOC3, PCI_ANY_ID, PCI_ANY_ID },
  1386. { 0 }
  1387. };
  1388. MODULE_DEVICE_TABLE(pci, ioc3_pci_tbl);
  1389. static struct pci_driver ioc3_driver = {
  1390. name: "ioc3-eth",
  1391. id_table: ioc3_pci_tbl,
  1392. probe: ioc3_probe,
  1393. remove: __devexit_p(ioc3_remove_one),
  1394. };
  1395. static int __init ioc3_init_module(void)
  1396. {
  1397. return pci_module_init(&ioc3_driver);
  1398. }
  1399. static void __exit ioc3_cleanup_module(void)
  1400. {
  1401. pci_unregister_driver(&ioc3_driver);
  1402. }
  1403. static int
  1404. ioc3_start_xmit(struct sk_buff *skb, struct net_device *dev)
  1405. {
  1406. unsigned long data;
  1407. struct ioc3_private *ip = dev->priv;
  1408. struct ioc3 *ioc3 = ip->regs;
  1409. unsigned int len;
  1410. struct ioc3_etxd *desc;
  1411. int produce;
  1412. spin_lock_irq(&ip->ioc3_lock);
  1413. data = (unsigned long) skb->data;
  1414. len = skb->len;
  1415. produce = ip->tx_pi;
  1416. desc = &ip->txr[produce];
  1417. if (len <= 104) {
  1418. /* Short packet, let's copy it directly into the ring.  */
  1419. memcpy(desc->data, skb->data, skb->len);
  1420. if (len < ETH_ZLEN) {
  1421. /* Very short packet, pad with zeros at the end. */
  1422. memset(desc->data + len, 0, ETH_ZLEN - len);
  1423. len = ETH_ZLEN;
  1424. }
  1425. desc->cmd    = cpu_to_be32(len | ETXD_INTWHENDONE | ETXD_D0V);
  1426. desc->bufcnt = cpu_to_be32(len);
  1427. } else if ((data ^ (data + len)) & 0x4000) {
  1428. unsigned long b2, s1, s2;
  1429. b2 = (data | 0x3fffUL) + 1UL;
  1430. s1 = b2 - data;
  1431. s2 = data + len - b2;
  1432. desc->cmd    = cpu_to_be32(len | ETXD_INTWHENDONE |
  1433.                            ETXD_B1V | ETXD_B2V);
  1434. desc->bufcnt = cpu_to_be32((s1 << ETXD_B1CNT_SHIFT)
  1435.                            | (s2 << ETXD_B2CNT_SHIFT));
  1436. desc->p1     = cpu_to_be64((0xa5UL << 56) |
  1437.                                            (data & TO_PHYS_MASK));
  1438. desc->p2     = cpu_to_be64((0xa5UL << 56) |
  1439.                            (data & TO_PHYS_MASK));
  1440. } else {
  1441. /* Normal sized packet that doesn't cross a page boundary. */
  1442. desc->cmd    = cpu_to_be32(len | ETXD_INTWHENDONE | ETXD_B1V);
  1443. desc->bufcnt = cpu_to_be32(len << ETXD_B1CNT_SHIFT);
  1444. desc->p1     = cpu_to_be64((0xa5UL << 56) |
  1445.                            (data & TO_PHYS_MASK));
  1446. }
  1447. BARRIER();
  1448. dev->trans_start = jiffies;
  1449. ip->tx_skbs[produce] = skb; /* Remember skb */
  1450. produce = (produce + 1) & 127;
  1451. ip->tx_pi = produce;
  1452. ioc3->etpir = produce << 7; /* Fire ... */
  1453. ip->txqlen++;
  1454. if (ip->txqlen > 127)
  1455. netif_stop_queue(dev);
  1456. spin_unlock_irq(&ip->ioc3_lock);
  1457. return 0;
  1458. }
  1459. static void ioc3_timeout(struct net_device *dev)
  1460. {
  1461. struct ioc3_private *ip = dev->priv;
  1462. printk(KERN_ERR "%s: transmit timed out, resettingn", dev->name);
  1463. ioc3_stop(ip);
  1464. ioc3_init(ip);
  1465. ioc3_mii_init(ip);
  1466. dev->trans_start = jiffies;
  1467. netif_wake_queue(dev);
  1468. }
  1469. /*
  1470.  * Given a multicast ethernet address, this routine calculates the
  1471.  * address's bit index in the logical address filter mask
  1472.  */
  1473. static inline unsigned int
  1474. ioc3_hash(const unsigned char *addr)
  1475. {
  1476. unsigned int temp = 0;
  1477. unsigned char byte;
  1478. u32 crc;
  1479. int bits;
  1480. crc = ether_crc_le(ETH_ALEN, addr);
  1481. crc &= 0x3f;    /* bit reverse lowest 6 bits for hash index */
  1482. for (bits = 6; --bits >= 0; ) {
  1483. temp <<= 1;
  1484. temp |= (crc & 0x1);
  1485. crc >>= 1;
  1486. }
  1487. return temp;
  1488. }
  1489. /* We provide both the mii-tools and the ethtool ioctls.  */
  1490. static int ioc3_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  1491. {
  1492. struct ioc3_private *ip = dev->priv;
  1493. struct ethtool_cmd *ep_user = (struct ethtool_cmd *) rq->ifr_data;
  1494. u16 *data = (u16 *)&rq->ifr_data;
  1495. struct ioc3 *ioc3 = ip->regs;
  1496. struct ethtool_cmd ecmd;
  1497. switch (cmd) {
  1498. case SIOCGMIIPHY: /* Get the address of the PHY in use.  */
  1499. if (ip->phy == -1)
  1500. return -ENODEV;
  1501. data[0] = ip->phy;
  1502. return 0;
  1503. case SIOCGMIIREG: { /* Read a PHY register.  */
  1504. unsigned int phy = data[0];
  1505. unsigned int reg = data[1];
  1506. if (phy > 0x1f || reg > 0x1f)
  1507. return -EINVAL;
  1508. spin_lock_irq(&ip->ioc3_lock);
  1509. while (ioc3->micr & MICR_BUSY);
  1510. ioc3->micr = (phy << MICR_PHYADDR_SHIFT) | reg | MICR_READTRIG;
  1511. while (ioc3->micr & MICR_BUSY);
  1512. data[3] = (ioc3->midr_r & MIDR_DATA_MASK);
  1513. spin_unlock_irq(&ip->ioc3_lock);
  1514. return 0;
  1515. case SIOCSMIIREG: /* Write a PHY register.  */
  1516. phy = data[0];
  1517. reg = data[1];
  1518. if (!capable(CAP_NET_ADMIN))
  1519. return -EPERM;
  1520. if (phy > 0x1f || reg > 0x1f)
  1521. return -EINVAL;
  1522. spin_lock_irq(&ip->ioc3_lock);
  1523. while (ioc3->micr & MICR_BUSY);
  1524. ioc3->midr_w = data[2];
  1525. ioc3->micr = (phy << MICR_PHYADDR_SHIFT) | reg;
  1526. while (ioc3->micr & MICR_BUSY);
  1527. spin_unlock_irq(&ip->ioc3_lock);
  1528. return 0;
  1529. }
  1530. case SIOCETHTOOL:
  1531. if (copy_from_user(&ecmd, ep_user, sizeof(ecmd)))
  1532. return -EFAULT;
  1533. if (ecmd.cmd == ETHTOOL_GSET) {
  1534. ecmd.supported =
  1535. (SUPPORTED_10baseT_Half |
  1536.  SUPPORTED_10baseT_Full |
  1537.  SUPPORTED_100baseT_Half |
  1538.  SUPPORTED_100baseT_Full | SUPPORTED_Autoneg |
  1539.  SUPPORTED_TP | SUPPORTED_MII);
  1540. ecmd.port = PORT_TP;
  1541. ecmd.transceiver = XCVR_INTERNAL;
  1542. ecmd.phy_address = ip->phy;
  1543. /* Record PHY settings. */
  1544. spin_lock_irq(&ip->ioc3_lock);
  1545. ip->sw_bmcr = mii_read(ip, MII_BMCR);
  1546. ip->sw_lpa = mii_read(ip, MII_LPA);
  1547. spin_unlock_irq(&ip->ioc3_lock);
  1548. if (ip->sw_bmcr & BMCR_ANENABLE) {
  1549. ecmd.autoneg = AUTONEG_ENABLE;
  1550. ecmd.speed = (ip->sw_lpa &
  1551.              (LPA_100HALF | LPA_100FULL)) ?
  1552.              SPEED_100 : SPEED_10;
  1553. if (ecmd.speed == SPEED_100)
  1554. ecmd.duplex = (ip->sw_lpa & (LPA_100FULL)) ?
  1555.               DUPLEX_FULL : DUPLEX_HALF;
  1556. else
  1557. ecmd.duplex = (ip->sw_lpa & (LPA_10FULL)) ?
  1558.               DUPLEX_FULL : DUPLEX_HALF;
  1559. } else {
  1560. ecmd.autoneg = AUTONEG_DISABLE;
  1561. ecmd.speed = (ip->sw_bmcr & BMCR_SPEED100) ?
  1562.              SPEED_100 : SPEED_10;
  1563. ecmd.duplex = (ip->sw_bmcr & BMCR_FULLDPLX) ?
  1564.               DUPLEX_FULL : DUPLEX_HALF;
  1565. }
  1566. if (copy_to_user(ep_user, &ecmd, sizeof(ecmd)))
  1567. return -EFAULT;
  1568. return 0;
  1569. } else if (ecmd.cmd == ETHTOOL_SSET) {
  1570. if (!capable(CAP_NET_ADMIN))
  1571. return -EPERM;
  1572. /* Verify the settings we care about. */
  1573. if (ecmd.autoneg != AUTONEG_ENABLE &&
  1574.     ecmd.autoneg != AUTONEG_DISABLE)
  1575. return -EINVAL;
  1576. if (ecmd.autoneg == AUTONEG_DISABLE &&
  1577.     ((ecmd.speed != SPEED_100 &&
  1578.       ecmd.speed != SPEED_10) ||
  1579.      (ecmd.duplex != DUPLEX_HALF &&
  1580.       ecmd.duplex != DUPLEX_FULL)))
  1581. return -EINVAL;
  1582. /* Ok, do it to it. */
  1583. del_timer(&ip->ioc3_timer);
  1584. spin_lock_irq(&ip->ioc3_lock);
  1585. ioc3_start_auto_negotiation(ip, &ecmd);
  1586. spin_unlock_irq(&ip->ioc3_lock);
  1587. return 0;
  1588. } else
  1589. default:
  1590. return -EOPNOTSUPP;
  1591. }
  1592. return -EOPNOTSUPP;
  1593. }
  1594. static void ioc3_set_multicast_list(struct net_device *dev)
  1595. {
  1596. struct dev_mc_list *dmi = dev->mc_list;
  1597. struct ioc3_private *ip = dev->priv;
  1598. struct ioc3 *ioc3 = ip->regs;
  1599. u64 ehar = 0;
  1600. int i;
  1601. netif_stop_queue(dev); /* Lock out others. */
  1602. if (dev->flags & IFF_PROMISC) { /* Set promiscuous.  */
  1603. /* Unconditionally log net taps.  */
  1604. printk(KERN_INFO "%s: Promiscuous mode enabled.n", dev->name);
  1605. ip->emcr |= EMCR_PROMISC;
  1606. ioc3->emcr = ip->emcr;
  1607. ioc3->emcr;
  1608. } else {
  1609. ip->emcr &= ~EMCR_PROMISC;
  1610. ioc3->emcr = ip->emcr; /* Clear promiscuous. */
  1611. ioc3->emcr;
  1612. if ((dev->flags & IFF_ALLMULTI) || (dev->mc_count > 64)) {
  1613. /* Too many for hashing to make sense or we want all
  1614.    multicast packets anyway,  so skip computing all the
  1615.    hashes and just accept all packets.  */
  1616. ip->ehar_h = 0xffffffff;
  1617. ip->ehar_l = 0xffffffff;
  1618. } else {
  1619. for (i = 0; i < dev->mc_count; i++) {
  1620. char *addr = dmi->dmi_addr;
  1621. dmi = dmi->next;
  1622. if (!(*addr & 1))
  1623. continue;
  1624. ehar |= (1UL << ioc3_hash(addr));
  1625. }
  1626. ip->ehar_h = ehar >> 32;
  1627. ip->ehar_l = ehar & 0xffffffff;
  1628. }
  1629. ioc3->ehar_h = ip->ehar_h;
  1630. ioc3->ehar_l = ip->ehar_l;
  1631. }
  1632. netif_wake_queue(dev); /* Let us get going again. */
  1633. }
  1634. MODULE_AUTHOR("Ralf Baechle <ralf@oss.sgi.com>");
  1635. MODULE_DESCRIPTION("SGI IOC3 Ethernet driver");
  1636. MODULE_LICENSE("GPL");
  1637. module_init(ioc3_init_module);
  1638. module_exit(ioc3_cleanup_module);