ioc3-eth.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715
  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, 01, 03, 06 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. #define IOC3_NAME "ioc3-eth"
  30. #define IOC3_VERSION "2.6.3-4"
  31. #include <linux/init.h>
  32. #include <linux/delay.h>
  33. #include <linux/kernel.h>
  34. #include <linux/mm.h>
  35. #include <linux/errno.h>
  36. #include <linux/module.h>
  37. #include <linux/pci.h>
  38. #include <linux/crc32.h>
  39. #include <linux/mii.h>
  40. #include <linux/in.h>
  41. #include <linux/ip.h>
  42. #include <linux/tcp.h>
  43. #include <linux/udp.h>
  44. #include <linux/dma-mapping.h>
  45. #ifdef CONFIG_SERIAL_8250
  46. #include <linux/serial_core.h>
  47. #include <linux/serial_8250.h>
  48. #include <linux/serial_reg.h>
  49. #endif
  50. #include <linux/netdevice.h>
  51. #include <linux/etherdevice.h>
  52. #include <linux/ethtool.h>
  53. #include <linux/skbuff.h>
  54. #include <net/ip.h>
  55. #include <asm/byteorder.h>
  56. #include <asm/io.h>
  57. #include <asm/pgtable.h>
  58. #include <asm/uaccess.h>
  59. #include <asm/sn/types.h>
  60. #include <asm/sn/ioc3.h>
  61. #include <asm/pci/bridge.h>
  62. /*
  63. * 64 RX buffers. This is tunable in the range of 16 <= x < 512. The
  64. * value must be a power of two.
  65. */
  66. #define RX_BUFFS 64
  67. #define ETCSR_FD ((17<<ETCSR_IPGR2_SHIFT) | (11<<ETCSR_IPGR1_SHIFT) | 21)
  68. #define ETCSR_HD ((21<<ETCSR_IPGR2_SHIFT) | (21<<ETCSR_IPGR1_SHIFT) | 21)
  69. /* Private per NIC data of the driver. */
  70. struct ioc3_private {
  71. struct ioc3 *regs;
  72. unsigned long *rxr; /* pointer to receiver ring */
  73. struct ioc3_etxd *txr;
  74. struct sk_buff *rx_skbs[512];
  75. struct sk_buff *tx_skbs[128];
  76. struct net_device_stats stats;
  77. int rx_ci; /* RX consumer index */
  78. int rx_pi; /* RX producer index */
  79. int tx_ci; /* TX consumer index */
  80. int tx_pi; /* TX producer index */
  81. int txqlen;
  82. u32 emcr, ehar_h, ehar_l;
  83. spinlock_t ioc3_lock;
  84. struct mii_if_info mii;
  85. unsigned long flags;
  86. #define IOC3_FLAG_RX_CHECKSUMS 1
  87. struct pci_dev *pdev;
  88. /* Members used by autonegotiation */
  89. struct timer_list ioc3_timer;
  90. };
  91. static inline struct net_device *priv_netdev(struct ioc3_private *dev)
  92. {
  93. return (void *)dev - ((sizeof(struct net_device) + 31) & ~31);
  94. }
  95. static int ioc3_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  96. static void ioc3_set_multicast_list(struct net_device *dev);
  97. static int ioc3_start_xmit(struct sk_buff *skb, struct net_device *dev);
  98. static void ioc3_timeout(struct net_device *dev);
  99. static inline unsigned int ioc3_hash(const unsigned char *addr);
  100. static inline void ioc3_stop(struct ioc3_private *ip);
  101. static void ioc3_init(struct net_device *dev);
  102. static const char ioc3_str[] = "IOC3 Ethernet";
  103. static const struct ethtool_ops ioc3_ethtool_ops;
  104. /* We use this to acquire receive skb's that we can DMA directly into. */
  105. #define IOC3_CACHELINE 128UL
  106. static inline unsigned long aligned_rx_skb_addr(unsigned long addr)
  107. {
  108. return (~addr + 1) & (IOC3_CACHELINE - 1UL);
  109. }
  110. static inline struct sk_buff * ioc3_alloc_skb(unsigned long length,
  111. unsigned int gfp_mask)
  112. {
  113. struct sk_buff *skb;
  114. skb = alloc_skb(length + IOC3_CACHELINE - 1, gfp_mask);
  115. if (likely(skb)) {
  116. int offset = aligned_rx_skb_addr((unsigned long) skb->data);
  117. if (offset)
  118. skb_reserve(skb, offset);
  119. }
  120. return skb;
  121. }
  122. static inline unsigned long ioc3_map(void *ptr, unsigned long vdev)
  123. {
  124. #ifdef CONFIG_SGI_IP27
  125. vdev <<= 57; /* Shift to PCI64_ATTR_VIRTUAL */
  126. return vdev | (0xaUL << PCI64_ATTR_TARG_SHFT) | PCI64_ATTR_PREF |
  127. ((unsigned long)ptr & TO_PHYS_MASK);
  128. #else
  129. return virt_to_bus(ptr);
  130. #endif
  131. }
  132. /* BEWARE: The IOC3 documentation documents the size of rx buffers as
  133. 1644 while it's actually 1664. This one was nasty to track down ... */
  134. #define RX_OFFSET 10
  135. #define RX_BUF_ALLOC_SIZE (1664 + RX_OFFSET + IOC3_CACHELINE)
  136. /* DMA barrier to separate cached and uncached accesses. */
  137. #define BARRIER() \
  138. __asm__("sync" ::: "memory")
  139. #define IOC3_SIZE 0x100000
  140. /*
  141. * IOC3 is a big endian device
  142. *
  143. * Unorthodox but makes the users of these macros more readable - the pointer
  144. * to the IOC3's memory mapped registers is expected as struct ioc3 * ioc3
  145. * in the environment.
  146. */
  147. #define ioc3_r_mcr() be32_to_cpu(ioc3->mcr)
  148. #define ioc3_w_mcr(v) do { ioc3->mcr = cpu_to_be32(v); } while (0)
  149. #define ioc3_w_gpcr_s(v) do { ioc3->gpcr_s = cpu_to_be32(v); } while (0)
  150. #define ioc3_r_emcr() be32_to_cpu(ioc3->emcr)
  151. #define ioc3_w_emcr(v) do { ioc3->emcr = cpu_to_be32(v); } while (0)
  152. #define ioc3_r_eisr() be32_to_cpu(ioc3->eisr)
  153. #define ioc3_w_eisr(v) do { ioc3->eisr = cpu_to_be32(v); } while (0)
  154. #define ioc3_r_eier() be32_to_cpu(ioc3->eier)
  155. #define ioc3_w_eier(v) do { ioc3->eier = cpu_to_be32(v); } while (0)
  156. #define ioc3_r_ercsr() be32_to_cpu(ioc3->ercsr)
  157. #define ioc3_w_ercsr(v) do { ioc3->ercsr = cpu_to_be32(v); } while (0)
  158. #define ioc3_r_erbr_h() be32_to_cpu(ioc3->erbr_h)
  159. #define ioc3_w_erbr_h(v) do { ioc3->erbr_h = cpu_to_be32(v); } while (0)
  160. #define ioc3_r_erbr_l() be32_to_cpu(ioc3->erbr_l)
  161. #define ioc3_w_erbr_l(v) do { ioc3->erbr_l = cpu_to_be32(v); } while (0)
  162. #define ioc3_r_erbar() be32_to_cpu(ioc3->erbar)
  163. #define ioc3_w_erbar(v) do { ioc3->erbar = cpu_to_be32(v); } while (0)
  164. #define ioc3_r_ercir() be32_to_cpu(ioc3->ercir)
  165. #define ioc3_w_ercir(v) do { ioc3->ercir = cpu_to_be32(v); } while (0)
  166. #define ioc3_r_erpir() be32_to_cpu(ioc3->erpir)
  167. #define ioc3_w_erpir(v) do { ioc3->erpir = cpu_to_be32(v); } while (0)
  168. #define ioc3_r_ertr() be32_to_cpu(ioc3->ertr)
  169. #define ioc3_w_ertr(v) do { ioc3->ertr = cpu_to_be32(v); } while (0)
  170. #define ioc3_r_etcsr() be32_to_cpu(ioc3->etcsr)
  171. #define ioc3_w_etcsr(v) do { ioc3->etcsr = cpu_to_be32(v); } while (0)
  172. #define ioc3_r_ersr() be32_to_cpu(ioc3->ersr)
  173. #define ioc3_w_ersr(v) do { ioc3->ersr = cpu_to_be32(v); } while (0)
  174. #define ioc3_r_etcdc() be32_to_cpu(ioc3->etcdc)
  175. #define ioc3_w_etcdc(v) do { ioc3->etcdc = cpu_to_be32(v); } while (0)
  176. #define ioc3_r_ebir() be32_to_cpu(ioc3->ebir)
  177. #define ioc3_w_ebir(v) do { ioc3->ebir = cpu_to_be32(v); } while (0)
  178. #define ioc3_r_etbr_h() be32_to_cpu(ioc3->etbr_h)
  179. #define ioc3_w_etbr_h(v) do { ioc3->etbr_h = cpu_to_be32(v); } while (0)
  180. #define ioc3_r_etbr_l() be32_to_cpu(ioc3->etbr_l)
  181. #define ioc3_w_etbr_l(v) do { ioc3->etbr_l = cpu_to_be32(v); } while (0)
  182. #define ioc3_r_etcir() be32_to_cpu(ioc3->etcir)
  183. #define ioc3_w_etcir(v) do { ioc3->etcir = cpu_to_be32(v); } while (0)
  184. #define ioc3_r_etpir() be32_to_cpu(ioc3->etpir)
  185. #define ioc3_w_etpir(v) do { ioc3->etpir = cpu_to_be32(v); } while (0)
  186. #define ioc3_r_emar_h() be32_to_cpu(ioc3->emar_h)
  187. #define ioc3_w_emar_h(v) do { ioc3->emar_h = cpu_to_be32(v); } while (0)
  188. #define ioc3_r_emar_l() be32_to_cpu(ioc3->emar_l)
  189. #define ioc3_w_emar_l(v) do { ioc3->emar_l = cpu_to_be32(v); } while (0)
  190. #define ioc3_r_ehar_h() be32_to_cpu(ioc3->ehar_h)
  191. #define ioc3_w_ehar_h(v) do { ioc3->ehar_h = cpu_to_be32(v); } while (0)
  192. #define ioc3_r_ehar_l() be32_to_cpu(ioc3->ehar_l)
  193. #define ioc3_w_ehar_l(v) do { ioc3->ehar_l = cpu_to_be32(v); } while (0)
  194. #define ioc3_r_micr() be32_to_cpu(ioc3->micr)
  195. #define ioc3_w_micr(v) do { ioc3->micr = cpu_to_be32(v); } while (0)
  196. #define ioc3_r_midr_r() be32_to_cpu(ioc3->midr_r)
  197. #define ioc3_w_midr_r(v) do { ioc3->midr_r = cpu_to_be32(v); } while (0)
  198. #define ioc3_r_midr_w() be32_to_cpu(ioc3->midr_w)
  199. #define ioc3_w_midr_w(v) do { ioc3->midr_w = cpu_to_be32(v); } while (0)
  200. static inline u32 mcr_pack(u32 pulse, u32 sample)
  201. {
  202. return (pulse << 10) | (sample << 2);
  203. }
  204. static int nic_wait(struct ioc3 *ioc3)
  205. {
  206. u32 mcr;
  207. do {
  208. mcr = ioc3_r_mcr();
  209. } while (!(mcr & 2));
  210. return mcr & 1;
  211. }
  212. static int nic_reset(struct ioc3 *ioc3)
  213. {
  214. int presence;
  215. ioc3_w_mcr(mcr_pack(500, 65));
  216. presence = nic_wait(ioc3);
  217. ioc3_w_mcr(mcr_pack(0, 500));
  218. nic_wait(ioc3);
  219. return presence;
  220. }
  221. static inline int nic_read_bit(struct ioc3 *ioc3)
  222. {
  223. int result;
  224. ioc3_w_mcr(mcr_pack(6, 13));
  225. result = nic_wait(ioc3);
  226. ioc3_w_mcr(mcr_pack(0, 100));
  227. nic_wait(ioc3);
  228. return result;
  229. }
  230. static inline void nic_write_bit(struct ioc3 *ioc3, int bit)
  231. {
  232. if (bit)
  233. ioc3_w_mcr(mcr_pack(6, 110));
  234. else
  235. ioc3_w_mcr(mcr_pack(80, 30));
  236. nic_wait(ioc3);
  237. }
  238. /*
  239. * Read a byte from an iButton device
  240. */
  241. static u32 nic_read_byte(struct ioc3 *ioc3)
  242. {
  243. u32 result = 0;
  244. int i;
  245. for (i = 0; i < 8; i++)
  246. result = (result >> 1) | (nic_read_bit(ioc3) << 7);
  247. return result;
  248. }
  249. /*
  250. * Write a byte to an iButton device
  251. */
  252. static void nic_write_byte(struct ioc3 *ioc3, int byte)
  253. {
  254. int i, bit;
  255. for (i = 8; i; i--) {
  256. bit = byte & 1;
  257. byte >>= 1;
  258. nic_write_bit(ioc3, bit);
  259. }
  260. }
  261. static u64 nic_find(struct ioc3 *ioc3, int *last)
  262. {
  263. int a, b, index, disc;
  264. u64 address = 0;
  265. nic_reset(ioc3);
  266. /* Search ROM. */
  267. nic_write_byte(ioc3, 0xf0);
  268. /* Algorithm from ``Book of iButton Standards''. */
  269. for (index = 0, disc = 0; index < 64; index++) {
  270. a = nic_read_bit(ioc3);
  271. b = nic_read_bit(ioc3);
  272. if (a && b) {
  273. printk("NIC search failed (not fatal).\n");
  274. *last = 0;
  275. return 0;
  276. }
  277. if (!a && !b) {
  278. if (index == *last) {
  279. address |= 1UL << index;
  280. } else if (index > *last) {
  281. address &= ~(1UL << index);
  282. disc = index;
  283. } else if ((address & (1UL << index)) == 0)
  284. disc = index;
  285. nic_write_bit(ioc3, address & (1UL << index));
  286. continue;
  287. } else {
  288. if (a)
  289. address |= 1UL << index;
  290. else
  291. address &= ~(1UL << index);
  292. nic_write_bit(ioc3, a);
  293. continue;
  294. }
  295. }
  296. *last = disc;
  297. return address;
  298. }
  299. static int nic_init(struct ioc3 *ioc3)
  300. {
  301. const char *unknown = "unknown";
  302. const char *type = unknown;
  303. u8 crc;
  304. u8 serial[6];
  305. int save = 0, i;
  306. while (1) {
  307. u64 reg;
  308. reg = nic_find(ioc3, &save);
  309. switch (reg & 0xff) {
  310. case 0x91:
  311. type = "DS1981U";
  312. break;
  313. default:
  314. if (save == 0) {
  315. /* Let the caller try again. */
  316. return -1;
  317. }
  318. continue;
  319. }
  320. nic_reset(ioc3);
  321. /* Match ROM. */
  322. nic_write_byte(ioc3, 0x55);
  323. for (i = 0; i < 8; i++)
  324. nic_write_byte(ioc3, (reg >> (i << 3)) & 0xff);
  325. reg >>= 8; /* Shift out type. */
  326. for (i = 0; i < 6; i++) {
  327. serial[i] = reg & 0xff;
  328. reg >>= 8;
  329. }
  330. crc = reg & 0xff;
  331. break;
  332. }
  333. printk("Found %s NIC", type);
  334. if (type != unknown) {
  335. printk (" registration number %02x:%02x:%02x:%02x:%02x:%02x,"
  336. " CRC %02x", serial[0], serial[1], serial[2],
  337. serial[3], serial[4], serial[5], crc);
  338. }
  339. printk(".\n");
  340. return 0;
  341. }
  342. /*
  343. * Read the NIC (Number-In-a-Can) device used to store the MAC address on
  344. * SN0 / SN00 nodeboards and PCI cards.
  345. */
  346. static void ioc3_get_eaddr_nic(struct ioc3_private *ip)
  347. {
  348. struct ioc3 *ioc3 = ip->regs;
  349. u8 nic[14];
  350. int tries = 2; /* There may be some problem with the battery? */
  351. int i;
  352. ioc3_w_gpcr_s(1 << 21);
  353. while (tries--) {
  354. if (!nic_init(ioc3))
  355. break;
  356. udelay(500);
  357. }
  358. if (tries < 0) {
  359. printk("Failed to read MAC address\n");
  360. return;
  361. }
  362. /* Read Memory. */
  363. nic_write_byte(ioc3, 0xf0);
  364. nic_write_byte(ioc3, 0x00);
  365. nic_write_byte(ioc3, 0x00);
  366. for (i = 13; i >= 0; i--)
  367. nic[i] = nic_read_byte(ioc3);
  368. for (i = 2; i < 8; i++)
  369. priv_netdev(ip)->dev_addr[i - 2] = nic[i];
  370. }
  371. /*
  372. * Ok, this is hosed by design. It's necessary to know what machine the
  373. * NIC is in in order to know how to read the NIC address. We also have
  374. * to know if it's a PCI card or a NIC in on the node board ...
  375. */
  376. static void ioc3_get_eaddr(struct ioc3_private *ip)
  377. {
  378. DECLARE_MAC_BUF(mac);
  379. ioc3_get_eaddr_nic(ip);
  380. printk("Ethernet address is %s.\n",
  381. print_mac(mac, priv_netdev(ip)->dev_addr));
  382. }
  383. static void __ioc3_set_mac_address(struct net_device *dev)
  384. {
  385. struct ioc3_private *ip = netdev_priv(dev);
  386. struct ioc3 *ioc3 = ip->regs;
  387. ioc3_w_emar_h((dev->dev_addr[5] << 8) | dev->dev_addr[4]);
  388. ioc3_w_emar_l((dev->dev_addr[3] << 24) | (dev->dev_addr[2] << 16) |
  389. (dev->dev_addr[1] << 8) | dev->dev_addr[0]);
  390. }
  391. static int ioc3_set_mac_address(struct net_device *dev, void *addr)
  392. {
  393. struct ioc3_private *ip = netdev_priv(dev);
  394. struct sockaddr *sa = addr;
  395. memcpy(dev->dev_addr, sa->sa_data, dev->addr_len);
  396. spin_lock_irq(&ip->ioc3_lock);
  397. __ioc3_set_mac_address(dev);
  398. spin_unlock_irq(&ip->ioc3_lock);
  399. return 0;
  400. }
  401. /*
  402. * Caller must hold the ioc3_lock ever for MII readers. This is also
  403. * used to protect the transmitter side but it's low contention.
  404. */
  405. static int ioc3_mdio_read(struct net_device *dev, int phy, int reg)
  406. {
  407. struct ioc3_private *ip = netdev_priv(dev);
  408. struct ioc3 *ioc3 = ip->regs;
  409. while (ioc3_r_micr() & MICR_BUSY);
  410. ioc3_w_micr((phy << MICR_PHYADDR_SHIFT) | reg | MICR_READTRIG);
  411. while (ioc3_r_micr() & MICR_BUSY);
  412. return ioc3_r_midr_r() & MIDR_DATA_MASK;
  413. }
  414. static void ioc3_mdio_write(struct net_device *dev, int phy, int reg, int data)
  415. {
  416. struct ioc3_private *ip = netdev_priv(dev);
  417. struct ioc3 *ioc3 = ip->regs;
  418. while (ioc3_r_micr() & MICR_BUSY);
  419. ioc3_w_midr_w(data);
  420. ioc3_w_micr((phy << MICR_PHYADDR_SHIFT) | reg);
  421. while (ioc3_r_micr() & MICR_BUSY);
  422. }
  423. static int ioc3_mii_init(struct ioc3_private *ip);
  424. static struct net_device_stats *ioc3_get_stats(struct net_device *dev)
  425. {
  426. struct ioc3_private *ip = netdev_priv(dev);
  427. struct ioc3 *ioc3 = ip->regs;
  428. ip->stats.collisions += (ioc3_r_etcdc() & ETCDC_COLLCNT_MASK);
  429. return &ip->stats;
  430. }
  431. static void ioc3_tcpudp_checksum(struct sk_buff *skb, uint32_t hwsum, int len)
  432. {
  433. struct ethhdr *eh = eth_hdr(skb);
  434. uint32_t csum, ehsum;
  435. unsigned int proto;
  436. struct iphdr *ih;
  437. uint16_t *ew;
  438. unsigned char *cp;
  439. /*
  440. * Did hardware handle the checksum at all? The cases we can handle
  441. * are:
  442. *
  443. * - TCP and UDP checksums of IPv4 only.
  444. * - IPv6 would be doable but we keep that for later ...
  445. * - Only unfragmented packets. Did somebody already tell you
  446. * fragmentation is evil?
  447. * - don't care about packet size. Worst case when processing a
  448. * malformed packet we'll try to access the packet at ip header +
  449. * 64 bytes which is still inside the skb. Even in the unlikely
  450. * case where the checksum is right the higher layers will still
  451. * drop the packet as appropriate.
  452. */
  453. if (eh->h_proto != ntohs(ETH_P_IP))
  454. return;
  455. ih = (struct iphdr *) ((char *)eh + ETH_HLEN);
  456. if (ih->frag_off & htons(IP_MF | IP_OFFSET))
  457. return;
  458. proto = ih->protocol;
  459. if (proto != IPPROTO_TCP && proto != IPPROTO_UDP)
  460. return;
  461. /* Same as tx - compute csum of pseudo header */
  462. csum = hwsum +
  463. (ih->tot_len - (ih->ihl << 2)) +
  464. htons((uint16_t)ih->protocol) +
  465. (ih->saddr >> 16) + (ih->saddr & 0xffff) +
  466. (ih->daddr >> 16) + (ih->daddr & 0xffff);
  467. /* Sum up ethernet dest addr, src addr and protocol */
  468. ew = (uint16_t *) eh;
  469. ehsum = ew[0] + ew[1] + ew[2] + ew[3] + ew[4] + ew[5] + ew[6];
  470. ehsum = (ehsum & 0xffff) + (ehsum >> 16);
  471. ehsum = (ehsum & 0xffff) + (ehsum >> 16);
  472. csum += 0xffff ^ ehsum;
  473. /* In the next step we also subtract the 1's complement
  474. checksum of the trailing ethernet CRC. */
  475. cp = (char *)eh + len; /* points at trailing CRC */
  476. if (len & 1) {
  477. csum += 0xffff ^ (uint16_t) ((cp[1] << 8) | cp[0]);
  478. csum += 0xffff ^ (uint16_t) ((cp[3] << 8) | cp[2]);
  479. } else {
  480. csum += 0xffff ^ (uint16_t) ((cp[0] << 8) | cp[1]);
  481. csum += 0xffff ^ (uint16_t) ((cp[2] << 8) | cp[3]);
  482. }
  483. csum = (csum & 0xffff) + (csum >> 16);
  484. csum = (csum & 0xffff) + (csum >> 16);
  485. if (csum == 0xffff)
  486. skb->ip_summed = CHECKSUM_UNNECESSARY;
  487. }
  488. static inline void ioc3_rx(struct ioc3_private *ip)
  489. {
  490. struct sk_buff *skb, *new_skb;
  491. struct ioc3 *ioc3 = ip->regs;
  492. int rx_entry, n_entry, len;
  493. struct ioc3_erxbuf *rxb;
  494. unsigned long *rxr;
  495. u32 w0, err;
  496. rxr = (unsigned long *) ip->rxr; /* Ring base */
  497. rx_entry = ip->rx_ci; /* RX consume index */
  498. n_entry = ip->rx_pi;
  499. skb = ip->rx_skbs[rx_entry];
  500. rxb = (struct ioc3_erxbuf *) (skb->data - RX_OFFSET);
  501. w0 = be32_to_cpu(rxb->w0);
  502. while (w0 & ERXBUF_V) {
  503. err = be32_to_cpu(rxb->err); /* It's valid ... */
  504. if (err & ERXBUF_GOODPKT) {
  505. len = ((w0 >> ERXBUF_BYTECNT_SHIFT) & 0x7ff) - 4;
  506. skb_trim(skb, len);
  507. skb->protocol = eth_type_trans(skb, priv_netdev(ip));
  508. new_skb = ioc3_alloc_skb(RX_BUF_ALLOC_SIZE, GFP_ATOMIC);
  509. if (!new_skb) {
  510. /* Ouch, drop packet and just recycle packet
  511. to keep the ring filled. */
  512. ip->stats.rx_dropped++;
  513. new_skb = skb;
  514. goto next;
  515. }
  516. if (likely(ip->flags & IOC3_FLAG_RX_CHECKSUMS))
  517. ioc3_tcpudp_checksum(skb,
  518. w0 & ERXBUF_IPCKSUM_MASK, len);
  519. netif_rx(skb);
  520. ip->rx_skbs[rx_entry] = NULL; /* Poison */
  521. /* Because we reserve afterwards. */
  522. skb_put(new_skb, (1664 + RX_OFFSET));
  523. rxb = (struct ioc3_erxbuf *) new_skb->data;
  524. skb_reserve(new_skb, RX_OFFSET);
  525. priv_netdev(ip)->last_rx = jiffies;
  526. ip->stats.rx_packets++; /* Statistics */
  527. ip->stats.rx_bytes += len;
  528. } else {
  529. /* The frame is invalid and the skb never
  530. reached the network layer so we can just
  531. recycle it. */
  532. new_skb = skb;
  533. ip->stats.rx_errors++;
  534. }
  535. if (err & ERXBUF_CRCERR) /* Statistics */
  536. ip->stats.rx_crc_errors++;
  537. if (err & ERXBUF_FRAMERR)
  538. ip->stats.rx_frame_errors++;
  539. next:
  540. ip->rx_skbs[n_entry] = new_skb;
  541. rxr[n_entry] = cpu_to_be64(ioc3_map(rxb, 1));
  542. rxb->w0 = 0; /* Clear valid flag */
  543. n_entry = (n_entry + 1) & 511; /* Update erpir */
  544. /* Now go on to the next ring entry. */
  545. rx_entry = (rx_entry + 1) & 511;
  546. skb = ip->rx_skbs[rx_entry];
  547. rxb = (struct ioc3_erxbuf *) (skb->data - RX_OFFSET);
  548. w0 = be32_to_cpu(rxb->w0);
  549. }
  550. ioc3_w_erpir((n_entry << 3) | ERPIR_ARM);
  551. ip->rx_pi = n_entry;
  552. ip->rx_ci = rx_entry;
  553. }
  554. static inline void ioc3_tx(struct ioc3_private *ip)
  555. {
  556. unsigned long packets, bytes;
  557. struct ioc3 *ioc3 = ip->regs;
  558. int tx_entry, o_entry;
  559. struct sk_buff *skb;
  560. u32 etcir;
  561. spin_lock(&ip->ioc3_lock);
  562. etcir = ioc3_r_etcir();
  563. tx_entry = (etcir >> 7) & 127;
  564. o_entry = ip->tx_ci;
  565. packets = 0;
  566. bytes = 0;
  567. while (o_entry != tx_entry) {
  568. packets++;
  569. skb = ip->tx_skbs[o_entry];
  570. bytes += skb->len;
  571. dev_kfree_skb_irq(skb);
  572. ip->tx_skbs[o_entry] = NULL;
  573. o_entry = (o_entry + 1) & 127; /* Next */
  574. etcir = ioc3_r_etcir(); /* More pkts sent? */
  575. tx_entry = (etcir >> 7) & 127;
  576. }
  577. ip->stats.tx_packets += packets;
  578. ip->stats.tx_bytes += bytes;
  579. ip->txqlen -= packets;
  580. if (ip->txqlen < 128)
  581. netif_wake_queue(priv_netdev(ip));
  582. ip->tx_ci = o_entry;
  583. spin_unlock(&ip->ioc3_lock);
  584. }
  585. /*
  586. * Deal with fatal IOC3 errors. This condition might be caused by a hard or
  587. * software problems, so we should try to recover
  588. * more gracefully if this ever happens. In theory we might be flooded
  589. * with such error interrupts if something really goes wrong, so we might
  590. * also consider to take the interface down.
  591. */
  592. static void ioc3_error(struct ioc3_private *ip, u32 eisr)
  593. {
  594. struct net_device *dev = priv_netdev(ip);
  595. unsigned char *iface = dev->name;
  596. spin_lock(&ip->ioc3_lock);
  597. if (eisr & EISR_RXOFLO)
  598. printk(KERN_ERR "%s: RX overflow.\n", iface);
  599. if (eisr & EISR_RXBUFOFLO)
  600. printk(KERN_ERR "%s: RX buffer overflow.\n", iface);
  601. if (eisr & EISR_RXMEMERR)
  602. printk(KERN_ERR "%s: RX PCI error.\n", iface);
  603. if (eisr & EISR_RXPARERR)
  604. printk(KERN_ERR "%s: RX SSRAM parity error.\n", iface);
  605. if (eisr & EISR_TXBUFUFLO)
  606. printk(KERN_ERR "%s: TX buffer underflow.\n", iface);
  607. if (eisr & EISR_TXMEMERR)
  608. printk(KERN_ERR "%s: TX PCI error.\n", iface);
  609. ioc3_stop(ip);
  610. ioc3_init(dev);
  611. ioc3_mii_init(ip);
  612. netif_wake_queue(dev);
  613. spin_unlock(&ip->ioc3_lock);
  614. }
  615. /* The interrupt handler does all of the Rx thread work and cleans up
  616. after the Tx thread. */
  617. static irqreturn_t ioc3_interrupt(int irq, void *_dev)
  618. {
  619. struct net_device *dev = (struct net_device *)_dev;
  620. struct ioc3_private *ip = netdev_priv(dev);
  621. struct ioc3 *ioc3 = ip->regs;
  622. const u32 enabled = EISR_RXTIMERINT | EISR_RXOFLO | EISR_RXBUFOFLO |
  623. EISR_RXMEMERR | EISR_RXPARERR | EISR_TXBUFUFLO |
  624. EISR_TXEXPLICIT | EISR_TXMEMERR;
  625. u32 eisr;
  626. eisr = ioc3_r_eisr() & enabled;
  627. ioc3_w_eisr(eisr);
  628. (void) ioc3_r_eisr(); /* Flush */
  629. if (eisr & (EISR_RXOFLO | EISR_RXBUFOFLO | EISR_RXMEMERR |
  630. EISR_RXPARERR | EISR_TXBUFUFLO | EISR_TXMEMERR))
  631. ioc3_error(ip, eisr);
  632. if (eisr & EISR_RXTIMERINT)
  633. ioc3_rx(ip);
  634. if (eisr & EISR_TXEXPLICIT)
  635. ioc3_tx(ip);
  636. return IRQ_HANDLED;
  637. }
  638. static inline void ioc3_setup_duplex(struct ioc3_private *ip)
  639. {
  640. struct ioc3 *ioc3 = ip->regs;
  641. if (ip->mii.full_duplex) {
  642. ioc3_w_etcsr(ETCSR_FD);
  643. ip->emcr |= EMCR_DUPLEX;
  644. } else {
  645. ioc3_w_etcsr(ETCSR_HD);
  646. ip->emcr &= ~EMCR_DUPLEX;
  647. }
  648. ioc3_w_emcr(ip->emcr);
  649. }
  650. static void ioc3_timer(unsigned long data)
  651. {
  652. struct ioc3_private *ip = (struct ioc3_private *) data;
  653. /* Print the link status if it has changed */
  654. mii_check_media(&ip->mii, 1, 0);
  655. ioc3_setup_duplex(ip);
  656. ip->ioc3_timer.expires = jiffies + ((12 * HZ)/10); /* 1.2s */
  657. add_timer(&ip->ioc3_timer);
  658. }
  659. /*
  660. * Try to find a PHY. There is no apparent relation between the MII addresses
  661. * in the SGI documentation and what we find in reality, so we simply probe
  662. * for the PHY. It seems IOC3 PHYs usually live on address 31. One of my
  663. * onboard IOC3s has the special oddity that probing doesn't seem to find it
  664. * yet the interface seems to work fine, so if probing fails we for now will
  665. * simply default to PHY 31 instead of bailing out.
  666. */
  667. static int ioc3_mii_init(struct ioc3_private *ip)
  668. {
  669. struct net_device *dev = priv_netdev(ip);
  670. int i, found = 0, res = 0;
  671. int ioc3_phy_workaround = 1;
  672. u16 word;
  673. for (i = 0; i < 32; i++) {
  674. word = ioc3_mdio_read(dev, i, MII_PHYSID1);
  675. if (word != 0xffff && word != 0x0000) {
  676. found = 1;
  677. break; /* Found a PHY */
  678. }
  679. }
  680. if (!found) {
  681. if (ioc3_phy_workaround)
  682. i = 31;
  683. else {
  684. ip->mii.phy_id = -1;
  685. res = -ENODEV;
  686. goto out;
  687. }
  688. }
  689. ip->mii.phy_id = i;
  690. out:
  691. return res;
  692. }
  693. static void ioc3_mii_start(struct ioc3_private *ip)
  694. {
  695. ip->ioc3_timer.expires = jiffies + (12 * HZ)/10; /* 1.2 sec. */
  696. ip->ioc3_timer.data = (unsigned long) ip;
  697. ip->ioc3_timer.function = &ioc3_timer;
  698. add_timer(&ip->ioc3_timer);
  699. }
  700. static inline void ioc3_clean_rx_ring(struct ioc3_private *ip)
  701. {
  702. struct sk_buff *skb;
  703. int i;
  704. for (i = ip->rx_ci; i & 15; i++) {
  705. ip->rx_skbs[ip->rx_pi] = ip->rx_skbs[ip->rx_ci];
  706. ip->rxr[ip->rx_pi++] = ip->rxr[ip->rx_ci++];
  707. }
  708. ip->rx_pi &= 511;
  709. ip->rx_ci &= 511;
  710. for (i = ip->rx_ci; i != ip->rx_pi; i = (i+1) & 511) {
  711. struct ioc3_erxbuf *rxb;
  712. skb = ip->rx_skbs[i];
  713. rxb = (struct ioc3_erxbuf *) (skb->data - RX_OFFSET);
  714. rxb->w0 = 0;
  715. }
  716. }
  717. static inline void ioc3_clean_tx_ring(struct ioc3_private *ip)
  718. {
  719. struct sk_buff *skb;
  720. int i;
  721. for (i=0; i < 128; i++) {
  722. skb = ip->tx_skbs[i];
  723. if (skb) {
  724. ip->tx_skbs[i] = NULL;
  725. dev_kfree_skb_any(skb);
  726. }
  727. ip->txr[i].cmd = 0;
  728. }
  729. ip->tx_pi = 0;
  730. ip->tx_ci = 0;
  731. }
  732. static void ioc3_free_rings(struct ioc3_private *ip)
  733. {
  734. struct sk_buff *skb;
  735. int rx_entry, n_entry;
  736. if (ip->txr) {
  737. ioc3_clean_tx_ring(ip);
  738. free_pages((unsigned long)ip->txr, 2);
  739. ip->txr = NULL;
  740. }
  741. if (ip->rxr) {
  742. n_entry = ip->rx_ci;
  743. rx_entry = ip->rx_pi;
  744. while (n_entry != rx_entry) {
  745. skb = ip->rx_skbs[n_entry];
  746. if (skb)
  747. dev_kfree_skb_any(skb);
  748. n_entry = (n_entry + 1) & 511;
  749. }
  750. free_page((unsigned long)ip->rxr);
  751. ip->rxr = NULL;
  752. }
  753. }
  754. static void ioc3_alloc_rings(struct net_device *dev)
  755. {
  756. struct ioc3_private *ip = netdev_priv(dev);
  757. struct ioc3_erxbuf *rxb;
  758. unsigned long *rxr;
  759. int i;
  760. if (ip->rxr == NULL) {
  761. /* Allocate and initialize rx ring. 4kb = 512 entries */
  762. ip->rxr = (unsigned long *) get_zeroed_page(GFP_ATOMIC);
  763. rxr = (unsigned long *) ip->rxr;
  764. if (!rxr)
  765. printk("ioc3_alloc_rings(): get_zeroed_page() failed!\n");
  766. /* Now the rx buffers. The RX ring may be larger but
  767. we only allocate 16 buffers for now. Need to tune
  768. this for performance and memory later. */
  769. for (i = 0; i < RX_BUFFS; i++) {
  770. struct sk_buff *skb;
  771. skb = ioc3_alloc_skb(RX_BUF_ALLOC_SIZE, GFP_ATOMIC);
  772. if (!skb) {
  773. show_free_areas();
  774. continue;
  775. }
  776. ip->rx_skbs[i] = skb;
  777. /* Because we reserve afterwards. */
  778. skb_put(skb, (1664 + RX_OFFSET));
  779. rxb = (struct ioc3_erxbuf *) skb->data;
  780. rxr[i] = cpu_to_be64(ioc3_map(rxb, 1));
  781. skb_reserve(skb, RX_OFFSET);
  782. }
  783. ip->rx_ci = 0;
  784. ip->rx_pi = RX_BUFFS;
  785. }
  786. if (ip->txr == NULL) {
  787. /* Allocate and initialize tx rings. 16kb = 128 bufs. */
  788. ip->txr = (struct ioc3_etxd *)__get_free_pages(GFP_KERNEL, 2);
  789. if (!ip->txr)
  790. printk("ioc3_alloc_rings(): __get_free_pages() failed!\n");
  791. ip->tx_pi = 0;
  792. ip->tx_ci = 0;
  793. }
  794. }
  795. static void ioc3_init_rings(struct net_device *dev)
  796. {
  797. struct ioc3_private *ip = netdev_priv(dev);
  798. struct ioc3 *ioc3 = ip->regs;
  799. unsigned long ring;
  800. ioc3_free_rings(ip);
  801. ioc3_alloc_rings(dev);
  802. ioc3_clean_rx_ring(ip);
  803. ioc3_clean_tx_ring(ip);
  804. /* Now the rx ring base, consume & produce registers. */
  805. ring = ioc3_map(ip->rxr, 0);
  806. ioc3_w_erbr_h(ring >> 32);
  807. ioc3_w_erbr_l(ring & 0xffffffff);
  808. ioc3_w_ercir(ip->rx_ci << 3);
  809. ioc3_w_erpir((ip->rx_pi << 3) | ERPIR_ARM);
  810. ring = ioc3_map(ip->txr, 0);
  811. ip->txqlen = 0; /* nothing queued */
  812. /* Now the tx ring base, consume & produce registers. */
  813. ioc3_w_etbr_h(ring >> 32);
  814. ioc3_w_etbr_l(ring & 0xffffffff);
  815. ioc3_w_etpir(ip->tx_pi << 7);
  816. ioc3_w_etcir(ip->tx_ci << 7);
  817. (void) ioc3_r_etcir(); /* Flush */
  818. }
  819. static inline void ioc3_ssram_disc(struct ioc3_private *ip)
  820. {
  821. struct ioc3 *ioc3 = ip->regs;
  822. volatile u32 *ssram0 = &ioc3->ssram[0x0000];
  823. volatile u32 *ssram1 = &ioc3->ssram[0x4000];
  824. unsigned int pattern = 0x5555;
  825. /* Assume the larger size SSRAM and enable parity checking */
  826. ioc3_w_emcr(ioc3_r_emcr() | (EMCR_BUFSIZ | EMCR_RAMPAR));
  827. *ssram0 = pattern;
  828. *ssram1 = ~pattern & IOC3_SSRAM_DM;
  829. if ((*ssram0 & IOC3_SSRAM_DM) != pattern ||
  830. (*ssram1 & IOC3_SSRAM_DM) != (~pattern & IOC3_SSRAM_DM)) {
  831. /* set ssram size to 64 KB */
  832. ip->emcr = EMCR_RAMPAR;
  833. ioc3_w_emcr(ioc3_r_emcr() & ~EMCR_BUFSIZ);
  834. } else
  835. ip->emcr = EMCR_BUFSIZ | EMCR_RAMPAR;
  836. }
  837. static void ioc3_init(struct net_device *dev)
  838. {
  839. struct ioc3_private *ip = netdev_priv(dev);
  840. struct ioc3 *ioc3 = ip->regs;
  841. del_timer_sync(&ip->ioc3_timer); /* Kill if running */
  842. ioc3_w_emcr(EMCR_RST); /* Reset */
  843. (void) ioc3_r_emcr(); /* Flush WB */
  844. udelay(4); /* Give it time ... */
  845. ioc3_w_emcr(0);
  846. (void) ioc3_r_emcr();
  847. /* Misc registers */
  848. #ifdef CONFIG_SGI_IP27
  849. ioc3_w_erbar(PCI64_ATTR_BAR >> 32); /* Barrier on last store */
  850. #else
  851. ioc3_w_erbar(0); /* Let PCI API get it right */
  852. #endif
  853. (void) ioc3_r_etcdc(); /* Clear on read */
  854. ioc3_w_ercsr(15); /* RX low watermark */
  855. ioc3_w_ertr(0); /* Interrupt immediately */
  856. __ioc3_set_mac_address(dev);
  857. ioc3_w_ehar_h(ip->ehar_h);
  858. ioc3_w_ehar_l(ip->ehar_l);
  859. ioc3_w_ersr(42); /* XXX should be random */
  860. ioc3_init_rings(dev);
  861. ip->emcr |= ((RX_OFFSET / 2) << EMCR_RXOFF_SHIFT) | EMCR_TXDMAEN |
  862. EMCR_TXEN | EMCR_RXDMAEN | EMCR_RXEN | EMCR_PADEN;
  863. ioc3_w_emcr(ip->emcr);
  864. ioc3_w_eier(EISR_RXTIMERINT | EISR_RXOFLO | EISR_RXBUFOFLO |
  865. EISR_RXMEMERR | EISR_RXPARERR | EISR_TXBUFUFLO |
  866. EISR_TXEXPLICIT | EISR_TXMEMERR);
  867. (void) ioc3_r_eier();
  868. }
  869. static inline void ioc3_stop(struct ioc3_private *ip)
  870. {
  871. struct ioc3 *ioc3 = ip->regs;
  872. ioc3_w_emcr(0); /* Shutup */
  873. ioc3_w_eier(0); /* Disable interrupts */
  874. (void) ioc3_r_eier(); /* Flush */
  875. }
  876. static int ioc3_open(struct net_device *dev)
  877. {
  878. struct ioc3_private *ip = netdev_priv(dev);
  879. if (request_irq(dev->irq, ioc3_interrupt, IRQF_SHARED, ioc3_str, dev)) {
  880. printk(KERN_ERR "%s: Can't get irq %d\n", dev->name, dev->irq);
  881. return -EAGAIN;
  882. }
  883. ip->ehar_h = 0;
  884. ip->ehar_l = 0;
  885. ioc3_init(dev);
  886. ioc3_mii_start(ip);
  887. netif_start_queue(dev);
  888. return 0;
  889. }
  890. static int ioc3_close(struct net_device *dev)
  891. {
  892. struct ioc3_private *ip = netdev_priv(dev);
  893. del_timer_sync(&ip->ioc3_timer);
  894. netif_stop_queue(dev);
  895. ioc3_stop(ip);
  896. free_irq(dev->irq, dev);
  897. ioc3_free_rings(ip);
  898. return 0;
  899. }
  900. /*
  901. * MENET cards have four IOC3 chips, which are attached to two sets of
  902. * PCI slot resources each: the primary connections are on slots
  903. * 0..3 and the secondaries are on 4..7
  904. *
  905. * All four ethernets are brought out to connectors; six serial ports
  906. * (a pair from each of the first three IOC3s) are brought out to
  907. * MiniDINs; all other subdevices are left swinging in the wind, leave
  908. * them disabled.
  909. */
  910. static int ioc3_adjacent_is_ioc3(struct pci_dev *pdev, int slot)
  911. {
  912. struct pci_dev *dev = pci_get_slot(pdev->bus, PCI_DEVFN(slot, 0));
  913. int ret = 0;
  914. if (dev) {
  915. if (dev->vendor == PCI_VENDOR_ID_SGI &&
  916. dev->device == PCI_DEVICE_ID_SGI_IOC3)
  917. ret = 1;
  918. pci_dev_put(dev);
  919. }
  920. return ret;
  921. }
  922. static int ioc3_is_menet(struct pci_dev *pdev)
  923. {
  924. return pdev->bus->parent == NULL &&
  925. ioc3_adjacent_is_ioc3(pdev, 0) &&
  926. ioc3_adjacent_is_ioc3(pdev, 1) &&
  927. ioc3_adjacent_is_ioc3(pdev, 2);
  928. }
  929. #ifdef CONFIG_SERIAL_8250
  930. /*
  931. * Note about serial ports and consoles:
  932. * For console output, everyone uses the IOC3 UARTA (offset 0x178)
  933. * connected to the master node (look in ip27_setup_console() and
  934. * ip27prom_console_write()).
  935. *
  936. * For serial (/dev/ttyS0 etc), we can not have hardcoded serial port
  937. * addresses on a partitioned machine. Since we currently use the ioc3
  938. * serial ports, we use dynamic serial port discovery that the serial.c
  939. * driver uses for pci/pnp ports (there is an entry for the SGI ioc3
  940. * boards in pci_boards[]). Unfortunately, UARTA's pio address is greater
  941. * than UARTB's, although UARTA on o200s has traditionally been known as
  942. * port 0. So, we just use one serial port from each ioc3 (since the
  943. * serial driver adds addresses to get to higher ports).
  944. *
  945. * The first one to do a register_console becomes the preferred console
  946. * (if there is no kernel command line console= directive). /dev/console
  947. * (ie 5, 1) is then "aliased" into the device number returned by the
  948. * "device" routine referred to in this console structure
  949. * (ip27prom_console_dev).
  950. *
  951. * Also look in ip27-pci.c:pci_fixup_ioc3() for some comments on working
  952. * around ioc3 oddities in this respect.
  953. *
  954. * The IOC3 serials use a 22MHz clock rate with an additional divider which
  955. * can be programmed in the SCR register if the DLAB bit is set.
  956. *
  957. * Register to interrupt zero because we share the interrupt with
  958. * the serial driver which we don't properly support yet.
  959. *
  960. * Can't use UPF_IOREMAP as the whole of IOC3 resources have already been
  961. * registered.
  962. */
  963. static void __devinit ioc3_8250_register(struct ioc3_uartregs __iomem *uart)
  964. {
  965. #define COSMISC_CONSTANT 6
  966. struct uart_port port = {
  967. .irq = 0,
  968. .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
  969. .iotype = UPIO_MEM,
  970. .regshift = 0,
  971. .uartclk = (22000000 << 1) / COSMISC_CONSTANT,
  972. .membase = (unsigned char __iomem *) uart,
  973. .mapbase = (unsigned long) uart,
  974. };
  975. unsigned char lcr;
  976. lcr = uart->iu_lcr;
  977. uart->iu_lcr = lcr | UART_LCR_DLAB;
  978. uart->iu_scr = COSMISC_CONSTANT,
  979. uart->iu_lcr = lcr;
  980. uart->iu_lcr;
  981. serial8250_register_port(&port);
  982. }
  983. static void __devinit ioc3_serial_probe(struct pci_dev *pdev, struct ioc3 *ioc3)
  984. {
  985. /*
  986. * We need to recognice and treat the fourth MENET serial as it
  987. * does not have an SuperIO chip attached to it, therefore attempting
  988. * to access it will result in bus errors. We call something an
  989. * MENET if PCI slot 0, 1, 2 and 3 of a master PCI bus all have an IOC3
  990. * in it. This is paranoid but we want to avoid blowing up on a
  991. * showhorn PCI box that happens to have 4 IOC3 cards in it so it's
  992. * not paranoid enough ...
  993. */
  994. if (ioc3_is_menet(pdev) && PCI_SLOT(pdev->devfn) == 3)
  995. return;
  996. /*
  997. * Switch IOC3 to PIO mode. It probably already was but let's be
  998. * paranoid
  999. */
  1000. ioc3->gpcr_s = GPCR_UARTA_MODESEL | GPCR_UARTB_MODESEL;
  1001. ioc3->gpcr_s;
  1002. ioc3->gppr_6 = 0;
  1003. ioc3->gppr_6;
  1004. ioc3->gppr_7 = 0;
  1005. ioc3->gppr_7;
  1006. ioc3->sscr_a = ioc3->sscr_a & ~SSCR_DMA_EN;
  1007. ioc3->sscr_a;
  1008. ioc3->sscr_b = ioc3->sscr_b & ~SSCR_DMA_EN;
  1009. ioc3->sscr_b;
  1010. /* Disable all SA/B interrupts except for SA/B_INT in SIO_IEC. */
  1011. ioc3->sio_iec &= ~ (SIO_IR_SA_TX_MT | SIO_IR_SA_RX_FULL |
  1012. SIO_IR_SA_RX_HIGH | SIO_IR_SA_RX_TIMER |
  1013. SIO_IR_SA_DELTA_DCD | SIO_IR_SA_DELTA_CTS |
  1014. SIO_IR_SA_TX_EXPLICIT | SIO_IR_SA_MEMERR);
  1015. ioc3->sio_iec |= SIO_IR_SA_INT;
  1016. ioc3->sscr_a = 0;
  1017. ioc3->sio_iec &= ~ (SIO_IR_SB_TX_MT | SIO_IR_SB_RX_FULL |
  1018. SIO_IR_SB_RX_HIGH | SIO_IR_SB_RX_TIMER |
  1019. SIO_IR_SB_DELTA_DCD | SIO_IR_SB_DELTA_CTS |
  1020. SIO_IR_SB_TX_EXPLICIT | SIO_IR_SB_MEMERR);
  1021. ioc3->sio_iec |= SIO_IR_SB_INT;
  1022. ioc3->sscr_b = 0;
  1023. ioc3_8250_register(&ioc3->sregs.uarta);
  1024. ioc3_8250_register(&ioc3->sregs.uartb);
  1025. }
  1026. #endif
  1027. static int ioc3_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  1028. {
  1029. unsigned int sw_physid1, sw_physid2;
  1030. struct net_device *dev = NULL;
  1031. struct ioc3_private *ip;
  1032. struct ioc3 *ioc3;
  1033. unsigned long ioc3_base, ioc3_size;
  1034. u32 vendor, model, rev;
  1035. int err, pci_using_dac;
  1036. /* Configure DMA attributes. */
  1037. err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
  1038. if (!err) {
  1039. pci_using_dac = 1;
  1040. err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
  1041. if (err < 0) {
  1042. printk(KERN_ERR "%s: Unable to obtain 64 bit DMA "
  1043. "for consistent allocations\n", pci_name(pdev));
  1044. goto out;
  1045. }
  1046. } else {
  1047. err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  1048. if (err) {
  1049. printk(KERN_ERR "%s: No usable DMA configuration, "
  1050. "aborting.\n", pci_name(pdev));
  1051. goto out;
  1052. }
  1053. pci_using_dac = 0;
  1054. }
  1055. if (pci_enable_device(pdev))
  1056. return -ENODEV;
  1057. dev = alloc_etherdev(sizeof(struct ioc3_private));
  1058. if (!dev) {
  1059. err = -ENOMEM;
  1060. goto out_disable;
  1061. }
  1062. if (pci_using_dac)
  1063. dev->features |= NETIF_F_HIGHDMA;
  1064. err = pci_request_regions(pdev, "ioc3");
  1065. if (err)
  1066. goto out_free;
  1067. SET_NETDEV_DEV(dev, &pdev->dev);
  1068. ip = netdev_priv(dev);
  1069. dev->irq = pdev->irq;
  1070. ioc3_base = pci_resource_start(pdev, 0);
  1071. ioc3_size = pci_resource_len(pdev, 0);
  1072. ioc3 = (struct ioc3 *) ioremap(ioc3_base, ioc3_size);
  1073. if (!ioc3) {
  1074. printk(KERN_CRIT "ioc3eth(%s): ioremap failed, goodbye.\n",
  1075. pci_name(pdev));
  1076. err = -ENOMEM;
  1077. goto out_res;
  1078. }
  1079. ip->regs = ioc3;
  1080. #ifdef CONFIG_SERIAL_8250
  1081. ioc3_serial_probe(pdev, ioc3);
  1082. #endif
  1083. spin_lock_init(&ip->ioc3_lock);
  1084. init_timer(&ip->ioc3_timer);
  1085. ioc3_stop(ip);
  1086. ioc3_init(dev);
  1087. ip->pdev = pdev;
  1088. ip->mii.phy_id_mask = 0x1f;
  1089. ip->mii.reg_num_mask = 0x1f;
  1090. ip->mii.dev = dev;
  1091. ip->mii.mdio_read = ioc3_mdio_read;
  1092. ip->mii.mdio_write = ioc3_mdio_write;
  1093. ioc3_mii_init(ip);
  1094. if (ip->mii.phy_id == -1) {
  1095. printk(KERN_CRIT "ioc3-eth(%s): Didn't find a PHY, goodbye.\n",
  1096. pci_name(pdev));
  1097. err = -ENODEV;
  1098. goto out_stop;
  1099. }
  1100. ioc3_mii_start(ip);
  1101. ioc3_ssram_disc(ip);
  1102. ioc3_get_eaddr(ip);
  1103. /* The IOC3-specific entries in the device structure. */
  1104. dev->open = ioc3_open;
  1105. dev->hard_start_xmit = ioc3_start_xmit;
  1106. dev->tx_timeout = ioc3_timeout;
  1107. dev->watchdog_timeo = 5 * HZ;
  1108. dev->stop = ioc3_close;
  1109. dev->get_stats = ioc3_get_stats;
  1110. dev->do_ioctl = ioc3_ioctl;
  1111. dev->set_multicast_list = ioc3_set_multicast_list;
  1112. dev->set_mac_address = ioc3_set_mac_address;
  1113. dev->ethtool_ops = &ioc3_ethtool_ops;
  1114. dev->features = NETIF_F_IP_CSUM;
  1115. sw_physid1 = ioc3_mdio_read(dev, ip->mii.phy_id, MII_PHYSID1);
  1116. sw_physid2 = ioc3_mdio_read(dev, ip->mii.phy_id, MII_PHYSID2);
  1117. err = register_netdev(dev);
  1118. if (err)
  1119. goto out_stop;
  1120. mii_check_media(&ip->mii, 1, 1);
  1121. ioc3_setup_duplex(ip);
  1122. vendor = (sw_physid1 << 12) | (sw_physid2 >> 4);
  1123. model = (sw_physid2 >> 4) & 0x3f;
  1124. rev = sw_physid2 & 0xf;
  1125. printk(KERN_INFO "%s: Using PHY %d, vendor 0x%x, model %d, "
  1126. "rev %d.\n", dev->name, ip->mii.phy_id, vendor, model, rev);
  1127. printk(KERN_INFO "%s: IOC3 SSRAM has %d kbyte.\n", dev->name,
  1128. ip->emcr & EMCR_BUFSIZ ? 128 : 64);
  1129. return 0;
  1130. out_stop:
  1131. ioc3_stop(ip);
  1132. del_timer_sync(&ip->ioc3_timer);
  1133. ioc3_free_rings(ip);
  1134. out_res:
  1135. pci_release_regions(pdev);
  1136. out_free:
  1137. free_netdev(dev);
  1138. out_disable:
  1139. /*
  1140. * We should call pci_disable_device(pdev); here if the IOC3 wasn't
  1141. * such a weird device ...
  1142. */
  1143. out:
  1144. return err;
  1145. }
  1146. static void __devexit ioc3_remove_one (struct pci_dev *pdev)
  1147. {
  1148. struct net_device *dev = pci_get_drvdata(pdev);
  1149. struct ioc3_private *ip = netdev_priv(dev);
  1150. struct ioc3 *ioc3 = ip->regs;
  1151. unregister_netdev(dev);
  1152. del_timer_sync(&ip->ioc3_timer);
  1153. iounmap(ioc3);
  1154. pci_release_regions(pdev);
  1155. free_netdev(dev);
  1156. /*
  1157. * We should call pci_disable_device(pdev); here if the IOC3 wasn't
  1158. * such a weird device ...
  1159. */
  1160. }
  1161. static struct pci_device_id ioc3_pci_tbl[] = {
  1162. { PCI_VENDOR_ID_SGI, PCI_DEVICE_ID_SGI_IOC3, PCI_ANY_ID, PCI_ANY_ID },
  1163. { 0 }
  1164. };
  1165. MODULE_DEVICE_TABLE(pci, ioc3_pci_tbl);
  1166. static struct pci_driver ioc3_driver = {
  1167. .name = "ioc3-eth",
  1168. .id_table = ioc3_pci_tbl,
  1169. .probe = ioc3_probe,
  1170. .remove = __devexit_p(ioc3_remove_one),
  1171. };
  1172. static int __init ioc3_init_module(void)
  1173. {
  1174. return pci_register_driver(&ioc3_driver);
  1175. }
  1176. static void __exit ioc3_cleanup_module(void)
  1177. {
  1178. pci_unregister_driver(&ioc3_driver);
  1179. }
  1180. static int ioc3_start_xmit(struct sk_buff *skb, struct net_device *dev)
  1181. {
  1182. unsigned long data;
  1183. struct ioc3_private *ip = netdev_priv(dev);
  1184. struct ioc3 *ioc3 = ip->regs;
  1185. unsigned int len;
  1186. struct ioc3_etxd *desc;
  1187. uint32_t w0 = 0;
  1188. int produce;
  1189. /*
  1190. * IOC3 has a fairly simple minded checksumming hardware which simply
  1191. * adds up the 1's complement checksum for the entire packet and
  1192. * inserts it at an offset which can be specified in the descriptor
  1193. * into the transmit packet. This means we have to compensate for the
  1194. * MAC header which should not be summed and the TCP/UDP pseudo headers
  1195. * manually.
  1196. */
  1197. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  1198. const struct iphdr *ih = ip_hdr(skb);
  1199. const int proto = ntohs(ih->protocol);
  1200. unsigned int csoff;
  1201. uint32_t csum, ehsum;
  1202. uint16_t *eh;
  1203. /* The MAC header. skb->mac seem the logic approach
  1204. to find the MAC header - except it's a NULL pointer ... */
  1205. eh = (uint16_t *) skb->data;
  1206. /* Sum up dest addr, src addr and protocol */
  1207. ehsum = eh[0] + eh[1] + eh[2] + eh[3] + eh[4] + eh[5] + eh[6];
  1208. /* Fold ehsum. can't use csum_fold which negates also ... */
  1209. ehsum = (ehsum & 0xffff) + (ehsum >> 16);
  1210. ehsum = (ehsum & 0xffff) + (ehsum >> 16);
  1211. /* Skip IP header; it's sum is always zero and was
  1212. already filled in by ip_output.c */
  1213. csum = csum_tcpudp_nofold(ih->saddr, ih->daddr,
  1214. ih->tot_len - (ih->ihl << 2),
  1215. proto, 0xffff ^ ehsum);
  1216. csum = (csum & 0xffff) + (csum >> 16); /* Fold again */
  1217. csum = (csum & 0xffff) + (csum >> 16);
  1218. csoff = ETH_HLEN + (ih->ihl << 2);
  1219. if (proto == IPPROTO_UDP) {
  1220. csoff += offsetof(struct udphdr, check);
  1221. udp_hdr(skb)->check = csum;
  1222. }
  1223. if (proto == IPPROTO_TCP) {
  1224. csoff += offsetof(struct tcphdr, check);
  1225. tcp_hdr(skb)->check = csum;
  1226. }
  1227. w0 = ETXD_DOCHECKSUM | (csoff << ETXD_CHKOFF_SHIFT);
  1228. }
  1229. spin_lock_irq(&ip->ioc3_lock);
  1230. data = (unsigned long) skb->data;
  1231. len = skb->len;
  1232. produce = ip->tx_pi;
  1233. desc = &ip->txr[produce];
  1234. if (len <= 104) {
  1235. /* Short packet, let's copy it directly into the ring. */
  1236. skb_copy_from_linear_data(skb, desc->data, skb->len);
  1237. if (len < ETH_ZLEN) {
  1238. /* Very short packet, pad with zeros at the end. */
  1239. memset(desc->data + len, 0, ETH_ZLEN - len);
  1240. len = ETH_ZLEN;
  1241. }
  1242. desc->cmd = cpu_to_be32(len | ETXD_INTWHENDONE | ETXD_D0V | w0);
  1243. desc->bufcnt = cpu_to_be32(len);
  1244. } else if ((data ^ (data + len - 1)) & 0x4000) {
  1245. unsigned long b2 = (data | 0x3fffUL) + 1UL;
  1246. unsigned long s1 = b2 - data;
  1247. unsigned long s2 = data + len - b2;
  1248. desc->cmd = cpu_to_be32(len | ETXD_INTWHENDONE |
  1249. ETXD_B1V | ETXD_B2V | w0);
  1250. desc->bufcnt = cpu_to_be32((s1 << ETXD_B1CNT_SHIFT) |
  1251. (s2 << ETXD_B2CNT_SHIFT));
  1252. desc->p1 = cpu_to_be64(ioc3_map(skb->data, 1));
  1253. desc->p2 = cpu_to_be64(ioc3_map((void *) b2, 1));
  1254. } else {
  1255. /* Normal sized packet that doesn't cross a page boundary. */
  1256. desc->cmd = cpu_to_be32(len | ETXD_INTWHENDONE | ETXD_B1V | w0);
  1257. desc->bufcnt = cpu_to_be32(len << ETXD_B1CNT_SHIFT);
  1258. desc->p1 = cpu_to_be64(ioc3_map(skb->data, 1));
  1259. }
  1260. BARRIER();
  1261. dev->trans_start = jiffies;
  1262. ip->tx_skbs[produce] = skb; /* Remember skb */
  1263. produce = (produce + 1) & 127;
  1264. ip->tx_pi = produce;
  1265. ioc3_w_etpir(produce << 7); /* Fire ... */
  1266. ip->txqlen++;
  1267. if (ip->txqlen >= 127)
  1268. netif_stop_queue(dev);
  1269. spin_unlock_irq(&ip->ioc3_lock);
  1270. return 0;
  1271. }
  1272. static void ioc3_timeout(struct net_device *dev)
  1273. {
  1274. struct ioc3_private *ip = netdev_priv(dev);
  1275. printk(KERN_ERR "%s: transmit timed out, resetting\n", dev->name);
  1276. spin_lock_irq(&ip->ioc3_lock);
  1277. ioc3_stop(ip);
  1278. ioc3_init(dev);
  1279. ioc3_mii_init(ip);
  1280. ioc3_mii_start(ip);
  1281. spin_unlock_irq(&ip->ioc3_lock);
  1282. netif_wake_queue(dev);
  1283. }
  1284. /*
  1285. * Given a multicast ethernet address, this routine calculates the
  1286. * address's bit index in the logical address filter mask
  1287. */
  1288. static inline unsigned int ioc3_hash(const unsigned char *addr)
  1289. {
  1290. unsigned int temp = 0;
  1291. u32 crc;
  1292. int bits;
  1293. crc = ether_crc_le(ETH_ALEN, addr);
  1294. crc &= 0x3f; /* bit reverse lowest 6 bits for hash index */
  1295. for (bits = 6; --bits >= 0; ) {
  1296. temp <<= 1;
  1297. temp |= (crc & 0x1);
  1298. crc >>= 1;
  1299. }
  1300. return temp;
  1301. }
  1302. static void ioc3_get_drvinfo (struct net_device *dev,
  1303. struct ethtool_drvinfo *info)
  1304. {
  1305. struct ioc3_private *ip = netdev_priv(dev);
  1306. strcpy (info->driver, IOC3_NAME);
  1307. strcpy (info->version, IOC3_VERSION);
  1308. strcpy (info->bus_info, pci_name(ip->pdev));
  1309. }
  1310. static int ioc3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  1311. {
  1312. struct ioc3_private *ip = netdev_priv(dev);
  1313. int rc;
  1314. spin_lock_irq(&ip->ioc3_lock);
  1315. rc = mii_ethtool_gset(&ip->mii, cmd);
  1316. spin_unlock_irq(&ip->ioc3_lock);
  1317. return rc;
  1318. }
  1319. static int ioc3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  1320. {
  1321. struct ioc3_private *ip = netdev_priv(dev);
  1322. int rc;
  1323. spin_lock_irq(&ip->ioc3_lock);
  1324. rc = mii_ethtool_sset(&ip->mii, cmd);
  1325. spin_unlock_irq(&ip->ioc3_lock);
  1326. return rc;
  1327. }
  1328. static int ioc3_nway_reset(struct net_device *dev)
  1329. {
  1330. struct ioc3_private *ip = netdev_priv(dev);
  1331. int rc;
  1332. spin_lock_irq(&ip->ioc3_lock);
  1333. rc = mii_nway_restart(&ip->mii);
  1334. spin_unlock_irq(&ip->ioc3_lock);
  1335. return rc;
  1336. }
  1337. static u32 ioc3_get_link(struct net_device *dev)
  1338. {
  1339. struct ioc3_private *ip = netdev_priv(dev);
  1340. int rc;
  1341. spin_lock_irq(&ip->ioc3_lock);
  1342. rc = mii_link_ok(&ip->mii);
  1343. spin_unlock_irq(&ip->ioc3_lock);
  1344. return rc;
  1345. }
  1346. static u32 ioc3_get_rx_csum(struct net_device *dev)
  1347. {
  1348. struct ioc3_private *ip = netdev_priv(dev);
  1349. return ip->flags & IOC3_FLAG_RX_CHECKSUMS;
  1350. }
  1351. static int ioc3_set_rx_csum(struct net_device *dev, u32 data)
  1352. {
  1353. struct ioc3_private *ip = netdev_priv(dev);
  1354. spin_lock_bh(&ip->ioc3_lock);
  1355. if (data)
  1356. ip->flags |= IOC3_FLAG_RX_CHECKSUMS;
  1357. else
  1358. ip->flags &= ~IOC3_FLAG_RX_CHECKSUMS;
  1359. spin_unlock_bh(&ip->ioc3_lock);
  1360. return 0;
  1361. }
  1362. static const struct ethtool_ops ioc3_ethtool_ops = {
  1363. .get_drvinfo = ioc3_get_drvinfo,
  1364. .get_settings = ioc3_get_settings,
  1365. .set_settings = ioc3_set_settings,
  1366. .nway_reset = ioc3_nway_reset,
  1367. .get_link = ioc3_get_link,
  1368. .get_rx_csum = ioc3_get_rx_csum,
  1369. .set_rx_csum = ioc3_set_rx_csum,
  1370. .get_tx_csum = ethtool_op_get_tx_csum,
  1371. .set_tx_csum = ethtool_op_set_tx_csum
  1372. };
  1373. static int ioc3_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  1374. {
  1375. struct ioc3_private *ip = netdev_priv(dev);
  1376. int rc;
  1377. spin_lock_irq(&ip->ioc3_lock);
  1378. rc = generic_mii_ioctl(&ip->mii, if_mii(rq), cmd, NULL);
  1379. spin_unlock_irq(&ip->ioc3_lock);
  1380. return rc;
  1381. }
  1382. static void ioc3_set_multicast_list(struct net_device *dev)
  1383. {
  1384. struct dev_mc_list *dmi = dev->mc_list;
  1385. struct ioc3_private *ip = netdev_priv(dev);
  1386. struct ioc3 *ioc3 = ip->regs;
  1387. u64 ehar = 0;
  1388. int i;
  1389. netif_stop_queue(dev); /* Lock out others. */
  1390. if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
  1391. ip->emcr |= EMCR_PROMISC;
  1392. ioc3_w_emcr(ip->emcr);
  1393. (void) ioc3_r_emcr();
  1394. } else {
  1395. ip->emcr &= ~EMCR_PROMISC;
  1396. ioc3_w_emcr(ip->emcr); /* Clear promiscuous. */
  1397. (void) ioc3_r_emcr();
  1398. if ((dev->flags & IFF_ALLMULTI) || (dev->mc_count > 64)) {
  1399. /* Too many for hashing to make sense or we want all
  1400. multicast packets anyway, so skip computing all the
  1401. hashes and just accept all packets. */
  1402. ip->ehar_h = 0xffffffff;
  1403. ip->ehar_l = 0xffffffff;
  1404. } else {
  1405. for (i = 0; i < dev->mc_count; i++) {
  1406. char *addr = dmi->dmi_addr;
  1407. dmi = dmi->next;
  1408. if (!(*addr & 1))
  1409. continue;
  1410. ehar |= (1UL << ioc3_hash(addr));
  1411. }
  1412. ip->ehar_h = ehar >> 32;
  1413. ip->ehar_l = ehar & 0xffffffff;
  1414. }
  1415. ioc3_w_ehar_h(ip->ehar_h);
  1416. ioc3_w_ehar_l(ip->ehar_l);
  1417. }
  1418. netif_wake_queue(dev); /* Let us get going again. */
  1419. }
  1420. MODULE_AUTHOR("Ralf Baechle <ralf@linux-mips.org>");
  1421. MODULE_DESCRIPTION("SGI IOC3 Ethernet driver");
  1422. MODULE_LICENSE("GPL");
  1423. module_init(ioc3_init_module);
  1424. module_exit(ioc3_cleanup_module);