bnx2x_ethtool.c 64 KB

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