bnx2x_ethtool.c 51 KB

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