bnad_ethtool.c 24 KB

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