bnx2x_ethtool.c 58 KB

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