ipg.c 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339
  1. /*
  2. * ipg.c: Device Driver for the IP1000 Gigabit Ethernet Adapter
  3. *
  4. * Copyright (C) 2003, 2007 IC Plus Corp
  5. *
  6. * Original Author:
  7. *
  8. * Craig Rich
  9. * Sundance Technology, Inc.
  10. * www.sundanceti.com
  11. * craig_rich@sundanceti.com
  12. *
  13. * Current Maintainer:
  14. *
  15. * Sorbica Shieh.
  16. * http://www.icplus.com.tw
  17. * sorbica@icplus.com.tw
  18. *
  19. * Jesse Huang
  20. * http://www.icplus.com.tw
  21. * jesse@icplus.com.tw
  22. */
  23. #include <linux/crc32.h>
  24. #include <linux/ethtool.h>
  25. #include <linux/mii.h>
  26. #include <linux/mutex.h>
  27. #include <asm/div64.h>
  28. #define IPG_RX_RING_BYTES (sizeof(struct ipg_rx) * IPG_RFDLIST_LENGTH)
  29. #define IPG_TX_RING_BYTES (sizeof(struct ipg_tx) * IPG_TFDLIST_LENGTH)
  30. #define IPG_RESET_MASK \
  31. (IPG_AC_GLOBAL_RESET | IPG_AC_RX_RESET | IPG_AC_TX_RESET | \
  32. IPG_AC_DMA | IPG_AC_FIFO | IPG_AC_NETWORK | IPG_AC_HOST | \
  33. IPG_AC_AUTO_INIT)
  34. #define ipg_w32(val32,reg) iowrite32((val32), ioaddr + (reg))
  35. #define ipg_w16(val16,reg) iowrite16((val16), ioaddr + (reg))
  36. #define ipg_w8(val8,reg) iowrite8((val8), ioaddr + (reg))
  37. #define ipg_r32(reg) ioread32(ioaddr + (reg))
  38. #define ipg_r16(reg) ioread16(ioaddr + (reg))
  39. #define ipg_r8(reg) ioread8(ioaddr + (reg))
  40. #define JUMBO_FRAME_4k_ONLY
  41. enum {
  42. netdev_io_size = 128
  43. };
  44. #include "ipg.h"
  45. #define DRV_NAME "ipg"
  46. MODULE_AUTHOR("IC Plus Corp. 2003");
  47. MODULE_DESCRIPTION("IC Plus IP1000 Gigabit Ethernet Adapter Linux Driver");
  48. MODULE_LICENSE("GPL");
  49. //variable record -- index by leading revision/length
  50. //Revision/Length(=N*4), Address1, Data1, Address2, Data2,...,AddressN,DataN
  51. static unsigned short DefaultPhyParam[] = {
  52. // 11/12/03 IP1000A v1-3 rev=0x40
  53. /*--------------------------------------------------------------------------
  54. (0x4000|(15*4)), 31, 0x0001, 27, 0x01e0, 31, 0x0002, 22, 0x85bd, 24, 0xfff2,
  55. 27, 0x0c10, 28, 0x0c10, 29, 0x2c10, 31, 0x0003, 23, 0x92f6,
  56. 31, 0x0000, 23, 0x003d, 30, 0x00de, 20, 0x20e7, 9, 0x0700,
  57. --------------------------------------------------------------------------*/
  58. // 12/17/03 IP1000A v1-4 rev=0x40
  59. (0x4000 | (07 * 4)), 31, 0x0001, 27, 0x01e0, 31, 0x0002, 27, 0xeb8e, 31,
  60. 0x0000,
  61. 30, 0x005e, 9, 0x0700,
  62. // 01/09/04 IP1000A v1-5 rev=0x41
  63. (0x4100 | (07 * 4)), 31, 0x0001, 27, 0x01e0, 31, 0x0002, 27, 0xeb8e, 31,
  64. 0x0000,
  65. 30, 0x005e, 9, 0x0700,
  66. 0x0000
  67. };
  68. static const char *ipg_brand_name[] = {
  69. "IC PLUS IP1000 1000/100/10 based NIC",
  70. "Sundance Technology ST2021 based NIC",
  71. "Tamarack Microelectronics TC9020/9021 based NIC",
  72. "Tamarack Microelectronics TC9020/9021 based NIC",
  73. "D-Link NIC",
  74. "D-Link NIC IP1000A"
  75. };
  76. static struct pci_device_id ipg_pci_tbl[] __devinitdata = {
  77. { PCI_VDEVICE(SUNDANCE, 0x1023), 0 },
  78. { PCI_VDEVICE(SUNDANCE, 0x2021), 1 },
  79. { PCI_VDEVICE(SUNDANCE, 0x1021), 2 },
  80. { PCI_VDEVICE(DLINK, 0x9021), 3 },
  81. { PCI_VDEVICE(DLINK, 0x4000), 4 },
  82. { PCI_VDEVICE(DLINK, 0x4020), 5 },
  83. { 0, }
  84. };
  85. MODULE_DEVICE_TABLE(pci, ipg_pci_tbl);
  86. static inline void __iomem *ipg_ioaddr(struct net_device *dev)
  87. {
  88. struct ipg_nic_private *sp = netdev_priv(dev);
  89. return sp->ioaddr;
  90. }
  91. #ifdef IPG_DEBUG
  92. static void ipg_dump_rfdlist(struct net_device *dev)
  93. {
  94. struct ipg_nic_private *sp = netdev_priv(dev);
  95. void __iomem *ioaddr = sp->ioaddr;
  96. unsigned int i;
  97. u32 offset;
  98. IPG_DEBUG_MSG("_dump_rfdlist\n");
  99. printk(KERN_INFO "rx_current = %2.2x\n", sp->rx_current);
  100. printk(KERN_INFO "rx_dirty = %2.2x\n", sp->rx_dirty);
  101. printk(KERN_INFO "RFDList start address = %16.16lx\n",
  102. (unsigned long) sp->rxd_map);
  103. printk(KERN_INFO "RFDListPtr register = %8.8x%8.8x\n",
  104. ipg_r32(IPG_RFDLISTPTR1), ipg_r32(IPG_RFDLISTPTR0));
  105. for (i = 0; i < IPG_RFDLIST_LENGTH; i++) {
  106. offset = (u32) &sp->rxd[i].next_desc - (u32) sp->rxd;
  107. printk(KERN_INFO "%2.2x %4.4x RFDNextPtr = %16.16lx\n", i,
  108. offset, (unsigned long) sp->rxd[i].next_desc);
  109. offset = (u32) &sp->rxd[i].rfs - (u32) sp->rxd;
  110. printk(KERN_INFO "%2.2x %4.4x RFS = %16.16lx\n", i,
  111. offset, (unsigned long) sp->rxd[i].rfs);
  112. offset = (u32) &sp->rxd[i].frag_info - (u32) sp->rxd;
  113. printk(KERN_INFO "%2.2x %4.4x frag_info = %16.16lx\n", i,
  114. offset, (unsigned long) sp->rxd[i].frag_info);
  115. }
  116. }
  117. static void ipg_dump_tfdlist(struct net_device *dev)
  118. {
  119. struct ipg_nic_private *sp = netdev_priv(dev);
  120. void __iomem *ioaddr = sp->ioaddr;
  121. unsigned int i;
  122. u32 offset;
  123. IPG_DEBUG_MSG("_dump_tfdlist\n");
  124. printk(KERN_INFO "tx_current = %2.2x\n", sp->tx_current);
  125. printk(KERN_INFO "tx_dirty = %2.2x\n", sp->tx_dirty);
  126. printk(KERN_INFO "TFDList start address = %16.16lx\n",
  127. (unsigned long) sp->txd_map);
  128. printk(KERN_INFO "TFDListPtr register = %8.8x%8.8x\n",
  129. ipg_r32(IPG_TFDLISTPTR1), ipg_r32(IPG_TFDLISTPTR0));
  130. for (i = 0; i < IPG_TFDLIST_LENGTH; i++) {
  131. offset = (u32) &sp->txd[i].next_desc - (u32) sp->txd;
  132. printk(KERN_INFO "%2.2x %4.4x TFDNextPtr = %16.16lx\n", i,
  133. offset, (unsigned long) sp->txd[i].next_desc);
  134. offset = (u32) &sp->txd[i].tfc - (u32) sp->txd;
  135. printk(KERN_INFO "%2.2x %4.4x TFC = %16.16lx\n", i,
  136. offset, (unsigned long) sp->txd[i].tfc);
  137. offset = (u32) &sp->txd[i].frag_info - (u32) sp->txd;
  138. printk(KERN_INFO "%2.2x %4.4x frag_info = %16.16lx\n", i,
  139. offset, (unsigned long) sp->txd[i].frag_info);
  140. }
  141. }
  142. #endif
  143. static void ipg_write_phy_ctl(void __iomem *ioaddr, u8 data)
  144. {
  145. ipg_w8(IPG_PC_RSVD_MASK & data, PHY_CTRL);
  146. ndelay(IPG_PC_PHYCTRLWAIT_NS);
  147. }
  148. static void ipg_drive_phy_ctl_low_high(void __iomem *ioaddr, u8 data)
  149. {
  150. ipg_write_phy_ctl(ioaddr, IPG_PC_MGMTCLK_LO | data);
  151. ipg_write_phy_ctl(ioaddr, IPG_PC_MGMTCLK_HI | data);
  152. }
  153. static void send_three_state(void __iomem *ioaddr, u8 phyctrlpolarity)
  154. {
  155. phyctrlpolarity |= (IPG_PC_MGMTDATA & 0) | IPG_PC_MGMTDIR;
  156. ipg_drive_phy_ctl_low_high(ioaddr, phyctrlpolarity);
  157. }
  158. static void send_end(void __iomem *ioaddr, u8 phyctrlpolarity)
  159. {
  160. ipg_w8((IPG_PC_MGMTCLK_LO | (IPG_PC_MGMTDATA & 0) | IPG_PC_MGMTDIR |
  161. phyctrlpolarity) & IPG_PC_RSVD_MASK, PHY_CTRL);
  162. }
  163. static u16 read_phy_bit(void __iomem * ioaddr, u8 phyctrlpolarity)
  164. {
  165. u16 bit_data;
  166. ipg_write_phy_ctl(ioaddr, IPG_PC_MGMTCLK_LO | phyctrlpolarity);
  167. bit_data = ((ipg_r8(PHY_CTRL) & IPG_PC_MGMTDATA) >> 1) & 1;
  168. ipg_write_phy_ctl(ioaddr, IPG_PC_MGMTCLK_HI | phyctrlpolarity);
  169. return bit_data;
  170. }
  171. /*
  172. * Read a register from the Physical Layer device located
  173. * on the IPG NIC, using the IPG PHYCTRL register.
  174. */
  175. static int mdio_read(struct net_device * dev, int phy_id, int phy_reg)
  176. {
  177. void __iomem *ioaddr = ipg_ioaddr(dev);
  178. /*
  179. * The GMII mangement frame structure for a read is as follows:
  180. *
  181. * |Preamble|st|op|phyad|regad|ta| data |idle|
  182. * |< 32 1s>|01|10|AAAAA|RRRRR|z0|DDDDDDDDDDDDDDDD|z |
  183. *
  184. * <32 1s> = 32 consecutive logic 1 values
  185. * A = bit of Physical Layer device address (MSB first)
  186. * R = bit of register address (MSB first)
  187. * z = High impedance state
  188. * D = bit of read data (MSB first)
  189. *
  190. * Transmission order is 'Preamble' field first, bits transmitted
  191. * left to right (first to last).
  192. */
  193. struct {
  194. u32 field;
  195. unsigned int len;
  196. } p[] = {
  197. { GMII_PREAMBLE, 32 }, /* Preamble */
  198. { GMII_ST, 2 }, /* ST */
  199. { GMII_READ, 2 }, /* OP */
  200. { phy_id, 5 }, /* PHYAD */
  201. { phy_reg, 5 }, /* REGAD */
  202. { 0x0000, 2 }, /* TA */
  203. { 0x0000, 16 }, /* DATA */
  204. { 0x0000, 1 } /* IDLE */
  205. };
  206. unsigned int i, j;
  207. u8 polarity, data;
  208. polarity = ipg_r8(PHY_CTRL);
  209. polarity &= (IPG_PC_DUPLEX_POLARITY | IPG_PC_LINK_POLARITY);
  210. /* Create the Preamble, ST, OP, PHYAD, and REGAD field. */
  211. for (j = 0; j < 5; j++) {
  212. for (i = 0; i < p[j].len; i++) {
  213. /* For each variable length field, the MSB must be
  214. * transmitted first. Rotate through the field bits,
  215. * starting with the MSB, and move each bit into the
  216. * the 1st (2^1) bit position (this is the bit position
  217. * corresponding to the MgmtData bit of the PhyCtrl
  218. * register for the IPG).
  219. *
  220. * Example: ST = 01;
  221. *
  222. * First write a '0' to bit 1 of the PhyCtrl
  223. * register, then write a '1' to bit 1 of the
  224. * PhyCtrl register.
  225. *
  226. * To do this, right shift the MSB of ST by the value:
  227. * [field length - 1 - #ST bits already written]
  228. * then left shift this result by 1.
  229. */
  230. data = (p[j].field >> (p[j].len - 1 - i)) << 1;
  231. data &= IPG_PC_MGMTDATA;
  232. data |= polarity | IPG_PC_MGMTDIR;
  233. ipg_drive_phy_ctl_low_high(ioaddr, data);
  234. }
  235. }
  236. send_three_state(ioaddr, polarity);
  237. read_phy_bit(ioaddr, polarity);
  238. /*
  239. * For a read cycle, the bits for the next two fields (TA and
  240. * DATA) are driven by the PHY (the IPG reads these bits).
  241. */
  242. for (i = 0; i < p[6].len; i++) {
  243. p[6].field |=
  244. (read_phy_bit(ioaddr, polarity) << (p[6].len - 1 - i));
  245. }
  246. send_three_state(ioaddr, polarity);
  247. send_three_state(ioaddr, polarity);
  248. send_three_state(ioaddr, polarity);
  249. send_end(ioaddr, polarity);
  250. /* Return the value of the DATA field. */
  251. return p[6].field;
  252. }
  253. /*
  254. * Write to a register from the Physical Layer device located
  255. * on the IPG NIC, using the IPG PHYCTRL register.
  256. */
  257. static void mdio_write(struct net_device *dev, int phy_id, int phy_reg, int val)
  258. {
  259. void __iomem *ioaddr = ipg_ioaddr(dev);
  260. /*
  261. * The GMII mangement frame structure for a read is as follows:
  262. *
  263. * |Preamble|st|op|phyad|regad|ta| data |idle|
  264. * |< 32 1s>|01|10|AAAAA|RRRRR|z0|DDDDDDDDDDDDDDDD|z |
  265. *
  266. * <32 1s> = 32 consecutive logic 1 values
  267. * A = bit of Physical Layer device address (MSB first)
  268. * R = bit of register address (MSB first)
  269. * z = High impedance state
  270. * D = bit of write data (MSB first)
  271. *
  272. * Transmission order is 'Preamble' field first, bits transmitted
  273. * left to right (first to last).
  274. */
  275. struct {
  276. u32 field;
  277. unsigned int len;
  278. } p[] = {
  279. { GMII_PREAMBLE, 32 }, /* Preamble */
  280. { GMII_ST, 2 }, /* ST */
  281. { GMII_WRITE, 2 }, /* OP */
  282. { phy_id, 5 }, /* PHYAD */
  283. { phy_reg, 5 }, /* REGAD */
  284. { 0x0002, 2 }, /* TA */
  285. { val & 0xffff, 16 }, /* DATA */
  286. { 0x0000, 1 } /* IDLE */
  287. };
  288. unsigned int i, j;
  289. u8 polarity, data;
  290. polarity = ipg_r8(PHY_CTRL);
  291. polarity &= (IPG_PC_DUPLEX_POLARITY | IPG_PC_LINK_POLARITY);
  292. /* Create the Preamble, ST, OP, PHYAD, and REGAD field. */
  293. for (j = 0; j < 7; j++) {
  294. for (i = 0; i < p[j].len; i++) {
  295. /* For each variable length field, the MSB must be
  296. * transmitted first. Rotate through the field bits,
  297. * starting with the MSB, and move each bit into the
  298. * the 1st (2^1) bit position (this is the bit position
  299. * corresponding to the MgmtData bit of the PhyCtrl
  300. * register for the IPG).
  301. *
  302. * Example: ST = 01;
  303. *
  304. * First write a '0' to bit 1 of the PhyCtrl
  305. * register, then write a '1' to bit 1 of the
  306. * PhyCtrl register.
  307. *
  308. * To do this, right shift the MSB of ST by the value:
  309. * [field length - 1 - #ST bits already written]
  310. * then left shift this result by 1.
  311. */
  312. data = (p[j].field >> (p[j].len - 1 - i)) << 1;
  313. data &= IPG_PC_MGMTDATA;
  314. data |= polarity | IPG_PC_MGMTDIR;
  315. ipg_drive_phy_ctl_low_high(ioaddr, data);
  316. }
  317. }
  318. /* The last cycle is a tri-state, so read from the PHY. */
  319. for (j = 7; j < 8; j++) {
  320. for (i = 0; i < p[j].len; i++) {
  321. ipg_write_phy_ctl(ioaddr, IPG_PC_MGMTCLK_LO | polarity);
  322. p[j].field |= ((ipg_r8(PHY_CTRL) &
  323. IPG_PC_MGMTDATA) >> 1) << (p[j].len - 1 - i);
  324. ipg_write_phy_ctl(ioaddr, IPG_PC_MGMTCLK_HI | polarity);
  325. }
  326. }
  327. }
  328. /* Set LED_Mode JES20040127EEPROM */
  329. static void ipg_set_led_mode(struct net_device *dev)
  330. {
  331. struct ipg_nic_private *sp = netdev_priv(dev);
  332. void __iomem *ioaddr = sp->ioaddr;
  333. u32 mode;
  334. mode = ipg_r32(ASIC_CTRL);
  335. mode &= ~(IPG_AC_LED_MODE_BIT_1 | IPG_AC_LED_MODE | IPG_AC_LED_SPEED);
  336. if ((sp->LED_Mode & 0x03) > 1)
  337. mode |= IPG_AC_LED_MODE_BIT_1; /* Write Asic Control Bit 29 */
  338. if ((sp->LED_Mode & 0x01) == 1)
  339. mode |= IPG_AC_LED_MODE; /* Write Asic Control Bit 14 */
  340. if ((sp->LED_Mode & 0x08) == 8)
  341. mode |= IPG_AC_LED_SPEED; /* Write Asic Control Bit 27 */
  342. ipg_w32(mode, ASIC_CTRL);
  343. }
  344. /* Set PHYSet JES20040127EEPROM */
  345. static void ipg_set_phy_set(struct net_device *dev)
  346. {
  347. struct ipg_nic_private *sp = netdev_priv(dev);
  348. void __iomem *ioaddr = sp->ioaddr;
  349. int physet;
  350. physet = ipg_r8(PHY_SET);
  351. physet &= ~(IPG_PS_MEM_LENB9B | IPG_PS_MEM_LEN9 | IPG_PS_NON_COMPDET);
  352. physet |= ((sp->LED_Mode & 0x70) >> 4);
  353. ipg_w8(physet, PHY_SET);
  354. }
  355. static int ipg_reset(struct net_device *dev, u32 resetflags)
  356. {
  357. /* Assert functional resets via the IPG AsicCtrl
  358. * register as specified by the 'resetflags' input
  359. * parameter.
  360. */
  361. void __iomem *ioaddr = ipg_ioaddr(dev); //JES20040127EEPROM:
  362. unsigned int timeout_count = 0;
  363. IPG_DEBUG_MSG("_reset\n");
  364. ipg_w32(ipg_r32(ASIC_CTRL) | resetflags, ASIC_CTRL);
  365. /* Delay added to account for problem with 10Mbps reset. */
  366. mdelay(IPG_AC_RESETWAIT);
  367. while (IPG_AC_RESET_BUSY & ipg_r32(ASIC_CTRL)) {
  368. mdelay(IPG_AC_RESETWAIT);
  369. if (++timeout_count > IPG_AC_RESET_TIMEOUT)
  370. return -ETIME;
  371. }
  372. /* Set LED Mode in Asic Control JES20040127EEPROM */
  373. ipg_set_led_mode(dev);
  374. /* Set PHYSet Register Value JES20040127EEPROM */
  375. ipg_set_phy_set(dev);
  376. return 0;
  377. }
  378. /* Find the GMII PHY address. */
  379. static int ipg_find_phyaddr(struct net_device *dev)
  380. {
  381. unsigned int phyaddr, i;
  382. for (i = 0; i < 32; i++) {
  383. u32 status;
  384. /* Search for the correct PHY address among 32 possible. */
  385. phyaddr = (IPG_NIC_PHY_ADDRESS + i) % 32;
  386. /* 10/22/03 Grace change verify from GMII_PHY_STATUS to
  387. GMII_PHY_ID1
  388. */
  389. status = mdio_read(dev, phyaddr, MII_BMSR);
  390. if ((status != 0xFFFF) && (status != 0))
  391. return phyaddr;
  392. }
  393. return 0x1f;
  394. }
  395. /*
  396. * Configure IPG based on result of IEEE 802.3 PHY
  397. * auto-negotiation.
  398. */
  399. static int ipg_config_autoneg(struct net_device *dev)
  400. {
  401. struct ipg_nic_private *sp = netdev_priv(dev);
  402. void __iomem *ioaddr = sp->ioaddr;
  403. unsigned int txflowcontrol;
  404. unsigned int rxflowcontrol;
  405. unsigned int fullduplex;
  406. unsigned int gig;
  407. u32 mac_ctrl_val;
  408. u32 asicctrl;
  409. u8 phyctrl;
  410. IPG_DEBUG_MSG("_config_autoneg\n");
  411. asicctrl = ipg_r32(ASIC_CTRL);
  412. phyctrl = ipg_r8(PHY_CTRL);
  413. mac_ctrl_val = ipg_r32(MAC_CTRL);
  414. /* Set flags for use in resolving auto-negotation, assuming
  415. * non-1000Mbps, half duplex, no flow control.
  416. */
  417. fullduplex = 0;
  418. txflowcontrol = 0;
  419. rxflowcontrol = 0;
  420. gig = 0;
  421. /* To accomodate a problem in 10Mbps operation,
  422. * set a global flag if PHY running in 10Mbps mode.
  423. */
  424. sp->tenmbpsmode = 0;
  425. printk(KERN_INFO "%s: Link speed = ", dev->name);
  426. /* Determine actual speed of operation. */
  427. switch (phyctrl & IPG_PC_LINK_SPEED) {
  428. case IPG_PC_LINK_SPEED_10MBPS:
  429. printk("10Mbps.\n");
  430. printk(KERN_INFO "%s: 10Mbps operational mode enabled.\n",
  431. dev->name);
  432. sp->tenmbpsmode = 1;
  433. break;
  434. case IPG_PC_LINK_SPEED_100MBPS:
  435. printk("100Mbps.\n");
  436. break;
  437. case IPG_PC_LINK_SPEED_1000MBPS:
  438. printk("1000Mbps.\n");
  439. gig = 1;
  440. break;
  441. default:
  442. printk("undefined!\n");
  443. return 0;
  444. }
  445. if (phyctrl & IPG_PC_DUPLEX_STATUS) {
  446. fullduplex = 1;
  447. txflowcontrol = 1;
  448. rxflowcontrol = 1;
  449. }
  450. /* Configure full duplex, and flow control. */
  451. if (fullduplex == 1) {
  452. /* Configure IPG for full duplex operation. */
  453. printk(KERN_INFO "%s: setting full duplex, ", dev->name);
  454. mac_ctrl_val |= IPG_MC_DUPLEX_SELECT_FD;
  455. if (txflowcontrol == 1) {
  456. printk("TX flow control");
  457. mac_ctrl_val |= IPG_MC_TX_FLOW_CONTROL_ENABLE;
  458. } else {
  459. printk("no TX flow control");
  460. mac_ctrl_val &= ~IPG_MC_TX_FLOW_CONTROL_ENABLE;
  461. }
  462. if (rxflowcontrol == 1) {
  463. printk(", RX flow control.");
  464. mac_ctrl_val |= IPG_MC_RX_FLOW_CONTROL_ENABLE;
  465. } else {
  466. printk(", no RX flow control.");
  467. mac_ctrl_val &= ~IPG_MC_RX_FLOW_CONTROL_ENABLE;
  468. }
  469. printk("\n");
  470. } else {
  471. /* Configure IPG for half duplex operation. */
  472. printk(KERN_INFO "%s: setting half duplex, "
  473. "no TX flow control, no RX flow control.\n", dev->name);
  474. mac_ctrl_val &= ~IPG_MC_DUPLEX_SELECT_FD &
  475. ~IPG_MC_TX_FLOW_CONTROL_ENABLE &
  476. ~IPG_MC_RX_FLOW_CONTROL_ENABLE;
  477. }
  478. ipg_w32(mac_ctrl_val, MAC_CTRL);
  479. return 0;
  480. }
  481. /* Determine and configure multicast operation and set
  482. * receive mode for IPG.
  483. */
  484. static void ipg_nic_set_multicast_list(struct net_device *dev)
  485. {
  486. void __iomem *ioaddr = ipg_ioaddr(dev);
  487. struct dev_mc_list *mc_list_ptr;
  488. unsigned int hashindex;
  489. u32 hashtable[2];
  490. u8 receivemode;
  491. IPG_DEBUG_MSG("_nic_set_multicast_list\n");
  492. receivemode = IPG_RM_RECEIVEUNICAST | IPG_RM_RECEIVEBROADCAST;
  493. if (dev->flags & IFF_PROMISC) {
  494. /* NIC to be configured in promiscuous mode. */
  495. receivemode = IPG_RM_RECEIVEALLFRAMES;
  496. } else if ((dev->flags & IFF_ALLMULTI) ||
  497. (dev->flags & IFF_MULTICAST &
  498. (dev->mc_count > IPG_MULTICAST_HASHTABLE_SIZE))) {
  499. /* NIC to be configured to receive all multicast
  500. * frames. */
  501. receivemode |= IPG_RM_RECEIVEMULTICAST;
  502. } else if (dev->flags & IFF_MULTICAST & (dev->mc_count > 0)) {
  503. /* NIC to be configured to receive selected
  504. * multicast addresses. */
  505. receivemode |= IPG_RM_RECEIVEMULTICASTHASH;
  506. }
  507. /* Calculate the bits to set for the 64 bit, IPG HASHTABLE.
  508. * The IPG applies a cyclic-redundancy-check (the same CRC
  509. * used to calculate the frame data FCS) to the destination
  510. * address all incoming multicast frames whose destination
  511. * address has the multicast bit set. The least significant
  512. * 6 bits of the CRC result are used as an addressing index
  513. * into the hash table. If the value of the bit addressed by
  514. * this index is a 1, the frame is passed to the host system.
  515. */
  516. /* Clear hashtable. */
  517. hashtable[0] = 0x00000000;
  518. hashtable[1] = 0x00000000;
  519. /* Cycle through all multicast addresses to filter. */
  520. for (mc_list_ptr = dev->mc_list;
  521. mc_list_ptr != NULL; mc_list_ptr = mc_list_ptr->next) {
  522. /* Calculate CRC result for each multicast address. */
  523. hashindex = crc32_le(0xffffffff, mc_list_ptr->dmi_addr,
  524. ETH_ALEN);
  525. /* Use only the least significant 6 bits. */
  526. hashindex = hashindex & 0x3F;
  527. /* Within "hashtable", set bit number "hashindex"
  528. * to a logic 1.
  529. */
  530. set_bit(hashindex, (void *)hashtable);
  531. }
  532. /* Write the value of the hashtable, to the 4, 16 bit
  533. * HASHTABLE IPG registers.
  534. */
  535. ipg_w32(hashtable[0], HASHTABLE_0);
  536. ipg_w32(hashtable[1], HASHTABLE_1);
  537. ipg_w8(IPG_RM_RSVD_MASK & receivemode, RECEIVE_MODE);
  538. IPG_DEBUG_MSG("ReceiveMode = %x\n", ipg_r8(RECEIVE_MODE));
  539. }
  540. static int ipg_io_config(struct net_device *dev)
  541. {
  542. void __iomem *ioaddr = ipg_ioaddr(dev);
  543. u32 origmacctrl;
  544. u32 restoremacctrl;
  545. IPG_DEBUG_MSG("_io_config\n");
  546. origmacctrl = ipg_r32(MAC_CTRL);
  547. restoremacctrl = origmacctrl | IPG_MC_STATISTICS_ENABLE;
  548. /* Based on compilation option, determine if FCS is to be
  549. * stripped on receive frames by IPG.
  550. */
  551. if (!IPG_STRIP_FCS_ON_RX)
  552. restoremacctrl |= IPG_MC_RCV_FCS;
  553. /* Determine if transmitter and/or receiver are
  554. * enabled so we may restore MACCTRL correctly.
  555. */
  556. if (origmacctrl & IPG_MC_TX_ENABLED)
  557. restoremacctrl |= IPG_MC_TX_ENABLE;
  558. if (origmacctrl & IPG_MC_RX_ENABLED)
  559. restoremacctrl |= IPG_MC_RX_ENABLE;
  560. /* Transmitter and receiver must be disabled before setting
  561. * IFSSelect.
  562. */
  563. ipg_w32((origmacctrl & (IPG_MC_RX_DISABLE | IPG_MC_TX_DISABLE)) &
  564. IPG_MC_RSVD_MASK, MAC_CTRL);
  565. /* Now that transmitter and receiver are disabled, write
  566. * to IFSSelect.
  567. */
  568. ipg_w32((origmacctrl & IPG_MC_IFS_96BIT) & IPG_MC_RSVD_MASK, MAC_CTRL);
  569. /* Set RECEIVEMODE register. */
  570. ipg_nic_set_multicast_list(dev);
  571. ipg_w16(IPG_MAX_RXFRAME_SIZE, MAX_FRAME_SIZE);
  572. ipg_w8(IPG_RXDMAPOLLPERIOD_VALUE, RX_DMA_POLL_PERIOD);
  573. ipg_w8(IPG_RXDMAURGENTTHRESH_VALUE, RX_DMA_URGENT_THRESH);
  574. ipg_w8(IPG_RXDMABURSTTHRESH_VALUE, RX_DMA_BURST_THRESH);
  575. ipg_w8(IPG_TXDMAPOLLPERIOD_VALUE, TX_DMA_POLL_PERIOD);
  576. ipg_w8(IPG_TXDMAURGENTTHRESH_VALUE, TX_DMA_URGENT_THRESH);
  577. ipg_w8(IPG_TXDMABURSTTHRESH_VALUE, TX_DMA_BURST_THRESH);
  578. ipg_w16((IPG_IE_HOST_ERROR | IPG_IE_TX_DMA_COMPLETE |
  579. IPG_IE_TX_COMPLETE | IPG_IE_INT_REQUESTED |
  580. IPG_IE_UPDATE_STATS | IPG_IE_LINK_EVENT |
  581. IPG_IE_RX_DMA_COMPLETE | IPG_IE_RX_DMA_PRIORITY), INT_ENABLE);
  582. ipg_w16(IPG_FLOWONTHRESH_VALUE, FLOW_ON_THRESH);
  583. ipg_w16(IPG_FLOWOFFTHRESH_VALUE, FLOW_OFF_THRESH);
  584. /* IPG multi-frag frame bug workaround.
  585. * Per silicon revision B3 eratta.
  586. */
  587. ipg_w16(ipg_r16(DEBUG_CTRL) | 0x0200, DEBUG_CTRL);
  588. /* IPG TX poll now bug workaround.
  589. * Per silicon revision B3 eratta.
  590. */
  591. ipg_w16(ipg_r16(DEBUG_CTRL) | 0x0010, DEBUG_CTRL);
  592. /* IPG RX poll now bug workaround.
  593. * Per silicon revision B3 eratta.
  594. */
  595. ipg_w16(ipg_r16(DEBUG_CTRL) | 0x0020, DEBUG_CTRL);
  596. /* Now restore MACCTRL to original setting. */
  597. ipg_w32(IPG_MC_RSVD_MASK & restoremacctrl, MAC_CTRL);
  598. /* Disable unused RMON statistics. */
  599. ipg_w32(IPG_RZ_ALL, RMON_STATISTICS_MASK);
  600. /* Disable unused MIB statistics. */
  601. ipg_w32(IPG_SM_MACCONTROLFRAMESXMTD | IPG_SM_MACCONTROLFRAMESRCVD |
  602. IPG_SM_BCSTOCTETXMTOK_BCSTFRAMESXMTDOK | IPG_SM_TXJUMBOFRAMES |
  603. IPG_SM_MCSTOCTETXMTOK_MCSTFRAMESXMTDOK | IPG_SM_RXJUMBOFRAMES |
  604. IPG_SM_BCSTOCTETRCVDOK_BCSTFRAMESRCVDOK |
  605. IPG_SM_UDPCHECKSUMERRORS | IPG_SM_TCPCHECKSUMERRORS |
  606. IPG_SM_IPCHECKSUMERRORS, STATISTICS_MASK);
  607. return 0;
  608. }
  609. /*
  610. * Create a receive buffer within system memory and update
  611. * NIC private structure appropriately.
  612. */
  613. static int ipg_get_rxbuff(struct net_device *dev, int entry)
  614. {
  615. struct ipg_nic_private *sp = netdev_priv(dev);
  616. struct ipg_rx *rxfd = sp->rxd + entry;
  617. struct sk_buff *skb;
  618. u64 rxfragsize;
  619. IPG_DEBUG_MSG("_get_rxbuff\n");
  620. skb = netdev_alloc_skb(dev, IPG_RXSUPPORT_SIZE + NET_IP_ALIGN);
  621. if (!skb) {
  622. sp->RxBuff[entry] = NULL;
  623. return -ENOMEM;
  624. }
  625. /* Adjust the data start location within the buffer to
  626. * align IP address field to a 16 byte boundary.
  627. */
  628. skb_reserve(skb, NET_IP_ALIGN);
  629. /* Associate the receive buffer with the IPG NIC. */
  630. skb->dev = dev;
  631. /* Save the address of the sk_buff structure. */
  632. sp->RxBuff[entry] = skb;
  633. rxfd->frag_info = cpu_to_le64(pci_map_single(sp->pdev, skb->data,
  634. sp->rx_buf_sz, PCI_DMA_FROMDEVICE));
  635. /* Set the RFD fragment length. */
  636. rxfragsize = IPG_RXFRAG_SIZE;
  637. rxfd->frag_info |= cpu_to_le64((rxfragsize << 48) & IPG_RFI_FRAGLEN);
  638. return 0;
  639. }
  640. static int init_rfdlist(struct net_device *dev)
  641. {
  642. struct ipg_nic_private *sp = netdev_priv(dev);
  643. void __iomem *ioaddr = sp->ioaddr;
  644. unsigned int i;
  645. IPG_DEBUG_MSG("_init_rfdlist\n");
  646. for (i = 0; i < IPG_RFDLIST_LENGTH; i++) {
  647. struct ipg_rx *rxfd = sp->rxd + i;
  648. if (sp->RxBuff[i]) {
  649. pci_unmap_single(sp->pdev,
  650. le64_to_cpu(rxfd->frag_info) & ~IPG_RFI_FRAGLEN,
  651. sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
  652. dev_kfree_skb_irq(sp->RxBuff[i]);
  653. sp->RxBuff[i] = NULL;
  654. }
  655. /* Clear out the RFS field. */
  656. rxfd->rfs = 0x0000000000000000;
  657. if (ipg_get_rxbuff(dev, i) < 0) {
  658. /*
  659. * A receive buffer was not ready, break the
  660. * RFD list here.
  661. */
  662. IPG_DEBUG_MSG("Cannot allocate Rx buffer.\n");
  663. /* Just in case we cannot allocate a single RFD.
  664. * Should not occur.
  665. */
  666. if (i == 0) {
  667. printk(KERN_ERR "%s: No memory available"
  668. " for RFD list.\n", dev->name);
  669. return -ENOMEM;
  670. }
  671. }
  672. rxfd->next_desc = cpu_to_le64(sp->rxd_map +
  673. sizeof(struct ipg_rx)*(i + 1));
  674. }
  675. sp->rxd[i - 1].next_desc = cpu_to_le64(sp->rxd_map);
  676. sp->rx_current = 0;
  677. sp->rx_dirty = 0;
  678. /* Write the location of the RFDList to the IPG. */
  679. ipg_w32((u32) sp->rxd_map, RFD_LIST_PTR_0);
  680. ipg_w32(0x00000000, RFD_LIST_PTR_1);
  681. return 0;
  682. }
  683. static void init_tfdlist(struct net_device *dev)
  684. {
  685. struct ipg_nic_private *sp = netdev_priv(dev);
  686. void __iomem *ioaddr = sp->ioaddr;
  687. unsigned int i;
  688. IPG_DEBUG_MSG("_init_tfdlist\n");
  689. for (i = 0; i < IPG_TFDLIST_LENGTH; i++) {
  690. struct ipg_tx *txfd = sp->txd + i;
  691. txfd->tfc = cpu_to_le64(IPG_TFC_TFDDONE);
  692. if (sp->TxBuff[i]) {
  693. dev_kfree_skb_irq(sp->TxBuff[i]);
  694. sp->TxBuff[i] = NULL;
  695. }
  696. txfd->next_desc = cpu_to_le64(sp->txd_map +
  697. sizeof(struct ipg_tx)*(i + 1));
  698. }
  699. sp->txd[i - 1].next_desc = cpu_to_le64(sp->txd_map);
  700. sp->tx_current = 0;
  701. sp->tx_dirty = 0;
  702. /* Write the location of the TFDList to the IPG. */
  703. IPG_DDEBUG_MSG("Starting TFDListPtr = %8.8x\n",
  704. (u32) sp->txd_map);
  705. ipg_w32((u32) sp->txd_map, TFD_LIST_PTR_0);
  706. ipg_w32(0x00000000, TFD_LIST_PTR_1);
  707. sp->ResetCurrentTFD = 1;
  708. }
  709. /*
  710. * Free all transmit buffers which have already been transfered
  711. * via DMA to the IPG.
  712. */
  713. static void ipg_nic_txfree(struct net_device *dev)
  714. {
  715. struct ipg_nic_private *sp = netdev_priv(dev);
  716. unsigned int released, pending, dirty;
  717. IPG_DEBUG_MSG("_nic_txfree\n");
  718. pending = sp->tx_current - sp->tx_dirty;
  719. dirty = sp->tx_dirty % IPG_TFDLIST_LENGTH;
  720. for (released = 0; released < pending; released++) {
  721. struct sk_buff *skb = sp->TxBuff[dirty];
  722. struct ipg_tx *txfd = sp->txd + dirty;
  723. IPG_DEBUG_MSG("TFC = %16.16lx\n", (unsigned long) txfd->tfc);
  724. /* Look at each TFD's TFC field beginning
  725. * at the last freed TFD up to the current TFD.
  726. * If the TFDDone bit is set, free the associated
  727. * buffer.
  728. */
  729. if (!(txfd->tfc & cpu_to_le64(IPG_TFC_TFDDONE)))
  730. break;
  731. /* Free the transmit buffer. */
  732. if (skb) {
  733. pci_unmap_single(sp->pdev,
  734. le64_to_cpu(txfd->frag_info) & ~IPG_TFI_FRAGLEN,
  735. skb->len, PCI_DMA_TODEVICE);
  736. dev_kfree_skb_irq(skb);
  737. sp->TxBuff[dirty] = NULL;
  738. }
  739. dirty = (dirty + 1) % IPG_TFDLIST_LENGTH;
  740. }
  741. sp->tx_dirty += released;
  742. if (netif_queue_stopped(dev) &&
  743. (sp->tx_current != (sp->tx_dirty + IPG_TFDLIST_LENGTH))) {
  744. netif_wake_queue(dev);
  745. }
  746. }
  747. static void ipg_tx_timeout(struct net_device *dev)
  748. {
  749. struct ipg_nic_private *sp = netdev_priv(dev);
  750. void __iomem *ioaddr = sp->ioaddr;
  751. ipg_reset(dev, IPG_AC_TX_RESET | IPG_AC_DMA | IPG_AC_NETWORK |
  752. IPG_AC_FIFO);
  753. spin_lock_irq(&sp->lock);
  754. /* Re-configure after DMA reset. */
  755. if (ipg_io_config(dev) < 0) {
  756. printk(KERN_INFO "%s: Error during re-configuration.\n",
  757. dev->name);
  758. }
  759. init_tfdlist(dev);
  760. spin_unlock_irq(&sp->lock);
  761. ipg_w32((ipg_r32(MAC_CTRL) | IPG_MC_TX_ENABLE) & IPG_MC_RSVD_MASK,
  762. MAC_CTRL);
  763. }
  764. /*
  765. * For TxComplete interrupts, free all transmit
  766. * buffers which have already been transfered via DMA
  767. * to the IPG.
  768. */
  769. static void ipg_nic_txcleanup(struct net_device *dev)
  770. {
  771. struct ipg_nic_private *sp = netdev_priv(dev);
  772. void __iomem *ioaddr = sp->ioaddr;
  773. unsigned int i;
  774. IPG_DEBUG_MSG("_nic_txcleanup\n");
  775. for (i = 0; i < IPG_TFDLIST_LENGTH; i++) {
  776. /* Reading the TXSTATUS register clears the
  777. * TX_COMPLETE interrupt.
  778. */
  779. u32 txstatusdword = ipg_r32(TX_STATUS);
  780. IPG_DEBUG_MSG("TxStatus = %8.8x\n", txstatusdword);
  781. /* Check for Transmit errors. Error bits only valid if
  782. * TX_COMPLETE bit in the TXSTATUS register is a 1.
  783. */
  784. if (!(txstatusdword & IPG_TS_TX_COMPLETE))
  785. break;
  786. /* If in 10Mbps mode, indicate transmit is ready. */
  787. if (sp->tenmbpsmode) {
  788. netif_wake_queue(dev);
  789. }
  790. /* Transmit error, increment stat counters. */
  791. if (txstatusdword & IPG_TS_TX_ERROR) {
  792. IPG_DEBUG_MSG("Transmit error.\n");
  793. sp->stats.tx_errors++;
  794. }
  795. /* Late collision, re-enable transmitter. */
  796. if (txstatusdword & IPG_TS_LATE_COLLISION) {
  797. IPG_DEBUG_MSG("Late collision on transmit.\n");
  798. ipg_w32((ipg_r32(MAC_CTRL) | IPG_MC_TX_ENABLE) &
  799. IPG_MC_RSVD_MASK, MAC_CTRL);
  800. }
  801. /* Maximum collisions, re-enable transmitter. */
  802. if (txstatusdword & IPG_TS_TX_MAX_COLL) {
  803. IPG_DEBUG_MSG("Maximum collisions on transmit.\n");
  804. ipg_w32((ipg_r32(MAC_CTRL) | IPG_MC_TX_ENABLE) &
  805. IPG_MC_RSVD_MASK, MAC_CTRL);
  806. }
  807. /* Transmit underrun, reset and re-enable
  808. * transmitter.
  809. */
  810. if (txstatusdword & IPG_TS_TX_UNDERRUN) {
  811. IPG_DEBUG_MSG("Transmitter underrun.\n");
  812. sp->stats.tx_fifo_errors++;
  813. ipg_reset(dev, IPG_AC_TX_RESET | IPG_AC_DMA |
  814. IPG_AC_NETWORK | IPG_AC_FIFO);
  815. /* Re-configure after DMA reset. */
  816. if (ipg_io_config(dev) < 0) {
  817. printk(KERN_INFO
  818. "%s: Error during re-configuration.\n",
  819. dev->name);
  820. }
  821. init_tfdlist(dev);
  822. ipg_w32((ipg_r32(MAC_CTRL) | IPG_MC_TX_ENABLE) &
  823. IPG_MC_RSVD_MASK, MAC_CTRL);
  824. }
  825. }
  826. ipg_nic_txfree(dev);
  827. }
  828. /* Provides statistical information about the IPG NIC. */
  829. static struct net_device_stats *ipg_nic_get_stats(struct net_device *dev)
  830. {
  831. struct ipg_nic_private *sp = netdev_priv(dev);
  832. void __iomem *ioaddr = sp->ioaddr;
  833. u16 temp1;
  834. u16 temp2;
  835. IPG_DEBUG_MSG("_nic_get_stats\n");
  836. /* Check to see if the NIC has been initialized via nic_open,
  837. * before trying to read statistic registers.
  838. */
  839. if (!test_bit(__LINK_STATE_START, &dev->state))
  840. return &sp->stats;
  841. sp->stats.rx_packets += ipg_r32(IPG_FRAMESRCVDOK);
  842. sp->stats.tx_packets += ipg_r32(IPG_FRAMESXMTDOK);
  843. sp->stats.rx_bytes += ipg_r32(IPG_OCTETRCVOK);
  844. sp->stats.tx_bytes += ipg_r32(IPG_OCTETXMTOK);
  845. temp1 = ipg_r16(IPG_FRAMESLOSTRXERRORS);
  846. sp->stats.rx_errors += temp1;
  847. sp->stats.rx_missed_errors += temp1;
  848. temp1 = ipg_r32(IPG_SINGLECOLFRAMES) + ipg_r32(IPG_MULTICOLFRAMES) +
  849. ipg_r32(IPG_LATECOLLISIONS);
  850. temp2 = ipg_r16(IPG_CARRIERSENSEERRORS);
  851. sp->stats.collisions += temp1;
  852. sp->stats.tx_dropped += ipg_r16(IPG_FRAMESABORTXSCOLLS);
  853. sp->stats.tx_errors += ipg_r16(IPG_FRAMESWEXDEFERRAL) +
  854. ipg_r32(IPG_FRAMESWDEFERREDXMT) + temp1 + temp2;
  855. sp->stats.multicast += ipg_r32(IPG_MCSTOCTETRCVDOK);
  856. /* detailed tx_errors */
  857. sp->stats.tx_carrier_errors += temp2;
  858. /* detailed rx_errors */
  859. sp->stats.rx_length_errors += ipg_r16(IPG_INRANGELENGTHERRORS) +
  860. ipg_r16(IPG_FRAMETOOLONGERRRORS);
  861. sp->stats.rx_crc_errors += ipg_r16(IPG_FRAMECHECKSEQERRORS);
  862. /* Unutilized IPG statistic registers. */
  863. ipg_r32(IPG_MCSTFRAMESRCVDOK);
  864. return &sp->stats;
  865. }
  866. /* Restore used receive buffers. */
  867. static int ipg_nic_rxrestore(struct net_device *dev)
  868. {
  869. struct ipg_nic_private *sp = netdev_priv(dev);
  870. const unsigned int curr = sp->rx_current;
  871. unsigned int dirty = sp->rx_dirty;
  872. IPG_DEBUG_MSG("_nic_rxrestore\n");
  873. for (dirty = sp->rx_dirty; curr - dirty > 0; dirty++) {
  874. unsigned int entry = dirty % IPG_RFDLIST_LENGTH;
  875. /* rx_copybreak may poke hole here and there. */
  876. if (sp->RxBuff[entry])
  877. continue;
  878. /* Generate a new receive buffer to replace the
  879. * current buffer (which will be released by the
  880. * Linux system).
  881. */
  882. if (ipg_get_rxbuff(dev, entry) < 0) {
  883. IPG_DEBUG_MSG("Cannot allocate new Rx buffer.\n");
  884. break;
  885. }
  886. /* Reset the RFS field. */
  887. sp->rxd[entry].rfs = 0x0000000000000000;
  888. }
  889. sp->rx_dirty = dirty;
  890. return 0;
  891. }
  892. #ifdef JUMBO_FRAME
  893. /* use jumboindex and jumbosize to control jumbo frame status
  894. initial status is jumboindex=-1 and jumbosize=0
  895. 1. jumboindex = -1 and jumbosize=0 : previous jumbo frame has been done.
  896. 2. jumboindex != -1 and jumbosize != 0 : jumbo frame is not over size and receiving
  897. 3. jumboindex = -1 and jumbosize != 0 : jumbo frame is over size, already dump
  898. previous receiving and need to continue dumping the current one
  899. */
  900. enum {
  901. NormalPacket,
  902. ErrorPacket
  903. };
  904. enum {
  905. Frame_NoStart_NoEnd = 0,
  906. Frame_WithStart = 1,
  907. Frame_WithEnd = 10,
  908. Frame_WithStart_WithEnd = 11
  909. };
  910. inline void ipg_nic_rx_free_skb(struct net_device *dev)
  911. {
  912. struct ipg_nic_private *sp = netdev_priv(dev);
  913. unsigned int entry = sp->rx_current % IPG_RFDLIST_LENGTH;
  914. if (sp->RxBuff[entry]) {
  915. struct ipg_rx *rxfd = sp->rxd + entry;
  916. pci_unmap_single(sp->pdev,
  917. le64_to_cpu(rxfd->frag_info & ~IPG_RFI_FRAGLEN),
  918. sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
  919. dev_kfree_skb_irq(sp->RxBuff[entry]);
  920. sp->RxBuff[entry] = NULL;
  921. }
  922. }
  923. inline int ipg_nic_rx_check_frame_type(struct net_device *dev)
  924. {
  925. struct ipg_nic_private *sp = netdev_priv(dev);
  926. struct ipg_rx *rxfd = sp->rxd + (sp->rx_current % IPG_RFDLIST_LENGTH);
  927. int type = Frame_NoStart_NoEnd;
  928. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_FRAMESTART)
  929. type += Frame_WithStart;
  930. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_FRAMEEND)
  931. type += Frame_WithEnd;
  932. return type;
  933. }
  934. inline int ipg_nic_rx_check_error(struct net_device *dev)
  935. {
  936. struct ipg_nic_private *sp = netdev_priv(dev);
  937. unsigned int entry = sp->rx_current % IPG_RFDLIST_LENGTH;
  938. struct ipg_rx *rxfd = sp->rxd + entry;
  939. if (IPG_DROP_ON_RX_ETH_ERRORS && (le64_to_cpu(rxfd->rfs) &
  940. (IPG_RFS_RXFIFOOVERRUN | IPG_RFS_RXRUNTFRAME |
  941. IPG_RFS_RXALIGNMENTERROR | IPG_RFS_RXFCSERROR |
  942. IPG_RFS_RXOVERSIZEDFRAME | IPG_RFS_RXLENGTHERROR))) {
  943. IPG_DEBUG_MSG("Rx error, RFS = %16.16lx\n",
  944. (unsigned long) rxfd->rfs);
  945. /* Increment general receive error statistic. */
  946. sp->stats.rx_errors++;
  947. /* Increment detailed receive error statistics. */
  948. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFIFOOVERRUN) {
  949. IPG_DEBUG_MSG("RX FIFO overrun occured.\n");
  950. sp->stats.rx_fifo_errors++;
  951. }
  952. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXRUNTFRAME) {
  953. IPG_DEBUG_MSG("RX runt occured.\n");
  954. sp->stats.rx_length_errors++;
  955. }
  956. /* Do nothing for IPG_RFS_RXOVERSIZEDFRAME,
  957. * error count handled by a IPG statistic register.
  958. */
  959. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXALIGNMENTERROR) {
  960. IPG_DEBUG_MSG("RX alignment error occured.\n");
  961. sp->stats.rx_frame_errors++;
  962. }
  963. /* Do nothing for IPG_RFS_RXFCSERROR, error count
  964. * handled by a IPG statistic register.
  965. */
  966. /* Free the memory associated with the RX
  967. * buffer since it is erroneous and we will
  968. * not pass it to higher layer processes.
  969. */
  970. if (sp->RxBuff[entry]) {
  971. pci_unmap_single(sp->pdev,
  972. le64_to_cpu(rxfd->frag_info & ~IPG_RFI_FRAGLEN),
  973. sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
  974. dev_kfree_skb_irq(sp->RxBuff[entry]);
  975. sp->RxBuff[entry] = NULL;
  976. }
  977. return ErrorPacket;
  978. }
  979. return NormalPacket;
  980. }
  981. static void ipg_nic_rx_with_start_and_end(struct net_device *dev,
  982. struct ipg_nic_private *sp,
  983. struct ipg_rx *rxfd, unsigned entry)
  984. {
  985. struct SJumbo *jumbo = &sp->Jumbo;
  986. struct sk_buff *skb;
  987. int framelen;
  988. if (jumbo->FoundStart) {
  989. dev_kfree_skb_irq(jumbo->skb);
  990. jumbo->FoundStart = 0;
  991. jumbo->CurrentSize = 0;
  992. jumbo->skb = NULL;
  993. }
  994. // 1: found error, 0 no error
  995. if (ipg_nic_rx_check_error(dev) != NormalPacket)
  996. return;
  997. skb = sp->RxBuff[entry];
  998. if (!skb)
  999. return;
  1000. // accept this frame and send to upper layer
  1001. framelen = le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFRAMELEN;
  1002. if (framelen > IPG_RXFRAG_SIZE)
  1003. framelen = IPG_RXFRAG_SIZE;
  1004. skb_put(skb, framelen);
  1005. skb->protocol = eth_type_trans(skb, dev);
  1006. skb->ip_summed = CHECKSUM_NONE;
  1007. netif_rx(skb);
  1008. dev->last_rx = jiffies;
  1009. sp->RxBuff[entry] = NULL;
  1010. }
  1011. static void ipg_nic_rx_with_start(struct net_device *dev,
  1012. struct ipg_nic_private *sp,
  1013. struct ipg_rx *rxfd, unsigned entry)
  1014. {
  1015. struct SJumbo *jumbo = &sp->Jumbo;
  1016. struct pci_dev *pdev = sp->pdev;
  1017. struct sk_buff *skb;
  1018. // 1: found error, 0 no error
  1019. if (ipg_nic_rx_check_error(dev) != NormalPacket)
  1020. return;
  1021. // accept this frame and send to upper layer
  1022. skb = sp->RxBuff[entry];
  1023. if (!skb)
  1024. return;
  1025. if (jumbo->FoundStart)
  1026. dev_kfree_skb_irq(jumbo->skb);
  1027. pci_unmap_single(pdev, le64_to_cpu(rxfd->frag_info & ~IPG_RFI_FRAGLEN),
  1028. sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
  1029. skb_put(skb, IPG_RXFRAG_SIZE);
  1030. jumbo->FoundStart = 1;
  1031. jumbo->CurrentSize = IPG_RXFRAG_SIZE;
  1032. jumbo->skb = skb;
  1033. sp->RxBuff[entry] = NULL;
  1034. dev->last_rx = jiffies;
  1035. }
  1036. static void ipg_nic_rx_with_end(struct net_device *dev,
  1037. struct ipg_nic_private *sp,
  1038. struct ipg_rx *rxfd, unsigned entry)
  1039. {
  1040. struct SJumbo *jumbo = &sp->Jumbo;
  1041. //1: found error, 0 no error
  1042. if (ipg_nic_rx_check_error(dev) == NormalPacket) {
  1043. struct sk_buff *skb = sp->RxBuff[entry];
  1044. if (!skb)
  1045. return;
  1046. if (jumbo->FoundStart) {
  1047. int framelen, endframelen;
  1048. framelen = le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFRAMELEN;
  1049. endframeLen = framelen - jumbo->CurrentSize;
  1050. /*
  1051. if (framelen > IPG_RXFRAG_SIZE)
  1052. framelen=IPG_RXFRAG_SIZE;
  1053. */
  1054. if (framelen > IPG_RXSUPPORT_SIZE)
  1055. dev_kfree_skb_irq(jumbo->skb);
  1056. else {
  1057. memcpy(skb_put(jumbo->skb, endframeLen),
  1058. skb->data, endframeLen);
  1059. jumbo->skb->protocol =
  1060. eth_type_trans(jumbo->skb, dev);
  1061. jumbo->skb->ip_summed = CHECKSUM_NONE;
  1062. netif_rx(jumbo->skb);
  1063. }
  1064. }
  1065. dev->last_rx = jiffies;
  1066. jumbo->FoundStart = 0;
  1067. jumbo->CurrentSize = 0;
  1068. jumbo->skb = NULL;
  1069. ipg_nic_rx_free_skb(dev);
  1070. } else {
  1071. dev_kfree_skb_irq(jumbo->skb);
  1072. jumbo->FoundStart = 0;
  1073. jumbo->CurrentSize = 0;
  1074. jumbo->skb = NULL;
  1075. }
  1076. }
  1077. static void ipg_nic_rx_no_start_no_end(struct net_device *dev,
  1078. struct ipg_nic_private *sp,
  1079. struct ipg_rx *rxfd, unsigned entry)
  1080. {
  1081. struct SJumbo *jumbo = &sp->Jumbo;
  1082. //1: found error, 0 no error
  1083. if (ipg_nic_rx_check_error(dev) == NormalPacket) {
  1084. struct sk_buff *skb = sp->RxBuff[entry];
  1085. if (skb) {
  1086. if (jumbo->FoundStart) {
  1087. jumbo->CurrentSize += IPG_RXFRAG_SIZE;
  1088. if (jumbo->CurrentSize <= IPG_RXSUPPORT_SIZE) {
  1089. memcpy(skb_put(jumbo->skb,
  1090. IPG_RXFRAG_SIZE),
  1091. skb->data, IPG_RXFRAG_SIZE);
  1092. }
  1093. }
  1094. dev->last_rx = jiffies;
  1095. ipg_nic_rx_free_skb(dev);
  1096. }
  1097. } else {
  1098. dev_kfree_skb_irq(jumbo->skb);
  1099. jumbo->FoundStart = 0;
  1100. jumbo->CurrentSize = 0;
  1101. jumbo->skb = NULL;
  1102. }
  1103. }
  1104. static int ipg_nic_rx(struct net_device *dev)
  1105. {
  1106. struct ipg_nic_private *sp = netdev_priv(dev);
  1107. unsigned int curr = sp->rx_current;
  1108. void __iomem *ioaddr = sp->ioaddr;
  1109. unsigned int i;
  1110. IPG_DEBUG_MSG("_nic_rx\n");
  1111. for (i = 0; i < IPG_MAXRFDPROCESS_COUNT; i++, curr++) {
  1112. unsigned int entry = curr % IPG_RFDLIST_LENGTH;
  1113. struct ipg_rx *rxfd = sp->rxd + entry;
  1114. if (!(rxfd->rfs & le64_to_cpu(IPG_RFS_RFDDONE)))
  1115. break;
  1116. switch (ipg_nic_rx_check_frame_type(dev)) {
  1117. case Frame_WithStart_WithEnd:
  1118. ipg_nic_rx_with_start_and_end(dev, tp, rxfd, entry);
  1119. break;
  1120. case Frame_WithStart:
  1121. ipg_nic_rx_with_start(dev, tp, rxfd, entry);
  1122. break;
  1123. case Frame_WithEnd:
  1124. ipg_nic_rx_with_end(dev, tp, rxfd, entry);
  1125. break;
  1126. case Frame_NoStart_NoEnd:
  1127. ipg_nic_rx_no_start_no_end(dev, tp, rxfd, entry);
  1128. break;
  1129. }
  1130. }
  1131. sp->rx_current = curr;
  1132. if (i == IPG_MAXRFDPROCESS_COUNT) {
  1133. /* There are more RFDs to process, however the
  1134. * allocated amount of RFD processing time has
  1135. * expired. Assert Interrupt Requested to make
  1136. * sure we come back to process the remaining RFDs.
  1137. */
  1138. ipg_w32(ipg_r32(ASIC_CTRL) | IPG_AC_INT_REQUEST, ASIC_CTRL);
  1139. }
  1140. ipg_nic_rxrestore(dev);
  1141. return 0;
  1142. }
  1143. #else
  1144. static int ipg_nic_rx(struct net_device *dev)
  1145. {
  1146. /* Transfer received Ethernet frames to higher network layers. */
  1147. struct ipg_nic_private *sp = netdev_priv(dev);
  1148. unsigned int curr = sp->rx_current;
  1149. void __iomem *ioaddr = sp->ioaddr;
  1150. struct ipg_rx *rxfd;
  1151. unsigned int i;
  1152. IPG_DEBUG_MSG("_nic_rx\n");
  1153. #define __RFS_MASK \
  1154. cpu_to_le64(IPG_RFS_RFDDONE | IPG_RFS_FRAMESTART | IPG_RFS_FRAMEEND)
  1155. for (i = 0; i < IPG_MAXRFDPROCESS_COUNT; i++, curr++) {
  1156. unsigned int entry = curr % IPG_RFDLIST_LENGTH;
  1157. struct sk_buff *skb = sp->RxBuff[entry];
  1158. unsigned int framelen;
  1159. rxfd = sp->rxd + entry;
  1160. if (((rxfd->rfs & __RFS_MASK) != __RFS_MASK) || !skb)
  1161. break;
  1162. /* Get received frame length. */
  1163. framelen = le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFRAMELEN;
  1164. /* Check for jumbo frame arrival with too small
  1165. * RXFRAG_SIZE.
  1166. */
  1167. if (framelen > IPG_RXFRAG_SIZE) {
  1168. IPG_DEBUG_MSG
  1169. ("RFS FrameLen > allocated fragment size.\n");
  1170. framelen = IPG_RXFRAG_SIZE;
  1171. }
  1172. if ((IPG_DROP_ON_RX_ETH_ERRORS && (le64_to_cpu(rxfd->rfs) &
  1173. (IPG_RFS_RXFIFOOVERRUN | IPG_RFS_RXRUNTFRAME |
  1174. IPG_RFS_RXALIGNMENTERROR | IPG_RFS_RXFCSERROR |
  1175. IPG_RFS_RXOVERSIZEDFRAME | IPG_RFS_RXLENGTHERROR)))) {
  1176. IPG_DEBUG_MSG("Rx error, RFS = %16.16lx\n",
  1177. (unsigned long int) rxfd->rfs);
  1178. /* Increment general receive error statistic. */
  1179. sp->stats.rx_errors++;
  1180. /* Increment detailed receive error statistics. */
  1181. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFIFOOVERRUN) {
  1182. IPG_DEBUG_MSG("RX FIFO overrun occured.\n");
  1183. sp->stats.rx_fifo_errors++;
  1184. }
  1185. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXRUNTFRAME) {
  1186. IPG_DEBUG_MSG("RX runt occured.\n");
  1187. sp->stats.rx_length_errors++;
  1188. }
  1189. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXOVERSIZEDFRAME) ;
  1190. /* Do nothing, error count handled by a IPG
  1191. * statistic register.
  1192. */
  1193. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXALIGNMENTERROR) {
  1194. IPG_DEBUG_MSG("RX alignment error occured.\n");
  1195. sp->stats.rx_frame_errors++;
  1196. }
  1197. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFCSERROR) ;
  1198. /* Do nothing, error count handled by a IPG
  1199. * statistic register.
  1200. */
  1201. /* Free the memory associated with the RX
  1202. * buffer since it is erroneous and we will
  1203. * not pass it to higher layer processes.
  1204. */
  1205. if (skb) {
  1206. __le64 info = rxfd->frag_info;
  1207. pci_unmap_single(sp->pdev,
  1208. le64_to_cpu(info) & ~IPG_RFI_FRAGLEN,
  1209. sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
  1210. dev_kfree_skb_irq(skb);
  1211. }
  1212. } else {
  1213. /* Adjust the new buffer length to accomodate the size
  1214. * of the received frame.
  1215. */
  1216. skb_put(skb, framelen);
  1217. /* Set the buffer's protocol field to Ethernet. */
  1218. skb->protocol = eth_type_trans(skb, dev);
  1219. /* If the frame contains an IP/TCP/UDP frame,
  1220. * determine if upper layer must check IP/TCP/UDP
  1221. * checksums.
  1222. *
  1223. * NOTE: DO NOT RELY ON THE TCP/UDP CHECKSUM
  1224. * VERIFICATION FOR SILICON REVISIONS B3
  1225. * AND EARLIER!
  1226. *
  1227. if ((le64_to_cpu(rxfd->rfs &
  1228. (IPG_RFS_TCPDETECTED | IPG_RFS_UDPDETECTED |
  1229. IPG_RFS_IPDETECTED))) &&
  1230. !(le64_to_cpu(rxfd->rfs &
  1231. (IPG_RFS_TCPERROR | IPG_RFS_UDPERROR |
  1232. IPG_RFS_IPERROR)))) {
  1233. * Indicate IP checksums were performed
  1234. * by the IPG.
  1235. *
  1236. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1237. } else
  1238. */
  1239. {
  1240. /* The IPG encountered an error with (or
  1241. * there were no) IP/TCP/UDP checksums.
  1242. * This may or may not indicate an invalid
  1243. * IP/TCP/UDP frame was received. Let the
  1244. * upper layer decide.
  1245. */
  1246. skb->ip_summed = CHECKSUM_NONE;
  1247. }
  1248. /* Hand off frame for higher layer processing.
  1249. * The function netif_rx() releases the sk_buff
  1250. * when processing completes.
  1251. */
  1252. netif_rx(skb);
  1253. /* Record frame receive time (jiffies = Linux
  1254. * kernel current time stamp).
  1255. */
  1256. dev->last_rx = jiffies;
  1257. }
  1258. /* Assure RX buffer is not reused by IPG. */
  1259. sp->RxBuff[entry] = NULL;
  1260. }
  1261. /*
  1262. * If there are more RFDs to proces and the allocated amount of RFD
  1263. * processing time has expired, assert Interrupt Requested to make
  1264. * sure we come back to process the remaining RFDs.
  1265. */
  1266. if (i == IPG_MAXRFDPROCESS_COUNT)
  1267. ipg_w32(ipg_r32(ASIC_CTRL) | IPG_AC_INT_REQUEST, ASIC_CTRL);
  1268. #ifdef IPG_DEBUG
  1269. /* Check if the RFD list contained no receive frame data. */
  1270. if (!i)
  1271. sp->EmptyRFDListCount++;
  1272. #endif
  1273. while ((le64_to_cpu(rxfd->rfs) & IPG_RFS_RFDDONE) &&
  1274. !((le64_to_cpu(rxfd->rfs) & IPG_RFS_FRAMESTART) &&
  1275. (le64_to_cpu(rxfd->rfs) & IPG_RFS_FRAMEEND))) {
  1276. unsigned int entry = curr++ % IPG_RFDLIST_LENGTH;
  1277. rxfd = sp->rxd + entry;
  1278. IPG_DEBUG_MSG("Frame requires multiple RFDs.\n");
  1279. /* An unexpected event, additional code needed to handle
  1280. * properly. So for the time being, just disregard the
  1281. * frame.
  1282. */
  1283. /* Free the memory associated with the RX
  1284. * buffer since it is erroneous and we will
  1285. * not pass it to higher layer processes.
  1286. */
  1287. if (sp->RxBuff[entry]) {
  1288. pci_unmap_single(sp->pdev,
  1289. le64_to_cpu(rxfd->frag_info) & ~IPG_RFI_FRAGLEN,
  1290. sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
  1291. dev_kfree_skb_irq(sp->RxBuff[entry]);
  1292. }
  1293. /* Assure RX buffer is not reused by IPG. */
  1294. sp->RxBuff[entry] = NULL;
  1295. }
  1296. sp->rx_current = curr;
  1297. /* Check to see if there are a minimum number of used
  1298. * RFDs before restoring any (should improve performance.)
  1299. */
  1300. if ((curr - sp->rx_dirty) >= IPG_MINUSEDRFDSTOFREE)
  1301. ipg_nic_rxrestore(dev);
  1302. return 0;
  1303. }
  1304. #endif
  1305. static void ipg_reset_after_host_error(struct work_struct *work)
  1306. {
  1307. struct ipg_nic_private *sp =
  1308. container_of(work, struct ipg_nic_private, task.work);
  1309. struct net_device *dev = sp->dev;
  1310. IPG_DDEBUG_MSG("DMACtrl = %8.8x\n", ioread32(sp->ioaddr + IPG_DMACTRL));
  1311. /*
  1312. * Acknowledge HostError interrupt by resetting
  1313. * IPG DMA and HOST.
  1314. */
  1315. ipg_reset(dev, IPG_AC_GLOBAL_RESET | IPG_AC_HOST | IPG_AC_DMA);
  1316. init_rfdlist(dev);
  1317. init_tfdlist(dev);
  1318. if (ipg_io_config(dev) < 0) {
  1319. printk(KERN_INFO "%s: Cannot recover from PCI error.\n",
  1320. dev->name);
  1321. schedule_delayed_work(&sp->task, HZ);
  1322. }
  1323. }
  1324. static irqreturn_t ipg_interrupt_handler(int irq, void *dev_inst)
  1325. {
  1326. struct net_device *dev = dev_inst;
  1327. struct ipg_nic_private *sp = netdev_priv(dev);
  1328. void __iomem *ioaddr = sp->ioaddr;
  1329. unsigned int handled = 0;
  1330. u16 status;
  1331. IPG_DEBUG_MSG("_interrupt_handler\n");
  1332. #ifdef JUMBO_FRAME
  1333. ipg_nic_rxrestore(dev);
  1334. #endif
  1335. spin_lock(&sp->lock);
  1336. /* Get interrupt source information, and acknowledge
  1337. * some (i.e. TxDMAComplete, RxDMAComplete, RxEarly,
  1338. * IntRequested, MacControlFrame, LinkEvent) interrupts
  1339. * if issued. Also, all IPG interrupts are disabled by
  1340. * reading IntStatusAck.
  1341. */
  1342. status = ipg_r16(INT_STATUS_ACK);
  1343. IPG_DEBUG_MSG("IntStatusAck = %4.4x\n", status);
  1344. /* Shared IRQ of remove event. */
  1345. if (!(status & IPG_IS_RSVD_MASK))
  1346. goto out_enable;
  1347. handled = 1;
  1348. if (unlikely(!netif_running(dev)))
  1349. goto out_unlock;
  1350. /* If RFDListEnd interrupt, restore all used RFDs. */
  1351. if (status & IPG_IS_RFD_LIST_END) {
  1352. IPG_DEBUG_MSG("RFDListEnd Interrupt.\n");
  1353. /* The RFD list end indicates an RFD was encountered
  1354. * with a 0 NextPtr, or with an RFDDone bit set to 1
  1355. * (indicating the RFD is not read for use by the
  1356. * IPG.) Try to restore all RFDs.
  1357. */
  1358. ipg_nic_rxrestore(dev);
  1359. #ifdef IPG_DEBUG
  1360. /* Increment the RFDlistendCount counter. */
  1361. sp->RFDlistendCount++;
  1362. #endif
  1363. }
  1364. /* If RFDListEnd, RxDMAPriority, RxDMAComplete, or
  1365. * IntRequested interrupt, process received frames. */
  1366. if ((status & IPG_IS_RX_DMA_PRIORITY) ||
  1367. (status & IPG_IS_RFD_LIST_END) ||
  1368. (status & IPG_IS_RX_DMA_COMPLETE) ||
  1369. (status & IPG_IS_INT_REQUESTED)) {
  1370. #ifdef IPG_DEBUG
  1371. /* Increment the RFD list checked counter if interrupted
  1372. * only to check the RFD list. */
  1373. if (status & (~(IPG_IS_RX_DMA_PRIORITY | IPG_IS_RFD_LIST_END |
  1374. IPG_IS_RX_DMA_COMPLETE | IPG_IS_INT_REQUESTED) &
  1375. (IPG_IS_HOST_ERROR | IPG_IS_TX_DMA_COMPLETE |
  1376. IPG_IS_LINK_EVENT | IPG_IS_TX_COMPLETE |
  1377. IPG_IS_UPDATE_STATS)))
  1378. sp->RFDListCheckedCount++;
  1379. #endif
  1380. ipg_nic_rx(dev);
  1381. }
  1382. /* If TxDMAComplete interrupt, free used TFDs. */
  1383. if (status & IPG_IS_TX_DMA_COMPLETE)
  1384. ipg_nic_txfree(dev);
  1385. /* TxComplete interrupts indicate one of numerous actions.
  1386. * Determine what action to take based on TXSTATUS register.
  1387. */
  1388. if (status & IPG_IS_TX_COMPLETE)
  1389. ipg_nic_txcleanup(dev);
  1390. /* If UpdateStats interrupt, update Linux Ethernet statistics */
  1391. if (status & IPG_IS_UPDATE_STATS)
  1392. ipg_nic_get_stats(dev);
  1393. /* If HostError interrupt, reset IPG. */
  1394. if (status & IPG_IS_HOST_ERROR) {
  1395. IPG_DDEBUG_MSG("HostError Interrupt\n");
  1396. schedule_delayed_work(&sp->task, 0);
  1397. }
  1398. /* If LinkEvent interrupt, resolve autonegotiation. */
  1399. if (status & IPG_IS_LINK_EVENT) {
  1400. if (ipg_config_autoneg(dev) < 0)
  1401. printk(KERN_INFO "%s: Auto-negotiation error.\n",
  1402. dev->name);
  1403. }
  1404. /* If MACCtrlFrame interrupt, do nothing. */
  1405. if (status & IPG_IS_MAC_CTRL_FRAME)
  1406. IPG_DEBUG_MSG("MACCtrlFrame interrupt.\n");
  1407. /* If RxComplete interrupt, do nothing. */
  1408. if (status & IPG_IS_RX_COMPLETE)
  1409. IPG_DEBUG_MSG("RxComplete interrupt.\n");
  1410. /* If RxEarly interrupt, do nothing. */
  1411. if (status & IPG_IS_RX_EARLY)
  1412. IPG_DEBUG_MSG("RxEarly interrupt.\n");
  1413. out_enable:
  1414. /* Re-enable IPG interrupts. */
  1415. ipg_w16(IPG_IE_TX_DMA_COMPLETE | IPG_IE_RX_DMA_COMPLETE |
  1416. IPG_IE_HOST_ERROR | IPG_IE_INT_REQUESTED | IPG_IE_TX_COMPLETE |
  1417. IPG_IE_LINK_EVENT | IPG_IE_UPDATE_STATS, INT_ENABLE);
  1418. out_unlock:
  1419. spin_unlock(&sp->lock);
  1420. return IRQ_RETVAL(handled);
  1421. }
  1422. static void ipg_rx_clear(struct ipg_nic_private *sp)
  1423. {
  1424. unsigned int i;
  1425. for (i = 0; i < IPG_RFDLIST_LENGTH; i++) {
  1426. if (sp->RxBuff[i]) {
  1427. struct ipg_rx *rxfd = sp->rxd + i;
  1428. dev_kfree_skb_irq(sp->RxBuff[i]);
  1429. sp->RxBuff[i] = NULL;
  1430. pci_unmap_single(sp->pdev,
  1431. le64_to_cpu(rxfd->frag_info) & ~IPG_RFI_FRAGLEN,
  1432. sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
  1433. }
  1434. }
  1435. }
  1436. static void ipg_tx_clear(struct ipg_nic_private *sp)
  1437. {
  1438. unsigned int i;
  1439. for (i = 0; i < IPG_TFDLIST_LENGTH; i++) {
  1440. if (sp->TxBuff[i]) {
  1441. struct ipg_tx *txfd = sp->txd + i;
  1442. pci_unmap_single(sp->pdev,
  1443. le64_to_cpu(txfd->frag_info) & ~IPG_TFI_FRAGLEN,
  1444. sp->TxBuff[i]->len, PCI_DMA_TODEVICE);
  1445. dev_kfree_skb_irq(sp->TxBuff[i]);
  1446. sp->TxBuff[i] = NULL;
  1447. }
  1448. }
  1449. }
  1450. static int ipg_nic_open(struct net_device *dev)
  1451. {
  1452. struct ipg_nic_private *sp = netdev_priv(dev);
  1453. void __iomem *ioaddr = sp->ioaddr;
  1454. struct pci_dev *pdev = sp->pdev;
  1455. int rc;
  1456. IPG_DEBUG_MSG("_nic_open\n");
  1457. sp->rx_buf_sz = IPG_RXSUPPORT_SIZE;
  1458. /* Check for interrupt line conflicts, and request interrupt
  1459. * line for IPG.
  1460. *
  1461. * IMPORTANT: Disable IPG interrupts prior to registering
  1462. * IRQ.
  1463. */
  1464. ipg_w16(0x0000, INT_ENABLE);
  1465. /* Register the interrupt line to be used by the IPG within
  1466. * the Linux system.
  1467. */
  1468. rc = request_irq(pdev->irq, &ipg_interrupt_handler, IRQF_SHARED,
  1469. dev->name, dev);
  1470. if (rc < 0) {
  1471. printk(KERN_INFO "%s: Error when requesting interrupt.\n",
  1472. dev->name);
  1473. goto out;
  1474. }
  1475. dev->irq = pdev->irq;
  1476. rc = -ENOMEM;
  1477. sp->rxd = dma_alloc_coherent(&pdev->dev, IPG_RX_RING_BYTES,
  1478. &sp->rxd_map, GFP_KERNEL);
  1479. if (!sp->rxd)
  1480. goto err_free_irq_0;
  1481. sp->txd = dma_alloc_coherent(&pdev->dev, IPG_TX_RING_BYTES,
  1482. &sp->txd_map, GFP_KERNEL);
  1483. if (!sp->txd)
  1484. goto err_free_rx_1;
  1485. rc = init_rfdlist(dev);
  1486. if (rc < 0) {
  1487. printk(KERN_INFO "%s: Error during configuration.\n",
  1488. dev->name);
  1489. goto err_free_tx_2;
  1490. }
  1491. init_tfdlist(dev);
  1492. rc = ipg_io_config(dev);
  1493. if (rc < 0) {
  1494. printk(KERN_INFO "%s: Error during configuration.\n",
  1495. dev->name);
  1496. goto err_release_tfdlist_3;
  1497. }
  1498. /* Resolve autonegotiation. */
  1499. if (ipg_config_autoneg(dev) < 0)
  1500. printk(KERN_INFO "%s: Auto-negotiation error.\n", dev->name);
  1501. #ifdef JUMBO_FRAME
  1502. /* initialize JUMBO Frame control variable */
  1503. sp->Jumbo.FoundStart = 0;
  1504. sp->Jumbo.CurrentSize = 0;
  1505. sp->Jumbo.skb = 0;
  1506. dev->mtu = IPG_TXFRAG_SIZE;
  1507. #endif
  1508. /* Enable transmit and receive operation of the IPG. */
  1509. ipg_w32((ipg_r32(MAC_CTRL) | IPG_MC_RX_ENABLE | IPG_MC_TX_ENABLE) &
  1510. IPG_MC_RSVD_MASK, MAC_CTRL);
  1511. netif_start_queue(dev);
  1512. out:
  1513. return rc;
  1514. err_release_tfdlist_3:
  1515. ipg_tx_clear(sp);
  1516. ipg_rx_clear(sp);
  1517. err_free_tx_2:
  1518. dma_free_coherent(&pdev->dev, IPG_TX_RING_BYTES, sp->txd, sp->txd_map);
  1519. err_free_rx_1:
  1520. dma_free_coherent(&pdev->dev, IPG_RX_RING_BYTES, sp->rxd, sp->rxd_map);
  1521. err_free_irq_0:
  1522. free_irq(pdev->irq, dev);
  1523. goto out;
  1524. }
  1525. static int ipg_nic_stop(struct net_device *dev)
  1526. {
  1527. struct ipg_nic_private *sp = netdev_priv(dev);
  1528. void __iomem *ioaddr = sp->ioaddr;
  1529. struct pci_dev *pdev = sp->pdev;
  1530. IPG_DEBUG_MSG("_nic_stop\n");
  1531. netif_stop_queue(dev);
  1532. IPG_DDEBUG_MSG("RFDlistendCount = %i\n", sp->RFDlistendCount);
  1533. IPG_DDEBUG_MSG("RFDListCheckedCount = %i\n", sp->rxdCheckedCount);
  1534. IPG_DDEBUG_MSG("EmptyRFDListCount = %i\n", sp->EmptyRFDListCount);
  1535. IPG_DUMPTFDLIST(dev);
  1536. do {
  1537. (void) ipg_r16(INT_STATUS_ACK);
  1538. ipg_reset(dev, IPG_AC_GLOBAL_RESET | IPG_AC_HOST | IPG_AC_DMA);
  1539. synchronize_irq(pdev->irq);
  1540. } while (ipg_r16(INT_ENABLE) & IPG_IE_RSVD_MASK);
  1541. ipg_rx_clear(sp);
  1542. ipg_tx_clear(sp);
  1543. pci_free_consistent(pdev, IPG_RX_RING_BYTES, sp->rxd, sp->rxd_map);
  1544. pci_free_consistent(pdev, IPG_TX_RING_BYTES, sp->txd, sp->txd_map);
  1545. free_irq(pdev->irq, dev);
  1546. return 0;
  1547. }
  1548. static int ipg_nic_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
  1549. {
  1550. struct ipg_nic_private *sp = netdev_priv(dev);
  1551. void __iomem *ioaddr = sp->ioaddr;
  1552. unsigned int entry = sp->tx_current % IPG_TFDLIST_LENGTH;
  1553. unsigned long flags;
  1554. struct ipg_tx *txfd;
  1555. IPG_DDEBUG_MSG("_nic_hard_start_xmit\n");
  1556. /* If in 10Mbps mode, stop the transmit queue so
  1557. * no more transmit frames are accepted.
  1558. */
  1559. if (sp->tenmbpsmode)
  1560. netif_stop_queue(dev);
  1561. if (sp->ResetCurrentTFD) {
  1562. sp->ResetCurrentTFD = 0;
  1563. entry = 0;
  1564. }
  1565. txfd = sp->txd + entry;
  1566. sp->TxBuff[entry] = skb;
  1567. /* Clear all TFC fields, except TFDDONE. */
  1568. txfd->tfc = cpu_to_le64(IPG_TFC_TFDDONE);
  1569. /* Specify the TFC field within the TFD. */
  1570. txfd->tfc |= cpu_to_le64(IPG_TFC_WORDALIGNDISABLED |
  1571. (IPG_TFC_FRAMEID & cpu_to_le64(sp->tx_current)) |
  1572. (IPG_TFC_FRAGCOUNT & (1 << 24)));
  1573. /* Request TxComplete interrupts at an interval defined
  1574. * by the constant IPG_FRAMESBETWEENTXCOMPLETES.
  1575. * Request TxComplete interrupt for every frame
  1576. * if in 10Mbps mode to accomodate problem with 10Mbps
  1577. * processing.
  1578. */
  1579. if (sp->tenmbpsmode)
  1580. txfd->tfc |= cpu_to_le64(IPG_TFC_TXINDICATE);
  1581. txfd->tfc |= cpu_to_le64(IPG_TFC_TXDMAINDICATE);
  1582. /* Based on compilation option, determine if FCS is to be
  1583. * appended to transmit frame by IPG.
  1584. */
  1585. if (!(IPG_APPEND_FCS_ON_TX))
  1586. txfd->tfc |= cpu_to_le64(IPG_TFC_FCSAPPENDDISABLE);
  1587. /* Based on compilation option, determine if IP, TCP and/or
  1588. * UDP checksums are to be added to transmit frame by IPG.
  1589. */
  1590. if (IPG_ADD_IPCHECKSUM_ON_TX)
  1591. txfd->tfc |= cpu_to_le64(IPG_TFC_IPCHECKSUMENABLE);
  1592. if (IPG_ADD_TCPCHECKSUM_ON_TX)
  1593. txfd->tfc |= cpu_to_le64(IPG_TFC_TCPCHECKSUMENABLE);
  1594. if (IPG_ADD_UDPCHECKSUM_ON_TX)
  1595. txfd->tfc |= cpu_to_le64(IPG_TFC_UDPCHECKSUMENABLE);
  1596. /* Based on compilation option, determine if VLAN tag info is to be
  1597. * inserted into transmit frame by IPG.
  1598. */
  1599. if (IPG_INSERT_MANUAL_VLAN_TAG) {
  1600. txfd->tfc |= cpu_to_le64(IPG_TFC_VLANTAGINSERT |
  1601. ((u64) IPG_MANUAL_VLAN_VID << 32) |
  1602. ((u64) IPG_MANUAL_VLAN_CFI << 44) |
  1603. ((u64) IPG_MANUAL_VLAN_USERPRIORITY << 45));
  1604. }
  1605. /* The fragment start location within system memory is defined
  1606. * by the sk_buff structure's data field. The physical address
  1607. * of this location within the system's virtual memory space
  1608. * is determined using the IPG_HOST2BUS_MAP function.
  1609. */
  1610. txfd->frag_info = cpu_to_le64(pci_map_single(sp->pdev, skb->data,
  1611. skb->len, PCI_DMA_TODEVICE));
  1612. /* The length of the fragment within system memory is defined by
  1613. * the sk_buff structure's len field.
  1614. */
  1615. txfd->frag_info |= cpu_to_le64(IPG_TFI_FRAGLEN &
  1616. ((u64) (skb->len & 0xffff) << 48));
  1617. /* Clear the TFDDone bit last to indicate the TFD is ready
  1618. * for transfer to the IPG.
  1619. */
  1620. txfd->tfc &= cpu_to_le64(~IPG_TFC_TFDDONE);
  1621. spin_lock_irqsave(&sp->lock, flags);
  1622. sp->tx_current++;
  1623. mmiowb();
  1624. ipg_w32(IPG_DC_TX_DMA_POLL_NOW, DMA_CTRL);
  1625. if (sp->tx_current == (sp->tx_dirty + IPG_TFDLIST_LENGTH))
  1626. netif_stop_queue(dev);
  1627. spin_unlock_irqrestore(&sp->lock, flags);
  1628. return NETDEV_TX_OK;
  1629. }
  1630. static void ipg_set_phy_default_param(unsigned char rev,
  1631. struct net_device *dev, int phy_address)
  1632. {
  1633. unsigned short length;
  1634. unsigned char revision;
  1635. unsigned short *phy_param;
  1636. unsigned short address, value;
  1637. phy_param = &DefaultPhyParam[0];
  1638. length = *phy_param & 0x00FF;
  1639. revision = (unsigned char)((*phy_param) >> 8);
  1640. phy_param++;
  1641. while (length != 0) {
  1642. if (rev == revision) {
  1643. while (length > 1) {
  1644. address = *phy_param;
  1645. value = *(phy_param + 1);
  1646. phy_param += 2;
  1647. mdio_write(dev, phy_address, address, value);
  1648. length -= 4;
  1649. }
  1650. break;
  1651. } else {
  1652. phy_param += length / 2;
  1653. length = *phy_param & 0x00FF;
  1654. revision = (unsigned char)((*phy_param) >> 8);
  1655. phy_param++;
  1656. }
  1657. }
  1658. }
  1659. /* JES20040127EEPROM */
  1660. static int read_eeprom(struct net_device *dev, int eep_addr)
  1661. {
  1662. void __iomem *ioaddr = ipg_ioaddr(dev);
  1663. unsigned int i;
  1664. int ret = 0;
  1665. u16 value;
  1666. value = IPG_EC_EEPROM_READOPCODE | (eep_addr & 0xff);
  1667. ipg_w16(value, EEPROM_CTRL);
  1668. for (i = 0; i < 1000; i++) {
  1669. u16 data;
  1670. mdelay(10);
  1671. data = ipg_r16(EEPROM_CTRL);
  1672. if (!(data & IPG_EC_EEPROM_BUSY)) {
  1673. ret = ipg_r16(EEPROM_DATA);
  1674. break;
  1675. }
  1676. }
  1677. return ret;
  1678. }
  1679. static void ipg_init_mii(struct net_device *dev)
  1680. {
  1681. struct ipg_nic_private *sp = netdev_priv(dev);
  1682. struct mii_if_info *mii_if = &sp->mii_if;
  1683. int phyaddr;
  1684. mii_if->dev = dev;
  1685. mii_if->mdio_read = mdio_read;
  1686. mii_if->mdio_write = mdio_write;
  1687. mii_if->phy_id_mask = 0x1f;
  1688. mii_if->reg_num_mask = 0x1f;
  1689. mii_if->phy_id = phyaddr = ipg_find_phyaddr(dev);
  1690. if (phyaddr != 0x1f) {
  1691. u16 mii_phyctrl, mii_1000cr;
  1692. u8 revisionid = 0;
  1693. mii_1000cr = mdio_read(dev, phyaddr, MII_CTRL1000);
  1694. mii_1000cr |= ADVERTISE_1000FULL | ADVERTISE_1000HALF |
  1695. GMII_PHY_1000BASETCONTROL_PreferMaster;
  1696. mdio_write(dev, phyaddr, MII_CTRL1000, mii_1000cr);
  1697. mii_phyctrl = mdio_read(dev, phyaddr, MII_BMCR);
  1698. /* Set default phyparam */
  1699. pci_read_config_byte(sp->pdev, PCI_REVISION_ID, &revisionid);
  1700. ipg_set_phy_default_param(revisionid, dev, phyaddr);
  1701. /* Reset PHY */
  1702. mii_phyctrl |= BMCR_RESET | BMCR_ANRESTART;
  1703. mdio_write(dev, phyaddr, MII_BMCR, mii_phyctrl);
  1704. }
  1705. }
  1706. static int ipg_hw_init(struct net_device *dev)
  1707. {
  1708. struct ipg_nic_private *sp = netdev_priv(dev);
  1709. void __iomem *ioaddr = sp->ioaddr;
  1710. unsigned int i;
  1711. int rc;
  1712. /* Read/Write and Reset EEPROM Value Jesse20040128EEPROM_VALUE */
  1713. /* Read LED Mode Configuration from EEPROM */
  1714. sp->LED_Mode = read_eeprom(dev, 6);
  1715. /* Reset all functions within the IPG. Do not assert
  1716. * RST_OUT as not compatible with some PHYs.
  1717. */
  1718. rc = ipg_reset(dev, IPG_RESET_MASK);
  1719. if (rc < 0)
  1720. goto out;
  1721. ipg_init_mii(dev);
  1722. /* Read MAC Address from EEPROM */
  1723. for (i = 0; i < 3; i++)
  1724. sp->station_addr[i] = read_eeprom(dev, 16 + i);
  1725. for (i = 0; i < 3; i++)
  1726. ipg_w16(sp->station_addr[i], STATION_ADDRESS_0 + 2*i);
  1727. /* Set station address in ethernet_device structure. */
  1728. dev->dev_addr[0] = ipg_r16(STATION_ADDRESS_0) & 0x00ff;
  1729. dev->dev_addr[1] = (ipg_r16(STATION_ADDRESS_0) & 0xff00) >> 8;
  1730. dev->dev_addr[2] = ipg_r16(STATION_ADDRESS_1) & 0x00ff;
  1731. dev->dev_addr[3] = (ipg_r16(STATION_ADDRESS_1) & 0xff00) >> 8;
  1732. dev->dev_addr[4] = ipg_r16(STATION_ADDRESS_2) & 0x00ff;
  1733. dev->dev_addr[5] = (ipg_r16(STATION_ADDRESS_2) & 0xff00) >> 8;
  1734. out:
  1735. return rc;
  1736. }
  1737. static int ipg_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  1738. {
  1739. struct ipg_nic_private *sp = netdev_priv(dev);
  1740. int rc;
  1741. mutex_lock(&sp->mii_mutex);
  1742. rc = generic_mii_ioctl(&sp->mii_if, if_mii(ifr), cmd, NULL);
  1743. mutex_unlock(&sp->mii_mutex);
  1744. return rc;
  1745. }
  1746. static int ipg_nic_change_mtu(struct net_device *dev, int new_mtu)
  1747. {
  1748. /* Function to accomodate changes to Maximum Transfer Unit
  1749. * (or MTU) of IPG NIC. Cannot use default function since
  1750. * the default will not allow for MTU > 1500 bytes.
  1751. */
  1752. IPG_DEBUG_MSG("_nic_change_mtu\n");
  1753. /* Check that the new MTU value is between 68 (14 byte header, 46
  1754. * byte payload, 4 byte FCS) and IPG_MAX_RXFRAME_SIZE, which
  1755. * corresponds to the MAXFRAMESIZE register in the IPG.
  1756. */
  1757. if ((new_mtu < 68) || (new_mtu > IPG_MAX_RXFRAME_SIZE))
  1758. return -EINVAL;
  1759. dev->mtu = new_mtu;
  1760. return 0;
  1761. }
  1762. static int ipg_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  1763. {
  1764. struct ipg_nic_private *sp = netdev_priv(dev);
  1765. int rc;
  1766. mutex_lock(&sp->mii_mutex);
  1767. rc = mii_ethtool_gset(&sp->mii_if, cmd);
  1768. mutex_unlock(&sp->mii_mutex);
  1769. return rc;
  1770. }
  1771. static int ipg_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  1772. {
  1773. struct ipg_nic_private *sp = netdev_priv(dev);
  1774. int rc;
  1775. mutex_lock(&sp->mii_mutex);
  1776. rc = mii_ethtool_sset(&sp->mii_if, cmd);
  1777. mutex_unlock(&sp->mii_mutex);
  1778. return rc;
  1779. }
  1780. static int ipg_nway_reset(struct net_device *dev)
  1781. {
  1782. struct ipg_nic_private *sp = netdev_priv(dev);
  1783. int rc;
  1784. mutex_lock(&sp->mii_mutex);
  1785. rc = mii_nway_restart(&sp->mii_if);
  1786. mutex_unlock(&sp->mii_mutex);
  1787. return rc;
  1788. }
  1789. static struct ethtool_ops ipg_ethtool_ops = {
  1790. .get_settings = ipg_get_settings,
  1791. .set_settings = ipg_set_settings,
  1792. .nway_reset = ipg_nway_reset,
  1793. };
  1794. static void ipg_remove(struct pci_dev *pdev)
  1795. {
  1796. struct net_device *dev = pci_get_drvdata(pdev);
  1797. struct ipg_nic_private *sp = netdev_priv(dev);
  1798. IPG_DEBUG_MSG("_remove\n");
  1799. /* Un-register Ethernet device. */
  1800. unregister_netdev(dev);
  1801. pci_iounmap(pdev, sp->ioaddr);
  1802. pci_release_regions(pdev);
  1803. free_netdev(dev);
  1804. pci_disable_device(pdev);
  1805. pci_set_drvdata(pdev, NULL);
  1806. }
  1807. static int __devinit ipg_probe(struct pci_dev *pdev,
  1808. const struct pci_device_id *id)
  1809. {
  1810. unsigned int i = id->driver_data;
  1811. struct ipg_nic_private *sp;
  1812. struct net_device *dev;
  1813. void __iomem *ioaddr;
  1814. int rc;
  1815. rc = pci_enable_device(pdev);
  1816. if (rc < 0)
  1817. goto out;
  1818. printk(KERN_INFO "%s: %s\n", pci_name(pdev), ipg_brand_name[i]);
  1819. pci_set_master(pdev);
  1820. rc = pci_set_dma_mask(pdev, DMA_40BIT_MASK);
  1821. if (rc < 0) {
  1822. rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  1823. if (rc < 0) {
  1824. printk(KERN_ERR "%s: DMA config failed.\n",
  1825. pci_name(pdev));
  1826. goto err_disable_0;
  1827. }
  1828. }
  1829. /*
  1830. * Initialize net device.
  1831. */
  1832. dev = alloc_etherdev(sizeof(struct ipg_nic_private));
  1833. if (!dev) {
  1834. printk(KERN_ERR "%s: alloc_etherdev failed\n", pci_name(pdev));
  1835. rc = -ENOMEM;
  1836. goto err_disable_0;
  1837. }
  1838. sp = netdev_priv(dev);
  1839. spin_lock_init(&sp->lock);
  1840. mutex_init(&sp->mii_mutex);
  1841. /* Declare IPG NIC functions for Ethernet device methods.
  1842. */
  1843. dev->open = &ipg_nic_open;
  1844. dev->stop = &ipg_nic_stop;
  1845. dev->hard_start_xmit = &ipg_nic_hard_start_xmit;
  1846. dev->get_stats = &ipg_nic_get_stats;
  1847. dev->set_multicast_list = &ipg_nic_set_multicast_list;
  1848. dev->do_ioctl = ipg_ioctl;
  1849. dev->tx_timeout = ipg_tx_timeout;
  1850. dev->change_mtu = &ipg_nic_change_mtu;
  1851. SET_NETDEV_DEV(dev, &pdev->dev);
  1852. SET_ETHTOOL_OPS(dev, &ipg_ethtool_ops);
  1853. rc = pci_request_regions(pdev, DRV_NAME);
  1854. if (rc)
  1855. goto err_free_dev_1;
  1856. ioaddr = pci_iomap(pdev, 1, pci_resource_len(pdev, 1));
  1857. if (!ioaddr) {
  1858. printk(KERN_ERR "%s cannot map MMIO\n", pci_name(pdev));
  1859. rc = -EIO;
  1860. goto err_release_regions_2;
  1861. }
  1862. /* Save the pointer to the PCI device information. */
  1863. sp->ioaddr = ioaddr;
  1864. sp->pdev = pdev;
  1865. sp->dev = dev;
  1866. INIT_DELAYED_WORK(&sp->task, ipg_reset_after_host_error);
  1867. pci_set_drvdata(pdev, dev);
  1868. rc = ipg_hw_init(dev);
  1869. if (rc < 0)
  1870. goto err_unmap_3;
  1871. rc = register_netdev(dev);
  1872. if (rc < 0)
  1873. goto err_unmap_3;
  1874. printk(KERN_INFO "Ethernet device registered as: %s\n", dev->name);
  1875. out:
  1876. return rc;
  1877. err_unmap_3:
  1878. pci_iounmap(pdev, ioaddr);
  1879. err_release_regions_2:
  1880. pci_release_regions(pdev);
  1881. err_free_dev_1:
  1882. free_netdev(dev);
  1883. err_disable_0:
  1884. pci_disable_device(pdev);
  1885. goto out;
  1886. }
  1887. static struct pci_driver ipg_pci_driver = {
  1888. .name = IPG_DRIVER_NAME,
  1889. .id_table = ipg_pci_tbl,
  1890. .probe = ipg_probe,
  1891. .remove = __devexit_p(ipg_remove),
  1892. };
  1893. static int __init ipg_init_module(void)
  1894. {
  1895. return pci_register_driver(&ipg_pci_driver);
  1896. }
  1897. static void __exit ipg_exit_module(void)
  1898. {
  1899. pci_unregister_driver(&ipg_pci_driver);
  1900. }
  1901. module_init(ipg_init_module);
  1902. module_exit(ipg_exit_module);