ethtool.c 63 KB

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