ipg.c 61 KB

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