ethtool.c 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322
  1. /* Intel PRO/1000 Linux driver
  2. * Copyright(c) 1999 - 2014 Intel Corporation.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * The full GNU General Public License is included in this distribution in
  14. * the file called "COPYING".
  15. *
  16. * Contact Information:
  17. * Linux NICS <linux.nics@intel.com>
  18. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. */
  21. /* ethtool support for e1000 */
  22. #include <linux/netdevice.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/ethtool.h>
  25. #include <linux/pci.h>
  26. #include <linux/slab.h>
  27. #include <linux/delay.h>
  28. #include <linux/vmalloc.h>
  29. #include <linux/pm_runtime.h>
  30. #include "e1000.h"
  31. enum { NETDEV_STATS, E1000_STATS };
  32. struct e1000_stats {
  33. char stat_string[ETH_GSTRING_LEN];
  34. int type;
  35. int sizeof_stat;
  36. int stat_offset;
  37. };
  38. #define E1000_STAT(str, m) { \
  39. .stat_string = str, \
  40. .type = E1000_STATS, \
  41. .sizeof_stat = sizeof(((struct e1000_adapter *)0)->m), \
  42. .stat_offset = offsetof(struct e1000_adapter, m) }
  43. #define E1000_NETDEV_STAT(str, m) { \
  44. .stat_string = str, \
  45. .type = NETDEV_STATS, \
  46. .sizeof_stat = sizeof(((struct rtnl_link_stats64 *)0)->m), \
  47. .stat_offset = offsetof(struct rtnl_link_stats64, m) }
  48. static const struct e1000_stats e1000_gstrings_stats[] = {
  49. E1000_STAT("rx_packets", stats.gprc),
  50. E1000_STAT("tx_packets", stats.gptc),
  51. E1000_STAT("rx_bytes", stats.gorc),
  52. E1000_STAT("tx_bytes", stats.gotc),
  53. E1000_STAT("rx_broadcast", stats.bprc),
  54. E1000_STAT("tx_broadcast", stats.bptc),
  55. E1000_STAT("rx_multicast", stats.mprc),
  56. E1000_STAT("tx_multicast", stats.mptc),
  57. E1000_NETDEV_STAT("rx_errors", rx_errors),
  58. E1000_NETDEV_STAT("tx_errors", tx_errors),
  59. E1000_NETDEV_STAT("tx_dropped", tx_dropped),
  60. E1000_STAT("multicast", stats.mprc),
  61. E1000_STAT("collisions", stats.colc),
  62. E1000_NETDEV_STAT("rx_length_errors", rx_length_errors),
  63. E1000_NETDEV_STAT("rx_over_errors", rx_over_errors),
  64. E1000_STAT("rx_crc_errors", stats.crcerrs),
  65. E1000_NETDEV_STAT("rx_frame_errors", rx_frame_errors),
  66. E1000_STAT("rx_no_buffer_count", stats.rnbc),
  67. E1000_STAT("rx_missed_errors", stats.mpc),
  68. E1000_STAT("tx_aborted_errors", stats.ecol),
  69. E1000_STAT("tx_carrier_errors", stats.tncrs),
  70. E1000_NETDEV_STAT("tx_fifo_errors", tx_fifo_errors),
  71. E1000_NETDEV_STAT("tx_heartbeat_errors", tx_heartbeat_errors),
  72. E1000_STAT("tx_window_errors", stats.latecol),
  73. E1000_STAT("tx_abort_late_coll", stats.latecol),
  74. E1000_STAT("tx_deferred_ok", stats.dc),
  75. E1000_STAT("tx_single_coll_ok", stats.scc),
  76. E1000_STAT("tx_multi_coll_ok", stats.mcc),
  77. E1000_STAT("tx_timeout_count", tx_timeout_count),
  78. E1000_STAT("tx_restart_queue", restart_queue),
  79. E1000_STAT("rx_long_length_errors", stats.roc),
  80. E1000_STAT("rx_short_length_errors", stats.ruc),
  81. E1000_STAT("rx_align_errors", stats.algnerrc),
  82. E1000_STAT("tx_tcp_seg_good", stats.tsctc),
  83. E1000_STAT("tx_tcp_seg_failed", stats.tsctfc),
  84. E1000_STAT("rx_flow_control_xon", stats.xonrxc),
  85. E1000_STAT("rx_flow_control_xoff", stats.xoffrxc),
  86. E1000_STAT("tx_flow_control_xon", stats.xontxc),
  87. E1000_STAT("tx_flow_control_xoff", stats.xofftxc),
  88. E1000_STAT("rx_csum_offload_good", hw_csum_good),
  89. E1000_STAT("rx_csum_offload_errors", hw_csum_err),
  90. E1000_STAT("rx_header_split", rx_hdr_split),
  91. E1000_STAT("alloc_rx_buff_failed", alloc_rx_buff_failed),
  92. E1000_STAT("tx_smbus", stats.mgptc),
  93. E1000_STAT("rx_smbus", stats.mgprc),
  94. E1000_STAT("dropped_smbus", stats.mgpdc),
  95. E1000_STAT("rx_dma_failed", rx_dma_failed),
  96. E1000_STAT("tx_dma_failed", tx_dma_failed),
  97. E1000_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
  98. E1000_STAT("uncorr_ecc_errors", uncorr_errors),
  99. E1000_STAT("corr_ecc_errors", corr_errors),
  100. E1000_STAT("tx_hwtstamp_timeouts", tx_hwtstamp_timeouts),
  101. };
  102. #define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
  103. #define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)
  104. static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
  105. "Register test (offline)", "Eeprom test (offline)",
  106. "Interrupt test (offline)", "Loopback test (offline)",
  107. "Link test (on/offline)"
  108. };
  109. #define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
  110. static int e1000_get_settings(struct net_device *netdev,
  111. struct ethtool_cmd *ecmd)
  112. {
  113. struct e1000_adapter *adapter = netdev_priv(netdev);
  114. struct e1000_hw *hw = &adapter->hw;
  115. u32 speed;
  116. if (hw->phy.media_type == e1000_media_type_copper) {
  117. ecmd->supported = (SUPPORTED_10baseT_Half |
  118. SUPPORTED_10baseT_Full |
  119. SUPPORTED_100baseT_Half |
  120. SUPPORTED_100baseT_Full |
  121. SUPPORTED_1000baseT_Full |
  122. SUPPORTED_Autoneg |
  123. SUPPORTED_TP);
  124. if (hw->phy.type == e1000_phy_ife)
  125. ecmd->supported &= ~SUPPORTED_1000baseT_Full;
  126. ecmd->advertising = ADVERTISED_TP;
  127. if (hw->mac.autoneg == 1) {
  128. ecmd->advertising |= ADVERTISED_Autoneg;
  129. /* the e1000 autoneg seems to match ethtool nicely */
  130. ecmd->advertising |= hw->phy.autoneg_advertised;
  131. }
  132. ecmd->port = PORT_TP;
  133. ecmd->phy_address = hw->phy.addr;
  134. ecmd->transceiver = XCVR_INTERNAL;
  135. } else {
  136. ecmd->supported = (SUPPORTED_1000baseT_Full |
  137. SUPPORTED_FIBRE |
  138. SUPPORTED_Autoneg);
  139. ecmd->advertising = (ADVERTISED_1000baseT_Full |
  140. ADVERTISED_FIBRE |
  141. ADVERTISED_Autoneg);
  142. ecmd->port = PORT_FIBRE;
  143. ecmd->transceiver = XCVR_EXTERNAL;
  144. }
  145. speed = SPEED_UNKNOWN;
  146. ecmd->duplex = DUPLEX_UNKNOWN;
  147. if (netif_running(netdev)) {
  148. if (netif_carrier_ok(netdev)) {
  149. speed = adapter->link_speed;
  150. ecmd->duplex = adapter->link_duplex - 1;
  151. }
  152. } else if (!pm_runtime_suspended(netdev->dev.parent)) {
  153. u32 status = er32(STATUS);
  154. if (status & E1000_STATUS_LU) {
  155. if (status & E1000_STATUS_SPEED_1000)
  156. speed = SPEED_1000;
  157. else if (status & E1000_STATUS_SPEED_100)
  158. speed = SPEED_100;
  159. else
  160. speed = SPEED_10;
  161. if (status & E1000_STATUS_FD)
  162. ecmd->duplex = DUPLEX_FULL;
  163. else
  164. ecmd->duplex = DUPLEX_HALF;
  165. }
  166. }
  167. ethtool_cmd_speed_set(ecmd, speed);
  168. ecmd->autoneg = ((hw->phy.media_type == e1000_media_type_fiber) ||
  169. hw->mac.autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
  170. /* MDI-X => 2; MDI =>1; Invalid =>0 */
  171. if ((hw->phy.media_type == e1000_media_type_copper) &&
  172. netif_carrier_ok(netdev))
  173. ecmd->eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X : ETH_TP_MDI;
  174. else
  175. ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID;
  176. if (hw->phy.mdix == AUTO_ALL_MODES)
  177. ecmd->eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO;
  178. else
  179. ecmd->eth_tp_mdix_ctrl = hw->phy.mdix;
  180. return 0;
  181. }
  182. static int e1000_set_spd_dplx(struct e1000_adapter *adapter, u32 spd, u8 dplx)
  183. {
  184. struct e1000_mac_info *mac = &adapter->hw.mac;
  185. mac->autoneg = 0;
  186. /* Make sure dplx is at most 1 bit and lsb of speed is not set
  187. * for the switch() below to work
  188. */
  189. if ((spd & 1) || (dplx & ~1))
  190. goto err_inval;
  191. /* Fiber NICs only allow 1000 gbps Full duplex */
  192. if ((adapter->hw.phy.media_type == e1000_media_type_fiber) &&
  193. (spd != SPEED_1000) && (dplx != DUPLEX_FULL)) {
  194. goto err_inval;
  195. }
  196. switch (spd + dplx) {
  197. case SPEED_10 + DUPLEX_HALF:
  198. mac->forced_speed_duplex = ADVERTISE_10_HALF;
  199. break;
  200. case SPEED_10 + DUPLEX_FULL:
  201. mac->forced_speed_duplex = ADVERTISE_10_FULL;
  202. break;
  203. case SPEED_100 + DUPLEX_HALF:
  204. mac->forced_speed_duplex = ADVERTISE_100_HALF;
  205. break;
  206. case SPEED_100 + DUPLEX_FULL:
  207. mac->forced_speed_duplex = ADVERTISE_100_FULL;
  208. break;
  209. case SPEED_1000 + DUPLEX_FULL:
  210. mac->autoneg = 1;
  211. adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
  212. break;
  213. case SPEED_1000 + DUPLEX_HALF: /* not supported */
  214. default:
  215. goto err_inval;
  216. }
  217. /* clear MDI, MDI(-X) override is only allowed when autoneg enabled */
  218. adapter->hw.phy.mdix = AUTO_ALL_MODES;
  219. return 0;
  220. err_inval:
  221. e_err("Unsupported Speed/Duplex configuration\n");
  222. return -EINVAL;
  223. }
  224. static int e1000_set_settings(struct net_device *netdev,
  225. struct ethtool_cmd *ecmd)
  226. {
  227. struct e1000_adapter *adapter = netdev_priv(netdev);
  228. struct e1000_hw *hw = &adapter->hw;
  229. int ret_val = 0;
  230. pm_runtime_get_sync(netdev->dev.parent);
  231. /* When SoL/IDER sessions are active, autoneg/speed/duplex
  232. * cannot be changed
  233. */
  234. if (hw->phy.ops.check_reset_block &&
  235. hw->phy.ops.check_reset_block(hw)) {
  236. e_err("Cannot change link characteristics when SoL/IDER is active.\n");
  237. ret_val = -EINVAL;
  238. goto out;
  239. }
  240. /* MDI setting is only allowed when autoneg enabled because
  241. * some hardware doesn't allow MDI setting when speed or
  242. * duplex is forced.
  243. */
  244. if (ecmd->eth_tp_mdix_ctrl) {
  245. if (hw->phy.media_type != e1000_media_type_copper) {
  246. ret_val = -EOPNOTSUPP;
  247. goto out;
  248. }
  249. if ((ecmd->eth_tp_mdix_ctrl != ETH_TP_MDI_AUTO) &&
  250. (ecmd->autoneg != AUTONEG_ENABLE)) {
  251. e_err("forcing MDI/MDI-X state is not supported when link speed and/or duplex are forced\n");
  252. ret_val = -EINVAL;
  253. goto out;
  254. }
  255. }
  256. while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
  257. usleep_range(1000, 2000);
  258. if (ecmd->autoneg == AUTONEG_ENABLE) {
  259. hw->mac.autoneg = 1;
  260. if (hw->phy.media_type == e1000_media_type_fiber)
  261. hw->phy.autoneg_advertised = ADVERTISED_1000baseT_Full |
  262. ADVERTISED_FIBRE | ADVERTISED_Autoneg;
  263. else
  264. hw->phy.autoneg_advertised = ecmd->advertising |
  265. ADVERTISED_TP | ADVERTISED_Autoneg;
  266. ecmd->advertising = hw->phy.autoneg_advertised;
  267. if (adapter->fc_autoneg)
  268. hw->fc.requested_mode = e1000_fc_default;
  269. } else {
  270. u32 speed = ethtool_cmd_speed(ecmd);
  271. /* calling this overrides forced MDI setting */
  272. if (e1000_set_spd_dplx(adapter, speed, ecmd->duplex)) {
  273. ret_val = -EINVAL;
  274. goto out;
  275. }
  276. }
  277. /* MDI-X => 2; MDI => 1; Auto => 3 */
  278. if (ecmd->eth_tp_mdix_ctrl) {
  279. /* fix up the value for auto (3 => 0) as zero is mapped
  280. * internally to auto
  281. */
  282. if (ecmd->eth_tp_mdix_ctrl == ETH_TP_MDI_AUTO)
  283. hw->phy.mdix = AUTO_ALL_MODES;
  284. else
  285. hw->phy.mdix = ecmd->eth_tp_mdix_ctrl;
  286. }
  287. /* reset the link */
  288. if (netif_running(adapter->netdev)) {
  289. e1000e_down(adapter, true);
  290. e1000e_up(adapter);
  291. } else {
  292. e1000e_reset(adapter);
  293. }
  294. out:
  295. pm_runtime_put_sync(netdev->dev.parent);
  296. clear_bit(__E1000_RESETTING, &adapter->state);
  297. return ret_val;
  298. }
  299. static void e1000_get_pauseparam(struct net_device *netdev,
  300. struct ethtool_pauseparam *pause)
  301. {
  302. struct e1000_adapter *adapter = netdev_priv(netdev);
  303. struct e1000_hw *hw = &adapter->hw;
  304. pause->autoneg =
  305. (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
  306. if (hw->fc.current_mode == e1000_fc_rx_pause) {
  307. pause->rx_pause = 1;
  308. } else if (hw->fc.current_mode == e1000_fc_tx_pause) {
  309. pause->tx_pause = 1;
  310. } else if (hw->fc.current_mode == e1000_fc_full) {
  311. pause->rx_pause = 1;
  312. pause->tx_pause = 1;
  313. }
  314. }
  315. static int e1000_set_pauseparam(struct net_device *netdev,
  316. struct ethtool_pauseparam *pause)
  317. {
  318. struct e1000_adapter *adapter = netdev_priv(netdev);
  319. struct e1000_hw *hw = &adapter->hw;
  320. int retval = 0;
  321. adapter->fc_autoneg = pause->autoneg;
  322. while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
  323. usleep_range(1000, 2000);
  324. pm_runtime_get_sync(netdev->dev.parent);
  325. if (adapter->fc_autoneg == AUTONEG_ENABLE) {
  326. hw->fc.requested_mode = e1000_fc_default;
  327. if (netif_running(adapter->netdev)) {
  328. e1000e_down(adapter, true);
  329. e1000e_up(adapter);
  330. } else {
  331. e1000e_reset(adapter);
  332. }
  333. } else {
  334. if (pause->rx_pause && pause->tx_pause)
  335. hw->fc.requested_mode = e1000_fc_full;
  336. else if (pause->rx_pause && !pause->tx_pause)
  337. hw->fc.requested_mode = e1000_fc_rx_pause;
  338. else if (!pause->rx_pause && pause->tx_pause)
  339. hw->fc.requested_mode = e1000_fc_tx_pause;
  340. else if (!pause->rx_pause && !pause->tx_pause)
  341. hw->fc.requested_mode = e1000_fc_none;
  342. hw->fc.current_mode = hw->fc.requested_mode;
  343. if (hw->phy.media_type == e1000_media_type_fiber) {
  344. retval = hw->mac.ops.setup_link(hw);
  345. /* implicit goto out */
  346. } else {
  347. retval = e1000e_force_mac_fc(hw);
  348. if (retval)
  349. goto out;
  350. e1000e_set_fc_watermarks(hw);
  351. }
  352. }
  353. out:
  354. pm_runtime_put_sync(netdev->dev.parent);
  355. clear_bit(__E1000_RESETTING, &adapter->state);
  356. return retval;
  357. }
  358. static u32 e1000_get_msglevel(struct net_device *netdev)
  359. {
  360. struct e1000_adapter *adapter = netdev_priv(netdev);
  361. return adapter->msg_enable;
  362. }
  363. static void e1000_set_msglevel(struct net_device *netdev, u32 data)
  364. {
  365. struct e1000_adapter *adapter = netdev_priv(netdev);
  366. adapter->msg_enable = data;
  367. }
  368. static int e1000_get_regs_len(struct net_device __always_unused *netdev)
  369. {
  370. #define E1000_REGS_LEN 32 /* overestimate */
  371. return E1000_REGS_LEN * sizeof(u32);
  372. }
  373. static void e1000_get_regs(struct net_device *netdev,
  374. struct ethtool_regs *regs, void *p)
  375. {
  376. struct e1000_adapter *adapter = netdev_priv(netdev);
  377. struct e1000_hw *hw = &adapter->hw;
  378. u32 *regs_buff = p;
  379. u16 phy_data;
  380. pm_runtime_get_sync(netdev->dev.parent);
  381. memset(p, 0, E1000_REGS_LEN * sizeof(u32));
  382. regs->version = (1 << 24) | (adapter->pdev->revision << 16) |
  383. adapter->pdev->device;
  384. regs_buff[0] = er32(CTRL);
  385. regs_buff[1] = er32(STATUS);
  386. regs_buff[2] = er32(RCTL);
  387. regs_buff[3] = er32(RDLEN(0));
  388. regs_buff[4] = er32(RDH(0));
  389. regs_buff[5] = er32(RDT(0));
  390. regs_buff[6] = er32(RDTR);
  391. regs_buff[7] = er32(TCTL);
  392. regs_buff[8] = er32(TDLEN(0));
  393. regs_buff[9] = er32(TDH(0));
  394. regs_buff[10] = er32(TDT(0));
  395. regs_buff[11] = er32(TIDV);
  396. regs_buff[12] = adapter->hw.phy.type; /* PHY type (IGP=1, M88=0) */
  397. /* ethtool doesn't use anything past this point, so all this
  398. * code is likely legacy junk for apps that may or may not exist
  399. */
  400. if (hw->phy.type == e1000_phy_m88) {
  401. e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
  402. regs_buff[13] = (u32)phy_data; /* cable length */
  403. regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
  404. regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
  405. regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
  406. e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  407. regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
  408. regs_buff[18] = regs_buff[13]; /* cable polarity */
  409. regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
  410. regs_buff[20] = regs_buff[17]; /* polarity correction */
  411. /* phy receive errors */
  412. regs_buff[22] = adapter->phy_stats.receive_errors;
  413. regs_buff[23] = regs_buff[13]; /* mdix mode */
  414. }
  415. regs_buff[21] = 0; /* was idle_errors */
  416. e1e_rphy(hw, MII_STAT1000, &phy_data);
  417. regs_buff[24] = (u32)phy_data; /* phy local receiver status */
  418. regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
  419. pm_runtime_put_sync(netdev->dev.parent);
  420. }
  421. static int e1000_get_eeprom_len(struct net_device *netdev)
  422. {
  423. struct e1000_adapter *adapter = netdev_priv(netdev);
  424. return adapter->hw.nvm.word_size * 2;
  425. }
  426. static int e1000_get_eeprom(struct net_device *netdev,
  427. struct ethtool_eeprom *eeprom, u8 *bytes)
  428. {
  429. struct e1000_adapter *adapter = netdev_priv(netdev);
  430. struct e1000_hw *hw = &adapter->hw;
  431. u16 *eeprom_buff;
  432. int first_word;
  433. int last_word;
  434. int ret_val = 0;
  435. u16 i;
  436. if (eeprom->len == 0)
  437. return -EINVAL;
  438. eeprom->magic = adapter->pdev->vendor | (adapter->pdev->device << 16);
  439. first_word = eeprom->offset >> 1;
  440. last_word = (eeprom->offset + eeprom->len - 1) >> 1;
  441. eeprom_buff = kmalloc(sizeof(u16) * (last_word - first_word + 1),
  442. GFP_KERNEL);
  443. if (!eeprom_buff)
  444. return -ENOMEM;
  445. pm_runtime_get_sync(netdev->dev.parent);
  446. if (hw->nvm.type == e1000_nvm_eeprom_spi) {
  447. ret_val = e1000_read_nvm(hw, first_word,
  448. last_word - first_word + 1,
  449. eeprom_buff);
  450. } else {
  451. for (i = 0; i < last_word - first_word + 1; i++) {
  452. ret_val = e1000_read_nvm(hw, first_word + i, 1,
  453. &eeprom_buff[i]);
  454. if (ret_val)
  455. break;
  456. }
  457. }
  458. pm_runtime_put_sync(netdev->dev.parent);
  459. if (ret_val) {
  460. /* a read error occurred, throw away the result */
  461. memset(eeprom_buff, 0xff, sizeof(u16) *
  462. (last_word - first_word + 1));
  463. } else {
  464. /* Device's eeprom is always little-endian, word addressable */
  465. for (i = 0; i < last_word - first_word + 1; i++)
  466. le16_to_cpus(&eeprom_buff[i]);
  467. }
  468. memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
  469. kfree(eeprom_buff);
  470. return ret_val;
  471. }
  472. static int e1000_set_eeprom(struct net_device *netdev,
  473. struct ethtool_eeprom *eeprom, u8 *bytes)
  474. {
  475. struct e1000_adapter *adapter = netdev_priv(netdev);
  476. struct e1000_hw *hw = &adapter->hw;
  477. u16 *eeprom_buff;
  478. void *ptr;
  479. int max_len;
  480. int first_word;
  481. int last_word;
  482. int ret_val = 0;
  483. u16 i;
  484. if (eeprom->len == 0)
  485. return -EOPNOTSUPP;
  486. if (eeprom->magic !=
  487. (adapter->pdev->vendor | (adapter->pdev->device << 16)))
  488. return -EFAULT;
  489. if (adapter->flags & FLAG_READ_ONLY_NVM)
  490. return -EINVAL;
  491. max_len = hw->nvm.word_size * 2;
  492. first_word = eeprom->offset >> 1;
  493. last_word = (eeprom->offset + eeprom->len - 1) >> 1;
  494. eeprom_buff = kmalloc(max_len, GFP_KERNEL);
  495. if (!eeprom_buff)
  496. return -ENOMEM;
  497. ptr = (void *)eeprom_buff;
  498. pm_runtime_get_sync(netdev->dev.parent);
  499. if (eeprom->offset & 1) {
  500. /* need read/modify/write of first changed EEPROM word */
  501. /* only the second byte of the word is being modified */
  502. ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]);
  503. ptr++;
  504. }
  505. if (((eeprom->offset + eeprom->len) & 1) && (!ret_val))
  506. /* need read/modify/write of last changed EEPROM word */
  507. /* only the first byte of the word is being modified */
  508. ret_val = e1000_read_nvm(hw, last_word, 1,
  509. &eeprom_buff[last_word - first_word]);
  510. if (ret_val)
  511. goto out;
  512. /* Device's eeprom is always little-endian, word addressable */
  513. for (i = 0; i < last_word - first_word + 1; i++)
  514. le16_to_cpus(&eeprom_buff[i]);
  515. memcpy(ptr, bytes, eeprom->len);
  516. for (i = 0; i < last_word - first_word + 1; i++)
  517. cpu_to_le16s(&eeprom_buff[i]);
  518. ret_val = e1000_write_nvm(hw, first_word,
  519. last_word - first_word + 1, eeprom_buff);
  520. if (ret_val)
  521. goto out;
  522. /* Update the checksum over the first part of the EEPROM if needed
  523. * and flush shadow RAM for applicable controllers
  524. */
  525. if ((first_word <= NVM_CHECKSUM_REG) ||
  526. (hw->mac.type == e1000_82583) ||
  527. (hw->mac.type == e1000_82574) ||
  528. (hw->mac.type == e1000_82573))
  529. ret_val = e1000e_update_nvm_checksum(hw);
  530. out:
  531. pm_runtime_put_sync(netdev->dev.parent);
  532. kfree(eeprom_buff);
  533. return ret_val;
  534. }
  535. static void e1000_get_drvinfo(struct net_device *netdev,
  536. struct ethtool_drvinfo *drvinfo)
  537. {
  538. struct e1000_adapter *adapter = netdev_priv(netdev);
  539. strlcpy(drvinfo->driver, e1000e_driver_name, sizeof(drvinfo->driver));
  540. strlcpy(drvinfo->version, e1000e_driver_version,
  541. sizeof(drvinfo->version));
  542. /* EEPROM image version # is reported as firmware version # for
  543. * PCI-E controllers
  544. */
  545. snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
  546. "%d.%d-%d",
  547. (adapter->eeprom_vers & 0xF000) >> 12,
  548. (adapter->eeprom_vers & 0x0FF0) >> 4,
  549. (adapter->eeprom_vers & 0x000F));
  550. strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
  551. sizeof(drvinfo->bus_info));
  552. drvinfo->regdump_len = e1000_get_regs_len(netdev);
  553. drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
  554. }
  555. static void e1000_get_ringparam(struct net_device *netdev,
  556. struct ethtool_ringparam *ring)
  557. {
  558. struct e1000_adapter *adapter = netdev_priv(netdev);
  559. ring->rx_max_pending = E1000_MAX_RXD;
  560. ring->tx_max_pending = E1000_MAX_TXD;
  561. ring->rx_pending = adapter->rx_ring_count;
  562. ring->tx_pending = adapter->tx_ring_count;
  563. }
  564. static int e1000_set_ringparam(struct net_device *netdev,
  565. struct ethtool_ringparam *ring)
  566. {
  567. struct e1000_adapter *adapter = netdev_priv(netdev);
  568. struct e1000_ring *temp_tx = NULL, *temp_rx = NULL;
  569. int err = 0, size = sizeof(struct e1000_ring);
  570. bool set_tx = false, set_rx = false;
  571. u16 new_rx_count, new_tx_count;
  572. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  573. return -EINVAL;
  574. new_rx_count = clamp_t(u32, ring->rx_pending, E1000_MIN_RXD,
  575. E1000_MAX_RXD);
  576. new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE);
  577. new_tx_count = clamp_t(u32, ring->tx_pending, E1000_MIN_TXD,
  578. E1000_MAX_TXD);
  579. new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE);
  580. if ((new_tx_count == adapter->tx_ring_count) &&
  581. (new_rx_count == adapter->rx_ring_count))
  582. /* nothing to do */
  583. return 0;
  584. while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
  585. usleep_range(1000, 2000);
  586. if (!netif_running(adapter->netdev)) {
  587. /* Set counts now and allocate resources during open() */
  588. adapter->tx_ring->count = new_tx_count;
  589. adapter->rx_ring->count = new_rx_count;
  590. adapter->tx_ring_count = new_tx_count;
  591. adapter->rx_ring_count = new_rx_count;
  592. goto clear_reset;
  593. }
  594. set_tx = (new_tx_count != adapter->tx_ring_count);
  595. set_rx = (new_rx_count != adapter->rx_ring_count);
  596. /* Allocate temporary storage for ring updates */
  597. if (set_tx) {
  598. temp_tx = vmalloc(size);
  599. if (!temp_tx) {
  600. err = -ENOMEM;
  601. goto free_temp;
  602. }
  603. }
  604. if (set_rx) {
  605. temp_rx = vmalloc(size);
  606. if (!temp_rx) {
  607. err = -ENOMEM;
  608. goto free_temp;
  609. }
  610. }
  611. pm_runtime_get_sync(netdev->dev.parent);
  612. e1000e_down(adapter, true);
  613. /* We can't just free everything and then setup again, because the
  614. * ISRs in MSI-X mode get passed pointers to the Tx and Rx ring
  615. * structs. First, attempt to allocate new resources...
  616. */
  617. if (set_tx) {
  618. memcpy(temp_tx, adapter->tx_ring, size);
  619. temp_tx->count = new_tx_count;
  620. err = e1000e_setup_tx_resources(temp_tx);
  621. if (err)
  622. goto err_setup;
  623. }
  624. if (set_rx) {
  625. memcpy(temp_rx, adapter->rx_ring, size);
  626. temp_rx->count = new_rx_count;
  627. err = e1000e_setup_rx_resources(temp_rx);
  628. if (err)
  629. goto err_setup_rx;
  630. }
  631. /* ...then free the old resources and copy back any new ring data */
  632. if (set_tx) {
  633. e1000e_free_tx_resources(adapter->tx_ring);
  634. memcpy(adapter->tx_ring, temp_tx, size);
  635. adapter->tx_ring_count = new_tx_count;
  636. }
  637. if (set_rx) {
  638. e1000e_free_rx_resources(adapter->rx_ring);
  639. memcpy(adapter->rx_ring, temp_rx, size);
  640. adapter->rx_ring_count = new_rx_count;
  641. }
  642. err_setup_rx:
  643. if (err && set_tx)
  644. e1000e_free_tx_resources(temp_tx);
  645. err_setup:
  646. e1000e_up(adapter);
  647. pm_runtime_put_sync(netdev->dev.parent);
  648. free_temp:
  649. vfree(temp_tx);
  650. vfree(temp_rx);
  651. clear_reset:
  652. clear_bit(__E1000_RESETTING, &adapter->state);
  653. return err;
  654. }
  655. static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data,
  656. int reg, int offset, u32 mask, u32 write)
  657. {
  658. u32 pat, val;
  659. static const u32 test[] = {
  660. 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF
  661. };
  662. for (pat = 0; pat < ARRAY_SIZE(test); pat++) {
  663. E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
  664. (test[pat] & write));
  665. val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
  666. if (val != (test[pat] & write & mask)) {
  667. e_err("pattern test failed (reg 0x%05X): got 0x%08X expected 0x%08X\n",
  668. reg + (offset << 2), val,
  669. (test[pat] & write & mask));
  670. *data = reg;
  671. return true;
  672. }
  673. }
  674. return false;
  675. }
  676. static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
  677. int reg, u32 mask, u32 write)
  678. {
  679. u32 val;
  680. __ew32(&adapter->hw, reg, write & mask);
  681. val = __er32(&adapter->hw, reg);
  682. if ((write & mask) != (val & mask)) {
  683. e_err("set/check test failed (reg 0x%05X): got 0x%08X expected 0x%08X\n",
  684. reg, (val & mask), (write & mask));
  685. *data = reg;
  686. return true;
  687. }
  688. return false;
  689. }
  690. #define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \
  691. do { \
  692. if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
  693. return 1; \
  694. } while (0)
  695. #define REG_PATTERN_TEST(reg, mask, write) \
  696. REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
  697. #define REG_SET_AND_CHECK(reg, mask, write) \
  698. do { \
  699. if (reg_set_and_check(adapter, data, reg, mask, write)) \
  700. return 1; \
  701. } while (0)
  702. static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
  703. {
  704. struct e1000_hw *hw = &adapter->hw;
  705. struct e1000_mac_info *mac = &adapter->hw.mac;
  706. u32 value;
  707. u32 before;
  708. u32 after;
  709. u32 i;
  710. u32 toggle;
  711. u32 mask;
  712. u32 wlock_mac = 0;
  713. /* The status register is Read Only, so a write should fail.
  714. * Some bits that get toggled are ignored. There are several bits
  715. * on newer hardware that are r/w.
  716. */
  717. switch (mac->type) {
  718. case e1000_82571:
  719. case e1000_82572:
  720. case e1000_80003es2lan:
  721. toggle = 0x7FFFF3FF;
  722. break;
  723. default:
  724. toggle = 0x7FFFF033;
  725. break;
  726. }
  727. before = er32(STATUS);
  728. value = (er32(STATUS) & toggle);
  729. ew32(STATUS, toggle);
  730. after = er32(STATUS) & toggle;
  731. if (value != after) {
  732. e_err("failed STATUS register test got: 0x%08X expected: 0x%08X\n",
  733. after, value);
  734. *data = 1;
  735. return 1;
  736. }
  737. /* restore previous status */
  738. ew32(STATUS, before);
  739. if (!(adapter->flags & FLAG_IS_ICH)) {
  740. REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
  741. REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF);
  742. REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF);
  743. REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF);
  744. }
  745. REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF);
  746. REG_PATTERN_TEST(E1000_RDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF);
  747. REG_PATTERN_TEST(E1000_RDLEN(0), 0x000FFF80, 0x000FFFFF);
  748. REG_PATTERN_TEST(E1000_RDH(0), 0x0000FFFF, 0x0000FFFF);
  749. REG_PATTERN_TEST(E1000_RDT(0), 0x0000FFFF, 0x0000FFFF);
  750. REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8);
  751. REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF);
  752. REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
  753. REG_PATTERN_TEST(E1000_TDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF);
  754. REG_PATTERN_TEST(E1000_TDLEN(0), 0x000FFF80, 0x000FFFFF);
  755. REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000);
  756. before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE);
  757. REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
  758. REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);
  759. REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
  760. REG_PATTERN_TEST(E1000_RDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF);
  761. if (!(adapter->flags & FLAG_IS_ICH))
  762. REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
  763. REG_PATTERN_TEST(E1000_TDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF);
  764. REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
  765. mask = 0x8003FFFF;
  766. switch (mac->type) {
  767. case e1000_ich10lan:
  768. case e1000_pchlan:
  769. case e1000_pch2lan:
  770. case e1000_pch_lpt:
  771. mask |= (1 << 18);
  772. break;
  773. default:
  774. break;
  775. }
  776. if (mac->type == e1000_pch_lpt)
  777. wlock_mac = (er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK) >>
  778. E1000_FWSM_WLOCK_MAC_SHIFT;
  779. for (i = 0; i < mac->rar_entry_count; i++) {
  780. if (mac->type == e1000_pch_lpt) {
  781. /* Cannot test write-protected SHRAL[n] registers */
  782. if ((wlock_mac == 1) || (wlock_mac && (i > wlock_mac)))
  783. continue;
  784. /* SHRAH[9] different than the others */
  785. if (i == 10)
  786. mask |= (1 << 30);
  787. else
  788. mask &= ~(1 << 30);
  789. }
  790. if (mac->type == e1000_pch2lan) {
  791. /* SHRAH[0,1,2] different than previous */
  792. if (i == 1)
  793. mask &= 0xFFF4FFFF;
  794. /* SHRAH[3] different than SHRAH[0,1,2] */
  795. if (i == 4)
  796. mask |= (1 << 30);
  797. /* RAR[1-6] owned by management engine - skipping */
  798. if (i > 0)
  799. i += 6;
  800. }
  801. REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1), mask,
  802. 0xFFFFFFFF);
  803. /* reset index to actual value */
  804. if ((mac->type == e1000_pch2lan) && (i > 6))
  805. i -= 6;
  806. }
  807. for (i = 0; i < mac->mta_reg_count; i++)
  808. REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF);
  809. *data = 0;
  810. return 0;
  811. }
  812. static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
  813. {
  814. u16 temp;
  815. u16 checksum = 0;
  816. u16 i;
  817. *data = 0;
  818. /* Read and add up the contents of the EEPROM */
  819. for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
  820. if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) {
  821. *data = 1;
  822. return *data;
  823. }
  824. checksum += temp;
  825. }
  826. /* If Checksum is not Correct return error else test passed */
  827. if ((checksum != (u16)NVM_SUM) && !(*data))
  828. *data = 2;
  829. return *data;
  830. }
  831. static irqreturn_t e1000_test_intr(int __always_unused irq, void *data)
  832. {
  833. struct net_device *netdev = (struct net_device *)data;
  834. struct e1000_adapter *adapter = netdev_priv(netdev);
  835. struct e1000_hw *hw = &adapter->hw;
  836. adapter->test_icr |= er32(ICR);
  837. return IRQ_HANDLED;
  838. }
  839. static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
  840. {
  841. struct net_device *netdev = adapter->netdev;
  842. struct e1000_hw *hw = &adapter->hw;
  843. u32 mask;
  844. u32 shared_int = 1;
  845. u32 irq = adapter->pdev->irq;
  846. int i;
  847. int ret_val = 0;
  848. int int_mode = E1000E_INT_MODE_LEGACY;
  849. *data = 0;
  850. /* NOTE: we don't test MSI/MSI-X interrupts here, yet */
  851. if (adapter->int_mode == E1000E_INT_MODE_MSIX) {
  852. int_mode = adapter->int_mode;
  853. e1000e_reset_interrupt_capability(adapter);
  854. adapter->int_mode = E1000E_INT_MODE_LEGACY;
  855. e1000e_set_interrupt_capability(adapter);
  856. }
  857. /* Hook up test interrupt handler just for this test */
  858. if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
  859. netdev)) {
  860. shared_int = 0;
  861. } else if (request_irq(irq, e1000_test_intr, IRQF_SHARED, netdev->name,
  862. netdev)) {
  863. *data = 1;
  864. ret_val = -1;
  865. goto out;
  866. }
  867. e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared"));
  868. /* Disable all the interrupts */
  869. ew32(IMC, 0xFFFFFFFF);
  870. e1e_flush();
  871. usleep_range(10000, 20000);
  872. /* Test each interrupt */
  873. for (i = 0; i < 10; i++) {
  874. /* Interrupt to test */
  875. mask = 1 << i;
  876. if (adapter->flags & FLAG_IS_ICH) {
  877. switch (mask) {
  878. case E1000_ICR_RXSEQ:
  879. continue;
  880. case 0x00000100:
  881. if (adapter->hw.mac.type == e1000_ich8lan ||
  882. adapter->hw.mac.type == e1000_ich9lan)
  883. continue;
  884. break;
  885. default:
  886. break;
  887. }
  888. }
  889. if (!shared_int) {
  890. /* Disable the interrupt to be reported in
  891. * the cause register and then force the same
  892. * interrupt and see if one gets posted. If
  893. * an interrupt was posted to the bus, the
  894. * test failed.
  895. */
  896. adapter->test_icr = 0;
  897. ew32(IMC, mask);
  898. ew32(ICS, mask);
  899. e1e_flush();
  900. usleep_range(10000, 20000);
  901. if (adapter->test_icr & mask) {
  902. *data = 3;
  903. break;
  904. }
  905. }
  906. /* Enable the interrupt to be reported in
  907. * the cause register and then force the same
  908. * interrupt and see if one gets posted. If
  909. * an interrupt was not posted to the bus, the
  910. * test failed.
  911. */
  912. adapter->test_icr = 0;
  913. ew32(IMS, mask);
  914. ew32(ICS, mask);
  915. e1e_flush();
  916. usleep_range(10000, 20000);
  917. if (!(adapter->test_icr & mask)) {
  918. *data = 4;
  919. break;
  920. }
  921. if (!shared_int) {
  922. /* Disable the other interrupts to be reported in
  923. * the cause register and then force the other
  924. * interrupts and see if any get posted. If
  925. * an interrupt was posted to the bus, the
  926. * test failed.
  927. */
  928. adapter->test_icr = 0;
  929. ew32(IMC, ~mask & 0x00007FFF);
  930. ew32(ICS, ~mask & 0x00007FFF);
  931. e1e_flush();
  932. usleep_range(10000, 20000);
  933. if (adapter->test_icr) {
  934. *data = 5;
  935. break;
  936. }
  937. }
  938. }
  939. /* Disable all the interrupts */
  940. ew32(IMC, 0xFFFFFFFF);
  941. e1e_flush();
  942. usleep_range(10000, 20000);
  943. /* Unhook test interrupt handler */
  944. free_irq(irq, netdev);
  945. out:
  946. if (int_mode == E1000E_INT_MODE_MSIX) {
  947. e1000e_reset_interrupt_capability(adapter);
  948. adapter->int_mode = int_mode;
  949. e1000e_set_interrupt_capability(adapter);
  950. }
  951. return ret_val;
  952. }
  953. static void e1000_free_desc_rings(struct e1000_adapter *adapter)
  954. {
  955. struct e1000_ring *tx_ring = &adapter->test_tx_ring;
  956. struct e1000_ring *rx_ring = &adapter->test_rx_ring;
  957. struct pci_dev *pdev = adapter->pdev;
  958. struct e1000_buffer *buffer_info;
  959. int i;
  960. if (tx_ring->desc && tx_ring->buffer_info) {
  961. for (i = 0; i < tx_ring->count; i++) {
  962. buffer_info = &tx_ring->buffer_info[i];
  963. if (buffer_info->dma)
  964. dma_unmap_single(&pdev->dev,
  965. buffer_info->dma,
  966. buffer_info->length,
  967. DMA_TO_DEVICE);
  968. if (buffer_info->skb)
  969. dev_kfree_skb(buffer_info->skb);
  970. }
  971. }
  972. if (rx_ring->desc && rx_ring->buffer_info) {
  973. for (i = 0; i < rx_ring->count; i++) {
  974. buffer_info = &rx_ring->buffer_info[i];
  975. if (buffer_info->dma)
  976. dma_unmap_single(&pdev->dev,
  977. buffer_info->dma,
  978. 2048, DMA_FROM_DEVICE);
  979. if (buffer_info->skb)
  980. dev_kfree_skb(buffer_info->skb);
  981. }
  982. }
  983. if (tx_ring->desc) {
  984. dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
  985. tx_ring->dma);
  986. tx_ring->desc = NULL;
  987. }
  988. if (rx_ring->desc) {
  989. dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
  990. rx_ring->dma);
  991. rx_ring->desc = NULL;
  992. }
  993. kfree(tx_ring->buffer_info);
  994. tx_ring->buffer_info = NULL;
  995. kfree(rx_ring->buffer_info);
  996. rx_ring->buffer_info = NULL;
  997. }
  998. static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
  999. {
  1000. struct e1000_ring *tx_ring = &adapter->test_tx_ring;
  1001. struct e1000_ring *rx_ring = &adapter->test_rx_ring;
  1002. struct pci_dev *pdev = adapter->pdev;
  1003. struct e1000_hw *hw = &adapter->hw;
  1004. u32 rctl;
  1005. int i;
  1006. int ret_val;
  1007. /* Setup Tx descriptor ring and Tx buffers */
  1008. if (!tx_ring->count)
  1009. tx_ring->count = E1000_DEFAULT_TXD;
  1010. tx_ring->buffer_info = kcalloc(tx_ring->count,
  1011. sizeof(struct e1000_buffer), GFP_KERNEL);
  1012. if (!tx_ring->buffer_info) {
  1013. ret_val = 1;
  1014. goto err_nomem;
  1015. }
  1016. tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
  1017. tx_ring->size = ALIGN(tx_ring->size, 4096);
  1018. tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
  1019. &tx_ring->dma, GFP_KERNEL);
  1020. if (!tx_ring->desc) {
  1021. ret_val = 2;
  1022. goto err_nomem;
  1023. }
  1024. tx_ring->next_to_use = 0;
  1025. tx_ring->next_to_clean = 0;
  1026. ew32(TDBAL(0), ((u64)tx_ring->dma & 0x00000000FFFFFFFF));
  1027. ew32(TDBAH(0), ((u64)tx_ring->dma >> 32));
  1028. ew32(TDLEN(0), tx_ring->count * sizeof(struct e1000_tx_desc));
  1029. ew32(TDH(0), 0);
  1030. ew32(TDT(0), 0);
  1031. ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR |
  1032. E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
  1033. E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
  1034. for (i = 0; i < tx_ring->count; i++) {
  1035. struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
  1036. struct sk_buff *skb;
  1037. unsigned int skb_size = 1024;
  1038. skb = alloc_skb(skb_size, GFP_KERNEL);
  1039. if (!skb) {
  1040. ret_val = 3;
  1041. goto err_nomem;
  1042. }
  1043. skb_put(skb, skb_size);
  1044. tx_ring->buffer_info[i].skb = skb;
  1045. tx_ring->buffer_info[i].length = skb->len;
  1046. tx_ring->buffer_info[i].dma =
  1047. dma_map_single(&pdev->dev, skb->data, skb->len,
  1048. DMA_TO_DEVICE);
  1049. if (dma_mapping_error(&pdev->dev,
  1050. tx_ring->buffer_info[i].dma)) {
  1051. ret_val = 4;
  1052. goto err_nomem;
  1053. }
  1054. tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
  1055. tx_desc->lower.data = cpu_to_le32(skb->len);
  1056. tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
  1057. E1000_TXD_CMD_IFCS |
  1058. E1000_TXD_CMD_RS);
  1059. tx_desc->upper.data = 0;
  1060. }
  1061. /* Setup Rx descriptor ring and Rx buffers */
  1062. if (!rx_ring->count)
  1063. rx_ring->count = E1000_DEFAULT_RXD;
  1064. rx_ring->buffer_info = kcalloc(rx_ring->count,
  1065. sizeof(struct e1000_buffer), GFP_KERNEL);
  1066. if (!rx_ring->buffer_info) {
  1067. ret_val = 5;
  1068. goto err_nomem;
  1069. }
  1070. rx_ring->size = rx_ring->count * sizeof(union e1000_rx_desc_extended);
  1071. rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
  1072. &rx_ring->dma, GFP_KERNEL);
  1073. if (!rx_ring->desc) {
  1074. ret_val = 6;
  1075. goto err_nomem;
  1076. }
  1077. rx_ring->next_to_use = 0;
  1078. rx_ring->next_to_clean = 0;
  1079. rctl = er32(RCTL);
  1080. if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
  1081. ew32(RCTL, rctl & ~E1000_RCTL_EN);
  1082. ew32(RDBAL(0), ((u64)rx_ring->dma & 0xFFFFFFFF));
  1083. ew32(RDBAH(0), ((u64)rx_ring->dma >> 32));
  1084. ew32(RDLEN(0), rx_ring->size);
  1085. ew32(RDH(0), 0);
  1086. ew32(RDT(0), 0);
  1087. rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
  1088. E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE |
  1089. E1000_RCTL_SBP | E1000_RCTL_SECRC |
  1090. E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
  1091. (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
  1092. ew32(RCTL, rctl);
  1093. for (i = 0; i < rx_ring->count; i++) {
  1094. union e1000_rx_desc_extended *rx_desc;
  1095. struct sk_buff *skb;
  1096. skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
  1097. if (!skb) {
  1098. ret_val = 7;
  1099. goto err_nomem;
  1100. }
  1101. skb_reserve(skb, NET_IP_ALIGN);
  1102. rx_ring->buffer_info[i].skb = skb;
  1103. rx_ring->buffer_info[i].dma =
  1104. dma_map_single(&pdev->dev, skb->data, 2048,
  1105. DMA_FROM_DEVICE);
  1106. if (dma_mapping_error(&pdev->dev,
  1107. rx_ring->buffer_info[i].dma)) {
  1108. ret_val = 8;
  1109. goto err_nomem;
  1110. }
  1111. rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
  1112. rx_desc->read.buffer_addr =
  1113. cpu_to_le64(rx_ring->buffer_info[i].dma);
  1114. memset(skb->data, 0x00, skb->len);
  1115. }
  1116. return 0;
  1117. err_nomem:
  1118. e1000_free_desc_rings(adapter);
  1119. return ret_val;
  1120. }
  1121. static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
  1122. {
  1123. /* Write out to PHY registers 29 and 30 to disable the Receiver. */
  1124. e1e_wphy(&adapter->hw, 29, 0x001F);
  1125. e1e_wphy(&adapter->hw, 30, 0x8FFC);
  1126. e1e_wphy(&adapter->hw, 29, 0x001A);
  1127. e1e_wphy(&adapter->hw, 30, 0x8FF0);
  1128. }
  1129. static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
  1130. {
  1131. struct e1000_hw *hw = &adapter->hw;
  1132. u32 ctrl_reg = 0;
  1133. u16 phy_reg = 0;
  1134. s32 ret_val = 0;
  1135. hw->mac.autoneg = 0;
  1136. if (hw->phy.type == e1000_phy_ife) {
  1137. /* force 100, set loopback */
  1138. e1e_wphy(hw, MII_BMCR, 0x6100);
  1139. /* Now set up the MAC to the same speed/duplex as the PHY. */
  1140. ctrl_reg = er32(CTRL);
  1141. ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
  1142. ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
  1143. E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
  1144. E1000_CTRL_SPD_100 |/* Force Speed to 100 */
  1145. E1000_CTRL_FD); /* Force Duplex to FULL */
  1146. ew32(CTRL, ctrl_reg);
  1147. e1e_flush();
  1148. usleep_range(500, 1000);
  1149. return 0;
  1150. }
  1151. /* Specific PHY configuration for loopback */
  1152. switch (hw->phy.type) {
  1153. case e1000_phy_m88:
  1154. /* Auto-MDI/MDIX Off */
  1155. e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
  1156. /* reset to update Auto-MDI/MDIX */
  1157. e1e_wphy(hw, MII_BMCR, 0x9140);
  1158. /* autoneg off */
  1159. e1e_wphy(hw, MII_BMCR, 0x8140);
  1160. break;
  1161. case e1000_phy_gg82563:
  1162. e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
  1163. break;
  1164. case e1000_phy_bm:
  1165. /* Set Default MAC Interface speed to 1GB */
  1166. e1e_rphy(hw, PHY_REG(2, 21), &phy_reg);
  1167. phy_reg &= ~0x0007;
  1168. phy_reg |= 0x006;
  1169. e1e_wphy(hw, PHY_REG(2, 21), phy_reg);
  1170. /* Assert SW reset for above settings to take effect */
  1171. hw->phy.ops.commit(hw);
  1172. usleep_range(1000, 2000);
  1173. /* Force Full Duplex */
  1174. e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
  1175. e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C);
  1176. /* Set Link Up (in force link) */
  1177. e1e_rphy(hw, PHY_REG(776, 16), &phy_reg);
  1178. e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040);
  1179. /* Force Link */
  1180. e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
  1181. e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040);
  1182. /* Set Early Link Enable */
  1183. e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
  1184. e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400);
  1185. break;
  1186. case e1000_phy_82577:
  1187. case e1000_phy_82578:
  1188. /* Workaround: K1 must be disabled for stable 1Gbps operation */
  1189. ret_val = hw->phy.ops.acquire(hw);
  1190. if (ret_val) {
  1191. e_err("Cannot setup 1Gbps loopback.\n");
  1192. return ret_val;
  1193. }
  1194. e1000_configure_k1_ich8lan(hw, false);
  1195. hw->phy.ops.release(hw);
  1196. break;
  1197. case e1000_phy_82579:
  1198. /* Disable PHY energy detect power down */
  1199. e1e_rphy(hw, PHY_REG(0, 21), &phy_reg);
  1200. e1e_wphy(hw, PHY_REG(0, 21), phy_reg & ~(1 << 3));
  1201. /* Disable full chip energy detect */
  1202. e1e_rphy(hw, PHY_REG(776, 18), &phy_reg);
  1203. e1e_wphy(hw, PHY_REG(776, 18), phy_reg | 1);
  1204. /* Enable loopback on the PHY */
  1205. e1e_wphy(hw, I82577_PHY_LBK_CTRL, 0x8001);
  1206. break;
  1207. default:
  1208. break;
  1209. }
  1210. /* force 1000, set loopback */
  1211. e1e_wphy(hw, MII_BMCR, 0x4140);
  1212. msleep(250);
  1213. /* Now set up the MAC to the same speed/duplex as the PHY. */
  1214. ctrl_reg = er32(CTRL);
  1215. ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
  1216. ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
  1217. E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
  1218. E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
  1219. E1000_CTRL_FD); /* Force Duplex to FULL */
  1220. if (adapter->flags & FLAG_IS_ICH)
  1221. ctrl_reg |= E1000_CTRL_SLU; /* Set Link Up */
  1222. if (hw->phy.media_type == e1000_media_type_copper &&
  1223. hw->phy.type == e1000_phy_m88) {
  1224. ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
  1225. } else {
  1226. /* Set the ILOS bit on the fiber Nic if half duplex link is
  1227. * detected.
  1228. */
  1229. if ((er32(STATUS) & E1000_STATUS_FD) == 0)
  1230. ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
  1231. }
  1232. ew32(CTRL, ctrl_reg);
  1233. /* Disable the receiver on the PHY so when a cable is plugged in, the
  1234. * PHY does not begin to autoneg when a cable is reconnected to the NIC.
  1235. */
  1236. if (hw->phy.type == e1000_phy_m88)
  1237. e1000_phy_disable_receiver(adapter);
  1238. usleep_range(500, 1000);
  1239. return 0;
  1240. }
  1241. static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
  1242. {
  1243. struct e1000_hw *hw = &adapter->hw;
  1244. u32 ctrl = er32(CTRL);
  1245. int link;
  1246. /* special requirements for 82571/82572 fiber adapters */
  1247. /* jump through hoops to make sure link is up because serdes
  1248. * link is hardwired up
  1249. */
  1250. ctrl |= E1000_CTRL_SLU;
  1251. ew32(CTRL, ctrl);
  1252. /* disable autoneg */
  1253. ctrl = er32(TXCW);
  1254. ctrl &= ~(1 << 31);
  1255. ew32(TXCW, ctrl);
  1256. link = (er32(STATUS) & E1000_STATUS_LU);
  1257. if (!link) {
  1258. /* set invert loss of signal */
  1259. ctrl = er32(CTRL);
  1260. ctrl |= E1000_CTRL_ILOS;
  1261. ew32(CTRL, ctrl);
  1262. }
  1263. /* special write to serdes control register to enable SerDes analog
  1264. * loopback
  1265. */
  1266. ew32(SCTL, E1000_SCTL_ENABLE_SERDES_LOOPBACK);
  1267. e1e_flush();
  1268. usleep_range(10000, 20000);
  1269. return 0;
  1270. }
  1271. /* only call this for fiber/serdes connections to es2lan */
  1272. static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
  1273. {
  1274. struct e1000_hw *hw = &adapter->hw;
  1275. u32 ctrlext = er32(CTRL_EXT);
  1276. u32 ctrl = er32(CTRL);
  1277. /* save CTRL_EXT to restore later, reuse an empty variable (unused
  1278. * on mac_type 80003es2lan)
  1279. */
  1280. adapter->tx_fifo_head = ctrlext;
  1281. /* clear the serdes mode bits, putting the device into mac loopback */
  1282. ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
  1283. ew32(CTRL_EXT, ctrlext);
  1284. /* force speed to 1000/FD, link up */
  1285. ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
  1286. ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
  1287. E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
  1288. ew32(CTRL, ctrl);
  1289. /* set mac loopback */
  1290. ctrl = er32(RCTL);
  1291. ctrl |= E1000_RCTL_LBM_MAC;
  1292. ew32(RCTL, ctrl);
  1293. /* set testing mode parameters (no need to reset later) */
  1294. #define KMRNCTRLSTA_OPMODE (0x1F << 16)
  1295. #define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
  1296. ew32(KMRNCTRLSTA,
  1297. (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
  1298. return 0;
  1299. }
  1300. static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
  1301. {
  1302. struct e1000_hw *hw = &adapter->hw;
  1303. u32 rctl;
  1304. if (hw->phy.media_type == e1000_media_type_fiber ||
  1305. hw->phy.media_type == e1000_media_type_internal_serdes) {
  1306. switch (hw->mac.type) {
  1307. case e1000_80003es2lan:
  1308. return e1000_set_es2lan_mac_loopback(adapter);
  1309. break;
  1310. case e1000_82571:
  1311. case e1000_82572:
  1312. return e1000_set_82571_fiber_loopback(adapter);
  1313. break;
  1314. default:
  1315. rctl = er32(RCTL);
  1316. rctl |= E1000_RCTL_LBM_TCVR;
  1317. ew32(RCTL, rctl);
  1318. return 0;
  1319. }
  1320. } else if (hw->phy.media_type == e1000_media_type_copper) {
  1321. return e1000_integrated_phy_loopback(adapter);
  1322. }
  1323. return 7;
  1324. }
  1325. static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
  1326. {
  1327. struct e1000_hw *hw = &adapter->hw;
  1328. u32 rctl;
  1329. u16 phy_reg;
  1330. rctl = er32(RCTL);
  1331. rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
  1332. ew32(RCTL, rctl);
  1333. switch (hw->mac.type) {
  1334. case e1000_80003es2lan:
  1335. if (hw->phy.media_type == e1000_media_type_fiber ||
  1336. hw->phy.media_type == e1000_media_type_internal_serdes) {
  1337. /* restore CTRL_EXT, stealing space from tx_fifo_head */
  1338. ew32(CTRL_EXT, adapter->tx_fifo_head);
  1339. adapter->tx_fifo_head = 0;
  1340. }
  1341. /* fall through */
  1342. case e1000_82571:
  1343. case e1000_82572:
  1344. if (hw->phy.media_type == e1000_media_type_fiber ||
  1345. hw->phy.media_type == e1000_media_type_internal_serdes) {
  1346. ew32(SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
  1347. e1e_flush();
  1348. usleep_range(10000, 20000);
  1349. break;
  1350. }
  1351. /* Fall Through */
  1352. default:
  1353. hw->mac.autoneg = 1;
  1354. if (hw->phy.type == e1000_phy_gg82563)
  1355. e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
  1356. e1e_rphy(hw, MII_BMCR, &phy_reg);
  1357. if (phy_reg & BMCR_LOOPBACK) {
  1358. phy_reg &= ~BMCR_LOOPBACK;
  1359. e1e_wphy(hw, MII_BMCR, phy_reg);
  1360. if (hw->phy.ops.commit)
  1361. hw->phy.ops.commit(hw);
  1362. }
  1363. break;
  1364. }
  1365. }
  1366. static void e1000_create_lbtest_frame(struct sk_buff *skb,
  1367. unsigned int frame_size)
  1368. {
  1369. memset(skb->data, 0xFF, frame_size);
  1370. frame_size &= ~1;
  1371. memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
  1372. memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
  1373. memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
  1374. }
  1375. static int e1000_check_lbtest_frame(struct sk_buff *skb,
  1376. unsigned int frame_size)
  1377. {
  1378. frame_size &= ~1;
  1379. if (*(skb->data + 3) == 0xFF)
  1380. if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
  1381. (*(skb->data + frame_size / 2 + 12) == 0xAF))
  1382. return 0;
  1383. return 13;
  1384. }
  1385. static int e1000_run_loopback_test(struct e1000_adapter *adapter)
  1386. {
  1387. struct e1000_ring *tx_ring = &adapter->test_tx_ring;
  1388. struct e1000_ring *rx_ring = &adapter->test_rx_ring;
  1389. struct pci_dev *pdev = adapter->pdev;
  1390. struct e1000_hw *hw = &adapter->hw;
  1391. struct e1000_buffer *buffer_info;
  1392. int i, j, k, l;
  1393. int lc;
  1394. int good_cnt;
  1395. int ret_val = 0;
  1396. unsigned long time;
  1397. ew32(RDT(0), rx_ring->count - 1);
  1398. /* Calculate the loop count based on the largest descriptor ring
  1399. * The idea is to wrap the largest ring a number of times using 64
  1400. * send/receive pairs during each loop
  1401. */
  1402. if (rx_ring->count <= tx_ring->count)
  1403. lc = ((tx_ring->count / 64) * 2) + 1;
  1404. else
  1405. lc = ((rx_ring->count / 64) * 2) + 1;
  1406. k = 0;
  1407. l = 0;
  1408. /* loop count loop */
  1409. for (j = 0; j <= lc; j++) {
  1410. /* send the packets */
  1411. for (i = 0; i < 64; i++) {
  1412. buffer_info = &tx_ring->buffer_info[k];
  1413. e1000_create_lbtest_frame(buffer_info->skb, 1024);
  1414. dma_sync_single_for_device(&pdev->dev,
  1415. buffer_info->dma,
  1416. buffer_info->length,
  1417. DMA_TO_DEVICE);
  1418. k++;
  1419. if (k == tx_ring->count)
  1420. k = 0;
  1421. }
  1422. ew32(TDT(0), k);
  1423. e1e_flush();
  1424. msleep(200);
  1425. time = jiffies; /* set the start time for the receive */
  1426. good_cnt = 0;
  1427. /* receive the sent packets */
  1428. do {
  1429. buffer_info = &rx_ring->buffer_info[l];
  1430. dma_sync_single_for_cpu(&pdev->dev,
  1431. buffer_info->dma, 2048,
  1432. DMA_FROM_DEVICE);
  1433. ret_val = e1000_check_lbtest_frame(buffer_info->skb,
  1434. 1024);
  1435. if (!ret_val)
  1436. good_cnt++;
  1437. l++;
  1438. if (l == rx_ring->count)
  1439. l = 0;
  1440. /* time + 20 msecs (200 msecs on 2.4) is more than
  1441. * enough time to complete the receives, if it's
  1442. * exceeded, break and error off
  1443. */
  1444. } while ((good_cnt < 64) && !time_after(jiffies, time + 20));
  1445. if (good_cnt != 64) {
  1446. ret_val = 13; /* ret_val is the same as mis-compare */
  1447. break;
  1448. }
  1449. if (time_after(jiffies, time + 20)) {
  1450. ret_val = 14; /* error code for time out error */
  1451. break;
  1452. }
  1453. }
  1454. return ret_val;
  1455. }
  1456. static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
  1457. {
  1458. struct e1000_hw *hw = &adapter->hw;
  1459. /* PHY loopback cannot be performed if SoL/IDER sessions are active */
  1460. if (hw->phy.ops.check_reset_block &&
  1461. hw->phy.ops.check_reset_block(hw)) {
  1462. e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
  1463. *data = 0;
  1464. goto out;
  1465. }
  1466. *data = e1000_setup_desc_rings(adapter);
  1467. if (*data)
  1468. goto out;
  1469. *data = e1000_setup_loopback_test(adapter);
  1470. if (*data)
  1471. goto err_loopback;
  1472. *data = e1000_run_loopback_test(adapter);
  1473. e1000_loopback_cleanup(adapter);
  1474. err_loopback:
  1475. e1000_free_desc_rings(adapter);
  1476. out:
  1477. return *data;
  1478. }
  1479. static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
  1480. {
  1481. struct e1000_hw *hw = &adapter->hw;
  1482. *data = 0;
  1483. if (hw->phy.media_type == e1000_media_type_internal_serdes) {
  1484. int i = 0;
  1485. hw->mac.serdes_has_link = false;
  1486. /* On some blade server designs, link establishment
  1487. * could take as long as 2-3 minutes
  1488. */
  1489. do {
  1490. hw->mac.ops.check_for_link(hw);
  1491. if (hw->mac.serdes_has_link)
  1492. return *data;
  1493. msleep(20);
  1494. } while (i++ < 3750);
  1495. *data = 1;
  1496. } else {
  1497. hw->mac.ops.check_for_link(hw);
  1498. if (hw->mac.autoneg)
  1499. /* On some Phy/switch combinations, link establishment
  1500. * can take a few seconds more than expected.
  1501. */
  1502. msleep_interruptible(5000);
  1503. if (!(er32(STATUS) & E1000_STATUS_LU))
  1504. *data = 1;
  1505. }
  1506. return *data;
  1507. }
  1508. static int e1000e_get_sset_count(struct net_device __always_unused *netdev,
  1509. int sset)
  1510. {
  1511. switch (sset) {
  1512. case ETH_SS_TEST:
  1513. return E1000_TEST_LEN;
  1514. case ETH_SS_STATS:
  1515. return E1000_STATS_LEN;
  1516. default:
  1517. return -EOPNOTSUPP;
  1518. }
  1519. }
  1520. static void e1000_diag_test(struct net_device *netdev,
  1521. struct ethtool_test *eth_test, u64 *data)
  1522. {
  1523. struct e1000_adapter *adapter = netdev_priv(netdev);
  1524. u16 autoneg_advertised;
  1525. u8 forced_speed_duplex;
  1526. u8 autoneg;
  1527. bool if_running = netif_running(netdev);
  1528. pm_runtime_get_sync(netdev->dev.parent);
  1529. set_bit(__E1000_TESTING, &adapter->state);
  1530. if (!if_running) {
  1531. /* Get control of and reset hardware */
  1532. if (adapter->flags & FLAG_HAS_AMT)
  1533. e1000e_get_hw_control(adapter);
  1534. e1000e_power_up_phy(adapter);
  1535. adapter->hw.phy.autoneg_wait_to_complete = 1;
  1536. e1000e_reset(adapter);
  1537. adapter->hw.phy.autoneg_wait_to_complete = 0;
  1538. }
  1539. if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
  1540. /* Offline tests */
  1541. /* save speed, duplex, autoneg settings */
  1542. autoneg_advertised = adapter->hw.phy.autoneg_advertised;
  1543. forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
  1544. autoneg = adapter->hw.mac.autoneg;
  1545. e_info("offline testing starting\n");
  1546. if (if_running)
  1547. /* indicate we're in test mode */
  1548. dev_close(netdev);
  1549. if (e1000_reg_test(adapter, &data[0]))
  1550. eth_test->flags |= ETH_TEST_FL_FAILED;
  1551. e1000e_reset(adapter);
  1552. if (e1000_eeprom_test(adapter, &data[1]))
  1553. eth_test->flags |= ETH_TEST_FL_FAILED;
  1554. e1000e_reset(adapter);
  1555. if (e1000_intr_test(adapter, &data[2]))
  1556. eth_test->flags |= ETH_TEST_FL_FAILED;
  1557. e1000e_reset(adapter);
  1558. if (e1000_loopback_test(adapter, &data[3]))
  1559. eth_test->flags |= ETH_TEST_FL_FAILED;
  1560. /* force this routine to wait until autoneg complete/timeout */
  1561. adapter->hw.phy.autoneg_wait_to_complete = 1;
  1562. e1000e_reset(adapter);
  1563. adapter->hw.phy.autoneg_wait_to_complete = 0;
  1564. if (e1000_link_test(adapter, &data[4]))
  1565. eth_test->flags |= ETH_TEST_FL_FAILED;
  1566. /* restore speed, duplex, autoneg settings */
  1567. adapter->hw.phy.autoneg_advertised = autoneg_advertised;
  1568. adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
  1569. adapter->hw.mac.autoneg = autoneg;
  1570. e1000e_reset(adapter);
  1571. clear_bit(__E1000_TESTING, &adapter->state);
  1572. if (if_running)
  1573. dev_open(netdev);
  1574. } else {
  1575. /* Online tests */
  1576. e_info("online testing starting\n");
  1577. /* register, eeprom, intr and loopback tests not run online */
  1578. data[0] = 0;
  1579. data[1] = 0;
  1580. data[2] = 0;
  1581. data[3] = 0;
  1582. if (e1000_link_test(adapter, &data[4]))
  1583. eth_test->flags |= ETH_TEST_FL_FAILED;
  1584. clear_bit(__E1000_TESTING, &adapter->state);
  1585. }
  1586. if (!if_running) {
  1587. e1000e_reset(adapter);
  1588. if (adapter->flags & FLAG_HAS_AMT)
  1589. e1000e_release_hw_control(adapter);
  1590. }
  1591. msleep_interruptible(4 * 1000);
  1592. pm_runtime_put_sync(netdev->dev.parent);
  1593. }
  1594. static void e1000_get_wol(struct net_device *netdev,
  1595. struct ethtool_wolinfo *wol)
  1596. {
  1597. struct e1000_adapter *adapter = netdev_priv(netdev);
  1598. wol->supported = 0;
  1599. wol->wolopts = 0;
  1600. if (!(adapter->flags & FLAG_HAS_WOL) ||
  1601. !device_can_wakeup(&adapter->pdev->dev))
  1602. return;
  1603. wol->supported = WAKE_UCAST | WAKE_MCAST |
  1604. WAKE_BCAST | WAKE_MAGIC | WAKE_PHY;
  1605. /* apply any specific unsupported masks here */
  1606. if (adapter->flags & FLAG_NO_WAKE_UCAST) {
  1607. wol->supported &= ~WAKE_UCAST;
  1608. if (adapter->wol & E1000_WUFC_EX)
  1609. e_err("Interface does not support directed (unicast) frame wake-up packets\n");
  1610. }
  1611. if (adapter->wol & E1000_WUFC_EX)
  1612. wol->wolopts |= WAKE_UCAST;
  1613. if (adapter->wol & E1000_WUFC_MC)
  1614. wol->wolopts |= WAKE_MCAST;
  1615. if (adapter->wol & E1000_WUFC_BC)
  1616. wol->wolopts |= WAKE_BCAST;
  1617. if (adapter->wol & E1000_WUFC_MAG)
  1618. wol->wolopts |= WAKE_MAGIC;
  1619. if (adapter->wol & E1000_WUFC_LNKC)
  1620. wol->wolopts |= WAKE_PHY;
  1621. }
  1622. static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  1623. {
  1624. struct e1000_adapter *adapter = netdev_priv(netdev);
  1625. if (!(adapter->flags & FLAG_HAS_WOL) ||
  1626. !device_can_wakeup(&adapter->pdev->dev) ||
  1627. (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
  1628. WAKE_MAGIC | WAKE_PHY)))
  1629. return -EOPNOTSUPP;
  1630. /* these settings will always override what we currently have */
  1631. adapter->wol = 0;
  1632. if (wol->wolopts & WAKE_UCAST)
  1633. adapter->wol |= E1000_WUFC_EX;
  1634. if (wol->wolopts & WAKE_MCAST)
  1635. adapter->wol |= E1000_WUFC_MC;
  1636. if (wol->wolopts & WAKE_BCAST)
  1637. adapter->wol |= E1000_WUFC_BC;
  1638. if (wol->wolopts & WAKE_MAGIC)
  1639. adapter->wol |= E1000_WUFC_MAG;
  1640. if (wol->wolopts & WAKE_PHY)
  1641. adapter->wol |= E1000_WUFC_LNKC;
  1642. device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
  1643. return 0;
  1644. }
  1645. static int e1000_set_phys_id(struct net_device *netdev,
  1646. enum ethtool_phys_id_state state)
  1647. {
  1648. struct e1000_adapter *adapter = netdev_priv(netdev);
  1649. struct e1000_hw *hw = &adapter->hw;
  1650. switch (state) {
  1651. case ETHTOOL_ID_ACTIVE:
  1652. pm_runtime_get_sync(netdev->dev.parent);
  1653. if (!hw->mac.ops.blink_led)
  1654. return 2; /* cycle on/off twice per second */
  1655. hw->mac.ops.blink_led(hw);
  1656. break;
  1657. case ETHTOOL_ID_INACTIVE:
  1658. if (hw->phy.type == e1000_phy_ife)
  1659. e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
  1660. hw->mac.ops.led_off(hw);
  1661. hw->mac.ops.cleanup_led(hw);
  1662. pm_runtime_put_sync(netdev->dev.parent);
  1663. break;
  1664. case ETHTOOL_ID_ON:
  1665. hw->mac.ops.led_on(hw);
  1666. break;
  1667. case ETHTOOL_ID_OFF:
  1668. hw->mac.ops.led_off(hw);
  1669. break;
  1670. }
  1671. return 0;
  1672. }
  1673. static int e1000_get_coalesce(struct net_device *netdev,
  1674. struct ethtool_coalesce *ec)
  1675. {
  1676. struct e1000_adapter *adapter = netdev_priv(netdev);
  1677. if (adapter->itr_setting <= 4)
  1678. ec->rx_coalesce_usecs = adapter->itr_setting;
  1679. else
  1680. ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
  1681. return 0;
  1682. }
  1683. static int e1000_set_coalesce(struct net_device *netdev,
  1684. struct ethtool_coalesce *ec)
  1685. {
  1686. struct e1000_adapter *adapter = netdev_priv(netdev);
  1687. if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
  1688. ((ec->rx_coalesce_usecs > 4) &&
  1689. (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
  1690. (ec->rx_coalesce_usecs == 2))
  1691. return -EINVAL;
  1692. if (ec->rx_coalesce_usecs == 4) {
  1693. adapter->itr_setting = 4;
  1694. adapter->itr = adapter->itr_setting;
  1695. } else if (ec->rx_coalesce_usecs <= 3) {
  1696. adapter->itr = 20000;
  1697. adapter->itr_setting = ec->rx_coalesce_usecs;
  1698. } else {
  1699. adapter->itr = (1000000 / ec->rx_coalesce_usecs);
  1700. adapter->itr_setting = adapter->itr & ~3;
  1701. }
  1702. pm_runtime_get_sync(netdev->dev.parent);
  1703. if (adapter->itr_setting != 0)
  1704. e1000e_write_itr(adapter, adapter->itr);
  1705. else
  1706. e1000e_write_itr(adapter, 0);
  1707. pm_runtime_put_sync(netdev->dev.parent);
  1708. return 0;
  1709. }
  1710. static int e1000_nway_reset(struct net_device *netdev)
  1711. {
  1712. struct e1000_adapter *adapter = netdev_priv(netdev);
  1713. if (!netif_running(netdev))
  1714. return -EAGAIN;
  1715. if (!adapter->hw.mac.autoneg)
  1716. return -EINVAL;
  1717. pm_runtime_get_sync(netdev->dev.parent);
  1718. e1000e_reinit_locked(adapter);
  1719. pm_runtime_put_sync(netdev->dev.parent);
  1720. return 0;
  1721. }
  1722. static void e1000_get_ethtool_stats(struct net_device *netdev,
  1723. struct ethtool_stats __always_unused *stats,
  1724. u64 *data)
  1725. {
  1726. struct e1000_adapter *adapter = netdev_priv(netdev);
  1727. struct rtnl_link_stats64 net_stats;
  1728. int i;
  1729. char *p = NULL;
  1730. pm_runtime_get_sync(netdev->dev.parent);
  1731. e1000e_get_stats64(netdev, &net_stats);
  1732. pm_runtime_put_sync(netdev->dev.parent);
  1733. for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
  1734. switch (e1000_gstrings_stats[i].type) {
  1735. case NETDEV_STATS:
  1736. p = (char *)&net_stats +
  1737. e1000_gstrings_stats[i].stat_offset;
  1738. break;
  1739. case E1000_STATS:
  1740. p = (char *)adapter +
  1741. e1000_gstrings_stats[i].stat_offset;
  1742. break;
  1743. default:
  1744. data[i] = 0;
  1745. continue;
  1746. }
  1747. data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
  1748. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1749. }
  1750. }
  1751. static void e1000_get_strings(struct net_device __always_unused *netdev,
  1752. u32 stringset, u8 *data)
  1753. {
  1754. u8 *p = data;
  1755. int i;
  1756. switch (stringset) {
  1757. case ETH_SS_TEST:
  1758. memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test));
  1759. break;
  1760. case ETH_SS_STATS:
  1761. for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
  1762. memcpy(p, e1000_gstrings_stats[i].stat_string,
  1763. ETH_GSTRING_LEN);
  1764. p += ETH_GSTRING_LEN;
  1765. }
  1766. break;
  1767. }
  1768. }
  1769. static int e1000_get_rxnfc(struct net_device *netdev,
  1770. struct ethtool_rxnfc *info,
  1771. u32 __always_unused *rule_locs)
  1772. {
  1773. info->data = 0;
  1774. switch (info->cmd) {
  1775. case ETHTOOL_GRXFH: {
  1776. struct e1000_adapter *adapter = netdev_priv(netdev);
  1777. struct e1000_hw *hw = &adapter->hw;
  1778. u32 mrqc;
  1779. pm_runtime_get_sync(netdev->dev.parent);
  1780. mrqc = er32(MRQC);
  1781. pm_runtime_put_sync(netdev->dev.parent);
  1782. if (!(mrqc & E1000_MRQC_RSS_FIELD_MASK))
  1783. return 0;
  1784. switch (info->flow_type) {
  1785. case TCP_V4_FLOW:
  1786. if (mrqc & E1000_MRQC_RSS_FIELD_IPV4_TCP)
  1787. info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  1788. /* fall through */
  1789. case UDP_V4_FLOW:
  1790. case SCTP_V4_FLOW:
  1791. case AH_ESP_V4_FLOW:
  1792. case IPV4_FLOW:
  1793. if (mrqc & E1000_MRQC_RSS_FIELD_IPV4)
  1794. info->data |= RXH_IP_SRC | RXH_IP_DST;
  1795. break;
  1796. case TCP_V6_FLOW:
  1797. if (mrqc & E1000_MRQC_RSS_FIELD_IPV6_TCP)
  1798. info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  1799. /* fall through */
  1800. case UDP_V6_FLOW:
  1801. case SCTP_V6_FLOW:
  1802. case AH_ESP_V6_FLOW:
  1803. case IPV6_FLOW:
  1804. if (mrqc & E1000_MRQC_RSS_FIELD_IPV6)
  1805. info->data |= RXH_IP_SRC | RXH_IP_DST;
  1806. break;
  1807. default:
  1808. break;
  1809. }
  1810. return 0;
  1811. }
  1812. default:
  1813. return -EOPNOTSUPP;
  1814. }
  1815. }
  1816. static int e1000e_get_eee(struct net_device *netdev, struct ethtool_eee *edata)
  1817. {
  1818. struct e1000_adapter *adapter = netdev_priv(netdev);
  1819. struct e1000_hw *hw = &adapter->hw;
  1820. u16 cap_addr, lpa_addr, pcs_stat_addr, phy_data;
  1821. u32 ret_val;
  1822. if (!(adapter->flags2 & FLAG2_HAS_EEE))
  1823. return -EOPNOTSUPP;
  1824. switch (hw->phy.type) {
  1825. case e1000_phy_82579:
  1826. cap_addr = I82579_EEE_CAPABILITY;
  1827. lpa_addr = I82579_EEE_LP_ABILITY;
  1828. pcs_stat_addr = I82579_EEE_PCS_STATUS;
  1829. break;
  1830. case e1000_phy_i217:
  1831. cap_addr = I217_EEE_CAPABILITY;
  1832. lpa_addr = I217_EEE_LP_ABILITY;
  1833. pcs_stat_addr = I217_EEE_PCS_STATUS;
  1834. break;
  1835. default:
  1836. return -EOPNOTSUPP;
  1837. }
  1838. pm_runtime_get_sync(netdev->dev.parent);
  1839. ret_val = hw->phy.ops.acquire(hw);
  1840. if (ret_val) {
  1841. pm_runtime_put_sync(netdev->dev.parent);
  1842. return -EBUSY;
  1843. }
  1844. /* EEE Capability */
  1845. ret_val = e1000_read_emi_reg_locked(hw, cap_addr, &phy_data);
  1846. if (ret_val)
  1847. goto release;
  1848. edata->supported = mmd_eee_cap_to_ethtool_sup_t(phy_data);
  1849. /* EEE Advertised */
  1850. edata->advertised = mmd_eee_adv_to_ethtool_adv_t(adapter->eee_advert);
  1851. /* EEE Link Partner Advertised */
  1852. ret_val = e1000_read_emi_reg_locked(hw, lpa_addr, &phy_data);
  1853. if (ret_val)
  1854. goto release;
  1855. edata->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(phy_data);
  1856. /* EEE PCS Status */
  1857. ret_val = e1000_read_emi_reg_locked(hw, pcs_stat_addr, &phy_data);
  1858. if (ret_val)
  1859. goto release;
  1860. if (hw->phy.type == e1000_phy_82579)
  1861. phy_data <<= 8;
  1862. /* Result of the EEE auto negotiation - there is no register that
  1863. * has the status of the EEE negotiation so do a best-guess based
  1864. * on whether Tx or Rx LPI indications have been received.
  1865. */
  1866. if (phy_data & (E1000_EEE_TX_LPI_RCVD | E1000_EEE_RX_LPI_RCVD))
  1867. edata->eee_active = true;
  1868. edata->eee_enabled = !hw->dev_spec.ich8lan.eee_disable;
  1869. edata->tx_lpi_enabled = true;
  1870. edata->tx_lpi_timer = er32(LPIC) >> E1000_LPIC_LPIET_SHIFT;
  1871. release:
  1872. hw->phy.ops.release(hw);
  1873. if (ret_val)
  1874. ret_val = -ENODATA;
  1875. pm_runtime_put_sync(netdev->dev.parent);
  1876. return ret_val;
  1877. }
  1878. static int e1000e_set_eee(struct net_device *netdev, struct ethtool_eee *edata)
  1879. {
  1880. struct e1000_adapter *adapter = netdev_priv(netdev);
  1881. struct e1000_hw *hw = &adapter->hw;
  1882. struct ethtool_eee eee_curr;
  1883. s32 ret_val;
  1884. ret_val = e1000e_get_eee(netdev, &eee_curr);
  1885. if (ret_val)
  1886. return ret_val;
  1887. if (eee_curr.tx_lpi_enabled != edata->tx_lpi_enabled) {
  1888. e_err("Setting EEE tx-lpi is not supported\n");
  1889. return -EINVAL;
  1890. }
  1891. if (eee_curr.tx_lpi_timer != edata->tx_lpi_timer) {
  1892. e_err("Setting EEE Tx LPI timer is not supported\n");
  1893. return -EINVAL;
  1894. }
  1895. if (edata->advertised & ~(ADVERTISE_100_FULL | ADVERTISE_1000_FULL)) {
  1896. e_err("EEE advertisement supports only 100TX and/or 1000T full-duplex\n");
  1897. return -EINVAL;
  1898. }
  1899. adapter->eee_advert = ethtool_adv_to_mmd_eee_adv_t(edata->advertised);
  1900. hw->dev_spec.ich8lan.eee_disable = !edata->eee_enabled;
  1901. pm_runtime_get_sync(netdev->dev.parent);
  1902. /* reset the link */
  1903. if (netif_running(netdev))
  1904. e1000e_reinit_locked(adapter);
  1905. else
  1906. e1000e_reset(adapter);
  1907. pm_runtime_put_sync(netdev->dev.parent);
  1908. return 0;
  1909. }
  1910. static int e1000e_get_ts_info(struct net_device *netdev,
  1911. struct ethtool_ts_info *info)
  1912. {
  1913. struct e1000_adapter *adapter = netdev_priv(netdev);
  1914. ethtool_op_get_ts_info(netdev, info);
  1915. if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
  1916. return 0;
  1917. info->so_timestamping |= (SOF_TIMESTAMPING_TX_HARDWARE |
  1918. SOF_TIMESTAMPING_RX_HARDWARE |
  1919. SOF_TIMESTAMPING_RAW_HARDWARE);
  1920. info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
  1921. info->rx_filters = ((1 << HWTSTAMP_FILTER_NONE) |
  1922. (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
  1923. (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
  1924. (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
  1925. (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |
  1926. (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
  1927. (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
  1928. (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
  1929. (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
  1930. (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
  1931. (1 << HWTSTAMP_FILTER_ALL));
  1932. if (adapter->ptp_clock)
  1933. info->phc_index = ptp_clock_index(adapter->ptp_clock);
  1934. return 0;
  1935. }
  1936. static const struct ethtool_ops e1000_ethtool_ops = {
  1937. .get_settings = e1000_get_settings,
  1938. .set_settings = e1000_set_settings,
  1939. .get_drvinfo = e1000_get_drvinfo,
  1940. .get_regs_len = e1000_get_regs_len,
  1941. .get_regs = e1000_get_regs,
  1942. .get_wol = e1000_get_wol,
  1943. .set_wol = e1000_set_wol,
  1944. .get_msglevel = e1000_get_msglevel,
  1945. .set_msglevel = e1000_set_msglevel,
  1946. .nway_reset = e1000_nway_reset,
  1947. .get_link = ethtool_op_get_link,
  1948. .get_eeprom_len = e1000_get_eeprom_len,
  1949. .get_eeprom = e1000_get_eeprom,
  1950. .set_eeprom = e1000_set_eeprom,
  1951. .get_ringparam = e1000_get_ringparam,
  1952. .set_ringparam = e1000_set_ringparam,
  1953. .get_pauseparam = e1000_get_pauseparam,
  1954. .set_pauseparam = e1000_set_pauseparam,
  1955. .self_test = e1000_diag_test,
  1956. .get_strings = e1000_get_strings,
  1957. .set_phys_id = e1000_set_phys_id,
  1958. .get_ethtool_stats = e1000_get_ethtool_stats,
  1959. .get_sset_count = e1000e_get_sset_count,
  1960. .get_coalesce = e1000_get_coalesce,
  1961. .set_coalesce = e1000_set_coalesce,
  1962. .get_rxnfc = e1000_get_rxnfc,
  1963. .get_ts_info = e1000e_get_ts_info,
  1964. .get_eee = e1000e_get_eee,
  1965. .set_eee = e1000e_set_eee,
  1966. };
  1967. void e1000e_set_ethtool_ops(struct net_device *netdev)
  1968. {
  1969. netdev->ethtool_ops = &e1000_ethtool_ops;
  1970. }