ethtool.c 63 KB

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