ethtool.c 63 KB

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