ipg.c 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352
  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. void __iomem *ioaddr = sp->ioaddr;
  718. unsigned int curr;
  719. u64 txd_map;
  720. unsigned int released, pending;
  721. txd_map = (u64)sp->txd_map;
  722. curr = ipg_r32(TFD_LIST_PTR_0) -
  723. do_div(txd_map, sizeof(struct ipg_tx)) - 1;
  724. IPG_DEBUG_MSG("_nic_txfree\n");
  725. pending = sp->tx_current - sp->tx_dirty;
  726. for (released = 0; released < pending; released++) {
  727. unsigned int dirty = sp->tx_dirty % IPG_TFDLIST_LENGTH;
  728. struct sk_buff *skb = sp->TxBuff[dirty];
  729. struct ipg_tx *txfd = sp->txd + dirty;
  730. IPG_DEBUG_MSG("TFC = %16.16lx\n", (unsigned long) txfd->tfc);
  731. /* Look at each TFD's TFC field beginning
  732. * at the last freed TFD up to the current TFD.
  733. * If the TFDDone bit is set, free the associated
  734. * buffer.
  735. */
  736. if (dirty == curr)
  737. break;
  738. /* Setup TFDDONE for compatible issue. */
  739. txfd->tfc |= cpu_to_le64(IPG_TFC_TFDDONE);
  740. /* Free the transmit buffer. */
  741. if (skb) {
  742. pci_unmap_single(sp->pdev,
  743. le64_to_cpu(txfd->frag_info) & ~IPG_TFI_FRAGLEN,
  744. skb->len, PCI_DMA_TODEVICE);
  745. IPG_DEV_KFREE_SKB(skb);
  746. sp->TxBuff[dirty] = NULL;
  747. }
  748. }
  749. sp->tx_dirty += released;
  750. if (netif_queue_stopped(dev) &&
  751. (sp->tx_current != (sp->tx_dirty + IPG_TFDLIST_LENGTH))) {
  752. netif_wake_queue(dev);
  753. }
  754. }
  755. static void ipg_tx_timeout(struct net_device *dev)
  756. {
  757. struct ipg_nic_private *sp = netdev_priv(dev);
  758. void __iomem *ioaddr = sp->ioaddr;
  759. ipg_reset(dev, IPG_AC_TX_RESET | IPG_AC_DMA | IPG_AC_NETWORK |
  760. IPG_AC_FIFO);
  761. spin_lock_irq(&sp->lock);
  762. /* Re-configure after DMA reset. */
  763. if (ipg_io_config(dev) < 0) {
  764. printk(KERN_INFO "%s: Error during re-configuration.\n",
  765. dev->name);
  766. }
  767. init_tfdlist(dev);
  768. spin_unlock_irq(&sp->lock);
  769. ipg_w32((ipg_r32(MAC_CTRL) | IPG_MC_TX_ENABLE) & IPG_MC_RSVD_MASK,
  770. MAC_CTRL);
  771. }
  772. /*
  773. * For TxComplete interrupts, free all transmit
  774. * buffers which have already been transfered via DMA
  775. * to the IPG.
  776. */
  777. static void ipg_nic_txcleanup(struct net_device *dev)
  778. {
  779. struct ipg_nic_private *sp = netdev_priv(dev);
  780. void __iomem *ioaddr = sp->ioaddr;
  781. unsigned int i;
  782. IPG_DEBUG_MSG("_nic_txcleanup\n");
  783. for (i = 0; i < IPG_TFDLIST_LENGTH; i++) {
  784. /* Reading the TXSTATUS register clears the
  785. * TX_COMPLETE interrupt.
  786. */
  787. u32 txstatusdword = ipg_r32(TX_STATUS);
  788. IPG_DEBUG_MSG("TxStatus = %8.8x\n", txstatusdword);
  789. /* Check for Transmit errors. Error bits only valid if
  790. * TX_COMPLETE bit in the TXSTATUS register is a 1.
  791. */
  792. if (!(txstatusdword & IPG_TS_TX_COMPLETE))
  793. break;
  794. /* If in 10Mbps mode, indicate transmit is ready. */
  795. if (sp->tenmbpsmode) {
  796. netif_wake_queue(dev);
  797. }
  798. /* Transmit error, increment stat counters. */
  799. if (txstatusdword & IPG_TS_TX_ERROR) {
  800. IPG_DEBUG_MSG("Transmit error.\n");
  801. sp->stats.tx_errors++;
  802. }
  803. /* Late collision, re-enable transmitter. */
  804. if (txstatusdword & IPG_TS_LATE_COLLISION) {
  805. IPG_DEBUG_MSG("Late collision on transmit.\n");
  806. ipg_w32((ipg_r32(MAC_CTRL) | IPG_MC_TX_ENABLE) &
  807. IPG_MC_RSVD_MASK, MAC_CTRL);
  808. }
  809. /* Maximum collisions, re-enable transmitter. */
  810. if (txstatusdword & IPG_TS_TX_MAX_COLL) {
  811. IPG_DEBUG_MSG("Maximum collisions on transmit.\n");
  812. ipg_w32((ipg_r32(MAC_CTRL) | IPG_MC_TX_ENABLE) &
  813. IPG_MC_RSVD_MASK, MAC_CTRL);
  814. }
  815. /* Transmit underrun, reset and re-enable
  816. * transmitter.
  817. */
  818. if (txstatusdword & IPG_TS_TX_UNDERRUN) {
  819. IPG_DEBUG_MSG("Transmitter underrun.\n");
  820. sp->stats.tx_fifo_errors++;
  821. ipg_reset(dev, IPG_AC_TX_RESET | IPG_AC_DMA |
  822. IPG_AC_NETWORK | IPG_AC_FIFO);
  823. /* Re-configure after DMA reset. */
  824. if (ipg_io_config(dev) < 0) {
  825. printk(KERN_INFO
  826. "%s: Error during re-configuration.\n",
  827. dev->name);
  828. }
  829. init_tfdlist(dev);
  830. ipg_w32((ipg_r32(MAC_CTRL) | IPG_MC_TX_ENABLE) &
  831. IPG_MC_RSVD_MASK, MAC_CTRL);
  832. }
  833. }
  834. ipg_nic_txfree(dev);
  835. }
  836. /* Provides statistical information about the IPG NIC. */
  837. static struct net_device_stats *ipg_nic_get_stats(struct net_device *dev)
  838. {
  839. struct ipg_nic_private *sp = netdev_priv(dev);
  840. void __iomem *ioaddr = sp->ioaddr;
  841. u16 temp1;
  842. u16 temp2;
  843. IPG_DEBUG_MSG("_nic_get_stats\n");
  844. /* Check to see if the NIC has been initialized via nic_open,
  845. * before trying to read statistic registers.
  846. */
  847. if (!test_bit(__LINK_STATE_START, &dev->state))
  848. return &sp->stats;
  849. sp->stats.rx_packets += ipg_r32(IPG_FRAMESRCVDOK);
  850. sp->stats.tx_packets += ipg_r32(IPG_FRAMESXMTDOK);
  851. sp->stats.rx_bytes += ipg_r32(IPG_OCTETRCVOK);
  852. sp->stats.tx_bytes += ipg_r32(IPG_OCTETXMTOK);
  853. temp1 = ipg_r16(IPG_FRAMESLOSTRXERRORS);
  854. sp->stats.rx_errors += temp1;
  855. sp->stats.rx_missed_errors += temp1;
  856. temp1 = ipg_r32(IPG_SINGLECOLFRAMES) + ipg_r32(IPG_MULTICOLFRAMES) +
  857. ipg_r32(IPG_LATECOLLISIONS);
  858. temp2 = ipg_r16(IPG_CARRIERSENSEERRORS);
  859. sp->stats.collisions += temp1;
  860. sp->stats.tx_dropped += ipg_r16(IPG_FRAMESABORTXSCOLLS);
  861. sp->stats.tx_errors += ipg_r16(IPG_FRAMESWEXDEFERRAL) +
  862. ipg_r32(IPG_FRAMESWDEFERREDXMT) + temp1 + temp2;
  863. sp->stats.multicast += ipg_r32(IPG_MCSTOCTETRCVDOK);
  864. /* detailed tx_errors */
  865. sp->stats.tx_carrier_errors += temp2;
  866. /* detailed rx_errors */
  867. sp->stats.rx_length_errors += ipg_r16(IPG_INRANGELENGTHERRORS) +
  868. ipg_r16(IPG_FRAMETOOLONGERRRORS);
  869. sp->stats.rx_crc_errors += ipg_r16(IPG_FRAMECHECKSEQERRORS);
  870. /* Unutilized IPG statistic registers. */
  871. ipg_r32(IPG_MCSTFRAMESRCVDOK);
  872. return &sp->stats;
  873. }
  874. /* Restore used receive buffers. */
  875. static int ipg_nic_rxrestore(struct net_device *dev)
  876. {
  877. struct ipg_nic_private *sp = netdev_priv(dev);
  878. const unsigned int curr = sp->rx_current;
  879. unsigned int dirty = sp->rx_dirty;
  880. IPG_DEBUG_MSG("_nic_rxrestore\n");
  881. for (dirty = sp->rx_dirty; curr - dirty > 0; dirty++) {
  882. unsigned int entry = dirty % IPG_RFDLIST_LENGTH;
  883. /* rx_copybreak may poke hole here and there. */
  884. if (sp->RxBuff[entry])
  885. continue;
  886. /* Generate a new receive buffer to replace the
  887. * current buffer (which will be released by the
  888. * Linux system).
  889. */
  890. if (ipg_get_rxbuff(dev, entry) < 0) {
  891. IPG_DEBUG_MSG("Cannot allocate new Rx buffer.\n");
  892. break;
  893. }
  894. /* Reset the RFS field. */
  895. sp->rxd[entry].rfs = 0x0000000000000000;
  896. }
  897. sp->rx_dirty = dirty;
  898. return 0;
  899. }
  900. #ifdef JUMBO_FRAME
  901. /* use jumboindex and jumbosize to control jumbo frame status
  902. initial status is jumboindex=-1 and jumbosize=0
  903. 1. jumboindex = -1 and jumbosize=0 : previous jumbo frame has been done.
  904. 2. jumboindex != -1 and jumbosize != 0 : jumbo frame is not over size and receiving
  905. 3. jumboindex = -1 and jumbosize != 0 : jumbo frame is over size, already dump
  906. previous receiving and need to continue dumping the current one
  907. */
  908. enum {
  909. NormalPacket,
  910. ErrorPacket
  911. };
  912. enum {
  913. Frame_NoStart_NoEnd = 0,
  914. Frame_WithStart = 1,
  915. Frame_WithEnd = 10,
  916. Frame_WithStart_WithEnd = 11
  917. };
  918. inline void ipg_nic_rx_free_skb(struct net_device *dev)
  919. {
  920. struct ipg_nic_private *sp = netdev_priv(dev);
  921. unsigned int entry = sp->rx_current % IPG_RFDLIST_LENGTH;
  922. if (sp->RxBuff[entry]) {
  923. struct ipg_rx *rxfd = sp->rxd + entry;
  924. pci_unmap_single(sp->pdev,
  925. le64_to_cpu(rxfd->frag_info & ~IPG_RFI_FRAGLEN),
  926. sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
  927. IPG_DEV_KFREE_SKB(sp->RxBuff[entry]);
  928. sp->RxBuff[entry] = NULL;
  929. }
  930. }
  931. inline int ipg_nic_rx_check_frame_type(struct net_device *dev)
  932. {
  933. struct ipg_nic_private *sp = netdev_priv(dev);
  934. struct ipg_rx *rxfd = sp->rxd + (sp->rx_current % IPG_RFDLIST_LENGTH);
  935. int type = Frame_NoStart_NoEnd;
  936. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_FRAMESTART)
  937. type += Frame_WithStart;
  938. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_FRAMEEND)
  939. type += Frame_WithEnd;
  940. return type;
  941. }
  942. inline int ipg_nic_rx_check_error(struct net_device *dev)
  943. {
  944. struct ipg_nic_private *sp = netdev_priv(dev);
  945. unsigned int entry = sp->rx_current % IPG_RFDLIST_LENGTH;
  946. struct ipg_rx *rxfd = sp->rxd + entry;
  947. if (IPG_DROP_ON_RX_ETH_ERRORS && (le64_to_cpu(rxfd->rfs) &
  948. (IPG_RFS_RXFIFOOVERRUN | IPG_RFS_RXRUNTFRAME |
  949. IPG_RFS_RXALIGNMENTERROR | IPG_RFS_RXFCSERROR |
  950. IPG_RFS_RXOVERSIZEDFRAME | IPG_RFS_RXLENGTHERROR))) {
  951. IPG_DEBUG_MSG("Rx error, RFS = %16.16lx\n",
  952. (unsigned long) rxfd->rfs);
  953. /* Increment general receive error statistic. */
  954. sp->stats.rx_errors++;
  955. /* Increment detailed receive error statistics. */
  956. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFIFOOVERRUN) {
  957. IPG_DEBUG_MSG("RX FIFO overrun occured.\n");
  958. sp->stats.rx_fifo_errors++;
  959. }
  960. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXRUNTFRAME) {
  961. IPG_DEBUG_MSG("RX runt occured.\n");
  962. sp->stats.rx_length_errors++;
  963. }
  964. /* Do nothing for IPG_RFS_RXOVERSIZEDFRAME,
  965. * error count handled by a IPG statistic register.
  966. */
  967. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXALIGNMENTERROR) {
  968. IPG_DEBUG_MSG("RX alignment error occured.\n");
  969. sp->stats.rx_frame_errors++;
  970. }
  971. /* Do nothing for IPG_RFS_RXFCSERROR, error count
  972. * handled by a IPG statistic register.
  973. */
  974. /* Free the memory associated with the RX
  975. * buffer since it is erroneous and we will
  976. * not pass it to higher layer processes.
  977. */
  978. if (sp->RxBuff[entry]) {
  979. pci_unmap_single(sp->pdev,
  980. le64_to_cpu(rxfd->frag_info & ~IPG_RFI_FRAGLEN),
  981. sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
  982. IPG_DEV_KFREE_SKB(sp->RxBuff[entry]);
  983. sp->RxBuff[entry] = NULL;
  984. }
  985. return ErrorPacket;
  986. }
  987. return NormalPacket;
  988. }
  989. static void ipg_nic_rx_with_start_and_end(struct net_device *dev,
  990. struct ipg_nic_private *sp,
  991. struct ipg_rx *rxfd, unsigned entry)
  992. {
  993. struct SJumbo *jumbo = &sp->Jumbo;
  994. struct sk_buff *skb;
  995. int framelen;
  996. if (jumbo->FoundStart) {
  997. IPG_DEV_KFREE_SKB(jumbo->skb);
  998. jumbo->FoundStart = 0;
  999. jumbo->CurrentSize = 0;
  1000. jumbo->skb = NULL;
  1001. }
  1002. // 1: found error, 0 no error
  1003. if (ipg_nic_rx_check_error(dev) != NormalPacket)
  1004. return;
  1005. skb = sp->RxBuff[entry];
  1006. if (!skb)
  1007. return;
  1008. // accept this frame and send to upper layer
  1009. framelen = le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFRAMELEN;
  1010. if (framelen > IPG_RXFRAG_SIZE)
  1011. framelen = IPG_RXFRAG_SIZE;
  1012. skb_put(skb, framelen);
  1013. skb->protocol = eth_type_trans(skb, dev);
  1014. skb->ip_summed = CHECKSUM_NONE;
  1015. netif_rx(skb);
  1016. dev->last_rx = jiffies;
  1017. sp->RxBuff[entry] = NULL;
  1018. }
  1019. static void ipg_nic_rx_with_start(struct net_device *dev,
  1020. struct ipg_nic_private *sp,
  1021. struct ipg_rx *rxfd, unsigned entry)
  1022. {
  1023. struct SJumbo *jumbo = &sp->Jumbo;
  1024. struct pci_dev *pdev = sp->pdev;
  1025. struct sk_buff *skb;
  1026. // 1: found error, 0 no error
  1027. if (ipg_nic_rx_check_error(dev) != NormalPacket)
  1028. return;
  1029. // accept this frame and send to upper layer
  1030. skb = sp->RxBuff[entry];
  1031. if (!skb)
  1032. return;
  1033. if (jumbo->FoundStart)
  1034. IPG_DEV_KFREE_SKB(jumbo->skb);
  1035. pci_unmap_single(pdev, le64_to_cpu(rxfd->frag_info & ~IPG_RFI_FRAGLEN),
  1036. sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
  1037. skb_put(skb, IPG_RXFRAG_SIZE);
  1038. jumbo->FoundStart = 1;
  1039. jumbo->CurrentSize = IPG_RXFRAG_SIZE;
  1040. jumbo->skb = skb;
  1041. sp->RxBuff[entry] = NULL;
  1042. dev->last_rx = jiffies;
  1043. }
  1044. static void ipg_nic_rx_with_end(struct net_device *dev,
  1045. struct ipg_nic_private *sp,
  1046. struct ipg_rx *rxfd, unsigned entry)
  1047. {
  1048. struct SJumbo *jumbo = &sp->Jumbo;
  1049. //1: found error, 0 no error
  1050. if (ipg_nic_rx_check_error(dev) == NormalPacket) {
  1051. struct sk_buff *skb = sp->RxBuff[entry];
  1052. if (!skb)
  1053. return;
  1054. if (jumbo->FoundStart) {
  1055. int framelen, endframelen;
  1056. framelen = le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFRAMELEN;
  1057. endframeLen = framelen - jumbo->CurrentSize;
  1058. /*
  1059. if (framelen > IPG_RXFRAG_SIZE)
  1060. framelen=IPG_RXFRAG_SIZE;
  1061. */
  1062. if (framelen > IPG_RXSUPPORT_SIZE)
  1063. IPG_DEV_KFREE_SKB(jumbo->skb);
  1064. else {
  1065. memcpy(skb_put(jumbo->skb, endframeLen),
  1066. skb->data, endframeLen);
  1067. jumbo->skb->protocol =
  1068. eth_type_trans(jumbo->skb, dev);
  1069. jumbo->skb->ip_summed = CHECKSUM_NONE;
  1070. netif_rx(jumbo->skb);
  1071. }
  1072. }
  1073. dev->last_rx = jiffies;
  1074. jumbo->FoundStart = 0;
  1075. jumbo->CurrentSize = 0;
  1076. jumbo->skb = NULL;
  1077. ipg_nic_rx_free_skb(dev);
  1078. } else {
  1079. IPG_DEV_KFREE_SKB(jumbo->skb);
  1080. jumbo->FoundStart = 0;
  1081. jumbo->CurrentSize = 0;
  1082. jumbo->skb = NULL;
  1083. }
  1084. }
  1085. static void ipg_nic_rx_no_start_no_end(struct net_device *dev,
  1086. struct ipg_nic_private *sp,
  1087. struct ipg_rx *rxfd, unsigned entry)
  1088. {
  1089. struct SJumbo *jumbo = &sp->Jumbo;
  1090. //1: found error, 0 no error
  1091. if (ipg_nic_rx_check_error(dev) == NormalPacket) {
  1092. struct sk_buff *skb = sp->RxBuff[entry];
  1093. if (skb) {
  1094. if (jumbo->FoundStart) {
  1095. jumbo->CurrentSize += IPG_RXFRAG_SIZE;
  1096. if (jumbo->CurrentSize <= IPG_RXSUPPORT_SIZE) {
  1097. memcpy(skb_put(jumbo->skb,
  1098. IPG_RXFRAG_SIZE),
  1099. skb->data, IPG_RXFRAG_SIZE);
  1100. }
  1101. }
  1102. dev->last_rx = jiffies;
  1103. ipg_nic_rx_free_skb(dev);
  1104. }
  1105. } else {
  1106. IPG_DEV_KFREE_SKB(jumbo->skb);
  1107. jumbo->FoundStart = 0;
  1108. jumbo->CurrentSize = 0;
  1109. jumbo->skb = NULL;
  1110. }
  1111. }
  1112. static int ipg_nic_rx(struct net_device *dev)
  1113. {
  1114. struct ipg_nic_private *sp = netdev_priv(dev);
  1115. unsigned int curr = sp->rx_current;
  1116. void __iomem *ioaddr = sp->ioaddr;
  1117. unsigned int i;
  1118. IPG_DEBUG_MSG("_nic_rx\n");
  1119. for (i = 0; i < IPG_MAXRFDPROCESS_COUNT; i++, curr++) {
  1120. unsigned int entry = curr % IPG_RFDLIST_LENGTH;
  1121. struct ipg_rx *rxfd = sp->rxd + entry;
  1122. if (!(rxfd->rfs & le64_to_cpu(IPG_RFS_RFDDONE)))
  1123. break;
  1124. switch (ipg_nic_rx_check_frame_type(dev)) {
  1125. case Frame_WithStart_WithEnd:
  1126. ipg_nic_rx_with_start_and_end(dev, tp, rxfd, entry);
  1127. break;
  1128. case Frame_WithStart:
  1129. ipg_nic_rx_with_start(dev, tp, rxfd, entry);
  1130. break;
  1131. case Frame_WithEnd:
  1132. ipg_nic_rx_with_end(dev, tp, rxfd, entry);
  1133. break;
  1134. case Frame_NoStart_NoEnd:
  1135. ipg_nic_rx_no_start_no_end(dev, tp, rxfd, entry);
  1136. break;
  1137. }
  1138. }
  1139. sp->rx_current = curr;
  1140. if (i == IPG_MAXRFDPROCESS_COUNT) {
  1141. /* There are more RFDs to process, however the
  1142. * allocated amount of RFD processing time has
  1143. * expired. Assert Interrupt Requested to make
  1144. * sure we come back to process the remaining RFDs.
  1145. */
  1146. ipg_w32(ipg_r32(ASIC_CTRL) | IPG_AC_INT_REQUEST, ASIC_CTRL);
  1147. }
  1148. ipg_nic_rxrestore(dev);
  1149. return 0;
  1150. }
  1151. #else
  1152. static int ipg_nic_rx(struct net_device *dev)
  1153. {
  1154. /* Transfer received Ethernet frames to higher network layers. */
  1155. struct ipg_nic_private *sp = netdev_priv(dev);
  1156. unsigned int curr = sp->rx_current;
  1157. void __iomem *ioaddr = sp->ioaddr;
  1158. struct ipg_rx *rxfd;
  1159. unsigned int i;
  1160. IPG_DEBUG_MSG("_nic_rx\n");
  1161. #define __RFS_MASK \
  1162. cpu_to_le64(IPG_RFS_RFDDONE | IPG_RFS_FRAMESTART | IPG_RFS_FRAMEEND)
  1163. for (i = 0; i < IPG_MAXRFDPROCESS_COUNT; i++, curr++) {
  1164. unsigned int entry = curr % IPG_RFDLIST_LENGTH;
  1165. struct sk_buff *skb = sp->RxBuff[entry];
  1166. unsigned int framelen;
  1167. rxfd = sp->rxd + entry;
  1168. if (((rxfd->rfs & __RFS_MASK) != __RFS_MASK) || !skb)
  1169. break;
  1170. /* Get received frame length. */
  1171. framelen = le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFRAMELEN;
  1172. /* Check for jumbo frame arrival with too small
  1173. * RXFRAG_SIZE.
  1174. */
  1175. if (framelen > IPG_RXFRAG_SIZE) {
  1176. IPG_DEBUG_MSG
  1177. ("RFS FrameLen > allocated fragment size.\n");
  1178. framelen = IPG_RXFRAG_SIZE;
  1179. }
  1180. if ((IPG_DROP_ON_RX_ETH_ERRORS && (le64_to_cpu(rxfd->rfs) &
  1181. (IPG_RFS_RXFIFOOVERRUN | IPG_RFS_RXRUNTFRAME |
  1182. IPG_RFS_RXALIGNMENTERROR | IPG_RFS_RXFCSERROR |
  1183. IPG_RFS_RXOVERSIZEDFRAME | IPG_RFS_RXLENGTHERROR)))) {
  1184. IPG_DEBUG_MSG("Rx error, RFS = %16.16lx\n",
  1185. (unsigned long int) rxfd->rfs);
  1186. /* Increment general receive error statistic. */
  1187. sp->stats.rx_errors++;
  1188. /* Increment detailed receive error statistics. */
  1189. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFIFOOVERRUN) {
  1190. IPG_DEBUG_MSG("RX FIFO overrun occured.\n");
  1191. sp->stats.rx_fifo_errors++;
  1192. }
  1193. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXRUNTFRAME) {
  1194. IPG_DEBUG_MSG("RX runt occured.\n");
  1195. sp->stats.rx_length_errors++;
  1196. }
  1197. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXOVERSIZEDFRAME) ;
  1198. /* Do nothing, error count handled by a IPG
  1199. * statistic register.
  1200. */
  1201. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXALIGNMENTERROR) {
  1202. IPG_DEBUG_MSG("RX alignment error occured.\n");
  1203. sp->stats.rx_frame_errors++;
  1204. }
  1205. if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFCSERROR) ;
  1206. /* Do nothing, error count handled by a IPG
  1207. * statistic register.
  1208. */
  1209. /* Free the memory associated with the RX
  1210. * buffer since it is erroneous and we will
  1211. * not pass it to higher layer processes.
  1212. */
  1213. if (skb) {
  1214. __le64 info = rxfd->frag_info;
  1215. pci_unmap_single(sp->pdev,
  1216. le64_to_cpu(info) & ~IPG_RFI_FRAGLEN,
  1217. sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
  1218. IPG_DEV_KFREE_SKB(skb);
  1219. }
  1220. } else {
  1221. /* Adjust the new buffer length to accomodate the size
  1222. * of the received frame.
  1223. */
  1224. skb_put(skb, framelen);
  1225. /* Set the buffer's protocol field to Ethernet. */
  1226. skb->protocol = eth_type_trans(skb, dev);
  1227. /* If the frame contains an IP/TCP/UDP frame,
  1228. * determine if upper layer must check IP/TCP/UDP
  1229. * checksums.
  1230. *
  1231. * NOTE: DO NOT RELY ON THE TCP/UDP CHECKSUM
  1232. * VERIFICATION FOR SILICON REVISIONS B3
  1233. * AND EARLIER!
  1234. *
  1235. if ((le64_to_cpu(rxfd->rfs &
  1236. (IPG_RFS_TCPDETECTED | IPG_RFS_UDPDETECTED |
  1237. IPG_RFS_IPDETECTED))) &&
  1238. !(le64_to_cpu(rxfd->rfs &
  1239. (IPG_RFS_TCPERROR | IPG_RFS_UDPERROR |
  1240. IPG_RFS_IPERROR)))) {
  1241. * Indicate IP checksums were performed
  1242. * by the IPG.
  1243. *
  1244. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1245. } else
  1246. */
  1247. {
  1248. /* The IPG encountered an error with (or
  1249. * there were no) IP/TCP/UDP checksums.
  1250. * This may or may not indicate an invalid
  1251. * IP/TCP/UDP frame was received. Let the
  1252. * upper layer decide.
  1253. */
  1254. skb->ip_summed = CHECKSUM_NONE;
  1255. }
  1256. /* Hand off frame for higher layer processing.
  1257. * The function netif_rx() releases the sk_buff
  1258. * when processing completes.
  1259. */
  1260. netif_rx(skb);
  1261. /* Record frame receive time (jiffies = Linux
  1262. * kernel current time stamp).
  1263. */
  1264. dev->last_rx = jiffies;
  1265. }
  1266. /* Assure RX buffer is not reused by IPG. */
  1267. sp->RxBuff[entry] = NULL;
  1268. }
  1269. /*
  1270. * If there are more RFDs to proces and the allocated amount of RFD
  1271. * processing time has expired, assert Interrupt Requested to make
  1272. * sure we come back to process the remaining RFDs.
  1273. */
  1274. if (i == IPG_MAXRFDPROCESS_COUNT)
  1275. ipg_w32(ipg_r32(ASIC_CTRL) | IPG_AC_INT_REQUEST, ASIC_CTRL);
  1276. #ifdef IPG_DEBUG
  1277. /* Check if the RFD list contained no receive frame data. */
  1278. if (!i)
  1279. sp->EmptyRFDListCount++;
  1280. #endif
  1281. while ((le64_to_cpu(rxfd->rfs) & IPG_RFS_RFDDONE) &&
  1282. !((le64_to_cpu(rxfd->rfs) & IPG_RFS_FRAMESTART) &&
  1283. (le64_to_cpu(rxfd->rfs) & IPG_RFS_FRAMEEND))) {
  1284. unsigned int entry = curr++ % IPG_RFDLIST_LENGTH;
  1285. rxfd = sp->rxd + entry;
  1286. IPG_DEBUG_MSG("Frame requires multiple RFDs.\n");
  1287. /* An unexpected event, additional code needed to handle
  1288. * properly. So for the time being, just disregard the
  1289. * frame.
  1290. */
  1291. /* Free the memory associated with the RX
  1292. * buffer since it is erroneous and we will
  1293. * not pass it to higher layer processes.
  1294. */
  1295. if (sp->RxBuff[entry]) {
  1296. pci_unmap_single(sp->pdev,
  1297. le64_to_cpu(rxfd->frag_info) & ~IPG_RFI_FRAGLEN,
  1298. sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
  1299. IPG_DEV_KFREE_SKB(sp->RxBuff[entry]);
  1300. }
  1301. /* Assure RX buffer is not reused by IPG. */
  1302. sp->RxBuff[entry] = NULL;
  1303. }
  1304. sp->rx_current = curr;
  1305. /* Check to see if there are a minimum number of used
  1306. * RFDs before restoring any (should improve performance.)
  1307. */
  1308. if ((curr - sp->rx_dirty) >= IPG_MINUSEDRFDSTOFREE)
  1309. ipg_nic_rxrestore(dev);
  1310. return 0;
  1311. }
  1312. #endif
  1313. static void ipg_reset_after_host_error(struct work_struct *work)
  1314. {
  1315. struct ipg_nic_private *sp =
  1316. container_of(work, struct ipg_nic_private, task.work);
  1317. struct net_device *dev = sp->dev;
  1318. IPG_DDEBUG_MSG("DMACtrl = %8.8x\n", ioread32(sp->ioaddr + IPG_DMACTRL));
  1319. /*
  1320. * Acknowledge HostError interrupt by resetting
  1321. * IPG DMA and HOST.
  1322. */
  1323. ipg_reset(dev, IPG_AC_GLOBAL_RESET | IPG_AC_HOST | IPG_AC_DMA);
  1324. init_rfdlist(dev);
  1325. init_tfdlist(dev);
  1326. if (ipg_io_config(dev) < 0) {
  1327. printk(KERN_INFO "%s: Cannot recover from PCI error.\n",
  1328. dev->name);
  1329. schedule_delayed_work(&sp->task, HZ);
  1330. }
  1331. }
  1332. static irqreturn_t ipg_interrupt_handler(int irq, void *dev_inst)
  1333. {
  1334. struct net_device *dev = dev_inst;
  1335. struct ipg_nic_private *sp = netdev_priv(dev);
  1336. void __iomem *ioaddr = sp->ioaddr;
  1337. unsigned int handled = 0;
  1338. u16 status;
  1339. IPG_DEBUG_MSG("_interrupt_handler\n");
  1340. #ifdef JUMBO_FRAME
  1341. ipg_nic_rxrestore(dev);
  1342. #endif
  1343. spin_lock(&sp->lock);
  1344. /* Get interrupt source information, and acknowledge
  1345. * some (i.e. TxDMAComplete, RxDMAComplete, RxEarly,
  1346. * IntRequested, MacControlFrame, LinkEvent) interrupts
  1347. * if issued. Also, all IPG interrupts are disabled by
  1348. * reading IntStatusAck.
  1349. */
  1350. status = ipg_r16(INT_STATUS_ACK);
  1351. IPG_DEBUG_MSG("IntStatusAck = %4.4x\n", status);
  1352. /* Shared IRQ of remove event. */
  1353. if (!(status & IPG_IS_RSVD_MASK))
  1354. goto out_enable;
  1355. handled = 1;
  1356. if (unlikely(!netif_running(dev)))
  1357. goto out_unlock;
  1358. /* If RFDListEnd interrupt, restore all used RFDs. */
  1359. if (status & IPG_IS_RFD_LIST_END) {
  1360. IPG_DEBUG_MSG("RFDListEnd Interrupt.\n");
  1361. /* The RFD list end indicates an RFD was encountered
  1362. * with a 0 NextPtr, or with an RFDDone bit set to 1
  1363. * (indicating the RFD is not read for use by the
  1364. * IPG.) Try to restore all RFDs.
  1365. */
  1366. ipg_nic_rxrestore(dev);
  1367. #ifdef IPG_DEBUG
  1368. /* Increment the RFDlistendCount counter. */
  1369. sp->RFDlistendCount++;
  1370. #endif
  1371. }
  1372. /* If RFDListEnd, RxDMAPriority, RxDMAComplete, or
  1373. * IntRequested interrupt, process received frames. */
  1374. if ((status & IPG_IS_RX_DMA_PRIORITY) ||
  1375. (status & IPG_IS_RFD_LIST_END) ||
  1376. (status & IPG_IS_RX_DMA_COMPLETE) ||
  1377. (status & IPG_IS_INT_REQUESTED)) {
  1378. #ifdef IPG_DEBUG
  1379. /* Increment the RFD list checked counter if interrupted
  1380. * only to check the RFD list. */
  1381. if (status & (~(IPG_IS_RX_DMA_PRIORITY | IPG_IS_RFD_LIST_END |
  1382. IPG_IS_RX_DMA_COMPLETE | IPG_IS_INT_REQUESTED) &
  1383. (IPG_IS_HOST_ERROR | IPG_IS_TX_DMA_COMPLETE |
  1384. IPG_IS_LINK_EVENT | IPG_IS_TX_COMPLETE |
  1385. IPG_IS_UPDATE_STATS)))
  1386. sp->RFDListCheckedCount++;
  1387. #endif
  1388. ipg_nic_rx(dev);
  1389. }
  1390. /* If TxDMAComplete interrupt, free used TFDs. */
  1391. if (status & IPG_IS_TX_DMA_COMPLETE)
  1392. ipg_nic_txfree(dev);
  1393. /* TxComplete interrupts indicate one of numerous actions.
  1394. * Determine what action to take based on TXSTATUS register.
  1395. */
  1396. if (status & IPG_IS_TX_COMPLETE)
  1397. ipg_nic_txcleanup(dev);
  1398. /* If UpdateStats interrupt, update Linux Ethernet statistics */
  1399. if (status & IPG_IS_UPDATE_STATS)
  1400. ipg_nic_get_stats(dev);
  1401. /* If HostError interrupt, reset IPG. */
  1402. if (status & IPG_IS_HOST_ERROR) {
  1403. IPG_DDEBUG_MSG("HostError Interrupt\n");
  1404. schedule_delayed_work(&sp->task, 0);
  1405. }
  1406. /* If LinkEvent interrupt, resolve autonegotiation. */
  1407. if (status & IPG_IS_LINK_EVENT) {
  1408. if (ipg_config_autoneg(dev) < 0)
  1409. printk(KERN_INFO "%s: Auto-negotiation error.\n",
  1410. dev->name);
  1411. }
  1412. /* If MACCtrlFrame interrupt, do nothing. */
  1413. if (status & IPG_IS_MAC_CTRL_FRAME)
  1414. IPG_DEBUG_MSG("MACCtrlFrame interrupt.\n");
  1415. /* If RxComplete interrupt, do nothing. */
  1416. if (status & IPG_IS_RX_COMPLETE)
  1417. IPG_DEBUG_MSG("RxComplete interrupt.\n");
  1418. /* If RxEarly interrupt, do nothing. */
  1419. if (status & IPG_IS_RX_EARLY)
  1420. IPG_DEBUG_MSG("RxEarly interrupt.\n");
  1421. out_enable:
  1422. /* Re-enable IPG interrupts. */
  1423. ipg_w16(IPG_IE_TX_DMA_COMPLETE | IPG_IE_RX_DMA_COMPLETE |
  1424. IPG_IE_HOST_ERROR | IPG_IE_INT_REQUESTED | IPG_IE_TX_COMPLETE |
  1425. IPG_IE_LINK_EVENT | IPG_IE_UPDATE_STATS, INT_ENABLE);
  1426. out_unlock:
  1427. spin_unlock(&sp->lock);
  1428. return IRQ_RETVAL(handled);
  1429. }
  1430. static void ipg_rx_clear(struct ipg_nic_private *sp)
  1431. {
  1432. unsigned int i;
  1433. for (i = 0; i < IPG_RFDLIST_LENGTH; i++) {
  1434. if (sp->RxBuff[i]) {
  1435. struct ipg_rx *rxfd = sp->rxd + i;
  1436. IPG_DEV_KFREE_SKB(sp->RxBuff[i]);
  1437. sp->RxBuff[i] = NULL;
  1438. pci_unmap_single(sp->pdev,
  1439. le64_to_cpu(rxfd->frag_info) & ~IPG_RFI_FRAGLEN,
  1440. sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
  1441. }
  1442. }
  1443. }
  1444. static void ipg_tx_clear(struct ipg_nic_private *sp)
  1445. {
  1446. unsigned int i;
  1447. for (i = 0; i < IPG_TFDLIST_LENGTH; i++) {
  1448. if (sp->TxBuff[i]) {
  1449. struct ipg_tx *txfd = sp->txd + i;
  1450. pci_unmap_single(sp->pdev,
  1451. le64_to_cpu(txfd->frag_info) & ~IPG_TFI_FRAGLEN,
  1452. sp->TxBuff[i]->len, PCI_DMA_TODEVICE);
  1453. IPG_DEV_KFREE_SKB(sp->TxBuff[i]);
  1454. sp->TxBuff[i] = NULL;
  1455. }
  1456. }
  1457. }
  1458. static int ipg_nic_open(struct net_device *dev)
  1459. {
  1460. struct ipg_nic_private *sp = netdev_priv(dev);
  1461. void __iomem *ioaddr = sp->ioaddr;
  1462. struct pci_dev *pdev = sp->pdev;
  1463. int rc;
  1464. IPG_DEBUG_MSG("_nic_open\n");
  1465. sp->rx_buf_sz = IPG_RXSUPPORT_SIZE;
  1466. /* Check for interrupt line conflicts, and request interrupt
  1467. * line for IPG.
  1468. *
  1469. * IMPORTANT: Disable IPG interrupts prior to registering
  1470. * IRQ.
  1471. */
  1472. ipg_w16(0x0000, INT_ENABLE);
  1473. /* Register the interrupt line to be used by the IPG within
  1474. * the Linux system.
  1475. */
  1476. rc = request_irq(pdev->irq, &ipg_interrupt_handler, IRQF_SHARED,
  1477. dev->name, dev);
  1478. if (rc < 0) {
  1479. printk(KERN_INFO "%s: Error when requesting interrupt.\n",
  1480. dev->name);
  1481. goto out;
  1482. }
  1483. dev->irq = pdev->irq;
  1484. rc = -ENOMEM;
  1485. sp->rxd = dma_alloc_coherent(&pdev->dev, IPG_RX_RING_BYTES,
  1486. &sp->rxd_map, GFP_KERNEL);
  1487. if (!sp->rxd)
  1488. goto err_free_irq_0;
  1489. sp->txd = dma_alloc_coherent(&pdev->dev, IPG_TX_RING_BYTES,
  1490. &sp->txd_map, GFP_KERNEL);
  1491. if (!sp->txd)
  1492. goto err_free_rx_1;
  1493. rc = init_rfdlist(dev);
  1494. if (rc < 0) {
  1495. printk(KERN_INFO "%s: Error during configuration.\n",
  1496. dev->name);
  1497. goto err_free_tx_2;
  1498. }
  1499. init_tfdlist(dev);
  1500. rc = ipg_io_config(dev);
  1501. if (rc < 0) {
  1502. printk(KERN_INFO "%s: Error during configuration.\n",
  1503. dev->name);
  1504. goto err_release_tfdlist_3;
  1505. }
  1506. /* Resolve autonegotiation. */
  1507. if (ipg_config_autoneg(dev) < 0)
  1508. printk(KERN_INFO "%s: Auto-negotiation error.\n", dev->name);
  1509. #ifdef JUMBO_FRAME
  1510. /* initialize JUMBO Frame control variable */
  1511. sp->Jumbo.FoundStart = 0;
  1512. sp->Jumbo.CurrentSize = 0;
  1513. sp->Jumbo.skb = 0;
  1514. dev->mtu = IPG_TXFRAG_SIZE;
  1515. #endif
  1516. /* Enable transmit and receive operation of the IPG. */
  1517. ipg_w32((ipg_r32(MAC_CTRL) | IPG_MC_RX_ENABLE | IPG_MC_TX_ENABLE) &
  1518. IPG_MC_RSVD_MASK, MAC_CTRL);
  1519. netif_start_queue(dev);
  1520. out:
  1521. return rc;
  1522. err_release_tfdlist_3:
  1523. ipg_tx_clear(sp);
  1524. ipg_rx_clear(sp);
  1525. err_free_tx_2:
  1526. dma_free_coherent(&pdev->dev, IPG_TX_RING_BYTES, sp->txd, sp->txd_map);
  1527. err_free_rx_1:
  1528. dma_free_coherent(&pdev->dev, IPG_RX_RING_BYTES, sp->rxd, sp->rxd_map);
  1529. err_free_irq_0:
  1530. free_irq(pdev->irq, dev);
  1531. goto out;
  1532. }
  1533. static int ipg_nic_stop(struct net_device *dev)
  1534. {
  1535. struct ipg_nic_private *sp = netdev_priv(dev);
  1536. void __iomem *ioaddr = sp->ioaddr;
  1537. struct pci_dev *pdev = sp->pdev;
  1538. IPG_DEBUG_MSG("_nic_stop\n");
  1539. netif_stop_queue(dev);
  1540. IPG_DDEBUG_MSG("RFDlistendCount = %i\n", sp->RFDlistendCount);
  1541. IPG_DDEBUG_MSG("RFDListCheckedCount = %i\n", sp->rxdCheckedCount);
  1542. IPG_DDEBUG_MSG("EmptyRFDListCount = %i\n", sp->EmptyRFDListCount);
  1543. IPG_DUMPTFDLIST(dev);
  1544. do {
  1545. (void) ipg_r16(INT_STATUS_ACK);
  1546. ipg_reset(dev, IPG_AC_GLOBAL_RESET | IPG_AC_HOST | IPG_AC_DMA);
  1547. synchronize_irq(pdev->irq);
  1548. } while (ipg_r16(INT_ENABLE) & IPG_IE_RSVD_MASK);
  1549. ipg_rx_clear(sp);
  1550. ipg_tx_clear(sp);
  1551. pci_free_consistent(pdev, IPG_RX_RING_BYTES, sp->rxd, sp->rxd_map);
  1552. pci_free_consistent(pdev, IPG_TX_RING_BYTES, sp->txd, sp->txd_map);
  1553. free_irq(pdev->irq, dev);
  1554. return 0;
  1555. }
  1556. static int ipg_nic_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
  1557. {
  1558. struct ipg_nic_private *sp = netdev_priv(dev);
  1559. void __iomem *ioaddr = sp->ioaddr;
  1560. unsigned int entry = sp->tx_current % IPG_TFDLIST_LENGTH;
  1561. unsigned long flags;
  1562. struct ipg_tx *txfd;
  1563. IPG_DDEBUG_MSG("_nic_hard_start_xmit\n");
  1564. /* If in 10Mbps mode, stop the transmit queue so
  1565. * no more transmit frames are accepted.
  1566. */
  1567. if (sp->tenmbpsmode)
  1568. netif_stop_queue(dev);
  1569. if (sp->ResetCurrentTFD) {
  1570. sp->ResetCurrentTFD = 0;
  1571. entry = 0;
  1572. }
  1573. txfd = sp->txd + entry;
  1574. sp->TxBuff[entry] = skb;
  1575. /* Clear all TFC fields, except TFDDONE. */
  1576. txfd->tfc = cpu_to_le64(IPG_TFC_TFDDONE);
  1577. /* Specify the TFC field within the TFD. */
  1578. txfd->tfc |= cpu_to_le64(IPG_TFC_WORDALIGNDISABLED |
  1579. (IPG_TFC_FRAMEID & cpu_to_le64(sp->tx_current)) |
  1580. (IPG_TFC_FRAGCOUNT & (1 << 24)));
  1581. /* Request TxComplete interrupts at an interval defined
  1582. * by the constant IPG_FRAMESBETWEENTXCOMPLETES.
  1583. * Request TxComplete interrupt for every frame
  1584. * if in 10Mbps mode to accomodate problem with 10Mbps
  1585. * processing.
  1586. */
  1587. if (sp->tenmbpsmode)
  1588. txfd->tfc |= cpu_to_le64(IPG_TFC_TXINDICATE);
  1589. else if (!((sp->tx_current - sp->tx_dirty + 1) >
  1590. IPG_FRAMESBETWEENTXDMACOMPLETES)) {
  1591. txfd->tfc |= cpu_to_le64(IPG_TFC_TXDMAINDICATE);
  1592. }
  1593. /* Based on compilation option, determine if FCS is to be
  1594. * appended to transmit frame by IPG.
  1595. */
  1596. if (!(IPG_APPEND_FCS_ON_TX))
  1597. txfd->tfc |= cpu_to_le64(IPG_TFC_FCSAPPENDDISABLE);
  1598. /* Based on compilation option, determine if IP, TCP and/or
  1599. * UDP checksums are to be added to transmit frame by IPG.
  1600. */
  1601. if (IPG_ADD_IPCHECKSUM_ON_TX)
  1602. txfd->tfc |= cpu_to_le64(IPG_TFC_IPCHECKSUMENABLE);
  1603. if (IPG_ADD_TCPCHECKSUM_ON_TX)
  1604. txfd->tfc |= cpu_to_le64(IPG_TFC_TCPCHECKSUMENABLE);
  1605. if (IPG_ADD_UDPCHECKSUM_ON_TX)
  1606. txfd->tfc |= cpu_to_le64(IPG_TFC_UDPCHECKSUMENABLE);
  1607. /* Based on compilation option, determine if VLAN tag info is to be
  1608. * inserted into transmit frame by IPG.
  1609. */
  1610. if (IPG_INSERT_MANUAL_VLAN_TAG) {
  1611. txfd->tfc |= cpu_to_le64(IPG_TFC_VLANTAGINSERT |
  1612. ((u64) IPG_MANUAL_VLAN_VID << 32) |
  1613. ((u64) IPG_MANUAL_VLAN_CFI << 44) |
  1614. ((u64) IPG_MANUAL_VLAN_USERPRIORITY << 45));
  1615. }
  1616. /* The fragment start location within system memory is defined
  1617. * by the sk_buff structure's data field. The physical address
  1618. * of this location within the system's virtual memory space
  1619. * is determined using the IPG_HOST2BUS_MAP function.
  1620. */
  1621. txfd->frag_info = cpu_to_le64(pci_map_single(sp->pdev, skb->data,
  1622. skb->len, PCI_DMA_TODEVICE));
  1623. /* The length of the fragment within system memory is defined by
  1624. * the sk_buff structure's len field.
  1625. */
  1626. txfd->frag_info |= cpu_to_le64(IPG_TFI_FRAGLEN &
  1627. ((u64) (skb->len & 0xffff) << 48));
  1628. /* Clear the TFDDone bit last to indicate the TFD is ready
  1629. * for transfer to the IPG.
  1630. */
  1631. txfd->tfc &= cpu_to_le64(~IPG_TFC_TFDDONE);
  1632. spin_lock_irqsave(&sp->lock, flags);
  1633. sp->tx_current++;
  1634. mmiowb();
  1635. ipg_w32(IPG_DC_TX_DMA_POLL_NOW, DMA_CTRL);
  1636. if (sp->tx_current == (sp->tx_dirty + IPG_TFDLIST_LENGTH))
  1637. netif_wake_queue(dev);
  1638. spin_unlock_irqrestore(&sp->lock, flags);
  1639. return NETDEV_TX_OK;
  1640. }
  1641. static void ipg_set_phy_default_param(unsigned char rev,
  1642. struct net_device *dev, int phy_address)
  1643. {
  1644. unsigned short length;
  1645. unsigned char revision;
  1646. unsigned short *phy_param;
  1647. unsigned short address, value;
  1648. phy_param = &DefaultPhyParam[0];
  1649. length = *phy_param & 0x00FF;
  1650. revision = (unsigned char)((*phy_param) >> 8);
  1651. phy_param++;
  1652. while (length != 0) {
  1653. if (rev == revision) {
  1654. while (length > 1) {
  1655. address = *phy_param;
  1656. value = *(phy_param + 1);
  1657. phy_param += 2;
  1658. mdio_write(dev, phy_address, address, value);
  1659. length -= 4;
  1660. }
  1661. break;
  1662. } else {
  1663. phy_param += length / 2;
  1664. length = *phy_param & 0x00FF;
  1665. revision = (unsigned char)((*phy_param) >> 8);
  1666. phy_param++;
  1667. }
  1668. }
  1669. }
  1670. /* JES20040127EEPROM */
  1671. static int read_eeprom(struct net_device *dev, int eep_addr)
  1672. {
  1673. void __iomem *ioaddr = ipg_ioaddr(dev);
  1674. unsigned int i;
  1675. int ret = 0;
  1676. u16 value;
  1677. value = IPG_EC_EEPROM_READOPCODE | (eep_addr & 0xff);
  1678. ipg_w16(value, EEPROM_CTRL);
  1679. for (i = 0; i < 1000; i++) {
  1680. u16 data;
  1681. mdelay(10);
  1682. data = ipg_r16(EEPROM_CTRL);
  1683. if (!(data & IPG_EC_EEPROM_BUSY)) {
  1684. ret = ipg_r16(EEPROM_DATA);
  1685. break;
  1686. }
  1687. }
  1688. return ret;
  1689. }
  1690. static void ipg_init_mii(struct net_device *dev)
  1691. {
  1692. struct ipg_nic_private *sp = netdev_priv(dev);
  1693. struct mii_if_info *mii_if = &sp->mii_if;
  1694. int phyaddr;
  1695. mii_if->dev = dev;
  1696. mii_if->mdio_read = mdio_read;
  1697. mii_if->mdio_write = mdio_write;
  1698. mii_if->phy_id_mask = 0x1f;
  1699. mii_if->reg_num_mask = 0x1f;
  1700. mii_if->phy_id = phyaddr = ipg_find_phyaddr(dev);
  1701. if (phyaddr != 0x1f) {
  1702. u16 mii_phyctrl, mii_1000cr;
  1703. u8 revisionid = 0;
  1704. mii_1000cr = mdio_read(dev, phyaddr, MII_CTRL1000);
  1705. mii_1000cr |= ADVERTISE_1000FULL | ADVERTISE_1000HALF |
  1706. GMII_PHY_1000BASETCONTROL_PreferMaster;
  1707. mdio_write(dev, phyaddr, MII_CTRL1000, mii_1000cr);
  1708. mii_phyctrl = mdio_read(dev, phyaddr, MII_BMCR);
  1709. /* Set default phyparam */
  1710. pci_read_config_byte(sp->pdev, PCI_REVISION_ID, &revisionid);
  1711. ipg_set_phy_default_param(revisionid, dev, phyaddr);
  1712. /* Reset PHY */
  1713. mii_phyctrl |= BMCR_RESET | BMCR_ANRESTART;
  1714. mdio_write(dev, phyaddr, MII_BMCR, mii_phyctrl);
  1715. }
  1716. }
  1717. static int ipg_hw_init(struct net_device *dev)
  1718. {
  1719. struct ipg_nic_private *sp = netdev_priv(dev);
  1720. void __iomem *ioaddr = sp->ioaddr;
  1721. unsigned int i;
  1722. int rc;
  1723. /* Read/Write and Reset EEPROM Value Jesse20040128EEPROM_VALUE */
  1724. /* Read LED Mode Configuration from EEPROM */
  1725. sp->LED_Mode = read_eeprom(dev, 6);
  1726. /* Reset all functions within the IPG. Do not assert
  1727. * RST_OUT as not compatible with some PHYs.
  1728. */
  1729. rc = ipg_reset(dev, IPG_RESET_MASK);
  1730. if (rc < 0)
  1731. goto out;
  1732. ipg_init_mii(dev);
  1733. /* Read MAC Address from EEPROM */
  1734. for (i = 0; i < 3; i++)
  1735. sp->station_addr[i] = read_eeprom(dev, 16 + i);
  1736. for (i = 0; i < 3; i++)
  1737. ipg_w16(sp->station_addr[i], STATION_ADDRESS_0 + 2*i);
  1738. /* Set station address in ethernet_device structure. */
  1739. dev->dev_addr[0] = ipg_r16(STATION_ADDRESS_0) & 0x00ff;
  1740. dev->dev_addr[1] = (ipg_r16(STATION_ADDRESS_0) & 0xff00) >> 8;
  1741. dev->dev_addr[2] = ipg_r16(STATION_ADDRESS_1) & 0x00ff;
  1742. dev->dev_addr[3] = (ipg_r16(STATION_ADDRESS_1) & 0xff00) >> 8;
  1743. dev->dev_addr[4] = ipg_r16(STATION_ADDRESS_2) & 0x00ff;
  1744. dev->dev_addr[5] = (ipg_r16(STATION_ADDRESS_2) & 0xff00) >> 8;
  1745. out:
  1746. return rc;
  1747. }
  1748. static int ipg_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  1749. {
  1750. struct ipg_nic_private *sp = netdev_priv(dev);
  1751. int rc;
  1752. mutex_lock(&sp->mii_mutex);
  1753. rc = generic_mii_ioctl(&sp->mii_if, if_mii(ifr), cmd, NULL);
  1754. mutex_unlock(&sp->mii_mutex);
  1755. return rc;
  1756. }
  1757. static int ipg_nic_change_mtu(struct net_device *dev, int new_mtu)
  1758. {
  1759. /* Function to accomodate changes to Maximum Transfer Unit
  1760. * (or MTU) of IPG NIC. Cannot use default function since
  1761. * the default will not allow for MTU > 1500 bytes.
  1762. */
  1763. IPG_DEBUG_MSG("_nic_change_mtu\n");
  1764. /* Check that the new MTU value is between 68 (14 byte header, 46
  1765. * byte payload, 4 byte FCS) and IPG_MAX_RXFRAME_SIZE, which
  1766. * corresponds to the MAXFRAMESIZE register in the IPG.
  1767. */
  1768. if ((new_mtu < 68) || (new_mtu > IPG_MAX_RXFRAME_SIZE))
  1769. return -EINVAL;
  1770. dev->mtu = new_mtu;
  1771. return 0;
  1772. }
  1773. static int ipg_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  1774. {
  1775. struct ipg_nic_private *sp = netdev_priv(dev);
  1776. int rc;
  1777. mutex_lock(&sp->mii_mutex);
  1778. rc = mii_ethtool_gset(&sp->mii_if, cmd);
  1779. mutex_unlock(&sp->mii_mutex);
  1780. return rc;
  1781. }
  1782. static int ipg_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  1783. {
  1784. struct ipg_nic_private *sp = netdev_priv(dev);
  1785. int rc;
  1786. mutex_lock(&sp->mii_mutex);
  1787. rc = mii_ethtool_sset(&sp->mii_if, cmd);
  1788. mutex_unlock(&sp->mii_mutex);
  1789. return rc;
  1790. }
  1791. static int ipg_nway_reset(struct net_device *dev)
  1792. {
  1793. struct ipg_nic_private *sp = netdev_priv(dev);
  1794. int rc;
  1795. mutex_lock(&sp->mii_mutex);
  1796. rc = mii_nway_restart(&sp->mii_if);
  1797. mutex_unlock(&sp->mii_mutex);
  1798. return rc;
  1799. }
  1800. static struct ethtool_ops ipg_ethtool_ops = {
  1801. .get_settings = ipg_get_settings,
  1802. .set_settings = ipg_set_settings,
  1803. .nway_reset = ipg_nway_reset,
  1804. };
  1805. static void ipg_remove(struct pci_dev *pdev)
  1806. {
  1807. struct net_device *dev = pci_get_drvdata(pdev);
  1808. struct ipg_nic_private *sp = netdev_priv(dev);
  1809. IPG_DEBUG_MSG("_remove\n");
  1810. /* Un-register Ethernet device. */
  1811. unregister_netdev(dev);
  1812. pci_iounmap(pdev, sp->ioaddr);
  1813. pci_release_regions(pdev);
  1814. free_netdev(dev);
  1815. pci_disable_device(pdev);
  1816. pci_set_drvdata(pdev, NULL);
  1817. }
  1818. static int __devinit ipg_probe(struct pci_dev *pdev,
  1819. const struct pci_device_id *id)
  1820. {
  1821. unsigned int i = id->driver_data;
  1822. struct ipg_nic_private *sp;
  1823. struct net_device *dev;
  1824. void __iomem *ioaddr;
  1825. int rc;
  1826. rc = pci_enable_device(pdev);
  1827. if (rc < 0)
  1828. goto out;
  1829. printk(KERN_INFO "%s: %s\n", pci_name(pdev), ipg_brand_name[i]);
  1830. pci_set_master(pdev);
  1831. rc = pci_set_dma_mask(pdev, DMA_40BIT_MASK);
  1832. if (rc < 0) {
  1833. rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  1834. if (rc < 0) {
  1835. printk(KERN_ERR "%s: DMA config failed.\n",
  1836. pci_name(pdev));
  1837. goto err_disable_0;
  1838. }
  1839. }
  1840. /*
  1841. * Initialize net device.
  1842. */
  1843. dev = alloc_etherdev(sizeof(struct ipg_nic_private));
  1844. if (!dev) {
  1845. printk(KERN_ERR "%s: alloc_etherdev failed\n", pci_name(pdev));
  1846. rc = -ENOMEM;
  1847. goto err_disable_0;
  1848. }
  1849. sp = netdev_priv(dev);
  1850. spin_lock_init(&sp->lock);
  1851. mutex_init(&sp->mii_mutex);
  1852. /* Declare IPG NIC functions for Ethernet device methods.
  1853. */
  1854. dev->open = &ipg_nic_open;
  1855. dev->stop = &ipg_nic_stop;
  1856. dev->hard_start_xmit = &ipg_nic_hard_start_xmit;
  1857. dev->get_stats = &ipg_nic_get_stats;
  1858. dev->set_multicast_list = &ipg_nic_set_multicast_list;
  1859. dev->do_ioctl = ipg_ioctl;
  1860. dev->tx_timeout = ipg_tx_timeout;
  1861. dev->change_mtu = &ipg_nic_change_mtu;
  1862. SET_NETDEV_DEV(dev, &pdev->dev);
  1863. SET_ETHTOOL_OPS(dev, &ipg_ethtool_ops);
  1864. rc = pci_request_regions(pdev, DRV_NAME);
  1865. if (rc)
  1866. goto err_free_dev_1;
  1867. ioaddr = pci_iomap(pdev, 1, pci_resource_len(pdev, 1));
  1868. if (!ioaddr) {
  1869. printk(KERN_ERR "%s cannot map MMIO\n", pci_name(pdev));
  1870. rc = -EIO;
  1871. goto err_release_regions_2;
  1872. }
  1873. /* Save the pointer to the PCI device information. */
  1874. sp->ioaddr = ioaddr;
  1875. sp->pdev = pdev;
  1876. sp->dev = dev;
  1877. INIT_DELAYED_WORK(&sp->task, ipg_reset_after_host_error);
  1878. pci_set_drvdata(pdev, dev);
  1879. rc = ipg_hw_init(dev);
  1880. if (rc < 0)
  1881. goto err_unmap_3;
  1882. rc = register_netdev(dev);
  1883. if (rc < 0)
  1884. goto err_unmap_3;
  1885. printk(KERN_INFO "Ethernet device registered as: %s\n", dev->name);
  1886. out:
  1887. return rc;
  1888. err_unmap_3:
  1889. pci_iounmap(pdev, ioaddr);
  1890. err_release_regions_2:
  1891. pci_release_regions(pdev);
  1892. err_free_dev_1:
  1893. free_netdev(dev);
  1894. err_disable_0:
  1895. pci_disable_device(pdev);
  1896. goto out;
  1897. }
  1898. static struct pci_driver ipg_pci_driver = {
  1899. .name = IPG_DRIVER_NAME,
  1900. .id_table = ipg_pci_tbl,
  1901. .probe = ipg_probe,
  1902. .remove = __devexit_p(ipg_remove),
  1903. };
  1904. static int __init ipg_init_module(void)
  1905. {
  1906. return pci_register_driver(&ipg_pci_driver);
  1907. }
  1908. static void __exit ipg_exit_module(void)
  1909. {
  1910. pci_unregister_driver(&ipg_pci_driver);
  1911. }
  1912. module_init(ipg_init_module);
  1913. module_exit(ipg_exit_module);