bnx2x_ethtool.c 64 KB

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