bnad_ethtool.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  1. /*
  2. * Linux network driver for Brocade Converged Network Adapter.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License (GPL) Version 2 as
  6. * published by the Free Software Foundation
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. */
  13. /*
  14. * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
  15. * All rights reserved
  16. * www.brocade.com
  17. */
  18. #include "cna.h"
  19. #include <linux/netdevice.h>
  20. #include <linux/skbuff.h>
  21. #include <linux/ethtool.h>
  22. #include <linux/rtnetlink.h>
  23. #include "bna.h"
  24. #include "bnad.h"
  25. #define BNAD_NUM_TXF_COUNTERS 12
  26. #define BNAD_NUM_RXF_COUNTERS 10
  27. #define BNAD_NUM_CQ_COUNTERS (3 + 5)
  28. #define BNAD_NUM_RXQ_COUNTERS 6
  29. #define BNAD_NUM_TXQ_COUNTERS 5
  30. #define BNAD_ETHTOOL_STATS_NUM \
  31. (sizeof(struct rtnl_link_stats64) / sizeof(u64) + \
  32. sizeof(struct bnad_drv_stats) / sizeof(u64) + \
  33. offsetof(struct bfi_enet_stats, rxf_stats[0]) / sizeof(u64))
  34. static const char *bnad_net_stats_strings[BNAD_ETHTOOL_STATS_NUM] = {
  35. "rx_packets",
  36. "tx_packets",
  37. "rx_bytes",
  38. "tx_bytes",
  39. "rx_errors",
  40. "tx_errors",
  41. "rx_dropped",
  42. "tx_dropped",
  43. "multicast",
  44. "collisions",
  45. "rx_length_errors",
  46. "rx_over_errors",
  47. "rx_crc_errors",
  48. "rx_frame_errors",
  49. "rx_fifo_errors",
  50. "rx_missed_errors",
  51. "tx_aborted_errors",
  52. "tx_carrier_errors",
  53. "tx_fifo_errors",
  54. "tx_heartbeat_errors",
  55. "tx_window_errors",
  56. "rx_compressed",
  57. "tx_compressed",
  58. "netif_queue_stop",
  59. "netif_queue_wakeup",
  60. "netif_queue_stopped",
  61. "tso4",
  62. "tso6",
  63. "tso_err",
  64. "tcpcsum_offload",
  65. "udpcsum_offload",
  66. "csum_help",
  67. "tx_skb_too_short",
  68. "tx_skb_stopping",
  69. "tx_skb_max_vectors",
  70. "tx_skb_mss_too_long",
  71. "tx_skb_tso_too_short",
  72. "tx_skb_tso_prepare",
  73. "tx_skb_non_tso_too_long",
  74. "tx_skb_tcp_hdr",
  75. "tx_skb_udp_hdr",
  76. "tx_skb_csum_err",
  77. "tx_skb_headlen_too_long",
  78. "tx_skb_headlen_zero",
  79. "tx_skb_frag_zero",
  80. "tx_skb_len_mismatch",
  81. "hw_stats_updates",
  82. "netif_rx_dropped",
  83. "link_toggle",
  84. "cee_toggle",
  85. "rxp_info_alloc_failed",
  86. "mbox_intr_disabled",
  87. "mbox_intr_enabled",
  88. "tx_unmap_q_alloc_failed",
  89. "rx_unmap_q_alloc_failed",
  90. "rxbuf_alloc_failed",
  91. "mac_frame_64",
  92. "mac_frame_65_127",
  93. "mac_frame_128_255",
  94. "mac_frame_256_511",
  95. "mac_frame_512_1023",
  96. "mac_frame_1024_1518",
  97. "mac_frame_1518_1522",
  98. "mac_rx_bytes",
  99. "mac_rx_packets",
  100. "mac_rx_fcs_error",
  101. "mac_rx_multicast",
  102. "mac_rx_broadcast",
  103. "mac_rx_control_frames",
  104. "mac_rx_pause",
  105. "mac_rx_unknown_opcode",
  106. "mac_rx_alignment_error",
  107. "mac_rx_frame_length_error",
  108. "mac_rx_code_error",
  109. "mac_rx_carrier_sense_error",
  110. "mac_rx_undersize",
  111. "mac_rx_oversize",
  112. "mac_rx_fragments",
  113. "mac_rx_jabber",
  114. "mac_rx_drop",
  115. "mac_tx_bytes",
  116. "mac_tx_packets",
  117. "mac_tx_multicast",
  118. "mac_tx_broadcast",
  119. "mac_tx_pause",
  120. "mac_tx_deferral",
  121. "mac_tx_excessive_deferral",
  122. "mac_tx_single_collision",
  123. "mac_tx_muliple_collision",
  124. "mac_tx_late_collision",
  125. "mac_tx_excessive_collision",
  126. "mac_tx_total_collision",
  127. "mac_tx_pause_honored",
  128. "mac_tx_drop",
  129. "mac_tx_jabber",
  130. "mac_tx_fcs_error",
  131. "mac_tx_control_frame",
  132. "mac_tx_oversize",
  133. "mac_tx_undersize",
  134. "mac_tx_fragments",
  135. "bpc_tx_pause_0",
  136. "bpc_tx_pause_1",
  137. "bpc_tx_pause_2",
  138. "bpc_tx_pause_3",
  139. "bpc_tx_pause_4",
  140. "bpc_tx_pause_5",
  141. "bpc_tx_pause_6",
  142. "bpc_tx_pause_7",
  143. "bpc_tx_zero_pause_0",
  144. "bpc_tx_zero_pause_1",
  145. "bpc_tx_zero_pause_2",
  146. "bpc_tx_zero_pause_3",
  147. "bpc_tx_zero_pause_4",
  148. "bpc_tx_zero_pause_5",
  149. "bpc_tx_zero_pause_6",
  150. "bpc_tx_zero_pause_7",
  151. "bpc_tx_first_pause_0",
  152. "bpc_tx_first_pause_1",
  153. "bpc_tx_first_pause_2",
  154. "bpc_tx_first_pause_3",
  155. "bpc_tx_first_pause_4",
  156. "bpc_tx_first_pause_5",
  157. "bpc_tx_first_pause_6",
  158. "bpc_tx_first_pause_7",
  159. "bpc_rx_pause_0",
  160. "bpc_rx_pause_1",
  161. "bpc_rx_pause_2",
  162. "bpc_rx_pause_3",
  163. "bpc_rx_pause_4",
  164. "bpc_rx_pause_5",
  165. "bpc_rx_pause_6",
  166. "bpc_rx_pause_7",
  167. "bpc_rx_zero_pause_0",
  168. "bpc_rx_zero_pause_1",
  169. "bpc_rx_zero_pause_2",
  170. "bpc_rx_zero_pause_3",
  171. "bpc_rx_zero_pause_4",
  172. "bpc_rx_zero_pause_5",
  173. "bpc_rx_zero_pause_6",
  174. "bpc_rx_zero_pause_7",
  175. "bpc_rx_first_pause_0",
  176. "bpc_rx_first_pause_1",
  177. "bpc_rx_first_pause_2",
  178. "bpc_rx_first_pause_3",
  179. "bpc_rx_first_pause_4",
  180. "bpc_rx_first_pause_5",
  181. "bpc_rx_first_pause_6",
  182. "bpc_rx_first_pause_7",
  183. "rad_rx_frames",
  184. "rad_rx_octets",
  185. "rad_rx_vlan_frames",
  186. "rad_rx_ucast",
  187. "rad_rx_ucast_octets",
  188. "rad_rx_ucast_vlan",
  189. "rad_rx_mcast",
  190. "rad_rx_mcast_octets",
  191. "rad_rx_mcast_vlan",
  192. "rad_rx_bcast",
  193. "rad_rx_bcast_octets",
  194. "rad_rx_bcast_vlan",
  195. "rad_rx_drops",
  196. "rlb_rad_rx_frames",
  197. "rlb_rad_rx_octets",
  198. "rlb_rad_rx_vlan_frames",
  199. "rlb_rad_rx_ucast",
  200. "rlb_rad_rx_ucast_octets",
  201. "rlb_rad_rx_ucast_vlan",
  202. "rlb_rad_rx_mcast",
  203. "rlb_rad_rx_mcast_octets",
  204. "rlb_rad_rx_mcast_vlan",
  205. "rlb_rad_rx_bcast",
  206. "rlb_rad_rx_bcast_octets",
  207. "rlb_rad_rx_bcast_vlan",
  208. "rlb_rad_rx_drops",
  209. "fc_rx_ucast_octets",
  210. "fc_rx_ucast",
  211. "fc_rx_ucast_vlan",
  212. "fc_rx_mcast_octets",
  213. "fc_rx_mcast",
  214. "fc_rx_mcast_vlan",
  215. "fc_rx_bcast_octets",
  216. "fc_rx_bcast",
  217. "fc_rx_bcast_vlan",
  218. "fc_tx_ucast_octets",
  219. "fc_tx_ucast",
  220. "fc_tx_ucast_vlan",
  221. "fc_tx_mcast_octets",
  222. "fc_tx_mcast",
  223. "fc_tx_mcast_vlan",
  224. "fc_tx_bcast_octets",
  225. "fc_tx_bcast",
  226. "fc_tx_bcast_vlan",
  227. "fc_tx_parity_errors",
  228. "fc_tx_timeout",
  229. "fc_tx_fid_parity_errors",
  230. };
  231. static int
  232. bnad_get_settings(struct net_device *netdev, struct ethtool_cmd *cmd)
  233. {
  234. cmd->supported = SUPPORTED_10000baseT_Full;
  235. cmd->advertising = ADVERTISED_10000baseT_Full;
  236. cmd->autoneg = AUTONEG_DISABLE;
  237. cmd->supported |= SUPPORTED_FIBRE;
  238. cmd->advertising |= ADVERTISED_FIBRE;
  239. cmd->port = PORT_FIBRE;
  240. cmd->phy_address = 0;
  241. if (netif_carrier_ok(netdev)) {
  242. ethtool_cmd_speed_set(cmd, SPEED_10000);
  243. cmd->duplex = DUPLEX_FULL;
  244. } else {
  245. ethtool_cmd_speed_set(cmd, -1);
  246. cmd->duplex = -1;
  247. }
  248. cmd->transceiver = XCVR_EXTERNAL;
  249. cmd->maxtxpkt = 0;
  250. cmd->maxrxpkt = 0;
  251. return 0;
  252. }
  253. static int
  254. bnad_set_settings(struct net_device *netdev, struct ethtool_cmd *cmd)
  255. {
  256. /* 10G full duplex setting supported only */
  257. if (cmd->autoneg == AUTONEG_ENABLE)
  258. return -EOPNOTSUPP; else {
  259. if ((ethtool_cmd_speed(cmd) == SPEED_10000)
  260. && (cmd->duplex == DUPLEX_FULL))
  261. return 0;
  262. }
  263. return -EOPNOTSUPP;
  264. }
  265. static void
  266. bnad_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
  267. {
  268. struct bnad *bnad = netdev_priv(netdev);
  269. struct bfa_ioc_attr *ioc_attr;
  270. unsigned long flags;
  271. strlcpy(drvinfo->driver, BNAD_NAME, sizeof(drvinfo->driver));
  272. strlcpy(drvinfo->version, BNAD_VERSION, sizeof(drvinfo->version));
  273. ioc_attr = kzalloc(sizeof(*ioc_attr), GFP_KERNEL);
  274. if (ioc_attr) {
  275. spin_lock_irqsave(&bnad->bna_lock, flags);
  276. bfa_nw_ioc_get_attr(&bnad->bna.ioceth.ioc, ioc_attr);
  277. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  278. strlcpy(drvinfo->fw_version, ioc_attr->adapter_attr.fw_ver,
  279. sizeof(drvinfo->fw_version));
  280. kfree(ioc_attr);
  281. }
  282. strlcpy(drvinfo->bus_info, pci_name(bnad->pcidev),
  283. sizeof(drvinfo->bus_info));
  284. }
  285. static void
  286. bnad_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wolinfo)
  287. {
  288. wolinfo->supported = 0;
  289. wolinfo->wolopts = 0;
  290. }
  291. static int
  292. bnad_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
  293. {
  294. struct bnad *bnad = netdev_priv(netdev);
  295. unsigned long flags;
  296. /* Lock rqd. to access bnad->bna_lock */
  297. spin_lock_irqsave(&bnad->bna_lock, flags);
  298. coalesce->use_adaptive_rx_coalesce =
  299. (bnad->cfg_flags & BNAD_CF_DIM_ENABLED) ? true : false;
  300. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  301. coalesce->rx_coalesce_usecs = bnad->rx_coalescing_timeo *
  302. BFI_COALESCING_TIMER_UNIT;
  303. coalesce->tx_coalesce_usecs = bnad->tx_coalescing_timeo *
  304. BFI_COALESCING_TIMER_UNIT;
  305. coalesce->tx_max_coalesced_frames = BFI_TX_INTERPKT_COUNT;
  306. return 0;
  307. }
  308. static int
  309. bnad_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
  310. {
  311. struct bnad *bnad = netdev_priv(netdev);
  312. unsigned long flags;
  313. int to_del = 0;
  314. if (coalesce->rx_coalesce_usecs == 0 ||
  315. coalesce->rx_coalesce_usecs >
  316. BFI_MAX_COALESCING_TIMEO * BFI_COALESCING_TIMER_UNIT)
  317. return -EINVAL;
  318. if (coalesce->tx_coalesce_usecs == 0 ||
  319. coalesce->tx_coalesce_usecs >
  320. BFI_MAX_COALESCING_TIMEO * BFI_COALESCING_TIMER_UNIT)
  321. return -EINVAL;
  322. mutex_lock(&bnad->conf_mutex);
  323. /*
  324. * Do not need to store rx_coalesce_usecs here
  325. * Every time DIM is disabled, we can get it from the
  326. * stack.
  327. */
  328. spin_lock_irqsave(&bnad->bna_lock, flags);
  329. if (coalesce->use_adaptive_rx_coalesce) {
  330. if (!(bnad->cfg_flags & BNAD_CF_DIM_ENABLED)) {
  331. bnad->cfg_flags |= BNAD_CF_DIM_ENABLED;
  332. bnad_dim_timer_start(bnad);
  333. }
  334. } else {
  335. if (bnad->cfg_flags & BNAD_CF_DIM_ENABLED) {
  336. bnad->cfg_flags &= ~BNAD_CF_DIM_ENABLED;
  337. if (bnad->cfg_flags & BNAD_CF_DIM_ENABLED &&
  338. test_bit(BNAD_RF_DIM_TIMER_RUNNING,
  339. &bnad->run_flags)) {
  340. clear_bit(BNAD_RF_DIM_TIMER_RUNNING,
  341. &bnad->run_flags);
  342. to_del = 1;
  343. }
  344. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  345. if (to_del)
  346. del_timer_sync(&bnad->dim_timer);
  347. spin_lock_irqsave(&bnad->bna_lock, flags);
  348. bnad_rx_coalescing_timeo_set(bnad);
  349. }
  350. }
  351. if (bnad->tx_coalescing_timeo != coalesce->tx_coalesce_usecs /
  352. BFI_COALESCING_TIMER_UNIT) {
  353. bnad->tx_coalescing_timeo = coalesce->tx_coalesce_usecs /
  354. BFI_COALESCING_TIMER_UNIT;
  355. bnad_tx_coalescing_timeo_set(bnad);
  356. }
  357. if (bnad->rx_coalescing_timeo != coalesce->rx_coalesce_usecs /
  358. BFI_COALESCING_TIMER_UNIT) {
  359. bnad->rx_coalescing_timeo = coalesce->rx_coalesce_usecs /
  360. BFI_COALESCING_TIMER_UNIT;
  361. if (!(bnad->cfg_flags & BNAD_CF_DIM_ENABLED))
  362. bnad_rx_coalescing_timeo_set(bnad);
  363. }
  364. /* Add Tx Inter-pkt DMA count? */
  365. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  366. mutex_unlock(&bnad->conf_mutex);
  367. return 0;
  368. }
  369. static void
  370. bnad_get_ringparam(struct net_device *netdev,
  371. struct ethtool_ringparam *ringparam)
  372. {
  373. struct bnad *bnad = netdev_priv(netdev);
  374. ringparam->rx_max_pending = BNAD_MAX_RXQ_DEPTH;
  375. ringparam->tx_max_pending = BNAD_MAX_TXQ_DEPTH;
  376. ringparam->rx_pending = bnad->rxq_depth;
  377. ringparam->tx_pending = bnad->txq_depth;
  378. }
  379. static int
  380. bnad_set_ringparam(struct net_device *netdev,
  381. struct ethtool_ringparam *ringparam)
  382. {
  383. int i, current_err, err = 0;
  384. struct bnad *bnad = netdev_priv(netdev);
  385. unsigned long flags;
  386. mutex_lock(&bnad->conf_mutex);
  387. if (ringparam->rx_pending == bnad->rxq_depth &&
  388. ringparam->tx_pending == bnad->txq_depth) {
  389. mutex_unlock(&bnad->conf_mutex);
  390. return 0;
  391. }
  392. if (ringparam->rx_pending < BNAD_MIN_Q_DEPTH ||
  393. ringparam->rx_pending > BNAD_MAX_RXQ_DEPTH ||
  394. !BNA_POWER_OF_2(ringparam->rx_pending)) {
  395. mutex_unlock(&bnad->conf_mutex);
  396. return -EINVAL;
  397. }
  398. if (ringparam->tx_pending < BNAD_MIN_Q_DEPTH ||
  399. ringparam->tx_pending > BNAD_MAX_TXQ_DEPTH ||
  400. !BNA_POWER_OF_2(ringparam->tx_pending)) {
  401. mutex_unlock(&bnad->conf_mutex);
  402. return -EINVAL;
  403. }
  404. if (ringparam->rx_pending != bnad->rxq_depth) {
  405. bnad->rxq_depth = ringparam->rx_pending;
  406. if (!netif_running(netdev)) {
  407. mutex_unlock(&bnad->conf_mutex);
  408. return 0;
  409. }
  410. for (i = 0; i < bnad->num_rx; i++) {
  411. if (!bnad->rx_info[i].rx)
  412. continue;
  413. bnad_cleanup_rx(bnad, i);
  414. current_err = bnad_setup_rx(bnad, i);
  415. if (current_err && !err)
  416. err = current_err;
  417. }
  418. if (!err && bnad->rx_info[0].rx) {
  419. /* restore rx configuration */
  420. bnad_restore_vlans(bnad, 0);
  421. bnad_enable_default_bcast(bnad);
  422. spin_lock_irqsave(&bnad->bna_lock, flags);
  423. bnad_mac_addr_set_locked(bnad, netdev->dev_addr);
  424. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  425. bnad->cfg_flags &= ~(BNAD_CF_ALLMULTI |
  426. BNAD_CF_PROMISC);
  427. bnad_set_rx_mode(netdev);
  428. }
  429. }
  430. if (ringparam->tx_pending != bnad->txq_depth) {
  431. bnad->txq_depth = ringparam->tx_pending;
  432. if (!netif_running(netdev)) {
  433. mutex_unlock(&bnad->conf_mutex);
  434. return 0;
  435. }
  436. for (i = 0; i < bnad->num_tx; i++) {
  437. if (!bnad->tx_info[i].tx)
  438. continue;
  439. bnad_cleanup_tx(bnad, i);
  440. current_err = bnad_setup_tx(bnad, i);
  441. if (current_err && !err)
  442. err = current_err;
  443. }
  444. }
  445. mutex_unlock(&bnad->conf_mutex);
  446. return err;
  447. }
  448. static void
  449. bnad_get_pauseparam(struct net_device *netdev,
  450. struct ethtool_pauseparam *pauseparam)
  451. {
  452. struct bnad *bnad = netdev_priv(netdev);
  453. pauseparam->autoneg = 0;
  454. pauseparam->rx_pause = bnad->bna.enet.pause_config.rx_pause;
  455. pauseparam->tx_pause = bnad->bna.enet.pause_config.tx_pause;
  456. }
  457. static int
  458. bnad_set_pauseparam(struct net_device *netdev,
  459. struct ethtool_pauseparam *pauseparam)
  460. {
  461. struct bnad *bnad = netdev_priv(netdev);
  462. struct bna_pause_config pause_config;
  463. unsigned long flags;
  464. if (pauseparam->autoneg == AUTONEG_ENABLE)
  465. return -EINVAL;
  466. mutex_lock(&bnad->conf_mutex);
  467. if (pauseparam->rx_pause != bnad->bna.enet.pause_config.rx_pause ||
  468. pauseparam->tx_pause != bnad->bna.enet.pause_config.tx_pause) {
  469. pause_config.rx_pause = pauseparam->rx_pause;
  470. pause_config.tx_pause = pauseparam->tx_pause;
  471. spin_lock_irqsave(&bnad->bna_lock, flags);
  472. bna_enet_pause_config(&bnad->bna.enet, &pause_config, NULL);
  473. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  474. }
  475. mutex_unlock(&bnad->conf_mutex);
  476. return 0;
  477. }
  478. static void
  479. bnad_get_strings(struct net_device *netdev, u32 stringset, u8 * string)
  480. {
  481. struct bnad *bnad = netdev_priv(netdev);
  482. int i, j, q_num;
  483. u32 bmap;
  484. mutex_lock(&bnad->conf_mutex);
  485. switch (stringset) {
  486. case ETH_SS_STATS:
  487. for (i = 0; i < BNAD_ETHTOOL_STATS_NUM; i++) {
  488. BUG_ON(!(strlen(bnad_net_stats_strings[i]) <
  489. ETH_GSTRING_LEN));
  490. memcpy(string, bnad_net_stats_strings[i],
  491. ETH_GSTRING_LEN);
  492. string += ETH_GSTRING_LEN;
  493. }
  494. bmap = bna_tx_rid_mask(&bnad->bna);
  495. for (i = 0; bmap; i++) {
  496. if (bmap & 1) {
  497. sprintf(string, "txf%d_ucast_octets", i);
  498. string += ETH_GSTRING_LEN;
  499. sprintf(string, "txf%d_ucast", i);
  500. string += ETH_GSTRING_LEN;
  501. sprintf(string, "txf%d_ucast_vlan", i);
  502. string += ETH_GSTRING_LEN;
  503. sprintf(string, "txf%d_mcast_octets", i);
  504. string += ETH_GSTRING_LEN;
  505. sprintf(string, "txf%d_mcast", i);
  506. string += ETH_GSTRING_LEN;
  507. sprintf(string, "txf%d_mcast_vlan", i);
  508. string += ETH_GSTRING_LEN;
  509. sprintf(string, "txf%d_bcast_octets", i);
  510. string += ETH_GSTRING_LEN;
  511. sprintf(string, "txf%d_bcast", i);
  512. string += ETH_GSTRING_LEN;
  513. sprintf(string, "txf%d_bcast_vlan", i);
  514. string += ETH_GSTRING_LEN;
  515. sprintf(string, "txf%d_errors", i);
  516. string += ETH_GSTRING_LEN;
  517. sprintf(string, "txf%d_filter_vlan", i);
  518. string += ETH_GSTRING_LEN;
  519. sprintf(string, "txf%d_filter_mac_sa", i);
  520. string += ETH_GSTRING_LEN;
  521. }
  522. bmap >>= 1;
  523. }
  524. bmap = bna_rx_rid_mask(&bnad->bna);
  525. for (i = 0; bmap; i++) {
  526. if (bmap & 1) {
  527. sprintf(string, "rxf%d_ucast_octets", i);
  528. string += ETH_GSTRING_LEN;
  529. sprintf(string, "rxf%d_ucast", i);
  530. string += ETH_GSTRING_LEN;
  531. sprintf(string, "rxf%d_ucast_vlan", i);
  532. string += ETH_GSTRING_LEN;
  533. sprintf(string, "rxf%d_mcast_octets", i);
  534. string += ETH_GSTRING_LEN;
  535. sprintf(string, "rxf%d_mcast", i);
  536. string += ETH_GSTRING_LEN;
  537. sprintf(string, "rxf%d_mcast_vlan", i);
  538. string += ETH_GSTRING_LEN;
  539. sprintf(string, "rxf%d_bcast_octets", i);
  540. string += ETH_GSTRING_LEN;
  541. sprintf(string, "rxf%d_bcast", i);
  542. string += ETH_GSTRING_LEN;
  543. sprintf(string, "rxf%d_bcast_vlan", i);
  544. string += ETH_GSTRING_LEN;
  545. sprintf(string, "rxf%d_frame_drops", i);
  546. string += ETH_GSTRING_LEN;
  547. }
  548. bmap >>= 1;
  549. }
  550. q_num = 0;
  551. for (i = 0; i < bnad->num_rx; i++) {
  552. if (!bnad->rx_info[i].rx)
  553. continue;
  554. for (j = 0; j < bnad->num_rxp_per_rx; j++) {
  555. sprintf(string, "cq%d_producer_index", q_num);
  556. string += ETH_GSTRING_LEN;
  557. sprintf(string, "cq%d_consumer_index", q_num);
  558. string += ETH_GSTRING_LEN;
  559. sprintf(string, "cq%d_hw_producer_index",
  560. q_num);
  561. string += ETH_GSTRING_LEN;
  562. sprintf(string, "cq%d_intr", q_num);
  563. string += ETH_GSTRING_LEN;
  564. sprintf(string, "cq%d_poll", q_num);
  565. string += ETH_GSTRING_LEN;
  566. sprintf(string, "cq%d_schedule", q_num);
  567. string += ETH_GSTRING_LEN;
  568. sprintf(string, "cq%d_keep_poll", q_num);
  569. string += ETH_GSTRING_LEN;
  570. sprintf(string, "cq%d_complete", q_num);
  571. string += ETH_GSTRING_LEN;
  572. q_num++;
  573. }
  574. }
  575. q_num = 0;
  576. for (i = 0; i < bnad->num_rx; i++) {
  577. if (!bnad->rx_info[i].rx)
  578. continue;
  579. for (j = 0; j < bnad->num_rxp_per_rx; j++) {
  580. sprintf(string, "rxq%d_packets", q_num);
  581. string += ETH_GSTRING_LEN;
  582. sprintf(string, "rxq%d_bytes", q_num);
  583. string += ETH_GSTRING_LEN;
  584. sprintf(string, "rxq%d_packets_with_error",
  585. q_num);
  586. string += ETH_GSTRING_LEN;
  587. sprintf(string, "rxq%d_allocbuf_failed", q_num);
  588. string += ETH_GSTRING_LEN;
  589. sprintf(string, "rxq%d_producer_index", q_num);
  590. string += ETH_GSTRING_LEN;
  591. sprintf(string, "rxq%d_consumer_index", q_num);
  592. string += ETH_GSTRING_LEN;
  593. q_num++;
  594. if (bnad->rx_info[i].rx_ctrl[j].ccb &&
  595. bnad->rx_info[i].rx_ctrl[j].ccb->
  596. rcb[1] &&
  597. bnad->rx_info[i].rx_ctrl[j].ccb->
  598. rcb[1]->rxq) {
  599. sprintf(string, "rxq%d_packets", q_num);
  600. string += ETH_GSTRING_LEN;
  601. sprintf(string, "rxq%d_bytes", q_num);
  602. string += ETH_GSTRING_LEN;
  603. sprintf(string,
  604. "rxq%d_packets_with_error", q_num);
  605. string += ETH_GSTRING_LEN;
  606. sprintf(string, "rxq%d_allocbuf_failed",
  607. q_num);
  608. string += ETH_GSTRING_LEN;
  609. sprintf(string, "rxq%d_producer_index",
  610. q_num);
  611. string += ETH_GSTRING_LEN;
  612. sprintf(string, "rxq%d_consumer_index",
  613. q_num);
  614. string += ETH_GSTRING_LEN;
  615. q_num++;
  616. }
  617. }
  618. }
  619. q_num = 0;
  620. for (i = 0; i < bnad->num_tx; i++) {
  621. if (!bnad->tx_info[i].tx)
  622. continue;
  623. for (j = 0; j < bnad->num_txq_per_tx; j++) {
  624. sprintf(string, "txq%d_packets", q_num);
  625. string += ETH_GSTRING_LEN;
  626. sprintf(string, "txq%d_bytes", q_num);
  627. string += ETH_GSTRING_LEN;
  628. sprintf(string, "txq%d_producer_index", q_num);
  629. string += ETH_GSTRING_LEN;
  630. sprintf(string, "txq%d_consumer_index", q_num);
  631. string += ETH_GSTRING_LEN;
  632. sprintf(string, "txq%d_hw_consumer_index",
  633. q_num);
  634. string += ETH_GSTRING_LEN;
  635. q_num++;
  636. }
  637. }
  638. break;
  639. default:
  640. break;
  641. }
  642. mutex_unlock(&bnad->conf_mutex);
  643. }
  644. static int
  645. bnad_get_stats_count_locked(struct net_device *netdev)
  646. {
  647. struct bnad *bnad = netdev_priv(netdev);
  648. int i, j, count = 0, rxf_active_num = 0, txf_active_num = 0;
  649. u32 bmap;
  650. bmap = bna_tx_rid_mask(&bnad->bna);
  651. for (i = 0; bmap; i++) {
  652. if (bmap & 1)
  653. txf_active_num++;
  654. bmap >>= 1;
  655. }
  656. bmap = bna_rx_rid_mask(&bnad->bna);
  657. for (i = 0; bmap; i++) {
  658. if (bmap & 1)
  659. rxf_active_num++;
  660. bmap >>= 1;
  661. }
  662. count = BNAD_ETHTOOL_STATS_NUM +
  663. txf_active_num * BNAD_NUM_TXF_COUNTERS +
  664. rxf_active_num * BNAD_NUM_RXF_COUNTERS;
  665. for (i = 0; i < bnad->num_rx; i++) {
  666. if (!bnad->rx_info[i].rx)
  667. continue;
  668. count += bnad->num_rxp_per_rx * BNAD_NUM_CQ_COUNTERS;
  669. count += bnad->num_rxp_per_rx * BNAD_NUM_RXQ_COUNTERS;
  670. for (j = 0; j < bnad->num_rxp_per_rx; j++)
  671. if (bnad->rx_info[i].rx_ctrl[j].ccb &&
  672. bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1] &&
  673. bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1]->rxq)
  674. count += BNAD_NUM_RXQ_COUNTERS;
  675. }
  676. for (i = 0; i < bnad->num_tx; i++) {
  677. if (!bnad->tx_info[i].tx)
  678. continue;
  679. count += bnad->num_txq_per_tx * BNAD_NUM_TXQ_COUNTERS;
  680. }
  681. return count;
  682. }
  683. static int
  684. bnad_per_q_stats_fill(struct bnad *bnad, u64 *buf, int bi)
  685. {
  686. int i, j;
  687. struct bna_rcb *rcb = NULL;
  688. struct bna_tcb *tcb = NULL;
  689. for (i = 0; i < bnad->num_rx; i++) {
  690. if (!bnad->rx_info[i].rx)
  691. continue;
  692. for (j = 0; j < bnad->num_rxp_per_rx; j++)
  693. if (bnad->rx_info[i].rx_ctrl[j].ccb &&
  694. bnad->rx_info[i].rx_ctrl[j].ccb->rcb[0] &&
  695. bnad->rx_info[i].rx_ctrl[j].ccb->rcb[0]->rxq) {
  696. buf[bi++] = bnad->rx_info[i].rx_ctrl[j].
  697. ccb->producer_index;
  698. buf[bi++] = 0; /* ccb->consumer_index */
  699. buf[bi++] = *(bnad->rx_info[i].rx_ctrl[j].
  700. ccb->hw_producer_index);
  701. buf[bi++] = bnad->rx_info[i].
  702. rx_ctrl[j].rx_intr_ctr;
  703. buf[bi++] = bnad->rx_info[i].
  704. rx_ctrl[j].rx_poll_ctr;
  705. buf[bi++] = bnad->rx_info[i].
  706. rx_ctrl[j].rx_schedule;
  707. buf[bi++] = bnad->rx_info[i].
  708. rx_ctrl[j].rx_keep_poll;
  709. buf[bi++] = bnad->rx_info[i].
  710. rx_ctrl[j].rx_complete;
  711. }
  712. }
  713. for (i = 0; i < bnad->num_rx; i++) {
  714. if (!bnad->rx_info[i].rx)
  715. continue;
  716. for (j = 0; j < bnad->num_rxp_per_rx; j++)
  717. if (bnad->rx_info[i].rx_ctrl[j].ccb) {
  718. if (bnad->rx_info[i].rx_ctrl[j].ccb->rcb[0] &&
  719. bnad->rx_info[i].rx_ctrl[j].ccb->
  720. rcb[0]->rxq) {
  721. rcb = bnad->rx_info[i].rx_ctrl[j].
  722. ccb->rcb[0];
  723. buf[bi++] = rcb->rxq->rx_packets;
  724. buf[bi++] = rcb->rxq->rx_bytes;
  725. buf[bi++] = rcb->rxq->
  726. rx_packets_with_error;
  727. buf[bi++] = rcb->rxq->
  728. rxbuf_alloc_failed;
  729. buf[bi++] = rcb->producer_index;
  730. buf[bi++] = rcb->consumer_index;
  731. }
  732. if (bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1] &&
  733. bnad->rx_info[i].rx_ctrl[j].ccb->
  734. rcb[1]->rxq) {
  735. rcb = bnad->rx_info[i].rx_ctrl[j].
  736. ccb->rcb[1];
  737. buf[bi++] = rcb->rxq->rx_packets;
  738. buf[bi++] = rcb->rxq->rx_bytes;
  739. buf[bi++] = rcb->rxq->
  740. rx_packets_with_error;
  741. buf[bi++] = rcb->rxq->
  742. rxbuf_alloc_failed;
  743. buf[bi++] = rcb->producer_index;
  744. buf[bi++] = rcb->consumer_index;
  745. }
  746. }
  747. }
  748. for (i = 0; i < bnad->num_tx; i++) {
  749. if (!bnad->tx_info[i].tx)
  750. continue;
  751. for (j = 0; j < bnad->num_txq_per_tx; j++)
  752. if (bnad->tx_info[i].tcb[j] &&
  753. bnad->tx_info[i].tcb[j]->txq) {
  754. tcb = bnad->tx_info[i].tcb[j];
  755. buf[bi++] = tcb->txq->tx_packets;
  756. buf[bi++] = tcb->txq->tx_bytes;
  757. buf[bi++] = tcb->producer_index;
  758. buf[bi++] = tcb->consumer_index;
  759. buf[bi++] = *(tcb->hw_consumer_index);
  760. }
  761. }
  762. return bi;
  763. }
  764. static void
  765. bnad_get_ethtool_stats(struct net_device *netdev, struct ethtool_stats *stats,
  766. u64 *buf)
  767. {
  768. struct bnad *bnad = netdev_priv(netdev);
  769. int i, j, bi;
  770. unsigned long flags;
  771. struct rtnl_link_stats64 *net_stats64;
  772. u64 *stats64;
  773. u32 bmap;
  774. mutex_lock(&bnad->conf_mutex);
  775. if (bnad_get_stats_count_locked(netdev) != stats->n_stats) {
  776. mutex_unlock(&bnad->conf_mutex);
  777. return;
  778. }
  779. /*
  780. * Used bna_lock to sync reads from bna_stats, which is written
  781. * under the same lock
  782. */
  783. spin_lock_irqsave(&bnad->bna_lock, flags);
  784. bi = 0;
  785. memset(buf, 0, stats->n_stats * sizeof(u64));
  786. net_stats64 = (struct rtnl_link_stats64 *)buf;
  787. bnad_netdev_qstats_fill(bnad, net_stats64);
  788. bnad_netdev_hwstats_fill(bnad, net_stats64);
  789. bi = sizeof(*net_stats64) / sizeof(u64);
  790. /* Get netif_queue_stopped from stack */
  791. bnad->stats.drv_stats.netif_queue_stopped = netif_queue_stopped(netdev);
  792. /* Fill driver stats into ethtool buffers */
  793. stats64 = (u64 *)&bnad->stats.drv_stats;
  794. for (i = 0; i < sizeof(struct bnad_drv_stats) / sizeof(u64); i++)
  795. buf[bi++] = stats64[i];
  796. /* Fill hardware stats excluding the rxf/txf into ethtool bufs */
  797. stats64 = (u64 *) &bnad->stats.bna_stats->hw_stats;
  798. for (i = 0;
  799. i < offsetof(struct bfi_enet_stats, rxf_stats[0]) /
  800. sizeof(u64);
  801. i++)
  802. buf[bi++] = stats64[i];
  803. /* Fill txf stats into ethtool buffers */
  804. bmap = bna_tx_rid_mask(&bnad->bna);
  805. for (i = 0; bmap; i++) {
  806. if (bmap & 1) {
  807. stats64 = (u64 *)&bnad->stats.bna_stats->
  808. hw_stats.txf_stats[i];
  809. for (j = 0; j < sizeof(struct bfi_enet_stats_txf) /
  810. sizeof(u64); j++)
  811. buf[bi++] = stats64[j];
  812. }
  813. bmap >>= 1;
  814. }
  815. /* Fill rxf stats into ethtool buffers */
  816. bmap = bna_rx_rid_mask(&bnad->bna);
  817. for (i = 0; bmap; i++) {
  818. if (bmap & 1) {
  819. stats64 = (u64 *)&bnad->stats.bna_stats->
  820. hw_stats.rxf_stats[i];
  821. for (j = 0; j < sizeof(struct bfi_enet_stats_rxf) /
  822. sizeof(u64); j++)
  823. buf[bi++] = stats64[j];
  824. }
  825. bmap >>= 1;
  826. }
  827. /* Fill per Q stats into ethtool buffers */
  828. bi = bnad_per_q_stats_fill(bnad, buf, bi);
  829. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  830. mutex_unlock(&bnad->conf_mutex);
  831. }
  832. static int
  833. bnad_get_sset_count(struct net_device *netdev, int sset)
  834. {
  835. switch (sset) {
  836. case ETH_SS_STATS:
  837. return bnad_get_stats_count_locked(netdev);
  838. default:
  839. return -EOPNOTSUPP;
  840. }
  841. }
  842. static u32
  843. bnad_get_flash_partition_by_offset(struct bnad *bnad, u32 offset,
  844. u32 *base_offset)
  845. {
  846. struct bfa_flash_attr *flash_attr;
  847. struct bnad_iocmd_comp fcomp;
  848. u32 i, flash_part = 0, ret;
  849. unsigned long flags = 0;
  850. flash_attr = kzalloc(sizeof(struct bfa_flash_attr), GFP_KERNEL);
  851. if (!flash_attr)
  852. return -ENOMEM;
  853. fcomp.bnad = bnad;
  854. fcomp.comp_status = 0;
  855. init_completion(&fcomp.comp);
  856. spin_lock_irqsave(&bnad->bna_lock, flags);
  857. ret = bfa_nw_flash_get_attr(&bnad->bna.flash, flash_attr,
  858. bnad_cb_completion, &fcomp);
  859. if (ret != BFA_STATUS_OK) {
  860. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  861. kfree(flash_attr);
  862. goto out_err;
  863. }
  864. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  865. wait_for_completion(&fcomp.comp);
  866. ret = fcomp.comp_status;
  867. /* Check for the flash type & base offset value */
  868. if (ret == BFA_STATUS_OK) {
  869. for (i = 0; i < flash_attr->npart; i++) {
  870. if (offset >= flash_attr->part[i].part_off &&
  871. offset < (flash_attr->part[i].part_off +
  872. flash_attr->part[i].part_size)) {
  873. flash_part = flash_attr->part[i].part_type;
  874. *base_offset = flash_attr->part[i].part_off;
  875. break;
  876. }
  877. }
  878. }
  879. kfree(flash_attr);
  880. return flash_part;
  881. out_err:
  882. return -EINVAL;
  883. }
  884. static int
  885. bnad_get_eeprom_len(struct net_device *netdev)
  886. {
  887. return BFA_TOTAL_FLASH_SIZE;
  888. }
  889. static int
  890. bnad_get_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
  891. u8 *bytes)
  892. {
  893. struct bnad *bnad = netdev_priv(netdev);
  894. struct bnad_iocmd_comp fcomp;
  895. u32 flash_part = 0, base_offset = 0;
  896. unsigned long flags = 0;
  897. int ret = 0;
  898. /* Check if the flash read request is valid */
  899. if (eeprom->magic != (bnad->pcidev->vendor |
  900. (bnad->pcidev->device << 16)))
  901. return -EFAULT;
  902. /* Query the flash partition based on the offset */
  903. flash_part = bnad_get_flash_partition_by_offset(bnad,
  904. eeprom->offset, &base_offset);
  905. if (flash_part <= 0)
  906. return -EFAULT;
  907. fcomp.bnad = bnad;
  908. fcomp.comp_status = 0;
  909. init_completion(&fcomp.comp);
  910. spin_lock_irqsave(&bnad->bna_lock, flags);
  911. ret = bfa_nw_flash_read_part(&bnad->bna.flash, flash_part,
  912. bnad->id, bytes, eeprom->len,
  913. eeprom->offset - base_offset,
  914. bnad_cb_completion, &fcomp);
  915. if (ret != BFA_STATUS_OK) {
  916. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  917. goto done;
  918. }
  919. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  920. wait_for_completion(&fcomp.comp);
  921. ret = fcomp.comp_status;
  922. done:
  923. return ret;
  924. }
  925. static int
  926. bnad_set_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
  927. u8 *bytes)
  928. {
  929. struct bnad *bnad = netdev_priv(netdev);
  930. struct bnad_iocmd_comp fcomp;
  931. u32 flash_part = 0, base_offset = 0;
  932. unsigned long flags = 0;
  933. int ret = 0;
  934. /* Check if the flash update request is valid */
  935. if (eeprom->magic != (bnad->pcidev->vendor |
  936. (bnad->pcidev->device << 16)))
  937. return -EINVAL;
  938. /* Query the flash partition based on the offset */
  939. flash_part = bnad_get_flash_partition_by_offset(bnad,
  940. eeprom->offset, &base_offset);
  941. if (flash_part <= 0)
  942. return -EFAULT;
  943. fcomp.bnad = bnad;
  944. fcomp.comp_status = 0;
  945. init_completion(&fcomp.comp);
  946. spin_lock_irqsave(&bnad->bna_lock, flags);
  947. ret = bfa_nw_flash_update_part(&bnad->bna.flash, flash_part,
  948. bnad->id, bytes, eeprom->len,
  949. eeprom->offset - base_offset,
  950. bnad_cb_completion, &fcomp);
  951. if (ret != BFA_STATUS_OK) {
  952. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  953. goto done;
  954. }
  955. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  956. wait_for_completion(&fcomp.comp);
  957. ret = fcomp.comp_status;
  958. done:
  959. return ret;
  960. }
  961. static const struct ethtool_ops bnad_ethtool_ops = {
  962. .get_settings = bnad_get_settings,
  963. .set_settings = bnad_set_settings,
  964. .get_drvinfo = bnad_get_drvinfo,
  965. .get_wol = bnad_get_wol,
  966. .get_link = ethtool_op_get_link,
  967. .get_coalesce = bnad_get_coalesce,
  968. .set_coalesce = bnad_set_coalesce,
  969. .get_ringparam = bnad_get_ringparam,
  970. .set_ringparam = bnad_set_ringparam,
  971. .get_pauseparam = bnad_get_pauseparam,
  972. .set_pauseparam = bnad_set_pauseparam,
  973. .get_strings = bnad_get_strings,
  974. .get_ethtool_stats = bnad_get_ethtool_stats,
  975. .get_sset_count = bnad_get_sset_count,
  976. .get_eeprom_len = bnad_get_eeprom_len,
  977. .get_eeprom = bnad_get_eeprom,
  978. .set_eeprom = bnad_set_eeprom,
  979. };
  980. void
  981. bnad_set_ethtool_ops(struct net_device *netdev)
  982. {
  983. SET_ETHTOOL_OPS(netdev, &bnad_ethtool_ops);
  984. }