ipg.c 61 KB

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