bnx2x_ethtool.c 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024
  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. 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_E1HMF(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 *pbd = 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 = cpu_to_le16(pkt_prod);
  1152. tx_start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
  1153. tx_start_bd->general_data = ((UNICAST_ADDRESS <<
  1154. ETH_TX_START_BD_ETH_ADDR_TYPE_SHIFT) | 1);
  1155. /* turn on parsing and get a BD */
  1156. bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
  1157. pbd = &fp_tx->tx_desc_ring[bd_prod].parse_bd;
  1158. memset(pbd, 0, sizeof(struct eth_tx_parse_bd));
  1159. wmb();
  1160. fp_tx->tx_db.data.prod += 2;
  1161. barrier();
  1162. DOORBELL(bp, fp_tx->index, fp_tx->tx_db.raw);
  1163. mmiowb();
  1164. num_pkts++;
  1165. fp_tx->tx_bd_prod += 2; /* start + pbd */
  1166. udelay(100);
  1167. tx_idx = le16_to_cpu(*fp_tx->tx_cons_sb);
  1168. if (tx_idx != tx_start_idx + num_pkts)
  1169. goto test_loopback_exit;
  1170. rx_idx = le16_to_cpu(*fp_rx->rx_cons_sb);
  1171. if (rx_idx != rx_start_idx + num_pkts)
  1172. goto test_loopback_exit;
  1173. cqe = &fp_rx->rx_comp_ring[RCQ_BD(fp_rx->rx_comp_cons)];
  1174. cqe_fp_flags = cqe->fast_path_cqe.type_error_flags;
  1175. if (CQE_TYPE(cqe_fp_flags) || (cqe_fp_flags & ETH_RX_ERROR_FALGS))
  1176. goto test_loopback_rx_exit;
  1177. len = le16_to_cpu(cqe->fast_path_cqe.pkt_len);
  1178. if (len != pkt_size)
  1179. goto test_loopback_rx_exit;
  1180. rx_buf = &fp_rx->rx_buf_ring[RX_BD(fp_rx->rx_bd_cons)];
  1181. skb = rx_buf->skb;
  1182. skb_reserve(skb, cqe->fast_path_cqe.placement_offset);
  1183. for (i = ETH_HLEN; i < pkt_size; i++)
  1184. if (*(skb->data + i) != (unsigned char) (i & 0xff))
  1185. goto test_loopback_rx_exit;
  1186. rc = 0;
  1187. test_loopback_rx_exit:
  1188. fp_rx->rx_bd_cons = NEXT_RX_IDX(fp_rx->rx_bd_cons);
  1189. fp_rx->rx_bd_prod = NEXT_RX_IDX(fp_rx->rx_bd_prod);
  1190. fp_rx->rx_comp_cons = NEXT_RCQ_IDX(fp_rx->rx_comp_cons);
  1191. fp_rx->rx_comp_prod = NEXT_RCQ_IDX(fp_rx->rx_comp_prod);
  1192. /* Update producers */
  1193. bnx2x_update_rx_prod(bp, fp_rx, fp_rx->rx_bd_prod, fp_rx->rx_comp_prod,
  1194. fp_rx->rx_sge_prod);
  1195. test_loopback_exit:
  1196. bp->link_params.loopback_mode = LOOPBACK_NONE;
  1197. return rc;
  1198. }
  1199. static int bnx2x_test_loopback(struct bnx2x *bp, u8 link_up)
  1200. {
  1201. int rc = 0, res;
  1202. if (BP_NOMCP(bp))
  1203. return rc;
  1204. if (!netif_running(bp->dev))
  1205. return BNX2X_LOOPBACK_FAILED;
  1206. bnx2x_netif_stop(bp, 1);
  1207. bnx2x_acquire_phy_lock(bp);
  1208. res = bnx2x_run_loopback(bp, BNX2X_PHY_LOOPBACK, link_up);
  1209. if (res) {
  1210. DP(NETIF_MSG_PROBE, " PHY loopback failed (res %d)\n", res);
  1211. rc |= BNX2X_PHY_LOOPBACK_FAILED;
  1212. }
  1213. res = bnx2x_run_loopback(bp, BNX2X_MAC_LOOPBACK, link_up);
  1214. if (res) {
  1215. DP(NETIF_MSG_PROBE, " MAC loopback failed (res %d)\n", res);
  1216. rc |= BNX2X_MAC_LOOPBACK_FAILED;
  1217. }
  1218. bnx2x_release_phy_lock(bp);
  1219. bnx2x_netif_start(bp);
  1220. return rc;
  1221. }
  1222. #define CRC32_RESIDUAL 0xdebb20e3
  1223. static int bnx2x_test_nvram(struct bnx2x *bp)
  1224. {
  1225. static const struct {
  1226. int offset;
  1227. int size;
  1228. } nvram_tbl[] = {
  1229. { 0, 0x14 }, /* bootstrap */
  1230. { 0x14, 0xec }, /* dir */
  1231. { 0x100, 0x350 }, /* manuf_info */
  1232. { 0x450, 0xf0 }, /* feature_info */
  1233. { 0x640, 0x64 }, /* upgrade_key_info */
  1234. { 0x6a4, 0x64 },
  1235. { 0x708, 0x70 }, /* manuf_key_info */
  1236. { 0x778, 0x70 },
  1237. { 0, 0 }
  1238. };
  1239. __be32 buf[0x350 / 4];
  1240. u8 *data = (u8 *)buf;
  1241. int i, rc;
  1242. u32 magic, crc;
  1243. if (BP_NOMCP(bp))
  1244. return 0;
  1245. rc = bnx2x_nvram_read(bp, 0, data, 4);
  1246. if (rc) {
  1247. DP(NETIF_MSG_PROBE, "magic value read (rc %d)\n", rc);
  1248. goto test_nvram_exit;
  1249. }
  1250. magic = be32_to_cpu(buf[0]);
  1251. if (magic != 0x669955aa) {
  1252. DP(NETIF_MSG_PROBE, "magic value (0x%08x)\n", magic);
  1253. rc = -ENODEV;
  1254. goto test_nvram_exit;
  1255. }
  1256. for (i = 0; nvram_tbl[i].size; i++) {
  1257. rc = bnx2x_nvram_read(bp, nvram_tbl[i].offset, data,
  1258. nvram_tbl[i].size);
  1259. if (rc) {
  1260. DP(NETIF_MSG_PROBE,
  1261. "nvram_tbl[%d] read data (rc %d)\n", i, rc);
  1262. goto test_nvram_exit;
  1263. }
  1264. crc = ether_crc_le(nvram_tbl[i].size, data);
  1265. if (crc != CRC32_RESIDUAL) {
  1266. DP(NETIF_MSG_PROBE,
  1267. "nvram_tbl[%d] crc value (0x%08x)\n", i, crc);
  1268. rc = -ENODEV;
  1269. goto test_nvram_exit;
  1270. }
  1271. }
  1272. test_nvram_exit:
  1273. return rc;
  1274. }
  1275. static int bnx2x_test_intr(struct bnx2x *bp)
  1276. {
  1277. struct mac_configuration_cmd *config = bnx2x_sp(bp, mac_config);
  1278. int i, rc;
  1279. if (!netif_running(bp->dev))
  1280. return -ENODEV;
  1281. config->hdr.length = 0;
  1282. if (CHIP_IS_E1(bp))
  1283. /* use last unicast entries */
  1284. config->hdr.offset = (BP_PORT(bp) ? 63 : 31);
  1285. else
  1286. config->hdr.offset = BP_FUNC(bp);
  1287. config->hdr.client_id = bp->fp->cl_id;
  1288. config->hdr.reserved1 = 0;
  1289. bp->set_mac_pending++;
  1290. smp_wmb();
  1291. rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
  1292. U64_HI(bnx2x_sp_mapping(bp, mac_config)),
  1293. U64_LO(bnx2x_sp_mapping(bp, mac_config)), 0);
  1294. if (rc == 0) {
  1295. for (i = 0; i < 10; i++) {
  1296. if (!bp->set_mac_pending)
  1297. break;
  1298. smp_rmb();
  1299. msleep_interruptible(10);
  1300. }
  1301. if (i == 10)
  1302. rc = -ENODEV;
  1303. }
  1304. return rc;
  1305. }
  1306. static void bnx2x_self_test(struct net_device *dev,
  1307. struct ethtool_test *etest, u64 *buf)
  1308. {
  1309. struct bnx2x *bp = netdev_priv(dev);
  1310. u8 is_serdes;
  1311. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  1312. printk(KERN_ERR "Handling parity error recovery. Try again later\n");
  1313. etest->flags |= ETH_TEST_FL_FAILED;
  1314. return;
  1315. }
  1316. memset(buf, 0, sizeof(u64) * BNX2X_NUM_TESTS);
  1317. if (!netif_running(dev))
  1318. return;
  1319. /* offline tests are not supported in MF mode */
  1320. if (IS_E1HMF(bp))
  1321. etest->flags &= ~ETH_TEST_FL_OFFLINE;
  1322. is_serdes = (bp->link_vars.link_status & LINK_STATUS_SERDES_LINK) > 0;
  1323. if (etest->flags & ETH_TEST_FL_OFFLINE) {
  1324. int port = BP_PORT(bp);
  1325. u32 val;
  1326. u8 link_up;
  1327. /* save current value of input enable for TX port IF */
  1328. val = REG_RD(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4);
  1329. /* disable input for TX port IF */
  1330. REG_WR(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4, 0);
  1331. link_up = bp->link_vars.link_up;
  1332. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  1333. bnx2x_nic_load(bp, LOAD_DIAG);
  1334. /* wait until link state is restored */
  1335. bnx2x_wait_for_link(bp, link_up, is_serdes);
  1336. if (bnx2x_test_registers(bp) != 0) {
  1337. buf[0] = 1;
  1338. etest->flags |= ETH_TEST_FL_FAILED;
  1339. }
  1340. if (bnx2x_test_memory(bp) != 0) {
  1341. buf[1] = 1;
  1342. etest->flags |= ETH_TEST_FL_FAILED;
  1343. }
  1344. buf[2] = bnx2x_test_loopback(bp, link_up);
  1345. if (buf[2] != 0)
  1346. etest->flags |= ETH_TEST_FL_FAILED;
  1347. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  1348. /* restore input for TX port IF */
  1349. REG_WR(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4, val);
  1350. bnx2x_nic_load(bp, LOAD_NORMAL);
  1351. /* wait until link state is restored */
  1352. bnx2x_wait_for_link(bp, link_up, is_serdes);
  1353. }
  1354. if (bnx2x_test_nvram(bp) != 0) {
  1355. buf[3] = 1;
  1356. etest->flags |= ETH_TEST_FL_FAILED;
  1357. }
  1358. if (bnx2x_test_intr(bp) != 0) {
  1359. buf[4] = 1;
  1360. etest->flags |= ETH_TEST_FL_FAILED;
  1361. }
  1362. if (bp->port.pmf)
  1363. if (bnx2x_link_test(bp, is_serdes) != 0) {
  1364. buf[5] = 1;
  1365. etest->flags |= ETH_TEST_FL_FAILED;
  1366. }
  1367. #ifdef BNX2X_EXTRA_DEBUG
  1368. bnx2x_panic_dump(bp);
  1369. #endif
  1370. }
  1371. static const struct {
  1372. long offset;
  1373. int size;
  1374. u8 string[ETH_GSTRING_LEN];
  1375. } bnx2x_q_stats_arr[BNX2X_NUM_Q_STATS] = {
  1376. /* 1 */ { Q_STATS_OFFSET32(total_bytes_received_hi), 8, "[%d]: rx_bytes" },
  1377. { Q_STATS_OFFSET32(error_bytes_received_hi),
  1378. 8, "[%d]: rx_error_bytes" },
  1379. { Q_STATS_OFFSET32(total_unicast_packets_received_hi),
  1380. 8, "[%d]: rx_ucast_packets" },
  1381. { Q_STATS_OFFSET32(total_multicast_packets_received_hi),
  1382. 8, "[%d]: rx_mcast_packets" },
  1383. { Q_STATS_OFFSET32(total_broadcast_packets_received_hi),
  1384. 8, "[%d]: rx_bcast_packets" },
  1385. { Q_STATS_OFFSET32(no_buff_discard_hi), 8, "[%d]: rx_discards" },
  1386. { Q_STATS_OFFSET32(rx_err_discard_pkt),
  1387. 4, "[%d]: rx_phy_ip_err_discards"},
  1388. { Q_STATS_OFFSET32(rx_skb_alloc_failed),
  1389. 4, "[%d]: rx_skb_alloc_discard" },
  1390. { Q_STATS_OFFSET32(hw_csum_err), 4, "[%d]: rx_csum_offload_errors" },
  1391. /* 10 */{ Q_STATS_OFFSET32(total_bytes_transmitted_hi), 8, "[%d]: tx_bytes" },
  1392. { Q_STATS_OFFSET32(total_unicast_packets_transmitted_hi),
  1393. 8, "[%d]: tx_ucast_packets" },
  1394. { Q_STATS_OFFSET32(total_multicast_packets_transmitted_hi),
  1395. 8, "[%d]: tx_mcast_packets" },
  1396. { Q_STATS_OFFSET32(total_broadcast_packets_transmitted_hi),
  1397. 8, "[%d]: tx_bcast_packets" }
  1398. };
  1399. static const struct {
  1400. long offset;
  1401. int size;
  1402. u32 flags;
  1403. #define STATS_FLAGS_PORT 1
  1404. #define STATS_FLAGS_FUNC 2
  1405. #define STATS_FLAGS_BOTH (STATS_FLAGS_FUNC | STATS_FLAGS_PORT)
  1406. u8 string[ETH_GSTRING_LEN];
  1407. } bnx2x_stats_arr[BNX2X_NUM_STATS] = {
  1408. /* 1 */ { STATS_OFFSET32(total_bytes_received_hi),
  1409. 8, STATS_FLAGS_BOTH, "rx_bytes" },
  1410. { STATS_OFFSET32(error_bytes_received_hi),
  1411. 8, STATS_FLAGS_BOTH, "rx_error_bytes" },
  1412. { STATS_OFFSET32(total_unicast_packets_received_hi),
  1413. 8, STATS_FLAGS_BOTH, "rx_ucast_packets" },
  1414. { STATS_OFFSET32(total_multicast_packets_received_hi),
  1415. 8, STATS_FLAGS_BOTH, "rx_mcast_packets" },
  1416. { STATS_OFFSET32(total_broadcast_packets_received_hi),
  1417. 8, STATS_FLAGS_BOTH, "rx_bcast_packets" },
  1418. { STATS_OFFSET32(rx_stat_dot3statsfcserrors_hi),
  1419. 8, STATS_FLAGS_PORT, "rx_crc_errors" },
  1420. { STATS_OFFSET32(rx_stat_dot3statsalignmenterrors_hi),
  1421. 8, STATS_FLAGS_PORT, "rx_align_errors" },
  1422. { STATS_OFFSET32(rx_stat_etherstatsundersizepkts_hi),
  1423. 8, STATS_FLAGS_PORT, "rx_undersize_packets" },
  1424. { STATS_OFFSET32(etherstatsoverrsizepkts_hi),
  1425. 8, STATS_FLAGS_PORT, "rx_oversize_packets" },
  1426. /* 10 */{ STATS_OFFSET32(rx_stat_etherstatsfragments_hi),
  1427. 8, STATS_FLAGS_PORT, "rx_fragments" },
  1428. { STATS_OFFSET32(rx_stat_etherstatsjabbers_hi),
  1429. 8, STATS_FLAGS_PORT, "rx_jabbers" },
  1430. { STATS_OFFSET32(no_buff_discard_hi),
  1431. 8, STATS_FLAGS_BOTH, "rx_discards" },
  1432. { STATS_OFFSET32(mac_filter_discard),
  1433. 4, STATS_FLAGS_PORT, "rx_filtered_packets" },
  1434. { STATS_OFFSET32(xxoverflow_discard),
  1435. 4, STATS_FLAGS_PORT, "rx_fw_discards" },
  1436. { STATS_OFFSET32(brb_drop_hi),
  1437. 8, STATS_FLAGS_PORT, "rx_brb_discard" },
  1438. { STATS_OFFSET32(brb_truncate_hi),
  1439. 8, STATS_FLAGS_PORT, "rx_brb_truncate" },
  1440. { STATS_OFFSET32(pause_frames_received_hi),
  1441. 8, STATS_FLAGS_PORT, "rx_pause_frames" },
  1442. { STATS_OFFSET32(rx_stat_maccontrolframesreceived_hi),
  1443. 8, STATS_FLAGS_PORT, "rx_mac_ctrl_frames" },
  1444. { STATS_OFFSET32(nig_timer_max),
  1445. 4, STATS_FLAGS_PORT, "rx_constant_pause_events" },
  1446. /* 20 */{ STATS_OFFSET32(rx_err_discard_pkt),
  1447. 4, STATS_FLAGS_BOTH, "rx_phy_ip_err_discards"},
  1448. { STATS_OFFSET32(rx_skb_alloc_failed),
  1449. 4, STATS_FLAGS_BOTH, "rx_skb_alloc_discard" },
  1450. { STATS_OFFSET32(hw_csum_err),
  1451. 4, STATS_FLAGS_BOTH, "rx_csum_offload_errors" },
  1452. { STATS_OFFSET32(total_bytes_transmitted_hi),
  1453. 8, STATS_FLAGS_BOTH, "tx_bytes" },
  1454. { STATS_OFFSET32(tx_stat_ifhcoutbadoctets_hi),
  1455. 8, STATS_FLAGS_PORT, "tx_error_bytes" },
  1456. { STATS_OFFSET32(total_unicast_packets_transmitted_hi),
  1457. 8, STATS_FLAGS_BOTH, "tx_ucast_packets" },
  1458. { STATS_OFFSET32(total_multicast_packets_transmitted_hi),
  1459. 8, STATS_FLAGS_BOTH, "tx_mcast_packets" },
  1460. { STATS_OFFSET32(total_broadcast_packets_transmitted_hi),
  1461. 8, STATS_FLAGS_BOTH, "tx_bcast_packets" },
  1462. { STATS_OFFSET32(tx_stat_dot3statsinternalmactransmiterrors_hi),
  1463. 8, STATS_FLAGS_PORT, "tx_mac_errors" },
  1464. { STATS_OFFSET32(rx_stat_dot3statscarriersenseerrors_hi),
  1465. 8, STATS_FLAGS_PORT, "tx_carrier_errors" },
  1466. /* 30 */{ STATS_OFFSET32(tx_stat_dot3statssinglecollisionframes_hi),
  1467. 8, STATS_FLAGS_PORT, "tx_single_collisions" },
  1468. { STATS_OFFSET32(tx_stat_dot3statsmultiplecollisionframes_hi),
  1469. 8, STATS_FLAGS_PORT, "tx_multi_collisions" },
  1470. { STATS_OFFSET32(tx_stat_dot3statsdeferredtransmissions_hi),
  1471. 8, STATS_FLAGS_PORT, "tx_deferred" },
  1472. { STATS_OFFSET32(tx_stat_dot3statsexcessivecollisions_hi),
  1473. 8, STATS_FLAGS_PORT, "tx_excess_collisions" },
  1474. { STATS_OFFSET32(tx_stat_dot3statslatecollisions_hi),
  1475. 8, STATS_FLAGS_PORT, "tx_late_collisions" },
  1476. { STATS_OFFSET32(tx_stat_etherstatscollisions_hi),
  1477. 8, STATS_FLAGS_PORT, "tx_total_collisions" },
  1478. { STATS_OFFSET32(tx_stat_etherstatspkts64octets_hi),
  1479. 8, STATS_FLAGS_PORT, "tx_64_byte_packets" },
  1480. { STATS_OFFSET32(tx_stat_etherstatspkts65octetsto127octets_hi),
  1481. 8, STATS_FLAGS_PORT, "tx_65_to_127_byte_packets" },
  1482. { STATS_OFFSET32(tx_stat_etherstatspkts128octetsto255octets_hi),
  1483. 8, STATS_FLAGS_PORT, "tx_128_to_255_byte_packets" },
  1484. { STATS_OFFSET32(tx_stat_etherstatspkts256octetsto511octets_hi),
  1485. 8, STATS_FLAGS_PORT, "tx_256_to_511_byte_packets" },
  1486. /* 40 */{ STATS_OFFSET32(tx_stat_etherstatspkts512octetsto1023octets_hi),
  1487. 8, STATS_FLAGS_PORT, "tx_512_to_1023_byte_packets" },
  1488. { STATS_OFFSET32(etherstatspkts1024octetsto1522octets_hi),
  1489. 8, STATS_FLAGS_PORT, "tx_1024_to_1522_byte_packets" },
  1490. { STATS_OFFSET32(etherstatspktsover1522octets_hi),
  1491. 8, STATS_FLAGS_PORT, "tx_1523_to_9022_byte_packets" },
  1492. { STATS_OFFSET32(pause_frames_sent_hi),
  1493. 8, STATS_FLAGS_PORT, "tx_pause_frames" }
  1494. };
  1495. #define IS_PORT_STAT(i) \
  1496. ((bnx2x_stats_arr[i].flags & STATS_FLAGS_BOTH) == STATS_FLAGS_PORT)
  1497. #define IS_FUNC_STAT(i) (bnx2x_stats_arr[i].flags & STATS_FLAGS_FUNC)
  1498. #define IS_E1HMF_MODE_STAT(bp) \
  1499. (IS_E1HMF(bp) && !(bp->msg_enable & BNX2X_MSG_STATS))
  1500. static int bnx2x_get_sset_count(struct net_device *dev, int stringset)
  1501. {
  1502. struct bnx2x *bp = netdev_priv(dev);
  1503. int i, num_stats;
  1504. switch (stringset) {
  1505. case ETH_SS_STATS:
  1506. if (is_multi(bp)) {
  1507. num_stats = BNX2X_NUM_Q_STATS * bp->num_queues;
  1508. if (!IS_E1HMF_MODE_STAT(bp))
  1509. num_stats += BNX2X_NUM_STATS;
  1510. } else {
  1511. if (IS_E1HMF_MODE_STAT(bp)) {
  1512. num_stats = 0;
  1513. for (i = 0; i < BNX2X_NUM_STATS; i++)
  1514. if (IS_FUNC_STAT(i))
  1515. num_stats++;
  1516. } else
  1517. num_stats = BNX2X_NUM_STATS;
  1518. }
  1519. return num_stats;
  1520. case ETH_SS_TEST:
  1521. return BNX2X_NUM_TESTS;
  1522. default:
  1523. return -EINVAL;
  1524. }
  1525. }
  1526. static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
  1527. {
  1528. struct bnx2x *bp = netdev_priv(dev);
  1529. int i, j, k;
  1530. switch (stringset) {
  1531. case ETH_SS_STATS:
  1532. if (is_multi(bp)) {
  1533. k = 0;
  1534. for_each_queue(bp, i) {
  1535. for (j = 0; j < BNX2X_NUM_Q_STATS; j++)
  1536. sprintf(buf + (k + j)*ETH_GSTRING_LEN,
  1537. bnx2x_q_stats_arr[j].string, i);
  1538. k += BNX2X_NUM_Q_STATS;
  1539. }
  1540. if (IS_E1HMF_MODE_STAT(bp))
  1541. break;
  1542. for (j = 0; j < BNX2X_NUM_STATS; j++)
  1543. strcpy(buf + (k + j)*ETH_GSTRING_LEN,
  1544. bnx2x_stats_arr[j].string);
  1545. } else {
  1546. for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
  1547. if (IS_E1HMF_MODE_STAT(bp) && IS_PORT_STAT(i))
  1548. continue;
  1549. strcpy(buf + j*ETH_GSTRING_LEN,
  1550. bnx2x_stats_arr[i].string);
  1551. j++;
  1552. }
  1553. }
  1554. break;
  1555. case ETH_SS_TEST:
  1556. memcpy(buf, bnx2x_tests_str_arr, sizeof(bnx2x_tests_str_arr));
  1557. break;
  1558. }
  1559. }
  1560. static void bnx2x_get_ethtool_stats(struct net_device *dev,
  1561. struct ethtool_stats *stats, u64 *buf)
  1562. {
  1563. struct bnx2x *bp = netdev_priv(dev);
  1564. u32 *hw_stats, *offset;
  1565. int i, j, k;
  1566. if (is_multi(bp)) {
  1567. k = 0;
  1568. for_each_queue(bp, i) {
  1569. hw_stats = (u32 *)&bp->fp[i].eth_q_stats;
  1570. for (j = 0; j < BNX2X_NUM_Q_STATS; j++) {
  1571. if (bnx2x_q_stats_arr[j].size == 0) {
  1572. /* skip this counter */
  1573. buf[k + j] = 0;
  1574. continue;
  1575. }
  1576. offset = (hw_stats +
  1577. bnx2x_q_stats_arr[j].offset);
  1578. if (bnx2x_q_stats_arr[j].size == 4) {
  1579. /* 4-byte counter */
  1580. buf[k + j] = (u64) *offset;
  1581. continue;
  1582. }
  1583. /* 8-byte counter */
  1584. buf[k + j] = HILO_U64(*offset, *(offset + 1));
  1585. }
  1586. k += BNX2X_NUM_Q_STATS;
  1587. }
  1588. if (IS_E1HMF_MODE_STAT(bp))
  1589. return;
  1590. hw_stats = (u32 *)&bp->eth_stats;
  1591. for (j = 0; j < BNX2X_NUM_STATS; j++) {
  1592. if (bnx2x_stats_arr[j].size == 0) {
  1593. /* skip this counter */
  1594. buf[k + j] = 0;
  1595. continue;
  1596. }
  1597. offset = (hw_stats + bnx2x_stats_arr[j].offset);
  1598. if (bnx2x_stats_arr[j].size == 4) {
  1599. /* 4-byte counter */
  1600. buf[k + j] = (u64) *offset;
  1601. continue;
  1602. }
  1603. /* 8-byte counter */
  1604. buf[k + j] = HILO_U64(*offset, *(offset + 1));
  1605. }
  1606. } else {
  1607. hw_stats = (u32 *)&bp->eth_stats;
  1608. for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
  1609. if (IS_E1HMF_MODE_STAT(bp) && IS_PORT_STAT(i))
  1610. continue;
  1611. if (bnx2x_stats_arr[i].size == 0) {
  1612. /* skip this counter */
  1613. buf[j] = 0;
  1614. j++;
  1615. continue;
  1616. }
  1617. offset = (hw_stats + bnx2x_stats_arr[i].offset);
  1618. if (bnx2x_stats_arr[i].size == 4) {
  1619. /* 4-byte counter */
  1620. buf[j] = (u64) *offset;
  1621. j++;
  1622. continue;
  1623. }
  1624. /* 8-byte counter */
  1625. buf[j] = HILO_U64(*offset, *(offset + 1));
  1626. j++;
  1627. }
  1628. }
  1629. }
  1630. static int bnx2x_phys_id(struct net_device *dev, u32 data)
  1631. {
  1632. struct bnx2x *bp = netdev_priv(dev);
  1633. int i;
  1634. if (!netif_running(dev))
  1635. return 0;
  1636. if (!bp->port.pmf)
  1637. return 0;
  1638. if (data == 0)
  1639. data = 2;
  1640. for (i = 0; i < (data * 2); i++) {
  1641. if ((i % 2) == 0)
  1642. bnx2x_set_led(&bp->link_params, &bp->link_vars,
  1643. LED_MODE_OPER, SPEED_1000);
  1644. else
  1645. bnx2x_set_led(&bp->link_params, &bp->link_vars,
  1646. LED_MODE_OFF, 0);
  1647. msleep_interruptible(500);
  1648. if (signal_pending(current))
  1649. break;
  1650. }
  1651. if (bp->link_vars.link_up)
  1652. bnx2x_set_led(&bp->link_params, &bp->link_vars, LED_MODE_OPER,
  1653. bp->link_vars.line_speed);
  1654. return 0;
  1655. }
  1656. static const struct ethtool_ops bnx2x_ethtool_ops = {
  1657. .get_settings = bnx2x_get_settings,
  1658. .set_settings = bnx2x_set_settings,
  1659. .get_drvinfo = bnx2x_get_drvinfo,
  1660. .get_regs_len = bnx2x_get_regs_len,
  1661. .get_regs = bnx2x_get_regs,
  1662. .get_wol = bnx2x_get_wol,
  1663. .set_wol = bnx2x_set_wol,
  1664. .get_msglevel = bnx2x_get_msglevel,
  1665. .set_msglevel = bnx2x_set_msglevel,
  1666. .nway_reset = bnx2x_nway_reset,
  1667. .get_link = bnx2x_get_link,
  1668. .get_eeprom_len = bnx2x_get_eeprom_len,
  1669. .get_eeprom = bnx2x_get_eeprom,
  1670. .set_eeprom = bnx2x_set_eeprom,
  1671. .get_coalesce = bnx2x_get_coalesce,
  1672. .set_coalesce = bnx2x_set_coalesce,
  1673. .get_ringparam = bnx2x_get_ringparam,
  1674. .set_ringparam = bnx2x_set_ringparam,
  1675. .get_pauseparam = bnx2x_get_pauseparam,
  1676. .set_pauseparam = bnx2x_set_pauseparam,
  1677. .get_rx_csum = bnx2x_get_rx_csum,
  1678. .set_rx_csum = bnx2x_set_rx_csum,
  1679. .get_tx_csum = ethtool_op_get_tx_csum,
  1680. .set_tx_csum = ethtool_op_set_tx_hw_csum,
  1681. .set_flags = bnx2x_set_flags,
  1682. .get_flags = ethtool_op_get_flags,
  1683. .get_sg = ethtool_op_get_sg,
  1684. .set_sg = ethtool_op_set_sg,
  1685. .get_tso = ethtool_op_get_tso,
  1686. .set_tso = bnx2x_set_tso,
  1687. .self_test = bnx2x_self_test,
  1688. .get_sset_count = bnx2x_get_sset_count,
  1689. .get_strings = bnx2x_get_strings,
  1690. .phys_id = bnx2x_phys_id,
  1691. .get_ethtool_stats = bnx2x_get_ethtool_stats,
  1692. };
  1693. void bnx2x_set_ethtool_ops(struct net_device *netdev)
  1694. {
  1695. SET_ETHTOOL_OPS(netdev, &bnx2x_ethtool_ops);
  1696. }