bnx2x_ethtool.c 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165
  1. /* bnx2x_ethtool.c: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2011 Broadcom Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation.
  8. *
  9. * Maintained by: Eilon Greenstein <eilong@broadcom.com>
  10. * Written by: Eliezer Tamir
  11. * Based on code from Michael Chan's bnx2 driver
  12. * UDP CSUM errata workaround by Arik Gendelman
  13. * Slowpath and fastpath rework by Vladislav Zolotarov
  14. * Statistics and Link management by Yitchak Gertner
  15. *
  16. */
  17. #include <linux/ethtool.h>
  18. #include <linux/netdevice.h>
  19. #include <linux/types.h>
  20. #include <linux/sched.h>
  21. #include <linux/crc32.h>
  22. #include "bnx2x.h"
  23. #include "bnx2x_cmn.h"
  24. #include "bnx2x_dump.h"
  25. #include "bnx2x_init.h"
  26. /* Note: in the format strings below %s is replaced by the queue-name which is
  27. * either its index or 'fcoe' for the fcoe queue. Make sure the format string
  28. * length does not exceed ETH_GSTRING_LEN - MAX_QUEUE_NAME_LEN + 2
  29. */
  30. #define MAX_QUEUE_NAME_LEN 4
  31. static const struct {
  32. long offset;
  33. int size;
  34. char string[ETH_GSTRING_LEN];
  35. } bnx2x_q_stats_arr[] = {
  36. /* 1 */ { Q_STATS_OFFSET32(total_bytes_received_hi), 8, "[%s]: rx_bytes" },
  37. { Q_STATS_OFFSET32(error_bytes_received_hi),
  38. 8, "[%s]: rx_error_bytes" },
  39. { Q_STATS_OFFSET32(total_unicast_packets_received_hi),
  40. 8, "[%s]: rx_ucast_packets" },
  41. { Q_STATS_OFFSET32(total_multicast_packets_received_hi),
  42. 8, "[%s]: rx_mcast_packets" },
  43. { Q_STATS_OFFSET32(total_broadcast_packets_received_hi),
  44. 8, "[%s]: rx_bcast_packets" },
  45. { Q_STATS_OFFSET32(no_buff_discard_hi), 8, "[%s]: rx_discards" },
  46. { Q_STATS_OFFSET32(rx_err_discard_pkt),
  47. 4, "[%s]: rx_phy_ip_err_discards"},
  48. { Q_STATS_OFFSET32(rx_skb_alloc_failed),
  49. 4, "[%s]: rx_skb_alloc_discard" },
  50. { Q_STATS_OFFSET32(hw_csum_err), 4, "[%s]: rx_csum_offload_errors" },
  51. /* 10 */{ Q_STATS_OFFSET32(total_bytes_transmitted_hi), 8, "[%s]: tx_bytes" },
  52. { Q_STATS_OFFSET32(total_unicast_packets_transmitted_hi),
  53. 8, "[%s]: tx_ucast_packets" },
  54. { Q_STATS_OFFSET32(total_multicast_packets_transmitted_hi),
  55. 8, "[%s]: tx_mcast_packets" },
  56. { Q_STATS_OFFSET32(total_broadcast_packets_transmitted_hi),
  57. 8, "[%s]: tx_bcast_packets" }
  58. };
  59. #define BNX2X_NUM_Q_STATS ARRAY_SIZE(bnx2x_q_stats_arr)
  60. static const struct {
  61. long offset;
  62. int size;
  63. u32 flags;
  64. #define STATS_FLAGS_PORT 1
  65. #define STATS_FLAGS_FUNC 2
  66. #define STATS_FLAGS_BOTH (STATS_FLAGS_FUNC | STATS_FLAGS_PORT)
  67. char string[ETH_GSTRING_LEN];
  68. } bnx2x_stats_arr[] = {
  69. /* 1 */ { STATS_OFFSET32(total_bytes_received_hi),
  70. 8, STATS_FLAGS_BOTH, "rx_bytes" },
  71. { STATS_OFFSET32(error_bytes_received_hi),
  72. 8, STATS_FLAGS_BOTH, "rx_error_bytes" },
  73. { STATS_OFFSET32(total_unicast_packets_received_hi),
  74. 8, STATS_FLAGS_BOTH, "rx_ucast_packets" },
  75. { STATS_OFFSET32(total_multicast_packets_received_hi),
  76. 8, STATS_FLAGS_BOTH, "rx_mcast_packets" },
  77. { STATS_OFFSET32(total_broadcast_packets_received_hi),
  78. 8, STATS_FLAGS_BOTH, "rx_bcast_packets" },
  79. { STATS_OFFSET32(rx_stat_dot3statsfcserrors_hi),
  80. 8, STATS_FLAGS_PORT, "rx_crc_errors" },
  81. { STATS_OFFSET32(rx_stat_dot3statsalignmenterrors_hi),
  82. 8, STATS_FLAGS_PORT, "rx_align_errors" },
  83. { STATS_OFFSET32(rx_stat_etherstatsundersizepkts_hi),
  84. 8, STATS_FLAGS_PORT, "rx_undersize_packets" },
  85. { STATS_OFFSET32(etherstatsoverrsizepkts_hi),
  86. 8, STATS_FLAGS_PORT, "rx_oversize_packets" },
  87. /* 10 */{ STATS_OFFSET32(rx_stat_etherstatsfragments_hi),
  88. 8, STATS_FLAGS_PORT, "rx_fragments" },
  89. { STATS_OFFSET32(rx_stat_etherstatsjabbers_hi),
  90. 8, STATS_FLAGS_PORT, "rx_jabbers" },
  91. { STATS_OFFSET32(no_buff_discard_hi),
  92. 8, STATS_FLAGS_BOTH, "rx_discards" },
  93. { STATS_OFFSET32(mac_filter_discard),
  94. 4, STATS_FLAGS_PORT, "rx_filtered_packets" },
  95. { STATS_OFFSET32(xxoverflow_discard),
  96. 4, STATS_FLAGS_PORT, "rx_fw_discards" },
  97. { STATS_OFFSET32(brb_drop_hi),
  98. 8, STATS_FLAGS_PORT, "rx_brb_discard" },
  99. { STATS_OFFSET32(brb_truncate_hi),
  100. 8, STATS_FLAGS_PORT, "rx_brb_truncate" },
  101. { STATS_OFFSET32(pause_frames_received_hi),
  102. 8, STATS_FLAGS_PORT, "rx_pause_frames" },
  103. { STATS_OFFSET32(rx_stat_maccontrolframesreceived_hi),
  104. 8, STATS_FLAGS_PORT, "rx_mac_ctrl_frames" },
  105. { STATS_OFFSET32(nig_timer_max),
  106. 4, STATS_FLAGS_PORT, "rx_constant_pause_events" },
  107. /* 20 */{ STATS_OFFSET32(rx_err_discard_pkt),
  108. 4, STATS_FLAGS_BOTH, "rx_phy_ip_err_discards"},
  109. { STATS_OFFSET32(rx_skb_alloc_failed),
  110. 4, STATS_FLAGS_BOTH, "rx_skb_alloc_discard" },
  111. { STATS_OFFSET32(hw_csum_err),
  112. 4, STATS_FLAGS_BOTH, "rx_csum_offload_errors" },
  113. { STATS_OFFSET32(total_bytes_transmitted_hi),
  114. 8, STATS_FLAGS_BOTH, "tx_bytes" },
  115. { STATS_OFFSET32(tx_stat_ifhcoutbadoctets_hi),
  116. 8, STATS_FLAGS_PORT, "tx_error_bytes" },
  117. { STATS_OFFSET32(total_unicast_packets_transmitted_hi),
  118. 8, STATS_FLAGS_BOTH, "tx_ucast_packets" },
  119. { STATS_OFFSET32(total_multicast_packets_transmitted_hi),
  120. 8, STATS_FLAGS_BOTH, "tx_mcast_packets" },
  121. { STATS_OFFSET32(total_broadcast_packets_transmitted_hi),
  122. 8, STATS_FLAGS_BOTH, "tx_bcast_packets" },
  123. { STATS_OFFSET32(tx_stat_dot3statsinternalmactransmiterrors_hi),
  124. 8, STATS_FLAGS_PORT, "tx_mac_errors" },
  125. { STATS_OFFSET32(rx_stat_dot3statscarriersenseerrors_hi),
  126. 8, STATS_FLAGS_PORT, "tx_carrier_errors" },
  127. /* 30 */{ STATS_OFFSET32(tx_stat_dot3statssinglecollisionframes_hi),
  128. 8, STATS_FLAGS_PORT, "tx_single_collisions" },
  129. { STATS_OFFSET32(tx_stat_dot3statsmultiplecollisionframes_hi),
  130. 8, STATS_FLAGS_PORT, "tx_multi_collisions" },
  131. { STATS_OFFSET32(tx_stat_dot3statsdeferredtransmissions_hi),
  132. 8, STATS_FLAGS_PORT, "tx_deferred" },
  133. { STATS_OFFSET32(tx_stat_dot3statsexcessivecollisions_hi),
  134. 8, STATS_FLAGS_PORT, "tx_excess_collisions" },
  135. { STATS_OFFSET32(tx_stat_dot3statslatecollisions_hi),
  136. 8, STATS_FLAGS_PORT, "tx_late_collisions" },
  137. { STATS_OFFSET32(tx_stat_etherstatscollisions_hi),
  138. 8, STATS_FLAGS_PORT, "tx_total_collisions" },
  139. { STATS_OFFSET32(tx_stat_etherstatspkts64octets_hi),
  140. 8, STATS_FLAGS_PORT, "tx_64_byte_packets" },
  141. { STATS_OFFSET32(tx_stat_etherstatspkts65octetsto127octets_hi),
  142. 8, STATS_FLAGS_PORT, "tx_65_to_127_byte_packets" },
  143. { STATS_OFFSET32(tx_stat_etherstatspkts128octetsto255octets_hi),
  144. 8, STATS_FLAGS_PORT, "tx_128_to_255_byte_packets" },
  145. { STATS_OFFSET32(tx_stat_etherstatspkts256octetsto511octets_hi),
  146. 8, STATS_FLAGS_PORT, "tx_256_to_511_byte_packets" },
  147. /* 40 */{ STATS_OFFSET32(tx_stat_etherstatspkts512octetsto1023octets_hi),
  148. 8, STATS_FLAGS_PORT, "tx_512_to_1023_byte_packets" },
  149. { STATS_OFFSET32(etherstatspkts1024octetsto1522octets_hi),
  150. 8, STATS_FLAGS_PORT, "tx_1024_to_1522_byte_packets" },
  151. { STATS_OFFSET32(etherstatspktsover1522octets_hi),
  152. 8, STATS_FLAGS_PORT, "tx_1523_to_9022_byte_packets" },
  153. { STATS_OFFSET32(pause_frames_sent_hi),
  154. 8, STATS_FLAGS_PORT, "tx_pause_frames" }
  155. };
  156. #define BNX2X_NUM_STATS ARRAY_SIZE(bnx2x_stats_arr)
  157. static int bnx2x_get_port_type(struct bnx2x *bp)
  158. {
  159. int port_type;
  160. u32 phy_idx = bnx2x_get_cur_phy_idx(bp);
  161. switch (bp->link_params.phy[phy_idx].media_type) {
  162. case ETH_PHY_SFP_FIBER:
  163. case ETH_PHY_XFP_FIBER:
  164. case ETH_PHY_KR:
  165. case ETH_PHY_CX4:
  166. port_type = PORT_FIBRE;
  167. break;
  168. case ETH_PHY_DA_TWINAX:
  169. port_type = PORT_DA;
  170. break;
  171. case ETH_PHY_BASE_T:
  172. port_type = PORT_TP;
  173. break;
  174. case ETH_PHY_NOT_PRESENT:
  175. port_type = PORT_NONE;
  176. break;
  177. case ETH_PHY_UNSPECIFIED:
  178. default:
  179. port_type = PORT_OTHER;
  180. break;
  181. }
  182. return port_type;
  183. }
  184. static int bnx2x_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  185. {
  186. struct bnx2x *bp = netdev_priv(dev);
  187. int cfg_idx = bnx2x_get_link_cfg_idx(bp);
  188. /* Dual Media boards present all available port types */
  189. cmd->supported = bp->port.supported[cfg_idx] |
  190. (bp->port.supported[cfg_idx ^ 1] &
  191. (SUPPORTED_TP | SUPPORTED_FIBRE));
  192. cmd->advertising = bp->port.advertising[cfg_idx];
  193. if ((bp->state == BNX2X_STATE_OPEN) &&
  194. !(bp->flags & MF_FUNC_DIS) &&
  195. (bp->link_vars.link_up)) {
  196. ethtool_cmd_speed_set(cmd, bp->link_vars.line_speed);
  197. cmd->duplex = bp->link_vars.duplex;
  198. } else {
  199. ethtool_cmd_speed_set(
  200. cmd, bp->link_params.req_line_speed[cfg_idx]);
  201. cmd->duplex = bp->link_params.req_duplex[cfg_idx];
  202. }
  203. if (IS_MF(bp))
  204. ethtool_cmd_speed_set(cmd, bnx2x_get_mf_speed(bp));
  205. cmd->port = bnx2x_get_port_type(bp);
  206. cmd->phy_address = bp->mdio.prtad;
  207. cmd->transceiver = XCVR_INTERNAL;
  208. if (bp->link_params.req_line_speed[cfg_idx] == SPEED_AUTO_NEG)
  209. cmd->autoneg = AUTONEG_ENABLE;
  210. else
  211. cmd->autoneg = AUTONEG_DISABLE;
  212. cmd->maxtxpkt = 0;
  213. cmd->maxrxpkt = 0;
  214. DP(NETIF_MSG_LINK, "ethtool_cmd: cmd %d\n"
  215. DP_LEVEL " supported 0x%x advertising 0x%x speed %u\n"
  216. DP_LEVEL " duplex %d port %d phy_address %d transceiver %d\n"
  217. DP_LEVEL " autoneg %d maxtxpkt %d maxrxpkt %d\n",
  218. cmd->cmd, cmd->supported, cmd->advertising,
  219. ethtool_cmd_speed(cmd),
  220. cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver,
  221. cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt);
  222. return 0;
  223. }
  224. static int bnx2x_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  225. {
  226. struct bnx2x *bp = netdev_priv(dev);
  227. u32 advertising, cfg_idx, old_multi_phy_config, new_multi_phy_config;
  228. u32 speed;
  229. if (IS_MF_SD(bp))
  230. return 0;
  231. DP(NETIF_MSG_LINK, "ethtool_cmd: cmd %d\n"
  232. " supported 0x%x advertising 0x%x speed %u\n"
  233. " duplex %d port %d phy_address %d transceiver %d\n"
  234. " autoneg %d maxtxpkt %d maxrxpkt %d\n",
  235. cmd->cmd, cmd->supported, cmd->advertising,
  236. ethtool_cmd_speed(cmd),
  237. cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver,
  238. cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt);
  239. speed = ethtool_cmd_speed(cmd);
  240. if (IS_MF_SI(bp)) {
  241. u32 part;
  242. u32 line_speed = bp->link_vars.line_speed;
  243. /* use 10G if no link detected */
  244. if (!line_speed)
  245. line_speed = 10000;
  246. if (bp->common.bc_ver < REQ_BC_VER_4_SET_MF_BW) {
  247. BNX2X_DEV_INFO("To set speed BC %X or higher "
  248. "is required, please upgrade BC\n",
  249. REQ_BC_VER_4_SET_MF_BW);
  250. return -EINVAL;
  251. }
  252. part = (speed * 100) / line_speed;
  253. if (line_speed < speed || !part) {
  254. BNX2X_DEV_INFO("Speed setting should be in a range "
  255. "from 1%% to 100%% "
  256. "of actual line speed\n");
  257. return -EINVAL;
  258. }
  259. if (bp->state != BNX2X_STATE_OPEN)
  260. /* store value for following "load" */
  261. bp->pending_max = part;
  262. else
  263. bnx2x_update_max_mf_config(bp, part);
  264. return 0;
  265. }
  266. cfg_idx = bnx2x_get_link_cfg_idx(bp);
  267. old_multi_phy_config = bp->link_params.multi_phy_config;
  268. switch (cmd->port) {
  269. case PORT_TP:
  270. if (bp->port.supported[cfg_idx] & SUPPORTED_TP)
  271. break; /* no port change */
  272. if (!(bp->port.supported[0] & SUPPORTED_TP ||
  273. bp->port.supported[1] & SUPPORTED_TP)) {
  274. DP(NETIF_MSG_LINK, "Unsupported port type\n");
  275. return -EINVAL;
  276. }
  277. bp->link_params.multi_phy_config &=
  278. ~PORT_HW_CFG_PHY_SELECTION_MASK;
  279. if (bp->link_params.multi_phy_config &
  280. PORT_HW_CFG_PHY_SWAPPED_ENABLED)
  281. bp->link_params.multi_phy_config |=
  282. PORT_HW_CFG_PHY_SELECTION_SECOND_PHY;
  283. else
  284. bp->link_params.multi_phy_config |=
  285. PORT_HW_CFG_PHY_SELECTION_FIRST_PHY;
  286. break;
  287. case PORT_FIBRE:
  288. if (bp->port.supported[cfg_idx] & SUPPORTED_FIBRE)
  289. break; /* no port change */
  290. if (!(bp->port.supported[0] & SUPPORTED_FIBRE ||
  291. bp->port.supported[1] & SUPPORTED_FIBRE)) {
  292. DP(NETIF_MSG_LINK, "Unsupported port type\n");
  293. return -EINVAL;
  294. }
  295. bp->link_params.multi_phy_config &=
  296. ~PORT_HW_CFG_PHY_SELECTION_MASK;
  297. if (bp->link_params.multi_phy_config &
  298. PORT_HW_CFG_PHY_SWAPPED_ENABLED)
  299. bp->link_params.multi_phy_config |=
  300. PORT_HW_CFG_PHY_SELECTION_FIRST_PHY;
  301. else
  302. bp->link_params.multi_phy_config |=
  303. PORT_HW_CFG_PHY_SELECTION_SECOND_PHY;
  304. break;
  305. default:
  306. DP(NETIF_MSG_LINK, "Unsupported port type\n");
  307. return -EINVAL;
  308. }
  309. /* Save new config in case command complete successuly */
  310. new_multi_phy_config = bp->link_params.multi_phy_config;
  311. /* Get the new cfg_idx */
  312. cfg_idx = bnx2x_get_link_cfg_idx(bp);
  313. /* Restore old config in case command failed */
  314. bp->link_params.multi_phy_config = old_multi_phy_config;
  315. DP(NETIF_MSG_LINK, "cfg_idx = %x\n", cfg_idx);
  316. if (cmd->autoneg == AUTONEG_ENABLE) {
  317. if (!(bp->port.supported[cfg_idx] & SUPPORTED_Autoneg)) {
  318. DP(NETIF_MSG_LINK, "Autoneg not supported\n");
  319. return -EINVAL;
  320. }
  321. /* advertise the requested speed and duplex if supported */
  322. cmd->advertising &= bp->port.supported[cfg_idx];
  323. bp->link_params.req_line_speed[cfg_idx] = SPEED_AUTO_NEG;
  324. bp->link_params.req_duplex[cfg_idx] = DUPLEX_FULL;
  325. bp->port.advertising[cfg_idx] |= (ADVERTISED_Autoneg |
  326. cmd->advertising);
  327. } else { /* forced speed */
  328. /* advertise the requested speed and duplex if supported */
  329. switch (speed) {
  330. case SPEED_10:
  331. if (cmd->duplex == DUPLEX_FULL) {
  332. if (!(bp->port.supported[cfg_idx] &
  333. SUPPORTED_10baseT_Full)) {
  334. DP(NETIF_MSG_LINK,
  335. "10M full not supported\n");
  336. return -EINVAL;
  337. }
  338. advertising = (ADVERTISED_10baseT_Full |
  339. ADVERTISED_TP);
  340. } else {
  341. if (!(bp->port.supported[cfg_idx] &
  342. SUPPORTED_10baseT_Half)) {
  343. DP(NETIF_MSG_LINK,
  344. "10M half not supported\n");
  345. return -EINVAL;
  346. }
  347. advertising = (ADVERTISED_10baseT_Half |
  348. ADVERTISED_TP);
  349. }
  350. break;
  351. case SPEED_100:
  352. if (cmd->duplex == DUPLEX_FULL) {
  353. if (!(bp->port.supported[cfg_idx] &
  354. SUPPORTED_100baseT_Full)) {
  355. DP(NETIF_MSG_LINK,
  356. "100M full not supported\n");
  357. return -EINVAL;
  358. }
  359. advertising = (ADVERTISED_100baseT_Full |
  360. ADVERTISED_TP);
  361. } else {
  362. if (!(bp->port.supported[cfg_idx] &
  363. SUPPORTED_100baseT_Half)) {
  364. DP(NETIF_MSG_LINK,
  365. "100M half not supported\n");
  366. return -EINVAL;
  367. }
  368. advertising = (ADVERTISED_100baseT_Half |
  369. ADVERTISED_TP);
  370. }
  371. break;
  372. case SPEED_1000:
  373. if (cmd->duplex != DUPLEX_FULL) {
  374. DP(NETIF_MSG_LINK, "1G half not supported\n");
  375. return -EINVAL;
  376. }
  377. if (!(bp->port.supported[cfg_idx] &
  378. SUPPORTED_1000baseT_Full)) {
  379. DP(NETIF_MSG_LINK, "1G full not supported\n");
  380. return -EINVAL;
  381. }
  382. advertising = (ADVERTISED_1000baseT_Full |
  383. ADVERTISED_TP);
  384. break;
  385. case SPEED_2500:
  386. if (cmd->duplex != DUPLEX_FULL) {
  387. DP(NETIF_MSG_LINK,
  388. "2.5G half not supported\n");
  389. return -EINVAL;
  390. }
  391. if (!(bp->port.supported[cfg_idx]
  392. & SUPPORTED_2500baseX_Full)) {
  393. DP(NETIF_MSG_LINK,
  394. "2.5G full not supported\n");
  395. return -EINVAL;
  396. }
  397. advertising = (ADVERTISED_2500baseX_Full |
  398. ADVERTISED_TP);
  399. break;
  400. case SPEED_10000:
  401. if (cmd->duplex != DUPLEX_FULL) {
  402. DP(NETIF_MSG_LINK, "10G half not supported\n");
  403. return -EINVAL;
  404. }
  405. if (!(bp->port.supported[cfg_idx]
  406. & SUPPORTED_10000baseT_Full)) {
  407. DP(NETIF_MSG_LINK, "10G full not supported\n");
  408. return -EINVAL;
  409. }
  410. advertising = (ADVERTISED_10000baseT_Full |
  411. ADVERTISED_FIBRE);
  412. break;
  413. default:
  414. DP(NETIF_MSG_LINK, "Unsupported speed %u\n", speed);
  415. return -EINVAL;
  416. }
  417. bp->link_params.req_line_speed[cfg_idx] = speed;
  418. bp->link_params.req_duplex[cfg_idx] = cmd->duplex;
  419. bp->port.advertising[cfg_idx] = advertising;
  420. }
  421. DP(NETIF_MSG_LINK, "req_line_speed %d\n"
  422. DP_LEVEL " req_duplex %d advertising 0x%x\n",
  423. bp->link_params.req_line_speed[cfg_idx],
  424. bp->link_params.req_duplex[cfg_idx],
  425. bp->port.advertising[cfg_idx]);
  426. /* Set new config */
  427. bp->link_params.multi_phy_config = new_multi_phy_config;
  428. if (netif_running(dev)) {
  429. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  430. bnx2x_link_set(bp);
  431. }
  432. return 0;
  433. }
  434. #define IS_E1_ONLINE(info) (((info) & RI_E1_ONLINE) == RI_E1_ONLINE)
  435. #define IS_E1H_ONLINE(info) (((info) & RI_E1H_ONLINE) == RI_E1H_ONLINE)
  436. #define IS_E2_ONLINE(info) (((info) & RI_E2_ONLINE) == RI_E2_ONLINE)
  437. static int bnx2x_get_regs_len(struct net_device *dev)
  438. {
  439. struct bnx2x *bp = netdev_priv(dev);
  440. int regdump_len = 0;
  441. int i, j, k;
  442. if (CHIP_IS_E1(bp)) {
  443. for (i = 0; i < REGS_COUNT; i++)
  444. if (IS_E1_ONLINE(reg_addrs[i].info))
  445. regdump_len += reg_addrs[i].size;
  446. for (i = 0; i < WREGS_COUNT_E1; i++)
  447. if (IS_E1_ONLINE(wreg_addrs_e1[i].info))
  448. regdump_len += wreg_addrs_e1[i].size *
  449. (1 + wreg_addrs_e1[i].read_regs_count);
  450. } else if (CHIP_IS_E1H(bp)) {
  451. for (i = 0; i < REGS_COUNT; i++)
  452. if (IS_E1H_ONLINE(reg_addrs[i].info))
  453. regdump_len += reg_addrs[i].size;
  454. for (i = 0; i < WREGS_COUNT_E1H; i++)
  455. if (IS_E1H_ONLINE(wreg_addrs_e1h[i].info))
  456. regdump_len += wreg_addrs_e1h[i].size *
  457. (1 + wreg_addrs_e1h[i].read_regs_count);
  458. } else if (CHIP_IS_E2(bp)) {
  459. for (i = 0; i < REGS_COUNT; i++)
  460. if (IS_E2_ONLINE(reg_addrs[i].info))
  461. regdump_len += reg_addrs[i].size;
  462. for (i = 0; i < WREGS_COUNT_E2; i++)
  463. if (IS_E2_ONLINE(wreg_addrs_e2[i].info))
  464. regdump_len += wreg_addrs_e2[i].size *
  465. (1 + wreg_addrs_e2[i].read_regs_count);
  466. for (i = 0; i < PAGE_MODE_VALUES_E2; i++)
  467. for (j = 0; j < PAGE_WRITE_REGS_E2; j++) {
  468. for (k = 0; k < PAGE_READ_REGS_E2; k++)
  469. if (IS_E2_ONLINE(page_read_regs_e2[k].
  470. info))
  471. regdump_len +=
  472. page_read_regs_e2[k].size;
  473. }
  474. }
  475. regdump_len *= 4;
  476. regdump_len += sizeof(struct dump_hdr);
  477. return regdump_len;
  478. }
  479. static inline void bnx2x_read_pages_regs_e2(struct bnx2x *bp, u32 *p)
  480. {
  481. u32 i, j, k, n;
  482. for (i = 0; i < PAGE_MODE_VALUES_E2; i++) {
  483. for (j = 0; j < PAGE_WRITE_REGS_E2; j++) {
  484. REG_WR(bp, page_write_regs_e2[j], page_vals_e2[i]);
  485. for (k = 0; k < PAGE_READ_REGS_E2; k++)
  486. if (IS_E2_ONLINE(page_read_regs_e2[k].info))
  487. for (n = 0; n <
  488. page_read_regs_e2[k].size; n++)
  489. *p++ = REG_RD(bp,
  490. page_read_regs_e2[k].addr + n*4);
  491. }
  492. }
  493. }
  494. static void bnx2x_get_regs(struct net_device *dev,
  495. struct ethtool_regs *regs, void *_p)
  496. {
  497. u32 *p = _p, i, j;
  498. struct bnx2x *bp = netdev_priv(dev);
  499. struct dump_hdr dump_hdr = {0};
  500. regs->version = 0;
  501. memset(p, 0, regs->len);
  502. if (!netif_running(bp->dev))
  503. return;
  504. /* Disable parity attentions as long as following dump may
  505. * cause false alarms by reading never written registers. We
  506. * will re-enable parity attentions right after the dump.
  507. */
  508. bnx2x_disable_blocks_parity(bp);
  509. dump_hdr.hdr_size = (sizeof(struct dump_hdr) / 4) - 1;
  510. dump_hdr.dump_sign = dump_sign_all;
  511. dump_hdr.xstorm_waitp = REG_RD(bp, XSTORM_WAITP_ADDR);
  512. dump_hdr.tstorm_waitp = REG_RD(bp, TSTORM_WAITP_ADDR);
  513. dump_hdr.ustorm_waitp = REG_RD(bp, USTORM_WAITP_ADDR);
  514. dump_hdr.cstorm_waitp = REG_RD(bp, CSTORM_WAITP_ADDR);
  515. if (CHIP_IS_E1(bp))
  516. dump_hdr.info = RI_E1_ONLINE;
  517. else if (CHIP_IS_E1H(bp))
  518. dump_hdr.info = RI_E1H_ONLINE;
  519. else if (CHIP_IS_E2(bp))
  520. dump_hdr.info = RI_E2_ONLINE |
  521. (BP_PATH(bp) ? RI_PATH1_DUMP : RI_PATH0_DUMP);
  522. memcpy(p, &dump_hdr, sizeof(struct dump_hdr));
  523. p += dump_hdr.hdr_size + 1;
  524. if (CHIP_IS_E1(bp)) {
  525. for (i = 0; i < REGS_COUNT; i++)
  526. if (IS_E1_ONLINE(reg_addrs[i].info))
  527. for (j = 0; j < reg_addrs[i].size; j++)
  528. *p++ = REG_RD(bp,
  529. reg_addrs[i].addr + j*4);
  530. } else if (CHIP_IS_E1H(bp)) {
  531. for (i = 0; i < REGS_COUNT; i++)
  532. if (IS_E1H_ONLINE(reg_addrs[i].info))
  533. for (j = 0; j < reg_addrs[i].size; j++)
  534. *p++ = REG_RD(bp,
  535. reg_addrs[i].addr + j*4);
  536. } else if (CHIP_IS_E2(bp)) {
  537. for (i = 0; i < REGS_COUNT; i++)
  538. if (IS_E2_ONLINE(reg_addrs[i].info))
  539. for (j = 0; j < reg_addrs[i].size; j++)
  540. *p++ = REG_RD(bp,
  541. reg_addrs[i].addr + j*4);
  542. bnx2x_read_pages_regs_e2(bp, p);
  543. }
  544. /* Re-enable parity attentions */
  545. bnx2x_clear_blocks_parity(bp);
  546. if (CHIP_PARITY_ENABLED(bp))
  547. bnx2x_enable_blocks_parity(bp);
  548. }
  549. #define PHY_FW_VER_LEN 20
  550. static void bnx2x_get_drvinfo(struct net_device *dev,
  551. struct ethtool_drvinfo *info)
  552. {
  553. struct bnx2x *bp = netdev_priv(dev);
  554. u8 phy_fw_ver[PHY_FW_VER_LEN];
  555. strcpy(info->driver, DRV_MODULE_NAME);
  556. strcpy(info->version, DRV_MODULE_VERSION);
  557. phy_fw_ver[0] = '\0';
  558. if (bp->port.pmf) {
  559. bnx2x_acquire_phy_lock(bp);
  560. bnx2x_get_ext_phy_fw_version(&bp->link_params,
  561. (bp->state != BNX2X_STATE_CLOSED),
  562. phy_fw_ver, PHY_FW_VER_LEN);
  563. bnx2x_release_phy_lock(bp);
  564. }
  565. strncpy(info->fw_version, bp->fw_ver, 32);
  566. snprintf(info->fw_version + strlen(bp->fw_ver), 32 - strlen(bp->fw_ver),
  567. "bc %d.%d.%d%s%s",
  568. (bp->common.bc_ver & 0xff0000) >> 16,
  569. (bp->common.bc_ver & 0xff00) >> 8,
  570. (bp->common.bc_ver & 0xff),
  571. ((phy_fw_ver[0] != '\0') ? " phy " : ""), phy_fw_ver);
  572. strcpy(info->bus_info, pci_name(bp->pdev));
  573. info->n_stats = BNX2X_NUM_STATS;
  574. info->testinfo_len = BNX2X_NUM_TESTS;
  575. info->eedump_len = bp->common.flash_size;
  576. info->regdump_len = bnx2x_get_regs_len(dev);
  577. }
  578. static void bnx2x_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  579. {
  580. struct bnx2x *bp = netdev_priv(dev);
  581. if (bp->flags & NO_WOL_FLAG) {
  582. wol->supported = 0;
  583. wol->wolopts = 0;
  584. } else {
  585. wol->supported = WAKE_MAGIC;
  586. if (bp->wol)
  587. wol->wolopts = WAKE_MAGIC;
  588. else
  589. wol->wolopts = 0;
  590. }
  591. memset(&wol->sopass, 0, sizeof(wol->sopass));
  592. }
  593. static int bnx2x_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  594. {
  595. struct bnx2x *bp = netdev_priv(dev);
  596. if (wol->wolopts & ~WAKE_MAGIC)
  597. return -EINVAL;
  598. if (wol->wolopts & WAKE_MAGIC) {
  599. if (bp->flags & NO_WOL_FLAG)
  600. return -EINVAL;
  601. bp->wol = 1;
  602. } else
  603. bp->wol = 0;
  604. return 0;
  605. }
  606. static u32 bnx2x_get_msglevel(struct net_device *dev)
  607. {
  608. struct bnx2x *bp = netdev_priv(dev);
  609. return bp->msg_enable;
  610. }
  611. static void bnx2x_set_msglevel(struct net_device *dev, u32 level)
  612. {
  613. struct bnx2x *bp = netdev_priv(dev);
  614. if (capable(CAP_NET_ADMIN)) {
  615. /* dump MCP trace */
  616. if (level & BNX2X_MSG_MCP)
  617. bnx2x_fw_dump_lvl(bp, KERN_INFO);
  618. bp->msg_enable = level;
  619. }
  620. }
  621. static int bnx2x_nway_reset(struct net_device *dev)
  622. {
  623. struct bnx2x *bp = netdev_priv(dev);
  624. if (!bp->port.pmf)
  625. return 0;
  626. if (netif_running(dev)) {
  627. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  628. bnx2x_link_set(bp);
  629. }
  630. return 0;
  631. }
  632. static u32 bnx2x_get_link(struct net_device *dev)
  633. {
  634. struct bnx2x *bp = netdev_priv(dev);
  635. if (bp->flags & MF_FUNC_DIS || (bp->state != BNX2X_STATE_OPEN))
  636. return 0;
  637. return bp->link_vars.link_up;
  638. }
  639. static int bnx2x_get_eeprom_len(struct net_device *dev)
  640. {
  641. struct bnx2x *bp = netdev_priv(dev);
  642. return bp->common.flash_size;
  643. }
  644. static int bnx2x_acquire_nvram_lock(struct bnx2x *bp)
  645. {
  646. int port = BP_PORT(bp);
  647. int count, i;
  648. u32 val = 0;
  649. /* adjust timeout for emulation/FPGA */
  650. count = NVRAM_TIMEOUT_COUNT;
  651. if (CHIP_REV_IS_SLOW(bp))
  652. count *= 100;
  653. /* request access to nvram interface */
  654. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  655. (MCPR_NVM_SW_ARB_ARB_REQ_SET1 << port));
  656. for (i = 0; i < count*10; i++) {
  657. val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB);
  658. if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))
  659. break;
  660. udelay(5);
  661. }
  662. if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))) {
  663. DP(BNX2X_MSG_NVM, "cannot get access to nvram interface\n");
  664. return -EBUSY;
  665. }
  666. return 0;
  667. }
  668. static int bnx2x_release_nvram_lock(struct bnx2x *bp)
  669. {
  670. int port = BP_PORT(bp);
  671. int count, i;
  672. u32 val = 0;
  673. /* adjust timeout for emulation/FPGA */
  674. count = NVRAM_TIMEOUT_COUNT;
  675. if (CHIP_REV_IS_SLOW(bp))
  676. count *= 100;
  677. /* relinquish nvram interface */
  678. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  679. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << port));
  680. for (i = 0; i < count*10; i++) {
  681. val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB);
  682. if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)))
  683. break;
  684. udelay(5);
  685. }
  686. if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)) {
  687. DP(BNX2X_MSG_NVM, "cannot free access to nvram interface\n");
  688. return -EBUSY;
  689. }
  690. return 0;
  691. }
  692. static void bnx2x_enable_nvram_access(struct bnx2x *bp)
  693. {
  694. u32 val;
  695. val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
  696. /* enable both bits, even on read */
  697. REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
  698. (val | MCPR_NVM_ACCESS_ENABLE_EN |
  699. MCPR_NVM_ACCESS_ENABLE_WR_EN));
  700. }
  701. static void bnx2x_disable_nvram_access(struct bnx2x *bp)
  702. {
  703. u32 val;
  704. val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
  705. /* disable both bits, even after read */
  706. REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
  707. (val & ~(MCPR_NVM_ACCESS_ENABLE_EN |
  708. MCPR_NVM_ACCESS_ENABLE_WR_EN)));
  709. }
  710. static int bnx2x_nvram_read_dword(struct bnx2x *bp, u32 offset, __be32 *ret_val,
  711. u32 cmd_flags)
  712. {
  713. int count, i, rc;
  714. u32 val;
  715. /* build the command word */
  716. cmd_flags |= MCPR_NVM_COMMAND_DOIT;
  717. /* need to clear DONE bit separately */
  718. REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
  719. /* address of the NVRAM to read from */
  720. REG_WR(bp, MCP_REG_MCPR_NVM_ADDR,
  721. (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
  722. /* issue a read command */
  723. REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
  724. /* adjust timeout for emulation/FPGA */
  725. count = NVRAM_TIMEOUT_COUNT;
  726. if (CHIP_REV_IS_SLOW(bp))
  727. count *= 100;
  728. /* wait for completion */
  729. *ret_val = 0;
  730. rc = -EBUSY;
  731. for (i = 0; i < count; i++) {
  732. udelay(5);
  733. val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND);
  734. if (val & MCPR_NVM_COMMAND_DONE) {
  735. val = REG_RD(bp, MCP_REG_MCPR_NVM_READ);
  736. /* we read nvram data in cpu order
  737. * but ethtool sees it as an array of bytes
  738. * converting to big-endian will do the work */
  739. *ret_val = cpu_to_be32(val);
  740. rc = 0;
  741. break;
  742. }
  743. }
  744. return rc;
  745. }
  746. static int bnx2x_nvram_read(struct bnx2x *bp, u32 offset, u8 *ret_buf,
  747. int buf_size)
  748. {
  749. int rc;
  750. u32 cmd_flags;
  751. __be32 val;
  752. if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
  753. DP(BNX2X_MSG_NVM,
  754. "Invalid parameter: offset 0x%x buf_size 0x%x\n",
  755. offset, buf_size);
  756. return -EINVAL;
  757. }
  758. if (offset + buf_size > bp->common.flash_size) {
  759. DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
  760. " buf_size (0x%x) > flash_size (0x%x)\n",
  761. offset, buf_size, bp->common.flash_size);
  762. return -EINVAL;
  763. }
  764. /* request access to nvram interface */
  765. rc = bnx2x_acquire_nvram_lock(bp);
  766. if (rc)
  767. return rc;
  768. /* enable access to nvram interface */
  769. bnx2x_enable_nvram_access(bp);
  770. /* read the first word(s) */
  771. cmd_flags = MCPR_NVM_COMMAND_FIRST;
  772. while ((buf_size > sizeof(u32)) && (rc == 0)) {
  773. rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags);
  774. memcpy(ret_buf, &val, 4);
  775. /* advance to the next dword */
  776. offset += sizeof(u32);
  777. ret_buf += sizeof(u32);
  778. buf_size -= sizeof(u32);
  779. cmd_flags = 0;
  780. }
  781. if (rc == 0) {
  782. cmd_flags |= MCPR_NVM_COMMAND_LAST;
  783. rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags);
  784. memcpy(ret_buf, &val, 4);
  785. }
  786. /* disable access to nvram interface */
  787. bnx2x_disable_nvram_access(bp);
  788. bnx2x_release_nvram_lock(bp);
  789. return rc;
  790. }
  791. static int bnx2x_get_eeprom(struct net_device *dev,
  792. struct ethtool_eeprom *eeprom, u8 *eebuf)
  793. {
  794. struct bnx2x *bp = netdev_priv(dev);
  795. int rc;
  796. if (!netif_running(dev))
  797. return -EAGAIN;
  798. DP(BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n"
  799. DP_LEVEL " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
  800. eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset,
  801. eeprom->len, eeprom->len);
  802. /* parameters already validated in ethtool_get_eeprom */
  803. rc = bnx2x_nvram_read(bp, eeprom->offset, eebuf, eeprom->len);
  804. return rc;
  805. }
  806. static int bnx2x_nvram_write_dword(struct bnx2x *bp, u32 offset, u32 val,
  807. u32 cmd_flags)
  808. {
  809. int count, i, rc;
  810. /* build the command word */
  811. cmd_flags |= MCPR_NVM_COMMAND_DOIT | MCPR_NVM_COMMAND_WR;
  812. /* need to clear DONE bit separately */
  813. REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
  814. /* write the data */
  815. REG_WR(bp, MCP_REG_MCPR_NVM_WRITE, val);
  816. /* address of the NVRAM to write to */
  817. REG_WR(bp, MCP_REG_MCPR_NVM_ADDR,
  818. (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
  819. /* issue the write command */
  820. REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
  821. /* adjust timeout for emulation/FPGA */
  822. count = NVRAM_TIMEOUT_COUNT;
  823. if (CHIP_REV_IS_SLOW(bp))
  824. count *= 100;
  825. /* wait for completion */
  826. rc = -EBUSY;
  827. for (i = 0; i < count; i++) {
  828. udelay(5);
  829. val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND);
  830. if (val & MCPR_NVM_COMMAND_DONE) {
  831. rc = 0;
  832. break;
  833. }
  834. }
  835. return rc;
  836. }
  837. #define BYTE_OFFSET(offset) (8 * (offset & 0x03))
  838. static int bnx2x_nvram_write1(struct bnx2x *bp, u32 offset, u8 *data_buf,
  839. int buf_size)
  840. {
  841. int rc;
  842. u32 cmd_flags;
  843. u32 align_offset;
  844. __be32 val;
  845. if (offset + buf_size > bp->common.flash_size) {
  846. DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
  847. " buf_size (0x%x) > flash_size (0x%x)\n",
  848. offset, buf_size, bp->common.flash_size);
  849. return -EINVAL;
  850. }
  851. /* request access to nvram interface */
  852. rc = bnx2x_acquire_nvram_lock(bp);
  853. if (rc)
  854. return rc;
  855. /* enable access to nvram interface */
  856. bnx2x_enable_nvram_access(bp);
  857. cmd_flags = (MCPR_NVM_COMMAND_FIRST | MCPR_NVM_COMMAND_LAST);
  858. align_offset = (offset & ~0x03);
  859. rc = bnx2x_nvram_read_dword(bp, align_offset, &val, cmd_flags);
  860. if (rc == 0) {
  861. val &= ~(0xff << BYTE_OFFSET(offset));
  862. val |= (*data_buf << BYTE_OFFSET(offset));
  863. /* nvram data is returned as an array of bytes
  864. * convert it back to cpu order */
  865. val = be32_to_cpu(val);
  866. rc = bnx2x_nvram_write_dword(bp, align_offset, val,
  867. cmd_flags);
  868. }
  869. /* disable access to nvram interface */
  870. bnx2x_disable_nvram_access(bp);
  871. bnx2x_release_nvram_lock(bp);
  872. return rc;
  873. }
  874. static int bnx2x_nvram_write(struct bnx2x *bp, u32 offset, u8 *data_buf,
  875. int buf_size)
  876. {
  877. int rc;
  878. u32 cmd_flags;
  879. u32 val;
  880. u32 written_so_far;
  881. if (buf_size == 1) /* ethtool */
  882. return bnx2x_nvram_write1(bp, offset, data_buf, buf_size);
  883. if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
  884. DP(BNX2X_MSG_NVM,
  885. "Invalid parameter: offset 0x%x buf_size 0x%x\n",
  886. offset, buf_size);
  887. return -EINVAL;
  888. }
  889. if (offset + buf_size > bp->common.flash_size) {
  890. DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
  891. " buf_size (0x%x) > flash_size (0x%x)\n",
  892. offset, buf_size, bp->common.flash_size);
  893. return -EINVAL;
  894. }
  895. /* request access to nvram interface */
  896. rc = bnx2x_acquire_nvram_lock(bp);
  897. if (rc)
  898. return rc;
  899. /* enable access to nvram interface */
  900. bnx2x_enable_nvram_access(bp);
  901. written_so_far = 0;
  902. cmd_flags = MCPR_NVM_COMMAND_FIRST;
  903. while ((written_so_far < buf_size) && (rc == 0)) {
  904. if (written_so_far == (buf_size - sizeof(u32)))
  905. cmd_flags |= MCPR_NVM_COMMAND_LAST;
  906. else if (((offset + 4) % NVRAM_PAGE_SIZE) == 0)
  907. cmd_flags |= MCPR_NVM_COMMAND_LAST;
  908. else if ((offset % NVRAM_PAGE_SIZE) == 0)
  909. cmd_flags |= MCPR_NVM_COMMAND_FIRST;
  910. memcpy(&val, data_buf, 4);
  911. rc = bnx2x_nvram_write_dword(bp, offset, val, cmd_flags);
  912. /* advance to the next dword */
  913. offset += sizeof(u32);
  914. data_buf += sizeof(u32);
  915. written_so_far += sizeof(u32);
  916. cmd_flags = 0;
  917. }
  918. /* disable access to nvram interface */
  919. bnx2x_disable_nvram_access(bp);
  920. bnx2x_release_nvram_lock(bp);
  921. return rc;
  922. }
  923. static int bnx2x_set_eeprom(struct net_device *dev,
  924. struct ethtool_eeprom *eeprom, u8 *eebuf)
  925. {
  926. struct bnx2x *bp = netdev_priv(dev);
  927. int port = BP_PORT(bp);
  928. int rc = 0;
  929. u32 ext_phy_config;
  930. if (!netif_running(dev))
  931. return -EAGAIN;
  932. DP(BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n"
  933. DP_LEVEL " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
  934. eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset,
  935. eeprom->len, eeprom->len);
  936. /* parameters already validated in ethtool_set_eeprom */
  937. /* PHY eeprom can be accessed only by the PMF */
  938. if ((eeprom->magic >= 0x50485900) && (eeprom->magic <= 0x504859FF) &&
  939. !bp->port.pmf)
  940. return -EINVAL;
  941. ext_phy_config =
  942. SHMEM_RD(bp,
  943. dev_info.port_hw_config[port].external_phy_config);
  944. if (eeprom->magic == 0x50485950) {
  945. /* 'PHYP' (0x50485950): prepare phy for FW upgrade */
  946. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  947. bnx2x_acquire_phy_lock(bp);
  948. rc |= bnx2x_link_reset(&bp->link_params,
  949. &bp->link_vars, 0);
  950. if (XGXS_EXT_PHY_TYPE(ext_phy_config) ==
  951. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101)
  952. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
  953. MISC_REGISTERS_GPIO_HIGH, port);
  954. bnx2x_release_phy_lock(bp);
  955. bnx2x_link_report(bp);
  956. } else if (eeprom->magic == 0x50485952) {
  957. /* 'PHYR' (0x50485952): re-init link after FW upgrade */
  958. if (bp->state == BNX2X_STATE_OPEN) {
  959. bnx2x_acquire_phy_lock(bp);
  960. rc |= bnx2x_link_reset(&bp->link_params,
  961. &bp->link_vars, 1);
  962. rc |= bnx2x_phy_init(&bp->link_params,
  963. &bp->link_vars);
  964. bnx2x_release_phy_lock(bp);
  965. bnx2x_calc_fc_adv(bp);
  966. }
  967. } else if (eeprom->magic == 0x53985943) {
  968. /* 'PHYC' (0x53985943): PHY FW upgrade completed */
  969. if (XGXS_EXT_PHY_TYPE(ext_phy_config) ==
  970. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101) {
  971. /* DSP Remove Download Mode */
  972. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
  973. MISC_REGISTERS_GPIO_LOW, port);
  974. bnx2x_acquire_phy_lock(bp);
  975. bnx2x_sfx7101_sp_sw_reset(bp,
  976. &bp->link_params.phy[EXT_PHY1]);
  977. /* wait 0.5 sec to allow it to run */
  978. msleep(500);
  979. bnx2x_ext_phy_hw_reset(bp, port);
  980. msleep(500);
  981. bnx2x_release_phy_lock(bp);
  982. }
  983. } else
  984. rc = bnx2x_nvram_write(bp, eeprom->offset, eebuf, eeprom->len);
  985. return rc;
  986. }
  987. static int bnx2x_get_coalesce(struct net_device *dev,
  988. struct ethtool_coalesce *coal)
  989. {
  990. struct bnx2x *bp = netdev_priv(dev);
  991. memset(coal, 0, sizeof(struct ethtool_coalesce));
  992. coal->rx_coalesce_usecs = bp->rx_ticks;
  993. coal->tx_coalesce_usecs = bp->tx_ticks;
  994. return 0;
  995. }
  996. static int bnx2x_set_coalesce(struct net_device *dev,
  997. struct ethtool_coalesce *coal)
  998. {
  999. struct bnx2x *bp = netdev_priv(dev);
  1000. bp->rx_ticks = (u16)coal->rx_coalesce_usecs;
  1001. if (bp->rx_ticks > BNX2X_MAX_COALESCE_TOUT)
  1002. bp->rx_ticks = BNX2X_MAX_COALESCE_TOUT;
  1003. bp->tx_ticks = (u16)coal->tx_coalesce_usecs;
  1004. if (bp->tx_ticks > BNX2X_MAX_COALESCE_TOUT)
  1005. bp->tx_ticks = BNX2X_MAX_COALESCE_TOUT;
  1006. if (netif_running(dev))
  1007. bnx2x_update_coalesce(bp);
  1008. return 0;
  1009. }
  1010. static void bnx2x_get_ringparam(struct net_device *dev,
  1011. struct ethtool_ringparam *ering)
  1012. {
  1013. struct bnx2x *bp = netdev_priv(dev);
  1014. ering->rx_max_pending = MAX_RX_AVAIL;
  1015. ering->rx_mini_max_pending = 0;
  1016. ering->rx_jumbo_max_pending = 0;
  1017. if (bp->rx_ring_size)
  1018. ering->rx_pending = bp->rx_ring_size;
  1019. else
  1020. if (bp->state == BNX2X_STATE_OPEN && bp->num_queues)
  1021. ering->rx_pending = MAX_RX_AVAIL/bp->num_queues;
  1022. else
  1023. ering->rx_pending = MAX_RX_AVAIL;
  1024. ering->rx_mini_pending = 0;
  1025. ering->rx_jumbo_pending = 0;
  1026. ering->tx_max_pending = MAX_TX_AVAIL;
  1027. ering->tx_pending = bp->tx_ring_size;
  1028. }
  1029. static int bnx2x_set_ringparam(struct net_device *dev,
  1030. struct ethtool_ringparam *ering)
  1031. {
  1032. struct bnx2x *bp = netdev_priv(dev);
  1033. int rc = 0;
  1034. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  1035. printk(KERN_ERR "Handling parity error recovery. Try again later\n");
  1036. return -EAGAIN;
  1037. }
  1038. if ((ering->rx_pending > MAX_RX_AVAIL) ||
  1039. (ering->rx_pending < (bp->disable_tpa ? MIN_RX_SIZE_NONTPA :
  1040. MIN_RX_SIZE_TPA)) ||
  1041. (ering->tx_pending > MAX_TX_AVAIL) ||
  1042. (ering->tx_pending <= MAX_SKB_FRAGS + 4))
  1043. return -EINVAL;
  1044. bp->rx_ring_size = ering->rx_pending;
  1045. bp->tx_ring_size = ering->tx_pending;
  1046. if (netif_running(dev)) {
  1047. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  1048. rc = bnx2x_nic_load(bp, LOAD_NORMAL);
  1049. }
  1050. return rc;
  1051. }
  1052. static void bnx2x_get_pauseparam(struct net_device *dev,
  1053. struct ethtool_pauseparam *epause)
  1054. {
  1055. struct bnx2x *bp = netdev_priv(dev);
  1056. int cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1057. epause->autoneg = (bp->link_params.req_flow_ctrl[cfg_idx] ==
  1058. BNX2X_FLOW_CTRL_AUTO);
  1059. epause->rx_pause = ((bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_RX) ==
  1060. BNX2X_FLOW_CTRL_RX);
  1061. epause->tx_pause = ((bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX) ==
  1062. BNX2X_FLOW_CTRL_TX);
  1063. DP(NETIF_MSG_LINK, "ethtool_pauseparam: cmd %d\n"
  1064. DP_LEVEL " autoneg %d rx_pause %d tx_pause %d\n",
  1065. epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);
  1066. }
  1067. static int bnx2x_set_pauseparam(struct net_device *dev,
  1068. struct ethtool_pauseparam *epause)
  1069. {
  1070. struct bnx2x *bp = netdev_priv(dev);
  1071. u32 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1072. if (IS_MF(bp))
  1073. return 0;
  1074. DP(NETIF_MSG_LINK, "ethtool_pauseparam: cmd %d\n"
  1075. DP_LEVEL " autoneg %d rx_pause %d tx_pause %d\n",
  1076. epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);
  1077. bp->link_params.req_flow_ctrl[cfg_idx] = BNX2X_FLOW_CTRL_AUTO;
  1078. if (epause->rx_pause)
  1079. bp->link_params.req_flow_ctrl[cfg_idx] |= BNX2X_FLOW_CTRL_RX;
  1080. if (epause->tx_pause)
  1081. bp->link_params.req_flow_ctrl[cfg_idx] |= BNX2X_FLOW_CTRL_TX;
  1082. if (bp->link_params.req_flow_ctrl[cfg_idx] == BNX2X_FLOW_CTRL_AUTO)
  1083. bp->link_params.req_flow_ctrl[cfg_idx] = BNX2X_FLOW_CTRL_NONE;
  1084. if (epause->autoneg) {
  1085. if (!(bp->port.supported[cfg_idx] & SUPPORTED_Autoneg)) {
  1086. DP(NETIF_MSG_LINK, "autoneg not supported\n");
  1087. return -EINVAL;
  1088. }
  1089. if (bp->link_params.req_line_speed[cfg_idx] == SPEED_AUTO_NEG) {
  1090. bp->link_params.req_flow_ctrl[cfg_idx] =
  1091. BNX2X_FLOW_CTRL_AUTO;
  1092. }
  1093. }
  1094. DP(NETIF_MSG_LINK,
  1095. "req_flow_ctrl 0x%x\n", bp->link_params.req_flow_ctrl[cfg_idx]);
  1096. if (netif_running(dev)) {
  1097. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  1098. bnx2x_link_set(bp);
  1099. }
  1100. return 0;
  1101. }
  1102. static const struct {
  1103. char string[ETH_GSTRING_LEN];
  1104. } bnx2x_tests_str_arr[BNX2X_NUM_TESTS] = {
  1105. { "register_test (offline)" },
  1106. { "memory_test (offline)" },
  1107. { "loopback_test (offline)" },
  1108. { "nvram_test (online)" },
  1109. { "interrupt_test (online)" },
  1110. { "link_test (online)" },
  1111. { "idle check (online)" }
  1112. };
  1113. static int bnx2x_test_registers(struct bnx2x *bp)
  1114. {
  1115. int idx, i, rc = -ENODEV;
  1116. u32 wr_val = 0;
  1117. int port = BP_PORT(bp);
  1118. static const struct {
  1119. u32 offset0;
  1120. u32 offset1;
  1121. u32 mask;
  1122. } reg_tbl[] = {
  1123. /* 0 */ { BRB1_REG_PAUSE_LOW_THRESHOLD_0, 4, 0x000003ff },
  1124. { DORQ_REG_DB_ADDR0, 4, 0xffffffff },
  1125. { HC_REG_AGG_INT_0, 4, 0x000003ff },
  1126. { PBF_REG_MAC_IF0_ENABLE, 4, 0x00000001 },
  1127. { PBF_REG_P0_INIT_CRD, 4, 0x000007ff },
  1128. { PRS_REG_CID_PORT_0, 4, 0x00ffffff },
  1129. { PXP2_REG_PSWRQ_CDU0_L2P, 4, 0x000fffff },
  1130. { PXP2_REG_RQ_CDU0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
  1131. { PXP2_REG_PSWRQ_TM0_L2P, 4, 0x000fffff },
  1132. { PXP2_REG_RQ_USDM0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
  1133. /* 10 */ { PXP2_REG_PSWRQ_TSDM0_L2P, 4, 0x000fffff },
  1134. { QM_REG_CONNNUM_0, 4, 0x000fffff },
  1135. { TM_REG_LIN0_MAX_ACTIVE_CID, 4, 0x0003ffff },
  1136. { SRC_REG_KEYRSS0_0, 40, 0xffffffff },
  1137. { SRC_REG_KEYRSS0_7, 40, 0xffffffff },
  1138. { XCM_REG_WU_DA_SET_TMR_CNT_FLG_CMD00, 4, 0x00000001 },
  1139. { XCM_REG_WU_DA_CNT_CMD00, 4, 0x00000003 },
  1140. { XCM_REG_GLB_DEL_ACK_MAX_CNT_0, 4, 0x000000ff },
  1141. { NIG_REG_LLH0_T_BIT, 4, 0x00000001 },
  1142. { NIG_REG_EMAC0_IN_EN, 4, 0x00000001 },
  1143. /* 20 */ { NIG_REG_BMAC0_IN_EN, 4, 0x00000001 },
  1144. { NIG_REG_XCM0_OUT_EN, 4, 0x00000001 },
  1145. { NIG_REG_BRB0_OUT_EN, 4, 0x00000001 },
  1146. { NIG_REG_LLH0_XCM_MASK, 4, 0x00000007 },
  1147. { NIG_REG_LLH0_ACPI_PAT_6_LEN, 68, 0x000000ff },
  1148. { NIG_REG_LLH0_ACPI_PAT_0_CRC, 68, 0xffffffff },
  1149. { NIG_REG_LLH0_DEST_MAC_0_0, 160, 0xffffffff },
  1150. { NIG_REG_LLH0_DEST_IP_0_1, 160, 0xffffffff },
  1151. { NIG_REG_LLH0_IPV4_IPV6_0, 160, 0x00000001 },
  1152. { NIG_REG_LLH0_DEST_UDP_0, 160, 0x0000ffff },
  1153. /* 30 */ { NIG_REG_LLH0_DEST_TCP_0, 160, 0x0000ffff },
  1154. { NIG_REG_LLH0_VLAN_ID_0, 160, 0x00000fff },
  1155. { NIG_REG_XGXS_SERDES0_MODE_SEL, 4, 0x00000001 },
  1156. { NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0, 4, 0x00000001 },
  1157. { NIG_REG_STATUS_INTERRUPT_PORT0, 4, 0x07ffffff },
  1158. { NIG_REG_XGXS0_CTRL_EXTREMOTEMDIOST, 24, 0x00000001 },
  1159. { NIG_REG_SERDES0_CTRL_PHY_ADDR, 16, 0x0000001f },
  1160. { 0xffffffff, 0, 0x00000000 }
  1161. };
  1162. if (!netif_running(bp->dev))
  1163. return rc;
  1164. /* Repeat the test twice:
  1165. First by writing 0x00000000, second by writing 0xffffffff */
  1166. for (idx = 0; idx < 2; idx++) {
  1167. switch (idx) {
  1168. case 0:
  1169. wr_val = 0;
  1170. break;
  1171. case 1:
  1172. wr_val = 0xffffffff;
  1173. break;
  1174. }
  1175. for (i = 0; reg_tbl[i].offset0 != 0xffffffff; i++) {
  1176. u32 offset, mask, save_val, val;
  1177. if (CHIP_IS_E2(bp) &&
  1178. reg_tbl[i].offset0 == HC_REG_AGG_INT_0)
  1179. continue;
  1180. offset = reg_tbl[i].offset0 + port*reg_tbl[i].offset1;
  1181. mask = reg_tbl[i].mask;
  1182. save_val = REG_RD(bp, offset);
  1183. REG_WR(bp, offset, wr_val & mask);
  1184. val = REG_RD(bp, offset);
  1185. /* Restore the original register's value */
  1186. REG_WR(bp, offset, save_val);
  1187. /* verify value is as expected */
  1188. if ((val & mask) != (wr_val & mask)) {
  1189. DP(NETIF_MSG_PROBE,
  1190. "offset 0x%x: val 0x%x != 0x%x mask 0x%x\n",
  1191. offset, val, wr_val, mask);
  1192. goto test_reg_exit;
  1193. }
  1194. }
  1195. }
  1196. rc = 0;
  1197. test_reg_exit:
  1198. return rc;
  1199. }
  1200. static int bnx2x_test_memory(struct bnx2x *bp)
  1201. {
  1202. int i, j, rc = -ENODEV;
  1203. u32 val;
  1204. static const struct {
  1205. u32 offset;
  1206. int size;
  1207. } mem_tbl[] = {
  1208. { CCM_REG_XX_DESCR_TABLE, CCM_REG_XX_DESCR_TABLE_SIZE },
  1209. { CFC_REG_ACTIVITY_COUNTER, CFC_REG_ACTIVITY_COUNTER_SIZE },
  1210. { CFC_REG_LINK_LIST, CFC_REG_LINK_LIST_SIZE },
  1211. { DMAE_REG_CMD_MEM, DMAE_REG_CMD_MEM_SIZE },
  1212. { TCM_REG_XX_DESCR_TABLE, TCM_REG_XX_DESCR_TABLE_SIZE },
  1213. { UCM_REG_XX_DESCR_TABLE, UCM_REG_XX_DESCR_TABLE_SIZE },
  1214. { XCM_REG_XX_DESCR_TABLE, XCM_REG_XX_DESCR_TABLE_SIZE },
  1215. { 0xffffffff, 0 }
  1216. };
  1217. static const struct {
  1218. char *name;
  1219. u32 offset;
  1220. u32 e1_mask;
  1221. u32 e1h_mask;
  1222. u32 e2_mask;
  1223. } prty_tbl[] = {
  1224. { "CCM_PRTY_STS", CCM_REG_CCM_PRTY_STS, 0x3ffc0, 0, 0 },
  1225. { "CFC_PRTY_STS", CFC_REG_CFC_PRTY_STS, 0x2, 0x2, 0 },
  1226. { "DMAE_PRTY_STS", DMAE_REG_DMAE_PRTY_STS, 0, 0, 0 },
  1227. { "TCM_PRTY_STS", TCM_REG_TCM_PRTY_STS, 0x3ffc0, 0, 0 },
  1228. { "UCM_PRTY_STS", UCM_REG_UCM_PRTY_STS, 0x3ffc0, 0, 0 },
  1229. { "XCM_PRTY_STS", XCM_REG_XCM_PRTY_STS, 0x3ffc1, 0, 0 },
  1230. { NULL, 0xffffffff, 0, 0, 0 }
  1231. };
  1232. if (!netif_running(bp->dev))
  1233. return rc;
  1234. /* pre-Check the parity status */
  1235. for (i = 0; prty_tbl[i].offset != 0xffffffff; i++) {
  1236. val = REG_RD(bp, prty_tbl[i].offset);
  1237. if ((CHIP_IS_E1(bp) && (val & ~(prty_tbl[i].e1_mask))) ||
  1238. (CHIP_IS_E1H(bp) && (val & ~(prty_tbl[i].e1h_mask))) ||
  1239. (CHIP_IS_E2(bp) && (val & ~(prty_tbl[i].e2_mask)))) {
  1240. DP(NETIF_MSG_HW,
  1241. "%s is 0x%x\n", prty_tbl[i].name, val);
  1242. goto test_mem_exit;
  1243. }
  1244. }
  1245. /* Go through all the memories */
  1246. for (i = 0; mem_tbl[i].offset != 0xffffffff; i++)
  1247. for (j = 0; j < mem_tbl[i].size; j++)
  1248. REG_RD(bp, mem_tbl[i].offset + j*4);
  1249. /* Check the parity status */
  1250. for (i = 0; prty_tbl[i].offset != 0xffffffff; i++) {
  1251. val = REG_RD(bp, prty_tbl[i].offset);
  1252. if ((CHIP_IS_E1(bp) && (val & ~(prty_tbl[i].e1_mask))) ||
  1253. (CHIP_IS_E1H(bp) && (val & ~(prty_tbl[i].e1h_mask))) ||
  1254. (CHIP_IS_E2(bp) && (val & ~(prty_tbl[i].e2_mask)))) {
  1255. DP(NETIF_MSG_HW,
  1256. "%s is 0x%x\n", prty_tbl[i].name, val);
  1257. goto test_mem_exit;
  1258. }
  1259. }
  1260. rc = 0;
  1261. test_mem_exit:
  1262. return rc;
  1263. }
  1264. static void bnx2x_wait_for_link(struct bnx2x *bp, u8 link_up, u8 is_serdes)
  1265. {
  1266. int cnt = 1400;
  1267. if (link_up)
  1268. while (bnx2x_link_test(bp, is_serdes) && cnt--)
  1269. msleep(10);
  1270. }
  1271. static int bnx2x_run_loopback(struct bnx2x *bp, int loopback_mode, u8 link_up)
  1272. {
  1273. unsigned int pkt_size, num_pkts, i;
  1274. struct sk_buff *skb;
  1275. unsigned char *packet;
  1276. struct bnx2x_fastpath *fp_rx = &bp->fp[0];
  1277. struct bnx2x_fastpath *fp_tx = &bp->fp[0];
  1278. u16 tx_start_idx, tx_idx;
  1279. u16 rx_start_idx, rx_idx;
  1280. u16 pkt_prod, bd_prod;
  1281. struct sw_tx_bd *tx_buf;
  1282. struct eth_tx_start_bd *tx_start_bd;
  1283. struct eth_tx_parse_bd_e1x *pbd_e1x = NULL;
  1284. struct eth_tx_parse_bd_e2 *pbd_e2 = NULL;
  1285. dma_addr_t mapping;
  1286. union eth_rx_cqe *cqe;
  1287. u8 cqe_fp_flags;
  1288. struct sw_rx_bd *rx_buf;
  1289. u16 len;
  1290. int rc = -ENODEV;
  1291. /* check the loopback mode */
  1292. switch (loopback_mode) {
  1293. case BNX2X_PHY_LOOPBACK:
  1294. if (bp->link_params.loopback_mode != LOOPBACK_XGXS)
  1295. return -EINVAL;
  1296. break;
  1297. case BNX2X_MAC_LOOPBACK:
  1298. bp->link_params.loopback_mode = LOOPBACK_BMAC;
  1299. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1300. break;
  1301. default:
  1302. return -EINVAL;
  1303. }
  1304. /* prepare the loopback packet */
  1305. pkt_size = (((bp->dev->mtu < ETH_MAX_PACKET_SIZE) ?
  1306. bp->dev->mtu : ETH_MAX_PACKET_SIZE) + ETH_HLEN);
  1307. skb = netdev_alloc_skb(bp->dev, fp_rx->rx_buf_size);
  1308. if (!skb) {
  1309. rc = -ENOMEM;
  1310. goto test_loopback_exit;
  1311. }
  1312. packet = skb_put(skb, pkt_size);
  1313. memcpy(packet, bp->dev->dev_addr, ETH_ALEN);
  1314. memset(packet + ETH_ALEN, 0, ETH_ALEN);
  1315. memset(packet + 2*ETH_ALEN, 0x77, (ETH_HLEN - 2*ETH_ALEN));
  1316. for (i = ETH_HLEN; i < pkt_size; i++)
  1317. packet[i] = (unsigned char) (i & 0xff);
  1318. /* send the loopback packet */
  1319. num_pkts = 0;
  1320. tx_start_idx = le16_to_cpu(*fp_tx->tx_cons_sb);
  1321. rx_start_idx = le16_to_cpu(*fp_rx->rx_cons_sb);
  1322. pkt_prod = fp_tx->tx_pkt_prod++;
  1323. tx_buf = &fp_tx->tx_buf_ring[TX_BD(pkt_prod)];
  1324. tx_buf->first_bd = fp_tx->tx_bd_prod;
  1325. tx_buf->skb = skb;
  1326. tx_buf->flags = 0;
  1327. bd_prod = TX_BD(fp_tx->tx_bd_prod);
  1328. tx_start_bd = &fp_tx->tx_desc_ring[bd_prod].start_bd;
  1329. mapping = dma_map_single(&bp->pdev->dev, skb->data,
  1330. skb_headlen(skb), DMA_TO_DEVICE);
  1331. tx_start_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
  1332. tx_start_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
  1333. tx_start_bd->nbd = cpu_to_le16(2); /* start + pbd */
  1334. tx_start_bd->nbytes = cpu_to_le16(skb_headlen(skb));
  1335. tx_start_bd->vlan_or_ethertype = cpu_to_le16(pkt_prod);
  1336. tx_start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
  1337. SET_FLAG(tx_start_bd->general_data,
  1338. ETH_TX_START_BD_ETH_ADDR_TYPE,
  1339. UNICAST_ADDRESS);
  1340. SET_FLAG(tx_start_bd->general_data,
  1341. ETH_TX_START_BD_HDR_NBDS,
  1342. 1);
  1343. /* turn on parsing and get a BD */
  1344. bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
  1345. pbd_e1x = &fp_tx->tx_desc_ring[bd_prod].parse_bd_e1x;
  1346. pbd_e2 = &fp_tx->tx_desc_ring[bd_prod].parse_bd_e2;
  1347. memset(pbd_e2, 0, sizeof(struct eth_tx_parse_bd_e2));
  1348. memset(pbd_e1x, 0, sizeof(struct eth_tx_parse_bd_e1x));
  1349. wmb();
  1350. fp_tx->tx_db.data.prod += 2;
  1351. barrier();
  1352. DOORBELL(bp, fp_tx->index, fp_tx->tx_db.raw);
  1353. mmiowb();
  1354. num_pkts++;
  1355. fp_tx->tx_bd_prod += 2; /* start + pbd */
  1356. udelay(100);
  1357. tx_idx = le16_to_cpu(*fp_tx->tx_cons_sb);
  1358. if (tx_idx != tx_start_idx + num_pkts)
  1359. goto test_loopback_exit;
  1360. /* Unlike HC IGU won't generate an interrupt for status block
  1361. * updates that have been performed while interrupts were
  1362. * disabled.
  1363. */
  1364. if (bp->common.int_block == INT_BLOCK_IGU) {
  1365. /* Disable local BHes to prevent a dead-lock situation between
  1366. * sch_direct_xmit() and bnx2x_run_loopback() (calling
  1367. * bnx2x_tx_int()), as both are taking netif_tx_lock().
  1368. */
  1369. local_bh_disable();
  1370. bnx2x_tx_int(fp_tx);
  1371. local_bh_enable();
  1372. }
  1373. rx_idx = le16_to_cpu(*fp_rx->rx_cons_sb);
  1374. if (rx_idx != rx_start_idx + num_pkts)
  1375. goto test_loopback_exit;
  1376. cqe = &fp_rx->rx_comp_ring[RCQ_BD(fp_rx->rx_comp_cons)];
  1377. cqe_fp_flags = cqe->fast_path_cqe.type_error_flags;
  1378. if (CQE_TYPE(cqe_fp_flags) || (cqe_fp_flags & ETH_RX_ERROR_FALGS))
  1379. goto test_loopback_rx_exit;
  1380. len = le16_to_cpu(cqe->fast_path_cqe.pkt_len);
  1381. if (len != pkt_size)
  1382. goto test_loopback_rx_exit;
  1383. rx_buf = &fp_rx->rx_buf_ring[RX_BD(fp_rx->rx_bd_cons)];
  1384. skb = rx_buf->skb;
  1385. skb_reserve(skb, cqe->fast_path_cqe.placement_offset);
  1386. for (i = ETH_HLEN; i < pkt_size; i++)
  1387. if (*(skb->data + i) != (unsigned char) (i & 0xff))
  1388. goto test_loopback_rx_exit;
  1389. rc = 0;
  1390. test_loopback_rx_exit:
  1391. fp_rx->rx_bd_cons = NEXT_RX_IDX(fp_rx->rx_bd_cons);
  1392. fp_rx->rx_bd_prod = NEXT_RX_IDX(fp_rx->rx_bd_prod);
  1393. fp_rx->rx_comp_cons = NEXT_RCQ_IDX(fp_rx->rx_comp_cons);
  1394. fp_rx->rx_comp_prod = NEXT_RCQ_IDX(fp_rx->rx_comp_prod);
  1395. /* Update producers */
  1396. bnx2x_update_rx_prod(bp, fp_rx, fp_rx->rx_bd_prod, fp_rx->rx_comp_prod,
  1397. fp_rx->rx_sge_prod);
  1398. test_loopback_exit:
  1399. bp->link_params.loopback_mode = LOOPBACK_NONE;
  1400. return rc;
  1401. }
  1402. static int bnx2x_test_loopback(struct bnx2x *bp, u8 link_up)
  1403. {
  1404. int rc = 0, res;
  1405. if (BP_NOMCP(bp))
  1406. return rc;
  1407. if (!netif_running(bp->dev))
  1408. return BNX2X_LOOPBACK_FAILED;
  1409. bnx2x_netif_stop(bp, 1);
  1410. bnx2x_acquire_phy_lock(bp);
  1411. res = bnx2x_run_loopback(bp, BNX2X_PHY_LOOPBACK, link_up);
  1412. if (res) {
  1413. DP(NETIF_MSG_PROBE, " PHY loopback failed (res %d)\n", res);
  1414. rc |= BNX2X_PHY_LOOPBACK_FAILED;
  1415. }
  1416. res = bnx2x_run_loopback(bp, BNX2X_MAC_LOOPBACK, link_up);
  1417. if (res) {
  1418. DP(NETIF_MSG_PROBE, " MAC loopback failed (res %d)\n", res);
  1419. rc |= BNX2X_MAC_LOOPBACK_FAILED;
  1420. }
  1421. bnx2x_release_phy_lock(bp);
  1422. bnx2x_netif_start(bp);
  1423. return rc;
  1424. }
  1425. #define CRC32_RESIDUAL 0xdebb20e3
  1426. static int bnx2x_test_nvram(struct bnx2x *bp)
  1427. {
  1428. static const struct {
  1429. int offset;
  1430. int size;
  1431. } nvram_tbl[] = {
  1432. { 0, 0x14 }, /* bootstrap */
  1433. { 0x14, 0xec }, /* dir */
  1434. { 0x100, 0x350 }, /* manuf_info */
  1435. { 0x450, 0xf0 }, /* feature_info */
  1436. { 0x640, 0x64 }, /* upgrade_key_info */
  1437. { 0x708, 0x70 }, /* manuf_key_info */
  1438. { 0, 0 }
  1439. };
  1440. __be32 buf[0x350 / 4];
  1441. u8 *data = (u8 *)buf;
  1442. int i, rc;
  1443. u32 magic, crc;
  1444. if (BP_NOMCP(bp))
  1445. return 0;
  1446. rc = bnx2x_nvram_read(bp, 0, data, 4);
  1447. if (rc) {
  1448. DP(NETIF_MSG_PROBE, "magic value read (rc %d)\n", rc);
  1449. goto test_nvram_exit;
  1450. }
  1451. magic = be32_to_cpu(buf[0]);
  1452. if (magic != 0x669955aa) {
  1453. DP(NETIF_MSG_PROBE, "magic value (0x%08x)\n", magic);
  1454. rc = -ENODEV;
  1455. goto test_nvram_exit;
  1456. }
  1457. for (i = 0; nvram_tbl[i].size; i++) {
  1458. rc = bnx2x_nvram_read(bp, nvram_tbl[i].offset, data,
  1459. nvram_tbl[i].size);
  1460. if (rc) {
  1461. DP(NETIF_MSG_PROBE,
  1462. "nvram_tbl[%d] read data (rc %d)\n", i, rc);
  1463. goto test_nvram_exit;
  1464. }
  1465. crc = ether_crc_le(nvram_tbl[i].size, data);
  1466. if (crc != CRC32_RESIDUAL) {
  1467. DP(NETIF_MSG_PROBE,
  1468. "nvram_tbl[%d] crc value (0x%08x)\n", i, crc);
  1469. rc = -ENODEV;
  1470. goto test_nvram_exit;
  1471. }
  1472. }
  1473. test_nvram_exit:
  1474. return rc;
  1475. }
  1476. static int bnx2x_test_intr(struct bnx2x *bp)
  1477. {
  1478. struct mac_configuration_cmd *config = bnx2x_sp(bp, mac_config);
  1479. int i, rc;
  1480. if (!netif_running(bp->dev))
  1481. return -ENODEV;
  1482. config->hdr.length = 0;
  1483. if (CHIP_IS_E1(bp))
  1484. config->hdr.offset = (BP_PORT(bp) ? 32 : 0);
  1485. else
  1486. config->hdr.offset = BP_FUNC(bp);
  1487. config->hdr.client_id = bp->fp->cl_id;
  1488. config->hdr.reserved1 = 0;
  1489. bp->set_mac_pending = 1;
  1490. smp_wmb();
  1491. rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_SET_MAC, 0,
  1492. U64_HI(bnx2x_sp_mapping(bp, mac_config)),
  1493. U64_LO(bnx2x_sp_mapping(bp, mac_config)), 1);
  1494. if (rc == 0) {
  1495. for (i = 0; i < 10; i++) {
  1496. if (!bp->set_mac_pending)
  1497. break;
  1498. smp_rmb();
  1499. msleep_interruptible(10);
  1500. }
  1501. if (i == 10)
  1502. rc = -ENODEV;
  1503. }
  1504. return rc;
  1505. }
  1506. static void bnx2x_self_test(struct net_device *dev,
  1507. struct ethtool_test *etest, u64 *buf)
  1508. {
  1509. struct bnx2x *bp = netdev_priv(dev);
  1510. u8 is_serdes;
  1511. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  1512. printk(KERN_ERR "Handling parity error recovery. Try again later\n");
  1513. etest->flags |= ETH_TEST_FL_FAILED;
  1514. return;
  1515. }
  1516. memset(buf, 0, sizeof(u64) * BNX2X_NUM_TESTS);
  1517. if (!netif_running(dev))
  1518. return;
  1519. /* offline tests are not supported in MF mode */
  1520. if (IS_MF(bp))
  1521. etest->flags &= ~ETH_TEST_FL_OFFLINE;
  1522. is_serdes = (bp->link_vars.link_status & LINK_STATUS_SERDES_LINK) > 0;
  1523. if (etest->flags & ETH_TEST_FL_OFFLINE) {
  1524. int port = BP_PORT(bp);
  1525. u32 val;
  1526. u8 link_up;
  1527. /* save current value of input enable for TX port IF */
  1528. val = REG_RD(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4);
  1529. /* disable input for TX port IF */
  1530. REG_WR(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4, 0);
  1531. link_up = bp->link_vars.link_up;
  1532. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  1533. bnx2x_nic_load(bp, LOAD_DIAG);
  1534. /* wait until link state is restored */
  1535. bnx2x_wait_for_link(bp, link_up, is_serdes);
  1536. if (bnx2x_test_registers(bp) != 0) {
  1537. buf[0] = 1;
  1538. etest->flags |= ETH_TEST_FL_FAILED;
  1539. }
  1540. if (bnx2x_test_memory(bp) != 0) {
  1541. buf[1] = 1;
  1542. etest->flags |= ETH_TEST_FL_FAILED;
  1543. }
  1544. buf[2] = bnx2x_test_loopback(bp, link_up);
  1545. if (buf[2] != 0)
  1546. etest->flags |= ETH_TEST_FL_FAILED;
  1547. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  1548. /* restore input for TX port IF */
  1549. REG_WR(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4, val);
  1550. bnx2x_nic_load(bp, LOAD_NORMAL);
  1551. /* wait until link state is restored */
  1552. bnx2x_wait_for_link(bp, link_up, is_serdes);
  1553. }
  1554. if (bnx2x_test_nvram(bp) != 0) {
  1555. buf[3] = 1;
  1556. etest->flags |= ETH_TEST_FL_FAILED;
  1557. }
  1558. if (bnx2x_test_intr(bp) != 0) {
  1559. buf[4] = 1;
  1560. etest->flags |= ETH_TEST_FL_FAILED;
  1561. }
  1562. if (bnx2x_link_test(bp, is_serdes) != 0) {
  1563. buf[5] = 1;
  1564. etest->flags |= ETH_TEST_FL_FAILED;
  1565. }
  1566. #ifdef BNX2X_EXTRA_DEBUG
  1567. bnx2x_panic_dump(bp);
  1568. #endif
  1569. }
  1570. #define IS_PORT_STAT(i) \
  1571. ((bnx2x_stats_arr[i].flags & STATS_FLAGS_BOTH) == STATS_FLAGS_PORT)
  1572. #define IS_FUNC_STAT(i) (bnx2x_stats_arr[i].flags & STATS_FLAGS_FUNC)
  1573. #define IS_MF_MODE_STAT(bp) \
  1574. (IS_MF(bp) && !(bp->msg_enable & BNX2X_MSG_STATS))
  1575. static int bnx2x_get_sset_count(struct net_device *dev, int stringset)
  1576. {
  1577. struct bnx2x *bp = netdev_priv(dev);
  1578. int i, num_stats;
  1579. switch (stringset) {
  1580. case ETH_SS_STATS:
  1581. if (is_multi(bp)) {
  1582. num_stats = BNX2X_NUM_STAT_QUEUES(bp) *
  1583. BNX2X_NUM_Q_STATS;
  1584. if (!IS_MF_MODE_STAT(bp))
  1585. num_stats += BNX2X_NUM_STATS;
  1586. } else {
  1587. if (IS_MF_MODE_STAT(bp)) {
  1588. num_stats = 0;
  1589. for (i = 0; i < BNX2X_NUM_STATS; i++)
  1590. if (IS_FUNC_STAT(i))
  1591. num_stats++;
  1592. } else
  1593. num_stats = BNX2X_NUM_STATS;
  1594. }
  1595. return num_stats;
  1596. case ETH_SS_TEST:
  1597. return BNX2X_NUM_TESTS;
  1598. default:
  1599. return -EINVAL;
  1600. }
  1601. }
  1602. static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
  1603. {
  1604. struct bnx2x *bp = netdev_priv(dev);
  1605. int i, j, k;
  1606. char queue_name[MAX_QUEUE_NAME_LEN+1];
  1607. switch (stringset) {
  1608. case ETH_SS_STATS:
  1609. if (is_multi(bp)) {
  1610. k = 0;
  1611. for_each_napi_queue(bp, i) {
  1612. memset(queue_name, 0, sizeof(queue_name));
  1613. if (IS_FCOE_IDX(i))
  1614. sprintf(queue_name, "fcoe");
  1615. else
  1616. sprintf(queue_name, "%d", i);
  1617. for (j = 0; j < BNX2X_NUM_Q_STATS; j++)
  1618. snprintf(buf + (k + j)*ETH_GSTRING_LEN,
  1619. ETH_GSTRING_LEN,
  1620. bnx2x_q_stats_arr[j].string,
  1621. queue_name);
  1622. k += BNX2X_NUM_Q_STATS;
  1623. }
  1624. if (IS_MF_MODE_STAT(bp))
  1625. break;
  1626. for (j = 0; j < BNX2X_NUM_STATS; j++)
  1627. strcpy(buf + (k + j)*ETH_GSTRING_LEN,
  1628. bnx2x_stats_arr[j].string);
  1629. } else {
  1630. for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
  1631. if (IS_MF_MODE_STAT(bp) && IS_PORT_STAT(i))
  1632. continue;
  1633. strcpy(buf + j*ETH_GSTRING_LEN,
  1634. bnx2x_stats_arr[i].string);
  1635. j++;
  1636. }
  1637. }
  1638. break;
  1639. case ETH_SS_TEST:
  1640. memcpy(buf, bnx2x_tests_str_arr, sizeof(bnx2x_tests_str_arr));
  1641. break;
  1642. }
  1643. }
  1644. static void bnx2x_get_ethtool_stats(struct net_device *dev,
  1645. struct ethtool_stats *stats, u64 *buf)
  1646. {
  1647. struct bnx2x *bp = netdev_priv(dev);
  1648. u32 *hw_stats, *offset;
  1649. int i, j, k;
  1650. if (is_multi(bp)) {
  1651. k = 0;
  1652. for_each_napi_queue(bp, i) {
  1653. hw_stats = (u32 *)&bp->fp[i].eth_q_stats;
  1654. for (j = 0; j < BNX2X_NUM_Q_STATS; j++) {
  1655. if (bnx2x_q_stats_arr[j].size == 0) {
  1656. /* skip this counter */
  1657. buf[k + j] = 0;
  1658. continue;
  1659. }
  1660. offset = (hw_stats +
  1661. bnx2x_q_stats_arr[j].offset);
  1662. if (bnx2x_q_stats_arr[j].size == 4) {
  1663. /* 4-byte counter */
  1664. buf[k + j] = (u64) *offset;
  1665. continue;
  1666. }
  1667. /* 8-byte counter */
  1668. buf[k + j] = HILO_U64(*offset, *(offset + 1));
  1669. }
  1670. k += BNX2X_NUM_Q_STATS;
  1671. }
  1672. if (IS_MF_MODE_STAT(bp))
  1673. return;
  1674. hw_stats = (u32 *)&bp->eth_stats;
  1675. for (j = 0; j < BNX2X_NUM_STATS; j++) {
  1676. if (bnx2x_stats_arr[j].size == 0) {
  1677. /* skip this counter */
  1678. buf[k + j] = 0;
  1679. continue;
  1680. }
  1681. offset = (hw_stats + bnx2x_stats_arr[j].offset);
  1682. if (bnx2x_stats_arr[j].size == 4) {
  1683. /* 4-byte counter */
  1684. buf[k + j] = (u64) *offset;
  1685. continue;
  1686. }
  1687. /* 8-byte counter */
  1688. buf[k + j] = HILO_U64(*offset, *(offset + 1));
  1689. }
  1690. } else {
  1691. hw_stats = (u32 *)&bp->eth_stats;
  1692. for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
  1693. if (IS_MF_MODE_STAT(bp) && IS_PORT_STAT(i))
  1694. continue;
  1695. if (bnx2x_stats_arr[i].size == 0) {
  1696. /* skip this counter */
  1697. buf[j] = 0;
  1698. j++;
  1699. continue;
  1700. }
  1701. offset = (hw_stats + bnx2x_stats_arr[i].offset);
  1702. if (bnx2x_stats_arr[i].size == 4) {
  1703. /* 4-byte counter */
  1704. buf[j] = (u64) *offset;
  1705. j++;
  1706. continue;
  1707. }
  1708. /* 8-byte counter */
  1709. buf[j] = HILO_U64(*offset, *(offset + 1));
  1710. j++;
  1711. }
  1712. }
  1713. }
  1714. static int bnx2x_set_phys_id(struct net_device *dev,
  1715. enum ethtool_phys_id_state state)
  1716. {
  1717. struct bnx2x *bp = netdev_priv(dev);
  1718. if (!netif_running(dev))
  1719. return -EAGAIN;
  1720. if (!bp->port.pmf)
  1721. return -EOPNOTSUPP;
  1722. switch (state) {
  1723. case ETHTOOL_ID_ACTIVE:
  1724. return 1; /* cycle on/off once per second */
  1725. case ETHTOOL_ID_ON:
  1726. bnx2x_set_led(&bp->link_params, &bp->link_vars,
  1727. LED_MODE_ON, SPEED_1000);
  1728. break;
  1729. case ETHTOOL_ID_OFF:
  1730. bnx2x_set_led(&bp->link_params, &bp->link_vars,
  1731. LED_MODE_FRONT_PANEL_OFF, 0);
  1732. break;
  1733. case ETHTOOL_ID_INACTIVE:
  1734. bnx2x_set_led(&bp->link_params, &bp->link_vars,
  1735. LED_MODE_OPER,
  1736. bp->link_vars.line_speed);
  1737. }
  1738. return 0;
  1739. }
  1740. static int bnx2x_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
  1741. void *rules __always_unused)
  1742. {
  1743. struct bnx2x *bp = netdev_priv(dev);
  1744. switch (info->cmd) {
  1745. case ETHTOOL_GRXRINGS:
  1746. info->data = BNX2X_NUM_ETH_QUEUES(bp);
  1747. return 0;
  1748. default:
  1749. return -EOPNOTSUPP;
  1750. }
  1751. }
  1752. static int bnx2x_get_rxfh_indir(struct net_device *dev,
  1753. struct ethtool_rxfh_indir *indir)
  1754. {
  1755. struct bnx2x *bp = netdev_priv(dev);
  1756. size_t copy_size =
  1757. min_t(size_t, indir->size, TSTORM_INDIRECTION_TABLE_SIZE);
  1758. if (bp->multi_mode == ETH_RSS_MODE_DISABLED)
  1759. return -EOPNOTSUPP;
  1760. indir->size = TSTORM_INDIRECTION_TABLE_SIZE;
  1761. memcpy(indir->ring_index, bp->rx_indir_table,
  1762. copy_size * sizeof(bp->rx_indir_table[0]));
  1763. return 0;
  1764. }
  1765. static int bnx2x_set_rxfh_indir(struct net_device *dev,
  1766. const struct ethtool_rxfh_indir *indir)
  1767. {
  1768. struct bnx2x *bp = netdev_priv(dev);
  1769. size_t i;
  1770. if (bp->multi_mode == ETH_RSS_MODE_DISABLED)
  1771. return -EOPNOTSUPP;
  1772. /* Validate size and indices */
  1773. if (indir->size != TSTORM_INDIRECTION_TABLE_SIZE)
  1774. return -EINVAL;
  1775. for (i = 0; i < TSTORM_INDIRECTION_TABLE_SIZE; i++)
  1776. if (indir->ring_index[i] >= BNX2X_NUM_ETH_QUEUES(bp))
  1777. return -EINVAL;
  1778. memcpy(bp->rx_indir_table, indir->ring_index,
  1779. indir->size * sizeof(bp->rx_indir_table[0]));
  1780. bnx2x_push_indir_table(bp);
  1781. return 0;
  1782. }
  1783. static const struct ethtool_ops bnx2x_ethtool_ops = {
  1784. .get_settings = bnx2x_get_settings,
  1785. .set_settings = bnx2x_set_settings,
  1786. .get_drvinfo = bnx2x_get_drvinfo,
  1787. .get_regs_len = bnx2x_get_regs_len,
  1788. .get_regs = bnx2x_get_regs,
  1789. .get_wol = bnx2x_get_wol,
  1790. .set_wol = bnx2x_set_wol,
  1791. .get_msglevel = bnx2x_get_msglevel,
  1792. .set_msglevel = bnx2x_set_msglevel,
  1793. .nway_reset = bnx2x_nway_reset,
  1794. .get_link = bnx2x_get_link,
  1795. .get_eeprom_len = bnx2x_get_eeprom_len,
  1796. .get_eeprom = bnx2x_get_eeprom,
  1797. .set_eeprom = bnx2x_set_eeprom,
  1798. .get_coalesce = bnx2x_get_coalesce,
  1799. .set_coalesce = bnx2x_set_coalesce,
  1800. .get_ringparam = bnx2x_get_ringparam,
  1801. .set_ringparam = bnx2x_set_ringparam,
  1802. .get_pauseparam = bnx2x_get_pauseparam,
  1803. .set_pauseparam = bnx2x_set_pauseparam,
  1804. .self_test = bnx2x_self_test,
  1805. .get_sset_count = bnx2x_get_sset_count,
  1806. .get_strings = bnx2x_get_strings,
  1807. .set_phys_id = bnx2x_set_phys_id,
  1808. .get_ethtool_stats = bnx2x_get_ethtool_stats,
  1809. .get_rxnfc = bnx2x_get_rxnfc,
  1810. .get_rxfh_indir = bnx2x_get_rxfh_indir,
  1811. .set_rxfh_indir = bnx2x_set_rxfh_indir,
  1812. };
  1813. void bnx2x_set_ethtool_ops(struct net_device *netdev)
  1814. {
  1815. SET_ETHTOOL_OPS(netdev, &bnx2x_ethtool_ops);
  1816. }