bnx2x_ethtool.c 59 KB

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