bnx2x_ethtool.c 61 KB

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