bnx2x_ethtool.c 58 KB

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