ipg.c 61 KB

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