ipg.c 60 KB

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