ipg.c 61 KB

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