ipg.c 61 KB

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