bnx2x_ethtool.c 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028
  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_MF(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_MF(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. if (bp->rx_ring_size)
  783. ering->rx_pending = bp->rx_ring_size;
  784. else
  785. if (bp->state == BNX2X_STATE_OPEN && bp->num_queues)
  786. ering->rx_pending = MAX_RX_AVAIL/bp->num_queues;
  787. else
  788. ering->rx_pending = MAX_RX_AVAIL;
  789. ering->rx_mini_pending = 0;
  790. ering->rx_jumbo_pending = 0;
  791. ering->tx_max_pending = MAX_TX_AVAIL;
  792. ering->tx_pending = bp->tx_ring_size;
  793. }
  794. static int bnx2x_set_ringparam(struct net_device *dev,
  795. struct ethtool_ringparam *ering)
  796. {
  797. struct bnx2x *bp = netdev_priv(dev);
  798. int rc = 0;
  799. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  800. printk(KERN_ERR "Handling parity error recovery. Try again later\n");
  801. return -EAGAIN;
  802. }
  803. if ((ering->rx_pending > MAX_RX_AVAIL) ||
  804. (ering->rx_pending < MIN_RX_AVAIL) ||
  805. (ering->tx_pending > MAX_TX_AVAIL) ||
  806. (ering->tx_pending <= MAX_SKB_FRAGS + 4))
  807. return -EINVAL;
  808. bp->rx_ring_size = ering->rx_pending;
  809. bp->tx_ring_size = ering->tx_pending;
  810. if (netif_running(dev)) {
  811. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  812. rc = bnx2x_nic_load(bp, LOAD_NORMAL);
  813. }
  814. return rc;
  815. }
  816. static void bnx2x_get_pauseparam(struct net_device *dev,
  817. struct ethtool_pauseparam *epause)
  818. {
  819. struct bnx2x *bp = netdev_priv(dev);
  820. int cfg_idx = bnx2x_get_link_cfg_idx(bp);
  821. epause->autoneg = (bp->link_params.req_flow_ctrl[cfg_idx] ==
  822. BNX2X_FLOW_CTRL_AUTO);
  823. epause->rx_pause = ((bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_RX) ==
  824. BNX2X_FLOW_CTRL_RX);
  825. epause->tx_pause = ((bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX) ==
  826. BNX2X_FLOW_CTRL_TX);
  827. DP(NETIF_MSG_LINK, "ethtool_pauseparam: cmd %d\n"
  828. DP_LEVEL " autoneg %d rx_pause %d tx_pause %d\n",
  829. epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);
  830. }
  831. static int bnx2x_set_pauseparam(struct net_device *dev,
  832. struct ethtool_pauseparam *epause)
  833. {
  834. struct bnx2x *bp = netdev_priv(dev);
  835. u32 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  836. if (IS_MF(bp))
  837. return 0;
  838. DP(NETIF_MSG_LINK, "ethtool_pauseparam: cmd %d\n"
  839. DP_LEVEL " autoneg %d rx_pause %d tx_pause %d\n",
  840. epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);
  841. bp->link_params.req_flow_ctrl[cfg_idx] = BNX2X_FLOW_CTRL_AUTO;
  842. if (epause->rx_pause)
  843. bp->link_params.req_flow_ctrl[cfg_idx] |= BNX2X_FLOW_CTRL_RX;
  844. if (epause->tx_pause)
  845. bp->link_params.req_flow_ctrl[cfg_idx] |= BNX2X_FLOW_CTRL_TX;
  846. if (bp->link_params.req_flow_ctrl[cfg_idx] == BNX2X_FLOW_CTRL_AUTO)
  847. bp->link_params.req_flow_ctrl[cfg_idx] = BNX2X_FLOW_CTRL_NONE;
  848. if (epause->autoneg) {
  849. if (!(bp->port.supported[cfg_idx] & SUPPORTED_Autoneg)) {
  850. DP(NETIF_MSG_LINK, "autoneg not supported\n");
  851. return -EINVAL;
  852. }
  853. if (bp->link_params.req_line_speed[cfg_idx] == SPEED_AUTO_NEG) {
  854. bp->link_params.req_flow_ctrl[cfg_idx] =
  855. BNX2X_FLOW_CTRL_AUTO;
  856. }
  857. }
  858. DP(NETIF_MSG_LINK,
  859. "req_flow_ctrl 0x%x\n", bp->link_params.req_flow_ctrl[cfg_idx]);
  860. if (netif_running(dev)) {
  861. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  862. bnx2x_link_set(bp);
  863. }
  864. return 0;
  865. }
  866. static int bnx2x_set_flags(struct net_device *dev, u32 data)
  867. {
  868. struct bnx2x *bp = netdev_priv(dev);
  869. int changed = 0;
  870. int rc = 0;
  871. if (data & ~(ETH_FLAG_LRO | ETH_FLAG_RXHASH))
  872. return -EINVAL;
  873. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  874. printk(KERN_ERR "Handling parity error recovery. Try again later\n");
  875. return -EAGAIN;
  876. }
  877. /* TPA requires Rx CSUM offloading */
  878. if ((data & ETH_FLAG_LRO) && bp->rx_csum) {
  879. if (!bp->disable_tpa) {
  880. if (!(dev->features & NETIF_F_LRO)) {
  881. dev->features |= NETIF_F_LRO;
  882. bp->flags |= TPA_ENABLE_FLAG;
  883. changed = 1;
  884. }
  885. } else
  886. rc = -EINVAL;
  887. } else if (dev->features & NETIF_F_LRO) {
  888. dev->features &= ~NETIF_F_LRO;
  889. bp->flags &= ~TPA_ENABLE_FLAG;
  890. changed = 1;
  891. }
  892. if (data & ETH_FLAG_RXHASH)
  893. dev->features |= NETIF_F_RXHASH;
  894. else
  895. dev->features &= ~NETIF_F_RXHASH;
  896. if (changed && netif_running(dev)) {
  897. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  898. rc = bnx2x_nic_load(bp, LOAD_NORMAL);
  899. }
  900. return rc;
  901. }
  902. static u32 bnx2x_get_rx_csum(struct net_device *dev)
  903. {
  904. struct bnx2x *bp = netdev_priv(dev);
  905. return bp->rx_csum;
  906. }
  907. static int bnx2x_set_rx_csum(struct net_device *dev, u32 data)
  908. {
  909. struct bnx2x *bp = netdev_priv(dev);
  910. int rc = 0;
  911. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  912. printk(KERN_ERR "Handling parity error recovery. Try again later\n");
  913. return -EAGAIN;
  914. }
  915. bp->rx_csum = data;
  916. /* Disable TPA, when Rx CSUM is disabled. Otherwise all
  917. TPA'ed packets will be discarded due to wrong TCP CSUM */
  918. if (!data) {
  919. u32 flags = ethtool_op_get_flags(dev);
  920. rc = bnx2x_set_flags(dev, (flags & ~ETH_FLAG_LRO));
  921. }
  922. return rc;
  923. }
  924. static int bnx2x_set_tso(struct net_device *dev, u32 data)
  925. {
  926. if (data) {
  927. dev->features |= (NETIF_F_TSO | NETIF_F_TSO_ECN);
  928. dev->features |= NETIF_F_TSO6;
  929. } else {
  930. dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO_ECN);
  931. dev->features &= ~NETIF_F_TSO6;
  932. }
  933. return 0;
  934. }
  935. static const struct {
  936. char string[ETH_GSTRING_LEN];
  937. } bnx2x_tests_str_arr[BNX2X_NUM_TESTS] = {
  938. { "register_test (offline)" },
  939. { "memory_test (offline)" },
  940. { "loopback_test (offline)" },
  941. { "nvram_test (online)" },
  942. { "interrupt_test (online)" },
  943. { "link_test (online)" },
  944. { "idle check (online)" }
  945. };
  946. static int bnx2x_test_registers(struct bnx2x *bp)
  947. {
  948. int idx, i, rc = -ENODEV;
  949. u32 wr_val = 0;
  950. int port = BP_PORT(bp);
  951. static const struct {
  952. u32 offset0;
  953. u32 offset1;
  954. u32 mask;
  955. } reg_tbl[] = {
  956. /* 0 */ { BRB1_REG_PAUSE_LOW_THRESHOLD_0, 4, 0x000003ff },
  957. { DORQ_REG_DB_ADDR0, 4, 0xffffffff },
  958. { HC_REG_AGG_INT_0, 4, 0x000003ff },
  959. { PBF_REG_MAC_IF0_ENABLE, 4, 0x00000001 },
  960. { PBF_REG_P0_INIT_CRD, 4, 0x000007ff },
  961. { PRS_REG_CID_PORT_0, 4, 0x00ffffff },
  962. { PXP2_REG_PSWRQ_CDU0_L2P, 4, 0x000fffff },
  963. { PXP2_REG_RQ_CDU0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
  964. { PXP2_REG_PSWRQ_TM0_L2P, 4, 0x000fffff },
  965. { PXP2_REG_RQ_USDM0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
  966. /* 10 */ { PXP2_REG_PSWRQ_TSDM0_L2P, 4, 0x000fffff },
  967. { QM_REG_CONNNUM_0, 4, 0x000fffff },
  968. { TM_REG_LIN0_MAX_ACTIVE_CID, 4, 0x0003ffff },
  969. { SRC_REG_KEYRSS0_0, 40, 0xffffffff },
  970. { SRC_REG_KEYRSS0_7, 40, 0xffffffff },
  971. { XCM_REG_WU_DA_SET_TMR_CNT_FLG_CMD00, 4, 0x00000001 },
  972. { XCM_REG_WU_DA_CNT_CMD00, 4, 0x00000003 },
  973. { XCM_REG_GLB_DEL_ACK_MAX_CNT_0, 4, 0x000000ff },
  974. { NIG_REG_LLH0_T_BIT, 4, 0x00000001 },
  975. { NIG_REG_EMAC0_IN_EN, 4, 0x00000001 },
  976. /* 20 */ { NIG_REG_BMAC0_IN_EN, 4, 0x00000001 },
  977. { NIG_REG_XCM0_OUT_EN, 4, 0x00000001 },
  978. { NIG_REG_BRB0_OUT_EN, 4, 0x00000001 },
  979. { NIG_REG_LLH0_XCM_MASK, 4, 0x00000007 },
  980. { NIG_REG_LLH0_ACPI_PAT_6_LEN, 68, 0x000000ff },
  981. { NIG_REG_LLH0_ACPI_PAT_0_CRC, 68, 0xffffffff },
  982. { NIG_REG_LLH0_DEST_MAC_0_0, 160, 0xffffffff },
  983. { NIG_REG_LLH0_DEST_IP_0_1, 160, 0xffffffff },
  984. { NIG_REG_LLH0_IPV4_IPV6_0, 160, 0x00000001 },
  985. { NIG_REG_LLH0_DEST_UDP_0, 160, 0x0000ffff },
  986. /* 30 */ { NIG_REG_LLH0_DEST_TCP_0, 160, 0x0000ffff },
  987. { NIG_REG_LLH0_VLAN_ID_0, 160, 0x00000fff },
  988. { NIG_REG_XGXS_SERDES0_MODE_SEL, 4, 0x00000001 },
  989. { NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0, 4, 0x00000001 },
  990. { NIG_REG_STATUS_INTERRUPT_PORT0, 4, 0x07ffffff },
  991. { NIG_REG_XGXS0_CTRL_EXTREMOTEMDIOST, 24, 0x00000001 },
  992. { NIG_REG_SERDES0_CTRL_PHY_ADDR, 16, 0x0000001f },
  993. { 0xffffffff, 0, 0x00000000 }
  994. };
  995. if (!netif_running(bp->dev))
  996. return rc;
  997. /* Repeat the test twice:
  998. First by writing 0x00000000, second by writing 0xffffffff */
  999. for (idx = 0; idx < 2; idx++) {
  1000. switch (idx) {
  1001. case 0:
  1002. wr_val = 0;
  1003. break;
  1004. case 1:
  1005. wr_val = 0xffffffff;
  1006. break;
  1007. }
  1008. for (i = 0; reg_tbl[i].offset0 != 0xffffffff; i++) {
  1009. u32 offset, mask, save_val, val;
  1010. offset = reg_tbl[i].offset0 + port*reg_tbl[i].offset1;
  1011. mask = reg_tbl[i].mask;
  1012. save_val = REG_RD(bp, offset);
  1013. REG_WR(bp, offset, (wr_val & mask));
  1014. val = REG_RD(bp, offset);
  1015. /* Restore the original register's value */
  1016. REG_WR(bp, offset, save_val);
  1017. /* verify value is as expected */
  1018. if ((val & mask) != (wr_val & mask)) {
  1019. DP(NETIF_MSG_PROBE,
  1020. "offset 0x%x: val 0x%x != 0x%x mask 0x%x\n",
  1021. offset, val, wr_val, mask);
  1022. goto test_reg_exit;
  1023. }
  1024. }
  1025. }
  1026. rc = 0;
  1027. test_reg_exit:
  1028. return rc;
  1029. }
  1030. static int bnx2x_test_memory(struct bnx2x *bp)
  1031. {
  1032. int i, j, rc = -ENODEV;
  1033. u32 val;
  1034. static const struct {
  1035. u32 offset;
  1036. int size;
  1037. } mem_tbl[] = {
  1038. { CCM_REG_XX_DESCR_TABLE, CCM_REG_XX_DESCR_TABLE_SIZE },
  1039. { CFC_REG_ACTIVITY_COUNTER, CFC_REG_ACTIVITY_COUNTER_SIZE },
  1040. { CFC_REG_LINK_LIST, CFC_REG_LINK_LIST_SIZE },
  1041. { DMAE_REG_CMD_MEM, DMAE_REG_CMD_MEM_SIZE },
  1042. { TCM_REG_XX_DESCR_TABLE, TCM_REG_XX_DESCR_TABLE_SIZE },
  1043. { UCM_REG_XX_DESCR_TABLE, UCM_REG_XX_DESCR_TABLE_SIZE },
  1044. { XCM_REG_XX_DESCR_TABLE, XCM_REG_XX_DESCR_TABLE_SIZE },
  1045. { 0xffffffff, 0 }
  1046. };
  1047. static const struct {
  1048. char *name;
  1049. u32 offset;
  1050. u32 e1_mask;
  1051. u32 e1h_mask;
  1052. } prty_tbl[] = {
  1053. { "CCM_PRTY_STS", CCM_REG_CCM_PRTY_STS, 0x3ffc0, 0 },
  1054. { "CFC_PRTY_STS", CFC_REG_CFC_PRTY_STS, 0x2, 0x2 },
  1055. { "DMAE_PRTY_STS", DMAE_REG_DMAE_PRTY_STS, 0, 0 },
  1056. { "TCM_PRTY_STS", TCM_REG_TCM_PRTY_STS, 0x3ffc0, 0 },
  1057. { "UCM_PRTY_STS", UCM_REG_UCM_PRTY_STS, 0x3ffc0, 0 },
  1058. { "XCM_PRTY_STS", XCM_REG_XCM_PRTY_STS, 0x3ffc1, 0 },
  1059. { NULL, 0xffffffff, 0, 0 }
  1060. };
  1061. if (!netif_running(bp->dev))
  1062. return rc;
  1063. /* Go through all the memories */
  1064. for (i = 0; mem_tbl[i].offset != 0xffffffff; i++)
  1065. for (j = 0; j < mem_tbl[i].size; j++)
  1066. REG_RD(bp, mem_tbl[i].offset + j*4);
  1067. /* Check the parity status */
  1068. for (i = 0; prty_tbl[i].offset != 0xffffffff; i++) {
  1069. val = REG_RD(bp, prty_tbl[i].offset);
  1070. if ((CHIP_IS_E1(bp) && (val & ~(prty_tbl[i].e1_mask))) ||
  1071. (CHIP_IS_E1H(bp) && (val & ~(prty_tbl[i].e1h_mask)))) {
  1072. DP(NETIF_MSG_HW,
  1073. "%s is 0x%x\n", prty_tbl[i].name, val);
  1074. goto test_mem_exit;
  1075. }
  1076. }
  1077. rc = 0;
  1078. test_mem_exit:
  1079. return rc;
  1080. }
  1081. static void bnx2x_wait_for_link(struct bnx2x *bp, u8 link_up, u8 is_serdes)
  1082. {
  1083. int cnt = 1000;
  1084. if (link_up)
  1085. while (bnx2x_link_test(bp, is_serdes) && cnt--)
  1086. msleep(10);
  1087. }
  1088. static int bnx2x_run_loopback(struct bnx2x *bp, int loopback_mode, u8 link_up)
  1089. {
  1090. unsigned int pkt_size, num_pkts, i;
  1091. struct sk_buff *skb;
  1092. unsigned char *packet;
  1093. struct bnx2x_fastpath *fp_rx = &bp->fp[0];
  1094. struct bnx2x_fastpath *fp_tx = &bp->fp[0];
  1095. u16 tx_start_idx, tx_idx;
  1096. u16 rx_start_idx, rx_idx;
  1097. u16 pkt_prod, bd_prod;
  1098. struct sw_tx_bd *tx_buf;
  1099. struct eth_tx_start_bd *tx_start_bd;
  1100. struct eth_tx_parse_bd_e1x *pbd_e1x = NULL;
  1101. dma_addr_t mapping;
  1102. union eth_rx_cqe *cqe;
  1103. u8 cqe_fp_flags;
  1104. struct sw_rx_bd *rx_buf;
  1105. u16 len;
  1106. int rc = -ENODEV;
  1107. /* check the loopback mode */
  1108. switch (loopback_mode) {
  1109. case BNX2X_PHY_LOOPBACK:
  1110. if (bp->link_params.loopback_mode != LOOPBACK_XGXS)
  1111. return -EINVAL;
  1112. break;
  1113. case BNX2X_MAC_LOOPBACK:
  1114. bp->link_params.loopback_mode = LOOPBACK_BMAC;
  1115. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1116. break;
  1117. default:
  1118. return -EINVAL;
  1119. }
  1120. /* prepare the loopback packet */
  1121. pkt_size = (((bp->dev->mtu < ETH_MAX_PACKET_SIZE) ?
  1122. bp->dev->mtu : ETH_MAX_PACKET_SIZE) + ETH_HLEN);
  1123. skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size);
  1124. if (!skb) {
  1125. rc = -ENOMEM;
  1126. goto test_loopback_exit;
  1127. }
  1128. packet = skb_put(skb, pkt_size);
  1129. memcpy(packet, bp->dev->dev_addr, ETH_ALEN);
  1130. memset(packet + ETH_ALEN, 0, ETH_ALEN);
  1131. memset(packet + 2*ETH_ALEN, 0x77, (ETH_HLEN - 2*ETH_ALEN));
  1132. for (i = ETH_HLEN; i < pkt_size; i++)
  1133. packet[i] = (unsigned char) (i & 0xff);
  1134. /* send the loopback packet */
  1135. num_pkts = 0;
  1136. tx_start_idx = le16_to_cpu(*fp_tx->tx_cons_sb);
  1137. rx_start_idx = le16_to_cpu(*fp_rx->rx_cons_sb);
  1138. pkt_prod = fp_tx->tx_pkt_prod++;
  1139. tx_buf = &fp_tx->tx_buf_ring[TX_BD(pkt_prod)];
  1140. tx_buf->first_bd = fp_tx->tx_bd_prod;
  1141. tx_buf->skb = skb;
  1142. tx_buf->flags = 0;
  1143. bd_prod = TX_BD(fp_tx->tx_bd_prod);
  1144. tx_start_bd = &fp_tx->tx_desc_ring[bd_prod].start_bd;
  1145. mapping = dma_map_single(&bp->pdev->dev, skb->data,
  1146. skb_headlen(skb), DMA_TO_DEVICE);
  1147. tx_start_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
  1148. tx_start_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
  1149. tx_start_bd->nbd = cpu_to_le16(2); /* start + pbd */
  1150. tx_start_bd->nbytes = cpu_to_le16(skb_headlen(skb));
  1151. tx_start_bd->vlan_or_ethertype = cpu_to_le16(pkt_prod);
  1152. tx_start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
  1153. SET_FLAG(tx_start_bd->general_data,
  1154. ETH_TX_START_BD_ETH_ADDR_TYPE,
  1155. UNICAST_ADDRESS);
  1156. SET_FLAG(tx_start_bd->general_data,
  1157. ETH_TX_START_BD_HDR_NBDS,
  1158. 1);
  1159. /* turn on parsing and get a BD */
  1160. bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
  1161. pbd_e1x = &fp_tx->tx_desc_ring[bd_prod].parse_bd_e1x;
  1162. memset(pbd_e1x, 0, sizeof(struct eth_tx_parse_bd_e1x));
  1163. wmb();
  1164. fp_tx->tx_db.data.prod += 2;
  1165. barrier();
  1166. DOORBELL(bp, fp_tx->index, fp_tx->tx_db.raw);
  1167. mmiowb();
  1168. num_pkts++;
  1169. fp_tx->tx_bd_prod += 2; /* start + pbd */
  1170. udelay(100);
  1171. tx_idx = le16_to_cpu(*fp_tx->tx_cons_sb);
  1172. if (tx_idx != tx_start_idx + num_pkts)
  1173. goto test_loopback_exit;
  1174. rx_idx = le16_to_cpu(*fp_rx->rx_cons_sb);
  1175. if (rx_idx != rx_start_idx + num_pkts)
  1176. goto test_loopback_exit;
  1177. cqe = &fp_rx->rx_comp_ring[RCQ_BD(fp_rx->rx_comp_cons)];
  1178. cqe_fp_flags = cqe->fast_path_cqe.type_error_flags;
  1179. if (CQE_TYPE(cqe_fp_flags) || (cqe_fp_flags & ETH_RX_ERROR_FALGS))
  1180. goto test_loopback_rx_exit;
  1181. len = le16_to_cpu(cqe->fast_path_cqe.pkt_len);
  1182. if (len != pkt_size)
  1183. goto test_loopback_rx_exit;
  1184. rx_buf = &fp_rx->rx_buf_ring[RX_BD(fp_rx->rx_bd_cons)];
  1185. skb = rx_buf->skb;
  1186. skb_reserve(skb, cqe->fast_path_cqe.placement_offset);
  1187. for (i = ETH_HLEN; i < pkt_size; i++)
  1188. if (*(skb->data + i) != (unsigned char) (i & 0xff))
  1189. goto test_loopback_rx_exit;
  1190. rc = 0;
  1191. test_loopback_rx_exit:
  1192. fp_rx->rx_bd_cons = NEXT_RX_IDX(fp_rx->rx_bd_cons);
  1193. fp_rx->rx_bd_prod = NEXT_RX_IDX(fp_rx->rx_bd_prod);
  1194. fp_rx->rx_comp_cons = NEXT_RCQ_IDX(fp_rx->rx_comp_cons);
  1195. fp_rx->rx_comp_prod = NEXT_RCQ_IDX(fp_rx->rx_comp_prod);
  1196. /* Update producers */
  1197. bnx2x_update_rx_prod(bp, fp_rx, fp_rx->rx_bd_prod, fp_rx->rx_comp_prod,
  1198. fp_rx->rx_sge_prod);
  1199. test_loopback_exit:
  1200. bp->link_params.loopback_mode = LOOPBACK_NONE;
  1201. return rc;
  1202. }
  1203. static int bnx2x_test_loopback(struct bnx2x *bp, u8 link_up)
  1204. {
  1205. int rc = 0, res;
  1206. if (BP_NOMCP(bp))
  1207. return rc;
  1208. if (!netif_running(bp->dev))
  1209. return BNX2X_LOOPBACK_FAILED;
  1210. bnx2x_netif_stop(bp, 1);
  1211. bnx2x_acquire_phy_lock(bp);
  1212. res = bnx2x_run_loopback(bp, BNX2X_PHY_LOOPBACK, link_up);
  1213. if (res) {
  1214. DP(NETIF_MSG_PROBE, " PHY loopback failed (res %d)\n", res);
  1215. rc |= BNX2X_PHY_LOOPBACK_FAILED;
  1216. }
  1217. res = bnx2x_run_loopback(bp, BNX2X_MAC_LOOPBACK, link_up);
  1218. if (res) {
  1219. DP(NETIF_MSG_PROBE, " MAC loopback failed (res %d)\n", res);
  1220. rc |= BNX2X_MAC_LOOPBACK_FAILED;
  1221. }
  1222. bnx2x_release_phy_lock(bp);
  1223. bnx2x_netif_start(bp);
  1224. return rc;
  1225. }
  1226. #define CRC32_RESIDUAL 0xdebb20e3
  1227. static int bnx2x_test_nvram(struct bnx2x *bp)
  1228. {
  1229. static const struct {
  1230. int offset;
  1231. int size;
  1232. } nvram_tbl[] = {
  1233. { 0, 0x14 }, /* bootstrap */
  1234. { 0x14, 0xec }, /* dir */
  1235. { 0x100, 0x350 }, /* manuf_info */
  1236. { 0x450, 0xf0 }, /* feature_info */
  1237. { 0x640, 0x64 }, /* upgrade_key_info */
  1238. { 0x6a4, 0x64 },
  1239. { 0x708, 0x70 }, /* manuf_key_info */
  1240. { 0x778, 0x70 },
  1241. { 0, 0 }
  1242. };
  1243. __be32 buf[0x350 / 4];
  1244. u8 *data = (u8 *)buf;
  1245. int i, rc;
  1246. u32 magic, crc;
  1247. if (BP_NOMCP(bp))
  1248. return 0;
  1249. rc = bnx2x_nvram_read(bp, 0, data, 4);
  1250. if (rc) {
  1251. DP(NETIF_MSG_PROBE, "magic value read (rc %d)\n", rc);
  1252. goto test_nvram_exit;
  1253. }
  1254. magic = be32_to_cpu(buf[0]);
  1255. if (magic != 0x669955aa) {
  1256. DP(NETIF_MSG_PROBE, "magic value (0x%08x)\n", magic);
  1257. rc = -ENODEV;
  1258. goto test_nvram_exit;
  1259. }
  1260. for (i = 0; nvram_tbl[i].size; i++) {
  1261. rc = bnx2x_nvram_read(bp, nvram_tbl[i].offset, data,
  1262. nvram_tbl[i].size);
  1263. if (rc) {
  1264. DP(NETIF_MSG_PROBE,
  1265. "nvram_tbl[%d] read data (rc %d)\n", i, rc);
  1266. goto test_nvram_exit;
  1267. }
  1268. crc = ether_crc_le(nvram_tbl[i].size, data);
  1269. if (crc != CRC32_RESIDUAL) {
  1270. DP(NETIF_MSG_PROBE,
  1271. "nvram_tbl[%d] crc value (0x%08x)\n", i, crc);
  1272. rc = -ENODEV;
  1273. goto test_nvram_exit;
  1274. }
  1275. }
  1276. test_nvram_exit:
  1277. return rc;
  1278. }
  1279. static int bnx2x_test_intr(struct bnx2x *bp)
  1280. {
  1281. struct mac_configuration_cmd *config = bnx2x_sp(bp, mac_config);
  1282. int i, rc;
  1283. if (!netif_running(bp->dev))
  1284. return -ENODEV;
  1285. config->hdr.length = 0;
  1286. if (CHIP_IS_E1(bp))
  1287. /* use last unicast entries */
  1288. config->hdr.offset = (BP_PORT(bp) ? 63 : 31);
  1289. else
  1290. config->hdr.offset = BP_FUNC(bp);
  1291. config->hdr.client_id = bp->fp->cl_id;
  1292. config->hdr.reserved1 = 0;
  1293. bp->set_mac_pending++;
  1294. smp_wmb();
  1295. rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_SET_MAC, 0,
  1296. U64_HI(bnx2x_sp_mapping(bp, mac_config)),
  1297. U64_LO(bnx2x_sp_mapping(bp, mac_config)), 1);
  1298. if (rc == 0) {
  1299. for (i = 0; i < 10; i++) {
  1300. if (!bp->set_mac_pending)
  1301. break;
  1302. smp_rmb();
  1303. msleep_interruptible(10);
  1304. }
  1305. if (i == 10)
  1306. rc = -ENODEV;
  1307. }
  1308. return rc;
  1309. }
  1310. static void bnx2x_self_test(struct net_device *dev,
  1311. struct ethtool_test *etest, u64 *buf)
  1312. {
  1313. struct bnx2x *bp = netdev_priv(dev);
  1314. u8 is_serdes;
  1315. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  1316. printk(KERN_ERR "Handling parity error recovery. Try again later\n");
  1317. etest->flags |= ETH_TEST_FL_FAILED;
  1318. return;
  1319. }
  1320. memset(buf, 0, sizeof(u64) * BNX2X_NUM_TESTS);
  1321. if (!netif_running(dev))
  1322. return;
  1323. /* offline tests are not supported in MF mode */
  1324. if (IS_MF(bp))
  1325. etest->flags &= ~ETH_TEST_FL_OFFLINE;
  1326. is_serdes = (bp->link_vars.link_status & LINK_STATUS_SERDES_LINK) > 0;
  1327. if (etest->flags & ETH_TEST_FL_OFFLINE) {
  1328. int port = BP_PORT(bp);
  1329. u32 val;
  1330. u8 link_up;
  1331. /* save current value of input enable for TX port IF */
  1332. val = REG_RD(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4);
  1333. /* disable input for TX port IF */
  1334. REG_WR(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4, 0);
  1335. link_up = bp->link_vars.link_up;
  1336. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  1337. bnx2x_nic_load(bp, LOAD_DIAG);
  1338. /* wait until link state is restored */
  1339. bnx2x_wait_for_link(bp, link_up, is_serdes);
  1340. if (bnx2x_test_registers(bp) != 0) {
  1341. buf[0] = 1;
  1342. etest->flags |= ETH_TEST_FL_FAILED;
  1343. }
  1344. if (bnx2x_test_memory(bp) != 0) {
  1345. buf[1] = 1;
  1346. etest->flags |= ETH_TEST_FL_FAILED;
  1347. }
  1348. buf[2] = bnx2x_test_loopback(bp, link_up);
  1349. if (buf[2] != 0)
  1350. etest->flags |= ETH_TEST_FL_FAILED;
  1351. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  1352. /* restore input for TX port IF */
  1353. REG_WR(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4, val);
  1354. bnx2x_nic_load(bp, LOAD_NORMAL);
  1355. /* wait until link state is restored */
  1356. bnx2x_wait_for_link(bp, link_up, is_serdes);
  1357. }
  1358. if (bnx2x_test_nvram(bp) != 0) {
  1359. buf[3] = 1;
  1360. etest->flags |= ETH_TEST_FL_FAILED;
  1361. }
  1362. if (bnx2x_test_intr(bp) != 0) {
  1363. buf[4] = 1;
  1364. etest->flags |= ETH_TEST_FL_FAILED;
  1365. }
  1366. if (bp->port.pmf)
  1367. if (bnx2x_link_test(bp, is_serdes) != 0) {
  1368. buf[5] = 1;
  1369. etest->flags |= ETH_TEST_FL_FAILED;
  1370. }
  1371. #ifdef BNX2X_EXTRA_DEBUG
  1372. bnx2x_panic_dump(bp);
  1373. #endif
  1374. }
  1375. static const struct {
  1376. long offset;
  1377. int size;
  1378. u8 string[ETH_GSTRING_LEN];
  1379. } bnx2x_q_stats_arr[BNX2X_NUM_Q_STATS] = {
  1380. /* 1 */ { Q_STATS_OFFSET32(total_bytes_received_hi), 8, "[%d]: rx_bytes" },
  1381. { Q_STATS_OFFSET32(error_bytes_received_hi),
  1382. 8, "[%d]: rx_error_bytes" },
  1383. { Q_STATS_OFFSET32(total_unicast_packets_received_hi),
  1384. 8, "[%d]: rx_ucast_packets" },
  1385. { Q_STATS_OFFSET32(total_multicast_packets_received_hi),
  1386. 8, "[%d]: rx_mcast_packets" },
  1387. { Q_STATS_OFFSET32(total_broadcast_packets_received_hi),
  1388. 8, "[%d]: rx_bcast_packets" },
  1389. { Q_STATS_OFFSET32(no_buff_discard_hi), 8, "[%d]: rx_discards" },
  1390. { Q_STATS_OFFSET32(rx_err_discard_pkt),
  1391. 4, "[%d]: rx_phy_ip_err_discards"},
  1392. { Q_STATS_OFFSET32(rx_skb_alloc_failed),
  1393. 4, "[%d]: rx_skb_alloc_discard" },
  1394. { Q_STATS_OFFSET32(hw_csum_err), 4, "[%d]: rx_csum_offload_errors" },
  1395. /* 10 */{ Q_STATS_OFFSET32(total_bytes_transmitted_hi), 8, "[%d]: tx_bytes" },
  1396. { Q_STATS_OFFSET32(total_unicast_packets_transmitted_hi),
  1397. 8, "[%d]: tx_ucast_packets" },
  1398. { Q_STATS_OFFSET32(total_multicast_packets_transmitted_hi),
  1399. 8, "[%d]: tx_mcast_packets" },
  1400. { Q_STATS_OFFSET32(total_broadcast_packets_transmitted_hi),
  1401. 8, "[%d]: tx_bcast_packets" }
  1402. };
  1403. static const struct {
  1404. long offset;
  1405. int size;
  1406. u32 flags;
  1407. #define STATS_FLAGS_PORT 1
  1408. #define STATS_FLAGS_FUNC 2
  1409. #define STATS_FLAGS_BOTH (STATS_FLAGS_FUNC | STATS_FLAGS_PORT)
  1410. u8 string[ETH_GSTRING_LEN];
  1411. } bnx2x_stats_arr[BNX2X_NUM_STATS] = {
  1412. /* 1 */ { STATS_OFFSET32(total_bytes_received_hi),
  1413. 8, STATS_FLAGS_BOTH, "rx_bytes" },
  1414. { STATS_OFFSET32(error_bytes_received_hi),
  1415. 8, STATS_FLAGS_BOTH, "rx_error_bytes" },
  1416. { STATS_OFFSET32(total_unicast_packets_received_hi),
  1417. 8, STATS_FLAGS_BOTH, "rx_ucast_packets" },
  1418. { STATS_OFFSET32(total_multicast_packets_received_hi),
  1419. 8, STATS_FLAGS_BOTH, "rx_mcast_packets" },
  1420. { STATS_OFFSET32(total_broadcast_packets_received_hi),
  1421. 8, STATS_FLAGS_BOTH, "rx_bcast_packets" },
  1422. { STATS_OFFSET32(rx_stat_dot3statsfcserrors_hi),
  1423. 8, STATS_FLAGS_PORT, "rx_crc_errors" },
  1424. { STATS_OFFSET32(rx_stat_dot3statsalignmenterrors_hi),
  1425. 8, STATS_FLAGS_PORT, "rx_align_errors" },
  1426. { STATS_OFFSET32(rx_stat_etherstatsundersizepkts_hi),
  1427. 8, STATS_FLAGS_PORT, "rx_undersize_packets" },
  1428. { STATS_OFFSET32(etherstatsoverrsizepkts_hi),
  1429. 8, STATS_FLAGS_PORT, "rx_oversize_packets" },
  1430. /* 10 */{ STATS_OFFSET32(rx_stat_etherstatsfragments_hi),
  1431. 8, STATS_FLAGS_PORT, "rx_fragments" },
  1432. { STATS_OFFSET32(rx_stat_etherstatsjabbers_hi),
  1433. 8, STATS_FLAGS_PORT, "rx_jabbers" },
  1434. { STATS_OFFSET32(no_buff_discard_hi),
  1435. 8, STATS_FLAGS_BOTH, "rx_discards" },
  1436. { STATS_OFFSET32(mac_filter_discard),
  1437. 4, STATS_FLAGS_PORT, "rx_filtered_packets" },
  1438. { STATS_OFFSET32(xxoverflow_discard),
  1439. 4, STATS_FLAGS_PORT, "rx_fw_discards" },
  1440. { STATS_OFFSET32(brb_drop_hi),
  1441. 8, STATS_FLAGS_PORT, "rx_brb_discard" },
  1442. { STATS_OFFSET32(brb_truncate_hi),
  1443. 8, STATS_FLAGS_PORT, "rx_brb_truncate" },
  1444. { STATS_OFFSET32(pause_frames_received_hi),
  1445. 8, STATS_FLAGS_PORT, "rx_pause_frames" },
  1446. { STATS_OFFSET32(rx_stat_maccontrolframesreceived_hi),
  1447. 8, STATS_FLAGS_PORT, "rx_mac_ctrl_frames" },
  1448. { STATS_OFFSET32(nig_timer_max),
  1449. 4, STATS_FLAGS_PORT, "rx_constant_pause_events" },
  1450. /* 20 */{ STATS_OFFSET32(rx_err_discard_pkt),
  1451. 4, STATS_FLAGS_BOTH, "rx_phy_ip_err_discards"},
  1452. { STATS_OFFSET32(rx_skb_alloc_failed),
  1453. 4, STATS_FLAGS_BOTH, "rx_skb_alloc_discard" },
  1454. { STATS_OFFSET32(hw_csum_err),
  1455. 4, STATS_FLAGS_BOTH, "rx_csum_offload_errors" },
  1456. { STATS_OFFSET32(total_bytes_transmitted_hi),
  1457. 8, STATS_FLAGS_BOTH, "tx_bytes" },
  1458. { STATS_OFFSET32(tx_stat_ifhcoutbadoctets_hi),
  1459. 8, STATS_FLAGS_PORT, "tx_error_bytes" },
  1460. { STATS_OFFSET32(total_unicast_packets_transmitted_hi),
  1461. 8, STATS_FLAGS_BOTH, "tx_ucast_packets" },
  1462. { STATS_OFFSET32(total_multicast_packets_transmitted_hi),
  1463. 8, STATS_FLAGS_BOTH, "tx_mcast_packets" },
  1464. { STATS_OFFSET32(total_broadcast_packets_transmitted_hi),
  1465. 8, STATS_FLAGS_BOTH, "tx_bcast_packets" },
  1466. { STATS_OFFSET32(tx_stat_dot3statsinternalmactransmiterrors_hi),
  1467. 8, STATS_FLAGS_PORT, "tx_mac_errors" },
  1468. { STATS_OFFSET32(rx_stat_dot3statscarriersenseerrors_hi),
  1469. 8, STATS_FLAGS_PORT, "tx_carrier_errors" },
  1470. /* 30 */{ STATS_OFFSET32(tx_stat_dot3statssinglecollisionframes_hi),
  1471. 8, STATS_FLAGS_PORT, "tx_single_collisions" },
  1472. { STATS_OFFSET32(tx_stat_dot3statsmultiplecollisionframes_hi),
  1473. 8, STATS_FLAGS_PORT, "tx_multi_collisions" },
  1474. { STATS_OFFSET32(tx_stat_dot3statsdeferredtransmissions_hi),
  1475. 8, STATS_FLAGS_PORT, "tx_deferred" },
  1476. { STATS_OFFSET32(tx_stat_dot3statsexcessivecollisions_hi),
  1477. 8, STATS_FLAGS_PORT, "tx_excess_collisions" },
  1478. { STATS_OFFSET32(tx_stat_dot3statslatecollisions_hi),
  1479. 8, STATS_FLAGS_PORT, "tx_late_collisions" },
  1480. { STATS_OFFSET32(tx_stat_etherstatscollisions_hi),
  1481. 8, STATS_FLAGS_PORT, "tx_total_collisions" },
  1482. { STATS_OFFSET32(tx_stat_etherstatspkts64octets_hi),
  1483. 8, STATS_FLAGS_PORT, "tx_64_byte_packets" },
  1484. { STATS_OFFSET32(tx_stat_etherstatspkts65octetsto127octets_hi),
  1485. 8, STATS_FLAGS_PORT, "tx_65_to_127_byte_packets" },
  1486. { STATS_OFFSET32(tx_stat_etherstatspkts128octetsto255octets_hi),
  1487. 8, STATS_FLAGS_PORT, "tx_128_to_255_byte_packets" },
  1488. { STATS_OFFSET32(tx_stat_etherstatspkts256octetsto511octets_hi),
  1489. 8, STATS_FLAGS_PORT, "tx_256_to_511_byte_packets" },
  1490. /* 40 */{ STATS_OFFSET32(tx_stat_etherstatspkts512octetsto1023octets_hi),
  1491. 8, STATS_FLAGS_PORT, "tx_512_to_1023_byte_packets" },
  1492. { STATS_OFFSET32(etherstatspkts1024octetsto1522octets_hi),
  1493. 8, STATS_FLAGS_PORT, "tx_1024_to_1522_byte_packets" },
  1494. { STATS_OFFSET32(etherstatspktsover1522octets_hi),
  1495. 8, STATS_FLAGS_PORT, "tx_1523_to_9022_byte_packets" },
  1496. { STATS_OFFSET32(pause_frames_sent_hi),
  1497. 8, STATS_FLAGS_PORT, "tx_pause_frames" }
  1498. };
  1499. #define IS_PORT_STAT(i) \
  1500. ((bnx2x_stats_arr[i].flags & STATS_FLAGS_BOTH) == STATS_FLAGS_PORT)
  1501. #define IS_FUNC_STAT(i) (bnx2x_stats_arr[i].flags & STATS_FLAGS_FUNC)
  1502. #define IS_MF_MODE_STAT(bp) \
  1503. (IS_MF(bp) && !(bp->msg_enable & BNX2X_MSG_STATS))
  1504. static int bnx2x_get_sset_count(struct net_device *dev, int stringset)
  1505. {
  1506. struct bnx2x *bp = netdev_priv(dev);
  1507. int i, num_stats;
  1508. switch (stringset) {
  1509. case ETH_SS_STATS:
  1510. if (is_multi(bp)) {
  1511. num_stats = BNX2X_NUM_Q_STATS * bp->num_queues;
  1512. if (!IS_MF_MODE_STAT(bp))
  1513. num_stats += BNX2X_NUM_STATS;
  1514. } else {
  1515. if (IS_MF_MODE_STAT(bp)) {
  1516. num_stats = 0;
  1517. for (i = 0; i < BNX2X_NUM_STATS; i++)
  1518. if (IS_FUNC_STAT(i))
  1519. num_stats++;
  1520. } else
  1521. num_stats = BNX2X_NUM_STATS;
  1522. }
  1523. return num_stats;
  1524. case ETH_SS_TEST:
  1525. return BNX2X_NUM_TESTS;
  1526. default:
  1527. return -EINVAL;
  1528. }
  1529. }
  1530. static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
  1531. {
  1532. struct bnx2x *bp = netdev_priv(dev);
  1533. int i, j, k;
  1534. switch (stringset) {
  1535. case ETH_SS_STATS:
  1536. if (is_multi(bp)) {
  1537. k = 0;
  1538. for_each_queue(bp, i) {
  1539. for (j = 0; j < BNX2X_NUM_Q_STATS; j++)
  1540. sprintf(buf + (k + j)*ETH_GSTRING_LEN,
  1541. bnx2x_q_stats_arr[j].string, i);
  1542. k += BNX2X_NUM_Q_STATS;
  1543. }
  1544. if (IS_MF_MODE_STAT(bp))
  1545. break;
  1546. for (j = 0; j < BNX2X_NUM_STATS; j++)
  1547. strcpy(buf + (k + j)*ETH_GSTRING_LEN,
  1548. bnx2x_stats_arr[j].string);
  1549. } else {
  1550. for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
  1551. if (IS_MF_MODE_STAT(bp) && IS_PORT_STAT(i))
  1552. continue;
  1553. strcpy(buf + j*ETH_GSTRING_LEN,
  1554. bnx2x_stats_arr[i].string);
  1555. j++;
  1556. }
  1557. }
  1558. break;
  1559. case ETH_SS_TEST:
  1560. memcpy(buf, bnx2x_tests_str_arr, sizeof(bnx2x_tests_str_arr));
  1561. break;
  1562. }
  1563. }
  1564. static void bnx2x_get_ethtool_stats(struct net_device *dev,
  1565. struct ethtool_stats *stats, u64 *buf)
  1566. {
  1567. struct bnx2x *bp = netdev_priv(dev);
  1568. u32 *hw_stats, *offset;
  1569. int i, j, k;
  1570. if (is_multi(bp)) {
  1571. k = 0;
  1572. for_each_queue(bp, i) {
  1573. hw_stats = (u32 *)&bp->fp[i].eth_q_stats;
  1574. for (j = 0; j < BNX2X_NUM_Q_STATS; j++) {
  1575. if (bnx2x_q_stats_arr[j].size == 0) {
  1576. /* skip this counter */
  1577. buf[k + j] = 0;
  1578. continue;
  1579. }
  1580. offset = (hw_stats +
  1581. bnx2x_q_stats_arr[j].offset);
  1582. if (bnx2x_q_stats_arr[j].size == 4) {
  1583. /* 4-byte counter */
  1584. buf[k + j] = (u64) *offset;
  1585. continue;
  1586. }
  1587. /* 8-byte counter */
  1588. buf[k + j] = HILO_U64(*offset, *(offset + 1));
  1589. }
  1590. k += BNX2X_NUM_Q_STATS;
  1591. }
  1592. if (IS_MF_MODE_STAT(bp))
  1593. return;
  1594. hw_stats = (u32 *)&bp->eth_stats;
  1595. for (j = 0; j < BNX2X_NUM_STATS; j++) {
  1596. if (bnx2x_stats_arr[j].size == 0) {
  1597. /* skip this counter */
  1598. buf[k + j] = 0;
  1599. continue;
  1600. }
  1601. offset = (hw_stats + bnx2x_stats_arr[j].offset);
  1602. if (bnx2x_stats_arr[j].size == 4) {
  1603. /* 4-byte counter */
  1604. buf[k + j] = (u64) *offset;
  1605. continue;
  1606. }
  1607. /* 8-byte counter */
  1608. buf[k + j] = HILO_U64(*offset, *(offset + 1));
  1609. }
  1610. } else {
  1611. hw_stats = (u32 *)&bp->eth_stats;
  1612. for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
  1613. if (IS_MF_MODE_STAT(bp) && IS_PORT_STAT(i))
  1614. continue;
  1615. if (bnx2x_stats_arr[i].size == 0) {
  1616. /* skip this counter */
  1617. buf[j] = 0;
  1618. j++;
  1619. continue;
  1620. }
  1621. offset = (hw_stats + bnx2x_stats_arr[i].offset);
  1622. if (bnx2x_stats_arr[i].size == 4) {
  1623. /* 4-byte counter */
  1624. buf[j] = (u64) *offset;
  1625. j++;
  1626. continue;
  1627. }
  1628. /* 8-byte counter */
  1629. buf[j] = HILO_U64(*offset, *(offset + 1));
  1630. j++;
  1631. }
  1632. }
  1633. }
  1634. static int bnx2x_phys_id(struct net_device *dev, u32 data)
  1635. {
  1636. struct bnx2x *bp = netdev_priv(dev);
  1637. int i;
  1638. if (!netif_running(dev))
  1639. return 0;
  1640. if (!bp->port.pmf)
  1641. return 0;
  1642. if (data == 0)
  1643. data = 2;
  1644. for (i = 0; i < (data * 2); i++) {
  1645. if ((i % 2) == 0)
  1646. bnx2x_set_led(&bp->link_params, &bp->link_vars,
  1647. LED_MODE_OPER, SPEED_1000);
  1648. else
  1649. bnx2x_set_led(&bp->link_params, &bp->link_vars,
  1650. LED_MODE_OFF, 0);
  1651. msleep_interruptible(500);
  1652. if (signal_pending(current))
  1653. break;
  1654. }
  1655. if (bp->link_vars.link_up)
  1656. bnx2x_set_led(&bp->link_params, &bp->link_vars, LED_MODE_OPER,
  1657. bp->link_vars.line_speed);
  1658. return 0;
  1659. }
  1660. static const struct ethtool_ops bnx2x_ethtool_ops = {
  1661. .get_settings = bnx2x_get_settings,
  1662. .set_settings = bnx2x_set_settings,
  1663. .get_drvinfo = bnx2x_get_drvinfo,
  1664. .get_regs_len = bnx2x_get_regs_len,
  1665. .get_regs = bnx2x_get_regs,
  1666. .get_wol = bnx2x_get_wol,
  1667. .set_wol = bnx2x_set_wol,
  1668. .get_msglevel = bnx2x_get_msglevel,
  1669. .set_msglevel = bnx2x_set_msglevel,
  1670. .nway_reset = bnx2x_nway_reset,
  1671. .get_link = bnx2x_get_link,
  1672. .get_eeprom_len = bnx2x_get_eeprom_len,
  1673. .get_eeprom = bnx2x_get_eeprom,
  1674. .set_eeprom = bnx2x_set_eeprom,
  1675. .get_coalesce = bnx2x_get_coalesce,
  1676. .set_coalesce = bnx2x_set_coalesce,
  1677. .get_ringparam = bnx2x_get_ringparam,
  1678. .set_ringparam = bnx2x_set_ringparam,
  1679. .get_pauseparam = bnx2x_get_pauseparam,
  1680. .set_pauseparam = bnx2x_set_pauseparam,
  1681. .get_rx_csum = bnx2x_get_rx_csum,
  1682. .set_rx_csum = bnx2x_set_rx_csum,
  1683. .get_tx_csum = ethtool_op_get_tx_csum,
  1684. .set_tx_csum = ethtool_op_set_tx_hw_csum,
  1685. .set_flags = bnx2x_set_flags,
  1686. .get_flags = ethtool_op_get_flags,
  1687. .get_sg = ethtool_op_get_sg,
  1688. .set_sg = ethtool_op_set_sg,
  1689. .get_tso = ethtool_op_get_tso,
  1690. .set_tso = bnx2x_set_tso,
  1691. .self_test = bnx2x_self_test,
  1692. .get_sset_count = bnx2x_get_sset_count,
  1693. .get_strings = bnx2x_get_strings,
  1694. .phys_id = bnx2x_phys_id,
  1695. .get_ethtool_stats = bnx2x_get_ethtool_stats,
  1696. };
  1697. void bnx2x_set_ethtool_ops(struct net_device *netdev)
  1698. {
  1699. SET_ETHTOOL_OPS(netdev, &bnx2x_ethtool_ops);
  1700. }