bnx2x_ethtool.c 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433
  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. if (bp->port.pmf) {
  715. bnx2x_acquire_phy_lock(bp);
  716. bnx2x_get_ext_phy_fw_version(&bp->link_params,
  717. (bp->state != BNX2X_STATE_CLOSED),
  718. phy_fw_ver, PHY_FW_VER_LEN);
  719. bnx2x_release_phy_lock(bp);
  720. }
  721. strlcpy(info->fw_version, bp->fw_ver, sizeof(info->fw_version));
  722. snprintf(info->fw_version + strlen(bp->fw_ver), 32 - strlen(bp->fw_ver),
  723. "bc %d.%d.%d%s%s",
  724. (bp->common.bc_ver & 0xff0000) >> 16,
  725. (bp->common.bc_ver & 0xff00) >> 8,
  726. (bp->common.bc_ver & 0xff),
  727. ((phy_fw_ver[0] != '\0') ? " phy " : ""), phy_fw_ver);
  728. strlcpy(info->bus_info, pci_name(bp->pdev), sizeof(info->bus_info));
  729. info->n_stats = BNX2X_NUM_STATS;
  730. info->testinfo_len = BNX2X_NUM_TESTS;
  731. info->eedump_len = bp->common.flash_size;
  732. info->regdump_len = bnx2x_get_regs_len(dev);
  733. }
  734. static void bnx2x_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  735. {
  736. struct bnx2x *bp = netdev_priv(dev);
  737. if (bp->flags & NO_WOL_FLAG) {
  738. wol->supported = 0;
  739. wol->wolopts = 0;
  740. } else {
  741. wol->supported = WAKE_MAGIC;
  742. if (bp->wol)
  743. wol->wolopts = WAKE_MAGIC;
  744. else
  745. wol->wolopts = 0;
  746. }
  747. memset(&wol->sopass, 0, sizeof(wol->sopass));
  748. }
  749. static int bnx2x_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  750. {
  751. struct bnx2x *bp = netdev_priv(dev);
  752. if (wol->wolopts & ~WAKE_MAGIC)
  753. return -EINVAL;
  754. if (wol->wolopts & WAKE_MAGIC) {
  755. if (bp->flags & NO_WOL_FLAG)
  756. return -EINVAL;
  757. bp->wol = 1;
  758. } else
  759. bp->wol = 0;
  760. return 0;
  761. }
  762. static u32 bnx2x_get_msglevel(struct net_device *dev)
  763. {
  764. struct bnx2x *bp = netdev_priv(dev);
  765. return bp->msg_enable;
  766. }
  767. static void bnx2x_set_msglevel(struct net_device *dev, u32 level)
  768. {
  769. struct bnx2x *bp = netdev_priv(dev);
  770. if (capable(CAP_NET_ADMIN)) {
  771. /* dump MCP trace */
  772. if (level & BNX2X_MSG_MCP)
  773. bnx2x_fw_dump_lvl(bp, KERN_INFO);
  774. bp->msg_enable = level;
  775. }
  776. }
  777. static int bnx2x_nway_reset(struct net_device *dev)
  778. {
  779. struct bnx2x *bp = netdev_priv(dev);
  780. if (!bp->port.pmf)
  781. return 0;
  782. if (netif_running(dev)) {
  783. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  784. bnx2x_link_set(bp);
  785. }
  786. return 0;
  787. }
  788. static u32 bnx2x_get_link(struct net_device *dev)
  789. {
  790. struct bnx2x *bp = netdev_priv(dev);
  791. if (bp->flags & MF_FUNC_DIS || (bp->state != BNX2X_STATE_OPEN))
  792. return 0;
  793. return bp->link_vars.link_up;
  794. }
  795. static int bnx2x_get_eeprom_len(struct net_device *dev)
  796. {
  797. struct bnx2x *bp = netdev_priv(dev);
  798. return bp->common.flash_size;
  799. }
  800. /* Per pf misc lock must be aquired before the per port mcp lock. Otherwise, had
  801. * we done things the other way around, if two pfs from the same port would
  802. * attempt to access nvram at the same time, we could run into a scenario such
  803. * as:
  804. * pf A takes the port lock.
  805. * pf B succeeds in taking the same lock since they are from the same port.
  806. * pf A takes the per pf misc lock. Performs eeprom access.
  807. * pf A finishes. Unlocks the per pf misc lock.
  808. * Pf B takes the lock and proceeds to perform it's own access.
  809. * pf A unlocks the per port lock, while pf B is still working (!).
  810. * mcp takes the per port lock and corrupts pf B's access (and/or has it's own
  811. * acess corrupted by pf B).*
  812. */
  813. static int bnx2x_acquire_nvram_lock(struct bnx2x *bp)
  814. {
  815. int port = BP_PORT(bp);
  816. int count, i;
  817. u32 val;
  818. /* acquire HW lock: protect against other PFs in PF Direct Assignment */
  819. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_NVRAM);
  820. /* adjust timeout for emulation/FPGA */
  821. count = BNX2X_NVRAM_TIMEOUT_COUNT;
  822. if (CHIP_REV_IS_SLOW(bp))
  823. count *= 100;
  824. /* request access to nvram interface */
  825. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  826. (MCPR_NVM_SW_ARB_ARB_REQ_SET1 << port));
  827. for (i = 0; i < count*10; i++) {
  828. val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB);
  829. if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))
  830. break;
  831. udelay(5);
  832. }
  833. if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))) {
  834. DP(BNX2X_MSG_NVM, "cannot get access to nvram interface\n");
  835. return -EBUSY;
  836. }
  837. return 0;
  838. }
  839. static int bnx2x_release_nvram_lock(struct bnx2x *bp)
  840. {
  841. int port = BP_PORT(bp);
  842. int count, i;
  843. u32 val;
  844. /* adjust timeout for emulation/FPGA */
  845. count = BNX2X_NVRAM_TIMEOUT_COUNT;
  846. if (CHIP_REV_IS_SLOW(bp))
  847. count *= 100;
  848. /* relinquish nvram interface */
  849. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  850. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << port));
  851. for (i = 0; i < count*10; i++) {
  852. val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB);
  853. if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)))
  854. break;
  855. udelay(5);
  856. }
  857. if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)) {
  858. DP(BNX2X_MSG_NVM, "cannot free access to nvram interface\n");
  859. return -EBUSY;
  860. }
  861. /* release HW lock: protect against other PFs in PF Direct Assignment */
  862. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_NVRAM);
  863. return 0;
  864. }
  865. static void bnx2x_enable_nvram_access(struct bnx2x *bp)
  866. {
  867. u32 val;
  868. val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
  869. /* enable both bits, even on read */
  870. REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
  871. (val | MCPR_NVM_ACCESS_ENABLE_EN |
  872. MCPR_NVM_ACCESS_ENABLE_WR_EN));
  873. }
  874. static void bnx2x_disable_nvram_access(struct bnx2x *bp)
  875. {
  876. u32 val;
  877. val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
  878. /* disable both bits, even after read */
  879. REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
  880. (val & ~(MCPR_NVM_ACCESS_ENABLE_EN |
  881. MCPR_NVM_ACCESS_ENABLE_WR_EN)));
  882. }
  883. static int bnx2x_nvram_read_dword(struct bnx2x *bp, u32 offset, __be32 *ret_val,
  884. u32 cmd_flags)
  885. {
  886. int count, i, rc;
  887. u32 val;
  888. /* build the command word */
  889. cmd_flags |= MCPR_NVM_COMMAND_DOIT;
  890. /* need to clear DONE bit separately */
  891. REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
  892. /* address of the NVRAM to read from */
  893. REG_WR(bp, MCP_REG_MCPR_NVM_ADDR,
  894. (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
  895. /* issue a read command */
  896. REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
  897. /* adjust timeout for emulation/FPGA */
  898. count = BNX2X_NVRAM_TIMEOUT_COUNT;
  899. if (CHIP_REV_IS_SLOW(bp))
  900. count *= 100;
  901. /* wait for completion */
  902. *ret_val = 0;
  903. rc = -EBUSY;
  904. for (i = 0; i < count; i++) {
  905. udelay(5);
  906. val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND);
  907. if (val & MCPR_NVM_COMMAND_DONE) {
  908. val = REG_RD(bp, MCP_REG_MCPR_NVM_READ);
  909. /* we read nvram data in cpu order
  910. * but ethtool sees it as an array of bytes
  911. * converting to big-endian will do the work */
  912. *ret_val = cpu_to_be32(val);
  913. rc = 0;
  914. break;
  915. }
  916. }
  917. return rc;
  918. }
  919. static int bnx2x_nvram_read(struct bnx2x *bp, u32 offset, u8 *ret_buf,
  920. int buf_size)
  921. {
  922. int rc;
  923. u32 cmd_flags;
  924. __be32 val;
  925. if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
  926. DP(BNX2X_MSG_NVM,
  927. "Invalid parameter: offset 0x%x buf_size 0x%x\n",
  928. offset, buf_size);
  929. return -EINVAL;
  930. }
  931. if (offset + buf_size > bp->common.flash_size) {
  932. DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
  933. " buf_size (0x%x) > flash_size (0x%x)\n",
  934. offset, buf_size, bp->common.flash_size);
  935. return -EINVAL;
  936. }
  937. /* request access to nvram interface */
  938. rc = bnx2x_acquire_nvram_lock(bp);
  939. if (rc)
  940. return rc;
  941. /* enable access to nvram interface */
  942. bnx2x_enable_nvram_access(bp);
  943. /* read the first word(s) */
  944. cmd_flags = MCPR_NVM_COMMAND_FIRST;
  945. while ((buf_size > sizeof(u32)) && (rc == 0)) {
  946. rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags);
  947. memcpy(ret_buf, &val, 4);
  948. /* advance to the next dword */
  949. offset += sizeof(u32);
  950. ret_buf += sizeof(u32);
  951. buf_size -= sizeof(u32);
  952. cmd_flags = 0;
  953. }
  954. if (rc == 0) {
  955. cmd_flags |= MCPR_NVM_COMMAND_LAST;
  956. rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags);
  957. memcpy(ret_buf, &val, 4);
  958. }
  959. /* disable access to nvram interface */
  960. bnx2x_disable_nvram_access(bp);
  961. bnx2x_release_nvram_lock(bp);
  962. return rc;
  963. }
  964. static int bnx2x_get_eeprom(struct net_device *dev,
  965. struct ethtool_eeprom *eeprom, u8 *eebuf)
  966. {
  967. struct bnx2x *bp = netdev_priv(dev);
  968. int rc;
  969. if (!netif_running(dev))
  970. return -EAGAIN;
  971. DP(BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n"
  972. " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
  973. eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset,
  974. eeprom->len, eeprom->len);
  975. /* parameters already validated in ethtool_get_eeprom */
  976. rc = bnx2x_nvram_read(bp, eeprom->offset, eebuf, eeprom->len);
  977. return rc;
  978. }
  979. static int bnx2x_nvram_write_dword(struct bnx2x *bp, u32 offset, u32 val,
  980. u32 cmd_flags)
  981. {
  982. int count, i, rc;
  983. /* build the command word */
  984. cmd_flags |= MCPR_NVM_COMMAND_DOIT | MCPR_NVM_COMMAND_WR;
  985. /* need to clear DONE bit separately */
  986. REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
  987. /* write the data */
  988. REG_WR(bp, MCP_REG_MCPR_NVM_WRITE, val);
  989. /* address of the NVRAM to write to */
  990. REG_WR(bp, MCP_REG_MCPR_NVM_ADDR,
  991. (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
  992. /* issue the write command */
  993. REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
  994. /* adjust timeout for emulation/FPGA */
  995. count = BNX2X_NVRAM_TIMEOUT_COUNT;
  996. if (CHIP_REV_IS_SLOW(bp))
  997. count *= 100;
  998. /* wait for completion */
  999. rc = -EBUSY;
  1000. for (i = 0; i < count; i++) {
  1001. udelay(5);
  1002. val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND);
  1003. if (val & MCPR_NVM_COMMAND_DONE) {
  1004. rc = 0;
  1005. break;
  1006. }
  1007. }
  1008. return rc;
  1009. }
  1010. #define BYTE_OFFSET(offset) (8 * (offset & 0x03))
  1011. static int bnx2x_nvram_write1(struct bnx2x *bp, u32 offset, u8 *data_buf,
  1012. int buf_size)
  1013. {
  1014. int rc;
  1015. u32 cmd_flags;
  1016. u32 align_offset;
  1017. __be32 val;
  1018. if (offset + buf_size > bp->common.flash_size) {
  1019. DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
  1020. " buf_size (0x%x) > flash_size (0x%x)\n",
  1021. offset, buf_size, bp->common.flash_size);
  1022. return -EINVAL;
  1023. }
  1024. /* request access to nvram interface */
  1025. rc = bnx2x_acquire_nvram_lock(bp);
  1026. if (rc)
  1027. return rc;
  1028. /* enable access to nvram interface */
  1029. bnx2x_enable_nvram_access(bp);
  1030. cmd_flags = (MCPR_NVM_COMMAND_FIRST | MCPR_NVM_COMMAND_LAST);
  1031. align_offset = (offset & ~0x03);
  1032. rc = bnx2x_nvram_read_dword(bp, align_offset, &val, cmd_flags);
  1033. if (rc == 0) {
  1034. val &= ~(0xff << BYTE_OFFSET(offset));
  1035. val |= (*data_buf << BYTE_OFFSET(offset));
  1036. /* nvram data is returned as an array of bytes
  1037. * convert it back to cpu order */
  1038. val = be32_to_cpu(val);
  1039. rc = bnx2x_nvram_write_dword(bp, align_offset, val,
  1040. cmd_flags);
  1041. }
  1042. /* disable access to nvram interface */
  1043. bnx2x_disable_nvram_access(bp);
  1044. bnx2x_release_nvram_lock(bp);
  1045. return rc;
  1046. }
  1047. static int bnx2x_nvram_write(struct bnx2x *bp, u32 offset, u8 *data_buf,
  1048. int buf_size)
  1049. {
  1050. int rc;
  1051. u32 cmd_flags;
  1052. u32 val;
  1053. u32 written_so_far;
  1054. if (buf_size == 1) /* ethtool */
  1055. return bnx2x_nvram_write1(bp, offset, data_buf, buf_size);
  1056. if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
  1057. DP(BNX2X_MSG_NVM,
  1058. "Invalid parameter: offset 0x%x buf_size 0x%x\n",
  1059. offset, buf_size);
  1060. return -EINVAL;
  1061. }
  1062. if (offset + buf_size > bp->common.flash_size) {
  1063. DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
  1064. " buf_size (0x%x) > flash_size (0x%x)\n",
  1065. offset, buf_size, bp->common.flash_size);
  1066. return -EINVAL;
  1067. }
  1068. /* request access to nvram interface */
  1069. rc = bnx2x_acquire_nvram_lock(bp);
  1070. if (rc)
  1071. return rc;
  1072. /* enable access to nvram interface */
  1073. bnx2x_enable_nvram_access(bp);
  1074. written_so_far = 0;
  1075. cmd_flags = MCPR_NVM_COMMAND_FIRST;
  1076. while ((written_so_far < buf_size) && (rc == 0)) {
  1077. if (written_so_far == (buf_size - sizeof(u32)))
  1078. cmd_flags |= MCPR_NVM_COMMAND_LAST;
  1079. else if (((offset + 4) % BNX2X_NVRAM_PAGE_SIZE) == 0)
  1080. cmd_flags |= MCPR_NVM_COMMAND_LAST;
  1081. else if ((offset % BNX2X_NVRAM_PAGE_SIZE) == 0)
  1082. cmd_flags |= MCPR_NVM_COMMAND_FIRST;
  1083. memcpy(&val, data_buf, 4);
  1084. rc = bnx2x_nvram_write_dword(bp, offset, val, cmd_flags);
  1085. /* advance to the next dword */
  1086. offset += sizeof(u32);
  1087. data_buf += sizeof(u32);
  1088. written_so_far += sizeof(u32);
  1089. cmd_flags = 0;
  1090. }
  1091. /* disable access to nvram interface */
  1092. bnx2x_disable_nvram_access(bp);
  1093. bnx2x_release_nvram_lock(bp);
  1094. return rc;
  1095. }
  1096. static int bnx2x_set_eeprom(struct net_device *dev,
  1097. struct ethtool_eeprom *eeprom, u8 *eebuf)
  1098. {
  1099. struct bnx2x *bp = netdev_priv(dev);
  1100. int port = BP_PORT(bp);
  1101. int rc = 0;
  1102. u32 ext_phy_config;
  1103. if (!netif_running(dev))
  1104. return -EAGAIN;
  1105. DP(BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n"
  1106. " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
  1107. eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset,
  1108. eeprom->len, eeprom->len);
  1109. /* parameters already validated in ethtool_set_eeprom */
  1110. /* PHY eeprom can be accessed only by the PMF */
  1111. if ((eeprom->magic >= 0x50485900) && (eeprom->magic <= 0x504859FF) &&
  1112. !bp->port.pmf)
  1113. return -EINVAL;
  1114. ext_phy_config =
  1115. SHMEM_RD(bp,
  1116. dev_info.port_hw_config[port].external_phy_config);
  1117. if (eeprom->magic == 0x50485950) {
  1118. /* 'PHYP' (0x50485950): prepare phy for FW upgrade */
  1119. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  1120. bnx2x_acquire_phy_lock(bp);
  1121. rc |= bnx2x_link_reset(&bp->link_params,
  1122. &bp->link_vars, 0);
  1123. if (XGXS_EXT_PHY_TYPE(ext_phy_config) ==
  1124. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101)
  1125. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
  1126. MISC_REGISTERS_GPIO_HIGH, port);
  1127. bnx2x_release_phy_lock(bp);
  1128. bnx2x_link_report(bp);
  1129. } else if (eeprom->magic == 0x50485952) {
  1130. /* 'PHYR' (0x50485952): re-init link after FW upgrade */
  1131. if (bp->state == BNX2X_STATE_OPEN) {
  1132. bnx2x_acquire_phy_lock(bp);
  1133. rc |= bnx2x_link_reset(&bp->link_params,
  1134. &bp->link_vars, 1);
  1135. rc |= bnx2x_phy_init(&bp->link_params,
  1136. &bp->link_vars);
  1137. bnx2x_release_phy_lock(bp);
  1138. bnx2x_calc_fc_adv(bp);
  1139. }
  1140. } else if (eeprom->magic == 0x53985943) {
  1141. /* 'PHYC' (0x53985943): PHY FW upgrade completed */
  1142. if (XGXS_EXT_PHY_TYPE(ext_phy_config) ==
  1143. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101) {
  1144. /* DSP Remove Download Mode */
  1145. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
  1146. MISC_REGISTERS_GPIO_LOW, port);
  1147. bnx2x_acquire_phy_lock(bp);
  1148. bnx2x_sfx7101_sp_sw_reset(bp,
  1149. &bp->link_params.phy[EXT_PHY1]);
  1150. /* wait 0.5 sec to allow it to run */
  1151. msleep(500);
  1152. bnx2x_ext_phy_hw_reset(bp, port);
  1153. msleep(500);
  1154. bnx2x_release_phy_lock(bp);
  1155. }
  1156. } else
  1157. rc = bnx2x_nvram_write(bp, eeprom->offset, eebuf, eeprom->len);
  1158. return rc;
  1159. }
  1160. static int bnx2x_get_coalesce(struct net_device *dev,
  1161. struct ethtool_coalesce *coal)
  1162. {
  1163. struct bnx2x *bp = netdev_priv(dev);
  1164. memset(coal, 0, sizeof(struct ethtool_coalesce));
  1165. coal->rx_coalesce_usecs = bp->rx_ticks;
  1166. coal->tx_coalesce_usecs = bp->tx_ticks;
  1167. return 0;
  1168. }
  1169. static int bnx2x_set_coalesce(struct net_device *dev,
  1170. struct ethtool_coalesce *coal)
  1171. {
  1172. struct bnx2x *bp = netdev_priv(dev);
  1173. bp->rx_ticks = (u16)coal->rx_coalesce_usecs;
  1174. if (bp->rx_ticks > BNX2X_MAX_COALESCE_TOUT)
  1175. bp->rx_ticks = BNX2X_MAX_COALESCE_TOUT;
  1176. bp->tx_ticks = (u16)coal->tx_coalesce_usecs;
  1177. if (bp->tx_ticks > BNX2X_MAX_COALESCE_TOUT)
  1178. bp->tx_ticks = BNX2X_MAX_COALESCE_TOUT;
  1179. if (netif_running(dev))
  1180. bnx2x_update_coalesce(bp);
  1181. return 0;
  1182. }
  1183. static void bnx2x_get_ringparam(struct net_device *dev,
  1184. struct ethtool_ringparam *ering)
  1185. {
  1186. struct bnx2x *bp = netdev_priv(dev);
  1187. ering->rx_max_pending = MAX_RX_AVAIL;
  1188. if (bp->rx_ring_size)
  1189. ering->rx_pending = bp->rx_ring_size;
  1190. else
  1191. ering->rx_pending = MAX_RX_AVAIL;
  1192. ering->tx_max_pending = MAX_TX_AVAIL;
  1193. ering->tx_pending = bp->tx_ring_size;
  1194. }
  1195. static int bnx2x_set_ringparam(struct net_device *dev,
  1196. struct ethtool_ringparam *ering)
  1197. {
  1198. struct bnx2x *bp = netdev_priv(dev);
  1199. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  1200. netdev_err(dev, "Handling parity error recovery. "
  1201. "Try again later\n");
  1202. return -EAGAIN;
  1203. }
  1204. if ((ering->rx_pending > MAX_RX_AVAIL) ||
  1205. (ering->rx_pending < (bp->disable_tpa ? MIN_RX_SIZE_NONTPA :
  1206. MIN_RX_SIZE_TPA)) ||
  1207. (ering->tx_pending > MAX_TX_AVAIL) ||
  1208. (ering->tx_pending <= MAX_SKB_FRAGS + 4))
  1209. return -EINVAL;
  1210. bp->rx_ring_size = ering->rx_pending;
  1211. bp->tx_ring_size = ering->tx_pending;
  1212. return bnx2x_reload_if_running(dev);
  1213. }
  1214. static void bnx2x_get_pauseparam(struct net_device *dev,
  1215. struct ethtool_pauseparam *epause)
  1216. {
  1217. struct bnx2x *bp = netdev_priv(dev);
  1218. int cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1219. int cfg_reg;
  1220. epause->autoneg = (bp->link_params.req_flow_ctrl[cfg_idx] ==
  1221. BNX2X_FLOW_CTRL_AUTO);
  1222. if (!epause->autoneg)
  1223. cfg_reg = bp->link_vars.flow_ctrl;
  1224. else
  1225. cfg_reg = bp->link_params.req_fc_auto_adv;
  1226. epause->rx_pause = ((cfg_reg & BNX2X_FLOW_CTRL_RX) ==
  1227. BNX2X_FLOW_CTRL_RX);
  1228. epause->tx_pause = ((cfg_reg & BNX2X_FLOW_CTRL_TX) ==
  1229. BNX2X_FLOW_CTRL_TX);
  1230. DP(NETIF_MSG_LINK, "ethtool_pauseparam: cmd %d\n"
  1231. " autoneg %d rx_pause %d tx_pause %d\n",
  1232. epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);
  1233. }
  1234. static int bnx2x_set_pauseparam(struct net_device *dev,
  1235. struct ethtool_pauseparam *epause)
  1236. {
  1237. struct bnx2x *bp = netdev_priv(dev);
  1238. u32 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1239. if (IS_MF(bp))
  1240. return 0;
  1241. DP(NETIF_MSG_LINK, "ethtool_pauseparam: cmd %d\n"
  1242. " autoneg %d rx_pause %d tx_pause %d\n",
  1243. epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);
  1244. bp->link_params.req_flow_ctrl[cfg_idx] = BNX2X_FLOW_CTRL_AUTO;
  1245. if (epause->rx_pause)
  1246. bp->link_params.req_flow_ctrl[cfg_idx] |= BNX2X_FLOW_CTRL_RX;
  1247. if (epause->tx_pause)
  1248. bp->link_params.req_flow_ctrl[cfg_idx] |= BNX2X_FLOW_CTRL_TX;
  1249. if (bp->link_params.req_flow_ctrl[cfg_idx] == BNX2X_FLOW_CTRL_AUTO)
  1250. bp->link_params.req_flow_ctrl[cfg_idx] = BNX2X_FLOW_CTRL_NONE;
  1251. if (epause->autoneg) {
  1252. if (!(bp->port.supported[cfg_idx] & SUPPORTED_Autoneg)) {
  1253. DP(NETIF_MSG_LINK, "autoneg not supported\n");
  1254. return -EINVAL;
  1255. }
  1256. if (bp->link_params.req_line_speed[cfg_idx] == SPEED_AUTO_NEG) {
  1257. bp->link_params.req_flow_ctrl[cfg_idx] =
  1258. BNX2X_FLOW_CTRL_AUTO;
  1259. }
  1260. }
  1261. DP(NETIF_MSG_LINK,
  1262. "req_flow_ctrl 0x%x\n", bp->link_params.req_flow_ctrl[cfg_idx]);
  1263. if (netif_running(dev)) {
  1264. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  1265. bnx2x_link_set(bp);
  1266. }
  1267. return 0;
  1268. }
  1269. static const struct {
  1270. char string[ETH_GSTRING_LEN];
  1271. } bnx2x_tests_str_arr[BNX2X_NUM_TESTS] = {
  1272. { "register_test (offline)" },
  1273. { "memory_test (offline)" },
  1274. { "loopback_test (offline)" },
  1275. { "nvram_test (online)" },
  1276. { "interrupt_test (online)" },
  1277. { "link_test (online)" },
  1278. { "idle check (online)" }
  1279. };
  1280. enum {
  1281. BNX2X_CHIP_E1_OFST = 0,
  1282. BNX2X_CHIP_E1H_OFST,
  1283. BNX2X_CHIP_E2_OFST,
  1284. BNX2X_CHIP_E3_OFST,
  1285. BNX2X_CHIP_E3B0_OFST,
  1286. BNX2X_CHIP_MAX_OFST
  1287. };
  1288. #define BNX2X_CHIP_MASK_E1 (1 << BNX2X_CHIP_E1_OFST)
  1289. #define BNX2X_CHIP_MASK_E1H (1 << BNX2X_CHIP_E1H_OFST)
  1290. #define BNX2X_CHIP_MASK_E2 (1 << BNX2X_CHIP_E2_OFST)
  1291. #define BNX2X_CHIP_MASK_E3 (1 << BNX2X_CHIP_E3_OFST)
  1292. #define BNX2X_CHIP_MASK_E3B0 (1 << BNX2X_CHIP_E3B0_OFST)
  1293. #define BNX2X_CHIP_MASK_ALL ((1 << BNX2X_CHIP_MAX_OFST) - 1)
  1294. #define BNX2X_CHIP_MASK_E1X (BNX2X_CHIP_MASK_E1 | BNX2X_CHIP_MASK_E1H)
  1295. static int bnx2x_test_registers(struct bnx2x *bp)
  1296. {
  1297. int idx, i, rc = -ENODEV;
  1298. u32 wr_val = 0, hw;
  1299. int port = BP_PORT(bp);
  1300. static const struct {
  1301. u32 hw;
  1302. u32 offset0;
  1303. u32 offset1;
  1304. u32 mask;
  1305. } reg_tbl[] = {
  1306. /* 0 */ { BNX2X_CHIP_MASK_ALL,
  1307. BRB1_REG_PAUSE_LOW_THRESHOLD_0, 4, 0x000003ff },
  1308. { BNX2X_CHIP_MASK_ALL,
  1309. DORQ_REG_DB_ADDR0, 4, 0xffffffff },
  1310. { BNX2X_CHIP_MASK_E1X,
  1311. HC_REG_AGG_INT_0, 4, 0x000003ff },
  1312. { BNX2X_CHIP_MASK_ALL,
  1313. PBF_REG_MAC_IF0_ENABLE, 4, 0x00000001 },
  1314. { BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2 | BNX2X_CHIP_MASK_E3,
  1315. PBF_REG_P0_INIT_CRD, 4, 0x000007ff },
  1316. { BNX2X_CHIP_MASK_E3B0,
  1317. PBF_REG_INIT_CRD_Q0, 4, 0x000007ff },
  1318. { BNX2X_CHIP_MASK_ALL,
  1319. PRS_REG_CID_PORT_0, 4, 0x00ffffff },
  1320. { BNX2X_CHIP_MASK_ALL,
  1321. PXP2_REG_PSWRQ_CDU0_L2P, 4, 0x000fffff },
  1322. { BNX2X_CHIP_MASK_ALL,
  1323. PXP2_REG_RQ_CDU0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
  1324. { BNX2X_CHIP_MASK_ALL,
  1325. PXP2_REG_PSWRQ_TM0_L2P, 4, 0x000fffff },
  1326. /* 10 */ { BNX2X_CHIP_MASK_ALL,
  1327. PXP2_REG_RQ_USDM0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
  1328. { BNX2X_CHIP_MASK_ALL,
  1329. PXP2_REG_PSWRQ_TSDM0_L2P, 4, 0x000fffff },
  1330. { BNX2X_CHIP_MASK_ALL,
  1331. QM_REG_CONNNUM_0, 4, 0x000fffff },
  1332. { BNX2X_CHIP_MASK_ALL,
  1333. TM_REG_LIN0_MAX_ACTIVE_CID, 4, 0x0003ffff },
  1334. { BNX2X_CHIP_MASK_ALL,
  1335. SRC_REG_KEYRSS0_0, 40, 0xffffffff },
  1336. { BNX2X_CHIP_MASK_ALL,
  1337. SRC_REG_KEYRSS0_7, 40, 0xffffffff },
  1338. { BNX2X_CHIP_MASK_ALL,
  1339. XCM_REG_WU_DA_SET_TMR_CNT_FLG_CMD00, 4, 0x00000001 },
  1340. { BNX2X_CHIP_MASK_ALL,
  1341. XCM_REG_WU_DA_CNT_CMD00, 4, 0x00000003 },
  1342. { BNX2X_CHIP_MASK_ALL,
  1343. XCM_REG_GLB_DEL_ACK_MAX_CNT_0, 4, 0x000000ff },
  1344. { BNX2X_CHIP_MASK_ALL,
  1345. NIG_REG_LLH0_T_BIT, 4, 0x00000001 },
  1346. /* 20 */ { BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2,
  1347. NIG_REG_EMAC0_IN_EN, 4, 0x00000001 },
  1348. { BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2,
  1349. NIG_REG_BMAC0_IN_EN, 4, 0x00000001 },
  1350. { BNX2X_CHIP_MASK_ALL,
  1351. NIG_REG_XCM0_OUT_EN, 4, 0x00000001 },
  1352. { BNX2X_CHIP_MASK_ALL,
  1353. NIG_REG_BRB0_OUT_EN, 4, 0x00000001 },
  1354. { BNX2X_CHIP_MASK_ALL,
  1355. NIG_REG_LLH0_XCM_MASK, 4, 0x00000007 },
  1356. { BNX2X_CHIP_MASK_ALL,
  1357. NIG_REG_LLH0_ACPI_PAT_6_LEN, 68, 0x000000ff },
  1358. { BNX2X_CHIP_MASK_ALL,
  1359. NIG_REG_LLH0_ACPI_PAT_0_CRC, 68, 0xffffffff },
  1360. { BNX2X_CHIP_MASK_ALL,
  1361. NIG_REG_LLH0_DEST_MAC_0_0, 160, 0xffffffff },
  1362. { BNX2X_CHIP_MASK_ALL,
  1363. NIG_REG_LLH0_DEST_IP_0_1, 160, 0xffffffff },
  1364. { BNX2X_CHIP_MASK_ALL,
  1365. NIG_REG_LLH0_IPV4_IPV6_0, 160, 0x00000001 },
  1366. /* 30 */ { BNX2X_CHIP_MASK_ALL,
  1367. NIG_REG_LLH0_DEST_UDP_0, 160, 0x0000ffff },
  1368. { BNX2X_CHIP_MASK_ALL,
  1369. NIG_REG_LLH0_DEST_TCP_0, 160, 0x0000ffff },
  1370. { BNX2X_CHIP_MASK_ALL,
  1371. NIG_REG_LLH0_VLAN_ID_0, 160, 0x00000fff },
  1372. { BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2,
  1373. NIG_REG_XGXS_SERDES0_MODE_SEL, 4, 0x00000001 },
  1374. { BNX2X_CHIP_MASK_ALL,
  1375. NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0, 4, 0x00000001},
  1376. { BNX2X_CHIP_MASK_ALL,
  1377. NIG_REG_STATUS_INTERRUPT_PORT0, 4, 0x07ffffff },
  1378. { BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2,
  1379. NIG_REG_XGXS0_CTRL_EXTREMOTEMDIOST, 24, 0x00000001 },
  1380. { BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2,
  1381. NIG_REG_SERDES0_CTRL_PHY_ADDR, 16, 0x0000001f },
  1382. { BNX2X_CHIP_MASK_ALL, 0xffffffff, 0, 0x00000000 }
  1383. };
  1384. if (!netif_running(bp->dev))
  1385. return rc;
  1386. if (CHIP_IS_E1(bp))
  1387. hw = BNX2X_CHIP_MASK_E1;
  1388. else if (CHIP_IS_E1H(bp))
  1389. hw = BNX2X_CHIP_MASK_E1H;
  1390. else if (CHIP_IS_E2(bp))
  1391. hw = BNX2X_CHIP_MASK_E2;
  1392. else if (CHIP_IS_E3B0(bp))
  1393. hw = BNX2X_CHIP_MASK_E3B0;
  1394. else /* e3 A0 */
  1395. hw = BNX2X_CHIP_MASK_E3;
  1396. /* Repeat the test twice:
  1397. First by writing 0x00000000, second by writing 0xffffffff */
  1398. for (idx = 0; idx < 2; idx++) {
  1399. switch (idx) {
  1400. case 0:
  1401. wr_val = 0;
  1402. break;
  1403. case 1:
  1404. wr_val = 0xffffffff;
  1405. break;
  1406. }
  1407. for (i = 0; reg_tbl[i].offset0 != 0xffffffff; i++) {
  1408. u32 offset, mask, save_val, val;
  1409. if (!(hw & reg_tbl[i].hw))
  1410. continue;
  1411. offset = reg_tbl[i].offset0 + port*reg_tbl[i].offset1;
  1412. mask = reg_tbl[i].mask;
  1413. save_val = REG_RD(bp, offset);
  1414. REG_WR(bp, offset, wr_val & mask);
  1415. val = REG_RD(bp, offset);
  1416. /* Restore the original register's value */
  1417. REG_WR(bp, offset, save_val);
  1418. /* verify value is as expected */
  1419. if ((val & mask) != (wr_val & mask)) {
  1420. DP(NETIF_MSG_HW,
  1421. "offset 0x%x: val 0x%x != 0x%x mask 0x%x\n",
  1422. offset, val, wr_val, mask);
  1423. goto test_reg_exit;
  1424. }
  1425. }
  1426. }
  1427. rc = 0;
  1428. test_reg_exit:
  1429. return rc;
  1430. }
  1431. static int bnx2x_test_memory(struct bnx2x *bp)
  1432. {
  1433. int i, j, rc = -ENODEV;
  1434. u32 val, index;
  1435. static const struct {
  1436. u32 offset;
  1437. int size;
  1438. } mem_tbl[] = {
  1439. { CCM_REG_XX_DESCR_TABLE, CCM_REG_XX_DESCR_TABLE_SIZE },
  1440. { CFC_REG_ACTIVITY_COUNTER, CFC_REG_ACTIVITY_COUNTER_SIZE },
  1441. { CFC_REG_LINK_LIST, CFC_REG_LINK_LIST_SIZE },
  1442. { DMAE_REG_CMD_MEM, DMAE_REG_CMD_MEM_SIZE },
  1443. { TCM_REG_XX_DESCR_TABLE, TCM_REG_XX_DESCR_TABLE_SIZE },
  1444. { UCM_REG_XX_DESCR_TABLE, UCM_REG_XX_DESCR_TABLE_SIZE },
  1445. { XCM_REG_XX_DESCR_TABLE, XCM_REG_XX_DESCR_TABLE_SIZE },
  1446. { 0xffffffff, 0 }
  1447. };
  1448. static const struct {
  1449. char *name;
  1450. u32 offset;
  1451. u32 hw_mask[BNX2X_CHIP_MAX_OFST];
  1452. } prty_tbl[] = {
  1453. { "CCM_PRTY_STS", CCM_REG_CCM_PRTY_STS,
  1454. {0x3ffc0, 0, 0, 0} },
  1455. { "CFC_PRTY_STS", CFC_REG_CFC_PRTY_STS,
  1456. {0x2, 0x2, 0, 0} },
  1457. { "DMAE_PRTY_STS", DMAE_REG_DMAE_PRTY_STS,
  1458. {0, 0, 0, 0} },
  1459. { "TCM_PRTY_STS", TCM_REG_TCM_PRTY_STS,
  1460. {0x3ffc0, 0, 0, 0} },
  1461. { "UCM_PRTY_STS", UCM_REG_UCM_PRTY_STS,
  1462. {0x3ffc0, 0, 0, 0} },
  1463. { "XCM_PRTY_STS", XCM_REG_XCM_PRTY_STS,
  1464. {0x3ffc1, 0, 0, 0} },
  1465. { NULL, 0xffffffff, {0, 0, 0, 0} }
  1466. };
  1467. if (!netif_running(bp->dev))
  1468. return rc;
  1469. if (CHIP_IS_E1(bp))
  1470. index = BNX2X_CHIP_E1_OFST;
  1471. else if (CHIP_IS_E1H(bp))
  1472. index = BNX2X_CHIP_E1H_OFST;
  1473. else if (CHIP_IS_E2(bp))
  1474. index = BNX2X_CHIP_E2_OFST;
  1475. else /* e3 */
  1476. index = BNX2X_CHIP_E3_OFST;
  1477. /* pre-Check the parity status */
  1478. for (i = 0; prty_tbl[i].offset != 0xffffffff; i++) {
  1479. val = REG_RD(bp, prty_tbl[i].offset);
  1480. if (val & ~(prty_tbl[i].hw_mask[index])) {
  1481. DP(NETIF_MSG_HW,
  1482. "%s is 0x%x\n", prty_tbl[i].name, val);
  1483. goto test_mem_exit;
  1484. }
  1485. }
  1486. /* Go through all the memories */
  1487. for (i = 0; mem_tbl[i].offset != 0xffffffff; i++)
  1488. for (j = 0; j < mem_tbl[i].size; j++)
  1489. REG_RD(bp, mem_tbl[i].offset + j*4);
  1490. /* Check the parity status */
  1491. for (i = 0; prty_tbl[i].offset != 0xffffffff; i++) {
  1492. val = REG_RD(bp, prty_tbl[i].offset);
  1493. if (val & ~(prty_tbl[i].hw_mask[index])) {
  1494. DP(NETIF_MSG_HW,
  1495. "%s is 0x%x\n", prty_tbl[i].name, val);
  1496. goto test_mem_exit;
  1497. }
  1498. }
  1499. rc = 0;
  1500. test_mem_exit:
  1501. return rc;
  1502. }
  1503. static void bnx2x_wait_for_link(struct bnx2x *bp, u8 link_up, u8 is_serdes)
  1504. {
  1505. int cnt = 1400;
  1506. if (link_up) {
  1507. while (bnx2x_link_test(bp, is_serdes) && cnt--)
  1508. msleep(20);
  1509. if (cnt <= 0 && bnx2x_link_test(bp, is_serdes))
  1510. DP(NETIF_MSG_LINK, "Timeout waiting for link up\n");
  1511. }
  1512. }
  1513. static int bnx2x_run_loopback(struct bnx2x *bp, int loopback_mode)
  1514. {
  1515. unsigned int pkt_size, num_pkts, i;
  1516. struct sk_buff *skb;
  1517. unsigned char *packet;
  1518. struct bnx2x_fastpath *fp_rx = &bp->fp[0];
  1519. struct bnx2x_fastpath *fp_tx = &bp->fp[0];
  1520. struct bnx2x_fp_txdata *txdata = &fp_tx->txdata[0];
  1521. u16 tx_start_idx, tx_idx;
  1522. u16 rx_start_idx, rx_idx;
  1523. u16 pkt_prod, bd_prod;
  1524. struct sw_tx_bd *tx_buf;
  1525. struct eth_tx_start_bd *tx_start_bd;
  1526. struct eth_tx_parse_bd_e1x *pbd_e1x = NULL;
  1527. struct eth_tx_parse_bd_e2 *pbd_e2 = NULL;
  1528. dma_addr_t mapping;
  1529. union eth_rx_cqe *cqe;
  1530. u8 cqe_fp_flags, cqe_fp_type;
  1531. struct sw_rx_bd *rx_buf;
  1532. u16 len;
  1533. int rc = -ENODEV;
  1534. u8 *data;
  1535. struct netdev_queue *txq = netdev_get_tx_queue(bp->dev, txdata->txq_index);
  1536. /* check the loopback mode */
  1537. switch (loopback_mode) {
  1538. case BNX2X_PHY_LOOPBACK:
  1539. if (bp->link_params.loopback_mode != LOOPBACK_XGXS)
  1540. return -EINVAL;
  1541. break;
  1542. case BNX2X_MAC_LOOPBACK:
  1543. if (CHIP_IS_E3(bp)) {
  1544. int cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1545. if (bp->port.supported[cfg_idx] &
  1546. (SUPPORTED_10000baseT_Full |
  1547. SUPPORTED_20000baseMLD2_Full |
  1548. SUPPORTED_20000baseKR2_Full))
  1549. bp->link_params.loopback_mode = LOOPBACK_XMAC;
  1550. else
  1551. bp->link_params.loopback_mode = LOOPBACK_UMAC;
  1552. } else
  1553. bp->link_params.loopback_mode = LOOPBACK_BMAC;
  1554. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1555. break;
  1556. default:
  1557. return -EINVAL;
  1558. }
  1559. /* prepare the loopback packet */
  1560. pkt_size = (((bp->dev->mtu < ETH_MAX_PACKET_SIZE) ?
  1561. bp->dev->mtu : ETH_MAX_PACKET_SIZE) + ETH_HLEN);
  1562. skb = netdev_alloc_skb(bp->dev, fp_rx->rx_buf_size);
  1563. if (!skb) {
  1564. rc = -ENOMEM;
  1565. goto test_loopback_exit;
  1566. }
  1567. packet = skb_put(skb, pkt_size);
  1568. memcpy(packet, bp->dev->dev_addr, ETH_ALEN);
  1569. memset(packet + ETH_ALEN, 0, ETH_ALEN);
  1570. memset(packet + 2*ETH_ALEN, 0x77, (ETH_HLEN - 2*ETH_ALEN));
  1571. for (i = ETH_HLEN; i < pkt_size; i++)
  1572. packet[i] = (unsigned char) (i & 0xff);
  1573. mapping = dma_map_single(&bp->pdev->dev, skb->data,
  1574. skb_headlen(skb), DMA_TO_DEVICE);
  1575. if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
  1576. rc = -ENOMEM;
  1577. dev_kfree_skb(skb);
  1578. BNX2X_ERR("Unable to map SKB\n");
  1579. goto test_loopback_exit;
  1580. }
  1581. /* send the loopback packet */
  1582. num_pkts = 0;
  1583. tx_start_idx = le16_to_cpu(*txdata->tx_cons_sb);
  1584. rx_start_idx = le16_to_cpu(*fp_rx->rx_cons_sb);
  1585. netdev_tx_sent_queue(txq, skb->len);
  1586. pkt_prod = txdata->tx_pkt_prod++;
  1587. tx_buf = &txdata->tx_buf_ring[TX_BD(pkt_prod)];
  1588. tx_buf->first_bd = txdata->tx_bd_prod;
  1589. tx_buf->skb = skb;
  1590. tx_buf->flags = 0;
  1591. bd_prod = TX_BD(txdata->tx_bd_prod);
  1592. tx_start_bd = &txdata->tx_desc_ring[bd_prod].start_bd;
  1593. tx_start_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
  1594. tx_start_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
  1595. tx_start_bd->nbd = cpu_to_le16(2); /* start + pbd */
  1596. tx_start_bd->nbytes = cpu_to_le16(skb_headlen(skb));
  1597. tx_start_bd->vlan_or_ethertype = cpu_to_le16(pkt_prod);
  1598. tx_start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
  1599. SET_FLAG(tx_start_bd->general_data,
  1600. ETH_TX_START_BD_ETH_ADDR_TYPE,
  1601. UNICAST_ADDRESS);
  1602. SET_FLAG(tx_start_bd->general_data,
  1603. ETH_TX_START_BD_HDR_NBDS,
  1604. 1);
  1605. /* turn on parsing and get a BD */
  1606. bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
  1607. pbd_e1x = &txdata->tx_desc_ring[bd_prod].parse_bd_e1x;
  1608. pbd_e2 = &txdata->tx_desc_ring[bd_prod].parse_bd_e2;
  1609. memset(pbd_e2, 0, sizeof(struct eth_tx_parse_bd_e2));
  1610. memset(pbd_e1x, 0, sizeof(struct eth_tx_parse_bd_e1x));
  1611. wmb();
  1612. txdata->tx_db.data.prod += 2;
  1613. barrier();
  1614. DOORBELL(bp, txdata->cid, txdata->tx_db.raw);
  1615. mmiowb();
  1616. barrier();
  1617. num_pkts++;
  1618. txdata->tx_bd_prod += 2; /* start + pbd */
  1619. udelay(100);
  1620. tx_idx = le16_to_cpu(*txdata->tx_cons_sb);
  1621. if (tx_idx != tx_start_idx + num_pkts)
  1622. goto test_loopback_exit;
  1623. /* Unlike HC IGU won't generate an interrupt for status block
  1624. * updates that have been performed while interrupts were
  1625. * disabled.
  1626. */
  1627. if (bp->common.int_block == INT_BLOCK_IGU) {
  1628. /* Disable local BHes to prevent a dead-lock situation between
  1629. * sch_direct_xmit() and bnx2x_run_loopback() (calling
  1630. * bnx2x_tx_int()), as both are taking netif_tx_lock().
  1631. */
  1632. local_bh_disable();
  1633. bnx2x_tx_int(bp, txdata);
  1634. local_bh_enable();
  1635. }
  1636. rx_idx = le16_to_cpu(*fp_rx->rx_cons_sb);
  1637. if (rx_idx != rx_start_idx + num_pkts)
  1638. goto test_loopback_exit;
  1639. cqe = &fp_rx->rx_comp_ring[RCQ_BD(fp_rx->rx_comp_cons)];
  1640. cqe_fp_flags = cqe->fast_path_cqe.type_error_flags;
  1641. cqe_fp_type = cqe_fp_flags & ETH_FAST_PATH_RX_CQE_TYPE;
  1642. if (!CQE_TYPE_FAST(cqe_fp_type) || (cqe_fp_flags & ETH_RX_ERROR_FALGS))
  1643. goto test_loopback_rx_exit;
  1644. len = le16_to_cpu(cqe->fast_path_cqe.pkt_len);
  1645. if (len != pkt_size)
  1646. goto test_loopback_rx_exit;
  1647. rx_buf = &fp_rx->rx_buf_ring[RX_BD(fp_rx->rx_bd_cons)];
  1648. dma_sync_single_for_cpu(&bp->pdev->dev,
  1649. dma_unmap_addr(rx_buf, mapping),
  1650. fp_rx->rx_buf_size, DMA_FROM_DEVICE);
  1651. data = rx_buf->data + NET_SKB_PAD + cqe->fast_path_cqe.placement_offset;
  1652. for (i = ETH_HLEN; i < pkt_size; i++)
  1653. if (*(data + i) != (unsigned char) (i & 0xff))
  1654. goto test_loopback_rx_exit;
  1655. rc = 0;
  1656. test_loopback_rx_exit:
  1657. fp_rx->rx_bd_cons = NEXT_RX_IDX(fp_rx->rx_bd_cons);
  1658. fp_rx->rx_bd_prod = NEXT_RX_IDX(fp_rx->rx_bd_prod);
  1659. fp_rx->rx_comp_cons = NEXT_RCQ_IDX(fp_rx->rx_comp_cons);
  1660. fp_rx->rx_comp_prod = NEXT_RCQ_IDX(fp_rx->rx_comp_prod);
  1661. /* Update producers */
  1662. bnx2x_update_rx_prod(bp, fp_rx, fp_rx->rx_bd_prod, fp_rx->rx_comp_prod,
  1663. fp_rx->rx_sge_prod);
  1664. test_loopback_exit:
  1665. bp->link_params.loopback_mode = LOOPBACK_NONE;
  1666. return rc;
  1667. }
  1668. static int bnx2x_test_loopback(struct bnx2x *bp)
  1669. {
  1670. int rc = 0, res;
  1671. if (BP_NOMCP(bp))
  1672. return rc;
  1673. if (!netif_running(bp->dev))
  1674. return BNX2X_LOOPBACK_FAILED;
  1675. bnx2x_netif_stop(bp, 1);
  1676. bnx2x_acquire_phy_lock(bp);
  1677. res = bnx2x_run_loopback(bp, BNX2X_PHY_LOOPBACK);
  1678. if (res) {
  1679. DP(NETIF_MSG_PROBE, " PHY loopback failed (res %d)\n", res);
  1680. rc |= BNX2X_PHY_LOOPBACK_FAILED;
  1681. }
  1682. res = bnx2x_run_loopback(bp, BNX2X_MAC_LOOPBACK);
  1683. if (res) {
  1684. DP(NETIF_MSG_PROBE, " MAC loopback failed (res %d)\n", res);
  1685. rc |= BNX2X_MAC_LOOPBACK_FAILED;
  1686. }
  1687. bnx2x_release_phy_lock(bp);
  1688. bnx2x_netif_start(bp);
  1689. return rc;
  1690. }
  1691. #define CRC32_RESIDUAL 0xdebb20e3
  1692. static int bnx2x_test_nvram(struct bnx2x *bp)
  1693. {
  1694. static const struct {
  1695. int offset;
  1696. int size;
  1697. } nvram_tbl[] = {
  1698. { 0, 0x14 }, /* bootstrap */
  1699. { 0x14, 0xec }, /* dir */
  1700. { 0x100, 0x350 }, /* manuf_info */
  1701. { 0x450, 0xf0 }, /* feature_info */
  1702. { 0x640, 0x64 }, /* upgrade_key_info */
  1703. { 0x708, 0x70 }, /* manuf_key_info */
  1704. { 0, 0 }
  1705. };
  1706. __be32 buf[0x350 / 4];
  1707. u8 *data = (u8 *)buf;
  1708. int i, rc;
  1709. u32 magic, crc;
  1710. if (BP_NOMCP(bp))
  1711. return 0;
  1712. rc = bnx2x_nvram_read(bp, 0, data, 4);
  1713. if (rc) {
  1714. DP(NETIF_MSG_PROBE, "magic value read (rc %d)\n", rc);
  1715. goto test_nvram_exit;
  1716. }
  1717. magic = be32_to_cpu(buf[0]);
  1718. if (magic != 0x669955aa) {
  1719. DP(NETIF_MSG_PROBE, "magic value (0x%08x)\n", magic);
  1720. rc = -ENODEV;
  1721. goto test_nvram_exit;
  1722. }
  1723. for (i = 0; nvram_tbl[i].size; i++) {
  1724. rc = bnx2x_nvram_read(bp, nvram_tbl[i].offset, data,
  1725. nvram_tbl[i].size);
  1726. if (rc) {
  1727. DP(NETIF_MSG_PROBE,
  1728. "nvram_tbl[%d] read data (rc %d)\n", i, rc);
  1729. goto test_nvram_exit;
  1730. }
  1731. crc = ether_crc_le(nvram_tbl[i].size, data);
  1732. if (crc != CRC32_RESIDUAL) {
  1733. DP(NETIF_MSG_PROBE,
  1734. "nvram_tbl[%d] crc value (0x%08x)\n", i, crc);
  1735. rc = -ENODEV;
  1736. goto test_nvram_exit;
  1737. }
  1738. }
  1739. test_nvram_exit:
  1740. return rc;
  1741. }
  1742. /* Send an EMPTY ramrod on the first queue */
  1743. static int bnx2x_test_intr(struct bnx2x *bp)
  1744. {
  1745. struct bnx2x_queue_state_params params = {0};
  1746. if (!netif_running(bp->dev))
  1747. return -ENODEV;
  1748. params.q_obj = &bp->fp->q_obj;
  1749. params.cmd = BNX2X_Q_CMD_EMPTY;
  1750. __set_bit(RAMROD_COMP_WAIT, &params.ramrod_flags);
  1751. return bnx2x_queue_state_change(bp, &params);
  1752. }
  1753. static void bnx2x_self_test(struct net_device *dev,
  1754. struct ethtool_test *etest, u64 *buf)
  1755. {
  1756. struct bnx2x *bp = netdev_priv(dev);
  1757. u8 is_serdes;
  1758. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  1759. netdev_err(bp->dev, "Handling parity error recovery. "
  1760. "Try again later\n");
  1761. etest->flags |= ETH_TEST_FL_FAILED;
  1762. return;
  1763. }
  1764. memset(buf, 0, sizeof(u64) * BNX2X_NUM_TESTS);
  1765. if (!netif_running(dev))
  1766. return;
  1767. /* offline tests are not supported in MF mode */
  1768. if (IS_MF(bp))
  1769. etest->flags &= ~ETH_TEST_FL_OFFLINE;
  1770. is_serdes = (bp->link_vars.link_status & LINK_STATUS_SERDES_LINK) > 0;
  1771. if (etest->flags & ETH_TEST_FL_OFFLINE) {
  1772. int port = BP_PORT(bp);
  1773. u32 val;
  1774. u8 link_up;
  1775. /* save current value of input enable for TX port IF */
  1776. val = REG_RD(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4);
  1777. /* disable input for TX port IF */
  1778. REG_WR(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4, 0);
  1779. link_up = bp->link_vars.link_up;
  1780. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  1781. bnx2x_nic_load(bp, LOAD_DIAG);
  1782. /* wait until link state is restored */
  1783. bnx2x_wait_for_link(bp, 1, is_serdes);
  1784. if (bnx2x_test_registers(bp) != 0) {
  1785. buf[0] = 1;
  1786. etest->flags |= ETH_TEST_FL_FAILED;
  1787. }
  1788. if (bnx2x_test_memory(bp) != 0) {
  1789. buf[1] = 1;
  1790. etest->flags |= ETH_TEST_FL_FAILED;
  1791. }
  1792. buf[2] = bnx2x_test_loopback(bp);
  1793. if (buf[2] != 0)
  1794. etest->flags |= ETH_TEST_FL_FAILED;
  1795. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  1796. /* restore input for TX port IF */
  1797. REG_WR(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4, val);
  1798. bnx2x_nic_load(bp, LOAD_NORMAL);
  1799. /* wait until link state is restored */
  1800. bnx2x_wait_for_link(bp, link_up, is_serdes);
  1801. }
  1802. if (bnx2x_test_nvram(bp) != 0) {
  1803. buf[3] = 1;
  1804. etest->flags |= ETH_TEST_FL_FAILED;
  1805. }
  1806. if (bnx2x_test_intr(bp) != 0) {
  1807. buf[4] = 1;
  1808. etest->flags |= ETH_TEST_FL_FAILED;
  1809. }
  1810. if (bnx2x_link_test(bp, is_serdes) != 0) {
  1811. buf[5] = 1;
  1812. etest->flags |= ETH_TEST_FL_FAILED;
  1813. }
  1814. #ifdef BNX2X_EXTRA_DEBUG
  1815. bnx2x_panic_dump(bp);
  1816. #endif
  1817. }
  1818. #define IS_PORT_STAT(i) \
  1819. ((bnx2x_stats_arr[i].flags & STATS_FLAGS_BOTH) == STATS_FLAGS_PORT)
  1820. #define IS_FUNC_STAT(i) (bnx2x_stats_arr[i].flags & STATS_FLAGS_FUNC)
  1821. #define IS_MF_MODE_STAT(bp) \
  1822. (IS_MF(bp) && !(bp->msg_enable & BNX2X_MSG_STATS))
  1823. /* ethtool statistics are displayed for all regular ethernet queues and the
  1824. * fcoe L2 queue if not disabled
  1825. */
  1826. static inline int bnx2x_num_stat_queues(struct bnx2x *bp)
  1827. {
  1828. return BNX2X_NUM_ETH_QUEUES(bp);
  1829. }
  1830. static int bnx2x_get_sset_count(struct net_device *dev, int stringset)
  1831. {
  1832. struct bnx2x *bp = netdev_priv(dev);
  1833. int i, num_stats;
  1834. switch (stringset) {
  1835. case ETH_SS_STATS:
  1836. if (is_multi(bp)) {
  1837. num_stats = bnx2x_num_stat_queues(bp) *
  1838. BNX2X_NUM_Q_STATS;
  1839. } else
  1840. num_stats = 0;
  1841. if (IS_MF_MODE_STAT(bp)) {
  1842. for (i = 0; i < BNX2X_NUM_STATS; i++)
  1843. if (IS_FUNC_STAT(i))
  1844. num_stats++;
  1845. } else
  1846. num_stats += BNX2X_NUM_STATS;
  1847. return num_stats;
  1848. case ETH_SS_TEST:
  1849. return BNX2X_NUM_TESTS;
  1850. default:
  1851. return -EINVAL;
  1852. }
  1853. }
  1854. static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
  1855. {
  1856. struct bnx2x *bp = netdev_priv(dev);
  1857. int i, j, k;
  1858. char queue_name[MAX_QUEUE_NAME_LEN+1];
  1859. switch (stringset) {
  1860. case ETH_SS_STATS:
  1861. k = 0;
  1862. if (is_multi(bp)) {
  1863. for_each_eth_queue(bp, i) {
  1864. memset(queue_name, 0, sizeof(queue_name));
  1865. sprintf(queue_name, "%d", i);
  1866. for (j = 0; j < BNX2X_NUM_Q_STATS; j++)
  1867. snprintf(buf + (k + j)*ETH_GSTRING_LEN,
  1868. ETH_GSTRING_LEN,
  1869. bnx2x_q_stats_arr[j].string,
  1870. queue_name);
  1871. k += BNX2X_NUM_Q_STATS;
  1872. }
  1873. }
  1874. for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
  1875. if (IS_MF_MODE_STAT(bp) && IS_PORT_STAT(i))
  1876. continue;
  1877. strcpy(buf + (k + j)*ETH_GSTRING_LEN,
  1878. bnx2x_stats_arr[i].string);
  1879. j++;
  1880. }
  1881. break;
  1882. case ETH_SS_TEST:
  1883. memcpy(buf, bnx2x_tests_str_arr, sizeof(bnx2x_tests_str_arr));
  1884. break;
  1885. }
  1886. }
  1887. static void bnx2x_get_ethtool_stats(struct net_device *dev,
  1888. struct ethtool_stats *stats, u64 *buf)
  1889. {
  1890. struct bnx2x *bp = netdev_priv(dev);
  1891. u32 *hw_stats, *offset;
  1892. int i, j, k = 0;
  1893. if (is_multi(bp)) {
  1894. for_each_eth_queue(bp, i) {
  1895. hw_stats = (u32 *)&bp->fp[i].eth_q_stats;
  1896. for (j = 0; j < BNX2X_NUM_Q_STATS; j++) {
  1897. if (bnx2x_q_stats_arr[j].size == 0) {
  1898. /* skip this counter */
  1899. buf[k + j] = 0;
  1900. continue;
  1901. }
  1902. offset = (hw_stats +
  1903. bnx2x_q_stats_arr[j].offset);
  1904. if (bnx2x_q_stats_arr[j].size == 4) {
  1905. /* 4-byte counter */
  1906. buf[k + j] = (u64) *offset;
  1907. continue;
  1908. }
  1909. /* 8-byte counter */
  1910. buf[k + j] = HILO_U64(*offset, *(offset + 1));
  1911. }
  1912. k += BNX2X_NUM_Q_STATS;
  1913. }
  1914. }
  1915. hw_stats = (u32 *)&bp->eth_stats;
  1916. for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
  1917. if (IS_MF_MODE_STAT(bp) && IS_PORT_STAT(i))
  1918. continue;
  1919. if (bnx2x_stats_arr[i].size == 0) {
  1920. /* skip this counter */
  1921. buf[k + j] = 0;
  1922. j++;
  1923. continue;
  1924. }
  1925. offset = (hw_stats + bnx2x_stats_arr[i].offset);
  1926. if (bnx2x_stats_arr[i].size == 4) {
  1927. /* 4-byte counter */
  1928. buf[k + j] = (u64) *offset;
  1929. j++;
  1930. continue;
  1931. }
  1932. /* 8-byte counter */
  1933. buf[k + j] = HILO_U64(*offset, *(offset + 1));
  1934. j++;
  1935. }
  1936. }
  1937. static int bnx2x_set_phys_id(struct net_device *dev,
  1938. enum ethtool_phys_id_state state)
  1939. {
  1940. struct bnx2x *bp = netdev_priv(dev);
  1941. if (!netif_running(dev))
  1942. return -EAGAIN;
  1943. if (!bp->port.pmf)
  1944. return -EOPNOTSUPP;
  1945. switch (state) {
  1946. case ETHTOOL_ID_ACTIVE:
  1947. return 1; /* cycle on/off once per second */
  1948. case ETHTOOL_ID_ON:
  1949. bnx2x_set_led(&bp->link_params, &bp->link_vars,
  1950. LED_MODE_ON, SPEED_1000);
  1951. break;
  1952. case ETHTOOL_ID_OFF:
  1953. bnx2x_set_led(&bp->link_params, &bp->link_vars,
  1954. LED_MODE_FRONT_PANEL_OFF, 0);
  1955. break;
  1956. case ETHTOOL_ID_INACTIVE:
  1957. bnx2x_set_led(&bp->link_params, &bp->link_vars,
  1958. LED_MODE_OPER,
  1959. bp->link_vars.line_speed);
  1960. }
  1961. return 0;
  1962. }
  1963. static int bnx2x_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
  1964. u32 *rules __always_unused)
  1965. {
  1966. struct bnx2x *bp = netdev_priv(dev);
  1967. switch (info->cmd) {
  1968. case ETHTOOL_GRXRINGS:
  1969. info->data = BNX2X_NUM_ETH_QUEUES(bp);
  1970. return 0;
  1971. default:
  1972. return -EOPNOTSUPP;
  1973. }
  1974. }
  1975. static u32 bnx2x_get_rxfh_indir_size(struct net_device *dev)
  1976. {
  1977. struct bnx2x *bp = netdev_priv(dev);
  1978. return (bp->multi_mode == ETH_RSS_MODE_DISABLED ?
  1979. 0 : T_ETH_INDIRECTION_TABLE_SIZE);
  1980. }
  1981. static int bnx2x_get_rxfh_indir(struct net_device *dev, u32 *indir)
  1982. {
  1983. struct bnx2x *bp = netdev_priv(dev);
  1984. u8 ind_table[T_ETH_INDIRECTION_TABLE_SIZE] = {0};
  1985. size_t i;
  1986. /* Get the current configuration of the RSS indirection table */
  1987. bnx2x_get_rss_ind_table(&bp->rss_conf_obj, ind_table);
  1988. /*
  1989. * We can't use a memcpy() as an internal storage of an
  1990. * indirection table is a u8 array while indir->ring_index
  1991. * points to an array of u32.
  1992. *
  1993. * Indirection table contains the FW Client IDs, so we need to
  1994. * align the returned table to the Client ID of the leading RSS
  1995. * queue.
  1996. */
  1997. for (i = 0; i < T_ETH_INDIRECTION_TABLE_SIZE; i++)
  1998. indir[i] = ind_table[i] - bp->fp->cl_id;
  1999. return 0;
  2000. }
  2001. static int bnx2x_set_rxfh_indir(struct net_device *dev, const u32 *indir)
  2002. {
  2003. struct bnx2x *bp = netdev_priv(dev);
  2004. size_t i;
  2005. u8 ind_table[T_ETH_INDIRECTION_TABLE_SIZE] = {0};
  2006. for (i = 0; i < T_ETH_INDIRECTION_TABLE_SIZE; i++) {
  2007. /*
  2008. * The same as in bnx2x_get_rxfh_indir: we can't use a memcpy()
  2009. * as an internal storage of an indirection table is a u8 array
  2010. * while indir->ring_index points to an array of u32.
  2011. *
  2012. * Indirection table contains the FW Client IDs, so we need to
  2013. * align the received table to the Client ID of the leading RSS
  2014. * queue
  2015. */
  2016. ind_table[i] = indir[i] + bp->fp->cl_id;
  2017. }
  2018. return bnx2x_config_rss_pf(bp, ind_table, false);
  2019. }
  2020. static const struct ethtool_ops bnx2x_ethtool_ops = {
  2021. .get_settings = bnx2x_get_settings,
  2022. .set_settings = bnx2x_set_settings,
  2023. .get_drvinfo = bnx2x_get_drvinfo,
  2024. .get_regs_len = bnx2x_get_regs_len,
  2025. .get_regs = bnx2x_get_regs,
  2026. .get_wol = bnx2x_get_wol,
  2027. .set_wol = bnx2x_set_wol,
  2028. .get_msglevel = bnx2x_get_msglevel,
  2029. .set_msglevel = bnx2x_set_msglevel,
  2030. .nway_reset = bnx2x_nway_reset,
  2031. .get_link = bnx2x_get_link,
  2032. .get_eeprom_len = bnx2x_get_eeprom_len,
  2033. .get_eeprom = bnx2x_get_eeprom,
  2034. .set_eeprom = bnx2x_set_eeprom,
  2035. .get_coalesce = bnx2x_get_coalesce,
  2036. .set_coalesce = bnx2x_set_coalesce,
  2037. .get_ringparam = bnx2x_get_ringparam,
  2038. .set_ringparam = bnx2x_set_ringparam,
  2039. .get_pauseparam = bnx2x_get_pauseparam,
  2040. .set_pauseparam = bnx2x_set_pauseparam,
  2041. .self_test = bnx2x_self_test,
  2042. .get_sset_count = bnx2x_get_sset_count,
  2043. .get_strings = bnx2x_get_strings,
  2044. .set_phys_id = bnx2x_set_phys_id,
  2045. .get_ethtool_stats = bnx2x_get_ethtool_stats,
  2046. .get_rxnfc = bnx2x_get_rxnfc,
  2047. .get_rxfh_indir_size = bnx2x_get_rxfh_indir_size,
  2048. .get_rxfh_indir = bnx2x_get_rxfh_indir,
  2049. .set_rxfh_indir = bnx2x_set_rxfh_indir,
  2050. };
  2051. void bnx2x_set_ethtool_ops(struct net_device *netdev)
  2052. {
  2053. SET_ETHTOOL_OPS(netdev, &bnx2x_ethtool_ops);
  2054. }