e1000_ethtool.c 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910
  1. /*******************************************************************************
  2. * Intel PRO/1000 Linux driver
  3. * Copyright(c) 1999 - 2006 Intel Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * The full GNU General Public License is included in this distribution in
  15. * the file called "COPYING".
  16. *
  17. * Contact Information:
  18. * Linux NICS <linux.nics@intel.com>
  19. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  20. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  21. *
  22. ******************************************************************************/
  23. /* ethtool support for e1000 */
  24. #include "e1000.h"
  25. #include <linux/uaccess.h>
  26. enum {NETDEV_STATS, E1000_STATS};
  27. struct e1000_stats {
  28. char stat_string[ETH_GSTRING_LEN];
  29. int type;
  30. int sizeof_stat;
  31. int stat_offset;
  32. };
  33. #define E1000_STAT(m) E1000_STATS, \
  34. sizeof(((struct e1000_adapter *)0)->m), \
  35. offsetof(struct e1000_adapter, m)
  36. #define E1000_NETDEV_STAT(m) NETDEV_STATS, \
  37. sizeof(((struct net_device *)0)->m), \
  38. offsetof(struct net_device, m)
  39. static const struct e1000_stats e1000_gstrings_stats[] = {
  40. { "rx_packets", E1000_STAT(stats.gprc) },
  41. { "tx_packets", E1000_STAT(stats.gptc) },
  42. { "rx_bytes", E1000_STAT(stats.gorcl) },
  43. { "tx_bytes", E1000_STAT(stats.gotcl) },
  44. { "rx_broadcast", E1000_STAT(stats.bprc) },
  45. { "tx_broadcast", E1000_STAT(stats.bptc) },
  46. { "rx_multicast", E1000_STAT(stats.mprc) },
  47. { "tx_multicast", E1000_STAT(stats.mptc) },
  48. { "rx_errors", E1000_STAT(stats.rxerrc) },
  49. { "tx_errors", E1000_STAT(stats.txerrc) },
  50. { "tx_dropped", E1000_NETDEV_STAT(stats.tx_dropped) },
  51. { "multicast", E1000_STAT(stats.mprc) },
  52. { "collisions", E1000_STAT(stats.colc) },
  53. { "rx_length_errors", E1000_STAT(stats.rlerrc) },
  54. { "rx_over_errors", E1000_NETDEV_STAT(stats.rx_over_errors) },
  55. { "rx_crc_errors", E1000_STAT(stats.crcerrs) },
  56. { "rx_frame_errors", E1000_NETDEV_STAT(stats.rx_frame_errors) },
  57. { "rx_no_buffer_count", E1000_STAT(stats.rnbc) },
  58. { "rx_missed_errors", E1000_STAT(stats.mpc) },
  59. { "tx_aborted_errors", E1000_STAT(stats.ecol) },
  60. { "tx_carrier_errors", E1000_STAT(stats.tncrs) },
  61. { "tx_fifo_errors", E1000_NETDEV_STAT(stats.tx_fifo_errors) },
  62. { "tx_heartbeat_errors", E1000_NETDEV_STAT(stats.tx_heartbeat_errors) },
  63. { "tx_window_errors", E1000_STAT(stats.latecol) },
  64. { "tx_abort_late_coll", E1000_STAT(stats.latecol) },
  65. { "tx_deferred_ok", E1000_STAT(stats.dc) },
  66. { "tx_single_coll_ok", E1000_STAT(stats.scc) },
  67. { "tx_multi_coll_ok", E1000_STAT(stats.mcc) },
  68. { "tx_timeout_count", E1000_STAT(tx_timeout_count) },
  69. { "tx_restart_queue", E1000_STAT(restart_queue) },
  70. { "rx_long_length_errors", E1000_STAT(stats.roc) },
  71. { "rx_short_length_errors", E1000_STAT(stats.ruc) },
  72. { "rx_align_errors", E1000_STAT(stats.algnerrc) },
  73. { "tx_tcp_seg_good", E1000_STAT(stats.tsctc) },
  74. { "tx_tcp_seg_failed", E1000_STAT(stats.tsctfc) },
  75. { "rx_flow_control_xon", E1000_STAT(stats.xonrxc) },
  76. { "rx_flow_control_xoff", E1000_STAT(stats.xoffrxc) },
  77. { "tx_flow_control_xon", E1000_STAT(stats.xontxc) },
  78. { "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) },
  79. { "rx_long_byte_count", E1000_STAT(stats.gorcl) },
  80. { "rx_csum_offload_good", E1000_STAT(hw_csum_good) },
  81. { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) },
  82. { "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed) },
  83. { "tx_smbus", E1000_STAT(stats.mgptc) },
  84. { "rx_smbus", E1000_STAT(stats.mgprc) },
  85. { "dropped_smbus", E1000_STAT(stats.mgpdc) },
  86. };
  87. #define E1000_QUEUE_STATS_LEN 0
  88. #define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
  89. #define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN + E1000_QUEUE_STATS_LEN)
  90. static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
  91. "Register test (offline)", "Eeprom test (offline)",
  92. "Interrupt test (offline)", "Loopback test (offline)",
  93. "Link test (on/offline)"
  94. };
  95. #define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
  96. static int e1000_get_settings(struct net_device *netdev,
  97. struct ethtool_cmd *ecmd)
  98. {
  99. struct e1000_adapter *adapter = netdev_priv(netdev);
  100. struct e1000_hw *hw = &adapter->hw;
  101. if (hw->media_type == e1000_media_type_copper) {
  102. ecmd->supported = (SUPPORTED_10baseT_Half |
  103. SUPPORTED_10baseT_Full |
  104. SUPPORTED_100baseT_Half |
  105. SUPPORTED_100baseT_Full |
  106. SUPPORTED_1000baseT_Full|
  107. SUPPORTED_Autoneg |
  108. SUPPORTED_TP);
  109. ecmd->advertising = ADVERTISED_TP;
  110. if (hw->autoneg == 1) {
  111. ecmd->advertising |= ADVERTISED_Autoneg;
  112. /* the e1000 autoneg seems to match ethtool nicely */
  113. ecmd->advertising |= hw->autoneg_advertised;
  114. }
  115. ecmd->port = PORT_TP;
  116. ecmd->phy_address = hw->phy_addr;
  117. if (hw->mac_type == e1000_82543)
  118. ecmd->transceiver = XCVR_EXTERNAL;
  119. else
  120. ecmd->transceiver = XCVR_INTERNAL;
  121. } else {
  122. ecmd->supported = (SUPPORTED_1000baseT_Full |
  123. SUPPORTED_FIBRE |
  124. SUPPORTED_Autoneg);
  125. ecmd->advertising = (ADVERTISED_1000baseT_Full |
  126. ADVERTISED_FIBRE |
  127. ADVERTISED_Autoneg);
  128. ecmd->port = PORT_FIBRE;
  129. if (hw->mac_type >= e1000_82545)
  130. ecmd->transceiver = XCVR_INTERNAL;
  131. else
  132. ecmd->transceiver = XCVR_EXTERNAL;
  133. }
  134. if (er32(STATUS) & E1000_STATUS_LU) {
  135. e1000_get_speed_and_duplex(hw, &adapter->link_speed,
  136. &adapter->link_duplex);
  137. ethtool_cmd_speed_set(ecmd, adapter->link_speed);
  138. /* unfortunately FULL_DUPLEX != DUPLEX_FULL
  139. * and HALF_DUPLEX != DUPLEX_HALF
  140. */
  141. if (adapter->link_duplex == FULL_DUPLEX)
  142. ecmd->duplex = DUPLEX_FULL;
  143. else
  144. ecmd->duplex = DUPLEX_HALF;
  145. } else {
  146. ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
  147. ecmd->duplex = DUPLEX_UNKNOWN;
  148. }
  149. ecmd->autoneg = ((hw->media_type == e1000_media_type_fiber) ||
  150. hw->autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
  151. /* MDI-X => 1; MDI => 0 */
  152. if ((hw->media_type == e1000_media_type_copper) &&
  153. netif_carrier_ok(netdev))
  154. ecmd->eth_tp_mdix = (!!adapter->phy_info.mdix_mode ?
  155. ETH_TP_MDI_X : ETH_TP_MDI);
  156. else
  157. ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID;
  158. if (hw->mdix == AUTO_ALL_MODES)
  159. ecmd->eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO;
  160. else
  161. ecmd->eth_tp_mdix_ctrl = hw->mdix;
  162. return 0;
  163. }
  164. static int e1000_set_settings(struct net_device *netdev,
  165. struct ethtool_cmd *ecmd)
  166. {
  167. struct e1000_adapter *adapter = netdev_priv(netdev);
  168. struct e1000_hw *hw = &adapter->hw;
  169. /* MDI setting is only allowed when autoneg enabled because
  170. * some hardware doesn't allow MDI setting when speed or
  171. * duplex is forced.
  172. */
  173. if (ecmd->eth_tp_mdix_ctrl) {
  174. if (hw->media_type != e1000_media_type_copper)
  175. return -EOPNOTSUPP;
  176. if ((ecmd->eth_tp_mdix_ctrl != ETH_TP_MDI_AUTO) &&
  177. (ecmd->autoneg != AUTONEG_ENABLE)) {
  178. e_err(drv, "forcing MDI/MDI-X state is not supported when link speed and/or duplex are forced\n");
  179. return -EINVAL;
  180. }
  181. }
  182. while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
  183. msleep(1);
  184. if (ecmd->autoneg == AUTONEG_ENABLE) {
  185. hw->autoneg = 1;
  186. if (hw->media_type == e1000_media_type_fiber)
  187. hw->autoneg_advertised = ADVERTISED_1000baseT_Full |
  188. ADVERTISED_FIBRE |
  189. ADVERTISED_Autoneg;
  190. else
  191. hw->autoneg_advertised = ecmd->advertising |
  192. ADVERTISED_TP |
  193. ADVERTISED_Autoneg;
  194. ecmd->advertising = hw->autoneg_advertised;
  195. } else {
  196. u32 speed = ethtool_cmd_speed(ecmd);
  197. /* calling this overrides forced MDI setting */
  198. if (e1000_set_spd_dplx(adapter, speed, ecmd->duplex)) {
  199. clear_bit(__E1000_RESETTING, &adapter->flags);
  200. return -EINVAL;
  201. }
  202. }
  203. /* MDI-X => 2; MDI => 1; Auto => 3 */
  204. if (ecmd->eth_tp_mdix_ctrl) {
  205. if (ecmd->eth_tp_mdix_ctrl == ETH_TP_MDI_AUTO)
  206. hw->mdix = AUTO_ALL_MODES;
  207. else
  208. hw->mdix = ecmd->eth_tp_mdix_ctrl;
  209. }
  210. /* reset the link */
  211. if (netif_running(adapter->netdev)) {
  212. e1000_down(adapter);
  213. e1000_up(adapter);
  214. } else {
  215. e1000_reset(adapter);
  216. }
  217. clear_bit(__E1000_RESETTING, &adapter->flags);
  218. return 0;
  219. }
  220. static u32 e1000_get_link(struct net_device *netdev)
  221. {
  222. struct e1000_adapter *adapter = netdev_priv(netdev);
  223. /* If the link is not reported up to netdev, interrupts are disabled,
  224. * and so the physical link state may have changed since we last
  225. * looked. Set get_link_status to make sure that the true link
  226. * state is interrogated, rather than pulling a cached and possibly
  227. * stale link state from the driver.
  228. */
  229. if (!netif_carrier_ok(netdev))
  230. adapter->hw.get_link_status = 1;
  231. return e1000_has_link(adapter);
  232. }
  233. static void e1000_get_pauseparam(struct net_device *netdev,
  234. struct ethtool_pauseparam *pause)
  235. {
  236. struct e1000_adapter *adapter = netdev_priv(netdev);
  237. struct e1000_hw *hw = &adapter->hw;
  238. pause->autoneg =
  239. (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
  240. if (hw->fc == E1000_FC_RX_PAUSE) {
  241. pause->rx_pause = 1;
  242. } else if (hw->fc == E1000_FC_TX_PAUSE) {
  243. pause->tx_pause = 1;
  244. } else if (hw->fc == E1000_FC_FULL) {
  245. pause->rx_pause = 1;
  246. pause->tx_pause = 1;
  247. }
  248. }
  249. static int e1000_set_pauseparam(struct net_device *netdev,
  250. struct ethtool_pauseparam *pause)
  251. {
  252. struct e1000_adapter *adapter = netdev_priv(netdev);
  253. struct e1000_hw *hw = &adapter->hw;
  254. int retval = 0;
  255. adapter->fc_autoneg = pause->autoneg;
  256. while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
  257. msleep(1);
  258. if (pause->rx_pause && pause->tx_pause)
  259. hw->fc = E1000_FC_FULL;
  260. else if (pause->rx_pause && !pause->tx_pause)
  261. hw->fc = E1000_FC_RX_PAUSE;
  262. else if (!pause->rx_pause && pause->tx_pause)
  263. hw->fc = E1000_FC_TX_PAUSE;
  264. else if (!pause->rx_pause && !pause->tx_pause)
  265. hw->fc = E1000_FC_NONE;
  266. hw->original_fc = hw->fc;
  267. if (adapter->fc_autoneg == AUTONEG_ENABLE) {
  268. if (netif_running(adapter->netdev)) {
  269. e1000_down(adapter);
  270. e1000_up(adapter);
  271. } else {
  272. e1000_reset(adapter);
  273. }
  274. } else
  275. retval = ((hw->media_type == e1000_media_type_fiber) ?
  276. e1000_setup_link(hw) : e1000_force_mac_fc(hw));
  277. clear_bit(__E1000_RESETTING, &adapter->flags);
  278. return retval;
  279. }
  280. static u32 e1000_get_msglevel(struct net_device *netdev)
  281. {
  282. struct e1000_adapter *adapter = netdev_priv(netdev);
  283. return adapter->msg_enable;
  284. }
  285. static void e1000_set_msglevel(struct net_device *netdev, u32 data)
  286. {
  287. struct e1000_adapter *adapter = netdev_priv(netdev);
  288. adapter->msg_enable = data;
  289. }
  290. static int e1000_get_regs_len(struct net_device *netdev)
  291. {
  292. #define E1000_REGS_LEN 32
  293. return E1000_REGS_LEN * sizeof(u32);
  294. }
  295. static void e1000_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
  296. void *p)
  297. {
  298. struct e1000_adapter *adapter = netdev_priv(netdev);
  299. struct e1000_hw *hw = &adapter->hw;
  300. u32 *regs_buff = p;
  301. u16 phy_data;
  302. memset(p, 0, E1000_REGS_LEN * sizeof(u32));
  303. regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
  304. regs_buff[0] = er32(CTRL);
  305. regs_buff[1] = er32(STATUS);
  306. regs_buff[2] = er32(RCTL);
  307. regs_buff[3] = er32(RDLEN);
  308. regs_buff[4] = er32(RDH);
  309. regs_buff[5] = er32(RDT);
  310. regs_buff[6] = er32(RDTR);
  311. regs_buff[7] = er32(TCTL);
  312. regs_buff[8] = er32(TDLEN);
  313. regs_buff[9] = er32(TDH);
  314. regs_buff[10] = er32(TDT);
  315. regs_buff[11] = er32(TIDV);
  316. regs_buff[12] = hw->phy_type; /* PHY type (IGP=1, M88=0) */
  317. if (hw->phy_type == e1000_phy_igp) {
  318. e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
  319. IGP01E1000_PHY_AGC_A);
  320. e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_A &
  321. IGP01E1000_PHY_PAGE_SELECT, &phy_data);
  322. regs_buff[13] = (u32)phy_data; /* cable length */
  323. e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
  324. IGP01E1000_PHY_AGC_B);
  325. e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_B &
  326. IGP01E1000_PHY_PAGE_SELECT, &phy_data);
  327. regs_buff[14] = (u32)phy_data; /* cable length */
  328. e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
  329. IGP01E1000_PHY_AGC_C);
  330. e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_C &
  331. IGP01E1000_PHY_PAGE_SELECT, &phy_data);
  332. regs_buff[15] = (u32)phy_data; /* cable length */
  333. e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
  334. IGP01E1000_PHY_AGC_D);
  335. e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_D &
  336. IGP01E1000_PHY_PAGE_SELECT, &phy_data);
  337. regs_buff[16] = (u32)phy_data; /* cable length */
  338. regs_buff[17] = 0; /* extended 10bt distance (not needed) */
  339. e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
  340. e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS &
  341. IGP01E1000_PHY_PAGE_SELECT, &phy_data);
  342. regs_buff[18] = (u32)phy_data; /* cable polarity */
  343. e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
  344. IGP01E1000_PHY_PCS_INIT_REG);
  345. e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG &
  346. IGP01E1000_PHY_PAGE_SELECT, &phy_data);
  347. regs_buff[19] = (u32)phy_data; /* cable polarity */
  348. regs_buff[20] = 0; /* polarity correction enabled (always) */
  349. regs_buff[22] = 0; /* phy receive errors (unavailable) */
  350. regs_buff[23] = regs_buff[18]; /* mdix mode */
  351. e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
  352. } else {
  353. e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
  354. regs_buff[13] = (u32)phy_data; /* cable length */
  355. regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
  356. regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
  357. regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
  358. e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  359. regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
  360. regs_buff[18] = regs_buff[13]; /* cable polarity */
  361. regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
  362. regs_buff[20] = regs_buff[17]; /* polarity correction */
  363. /* phy receive errors */
  364. regs_buff[22] = adapter->phy_stats.receive_errors;
  365. regs_buff[23] = regs_buff[13]; /* mdix mode */
  366. }
  367. regs_buff[21] = adapter->phy_stats.idle_errors; /* phy idle errors */
  368. e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
  369. regs_buff[24] = (u32)phy_data; /* phy local receiver status */
  370. regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
  371. if (hw->mac_type >= e1000_82540 &&
  372. hw->media_type == e1000_media_type_copper) {
  373. regs_buff[26] = er32(MANC);
  374. }
  375. }
  376. static int e1000_get_eeprom_len(struct net_device *netdev)
  377. {
  378. struct e1000_adapter *adapter = netdev_priv(netdev);
  379. struct e1000_hw *hw = &adapter->hw;
  380. return hw->eeprom.word_size * 2;
  381. }
  382. static int e1000_get_eeprom(struct net_device *netdev,
  383. struct ethtool_eeprom *eeprom, u8 *bytes)
  384. {
  385. struct e1000_adapter *adapter = netdev_priv(netdev);
  386. struct e1000_hw *hw = &adapter->hw;
  387. u16 *eeprom_buff;
  388. int first_word, last_word;
  389. int ret_val = 0;
  390. u16 i;
  391. if (eeprom->len == 0)
  392. return -EINVAL;
  393. eeprom->magic = hw->vendor_id | (hw->device_id << 16);
  394. first_word = eeprom->offset >> 1;
  395. last_word = (eeprom->offset + eeprom->len - 1) >> 1;
  396. eeprom_buff = kmalloc(sizeof(u16) *
  397. (last_word - first_word + 1), GFP_KERNEL);
  398. if (!eeprom_buff)
  399. return -ENOMEM;
  400. if (hw->eeprom.type == e1000_eeprom_spi)
  401. ret_val = e1000_read_eeprom(hw, first_word,
  402. last_word - first_word + 1,
  403. eeprom_buff);
  404. else {
  405. for (i = 0; i < last_word - first_word + 1; i++) {
  406. ret_val = e1000_read_eeprom(hw, first_word + i, 1,
  407. &eeprom_buff[i]);
  408. if (ret_val)
  409. break;
  410. }
  411. }
  412. /* Device's eeprom is always little-endian, word addressable */
  413. for (i = 0; i < last_word - first_word + 1; i++)
  414. le16_to_cpus(&eeprom_buff[i]);
  415. memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1),
  416. eeprom->len);
  417. kfree(eeprom_buff);
  418. return ret_val;
  419. }
  420. static int e1000_set_eeprom(struct net_device *netdev,
  421. struct ethtool_eeprom *eeprom, u8 *bytes)
  422. {
  423. struct e1000_adapter *adapter = netdev_priv(netdev);
  424. struct e1000_hw *hw = &adapter->hw;
  425. u16 *eeprom_buff;
  426. void *ptr;
  427. int max_len, first_word, last_word, ret_val = 0;
  428. u16 i;
  429. if (eeprom->len == 0)
  430. return -EOPNOTSUPP;
  431. if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
  432. return -EFAULT;
  433. max_len = hw->eeprom.word_size * 2;
  434. first_word = eeprom->offset >> 1;
  435. last_word = (eeprom->offset + eeprom->len - 1) >> 1;
  436. eeprom_buff = kmalloc(max_len, GFP_KERNEL);
  437. if (!eeprom_buff)
  438. return -ENOMEM;
  439. ptr = (void *)eeprom_buff;
  440. if (eeprom->offset & 1) {
  441. /* need read/modify/write of first changed EEPROM word
  442. * only the second byte of the word is being modified
  443. */
  444. ret_val = e1000_read_eeprom(hw, first_word, 1,
  445. &eeprom_buff[0]);
  446. ptr++;
  447. }
  448. if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0)) {
  449. /* need read/modify/write of last changed EEPROM word
  450. * only the first byte of the word is being modified
  451. */
  452. ret_val = e1000_read_eeprom(hw, last_word, 1,
  453. &eeprom_buff[last_word - first_word]);
  454. }
  455. /* Device's eeprom is always little-endian, word addressable */
  456. for (i = 0; i < last_word - first_word + 1; i++)
  457. le16_to_cpus(&eeprom_buff[i]);
  458. memcpy(ptr, bytes, eeprom->len);
  459. for (i = 0; i < last_word - first_word + 1; i++)
  460. eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
  461. ret_val = e1000_write_eeprom(hw, first_word,
  462. last_word - first_word + 1, eeprom_buff);
  463. /* Update the checksum over the first part of the EEPROM if needed */
  464. if ((ret_val == 0) && (first_word <= EEPROM_CHECKSUM_REG))
  465. e1000_update_eeprom_checksum(hw);
  466. kfree(eeprom_buff);
  467. return ret_val;
  468. }
  469. static void e1000_get_drvinfo(struct net_device *netdev,
  470. struct ethtool_drvinfo *drvinfo)
  471. {
  472. struct e1000_adapter *adapter = netdev_priv(netdev);
  473. strlcpy(drvinfo->driver, e1000_driver_name,
  474. sizeof(drvinfo->driver));
  475. strlcpy(drvinfo->version, e1000_driver_version,
  476. sizeof(drvinfo->version));
  477. strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
  478. sizeof(drvinfo->bus_info));
  479. drvinfo->regdump_len = e1000_get_regs_len(netdev);
  480. drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
  481. }
  482. static void e1000_get_ringparam(struct net_device *netdev,
  483. struct ethtool_ringparam *ring)
  484. {
  485. struct e1000_adapter *adapter = netdev_priv(netdev);
  486. struct e1000_hw *hw = &adapter->hw;
  487. e1000_mac_type mac_type = hw->mac_type;
  488. struct e1000_tx_ring *txdr = adapter->tx_ring;
  489. struct e1000_rx_ring *rxdr = adapter->rx_ring;
  490. ring->rx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_RXD :
  491. E1000_MAX_82544_RXD;
  492. ring->tx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_TXD :
  493. E1000_MAX_82544_TXD;
  494. ring->rx_pending = rxdr->count;
  495. ring->tx_pending = txdr->count;
  496. }
  497. static int e1000_set_ringparam(struct net_device *netdev,
  498. struct ethtool_ringparam *ring)
  499. {
  500. struct e1000_adapter *adapter = netdev_priv(netdev);
  501. struct e1000_hw *hw = &adapter->hw;
  502. e1000_mac_type mac_type = hw->mac_type;
  503. struct e1000_tx_ring *txdr, *tx_old;
  504. struct e1000_rx_ring *rxdr, *rx_old;
  505. int i, err;
  506. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  507. return -EINVAL;
  508. while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
  509. msleep(1);
  510. if (netif_running(adapter->netdev))
  511. e1000_down(adapter);
  512. tx_old = adapter->tx_ring;
  513. rx_old = adapter->rx_ring;
  514. err = -ENOMEM;
  515. txdr = kcalloc(adapter->num_tx_queues, sizeof(struct e1000_tx_ring),
  516. GFP_KERNEL);
  517. if (!txdr)
  518. goto err_alloc_tx;
  519. rxdr = kcalloc(adapter->num_rx_queues, sizeof(struct e1000_rx_ring),
  520. GFP_KERNEL);
  521. if (!rxdr)
  522. goto err_alloc_rx;
  523. adapter->tx_ring = txdr;
  524. adapter->rx_ring = rxdr;
  525. rxdr->count = max(ring->rx_pending, (u32)E1000_MIN_RXD);
  526. rxdr->count = min(rxdr->count, (u32)(mac_type < e1000_82544 ?
  527. E1000_MAX_RXD : E1000_MAX_82544_RXD));
  528. rxdr->count = ALIGN(rxdr->count, REQ_RX_DESCRIPTOR_MULTIPLE);
  529. txdr->count = max(ring->tx_pending, (u32)E1000_MIN_TXD);
  530. txdr->count = min(txdr->count, (u32)(mac_type < e1000_82544 ?
  531. E1000_MAX_TXD : E1000_MAX_82544_TXD));
  532. txdr->count = ALIGN(txdr->count, REQ_TX_DESCRIPTOR_MULTIPLE);
  533. for (i = 0; i < adapter->num_tx_queues; i++)
  534. txdr[i].count = txdr->count;
  535. for (i = 0; i < adapter->num_rx_queues; i++)
  536. rxdr[i].count = rxdr->count;
  537. if (netif_running(adapter->netdev)) {
  538. /* Try to get new resources before deleting old */
  539. err = e1000_setup_all_rx_resources(adapter);
  540. if (err)
  541. goto err_setup_rx;
  542. err = e1000_setup_all_tx_resources(adapter);
  543. if (err)
  544. goto err_setup_tx;
  545. /* save the new, restore the old in order to free it,
  546. * then restore the new back again
  547. */
  548. adapter->rx_ring = rx_old;
  549. adapter->tx_ring = tx_old;
  550. e1000_free_all_rx_resources(adapter);
  551. e1000_free_all_tx_resources(adapter);
  552. kfree(tx_old);
  553. kfree(rx_old);
  554. adapter->rx_ring = rxdr;
  555. adapter->tx_ring = txdr;
  556. err = e1000_up(adapter);
  557. if (err)
  558. goto err_setup;
  559. }
  560. clear_bit(__E1000_RESETTING, &adapter->flags);
  561. return 0;
  562. err_setup_tx:
  563. e1000_free_all_rx_resources(adapter);
  564. err_setup_rx:
  565. adapter->rx_ring = rx_old;
  566. adapter->tx_ring = tx_old;
  567. kfree(rxdr);
  568. err_alloc_rx:
  569. kfree(txdr);
  570. err_alloc_tx:
  571. e1000_up(adapter);
  572. err_setup:
  573. clear_bit(__E1000_RESETTING, &adapter->flags);
  574. return err;
  575. }
  576. static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data, int reg,
  577. u32 mask, u32 write)
  578. {
  579. struct e1000_hw *hw = &adapter->hw;
  580. static const u32 test[] = {
  581. 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF
  582. };
  583. u8 __iomem *address = hw->hw_addr + reg;
  584. u32 read;
  585. int i;
  586. for (i = 0; i < ARRAY_SIZE(test); i++) {
  587. writel(write & test[i], address);
  588. read = readl(address);
  589. if (read != (write & test[i] & mask)) {
  590. e_err(drv, "pattern test reg %04X failed: "
  591. "got 0x%08X expected 0x%08X\n",
  592. reg, read, (write & test[i] & mask));
  593. *data = reg;
  594. return true;
  595. }
  596. }
  597. return false;
  598. }
  599. static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data, int reg,
  600. u32 mask, u32 write)
  601. {
  602. struct e1000_hw *hw = &adapter->hw;
  603. u8 __iomem *address = hw->hw_addr + reg;
  604. u32 read;
  605. writel(write & mask, address);
  606. read = readl(address);
  607. if ((read & mask) != (write & mask)) {
  608. e_err(drv, "set/check reg %04X test failed: "
  609. "got 0x%08X expected 0x%08X\n",
  610. reg, (read & mask), (write & mask));
  611. *data = reg;
  612. return true;
  613. }
  614. return false;
  615. }
  616. #define REG_PATTERN_TEST(reg, mask, write) \
  617. do { \
  618. if (reg_pattern_test(adapter, data, \
  619. (hw->mac_type >= e1000_82543) \
  620. ? E1000_##reg : E1000_82542_##reg, \
  621. mask, write)) \
  622. return 1; \
  623. } while (0)
  624. #define REG_SET_AND_CHECK(reg, mask, write) \
  625. do { \
  626. if (reg_set_and_check(adapter, data, \
  627. (hw->mac_type >= e1000_82543) \
  628. ? E1000_##reg : E1000_82542_##reg, \
  629. mask, write)) \
  630. return 1; \
  631. } while (0)
  632. static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
  633. {
  634. u32 value, before, after;
  635. u32 i, toggle;
  636. struct e1000_hw *hw = &adapter->hw;
  637. /* The status register is Read Only, so a write should fail.
  638. * Some bits that get toggled are ignored.
  639. */
  640. /* there are several bits on newer hardware that are r/w */
  641. toggle = 0xFFFFF833;
  642. before = er32(STATUS);
  643. value = (er32(STATUS) & toggle);
  644. ew32(STATUS, toggle);
  645. after = er32(STATUS) & toggle;
  646. if (value != after) {
  647. e_err(drv, "failed STATUS register test got: "
  648. "0x%08X expected: 0x%08X\n", after, value);
  649. *data = 1;
  650. return 1;
  651. }
  652. /* restore previous status */
  653. ew32(STATUS, before);
  654. REG_PATTERN_TEST(FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
  655. REG_PATTERN_TEST(FCAH, 0x0000FFFF, 0xFFFFFFFF);
  656. REG_PATTERN_TEST(FCT, 0x0000FFFF, 0xFFFFFFFF);
  657. REG_PATTERN_TEST(VET, 0x0000FFFF, 0xFFFFFFFF);
  658. REG_PATTERN_TEST(RDTR, 0x0000FFFF, 0xFFFFFFFF);
  659. REG_PATTERN_TEST(RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
  660. REG_PATTERN_TEST(RDLEN, 0x000FFF80, 0x000FFFFF);
  661. REG_PATTERN_TEST(RDH, 0x0000FFFF, 0x0000FFFF);
  662. REG_PATTERN_TEST(RDT, 0x0000FFFF, 0x0000FFFF);
  663. REG_PATTERN_TEST(FCRTH, 0x0000FFF8, 0x0000FFF8);
  664. REG_PATTERN_TEST(FCTTV, 0x0000FFFF, 0x0000FFFF);
  665. REG_PATTERN_TEST(TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
  666. REG_PATTERN_TEST(TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
  667. REG_PATTERN_TEST(TDLEN, 0x000FFF80, 0x000FFFFF);
  668. REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x00000000);
  669. before = 0x06DFB3FE;
  670. REG_SET_AND_CHECK(RCTL, before, 0x003FFFFB);
  671. REG_SET_AND_CHECK(TCTL, 0xFFFFFFFF, 0x00000000);
  672. if (hw->mac_type >= e1000_82543) {
  673. REG_SET_AND_CHECK(RCTL, before, 0xFFFFFFFF);
  674. REG_PATTERN_TEST(RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
  675. REG_PATTERN_TEST(TXCW, 0xC000FFFF, 0x0000FFFF);
  676. REG_PATTERN_TEST(TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
  677. REG_PATTERN_TEST(TIDV, 0x0000FFFF, 0x0000FFFF);
  678. value = E1000_RAR_ENTRIES;
  679. for (i = 0; i < value; i++) {
  680. REG_PATTERN_TEST(RA + (((i << 1) + 1) << 2),
  681. 0x8003FFFF, 0xFFFFFFFF);
  682. }
  683. } else {
  684. REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x01FFFFFF);
  685. REG_PATTERN_TEST(RDBAL, 0xFFFFF000, 0xFFFFFFFF);
  686. REG_PATTERN_TEST(TXCW, 0x0000FFFF, 0x0000FFFF);
  687. REG_PATTERN_TEST(TDBAL, 0xFFFFF000, 0xFFFFFFFF);
  688. }
  689. value = E1000_MC_TBL_SIZE;
  690. for (i = 0; i < value; i++)
  691. REG_PATTERN_TEST(MTA + (i << 2), 0xFFFFFFFF, 0xFFFFFFFF);
  692. *data = 0;
  693. return 0;
  694. }
  695. static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
  696. {
  697. struct e1000_hw *hw = &adapter->hw;
  698. u16 temp;
  699. u16 checksum = 0;
  700. u16 i;
  701. *data = 0;
  702. /* Read and add up the contents of the EEPROM */
  703. for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
  704. if ((e1000_read_eeprom(hw, i, 1, &temp)) < 0) {
  705. *data = 1;
  706. break;
  707. }
  708. checksum += temp;
  709. }
  710. /* If Checksum is not Correct return error else test passed */
  711. if ((checksum != (u16)EEPROM_SUM) && !(*data))
  712. *data = 2;
  713. return *data;
  714. }
  715. static irqreturn_t e1000_test_intr(int irq, void *data)
  716. {
  717. struct net_device *netdev = (struct net_device *)data;
  718. struct e1000_adapter *adapter = netdev_priv(netdev);
  719. struct e1000_hw *hw = &adapter->hw;
  720. adapter->test_icr |= er32(ICR);
  721. return IRQ_HANDLED;
  722. }
  723. static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
  724. {
  725. struct net_device *netdev = adapter->netdev;
  726. u32 mask, i = 0;
  727. bool shared_int = true;
  728. u32 irq = adapter->pdev->irq;
  729. struct e1000_hw *hw = &adapter->hw;
  730. *data = 0;
  731. /* NOTE: we don't test MSI interrupts here, yet
  732. * Hook up test interrupt handler just for this test
  733. */
  734. if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
  735. netdev))
  736. shared_int = false;
  737. else if (request_irq(irq, e1000_test_intr, IRQF_SHARED,
  738. netdev->name, netdev)) {
  739. *data = 1;
  740. return -1;
  741. }
  742. e_info(hw, "testing %s interrupt\n", (shared_int ?
  743. "shared" : "unshared"));
  744. /* Disable all the interrupts */
  745. ew32(IMC, 0xFFFFFFFF);
  746. E1000_WRITE_FLUSH();
  747. msleep(10);
  748. /* Test each interrupt */
  749. for (; i < 10; i++) {
  750. /* Interrupt to test */
  751. mask = 1 << i;
  752. if (!shared_int) {
  753. /* Disable the interrupt to be reported in
  754. * the cause register and then force the same
  755. * interrupt and see if one gets posted. If
  756. * an interrupt was posted to the bus, the
  757. * test failed.
  758. */
  759. adapter->test_icr = 0;
  760. ew32(IMC, mask);
  761. ew32(ICS, mask);
  762. E1000_WRITE_FLUSH();
  763. msleep(10);
  764. if (adapter->test_icr & mask) {
  765. *data = 3;
  766. break;
  767. }
  768. }
  769. /* Enable the interrupt to be reported in
  770. * the cause register and then force the same
  771. * interrupt and see if one gets posted. If
  772. * an interrupt was not posted to the bus, the
  773. * test failed.
  774. */
  775. adapter->test_icr = 0;
  776. ew32(IMS, mask);
  777. ew32(ICS, mask);
  778. E1000_WRITE_FLUSH();
  779. msleep(10);
  780. if (!(adapter->test_icr & mask)) {
  781. *data = 4;
  782. break;
  783. }
  784. if (!shared_int) {
  785. /* Disable the other interrupts to be reported in
  786. * the cause register and then force the other
  787. * interrupts and see if any get posted. If
  788. * an interrupt was posted to the bus, the
  789. * test failed.
  790. */
  791. adapter->test_icr = 0;
  792. ew32(IMC, ~mask & 0x00007FFF);
  793. ew32(ICS, ~mask & 0x00007FFF);
  794. E1000_WRITE_FLUSH();
  795. msleep(10);
  796. if (adapter->test_icr) {
  797. *data = 5;
  798. break;
  799. }
  800. }
  801. }
  802. /* Disable all the interrupts */
  803. ew32(IMC, 0xFFFFFFFF);
  804. E1000_WRITE_FLUSH();
  805. msleep(10);
  806. /* Unhook test interrupt handler */
  807. free_irq(irq, netdev);
  808. return *data;
  809. }
  810. static void e1000_free_desc_rings(struct e1000_adapter *adapter)
  811. {
  812. struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
  813. struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
  814. struct pci_dev *pdev = adapter->pdev;
  815. int i;
  816. if (txdr->desc && txdr->buffer_info) {
  817. for (i = 0; i < txdr->count; i++) {
  818. if (txdr->buffer_info[i].dma)
  819. dma_unmap_single(&pdev->dev,
  820. txdr->buffer_info[i].dma,
  821. txdr->buffer_info[i].length,
  822. DMA_TO_DEVICE);
  823. if (txdr->buffer_info[i].skb)
  824. dev_kfree_skb(txdr->buffer_info[i].skb);
  825. }
  826. }
  827. if (rxdr->desc && rxdr->buffer_info) {
  828. for (i = 0; i < rxdr->count; i++) {
  829. if (rxdr->buffer_info[i].dma)
  830. dma_unmap_single(&pdev->dev,
  831. rxdr->buffer_info[i].dma,
  832. E1000_RXBUFFER_2048,
  833. DMA_FROM_DEVICE);
  834. kfree(rxdr->buffer_info[i].rxbuf.data);
  835. }
  836. }
  837. if (txdr->desc) {
  838. dma_free_coherent(&pdev->dev, txdr->size, txdr->desc,
  839. txdr->dma);
  840. txdr->desc = NULL;
  841. }
  842. if (rxdr->desc) {
  843. dma_free_coherent(&pdev->dev, rxdr->size, rxdr->desc,
  844. rxdr->dma);
  845. rxdr->desc = NULL;
  846. }
  847. kfree(txdr->buffer_info);
  848. txdr->buffer_info = NULL;
  849. kfree(rxdr->buffer_info);
  850. rxdr->buffer_info = NULL;
  851. }
  852. static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
  853. {
  854. struct e1000_hw *hw = &adapter->hw;
  855. struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
  856. struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
  857. struct pci_dev *pdev = adapter->pdev;
  858. u32 rctl;
  859. int i, ret_val;
  860. /* Setup Tx descriptor ring and Tx buffers */
  861. if (!txdr->count)
  862. txdr->count = E1000_DEFAULT_TXD;
  863. txdr->buffer_info = kcalloc(txdr->count, sizeof(struct e1000_tx_buffer),
  864. GFP_KERNEL);
  865. if (!txdr->buffer_info) {
  866. ret_val = 1;
  867. goto err_nomem;
  868. }
  869. txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
  870. txdr->size = ALIGN(txdr->size, 4096);
  871. txdr->desc = dma_zalloc_coherent(&pdev->dev, txdr->size, &txdr->dma,
  872. GFP_KERNEL);
  873. if (!txdr->desc) {
  874. ret_val = 2;
  875. goto err_nomem;
  876. }
  877. txdr->next_to_use = txdr->next_to_clean = 0;
  878. ew32(TDBAL, ((u64)txdr->dma & 0x00000000FFFFFFFF));
  879. ew32(TDBAH, ((u64)txdr->dma >> 32));
  880. ew32(TDLEN, txdr->count * sizeof(struct e1000_tx_desc));
  881. ew32(TDH, 0);
  882. ew32(TDT, 0);
  883. ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN |
  884. E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
  885. E1000_FDX_COLLISION_DISTANCE << E1000_COLD_SHIFT);
  886. for (i = 0; i < txdr->count; i++) {
  887. struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*txdr, i);
  888. struct sk_buff *skb;
  889. unsigned int size = 1024;
  890. skb = alloc_skb(size, GFP_KERNEL);
  891. if (!skb) {
  892. ret_val = 3;
  893. goto err_nomem;
  894. }
  895. skb_put(skb, size);
  896. txdr->buffer_info[i].skb = skb;
  897. txdr->buffer_info[i].length = skb->len;
  898. txdr->buffer_info[i].dma =
  899. dma_map_single(&pdev->dev, skb->data, skb->len,
  900. DMA_TO_DEVICE);
  901. if (dma_mapping_error(&pdev->dev, txdr->buffer_info[i].dma)) {
  902. ret_val = 4;
  903. goto err_nomem;
  904. }
  905. tx_desc->buffer_addr = cpu_to_le64(txdr->buffer_info[i].dma);
  906. tx_desc->lower.data = cpu_to_le32(skb->len);
  907. tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
  908. E1000_TXD_CMD_IFCS |
  909. E1000_TXD_CMD_RPS);
  910. tx_desc->upper.data = 0;
  911. }
  912. /* Setup Rx descriptor ring and Rx buffers */
  913. if (!rxdr->count)
  914. rxdr->count = E1000_DEFAULT_RXD;
  915. rxdr->buffer_info = kcalloc(rxdr->count, sizeof(struct e1000_rx_buffer),
  916. GFP_KERNEL);
  917. if (!rxdr->buffer_info) {
  918. ret_val = 5;
  919. goto err_nomem;
  920. }
  921. rxdr->size = rxdr->count * sizeof(struct e1000_rx_desc);
  922. rxdr->desc = dma_zalloc_coherent(&pdev->dev, rxdr->size, &rxdr->dma,
  923. GFP_KERNEL);
  924. if (!rxdr->desc) {
  925. ret_val = 6;
  926. goto err_nomem;
  927. }
  928. rxdr->next_to_use = rxdr->next_to_clean = 0;
  929. rctl = er32(RCTL);
  930. ew32(RCTL, rctl & ~E1000_RCTL_EN);
  931. ew32(RDBAL, ((u64)rxdr->dma & 0xFFFFFFFF));
  932. ew32(RDBAH, ((u64)rxdr->dma >> 32));
  933. ew32(RDLEN, rxdr->size);
  934. ew32(RDH, 0);
  935. ew32(RDT, 0);
  936. rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
  937. E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
  938. (hw->mc_filter_type << E1000_RCTL_MO_SHIFT);
  939. ew32(RCTL, rctl);
  940. for (i = 0; i < rxdr->count; i++) {
  941. struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rxdr, i);
  942. u8 *buf;
  943. buf = kzalloc(E1000_RXBUFFER_2048 + NET_SKB_PAD + NET_IP_ALIGN,
  944. GFP_KERNEL);
  945. if (!buf) {
  946. ret_val = 7;
  947. goto err_nomem;
  948. }
  949. rxdr->buffer_info[i].rxbuf.data = buf;
  950. rxdr->buffer_info[i].dma =
  951. dma_map_single(&pdev->dev,
  952. buf + NET_SKB_PAD + NET_IP_ALIGN,
  953. E1000_RXBUFFER_2048, DMA_FROM_DEVICE);
  954. if (dma_mapping_error(&pdev->dev, rxdr->buffer_info[i].dma)) {
  955. ret_val = 8;
  956. goto err_nomem;
  957. }
  958. rx_desc->buffer_addr = cpu_to_le64(rxdr->buffer_info[i].dma);
  959. }
  960. return 0;
  961. err_nomem:
  962. e1000_free_desc_rings(adapter);
  963. return ret_val;
  964. }
  965. static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
  966. {
  967. struct e1000_hw *hw = &adapter->hw;
  968. /* Write out to PHY registers 29 and 30 to disable the Receiver. */
  969. e1000_write_phy_reg(hw, 29, 0x001F);
  970. e1000_write_phy_reg(hw, 30, 0x8FFC);
  971. e1000_write_phy_reg(hw, 29, 0x001A);
  972. e1000_write_phy_reg(hw, 30, 0x8FF0);
  973. }
  974. static void e1000_phy_reset_clk_and_crs(struct e1000_adapter *adapter)
  975. {
  976. struct e1000_hw *hw = &adapter->hw;
  977. u16 phy_reg;
  978. /* Because we reset the PHY above, we need to re-force TX_CLK in the
  979. * Extended PHY Specific Control Register to 25MHz clock. This
  980. * value defaults back to a 2.5MHz clock when the PHY is reset.
  981. */
  982. e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg);
  983. phy_reg |= M88E1000_EPSCR_TX_CLK_25;
  984. e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_reg);
  985. /* In addition, because of the s/w reset above, we need to enable
  986. * CRS on TX. This must be set for both full and half duplex
  987. * operation.
  988. */
  989. e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_reg);
  990. phy_reg |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  991. e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_reg);
  992. }
  993. static int e1000_nonintegrated_phy_loopback(struct e1000_adapter *adapter)
  994. {
  995. struct e1000_hw *hw = &adapter->hw;
  996. u32 ctrl_reg;
  997. u16 phy_reg;
  998. /* Setup the Device Control Register for PHY loopback test. */
  999. ctrl_reg = er32(CTRL);
  1000. ctrl_reg |= (E1000_CTRL_ILOS | /* Invert Loss-Of-Signal */
  1001. E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
  1002. E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
  1003. E1000_CTRL_SPD_1000 | /* Force Speed to 1000 */
  1004. E1000_CTRL_FD); /* Force Duplex to FULL */
  1005. ew32(CTRL, ctrl_reg);
  1006. /* Read the PHY Specific Control Register (0x10) */
  1007. e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_reg);
  1008. /* Clear Auto-Crossover bits in PHY Specific Control Register
  1009. * (bits 6:5).
  1010. */
  1011. phy_reg &= ~M88E1000_PSCR_AUTO_X_MODE;
  1012. e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_reg);
  1013. /* Perform software reset on the PHY */
  1014. e1000_phy_reset(hw);
  1015. /* Have to setup TX_CLK and TX_CRS after software reset */
  1016. e1000_phy_reset_clk_and_crs(adapter);
  1017. e1000_write_phy_reg(hw, PHY_CTRL, 0x8100);
  1018. /* Wait for reset to complete. */
  1019. udelay(500);
  1020. /* Have to setup TX_CLK and TX_CRS after software reset */
  1021. e1000_phy_reset_clk_and_crs(adapter);
  1022. /* Write out to PHY registers 29 and 30 to disable the Receiver. */
  1023. e1000_phy_disable_receiver(adapter);
  1024. /* Set the loopback bit in the PHY control register. */
  1025. e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
  1026. phy_reg |= MII_CR_LOOPBACK;
  1027. e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
  1028. /* Setup TX_CLK and TX_CRS one more time. */
  1029. e1000_phy_reset_clk_and_crs(adapter);
  1030. /* Check Phy Configuration */
  1031. e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
  1032. if (phy_reg != 0x4100)
  1033. return 9;
  1034. e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg);
  1035. if (phy_reg != 0x0070)
  1036. return 10;
  1037. e1000_read_phy_reg(hw, 29, &phy_reg);
  1038. if (phy_reg != 0x001A)
  1039. return 11;
  1040. return 0;
  1041. }
  1042. static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
  1043. {
  1044. struct e1000_hw *hw = &adapter->hw;
  1045. u32 ctrl_reg = 0;
  1046. u32 stat_reg = 0;
  1047. hw->autoneg = false;
  1048. if (hw->phy_type == e1000_phy_m88) {
  1049. /* Auto-MDI/MDIX Off */
  1050. e1000_write_phy_reg(hw,
  1051. M88E1000_PHY_SPEC_CTRL, 0x0808);
  1052. /* reset to update Auto-MDI/MDIX */
  1053. e1000_write_phy_reg(hw, PHY_CTRL, 0x9140);
  1054. /* autoneg off */
  1055. e1000_write_phy_reg(hw, PHY_CTRL, 0x8140);
  1056. }
  1057. ctrl_reg = er32(CTRL);
  1058. /* force 1000, set loopback */
  1059. e1000_write_phy_reg(hw, PHY_CTRL, 0x4140);
  1060. /* Now set up the MAC to the same speed/duplex as the PHY. */
  1061. ctrl_reg = er32(CTRL);
  1062. ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
  1063. ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
  1064. E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
  1065. E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
  1066. E1000_CTRL_FD); /* Force Duplex to FULL */
  1067. if (hw->media_type == e1000_media_type_copper &&
  1068. hw->phy_type == e1000_phy_m88)
  1069. ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
  1070. else {
  1071. /* Set the ILOS bit on the fiber Nic is half
  1072. * duplex link is detected.
  1073. */
  1074. stat_reg = er32(STATUS);
  1075. if ((stat_reg & E1000_STATUS_FD) == 0)
  1076. ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
  1077. }
  1078. ew32(CTRL, ctrl_reg);
  1079. /* Disable the receiver on the PHY so when a cable is plugged in, the
  1080. * PHY does not begin to autoneg when a cable is reconnected to the NIC.
  1081. */
  1082. if (hw->phy_type == e1000_phy_m88)
  1083. e1000_phy_disable_receiver(adapter);
  1084. udelay(500);
  1085. return 0;
  1086. }
  1087. static int e1000_set_phy_loopback(struct e1000_adapter *adapter)
  1088. {
  1089. struct e1000_hw *hw = &adapter->hw;
  1090. u16 phy_reg = 0;
  1091. u16 count = 0;
  1092. switch (hw->mac_type) {
  1093. case e1000_82543:
  1094. if (hw->media_type == e1000_media_type_copper) {
  1095. /* Attempt to setup Loopback mode on Non-integrated PHY.
  1096. * Some PHY registers get corrupted at random, so
  1097. * attempt this 10 times.
  1098. */
  1099. while (e1000_nonintegrated_phy_loopback(adapter) &&
  1100. count++ < 10);
  1101. if (count < 11)
  1102. return 0;
  1103. }
  1104. break;
  1105. case e1000_82544:
  1106. case e1000_82540:
  1107. case e1000_82545:
  1108. case e1000_82545_rev_3:
  1109. case e1000_82546:
  1110. case e1000_82546_rev_3:
  1111. case e1000_82541:
  1112. case e1000_82541_rev_2:
  1113. case e1000_82547:
  1114. case e1000_82547_rev_2:
  1115. return e1000_integrated_phy_loopback(adapter);
  1116. default:
  1117. /* Default PHY loopback work is to read the MII
  1118. * control register and assert bit 14 (loopback mode).
  1119. */
  1120. e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
  1121. phy_reg |= MII_CR_LOOPBACK;
  1122. e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
  1123. return 0;
  1124. }
  1125. return 8;
  1126. }
  1127. static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
  1128. {
  1129. struct e1000_hw *hw = &adapter->hw;
  1130. u32 rctl;
  1131. if (hw->media_type == e1000_media_type_fiber ||
  1132. hw->media_type == e1000_media_type_internal_serdes) {
  1133. switch (hw->mac_type) {
  1134. case e1000_82545:
  1135. case e1000_82546:
  1136. case e1000_82545_rev_3:
  1137. case e1000_82546_rev_3:
  1138. return e1000_set_phy_loopback(adapter);
  1139. default:
  1140. rctl = er32(RCTL);
  1141. rctl |= E1000_RCTL_LBM_TCVR;
  1142. ew32(RCTL, rctl);
  1143. return 0;
  1144. }
  1145. } else if (hw->media_type == e1000_media_type_copper) {
  1146. return e1000_set_phy_loopback(adapter);
  1147. }
  1148. return 7;
  1149. }
  1150. static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
  1151. {
  1152. struct e1000_hw *hw = &adapter->hw;
  1153. u32 rctl;
  1154. u16 phy_reg;
  1155. rctl = er32(RCTL);
  1156. rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
  1157. ew32(RCTL, rctl);
  1158. switch (hw->mac_type) {
  1159. case e1000_82545:
  1160. case e1000_82546:
  1161. case e1000_82545_rev_3:
  1162. case e1000_82546_rev_3:
  1163. default:
  1164. hw->autoneg = true;
  1165. e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
  1166. if (phy_reg & MII_CR_LOOPBACK) {
  1167. phy_reg &= ~MII_CR_LOOPBACK;
  1168. e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
  1169. e1000_phy_reset(hw);
  1170. }
  1171. break;
  1172. }
  1173. }
  1174. static void e1000_create_lbtest_frame(struct sk_buff *skb,
  1175. unsigned int frame_size)
  1176. {
  1177. memset(skb->data, 0xFF, frame_size);
  1178. frame_size &= ~1;
  1179. memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
  1180. memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
  1181. memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
  1182. }
  1183. static int e1000_check_lbtest_frame(const unsigned char *data,
  1184. unsigned int frame_size)
  1185. {
  1186. frame_size &= ~1;
  1187. if (*(data + 3) == 0xFF) {
  1188. if ((*(data + frame_size / 2 + 10) == 0xBE) &&
  1189. (*(data + frame_size / 2 + 12) == 0xAF)) {
  1190. return 0;
  1191. }
  1192. }
  1193. return 13;
  1194. }
  1195. static int e1000_run_loopback_test(struct e1000_adapter *adapter)
  1196. {
  1197. struct e1000_hw *hw = &adapter->hw;
  1198. struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
  1199. struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
  1200. struct pci_dev *pdev = adapter->pdev;
  1201. int i, j, k, l, lc, good_cnt, ret_val = 0;
  1202. unsigned long time;
  1203. ew32(RDT, rxdr->count - 1);
  1204. /* Calculate the loop count based on the largest descriptor ring
  1205. * The idea is to wrap the largest ring a number of times using 64
  1206. * send/receive pairs during each loop
  1207. */
  1208. if (rxdr->count <= txdr->count)
  1209. lc = ((txdr->count / 64) * 2) + 1;
  1210. else
  1211. lc = ((rxdr->count / 64) * 2) + 1;
  1212. k = l = 0;
  1213. for (j = 0; j <= lc; j++) { /* loop count loop */
  1214. for (i = 0; i < 64; i++) { /* send the packets */
  1215. e1000_create_lbtest_frame(txdr->buffer_info[i].skb,
  1216. 1024);
  1217. dma_sync_single_for_device(&pdev->dev,
  1218. txdr->buffer_info[k].dma,
  1219. txdr->buffer_info[k].length,
  1220. DMA_TO_DEVICE);
  1221. if (unlikely(++k == txdr->count))
  1222. k = 0;
  1223. }
  1224. ew32(TDT, k);
  1225. E1000_WRITE_FLUSH();
  1226. msleep(200);
  1227. time = jiffies; /* set the start time for the receive */
  1228. good_cnt = 0;
  1229. do { /* receive the sent packets */
  1230. dma_sync_single_for_cpu(&pdev->dev,
  1231. rxdr->buffer_info[l].dma,
  1232. E1000_RXBUFFER_2048,
  1233. DMA_FROM_DEVICE);
  1234. ret_val = e1000_check_lbtest_frame(
  1235. rxdr->buffer_info[l].rxbuf.data +
  1236. NET_SKB_PAD + NET_IP_ALIGN,
  1237. 1024);
  1238. if (!ret_val)
  1239. good_cnt++;
  1240. if (unlikely(++l == rxdr->count))
  1241. l = 0;
  1242. /* time + 20 msecs (200 msecs on 2.4) is more than
  1243. * enough time to complete the receives, if it's
  1244. * exceeded, break and error off
  1245. */
  1246. } while (good_cnt < 64 && time_after(time + 20, jiffies));
  1247. if (good_cnt != 64) {
  1248. ret_val = 13; /* ret_val is the same as mis-compare */
  1249. break;
  1250. }
  1251. if (jiffies >= (time + 2)) {
  1252. ret_val = 14; /* error code for time out error */
  1253. break;
  1254. }
  1255. } /* end loop count loop */
  1256. return ret_val;
  1257. }
  1258. static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
  1259. {
  1260. *data = e1000_setup_desc_rings(adapter);
  1261. if (*data)
  1262. goto out;
  1263. *data = e1000_setup_loopback_test(adapter);
  1264. if (*data)
  1265. goto err_loopback;
  1266. *data = e1000_run_loopback_test(adapter);
  1267. e1000_loopback_cleanup(adapter);
  1268. err_loopback:
  1269. e1000_free_desc_rings(adapter);
  1270. out:
  1271. return *data;
  1272. }
  1273. static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
  1274. {
  1275. struct e1000_hw *hw = &adapter->hw;
  1276. *data = 0;
  1277. if (hw->media_type == e1000_media_type_internal_serdes) {
  1278. int i = 0;
  1279. hw->serdes_has_link = false;
  1280. /* On some blade server designs, link establishment
  1281. * could take as long as 2-3 minutes
  1282. */
  1283. do {
  1284. e1000_check_for_link(hw);
  1285. if (hw->serdes_has_link)
  1286. return *data;
  1287. msleep(20);
  1288. } while (i++ < 3750);
  1289. *data = 1;
  1290. } else {
  1291. e1000_check_for_link(hw);
  1292. if (hw->autoneg) /* if auto_neg is set wait for it */
  1293. msleep(4000);
  1294. if (!(er32(STATUS) & E1000_STATUS_LU))
  1295. *data = 1;
  1296. }
  1297. return *data;
  1298. }
  1299. static int e1000_get_sset_count(struct net_device *netdev, int sset)
  1300. {
  1301. switch (sset) {
  1302. case ETH_SS_TEST:
  1303. return E1000_TEST_LEN;
  1304. case ETH_SS_STATS:
  1305. return E1000_STATS_LEN;
  1306. default:
  1307. return -EOPNOTSUPP;
  1308. }
  1309. }
  1310. static void e1000_diag_test(struct net_device *netdev,
  1311. struct ethtool_test *eth_test, u64 *data)
  1312. {
  1313. struct e1000_adapter *adapter = netdev_priv(netdev);
  1314. struct e1000_hw *hw = &adapter->hw;
  1315. bool if_running = netif_running(netdev);
  1316. set_bit(__E1000_TESTING, &adapter->flags);
  1317. if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
  1318. /* Offline tests */
  1319. /* save speed, duplex, autoneg settings */
  1320. u16 autoneg_advertised = hw->autoneg_advertised;
  1321. u8 forced_speed_duplex = hw->forced_speed_duplex;
  1322. u8 autoneg = hw->autoneg;
  1323. e_info(hw, "offline testing starting\n");
  1324. /* Link test performed before hardware reset so autoneg doesn't
  1325. * interfere with test result
  1326. */
  1327. if (e1000_link_test(adapter, &data[4]))
  1328. eth_test->flags |= ETH_TEST_FL_FAILED;
  1329. if (if_running)
  1330. /* indicate we're in test mode */
  1331. dev_close(netdev);
  1332. else
  1333. e1000_reset(adapter);
  1334. if (e1000_reg_test(adapter, &data[0]))
  1335. eth_test->flags |= ETH_TEST_FL_FAILED;
  1336. e1000_reset(adapter);
  1337. if (e1000_eeprom_test(adapter, &data[1]))
  1338. eth_test->flags |= ETH_TEST_FL_FAILED;
  1339. e1000_reset(adapter);
  1340. if (e1000_intr_test(adapter, &data[2]))
  1341. eth_test->flags |= ETH_TEST_FL_FAILED;
  1342. e1000_reset(adapter);
  1343. /* make sure the phy is powered up */
  1344. e1000_power_up_phy(adapter);
  1345. if (e1000_loopback_test(adapter, &data[3]))
  1346. eth_test->flags |= ETH_TEST_FL_FAILED;
  1347. /* restore speed, duplex, autoneg settings */
  1348. hw->autoneg_advertised = autoneg_advertised;
  1349. hw->forced_speed_duplex = forced_speed_duplex;
  1350. hw->autoneg = autoneg;
  1351. e1000_reset(adapter);
  1352. clear_bit(__E1000_TESTING, &adapter->flags);
  1353. if (if_running)
  1354. dev_open(netdev);
  1355. } else {
  1356. e_info(hw, "online testing starting\n");
  1357. /* Online tests */
  1358. if (e1000_link_test(adapter, &data[4]))
  1359. eth_test->flags |= ETH_TEST_FL_FAILED;
  1360. /* Online tests aren't run; pass by default */
  1361. data[0] = 0;
  1362. data[1] = 0;
  1363. data[2] = 0;
  1364. data[3] = 0;
  1365. clear_bit(__E1000_TESTING, &adapter->flags);
  1366. }
  1367. msleep_interruptible(4 * 1000);
  1368. }
  1369. static int e1000_wol_exclusion(struct e1000_adapter *adapter,
  1370. struct ethtool_wolinfo *wol)
  1371. {
  1372. struct e1000_hw *hw = &adapter->hw;
  1373. int retval = 1; /* fail by default */
  1374. switch (hw->device_id) {
  1375. case E1000_DEV_ID_82542:
  1376. case E1000_DEV_ID_82543GC_FIBER:
  1377. case E1000_DEV_ID_82543GC_COPPER:
  1378. case E1000_DEV_ID_82544EI_FIBER:
  1379. case E1000_DEV_ID_82546EB_QUAD_COPPER:
  1380. case E1000_DEV_ID_82545EM_FIBER:
  1381. case E1000_DEV_ID_82545EM_COPPER:
  1382. case E1000_DEV_ID_82546GB_QUAD_COPPER:
  1383. case E1000_DEV_ID_82546GB_PCIE:
  1384. /* these don't support WoL at all */
  1385. wol->supported = 0;
  1386. break;
  1387. case E1000_DEV_ID_82546EB_FIBER:
  1388. case E1000_DEV_ID_82546GB_FIBER:
  1389. /* Wake events not supported on port B */
  1390. if (er32(STATUS) & E1000_STATUS_FUNC_1) {
  1391. wol->supported = 0;
  1392. break;
  1393. }
  1394. /* return success for non excluded adapter ports */
  1395. retval = 0;
  1396. break;
  1397. case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
  1398. /* quad port adapters only support WoL on port A */
  1399. if (!adapter->quad_port_a) {
  1400. wol->supported = 0;
  1401. break;
  1402. }
  1403. /* return success for non excluded adapter ports */
  1404. retval = 0;
  1405. break;
  1406. default:
  1407. /* dual port cards only support WoL on port A from now on
  1408. * unless it was enabled in the eeprom for port B
  1409. * so exclude FUNC_1 ports from having WoL enabled
  1410. */
  1411. if (er32(STATUS) & E1000_STATUS_FUNC_1 &&
  1412. !adapter->eeprom_wol) {
  1413. wol->supported = 0;
  1414. break;
  1415. }
  1416. retval = 0;
  1417. }
  1418. return retval;
  1419. }
  1420. static void e1000_get_wol(struct net_device *netdev,
  1421. struct ethtool_wolinfo *wol)
  1422. {
  1423. struct e1000_adapter *adapter = netdev_priv(netdev);
  1424. struct e1000_hw *hw = &adapter->hw;
  1425. wol->supported = WAKE_UCAST | WAKE_MCAST | WAKE_BCAST | WAKE_MAGIC;
  1426. wol->wolopts = 0;
  1427. /* this function will set ->supported = 0 and return 1 if wol is not
  1428. * supported by this hardware
  1429. */
  1430. if (e1000_wol_exclusion(adapter, wol) ||
  1431. !device_can_wakeup(&adapter->pdev->dev))
  1432. return;
  1433. /* apply any specific unsupported masks here */
  1434. switch (hw->device_id) {
  1435. case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
  1436. /* KSP3 does not support UCAST wake-ups */
  1437. wol->supported &= ~WAKE_UCAST;
  1438. if (adapter->wol & E1000_WUFC_EX)
  1439. e_err(drv, "Interface does not support directed "
  1440. "(unicast) frame wake-up packets\n");
  1441. break;
  1442. default:
  1443. break;
  1444. }
  1445. if (adapter->wol & E1000_WUFC_EX)
  1446. wol->wolopts |= WAKE_UCAST;
  1447. if (adapter->wol & E1000_WUFC_MC)
  1448. wol->wolopts |= WAKE_MCAST;
  1449. if (adapter->wol & E1000_WUFC_BC)
  1450. wol->wolopts |= WAKE_BCAST;
  1451. if (adapter->wol & E1000_WUFC_MAG)
  1452. wol->wolopts |= WAKE_MAGIC;
  1453. }
  1454. static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  1455. {
  1456. struct e1000_adapter *adapter = netdev_priv(netdev);
  1457. struct e1000_hw *hw = &adapter->hw;
  1458. if (wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE))
  1459. return -EOPNOTSUPP;
  1460. if (e1000_wol_exclusion(adapter, wol) ||
  1461. !device_can_wakeup(&adapter->pdev->dev))
  1462. return wol->wolopts ? -EOPNOTSUPP : 0;
  1463. switch (hw->device_id) {
  1464. case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
  1465. if (wol->wolopts & WAKE_UCAST) {
  1466. e_err(drv, "Interface does not support directed "
  1467. "(unicast) frame wake-up packets\n");
  1468. return -EOPNOTSUPP;
  1469. }
  1470. break;
  1471. default:
  1472. break;
  1473. }
  1474. /* these settings will always override what we currently have */
  1475. adapter->wol = 0;
  1476. if (wol->wolopts & WAKE_UCAST)
  1477. adapter->wol |= E1000_WUFC_EX;
  1478. if (wol->wolopts & WAKE_MCAST)
  1479. adapter->wol |= E1000_WUFC_MC;
  1480. if (wol->wolopts & WAKE_BCAST)
  1481. adapter->wol |= E1000_WUFC_BC;
  1482. if (wol->wolopts & WAKE_MAGIC)
  1483. adapter->wol |= E1000_WUFC_MAG;
  1484. device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
  1485. return 0;
  1486. }
  1487. static int e1000_set_phys_id(struct net_device *netdev,
  1488. enum ethtool_phys_id_state state)
  1489. {
  1490. struct e1000_adapter *adapter = netdev_priv(netdev);
  1491. struct e1000_hw *hw = &adapter->hw;
  1492. switch (state) {
  1493. case ETHTOOL_ID_ACTIVE:
  1494. e1000_setup_led(hw);
  1495. return 2;
  1496. case ETHTOOL_ID_ON:
  1497. e1000_led_on(hw);
  1498. break;
  1499. case ETHTOOL_ID_OFF:
  1500. e1000_led_off(hw);
  1501. break;
  1502. case ETHTOOL_ID_INACTIVE:
  1503. e1000_cleanup_led(hw);
  1504. }
  1505. return 0;
  1506. }
  1507. static int e1000_get_coalesce(struct net_device *netdev,
  1508. struct ethtool_coalesce *ec)
  1509. {
  1510. struct e1000_adapter *adapter = netdev_priv(netdev);
  1511. if (adapter->hw.mac_type < e1000_82545)
  1512. return -EOPNOTSUPP;
  1513. if (adapter->itr_setting <= 4)
  1514. ec->rx_coalesce_usecs = adapter->itr_setting;
  1515. else
  1516. ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
  1517. return 0;
  1518. }
  1519. static int e1000_set_coalesce(struct net_device *netdev,
  1520. struct ethtool_coalesce *ec)
  1521. {
  1522. struct e1000_adapter *adapter = netdev_priv(netdev);
  1523. struct e1000_hw *hw = &adapter->hw;
  1524. if (hw->mac_type < e1000_82545)
  1525. return -EOPNOTSUPP;
  1526. if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
  1527. ((ec->rx_coalesce_usecs > 4) &&
  1528. (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
  1529. (ec->rx_coalesce_usecs == 2))
  1530. return -EINVAL;
  1531. if (ec->rx_coalesce_usecs == 4) {
  1532. adapter->itr = adapter->itr_setting = 4;
  1533. } else if (ec->rx_coalesce_usecs <= 3) {
  1534. adapter->itr = 20000;
  1535. adapter->itr_setting = ec->rx_coalesce_usecs;
  1536. } else {
  1537. adapter->itr = (1000000 / ec->rx_coalesce_usecs);
  1538. adapter->itr_setting = adapter->itr & ~3;
  1539. }
  1540. if (adapter->itr_setting != 0)
  1541. ew32(ITR, 1000000000 / (adapter->itr * 256));
  1542. else
  1543. ew32(ITR, 0);
  1544. return 0;
  1545. }
  1546. static int e1000_nway_reset(struct net_device *netdev)
  1547. {
  1548. struct e1000_adapter *adapter = netdev_priv(netdev);
  1549. if (netif_running(netdev))
  1550. e1000_reinit_locked(adapter);
  1551. return 0;
  1552. }
  1553. static void e1000_get_ethtool_stats(struct net_device *netdev,
  1554. struct ethtool_stats *stats, u64 *data)
  1555. {
  1556. struct e1000_adapter *adapter = netdev_priv(netdev);
  1557. int i;
  1558. char *p = NULL;
  1559. const struct e1000_stats *stat = e1000_gstrings_stats;
  1560. e1000_update_stats(adapter);
  1561. for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
  1562. switch (stat->type) {
  1563. case NETDEV_STATS:
  1564. p = (char *)netdev + stat->stat_offset;
  1565. break;
  1566. case E1000_STATS:
  1567. p = (char *)adapter + stat->stat_offset;
  1568. break;
  1569. default:
  1570. WARN_ONCE(1, "Invalid E1000 stat type: %u index %d\n",
  1571. stat->type, i);
  1572. break;
  1573. }
  1574. if (stat->sizeof_stat == sizeof(u64))
  1575. data[i] = *(u64 *)p;
  1576. else
  1577. data[i] = *(u32 *)p;
  1578. stat++;
  1579. }
  1580. /* BUG_ON(i != E1000_STATS_LEN); */
  1581. }
  1582. static void e1000_get_strings(struct net_device *netdev, u32 stringset,
  1583. u8 *data)
  1584. {
  1585. u8 *p = data;
  1586. int i;
  1587. switch (stringset) {
  1588. case ETH_SS_TEST:
  1589. memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test));
  1590. break;
  1591. case ETH_SS_STATS:
  1592. for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
  1593. memcpy(p, e1000_gstrings_stats[i].stat_string,
  1594. ETH_GSTRING_LEN);
  1595. p += ETH_GSTRING_LEN;
  1596. }
  1597. /* BUG_ON(p - data != E1000_STATS_LEN * ETH_GSTRING_LEN); */
  1598. break;
  1599. }
  1600. }
  1601. static const struct ethtool_ops e1000_ethtool_ops = {
  1602. .get_settings = e1000_get_settings,
  1603. .set_settings = e1000_set_settings,
  1604. .get_drvinfo = e1000_get_drvinfo,
  1605. .get_regs_len = e1000_get_regs_len,
  1606. .get_regs = e1000_get_regs,
  1607. .get_wol = e1000_get_wol,
  1608. .set_wol = e1000_set_wol,
  1609. .get_msglevel = e1000_get_msglevel,
  1610. .set_msglevel = e1000_set_msglevel,
  1611. .nway_reset = e1000_nway_reset,
  1612. .get_link = e1000_get_link,
  1613. .get_eeprom_len = e1000_get_eeprom_len,
  1614. .get_eeprom = e1000_get_eeprom,
  1615. .set_eeprom = e1000_set_eeprom,
  1616. .get_ringparam = e1000_get_ringparam,
  1617. .set_ringparam = e1000_set_ringparam,
  1618. .get_pauseparam = e1000_get_pauseparam,
  1619. .set_pauseparam = e1000_set_pauseparam,
  1620. .self_test = e1000_diag_test,
  1621. .get_strings = e1000_get_strings,
  1622. .set_phys_id = e1000_set_phys_id,
  1623. .get_ethtool_stats = e1000_get_ethtool_stats,
  1624. .get_sset_count = e1000_get_sset_count,
  1625. .get_coalesce = e1000_get_coalesce,
  1626. .set_coalesce = e1000_set_coalesce,
  1627. .get_ts_info = ethtool_op_get_ts_info,
  1628. };
  1629. void e1000_set_ethtool_ops(struct net_device *netdev)
  1630. {
  1631. netdev->ethtool_ops = &e1000_ethtool_ops;
  1632. }