bnx2x_ethtool.c 66 KB

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