ipg.c 61 KB

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