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