e1000_ethtool.c 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911
  1. /*******************************************************************************
  2. * Intel PRO/1000 Linux driver
  3. * Copyright(c) 1999 - 2006 Intel Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * The full GNU General Public License is included in this distribution in
  15. * the file called "COPYING".
  16. *
  17. * Contact Information:
  18. * Linux NICS <linux.nics@intel.com>
  19. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  20. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  21. *
  22. ******************************************************************************/
  23. /* ethtool support for e1000 */
  24. #include "e1000.h"
  25. #include <linux/jiffies.h>
  26. #include <linux/uaccess.h>
  27. enum {NETDEV_STATS, E1000_STATS};
  28. struct e1000_stats {
  29. char stat_string[ETH_GSTRING_LEN];
  30. int type;
  31. int sizeof_stat;
  32. int stat_offset;
  33. };
  34. #define E1000_STAT(m) E1000_STATS, \
  35. sizeof(((struct e1000_adapter *)0)->m), \
  36. offsetof(struct e1000_adapter, m)
  37. #define E1000_NETDEV_STAT(m) NETDEV_STATS, \
  38. sizeof(((struct net_device *)0)->m), \
  39. offsetof(struct net_device, m)
  40. static const struct e1000_stats e1000_gstrings_stats[] = {
  41. { "rx_packets", E1000_STAT(stats.gprc) },
  42. { "tx_packets", E1000_STAT(stats.gptc) },
  43. { "rx_bytes", E1000_STAT(stats.gorcl) },
  44. { "tx_bytes", E1000_STAT(stats.gotcl) },
  45. { "rx_broadcast", E1000_STAT(stats.bprc) },
  46. { "tx_broadcast", E1000_STAT(stats.bptc) },
  47. { "rx_multicast", E1000_STAT(stats.mprc) },
  48. { "tx_multicast", E1000_STAT(stats.mptc) },
  49. { "rx_errors", E1000_STAT(stats.rxerrc) },
  50. { "tx_errors", E1000_STAT(stats.txerrc) },
  51. { "tx_dropped", E1000_NETDEV_STAT(stats.tx_dropped) },
  52. { "multicast", E1000_STAT(stats.mprc) },
  53. { "collisions", E1000_STAT(stats.colc) },
  54. { "rx_length_errors", E1000_STAT(stats.rlerrc) },
  55. { "rx_over_errors", E1000_NETDEV_STAT(stats.rx_over_errors) },
  56. { "rx_crc_errors", E1000_STAT(stats.crcerrs) },
  57. { "rx_frame_errors", E1000_NETDEV_STAT(stats.rx_frame_errors) },
  58. { "rx_no_buffer_count", E1000_STAT(stats.rnbc) },
  59. { "rx_missed_errors", E1000_STAT(stats.mpc) },
  60. { "tx_aborted_errors", E1000_STAT(stats.ecol) },
  61. { "tx_carrier_errors", E1000_STAT(stats.tncrs) },
  62. { "tx_fifo_errors", E1000_NETDEV_STAT(stats.tx_fifo_errors) },
  63. { "tx_heartbeat_errors", E1000_NETDEV_STAT(stats.tx_heartbeat_errors) },
  64. { "tx_window_errors", E1000_STAT(stats.latecol) },
  65. { "tx_abort_late_coll", E1000_STAT(stats.latecol) },
  66. { "tx_deferred_ok", E1000_STAT(stats.dc) },
  67. { "tx_single_coll_ok", E1000_STAT(stats.scc) },
  68. { "tx_multi_coll_ok", E1000_STAT(stats.mcc) },
  69. { "tx_timeout_count", E1000_STAT(tx_timeout_count) },
  70. { "tx_restart_queue", E1000_STAT(restart_queue) },
  71. { "rx_long_length_errors", E1000_STAT(stats.roc) },
  72. { "rx_short_length_errors", E1000_STAT(stats.ruc) },
  73. { "rx_align_errors", E1000_STAT(stats.algnerrc) },
  74. { "tx_tcp_seg_good", E1000_STAT(stats.tsctc) },
  75. { "tx_tcp_seg_failed", E1000_STAT(stats.tsctfc) },
  76. { "rx_flow_control_xon", E1000_STAT(stats.xonrxc) },
  77. { "rx_flow_control_xoff", E1000_STAT(stats.xoffrxc) },
  78. { "tx_flow_control_xon", E1000_STAT(stats.xontxc) },
  79. { "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) },
  80. { "rx_long_byte_count", E1000_STAT(stats.gorcl) },
  81. { "rx_csum_offload_good", E1000_STAT(hw_csum_good) },
  82. { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) },
  83. { "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed) },
  84. { "tx_smbus", E1000_STAT(stats.mgptc) },
  85. { "rx_smbus", E1000_STAT(stats.mgprc) },
  86. { "dropped_smbus", E1000_STAT(stats.mgpdc) },
  87. };
  88. #define E1000_QUEUE_STATS_LEN 0
  89. #define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
  90. #define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN + E1000_QUEUE_STATS_LEN)
  91. static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
  92. "Register test (offline)", "Eeprom test (offline)",
  93. "Interrupt test (offline)", "Loopback test (offline)",
  94. "Link test (on/offline)"
  95. };
  96. #define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
  97. static int e1000_get_settings(struct net_device *netdev,
  98. struct ethtool_cmd *ecmd)
  99. {
  100. struct e1000_adapter *adapter = netdev_priv(netdev);
  101. struct e1000_hw *hw = &adapter->hw;
  102. if (hw->media_type == e1000_media_type_copper) {
  103. ecmd->supported = (SUPPORTED_10baseT_Half |
  104. SUPPORTED_10baseT_Full |
  105. SUPPORTED_100baseT_Half |
  106. SUPPORTED_100baseT_Full |
  107. SUPPORTED_1000baseT_Full|
  108. SUPPORTED_Autoneg |
  109. SUPPORTED_TP);
  110. ecmd->advertising = ADVERTISED_TP;
  111. if (hw->autoneg == 1) {
  112. ecmd->advertising |= ADVERTISED_Autoneg;
  113. /* the e1000 autoneg seems to match ethtool nicely */
  114. ecmd->advertising |= hw->autoneg_advertised;
  115. }
  116. ecmd->port = PORT_TP;
  117. ecmd->phy_address = hw->phy_addr;
  118. if (hw->mac_type == e1000_82543)
  119. ecmd->transceiver = XCVR_EXTERNAL;
  120. else
  121. ecmd->transceiver = XCVR_INTERNAL;
  122. } else {
  123. ecmd->supported = (SUPPORTED_1000baseT_Full |
  124. SUPPORTED_FIBRE |
  125. SUPPORTED_Autoneg);
  126. ecmd->advertising = (ADVERTISED_1000baseT_Full |
  127. ADVERTISED_FIBRE |
  128. ADVERTISED_Autoneg);
  129. ecmd->port = PORT_FIBRE;
  130. if (hw->mac_type >= e1000_82545)
  131. ecmd->transceiver = XCVR_INTERNAL;
  132. else
  133. ecmd->transceiver = XCVR_EXTERNAL;
  134. }
  135. if (er32(STATUS) & E1000_STATUS_LU) {
  136. e1000_get_speed_and_duplex(hw, &adapter->link_speed,
  137. &adapter->link_duplex);
  138. ethtool_cmd_speed_set(ecmd, adapter->link_speed);
  139. /* unfortunately FULL_DUPLEX != DUPLEX_FULL
  140. * and HALF_DUPLEX != DUPLEX_HALF
  141. */
  142. if (adapter->link_duplex == FULL_DUPLEX)
  143. ecmd->duplex = DUPLEX_FULL;
  144. else
  145. ecmd->duplex = DUPLEX_HALF;
  146. } else {
  147. ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
  148. ecmd->duplex = DUPLEX_UNKNOWN;
  149. }
  150. ecmd->autoneg = ((hw->media_type == e1000_media_type_fiber) ||
  151. hw->autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
  152. /* MDI-X => 1; MDI => 0 */
  153. if ((hw->media_type == e1000_media_type_copper) &&
  154. netif_carrier_ok(netdev))
  155. ecmd->eth_tp_mdix = (!!adapter->phy_info.mdix_mode ?
  156. ETH_TP_MDI_X : ETH_TP_MDI);
  157. else
  158. ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID;
  159. if (hw->mdix == AUTO_ALL_MODES)
  160. ecmd->eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO;
  161. else
  162. ecmd->eth_tp_mdix_ctrl = hw->mdix;
  163. return 0;
  164. }
  165. static int e1000_set_settings(struct net_device *netdev,
  166. struct ethtool_cmd *ecmd)
  167. {
  168. struct e1000_adapter *adapter = netdev_priv(netdev);
  169. struct e1000_hw *hw = &adapter->hw;
  170. /* MDI setting is only allowed when autoneg enabled because
  171. * some hardware doesn't allow MDI setting when speed or
  172. * duplex is forced.
  173. */
  174. if (ecmd->eth_tp_mdix_ctrl) {
  175. if (hw->media_type != e1000_media_type_copper)
  176. return -EOPNOTSUPP;
  177. if ((ecmd->eth_tp_mdix_ctrl != ETH_TP_MDI_AUTO) &&
  178. (ecmd->autoneg != AUTONEG_ENABLE)) {
  179. e_err(drv, "forcing MDI/MDI-X state is not supported when link speed and/or duplex are forced\n");
  180. return -EINVAL;
  181. }
  182. }
  183. while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
  184. msleep(1);
  185. if (ecmd->autoneg == AUTONEG_ENABLE) {
  186. hw->autoneg = 1;
  187. if (hw->media_type == e1000_media_type_fiber)
  188. hw->autoneg_advertised = ADVERTISED_1000baseT_Full |
  189. ADVERTISED_FIBRE |
  190. ADVERTISED_Autoneg;
  191. else
  192. hw->autoneg_advertised = ecmd->advertising |
  193. ADVERTISED_TP |
  194. ADVERTISED_Autoneg;
  195. ecmd->advertising = hw->autoneg_advertised;
  196. } else {
  197. u32 speed = ethtool_cmd_speed(ecmd);
  198. /* calling this overrides forced MDI setting */
  199. if (e1000_set_spd_dplx(adapter, speed, ecmd->duplex)) {
  200. clear_bit(__E1000_RESETTING, &adapter->flags);
  201. return -EINVAL;
  202. }
  203. }
  204. /* MDI-X => 2; MDI => 1; Auto => 3 */
  205. if (ecmd->eth_tp_mdix_ctrl) {
  206. if (ecmd->eth_tp_mdix_ctrl == ETH_TP_MDI_AUTO)
  207. hw->mdix = AUTO_ALL_MODES;
  208. else
  209. hw->mdix = ecmd->eth_tp_mdix_ctrl;
  210. }
  211. /* reset the link */
  212. if (netif_running(adapter->netdev)) {
  213. e1000_down(adapter);
  214. e1000_up(adapter);
  215. } else {
  216. e1000_reset(adapter);
  217. }
  218. clear_bit(__E1000_RESETTING, &adapter->flags);
  219. return 0;
  220. }
  221. static u32 e1000_get_link(struct net_device *netdev)
  222. {
  223. struct e1000_adapter *adapter = netdev_priv(netdev);
  224. /* If the link is not reported up to netdev, interrupts are disabled,
  225. * and so the physical link state may have changed since we last
  226. * looked. Set get_link_status to make sure that the true link
  227. * state is interrogated, rather than pulling a cached and possibly
  228. * stale link state from the driver.
  229. */
  230. if (!netif_carrier_ok(netdev))
  231. adapter->hw.get_link_status = 1;
  232. return e1000_has_link(adapter);
  233. }
  234. static void e1000_get_pauseparam(struct net_device *netdev,
  235. struct ethtool_pauseparam *pause)
  236. {
  237. struct e1000_adapter *adapter = netdev_priv(netdev);
  238. struct e1000_hw *hw = &adapter->hw;
  239. pause->autoneg =
  240. (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
  241. if (hw->fc == E1000_FC_RX_PAUSE) {
  242. pause->rx_pause = 1;
  243. } else if (hw->fc == E1000_FC_TX_PAUSE) {
  244. pause->tx_pause = 1;
  245. } else if (hw->fc == E1000_FC_FULL) {
  246. pause->rx_pause = 1;
  247. pause->tx_pause = 1;
  248. }
  249. }
  250. static int e1000_set_pauseparam(struct net_device *netdev,
  251. struct ethtool_pauseparam *pause)
  252. {
  253. struct e1000_adapter *adapter = netdev_priv(netdev);
  254. struct e1000_hw *hw = &adapter->hw;
  255. int retval = 0;
  256. adapter->fc_autoneg = pause->autoneg;
  257. while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
  258. msleep(1);
  259. if (pause->rx_pause && pause->tx_pause)
  260. hw->fc = E1000_FC_FULL;
  261. else if (pause->rx_pause && !pause->tx_pause)
  262. hw->fc = E1000_FC_RX_PAUSE;
  263. else if (!pause->rx_pause && pause->tx_pause)
  264. hw->fc = E1000_FC_TX_PAUSE;
  265. else if (!pause->rx_pause && !pause->tx_pause)
  266. hw->fc = E1000_FC_NONE;
  267. hw->original_fc = hw->fc;
  268. if (adapter->fc_autoneg == AUTONEG_ENABLE) {
  269. if (netif_running(adapter->netdev)) {
  270. e1000_down(adapter);
  271. e1000_up(adapter);
  272. } else {
  273. e1000_reset(adapter);
  274. }
  275. } else
  276. retval = ((hw->media_type == e1000_media_type_fiber) ?
  277. e1000_setup_link(hw) : e1000_force_mac_fc(hw));
  278. clear_bit(__E1000_RESETTING, &adapter->flags);
  279. return retval;
  280. }
  281. static u32 e1000_get_msglevel(struct net_device *netdev)
  282. {
  283. struct e1000_adapter *adapter = netdev_priv(netdev);
  284. return adapter->msg_enable;
  285. }
  286. static void e1000_set_msglevel(struct net_device *netdev, u32 data)
  287. {
  288. struct e1000_adapter *adapter = netdev_priv(netdev);
  289. adapter->msg_enable = data;
  290. }
  291. static int e1000_get_regs_len(struct net_device *netdev)
  292. {
  293. #define E1000_REGS_LEN 32
  294. return E1000_REGS_LEN * sizeof(u32);
  295. }
  296. static void e1000_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
  297. void *p)
  298. {
  299. struct e1000_adapter *adapter = netdev_priv(netdev);
  300. struct e1000_hw *hw = &adapter->hw;
  301. u32 *regs_buff = p;
  302. u16 phy_data;
  303. memset(p, 0, E1000_REGS_LEN * sizeof(u32));
  304. regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
  305. regs_buff[0] = er32(CTRL);
  306. regs_buff[1] = er32(STATUS);
  307. regs_buff[2] = er32(RCTL);
  308. regs_buff[3] = er32(RDLEN);
  309. regs_buff[4] = er32(RDH);
  310. regs_buff[5] = er32(RDT);
  311. regs_buff[6] = er32(RDTR);
  312. regs_buff[7] = er32(TCTL);
  313. regs_buff[8] = er32(TDLEN);
  314. regs_buff[9] = er32(TDH);
  315. regs_buff[10] = er32(TDT);
  316. regs_buff[11] = er32(TIDV);
  317. regs_buff[12] = hw->phy_type; /* PHY type (IGP=1, M88=0) */
  318. if (hw->phy_type == e1000_phy_igp) {
  319. e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
  320. IGP01E1000_PHY_AGC_A);
  321. e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_A &
  322. IGP01E1000_PHY_PAGE_SELECT, &phy_data);
  323. regs_buff[13] = (u32)phy_data; /* cable length */
  324. e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
  325. IGP01E1000_PHY_AGC_B);
  326. e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_B &
  327. IGP01E1000_PHY_PAGE_SELECT, &phy_data);
  328. regs_buff[14] = (u32)phy_data; /* cable length */
  329. e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
  330. IGP01E1000_PHY_AGC_C);
  331. e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_C &
  332. IGP01E1000_PHY_PAGE_SELECT, &phy_data);
  333. regs_buff[15] = (u32)phy_data; /* cable length */
  334. e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
  335. IGP01E1000_PHY_AGC_D);
  336. e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_D &
  337. IGP01E1000_PHY_PAGE_SELECT, &phy_data);
  338. regs_buff[16] = (u32)phy_data; /* cable length */
  339. regs_buff[17] = 0; /* extended 10bt distance (not needed) */
  340. e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
  341. e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS &
  342. IGP01E1000_PHY_PAGE_SELECT, &phy_data);
  343. regs_buff[18] = (u32)phy_data; /* cable polarity */
  344. e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
  345. IGP01E1000_PHY_PCS_INIT_REG);
  346. e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG &
  347. IGP01E1000_PHY_PAGE_SELECT, &phy_data);
  348. regs_buff[19] = (u32)phy_data; /* cable polarity */
  349. regs_buff[20] = 0; /* polarity correction enabled (always) */
  350. regs_buff[22] = 0; /* phy receive errors (unavailable) */
  351. regs_buff[23] = regs_buff[18]; /* mdix mode */
  352. e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
  353. } else {
  354. e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
  355. regs_buff[13] = (u32)phy_data; /* cable length */
  356. regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
  357. regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
  358. regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
  359. e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  360. regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
  361. regs_buff[18] = regs_buff[13]; /* cable polarity */
  362. regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
  363. regs_buff[20] = regs_buff[17]; /* polarity correction */
  364. /* phy receive errors */
  365. regs_buff[22] = adapter->phy_stats.receive_errors;
  366. regs_buff[23] = regs_buff[13]; /* mdix mode */
  367. }
  368. regs_buff[21] = adapter->phy_stats.idle_errors; /* phy idle errors */
  369. e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
  370. regs_buff[24] = (u32)phy_data; /* phy local receiver status */
  371. regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
  372. if (hw->mac_type >= e1000_82540 &&
  373. hw->media_type == e1000_media_type_copper) {
  374. regs_buff[26] = er32(MANC);
  375. }
  376. }
  377. static int e1000_get_eeprom_len(struct net_device *netdev)
  378. {
  379. struct e1000_adapter *adapter = netdev_priv(netdev);
  380. struct e1000_hw *hw = &adapter->hw;
  381. return hw->eeprom.word_size * 2;
  382. }
  383. static int e1000_get_eeprom(struct net_device *netdev,
  384. struct ethtool_eeprom *eeprom, u8 *bytes)
  385. {
  386. struct e1000_adapter *adapter = netdev_priv(netdev);
  387. struct e1000_hw *hw = &adapter->hw;
  388. u16 *eeprom_buff;
  389. int first_word, last_word;
  390. int ret_val = 0;
  391. u16 i;
  392. if (eeprom->len == 0)
  393. return -EINVAL;
  394. eeprom->magic = hw->vendor_id | (hw->device_id << 16);
  395. first_word = eeprom->offset >> 1;
  396. last_word = (eeprom->offset + eeprom->len - 1) >> 1;
  397. eeprom_buff = kmalloc(sizeof(u16) *
  398. (last_word - first_word + 1), GFP_KERNEL);
  399. if (!eeprom_buff)
  400. return -ENOMEM;
  401. if (hw->eeprom.type == e1000_eeprom_spi)
  402. ret_val = e1000_read_eeprom(hw, first_word,
  403. last_word - first_word + 1,
  404. eeprom_buff);
  405. else {
  406. for (i = 0; i < last_word - first_word + 1; i++) {
  407. ret_val = e1000_read_eeprom(hw, first_word + i, 1,
  408. &eeprom_buff[i]);
  409. if (ret_val)
  410. break;
  411. }
  412. }
  413. /* Device's eeprom is always little-endian, word addressable */
  414. for (i = 0; i < last_word - first_word + 1; i++)
  415. le16_to_cpus(&eeprom_buff[i]);
  416. memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1),
  417. eeprom->len);
  418. kfree(eeprom_buff);
  419. return ret_val;
  420. }
  421. static int e1000_set_eeprom(struct net_device *netdev,
  422. struct ethtool_eeprom *eeprom, u8 *bytes)
  423. {
  424. struct e1000_adapter *adapter = netdev_priv(netdev);
  425. struct e1000_hw *hw = &adapter->hw;
  426. u16 *eeprom_buff;
  427. void *ptr;
  428. int max_len, first_word, last_word, ret_val = 0;
  429. u16 i;
  430. if (eeprom->len == 0)
  431. return -EOPNOTSUPP;
  432. if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
  433. return -EFAULT;
  434. max_len = hw->eeprom.word_size * 2;
  435. first_word = eeprom->offset >> 1;
  436. last_word = (eeprom->offset + eeprom->len - 1) >> 1;
  437. eeprom_buff = kmalloc(max_len, GFP_KERNEL);
  438. if (!eeprom_buff)
  439. return -ENOMEM;
  440. ptr = (void *)eeprom_buff;
  441. if (eeprom->offset & 1) {
  442. /* need read/modify/write of first changed EEPROM word
  443. * only the second byte of the word is being modified
  444. */
  445. ret_val = e1000_read_eeprom(hw, first_word, 1,
  446. &eeprom_buff[0]);
  447. ptr++;
  448. }
  449. if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0)) {
  450. /* need read/modify/write of last changed EEPROM word
  451. * only the first byte of the word is being modified
  452. */
  453. ret_val = e1000_read_eeprom(hw, last_word, 1,
  454. &eeprom_buff[last_word - first_word]);
  455. }
  456. /* Device's eeprom is always little-endian, word addressable */
  457. for (i = 0; i < last_word - first_word + 1; i++)
  458. le16_to_cpus(&eeprom_buff[i]);
  459. memcpy(ptr, bytes, eeprom->len);
  460. for (i = 0; i < last_word - first_word + 1; i++)
  461. eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
  462. ret_val = e1000_write_eeprom(hw, first_word,
  463. last_word - first_word + 1, eeprom_buff);
  464. /* Update the checksum over the first part of the EEPROM if needed */
  465. if ((ret_val == 0) && (first_word <= EEPROM_CHECKSUM_REG))
  466. e1000_update_eeprom_checksum(hw);
  467. kfree(eeprom_buff);
  468. return ret_val;
  469. }
  470. static void e1000_get_drvinfo(struct net_device *netdev,
  471. struct ethtool_drvinfo *drvinfo)
  472. {
  473. struct e1000_adapter *adapter = netdev_priv(netdev);
  474. strlcpy(drvinfo->driver, e1000_driver_name,
  475. sizeof(drvinfo->driver));
  476. strlcpy(drvinfo->version, e1000_driver_version,
  477. sizeof(drvinfo->version));
  478. strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
  479. sizeof(drvinfo->bus_info));
  480. drvinfo->regdump_len = e1000_get_regs_len(netdev);
  481. drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
  482. }
  483. static void e1000_get_ringparam(struct net_device *netdev,
  484. struct ethtool_ringparam *ring)
  485. {
  486. struct e1000_adapter *adapter = netdev_priv(netdev);
  487. struct e1000_hw *hw = &adapter->hw;
  488. e1000_mac_type mac_type = hw->mac_type;
  489. struct e1000_tx_ring *txdr = adapter->tx_ring;
  490. struct e1000_rx_ring *rxdr = adapter->rx_ring;
  491. ring->rx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_RXD :
  492. E1000_MAX_82544_RXD;
  493. ring->tx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_TXD :
  494. E1000_MAX_82544_TXD;
  495. ring->rx_pending = rxdr->count;
  496. ring->tx_pending = txdr->count;
  497. }
  498. static int e1000_set_ringparam(struct net_device *netdev,
  499. struct ethtool_ringparam *ring)
  500. {
  501. struct e1000_adapter *adapter = netdev_priv(netdev);
  502. struct e1000_hw *hw = &adapter->hw;
  503. e1000_mac_type mac_type = hw->mac_type;
  504. struct e1000_tx_ring *txdr, *tx_old;
  505. struct e1000_rx_ring *rxdr, *rx_old;
  506. int i, err;
  507. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  508. return -EINVAL;
  509. while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
  510. msleep(1);
  511. if (netif_running(adapter->netdev))
  512. e1000_down(adapter);
  513. tx_old = adapter->tx_ring;
  514. rx_old = adapter->rx_ring;
  515. err = -ENOMEM;
  516. txdr = kcalloc(adapter->num_tx_queues, sizeof(struct e1000_tx_ring),
  517. GFP_KERNEL);
  518. if (!txdr)
  519. goto err_alloc_tx;
  520. rxdr = kcalloc(adapter->num_rx_queues, sizeof(struct e1000_rx_ring),
  521. GFP_KERNEL);
  522. if (!rxdr)
  523. goto err_alloc_rx;
  524. adapter->tx_ring = txdr;
  525. adapter->rx_ring = rxdr;
  526. rxdr->count = max(ring->rx_pending, (u32)E1000_MIN_RXD);
  527. rxdr->count = min(rxdr->count, (u32)(mac_type < e1000_82544 ?
  528. E1000_MAX_RXD : E1000_MAX_82544_RXD));
  529. rxdr->count = ALIGN(rxdr->count, REQ_RX_DESCRIPTOR_MULTIPLE);
  530. txdr->count = max(ring->tx_pending, (u32)E1000_MIN_TXD);
  531. txdr->count = min(txdr->count, (u32)(mac_type < e1000_82544 ?
  532. E1000_MAX_TXD : E1000_MAX_82544_TXD));
  533. txdr->count = ALIGN(txdr->count, REQ_TX_DESCRIPTOR_MULTIPLE);
  534. for (i = 0; i < adapter->num_tx_queues; i++)
  535. txdr[i].count = txdr->count;
  536. for (i = 0; i < adapter->num_rx_queues; i++)
  537. rxdr[i].count = rxdr->count;
  538. if (netif_running(adapter->netdev)) {
  539. /* Try to get new resources before deleting old */
  540. err = e1000_setup_all_rx_resources(adapter);
  541. if (err)
  542. goto err_setup_rx;
  543. err = e1000_setup_all_tx_resources(adapter);
  544. if (err)
  545. goto err_setup_tx;
  546. /* save the new, restore the old in order to free it,
  547. * then restore the new back again
  548. */
  549. adapter->rx_ring = rx_old;
  550. adapter->tx_ring = tx_old;
  551. e1000_free_all_rx_resources(adapter);
  552. e1000_free_all_tx_resources(adapter);
  553. kfree(tx_old);
  554. kfree(rx_old);
  555. adapter->rx_ring = rxdr;
  556. adapter->tx_ring = txdr;
  557. err = e1000_up(adapter);
  558. if (err)
  559. goto err_setup;
  560. }
  561. clear_bit(__E1000_RESETTING, &adapter->flags);
  562. return 0;
  563. err_setup_tx:
  564. e1000_free_all_rx_resources(adapter);
  565. err_setup_rx:
  566. adapter->rx_ring = rx_old;
  567. adapter->tx_ring = tx_old;
  568. kfree(rxdr);
  569. err_alloc_rx:
  570. kfree(txdr);
  571. err_alloc_tx:
  572. e1000_up(adapter);
  573. err_setup:
  574. clear_bit(__E1000_RESETTING, &adapter->flags);
  575. return err;
  576. }
  577. static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data, int reg,
  578. u32 mask, u32 write)
  579. {
  580. struct e1000_hw *hw = &adapter->hw;
  581. static const u32 test[] = {
  582. 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF
  583. };
  584. u8 __iomem *address = hw->hw_addr + reg;
  585. u32 read;
  586. int i;
  587. for (i = 0; i < ARRAY_SIZE(test); i++) {
  588. writel(write & test[i], address);
  589. read = readl(address);
  590. if (read != (write & test[i] & mask)) {
  591. e_err(drv, "pattern test reg %04X failed: "
  592. "got 0x%08X expected 0x%08X\n",
  593. reg, read, (write & test[i] & mask));
  594. *data = reg;
  595. return true;
  596. }
  597. }
  598. return false;
  599. }
  600. static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data, int reg,
  601. u32 mask, u32 write)
  602. {
  603. struct e1000_hw *hw = &adapter->hw;
  604. u8 __iomem *address = hw->hw_addr + reg;
  605. u32 read;
  606. writel(write & mask, address);
  607. read = readl(address);
  608. if ((read & mask) != (write & mask)) {
  609. e_err(drv, "set/check reg %04X test failed: "
  610. "got 0x%08X expected 0x%08X\n",
  611. reg, (read & mask), (write & mask));
  612. *data = reg;
  613. return true;
  614. }
  615. return false;
  616. }
  617. #define REG_PATTERN_TEST(reg, mask, write) \
  618. do { \
  619. if (reg_pattern_test(adapter, data, \
  620. (hw->mac_type >= e1000_82543) \
  621. ? E1000_##reg : E1000_82542_##reg, \
  622. mask, write)) \
  623. return 1; \
  624. } while (0)
  625. #define REG_SET_AND_CHECK(reg, mask, write) \
  626. do { \
  627. if (reg_set_and_check(adapter, data, \
  628. (hw->mac_type >= e1000_82543) \
  629. ? E1000_##reg : E1000_82542_##reg, \
  630. mask, write)) \
  631. return 1; \
  632. } while (0)
  633. static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
  634. {
  635. u32 value, before, after;
  636. u32 i, toggle;
  637. struct e1000_hw *hw = &adapter->hw;
  638. /* The status register is Read Only, so a write should fail.
  639. * Some bits that get toggled are ignored.
  640. */
  641. /* there are several bits on newer hardware that are r/w */
  642. toggle = 0xFFFFF833;
  643. before = er32(STATUS);
  644. value = (er32(STATUS) & toggle);
  645. ew32(STATUS, toggle);
  646. after = er32(STATUS) & toggle;
  647. if (value != after) {
  648. e_err(drv, "failed STATUS register test got: "
  649. "0x%08X expected: 0x%08X\n", after, value);
  650. *data = 1;
  651. return 1;
  652. }
  653. /* restore previous status */
  654. ew32(STATUS, before);
  655. REG_PATTERN_TEST(FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
  656. REG_PATTERN_TEST(FCAH, 0x0000FFFF, 0xFFFFFFFF);
  657. REG_PATTERN_TEST(FCT, 0x0000FFFF, 0xFFFFFFFF);
  658. REG_PATTERN_TEST(VET, 0x0000FFFF, 0xFFFFFFFF);
  659. REG_PATTERN_TEST(RDTR, 0x0000FFFF, 0xFFFFFFFF);
  660. REG_PATTERN_TEST(RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
  661. REG_PATTERN_TEST(RDLEN, 0x000FFF80, 0x000FFFFF);
  662. REG_PATTERN_TEST(RDH, 0x0000FFFF, 0x0000FFFF);
  663. REG_PATTERN_TEST(RDT, 0x0000FFFF, 0x0000FFFF);
  664. REG_PATTERN_TEST(FCRTH, 0x0000FFF8, 0x0000FFF8);
  665. REG_PATTERN_TEST(FCTTV, 0x0000FFFF, 0x0000FFFF);
  666. REG_PATTERN_TEST(TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
  667. REG_PATTERN_TEST(TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
  668. REG_PATTERN_TEST(TDLEN, 0x000FFF80, 0x000FFFFF);
  669. REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x00000000);
  670. before = 0x06DFB3FE;
  671. REG_SET_AND_CHECK(RCTL, before, 0x003FFFFB);
  672. REG_SET_AND_CHECK(TCTL, 0xFFFFFFFF, 0x00000000);
  673. if (hw->mac_type >= e1000_82543) {
  674. REG_SET_AND_CHECK(RCTL, before, 0xFFFFFFFF);
  675. REG_PATTERN_TEST(RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
  676. REG_PATTERN_TEST(TXCW, 0xC000FFFF, 0x0000FFFF);
  677. REG_PATTERN_TEST(TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
  678. REG_PATTERN_TEST(TIDV, 0x0000FFFF, 0x0000FFFF);
  679. value = E1000_RAR_ENTRIES;
  680. for (i = 0; i < value; i++) {
  681. REG_PATTERN_TEST(RA + (((i << 1) + 1) << 2),
  682. 0x8003FFFF, 0xFFFFFFFF);
  683. }
  684. } else {
  685. REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x01FFFFFF);
  686. REG_PATTERN_TEST(RDBAL, 0xFFFFF000, 0xFFFFFFFF);
  687. REG_PATTERN_TEST(TXCW, 0x0000FFFF, 0x0000FFFF);
  688. REG_PATTERN_TEST(TDBAL, 0xFFFFF000, 0xFFFFFFFF);
  689. }
  690. value = E1000_MC_TBL_SIZE;
  691. for (i = 0; i < value; i++)
  692. REG_PATTERN_TEST(MTA + (i << 2), 0xFFFFFFFF, 0xFFFFFFFF);
  693. *data = 0;
  694. return 0;
  695. }
  696. static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
  697. {
  698. struct e1000_hw *hw = &adapter->hw;
  699. u16 temp;
  700. u16 checksum = 0;
  701. u16 i;
  702. *data = 0;
  703. /* Read and add up the contents of the EEPROM */
  704. for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
  705. if ((e1000_read_eeprom(hw, i, 1, &temp)) < 0) {
  706. *data = 1;
  707. break;
  708. }
  709. checksum += temp;
  710. }
  711. /* If Checksum is not Correct return error else test passed */
  712. if ((checksum != (u16)EEPROM_SUM) && !(*data))
  713. *data = 2;
  714. return *data;
  715. }
  716. static irqreturn_t e1000_test_intr(int irq, void *data)
  717. {
  718. struct net_device *netdev = (struct net_device *)data;
  719. struct e1000_adapter *adapter = netdev_priv(netdev);
  720. struct e1000_hw *hw = &adapter->hw;
  721. adapter->test_icr |= er32(ICR);
  722. return IRQ_HANDLED;
  723. }
  724. static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
  725. {
  726. struct net_device *netdev = adapter->netdev;
  727. u32 mask, i = 0;
  728. bool shared_int = true;
  729. u32 irq = adapter->pdev->irq;
  730. struct e1000_hw *hw = &adapter->hw;
  731. *data = 0;
  732. /* NOTE: we don't test MSI interrupts here, yet
  733. * Hook up test interrupt handler just for this test
  734. */
  735. if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
  736. netdev))
  737. shared_int = false;
  738. else if (request_irq(irq, e1000_test_intr, IRQF_SHARED,
  739. netdev->name, netdev)) {
  740. *data = 1;
  741. return -1;
  742. }
  743. e_info(hw, "testing %s interrupt\n", (shared_int ?
  744. "shared" : "unshared"));
  745. /* Disable all the interrupts */
  746. ew32(IMC, 0xFFFFFFFF);
  747. E1000_WRITE_FLUSH();
  748. msleep(10);
  749. /* Test each interrupt */
  750. for (; i < 10; i++) {
  751. /* Interrupt to test */
  752. mask = 1 << i;
  753. if (!shared_int) {
  754. /* Disable the interrupt to be reported in
  755. * the cause register and then force the same
  756. * interrupt and see if one gets posted. If
  757. * an interrupt was posted to the bus, the
  758. * test failed.
  759. */
  760. adapter->test_icr = 0;
  761. ew32(IMC, mask);
  762. ew32(ICS, mask);
  763. E1000_WRITE_FLUSH();
  764. msleep(10);
  765. if (adapter->test_icr & mask) {
  766. *data = 3;
  767. break;
  768. }
  769. }
  770. /* Enable the interrupt to be reported in
  771. * the cause register and then force the same
  772. * interrupt and see if one gets posted. If
  773. * an interrupt was not posted to the bus, the
  774. * test failed.
  775. */
  776. adapter->test_icr = 0;
  777. ew32(IMS, mask);
  778. ew32(ICS, mask);
  779. E1000_WRITE_FLUSH();
  780. msleep(10);
  781. if (!(adapter->test_icr & mask)) {
  782. *data = 4;
  783. break;
  784. }
  785. if (!shared_int) {
  786. /* Disable the other interrupts to be reported in
  787. * the cause register and then force the other
  788. * interrupts and see if any get posted. If
  789. * an interrupt was posted to the bus, the
  790. * test failed.
  791. */
  792. adapter->test_icr = 0;
  793. ew32(IMC, ~mask & 0x00007FFF);
  794. ew32(ICS, ~mask & 0x00007FFF);
  795. E1000_WRITE_FLUSH();
  796. msleep(10);
  797. if (adapter->test_icr) {
  798. *data = 5;
  799. break;
  800. }
  801. }
  802. }
  803. /* Disable all the interrupts */
  804. ew32(IMC, 0xFFFFFFFF);
  805. E1000_WRITE_FLUSH();
  806. msleep(10);
  807. /* Unhook test interrupt handler */
  808. free_irq(irq, netdev);
  809. return *data;
  810. }
  811. static void e1000_free_desc_rings(struct e1000_adapter *adapter)
  812. {
  813. struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
  814. struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
  815. struct pci_dev *pdev = adapter->pdev;
  816. int i;
  817. if (txdr->desc && txdr->buffer_info) {
  818. for (i = 0; i < txdr->count; i++) {
  819. if (txdr->buffer_info[i].dma)
  820. dma_unmap_single(&pdev->dev,
  821. txdr->buffer_info[i].dma,
  822. txdr->buffer_info[i].length,
  823. DMA_TO_DEVICE);
  824. if (txdr->buffer_info[i].skb)
  825. dev_kfree_skb(txdr->buffer_info[i].skb);
  826. }
  827. }
  828. if (rxdr->desc && rxdr->buffer_info) {
  829. for (i = 0; i < rxdr->count; i++) {
  830. if (rxdr->buffer_info[i].dma)
  831. dma_unmap_single(&pdev->dev,
  832. rxdr->buffer_info[i].dma,
  833. E1000_RXBUFFER_2048,
  834. DMA_FROM_DEVICE);
  835. kfree(rxdr->buffer_info[i].rxbuf.data);
  836. }
  837. }
  838. if (txdr->desc) {
  839. dma_free_coherent(&pdev->dev, txdr->size, txdr->desc,
  840. txdr->dma);
  841. txdr->desc = NULL;
  842. }
  843. if (rxdr->desc) {
  844. dma_free_coherent(&pdev->dev, rxdr->size, rxdr->desc,
  845. rxdr->dma);
  846. rxdr->desc = NULL;
  847. }
  848. kfree(txdr->buffer_info);
  849. txdr->buffer_info = NULL;
  850. kfree(rxdr->buffer_info);
  851. rxdr->buffer_info = NULL;
  852. }
  853. static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
  854. {
  855. struct e1000_hw *hw = &adapter->hw;
  856. struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
  857. struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
  858. struct pci_dev *pdev = adapter->pdev;
  859. u32 rctl;
  860. int i, ret_val;
  861. /* Setup Tx descriptor ring and Tx buffers */
  862. if (!txdr->count)
  863. txdr->count = E1000_DEFAULT_TXD;
  864. txdr->buffer_info = kcalloc(txdr->count, sizeof(struct e1000_tx_buffer),
  865. GFP_KERNEL);
  866. if (!txdr->buffer_info) {
  867. ret_val = 1;
  868. goto err_nomem;
  869. }
  870. txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
  871. txdr->size = ALIGN(txdr->size, 4096);
  872. txdr->desc = dma_zalloc_coherent(&pdev->dev, txdr->size, &txdr->dma,
  873. GFP_KERNEL);
  874. if (!txdr->desc) {
  875. ret_val = 2;
  876. goto err_nomem;
  877. }
  878. txdr->next_to_use = txdr->next_to_clean = 0;
  879. ew32(TDBAL, ((u64)txdr->dma & 0x00000000FFFFFFFF));
  880. ew32(TDBAH, ((u64)txdr->dma >> 32));
  881. ew32(TDLEN, txdr->count * sizeof(struct e1000_tx_desc));
  882. ew32(TDH, 0);
  883. ew32(TDT, 0);
  884. ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN |
  885. E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
  886. E1000_FDX_COLLISION_DISTANCE << E1000_COLD_SHIFT);
  887. for (i = 0; i < txdr->count; i++) {
  888. struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*txdr, i);
  889. struct sk_buff *skb;
  890. unsigned int size = 1024;
  891. skb = alloc_skb(size, GFP_KERNEL);
  892. if (!skb) {
  893. ret_val = 3;
  894. goto err_nomem;
  895. }
  896. skb_put(skb, size);
  897. txdr->buffer_info[i].skb = skb;
  898. txdr->buffer_info[i].length = skb->len;
  899. txdr->buffer_info[i].dma =
  900. dma_map_single(&pdev->dev, skb->data, skb->len,
  901. DMA_TO_DEVICE);
  902. if (dma_mapping_error(&pdev->dev, txdr->buffer_info[i].dma)) {
  903. ret_val = 4;
  904. goto err_nomem;
  905. }
  906. tx_desc->buffer_addr = cpu_to_le64(txdr->buffer_info[i].dma);
  907. tx_desc->lower.data = cpu_to_le32(skb->len);
  908. tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
  909. E1000_TXD_CMD_IFCS |
  910. E1000_TXD_CMD_RPS);
  911. tx_desc->upper.data = 0;
  912. }
  913. /* Setup Rx descriptor ring and Rx buffers */
  914. if (!rxdr->count)
  915. rxdr->count = E1000_DEFAULT_RXD;
  916. rxdr->buffer_info = kcalloc(rxdr->count, sizeof(struct e1000_rx_buffer),
  917. GFP_KERNEL);
  918. if (!rxdr->buffer_info) {
  919. ret_val = 5;
  920. goto err_nomem;
  921. }
  922. rxdr->size = rxdr->count * sizeof(struct e1000_rx_desc);
  923. rxdr->desc = dma_zalloc_coherent(&pdev->dev, rxdr->size, &rxdr->dma,
  924. GFP_KERNEL);
  925. if (!rxdr->desc) {
  926. ret_val = 6;
  927. goto err_nomem;
  928. }
  929. rxdr->next_to_use = rxdr->next_to_clean = 0;
  930. rctl = er32(RCTL);
  931. ew32(RCTL, rctl & ~E1000_RCTL_EN);
  932. ew32(RDBAL, ((u64)rxdr->dma & 0xFFFFFFFF));
  933. ew32(RDBAH, ((u64)rxdr->dma >> 32));
  934. ew32(RDLEN, rxdr->size);
  935. ew32(RDH, 0);
  936. ew32(RDT, 0);
  937. rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
  938. E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
  939. (hw->mc_filter_type << E1000_RCTL_MO_SHIFT);
  940. ew32(RCTL, rctl);
  941. for (i = 0; i < rxdr->count; i++) {
  942. struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rxdr, i);
  943. u8 *buf;
  944. buf = kzalloc(E1000_RXBUFFER_2048 + NET_SKB_PAD + NET_IP_ALIGN,
  945. GFP_KERNEL);
  946. if (!buf) {
  947. ret_val = 7;
  948. goto err_nomem;
  949. }
  950. rxdr->buffer_info[i].rxbuf.data = buf;
  951. rxdr->buffer_info[i].dma =
  952. dma_map_single(&pdev->dev,
  953. buf + NET_SKB_PAD + NET_IP_ALIGN,
  954. E1000_RXBUFFER_2048, DMA_FROM_DEVICE);
  955. if (dma_mapping_error(&pdev->dev, rxdr->buffer_info[i].dma)) {
  956. ret_val = 8;
  957. goto err_nomem;
  958. }
  959. rx_desc->buffer_addr = cpu_to_le64(rxdr->buffer_info[i].dma);
  960. }
  961. return 0;
  962. err_nomem:
  963. e1000_free_desc_rings(adapter);
  964. return ret_val;
  965. }
  966. static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
  967. {
  968. struct e1000_hw *hw = &adapter->hw;
  969. /* Write out to PHY registers 29 and 30 to disable the Receiver. */
  970. e1000_write_phy_reg(hw, 29, 0x001F);
  971. e1000_write_phy_reg(hw, 30, 0x8FFC);
  972. e1000_write_phy_reg(hw, 29, 0x001A);
  973. e1000_write_phy_reg(hw, 30, 0x8FF0);
  974. }
  975. static void e1000_phy_reset_clk_and_crs(struct e1000_adapter *adapter)
  976. {
  977. struct e1000_hw *hw = &adapter->hw;
  978. u16 phy_reg;
  979. /* Because we reset the PHY above, we need to re-force TX_CLK in the
  980. * Extended PHY Specific Control Register to 25MHz clock. This
  981. * value defaults back to a 2.5MHz clock when the PHY is reset.
  982. */
  983. e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg);
  984. phy_reg |= M88E1000_EPSCR_TX_CLK_25;
  985. e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_reg);
  986. /* In addition, because of the s/w reset above, we need to enable
  987. * CRS on TX. This must be set for both full and half duplex
  988. * operation.
  989. */
  990. e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_reg);
  991. phy_reg |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  992. e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_reg);
  993. }
  994. static int e1000_nonintegrated_phy_loopback(struct e1000_adapter *adapter)
  995. {
  996. struct e1000_hw *hw = &adapter->hw;
  997. u32 ctrl_reg;
  998. u16 phy_reg;
  999. /* Setup the Device Control Register for PHY loopback test. */
  1000. ctrl_reg = er32(CTRL);
  1001. ctrl_reg |= (E1000_CTRL_ILOS | /* Invert Loss-Of-Signal */
  1002. E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
  1003. E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
  1004. E1000_CTRL_SPD_1000 | /* Force Speed to 1000 */
  1005. E1000_CTRL_FD); /* Force Duplex to FULL */
  1006. ew32(CTRL, ctrl_reg);
  1007. /* Read the PHY Specific Control Register (0x10) */
  1008. e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_reg);
  1009. /* Clear Auto-Crossover bits in PHY Specific Control Register
  1010. * (bits 6:5).
  1011. */
  1012. phy_reg &= ~M88E1000_PSCR_AUTO_X_MODE;
  1013. e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_reg);
  1014. /* Perform software reset on the PHY */
  1015. e1000_phy_reset(hw);
  1016. /* Have to setup TX_CLK and TX_CRS after software reset */
  1017. e1000_phy_reset_clk_and_crs(adapter);
  1018. e1000_write_phy_reg(hw, PHY_CTRL, 0x8100);
  1019. /* Wait for reset to complete. */
  1020. udelay(500);
  1021. /* Have to setup TX_CLK and TX_CRS after software reset */
  1022. e1000_phy_reset_clk_and_crs(adapter);
  1023. /* Write out to PHY registers 29 and 30 to disable the Receiver. */
  1024. e1000_phy_disable_receiver(adapter);
  1025. /* Set the loopback bit in the PHY control register. */
  1026. e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
  1027. phy_reg |= MII_CR_LOOPBACK;
  1028. e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
  1029. /* Setup TX_CLK and TX_CRS one more time. */
  1030. e1000_phy_reset_clk_and_crs(adapter);
  1031. /* Check Phy Configuration */
  1032. e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
  1033. if (phy_reg != 0x4100)
  1034. return 9;
  1035. e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg);
  1036. if (phy_reg != 0x0070)
  1037. return 10;
  1038. e1000_read_phy_reg(hw, 29, &phy_reg);
  1039. if (phy_reg != 0x001A)
  1040. return 11;
  1041. return 0;
  1042. }
  1043. static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
  1044. {
  1045. struct e1000_hw *hw = &adapter->hw;
  1046. u32 ctrl_reg = 0;
  1047. u32 stat_reg = 0;
  1048. hw->autoneg = false;
  1049. if (hw->phy_type == e1000_phy_m88) {
  1050. /* Auto-MDI/MDIX Off */
  1051. e1000_write_phy_reg(hw,
  1052. M88E1000_PHY_SPEC_CTRL, 0x0808);
  1053. /* reset to update Auto-MDI/MDIX */
  1054. e1000_write_phy_reg(hw, PHY_CTRL, 0x9140);
  1055. /* autoneg off */
  1056. e1000_write_phy_reg(hw, PHY_CTRL, 0x8140);
  1057. }
  1058. ctrl_reg = er32(CTRL);
  1059. /* force 1000, set loopback */
  1060. e1000_write_phy_reg(hw, PHY_CTRL, 0x4140);
  1061. /* Now set up the MAC to the same speed/duplex as the PHY. */
  1062. ctrl_reg = er32(CTRL);
  1063. ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
  1064. ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
  1065. E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
  1066. E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
  1067. E1000_CTRL_FD); /* Force Duplex to FULL */
  1068. if (hw->media_type == e1000_media_type_copper &&
  1069. hw->phy_type == e1000_phy_m88)
  1070. ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
  1071. else {
  1072. /* Set the ILOS bit on the fiber Nic is half
  1073. * duplex link is detected.
  1074. */
  1075. stat_reg = er32(STATUS);
  1076. if ((stat_reg & E1000_STATUS_FD) == 0)
  1077. ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
  1078. }
  1079. ew32(CTRL, ctrl_reg);
  1080. /* Disable the receiver on the PHY so when a cable is plugged in, the
  1081. * PHY does not begin to autoneg when a cable is reconnected to the NIC.
  1082. */
  1083. if (hw->phy_type == e1000_phy_m88)
  1084. e1000_phy_disable_receiver(adapter);
  1085. udelay(500);
  1086. return 0;
  1087. }
  1088. static int e1000_set_phy_loopback(struct e1000_adapter *adapter)
  1089. {
  1090. struct e1000_hw *hw = &adapter->hw;
  1091. u16 phy_reg = 0;
  1092. u16 count = 0;
  1093. switch (hw->mac_type) {
  1094. case e1000_82543:
  1095. if (hw->media_type == e1000_media_type_copper) {
  1096. /* Attempt to setup Loopback mode on Non-integrated PHY.
  1097. * Some PHY registers get corrupted at random, so
  1098. * attempt this 10 times.
  1099. */
  1100. while (e1000_nonintegrated_phy_loopback(adapter) &&
  1101. count++ < 10);
  1102. if (count < 11)
  1103. return 0;
  1104. }
  1105. break;
  1106. case e1000_82544:
  1107. case e1000_82540:
  1108. case e1000_82545:
  1109. case e1000_82545_rev_3:
  1110. case e1000_82546:
  1111. case e1000_82546_rev_3:
  1112. case e1000_82541:
  1113. case e1000_82541_rev_2:
  1114. case e1000_82547:
  1115. case e1000_82547_rev_2:
  1116. return e1000_integrated_phy_loopback(adapter);
  1117. default:
  1118. /* Default PHY loopback work is to read the MII
  1119. * control register and assert bit 14 (loopback mode).
  1120. */
  1121. e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
  1122. phy_reg |= MII_CR_LOOPBACK;
  1123. e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
  1124. return 0;
  1125. }
  1126. return 8;
  1127. }
  1128. static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
  1129. {
  1130. struct e1000_hw *hw = &adapter->hw;
  1131. u32 rctl;
  1132. if (hw->media_type == e1000_media_type_fiber ||
  1133. hw->media_type == e1000_media_type_internal_serdes) {
  1134. switch (hw->mac_type) {
  1135. case e1000_82545:
  1136. case e1000_82546:
  1137. case e1000_82545_rev_3:
  1138. case e1000_82546_rev_3:
  1139. return e1000_set_phy_loopback(adapter);
  1140. default:
  1141. rctl = er32(RCTL);
  1142. rctl |= E1000_RCTL_LBM_TCVR;
  1143. ew32(RCTL, rctl);
  1144. return 0;
  1145. }
  1146. } else if (hw->media_type == e1000_media_type_copper) {
  1147. return e1000_set_phy_loopback(adapter);
  1148. }
  1149. return 7;
  1150. }
  1151. static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
  1152. {
  1153. struct e1000_hw *hw = &adapter->hw;
  1154. u32 rctl;
  1155. u16 phy_reg;
  1156. rctl = er32(RCTL);
  1157. rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
  1158. ew32(RCTL, rctl);
  1159. switch (hw->mac_type) {
  1160. case e1000_82545:
  1161. case e1000_82546:
  1162. case e1000_82545_rev_3:
  1163. case e1000_82546_rev_3:
  1164. default:
  1165. hw->autoneg = true;
  1166. e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
  1167. if (phy_reg & MII_CR_LOOPBACK) {
  1168. phy_reg &= ~MII_CR_LOOPBACK;
  1169. e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
  1170. e1000_phy_reset(hw);
  1171. }
  1172. break;
  1173. }
  1174. }
  1175. static void e1000_create_lbtest_frame(struct sk_buff *skb,
  1176. unsigned int frame_size)
  1177. {
  1178. memset(skb->data, 0xFF, frame_size);
  1179. frame_size &= ~1;
  1180. memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
  1181. memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
  1182. memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
  1183. }
  1184. static int e1000_check_lbtest_frame(const unsigned char *data,
  1185. unsigned int frame_size)
  1186. {
  1187. frame_size &= ~1;
  1188. if (*(data + 3) == 0xFF) {
  1189. if ((*(data + frame_size / 2 + 10) == 0xBE) &&
  1190. (*(data + frame_size / 2 + 12) == 0xAF)) {
  1191. return 0;
  1192. }
  1193. }
  1194. return 13;
  1195. }
  1196. static int e1000_run_loopback_test(struct e1000_adapter *adapter)
  1197. {
  1198. struct e1000_hw *hw = &adapter->hw;
  1199. struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
  1200. struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
  1201. struct pci_dev *pdev = adapter->pdev;
  1202. int i, j, k, l, lc, good_cnt, ret_val = 0;
  1203. unsigned long time;
  1204. ew32(RDT, rxdr->count - 1);
  1205. /* Calculate the loop count based on the largest descriptor ring
  1206. * The idea is to wrap the largest ring a number of times using 64
  1207. * send/receive pairs during each loop
  1208. */
  1209. if (rxdr->count <= txdr->count)
  1210. lc = ((txdr->count / 64) * 2) + 1;
  1211. else
  1212. lc = ((rxdr->count / 64) * 2) + 1;
  1213. k = l = 0;
  1214. for (j = 0; j <= lc; j++) { /* loop count loop */
  1215. for (i = 0; i < 64; i++) { /* send the packets */
  1216. e1000_create_lbtest_frame(txdr->buffer_info[i].skb,
  1217. 1024);
  1218. dma_sync_single_for_device(&pdev->dev,
  1219. txdr->buffer_info[k].dma,
  1220. txdr->buffer_info[k].length,
  1221. DMA_TO_DEVICE);
  1222. if (unlikely(++k == txdr->count))
  1223. k = 0;
  1224. }
  1225. ew32(TDT, k);
  1226. E1000_WRITE_FLUSH();
  1227. msleep(200);
  1228. time = jiffies; /* set the start time for the receive */
  1229. good_cnt = 0;
  1230. do { /* receive the sent packets */
  1231. dma_sync_single_for_cpu(&pdev->dev,
  1232. rxdr->buffer_info[l].dma,
  1233. E1000_RXBUFFER_2048,
  1234. DMA_FROM_DEVICE);
  1235. ret_val = e1000_check_lbtest_frame(
  1236. rxdr->buffer_info[l].rxbuf.data +
  1237. NET_SKB_PAD + NET_IP_ALIGN,
  1238. 1024);
  1239. if (!ret_val)
  1240. good_cnt++;
  1241. if (unlikely(++l == rxdr->count))
  1242. l = 0;
  1243. /* time + 20 msecs (200 msecs on 2.4) is more than
  1244. * enough time to complete the receives, if it's
  1245. * exceeded, break and error off
  1246. */
  1247. } while (good_cnt < 64 && time_after(time + 20, jiffies));
  1248. if (good_cnt != 64) {
  1249. ret_val = 13; /* ret_val is the same as mis-compare */
  1250. break;
  1251. }
  1252. if (time_after_eq(jiffies, time + 2)) {
  1253. ret_val = 14; /* error code for time out error */
  1254. break;
  1255. }
  1256. } /* end loop count loop */
  1257. return ret_val;
  1258. }
  1259. static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
  1260. {
  1261. *data = e1000_setup_desc_rings(adapter);
  1262. if (*data)
  1263. goto out;
  1264. *data = e1000_setup_loopback_test(adapter);
  1265. if (*data)
  1266. goto err_loopback;
  1267. *data = e1000_run_loopback_test(adapter);
  1268. e1000_loopback_cleanup(adapter);
  1269. err_loopback:
  1270. e1000_free_desc_rings(adapter);
  1271. out:
  1272. return *data;
  1273. }
  1274. static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
  1275. {
  1276. struct e1000_hw *hw = &adapter->hw;
  1277. *data = 0;
  1278. if (hw->media_type == e1000_media_type_internal_serdes) {
  1279. int i = 0;
  1280. hw->serdes_has_link = false;
  1281. /* On some blade server designs, link establishment
  1282. * could take as long as 2-3 minutes
  1283. */
  1284. do {
  1285. e1000_check_for_link(hw);
  1286. if (hw->serdes_has_link)
  1287. return *data;
  1288. msleep(20);
  1289. } while (i++ < 3750);
  1290. *data = 1;
  1291. } else {
  1292. e1000_check_for_link(hw);
  1293. if (hw->autoneg) /* if auto_neg is set wait for it */
  1294. msleep(4000);
  1295. if (!(er32(STATUS) & E1000_STATUS_LU))
  1296. *data = 1;
  1297. }
  1298. return *data;
  1299. }
  1300. static int e1000_get_sset_count(struct net_device *netdev, int sset)
  1301. {
  1302. switch (sset) {
  1303. case ETH_SS_TEST:
  1304. return E1000_TEST_LEN;
  1305. case ETH_SS_STATS:
  1306. return E1000_STATS_LEN;
  1307. default:
  1308. return -EOPNOTSUPP;
  1309. }
  1310. }
  1311. static void e1000_diag_test(struct net_device *netdev,
  1312. struct ethtool_test *eth_test, u64 *data)
  1313. {
  1314. struct e1000_adapter *adapter = netdev_priv(netdev);
  1315. struct e1000_hw *hw = &adapter->hw;
  1316. bool if_running = netif_running(netdev);
  1317. set_bit(__E1000_TESTING, &adapter->flags);
  1318. if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
  1319. /* Offline tests */
  1320. /* save speed, duplex, autoneg settings */
  1321. u16 autoneg_advertised = hw->autoneg_advertised;
  1322. u8 forced_speed_duplex = hw->forced_speed_duplex;
  1323. u8 autoneg = hw->autoneg;
  1324. e_info(hw, "offline testing starting\n");
  1325. /* Link test performed before hardware reset so autoneg doesn't
  1326. * interfere with test result
  1327. */
  1328. if (e1000_link_test(adapter, &data[4]))
  1329. eth_test->flags |= ETH_TEST_FL_FAILED;
  1330. if (if_running)
  1331. /* indicate we're in test mode */
  1332. dev_close(netdev);
  1333. else
  1334. e1000_reset(adapter);
  1335. if (e1000_reg_test(adapter, &data[0]))
  1336. eth_test->flags |= ETH_TEST_FL_FAILED;
  1337. e1000_reset(adapter);
  1338. if (e1000_eeprom_test(adapter, &data[1]))
  1339. eth_test->flags |= ETH_TEST_FL_FAILED;
  1340. e1000_reset(adapter);
  1341. if (e1000_intr_test(adapter, &data[2]))
  1342. eth_test->flags |= ETH_TEST_FL_FAILED;
  1343. e1000_reset(adapter);
  1344. /* make sure the phy is powered up */
  1345. e1000_power_up_phy(adapter);
  1346. if (e1000_loopback_test(adapter, &data[3]))
  1347. eth_test->flags |= ETH_TEST_FL_FAILED;
  1348. /* restore speed, duplex, autoneg settings */
  1349. hw->autoneg_advertised = autoneg_advertised;
  1350. hw->forced_speed_duplex = forced_speed_duplex;
  1351. hw->autoneg = autoneg;
  1352. e1000_reset(adapter);
  1353. clear_bit(__E1000_TESTING, &adapter->flags);
  1354. if (if_running)
  1355. dev_open(netdev);
  1356. } else {
  1357. e_info(hw, "online testing starting\n");
  1358. /* Online tests */
  1359. if (e1000_link_test(adapter, &data[4]))
  1360. eth_test->flags |= ETH_TEST_FL_FAILED;
  1361. /* Online tests aren't run; pass by default */
  1362. data[0] = 0;
  1363. data[1] = 0;
  1364. data[2] = 0;
  1365. data[3] = 0;
  1366. clear_bit(__E1000_TESTING, &adapter->flags);
  1367. }
  1368. msleep_interruptible(4 * 1000);
  1369. }
  1370. static int e1000_wol_exclusion(struct e1000_adapter *adapter,
  1371. struct ethtool_wolinfo *wol)
  1372. {
  1373. struct e1000_hw *hw = &adapter->hw;
  1374. int retval = 1; /* fail by default */
  1375. switch (hw->device_id) {
  1376. case E1000_DEV_ID_82542:
  1377. case E1000_DEV_ID_82543GC_FIBER:
  1378. case E1000_DEV_ID_82543GC_COPPER:
  1379. case E1000_DEV_ID_82544EI_FIBER:
  1380. case E1000_DEV_ID_82546EB_QUAD_COPPER:
  1381. case E1000_DEV_ID_82545EM_FIBER:
  1382. case E1000_DEV_ID_82545EM_COPPER:
  1383. case E1000_DEV_ID_82546GB_QUAD_COPPER:
  1384. case E1000_DEV_ID_82546GB_PCIE:
  1385. /* these don't support WoL at all */
  1386. wol->supported = 0;
  1387. break;
  1388. case E1000_DEV_ID_82546EB_FIBER:
  1389. case E1000_DEV_ID_82546GB_FIBER:
  1390. /* Wake events not supported on port B */
  1391. if (er32(STATUS) & E1000_STATUS_FUNC_1) {
  1392. wol->supported = 0;
  1393. break;
  1394. }
  1395. /* return success for non excluded adapter ports */
  1396. retval = 0;
  1397. break;
  1398. case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
  1399. /* quad port adapters only support WoL on port A */
  1400. if (!adapter->quad_port_a) {
  1401. wol->supported = 0;
  1402. break;
  1403. }
  1404. /* return success for non excluded adapter ports */
  1405. retval = 0;
  1406. break;
  1407. default:
  1408. /* dual port cards only support WoL on port A from now on
  1409. * unless it was enabled in the eeprom for port B
  1410. * so exclude FUNC_1 ports from having WoL enabled
  1411. */
  1412. if (er32(STATUS) & E1000_STATUS_FUNC_1 &&
  1413. !adapter->eeprom_wol) {
  1414. wol->supported = 0;
  1415. break;
  1416. }
  1417. retval = 0;
  1418. }
  1419. return retval;
  1420. }
  1421. static void e1000_get_wol(struct net_device *netdev,
  1422. struct ethtool_wolinfo *wol)
  1423. {
  1424. struct e1000_adapter *adapter = netdev_priv(netdev);
  1425. struct e1000_hw *hw = &adapter->hw;
  1426. wol->supported = WAKE_UCAST | WAKE_MCAST | WAKE_BCAST | WAKE_MAGIC;
  1427. wol->wolopts = 0;
  1428. /* this function will set ->supported = 0 and return 1 if wol is not
  1429. * supported by this hardware
  1430. */
  1431. if (e1000_wol_exclusion(adapter, wol) ||
  1432. !device_can_wakeup(&adapter->pdev->dev))
  1433. return;
  1434. /* apply any specific unsupported masks here */
  1435. switch (hw->device_id) {
  1436. case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
  1437. /* KSP3 does not support UCAST wake-ups */
  1438. wol->supported &= ~WAKE_UCAST;
  1439. if (adapter->wol & E1000_WUFC_EX)
  1440. e_err(drv, "Interface does not support directed "
  1441. "(unicast) frame wake-up packets\n");
  1442. break;
  1443. default:
  1444. break;
  1445. }
  1446. if (adapter->wol & E1000_WUFC_EX)
  1447. wol->wolopts |= WAKE_UCAST;
  1448. if (adapter->wol & E1000_WUFC_MC)
  1449. wol->wolopts |= WAKE_MCAST;
  1450. if (adapter->wol & E1000_WUFC_BC)
  1451. wol->wolopts |= WAKE_BCAST;
  1452. if (adapter->wol & E1000_WUFC_MAG)
  1453. wol->wolopts |= WAKE_MAGIC;
  1454. }
  1455. static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  1456. {
  1457. struct e1000_adapter *adapter = netdev_priv(netdev);
  1458. struct e1000_hw *hw = &adapter->hw;
  1459. if (wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE))
  1460. return -EOPNOTSUPP;
  1461. if (e1000_wol_exclusion(adapter, wol) ||
  1462. !device_can_wakeup(&adapter->pdev->dev))
  1463. return wol->wolopts ? -EOPNOTSUPP : 0;
  1464. switch (hw->device_id) {
  1465. case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
  1466. if (wol->wolopts & WAKE_UCAST) {
  1467. e_err(drv, "Interface does not support directed "
  1468. "(unicast) frame wake-up packets\n");
  1469. return -EOPNOTSUPP;
  1470. }
  1471. break;
  1472. default:
  1473. break;
  1474. }
  1475. /* these settings will always override what we currently have */
  1476. adapter->wol = 0;
  1477. if (wol->wolopts & WAKE_UCAST)
  1478. adapter->wol |= E1000_WUFC_EX;
  1479. if (wol->wolopts & WAKE_MCAST)
  1480. adapter->wol |= E1000_WUFC_MC;
  1481. if (wol->wolopts & WAKE_BCAST)
  1482. adapter->wol |= E1000_WUFC_BC;
  1483. if (wol->wolopts & WAKE_MAGIC)
  1484. adapter->wol |= E1000_WUFC_MAG;
  1485. device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
  1486. return 0;
  1487. }
  1488. static int e1000_set_phys_id(struct net_device *netdev,
  1489. enum ethtool_phys_id_state state)
  1490. {
  1491. struct e1000_adapter *adapter = netdev_priv(netdev);
  1492. struct e1000_hw *hw = &adapter->hw;
  1493. switch (state) {
  1494. case ETHTOOL_ID_ACTIVE:
  1495. e1000_setup_led(hw);
  1496. return 2;
  1497. case ETHTOOL_ID_ON:
  1498. e1000_led_on(hw);
  1499. break;
  1500. case ETHTOOL_ID_OFF:
  1501. e1000_led_off(hw);
  1502. break;
  1503. case ETHTOOL_ID_INACTIVE:
  1504. e1000_cleanup_led(hw);
  1505. }
  1506. return 0;
  1507. }
  1508. static int e1000_get_coalesce(struct net_device *netdev,
  1509. struct ethtool_coalesce *ec)
  1510. {
  1511. struct e1000_adapter *adapter = netdev_priv(netdev);
  1512. if (adapter->hw.mac_type < e1000_82545)
  1513. return -EOPNOTSUPP;
  1514. if (adapter->itr_setting <= 4)
  1515. ec->rx_coalesce_usecs = adapter->itr_setting;
  1516. else
  1517. ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
  1518. return 0;
  1519. }
  1520. static int e1000_set_coalesce(struct net_device *netdev,
  1521. struct ethtool_coalesce *ec)
  1522. {
  1523. struct e1000_adapter *adapter = netdev_priv(netdev);
  1524. struct e1000_hw *hw = &adapter->hw;
  1525. if (hw->mac_type < e1000_82545)
  1526. return -EOPNOTSUPP;
  1527. if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
  1528. ((ec->rx_coalesce_usecs > 4) &&
  1529. (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
  1530. (ec->rx_coalesce_usecs == 2))
  1531. return -EINVAL;
  1532. if (ec->rx_coalesce_usecs == 4) {
  1533. adapter->itr = adapter->itr_setting = 4;
  1534. } else if (ec->rx_coalesce_usecs <= 3) {
  1535. adapter->itr = 20000;
  1536. adapter->itr_setting = ec->rx_coalesce_usecs;
  1537. } else {
  1538. adapter->itr = (1000000 / ec->rx_coalesce_usecs);
  1539. adapter->itr_setting = adapter->itr & ~3;
  1540. }
  1541. if (adapter->itr_setting != 0)
  1542. ew32(ITR, 1000000000 / (adapter->itr * 256));
  1543. else
  1544. ew32(ITR, 0);
  1545. return 0;
  1546. }
  1547. static int e1000_nway_reset(struct net_device *netdev)
  1548. {
  1549. struct e1000_adapter *adapter = netdev_priv(netdev);
  1550. if (netif_running(netdev))
  1551. e1000_reinit_locked(adapter);
  1552. return 0;
  1553. }
  1554. static void e1000_get_ethtool_stats(struct net_device *netdev,
  1555. struct ethtool_stats *stats, u64 *data)
  1556. {
  1557. struct e1000_adapter *adapter = netdev_priv(netdev);
  1558. int i;
  1559. char *p = NULL;
  1560. const struct e1000_stats *stat = e1000_gstrings_stats;
  1561. e1000_update_stats(adapter);
  1562. for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
  1563. switch (stat->type) {
  1564. case NETDEV_STATS:
  1565. p = (char *)netdev + stat->stat_offset;
  1566. break;
  1567. case E1000_STATS:
  1568. p = (char *)adapter + stat->stat_offset;
  1569. break;
  1570. default:
  1571. WARN_ONCE(1, "Invalid E1000 stat type: %u index %d\n",
  1572. stat->type, i);
  1573. break;
  1574. }
  1575. if (stat->sizeof_stat == sizeof(u64))
  1576. data[i] = *(u64 *)p;
  1577. else
  1578. data[i] = *(u32 *)p;
  1579. stat++;
  1580. }
  1581. /* BUG_ON(i != E1000_STATS_LEN); */
  1582. }
  1583. static void e1000_get_strings(struct net_device *netdev, u32 stringset,
  1584. u8 *data)
  1585. {
  1586. u8 *p = data;
  1587. int i;
  1588. switch (stringset) {
  1589. case ETH_SS_TEST:
  1590. memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test));
  1591. break;
  1592. case ETH_SS_STATS:
  1593. for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
  1594. memcpy(p, e1000_gstrings_stats[i].stat_string,
  1595. ETH_GSTRING_LEN);
  1596. p += ETH_GSTRING_LEN;
  1597. }
  1598. /* BUG_ON(p - data != E1000_STATS_LEN * ETH_GSTRING_LEN); */
  1599. break;
  1600. }
  1601. }
  1602. static const struct ethtool_ops e1000_ethtool_ops = {
  1603. .get_settings = e1000_get_settings,
  1604. .set_settings = e1000_set_settings,
  1605. .get_drvinfo = e1000_get_drvinfo,
  1606. .get_regs_len = e1000_get_regs_len,
  1607. .get_regs = e1000_get_regs,
  1608. .get_wol = e1000_get_wol,
  1609. .set_wol = e1000_set_wol,
  1610. .get_msglevel = e1000_get_msglevel,
  1611. .set_msglevel = e1000_set_msglevel,
  1612. .nway_reset = e1000_nway_reset,
  1613. .get_link = e1000_get_link,
  1614. .get_eeprom_len = e1000_get_eeprom_len,
  1615. .get_eeprom = e1000_get_eeprom,
  1616. .set_eeprom = e1000_set_eeprom,
  1617. .get_ringparam = e1000_get_ringparam,
  1618. .set_ringparam = e1000_set_ringparam,
  1619. .get_pauseparam = e1000_get_pauseparam,
  1620. .set_pauseparam = e1000_set_pauseparam,
  1621. .self_test = e1000_diag_test,
  1622. .get_strings = e1000_get_strings,
  1623. .set_phys_id = e1000_set_phys_id,
  1624. .get_ethtool_stats = e1000_get_ethtool_stats,
  1625. .get_sset_count = e1000_get_sset_count,
  1626. .get_coalesce = e1000_get_coalesce,
  1627. .set_coalesce = e1000_set_coalesce,
  1628. .get_ts_info = ethtool_op_get_ts_info,
  1629. };
  1630. void e1000_set_ethtool_ops(struct net_device *netdev)
  1631. {
  1632. netdev->ethtool_ops = &e1000_ethtool_ops;
  1633. }