ipg.c 60 KB

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