ethtool.c 63 KB

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