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