bnx2x_ethtool.c 60 KB

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