bnx2x_ethtool.c 60 KB

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