bnad_ethtool.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961
  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 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. strcpy(drvinfo->driver, BNAD_NAME);
  272. strcpy(drvinfo->version, BNAD_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. strncpy(drvinfo->fw_version, ioc_attr->adapter_attr.fw_ver,
  279. sizeof(drvinfo->fw_version) - 1);
  280. kfree(ioc_attr);
  281. }
  282. strncpy(drvinfo->bus_info, pci_name(bnad->pcidev), ETHTOOL_BUSINFO_LEN);
  283. }
  284. static void
  285. bnad_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wolinfo)
  286. {
  287. wolinfo->supported = 0;
  288. wolinfo->wolopts = 0;
  289. }
  290. static int
  291. bnad_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
  292. {
  293. struct bnad *bnad = netdev_priv(netdev);
  294. unsigned long flags;
  295. /* Lock rqd. to access bnad->bna_lock */
  296. spin_lock_irqsave(&bnad->bna_lock, flags);
  297. coalesce->use_adaptive_rx_coalesce =
  298. (bnad->cfg_flags & BNAD_CF_DIM_ENABLED) ? true : false;
  299. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  300. coalesce->rx_coalesce_usecs = bnad->rx_coalescing_timeo *
  301. BFI_COALESCING_TIMER_UNIT;
  302. coalesce->tx_coalesce_usecs = bnad->tx_coalescing_timeo *
  303. BFI_COALESCING_TIMER_UNIT;
  304. coalesce->tx_max_coalesced_frames = BFI_TX_INTERPKT_COUNT;
  305. return 0;
  306. }
  307. static int
  308. bnad_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
  309. {
  310. struct bnad *bnad = netdev_priv(netdev);
  311. unsigned long flags;
  312. int to_del = 0;
  313. if (coalesce->rx_coalesce_usecs == 0 ||
  314. coalesce->rx_coalesce_usecs >
  315. BFI_MAX_COALESCING_TIMEO * BFI_COALESCING_TIMER_UNIT)
  316. return -EINVAL;
  317. if (coalesce->tx_coalesce_usecs == 0 ||
  318. coalesce->tx_coalesce_usecs >
  319. BFI_MAX_COALESCING_TIMEO * BFI_COALESCING_TIMER_UNIT)
  320. return -EINVAL;
  321. mutex_lock(&bnad->conf_mutex);
  322. /*
  323. * Do not need to store rx_coalesce_usecs here
  324. * Every time DIM is disabled, we can get it from the
  325. * stack.
  326. */
  327. spin_lock_irqsave(&bnad->bna_lock, flags);
  328. if (coalesce->use_adaptive_rx_coalesce) {
  329. if (!(bnad->cfg_flags & BNAD_CF_DIM_ENABLED)) {
  330. bnad->cfg_flags |= BNAD_CF_DIM_ENABLED;
  331. bnad_dim_timer_start(bnad);
  332. }
  333. } else {
  334. if (bnad->cfg_flags & BNAD_CF_DIM_ENABLED) {
  335. bnad->cfg_flags &= ~BNAD_CF_DIM_ENABLED;
  336. if (bnad->cfg_flags & BNAD_CF_DIM_ENABLED &&
  337. test_bit(BNAD_RF_DIM_TIMER_RUNNING,
  338. &bnad->run_flags)) {
  339. clear_bit(BNAD_RF_DIM_TIMER_RUNNING,
  340. &bnad->run_flags);
  341. to_del = 1;
  342. }
  343. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  344. if (to_del)
  345. del_timer_sync(&bnad->dim_timer);
  346. spin_lock_irqsave(&bnad->bna_lock, flags);
  347. bnad_rx_coalescing_timeo_set(bnad);
  348. }
  349. }
  350. if (bnad->tx_coalescing_timeo != coalesce->tx_coalesce_usecs /
  351. BFI_COALESCING_TIMER_UNIT) {
  352. bnad->tx_coalescing_timeo = coalesce->tx_coalesce_usecs /
  353. BFI_COALESCING_TIMER_UNIT;
  354. bnad_tx_coalescing_timeo_set(bnad);
  355. }
  356. if (bnad->rx_coalescing_timeo != coalesce->rx_coalesce_usecs /
  357. BFI_COALESCING_TIMER_UNIT) {
  358. bnad->rx_coalescing_timeo = coalesce->rx_coalesce_usecs /
  359. BFI_COALESCING_TIMER_UNIT;
  360. if (!(bnad->cfg_flags & BNAD_CF_DIM_ENABLED))
  361. bnad_rx_coalescing_timeo_set(bnad);
  362. }
  363. /* Add Tx Inter-pkt DMA count? */
  364. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  365. mutex_unlock(&bnad->conf_mutex);
  366. return 0;
  367. }
  368. static void
  369. bnad_get_ringparam(struct net_device *netdev,
  370. struct ethtool_ringparam *ringparam)
  371. {
  372. struct bnad *bnad = netdev_priv(netdev);
  373. ringparam->rx_max_pending = BNAD_MAX_RXQ_DEPTH;
  374. ringparam->rx_mini_max_pending = 0;
  375. ringparam->rx_jumbo_max_pending = 0;
  376. ringparam->tx_max_pending = BNAD_MAX_TXQ_DEPTH;
  377. ringparam->rx_pending = bnad->rxq_depth;
  378. ringparam->rx_mini_max_pending = 0;
  379. ringparam->rx_jumbo_max_pending = 0;
  380. ringparam->tx_pending = bnad->txq_depth;
  381. }
  382. static int
  383. bnad_set_ringparam(struct net_device *netdev,
  384. struct ethtool_ringparam *ringparam)
  385. {
  386. int i, current_err, err = 0;
  387. struct bnad *bnad = netdev_priv(netdev);
  388. unsigned long flags;
  389. mutex_lock(&bnad->conf_mutex);
  390. if (ringparam->rx_pending == bnad->rxq_depth &&
  391. ringparam->tx_pending == bnad->txq_depth) {
  392. mutex_unlock(&bnad->conf_mutex);
  393. return 0;
  394. }
  395. if (ringparam->rx_pending < BNAD_MIN_Q_DEPTH ||
  396. ringparam->rx_pending > BNAD_MAX_RXQ_DEPTH ||
  397. !BNA_POWER_OF_2(ringparam->rx_pending)) {
  398. mutex_unlock(&bnad->conf_mutex);
  399. return -EINVAL;
  400. }
  401. if (ringparam->tx_pending < BNAD_MIN_Q_DEPTH ||
  402. ringparam->tx_pending > BNAD_MAX_TXQ_DEPTH ||
  403. !BNA_POWER_OF_2(ringparam->tx_pending)) {
  404. mutex_unlock(&bnad->conf_mutex);
  405. return -EINVAL;
  406. }
  407. if (ringparam->rx_pending != bnad->rxq_depth) {
  408. bnad->rxq_depth = ringparam->rx_pending;
  409. if (!netif_running(netdev)) {
  410. mutex_unlock(&bnad->conf_mutex);
  411. return 0;
  412. }
  413. for (i = 0; i < bnad->num_rx; i++) {
  414. if (!bnad->rx_info[i].rx)
  415. continue;
  416. bnad_cleanup_rx(bnad, i);
  417. current_err = bnad_setup_rx(bnad, i);
  418. if (current_err && !err)
  419. err = current_err;
  420. if (!err)
  421. bnad_restore_vlans(bnad, i);
  422. }
  423. if (!err && bnad->rx_info[0].rx) {
  424. /* restore rx configuration */
  425. bnad_enable_default_bcast(bnad);
  426. spin_lock_irqsave(&bnad->bna_lock, flags);
  427. bnad_mac_addr_set_locked(bnad, netdev->dev_addr);
  428. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  429. bnad_set_rx_mode(netdev);
  430. }
  431. }
  432. if (ringparam->tx_pending != bnad->txq_depth) {
  433. bnad->txq_depth = ringparam->tx_pending;
  434. if (!netif_running(netdev)) {
  435. mutex_unlock(&bnad->conf_mutex);
  436. return 0;
  437. }
  438. for (i = 0; i < bnad->num_tx; i++) {
  439. if (!bnad->tx_info[i].tx)
  440. continue;
  441. bnad_cleanup_tx(bnad, i);
  442. current_err = bnad_setup_tx(bnad, i);
  443. if (current_err && !err)
  444. err = current_err;
  445. }
  446. }
  447. mutex_unlock(&bnad->conf_mutex);
  448. return err;
  449. }
  450. static void
  451. bnad_get_pauseparam(struct net_device *netdev,
  452. struct ethtool_pauseparam *pauseparam)
  453. {
  454. struct bnad *bnad = netdev_priv(netdev);
  455. pauseparam->autoneg = 0;
  456. pauseparam->rx_pause = bnad->bna.enet.pause_config.rx_pause;
  457. pauseparam->tx_pause = bnad->bna.enet.pause_config.tx_pause;
  458. }
  459. static int
  460. bnad_set_pauseparam(struct net_device *netdev,
  461. struct ethtool_pauseparam *pauseparam)
  462. {
  463. struct bnad *bnad = netdev_priv(netdev);
  464. struct bna_pause_config pause_config;
  465. unsigned long flags;
  466. if (pauseparam->autoneg == AUTONEG_ENABLE)
  467. return -EINVAL;
  468. mutex_lock(&bnad->conf_mutex);
  469. if (pauseparam->rx_pause != bnad->bna.enet.pause_config.rx_pause ||
  470. pauseparam->tx_pause != bnad->bna.enet.pause_config.tx_pause) {
  471. pause_config.rx_pause = pauseparam->rx_pause;
  472. pause_config.tx_pause = pauseparam->tx_pause;
  473. spin_lock_irqsave(&bnad->bna_lock, flags);
  474. bna_enet_pause_config(&bnad->bna.enet, &pause_config, NULL);
  475. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  476. }
  477. mutex_unlock(&bnad->conf_mutex);
  478. return 0;
  479. }
  480. static void
  481. bnad_get_strings(struct net_device *netdev, u32 stringset, u8 * string)
  482. {
  483. struct bnad *bnad = netdev_priv(netdev);
  484. int i, j, q_num;
  485. u32 bmap;
  486. mutex_lock(&bnad->conf_mutex);
  487. switch (stringset) {
  488. case ETH_SS_STATS:
  489. for (i = 0; i < BNAD_ETHTOOL_STATS_NUM; i++) {
  490. BUG_ON(!(strlen(bnad_net_stats_strings[i]) <
  491. ETH_GSTRING_LEN));
  492. memcpy(string, bnad_net_stats_strings[i],
  493. ETH_GSTRING_LEN);
  494. string += ETH_GSTRING_LEN;
  495. }
  496. bmap = bna_tx_rid_mask(&bnad->bna);
  497. for (i = 0; bmap; i++) {
  498. if (bmap & 1) {
  499. sprintf(string, "txf%d_ucast_octets", i);
  500. string += ETH_GSTRING_LEN;
  501. sprintf(string, "txf%d_ucast", i);
  502. string += ETH_GSTRING_LEN;
  503. sprintf(string, "txf%d_ucast_vlan", i);
  504. string += ETH_GSTRING_LEN;
  505. sprintf(string, "txf%d_mcast_octets", i);
  506. string += ETH_GSTRING_LEN;
  507. sprintf(string, "txf%d_mcast", i);
  508. string += ETH_GSTRING_LEN;
  509. sprintf(string, "txf%d_mcast_vlan", i);
  510. string += ETH_GSTRING_LEN;
  511. sprintf(string, "txf%d_bcast_octets", i);
  512. string += ETH_GSTRING_LEN;
  513. sprintf(string, "txf%d_bcast", i);
  514. string += ETH_GSTRING_LEN;
  515. sprintf(string, "txf%d_bcast_vlan", i);
  516. string += ETH_GSTRING_LEN;
  517. sprintf(string, "txf%d_errors", i);
  518. string += ETH_GSTRING_LEN;
  519. sprintf(string, "txf%d_filter_vlan", i);
  520. string += ETH_GSTRING_LEN;
  521. sprintf(string, "txf%d_filter_mac_sa", i);
  522. string += ETH_GSTRING_LEN;
  523. }
  524. bmap >>= 1;
  525. }
  526. bmap = bna_rx_rid_mask(&bnad->bna);
  527. for (i = 0; bmap; i++) {
  528. if (bmap & 1) {
  529. sprintf(string, "rxf%d_ucast_octets", i);
  530. string += ETH_GSTRING_LEN;
  531. sprintf(string, "rxf%d_ucast", i);
  532. string += ETH_GSTRING_LEN;
  533. sprintf(string, "rxf%d_ucast_vlan", i);
  534. string += ETH_GSTRING_LEN;
  535. sprintf(string, "rxf%d_mcast_octets", i);
  536. string += ETH_GSTRING_LEN;
  537. sprintf(string, "rxf%d_mcast", i);
  538. string += ETH_GSTRING_LEN;
  539. sprintf(string, "rxf%d_mcast_vlan", i);
  540. string += ETH_GSTRING_LEN;
  541. sprintf(string, "rxf%d_bcast_octets", i);
  542. string += ETH_GSTRING_LEN;
  543. sprintf(string, "rxf%d_bcast", i);
  544. string += ETH_GSTRING_LEN;
  545. sprintf(string, "rxf%d_bcast_vlan", i);
  546. string += ETH_GSTRING_LEN;
  547. sprintf(string, "rxf%d_frame_drops", i);
  548. string += ETH_GSTRING_LEN;
  549. }
  550. bmap >>= 1;
  551. }
  552. q_num = 0;
  553. for (i = 0; i < bnad->num_rx; i++) {
  554. if (!bnad->rx_info[i].rx)
  555. continue;
  556. for (j = 0; j < bnad->num_rxp_per_rx; j++) {
  557. sprintf(string, "cq%d_producer_index", q_num);
  558. string += ETH_GSTRING_LEN;
  559. sprintf(string, "cq%d_consumer_index", q_num);
  560. string += ETH_GSTRING_LEN;
  561. sprintf(string, "cq%d_hw_producer_index",
  562. q_num);
  563. string += ETH_GSTRING_LEN;
  564. sprintf(string, "cq%d_intr", q_num);
  565. string += ETH_GSTRING_LEN;
  566. sprintf(string, "cq%d_poll", q_num);
  567. string += ETH_GSTRING_LEN;
  568. sprintf(string, "cq%d_schedule", q_num);
  569. string += ETH_GSTRING_LEN;
  570. sprintf(string, "cq%d_keep_poll", q_num);
  571. string += ETH_GSTRING_LEN;
  572. sprintf(string, "cq%d_complete", q_num);
  573. string += ETH_GSTRING_LEN;
  574. q_num++;
  575. }
  576. }
  577. q_num = 0;
  578. for (i = 0; i < bnad->num_rx; i++) {
  579. if (!bnad->rx_info[i].rx)
  580. continue;
  581. for (j = 0; j < bnad->num_rxp_per_rx; j++) {
  582. sprintf(string, "rxq%d_packets", q_num);
  583. string += ETH_GSTRING_LEN;
  584. sprintf(string, "rxq%d_bytes", q_num);
  585. string += ETH_GSTRING_LEN;
  586. sprintf(string, "rxq%d_packets_with_error",
  587. q_num);
  588. string += ETH_GSTRING_LEN;
  589. sprintf(string, "rxq%d_allocbuf_failed", q_num);
  590. string += ETH_GSTRING_LEN;
  591. sprintf(string, "rxq%d_producer_index", q_num);
  592. string += ETH_GSTRING_LEN;
  593. sprintf(string, "rxq%d_consumer_index", q_num);
  594. string += ETH_GSTRING_LEN;
  595. q_num++;
  596. if (bnad->rx_info[i].rx_ctrl[j].ccb &&
  597. bnad->rx_info[i].rx_ctrl[j].ccb->
  598. rcb[1] &&
  599. bnad->rx_info[i].rx_ctrl[j].ccb->
  600. rcb[1]->rxq) {
  601. sprintf(string, "rxq%d_packets", q_num);
  602. string += ETH_GSTRING_LEN;
  603. sprintf(string, "rxq%d_bytes", q_num);
  604. string += ETH_GSTRING_LEN;
  605. sprintf(string,
  606. "rxq%d_packets_with_error", q_num);
  607. string += ETH_GSTRING_LEN;
  608. sprintf(string, "rxq%d_allocbuf_failed",
  609. q_num);
  610. string += ETH_GSTRING_LEN;
  611. sprintf(string, "rxq%d_producer_index",
  612. q_num);
  613. string += ETH_GSTRING_LEN;
  614. sprintf(string, "rxq%d_consumer_index",
  615. q_num);
  616. string += ETH_GSTRING_LEN;
  617. q_num++;
  618. }
  619. }
  620. }
  621. q_num = 0;
  622. for (i = 0; i < bnad->num_tx; i++) {
  623. if (!bnad->tx_info[i].tx)
  624. continue;
  625. for (j = 0; j < bnad->num_txq_per_tx; j++) {
  626. sprintf(string, "txq%d_packets", q_num);
  627. string += ETH_GSTRING_LEN;
  628. sprintf(string, "txq%d_bytes", q_num);
  629. string += ETH_GSTRING_LEN;
  630. sprintf(string, "txq%d_producer_index", q_num);
  631. string += ETH_GSTRING_LEN;
  632. sprintf(string, "txq%d_consumer_index", q_num);
  633. string += ETH_GSTRING_LEN;
  634. sprintf(string, "txq%d_hw_consumer_index",
  635. q_num);
  636. string += ETH_GSTRING_LEN;
  637. q_num++;
  638. }
  639. }
  640. break;
  641. default:
  642. break;
  643. }
  644. mutex_unlock(&bnad->conf_mutex);
  645. }
  646. static int
  647. bnad_get_stats_count_locked(struct net_device *netdev)
  648. {
  649. struct bnad *bnad = netdev_priv(netdev);
  650. int i, j, count = 0, rxf_active_num = 0, txf_active_num = 0;
  651. u32 bmap;
  652. bmap = bna_tx_rid_mask(&bnad->bna);
  653. for (i = 0; bmap; i++) {
  654. if (bmap & 1)
  655. txf_active_num++;
  656. bmap >>= 1;
  657. }
  658. bmap = bna_rx_rid_mask(&bnad->bna);
  659. for (i = 0; bmap; i++) {
  660. if (bmap & 1)
  661. rxf_active_num++;
  662. bmap >>= 1;
  663. }
  664. count = BNAD_ETHTOOL_STATS_NUM +
  665. txf_active_num * BNAD_NUM_TXF_COUNTERS +
  666. rxf_active_num * BNAD_NUM_RXF_COUNTERS;
  667. for (i = 0; i < bnad->num_rx; i++) {
  668. if (!bnad->rx_info[i].rx)
  669. continue;
  670. count += bnad->num_rxp_per_rx * BNAD_NUM_CQ_COUNTERS;
  671. count += bnad->num_rxp_per_rx * BNAD_NUM_RXQ_COUNTERS;
  672. for (j = 0; j < bnad->num_rxp_per_rx; j++)
  673. if (bnad->rx_info[i].rx_ctrl[j].ccb &&
  674. bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1] &&
  675. bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1]->rxq)
  676. count += BNAD_NUM_RXQ_COUNTERS;
  677. }
  678. for (i = 0; i < bnad->num_tx; i++) {
  679. if (!bnad->tx_info[i].tx)
  680. continue;
  681. count += bnad->num_txq_per_tx * BNAD_NUM_TXQ_COUNTERS;
  682. }
  683. return count;
  684. }
  685. static int
  686. bnad_per_q_stats_fill(struct bnad *bnad, u64 *buf, int bi)
  687. {
  688. int i, j;
  689. struct bna_rcb *rcb = NULL;
  690. struct bna_tcb *tcb = NULL;
  691. for (i = 0; i < bnad->num_rx; i++) {
  692. if (!bnad->rx_info[i].rx)
  693. continue;
  694. for (j = 0; j < bnad->num_rxp_per_rx; j++)
  695. if (bnad->rx_info[i].rx_ctrl[j].ccb &&
  696. bnad->rx_info[i].rx_ctrl[j].ccb->rcb[0] &&
  697. bnad->rx_info[i].rx_ctrl[j].ccb->rcb[0]->rxq) {
  698. buf[bi++] = bnad->rx_info[i].rx_ctrl[j].
  699. ccb->producer_index;
  700. buf[bi++] = 0; /* ccb->consumer_index */
  701. buf[bi++] = *(bnad->rx_info[i].rx_ctrl[j].
  702. ccb->hw_producer_index);
  703. buf[bi++] = bnad->rx_info[i].
  704. rx_ctrl[j].rx_intr_ctr;
  705. buf[bi++] = bnad->rx_info[i].
  706. rx_ctrl[j].rx_poll_ctr;
  707. buf[bi++] = bnad->rx_info[i].
  708. rx_ctrl[j].rx_schedule;
  709. buf[bi++] = bnad->rx_info[i].
  710. rx_ctrl[j].rx_keep_poll;
  711. buf[bi++] = bnad->rx_info[i].
  712. rx_ctrl[j].rx_complete;
  713. }
  714. }
  715. for (i = 0; i < bnad->num_rx; i++) {
  716. if (!bnad->rx_info[i].rx)
  717. continue;
  718. for (j = 0; j < bnad->num_rxp_per_rx; j++)
  719. if (bnad->rx_info[i].rx_ctrl[j].ccb) {
  720. if (bnad->rx_info[i].rx_ctrl[j].ccb->rcb[0] &&
  721. bnad->rx_info[i].rx_ctrl[j].ccb->
  722. rcb[0]->rxq) {
  723. rcb = bnad->rx_info[i].rx_ctrl[j].
  724. ccb->rcb[0];
  725. buf[bi++] = rcb->rxq->rx_packets;
  726. buf[bi++] = rcb->rxq->rx_bytes;
  727. buf[bi++] = rcb->rxq->
  728. rx_packets_with_error;
  729. buf[bi++] = rcb->rxq->
  730. rxbuf_alloc_failed;
  731. buf[bi++] = rcb->producer_index;
  732. buf[bi++] = rcb->consumer_index;
  733. }
  734. if (bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1] &&
  735. bnad->rx_info[i].rx_ctrl[j].ccb->
  736. rcb[1]->rxq) {
  737. rcb = bnad->rx_info[i].rx_ctrl[j].
  738. ccb->rcb[1];
  739. buf[bi++] = rcb->rxq->rx_packets;
  740. buf[bi++] = rcb->rxq->rx_bytes;
  741. buf[bi++] = rcb->rxq->
  742. rx_packets_with_error;
  743. buf[bi++] = rcb->rxq->
  744. rxbuf_alloc_failed;
  745. buf[bi++] = rcb->producer_index;
  746. buf[bi++] = rcb->consumer_index;
  747. }
  748. }
  749. }
  750. for (i = 0; i < bnad->num_tx; i++) {
  751. if (!bnad->tx_info[i].tx)
  752. continue;
  753. for (j = 0; j < bnad->num_txq_per_tx; j++)
  754. if (bnad->tx_info[i].tcb[j] &&
  755. bnad->tx_info[i].tcb[j]->txq) {
  756. tcb = bnad->tx_info[i].tcb[j];
  757. buf[bi++] = tcb->txq->tx_packets;
  758. buf[bi++] = tcb->txq->tx_bytes;
  759. buf[bi++] = tcb->producer_index;
  760. buf[bi++] = tcb->consumer_index;
  761. buf[bi++] = *(tcb->hw_consumer_index);
  762. }
  763. }
  764. return bi;
  765. }
  766. static void
  767. bnad_get_ethtool_stats(struct net_device *netdev, struct ethtool_stats *stats,
  768. u64 *buf)
  769. {
  770. struct bnad *bnad = netdev_priv(netdev);
  771. int i, j, bi;
  772. unsigned long flags;
  773. struct rtnl_link_stats64 *net_stats64;
  774. u64 *stats64;
  775. u32 bmap;
  776. mutex_lock(&bnad->conf_mutex);
  777. if (bnad_get_stats_count_locked(netdev) != stats->n_stats) {
  778. mutex_unlock(&bnad->conf_mutex);
  779. return;
  780. }
  781. /*
  782. * Used bna_lock to sync reads from bna_stats, which is written
  783. * under the same lock
  784. */
  785. spin_lock_irqsave(&bnad->bna_lock, flags);
  786. bi = 0;
  787. memset(buf, 0, stats->n_stats * sizeof(u64));
  788. net_stats64 = (struct rtnl_link_stats64 *)buf;
  789. bnad_netdev_qstats_fill(bnad, net_stats64);
  790. bnad_netdev_hwstats_fill(bnad, net_stats64);
  791. bi = sizeof(*net_stats64) / sizeof(u64);
  792. /* Get netif_queue_stopped from stack */
  793. bnad->stats.drv_stats.netif_queue_stopped = netif_queue_stopped(netdev);
  794. /* Fill driver stats into ethtool buffers */
  795. stats64 = (u64 *)&bnad->stats.drv_stats;
  796. for (i = 0; i < sizeof(struct bnad_drv_stats) / sizeof(u64); i++)
  797. buf[bi++] = stats64[i];
  798. /* Fill hardware stats excluding the rxf/txf into ethtool bufs */
  799. stats64 = (u64 *) &bnad->stats.bna_stats->hw_stats;
  800. for (i = 0;
  801. i < offsetof(struct bfi_enet_stats, rxf_stats[0]) /
  802. sizeof(u64);
  803. i++)
  804. buf[bi++] = stats64[i];
  805. /* Fill txf stats into ethtool buffers */
  806. bmap = bna_tx_rid_mask(&bnad->bna);
  807. for (i = 0; bmap; i++) {
  808. if (bmap & 1) {
  809. stats64 = (u64 *)&bnad->stats.bna_stats->
  810. hw_stats.txf_stats[i];
  811. for (j = 0; j < sizeof(struct bfi_enet_stats_txf) /
  812. sizeof(u64); j++)
  813. buf[bi++] = stats64[j];
  814. }
  815. bmap >>= 1;
  816. }
  817. /* Fill rxf stats into ethtool buffers */
  818. bmap = bna_rx_rid_mask(&bnad->bna);
  819. for (i = 0; bmap; i++) {
  820. if (bmap & 1) {
  821. stats64 = (u64 *)&bnad->stats.bna_stats->
  822. hw_stats.rxf_stats[i];
  823. for (j = 0; j < sizeof(struct bfi_enet_stats_rxf) /
  824. sizeof(u64); j++)
  825. buf[bi++] = stats64[j];
  826. }
  827. bmap >>= 1;
  828. }
  829. /* Fill per Q stats into ethtool buffers */
  830. bi = bnad_per_q_stats_fill(bnad, buf, bi);
  831. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  832. mutex_unlock(&bnad->conf_mutex);
  833. }
  834. static int
  835. bnad_get_sset_count(struct net_device *netdev, int sset)
  836. {
  837. switch (sset) {
  838. case ETH_SS_STATS:
  839. return bnad_get_stats_count_locked(netdev);
  840. default:
  841. return -EOPNOTSUPP;
  842. }
  843. }
  844. static struct ethtool_ops bnad_ethtool_ops = {
  845. .get_settings = bnad_get_settings,
  846. .set_settings = bnad_set_settings,
  847. .get_drvinfo = bnad_get_drvinfo,
  848. .get_wol = bnad_get_wol,
  849. .get_link = ethtool_op_get_link,
  850. .get_coalesce = bnad_get_coalesce,
  851. .set_coalesce = bnad_set_coalesce,
  852. .get_ringparam = bnad_get_ringparam,
  853. .set_ringparam = bnad_set_ringparam,
  854. .get_pauseparam = bnad_get_pauseparam,
  855. .set_pauseparam = bnad_set_pauseparam,
  856. .get_strings = bnad_get_strings,
  857. .get_ethtool_stats = bnad_get_ethtool_stats,
  858. .get_sset_count = bnad_get_sset_count
  859. };
  860. void
  861. bnad_set_ethtool_ops(struct net_device *netdev)
  862. {
  863. SET_ETHTOOL_OPS(netdev, &bnad_ethtool_ops);
  864. }