bnx2x_ethtool.c 64 KB

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