bnx2x_ethtool.c 63 KB

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