bnx2x_ethtool.c 67 KB

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