bnx2x_ethtool.c 65 KB

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