Linux Audio

Check our new training course

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