ethtool.c 62 KB

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