bnx2x_ethtool.c 54 KB

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