ethtool.c 63 KB

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