ipg.c 60 KB

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