bnx2x_ethtool.c 58 KB

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