ipg.c 60 KB

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