ethtool.c 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341
  1. /* Intel PRO/1000 Linux driver
  2. * Copyright(c) 1999 - 2015 Intel Corporation.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * The full GNU General Public License is included in this distribution in
  14. * the file called "COPYING".
  15. *
  16. * Contact Information:
  17. * Linux NICS <linux.nics@intel.com>
  18. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. */
  21. /* ethtool support for e1000 */
  22. #include <linux/netdevice.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/ethtool.h>
  25. #include <linux/pci.h>
  26. #include <linux/slab.h>
  27. #include <linux/delay.h>
  28. #include <linux/vmalloc.h>
  29. #include <linux/pm_runtime.h>
  30. #include "e1000.h"
  31. enum { NETDEV_STATS, E1000_STATS };
  32. struct e1000_stats {
  33. char stat_string[ETH_GSTRING_LEN];
  34. int type;
  35. int sizeof_stat;
  36. int stat_offset;
  37. };
  38. #define E1000_STAT(str, m) { \
  39. .stat_string = str, \
  40. .type = E1000_STATS, \
  41. .sizeof_stat = sizeof(((struct e1000_adapter *)0)->m), \
  42. .stat_offset = offsetof(struct e1000_adapter, m) }
  43. #define E1000_NETDEV_STAT(str, m) { \
  44. .stat_string = str, \
  45. .type = NETDEV_STATS, \
  46. .sizeof_stat = sizeof(((struct rtnl_link_stats64 *)0)->m), \
  47. .stat_offset = offsetof(struct rtnl_link_stats64, m) }
  48. static const struct e1000_stats e1000_gstrings_stats[] = {
  49. E1000_STAT("rx_packets", stats.gprc),
  50. E1000_STAT("tx_packets", stats.gptc),
  51. E1000_STAT("rx_bytes", stats.gorc),
  52. E1000_STAT("tx_bytes", stats.gotc),
  53. E1000_STAT("rx_broadcast", stats.bprc),
  54. E1000_STAT("tx_broadcast", stats.bptc),
  55. E1000_STAT("rx_multicast", stats.mprc),
  56. E1000_STAT("tx_multicast", stats.mptc),
  57. E1000_NETDEV_STAT("rx_errors", rx_errors),
  58. E1000_NETDEV_STAT("tx_errors", tx_errors),
  59. E1000_NETDEV_STAT("tx_dropped", tx_dropped),
  60. E1000_STAT("multicast", stats.mprc),
  61. E1000_STAT("collisions", stats.colc),
  62. E1000_NETDEV_STAT("rx_length_errors", rx_length_errors),
  63. E1000_NETDEV_STAT("rx_over_errors", rx_over_errors),
  64. E1000_STAT("rx_crc_errors", stats.crcerrs),
  65. E1000_NETDEV_STAT("rx_frame_errors", rx_frame_errors),
  66. E1000_STAT("rx_no_buffer_count", stats.rnbc),
  67. E1000_STAT("rx_missed_errors", stats.mpc),
  68. E1000_STAT("tx_aborted_errors", stats.ecol),
  69. E1000_STAT("tx_carrier_errors", stats.tncrs),
  70. E1000_NETDEV_STAT("tx_fifo_errors", tx_fifo_errors),
  71. E1000_NETDEV_STAT("tx_heartbeat_errors", tx_heartbeat_errors),
  72. E1000_STAT("tx_window_errors", stats.latecol),
  73. E1000_STAT("tx_abort_late_coll", stats.latecol),
  74. E1000_STAT("tx_deferred_ok", stats.dc),
  75. E1000_STAT("tx_single_coll_ok", stats.scc),
  76. E1000_STAT("tx_multi_coll_ok", stats.mcc),
  77. E1000_STAT("tx_timeout_count", tx_timeout_count),
  78. E1000_STAT("tx_restart_queue", restart_queue),
  79. E1000_STAT("rx_long_length_errors", stats.roc),
  80. E1000_STAT("rx_short_length_errors", stats.ruc),
  81. E1000_STAT("rx_align_errors", stats.algnerrc),
  82. E1000_STAT("tx_tcp_seg_good", stats.tsctc),
  83. E1000_STAT("tx_tcp_seg_failed", stats.tsctfc),
  84. E1000_STAT("rx_flow_control_xon", stats.xonrxc),
  85. E1000_STAT("rx_flow_control_xoff", stats.xoffrxc),
  86. E1000_STAT("tx_flow_control_xon", stats.xontxc),
  87. E1000_STAT("tx_flow_control_xoff", stats.xofftxc),
  88. E1000_STAT("rx_csum_offload_good", hw_csum_good),
  89. E1000_STAT("rx_csum_offload_errors", hw_csum_err),
  90. E1000_STAT("rx_header_split", rx_hdr_split),
  91. E1000_STAT("alloc_rx_buff_failed", alloc_rx_buff_failed),
  92. E1000_STAT("tx_smbus", stats.mgptc),
  93. E1000_STAT("rx_smbus", stats.mgprc),
  94. E1000_STAT("dropped_smbus", stats.mgpdc),
  95. E1000_STAT("rx_dma_failed", rx_dma_failed),
  96. E1000_STAT("tx_dma_failed", tx_dma_failed),
  97. E1000_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
  98. E1000_STAT("uncorr_ecc_errors", uncorr_errors),
  99. E1000_STAT("corr_ecc_errors", corr_errors),
  100. E1000_STAT("tx_hwtstamp_timeouts", tx_hwtstamp_timeouts),
  101. };
  102. #define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
  103. #define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)
  104. static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
  105. "Register test (offline)", "Eeprom test (offline)",
  106. "Interrupt test (offline)", "Loopback test (offline)",
  107. "Link test (on/offline)"
  108. };
  109. #define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
  110. static int e1000_get_settings(struct net_device *netdev,
  111. struct ethtool_cmd *ecmd)
  112. {
  113. struct e1000_adapter *adapter = netdev_priv(netdev);
  114. struct e1000_hw *hw = &adapter->hw;
  115. u32 speed;
  116. if (hw->phy.media_type == e1000_media_type_copper) {
  117. ecmd->supported = (SUPPORTED_10baseT_Half |
  118. SUPPORTED_10baseT_Full |
  119. SUPPORTED_100baseT_Half |
  120. SUPPORTED_100baseT_Full |
  121. SUPPORTED_1000baseT_Full |
  122. SUPPORTED_Autoneg |
  123. SUPPORTED_TP);
  124. if (hw->phy.type == e1000_phy_ife)
  125. ecmd->supported &= ~SUPPORTED_1000baseT_Full;
  126. ecmd->advertising = ADVERTISED_TP;
  127. if (hw->mac.autoneg == 1) {
  128. ecmd->advertising |= ADVERTISED_Autoneg;
  129. /* the e1000 autoneg seems to match ethtool nicely */
  130. ecmd->advertising |= hw->phy.autoneg_advertised;
  131. }
  132. ecmd->port = PORT_TP;
  133. ecmd->phy_address = hw->phy.addr;
  134. ecmd->transceiver = XCVR_INTERNAL;
  135. } else {
  136. ecmd->supported = (SUPPORTED_1000baseT_Full |
  137. SUPPORTED_FIBRE |
  138. SUPPORTED_Autoneg);
  139. ecmd->advertising = (ADVERTISED_1000baseT_Full |
  140. ADVERTISED_FIBRE |
  141. ADVERTISED_Autoneg);
  142. ecmd->port = PORT_FIBRE;
  143. ecmd->transceiver = XCVR_EXTERNAL;
  144. }
  145. speed = SPEED_UNKNOWN;
  146. ecmd->duplex = DUPLEX_UNKNOWN;
  147. if (netif_running(netdev)) {
  148. if (netif_carrier_ok(netdev)) {
  149. speed = adapter->link_speed;
  150. ecmd->duplex = adapter->link_duplex - 1;
  151. }
  152. } else if (!pm_runtime_suspended(netdev->dev.parent)) {
  153. u32 status = er32(STATUS);
  154. if (status & E1000_STATUS_LU) {
  155. if (status & E1000_STATUS_SPEED_1000)
  156. speed = SPEED_1000;
  157. else if (status & E1000_STATUS_SPEED_100)
  158. speed = SPEED_100;
  159. else
  160. speed = SPEED_10;
  161. if (status & E1000_STATUS_FD)
  162. ecmd->duplex = DUPLEX_FULL;
  163. else
  164. ecmd->duplex = DUPLEX_HALF;
  165. }
  166. }
  167. ethtool_cmd_speed_set(ecmd, speed);
  168. ecmd->autoneg = ((hw->phy.media_type == e1000_media_type_fiber) ||
  169. hw->mac.autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
  170. /* MDI-X => 2; MDI =>1; Invalid =>0 */
  171. if ((hw->phy.media_type == e1000_media_type_copper) &&
  172. netif_carrier_ok(netdev))
  173. ecmd->eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X : ETH_TP_MDI;
  174. else
  175. ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID;
  176. if (hw->phy.mdix == AUTO_ALL_MODES)
  177. ecmd->eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO;
  178. else
  179. ecmd->eth_tp_mdix_ctrl = hw->phy.mdix;
  180. 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. }
  553. static void e1000_get_ringparam(struct net_device *netdev,
  554. struct ethtool_ringparam *ring)
  555. {
  556. struct e1000_adapter *adapter = netdev_priv(netdev);
  557. ring->rx_max_pending = E1000_MAX_RXD;
  558. ring->tx_max_pending = E1000_MAX_TXD;
  559. ring->rx_pending = adapter->rx_ring_count;
  560. ring->tx_pending = adapter->tx_ring_count;
  561. }
  562. static int e1000_set_ringparam(struct net_device *netdev,
  563. struct ethtool_ringparam *ring)
  564. {
  565. struct e1000_adapter *adapter = netdev_priv(netdev);
  566. struct e1000_ring *temp_tx = NULL, *temp_rx = NULL;
  567. int err = 0, size = sizeof(struct e1000_ring);
  568. bool set_tx = false, set_rx = false;
  569. u16 new_rx_count, new_tx_count;
  570. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  571. return -EINVAL;
  572. new_rx_count = clamp_t(u32, ring->rx_pending, E1000_MIN_RXD,
  573. E1000_MAX_RXD);
  574. new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE);
  575. new_tx_count = clamp_t(u32, ring->tx_pending, E1000_MIN_TXD,
  576. E1000_MAX_TXD);
  577. new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE);
  578. if ((new_tx_count == adapter->tx_ring_count) &&
  579. (new_rx_count == adapter->rx_ring_count))
  580. /* nothing to do */
  581. return 0;
  582. while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
  583. usleep_range(1000, 2000);
  584. if (!netif_running(adapter->netdev)) {
  585. /* Set counts now and allocate resources during open() */
  586. adapter->tx_ring->count = new_tx_count;
  587. adapter->rx_ring->count = new_rx_count;
  588. adapter->tx_ring_count = new_tx_count;
  589. adapter->rx_ring_count = new_rx_count;
  590. goto clear_reset;
  591. }
  592. set_tx = (new_tx_count != adapter->tx_ring_count);
  593. set_rx = (new_rx_count != adapter->rx_ring_count);
  594. /* Allocate temporary storage for ring updates */
  595. if (set_tx) {
  596. temp_tx = vmalloc(size);
  597. if (!temp_tx) {
  598. err = -ENOMEM;
  599. goto free_temp;
  600. }
  601. }
  602. if (set_rx) {
  603. temp_rx = vmalloc(size);
  604. if (!temp_rx) {
  605. err = -ENOMEM;
  606. goto free_temp;
  607. }
  608. }
  609. pm_runtime_get_sync(netdev->dev.parent);
  610. e1000e_down(adapter, true);
  611. /* We can't just free everything and then setup again, because the
  612. * ISRs in MSI-X mode get passed pointers to the Tx and Rx ring
  613. * structs. First, attempt to allocate new resources...
  614. */
  615. if (set_tx) {
  616. memcpy(temp_tx, adapter->tx_ring, size);
  617. temp_tx->count = new_tx_count;
  618. err = e1000e_setup_tx_resources(temp_tx);
  619. if (err)
  620. goto err_setup;
  621. }
  622. if (set_rx) {
  623. memcpy(temp_rx, adapter->rx_ring, size);
  624. temp_rx->count = new_rx_count;
  625. err = e1000e_setup_rx_resources(temp_rx);
  626. if (err)
  627. goto err_setup_rx;
  628. }
  629. /* ...then free the old resources and copy back any new ring data */
  630. if (set_tx) {
  631. e1000e_free_tx_resources(adapter->tx_ring);
  632. memcpy(adapter->tx_ring, temp_tx, size);
  633. adapter->tx_ring_count = new_tx_count;
  634. }
  635. if (set_rx) {
  636. e1000e_free_rx_resources(adapter->rx_ring);
  637. memcpy(adapter->rx_ring, temp_rx, size);
  638. adapter->rx_ring_count = new_rx_count;
  639. }
  640. err_setup_rx:
  641. if (err && set_tx)
  642. e1000e_free_tx_resources(temp_tx);
  643. err_setup:
  644. e1000e_up(adapter);
  645. pm_runtime_put_sync(netdev->dev.parent);
  646. free_temp:
  647. vfree(temp_tx);
  648. vfree(temp_rx);
  649. clear_reset:
  650. clear_bit(__E1000_RESETTING, &adapter->state);
  651. return err;
  652. }
  653. static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data,
  654. int reg, int offset, u32 mask, u32 write)
  655. {
  656. u32 pat, val;
  657. static const u32 test[] = {
  658. 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF
  659. };
  660. for (pat = 0; pat < ARRAY_SIZE(test); pat++) {
  661. E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
  662. (test[pat] & write));
  663. val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
  664. if (val != (test[pat] & write & mask)) {
  665. e_err("pattern test failed (reg 0x%05X): got 0x%08X expected 0x%08X\n",
  666. reg + (offset << 2), val,
  667. (test[pat] & write & mask));
  668. *data = reg;
  669. return true;
  670. }
  671. }
  672. return false;
  673. }
  674. static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
  675. int reg, u32 mask, u32 write)
  676. {
  677. u32 val;
  678. __ew32(&adapter->hw, reg, write & mask);
  679. val = __er32(&adapter->hw, reg);
  680. if ((write & mask) != (val & mask)) {
  681. e_err("set/check test failed (reg 0x%05X): got 0x%08X expected 0x%08X\n",
  682. reg, (val & mask), (write & mask));
  683. *data = reg;
  684. return true;
  685. }
  686. return false;
  687. }
  688. #define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \
  689. do { \
  690. if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
  691. return 1; \
  692. } while (0)
  693. #define REG_PATTERN_TEST(reg, mask, write) \
  694. REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
  695. #define REG_SET_AND_CHECK(reg, mask, write) \
  696. do { \
  697. if (reg_set_and_check(adapter, data, reg, mask, write)) \
  698. return 1; \
  699. } while (0)
  700. static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
  701. {
  702. struct e1000_hw *hw = &adapter->hw;
  703. struct e1000_mac_info *mac = &adapter->hw.mac;
  704. u32 value;
  705. u32 before;
  706. u32 after;
  707. u32 i;
  708. u32 toggle;
  709. u32 mask;
  710. u32 wlock_mac = 0;
  711. /* The status register is Read Only, so a write should fail.
  712. * Some bits that get toggled are ignored. There are several bits
  713. * on newer hardware that are r/w.
  714. */
  715. switch (mac->type) {
  716. case e1000_82571:
  717. case e1000_82572:
  718. case e1000_80003es2lan:
  719. toggle = 0x7FFFF3FF;
  720. break;
  721. default:
  722. toggle = 0x7FFFF033;
  723. break;
  724. }
  725. before = er32(STATUS);
  726. value = (er32(STATUS) & toggle);
  727. ew32(STATUS, toggle);
  728. after = er32(STATUS) & toggle;
  729. if (value != after) {
  730. e_err("failed STATUS register test got: 0x%08X expected: 0x%08X\n",
  731. after, value);
  732. *data = 1;
  733. return 1;
  734. }
  735. /* restore previous status */
  736. ew32(STATUS, before);
  737. if (!(adapter->flags & FLAG_IS_ICH)) {
  738. REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
  739. REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF);
  740. REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF);
  741. REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF);
  742. }
  743. REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF);
  744. REG_PATTERN_TEST(E1000_RDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF);
  745. REG_PATTERN_TEST(E1000_RDLEN(0), 0x000FFF80, 0x000FFFFF);
  746. REG_PATTERN_TEST(E1000_RDH(0), 0x0000FFFF, 0x0000FFFF);
  747. REG_PATTERN_TEST(E1000_RDT(0), 0x0000FFFF, 0x0000FFFF);
  748. REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8);
  749. REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF);
  750. REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
  751. REG_PATTERN_TEST(E1000_TDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF);
  752. REG_PATTERN_TEST(E1000_TDLEN(0), 0x000FFF80, 0x000FFFFF);
  753. REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000);
  754. before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE);
  755. REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
  756. REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);
  757. REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
  758. REG_PATTERN_TEST(E1000_RDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF);
  759. if (!(adapter->flags & FLAG_IS_ICH))
  760. REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
  761. REG_PATTERN_TEST(E1000_TDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF);
  762. REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
  763. mask = 0x8003FFFF;
  764. switch (mac->type) {
  765. case e1000_ich10lan:
  766. case e1000_pchlan:
  767. case e1000_pch2lan:
  768. case e1000_pch_lpt:
  769. case e1000_pch_spt:
  770. mask |= (1 << 18);
  771. break;
  772. default:
  773. break;
  774. }
  775. if ((mac->type == e1000_pch_lpt) || (mac->type == e1000_pch_spt))
  776. wlock_mac = (er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK) >>
  777. E1000_FWSM_WLOCK_MAC_SHIFT;
  778. for (i = 0; i < mac->rar_entry_count; i++) {
  779. if ((mac->type == e1000_pch_lpt) ||
  780. (mac->type == e1000_pch_spt)) {
  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, fext_nvm11, tarc0;
  1304. if (hw->mac.type == e1000_pch_spt) {
  1305. fext_nvm11 = er32(FEXTNVM11);
  1306. fext_nvm11 |= E1000_FEXTNVM11_DISABLE_MULR_FIX;
  1307. ew32(FEXTNVM11, fext_nvm11);
  1308. tarc0 = er32(TARC(0));
  1309. /* clear bits 28 & 29 (control of MULR concurrent requests) */
  1310. tarc0 &= 0xcfffffff;
  1311. /* set bit 29 (value of MULR requests is now 2) */
  1312. tarc0 |= 0x20000000;
  1313. ew32(TARC(0), tarc0);
  1314. }
  1315. if (hw->phy.media_type == e1000_media_type_fiber ||
  1316. hw->phy.media_type == e1000_media_type_internal_serdes) {
  1317. switch (hw->mac.type) {
  1318. case e1000_80003es2lan:
  1319. return e1000_set_es2lan_mac_loopback(adapter);
  1320. case e1000_82571:
  1321. case e1000_82572:
  1322. return e1000_set_82571_fiber_loopback(adapter);
  1323. default:
  1324. rctl = er32(RCTL);
  1325. rctl |= E1000_RCTL_LBM_TCVR;
  1326. ew32(RCTL, rctl);
  1327. return 0;
  1328. }
  1329. } else if (hw->phy.media_type == e1000_media_type_copper) {
  1330. return e1000_integrated_phy_loopback(adapter);
  1331. }
  1332. return 7;
  1333. }
  1334. static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
  1335. {
  1336. struct e1000_hw *hw = &adapter->hw;
  1337. u32 rctl, fext_nvm11, tarc0;
  1338. u16 phy_reg;
  1339. rctl = er32(RCTL);
  1340. rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
  1341. ew32(RCTL, rctl);
  1342. switch (hw->mac.type) {
  1343. case e1000_pch_spt:
  1344. fext_nvm11 = er32(FEXTNVM11);
  1345. fext_nvm11 &= ~E1000_FEXTNVM11_DISABLE_MULR_FIX;
  1346. ew32(FEXTNVM11, fext_nvm11);
  1347. tarc0 = er32(TARC(0));
  1348. /* clear bits 28 & 29 (control of MULR concurrent requests) */
  1349. /* set bit 29 (value of MULR requests is now 0) */
  1350. tarc0 &= 0xcfffffff;
  1351. ew32(TARC(0), tarc0);
  1352. /* fall through */
  1353. case e1000_80003es2lan:
  1354. if (hw->phy.media_type == e1000_media_type_fiber ||
  1355. hw->phy.media_type == e1000_media_type_internal_serdes) {
  1356. /* restore CTRL_EXT, stealing space from tx_fifo_head */
  1357. ew32(CTRL_EXT, adapter->tx_fifo_head);
  1358. adapter->tx_fifo_head = 0;
  1359. }
  1360. /* fall through */
  1361. case e1000_82571:
  1362. case e1000_82572:
  1363. if (hw->phy.media_type == e1000_media_type_fiber ||
  1364. hw->phy.media_type == e1000_media_type_internal_serdes) {
  1365. ew32(SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
  1366. e1e_flush();
  1367. usleep_range(10000, 20000);
  1368. break;
  1369. }
  1370. /* Fall Through */
  1371. default:
  1372. hw->mac.autoneg = 1;
  1373. if (hw->phy.type == e1000_phy_gg82563)
  1374. e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
  1375. e1e_rphy(hw, MII_BMCR, &phy_reg);
  1376. if (phy_reg & BMCR_LOOPBACK) {
  1377. phy_reg &= ~BMCR_LOOPBACK;
  1378. e1e_wphy(hw, MII_BMCR, phy_reg);
  1379. if (hw->phy.ops.commit)
  1380. hw->phy.ops.commit(hw);
  1381. }
  1382. break;
  1383. }
  1384. }
  1385. static void e1000_create_lbtest_frame(struct sk_buff *skb,
  1386. unsigned int frame_size)
  1387. {
  1388. memset(skb->data, 0xFF, frame_size);
  1389. frame_size &= ~1;
  1390. memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
  1391. memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
  1392. memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
  1393. }
  1394. static int e1000_check_lbtest_frame(struct sk_buff *skb,
  1395. unsigned int frame_size)
  1396. {
  1397. frame_size &= ~1;
  1398. if (*(skb->data + 3) == 0xFF)
  1399. if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
  1400. (*(skb->data + frame_size / 2 + 12) == 0xAF))
  1401. return 0;
  1402. return 13;
  1403. }
  1404. static int e1000_run_loopback_test(struct e1000_adapter *adapter)
  1405. {
  1406. struct e1000_ring *tx_ring = &adapter->test_tx_ring;
  1407. struct e1000_ring *rx_ring = &adapter->test_rx_ring;
  1408. struct pci_dev *pdev = adapter->pdev;
  1409. struct e1000_hw *hw = &adapter->hw;
  1410. struct e1000_buffer *buffer_info;
  1411. int i, j, k, l;
  1412. int lc;
  1413. int good_cnt;
  1414. int ret_val = 0;
  1415. unsigned long time;
  1416. ew32(RDT(0), rx_ring->count - 1);
  1417. /* Calculate the loop count based on the largest descriptor ring
  1418. * The idea is to wrap the largest ring a number of times using 64
  1419. * send/receive pairs during each loop
  1420. */
  1421. if (rx_ring->count <= tx_ring->count)
  1422. lc = ((tx_ring->count / 64) * 2) + 1;
  1423. else
  1424. lc = ((rx_ring->count / 64) * 2) + 1;
  1425. k = 0;
  1426. l = 0;
  1427. /* loop count loop */
  1428. for (j = 0; j <= lc; j++) {
  1429. /* send the packets */
  1430. for (i = 0; i < 64; i++) {
  1431. buffer_info = &tx_ring->buffer_info[k];
  1432. e1000_create_lbtest_frame(buffer_info->skb, 1024);
  1433. dma_sync_single_for_device(&pdev->dev,
  1434. buffer_info->dma,
  1435. buffer_info->length,
  1436. DMA_TO_DEVICE);
  1437. k++;
  1438. if (k == tx_ring->count)
  1439. k = 0;
  1440. }
  1441. ew32(TDT(0), k);
  1442. e1e_flush();
  1443. msleep(200);
  1444. time = jiffies; /* set the start time for the receive */
  1445. good_cnt = 0;
  1446. /* receive the sent packets */
  1447. do {
  1448. buffer_info = &rx_ring->buffer_info[l];
  1449. dma_sync_single_for_cpu(&pdev->dev,
  1450. buffer_info->dma, 2048,
  1451. DMA_FROM_DEVICE);
  1452. ret_val = e1000_check_lbtest_frame(buffer_info->skb,
  1453. 1024);
  1454. if (!ret_val)
  1455. good_cnt++;
  1456. l++;
  1457. if (l == rx_ring->count)
  1458. l = 0;
  1459. /* time + 20 msecs (200 msecs on 2.4) is more than
  1460. * enough time to complete the receives, if it's
  1461. * exceeded, break and error off
  1462. */
  1463. } while ((good_cnt < 64) && !time_after(jiffies, time + 20));
  1464. if (good_cnt != 64) {
  1465. ret_val = 13; /* ret_val is the same as mis-compare */
  1466. break;
  1467. }
  1468. if (time_after(jiffies, time + 20)) {
  1469. ret_val = 14; /* error code for time out error */
  1470. break;
  1471. }
  1472. }
  1473. return ret_val;
  1474. }
  1475. static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
  1476. {
  1477. struct e1000_hw *hw = &adapter->hw;
  1478. /* PHY loopback cannot be performed if SoL/IDER sessions are active */
  1479. if (hw->phy.ops.check_reset_block &&
  1480. hw->phy.ops.check_reset_block(hw)) {
  1481. e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
  1482. *data = 0;
  1483. goto out;
  1484. }
  1485. *data = e1000_setup_desc_rings(adapter);
  1486. if (*data)
  1487. goto out;
  1488. *data = e1000_setup_loopback_test(adapter);
  1489. if (*data)
  1490. goto err_loopback;
  1491. *data = e1000_run_loopback_test(adapter);
  1492. e1000_loopback_cleanup(adapter);
  1493. err_loopback:
  1494. e1000_free_desc_rings(adapter);
  1495. out:
  1496. return *data;
  1497. }
  1498. static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
  1499. {
  1500. struct e1000_hw *hw = &adapter->hw;
  1501. *data = 0;
  1502. if (hw->phy.media_type == e1000_media_type_internal_serdes) {
  1503. int i = 0;
  1504. hw->mac.serdes_has_link = false;
  1505. /* On some blade server designs, link establishment
  1506. * could take as long as 2-3 minutes
  1507. */
  1508. do {
  1509. hw->mac.ops.check_for_link(hw);
  1510. if (hw->mac.serdes_has_link)
  1511. return *data;
  1512. msleep(20);
  1513. } while (i++ < 3750);
  1514. *data = 1;
  1515. } else {
  1516. hw->mac.ops.check_for_link(hw);
  1517. if (hw->mac.autoneg)
  1518. /* On some Phy/switch combinations, link establishment
  1519. * can take a few seconds more than expected.
  1520. */
  1521. msleep_interruptible(5000);
  1522. if (!(er32(STATUS) & E1000_STATUS_LU))
  1523. *data = 1;
  1524. }
  1525. return *data;
  1526. }
  1527. static int e1000e_get_sset_count(struct net_device __always_unused *netdev,
  1528. int sset)
  1529. {
  1530. switch (sset) {
  1531. case ETH_SS_TEST:
  1532. return E1000_TEST_LEN;
  1533. case ETH_SS_STATS:
  1534. return E1000_STATS_LEN;
  1535. default:
  1536. return -EOPNOTSUPP;
  1537. }
  1538. }
  1539. static void e1000_diag_test(struct net_device *netdev,
  1540. struct ethtool_test *eth_test, u64 *data)
  1541. {
  1542. struct e1000_adapter *adapter = netdev_priv(netdev);
  1543. u16 autoneg_advertised;
  1544. u8 forced_speed_duplex;
  1545. u8 autoneg;
  1546. bool if_running = netif_running(netdev);
  1547. pm_runtime_get_sync(netdev->dev.parent);
  1548. set_bit(__E1000_TESTING, &adapter->state);
  1549. if (!if_running) {
  1550. /* Get control of and reset hardware */
  1551. if (adapter->flags & FLAG_HAS_AMT)
  1552. e1000e_get_hw_control(adapter);
  1553. e1000e_power_up_phy(adapter);
  1554. adapter->hw.phy.autoneg_wait_to_complete = 1;
  1555. e1000e_reset(adapter);
  1556. adapter->hw.phy.autoneg_wait_to_complete = 0;
  1557. }
  1558. if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
  1559. /* Offline tests */
  1560. /* save speed, duplex, autoneg settings */
  1561. autoneg_advertised = adapter->hw.phy.autoneg_advertised;
  1562. forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
  1563. autoneg = adapter->hw.mac.autoneg;
  1564. e_info("offline testing starting\n");
  1565. if (if_running)
  1566. /* indicate we're in test mode */
  1567. dev_close(netdev);
  1568. if (e1000_reg_test(adapter, &data[0]))
  1569. eth_test->flags |= ETH_TEST_FL_FAILED;
  1570. e1000e_reset(adapter);
  1571. if (e1000_eeprom_test(adapter, &data[1]))
  1572. eth_test->flags |= ETH_TEST_FL_FAILED;
  1573. e1000e_reset(adapter);
  1574. if (e1000_intr_test(adapter, &data[2]))
  1575. eth_test->flags |= ETH_TEST_FL_FAILED;
  1576. e1000e_reset(adapter);
  1577. if (e1000_loopback_test(adapter, &data[3]))
  1578. eth_test->flags |= ETH_TEST_FL_FAILED;
  1579. /* force this routine to wait until autoneg complete/timeout */
  1580. adapter->hw.phy.autoneg_wait_to_complete = 1;
  1581. e1000e_reset(adapter);
  1582. adapter->hw.phy.autoneg_wait_to_complete = 0;
  1583. if (e1000_link_test(adapter, &data[4]))
  1584. eth_test->flags |= ETH_TEST_FL_FAILED;
  1585. /* restore speed, duplex, autoneg settings */
  1586. adapter->hw.phy.autoneg_advertised = autoneg_advertised;
  1587. adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
  1588. adapter->hw.mac.autoneg = autoneg;
  1589. e1000e_reset(adapter);
  1590. clear_bit(__E1000_TESTING, &adapter->state);
  1591. if (if_running)
  1592. dev_open(netdev);
  1593. } else {
  1594. /* Online tests */
  1595. e_info("online testing starting\n");
  1596. /* register, eeprom, intr and loopback tests not run online */
  1597. data[0] = 0;
  1598. data[1] = 0;
  1599. data[2] = 0;
  1600. data[3] = 0;
  1601. if (e1000_link_test(adapter, &data[4]))
  1602. eth_test->flags |= ETH_TEST_FL_FAILED;
  1603. clear_bit(__E1000_TESTING, &adapter->state);
  1604. }
  1605. if (!if_running) {
  1606. e1000e_reset(adapter);
  1607. if (adapter->flags & FLAG_HAS_AMT)
  1608. e1000e_release_hw_control(adapter);
  1609. }
  1610. msleep_interruptible(4 * 1000);
  1611. pm_runtime_put_sync(netdev->dev.parent);
  1612. }
  1613. static void e1000_get_wol(struct net_device *netdev,
  1614. struct ethtool_wolinfo *wol)
  1615. {
  1616. struct e1000_adapter *adapter = netdev_priv(netdev);
  1617. wol->supported = 0;
  1618. wol->wolopts = 0;
  1619. if (!(adapter->flags & FLAG_HAS_WOL) ||
  1620. !device_can_wakeup(&adapter->pdev->dev))
  1621. return;
  1622. wol->supported = WAKE_UCAST | WAKE_MCAST |
  1623. WAKE_BCAST | WAKE_MAGIC | WAKE_PHY;
  1624. /* apply any specific unsupported masks here */
  1625. if (adapter->flags & FLAG_NO_WAKE_UCAST) {
  1626. wol->supported &= ~WAKE_UCAST;
  1627. if (adapter->wol & E1000_WUFC_EX)
  1628. e_err("Interface does not support directed (unicast) frame wake-up packets\n");
  1629. }
  1630. if (adapter->wol & E1000_WUFC_EX)
  1631. wol->wolopts |= WAKE_UCAST;
  1632. if (adapter->wol & E1000_WUFC_MC)
  1633. wol->wolopts |= WAKE_MCAST;
  1634. if (adapter->wol & E1000_WUFC_BC)
  1635. wol->wolopts |= WAKE_BCAST;
  1636. if (adapter->wol & E1000_WUFC_MAG)
  1637. wol->wolopts |= WAKE_MAGIC;
  1638. if (adapter->wol & E1000_WUFC_LNKC)
  1639. wol->wolopts |= WAKE_PHY;
  1640. }
  1641. static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  1642. {
  1643. struct e1000_adapter *adapter = netdev_priv(netdev);
  1644. if (!(adapter->flags & FLAG_HAS_WOL) ||
  1645. !device_can_wakeup(&adapter->pdev->dev) ||
  1646. (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
  1647. WAKE_MAGIC | WAKE_PHY)))
  1648. return -EOPNOTSUPP;
  1649. /* these settings will always override what we currently have */
  1650. adapter->wol = 0;
  1651. if (wol->wolopts & WAKE_UCAST)
  1652. adapter->wol |= E1000_WUFC_EX;
  1653. if (wol->wolopts & WAKE_MCAST)
  1654. adapter->wol |= E1000_WUFC_MC;
  1655. if (wol->wolopts & WAKE_BCAST)
  1656. adapter->wol |= E1000_WUFC_BC;
  1657. if (wol->wolopts & WAKE_MAGIC)
  1658. adapter->wol |= E1000_WUFC_MAG;
  1659. if (wol->wolopts & WAKE_PHY)
  1660. adapter->wol |= E1000_WUFC_LNKC;
  1661. device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
  1662. return 0;
  1663. }
  1664. static int e1000_set_phys_id(struct net_device *netdev,
  1665. enum ethtool_phys_id_state state)
  1666. {
  1667. struct e1000_adapter *adapter = netdev_priv(netdev);
  1668. struct e1000_hw *hw = &adapter->hw;
  1669. switch (state) {
  1670. case ETHTOOL_ID_ACTIVE:
  1671. pm_runtime_get_sync(netdev->dev.parent);
  1672. if (!hw->mac.ops.blink_led)
  1673. return 2; /* cycle on/off twice per second */
  1674. hw->mac.ops.blink_led(hw);
  1675. break;
  1676. case ETHTOOL_ID_INACTIVE:
  1677. if (hw->phy.type == e1000_phy_ife)
  1678. e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
  1679. hw->mac.ops.led_off(hw);
  1680. hw->mac.ops.cleanup_led(hw);
  1681. pm_runtime_put_sync(netdev->dev.parent);
  1682. break;
  1683. case ETHTOOL_ID_ON:
  1684. hw->mac.ops.led_on(hw);
  1685. break;
  1686. case ETHTOOL_ID_OFF:
  1687. hw->mac.ops.led_off(hw);
  1688. break;
  1689. }
  1690. return 0;
  1691. }
  1692. static int e1000_get_coalesce(struct net_device *netdev,
  1693. struct ethtool_coalesce *ec)
  1694. {
  1695. struct e1000_adapter *adapter = netdev_priv(netdev);
  1696. if (adapter->itr_setting <= 4)
  1697. ec->rx_coalesce_usecs = adapter->itr_setting;
  1698. else
  1699. ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
  1700. return 0;
  1701. }
  1702. static int e1000_set_coalesce(struct net_device *netdev,
  1703. struct ethtool_coalesce *ec)
  1704. {
  1705. struct e1000_adapter *adapter = netdev_priv(netdev);
  1706. if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
  1707. ((ec->rx_coalesce_usecs > 4) &&
  1708. (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
  1709. (ec->rx_coalesce_usecs == 2))
  1710. return -EINVAL;
  1711. if (ec->rx_coalesce_usecs == 4) {
  1712. adapter->itr_setting = 4;
  1713. adapter->itr = adapter->itr_setting;
  1714. } else if (ec->rx_coalesce_usecs <= 3) {
  1715. adapter->itr = 20000;
  1716. adapter->itr_setting = ec->rx_coalesce_usecs;
  1717. } else {
  1718. adapter->itr = (1000000 / ec->rx_coalesce_usecs);
  1719. adapter->itr_setting = adapter->itr & ~3;
  1720. }
  1721. pm_runtime_get_sync(netdev->dev.parent);
  1722. if (adapter->itr_setting != 0)
  1723. e1000e_write_itr(adapter, adapter->itr);
  1724. else
  1725. e1000e_write_itr(adapter, 0);
  1726. pm_runtime_put_sync(netdev->dev.parent);
  1727. return 0;
  1728. }
  1729. static int e1000_nway_reset(struct net_device *netdev)
  1730. {
  1731. struct e1000_adapter *adapter = netdev_priv(netdev);
  1732. if (!netif_running(netdev))
  1733. return -EAGAIN;
  1734. if (!adapter->hw.mac.autoneg)
  1735. return -EINVAL;
  1736. pm_runtime_get_sync(netdev->dev.parent);
  1737. e1000e_reinit_locked(adapter);
  1738. pm_runtime_put_sync(netdev->dev.parent);
  1739. return 0;
  1740. }
  1741. static void e1000_get_ethtool_stats(struct net_device *netdev,
  1742. struct ethtool_stats __always_unused *stats,
  1743. u64 *data)
  1744. {
  1745. struct e1000_adapter *adapter = netdev_priv(netdev);
  1746. struct rtnl_link_stats64 net_stats;
  1747. int i;
  1748. char *p = NULL;
  1749. pm_runtime_get_sync(netdev->dev.parent);
  1750. e1000e_get_stats64(netdev, &net_stats);
  1751. pm_runtime_put_sync(netdev->dev.parent);
  1752. for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
  1753. switch (e1000_gstrings_stats[i].type) {
  1754. case NETDEV_STATS:
  1755. p = (char *)&net_stats +
  1756. e1000_gstrings_stats[i].stat_offset;
  1757. break;
  1758. case E1000_STATS:
  1759. p = (char *)adapter +
  1760. e1000_gstrings_stats[i].stat_offset;
  1761. break;
  1762. default:
  1763. data[i] = 0;
  1764. continue;
  1765. }
  1766. data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
  1767. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1768. }
  1769. }
  1770. static void e1000_get_strings(struct net_device __always_unused *netdev,
  1771. u32 stringset, u8 *data)
  1772. {
  1773. u8 *p = data;
  1774. int i;
  1775. switch (stringset) {
  1776. case ETH_SS_TEST:
  1777. memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test));
  1778. break;
  1779. case ETH_SS_STATS:
  1780. for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
  1781. memcpy(p, e1000_gstrings_stats[i].stat_string,
  1782. ETH_GSTRING_LEN);
  1783. p += ETH_GSTRING_LEN;
  1784. }
  1785. break;
  1786. }
  1787. }
  1788. static int e1000_get_rxnfc(struct net_device *netdev,
  1789. struct ethtool_rxnfc *info,
  1790. u32 __always_unused *rule_locs)
  1791. {
  1792. info->data = 0;
  1793. switch (info->cmd) {
  1794. case ETHTOOL_GRXFH: {
  1795. struct e1000_adapter *adapter = netdev_priv(netdev);
  1796. struct e1000_hw *hw = &adapter->hw;
  1797. u32 mrqc;
  1798. pm_runtime_get_sync(netdev->dev.parent);
  1799. mrqc = er32(MRQC);
  1800. pm_runtime_put_sync(netdev->dev.parent);
  1801. if (!(mrqc & E1000_MRQC_RSS_FIELD_MASK))
  1802. return 0;
  1803. switch (info->flow_type) {
  1804. case TCP_V4_FLOW:
  1805. if (mrqc & E1000_MRQC_RSS_FIELD_IPV4_TCP)
  1806. info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  1807. /* fall through */
  1808. case UDP_V4_FLOW:
  1809. case SCTP_V4_FLOW:
  1810. case AH_ESP_V4_FLOW:
  1811. case IPV4_FLOW:
  1812. if (mrqc & E1000_MRQC_RSS_FIELD_IPV4)
  1813. info->data |= RXH_IP_SRC | RXH_IP_DST;
  1814. break;
  1815. case TCP_V6_FLOW:
  1816. if (mrqc & E1000_MRQC_RSS_FIELD_IPV6_TCP)
  1817. info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  1818. /* fall through */
  1819. case UDP_V6_FLOW:
  1820. case SCTP_V6_FLOW:
  1821. case AH_ESP_V6_FLOW:
  1822. case IPV6_FLOW:
  1823. if (mrqc & E1000_MRQC_RSS_FIELD_IPV6)
  1824. info->data |= RXH_IP_SRC | RXH_IP_DST;
  1825. break;
  1826. default:
  1827. break;
  1828. }
  1829. return 0;
  1830. }
  1831. default:
  1832. return -EOPNOTSUPP;
  1833. }
  1834. }
  1835. static int e1000e_get_eee(struct net_device *netdev, struct ethtool_eee *edata)
  1836. {
  1837. struct e1000_adapter *adapter = netdev_priv(netdev);
  1838. struct e1000_hw *hw = &adapter->hw;
  1839. u16 cap_addr, lpa_addr, pcs_stat_addr, phy_data;
  1840. u32 ret_val;
  1841. if (!(adapter->flags2 & FLAG2_HAS_EEE))
  1842. return -EOPNOTSUPP;
  1843. switch (hw->phy.type) {
  1844. case e1000_phy_82579:
  1845. cap_addr = I82579_EEE_CAPABILITY;
  1846. lpa_addr = I82579_EEE_LP_ABILITY;
  1847. pcs_stat_addr = I82579_EEE_PCS_STATUS;
  1848. break;
  1849. case e1000_phy_i217:
  1850. cap_addr = I217_EEE_CAPABILITY;
  1851. lpa_addr = I217_EEE_LP_ABILITY;
  1852. pcs_stat_addr = I217_EEE_PCS_STATUS;
  1853. break;
  1854. default:
  1855. return -EOPNOTSUPP;
  1856. }
  1857. pm_runtime_get_sync(netdev->dev.parent);
  1858. ret_val = hw->phy.ops.acquire(hw);
  1859. if (ret_val) {
  1860. pm_runtime_put_sync(netdev->dev.parent);
  1861. return -EBUSY;
  1862. }
  1863. /* EEE Capability */
  1864. ret_val = e1000_read_emi_reg_locked(hw, cap_addr, &phy_data);
  1865. if (ret_val)
  1866. goto release;
  1867. edata->supported = mmd_eee_cap_to_ethtool_sup_t(phy_data);
  1868. /* EEE Advertised */
  1869. edata->advertised = mmd_eee_adv_to_ethtool_adv_t(adapter->eee_advert);
  1870. /* EEE Link Partner Advertised */
  1871. ret_val = e1000_read_emi_reg_locked(hw, lpa_addr, &phy_data);
  1872. if (ret_val)
  1873. goto release;
  1874. edata->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(phy_data);
  1875. /* EEE PCS Status */
  1876. ret_val = e1000_read_emi_reg_locked(hw, pcs_stat_addr, &phy_data);
  1877. if (ret_val)
  1878. goto release;
  1879. if (hw->phy.type == e1000_phy_82579)
  1880. phy_data <<= 8;
  1881. /* Result of the EEE auto negotiation - there is no register that
  1882. * has the status of the EEE negotiation so do a best-guess based
  1883. * on whether Tx or Rx LPI indications have been received.
  1884. */
  1885. if (phy_data & (E1000_EEE_TX_LPI_RCVD | E1000_EEE_RX_LPI_RCVD))
  1886. edata->eee_active = true;
  1887. edata->eee_enabled = !hw->dev_spec.ich8lan.eee_disable;
  1888. edata->tx_lpi_enabled = true;
  1889. edata->tx_lpi_timer = er32(LPIC) >> E1000_LPIC_LPIET_SHIFT;
  1890. release:
  1891. hw->phy.ops.release(hw);
  1892. if (ret_val)
  1893. ret_val = -ENODATA;
  1894. pm_runtime_put_sync(netdev->dev.parent);
  1895. return ret_val;
  1896. }
  1897. static int e1000e_set_eee(struct net_device *netdev, struct ethtool_eee *edata)
  1898. {
  1899. struct e1000_adapter *adapter = netdev_priv(netdev);
  1900. struct e1000_hw *hw = &adapter->hw;
  1901. struct ethtool_eee eee_curr;
  1902. s32 ret_val;
  1903. ret_val = e1000e_get_eee(netdev, &eee_curr);
  1904. if (ret_val)
  1905. return ret_val;
  1906. if (eee_curr.tx_lpi_enabled != edata->tx_lpi_enabled) {
  1907. e_err("Setting EEE tx-lpi is not supported\n");
  1908. return -EINVAL;
  1909. }
  1910. if (eee_curr.tx_lpi_timer != edata->tx_lpi_timer) {
  1911. e_err("Setting EEE Tx LPI timer is not supported\n");
  1912. return -EINVAL;
  1913. }
  1914. if (edata->advertised & ~(ADVERTISE_100_FULL | ADVERTISE_1000_FULL)) {
  1915. e_err("EEE advertisement supports only 100TX and/or 1000T full-duplex\n");
  1916. return -EINVAL;
  1917. }
  1918. adapter->eee_advert = ethtool_adv_to_mmd_eee_adv_t(edata->advertised);
  1919. hw->dev_spec.ich8lan.eee_disable = !edata->eee_enabled;
  1920. pm_runtime_get_sync(netdev->dev.parent);
  1921. /* reset the link */
  1922. if (netif_running(netdev))
  1923. e1000e_reinit_locked(adapter);
  1924. else
  1925. e1000e_reset(adapter);
  1926. pm_runtime_put_sync(netdev->dev.parent);
  1927. return 0;
  1928. }
  1929. static int e1000e_get_ts_info(struct net_device *netdev,
  1930. struct ethtool_ts_info *info)
  1931. {
  1932. struct e1000_adapter *adapter = netdev_priv(netdev);
  1933. ethtool_op_get_ts_info(netdev, info);
  1934. if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
  1935. return 0;
  1936. info->so_timestamping |= (SOF_TIMESTAMPING_TX_HARDWARE |
  1937. SOF_TIMESTAMPING_RX_HARDWARE |
  1938. SOF_TIMESTAMPING_RAW_HARDWARE);
  1939. info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
  1940. info->rx_filters = ((1 << HWTSTAMP_FILTER_NONE) |
  1941. (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
  1942. (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
  1943. (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
  1944. (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |
  1945. (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
  1946. (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
  1947. (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
  1948. (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
  1949. (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
  1950. (1 << HWTSTAMP_FILTER_ALL));
  1951. if (adapter->ptp_clock)
  1952. info->phc_index = ptp_clock_index(adapter->ptp_clock);
  1953. return 0;
  1954. }
  1955. static const struct ethtool_ops e1000_ethtool_ops = {
  1956. .get_settings = e1000_get_settings,
  1957. .set_settings = e1000_set_settings,
  1958. .get_drvinfo = e1000_get_drvinfo,
  1959. .get_regs_len = e1000_get_regs_len,
  1960. .get_regs = e1000_get_regs,
  1961. .get_wol = e1000_get_wol,
  1962. .set_wol = e1000_set_wol,
  1963. .get_msglevel = e1000_get_msglevel,
  1964. .set_msglevel = e1000_set_msglevel,
  1965. .nway_reset = e1000_nway_reset,
  1966. .get_link = ethtool_op_get_link,
  1967. .get_eeprom_len = e1000_get_eeprom_len,
  1968. .get_eeprom = e1000_get_eeprom,
  1969. .set_eeprom = e1000_set_eeprom,
  1970. .get_ringparam = e1000_get_ringparam,
  1971. .set_ringparam = e1000_set_ringparam,
  1972. .get_pauseparam = e1000_get_pauseparam,
  1973. .set_pauseparam = e1000_set_pauseparam,
  1974. .self_test = e1000_diag_test,
  1975. .get_strings = e1000_get_strings,
  1976. .set_phys_id = e1000_set_phys_id,
  1977. .get_ethtool_stats = e1000_get_ethtool_stats,
  1978. .get_sset_count = e1000e_get_sset_count,
  1979. .get_coalesce = e1000_get_coalesce,
  1980. .set_coalesce = e1000_set_coalesce,
  1981. .get_rxnfc = e1000_get_rxnfc,
  1982. .get_ts_info = e1000e_get_ts_info,
  1983. .get_eee = e1000e_get_eee,
  1984. .set_eee = e1000e_set_eee,
  1985. };
  1986. void e1000e_set_ethtool_ops(struct net_device *netdev)
  1987. {
  1988. netdev->ethtool_ops = &e1000_ethtool_ops;
  1989. }