ipg.c 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312
  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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  24. #include <linux/crc32.h>
  25. #include <linux/ethtool.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/gfp.h>
  28. #include <linux/mii.h>
  29. #include <linux/mutex.h>
  30. #include <asm/div64.h>
  31. #define IPG_RX_RING_BYTES (sizeof(struct ipg_rx) * IPG_RFDLIST_LENGTH)
  32. #define IPG_TX_RING_BYTES (sizeof(struct ipg_tx) * IPG_TFDLIST_LENGTH)
  33. #define IPG_RESET_MASK \
  34. (IPG_AC_GLOBAL_RESET | IPG_AC_RX_RESET | IPG_AC_TX_RESET | \
  35. IPG_AC_DMA | IPG_AC_FIFO | IPG_AC_NETWORK | IPG_AC_HOST | \
  36. IPG_AC_AUTO_INIT)
  37. #define ipg_w32(val32, reg) iowrite32((val32), ioaddr + (reg))
  38. #define ipg_w16(val16, reg) iowrite16((val16), ioaddr + (reg))
  39. #define ipg_w8(val8, reg) iowrite8((val8), ioaddr + (reg))
  40. #define ipg_r32(reg) ioread32(ioaddr + (reg))
  41. #define ipg_r16(reg) ioread16(ioaddr + (reg))
  42. #define ipg_r8(reg) ioread8(ioaddr + (reg))
  43. enum {
  44. netdev_io_size = 128
  45. };
  46. #include "ipg.h"
  47. #define DRV_NAME "ipg"
  48. MODULE_AUTHOR("IC Plus Corp. 2003");
  49. MODULE_DESCRIPTION("IC Plus IP1000 Gigabit Ethernet Adapter Linux Driver");
  50. MODULE_LICENSE("GPL");
  51. /*
  52. * Defaults
  53. */
  54. #define IPG_MAX_RXFRAME_SIZE 0x0600
  55. #define IPG_RXFRAG_SIZE 0x0600
  56. #define IPG_RXSUPPORT_SIZE 0x0600
  57. #define IPG_IS_JUMBO false
  58. /*
  59. * Variable record -- index by leading revision/length
  60. * Revision/Length(=N*4), Address1, Data1, Address2, Data2,...,AddressN,DataN
  61. */
  62. static const unsigned short DefaultPhyParam[] = {
  63. /* 11/12/03 IP1000A v1-3 rev=0x40 */
  64. /*--------------------------------------------------------------------------
  65. (0x4000|(15*4)), 31, 0x0001, 27, 0x01e0, 31, 0x0002, 22, 0x85bd, 24, 0xfff2,
  66. 27, 0x0c10, 28, 0x0c10, 29, 0x2c10, 31, 0x0003, 23, 0x92f6,
  67. 31, 0x0000, 23, 0x003d, 30, 0x00de, 20, 0x20e7, 9, 0x0700,
  68. --------------------------------------------------------------------------*/
  69. /* 12/17/03 IP1000A v1-4 rev=0x40 */
  70. (0x4000 | (07 * 4)), 31, 0x0001, 27, 0x01e0, 31, 0x0002, 27, 0xeb8e, 31,
  71. 0x0000,
  72. 30, 0x005e, 9, 0x0700,
  73. /* 01/09/04 IP1000A v1-5 rev=0x41 */
  74. (0x4100 | (07 * 4)), 31, 0x0001, 27, 0x01e0, 31, 0x0002, 27, 0xeb8e, 31,
  75. 0x0000,
  76. 30, 0x005e, 9, 0x0700,
  77. 0x0000
  78. };
  79. static const char * const ipg_brand_name[] = {
  80. "IC PLUS IP1000 1000/100/10 based NIC",
  81. "Sundance Technology ST2021 based NIC",
  82. "Tamarack Microelectronics TC9020/9021 based NIC",
  83. "D-Link NIC IP1000A"
  84. };
  85. static DEFINE_PCI_DEVICE_TABLE(ipg_pci_tbl) = {
  86. { PCI_VDEVICE(SUNDANCE, 0x1023), 0 },
  87. { PCI_VDEVICE(SUNDANCE, 0x2021), 1 },
  88. { PCI_VDEVICE(DLINK, 0x9021), 2 },
  89. { PCI_VDEVICE(DLINK, 0x4020), 3 },
  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. netdev_info(dev, "rx_current = %02x\n", sp->rx_current);
  107. netdev_info(dev, "rx_dirty = %02x\n", sp->rx_dirty);
  108. netdev_info(dev, "RFDList start address = %016lx\n",
  109. (unsigned long)sp->rxd_map);
  110. netdev_info(dev, "RFDListPtr register = %08x%08x\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. netdev_info(dev, "%02x %04x RFDNextPtr = %016lx\n",
  115. i, offset, (unsigned long)sp->rxd[i].next_desc);
  116. offset = (u32) &sp->rxd[i].rfs - (u32) sp->rxd;
  117. netdev_info(dev, "%02x %04x RFS = %016lx\n",
  118. i, offset, (unsigned long)sp->rxd[i].rfs);
  119. offset = (u32) &sp->rxd[i].frag_info - (u32) sp->rxd;
  120. netdev_info(dev, "%02x %04x frag_info = %016lx\n",
  121. i, 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. netdev_info(dev, "tx_current = %02x\n", sp->tx_current);
  132. netdev_info(dev, "tx_dirty = %02x\n", sp->tx_dirty);
  133. netdev_info(dev, "TFDList start address = %016lx\n",
  134. (unsigned long) sp->txd_map);
  135. netdev_info(dev, "TFDListPtr register = %08x%08x\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. netdev_info(dev, "%02x %04x TFDNextPtr = %016lx\n",
  140. i, offset, (unsigned long)sp->txd[i].next_desc);
  141. offset = (u32) &sp->txd[i].tfc - (u32) sp->txd;
  142. netdev_info(dev, "%02x %04x TFC = %016lx\n",
  143. i, offset, (unsigned long) sp->txd[i].tfc);
  144. offset = (u32) &sp->txd[i].frag_info - (u32) sp->txd;
  145. netdev_info(dev, "%02x %04x frag_info = %016lx\n",
  146. i, 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. ipg_write_phy_ctl(ioaddr, IPG_PC_MGMTCLK_LO | polarity);
  327. ipg_r8(PHY_CTRL);
  328. ipg_write_phy_ctl(ioaddr, IPG_PC_MGMTCLK_HI | polarity);
  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. const char *speed;
  410. const char *duplex;
  411. const char *tx_desc;
  412. const char *rx_desc;
  413. IPG_DEBUG_MSG("_config_autoneg\n");
  414. asicctrl = ipg_r32(ASIC_CTRL);
  415. phyctrl = ipg_r8(PHY_CTRL);
  416. mac_ctrl_val = ipg_r32(MAC_CTRL);
  417. /* Set flags for use in resolving auto-negotiation, assuming
  418. * non-1000Mbps, half duplex, no flow control.
  419. */
  420. fullduplex = 0;
  421. txflowcontrol = 0;
  422. rxflowcontrol = 0;
  423. /* To accommodate a problem in 10Mbps operation,
  424. * set a global flag if PHY running in 10Mbps mode.
  425. */
  426. sp->tenmbpsmode = 0;
  427. /* Determine actual speed of operation. */
  428. switch (phyctrl & IPG_PC_LINK_SPEED) {
  429. case IPG_PC_LINK_SPEED_10MBPS:
  430. speed = "10Mbps";
  431. sp->tenmbpsmode = 1;
  432. break;
  433. case IPG_PC_LINK_SPEED_100MBPS:
  434. speed = "100Mbps";
  435. break;
  436. case IPG_PC_LINK_SPEED_1000MBPS:
  437. speed = "1000Mbps";
  438. break;
  439. default:
  440. speed = "undefined!";
  441. return 0;
  442. }
  443. netdev_info(dev, "Link speed = %s\n", speed);
  444. if (sp->tenmbpsmode == 1)
  445. netdev_info(dev, "10Mbps operational mode enabled\n");
  446. if (phyctrl & IPG_PC_DUPLEX_STATUS) {
  447. fullduplex = 1;
  448. txflowcontrol = 1;
  449. rxflowcontrol = 1;
  450. }
  451. /* Configure full duplex, and flow control. */
  452. if (fullduplex == 1) {
  453. /* Configure IPG for full duplex operation. */
  454. duplex = "full";
  455. mac_ctrl_val |= IPG_MC_DUPLEX_SELECT_FD;
  456. if (txflowcontrol == 1) {
  457. tx_desc = "";
  458. mac_ctrl_val |= IPG_MC_TX_FLOW_CONTROL_ENABLE;
  459. } else {
  460. tx_desc = "no ";
  461. mac_ctrl_val &= ~IPG_MC_TX_FLOW_CONTROL_ENABLE;
  462. }
  463. if (rxflowcontrol == 1) {
  464. rx_desc = "";
  465. mac_ctrl_val |= IPG_MC_RX_FLOW_CONTROL_ENABLE;
  466. } else {
  467. rx_desc = "no ";
  468. mac_ctrl_val &= ~IPG_MC_RX_FLOW_CONTROL_ENABLE;
  469. }
  470. } else {
  471. duplex = "half";
  472. tx_desc = "no ";
  473. rx_desc = "no ";
  474. mac_ctrl_val &= (~IPG_MC_DUPLEX_SELECT_FD &
  475. ~IPG_MC_TX_FLOW_CONTROL_ENABLE &
  476. ~IPG_MC_RX_FLOW_CONTROL_ENABLE);
  477. }
  478. netdev_info(dev, "setting %s duplex, %sTX, %sRX flow control\n",
  479. duplex, tx_desc, rx_desc);
  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 netdev_hw_addr *ha;
  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(ha, dev) {
  523. /* Calculate CRC result for each multicast address. */
  524. hashindex = crc32_le(0xffffffff, ha->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. /* Save the address of the sk_buff structure. */
  628. sp->rx_buff[entry] = skb;
  629. rxfd->frag_info = cpu_to_le64(pci_map_single(sp->pdev, skb->data,
  630. sp->rx_buf_sz, PCI_DMA_FROMDEVICE));
  631. /* Set the RFD fragment length. */
  632. rxfragsize = sp->rxfrag_size;
  633. rxfd->frag_info |= cpu_to_le64((rxfragsize << 48) & IPG_RFI_FRAGLEN);
  634. return 0;
  635. }
  636. static int init_rfdlist(struct net_device *dev)
  637. {
  638. struct ipg_nic_private *sp = netdev_priv(dev);
  639. void __iomem *ioaddr = sp->ioaddr;
  640. unsigned int i;
  641. IPG_DEBUG_MSG("_init_rfdlist\n");
  642. for (i = 0; i < IPG_RFDLIST_LENGTH; i++) {
  643. struct ipg_rx *rxfd = sp->rxd + i;
  644. if (sp->rx_buff[i]) {
  645. pci_unmap_single(sp->pdev,
  646. le64_to_cpu(rxfd->frag_info) & ~IPG_RFI_FRAGLEN,
  647. sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
  648. dev_kfree_skb_irq(sp->rx_buff[i]);
  649. sp->rx_buff[i] = NULL;
  650. }
  651. /* Clear out the RFS field. */
  652. rxfd->rfs = 0x0000000000000000;
  653. if (ipg_get_rxbuff(dev, i) < 0) {
  654. /*
  655. * A receive buffer was not ready, break the
  656. * RFD list here.
  657. */
  658. IPG_DEBUG_MSG("Cannot allocate Rx buffer\n");
  659. /* Just in case we cannot allocate a single RFD.
  660. * Should not occur.
  661. */
  662. if (i == 0) {
  663. netdev_err(dev, "No memory available for RFD list\n");
  664. return -ENOMEM;
  665. }
  666. }
  667. rxfd->next_desc = cpu_to_le64(sp->rxd_map +
  668. sizeof(struct ipg_rx)*(i + 1));
  669. }
  670. sp->rxd[i - 1].next_desc = cpu_to_le64(sp->rxd_map);
  671. sp->rx_current = 0;
  672. sp->rx_dirty = 0;
  673. /* Write the location of the RFDList to the IPG. */
  674. ipg_w32((u32) sp->rxd_map, RFD_LIST_PTR_0);
  675. ipg_w32(0x00000000, RFD_LIST_PTR_1);
  676. return 0;
  677. }
  678. static void init_tfdlist(struct net_device *dev)
  679. {
  680. struct ipg_nic_private *sp = netdev_priv(dev);
  681. void __iomem *ioaddr = sp->ioaddr;
  682. unsigned int i;
  683. IPG_DEBUG_MSG("_init_tfdlist\n");
  684. for (i = 0; i < IPG_TFDLIST_LENGTH; i++) {
  685. struct ipg_tx *txfd = sp->txd + i;
  686. txfd->tfc = cpu_to_le64(IPG_TFC_TFDDONE);
  687. if (sp->tx_buff[i]) {
  688. dev_kfree_skb_irq(sp->tx_buff[i]);
  689. sp->tx_buff[i] = NULL;
  690. }
  691. txfd->next_desc = cpu_to_le64(sp->txd_map +
  692. sizeof(struct ipg_tx)*(i + 1));
  693. }
  694. sp->txd[i - 1].next_desc = cpu_to_le64(sp->txd_map);
  695. sp->tx_current = 0;
  696. sp->tx_dirty = 0;
  697. /* Write the location of the TFDList to the IPG. */
  698. IPG_DDEBUG_MSG("Starting TFDListPtr = %08x\n",
  699. (u32) sp->txd_map);
  700. ipg_w32((u32) sp->txd_map, TFD_LIST_PTR_0);
  701. ipg_w32(0x00000000, TFD_LIST_PTR_1);
  702. sp->reset_current_tfd = 1;
  703. }
  704. /*
  705. * Free all transmit buffers which have already been transferred
  706. * via DMA to the IPG.
  707. */
  708. static void ipg_nic_txfree(struct net_device *dev)
  709. {
  710. struct ipg_nic_private *sp = netdev_priv(dev);
  711. unsigned int released, pending, dirty;
  712. IPG_DEBUG_MSG("_nic_txfree\n");
  713. pending = sp->tx_current - sp->tx_dirty;
  714. dirty = sp->tx_dirty % IPG_TFDLIST_LENGTH;
  715. for (released = 0; released < pending; released++) {
  716. struct sk_buff *skb = sp->tx_buff[dirty];
  717. struct ipg_tx *txfd = sp->txd + dirty;
  718. IPG_DEBUG_MSG("TFC = %016lx\n", (unsigned long) txfd->tfc);
  719. /* Look at each TFD's TFC field beginning
  720. * at the last freed TFD up to the current TFD.
  721. * If the TFDDone bit is set, free the associated
  722. * buffer.
  723. */
  724. if (!(txfd->tfc & cpu_to_le64(IPG_TFC_TFDDONE)))
  725. break;
  726. /* Free the transmit buffer. */
  727. if (skb) {
  728. pci_unmap_single(sp->pdev,
  729. le64_to_cpu(txfd->frag_info) & ~IPG_TFI_FRAGLEN,
  730. skb->len, PCI_DMA_TODEVICE);
  731. dev_kfree_skb_irq(skb);
  732. sp->tx_buff[dirty] = NULL;
  733. }
  734. dirty = (dirty + 1) % IPG_TFDLIST_LENGTH;
  735. }
  736. sp->tx_dirty += released;
  737. if (netif_queue_stopped(dev) &&
  738. (sp->tx_current != (sp->tx_dirty + IPG_TFDLIST_LENGTH))) {
  739. netif_wake_queue(dev);
  740. }
  741. }
  742. static void ipg_tx_timeout(struct net_device *dev)
  743. {
  744. struct ipg_nic_private *sp = netdev_priv(dev);
  745. void __iomem *ioaddr = sp->ioaddr;
  746. ipg_reset(dev, IPG_AC_TX_RESET | IPG_AC_DMA | IPG_AC_NETWORK |
  747. IPG_AC_FIFO);
  748. spin_lock_irq(&sp->lock);
  749. /* Re-configure after DMA reset. */
  750. if (ipg_io_config(dev) < 0)
  751. netdev_info(dev, "Error during re-configuration\n");
  752. init_tfdlist(dev);
  753. spin_unlock_irq(&sp->lock);
  754. ipg_w32((ipg_r32(MAC_CTRL) | IPG_MC_TX_ENABLE) & IPG_MC_RSVD_MASK,
  755. MAC_CTRL);
  756. }
  757. /*
  758. * For TxComplete interrupts, free all transmit
  759. * buffers which have already been transferred via DMA
  760. * to the IPG.
  761. */
  762. static void ipg_nic_txcleanup(struct net_device *dev)
  763. {
  764. struct ipg_nic_private *sp = netdev_priv(dev);
  765. void __iomem *ioaddr = sp->ioaddr;
  766. unsigned int i;
  767. IPG_DEBUG_MSG("_nic_txcleanup\n");
  768. for (i = 0; i < IPG_TFDLIST_LENGTH; i++) {
  769. /* Reading the TXSTATUS register clears the
  770. * TX_COMPLETE interrupt.
  771. */
  772. u32 txstatusdword = ipg_r32(TX_STATUS);
  773. IPG_DEBUG_MSG("TxStatus = %08x\n", txstatusdword);
  774. /* Check for Transmit errors. Error bits only valid if
  775. * TX_COMPLETE bit in the TXSTATUS register is a 1.
  776. */
  777. if (!(txstatusdword & IPG_TS_TX_COMPLETE))
  778. break;
  779. /* If in 10Mbps mode, indicate transmit is ready. */
  780. if (sp->tenmbpsmode) {
  781. netif_wake_queue(dev);
  782. }
  783. /* Transmit error, increment stat counters. */
  784. if (txstatusdword & IPG_TS_TX_ERROR) {
  785. IPG_DEBUG_MSG("Transmit error\n");
  786. sp->stats.tx_errors++;
  787. }
  788. /* Late collision, re-enable transmitter. */
  789. if (txstatusdword & IPG_TS_LATE_COLLISION) {
  790. IPG_DEBUG_MSG("Late collision on transmit\n");
  791. ipg_w32((ipg_r32(MAC_CTRL) | IPG_MC_TX_ENABLE) &
  792. IPG_MC_RSVD_MASK, MAC_CTRL);
  793. }
  794. /* Maximum collisions, re-enable transmitter. */
  795. if (txstatusdword & IPG_TS_TX_MAX_COLL) {
  796. IPG_DEBUG_MSG("Maximum collisions on transmit\n");
  797. ipg_w32((ipg_r32(MAC_CTRL) | IPG_MC_TX_ENABLE) &
  798. IPG_MC_RSVD_MASK, MAC_CTRL);
  799. }
  800. /* Transmit underrun, reset and re-enable
  801. * transmitter.
  802. */
  803. if (txstatusdword & IPG_TS_TX_UNDERRUN) {
  804. IPG_DEBUG_MSG("Transmitter underrun\n");
  805. sp->stats.tx_fifo_errors++;
  806. ipg_reset(dev, IPG_AC_TX_RESET | IPG_AC_DMA |
  807. IPG_AC_NETWORK | IPG_AC_FIFO);
  808. /* Re-configure after DMA reset. */
  809. if (ipg_io_config(dev) < 0) {
  810. netdev_info(dev, "Error during re-configuration\n");
  811. }
  812. init_tfdlist(dev);
  813. ipg_w32((ipg_r32(MAC_CTRL) | IPG_MC_TX_ENABLE) &
  814. IPG_MC_RSVD_MASK, MAC_CTRL);
  815. }
  816. }
  817. ipg_nic_txfree(dev);
  818. }
  819. /* Provides statistical information about the IPG NIC. */
  820. static struct net_device_stats *ipg_nic_get_stats(struct net_device *dev)
  821. {
  822. struct ipg_nic_private *sp = netdev_priv(dev);
  823. void __iomem *ioaddr = sp->ioaddr;
  824. u16 temp1;
  825. u16 temp2;
  826. IPG_DEBUG_MSG("_nic_get_stats\n");
  827. /* Check to see if the NIC has been initialized via nic_open,
  828. * before trying to read statistic registers.
  829. */
  830. if (!test_bit(__LINK_STATE_START, &dev->state))
  831. return &sp->stats;
  832. sp->stats.rx_packets += ipg_r32(IPG_FRAMESRCVDOK);
  833. sp->stats.tx_packets += ipg_r32(IPG_FRAMESXMTDOK);
  834. sp->stats.rx_bytes += ipg_r32(IPG_OCTETRCVOK);
  835. sp->stats.tx_bytes += ipg_r32(IPG_OCTETXMTOK);
  836. temp1 = ipg_r16(IPG_FRAMESLOSTRXERRORS);
  837. sp->stats.rx_errors += temp1;
  838. sp->stats.rx_missed_errors += temp1;
  839. temp1 = ipg_r32(IPG_SINGLECOLFRAMES) + ipg_r32(IPG_MULTICOLFRAMES) +
  840. ipg_r32(IPG_LATECOLLISIONS);
  841. temp2 = ipg_r16(IPG_CARRIERSENSEERRORS);
  842. sp->stats.collisions += temp1;
  843. sp->stats.tx_dropped += ipg_r16(IPG_FRAMESABORTXSCOLLS);
  844. sp->stats.tx_errors += ipg_r16(IPG_FRAMESWEXDEFERRAL) +
  845. ipg_r32(IPG_FRAMESWDEFERREDXMT) + temp1 + temp2;
  846. sp->stats.multicast += ipg_r32(IPG_MCSTOCTETRCVDOK);
  847. /* detailed tx_errors */
  848. sp->stats.tx_carrier_errors += temp2;
  849. /* detailed rx_errors */
  850. sp->stats.rx_length_errors += ipg_r16(IPG_INRANGELENGTHERRORS) +
  851. ipg_r16(IPG_FRAMETOOLONGERRRORS);
  852. sp->stats.rx_crc_errors += ipg_r16(IPG_FRAMECHECKSEQERRORS);
  853. /* Unutilized IPG statistic registers. */
  854. ipg_r32(IPG_MCSTFRAMESRCVDOK);
  855. return &sp->stats;
  856. }
  857. /* Restore used receive buffers. */
  858. static int ipg_nic_rxrestore(struct net_device *dev)
  859. {
  860. struct ipg_nic_private *sp = netdev_priv(dev);
  861. const unsigned int curr = sp->rx_current;
  862. unsigned int dirty = sp->rx_dirty;
  863. IPG_DEBUG_MSG("_nic_rxrestore\n");
  864. for (dirty = sp->rx_dirty; curr - dirty > 0; dirty++) {
  865. unsigned int entry = dirty % IPG_RFDLIST_LENGTH;
  866. /* rx_copybreak may poke hole here and there. */
  867. if (sp->rx_buff[entry])
  868. continue;
  869. /* Generate a new receive buffer to replace the
  870. * current buffer (which will be released by the
  871. * Linux system).
  872. */
  873. if (ipg_get_rxbuff(dev, entry) < 0) {
  874. IPG_DEBUG_MSG("Cannot allocate new Rx buffer\n");
  875. break;
  876. }
  877. /* Reset the RFS field. */
  878. sp->rxd[entry].rfs = 0x0000000000000000;
  879. }
  880. sp->rx_dirty = dirty;
  881. return 0;
  882. }
  883. /* use jumboindex and jumbosize to control jumbo frame status
  884. * initial status is jumboindex=-1 and jumbosize=0
  885. * 1. jumboindex = -1 and jumbosize=0 : previous jumbo frame has been done.
  886. * 2. jumboindex != -1 and jumbosize != 0 : jumbo frame is not over size and receiving
  887. * 3. jumboindex = -1 and jumbosize != 0 : jumbo frame is over size, already dump
  888. * previous receiving and need to continue dumping the current one
  889. */
  890. enum {
  891. NORMAL_PACKET,
  892. ERROR_PACKET
  893. };
  894. enum {
  895. FRAME_NO_START_NO_END = 0,
  896. FRAME_WITH_START = 1,
  897. FRAME_WITH_END = 10,
  898. FRAME_WITH_START_WITH_END = 11
  899. };
  900. static void ipg_nic_rx_free_skb(struct net_device *dev)
  901. {
  902. struct ipg_nic_private *sp = netdev_priv(dev);
  903. unsigned int entry = sp->rx_current % IPG_RFDLIST_LENGTH;
  904. if (sp->rx_buff[entry]) {
  905. struct ipg_rx *rxfd = sp->rxd + entry;
  906. pci_unmap_single(sp->pdev,
  907. le64_to_cpu(rxfd->frag_info) & ~IPG_RFI_FRAGLEN,
  908. sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
  909. dev_kfree_skb_irq(sp->rx_buff[entry]);
  910. sp->rx_buff[entry] = NULL;
  911. }
  912. }
  913. static int ipg_nic_rx_check_frame_type(struct net_device *dev)
  914. {
  915. struct ipg_nic_private *sp = netdev_priv(dev);
  916. struct ipg_rx *rxfd = sp->rxd + (sp->rx_current % IPG_RFDLIST_LENGTH);
  917. int type = FRAME_NO_START_NO_END;
  918. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_FRAMESTART)
  919. type += FRAME_WITH_START;
  920. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_FRAMEEND)
  921. type += FRAME_WITH_END;
  922. return type;
  923. }
  924. static int ipg_nic_rx_check_error(struct net_device *dev)
  925. {
  926. struct ipg_nic_private *sp = netdev_priv(dev);
  927. unsigned int entry = sp->rx_current % IPG_RFDLIST_LENGTH;
  928. struct ipg_rx *rxfd = sp->rxd + entry;
  929. if (IPG_DROP_ON_RX_ETH_ERRORS && (le64_to_cpu(rxfd->rfs) &
  930. (IPG_RFS_RXFIFOOVERRUN | IPG_RFS_RXRUNTFRAME |
  931. IPG_RFS_RXALIGNMENTERROR | IPG_RFS_RXFCSERROR |
  932. IPG_RFS_RXOVERSIZEDFRAME | IPG_RFS_RXLENGTHERROR))) {
  933. IPG_DEBUG_MSG("Rx error, RFS = %016lx\n",
  934. (unsigned long) rxfd->rfs);
  935. /* Increment general receive error statistic. */
  936. sp->stats.rx_errors++;
  937. /* Increment detailed receive error statistics. */
  938. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFIFOOVERRUN) {
  939. IPG_DEBUG_MSG("RX FIFO overrun occurred\n");
  940. sp->stats.rx_fifo_errors++;
  941. }
  942. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXRUNTFRAME) {
  943. IPG_DEBUG_MSG("RX runt occurred\n");
  944. sp->stats.rx_length_errors++;
  945. }
  946. /* Do nothing for IPG_RFS_RXOVERSIZEDFRAME,
  947. * error count handled by a IPG statistic register.
  948. */
  949. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXALIGNMENTERROR) {
  950. IPG_DEBUG_MSG("RX alignment error occurred\n");
  951. sp->stats.rx_frame_errors++;
  952. }
  953. /* Do nothing for IPG_RFS_RXFCSERROR, error count
  954. * handled by a IPG statistic register.
  955. */
  956. /* Free the memory associated with the RX
  957. * buffer since it is erroneous and we will
  958. * not pass it to higher layer processes.
  959. */
  960. if (sp->rx_buff[entry]) {
  961. pci_unmap_single(sp->pdev,
  962. le64_to_cpu(rxfd->frag_info) & ~IPG_RFI_FRAGLEN,
  963. sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
  964. dev_kfree_skb_irq(sp->rx_buff[entry]);
  965. sp->rx_buff[entry] = NULL;
  966. }
  967. return ERROR_PACKET;
  968. }
  969. return NORMAL_PACKET;
  970. }
  971. static void ipg_nic_rx_with_start_and_end(struct net_device *dev,
  972. struct ipg_nic_private *sp,
  973. struct ipg_rx *rxfd, unsigned entry)
  974. {
  975. struct ipg_jumbo *jumbo = &sp->jumbo;
  976. struct sk_buff *skb;
  977. int framelen;
  978. if (jumbo->found_start) {
  979. dev_kfree_skb_irq(jumbo->skb);
  980. jumbo->found_start = 0;
  981. jumbo->current_size = 0;
  982. jumbo->skb = NULL;
  983. }
  984. /* 1: found error, 0 no error */
  985. if (ipg_nic_rx_check_error(dev) != NORMAL_PACKET)
  986. return;
  987. skb = sp->rx_buff[entry];
  988. if (!skb)
  989. return;
  990. /* accept this frame and send to upper layer */
  991. framelen = le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFRAMELEN;
  992. if (framelen > sp->rxfrag_size)
  993. framelen = sp->rxfrag_size;
  994. skb_put(skb, framelen);
  995. skb->protocol = eth_type_trans(skb, dev);
  996. skb_checksum_none_assert(skb);
  997. netif_rx(skb);
  998. sp->rx_buff[entry] = NULL;
  999. }
  1000. static void ipg_nic_rx_with_start(struct net_device *dev,
  1001. struct ipg_nic_private *sp,
  1002. struct ipg_rx *rxfd, unsigned entry)
  1003. {
  1004. struct ipg_jumbo *jumbo = &sp->jumbo;
  1005. struct pci_dev *pdev = sp->pdev;
  1006. struct sk_buff *skb;
  1007. /* 1: found error, 0 no error */
  1008. if (ipg_nic_rx_check_error(dev) != NORMAL_PACKET)
  1009. return;
  1010. /* accept this frame and send to upper layer */
  1011. skb = sp->rx_buff[entry];
  1012. if (!skb)
  1013. return;
  1014. if (jumbo->found_start)
  1015. dev_kfree_skb_irq(jumbo->skb);
  1016. pci_unmap_single(pdev, le64_to_cpu(rxfd->frag_info) & ~IPG_RFI_FRAGLEN,
  1017. sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
  1018. skb_put(skb, sp->rxfrag_size);
  1019. jumbo->found_start = 1;
  1020. jumbo->current_size = sp->rxfrag_size;
  1021. jumbo->skb = skb;
  1022. sp->rx_buff[entry] = NULL;
  1023. }
  1024. static void ipg_nic_rx_with_end(struct net_device *dev,
  1025. struct ipg_nic_private *sp,
  1026. struct ipg_rx *rxfd, unsigned entry)
  1027. {
  1028. struct ipg_jumbo *jumbo = &sp->jumbo;
  1029. /* 1: found error, 0 no error */
  1030. if (ipg_nic_rx_check_error(dev) == NORMAL_PACKET) {
  1031. struct sk_buff *skb = sp->rx_buff[entry];
  1032. if (!skb)
  1033. return;
  1034. if (jumbo->found_start) {
  1035. int framelen, endframelen;
  1036. framelen = le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFRAMELEN;
  1037. endframelen = framelen - jumbo->current_size;
  1038. if (framelen > sp->rxsupport_size)
  1039. dev_kfree_skb_irq(jumbo->skb);
  1040. else {
  1041. memcpy(skb_put(jumbo->skb, endframelen),
  1042. skb->data, endframelen);
  1043. jumbo->skb->protocol =
  1044. eth_type_trans(jumbo->skb, dev);
  1045. skb_checksum_none_assert(jumbo->skb);
  1046. netif_rx(jumbo->skb);
  1047. }
  1048. }
  1049. jumbo->found_start = 0;
  1050. jumbo->current_size = 0;
  1051. jumbo->skb = NULL;
  1052. ipg_nic_rx_free_skb(dev);
  1053. } else {
  1054. dev_kfree_skb_irq(jumbo->skb);
  1055. jumbo->found_start = 0;
  1056. jumbo->current_size = 0;
  1057. jumbo->skb = NULL;
  1058. }
  1059. }
  1060. static void ipg_nic_rx_no_start_no_end(struct net_device *dev,
  1061. struct ipg_nic_private *sp,
  1062. struct ipg_rx *rxfd, unsigned entry)
  1063. {
  1064. struct ipg_jumbo *jumbo = &sp->jumbo;
  1065. /* 1: found error, 0 no error */
  1066. if (ipg_nic_rx_check_error(dev) == NORMAL_PACKET) {
  1067. struct sk_buff *skb = sp->rx_buff[entry];
  1068. if (skb) {
  1069. if (jumbo->found_start) {
  1070. jumbo->current_size += sp->rxfrag_size;
  1071. if (jumbo->current_size <= sp->rxsupport_size) {
  1072. memcpy(skb_put(jumbo->skb,
  1073. sp->rxfrag_size),
  1074. skb->data, sp->rxfrag_size);
  1075. }
  1076. }
  1077. ipg_nic_rx_free_skb(dev);
  1078. }
  1079. } else {
  1080. dev_kfree_skb_irq(jumbo->skb);
  1081. jumbo->found_start = 0;
  1082. jumbo->current_size = 0;
  1083. jumbo->skb = NULL;
  1084. }
  1085. }
  1086. static int ipg_nic_rx_jumbo(struct net_device *dev)
  1087. {
  1088. struct ipg_nic_private *sp = netdev_priv(dev);
  1089. unsigned int curr = sp->rx_current;
  1090. void __iomem *ioaddr = sp->ioaddr;
  1091. unsigned int i;
  1092. IPG_DEBUG_MSG("_nic_rx\n");
  1093. for (i = 0; i < IPG_MAXRFDPROCESS_COUNT; i++, curr++) {
  1094. unsigned int entry = curr % IPG_RFDLIST_LENGTH;
  1095. struct ipg_rx *rxfd = sp->rxd + entry;
  1096. if (!(rxfd->rfs & cpu_to_le64(IPG_RFS_RFDDONE)))
  1097. break;
  1098. switch (ipg_nic_rx_check_frame_type(dev)) {
  1099. case FRAME_WITH_START_WITH_END:
  1100. ipg_nic_rx_with_start_and_end(dev, sp, rxfd, entry);
  1101. break;
  1102. case FRAME_WITH_START:
  1103. ipg_nic_rx_with_start(dev, sp, rxfd, entry);
  1104. break;
  1105. case FRAME_WITH_END:
  1106. ipg_nic_rx_with_end(dev, sp, rxfd, entry);
  1107. break;
  1108. case FRAME_NO_START_NO_END:
  1109. ipg_nic_rx_no_start_no_end(dev, sp, rxfd, entry);
  1110. break;
  1111. }
  1112. }
  1113. sp->rx_current = curr;
  1114. if (i == IPG_MAXRFDPROCESS_COUNT) {
  1115. /* There are more RFDs to process, however the
  1116. * allocated amount of RFD processing time has
  1117. * expired. Assert Interrupt Requested to make
  1118. * sure we come back to process the remaining RFDs.
  1119. */
  1120. ipg_w32(ipg_r32(ASIC_CTRL) | IPG_AC_INT_REQUEST, ASIC_CTRL);
  1121. }
  1122. ipg_nic_rxrestore(dev);
  1123. return 0;
  1124. }
  1125. static int ipg_nic_rx(struct net_device *dev)
  1126. {
  1127. /* Transfer received Ethernet frames to higher network layers. */
  1128. struct ipg_nic_private *sp = netdev_priv(dev);
  1129. unsigned int curr = sp->rx_current;
  1130. void __iomem *ioaddr = sp->ioaddr;
  1131. struct ipg_rx *rxfd;
  1132. unsigned int i;
  1133. IPG_DEBUG_MSG("_nic_rx\n");
  1134. #define __RFS_MASK \
  1135. cpu_to_le64(IPG_RFS_RFDDONE | IPG_RFS_FRAMESTART | IPG_RFS_FRAMEEND)
  1136. for (i = 0; i < IPG_MAXRFDPROCESS_COUNT; i++, curr++) {
  1137. unsigned int entry = curr % IPG_RFDLIST_LENGTH;
  1138. struct sk_buff *skb = sp->rx_buff[entry];
  1139. unsigned int framelen;
  1140. rxfd = sp->rxd + entry;
  1141. if (((rxfd->rfs & __RFS_MASK) != __RFS_MASK) || !skb)
  1142. break;
  1143. /* Get received frame length. */
  1144. framelen = le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFRAMELEN;
  1145. /* Check for jumbo frame arrival with too small
  1146. * RXFRAG_SIZE.
  1147. */
  1148. if (framelen > sp->rxfrag_size) {
  1149. IPG_DEBUG_MSG
  1150. ("RFS FrameLen > allocated fragment size\n");
  1151. framelen = sp->rxfrag_size;
  1152. }
  1153. if ((IPG_DROP_ON_RX_ETH_ERRORS && (le64_to_cpu(rxfd->rfs) &
  1154. (IPG_RFS_RXFIFOOVERRUN | IPG_RFS_RXRUNTFRAME |
  1155. IPG_RFS_RXALIGNMENTERROR | IPG_RFS_RXFCSERROR |
  1156. IPG_RFS_RXOVERSIZEDFRAME | IPG_RFS_RXLENGTHERROR)))) {
  1157. IPG_DEBUG_MSG("Rx error, RFS = %016lx\n",
  1158. (unsigned long int) rxfd->rfs);
  1159. /* Increment general receive error statistic. */
  1160. sp->stats.rx_errors++;
  1161. /* Increment detailed receive error statistics. */
  1162. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFIFOOVERRUN) {
  1163. IPG_DEBUG_MSG("RX FIFO overrun occurred\n");
  1164. sp->stats.rx_fifo_errors++;
  1165. }
  1166. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXRUNTFRAME) {
  1167. IPG_DEBUG_MSG("RX runt occurred\n");
  1168. sp->stats.rx_length_errors++;
  1169. }
  1170. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXOVERSIZEDFRAME) ;
  1171. /* Do nothing, error count handled by a IPG
  1172. * statistic register.
  1173. */
  1174. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXALIGNMENTERROR) {
  1175. IPG_DEBUG_MSG("RX alignment error occurred\n");
  1176. sp->stats.rx_frame_errors++;
  1177. }
  1178. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFCSERROR) ;
  1179. /* Do nothing, error count handled by a IPG
  1180. * statistic register.
  1181. */
  1182. /* Free the memory associated with the RX
  1183. * buffer since it is erroneous and we will
  1184. * not pass it to higher layer processes.
  1185. */
  1186. if (skb) {
  1187. __le64 info = rxfd->frag_info;
  1188. pci_unmap_single(sp->pdev,
  1189. le64_to_cpu(info) & ~IPG_RFI_FRAGLEN,
  1190. sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
  1191. dev_kfree_skb_irq(skb);
  1192. }
  1193. } else {
  1194. /* Adjust the new buffer length to accommodate the size
  1195. * of the received frame.
  1196. */
  1197. skb_put(skb, framelen);
  1198. /* Set the buffer's protocol field to Ethernet. */
  1199. skb->protocol = eth_type_trans(skb, dev);
  1200. /* The IPG encountered an error with (or
  1201. * there were no) IP/TCP/UDP checksums.
  1202. * This may or may not indicate an invalid
  1203. * IP/TCP/UDP frame was received. Let the
  1204. * upper layer decide.
  1205. */
  1206. skb_checksum_none_assert(skb);
  1207. /* Hand off frame for higher layer processing.
  1208. * The function netif_rx() releases the sk_buff
  1209. * when processing completes.
  1210. */
  1211. netif_rx(skb);
  1212. }
  1213. /* Assure RX buffer is not reused by IPG. */
  1214. sp->rx_buff[entry] = NULL;
  1215. }
  1216. /*
  1217. * If there are more RFDs to process and the allocated amount of RFD
  1218. * processing time has expired, assert Interrupt Requested to make
  1219. * sure we come back to process the remaining RFDs.
  1220. */
  1221. if (i == IPG_MAXRFDPROCESS_COUNT)
  1222. ipg_w32(ipg_r32(ASIC_CTRL) | IPG_AC_INT_REQUEST, ASIC_CTRL);
  1223. #ifdef IPG_DEBUG
  1224. /* Check if the RFD list contained no receive frame data. */
  1225. if (!i)
  1226. sp->EmptyRFDListCount++;
  1227. #endif
  1228. while ((le64_to_cpu(rxfd->rfs) & IPG_RFS_RFDDONE) &&
  1229. !((le64_to_cpu(rxfd->rfs) & IPG_RFS_FRAMESTART) &&
  1230. (le64_to_cpu(rxfd->rfs) & IPG_RFS_FRAMEEND))) {
  1231. unsigned int entry = curr++ % IPG_RFDLIST_LENGTH;
  1232. rxfd = sp->rxd + entry;
  1233. IPG_DEBUG_MSG("Frame requires multiple RFDs\n");
  1234. /* An unexpected event, additional code needed to handle
  1235. * properly. So for the time being, just disregard the
  1236. * frame.
  1237. */
  1238. /* Free the memory associated with the RX
  1239. * buffer since it is erroneous and we will
  1240. * not pass it to higher layer processes.
  1241. */
  1242. if (sp->rx_buff[entry]) {
  1243. pci_unmap_single(sp->pdev,
  1244. le64_to_cpu(rxfd->frag_info) & ~IPG_RFI_FRAGLEN,
  1245. sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
  1246. dev_kfree_skb_irq(sp->rx_buff[entry]);
  1247. }
  1248. /* Assure RX buffer is not reused by IPG. */
  1249. sp->rx_buff[entry] = NULL;
  1250. }
  1251. sp->rx_current = curr;
  1252. /* Check to see if there are a minimum number of used
  1253. * RFDs before restoring any (should improve performance.)
  1254. */
  1255. if ((curr - sp->rx_dirty) >= IPG_MINUSEDRFDSTOFREE)
  1256. ipg_nic_rxrestore(dev);
  1257. return 0;
  1258. }
  1259. static void ipg_reset_after_host_error(struct work_struct *work)
  1260. {
  1261. struct ipg_nic_private *sp =
  1262. container_of(work, struct ipg_nic_private, task.work);
  1263. struct net_device *dev = sp->dev;
  1264. /*
  1265. * Acknowledge HostError interrupt by resetting
  1266. * IPG DMA and HOST.
  1267. */
  1268. ipg_reset(dev, IPG_AC_GLOBAL_RESET | IPG_AC_HOST | IPG_AC_DMA);
  1269. init_rfdlist(dev);
  1270. init_tfdlist(dev);
  1271. if (ipg_io_config(dev) < 0) {
  1272. netdev_info(dev, "Cannot recover from PCI error\n");
  1273. schedule_delayed_work(&sp->task, HZ);
  1274. }
  1275. }
  1276. static irqreturn_t ipg_interrupt_handler(int irq, void *dev_inst)
  1277. {
  1278. struct net_device *dev = dev_inst;
  1279. struct ipg_nic_private *sp = netdev_priv(dev);
  1280. void __iomem *ioaddr = sp->ioaddr;
  1281. unsigned int handled = 0;
  1282. u16 status;
  1283. IPG_DEBUG_MSG("_interrupt_handler\n");
  1284. if (sp->is_jumbo)
  1285. ipg_nic_rxrestore(dev);
  1286. spin_lock(&sp->lock);
  1287. /* Get interrupt source information, and acknowledge
  1288. * some (i.e. TxDMAComplete, RxDMAComplete, RxEarly,
  1289. * IntRequested, MacControlFrame, LinkEvent) interrupts
  1290. * if issued. Also, all IPG interrupts are disabled by
  1291. * reading IntStatusAck.
  1292. */
  1293. status = ipg_r16(INT_STATUS_ACK);
  1294. IPG_DEBUG_MSG("IntStatusAck = %04x\n", status);
  1295. /* Shared IRQ of remove event. */
  1296. if (!(status & IPG_IS_RSVD_MASK))
  1297. goto out_enable;
  1298. handled = 1;
  1299. if (unlikely(!netif_running(dev)))
  1300. goto out_unlock;
  1301. /* If RFDListEnd interrupt, restore all used RFDs. */
  1302. if (status & IPG_IS_RFD_LIST_END) {
  1303. IPG_DEBUG_MSG("RFDListEnd Interrupt\n");
  1304. /* The RFD list end indicates an RFD was encountered
  1305. * with a 0 NextPtr, or with an RFDDone bit set to 1
  1306. * (indicating the RFD is not read for use by the
  1307. * IPG.) Try to restore all RFDs.
  1308. */
  1309. ipg_nic_rxrestore(dev);
  1310. #ifdef IPG_DEBUG
  1311. /* Increment the RFDlistendCount counter. */
  1312. sp->RFDlistendCount++;
  1313. #endif
  1314. }
  1315. /* If RFDListEnd, RxDMAPriority, RxDMAComplete, or
  1316. * IntRequested interrupt, process received frames. */
  1317. if ((status & IPG_IS_RX_DMA_PRIORITY) ||
  1318. (status & IPG_IS_RFD_LIST_END) ||
  1319. (status & IPG_IS_RX_DMA_COMPLETE) ||
  1320. (status & IPG_IS_INT_REQUESTED)) {
  1321. #ifdef IPG_DEBUG
  1322. /* Increment the RFD list checked counter if interrupted
  1323. * only to check the RFD list. */
  1324. if (status & (~(IPG_IS_RX_DMA_PRIORITY | IPG_IS_RFD_LIST_END |
  1325. IPG_IS_RX_DMA_COMPLETE | IPG_IS_INT_REQUESTED) &
  1326. (IPG_IS_HOST_ERROR | IPG_IS_TX_DMA_COMPLETE |
  1327. IPG_IS_LINK_EVENT | IPG_IS_TX_COMPLETE |
  1328. IPG_IS_UPDATE_STATS)))
  1329. sp->RFDListCheckedCount++;
  1330. #endif
  1331. if (sp->is_jumbo)
  1332. ipg_nic_rx_jumbo(dev);
  1333. else
  1334. ipg_nic_rx(dev);
  1335. }
  1336. /* If TxDMAComplete interrupt, free used TFDs. */
  1337. if (status & IPG_IS_TX_DMA_COMPLETE)
  1338. ipg_nic_txfree(dev);
  1339. /* TxComplete interrupts indicate one of numerous actions.
  1340. * Determine what action to take based on TXSTATUS register.
  1341. */
  1342. if (status & IPG_IS_TX_COMPLETE)
  1343. ipg_nic_txcleanup(dev);
  1344. /* If UpdateStats interrupt, update Linux Ethernet statistics */
  1345. if (status & IPG_IS_UPDATE_STATS)
  1346. ipg_nic_get_stats(dev);
  1347. /* If HostError interrupt, reset IPG. */
  1348. if (status & IPG_IS_HOST_ERROR) {
  1349. IPG_DDEBUG_MSG("HostError Interrupt\n");
  1350. schedule_delayed_work(&sp->task, 0);
  1351. }
  1352. /* If LinkEvent interrupt, resolve autonegotiation. */
  1353. if (status & IPG_IS_LINK_EVENT) {
  1354. if (ipg_config_autoneg(dev) < 0)
  1355. netdev_info(dev, "Auto-negotiation error\n");
  1356. }
  1357. /* If MACCtrlFrame interrupt, do nothing. */
  1358. if (status & IPG_IS_MAC_CTRL_FRAME)
  1359. IPG_DEBUG_MSG("MACCtrlFrame interrupt\n");
  1360. /* If RxComplete interrupt, do nothing. */
  1361. if (status & IPG_IS_RX_COMPLETE)
  1362. IPG_DEBUG_MSG("RxComplete interrupt\n");
  1363. /* If RxEarly interrupt, do nothing. */
  1364. if (status & IPG_IS_RX_EARLY)
  1365. IPG_DEBUG_MSG("RxEarly interrupt\n");
  1366. out_enable:
  1367. /* Re-enable IPG interrupts. */
  1368. ipg_w16(IPG_IE_TX_DMA_COMPLETE | IPG_IE_RX_DMA_COMPLETE |
  1369. IPG_IE_HOST_ERROR | IPG_IE_INT_REQUESTED | IPG_IE_TX_COMPLETE |
  1370. IPG_IE_LINK_EVENT | IPG_IE_UPDATE_STATS, INT_ENABLE);
  1371. out_unlock:
  1372. spin_unlock(&sp->lock);
  1373. return IRQ_RETVAL(handled);
  1374. }
  1375. static void ipg_rx_clear(struct ipg_nic_private *sp)
  1376. {
  1377. unsigned int i;
  1378. for (i = 0; i < IPG_RFDLIST_LENGTH; i++) {
  1379. if (sp->rx_buff[i]) {
  1380. struct ipg_rx *rxfd = sp->rxd + i;
  1381. dev_kfree_skb_irq(sp->rx_buff[i]);
  1382. sp->rx_buff[i] = NULL;
  1383. pci_unmap_single(sp->pdev,
  1384. le64_to_cpu(rxfd->frag_info) & ~IPG_RFI_FRAGLEN,
  1385. sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
  1386. }
  1387. }
  1388. }
  1389. static void ipg_tx_clear(struct ipg_nic_private *sp)
  1390. {
  1391. unsigned int i;
  1392. for (i = 0; i < IPG_TFDLIST_LENGTH; i++) {
  1393. if (sp->tx_buff[i]) {
  1394. struct ipg_tx *txfd = sp->txd + i;
  1395. pci_unmap_single(sp->pdev,
  1396. le64_to_cpu(txfd->frag_info) & ~IPG_TFI_FRAGLEN,
  1397. sp->tx_buff[i]->len, PCI_DMA_TODEVICE);
  1398. dev_kfree_skb_irq(sp->tx_buff[i]);
  1399. sp->tx_buff[i] = NULL;
  1400. }
  1401. }
  1402. }
  1403. static int ipg_nic_open(struct net_device *dev)
  1404. {
  1405. struct ipg_nic_private *sp = netdev_priv(dev);
  1406. void __iomem *ioaddr = sp->ioaddr;
  1407. struct pci_dev *pdev = sp->pdev;
  1408. int rc;
  1409. IPG_DEBUG_MSG("_nic_open\n");
  1410. sp->rx_buf_sz = sp->rxsupport_size;
  1411. /* Check for interrupt line conflicts, and request interrupt
  1412. * line for IPG.
  1413. *
  1414. * IMPORTANT: Disable IPG interrupts prior to registering
  1415. * IRQ.
  1416. */
  1417. ipg_w16(0x0000, INT_ENABLE);
  1418. /* Register the interrupt line to be used by the IPG within
  1419. * the Linux system.
  1420. */
  1421. rc = request_irq(pdev->irq, ipg_interrupt_handler, IRQF_SHARED,
  1422. dev->name, dev);
  1423. if (rc < 0) {
  1424. netdev_info(dev, "Error when requesting interrupt\n");
  1425. goto out;
  1426. }
  1427. dev->irq = pdev->irq;
  1428. rc = -ENOMEM;
  1429. sp->rxd = dma_alloc_coherent(&pdev->dev, IPG_RX_RING_BYTES,
  1430. &sp->rxd_map, GFP_KERNEL);
  1431. if (!sp->rxd)
  1432. goto err_free_irq_0;
  1433. sp->txd = dma_alloc_coherent(&pdev->dev, IPG_TX_RING_BYTES,
  1434. &sp->txd_map, GFP_KERNEL);
  1435. if (!sp->txd)
  1436. goto err_free_rx_1;
  1437. rc = init_rfdlist(dev);
  1438. if (rc < 0) {
  1439. netdev_info(dev, "Error during configuration\n");
  1440. goto err_free_tx_2;
  1441. }
  1442. init_tfdlist(dev);
  1443. rc = ipg_io_config(dev);
  1444. if (rc < 0) {
  1445. netdev_info(dev, "Error during configuration\n");
  1446. goto err_release_tfdlist_3;
  1447. }
  1448. /* Resolve autonegotiation. */
  1449. if (ipg_config_autoneg(dev) < 0)
  1450. netdev_info(dev, "Auto-negotiation error\n");
  1451. /* initialize JUMBO Frame control variable */
  1452. sp->jumbo.found_start = 0;
  1453. sp->jumbo.current_size = 0;
  1454. sp->jumbo.skb = NULL;
  1455. /* Enable transmit and receive operation of the IPG. */
  1456. ipg_w32((ipg_r32(MAC_CTRL) | IPG_MC_RX_ENABLE | IPG_MC_TX_ENABLE) &
  1457. IPG_MC_RSVD_MASK, MAC_CTRL);
  1458. netif_start_queue(dev);
  1459. out:
  1460. return rc;
  1461. err_release_tfdlist_3:
  1462. ipg_tx_clear(sp);
  1463. ipg_rx_clear(sp);
  1464. err_free_tx_2:
  1465. dma_free_coherent(&pdev->dev, IPG_TX_RING_BYTES, sp->txd, sp->txd_map);
  1466. err_free_rx_1:
  1467. dma_free_coherent(&pdev->dev, IPG_RX_RING_BYTES, sp->rxd, sp->rxd_map);
  1468. err_free_irq_0:
  1469. free_irq(pdev->irq, dev);
  1470. goto out;
  1471. }
  1472. static int ipg_nic_stop(struct net_device *dev)
  1473. {
  1474. struct ipg_nic_private *sp = netdev_priv(dev);
  1475. void __iomem *ioaddr = sp->ioaddr;
  1476. struct pci_dev *pdev = sp->pdev;
  1477. IPG_DEBUG_MSG("_nic_stop\n");
  1478. netif_stop_queue(dev);
  1479. IPG_DUMPTFDLIST(dev);
  1480. do {
  1481. (void) ipg_r16(INT_STATUS_ACK);
  1482. ipg_reset(dev, IPG_AC_GLOBAL_RESET | IPG_AC_HOST | IPG_AC_DMA);
  1483. synchronize_irq(pdev->irq);
  1484. } while (ipg_r16(INT_ENABLE) & IPG_IE_RSVD_MASK);
  1485. ipg_rx_clear(sp);
  1486. ipg_tx_clear(sp);
  1487. pci_free_consistent(pdev, IPG_RX_RING_BYTES, sp->rxd, sp->rxd_map);
  1488. pci_free_consistent(pdev, IPG_TX_RING_BYTES, sp->txd, sp->txd_map);
  1489. free_irq(pdev->irq, dev);
  1490. return 0;
  1491. }
  1492. static netdev_tx_t ipg_nic_hard_start_xmit(struct sk_buff *skb,
  1493. struct net_device *dev)
  1494. {
  1495. struct ipg_nic_private *sp = netdev_priv(dev);
  1496. void __iomem *ioaddr = sp->ioaddr;
  1497. unsigned int entry = sp->tx_current % IPG_TFDLIST_LENGTH;
  1498. unsigned long flags;
  1499. struct ipg_tx *txfd;
  1500. IPG_DDEBUG_MSG("_nic_hard_start_xmit\n");
  1501. /* If in 10Mbps mode, stop the transmit queue so
  1502. * no more transmit frames are accepted.
  1503. */
  1504. if (sp->tenmbpsmode)
  1505. netif_stop_queue(dev);
  1506. if (sp->reset_current_tfd) {
  1507. sp->reset_current_tfd = 0;
  1508. entry = 0;
  1509. }
  1510. txfd = sp->txd + entry;
  1511. sp->tx_buff[entry] = skb;
  1512. /* Clear all TFC fields, except TFDDONE. */
  1513. txfd->tfc = cpu_to_le64(IPG_TFC_TFDDONE);
  1514. /* Specify the TFC field within the TFD. */
  1515. txfd->tfc |= cpu_to_le64(IPG_TFC_WORDALIGNDISABLED |
  1516. (IPG_TFC_FRAMEID & sp->tx_current) |
  1517. (IPG_TFC_FRAGCOUNT & (1 << 24)));
  1518. /*
  1519. * 16--17 (WordAlign) <- 3 (disable),
  1520. * 0--15 (FrameId) <- sp->tx_current,
  1521. * 24--27 (FragCount) <- 1
  1522. */
  1523. /* Request TxComplete interrupts at an interval defined
  1524. * by the constant IPG_FRAMESBETWEENTXCOMPLETES.
  1525. * Request TxComplete interrupt for every frame
  1526. * if in 10Mbps mode to accommodate problem with 10Mbps
  1527. * processing.
  1528. */
  1529. if (sp->tenmbpsmode)
  1530. txfd->tfc |= cpu_to_le64(IPG_TFC_TXINDICATE);
  1531. txfd->tfc |= cpu_to_le64(IPG_TFC_TXDMAINDICATE);
  1532. /* Based on compilation option, determine if FCS is to be
  1533. * appended to transmit frame by IPG.
  1534. */
  1535. if (!(IPG_APPEND_FCS_ON_TX))
  1536. txfd->tfc |= cpu_to_le64(IPG_TFC_FCSAPPENDDISABLE);
  1537. /* Based on compilation option, determine if IP, TCP and/or
  1538. * UDP checksums are to be added to transmit frame by IPG.
  1539. */
  1540. if (IPG_ADD_IPCHECKSUM_ON_TX)
  1541. txfd->tfc |= cpu_to_le64(IPG_TFC_IPCHECKSUMENABLE);
  1542. if (IPG_ADD_TCPCHECKSUM_ON_TX)
  1543. txfd->tfc |= cpu_to_le64(IPG_TFC_TCPCHECKSUMENABLE);
  1544. if (IPG_ADD_UDPCHECKSUM_ON_TX)
  1545. txfd->tfc |= cpu_to_le64(IPG_TFC_UDPCHECKSUMENABLE);
  1546. /* Based on compilation option, determine if VLAN tag info is to be
  1547. * inserted into transmit frame by IPG.
  1548. */
  1549. if (IPG_INSERT_MANUAL_VLAN_TAG) {
  1550. txfd->tfc |= cpu_to_le64(IPG_TFC_VLANTAGINSERT |
  1551. ((u64) IPG_MANUAL_VLAN_VID << 32) |
  1552. ((u64) IPG_MANUAL_VLAN_CFI << 44) |
  1553. ((u64) IPG_MANUAL_VLAN_USERPRIORITY << 45));
  1554. }
  1555. /* The fragment start location within system memory is defined
  1556. * by the sk_buff structure's data field. The physical address
  1557. * of this location within the system's virtual memory space
  1558. * is determined using the IPG_HOST2BUS_MAP function.
  1559. */
  1560. txfd->frag_info = cpu_to_le64(pci_map_single(sp->pdev, skb->data,
  1561. skb->len, PCI_DMA_TODEVICE));
  1562. /* The length of the fragment within system memory is defined by
  1563. * the sk_buff structure's len field.
  1564. */
  1565. txfd->frag_info |= cpu_to_le64(IPG_TFI_FRAGLEN &
  1566. ((u64) (skb->len & 0xffff) << 48));
  1567. /* Clear the TFDDone bit last to indicate the TFD is ready
  1568. * for transfer to the IPG.
  1569. */
  1570. txfd->tfc &= cpu_to_le64(~IPG_TFC_TFDDONE);
  1571. spin_lock_irqsave(&sp->lock, flags);
  1572. sp->tx_current++;
  1573. mmiowb();
  1574. ipg_w32(IPG_DC_TX_DMA_POLL_NOW, DMA_CTRL);
  1575. if (sp->tx_current == (sp->tx_dirty + IPG_TFDLIST_LENGTH))
  1576. netif_stop_queue(dev);
  1577. spin_unlock_irqrestore(&sp->lock, flags);
  1578. return NETDEV_TX_OK;
  1579. }
  1580. static void ipg_set_phy_default_param(unsigned char rev,
  1581. struct net_device *dev, int phy_address)
  1582. {
  1583. unsigned short length;
  1584. unsigned char revision;
  1585. const unsigned short *phy_param;
  1586. unsigned short address, value;
  1587. phy_param = &DefaultPhyParam[0];
  1588. length = *phy_param & 0x00FF;
  1589. revision = (unsigned char)((*phy_param) >> 8);
  1590. phy_param++;
  1591. while (length != 0) {
  1592. if (rev == revision) {
  1593. while (length > 1) {
  1594. address = *phy_param;
  1595. value = *(phy_param + 1);
  1596. phy_param += 2;
  1597. mdio_write(dev, phy_address, address, value);
  1598. length -= 4;
  1599. }
  1600. break;
  1601. } else {
  1602. phy_param += length / 2;
  1603. length = *phy_param & 0x00FF;
  1604. revision = (unsigned char)((*phy_param) >> 8);
  1605. phy_param++;
  1606. }
  1607. }
  1608. }
  1609. static int read_eeprom(struct net_device *dev, int eep_addr)
  1610. {
  1611. void __iomem *ioaddr = ipg_ioaddr(dev);
  1612. unsigned int i;
  1613. int ret = 0;
  1614. u16 value;
  1615. value = IPG_EC_EEPROM_READOPCODE | (eep_addr & 0xff);
  1616. ipg_w16(value, EEPROM_CTRL);
  1617. for (i = 0; i < 1000; i++) {
  1618. u16 data;
  1619. mdelay(10);
  1620. data = ipg_r16(EEPROM_CTRL);
  1621. if (!(data & IPG_EC_EEPROM_BUSY)) {
  1622. ret = ipg_r16(EEPROM_DATA);
  1623. break;
  1624. }
  1625. }
  1626. return ret;
  1627. }
  1628. static void ipg_init_mii(struct net_device *dev)
  1629. {
  1630. struct ipg_nic_private *sp = netdev_priv(dev);
  1631. struct mii_if_info *mii_if = &sp->mii_if;
  1632. int phyaddr;
  1633. mii_if->dev = dev;
  1634. mii_if->mdio_read = mdio_read;
  1635. mii_if->mdio_write = mdio_write;
  1636. mii_if->phy_id_mask = 0x1f;
  1637. mii_if->reg_num_mask = 0x1f;
  1638. mii_if->phy_id = phyaddr = ipg_find_phyaddr(dev);
  1639. if (phyaddr != 0x1f) {
  1640. u16 mii_phyctrl, mii_1000cr;
  1641. mii_1000cr = mdio_read(dev, phyaddr, MII_CTRL1000);
  1642. mii_1000cr |= ADVERTISE_1000FULL | ADVERTISE_1000HALF |
  1643. GMII_PHY_1000BASETCONTROL_PreferMaster;
  1644. mdio_write(dev, phyaddr, MII_CTRL1000, mii_1000cr);
  1645. mii_phyctrl = mdio_read(dev, phyaddr, MII_BMCR);
  1646. /* Set default phyparam */
  1647. ipg_set_phy_default_param(sp->pdev->revision, dev, phyaddr);
  1648. /* Reset PHY */
  1649. mii_phyctrl |= BMCR_RESET | BMCR_ANRESTART;
  1650. mdio_write(dev, phyaddr, MII_BMCR, mii_phyctrl);
  1651. }
  1652. }
  1653. static int ipg_hw_init(struct net_device *dev)
  1654. {
  1655. struct ipg_nic_private *sp = netdev_priv(dev);
  1656. void __iomem *ioaddr = sp->ioaddr;
  1657. unsigned int i;
  1658. int rc;
  1659. /* Read/Write and Reset EEPROM Value */
  1660. /* Read LED Mode Configuration from EEPROM */
  1661. sp->led_mode = read_eeprom(dev, 6);
  1662. /* Reset all functions within the IPG. Do not assert
  1663. * RST_OUT as not compatible with some PHYs.
  1664. */
  1665. rc = ipg_reset(dev, IPG_RESET_MASK);
  1666. if (rc < 0)
  1667. goto out;
  1668. ipg_init_mii(dev);
  1669. /* Read MAC Address from EEPROM */
  1670. for (i = 0; i < 3; i++)
  1671. sp->station_addr[i] = read_eeprom(dev, 16 + i);
  1672. for (i = 0; i < 3; i++)
  1673. ipg_w16(sp->station_addr[i], STATION_ADDRESS_0 + 2*i);
  1674. /* Set station address in ethernet_device structure. */
  1675. dev->dev_addr[0] = ipg_r16(STATION_ADDRESS_0) & 0x00ff;
  1676. dev->dev_addr[1] = (ipg_r16(STATION_ADDRESS_0) & 0xff00) >> 8;
  1677. dev->dev_addr[2] = ipg_r16(STATION_ADDRESS_1) & 0x00ff;
  1678. dev->dev_addr[3] = (ipg_r16(STATION_ADDRESS_1) & 0xff00) >> 8;
  1679. dev->dev_addr[4] = ipg_r16(STATION_ADDRESS_2) & 0x00ff;
  1680. dev->dev_addr[5] = (ipg_r16(STATION_ADDRESS_2) & 0xff00) >> 8;
  1681. out:
  1682. return rc;
  1683. }
  1684. static int ipg_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  1685. {
  1686. struct ipg_nic_private *sp = netdev_priv(dev);
  1687. int rc;
  1688. mutex_lock(&sp->mii_mutex);
  1689. rc = generic_mii_ioctl(&sp->mii_if, if_mii(ifr), cmd, NULL);
  1690. mutex_unlock(&sp->mii_mutex);
  1691. return rc;
  1692. }
  1693. static int ipg_nic_change_mtu(struct net_device *dev, int new_mtu)
  1694. {
  1695. struct ipg_nic_private *sp = netdev_priv(dev);
  1696. int err;
  1697. /* Function to accommodate changes to Maximum Transfer Unit
  1698. * (or MTU) of IPG NIC. Cannot use default function since
  1699. * the default will not allow for MTU > 1500 bytes.
  1700. */
  1701. IPG_DEBUG_MSG("_nic_change_mtu\n");
  1702. /*
  1703. * Check that the new MTU value is between 68 (14 byte header, 46 byte
  1704. * payload, 4 byte FCS) and 10 KB, which is the largest supported MTU.
  1705. */
  1706. if (new_mtu < 68 || new_mtu > 10240)
  1707. return -EINVAL;
  1708. err = ipg_nic_stop(dev);
  1709. if (err)
  1710. return err;
  1711. dev->mtu = new_mtu;
  1712. sp->max_rxframe_size = new_mtu;
  1713. sp->rxfrag_size = new_mtu;
  1714. if (sp->rxfrag_size > 4088)
  1715. sp->rxfrag_size = 4088;
  1716. sp->rxsupport_size = sp->max_rxframe_size;
  1717. if (new_mtu > 0x0600)
  1718. sp->is_jumbo = true;
  1719. else
  1720. sp->is_jumbo = false;
  1721. return ipg_nic_open(dev);
  1722. }
  1723. static int ipg_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  1724. {
  1725. struct ipg_nic_private *sp = netdev_priv(dev);
  1726. int rc;
  1727. mutex_lock(&sp->mii_mutex);
  1728. rc = mii_ethtool_gset(&sp->mii_if, cmd);
  1729. mutex_unlock(&sp->mii_mutex);
  1730. return rc;
  1731. }
  1732. static int ipg_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  1733. {
  1734. struct ipg_nic_private *sp = netdev_priv(dev);
  1735. int rc;
  1736. mutex_lock(&sp->mii_mutex);
  1737. rc = mii_ethtool_sset(&sp->mii_if, cmd);
  1738. mutex_unlock(&sp->mii_mutex);
  1739. return rc;
  1740. }
  1741. static int ipg_nway_reset(struct net_device *dev)
  1742. {
  1743. struct ipg_nic_private *sp = netdev_priv(dev);
  1744. int rc;
  1745. mutex_lock(&sp->mii_mutex);
  1746. rc = mii_nway_restart(&sp->mii_if);
  1747. mutex_unlock(&sp->mii_mutex);
  1748. return rc;
  1749. }
  1750. static const struct ethtool_ops ipg_ethtool_ops = {
  1751. .get_settings = ipg_get_settings,
  1752. .set_settings = ipg_set_settings,
  1753. .nway_reset = ipg_nway_reset,
  1754. };
  1755. static void ipg_remove(struct pci_dev *pdev)
  1756. {
  1757. struct net_device *dev = pci_get_drvdata(pdev);
  1758. struct ipg_nic_private *sp = netdev_priv(dev);
  1759. IPG_DEBUG_MSG("_remove\n");
  1760. /* Un-register Ethernet device. */
  1761. unregister_netdev(dev);
  1762. pci_iounmap(pdev, sp->ioaddr);
  1763. pci_release_regions(pdev);
  1764. free_netdev(dev);
  1765. pci_disable_device(pdev);
  1766. pci_set_drvdata(pdev, NULL);
  1767. }
  1768. static const struct net_device_ops ipg_netdev_ops = {
  1769. .ndo_open = ipg_nic_open,
  1770. .ndo_stop = ipg_nic_stop,
  1771. .ndo_start_xmit = ipg_nic_hard_start_xmit,
  1772. .ndo_get_stats = ipg_nic_get_stats,
  1773. .ndo_set_rx_mode = ipg_nic_set_multicast_list,
  1774. .ndo_do_ioctl = ipg_ioctl,
  1775. .ndo_tx_timeout = ipg_tx_timeout,
  1776. .ndo_change_mtu = ipg_nic_change_mtu,
  1777. .ndo_set_mac_address = eth_mac_addr,
  1778. .ndo_validate_addr = eth_validate_addr,
  1779. };
  1780. static int ipg_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  1781. {
  1782. unsigned int i = id->driver_data;
  1783. struct ipg_nic_private *sp;
  1784. struct net_device *dev;
  1785. void __iomem *ioaddr;
  1786. int rc;
  1787. rc = pci_enable_device(pdev);
  1788. if (rc < 0)
  1789. goto out;
  1790. pr_info("%s: %s\n", pci_name(pdev), ipg_brand_name[i]);
  1791. pci_set_master(pdev);
  1792. rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(40));
  1793. if (rc < 0) {
  1794. rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  1795. if (rc < 0) {
  1796. pr_err("%s: DMA config failed\n", pci_name(pdev));
  1797. goto err_disable_0;
  1798. }
  1799. }
  1800. /*
  1801. * Initialize net device.
  1802. */
  1803. dev = alloc_etherdev(sizeof(struct ipg_nic_private));
  1804. if (!dev) {
  1805. rc = -ENOMEM;
  1806. goto err_disable_0;
  1807. }
  1808. sp = netdev_priv(dev);
  1809. spin_lock_init(&sp->lock);
  1810. mutex_init(&sp->mii_mutex);
  1811. sp->is_jumbo = IPG_IS_JUMBO;
  1812. sp->rxfrag_size = IPG_RXFRAG_SIZE;
  1813. sp->rxsupport_size = IPG_RXSUPPORT_SIZE;
  1814. sp->max_rxframe_size = IPG_MAX_RXFRAME_SIZE;
  1815. /* Declare IPG NIC functions for Ethernet device methods.
  1816. */
  1817. dev->netdev_ops = &ipg_netdev_ops;
  1818. SET_NETDEV_DEV(dev, &pdev->dev);
  1819. SET_ETHTOOL_OPS(dev, &ipg_ethtool_ops);
  1820. rc = pci_request_regions(pdev, DRV_NAME);
  1821. if (rc)
  1822. goto err_free_dev_1;
  1823. ioaddr = pci_iomap(pdev, 1, pci_resource_len(pdev, 1));
  1824. if (!ioaddr) {
  1825. pr_err("%s: cannot map MMIO\n", pci_name(pdev));
  1826. rc = -EIO;
  1827. goto err_release_regions_2;
  1828. }
  1829. /* Save the pointer to the PCI device information. */
  1830. sp->ioaddr = ioaddr;
  1831. sp->pdev = pdev;
  1832. sp->dev = dev;
  1833. INIT_DELAYED_WORK(&sp->task, ipg_reset_after_host_error);
  1834. pci_set_drvdata(pdev, dev);
  1835. rc = ipg_hw_init(dev);
  1836. if (rc < 0)
  1837. goto err_unmap_3;
  1838. rc = register_netdev(dev);
  1839. if (rc < 0)
  1840. goto err_unmap_3;
  1841. netdev_info(dev, "Ethernet device registered\n");
  1842. out:
  1843. return rc;
  1844. err_unmap_3:
  1845. pci_iounmap(pdev, ioaddr);
  1846. err_release_regions_2:
  1847. pci_release_regions(pdev);
  1848. err_free_dev_1:
  1849. free_netdev(dev);
  1850. err_disable_0:
  1851. pci_disable_device(pdev);
  1852. goto out;
  1853. }
  1854. static struct pci_driver ipg_pci_driver = {
  1855. .name = IPG_DRIVER_NAME,
  1856. .id_table = ipg_pci_tbl,
  1857. .probe = ipg_probe,
  1858. .remove = ipg_remove,
  1859. };
  1860. static int __init ipg_init_module(void)
  1861. {
  1862. return pci_register_driver(&ipg_pci_driver);
  1863. }
  1864. static void __exit ipg_exit_module(void)
  1865. {
  1866. pci_unregister_driver(&ipg_pci_driver);
  1867. }
  1868. module_init(ipg_init_module);
  1869. module_exit(ipg_exit_module);