ethtool.c 63 KB

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