bnad_ethtool.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895
  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
  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_ll_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. "csum_help_err",
  68. "hw_stats_updates",
  69. "netif_rx_schedule",
  70. "netif_rx_complete",
  71. "netif_rx_dropped",
  72. "link_toggle",
  73. "cee_up",
  74. "rxp_info_alloc_failed",
  75. "mbox_intr_disabled",
  76. "mbox_intr_enabled",
  77. "tx_unmap_q_alloc_failed",
  78. "rx_unmap_q_alloc_failed",
  79. "rxbuf_alloc_failed",
  80. "mac_frame_64",
  81. "mac_frame_65_127",
  82. "mac_frame_128_255",
  83. "mac_frame_256_511",
  84. "mac_frame_512_1023",
  85. "mac_frame_1024_1518",
  86. "mac_frame_1518_1522",
  87. "mac_rx_bytes",
  88. "mac_rx_packets",
  89. "mac_rx_fcs_error",
  90. "mac_rx_multicast",
  91. "mac_rx_broadcast",
  92. "mac_rx_control_frames",
  93. "mac_rx_pause",
  94. "mac_rx_unknown_opcode",
  95. "mac_rx_alignment_error",
  96. "mac_rx_frame_length_error",
  97. "mac_rx_code_error",
  98. "mac_rx_carrier_sense_error",
  99. "mac_rx_undersize",
  100. "mac_rx_oversize",
  101. "mac_rx_fragments",
  102. "mac_rx_jabber",
  103. "mac_rx_drop",
  104. "mac_tx_bytes",
  105. "mac_tx_packets",
  106. "mac_tx_multicast",
  107. "mac_tx_broadcast",
  108. "mac_tx_pause",
  109. "mac_tx_deferral",
  110. "mac_tx_excessive_deferral",
  111. "mac_tx_single_collision",
  112. "mac_tx_muliple_collision",
  113. "mac_tx_late_collision",
  114. "mac_tx_excessive_collision",
  115. "mac_tx_total_collision",
  116. "mac_tx_pause_honored",
  117. "mac_tx_drop",
  118. "mac_tx_jabber",
  119. "mac_tx_fcs_error",
  120. "mac_tx_control_frame",
  121. "mac_tx_oversize",
  122. "mac_tx_undersize",
  123. "mac_tx_fragments",
  124. "bpc_tx_pause_0",
  125. "bpc_tx_pause_1",
  126. "bpc_tx_pause_2",
  127. "bpc_tx_pause_3",
  128. "bpc_tx_pause_4",
  129. "bpc_tx_pause_5",
  130. "bpc_tx_pause_6",
  131. "bpc_tx_pause_7",
  132. "bpc_tx_zero_pause_0",
  133. "bpc_tx_zero_pause_1",
  134. "bpc_tx_zero_pause_2",
  135. "bpc_tx_zero_pause_3",
  136. "bpc_tx_zero_pause_4",
  137. "bpc_tx_zero_pause_5",
  138. "bpc_tx_zero_pause_6",
  139. "bpc_tx_zero_pause_7",
  140. "bpc_tx_first_pause_0",
  141. "bpc_tx_first_pause_1",
  142. "bpc_tx_first_pause_2",
  143. "bpc_tx_first_pause_3",
  144. "bpc_tx_first_pause_4",
  145. "bpc_tx_first_pause_5",
  146. "bpc_tx_first_pause_6",
  147. "bpc_tx_first_pause_7",
  148. "bpc_rx_pause_0",
  149. "bpc_rx_pause_1",
  150. "bpc_rx_pause_2",
  151. "bpc_rx_pause_3",
  152. "bpc_rx_pause_4",
  153. "bpc_rx_pause_5",
  154. "bpc_rx_pause_6",
  155. "bpc_rx_pause_7",
  156. "bpc_rx_zero_pause_0",
  157. "bpc_rx_zero_pause_1",
  158. "bpc_rx_zero_pause_2",
  159. "bpc_rx_zero_pause_3",
  160. "bpc_rx_zero_pause_4",
  161. "bpc_rx_zero_pause_5",
  162. "bpc_rx_zero_pause_6",
  163. "bpc_rx_zero_pause_7",
  164. "bpc_rx_first_pause_0",
  165. "bpc_rx_first_pause_1",
  166. "bpc_rx_first_pause_2",
  167. "bpc_rx_first_pause_3",
  168. "bpc_rx_first_pause_4",
  169. "bpc_rx_first_pause_5",
  170. "bpc_rx_first_pause_6",
  171. "bpc_rx_first_pause_7",
  172. "rad_rx_frames",
  173. "rad_rx_octets",
  174. "rad_rx_vlan_frames",
  175. "rad_rx_ucast",
  176. "rad_rx_ucast_octets",
  177. "rad_rx_ucast_vlan",
  178. "rad_rx_mcast",
  179. "rad_rx_mcast_octets",
  180. "rad_rx_mcast_vlan",
  181. "rad_rx_bcast",
  182. "rad_rx_bcast_octets",
  183. "rad_rx_bcast_vlan",
  184. "rad_rx_drops",
  185. "fc_rx_ucast_octets",
  186. "fc_rx_ucast",
  187. "fc_rx_ucast_vlan",
  188. "fc_rx_mcast_octets",
  189. "fc_rx_mcast",
  190. "fc_rx_mcast_vlan",
  191. "fc_rx_bcast_octets",
  192. "fc_rx_bcast",
  193. "fc_rx_bcast_vlan",
  194. "fc_tx_ucast_octets",
  195. "fc_tx_ucast",
  196. "fc_tx_ucast_vlan",
  197. "fc_tx_mcast_octets",
  198. "fc_tx_mcast",
  199. "fc_tx_mcast_vlan",
  200. "fc_tx_bcast_octets",
  201. "fc_tx_bcast",
  202. "fc_tx_bcast_vlan",
  203. "fc_tx_parity_errors",
  204. "fc_tx_timeout",
  205. "fc_tx_fid_parity_errors",
  206. };
  207. static int
  208. bnad_get_settings(struct net_device *netdev, struct ethtool_cmd *cmd)
  209. {
  210. cmd->supported = SUPPORTED_10000baseT_Full;
  211. cmd->advertising = ADVERTISED_10000baseT_Full;
  212. cmd->autoneg = AUTONEG_DISABLE;
  213. cmd->supported |= SUPPORTED_FIBRE;
  214. cmd->advertising |= ADVERTISED_FIBRE;
  215. cmd->port = PORT_FIBRE;
  216. cmd->phy_address = 0;
  217. if (netif_carrier_ok(netdev)) {
  218. ethtool_cmd_speed_set(cmd, SPEED_10000);
  219. cmd->duplex = DUPLEX_FULL;
  220. } else {
  221. ethtool_cmd_speed_set(cmd, -1);
  222. cmd->duplex = -1;
  223. }
  224. cmd->transceiver = XCVR_EXTERNAL;
  225. cmd->maxtxpkt = 0;
  226. cmd->maxrxpkt = 0;
  227. return 0;
  228. }
  229. static int
  230. bnad_set_settings(struct net_device *netdev, struct ethtool_cmd *cmd)
  231. {
  232. /* 10G full duplex setting supported only */
  233. if (cmd->autoneg == AUTONEG_ENABLE)
  234. return -EOPNOTSUPP; else {
  235. if ((ethtool_cmd_speed(cmd) == SPEED_10000)
  236. && (cmd->duplex == DUPLEX_FULL))
  237. return 0;
  238. }
  239. return -EOPNOTSUPP;
  240. }
  241. static void
  242. bnad_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
  243. {
  244. struct bnad *bnad = netdev_priv(netdev);
  245. struct bfa_ioc_attr *ioc_attr;
  246. unsigned long flags;
  247. strcpy(drvinfo->driver, BNAD_NAME);
  248. strcpy(drvinfo->version, BNAD_VERSION);
  249. ioc_attr = kzalloc(sizeof(*ioc_attr), GFP_KERNEL);
  250. if (ioc_attr) {
  251. spin_lock_irqsave(&bnad->bna_lock, flags);
  252. bfa_nw_ioc_get_attr(&bnad->bna.device.ioc, ioc_attr);
  253. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  254. strncpy(drvinfo->fw_version, ioc_attr->adapter_attr.fw_ver,
  255. sizeof(drvinfo->fw_version) - 1);
  256. kfree(ioc_attr);
  257. }
  258. strncpy(drvinfo->bus_info, pci_name(bnad->pcidev), ETHTOOL_BUSINFO_LEN);
  259. }
  260. static void
  261. bnad_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wolinfo)
  262. {
  263. wolinfo->supported = 0;
  264. wolinfo->wolopts = 0;
  265. }
  266. static int
  267. bnad_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
  268. {
  269. struct bnad *bnad = netdev_priv(netdev);
  270. unsigned long flags;
  271. /* Lock rqd. to access bnad->bna_lock */
  272. spin_lock_irqsave(&bnad->bna_lock, flags);
  273. coalesce->use_adaptive_rx_coalesce =
  274. (bnad->cfg_flags & BNAD_CF_DIM_ENABLED) ? true : false;
  275. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  276. coalesce->rx_coalesce_usecs = bnad->rx_coalescing_timeo *
  277. BFI_COALESCING_TIMER_UNIT;
  278. coalesce->tx_coalesce_usecs = bnad->tx_coalescing_timeo *
  279. BFI_COALESCING_TIMER_UNIT;
  280. coalesce->tx_max_coalesced_frames = BFI_TX_INTERPKT_COUNT;
  281. return 0;
  282. }
  283. static int
  284. bnad_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
  285. {
  286. struct bnad *bnad = netdev_priv(netdev);
  287. unsigned long flags;
  288. int dim_timer_del = 0;
  289. if (coalesce->rx_coalesce_usecs == 0 ||
  290. coalesce->rx_coalesce_usecs >
  291. BFI_MAX_COALESCING_TIMEO * BFI_COALESCING_TIMER_UNIT)
  292. return -EINVAL;
  293. if (coalesce->tx_coalesce_usecs == 0 ||
  294. coalesce->tx_coalesce_usecs >
  295. BFI_MAX_COALESCING_TIMEO * BFI_COALESCING_TIMER_UNIT)
  296. return -EINVAL;
  297. mutex_lock(&bnad->conf_mutex);
  298. /*
  299. * Do not need to store rx_coalesce_usecs here
  300. * Every time DIM is disabled, we can get it from the
  301. * stack.
  302. */
  303. spin_lock_irqsave(&bnad->bna_lock, flags);
  304. if (coalesce->use_adaptive_rx_coalesce) {
  305. if (!(bnad->cfg_flags & BNAD_CF_DIM_ENABLED)) {
  306. bnad->cfg_flags |= BNAD_CF_DIM_ENABLED;
  307. bnad_dim_timer_start(bnad);
  308. }
  309. } else {
  310. if (bnad->cfg_flags & BNAD_CF_DIM_ENABLED) {
  311. bnad->cfg_flags &= ~BNAD_CF_DIM_ENABLED;
  312. dim_timer_del = bnad_dim_timer_running(bnad);
  313. if (dim_timer_del) {
  314. clear_bit(BNAD_RF_DIM_TIMER_RUNNING,
  315. &bnad->run_flags);
  316. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  317. del_timer_sync(&bnad->dim_timer);
  318. spin_lock_irqsave(&bnad->bna_lock, flags);
  319. }
  320. bnad_rx_coalescing_timeo_set(bnad);
  321. }
  322. }
  323. if (bnad->tx_coalescing_timeo != coalesce->tx_coalesce_usecs /
  324. BFI_COALESCING_TIMER_UNIT) {
  325. bnad->tx_coalescing_timeo = coalesce->tx_coalesce_usecs /
  326. BFI_COALESCING_TIMER_UNIT;
  327. bnad_tx_coalescing_timeo_set(bnad);
  328. }
  329. if (bnad->rx_coalescing_timeo != coalesce->rx_coalesce_usecs /
  330. BFI_COALESCING_TIMER_UNIT) {
  331. bnad->rx_coalescing_timeo = coalesce->rx_coalesce_usecs /
  332. BFI_COALESCING_TIMER_UNIT;
  333. if (!(bnad->cfg_flags & BNAD_CF_DIM_ENABLED))
  334. bnad_rx_coalescing_timeo_set(bnad);
  335. }
  336. /* Add Tx Inter-pkt DMA count? */
  337. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  338. mutex_unlock(&bnad->conf_mutex);
  339. return 0;
  340. }
  341. static void
  342. bnad_get_ringparam(struct net_device *netdev,
  343. struct ethtool_ringparam *ringparam)
  344. {
  345. struct bnad *bnad = netdev_priv(netdev);
  346. ringparam->rx_max_pending = BNAD_MAX_Q_DEPTH / bnad_rxqs_per_cq;
  347. ringparam->rx_mini_max_pending = 0;
  348. ringparam->rx_jumbo_max_pending = 0;
  349. ringparam->tx_max_pending = BNAD_MAX_Q_DEPTH;
  350. ringparam->rx_pending = bnad->rxq_depth;
  351. ringparam->rx_mini_max_pending = 0;
  352. ringparam->rx_jumbo_max_pending = 0;
  353. ringparam->tx_pending = bnad->txq_depth;
  354. }
  355. static int
  356. bnad_set_ringparam(struct net_device *netdev,
  357. struct ethtool_ringparam *ringparam)
  358. {
  359. int i, current_err, err = 0;
  360. struct bnad *bnad = netdev_priv(netdev);
  361. mutex_lock(&bnad->conf_mutex);
  362. if (ringparam->rx_pending == bnad->rxq_depth &&
  363. ringparam->tx_pending == bnad->txq_depth) {
  364. mutex_unlock(&bnad->conf_mutex);
  365. return 0;
  366. }
  367. if (ringparam->rx_pending < BNAD_MIN_Q_DEPTH ||
  368. ringparam->rx_pending > BNAD_MAX_Q_DEPTH / bnad_rxqs_per_cq ||
  369. !BNA_POWER_OF_2(ringparam->rx_pending)) {
  370. mutex_unlock(&bnad->conf_mutex);
  371. return -EINVAL;
  372. }
  373. if (ringparam->tx_pending < BNAD_MIN_Q_DEPTH ||
  374. ringparam->tx_pending > BNAD_MAX_Q_DEPTH ||
  375. !BNA_POWER_OF_2(ringparam->tx_pending)) {
  376. mutex_unlock(&bnad->conf_mutex);
  377. return -EINVAL;
  378. }
  379. if (ringparam->rx_pending != bnad->rxq_depth) {
  380. bnad->rxq_depth = ringparam->rx_pending;
  381. for (i = 0; i < bnad->num_rx; i++) {
  382. if (!bnad->rx_info[i].rx)
  383. continue;
  384. bnad_cleanup_rx(bnad, i);
  385. current_err = bnad_setup_rx(bnad, i);
  386. if (current_err && !err)
  387. err = current_err;
  388. }
  389. }
  390. if (ringparam->tx_pending != bnad->txq_depth) {
  391. bnad->txq_depth = ringparam->tx_pending;
  392. for (i = 0; i < bnad->num_tx; i++) {
  393. if (!bnad->tx_info[i].tx)
  394. continue;
  395. bnad_cleanup_tx(bnad, i);
  396. current_err = bnad_setup_tx(bnad, i);
  397. if (current_err && !err)
  398. err = current_err;
  399. }
  400. }
  401. mutex_unlock(&bnad->conf_mutex);
  402. return err;
  403. }
  404. static void
  405. bnad_get_pauseparam(struct net_device *netdev,
  406. struct ethtool_pauseparam *pauseparam)
  407. {
  408. struct bnad *bnad = netdev_priv(netdev);
  409. pauseparam->autoneg = 0;
  410. pauseparam->rx_pause = bnad->bna.port.pause_config.rx_pause;
  411. pauseparam->tx_pause = bnad->bna.port.pause_config.tx_pause;
  412. }
  413. static int
  414. bnad_set_pauseparam(struct net_device *netdev,
  415. struct ethtool_pauseparam *pauseparam)
  416. {
  417. struct bnad *bnad = netdev_priv(netdev);
  418. struct bna_pause_config pause_config;
  419. unsigned long flags;
  420. if (pauseparam->autoneg == AUTONEG_ENABLE)
  421. return -EINVAL;
  422. mutex_lock(&bnad->conf_mutex);
  423. if (pauseparam->rx_pause != bnad->bna.port.pause_config.rx_pause ||
  424. pauseparam->tx_pause != bnad->bna.port.pause_config.tx_pause) {
  425. pause_config.rx_pause = pauseparam->rx_pause;
  426. pause_config.tx_pause = pauseparam->tx_pause;
  427. spin_lock_irqsave(&bnad->bna_lock, flags);
  428. bna_port_pause_config(&bnad->bna.port, &pause_config, NULL);
  429. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  430. }
  431. mutex_unlock(&bnad->conf_mutex);
  432. return 0;
  433. }
  434. static void
  435. bnad_get_strings(struct net_device *netdev, u32 stringset, u8 * string)
  436. {
  437. struct bnad *bnad = netdev_priv(netdev);
  438. int i, j, q_num;
  439. u64 bmap;
  440. mutex_lock(&bnad->conf_mutex);
  441. switch (stringset) {
  442. case ETH_SS_STATS:
  443. for (i = 0; i < BNAD_ETHTOOL_STATS_NUM; i++) {
  444. BUG_ON(!(strlen(bnad_net_stats_strings[i]) <
  445. ETH_GSTRING_LEN));
  446. memcpy(string, bnad_net_stats_strings[i],
  447. ETH_GSTRING_LEN);
  448. string += ETH_GSTRING_LEN;
  449. }
  450. bmap = (u64)bnad->bna.tx_mod.txf_bmap[0] |
  451. ((u64)bnad->bna.tx_mod.txf_bmap[1] << 32);
  452. for (i = 0; bmap && (i < BFI_LL_TXF_ID_MAX); i++) {
  453. if (bmap & 1) {
  454. sprintf(string, "txf%d_ucast_octets", i);
  455. string += ETH_GSTRING_LEN;
  456. sprintf(string, "txf%d_ucast", i);
  457. string += ETH_GSTRING_LEN;
  458. sprintf(string, "txf%d_ucast_vlan", i);
  459. string += ETH_GSTRING_LEN;
  460. sprintf(string, "txf%d_mcast_octets", i);
  461. string += ETH_GSTRING_LEN;
  462. sprintf(string, "txf%d_mcast", i);
  463. string += ETH_GSTRING_LEN;
  464. sprintf(string, "txf%d_mcast_vlan", i);
  465. string += ETH_GSTRING_LEN;
  466. sprintf(string, "txf%d_bcast_octets", i);
  467. string += ETH_GSTRING_LEN;
  468. sprintf(string, "txf%d_bcast", i);
  469. string += ETH_GSTRING_LEN;
  470. sprintf(string, "txf%d_bcast_vlan", i);
  471. string += ETH_GSTRING_LEN;
  472. sprintf(string, "txf%d_errors", i);
  473. string += ETH_GSTRING_LEN;
  474. sprintf(string, "txf%d_filter_vlan", i);
  475. string += ETH_GSTRING_LEN;
  476. sprintf(string, "txf%d_filter_mac_sa", i);
  477. string += ETH_GSTRING_LEN;
  478. }
  479. bmap >>= 1;
  480. }
  481. bmap = (u64)bnad->bna.rx_mod.rxf_bmap[0] |
  482. ((u64)bnad->bna.rx_mod.rxf_bmap[1] << 32);
  483. for (i = 0; bmap && (i < BFI_LL_RXF_ID_MAX); i++) {
  484. if (bmap & 1) {
  485. sprintf(string, "rxf%d_ucast_octets", i);
  486. string += ETH_GSTRING_LEN;
  487. sprintf(string, "rxf%d_ucast", i);
  488. string += ETH_GSTRING_LEN;
  489. sprintf(string, "rxf%d_ucast_vlan", i);
  490. string += ETH_GSTRING_LEN;
  491. sprintf(string, "rxf%d_mcast_octets", i);
  492. string += ETH_GSTRING_LEN;
  493. sprintf(string, "rxf%d_mcast", i);
  494. string += ETH_GSTRING_LEN;
  495. sprintf(string, "rxf%d_mcast_vlan", i);
  496. string += ETH_GSTRING_LEN;
  497. sprintf(string, "rxf%d_bcast_octets", i);
  498. string += ETH_GSTRING_LEN;
  499. sprintf(string, "rxf%d_bcast", i);
  500. string += ETH_GSTRING_LEN;
  501. sprintf(string, "rxf%d_bcast_vlan", i);
  502. string += ETH_GSTRING_LEN;
  503. sprintf(string, "rxf%d_frame_drops", i);
  504. string += ETH_GSTRING_LEN;
  505. }
  506. bmap >>= 1;
  507. }
  508. q_num = 0;
  509. for (i = 0; i < bnad->num_rx; i++) {
  510. if (!bnad->rx_info[i].rx)
  511. continue;
  512. for (j = 0; j < bnad->num_rxp_per_rx; j++) {
  513. sprintf(string, "cq%d_producer_index", q_num);
  514. string += ETH_GSTRING_LEN;
  515. sprintf(string, "cq%d_consumer_index", q_num);
  516. string += ETH_GSTRING_LEN;
  517. sprintf(string, "cq%d_hw_producer_index",
  518. q_num);
  519. string += ETH_GSTRING_LEN;
  520. q_num++;
  521. }
  522. }
  523. q_num = 0;
  524. for (i = 0; i < bnad->num_rx; i++) {
  525. if (!bnad->rx_info[i].rx)
  526. continue;
  527. for (j = 0; j < bnad->num_rxp_per_rx; j++) {
  528. sprintf(string, "rxq%d_packets", q_num);
  529. string += ETH_GSTRING_LEN;
  530. sprintf(string, "rxq%d_bytes", q_num);
  531. string += ETH_GSTRING_LEN;
  532. sprintf(string, "rxq%d_packets_with_error",
  533. q_num);
  534. string += ETH_GSTRING_LEN;
  535. sprintf(string, "rxq%d_allocbuf_failed", q_num);
  536. string += ETH_GSTRING_LEN;
  537. sprintf(string, "rxq%d_producer_index", q_num);
  538. string += ETH_GSTRING_LEN;
  539. sprintf(string, "rxq%d_consumer_index", q_num);
  540. string += ETH_GSTRING_LEN;
  541. q_num++;
  542. if (bnad->rx_info[i].rx_ctrl[j].ccb &&
  543. bnad->rx_info[i].rx_ctrl[j].ccb->
  544. rcb[1] &&
  545. bnad->rx_info[i].rx_ctrl[j].ccb->
  546. rcb[1]->rxq) {
  547. sprintf(string, "rxq%d_packets", q_num);
  548. string += ETH_GSTRING_LEN;
  549. sprintf(string, "rxq%d_bytes", q_num);
  550. string += ETH_GSTRING_LEN;
  551. sprintf(string,
  552. "rxq%d_packets_with_error", q_num);
  553. string += ETH_GSTRING_LEN;
  554. sprintf(string, "rxq%d_allocbuf_failed",
  555. q_num);
  556. string += ETH_GSTRING_LEN;
  557. sprintf(string, "rxq%d_producer_index",
  558. q_num);
  559. string += ETH_GSTRING_LEN;
  560. sprintf(string, "rxq%d_consumer_index",
  561. q_num);
  562. string += ETH_GSTRING_LEN;
  563. q_num++;
  564. }
  565. }
  566. }
  567. q_num = 0;
  568. for (i = 0; i < bnad->num_tx; i++) {
  569. if (!bnad->tx_info[i].tx)
  570. continue;
  571. for (j = 0; j < bnad->num_txq_per_tx; j++) {
  572. sprintf(string, "txq%d_packets", q_num);
  573. string += ETH_GSTRING_LEN;
  574. sprintf(string, "txq%d_bytes", q_num);
  575. string += ETH_GSTRING_LEN;
  576. sprintf(string, "txq%d_producer_index", q_num);
  577. string += ETH_GSTRING_LEN;
  578. sprintf(string, "txq%d_consumer_index", q_num);
  579. string += ETH_GSTRING_LEN;
  580. sprintf(string, "txq%d_hw_consumer_index",
  581. q_num);
  582. string += ETH_GSTRING_LEN;
  583. q_num++;
  584. }
  585. }
  586. break;
  587. default:
  588. break;
  589. }
  590. mutex_unlock(&bnad->conf_mutex);
  591. }
  592. static int
  593. bnad_get_stats_count_locked(struct net_device *netdev)
  594. {
  595. struct bnad *bnad = netdev_priv(netdev);
  596. int i, j, count, rxf_active_num = 0, txf_active_num = 0;
  597. u64 bmap;
  598. bmap = (u64)bnad->bna.tx_mod.txf_bmap[0] |
  599. ((u64)bnad->bna.tx_mod.txf_bmap[1] << 32);
  600. for (i = 0; bmap && (i < BFI_LL_TXF_ID_MAX); i++) {
  601. if (bmap & 1)
  602. txf_active_num++;
  603. bmap >>= 1;
  604. }
  605. bmap = (u64)bnad->bna.rx_mod.rxf_bmap[0] |
  606. ((u64)bnad->bna.rx_mod.rxf_bmap[1] << 32);
  607. for (i = 0; bmap && (i < BFI_LL_RXF_ID_MAX); i++) {
  608. if (bmap & 1)
  609. rxf_active_num++;
  610. bmap >>= 1;
  611. }
  612. count = BNAD_ETHTOOL_STATS_NUM +
  613. txf_active_num * BNAD_NUM_TXF_COUNTERS +
  614. rxf_active_num * BNAD_NUM_RXF_COUNTERS;
  615. for (i = 0; i < bnad->num_rx; i++) {
  616. if (!bnad->rx_info[i].rx)
  617. continue;
  618. count += bnad->num_rxp_per_rx * BNAD_NUM_CQ_COUNTERS;
  619. count += bnad->num_rxp_per_rx * BNAD_NUM_RXQ_COUNTERS;
  620. for (j = 0; j < bnad->num_rxp_per_rx; j++)
  621. if (bnad->rx_info[i].rx_ctrl[j].ccb &&
  622. bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1] &&
  623. bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1]->rxq)
  624. count += BNAD_NUM_RXQ_COUNTERS;
  625. }
  626. for (i = 0; i < bnad->num_tx; i++) {
  627. if (!bnad->tx_info[i].tx)
  628. continue;
  629. count += bnad->num_txq_per_tx * BNAD_NUM_TXQ_COUNTERS;
  630. }
  631. return count;
  632. }
  633. static int
  634. bnad_per_q_stats_fill(struct bnad *bnad, u64 *buf, int bi)
  635. {
  636. int i, j;
  637. struct bna_rcb *rcb = NULL;
  638. struct bna_tcb *tcb = NULL;
  639. for (i = 0; i < bnad->num_rx; i++) {
  640. if (!bnad->rx_info[i].rx)
  641. continue;
  642. for (j = 0; j < bnad->num_rxp_per_rx; j++)
  643. if (bnad->rx_info[i].rx_ctrl[j].ccb &&
  644. bnad->rx_info[i].rx_ctrl[j].ccb->rcb[0] &&
  645. bnad->rx_info[i].rx_ctrl[j].ccb->rcb[0]->rxq) {
  646. buf[bi++] = bnad->rx_info[i].rx_ctrl[j].
  647. ccb->producer_index;
  648. buf[bi++] = 0; /* ccb->consumer_index */
  649. buf[bi++] = *(bnad->rx_info[i].rx_ctrl[j].
  650. ccb->hw_producer_index);
  651. }
  652. }
  653. for (i = 0; i < bnad->num_rx; i++) {
  654. if (!bnad->rx_info[i].rx)
  655. continue;
  656. for (j = 0; j < bnad->num_rxp_per_rx; j++)
  657. if (bnad->rx_info[i].rx_ctrl[j].ccb) {
  658. if (bnad->rx_info[i].rx_ctrl[j].ccb->rcb[0] &&
  659. bnad->rx_info[i].rx_ctrl[j].ccb->
  660. rcb[0]->rxq) {
  661. rcb = bnad->rx_info[i].rx_ctrl[j].
  662. ccb->rcb[0];
  663. buf[bi++] = rcb->rxq->rx_packets;
  664. buf[bi++] = rcb->rxq->rx_bytes;
  665. buf[bi++] = rcb->rxq->
  666. rx_packets_with_error;
  667. buf[bi++] = rcb->rxq->
  668. rxbuf_alloc_failed;
  669. buf[bi++] = rcb->producer_index;
  670. buf[bi++] = rcb->consumer_index;
  671. }
  672. if (bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1] &&
  673. bnad->rx_info[i].rx_ctrl[j].ccb->
  674. rcb[1]->rxq) {
  675. rcb = bnad->rx_info[i].rx_ctrl[j].
  676. ccb->rcb[1];
  677. buf[bi++] = rcb->rxq->rx_packets;
  678. buf[bi++] = rcb->rxq->rx_bytes;
  679. buf[bi++] = rcb->rxq->
  680. rx_packets_with_error;
  681. buf[bi++] = rcb->rxq->
  682. rxbuf_alloc_failed;
  683. buf[bi++] = rcb->producer_index;
  684. buf[bi++] = rcb->consumer_index;
  685. }
  686. }
  687. }
  688. for (i = 0; i < bnad->num_tx; i++) {
  689. if (!bnad->tx_info[i].tx)
  690. continue;
  691. for (j = 0; j < bnad->num_txq_per_tx; j++)
  692. if (bnad->tx_info[i].tcb[j] &&
  693. bnad->tx_info[i].tcb[j]->txq) {
  694. tcb = bnad->tx_info[i].tcb[j];
  695. buf[bi++] = tcb->txq->tx_packets;
  696. buf[bi++] = tcb->txq->tx_bytes;
  697. buf[bi++] = tcb->producer_index;
  698. buf[bi++] = tcb->consumer_index;
  699. buf[bi++] = *(tcb->hw_consumer_index);
  700. }
  701. }
  702. return bi;
  703. }
  704. static void
  705. bnad_get_ethtool_stats(struct net_device *netdev, struct ethtool_stats *stats,
  706. u64 *buf)
  707. {
  708. struct bnad *bnad = netdev_priv(netdev);
  709. int i, j, bi;
  710. unsigned long flags;
  711. struct rtnl_link_stats64 *net_stats64;
  712. u64 *stats64;
  713. u64 bmap;
  714. mutex_lock(&bnad->conf_mutex);
  715. if (bnad_get_stats_count_locked(netdev) != stats->n_stats) {
  716. mutex_unlock(&bnad->conf_mutex);
  717. return;
  718. }
  719. /*
  720. * Used bna_lock to sync reads from bna_stats, which is written
  721. * under the same lock
  722. */
  723. spin_lock_irqsave(&bnad->bna_lock, flags);
  724. bi = 0;
  725. memset(buf, 0, stats->n_stats * sizeof(u64));
  726. net_stats64 = (struct rtnl_link_stats64 *)buf;
  727. bnad_netdev_qstats_fill(bnad, net_stats64);
  728. bnad_netdev_hwstats_fill(bnad, net_stats64);
  729. bi = sizeof(*net_stats64) / sizeof(u64);
  730. /* Get netif_queue_stopped from stack */
  731. bnad->stats.drv_stats.netif_queue_stopped = netif_queue_stopped(netdev);
  732. /* Fill driver stats into ethtool buffers */
  733. stats64 = (u64 *)&bnad->stats.drv_stats;
  734. for (i = 0; i < sizeof(struct bnad_drv_stats) / sizeof(u64); i++)
  735. buf[bi++] = stats64[i];
  736. /* Fill hardware stats excluding the rxf/txf into ethtool bufs */
  737. stats64 = (u64 *) bnad->stats.bna_stats->hw_stats;
  738. for (i = 0;
  739. i < offsetof(struct bfi_ll_stats, rxf_stats[0]) / sizeof(u64);
  740. i++)
  741. buf[bi++] = stats64[i];
  742. /* Fill txf stats into ethtool buffers */
  743. bmap = (u64)bnad->bna.tx_mod.txf_bmap[0] |
  744. ((u64)bnad->bna.tx_mod.txf_bmap[1] << 32);
  745. for (i = 0; bmap && (i < BFI_LL_TXF_ID_MAX); i++) {
  746. if (bmap & 1) {
  747. stats64 = (u64 *)&bnad->stats.bna_stats->
  748. hw_stats->txf_stats[i];
  749. for (j = 0; j < sizeof(struct bfi_ll_stats_txf) /
  750. sizeof(u64); j++)
  751. buf[bi++] = stats64[j];
  752. }
  753. bmap >>= 1;
  754. }
  755. /* Fill rxf stats into ethtool buffers */
  756. bmap = (u64)bnad->bna.rx_mod.rxf_bmap[0] |
  757. ((u64)bnad->bna.rx_mod.rxf_bmap[1] << 32);
  758. for (i = 0; bmap && (i < BFI_LL_RXF_ID_MAX); i++) {
  759. if (bmap & 1) {
  760. stats64 = (u64 *)&bnad->stats.bna_stats->
  761. hw_stats->rxf_stats[i];
  762. for (j = 0; j < sizeof(struct bfi_ll_stats_rxf) /
  763. sizeof(u64); j++)
  764. buf[bi++] = stats64[j];
  765. }
  766. bmap >>= 1;
  767. }
  768. /* Fill per Q stats into ethtool buffers */
  769. bi = bnad_per_q_stats_fill(bnad, buf, bi);
  770. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  771. mutex_unlock(&bnad->conf_mutex);
  772. }
  773. static int
  774. bnad_get_sset_count(struct net_device *netdev, int sset)
  775. {
  776. switch (sset) {
  777. case ETH_SS_STATS:
  778. return bnad_get_stats_count_locked(netdev);
  779. default:
  780. return -EOPNOTSUPP;
  781. }
  782. }
  783. static struct ethtool_ops bnad_ethtool_ops = {
  784. .get_settings = bnad_get_settings,
  785. .set_settings = bnad_set_settings,
  786. .get_drvinfo = bnad_get_drvinfo,
  787. .get_wol = bnad_get_wol,
  788. .get_link = ethtool_op_get_link,
  789. .get_coalesce = bnad_get_coalesce,
  790. .set_coalesce = bnad_set_coalesce,
  791. .get_ringparam = bnad_get_ringparam,
  792. .set_ringparam = bnad_set_ringparam,
  793. .get_pauseparam = bnad_get_pauseparam,
  794. .set_pauseparam = bnad_set_pauseparam,
  795. .get_strings = bnad_get_strings,
  796. .get_ethtool_stats = bnad_get_ethtool_stats,
  797. .get_sset_count = bnad_get_sset_count
  798. };
  799. void
  800. bnad_set_ethtool_ops(struct net_device *netdev)
  801. {
  802. SET_ETHTOOL_OPS(netdev, &bnad_ethtool_ops);
  803. }