bnx2x_ethtool.c 65 KB

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