Linux Audio

Check our new training course

Loading...
v6.13.7
   1/**********************************************************************
   2 * Author: Cavium, Inc.
   3 *
   4 * Contact: support@cavium.com
   5 *          Please include "LiquidIO" in the subject.
   6 *
   7 * Copyright (c) 2003-2016 Cavium, Inc.
   8 *
   9 * This file is free software; you can redistribute it and/or modify
  10 * it under the terms of the GNU General Public License, Version 2, as
  11 * published by the Free Software Foundation.
  12 *
  13 * This file is distributed in the hope that it will be useful, but
  14 * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
  15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
  16 * NONINFRINGEMENT.  See the GNU General Public License for more details.
  17 ***********************************************************************/
  18#include <linux/ethtool.h>
  19#include <linux/netdevice.h>
  20#include <linux/net_tstamp.h>
  21#include <linux/pci.h>
  22#include "liquidio_common.h"
  23#include "octeon_droq.h"
  24#include "octeon_iq.h"
  25#include "response_manager.h"
  26#include "octeon_device.h"
  27#include "octeon_nic.h"
  28#include "octeon_main.h"
  29#include "octeon_network.h"
  30#include "cn66xx_regs.h"
  31#include "cn66xx_device.h"
  32#include "cn23xx_pf_device.h"
  33#include "cn23xx_vf_device.h"
  34
  35static int lio_reset_queues(struct net_device *netdev, uint32_t num_qs);
  36
  37struct oct_intrmod_resp {
  38	u64     rh;
  39	struct oct_intrmod_cfg intrmod;
  40	u64     status;
  41};
  42
  43struct oct_mdio_cmd_resp {
  44	u64 rh;
  45	struct oct_mdio_cmd resp;
  46	u64 status;
  47};
  48
  49#define OCT_MDIO45_RESP_SIZE   (sizeof(struct oct_mdio_cmd_resp))
  50
  51/* Octeon's interface mode of operation */
  52enum {
  53	INTERFACE_MODE_DISABLED,
  54	INTERFACE_MODE_RGMII,
  55	INTERFACE_MODE_GMII,
  56	INTERFACE_MODE_SPI,
  57	INTERFACE_MODE_PCIE,
  58	INTERFACE_MODE_XAUI,
  59	INTERFACE_MODE_SGMII,
  60	INTERFACE_MODE_PICMG,
  61	INTERFACE_MODE_NPI,
  62	INTERFACE_MODE_LOOP,
  63	INTERFACE_MODE_SRIO,
  64	INTERFACE_MODE_ILK,
  65	INTERFACE_MODE_RXAUI,
  66	INTERFACE_MODE_QSGMII,
  67	INTERFACE_MODE_AGL,
  68	INTERFACE_MODE_XLAUI,
  69	INTERFACE_MODE_XFI,
  70	INTERFACE_MODE_10G_KR,
  71	INTERFACE_MODE_40G_KR4,
  72	INTERFACE_MODE_MIXED,
  73};
  74
  75#define OCT_ETHTOOL_REGDUMP_LEN  4096
  76#define OCT_ETHTOOL_REGDUMP_LEN_23XX  (4096 * 11)
  77#define OCT_ETHTOOL_REGDUMP_LEN_23XX_VF  (4096 * 2)
  78#define OCT_ETHTOOL_REGSVER  1
  79
  80/* statistics of PF */
  81static const char oct_stats_strings[][ETH_GSTRING_LEN] = {
  82	"rx_packets",
  83	"tx_packets",
  84	"rx_bytes",
  85	"tx_bytes",
  86	"rx_errors",
  87	"tx_errors",
  88	"rx_dropped",
  89	"tx_dropped",
  90
  91	"tx_total_sent",
  92	"tx_total_fwd",
  93	"tx_err_pko",
  94	"tx_err_pki",
  95	"tx_err_link",
  96	"tx_err_drop",
  97
  98	"tx_tso",
  99	"tx_tso_packets",
 100	"tx_tso_err",
 101	"tx_vxlan",
 102
 103	"tx_mcast",
 104	"tx_bcast",
 105
 106	"mac_tx_total_pkts",
 107	"mac_tx_total_bytes",
 108	"mac_tx_mcast_pkts",
 109	"mac_tx_bcast_pkts",
 110	"mac_tx_ctl_packets",
 111	"mac_tx_total_collisions",
 112	"mac_tx_one_collision",
 113	"mac_tx_multi_collision",
 114	"mac_tx_max_collision_fail",
 115	"mac_tx_max_deferral_fail",
 116	"mac_tx_fifo_err",
 117	"mac_tx_runts",
 118
 119	"rx_total_rcvd",
 120	"rx_total_fwd",
 121	"rx_mcast",
 122	"rx_bcast",
 123	"rx_jabber_err",
 124	"rx_l2_err",
 125	"rx_frame_err",
 126	"rx_err_pko",
 127	"rx_err_link",
 128	"rx_err_drop",
 129
 130	"rx_vxlan",
 131	"rx_vxlan_err",
 132
 133	"rx_lro_pkts",
 134	"rx_lro_bytes",
 135	"rx_total_lro",
 136
 137	"rx_lro_aborts",
 138	"rx_lro_aborts_port",
 139	"rx_lro_aborts_seq",
 140	"rx_lro_aborts_tsval",
 141	"rx_lro_aborts_timer",
 142	"rx_fwd_rate",
 143
 144	"mac_rx_total_rcvd",
 145	"mac_rx_bytes",
 146	"mac_rx_total_bcst",
 147	"mac_rx_total_mcst",
 148	"mac_rx_runts",
 149	"mac_rx_ctl_packets",
 150	"mac_rx_fifo_err",
 151	"mac_rx_dma_drop",
 152	"mac_rx_fcs_err",
 153
 154	"link_state_changes",
 155};
 156
 157/* statistics of VF */
 158static const char oct_vf_stats_strings[][ETH_GSTRING_LEN] = {
 159	"rx_packets",
 160	"tx_packets",
 161	"rx_bytes",
 162	"tx_bytes",
 163	"rx_errors",
 164	"tx_errors",
 165	"rx_dropped",
 166	"tx_dropped",
 167	"rx_mcast",
 168	"tx_mcast",
 169	"rx_bcast",
 170	"tx_bcast",
 171	"link_state_changes",
 172};
 173
 174/* statistics of host tx queue */
 175static const char oct_iq_stats_strings[][ETH_GSTRING_LEN] = {
 176	"packets",
 177	"bytes",
 178	"dropped",
 179	"iq_busy",
 180	"sgentry_sent",
 181
 182	"fw_instr_posted",
 183	"fw_instr_processed",
 184	"fw_instr_dropped",
 185	"fw_bytes_sent",
 186
 187	"tso",
 188	"vxlan",
 189	"txq_restart",
 190};
 191
 192/* statistics of host rx queue */
 193static const char oct_droq_stats_strings[][ETH_GSTRING_LEN] = {
 194	"packets",
 195	"bytes",
 196	"dropped",
 197	"dropped_nomem",
 198	"dropped_toomany",
 199	"fw_dropped",
 200	"fw_pkts_received",
 201	"fw_bytes_received",
 202	"fw_dropped_nodispatch",
 203
 204	"vxlan",
 205	"buffer_alloc_failure",
 206};
 207
 208/* LiquidIO driver private flags */
 209static const char oct_priv_flags_strings[][ETH_GSTRING_LEN] = {
 210};
 211
 212#define OCTNIC_NCMD_AUTONEG_ON  0x1
 213#define OCTNIC_NCMD_PHY_ON      0x2
 214
 215static int lio_get_link_ksettings(struct net_device *netdev,
 216				  struct ethtool_link_ksettings *ecmd)
 217{
 218	struct lio *lio = GET_LIO(netdev);
 219	struct octeon_device *oct = lio->oct_dev;
 220	struct oct_link_info *linfo;
 221
 222	linfo = &lio->linfo;
 223
 224	ethtool_link_ksettings_zero_link_mode(ecmd, supported);
 225	ethtool_link_ksettings_zero_link_mode(ecmd, advertising);
 226
 227	switch (linfo->link.s.phy_type) {
 228	case LIO_PHY_PORT_TP:
 229		ecmd->base.port = PORT_TP;
 230		ecmd->base.autoneg = AUTONEG_DISABLE;
 231		ethtool_link_ksettings_add_link_mode(ecmd, supported, TP);
 232		ethtool_link_ksettings_add_link_mode(ecmd, supported, Pause);
 233		ethtool_link_ksettings_add_link_mode(ecmd, supported,
 234						     10000baseT_Full);
 235
 236		ethtool_link_ksettings_add_link_mode(ecmd, advertising, Pause);
 237		ethtool_link_ksettings_add_link_mode(ecmd, advertising,
 238						     10000baseT_Full);
 239
 240		break;
 241
 242	case LIO_PHY_PORT_FIBRE:
 243		if (linfo->link.s.if_mode == INTERFACE_MODE_XAUI ||
 244		    linfo->link.s.if_mode == INTERFACE_MODE_RXAUI ||
 245		    linfo->link.s.if_mode == INTERFACE_MODE_XLAUI ||
 246		    linfo->link.s.if_mode == INTERFACE_MODE_XFI) {
 247			dev_dbg(&oct->pci_dev->dev, "ecmd->base.transceiver is XCVR_EXTERNAL\n");
 248			ecmd->base.transceiver = XCVR_EXTERNAL;
 249		} else {
 250			dev_err(&oct->pci_dev->dev, "Unknown link interface mode: %d\n",
 251				linfo->link.s.if_mode);
 252		}
 253
 254		ecmd->base.port = PORT_FIBRE;
 255		ecmd->base.autoneg = AUTONEG_DISABLE;
 256		ethtool_link_ksettings_add_link_mode(ecmd, supported, FIBRE);
 257
 258		ethtool_link_ksettings_add_link_mode(ecmd, supported, Pause);
 259		ethtool_link_ksettings_add_link_mode(ecmd, advertising, Pause);
 260		if (oct->subsystem_id == OCTEON_CN2350_25GB_SUBSYS_ID ||
 261		    oct->subsystem_id == OCTEON_CN2360_25GB_SUBSYS_ID) {
 262			if (OCTEON_CN23XX_PF(oct)) {
 263				ethtool_link_ksettings_add_link_mode
 264					(ecmd, supported, 25000baseSR_Full);
 265				ethtool_link_ksettings_add_link_mode
 266					(ecmd, supported, 25000baseKR_Full);
 267				ethtool_link_ksettings_add_link_mode
 268					(ecmd, supported, 25000baseCR_Full);
 269
 270				if (oct->no_speed_setting == 0)  {
 271					ethtool_link_ksettings_add_link_mode
 272						(ecmd, supported,
 273						 10000baseSR_Full);
 274					ethtool_link_ksettings_add_link_mode
 275						(ecmd, supported,
 276						 10000baseKR_Full);
 277					ethtool_link_ksettings_add_link_mode
 278						(ecmd, supported,
 279						 10000baseCR_Full);
 280				}
 281
 282				if (oct->no_speed_setting == 0) {
 283					liquidio_get_speed(lio);
 284					liquidio_get_fec(lio);
 285				} else {
 286					oct->speed_setting = 25;
 287				}
 288
 289				if (oct->speed_setting == 10) {
 290					ethtool_link_ksettings_add_link_mode
 291						(ecmd, advertising,
 292						 10000baseSR_Full);
 293					ethtool_link_ksettings_add_link_mode
 294						(ecmd, advertising,
 295						 10000baseKR_Full);
 296					ethtool_link_ksettings_add_link_mode
 297						(ecmd, advertising,
 298						 10000baseCR_Full);
 299				}
 300				if (oct->speed_setting == 25) {
 301					ethtool_link_ksettings_add_link_mode
 302						(ecmd, advertising,
 303						 25000baseSR_Full);
 304					ethtool_link_ksettings_add_link_mode
 305						(ecmd, advertising,
 306						 25000baseKR_Full);
 307					ethtool_link_ksettings_add_link_mode
 308						(ecmd, advertising,
 309						 25000baseCR_Full);
 310				}
 311
 312				if (oct->no_speed_setting)
 313					break;
 314
 315				ethtool_link_ksettings_add_link_mode
 316					(ecmd, supported, FEC_RS);
 317				ethtool_link_ksettings_add_link_mode
 318					(ecmd, supported, FEC_NONE);
 319					/*FEC_OFF*/
 320				if (oct->props[lio->ifidx].fec == 1) {
 321					/* ETHTOOL_FEC_RS */
 322					ethtool_link_ksettings_add_link_mode
 323						(ecmd, advertising, FEC_RS);
 324				} else {
 325					/* ETHTOOL_FEC_OFF */
 326					ethtool_link_ksettings_add_link_mode
 327						(ecmd, advertising, FEC_NONE);
 328				}
 329			} else { /* VF */
 330				if (linfo->link.s.speed == 10000) {
 331					ethtool_link_ksettings_add_link_mode
 332						(ecmd, supported,
 333						 10000baseSR_Full);
 334					ethtool_link_ksettings_add_link_mode
 335						(ecmd, supported,
 336						 10000baseKR_Full);
 337					ethtool_link_ksettings_add_link_mode
 338						(ecmd, supported,
 339						 10000baseCR_Full);
 340
 341					ethtool_link_ksettings_add_link_mode
 342						(ecmd, advertising,
 343						 10000baseSR_Full);
 344					ethtool_link_ksettings_add_link_mode
 345						(ecmd, advertising,
 346						 10000baseKR_Full);
 347					ethtool_link_ksettings_add_link_mode
 348						(ecmd, advertising,
 349						 10000baseCR_Full);
 350				}
 351
 352				if (linfo->link.s.speed == 25000) {
 353					ethtool_link_ksettings_add_link_mode
 354						(ecmd, supported,
 355						 25000baseSR_Full);
 356					ethtool_link_ksettings_add_link_mode
 357						(ecmd, supported,
 358						 25000baseKR_Full);
 359					ethtool_link_ksettings_add_link_mode
 360						(ecmd, supported,
 361						 25000baseCR_Full);
 362
 363					ethtool_link_ksettings_add_link_mode
 364						(ecmd, advertising,
 365						 25000baseSR_Full);
 366					ethtool_link_ksettings_add_link_mode
 367						(ecmd, advertising,
 368						 25000baseKR_Full);
 369					ethtool_link_ksettings_add_link_mode
 370						(ecmd, advertising,
 371						 25000baseCR_Full);
 372				}
 373			}
 374		} else {
 375			ethtool_link_ksettings_add_link_mode(ecmd, supported,
 376							     10000baseT_Full);
 377			ethtool_link_ksettings_add_link_mode(ecmd, advertising,
 378							     10000baseT_Full);
 379		}
 380		break;
 381	}
 382
 383	if (linfo->link.s.link_up) {
 384		ecmd->base.speed = linfo->link.s.speed;
 385		ecmd->base.duplex = linfo->link.s.duplex;
 386	} else {
 387		ecmd->base.speed = SPEED_UNKNOWN;
 388		ecmd->base.duplex = DUPLEX_UNKNOWN;
 389	}
 390
 391	return 0;
 392}
 393
 394static int lio_set_link_ksettings(struct net_device *netdev,
 395				  const struct ethtool_link_ksettings *ecmd)
 396{
 397	const int speed = ecmd->base.speed;
 398	struct lio *lio = GET_LIO(netdev);
 399	struct oct_link_info *linfo;
 400	struct octeon_device *oct;
 401
 402	oct = lio->oct_dev;
 403
 404	linfo = &lio->linfo;
 405
 406	if (!(oct->subsystem_id == OCTEON_CN2350_25GB_SUBSYS_ID ||
 407	      oct->subsystem_id == OCTEON_CN2360_25GB_SUBSYS_ID))
 408		return -EOPNOTSUPP;
 409
 410	if (oct->no_speed_setting) {
 411		dev_err(&oct->pci_dev->dev, "%s: Changing speed is not supported\n",
 412			__func__);
 413		return -EOPNOTSUPP;
 414	}
 415
 416	if ((ecmd->base.duplex != DUPLEX_UNKNOWN &&
 417	     ecmd->base.duplex != linfo->link.s.duplex) ||
 418	     ecmd->base.autoneg != AUTONEG_DISABLE ||
 419	    (ecmd->base.speed != 10000 && ecmd->base.speed != 25000 &&
 420	     ecmd->base.speed != SPEED_UNKNOWN))
 421		return -EOPNOTSUPP;
 422
 423	if ((oct->speed_boot == speed / 1000) &&
 424	    oct->speed_boot == oct->speed_setting)
 425		return 0;
 426
 427	liquidio_set_speed(lio, speed / 1000);
 428
 429	dev_dbg(&oct->pci_dev->dev, "Port speed is set to %dG\n",
 430		oct->speed_setting);
 431
 432	return 0;
 433}
 434
 435static void
 436lio_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
 437{
 438	struct lio *lio;
 439	struct octeon_device *oct;
 440
 441	lio = GET_LIO(netdev);
 442	oct = lio->oct_dev;
 443
 444	memset(drvinfo, 0, sizeof(struct ethtool_drvinfo));
 445	strscpy(drvinfo->driver, "liquidio", sizeof(drvinfo->driver));
 446	strscpy(drvinfo->fw_version, oct->fw_info.liquidio_firmware_version,
 447		sizeof(drvinfo->fw_version));
 448	strscpy(drvinfo->bus_info, pci_name(oct->pci_dev),
 449		sizeof(drvinfo->bus_info));
 450}
 451
 452static void
 453lio_get_vf_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
 454{
 455	struct octeon_device *oct;
 456	struct lio *lio;
 457
 458	lio = GET_LIO(netdev);
 459	oct = lio->oct_dev;
 460
 461	memset(drvinfo, 0, sizeof(struct ethtool_drvinfo));
 462	strscpy(drvinfo->driver, "liquidio_vf", sizeof(drvinfo->driver));
 463	strscpy(drvinfo->fw_version, oct->fw_info.liquidio_firmware_version,
 464		sizeof(drvinfo->fw_version));
 465	strscpy(drvinfo->bus_info, pci_name(oct->pci_dev),
 466		sizeof(drvinfo->bus_info));
 467}
 468
 469static int
 470lio_send_queue_count_update(struct net_device *netdev, uint32_t num_queues)
 471{
 472	struct lio *lio = GET_LIO(netdev);
 473	struct octeon_device *oct = lio->oct_dev;
 474	struct octnic_ctrl_pkt nctrl;
 475	int ret = 0;
 476
 477	memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
 478
 479	nctrl.ncmd.u64 = 0;
 480	nctrl.ncmd.s.cmd = OCTNET_CMD_QUEUE_COUNT_CTL;
 481	nctrl.ncmd.s.param1 = num_queues;
 482	nctrl.ncmd.s.param2 = num_queues;
 483	nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
 484	nctrl.netpndev = (u64)netdev;
 485	nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
 486
 487	ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
 488	if (ret) {
 489		dev_err(&oct->pci_dev->dev, "Failed to send Queue reset command (ret: 0x%x)\n",
 490			ret);
 491		return -1;
 492	}
 493
 494	return 0;
 495}
 496
 497static void
 498lio_ethtool_get_channels(struct net_device *dev,
 499			 struct ethtool_channels *channel)
 500{
 501	struct lio *lio = GET_LIO(dev);
 502	struct octeon_device *oct = lio->oct_dev;
 503	u32 max_rx = 0, max_tx = 0, tx_count = 0, rx_count = 0;
 504	u32 combined_count = 0, max_combined = 0;
 505
 506	if (OCTEON_CN6XXX(oct)) {
 507		struct octeon_config *conf6x = CHIP_CONF(oct, cn6xxx);
 508
 509		max_rx = CFG_GET_OQ_MAX_Q(conf6x);
 510		max_tx = CFG_GET_IQ_MAX_Q(conf6x);
 511		rx_count = CFG_GET_NUM_RXQS_NIC_IF(conf6x, lio->ifidx);
 512		tx_count = CFG_GET_NUM_TXQS_NIC_IF(conf6x, lio->ifidx);
 513	} else if (OCTEON_CN23XX_PF(oct)) {
 514		if (oct->sriov_info.sriov_enabled) {
 515			max_combined = lio->linfo.num_txpciq;
 516		} else {
 517			struct octeon_config *conf23_pf =
 518				CHIP_CONF(oct, cn23xx_pf);
 519
 520			max_combined = CFG_GET_IQ_MAX_Q(conf23_pf);
 521		}
 522		combined_count = oct->num_iqs;
 523	} else if (OCTEON_CN23XX_VF(oct)) {
 524		u64 reg_val = 0ULL;
 525		u64 ctrl = CN23XX_VF_SLI_IQ_PKT_CONTROL64(0);
 526
 527		reg_val = octeon_read_csr64(oct, ctrl);
 528		reg_val = reg_val >> CN23XX_PKT_INPUT_CTL_RPVF_POS;
 529		max_combined = reg_val & CN23XX_PKT_INPUT_CTL_RPVF_MASK;
 530		combined_count = oct->num_iqs;
 531	}
 532
 533	channel->max_rx = max_rx;
 534	channel->max_tx = max_tx;
 535	channel->max_combined = max_combined;
 536	channel->rx_count = rx_count;
 537	channel->tx_count = tx_count;
 538	channel->combined_count = combined_count;
 539}
 540
 541static int
 542lio_irq_reallocate_irqs(struct octeon_device *oct, uint32_t num_ioqs)
 543{
 544	struct msix_entry *msix_entries;
 545	int num_msix_irqs = 0;
 546	int i;
 547
 548	if (!oct->msix_on)
 549		return 0;
 550
 551	/* Disable the input and output queues now. No more packets will
 552	 * arrive from Octeon.
 553	 */
 554	oct->fn_list.disable_interrupt(oct, OCTEON_ALL_INTR);
 555
 556	if (oct->msix_on) {
 557		if (OCTEON_CN23XX_PF(oct))
 558			num_msix_irqs = oct->num_msix_irqs - 1;
 559		else if (OCTEON_CN23XX_VF(oct))
 560			num_msix_irqs = oct->num_msix_irqs;
 561
 562		msix_entries = (struct msix_entry *)oct->msix_entries;
 563		for (i = 0; i < num_msix_irqs; i++) {
 564			if (oct->ioq_vector[i].vector) {
 565				/* clear the affinity_cpumask */
 566				irq_set_affinity_hint(msix_entries[i].vector,
 567						      NULL);
 568				free_irq(msix_entries[i].vector,
 569					 &oct->ioq_vector[i]);
 570				oct->ioq_vector[i].vector = 0;
 571			}
 572		}
 573
 574		/* non-iov vector's argument is oct struct */
 575		if (OCTEON_CN23XX_PF(oct))
 576			free_irq(msix_entries[i].vector, oct);
 577
 578		pci_disable_msix(oct->pci_dev);
 579		kfree(oct->msix_entries);
 580		oct->msix_entries = NULL;
 581	}
 582
 583	kfree(oct->irq_name_storage);
 584	oct->irq_name_storage = NULL;
 585
 586	if (octeon_allocate_ioq_vector(oct, num_ioqs)) {
 587		dev_err(&oct->pci_dev->dev, "OCTEON: ioq vector allocation failed\n");
 588		return -1;
 589	}
 590
 591	if (octeon_setup_interrupt(oct, num_ioqs)) {
 592		dev_info(&oct->pci_dev->dev, "Setup interrupt failed\n");
 593		return -1;
 594	}
 595
 596	/* Enable Octeon device interrupts */
 597	oct->fn_list.enable_interrupt(oct, OCTEON_ALL_INTR);
 598
 599	return 0;
 600}
 601
 602static int
 603lio_ethtool_set_channels(struct net_device *dev,
 604			 struct ethtool_channels *channel)
 605{
 606	u32 combined_count, max_combined;
 607	struct lio *lio = GET_LIO(dev);
 608	struct octeon_device *oct = lio->oct_dev;
 609	int stopped = 0;
 610
 611	if (strcmp(oct->fw_info.liquidio_firmware_version, "1.6.1") < 0) {
 612		dev_err(&oct->pci_dev->dev, "Minimum firmware version required is 1.6.1\n");
 613		return -EINVAL;
 614	}
 615
 616	if (!channel->combined_count || channel->other_count ||
 617	    channel->rx_count || channel->tx_count)
 618		return -EINVAL;
 619
 620	combined_count = channel->combined_count;
 621
 622	if (OCTEON_CN23XX_PF(oct)) {
 623		if (oct->sriov_info.sriov_enabled) {
 624			max_combined = lio->linfo.num_txpciq;
 625		} else {
 626			struct octeon_config *conf23_pf =
 627				CHIP_CONF(oct,
 628					  cn23xx_pf);
 629
 630			max_combined =
 631				CFG_GET_IQ_MAX_Q(conf23_pf);
 632		}
 633	} else if (OCTEON_CN23XX_VF(oct)) {
 634		u64 reg_val = 0ULL;
 635		u64 ctrl = CN23XX_VF_SLI_IQ_PKT_CONTROL64(0);
 636
 637		reg_val = octeon_read_csr64(oct, ctrl);
 638		reg_val = reg_val >> CN23XX_PKT_INPUT_CTL_RPVF_POS;
 639		max_combined = reg_val & CN23XX_PKT_INPUT_CTL_RPVF_MASK;
 640	} else {
 641		return -EINVAL;
 642	}
 643
 644	if (combined_count > max_combined || combined_count < 1)
 645		return -EINVAL;
 646
 647	if (combined_count == oct->num_iqs)
 648		return 0;
 649
 650	ifstate_set(lio, LIO_IFSTATE_RESETTING);
 651
 652	if (netif_running(dev)) {
 653		dev->netdev_ops->ndo_stop(dev);
 654		stopped = 1;
 655	}
 656
 657	if (lio_reset_queues(dev, combined_count))
 658		return -EINVAL;
 659
 660	if (stopped)
 661		dev->netdev_ops->ndo_open(dev);
 662
 663	ifstate_reset(lio, LIO_IFSTATE_RESETTING);
 664
 665	return 0;
 666}
 667
 668static int lio_get_eeprom_len(struct net_device *netdev)
 669{
 670	u8 buf[192];
 671	struct lio *lio = GET_LIO(netdev);
 672	struct octeon_device *oct_dev = lio->oct_dev;
 673	struct octeon_board_info *board_info;
 674	int len;
 675
 676	board_info = (struct octeon_board_info *)(&oct_dev->boardinfo);
 677	len = sprintf(buf, "boardname:%s serialnum:%s maj:%lld min:%lld\n",
 678		      board_info->name, board_info->serial_number,
 679		      board_info->major, board_info->minor);
 680
 681	return len;
 682}
 683
 684static int
 685lio_get_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
 686	       u8 *bytes)
 687{
 688	struct lio *lio = GET_LIO(netdev);
 689	struct octeon_device *oct_dev = lio->oct_dev;
 690	struct octeon_board_info *board_info;
 691
 692	if (eeprom->offset)
 693		return -EINVAL;
 694
 695	eeprom->magic = oct_dev->pci_dev->vendor;
 696	board_info = (struct octeon_board_info *)(&oct_dev->boardinfo);
 697	sprintf((char *)bytes,
 698		"boardname:%s serialnum:%s maj:%lld min:%lld\n",
 699		board_info->name, board_info->serial_number,
 700		board_info->major, board_info->minor);
 701
 702	return 0;
 703}
 704
 705static int octnet_gpio_access(struct net_device *netdev, int addr, int val)
 706{
 707	struct lio *lio = GET_LIO(netdev);
 708	struct octeon_device *oct = lio->oct_dev;
 709	struct octnic_ctrl_pkt nctrl;
 710	int ret = 0;
 711
 712	memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
 713
 714	nctrl.ncmd.u64 = 0;
 715	nctrl.ncmd.s.cmd = OCTNET_CMD_GPIO_ACCESS;
 716	nctrl.ncmd.s.param1 = addr;
 717	nctrl.ncmd.s.param2 = val;
 718	nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
 719	nctrl.netpndev = (u64)netdev;
 720	nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
 721
 722	ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
 723	if (ret) {
 724		dev_err(&oct->pci_dev->dev,
 725			"Failed to configure gpio value, ret=%d\n", ret);
 726		return -EINVAL;
 727	}
 728
 729	return 0;
 730}
 731
 732static int octnet_id_active(struct net_device *netdev, int val)
 733{
 734	struct lio *lio = GET_LIO(netdev);
 735	struct octeon_device *oct = lio->oct_dev;
 736	struct octnic_ctrl_pkt nctrl;
 737	int ret = 0;
 738
 739	memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
 740
 741	nctrl.ncmd.u64 = 0;
 742	nctrl.ncmd.s.cmd = OCTNET_CMD_ID_ACTIVE;
 743	nctrl.ncmd.s.param1 = val;
 744	nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
 745	nctrl.netpndev = (u64)netdev;
 746	nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
 747
 748	ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
 749	if (ret) {
 750		dev_err(&oct->pci_dev->dev,
 751			"Failed to configure gpio value, ret=%d\n", ret);
 752		return -EINVAL;
 753	}
 754
 755	return 0;
 756}
 757
 758/* This routine provides PHY access routines for
 759 * mdio  clause45 .
 760 */
 761static int
 762octnet_mdio45_access(struct lio *lio, int op, int loc, int *value)
 763{
 764	struct octeon_device *oct_dev = lio->oct_dev;
 765	struct octeon_soft_command *sc;
 766	struct oct_mdio_cmd_resp *mdio_cmd_rsp;
 767	struct oct_mdio_cmd *mdio_cmd;
 768	int retval = 0;
 769
 770	sc = (struct octeon_soft_command *)
 771		octeon_alloc_soft_command(oct_dev,
 772					  sizeof(struct oct_mdio_cmd),
 773					  sizeof(struct oct_mdio_cmd_resp), 0);
 774
 775	if (!sc)
 776		return -ENOMEM;
 777
 778	mdio_cmd_rsp = (struct oct_mdio_cmd_resp *)sc->virtrptr;
 779	mdio_cmd = (struct oct_mdio_cmd *)sc->virtdptr;
 780
 781	mdio_cmd->op = op;
 782	mdio_cmd->mdio_addr = loc;
 783	if (op)
 784		mdio_cmd->value1 = *value;
 785	octeon_swap_8B_data((u64 *)mdio_cmd, sizeof(struct oct_mdio_cmd) / 8);
 786
 787	sc->iq_no = lio->linfo.txpciq[0].s.q_no;
 788
 789	octeon_prepare_soft_command(oct_dev, sc, OPCODE_NIC, OPCODE_NIC_MDIO45,
 790				    0, 0, 0);
 791
 792	init_completion(&sc->complete);
 793	sc->sc_status = OCTEON_REQUEST_PENDING;
 794
 795	retval = octeon_send_soft_command(oct_dev, sc);
 796	if (retval == IQ_SEND_FAILED) {
 797		dev_err(&oct_dev->pci_dev->dev,
 798			"octnet_mdio45_access instruction failed status: %x\n",
 799			retval);
 800		octeon_free_soft_command(oct_dev, sc);
 801		return -EBUSY;
 802	} else {
 803		/* Sleep on a wait queue till the cond flag indicates that the
 804		 * response arrived
 805		 */
 806		retval = wait_for_sc_completion_timeout(oct_dev, sc, 0);
 807		if (retval)
 808			return retval;
 809
 810		retval = mdio_cmd_rsp->status;
 811		if (retval) {
 812			dev_err(&oct_dev->pci_dev->dev,
 813				"octnet mdio45 access failed: %x\n", retval);
 814			WRITE_ONCE(sc->caller_is_done, true);
 815			return -EBUSY;
 816		}
 817
 818		octeon_swap_8B_data((u64 *)(&mdio_cmd_rsp->resp),
 819				    sizeof(struct oct_mdio_cmd) / 8);
 820
 821		if (!op)
 822			*value = mdio_cmd_rsp->resp.value1;
 823
 824		WRITE_ONCE(sc->caller_is_done, true);
 825	}
 826
 827	return retval;
 828}
 829
 830static int lio_set_phys_id(struct net_device *netdev,
 831			   enum ethtool_phys_id_state state)
 832{
 833	struct lio *lio = GET_LIO(netdev);
 834	struct octeon_device *oct = lio->oct_dev;
 835	struct oct_link_info *linfo;
 836	int value, ret;
 837	u32 cur_ver;
 838
 839	linfo = &lio->linfo;
 840	cur_ver = OCT_FW_VER(oct->fw_info.ver.maj,
 841			     oct->fw_info.ver.min,
 842			     oct->fw_info.ver.rev);
 843
 844	switch (state) {
 845	case ETHTOOL_ID_ACTIVE:
 846		if (oct->chip_id == OCTEON_CN66XX) {
 847			octnet_gpio_access(netdev, VITESSE_PHY_GPIO_CFG,
 848					   VITESSE_PHY_GPIO_DRIVEON);
 849			return 2;
 850
 851		} else if (oct->chip_id == OCTEON_CN68XX) {
 852			/* Save the current LED settings */
 853			ret = octnet_mdio45_access(lio, 0,
 854						   LIO68XX_LED_BEACON_ADDR,
 855						   &lio->phy_beacon_val);
 856			if (ret)
 857				return ret;
 858
 859			ret = octnet_mdio45_access(lio, 0,
 860						   LIO68XX_LED_CTRL_ADDR,
 861						   &lio->led_ctrl_val);
 862			if (ret)
 863				return ret;
 864
 865			/* Configure Beacon values */
 866			value = LIO68XX_LED_BEACON_CFGON;
 867			ret = octnet_mdio45_access(lio, 1,
 868						   LIO68XX_LED_BEACON_ADDR,
 869						   &value);
 870			if (ret)
 871				return ret;
 872
 873			value = LIO68XX_LED_CTRL_CFGON;
 874			ret = octnet_mdio45_access(lio, 1,
 875						   LIO68XX_LED_CTRL_ADDR,
 876						   &value);
 877			if (ret)
 878				return ret;
 879		} else if (oct->chip_id == OCTEON_CN23XX_PF_VID) {
 880			octnet_id_active(netdev, LED_IDENTIFICATION_ON);
 881			if (linfo->link.s.phy_type == LIO_PHY_PORT_TP &&
 882			    cur_ver > OCT_FW_VER(1, 7, 2))
 883				return 2;
 884			else
 885				return 0;
 886		} else {
 887			return -EINVAL;
 888		}
 889		break;
 890
 891	case ETHTOOL_ID_ON:
 892		if (oct->chip_id == OCTEON_CN23XX_PF_VID &&
 893		    linfo->link.s.phy_type == LIO_PHY_PORT_TP &&
 894		    cur_ver > OCT_FW_VER(1, 7, 2))
 895			octnet_id_active(netdev, LED_IDENTIFICATION_ON);
 896		else if (oct->chip_id == OCTEON_CN66XX)
 897			octnet_gpio_access(netdev, VITESSE_PHY_GPIO_CFG,
 898					   VITESSE_PHY_GPIO_HIGH);
 899		else
 900			return -EINVAL;
 901
 902		break;
 903
 904	case ETHTOOL_ID_OFF:
 905		if (oct->chip_id == OCTEON_CN23XX_PF_VID &&
 906		    linfo->link.s.phy_type == LIO_PHY_PORT_TP &&
 907		    cur_ver > OCT_FW_VER(1, 7, 2))
 908			octnet_id_active(netdev, LED_IDENTIFICATION_OFF);
 909		else if (oct->chip_id == OCTEON_CN66XX)
 910			octnet_gpio_access(netdev, VITESSE_PHY_GPIO_CFG,
 911					   VITESSE_PHY_GPIO_LOW);
 912		else
 913			return -EINVAL;
 914
 915		break;
 916
 917	case ETHTOOL_ID_INACTIVE:
 918		if (oct->chip_id == OCTEON_CN66XX) {
 919			octnet_gpio_access(netdev, VITESSE_PHY_GPIO_CFG,
 920					   VITESSE_PHY_GPIO_DRIVEOFF);
 921		} else if (oct->chip_id == OCTEON_CN68XX) {
 922			/* Restore LED settings */
 923			ret = octnet_mdio45_access(lio, 1,
 924						   LIO68XX_LED_CTRL_ADDR,
 925						   &lio->led_ctrl_val);
 926			if (ret)
 927				return ret;
 928
 929			ret = octnet_mdio45_access(lio, 1,
 930						   LIO68XX_LED_BEACON_ADDR,
 931						   &lio->phy_beacon_val);
 932			if (ret)
 933				return ret;
 934		} else if (oct->chip_id == OCTEON_CN23XX_PF_VID) {
 935			octnet_id_active(netdev, LED_IDENTIFICATION_OFF);
 936
 937			return 0;
 938		} else {
 939			return -EINVAL;
 940		}
 941		break;
 942
 943	default:
 944		return -EINVAL;
 945	}
 946
 947	return 0;
 948}
 949
 950static void
 951lio_ethtool_get_ringparam(struct net_device *netdev,
 952			  struct ethtool_ringparam *ering,
 953			  struct kernel_ethtool_ringparam *kernel_ering,
 954			  struct netlink_ext_ack *extack)
 955{
 956	struct lio *lio = GET_LIO(netdev);
 957	struct octeon_device *oct = lio->oct_dev;
 958	u32 tx_max_pending = 0, rx_max_pending = 0, tx_pending = 0,
 959	    rx_pending = 0;
 960
 961	if (ifstate_check(lio, LIO_IFSTATE_RESETTING))
 962		return;
 963
 964	if (OCTEON_CN6XXX(oct)) {
 965		struct octeon_config *conf6x = CHIP_CONF(oct, cn6xxx);
 966
 967		tx_max_pending = CN6XXX_MAX_IQ_DESCRIPTORS;
 968		rx_max_pending = CN6XXX_MAX_OQ_DESCRIPTORS;
 969		rx_pending = CFG_GET_NUM_RX_DESCS_NIC_IF(conf6x, lio->ifidx);
 970		tx_pending = CFG_GET_NUM_TX_DESCS_NIC_IF(conf6x, lio->ifidx);
 971	} else if (OCTEON_CN23XX_PF(oct) || OCTEON_CN23XX_VF(oct)) {
 972		tx_max_pending = CN23XX_MAX_IQ_DESCRIPTORS;
 973		rx_max_pending = CN23XX_MAX_OQ_DESCRIPTORS;
 974		rx_pending = oct->droq[0]->max_count;
 975		tx_pending = oct->instr_queue[0]->max_count;
 976	}
 977
 978	ering->tx_pending = tx_pending;
 979	ering->tx_max_pending = tx_max_pending;
 980	ering->rx_pending = rx_pending;
 981	ering->rx_max_pending = rx_max_pending;
 982	ering->rx_mini_pending = 0;
 983	ering->rx_jumbo_pending = 0;
 984	ering->rx_mini_max_pending = 0;
 985	ering->rx_jumbo_max_pending = 0;
 986}
 987
 988static int lio_23xx_reconfigure_queue_count(struct lio *lio)
 989{
 990	struct octeon_device *oct = lio->oct_dev;
 991	u32 resp_size, data_size;
 992	struct liquidio_if_cfg_resp *resp;
 993	struct octeon_soft_command *sc;
 994	union oct_nic_if_cfg if_cfg;
 995	struct lio_version *vdata;
 996	u32 ifidx_or_pfnum;
 997	int retval;
 998	int j;
 999
1000	resp_size = sizeof(struct liquidio_if_cfg_resp);
1001	data_size = sizeof(struct lio_version);
1002	sc = (struct octeon_soft_command *)
1003		octeon_alloc_soft_command(oct, data_size,
1004					  resp_size, 0);
1005	if (!sc) {
1006		dev_err(&oct->pci_dev->dev, "%s: Failed to allocate soft command\n",
1007			__func__);
1008		return -1;
1009	}
1010
1011	resp = (struct liquidio_if_cfg_resp *)sc->virtrptr;
1012	vdata = (struct lio_version *)sc->virtdptr;
1013
1014	vdata->major = (__force u16)cpu_to_be16(LIQUIDIO_BASE_MAJOR_VERSION);
1015	vdata->minor = (__force u16)cpu_to_be16(LIQUIDIO_BASE_MINOR_VERSION);
1016	vdata->micro = (__force u16)cpu_to_be16(LIQUIDIO_BASE_MICRO_VERSION);
1017
1018	ifidx_or_pfnum = oct->pf_num;
1019
1020	if_cfg.u64 = 0;
1021	if_cfg.s.num_iqueues = oct->sriov_info.num_pf_rings;
1022	if_cfg.s.num_oqueues = oct->sriov_info.num_pf_rings;
1023	if_cfg.s.base_queue = oct->sriov_info.pf_srn;
1024	if_cfg.s.gmx_port_id = oct->pf_num;
1025
1026	sc->iq_no = 0;
1027	octeon_prepare_soft_command(oct, sc, OPCODE_NIC,
1028				    OPCODE_NIC_QCOUNT_UPDATE, 0,
1029				    if_cfg.u64, 0);
1030
1031	init_completion(&sc->complete);
1032	sc->sc_status = OCTEON_REQUEST_PENDING;
1033
1034	retval = octeon_send_soft_command(oct, sc);
1035	if (retval == IQ_SEND_FAILED) {
1036		dev_err(&oct->pci_dev->dev,
1037			"Sending iq/oq config failed status: %x\n",
1038			retval);
1039		octeon_free_soft_command(oct, sc);
1040		return -EIO;
1041	}
1042
1043	retval = wait_for_sc_completion_timeout(oct, sc, 0);
1044	if (retval)
1045		return retval;
1046
1047	retval = resp->status;
1048	if (retval) {
1049		dev_err(&oct->pci_dev->dev,
1050			"iq/oq config failed: %x\n", retval);
1051		WRITE_ONCE(sc->caller_is_done, true);
1052		return -1;
1053	}
1054
1055	octeon_swap_8B_data((u64 *)(&resp->cfg_info),
1056			    (sizeof(struct liquidio_if_cfg_info)) >> 3);
1057
1058	lio->ifidx = ifidx_or_pfnum;
1059	lio->linfo.num_rxpciq = hweight64(resp->cfg_info.iqmask);
1060	lio->linfo.num_txpciq = hweight64(resp->cfg_info.iqmask);
1061	for (j = 0; j < lio->linfo.num_rxpciq; j++) {
1062		lio->linfo.rxpciq[j].u64 =
1063			resp->cfg_info.linfo.rxpciq[j].u64;
1064	}
1065
1066	for (j = 0; j < lio->linfo.num_txpciq; j++) {
1067		lio->linfo.txpciq[j].u64 =
1068			resp->cfg_info.linfo.txpciq[j].u64;
1069	}
1070
1071	lio->linfo.hw_addr = resp->cfg_info.linfo.hw_addr;
1072	lio->linfo.gmxport = resp->cfg_info.linfo.gmxport;
1073	lio->linfo.link.u64 = resp->cfg_info.linfo.link.u64;
1074	lio->txq = lio->linfo.txpciq[0].s.q_no;
1075	lio->rxq = lio->linfo.rxpciq[0].s.q_no;
1076
1077	dev_info(&oct->pci_dev->dev, "Queue count updated to %d\n",
1078		 lio->linfo.num_rxpciq);
1079
1080	WRITE_ONCE(sc->caller_is_done, true);
1081
1082	return 0;
1083}
1084
1085static int lio_reset_queues(struct net_device *netdev, uint32_t num_qs)
1086{
1087	struct lio *lio = GET_LIO(netdev);
1088	struct octeon_device *oct = lio->oct_dev;
1089	int i, queue_count_update = 0;
1090	struct napi_struct *napi, *n;
1091	int ret;
1092
1093	schedule_timeout_uninterruptible(msecs_to_jiffies(100));
1094
1095	if (wait_for_pending_requests(oct))
1096		dev_err(&oct->pci_dev->dev, "There were pending requests\n");
1097
1098	if (lio_wait_for_instr_fetch(oct))
1099		dev_err(&oct->pci_dev->dev, "IQ had pending instructions\n");
1100
1101	if (octeon_set_io_queues_off(oct)) {
1102		dev_err(&oct->pci_dev->dev, "Setting io queues off failed\n");
1103		return -1;
1104	}
1105
1106	/* Disable the input and output queues now. No more packets will
1107	 * arrive from Octeon.
1108	 */
1109	oct->fn_list.disable_io_queues(oct);
1110	/* Delete NAPI */
1111	list_for_each_entry_safe(napi, n, &netdev->napi_list, dev_list)
1112		netif_napi_del(napi);
1113
1114	if (num_qs != oct->num_iqs) {
1115		ret = netif_set_real_num_rx_queues(netdev, num_qs);
1116		if (ret) {
1117			dev_err(&oct->pci_dev->dev,
1118				"Setting real number rx failed\n");
1119			return ret;
1120		}
1121
1122		ret = netif_set_real_num_tx_queues(netdev, num_qs);
1123		if (ret) {
1124			dev_err(&oct->pci_dev->dev,
1125				"Setting real number tx failed\n");
1126			return ret;
1127		}
1128
1129		/* The value of queue_count_update decides whether it is the
1130		 * queue count or the descriptor count that is being
1131		 * re-configured.
1132		 */
1133		queue_count_update = 1;
1134	}
1135
1136	/* Re-configuration of queues can happen in two scenarios, SRIOV enabled
1137	 * and SRIOV disabled. Few things like recreating queue zero, resetting
1138	 * glists and IRQs are required for both. For the latter, some more
1139	 * steps like updating sriov_info for the octeon device need to be done.
1140	 */
1141	if (queue_count_update) {
1142		cleanup_rx_oom_poll_fn(netdev);
1143
1144		lio_delete_glists(lio);
1145
1146		/* Delete mbox for PF which is SRIOV disabled because sriov_info
1147		 * will be now changed.
1148		 */
1149		if ((OCTEON_CN23XX_PF(oct)) && !oct->sriov_info.sriov_enabled)
1150			oct->fn_list.free_mbox(oct);
1151	}
1152
1153	for (i = 0; i < MAX_OCTEON_OUTPUT_QUEUES(oct); i++) {
1154		if (!(oct->io_qmask.oq & BIT_ULL(i)))
1155			continue;
1156		octeon_delete_droq(oct, i);
1157	}
1158
1159	for (i = 0; i < MAX_OCTEON_INSTR_QUEUES(oct); i++) {
1160		if (!(oct->io_qmask.iq & BIT_ULL(i)))
1161			continue;
1162		octeon_delete_instr_queue(oct, i);
1163	}
1164
1165	if (queue_count_update) {
1166		/* For PF re-configure sriov related information */
1167		if ((OCTEON_CN23XX_PF(oct)) &&
1168		    !oct->sriov_info.sriov_enabled) {
1169			oct->sriov_info.num_pf_rings = num_qs;
1170			if (cn23xx_sriov_config(oct)) {
1171				dev_err(&oct->pci_dev->dev,
1172					"Queue reset aborted: SRIOV config failed\n");
1173				return -1;
1174			}
1175
1176			num_qs = oct->sriov_info.num_pf_rings;
1177		}
1178	}
1179
1180	if (oct->fn_list.setup_device_regs(oct)) {
1181		dev_err(&oct->pci_dev->dev, "Failed to configure device registers\n");
1182		return -1;
1183	}
1184
1185	/* The following are needed in case of queue count re-configuration and
1186	 * not for descriptor count re-configuration.
1187	 */
1188	if (queue_count_update) {
1189		if (octeon_setup_instr_queues(oct))
1190			return -1;
1191
1192		if (octeon_setup_output_queues(oct))
1193			return -1;
1194
1195		/* Recreating mbox for PF that is SRIOV disabled */
1196		if (OCTEON_CN23XX_PF(oct) && !oct->sriov_info.sriov_enabled) {
1197			if (oct->fn_list.setup_mbox(oct)) {
1198				dev_err(&oct->pci_dev->dev, "Mailbox setup failed\n");
1199				return -1;
1200			}
1201		}
1202
1203		/* Deleting and recreating IRQs whether the interface is SRIOV
1204		 * enabled or disabled.
1205		 */
1206		if (lio_irq_reallocate_irqs(oct, num_qs)) {
1207			dev_err(&oct->pci_dev->dev, "IRQs could not be allocated\n");
1208			return -1;
1209		}
1210
1211		/* Enable the input and output queues for this Octeon device */
1212		if (oct->fn_list.enable_io_queues(oct)) {
1213			dev_err(&oct->pci_dev->dev, "Failed to enable input/output queues\n");
1214			return -1;
1215		}
1216
1217		for (i = 0; i < oct->num_oqs; i++)
1218			writel(oct->droq[i]->max_count,
1219			       oct->droq[i]->pkts_credit_reg);
1220
1221		/* Informing firmware about the new queue count. It is required
1222		 * for firmware to allocate more number of queues than those at
1223		 * load time.
1224		 */
1225		if (OCTEON_CN23XX_PF(oct) && !oct->sriov_info.sriov_enabled) {
1226			if (lio_23xx_reconfigure_queue_count(lio))
1227				return -1;
1228		}
1229	}
1230
1231	/* Once firmware is aware of the new value, queues can be recreated */
1232	if (liquidio_setup_io_queues(oct, 0, num_qs, num_qs)) {
1233		dev_err(&oct->pci_dev->dev, "I/O queues creation failed\n");
1234		return -1;
1235	}
1236
1237	if (queue_count_update) {
1238		if (lio_setup_glists(oct, lio, num_qs)) {
1239			dev_err(&oct->pci_dev->dev, "Gather list allocation failed\n");
1240			return -1;
1241		}
1242
1243		if (setup_rx_oom_poll_fn(netdev)) {
1244			dev_err(&oct->pci_dev->dev, "lio_setup_rx_oom_poll_fn failed\n");
1245			return 1;
1246		}
1247
1248		/* Send firmware the information about new number of queues
1249		 * if the interface is a VF or a PF that is SRIOV enabled.
1250		 */
1251		if (oct->sriov_info.sriov_enabled || OCTEON_CN23XX_VF(oct))
1252			if (lio_send_queue_count_update(netdev, num_qs))
1253				return -1;
1254	}
1255
1256	return 0;
1257}
1258
1259static int
1260lio_ethtool_set_ringparam(struct net_device *netdev,
1261			  struct ethtool_ringparam *ering,
1262			  struct kernel_ethtool_ringparam *kernel_ering,
1263			  struct netlink_ext_ack *extack)
1264{
1265	u32 rx_count, tx_count, rx_count_old, tx_count_old;
1266	struct lio *lio = GET_LIO(netdev);
1267	struct octeon_device *oct = lio->oct_dev;
1268	int stopped = 0;
1269
1270	if (!OCTEON_CN23XX_PF(oct) && !OCTEON_CN23XX_VF(oct))
1271		return -EINVAL;
1272
1273	if (ering->rx_mini_pending || ering->rx_jumbo_pending)
1274		return -EINVAL;
1275
1276	rx_count = clamp_t(u32, ering->rx_pending, CN23XX_MIN_OQ_DESCRIPTORS,
1277			   CN23XX_MAX_OQ_DESCRIPTORS);
1278	tx_count = clamp_t(u32, ering->tx_pending, CN23XX_MIN_IQ_DESCRIPTORS,
1279			   CN23XX_MAX_IQ_DESCRIPTORS);
1280
1281	rx_count_old = oct->droq[0]->max_count;
1282	tx_count_old = oct->instr_queue[0]->max_count;
1283
1284	if (rx_count == rx_count_old && tx_count == tx_count_old)
1285		return 0;
1286
1287	ifstate_set(lio, LIO_IFSTATE_RESETTING);
1288
1289	if (netif_running(netdev)) {
1290		netdev->netdev_ops->ndo_stop(netdev);
1291		stopped = 1;
1292	}
1293
1294	/* Change RX/TX DESCS  count */
1295	if (tx_count != tx_count_old)
1296		CFG_SET_NUM_TX_DESCS_NIC_IF(octeon_get_conf(oct), lio->ifidx,
1297					    tx_count);
1298	if (rx_count != rx_count_old)
1299		CFG_SET_NUM_RX_DESCS_NIC_IF(octeon_get_conf(oct), lio->ifidx,
1300					    rx_count);
1301
1302	if (lio_reset_queues(netdev, oct->num_iqs))
1303		goto err_lio_reset_queues;
1304
1305	if (stopped)
1306		netdev->netdev_ops->ndo_open(netdev);
1307
1308	ifstate_reset(lio, LIO_IFSTATE_RESETTING);
1309
1310	return 0;
1311
1312err_lio_reset_queues:
1313	if (tx_count != tx_count_old)
1314		CFG_SET_NUM_TX_DESCS_NIC_IF(octeon_get_conf(oct), lio->ifidx,
1315					    tx_count_old);
1316	if (rx_count != rx_count_old)
1317		CFG_SET_NUM_RX_DESCS_NIC_IF(octeon_get_conf(oct), lio->ifidx,
1318					    rx_count_old);
1319	return -EINVAL;
1320}
1321
1322static u32 lio_get_msglevel(struct net_device *netdev)
1323{
1324	struct lio *lio = GET_LIO(netdev);
1325
1326	return lio->msg_enable;
1327}
1328
1329static void lio_set_msglevel(struct net_device *netdev, u32 msglvl)
1330{
1331	struct lio *lio = GET_LIO(netdev);
1332
1333	if ((msglvl ^ lio->msg_enable) & NETIF_MSG_HW) {
1334		if (msglvl & NETIF_MSG_HW)
1335			liquidio_set_feature(netdev,
1336					     OCTNET_CMD_VERBOSE_ENABLE, 0);
1337		else
1338			liquidio_set_feature(netdev,
1339					     OCTNET_CMD_VERBOSE_DISABLE, 0);
1340	}
1341
1342	lio->msg_enable = msglvl;
1343}
1344
1345static void lio_vf_set_msglevel(struct net_device *netdev, u32 msglvl)
1346{
1347	struct lio *lio = GET_LIO(netdev);
1348
1349	lio->msg_enable = msglvl;
1350}
1351
1352static void
1353lio_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
1354{
1355	/* Notes: Not supporting any auto negotiation in these
1356	 * drivers. Just report pause frame support.
1357	 */
1358	struct lio *lio = GET_LIO(netdev);
1359	struct octeon_device *oct = lio->oct_dev;
1360
1361	pause->autoneg = 0;
1362
1363	pause->tx_pause = oct->tx_pause;
1364	pause->rx_pause = oct->rx_pause;
1365}
1366
1367static int
1368lio_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
1369{
1370	/* Notes: Not supporting any auto negotiation in these
1371	 * drivers.
1372	 */
1373	struct lio *lio = GET_LIO(netdev);
1374	struct octeon_device *oct = lio->oct_dev;
1375	struct octnic_ctrl_pkt nctrl;
1376	struct oct_link_info *linfo = &lio->linfo;
1377
1378	int ret = 0;
1379
1380	if (oct->chip_id != OCTEON_CN23XX_PF_VID)
1381		return -EINVAL;
1382
1383	if (linfo->link.s.duplex == 0) {
1384		/*no flow control for half duplex*/
1385		if (pause->rx_pause || pause->tx_pause)
1386			return -EINVAL;
1387	}
1388
1389	/*do not support autoneg of link flow control*/
1390	if (pause->autoneg == AUTONEG_ENABLE)
1391		return -EINVAL;
1392
1393	memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
1394
1395	nctrl.ncmd.u64 = 0;
1396	nctrl.ncmd.s.cmd = OCTNET_CMD_SET_FLOW_CTL;
1397	nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
1398	nctrl.netpndev = (u64)netdev;
1399	nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
1400
1401	if (pause->rx_pause) {
1402		/*enable rx pause*/
1403		nctrl.ncmd.s.param1 = 1;
1404	} else {
1405		/*disable rx pause*/
1406		nctrl.ncmd.s.param1 = 0;
1407	}
1408
1409	if (pause->tx_pause) {
1410		/*enable tx pause*/
1411		nctrl.ncmd.s.param2 = 1;
1412	} else {
1413		/*disable tx pause*/
1414		nctrl.ncmd.s.param2 = 0;
1415	}
1416
1417	ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
1418	if (ret) {
1419		dev_err(&oct->pci_dev->dev,
1420			"Failed to set pause parameter, ret=%d\n", ret);
1421		return -EINVAL;
1422	}
1423
1424	oct->rx_pause = pause->rx_pause;
1425	oct->tx_pause = pause->tx_pause;
1426
1427	return 0;
1428}
1429
1430static void
1431lio_get_ethtool_stats(struct net_device *netdev,
1432		      struct ethtool_stats *stats  __attribute__((unused)),
1433		      u64 *data)
1434{
1435	struct lio *lio = GET_LIO(netdev);
1436	struct octeon_device *oct_dev = lio->oct_dev;
1437	struct rtnl_link_stats64 lstats;
1438	int i = 0, j;
1439
1440	if (ifstate_check(lio, LIO_IFSTATE_RESETTING))
1441		return;
1442
1443	netdev->netdev_ops->ndo_get_stats64(netdev, &lstats);
1444	/*sum of oct->droq[oq_no]->stats->rx_pkts_received */
1445	data[i++] = lstats.rx_packets;
1446	/*sum of oct->instr_queue[iq_no]->stats.tx_done */
1447	data[i++] = lstats.tx_packets;
1448	/*sum of oct->droq[oq_no]->stats->rx_bytes_received */
1449	data[i++] = lstats.rx_bytes;
1450	/*sum of oct->instr_queue[iq_no]->stats.tx_tot_bytes */
1451	data[i++] = lstats.tx_bytes;
1452	data[i++] = lstats.rx_errors +
1453			oct_dev->link_stats.fromwire.fcs_err +
1454			oct_dev->link_stats.fromwire.jabber_err +
1455			oct_dev->link_stats.fromwire.l2_err +
1456			oct_dev->link_stats.fromwire.frame_err;
1457	data[i++] = lstats.tx_errors;
1458	/*sum of oct->droq[oq_no]->stats->rx_dropped +
1459	 *oct->droq[oq_no]->stats->dropped_nodispatch +
1460	 *oct->droq[oq_no]->stats->dropped_toomany +
1461	 *oct->droq[oq_no]->stats->dropped_nomem
1462	 */
1463	data[i++] = lstats.rx_dropped +
1464			oct_dev->link_stats.fromwire.fifo_err +
1465			oct_dev->link_stats.fromwire.dmac_drop +
1466			oct_dev->link_stats.fromwire.red_drops +
1467			oct_dev->link_stats.fromwire.fw_err_pko +
1468			oct_dev->link_stats.fromwire.fw_err_link +
1469			oct_dev->link_stats.fromwire.fw_err_drop;
1470	/*sum of oct->instr_queue[iq_no]->stats.tx_dropped */
1471	data[i++] = lstats.tx_dropped +
1472			oct_dev->link_stats.fromhost.max_collision_fail +
1473			oct_dev->link_stats.fromhost.max_deferral_fail +
1474			oct_dev->link_stats.fromhost.total_collisions +
1475			oct_dev->link_stats.fromhost.fw_err_pko +
1476			oct_dev->link_stats.fromhost.fw_err_link +
1477			oct_dev->link_stats.fromhost.fw_err_drop +
1478			oct_dev->link_stats.fromhost.fw_err_pki;
1479
1480	/* firmware tx stats */
1481	/*per_core_stats[cvmx_get_core_num()].link_stats[mdata->from_ifidx].
1482	 *fromhost.fw_total_sent
1483	 */
1484	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_total_sent);
1485	/*per_core_stats[i].link_stats[port].fromwire.fw_total_fwd */
1486	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_total_fwd);
1487	/*per_core_stats[j].link_stats[i].fromhost.fw_err_pko */
1488	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_err_pko);
1489	/*per_core_stats[j].link_stats[i].fromhost.fw_err_pki */
1490	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_err_pki);
1491	/*per_core_stats[j].link_stats[i].fromhost.fw_err_link */
1492	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_err_link);
1493	/*per_core_stats[cvmx_get_core_num()].link_stats[idx].fromhost.
1494	 *fw_err_drop
1495	 */
1496	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_err_drop);
1497
1498	/*per_core_stats[cvmx_get_core_num()].link_stats[idx].fromhost.fw_tso */
1499	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_tso);
1500	/*per_core_stats[cvmx_get_core_num()].link_stats[idx].fromhost.
1501	 *fw_tso_fwd
1502	 */
1503	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_tso_fwd);
1504	/*per_core_stats[cvmx_get_core_num()].link_stats[idx].fromhost.
1505	 *fw_err_tso
1506	 */
1507	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_err_tso);
1508	/*per_core_stats[cvmx_get_core_num()].link_stats[idx].fromhost.
1509	 *fw_tx_vxlan
1510	 */
1511	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_tx_vxlan);
1512
1513	/* Multicast packets sent by this port */
1514	data[i++] = oct_dev->link_stats.fromhost.fw_total_mcast_sent;
1515	data[i++] = oct_dev->link_stats.fromhost.fw_total_bcast_sent;
1516
1517	/* mac tx statistics */
1518	/*CVMX_BGXX_CMRX_TX_STAT5 */
1519	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.total_pkts_sent);
1520	/*CVMX_BGXX_CMRX_TX_STAT4 */
1521	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.total_bytes_sent);
1522	/*CVMX_BGXX_CMRX_TX_STAT15 */
1523	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.mcast_pkts_sent);
1524	/*CVMX_BGXX_CMRX_TX_STAT14 */
1525	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.bcast_pkts_sent);
1526	/*CVMX_BGXX_CMRX_TX_STAT17 */
1527	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.ctl_sent);
1528	/*CVMX_BGXX_CMRX_TX_STAT0 */
1529	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.total_collisions);
1530	/*CVMX_BGXX_CMRX_TX_STAT3 */
1531	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.one_collision_sent);
1532	/*CVMX_BGXX_CMRX_TX_STAT2 */
1533	data[i++] =
1534		CVM_CAST64(oct_dev->link_stats.fromhost.multi_collision_sent);
1535	/*CVMX_BGXX_CMRX_TX_STAT0 */
1536	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.max_collision_fail);
1537	/*CVMX_BGXX_CMRX_TX_STAT1 */
1538	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.max_deferral_fail);
1539	/*CVMX_BGXX_CMRX_TX_STAT16 */
1540	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fifo_err);
1541	/*CVMX_BGXX_CMRX_TX_STAT6 */
1542	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.runts);
1543
1544	/* RX firmware stats */
1545	/*per_core_stats[cvmx_get_core_num()].link_stats[ifidx].fromwire.
1546	 *fw_total_rcvd
1547	 */
1548	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_total_rcvd);
1549	/*per_core_stats[cvmx_get_core_num()].link_stats[ifidx].fromwire.
1550	 *fw_total_fwd
1551	 */
1552	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_total_fwd);
1553	/* Multicast packets received on this port */
1554	data[i++] = oct_dev->link_stats.fromwire.fw_total_mcast;
1555	data[i++] = oct_dev->link_stats.fromwire.fw_total_bcast;
1556	/*per_core_stats[core_id].link_stats[ifidx].fromwire.jabber_err */
1557	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.jabber_err);
1558	/*per_core_stats[core_id].link_stats[ifidx].fromwire.l2_err */
1559	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.l2_err);
1560	/*per_core_stats[core_id].link_stats[ifidx].fromwire.frame_err */
1561	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.frame_err);
1562	/*per_core_stats[cvmx_get_core_num()].link_stats[ifidx].fromwire.
1563	 *fw_err_pko
1564	 */
1565	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_err_pko);
1566	/*per_core_stats[j].link_stats[i].fromwire.fw_err_link */
1567	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_err_link);
1568	/*per_core_stats[cvmx_get_core_num()].link_stats[lro_ctx->ifidx].
1569	 *fromwire.fw_err_drop
1570	 */
1571	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_err_drop);
1572
1573	/*per_core_stats[cvmx_get_core_num()].link_stats[lro_ctx->ifidx].
1574	 *fromwire.fw_rx_vxlan
1575	 */
1576	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_rx_vxlan);
1577	/*per_core_stats[cvmx_get_core_num()].link_stats[lro_ctx->ifidx].
1578	 *fromwire.fw_rx_vxlan_err
1579	 */
1580	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_rx_vxlan_err);
1581
1582	/* LRO */
1583	/*per_core_stats[cvmx_get_core_num()].link_stats[ifidx].fromwire.
1584	 *fw_lro_pkts
1585	 */
1586	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_lro_pkts);
1587	/*per_core_stats[cvmx_get_core_num()].link_stats[ifidx].fromwire.
1588	 *fw_lro_octs
1589	 */
1590	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_lro_octs);
1591	/*per_core_stats[j].link_stats[i].fromwire.fw_total_lro */
1592	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_total_lro);
1593	/*per_core_stats[j].link_stats[i].fromwire.fw_lro_aborts */
1594	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_lro_aborts);
1595	/*per_core_stats[cvmx_get_core_num()].link_stats[ifidx].fromwire.
1596	 *fw_lro_aborts_port
1597	 */
1598	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_lro_aborts_port);
1599	/*per_core_stats[cvmx_get_core_num()].link_stats[ifidx].fromwire.
1600	 *fw_lro_aborts_seq
1601	 */
1602	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_lro_aborts_seq);
1603	/*per_core_stats[cvmx_get_core_num()].link_stats[ifidx].fromwire.
1604	 *fw_lro_aborts_tsval
1605	 */
1606	data[i++] =
1607		CVM_CAST64(oct_dev->link_stats.fromwire.fw_lro_aborts_tsval);
1608	/*per_core_stats[cvmx_get_core_num()].link_stats[ifidx].fromwire.
1609	 *fw_lro_aborts_timer
1610	 */
1611	/* intrmod: packet forward rate */
1612	data[i++] =
1613		CVM_CAST64(oct_dev->link_stats.fromwire.fw_lro_aborts_timer);
1614	/*per_core_stats[j].link_stats[i].fromwire.fw_lro_aborts */
1615	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fwd_rate);
1616
1617	/* mac: link-level stats */
1618	/*CVMX_BGXX_CMRX_RX_STAT0 */
1619	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.total_rcvd);
1620	/*CVMX_BGXX_CMRX_RX_STAT1 */
1621	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.bytes_rcvd);
1622	/*CVMX_PKI_STATX_STAT5 */
1623	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.total_bcst);
1624	/*CVMX_PKI_STATX_STAT5 */
1625	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.total_mcst);
1626	/*wqe->word2.err_code or wqe->word2.err_level */
1627	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.runts);
1628	/*CVMX_BGXX_CMRX_RX_STAT2 */
1629	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.ctl_rcvd);
1630	/*CVMX_BGXX_CMRX_RX_STAT6 */
1631	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fifo_err);
1632	/*CVMX_BGXX_CMRX_RX_STAT4 */
1633	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.dmac_drop);
1634	/*wqe->word2.err_code or wqe->word2.err_level */
1635	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fcs_err);
1636	/*lio->link_changes*/
1637	data[i++] = CVM_CAST64(lio->link_changes);
1638
1639	for (j = 0; j < MAX_OCTEON_INSTR_QUEUES(oct_dev); j++) {
1640		if (!(oct_dev->io_qmask.iq & BIT_ULL(j)))
1641			continue;
1642		/*packets to network port*/
1643		/*# of packets tx to network */
1644		data[i++] = CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_done);
1645		/*# of bytes tx to network */
1646		data[i++] =
1647			CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_tot_bytes);
1648		/*# of packets dropped */
1649		data[i++] =
1650			CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_dropped);
1651		/*# of tx fails due to queue full */
1652		data[i++] =
1653			CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_iq_busy);
1654		/*XXX gather entries sent */
1655		data[i++] =
1656			CVM_CAST64(oct_dev->instr_queue[j]->stats.sgentry_sent);
1657
1658		/*instruction to firmware: data and control */
1659		/*# of instructions to the queue */
1660		data[i++] =
1661			CVM_CAST64(oct_dev->instr_queue[j]->stats.instr_posted);
1662		/*# of instructions processed */
1663		data[i++] = CVM_CAST64(
1664				oct_dev->instr_queue[j]->stats.instr_processed);
1665		/*# of instructions could not be processed */
1666		data[i++] = CVM_CAST64(
1667				oct_dev->instr_queue[j]->stats.instr_dropped);
1668		/*bytes sent through the queue */
1669		data[i++] =
1670			CVM_CAST64(oct_dev->instr_queue[j]->stats.bytes_sent);
1671
1672		/*tso request*/
1673		data[i++] = CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_gso);
1674		/*vxlan request*/
1675		data[i++] = CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_vxlan);
1676		/*txq restart*/
1677		data[i++] =
1678			CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_restart);
1679	}
1680
1681	/* RX */
1682	for (j = 0; j < MAX_OCTEON_OUTPUT_QUEUES(oct_dev); j++) {
1683		if (!(oct_dev->io_qmask.oq & BIT_ULL(j)))
1684			continue;
1685
1686		/*packets send to TCP/IP network stack */
1687		/*# of packets to network stack */
1688		data[i++] =
1689			CVM_CAST64(oct_dev->droq[j]->stats.rx_pkts_received);
1690		/*# of bytes to network stack */
1691		data[i++] =
1692			CVM_CAST64(oct_dev->droq[j]->stats.rx_bytes_received);
1693		/*# of packets dropped */
1694		data[i++] = CVM_CAST64(oct_dev->droq[j]->stats.dropped_nomem +
1695				       oct_dev->droq[j]->stats.dropped_toomany +
1696				       oct_dev->droq[j]->stats.rx_dropped);
1697		data[i++] =
1698			CVM_CAST64(oct_dev->droq[j]->stats.dropped_nomem);
1699		data[i++] =
1700			CVM_CAST64(oct_dev->droq[j]->stats.dropped_toomany);
1701		data[i++] =
1702			CVM_CAST64(oct_dev->droq[j]->stats.rx_dropped);
1703
1704		/*control and data path*/
1705		data[i++] =
1706			CVM_CAST64(oct_dev->droq[j]->stats.pkts_received);
1707		data[i++] =
1708			CVM_CAST64(oct_dev->droq[j]->stats.bytes_received);
1709		data[i++] =
1710			CVM_CAST64(oct_dev->droq[j]->stats.dropped_nodispatch);
1711
1712		data[i++] =
1713			CVM_CAST64(oct_dev->droq[j]->stats.rx_vxlan);
1714		data[i++] =
1715			CVM_CAST64(oct_dev->droq[j]->stats.rx_alloc_failure);
1716	}
1717}
1718
1719static void lio_vf_get_ethtool_stats(struct net_device *netdev,
1720				     struct ethtool_stats *stats
1721				     __attribute__((unused)),
1722				     u64 *data)
1723{
1724	struct rtnl_link_stats64 lstats;
1725	struct lio *lio = GET_LIO(netdev);
1726	struct octeon_device *oct_dev = lio->oct_dev;
1727	int i = 0, j, vj;
1728
1729	if (ifstate_check(lio, LIO_IFSTATE_RESETTING))
1730		return;
1731
1732	netdev->netdev_ops->ndo_get_stats64(netdev, &lstats);
1733	/* sum of oct->droq[oq_no]->stats->rx_pkts_received */
1734	data[i++] = lstats.rx_packets;
1735	/* sum of oct->instr_queue[iq_no]->stats.tx_done */
1736	data[i++] = lstats.tx_packets;
1737	/* sum of oct->droq[oq_no]->stats->rx_bytes_received */
1738	data[i++] = lstats.rx_bytes;
1739	/* sum of oct->instr_queue[iq_no]->stats.tx_tot_bytes */
1740	data[i++] = lstats.tx_bytes;
1741	data[i++] = lstats.rx_errors;
1742	data[i++] = lstats.tx_errors;
1743	 /* sum of oct->droq[oq_no]->stats->rx_dropped +
1744	  * oct->droq[oq_no]->stats->dropped_nodispatch +
1745	  * oct->droq[oq_no]->stats->dropped_toomany +
1746	  * oct->droq[oq_no]->stats->dropped_nomem
1747	  */
1748	data[i++] = lstats.rx_dropped;
1749	/* sum of oct->instr_queue[iq_no]->stats.tx_dropped */
1750	data[i++] = lstats.tx_dropped +
1751		oct_dev->link_stats.fromhost.fw_err_drop;
1752
1753	data[i++] = oct_dev->link_stats.fromwire.fw_total_mcast;
1754	data[i++] = oct_dev->link_stats.fromhost.fw_total_mcast_sent;
1755	data[i++] = oct_dev->link_stats.fromwire.fw_total_bcast;
1756	data[i++] = oct_dev->link_stats.fromhost.fw_total_bcast_sent;
1757
1758	/* lio->link_changes */
1759	data[i++] = CVM_CAST64(lio->link_changes);
1760
1761	for (vj = 0; vj < oct_dev->num_iqs; vj++) {
1762		j = lio->linfo.txpciq[vj].s.q_no;
1763
1764		/* packets to network port */
1765		/* # of packets tx to network */
1766		data[i++] = CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_done);
1767		 /* # of bytes tx to network */
1768		data[i++] = CVM_CAST64(
1769				oct_dev->instr_queue[j]->stats.tx_tot_bytes);
1770		/* # of packets dropped */
1771		data[i++] = CVM_CAST64(
1772				oct_dev->instr_queue[j]->stats.tx_dropped);
1773		/* # of tx fails due to queue full */
1774		data[i++] = CVM_CAST64(
1775				oct_dev->instr_queue[j]->stats.tx_iq_busy);
1776		/* XXX gather entries sent */
1777		data[i++] = CVM_CAST64(
1778				oct_dev->instr_queue[j]->stats.sgentry_sent);
1779
1780		/* instruction to firmware: data and control */
1781		/* # of instructions to the queue */
1782		data[i++] = CVM_CAST64(
1783				oct_dev->instr_queue[j]->stats.instr_posted);
1784		/* # of instructions processed */
1785		data[i++] =
1786		    CVM_CAST64(oct_dev->instr_queue[j]->stats.instr_processed);
1787		/* # of instructions could not be processed */
1788		data[i++] =
1789		    CVM_CAST64(oct_dev->instr_queue[j]->stats.instr_dropped);
1790		/* bytes sent through the queue */
1791		data[i++] = CVM_CAST64(
1792				oct_dev->instr_queue[j]->stats.bytes_sent);
1793		/* tso request */
1794		data[i++] = CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_gso);
1795		/* vxlan request */
1796		data[i++] = CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_vxlan);
1797		/* txq restart */
1798		data[i++] = CVM_CAST64(
1799				oct_dev->instr_queue[j]->stats.tx_restart);
1800	}
1801
1802	/* RX */
1803	for (vj = 0; vj < oct_dev->num_oqs; vj++) {
1804		j = lio->linfo.rxpciq[vj].s.q_no;
1805
1806		/* packets send to TCP/IP network stack */
1807		/* # of packets to network stack */
1808		data[i++] = CVM_CAST64(
1809				oct_dev->droq[j]->stats.rx_pkts_received);
1810		/* # of bytes to network stack */
1811		data[i++] = CVM_CAST64(
1812				oct_dev->droq[j]->stats.rx_bytes_received);
1813		data[i++] = CVM_CAST64(oct_dev->droq[j]->stats.dropped_nomem +
1814				       oct_dev->droq[j]->stats.dropped_toomany +
1815				       oct_dev->droq[j]->stats.rx_dropped);
1816		data[i++] = CVM_CAST64(oct_dev->droq[j]->stats.dropped_nomem);
1817		data[i++] = CVM_CAST64(oct_dev->droq[j]->stats.dropped_toomany);
1818		data[i++] = CVM_CAST64(oct_dev->droq[j]->stats.rx_dropped);
1819
1820		/* control and data path */
1821		data[i++] = CVM_CAST64(oct_dev->droq[j]->stats.pkts_received);
1822		data[i++] = CVM_CAST64(oct_dev->droq[j]->stats.bytes_received);
1823		data[i++] =
1824			CVM_CAST64(oct_dev->droq[j]->stats.dropped_nodispatch);
1825
1826		data[i++] = CVM_CAST64(oct_dev->droq[j]->stats.rx_vxlan);
1827		data[i++] =
1828		    CVM_CAST64(oct_dev->droq[j]->stats.rx_alloc_failure);
1829	}
1830}
1831
1832static void lio_get_priv_flags_strings(struct lio *lio, u8 *data)
1833{
1834	struct octeon_device *oct_dev = lio->oct_dev;
1835	int i;
1836
1837	switch (oct_dev->chip_id) {
1838	case OCTEON_CN23XX_PF_VID:
1839	case OCTEON_CN23XX_VF_VID:
1840		for (i = 0; i < ARRAY_SIZE(oct_priv_flags_strings); i++) {
1841			sprintf(data, "%s", oct_priv_flags_strings[i]);
1842			data += ETH_GSTRING_LEN;
1843		}
1844		break;
1845	case OCTEON_CN68XX:
1846	case OCTEON_CN66XX:
1847		break;
1848	default:
1849		netif_info(lio, drv, lio->netdev, "Unknown Chip !!\n");
1850		break;
1851	}
1852}
1853
1854static void lio_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
1855{
1856	struct lio *lio = GET_LIO(netdev);
1857	struct octeon_device *oct_dev = lio->oct_dev;
1858	int num_iq_stats, num_oq_stats, i, j;
1859	int num_stats;
1860
1861	switch (stringset) {
1862	case ETH_SS_STATS:
1863		num_stats = ARRAY_SIZE(oct_stats_strings);
1864		for (j = 0; j < num_stats; j++) {
1865			sprintf(data, "%s", oct_stats_strings[j]);
1866			data += ETH_GSTRING_LEN;
1867		}
1868
1869		num_iq_stats = ARRAY_SIZE(oct_iq_stats_strings);
1870		for (i = 0; i < MAX_OCTEON_INSTR_QUEUES(oct_dev); i++) {
1871			if (!(oct_dev->io_qmask.iq & BIT_ULL(i)))
1872				continue;
1873			for (j = 0; j < num_iq_stats; j++) {
1874				sprintf(data, "tx-%d-%s", i,
1875					oct_iq_stats_strings[j]);
1876				data += ETH_GSTRING_LEN;
1877			}
1878		}
1879
1880		num_oq_stats = ARRAY_SIZE(oct_droq_stats_strings);
1881		for (i = 0; i < MAX_OCTEON_OUTPUT_QUEUES(oct_dev); i++) {
1882			if (!(oct_dev->io_qmask.oq & BIT_ULL(i)))
1883				continue;
1884			for (j = 0; j < num_oq_stats; j++) {
1885				sprintf(data, "rx-%d-%s", i,
1886					oct_droq_stats_strings[j]);
1887				data += ETH_GSTRING_LEN;
1888			}
1889		}
1890		break;
1891
1892	case ETH_SS_PRIV_FLAGS:
1893		lio_get_priv_flags_strings(lio, data);
1894		break;
1895	default:
1896		netif_info(lio, drv, lio->netdev, "Unknown Stringset !!\n");
1897		break;
1898	}
1899}
1900
1901static void lio_vf_get_strings(struct net_device *netdev, u32 stringset,
1902			       u8 *data)
1903{
1904	int num_iq_stats, num_oq_stats, i, j;
1905	struct lio *lio = GET_LIO(netdev);
1906	struct octeon_device *oct_dev = lio->oct_dev;
1907	int num_stats;
1908
1909	switch (stringset) {
1910	case ETH_SS_STATS:
1911		num_stats = ARRAY_SIZE(oct_vf_stats_strings);
1912		for (j = 0; j < num_stats; j++) {
1913			sprintf(data, "%s", oct_vf_stats_strings[j]);
1914			data += ETH_GSTRING_LEN;
1915		}
1916
1917		num_iq_stats = ARRAY_SIZE(oct_iq_stats_strings);
1918		for (i = 0; i < MAX_OCTEON_INSTR_QUEUES(oct_dev); i++) {
1919			if (!(oct_dev->io_qmask.iq & BIT_ULL(i)))
1920				continue;
1921			for (j = 0; j < num_iq_stats; j++) {
1922				sprintf(data, "tx-%d-%s", i,
1923					oct_iq_stats_strings[j]);
1924				data += ETH_GSTRING_LEN;
1925			}
1926		}
1927
1928		num_oq_stats = ARRAY_SIZE(oct_droq_stats_strings);
1929		for (i = 0; i < MAX_OCTEON_OUTPUT_QUEUES(oct_dev); i++) {
1930			if (!(oct_dev->io_qmask.oq & BIT_ULL(i)))
1931				continue;
1932			for (j = 0; j < num_oq_stats; j++) {
1933				sprintf(data, "rx-%d-%s", i,
1934					oct_droq_stats_strings[j]);
1935				data += ETH_GSTRING_LEN;
1936			}
1937		}
1938		break;
1939
1940	case ETH_SS_PRIV_FLAGS:
1941		lio_get_priv_flags_strings(lio, data);
1942		break;
1943	default:
1944		netif_info(lio, drv, lio->netdev, "Unknown Stringset !!\n");
1945		break;
1946	}
1947}
1948
1949static int lio_get_priv_flags_ss_count(struct lio *lio)
1950{
1951	struct octeon_device *oct_dev = lio->oct_dev;
1952
1953	switch (oct_dev->chip_id) {
1954	case OCTEON_CN23XX_PF_VID:
1955	case OCTEON_CN23XX_VF_VID:
1956		return ARRAY_SIZE(oct_priv_flags_strings);
1957	case OCTEON_CN68XX:
1958	case OCTEON_CN66XX:
1959		return -EOPNOTSUPP;
1960	default:
1961		netif_info(lio, drv, lio->netdev, "Unknown Chip !!\n");
1962		return -EOPNOTSUPP;
1963	}
1964}
1965
1966static int lio_get_sset_count(struct net_device *netdev, int sset)
1967{
1968	struct lio *lio = GET_LIO(netdev);
1969	struct octeon_device *oct_dev = lio->oct_dev;
1970
1971	switch (sset) {
1972	case ETH_SS_STATS:
1973		return (ARRAY_SIZE(oct_stats_strings) +
1974			ARRAY_SIZE(oct_iq_stats_strings) * oct_dev->num_iqs +
1975			ARRAY_SIZE(oct_droq_stats_strings) * oct_dev->num_oqs);
1976	case ETH_SS_PRIV_FLAGS:
1977		return lio_get_priv_flags_ss_count(lio);
1978	default:
1979		return -EOPNOTSUPP;
1980	}
1981}
1982
1983static int lio_vf_get_sset_count(struct net_device *netdev, int sset)
1984{
1985	struct lio *lio = GET_LIO(netdev);
1986	struct octeon_device *oct_dev = lio->oct_dev;
1987
1988	switch (sset) {
1989	case ETH_SS_STATS:
1990		return (ARRAY_SIZE(oct_vf_stats_strings) +
1991			ARRAY_SIZE(oct_iq_stats_strings) * oct_dev->num_iqs +
1992			ARRAY_SIZE(oct_droq_stats_strings) * oct_dev->num_oqs);
1993	case ETH_SS_PRIV_FLAGS:
1994		return lio_get_priv_flags_ss_count(lio);
1995	default:
1996		return -EOPNOTSUPP;
1997	}
1998}
1999
2000/*  get interrupt moderation parameters */
2001static int octnet_get_intrmod_cfg(struct lio *lio,
2002				  struct oct_intrmod_cfg *intr_cfg)
2003{
2004	struct octeon_soft_command *sc;
2005	struct oct_intrmod_resp *resp;
2006	int retval;
2007	struct octeon_device *oct_dev = lio->oct_dev;
2008
2009	/* Alloc soft command */
2010	sc = (struct octeon_soft_command *)
2011		octeon_alloc_soft_command(oct_dev,
2012					  0,
2013					  sizeof(struct oct_intrmod_resp), 0);
2014
2015	if (!sc)
2016		return -ENOMEM;
2017
2018	resp = (struct oct_intrmod_resp *)sc->virtrptr;
2019	memset(resp, 0, sizeof(struct oct_intrmod_resp));
2020
2021	sc->iq_no = lio->linfo.txpciq[0].s.q_no;
2022
2023	octeon_prepare_soft_command(oct_dev, sc, OPCODE_NIC,
2024				    OPCODE_NIC_INTRMOD_PARAMS, 0, 0, 0);
2025
2026	init_completion(&sc->complete);
2027	sc->sc_status = OCTEON_REQUEST_PENDING;
2028
2029	retval = octeon_send_soft_command(oct_dev, sc);
2030	if (retval == IQ_SEND_FAILED) {
2031		octeon_free_soft_command(oct_dev, sc);
2032		return -EINVAL;
2033	}
2034
2035	/* Sleep on a wait queue till the cond flag indicates that the
2036	 * response arrived or timed-out.
2037	 */
2038	retval = wait_for_sc_completion_timeout(oct_dev, sc, 0);
2039	if (retval)
2040		return -ENODEV;
2041
2042	if (resp->status) {
2043		dev_err(&oct_dev->pci_dev->dev,
2044			"Get interrupt moderation parameters failed\n");
2045		WRITE_ONCE(sc->caller_is_done, true);
2046		return -ENODEV;
2047	}
2048
2049	octeon_swap_8B_data((u64 *)&resp->intrmod,
2050			    (sizeof(struct oct_intrmod_cfg)) / 8);
2051	memcpy(intr_cfg, &resp->intrmod, sizeof(struct oct_intrmod_cfg));
2052	WRITE_ONCE(sc->caller_is_done, true);
2053
2054	return 0;
2055}
2056
2057/*  Configure interrupt moderation parameters */
2058static int octnet_set_intrmod_cfg(struct lio *lio,
2059				  struct oct_intrmod_cfg *intr_cfg)
2060{
2061	struct octeon_soft_command *sc;
2062	struct oct_intrmod_cfg *cfg;
2063	int retval;
2064	struct octeon_device *oct_dev = lio->oct_dev;
2065
2066	/* Alloc soft command */
2067	sc = (struct octeon_soft_command *)
2068		octeon_alloc_soft_command(oct_dev,
2069					  sizeof(struct oct_intrmod_cfg),
2070					  16, 0);
2071
2072	if (!sc)
2073		return -ENOMEM;
2074
2075	cfg = (struct oct_intrmod_cfg *)sc->virtdptr;
2076
2077	memcpy(cfg, intr_cfg, sizeof(struct oct_intrmod_cfg));
2078	octeon_swap_8B_data((u64 *)cfg, (sizeof(struct oct_intrmod_cfg)) / 8);
2079
2080	sc->iq_no = lio->linfo.txpciq[0].s.q_no;
2081
2082	octeon_prepare_soft_command(oct_dev, sc, OPCODE_NIC,
2083				    OPCODE_NIC_INTRMOD_CFG, 0, 0, 0);
2084
2085	init_completion(&sc->complete);
2086	sc->sc_status = OCTEON_REQUEST_PENDING;
2087
2088	retval = octeon_send_soft_command(oct_dev, sc);
2089	if (retval == IQ_SEND_FAILED) {
2090		octeon_free_soft_command(oct_dev, sc);
2091		return -EINVAL;
2092	}
2093
2094	/* Sleep on a wait queue till the cond flag indicates that the
2095	 * response arrived or timed-out.
2096	 */
2097	retval = wait_for_sc_completion_timeout(oct_dev, sc, 0);
2098	if (retval)
2099		return retval;
2100
2101	retval = sc->sc_status;
2102	if (retval == 0) {
2103		dev_info(&oct_dev->pci_dev->dev,
2104			 "Rx-Adaptive Interrupt moderation %s\n",
2105			 (intr_cfg->rx_enable) ?
2106			 "enabled" : "disabled");
2107		WRITE_ONCE(sc->caller_is_done, true);
2108		return 0;
2109	}
2110
2111	dev_err(&oct_dev->pci_dev->dev,
2112		"intrmod config failed. Status: %x\n", retval);
2113	WRITE_ONCE(sc->caller_is_done, true);
2114	return -ENODEV;
2115}
2116
2117static int lio_get_intr_coalesce(struct net_device *netdev,
2118				 struct ethtool_coalesce *intr_coal,
2119				 struct kernel_ethtool_coalesce *kernel_coal,
2120				 struct netlink_ext_ack *extack)
2121{
2122	struct lio *lio = GET_LIO(netdev);
2123	struct octeon_device *oct = lio->oct_dev;
2124	struct octeon_instr_queue *iq;
2125	struct oct_intrmod_cfg intrmod_cfg;
2126
2127	if (octnet_get_intrmod_cfg(lio, &intrmod_cfg))
2128		return -ENODEV;
2129
2130	switch (oct->chip_id) {
2131	case OCTEON_CN23XX_PF_VID:
2132	case OCTEON_CN23XX_VF_VID: {
2133		if (!intrmod_cfg.rx_enable) {
2134			intr_coal->rx_coalesce_usecs = oct->rx_coalesce_usecs;
2135			intr_coal->rx_max_coalesced_frames =
2136				oct->rx_max_coalesced_frames;
2137		}
2138		if (!intrmod_cfg.tx_enable)
2139			intr_coal->tx_max_coalesced_frames =
2140				oct->tx_max_coalesced_frames;
2141		break;
2142	}
2143	case OCTEON_CN68XX:
2144	case OCTEON_CN66XX: {
2145		struct octeon_cn6xxx *cn6xxx =
2146			(struct octeon_cn6xxx *)oct->chip;
2147
2148		if (!intrmod_cfg.rx_enable) {
2149			intr_coal->rx_coalesce_usecs =
2150				CFG_GET_OQ_INTR_TIME(cn6xxx->conf);
2151			intr_coal->rx_max_coalesced_frames =
2152				CFG_GET_OQ_INTR_PKT(cn6xxx->conf);
2153		}
2154		iq = oct->instr_queue[lio->linfo.txpciq[0].s.q_no];
2155		intr_coal->tx_max_coalesced_frames = iq->fill_threshold;
2156		break;
2157	}
2158	default:
2159		netif_info(lio, drv, lio->netdev, "Unknown Chip !!\n");
2160		return -EINVAL;
2161	}
2162	if (intrmod_cfg.rx_enable) {
2163		intr_coal->use_adaptive_rx_coalesce =
2164			intrmod_cfg.rx_enable;
2165		intr_coal->rate_sample_interval =
2166			intrmod_cfg.check_intrvl;
2167		intr_coal->pkt_rate_high =
2168			intrmod_cfg.maxpkt_ratethr;
2169		intr_coal->pkt_rate_low =
2170			intrmod_cfg.minpkt_ratethr;
2171		intr_coal->rx_max_coalesced_frames_high =
2172			intrmod_cfg.rx_maxcnt_trigger;
2173		intr_coal->rx_coalesce_usecs_high =
2174			intrmod_cfg.rx_maxtmr_trigger;
2175		intr_coal->rx_coalesce_usecs_low =
2176			intrmod_cfg.rx_mintmr_trigger;
2177		intr_coal->rx_max_coalesced_frames_low =
2178			intrmod_cfg.rx_mincnt_trigger;
2179	}
2180	if ((OCTEON_CN23XX_PF(oct) || OCTEON_CN23XX_VF(oct)) &&
2181	    (intrmod_cfg.tx_enable)) {
2182		intr_coal->use_adaptive_tx_coalesce =
2183			intrmod_cfg.tx_enable;
2184		intr_coal->tx_max_coalesced_frames_high =
2185			intrmod_cfg.tx_maxcnt_trigger;
2186		intr_coal->tx_max_coalesced_frames_low =
2187			intrmod_cfg.tx_mincnt_trigger;
2188	}
2189	return 0;
2190}
2191
2192/* Enable/Disable auto interrupt Moderation */
2193static int oct_cfg_adaptive_intr(struct lio *lio,
2194				 struct oct_intrmod_cfg *intrmod_cfg,
2195				 struct ethtool_coalesce *intr_coal)
2196{
2197	int ret = 0;
2198
2199	if (intrmod_cfg->rx_enable || intrmod_cfg->tx_enable) {
2200		intrmod_cfg->check_intrvl = intr_coal->rate_sample_interval;
2201		intrmod_cfg->maxpkt_ratethr = intr_coal->pkt_rate_high;
2202		intrmod_cfg->minpkt_ratethr = intr_coal->pkt_rate_low;
2203	}
2204	if (intrmod_cfg->rx_enable) {
2205		intrmod_cfg->rx_maxcnt_trigger =
2206			intr_coal->rx_max_coalesced_frames_high;
2207		intrmod_cfg->rx_maxtmr_trigger =
2208			intr_coal->rx_coalesce_usecs_high;
2209		intrmod_cfg->rx_mintmr_trigger =
2210			intr_coal->rx_coalesce_usecs_low;
2211		intrmod_cfg->rx_mincnt_trigger =
2212			intr_coal->rx_max_coalesced_frames_low;
2213	}
2214	if (intrmod_cfg->tx_enable) {
2215		intrmod_cfg->tx_maxcnt_trigger =
2216			intr_coal->tx_max_coalesced_frames_high;
2217		intrmod_cfg->tx_mincnt_trigger =
2218			intr_coal->tx_max_coalesced_frames_low;
2219	}
2220
2221	ret = octnet_set_intrmod_cfg(lio, intrmod_cfg);
2222
2223	return ret;
2224}
2225
2226static int
2227oct_cfg_rx_intrcnt(struct lio *lio,
2228		   struct oct_intrmod_cfg *intrmod,
2229		   struct ethtool_coalesce *intr_coal)
2230{
2231	struct octeon_device *oct = lio->oct_dev;
2232	u32 rx_max_coalesced_frames;
2233
2234	/* Config Cnt based interrupt values */
2235	switch (oct->chip_id) {
2236	case OCTEON_CN68XX:
2237	case OCTEON_CN66XX: {
2238		struct octeon_cn6xxx *cn6xxx =
2239			(struct octeon_cn6xxx *)oct->chip;
2240
2241		if (!intr_coal->rx_max_coalesced_frames)
2242			rx_max_coalesced_frames = CN6XXX_OQ_INTR_PKT;
2243		else
2244			rx_max_coalesced_frames =
2245				intr_coal->rx_max_coalesced_frames;
2246		octeon_write_csr(oct, CN6XXX_SLI_OQ_INT_LEVEL_PKTS,
2247				 rx_max_coalesced_frames);
2248		CFG_SET_OQ_INTR_PKT(cn6xxx->conf, rx_max_coalesced_frames);
2249		break;
2250	}
2251	case OCTEON_CN23XX_PF_VID: {
2252		int q_no;
2253
2254		if (!intr_coal->rx_max_coalesced_frames)
2255			rx_max_coalesced_frames = intrmod->rx_frames;
2256		else
2257			rx_max_coalesced_frames =
2258			    intr_coal->rx_max_coalesced_frames;
2259		for (q_no = 0; q_no < oct->num_oqs; q_no++) {
2260			q_no += oct->sriov_info.pf_srn;
2261			octeon_write_csr64(
2262			    oct, CN23XX_SLI_OQ_PKT_INT_LEVELS(q_no),
2263			    (octeon_read_csr64(
2264				 oct, CN23XX_SLI_OQ_PKT_INT_LEVELS(q_no)) &
2265			     (0x3fffff00000000UL)) |
2266				(rx_max_coalesced_frames - 1));
2267			/*consider setting resend bit*/
2268		}
2269		intrmod->rx_frames = rx_max_coalesced_frames;
2270		oct->rx_max_coalesced_frames = rx_max_coalesced_frames;
2271		break;
2272	}
2273	case OCTEON_CN23XX_VF_VID: {
2274		int q_no;
2275
2276		if (!intr_coal->rx_max_coalesced_frames)
2277			rx_max_coalesced_frames = intrmod->rx_frames;
2278		else
2279			rx_max_coalesced_frames =
2280			    intr_coal->rx_max_coalesced_frames;
2281		for (q_no = 0; q_no < oct->num_oqs; q_no++) {
2282			octeon_write_csr64(
2283			    oct, CN23XX_VF_SLI_OQ_PKT_INT_LEVELS(q_no),
2284			    (octeon_read_csr64(
2285				 oct, CN23XX_VF_SLI_OQ_PKT_INT_LEVELS(q_no)) &
2286			     (0x3fffff00000000UL)) |
2287				(rx_max_coalesced_frames - 1));
2288			/*consider writing to resend bit here*/
2289		}
2290		intrmod->rx_frames = rx_max_coalesced_frames;
2291		oct->rx_max_coalesced_frames = rx_max_coalesced_frames;
2292		break;
2293	}
2294	default:
2295		return -EINVAL;
2296	}
2297	return 0;
2298}
2299
2300static int oct_cfg_rx_intrtime(struct lio *lio,
2301			       struct oct_intrmod_cfg *intrmod,
2302			       struct ethtool_coalesce *intr_coal)
2303{
2304	struct octeon_device *oct = lio->oct_dev;
2305	u32 time_threshold, rx_coalesce_usecs;
2306
2307	/* Config Time based interrupt values */
2308	switch (oct->chip_id) {
2309	case OCTEON_CN68XX:
2310	case OCTEON_CN66XX: {
2311		struct octeon_cn6xxx *cn6xxx =
2312			(struct octeon_cn6xxx *)oct->chip;
2313		if (!intr_coal->rx_coalesce_usecs)
2314			rx_coalesce_usecs = CN6XXX_OQ_INTR_TIME;
2315		else
2316			rx_coalesce_usecs = intr_coal->rx_coalesce_usecs;
2317
2318		time_threshold = lio_cn6xxx_get_oq_ticks(oct,
2319							 rx_coalesce_usecs);
2320		octeon_write_csr(oct,
2321				 CN6XXX_SLI_OQ_INT_LEVEL_TIME,
2322				 time_threshold);
2323
2324		CFG_SET_OQ_INTR_TIME(cn6xxx->conf, rx_coalesce_usecs);
2325		break;
2326	}
2327	case OCTEON_CN23XX_PF_VID: {
2328		u64 time_threshold;
2329		int q_no;
2330
2331		if (!intr_coal->rx_coalesce_usecs)
2332			rx_coalesce_usecs = intrmod->rx_usecs;
2333		else
2334			rx_coalesce_usecs = intr_coal->rx_coalesce_usecs;
2335		time_threshold =
2336		    cn23xx_pf_get_oq_ticks(oct, (u32)rx_coalesce_usecs);
2337		for (q_no = 0; q_no < oct->num_oqs; q_no++) {
2338			q_no += oct->sriov_info.pf_srn;
2339			octeon_write_csr64(oct,
2340					   CN23XX_SLI_OQ_PKT_INT_LEVELS(q_no),
2341					   (intrmod->rx_frames |
2342					    ((u64)time_threshold << 32)));
2343			/*consider writing to resend bit here*/
2344		}
2345		intrmod->rx_usecs = rx_coalesce_usecs;
2346		oct->rx_coalesce_usecs = rx_coalesce_usecs;
2347		break;
2348	}
2349	case OCTEON_CN23XX_VF_VID: {
2350		u64 time_threshold;
2351		int q_no;
2352
2353		if (!intr_coal->rx_coalesce_usecs)
2354			rx_coalesce_usecs = intrmod->rx_usecs;
2355		else
2356			rx_coalesce_usecs = intr_coal->rx_coalesce_usecs;
2357
2358		time_threshold =
2359		    cn23xx_vf_get_oq_ticks(oct, (u32)rx_coalesce_usecs);
2360		for (q_no = 0; q_no < oct->num_oqs; q_no++) {
2361			octeon_write_csr64(
2362				oct, CN23XX_VF_SLI_OQ_PKT_INT_LEVELS(q_no),
2363				(intrmod->rx_frames |
2364				 ((u64)time_threshold << 32)));
2365			/*consider setting resend bit*/
2366		}
2367		intrmod->rx_usecs = rx_coalesce_usecs;
2368		oct->rx_coalesce_usecs = rx_coalesce_usecs;
2369		break;
2370	}
2371	default:
2372		return -EINVAL;
2373	}
2374
2375	return 0;
2376}
2377
2378static int
2379oct_cfg_tx_intrcnt(struct lio *lio,
2380		   struct oct_intrmod_cfg *intrmod,
2381		   struct ethtool_coalesce *intr_coal)
2382{
2383	struct octeon_device *oct = lio->oct_dev;
2384	u32 iq_intr_pkt;
2385	void __iomem *inst_cnt_reg;
2386	u64 val;
2387
2388	/* Config Cnt based interrupt values */
2389	switch (oct->chip_id) {
2390	case OCTEON_CN68XX:
2391	case OCTEON_CN66XX:
2392		break;
2393	case OCTEON_CN23XX_VF_VID:
2394	case OCTEON_CN23XX_PF_VID: {
2395		int q_no;
2396
2397		if (!intr_coal->tx_max_coalesced_frames)
2398			iq_intr_pkt = CN23XX_DEF_IQ_INTR_THRESHOLD &
2399				      CN23XX_PKT_IN_DONE_WMARK_MASK;
2400		else
2401			iq_intr_pkt = intr_coal->tx_max_coalesced_frames &
2402				      CN23XX_PKT_IN_DONE_WMARK_MASK;
2403		for (q_no = 0; q_no < oct->num_iqs; q_no++) {
2404			inst_cnt_reg = (oct->instr_queue[q_no])->inst_cnt_reg;
2405			val = readq(inst_cnt_reg);
2406			/*clear wmark and count.dont want to write count back*/
2407			val = (val & 0xFFFF000000000000ULL) |
2408			      ((u64)(iq_intr_pkt - 1)
2409			       << CN23XX_PKT_IN_DONE_WMARK_BIT_POS);
2410			writeq(val, inst_cnt_reg);
2411			/*consider setting resend bit*/
2412		}
2413		intrmod->tx_frames = iq_intr_pkt;
2414		oct->tx_max_coalesced_frames = iq_intr_pkt;
2415		break;
2416	}
2417	default:
2418		return -EINVAL;
2419	}
2420	return 0;
2421}
2422
2423static int lio_set_intr_coalesce(struct net_device *netdev,
2424				 struct ethtool_coalesce *intr_coal,
2425				 struct kernel_ethtool_coalesce *kernel_coal,
2426				 struct netlink_ext_ack *extack)
2427{
2428	struct lio *lio = GET_LIO(netdev);
2429	int ret;
2430	struct octeon_device *oct = lio->oct_dev;
2431	struct oct_intrmod_cfg intrmod = {0};
2432	u32 j, q_no;
2433	int db_max, db_min;
2434
2435	switch (oct->chip_id) {
2436	case OCTEON_CN68XX:
2437	case OCTEON_CN66XX:
2438		db_min = CN6XXX_DB_MIN;
2439		db_max = CN6XXX_DB_MAX;
2440		if ((intr_coal->tx_max_coalesced_frames >= db_min) &&
2441		    (intr_coal->tx_max_coalesced_frames <= db_max)) {
2442			for (j = 0; j < lio->linfo.num_txpciq; j++) {
2443				q_no = lio->linfo.txpciq[j].s.q_no;
2444				oct->instr_queue[q_no]->fill_threshold =
2445					intr_coal->tx_max_coalesced_frames;
2446			}
2447		} else {
2448			dev_err(&oct->pci_dev->dev,
2449				"LIQUIDIO: Invalid tx-frames:%d. Range is min:%d max:%d\n",
2450				intr_coal->tx_max_coalesced_frames,
2451				db_min, db_max);
2452			return -EINVAL;
2453		}
2454		break;
2455	case OCTEON_CN23XX_PF_VID:
2456	case OCTEON_CN23XX_VF_VID:
2457		break;
2458	default:
2459		return -EINVAL;
2460	}
2461
2462	intrmod.rx_enable = intr_coal->use_adaptive_rx_coalesce ? 1 : 0;
2463	intrmod.tx_enable = intr_coal->use_adaptive_tx_coalesce ? 1 : 0;
2464	intrmod.rx_frames = CFG_GET_OQ_INTR_PKT(octeon_get_conf(oct));
2465	intrmod.rx_usecs = CFG_GET_OQ_INTR_TIME(octeon_get_conf(oct));
2466	intrmod.tx_frames = CFG_GET_IQ_INTR_PKT(octeon_get_conf(oct));
2467
2468	ret = oct_cfg_adaptive_intr(lio, &intrmod, intr_coal);
2469
2470	if (!intr_coal->use_adaptive_rx_coalesce) {
2471		ret = oct_cfg_rx_intrtime(lio, &intrmod, intr_coal);
2472		if (ret)
2473			goto ret_intrmod;
2474
2475		ret = oct_cfg_rx_intrcnt(lio, &intrmod, intr_coal);
2476		if (ret)
2477			goto ret_intrmod;
2478	} else {
2479		oct->rx_coalesce_usecs =
2480			CFG_GET_OQ_INTR_TIME(octeon_get_conf(oct));
2481		oct->rx_max_coalesced_frames =
2482			CFG_GET_OQ_INTR_PKT(octeon_get_conf(oct));
2483	}
2484
2485	if (!intr_coal->use_adaptive_tx_coalesce) {
2486		ret = oct_cfg_tx_intrcnt(lio, &intrmod, intr_coal);
2487		if (ret)
2488			goto ret_intrmod;
2489	} else {
2490		oct->tx_max_coalesced_frames =
2491			CFG_GET_IQ_INTR_PKT(octeon_get_conf(oct));
2492	}
2493
2494	return 0;
2495ret_intrmod:
2496	return ret;
2497}
2498
2499#ifdef PTP_HARDWARE_TIMESTAMPING
2500static int lio_get_ts_info(struct net_device *netdev,
2501			   struct kernel_ethtool_ts_info *info)
2502{
2503	struct lio *lio = GET_LIO(netdev);
2504
2505	info->so_timestamping =
 
2506		SOF_TIMESTAMPING_TX_HARDWARE |
2507		SOF_TIMESTAMPING_RX_HARDWARE |
2508		SOF_TIMESTAMPING_RAW_HARDWARE |
2509		SOF_TIMESTAMPING_TX_SOFTWARE;
 
 
 
2510
2511	if (lio->ptp_clock)
2512		info->phc_index = ptp_clock_index(lio->ptp_clock);
 
 
2513
 
2514	info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
2515
2516	info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
2517			   (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
2518			   (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
2519			   (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT);
 
2520
2521	return 0;
2522}
2523#endif
2524
2525/* Return register dump len. */
2526static int lio_get_regs_len(struct net_device *dev)
2527{
2528	struct lio *lio = GET_LIO(dev);
2529	struct octeon_device *oct = lio->oct_dev;
2530
2531	switch (oct->chip_id) {
2532	case OCTEON_CN23XX_PF_VID:
2533		return OCT_ETHTOOL_REGDUMP_LEN_23XX;
2534	case OCTEON_CN23XX_VF_VID:
2535		return OCT_ETHTOOL_REGDUMP_LEN_23XX_VF;
2536	default:
2537		return OCT_ETHTOOL_REGDUMP_LEN;
2538	}
2539}
2540
2541static int cn23xx_read_csr_reg(char *s, struct octeon_device *oct)
2542{
2543	u32 reg;
2544	u8 pf_num = oct->pf_num;
2545	int len = 0;
2546	int i;
2547
2548	/* PCI  Window Registers */
2549
2550	len += sprintf(s + len, "\n\t Octeon CSR Registers\n\n");
2551
2552	/*0x29030 or 0x29040*/
2553	reg = CN23XX_SLI_PKT_MAC_RINFO64(oct->pcie_port, oct->pf_num);
2554	len += sprintf(s + len,
2555		       "\n[%08x] (SLI_PKT_MAC%d_PF%d_RINFO): %016llx\n",
2556		       reg, oct->pcie_port, oct->pf_num,
2557		       (u64)octeon_read_csr64(oct, reg));
2558
2559	/*0x27080 or 0x27090*/
2560	reg = CN23XX_SLI_MAC_PF_INT_ENB64(oct->pcie_port, oct->pf_num);
2561	len +=
2562	    sprintf(s + len, "\n[%08x] (SLI_MAC%d_PF%d_INT_ENB): %016llx\n",
2563		    reg, oct->pcie_port, oct->pf_num,
2564		    (u64)octeon_read_csr64(oct, reg));
2565
2566	/*0x27000 or 0x27010*/
2567	reg = CN23XX_SLI_MAC_PF_INT_SUM64(oct->pcie_port, oct->pf_num);
2568	len +=
2569	    sprintf(s + len, "\n[%08x] (SLI_MAC%d_PF%d_INT_SUM): %016llx\n",
2570		    reg, oct->pcie_port, oct->pf_num,
2571		    (u64)octeon_read_csr64(oct, reg));
2572
2573	/*0x29120*/
2574	reg = 0x29120;
2575	len += sprintf(s + len, "\n[%08x] (SLI_PKT_MEM_CTL): %016llx\n", reg,
2576		       (u64)octeon_read_csr64(oct, reg));
2577
2578	/*0x27300*/
2579	reg = 0x27300 + oct->pcie_port * CN23XX_MAC_INT_OFFSET +
2580	      (oct->pf_num) * CN23XX_PF_INT_OFFSET;
2581	len += sprintf(
2582	    s + len, "\n[%08x] (SLI_MAC%d_PF%d_PKT_VF_INT): %016llx\n", reg,
2583	    oct->pcie_port, oct->pf_num, (u64)octeon_read_csr64(oct, reg));
2584
2585	/*0x27200*/
2586	reg = 0x27200 + oct->pcie_port * CN23XX_MAC_INT_OFFSET +
2587	      (oct->pf_num) * CN23XX_PF_INT_OFFSET;
2588	len += sprintf(s + len,
2589		       "\n[%08x] (SLI_MAC%d_PF%d_PP_VF_INT): %016llx\n",
2590		       reg, oct->pcie_port, oct->pf_num,
2591		       (u64)octeon_read_csr64(oct, reg));
2592
2593	/*29130*/
2594	reg = CN23XX_SLI_PKT_CNT_INT;
2595	len += sprintf(s + len, "\n[%08x] (SLI_PKT_CNT_INT): %016llx\n", reg,
2596		       (u64)octeon_read_csr64(oct, reg));
2597
2598	/*0x29140*/
2599	reg = CN23XX_SLI_PKT_TIME_INT;
2600	len += sprintf(s + len, "\n[%08x] (SLI_PKT_TIME_INT): %016llx\n", reg,
2601		       (u64)octeon_read_csr64(oct, reg));
2602
2603	/*0x29160*/
2604	reg = 0x29160;
2605	len += sprintf(s + len, "\n[%08x] (SLI_PKT_INT): %016llx\n", reg,
2606		       (u64)octeon_read_csr64(oct, reg));
2607
2608	/*0x29180*/
2609	reg = CN23XX_SLI_OQ_WMARK;
2610	len += sprintf(s + len, "\n[%08x] (SLI_PKT_OUTPUT_WMARK): %016llx\n",
2611		       reg, (u64)octeon_read_csr64(oct, reg));
2612
2613	/*0x291E0*/
2614	reg = CN23XX_SLI_PKT_IOQ_RING_RST;
2615	len += sprintf(s + len, "\n[%08x] (SLI_PKT_RING_RST): %016llx\n", reg,
2616		       (u64)octeon_read_csr64(oct, reg));
2617
2618	/*0x29210*/
2619	reg = CN23XX_SLI_GBL_CONTROL;
2620	len += sprintf(s + len,
2621		       "\n[%08x] (SLI_PKT_GBL_CONTROL): %016llx\n", reg,
2622		       (u64)octeon_read_csr64(oct, reg));
2623
2624	/*0x29220*/
2625	reg = 0x29220;
2626	len += sprintf(s + len, "\n[%08x] (SLI_PKT_BIST_STATUS): %016llx\n",
2627		       reg, (u64)octeon_read_csr64(oct, reg));
2628
2629	/*PF only*/
2630	if (pf_num == 0) {
2631		/*0x29260*/
2632		reg = CN23XX_SLI_OUT_BP_EN_W1S;
2633		len += sprintf(s + len,
2634			       "\n[%08x] (SLI_PKT_OUT_BP_EN_W1S):  %016llx\n",
2635			       reg, (u64)octeon_read_csr64(oct, reg));
2636	} else if (pf_num == 1) {
2637		/*0x29270*/
2638		reg = CN23XX_SLI_OUT_BP_EN2_W1S;
2639		len += sprintf(s + len,
2640			       "\n[%08x] (SLI_PKT_OUT_BP_EN2_W1S): %016llx\n",
2641			       reg, (u64)octeon_read_csr64(oct, reg));
2642	}
2643
2644	for (i = 0; i < CN23XX_MAX_OUTPUT_QUEUES; i++) {
2645		reg = CN23XX_SLI_OQ_BUFF_INFO_SIZE(i);
2646		len +=
2647		    sprintf(s + len, "\n[%08x] (SLI_PKT%d_OUT_SIZE): %016llx\n",
2648			    reg, i, (u64)octeon_read_csr64(oct, reg));
2649	}
2650
2651	/*0x10040*/
2652	for (i = 0; i < CN23XX_MAX_INPUT_QUEUES; i++) {
2653		reg = CN23XX_SLI_IQ_INSTR_COUNT64(i);
2654		len += sprintf(s + len,
2655			       "\n[%08x] (SLI_PKT_IN_DONE%d_CNTS): %016llx\n",
2656			       reg, i, (u64)octeon_read_csr64(oct, reg));
2657	}
2658
2659	/*0x10080*/
2660	for (i = 0; i < CN23XX_MAX_OUTPUT_QUEUES; i++) {
2661		reg = CN23XX_SLI_OQ_PKTS_CREDIT(i);
2662		len += sprintf(s + len,
2663			       "\n[%08x] (SLI_PKT%d_SLIST_BAOFF_DBELL): %016llx\n",
2664			       reg, i, (u64)octeon_read_csr64(oct, reg));
2665	}
2666
2667	/*0x10090*/
2668	for (i = 0; i < CN23XX_MAX_OUTPUT_QUEUES; i++) {
2669		reg = CN23XX_SLI_OQ_SIZE(i);
2670		len += sprintf(
2671		    s + len, "\n[%08x] (SLI_PKT%d_SLIST_FIFO_RSIZE): %016llx\n",
2672		    reg, i, (u64)octeon_read_csr64(oct, reg));
2673	}
2674
2675	/*0x10050*/
2676	for (i = 0; i < CN23XX_MAX_OUTPUT_QUEUES; i++) {
2677		reg = CN23XX_SLI_OQ_PKT_CONTROL(i);
2678		len += sprintf(
2679			s + len,
2680			"\n[%08x] (SLI_PKT%d__OUTPUT_CONTROL): %016llx\n",
2681			reg, i, (u64)octeon_read_csr64(oct, reg));
2682	}
2683
2684	/*0x10070*/
2685	for (i = 0; i < CN23XX_MAX_OUTPUT_QUEUES; i++) {
2686		reg = CN23XX_SLI_OQ_BASE_ADDR64(i);
2687		len += sprintf(s + len,
2688			       "\n[%08x] (SLI_PKT%d_SLIST_BADDR): %016llx\n",
2689			       reg, i, (u64)octeon_read_csr64(oct, reg));
2690	}
2691
2692	/*0x100a0*/
2693	for (i = 0; i < CN23XX_MAX_OUTPUT_QUEUES; i++) {
2694		reg = CN23XX_SLI_OQ_PKT_INT_LEVELS(i);
2695		len += sprintf(s + len,
2696			       "\n[%08x] (SLI_PKT%d_INT_LEVELS): %016llx\n",
2697			       reg, i, (u64)octeon_read_csr64(oct, reg));
2698	}
2699
2700	/*0x100b0*/
2701	for (i = 0; i < CN23XX_MAX_OUTPUT_QUEUES; i++) {
2702		reg = CN23XX_SLI_OQ_PKTS_SENT(i);
2703		len += sprintf(s + len, "\n[%08x] (SLI_PKT%d_CNTS): %016llx\n",
2704			       reg, i, (u64)octeon_read_csr64(oct, reg));
2705	}
2706
2707	/*0x100c0*/
2708	for (i = 0; i < CN23XX_MAX_OUTPUT_QUEUES; i++) {
2709		reg = 0x100c0 + i * CN23XX_OQ_OFFSET;
2710		len += sprintf(s + len,
2711			       "\n[%08x] (SLI_PKT%d_ERROR_INFO): %016llx\n",
2712			       reg, i, (u64)octeon_read_csr64(oct, reg));
2713
2714		/*0x10000*/
2715		for (i = 0; i < CN23XX_MAX_INPUT_QUEUES; i++) {
2716			reg = CN23XX_SLI_IQ_PKT_CONTROL64(i);
2717			len += sprintf(
2718				s + len,
2719				"\n[%08x] (SLI_PKT%d_INPUT_CONTROL): %016llx\n",
2720				reg, i, (u64)octeon_read_csr64(oct, reg));
2721		}
2722
2723		/*0x10010*/
2724		for (i = 0; i < CN23XX_MAX_INPUT_QUEUES; i++) {
2725			reg = CN23XX_SLI_IQ_BASE_ADDR64(i);
2726			len += sprintf(
2727			    s + len,
2728			    "\n[%08x] (SLI_PKT%d_INSTR_BADDR): %016llx\n", reg,
2729			    i, (u64)octeon_read_csr64(oct, reg));
2730		}
2731
2732		/*0x10020*/
2733		for (i = 0; i < CN23XX_MAX_INPUT_QUEUES; i++) {
2734			reg = CN23XX_SLI_IQ_DOORBELL(i);
2735			len += sprintf(
2736			    s + len,
2737			    "\n[%08x] (SLI_PKT%d_INSTR_BAOFF_DBELL): %016llx\n",
2738			    reg, i, (u64)octeon_read_csr64(oct, reg));
2739		}
2740
2741		/*0x10030*/
2742		for (i = 0; i < CN23XX_MAX_INPUT_QUEUES; i++) {
2743			reg = CN23XX_SLI_IQ_SIZE(i);
2744			len += sprintf(
2745			    s + len,
2746			    "\n[%08x] (SLI_PKT%d_INSTR_FIFO_RSIZE): %016llx\n",
2747			    reg, i, (u64)octeon_read_csr64(oct, reg));
2748		}
2749
2750		/*0x10040*/
2751		for (i = 0; i < CN23XX_MAX_INPUT_QUEUES; i++)
2752			reg = CN23XX_SLI_IQ_INSTR_COUNT64(i);
2753		len += sprintf(s + len,
2754			       "\n[%08x] (SLI_PKT_IN_DONE%d_CNTS): %016llx\n",
2755			       reg, i, (u64)octeon_read_csr64(oct, reg));
2756	}
2757
2758	return len;
2759}
2760
2761static int cn23xx_vf_read_csr_reg(char *s, struct octeon_device *oct)
2762{
2763	int len = 0;
2764	u32 reg;
2765	int i;
2766
2767	/* PCI  Window Registers */
2768
2769	len += sprintf(s + len, "\n\t Octeon CSR Registers\n\n");
2770
2771	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2772		reg = CN23XX_VF_SLI_OQ_BUFF_INFO_SIZE(i);
2773		len += sprintf(s + len,
2774			       "\n[%08x] (SLI_PKT%d_OUT_SIZE): %016llx\n",
2775			       reg, i, (u64)octeon_read_csr64(oct, reg));
2776	}
2777
2778	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2779		reg = CN23XX_VF_SLI_IQ_INSTR_COUNT64(i);
2780		len += sprintf(s + len,
2781			       "\n[%08x] (SLI_PKT_IN_DONE%d_CNTS): %016llx\n",
2782			       reg, i, (u64)octeon_read_csr64(oct, reg));
2783	}
2784
2785	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2786		reg = CN23XX_VF_SLI_OQ_PKTS_CREDIT(i);
2787		len += sprintf(s + len,
2788			       "\n[%08x] (SLI_PKT%d_SLIST_BAOFF_DBELL): %016llx\n",
2789			       reg, i, (u64)octeon_read_csr64(oct, reg));
2790	}
2791
2792	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2793		reg = CN23XX_VF_SLI_OQ_SIZE(i);
2794		len += sprintf(s + len,
2795			       "\n[%08x] (SLI_PKT%d_SLIST_FIFO_RSIZE): %016llx\n",
2796			       reg, i, (u64)octeon_read_csr64(oct, reg));
2797	}
2798
2799	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2800		reg = CN23XX_VF_SLI_OQ_PKT_CONTROL(i);
2801		len += sprintf(s + len,
2802			       "\n[%08x] (SLI_PKT%d__OUTPUT_CONTROL): %016llx\n",
2803			       reg, i, (u64)octeon_read_csr64(oct, reg));
2804	}
2805
2806	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2807		reg = CN23XX_VF_SLI_OQ_BASE_ADDR64(i);
2808		len += sprintf(s + len,
2809			       "\n[%08x] (SLI_PKT%d_SLIST_BADDR): %016llx\n",
2810			       reg, i, (u64)octeon_read_csr64(oct, reg));
2811	}
2812
2813	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2814		reg = CN23XX_VF_SLI_OQ_PKT_INT_LEVELS(i);
2815		len += sprintf(s + len,
2816			       "\n[%08x] (SLI_PKT%d_INT_LEVELS): %016llx\n",
2817			       reg, i, (u64)octeon_read_csr64(oct, reg));
2818	}
2819
2820	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2821		reg = CN23XX_VF_SLI_OQ_PKTS_SENT(i);
2822		len += sprintf(s + len, "\n[%08x] (SLI_PKT%d_CNTS): %016llx\n",
2823			       reg, i, (u64)octeon_read_csr64(oct, reg));
2824	}
2825
2826	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2827		reg = 0x100c0 + i * CN23XX_VF_OQ_OFFSET;
2828		len += sprintf(s + len,
2829			       "\n[%08x] (SLI_PKT%d_ERROR_INFO): %016llx\n",
2830			       reg, i, (u64)octeon_read_csr64(oct, reg));
2831	}
2832
2833	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2834		reg = 0x100d0 + i * CN23XX_VF_IQ_OFFSET;
2835		len += sprintf(s + len,
2836			       "\n[%08x] (SLI_PKT%d_VF_INT_SUM): %016llx\n",
2837			       reg, i, (u64)octeon_read_csr64(oct, reg));
2838	}
2839
2840	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2841		reg = CN23XX_VF_SLI_IQ_PKT_CONTROL64(i);
2842		len += sprintf(s + len,
2843			       "\n[%08x] (SLI_PKT%d_INPUT_CONTROL): %016llx\n",
2844			       reg, i, (u64)octeon_read_csr64(oct, reg));
2845	}
2846
2847	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2848		reg = CN23XX_VF_SLI_IQ_BASE_ADDR64(i);
2849		len += sprintf(s + len,
2850			       "\n[%08x] (SLI_PKT%d_INSTR_BADDR): %016llx\n",
2851			       reg, i, (u64)octeon_read_csr64(oct, reg));
2852	}
2853
2854	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2855		reg = CN23XX_VF_SLI_IQ_DOORBELL(i);
2856		len += sprintf(s + len,
2857			       "\n[%08x] (SLI_PKT%d_INSTR_BAOFF_DBELL): %016llx\n",
2858			       reg, i, (u64)octeon_read_csr64(oct, reg));
2859	}
2860
2861	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2862		reg = CN23XX_VF_SLI_IQ_SIZE(i);
2863		len += sprintf(s + len,
2864			       "\n[%08x] (SLI_PKT%d_INSTR_FIFO_RSIZE): %016llx\n",
2865			       reg, i, (u64)octeon_read_csr64(oct, reg));
2866	}
2867
2868	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2869		reg = CN23XX_VF_SLI_IQ_INSTR_COUNT64(i);
2870		len += sprintf(s + len,
2871			       "\n[%08x] (SLI_PKT_IN_DONE%d_CNTS): %016llx\n",
2872			       reg, i, (u64)octeon_read_csr64(oct, reg));
2873	}
2874
2875	return len;
2876}
2877
2878static int cn6xxx_read_csr_reg(char *s, struct octeon_device *oct)
2879{
2880	u32 reg;
2881	int i, len = 0;
2882
2883	/* PCI  Window Registers */
2884
2885	len += sprintf(s + len, "\n\t Octeon CSR Registers\n\n");
2886	reg = CN6XXX_WIN_WR_ADDR_LO;
2887	len += sprintf(s + len, "\n[%02x] (WIN_WR_ADDR_LO): %08x\n",
2888		       CN6XXX_WIN_WR_ADDR_LO, octeon_read_csr(oct, reg));
2889	reg = CN6XXX_WIN_WR_ADDR_HI;
2890	len += sprintf(s + len, "[%02x] (WIN_WR_ADDR_HI): %08x\n",
2891		       CN6XXX_WIN_WR_ADDR_HI, octeon_read_csr(oct, reg));
2892	reg = CN6XXX_WIN_RD_ADDR_LO;
2893	len += sprintf(s + len, "[%02x] (WIN_RD_ADDR_LO): %08x\n",
2894		       CN6XXX_WIN_RD_ADDR_LO, octeon_read_csr(oct, reg));
2895	reg = CN6XXX_WIN_RD_ADDR_HI;
2896	len += sprintf(s + len, "[%02x] (WIN_RD_ADDR_HI): %08x\n",
2897		       CN6XXX_WIN_RD_ADDR_HI, octeon_read_csr(oct, reg));
2898	reg = CN6XXX_WIN_WR_DATA_LO;
2899	len += sprintf(s + len, "[%02x] (WIN_WR_DATA_LO): %08x\n",
2900		       CN6XXX_WIN_WR_DATA_LO, octeon_read_csr(oct, reg));
2901	reg = CN6XXX_WIN_WR_DATA_HI;
2902	len += sprintf(s + len, "[%02x] (WIN_WR_DATA_HI): %08x\n",
2903		       CN6XXX_WIN_WR_DATA_HI, octeon_read_csr(oct, reg));
2904	len += sprintf(s + len, "[%02x] (WIN_WR_MASK_REG): %08x\n",
2905		       CN6XXX_WIN_WR_MASK_REG,
2906		       octeon_read_csr(oct, CN6XXX_WIN_WR_MASK_REG));
2907
2908	/* PCI  Interrupt Register */
2909	len += sprintf(s + len, "\n[%x] (INT_ENABLE PORT 0): %08x\n",
2910		       CN6XXX_SLI_INT_ENB64_PORT0, octeon_read_csr(oct,
2911						CN6XXX_SLI_INT_ENB64_PORT0));
2912	len += sprintf(s + len, "\n[%x] (INT_ENABLE PORT 1): %08x\n",
2913		       CN6XXX_SLI_INT_ENB64_PORT1,
2914		       octeon_read_csr(oct, CN6XXX_SLI_INT_ENB64_PORT1));
2915	len += sprintf(s + len, "[%x] (INT_SUM): %08x\n", CN6XXX_SLI_INT_SUM64,
2916		       octeon_read_csr(oct, CN6XXX_SLI_INT_SUM64));
2917
2918	/* PCI  Output queue registers */
2919	for (i = 0; i < oct->num_oqs; i++) {
2920		reg = CN6XXX_SLI_OQ_PKTS_SENT(i);
2921		len += sprintf(s + len, "\n[%x] (PKTS_SENT_%d): %08x\n",
2922			       reg, i, octeon_read_csr(oct, reg));
2923		reg = CN6XXX_SLI_OQ_PKTS_CREDIT(i);
2924		len += sprintf(s + len, "[%x] (PKT_CREDITS_%d): %08x\n",
2925			       reg, i, octeon_read_csr(oct, reg));
2926	}
2927	reg = CN6XXX_SLI_OQ_INT_LEVEL_PKTS;
2928	len += sprintf(s + len, "\n[%x] (PKTS_SENT_INT_LEVEL): %08x\n",
2929		       reg, octeon_read_csr(oct, reg));
2930	reg = CN6XXX_SLI_OQ_INT_LEVEL_TIME;
2931	len += sprintf(s + len, "[%x] (PKTS_SENT_TIME): %08x\n",
2932		       reg, octeon_read_csr(oct, reg));
2933
2934	/* PCI  Input queue registers */
2935	for (i = 0; i <= 3; i++) {
2936		u32 reg;
2937
2938		reg = CN6XXX_SLI_IQ_DOORBELL(i);
2939		len += sprintf(s + len, "\n[%x] (INSTR_DOORBELL_%d): %08x\n",
2940			       reg, i, octeon_read_csr(oct, reg));
2941		reg = CN6XXX_SLI_IQ_INSTR_COUNT(i);
2942		len += sprintf(s + len, "[%x] (INSTR_COUNT_%d): %08x\n",
2943			       reg, i, octeon_read_csr(oct, reg));
2944	}
2945
2946	/* PCI  DMA registers */
2947
2948	len += sprintf(s + len, "\n[%x] (DMA_CNT_0): %08x\n",
2949		       CN6XXX_DMA_CNT(0),
2950		       octeon_read_csr(oct, CN6XXX_DMA_CNT(0)));
2951	reg = CN6XXX_DMA_PKT_INT_LEVEL(0);
2952	len += sprintf(s + len, "[%x] (DMA_INT_LEV_0): %08x\n",
2953		       CN6XXX_DMA_PKT_INT_LEVEL(0), octeon_read_csr(oct, reg));
2954	reg = CN6XXX_DMA_TIME_INT_LEVEL(0);
2955	len += sprintf(s + len, "[%x] (DMA_TIME_0): %08x\n",
2956		       CN6XXX_DMA_TIME_INT_LEVEL(0),
2957		       octeon_read_csr(oct, reg));
2958
2959	len += sprintf(s + len, "\n[%x] (DMA_CNT_1): %08x\n",
2960		       CN6XXX_DMA_CNT(1),
2961		       octeon_read_csr(oct, CN6XXX_DMA_CNT(1)));
2962	reg = CN6XXX_DMA_PKT_INT_LEVEL(1);
2963	len += sprintf(s + len, "[%x] (DMA_INT_LEV_1): %08x\n",
2964		       CN6XXX_DMA_PKT_INT_LEVEL(1),
2965		       octeon_read_csr(oct, reg));
2966	reg = CN6XXX_DMA_PKT_INT_LEVEL(1);
2967	len += sprintf(s + len, "[%x] (DMA_TIME_1): %08x\n",
2968		       CN6XXX_DMA_TIME_INT_LEVEL(1),
2969		       octeon_read_csr(oct, reg));
2970
2971	/* PCI  Index registers */
2972
2973	len += sprintf(s + len, "\n");
2974
2975	for (i = 0; i < 16; i++) {
2976		reg = lio_pci_readq(oct, CN6XXX_BAR1_REG(i, oct->pcie_port));
2977		len += sprintf(s + len, "[%llx] (BAR1_INDEX_%02d): %08x\n",
2978			       CN6XXX_BAR1_REG(i, oct->pcie_port), i, reg);
2979	}
2980
2981	return len;
2982}
2983
2984static int cn6xxx_read_config_reg(char *s, struct octeon_device *oct)
2985{
2986	u32 val;
2987	int i, len = 0;
2988
2989	/* PCI CONFIG Registers */
2990
2991	len += sprintf(s + len,
2992		       "\n\t Octeon Config space Registers\n\n");
2993
2994	for (i = 0; i <= 13; i++) {
2995		pci_read_config_dword(oct->pci_dev, (i * 4), &val);
2996		len += sprintf(s + len, "[0x%x] (Config[%d]): 0x%08x\n",
2997			       (i * 4), i, val);
2998	}
2999
3000	for (i = 30; i <= 34; i++) {
3001		pci_read_config_dword(oct->pci_dev, (i * 4), &val);
3002		len += sprintf(s + len, "[0x%x] (Config[%d]): 0x%08x\n",
3003			       (i * 4), i, val);
3004	}
3005
3006	return len;
3007}
3008
3009/*  Return register dump user app.  */
3010static void lio_get_regs(struct net_device *dev,
3011			 struct ethtool_regs *regs, void *regbuf)
3012{
3013	struct lio *lio = GET_LIO(dev);
3014	int len = 0;
3015	struct octeon_device *oct = lio->oct_dev;
3016
3017	regs->version = OCT_ETHTOOL_REGSVER;
3018
3019	switch (oct->chip_id) {
3020	case OCTEON_CN23XX_PF_VID:
3021		memset(regbuf, 0, OCT_ETHTOOL_REGDUMP_LEN_23XX);
3022		len += cn23xx_read_csr_reg(regbuf + len, oct);
3023		break;
3024	case OCTEON_CN23XX_VF_VID:
3025		memset(regbuf, 0, OCT_ETHTOOL_REGDUMP_LEN_23XX_VF);
3026		len += cn23xx_vf_read_csr_reg(regbuf + len, oct);
3027		break;
3028	case OCTEON_CN68XX:
3029	case OCTEON_CN66XX:
3030		memset(regbuf, 0, OCT_ETHTOOL_REGDUMP_LEN);
3031		len += cn6xxx_read_csr_reg(regbuf + len, oct);
3032		len += cn6xxx_read_config_reg(regbuf + len, oct);
3033		break;
3034	default:
3035		dev_err(&oct->pci_dev->dev, "%s Unknown chipid: %d\n",
3036			__func__, oct->chip_id);
3037	}
3038}
3039
3040static u32 lio_get_priv_flags(struct net_device *netdev)
3041{
3042	struct lio *lio = GET_LIO(netdev);
3043
3044	return lio->oct_dev->priv_flags;
3045}
3046
3047static int lio_set_priv_flags(struct net_device *netdev, u32 flags)
3048{
3049	struct lio *lio = GET_LIO(netdev);
3050	bool intr_by_tx_bytes = !!(flags & (0x1 << OCT_PRIV_FLAG_TX_BYTES));
3051
3052	lio_set_priv_flag(lio->oct_dev, OCT_PRIV_FLAG_TX_BYTES,
3053			  intr_by_tx_bytes);
3054	return 0;
3055}
3056
3057static int lio_get_fecparam(struct net_device *netdev,
3058			    struct ethtool_fecparam *fec)
3059{
3060	struct lio *lio = GET_LIO(netdev);
3061	struct octeon_device *oct = lio->oct_dev;
3062
3063	fec->active_fec = ETHTOOL_FEC_NONE;
3064	fec->fec = ETHTOOL_FEC_NONE;
3065
3066	if (oct->subsystem_id == OCTEON_CN2350_25GB_SUBSYS_ID ||
3067	    oct->subsystem_id == OCTEON_CN2360_25GB_SUBSYS_ID) {
3068		if (oct->no_speed_setting == 1)
3069			return 0;
3070
3071		liquidio_get_fec(lio);
3072		fec->fec = (ETHTOOL_FEC_RS | ETHTOOL_FEC_OFF);
3073		if (oct->props[lio->ifidx].fec == 1)
3074			fec->active_fec = ETHTOOL_FEC_RS;
3075		else
3076			fec->active_fec = ETHTOOL_FEC_OFF;
3077	}
3078
3079	return 0;
3080}
3081
3082static int lio_set_fecparam(struct net_device *netdev,
3083			    struct ethtool_fecparam *fec)
3084{
3085	struct lio *lio = GET_LIO(netdev);
3086	struct octeon_device *oct = lio->oct_dev;
3087
3088	if (oct->subsystem_id == OCTEON_CN2350_25GB_SUBSYS_ID ||
3089	    oct->subsystem_id == OCTEON_CN2360_25GB_SUBSYS_ID) {
3090		if (oct->no_speed_setting == 1)
3091			return -EOPNOTSUPP;
3092
3093		if (fec->fec & ETHTOOL_FEC_OFF)
3094			liquidio_set_fec(lio, 0);
3095		else if (fec->fec & ETHTOOL_FEC_RS)
3096			liquidio_set_fec(lio, 1);
3097		else
3098			return -EOPNOTSUPP;
3099	} else {
3100		return -EOPNOTSUPP;
3101	}
3102
3103	return 0;
3104}
3105
3106#define LIO_ETHTOOL_COALESCE	(ETHTOOL_COALESCE_RX_USECS |		\
3107				 ETHTOOL_COALESCE_MAX_FRAMES |		\
3108				 ETHTOOL_COALESCE_USE_ADAPTIVE |	\
3109				 ETHTOOL_COALESCE_RX_MAX_FRAMES_LOW |	\
3110				 ETHTOOL_COALESCE_TX_MAX_FRAMES_LOW |	\
3111				 ETHTOOL_COALESCE_RX_MAX_FRAMES_HIGH |	\
3112				 ETHTOOL_COALESCE_TX_MAX_FRAMES_HIGH |	\
3113				 ETHTOOL_COALESCE_PKT_RATE_RX_USECS)
3114
3115static const struct ethtool_ops lio_ethtool_ops = {
3116	.supported_coalesce_params = LIO_ETHTOOL_COALESCE,
3117	.get_link_ksettings	= lio_get_link_ksettings,
3118	.set_link_ksettings	= lio_set_link_ksettings,
3119	.get_fecparam		= lio_get_fecparam,
3120	.set_fecparam		= lio_set_fecparam,
3121	.get_link		= ethtool_op_get_link,
3122	.get_drvinfo		= lio_get_drvinfo,
3123	.get_ringparam		= lio_ethtool_get_ringparam,
3124	.set_ringparam		= lio_ethtool_set_ringparam,
3125	.get_channels		= lio_ethtool_get_channels,
3126	.set_channels		= lio_ethtool_set_channels,
3127	.set_phys_id		= lio_set_phys_id,
3128	.get_eeprom_len		= lio_get_eeprom_len,
3129	.get_eeprom		= lio_get_eeprom,
3130	.get_strings		= lio_get_strings,
3131	.get_ethtool_stats	= lio_get_ethtool_stats,
3132	.get_pauseparam		= lio_get_pauseparam,
3133	.set_pauseparam		= lio_set_pauseparam,
3134	.get_regs_len		= lio_get_regs_len,
3135	.get_regs		= lio_get_regs,
3136	.get_msglevel		= lio_get_msglevel,
3137	.set_msglevel		= lio_set_msglevel,
3138	.get_sset_count		= lio_get_sset_count,
3139	.get_coalesce		= lio_get_intr_coalesce,
3140	.set_coalesce		= lio_set_intr_coalesce,
3141	.get_priv_flags		= lio_get_priv_flags,
3142	.set_priv_flags		= lio_set_priv_flags,
3143#ifdef PTP_HARDWARE_TIMESTAMPING
3144	.get_ts_info		= lio_get_ts_info,
3145#endif
3146};
3147
3148static const struct ethtool_ops lio_vf_ethtool_ops = {
3149	.supported_coalesce_params = LIO_ETHTOOL_COALESCE,
3150	.get_link_ksettings	= lio_get_link_ksettings,
3151	.get_link		= ethtool_op_get_link,
3152	.get_drvinfo		= lio_get_vf_drvinfo,
3153	.get_ringparam		= lio_ethtool_get_ringparam,
3154	.set_ringparam          = lio_ethtool_set_ringparam,
3155	.get_channels		= lio_ethtool_get_channels,
3156	.set_channels		= lio_ethtool_set_channels,
3157	.get_strings		= lio_vf_get_strings,
3158	.get_ethtool_stats	= lio_vf_get_ethtool_stats,
3159	.get_regs_len		= lio_get_regs_len,
3160	.get_regs		= lio_get_regs,
3161	.get_msglevel		= lio_get_msglevel,
3162	.set_msglevel		= lio_vf_set_msglevel,
3163	.get_sset_count		= lio_vf_get_sset_count,
3164	.get_coalesce		= lio_get_intr_coalesce,
3165	.set_coalesce		= lio_set_intr_coalesce,
3166	.get_priv_flags		= lio_get_priv_flags,
3167	.set_priv_flags		= lio_set_priv_flags,
3168#ifdef PTP_HARDWARE_TIMESTAMPING
3169	.get_ts_info		= lio_get_ts_info,
3170#endif
3171};
3172
3173void liquidio_set_ethtool_ops(struct net_device *netdev)
3174{
3175	struct lio *lio = GET_LIO(netdev);
3176	struct octeon_device *oct = lio->oct_dev;
3177
3178	if (OCTEON_CN23XX_VF(oct))
3179		netdev->ethtool_ops = &lio_vf_ethtool_ops;
3180	else
3181		netdev->ethtool_ops = &lio_ethtool_ops;
3182}
3183EXPORT_SYMBOL_GPL(liquidio_set_ethtool_ops);
v5.9
   1/**********************************************************************
   2 * Author: Cavium, Inc.
   3 *
   4 * Contact: support@cavium.com
   5 *          Please include "LiquidIO" in the subject.
   6 *
   7 * Copyright (c) 2003-2016 Cavium, Inc.
   8 *
   9 * This file is free software; you can redistribute it and/or modify
  10 * it under the terms of the GNU General Public License, Version 2, as
  11 * published by the Free Software Foundation.
  12 *
  13 * This file is distributed in the hope that it will be useful, but
  14 * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
  15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
  16 * NONINFRINGEMENT.  See the GNU General Public License for more details.
  17 ***********************************************************************/
 
  18#include <linux/netdevice.h>
  19#include <linux/net_tstamp.h>
  20#include <linux/pci.h>
  21#include "liquidio_common.h"
  22#include "octeon_droq.h"
  23#include "octeon_iq.h"
  24#include "response_manager.h"
  25#include "octeon_device.h"
  26#include "octeon_nic.h"
  27#include "octeon_main.h"
  28#include "octeon_network.h"
  29#include "cn66xx_regs.h"
  30#include "cn66xx_device.h"
  31#include "cn23xx_pf_device.h"
  32#include "cn23xx_vf_device.h"
  33
  34static int lio_reset_queues(struct net_device *netdev, uint32_t num_qs);
  35
  36struct oct_intrmod_resp {
  37	u64     rh;
  38	struct oct_intrmod_cfg intrmod;
  39	u64     status;
  40};
  41
  42struct oct_mdio_cmd_resp {
  43	u64 rh;
  44	struct oct_mdio_cmd resp;
  45	u64 status;
  46};
  47
  48#define OCT_MDIO45_RESP_SIZE   (sizeof(struct oct_mdio_cmd_resp))
  49
  50/* Octeon's interface mode of operation */
  51enum {
  52	INTERFACE_MODE_DISABLED,
  53	INTERFACE_MODE_RGMII,
  54	INTERFACE_MODE_GMII,
  55	INTERFACE_MODE_SPI,
  56	INTERFACE_MODE_PCIE,
  57	INTERFACE_MODE_XAUI,
  58	INTERFACE_MODE_SGMII,
  59	INTERFACE_MODE_PICMG,
  60	INTERFACE_MODE_NPI,
  61	INTERFACE_MODE_LOOP,
  62	INTERFACE_MODE_SRIO,
  63	INTERFACE_MODE_ILK,
  64	INTERFACE_MODE_RXAUI,
  65	INTERFACE_MODE_QSGMII,
  66	INTERFACE_MODE_AGL,
  67	INTERFACE_MODE_XLAUI,
  68	INTERFACE_MODE_XFI,
  69	INTERFACE_MODE_10G_KR,
  70	INTERFACE_MODE_40G_KR4,
  71	INTERFACE_MODE_MIXED,
  72};
  73
  74#define OCT_ETHTOOL_REGDUMP_LEN  4096
  75#define OCT_ETHTOOL_REGDUMP_LEN_23XX  (4096 * 11)
  76#define OCT_ETHTOOL_REGDUMP_LEN_23XX_VF  (4096 * 2)
  77#define OCT_ETHTOOL_REGSVER  1
  78
  79/* statistics of PF */
  80static const char oct_stats_strings[][ETH_GSTRING_LEN] = {
  81	"rx_packets",
  82	"tx_packets",
  83	"rx_bytes",
  84	"tx_bytes",
  85	"rx_errors",
  86	"tx_errors",
  87	"rx_dropped",
  88	"tx_dropped",
  89
  90	"tx_total_sent",
  91	"tx_total_fwd",
  92	"tx_err_pko",
  93	"tx_err_pki",
  94	"tx_err_link",
  95	"tx_err_drop",
  96
  97	"tx_tso",
  98	"tx_tso_packets",
  99	"tx_tso_err",
 100	"tx_vxlan",
 101
 102	"tx_mcast",
 103	"tx_bcast",
 104
 105	"mac_tx_total_pkts",
 106	"mac_tx_total_bytes",
 107	"mac_tx_mcast_pkts",
 108	"mac_tx_bcast_pkts",
 109	"mac_tx_ctl_packets",
 110	"mac_tx_total_collisions",
 111	"mac_tx_one_collision",
 112	"mac_tx_multi_collision",
 113	"mac_tx_max_collision_fail",
 114	"mac_tx_max_deferral_fail",
 115	"mac_tx_fifo_err",
 116	"mac_tx_runts",
 117
 118	"rx_total_rcvd",
 119	"rx_total_fwd",
 120	"rx_mcast",
 121	"rx_bcast",
 122	"rx_jabber_err",
 123	"rx_l2_err",
 124	"rx_frame_err",
 125	"rx_err_pko",
 126	"rx_err_link",
 127	"rx_err_drop",
 128
 129	"rx_vxlan",
 130	"rx_vxlan_err",
 131
 132	"rx_lro_pkts",
 133	"rx_lro_bytes",
 134	"rx_total_lro",
 135
 136	"rx_lro_aborts",
 137	"rx_lro_aborts_port",
 138	"rx_lro_aborts_seq",
 139	"rx_lro_aborts_tsval",
 140	"rx_lro_aborts_timer",
 141	"rx_fwd_rate",
 142
 143	"mac_rx_total_rcvd",
 144	"mac_rx_bytes",
 145	"mac_rx_total_bcst",
 146	"mac_rx_total_mcst",
 147	"mac_rx_runts",
 148	"mac_rx_ctl_packets",
 149	"mac_rx_fifo_err",
 150	"mac_rx_dma_drop",
 151	"mac_rx_fcs_err",
 152
 153	"link_state_changes",
 154};
 155
 156/* statistics of VF */
 157static const char oct_vf_stats_strings[][ETH_GSTRING_LEN] = {
 158	"rx_packets",
 159	"tx_packets",
 160	"rx_bytes",
 161	"tx_bytes",
 162	"rx_errors",
 163	"tx_errors",
 164	"rx_dropped",
 165	"tx_dropped",
 166	"rx_mcast",
 167	"tx_mcast",
 168	"rx_bcast",
 169	"tx_bcast",
 170	"link_state_changes",
 171};
 172
 173/* statistics of host tx queue */
 174static const char oct_iq_stats_strings[][ETH_GSTRING_LEN] = {
 175	"packets",
 176	"bytes",
 177	"dropped",
 178	"iq_busy",
 179	"sgentry_sent",
 180
 181	"fw_instr_posted",
 182	"fw_instr_processed",
 183	"fw_instr_dropped",
 184	"fw_bytes_sent",
 185
 186	"tso",
 187	"vxlan",
 188	"txq_restart",
 189};
 190
 191/* statistics of host rx queue */
 192static const char oct_droq_stats_strings[][ETH_GSTRING_LEN] = {
 193	"packets",
 194	"bytes",
 195	"dropped",
 196	"dropped_nomem",
 197	"dropped_toomany",
 198	"fw_dropped",
 199	"fw_pkts_received",
 200	"fw_bytes_received",
 201	"fw_dropped_nodispatch",
 202
 203	"vxlan",
 204	"buffer_alloc_failure",
 205};
 206
 207/* LiquidIO driver private flags */
 208static const char oct_priv_flags_strings[][ETH_GSTRING_LEN] = {
 209};
 210
 211#define OCTNIC_NCMD_AUTONEG_ON  0x1
 212#define OCTNIC_NCMD_PHY_ON      0x2
 213
 214static int lio_get_link_ksettings(struct net_device *netdev,
 215				  struct ethtool_link_ksettings *ecmd)
 216{
 217	struct lio *lio = GET_LIO(netdev);
 218	struct octeon_device *oct = lio->oct_dev;
 219	struct oct_link_info *linfo;
 220
 221	linfo = &lio->linfo;
 222
 223	ethtool_link_ksettings_zero_link_mode(ecmd, supported);
 224	ethtool_link_ksettings_zero_link_mode(ecmd, advertising);
 225
 226	switch (linfo->link.s.phy_type) {
 227	case LIO_PHY_PORT_TP:
 228		ecmd->base.port = PORT_TP;
 229		ecmd->base.autoneg = AUTONEG_DISABLE;
 230		ethtool_link_ksettings_add_link_mode(ecmd, supported, TP);
 231		ethtool_link_ksettings_add_link_mode(ecmd, supported, Pause);
 232		ethtool_link_ksettings_add_link_mode(ecmd, supported,
 233						     10000baseT_Full);
 234
 235		ethtool_link_ksettings_add_link_mode(ecmd, advertising, Pause);
 236		ethtool_link_ksettings_add_link_mode(ecmd, advertising,
 237						     10000baseT_Full);
 238
 239		break;
 240
 241	case LIO_PHY_PORT_FIBRE:
 242		if (linfo->link.s.if_mode == INTERFACE_MODE_XAUI ||
 243		    linfo->link.s.if_mode == INTERFACE_MODE_RXAUI ||
 244		    linfo->link.s.if_mode == INTERFACE_MODE_XLAUI ||
 245		    linfo->link.s.if_mode == INTERFACE_MODE_XFI) {
 246			dev_dbg(&oct->pci_dev->dev, "ecmd->base.transceiver is XCVR_EXTERNAL\n");
 247			ecmd->base.transceiver = XCVR_EXTERNAL;
 248		} else {
 249			dev_err(&oct->pci_dev->dev, "Unknown link interface mode: %d\n",
 250				linfo->link.s.if_mode);
 251		}
 252
 253		ecmd->base.port = PORT_FIBRE;
 254		ecmd->base.autoneg = AUTONEG_DISABLE;
 255		ethtool_link_ksettings_add_link_mode(ecmd, supported, FIBRE);
 256
 257		ethtool_link_ksettings_add_link_mode(ecmd, supported, Pause);
 258		ethtool_link_ksettings_add_link_mode(ecmd, advertising, Pause);
 259		if (oct->subsystem_id == OCTEON_CN2350_25GB_SUBSYS_ID ||
 260		    oct->subsystem_id == OCTEON_CN2360_25GB_SUBSYS_ID) {
 261			if (OCTEON_CN23XX_PF(oct)) {
 262				ethtool_link_ksettings_add_link_mode
 263					(ecmd, supported, 25000baseSR_Full);
 264				ethtool_link_ksettings_add_link_mode
 265					(ecmd, supported, 25000baseKR_Full);
 266				ethtool_link_ksettings_add_link_mode
 267					(ecmd, supported, 25000baseCR_Full);
 268
 269				if (oct->no_speed_setting == 0)  {
 270					ethtool_link_ksettings_add_link_mode
 271						(ecmd, supported,
 272						 10000baseSR_Full);
 273					ethtool_link_ksettings_add_link_mode
 274						(ecmd, supported,
 275						 10000baseKR_Full);
 276					ethtool_link_ksettings_add_link_mode
 277						(ecmd, supported,
 278						 10000baseCR_Full);
 279				}
 280
 281				if (oct->no_speed_setting == 0) {
 282					liquidio_get_speed(lio);
 283					liquidio_get_fec(lio);
 284				} else {
 285					oct->speed_setting = 25;
 286				}
 287
 288				if (oct->speed_setting == 10) {
 289					ethtool_link_ksettings_add_link_mode
 290						(ecmd, advertising,
 291						 10000baseSR_Full);
 292					ethtool_link_ksettings_add_link_mode
 293						(ecmd, advertising,
 294						 10000baseKR_Full);
 295					ethtool_link_ksettings_add_link_mode
 296						(ecmd, advertising,
 297						 10000baseCR_Full);
 298				}
 299				if (oct->speed_setting == 25) {
 300					ethtool_link_ksettings_add_link_mode
 301						(ecmd, advertising,
 302						 25000baseSR_Full);
 303					ethtool_link_ksettings_add_link_mode
 304						(ecmd, advertising,
 305						 25000baseKR_Full);
 306					ethtool_link_ksettings_add_link_mode
 307						(ecmd, advertising,
 308						 25000baseCR_Full);
 309				}
 310
 311				if (oct->no_speed_setting)
 312					break;
 313
 314				ethtool_link_ksettings_add_link_mode
 315					(ecmd, supported, FEC_RS);
 316				ethtool_link_ksettings_add_link_mode
 317					(ecmd, supported, FEC_NONE);
 318					/*FEC_OFF*/
 319				if (oct->props[lio->ifidx].fec == 1) {
 320					/* ETHTOOL_FEC_RS */
 321					ethtool_link_ksettings_add_link_mode
 322						(ecmd, advertising, FEC_RS);
 323				} else {
 324					/* ETHTOOL_FEC_OFF */
 325					ethtool_link_ksettings_add_link_mode
 326						(ecmd, advertising, FEC_NONE);
 327				}
 328			} else { /* VF */
 329				if (linfo->link.s.speed == 10000) {
 330					ethtool_link_ksettings_add_link_mode
 331						(ecmd, supported,
 332						 10000baseSR_Full);
 333					ethtool_link_ksettings_add_link_mode
 334						(ecmd, supported,
 335						 10000baseKR_Full);
 336					ethtool_link_ksettings_add_link_mode
 337						(ecmd, supported,
 338						 10000baseCR_Full);
 339
 340					ethtool_link_ksettings_add_link_mode
 341						(ecmd, advertising,
 342						 10000baseSR_Full);
 343					ethtool_link_ksettings_add_link_mode
 344						(ecmd, advertising,
 345						 10000baseKR_Full);
 346					ethtool_link_ksettings_add_link_mode
 347						(ecmd, advertising,
 348						 10000baseCR_Full);
 349				}
 350
 351				if (linfo->link.s.speed == 25000) {
 352					ethtool_link_ksettings_add_link_mode
 353						(ecmd, supported,
 354						 25000baseSR_Full);
 355					ethtool_link_ksettings_add_link_mode
 356						(ecmd, supported,
 357						 25000baseKR_Full);
 358					ethtool_link_ksettings_add_link_mode
 359						(ecmd, supported,
 360						 25000baseCR_Full);
 361
 362					ethtool_link_ksettings_add_link_mode
 363						(ecmd, advertising,
 364						 25000baseSR_Full);
 365					ethtool_link_ksettings_add_link_mode
 366						(ecmd, advertising,
 367						 25000baseKR_Full);
 368					ethtool_link_ksettings_add_link_mode
 369						(ecmd, advertising,
 370						 25000baseCR_Full);
 371				}
 372			}
 373		} else {
 374			ethtool_link_ksettings_add_link_mode(ecmd, supported,
 375							     10000baseT_Full);
 376			ethtool_link_ksettings_add_link_mode(ecmd, advertising,
 377							     10000baseT_Full);
 378		}
 379		break;
 380	}
 381
 382	if (linfo->link.s.link_up) {
 383		ecmd->base.speed = linfo->link.s.speed;
 384		ecmd->base.duplex = linfo->link.s.duplex;
 385	} else {
 386		ecmd->base.speed = SPEED_UNKNOWN;
 387		ecmd->base.duplex = DUPLEX_UNKNOWN;
 388	}
 389
 390	return 0;
 391}
 392
 393static int lio_set_link_ksettings(struct net_device *netdev,
 394				  const struct ethtool_link_ksettings *ecmd)
 395{
 396	const int speed = ecmd->base.speed;
 397	struct lio *lio = GET_LIO(netdev);
 398	struct oct_link_info *linfo;
 399	struct octeon_device *oct;
 400
 401	oct = lio->oct_dev;
 402
 403	linfo = &lio->linfo;
 404
 405	if (!(oct->subsystem_id == OCTEON_CN2350_25GB_SUBSYS_ID ||
 406	      oct->subsystem_id == OCTEON_CN2360_25GB_SUBSYS_ID))
 407		return -EOPNOTSUPP;
 408
 409	if (oct->no_speed_setting) {
 410		dev_err(&oct->pci_dev->dev, "%s: Changing speed is not supported\n",
 411			__func__);
 412		return -EOPNOTSUPP;
 413	}
 414
 415	if ((ecmd->base.duplex != DUPLEX_UNKNOWN &&
 416	     ecmd->base.duplex != linfo->link.s.duplex) ||
 417	     ecmd->base.autoneg != AUTONEG_DISABLE ||
 418	    (ecmd->base.speed != 10000 && ecmd->base.speed != 25000 &&
 419	     ecmd->base.speed != SPEED_UNKNOWN))
 420		return -EOPNOTSUPP;
 421
 422	if ((oct->speed_boot == speed / 1000) &&
 423	    oct->speed_boot == oct->speed_setting)
 424		return 0;
 425
 426	liquidio_set_speed(lio, speed / 1000);
 427
 428	dev_dbg(&oct->pci_dev->dev, "Port speed is set to %dG\n",
 429		oct->speed_setting);
 430
 431	return 0;
 432}
 433
 434static void
 435lio_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
 436{
 437	struct lio *lio;
 438	struct octeon_device *oct;
 439
 440	lio = GET_LIO(netdev);
 441	oct = lio->oct_dev;
 442
 443	memset(drvinfo, 0, sizeof(struct ethtool_drvinfo));
 444	strcpy(drvinfo->driver, "liquidio");
 445	strncpy(drvinfo->fw_version, oct->fw_info.liquidio_firmware_version,
 446		ETHTOOL_FWVERS_LEN);
 447	strncpy(drvinfo->bus_info, pci_name(oct->pci_dev), 32);
 
 448}
 449
 450static void
 451lio_get_vf_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
 452{
 453	struct octeon_device *oct;
 454	struct lio *lio;
 455
 456	lio = GET_LIO(netdev);
 457	oct = lio->oct_dev;
 458
 459	memset(drvinfo, 0, sizeof(struct ethtool_drvinfo));
 460	strcpy(drvinfo->driver, "liquidio_vf");
 461	strncpy(drvinfo->fw_version, oct->fw_info.liquidio_firmware_version,
 462		ETHTOOL_FWVERS_LEN);
 463	strncpy(drvinfo->bus_info, pci_name(oct->pci_dev), 32);
 
 464}
 465
 466static int
 467lio_send_queue_count_update(struct net_device *netdev, uint32_t num_queues)
 468{
 469	struct lio *lio = GET_LIO(netdev);
 470	struct octeon_device *oct = lio->oct_dev;
 471	struct octnic_ctrl_pkt nctrl;
 472	int ret = 0;
 473
 474	memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
 475
 476	nctrl.ncmd.u64 = 0;
 477	nctrl.ncmd.s.cmd = OCTNET_CMD_QUEUE_COUNT_CTL;
 478	nctrl.ncmd.s.param1 = num_queues;
 479	nctrl.ncmd.s.param2 = num_queues;
 480	nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
 481	nctrl.netpndev = (u64)netdev;
 482	nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
 483
 484	ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
 485	if (ret) {
 486		dev_err(&oct->pci_dev->dev, "Failed to send Queue reset command (ret: 0x%x)\n",
 487			ret);
 488		return -1;
 489	}
 490
 491	return 0;
 492}
 493
 494static void
 495lio_ethtool_get_channels(struct net_device *dev,
 496			 struct ethtool_channels *channel)
 497{
 498	struct lio *lio = GET_LIO(dev);
 499	struct octeon_device *oct = lio->oct_dev;
 500	u32 max_rx = 0, max_tx = 0, tx_count = 0, rx_count = 0;
 501	u32 combined_count = 0, max_combined = 0;
 502
 503	if (OCTEON_CN6XXX(oct)) {
 504		struct octeon_config *conf6x = CHIP_CONF(oct, cn6xxx);
 505
 506		max_rx = CFG_GET_OQ_MAX_Q(conf6x);
 507		max_tx = CFG_GET_IQ_MAX_Q(conf6x);
 508		rx_count = CFG_GET_NUM_RXQS_NIC_IF(conf6x, lio->ifidx);
 509		tx_count = CFG_GET_NUM_TXQS_NIC_IF(conf6x, lio->ifidx);
 510	} else if (OCTEON_CN23XX_PF(oct)) {
 511		if (oct->sriov_info.sriov_enabled) {
 512			max_combined = lio->linfo.num_txpciq;
 513		} else {
 514			struct octeon_config *conf23_pf =
 515				CHIP_CONF(oct, cn23xx_pf);
 516
 517			max_combined = CFG_GET_IQ_MAX_Q(conf23_pf);
 518		}
 519		combined_count = oct->num_iqs;
 520	} else if (OCTEON_CN23XX_VF(oct)) {
 521		u64 reg_val = 0ULL;
 522		u64 ctrl = CN23XX_VF_SLI_IQ_PKT_CONTROL64(0);
 523
 524		reg_val = octeon_read_csr64(oct, ctrl);
 525		reg_val = reg_val >> CN23XX_PKT_INPUT_CTL_RPVF_POS;
 526		max_combined = reg_val & CN23XX_PKT_INPUT_CTL_RPVF_MASK;
 527		combined_count = oct->num_iqs;
 528	}
 529
 530	channel->max_rx = max_rx;
 531	channel->max_tx = max_tx;
 532	channel->max_combined = max_combined;
 533	channel->rx_count = rx_count;
 534	channel->tx_count = tx_count;
 535	channel->combined_count = combined_count;
 536}
 537
 538static int
 539lio_irq_reallocate_irqs(struct octeon_device *oct, uint32_t num_ioqs)
 540{
 541	struct msix_entry *msix_entries;
 542	int num_msix_irqs = 0;
 543	int i;
 544
 545	if (!oct->msix_on)
 546		return 0;
 547
 548	/* Disable the input and output queues now. No more packets will
 549	 * arrive from Octeon.
 550	 */
 551	oct->fn_list.disable_interrupt(oct, OCTEON_ALL_INTR);
 552
 553	if (oct->msix_on) {
 554		if (OCTEON_CN23XX_PF(oct))
 555			num_msix_irqs = oct->num_msix_irqs - 1;
 556		else if (OCTEON_CN23XX_VF(oct))
 557			num_msix_irqs = oct->num_msix_irqs;
 558
 559		msix_entries = (struct msix_entry *)oct->msix_entries;
 560		for (i = 0; i < num_msix_irqs; i++) {
 561			if (oct->ioq_vector[i].vector) {
 562				/* clear the affinity_cpumask */
 563				irq_set_affinity_hint(msix_entries[i].vector,
 564						      NULL);
 565				free_irq(msix_entries[i].vector,
 566					 &oct->ioq_vector[i]);
 567				oct->ioq_vector[i].vector = 0;
 568			}
 569		}
 570
 571		/* non-iov vector's argument is oct struct */
 572		if (OCTEON_CN23XX_PF(oct))
 573			free_irq(msix_entries[i].vector, oct);
 574
 575		pci_disable_msix(oct->pci_dev);
 576		kfree(oct->msix_entries);
 577		oct->msix_entries = NULL;
 578	}
 579
 580	kfree(oct->irq_name_storage);
 581	oct->irq_name_storage = NULL;
 582
 583	if (octeon_allocate_ioq_vector(oct, num_ioqs)) {
 584		dev_err(&oct->pci_dev->dev, "OCTEON: ioq vector allocation failed\n");
 585		return -1;
 586	}
 587
 588	if (octeon_setup_interrupt(oct, num_ioqs)) {
 589		dev_info(&oct->pci_dev->dev, "Setup interrupt failed\n");
 590		return -1;
 591	}
 592
 593	/* Enable Octeon device interrupts */
 594	oct->fn_list.enable_interrupt(oct, OCTEON_ALL_INTR);
 595
 596	return 0;
 597}
 598
 599static int
 600lio_ethtool_set_channels(struct net_device *dev,
 601			 struct ethtool_channels *channel)
 602{
 603	u32 combined_count, max_combined;
 604	struct lio *lio = GET_LIO(dev);
 605	struct octeon_device *oct = lio->oct_dev;
 606	int stopped = 0;
 607
 608	if (strcmp(oct->fw_info.liquidio_firmware_version, "1.6.1") < 0) {
 609		dev_err(&oct->pci_dev->dev, "Minimum firmware version required is 1.6.1\n");
 610		return -EINVAL;
 611	}
 612
 613	if (!channel->combined_count || channel->other_count ||
 614	    channel->rx_count || channel->tx_count)
 615		return -EINVAL;
 616
 617	combined_count = channel->combined_count;
 618
 619	if (OCTEON_CN23XX_PF(oct)) {
 620		if (oct->sriov_info.sriov_enabled) {
 621			max_combined = lio->linfo.num_txpciq;
 622		} else {
 623			struct octeon_config *conf23_pf =
 624				CHIP_CONF(oct,
 625					  cn23xx_pf);
 626
 627			max_combined =
 628				CFG_GET_IQ_MAX_Q(conf23_pf);
 629		}
 630	} else if (OCTEON_CN23XX_VF(oct)) {
 631		u64 reg_val = 0ULL;
 632		u64 ctrl = CN23XX_VF_SLI_IQ_PKT_CONTROL64(0);
 633
 634		reg_val = octeon_read_csr64(oct, ctrl);
 635		reg_val = reg_val >> CN23XX_PKT_INPUT_CTL_RPVF_POS;
 636		max_combined = reg_val & CN23XX_PKT_INPUT_CTL_RPVF_MASK;
 637	} else {
 638		return -EINVAL;
 639	}
 640
 641	if (combined_count > max_combined || combined_count < 1)
 642		return -EINVAL;
 643
 644	if (combined_count == oct->num_iqs)
 645		return 0;
 646
 647	ifstate_set(lio, LIO_IFSTATE_RESETTING);
 648
 649	if (netif_running(dev)) {
 650		dev->netdev_ops->ndo_stop(dev);
 651		stopped = 1;
 652	}
 653
 654	if (lio_reset_queues(dev, combined_count))
 655		return -EINVAL;
 656
 657	if (stopped)
 658		dev->netdev_ops->ndo_open(dev);
 659
 660	ifstate_reset(lio, LIO_IFSTATE_RESETTING);
 661
 662	return 0;
 663}
 664
 665static int lio_get_eeprom_len(struct net_device *netdev)
 666{
 667	u8 buf[192];
 668	struct lio *lio = GET_LIO(netdev);
 669	struct octeon_device *oct_dev = lio->oct_dev;
 670	struct octeon_board_info *board_info;
 671	int len;
 672
 673	board_info = (struct octeon_board_info *)(&oct_dev->boardinfo);
 674	len = sprintf(buf, "boardname:%s serialnum:%s maj:%lld min:%lld\n",
 675		      board_info->name, board_info->serial_number,
 676		      board_info->major, board_info->minor);
 677
 678	return len;
 679}
 680
 681static int
 682lio_get_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
 683	       u8 *bytes)
 684{
 685	struct lio *lio = GET_LIO(netdev);
 686	struct octeon_device *oct_dev = lio->oct_dev;
 687	struct octeon_board_info *board_info;
 688
 689	if (eeprom->offset)
 690		return -EINVAL;
 691
 692	eeprom->magic = oct_dev->pci_dev->vendor;
 693	board_info = (struct octeon_board_info *)(&oct_dev->boardinfo);
 694	sprintf((char *)bytes,
 695		"boardname:%s serialnum:%s maj:%lld min:%lld\n",
 696		board_info->name, board_info->serial_number,
 697		board_info->major, board_info->minor);
 698
 699	return 0;
 700}
 701
 702static int octnet_gpio_access(struct net_device *netdev, int addr, int val)
 703{
 704	struct lio *lio = GET_LIO(netdev);
 705	struct octeon_device *oct = lio->oct_dev;
 706	struct octnic_ctrl_pkt nctrl;
 707	int ret = 0;
 708
 709	memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
 710
 711	nctrl.ncmd.u64 = 0;
 712	nctrl.ncmd.s.cmd = OCTNET_CMD_GPIO_ACCESS;
 713	nctrl.ncmd.s.param1 = addr;
 714	nctrl.ncmd.s.param2 = val;
 715	nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
 716	nctrl.netpndev = (u64)netdev;
 717	nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
 718
 719	ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
 720	if (ret) {
 721		dev_err(&oct->pci_dev->dev,
 722			"Failed to configure gpio value, ret=%d\n", ret);
 723		return -EINVAL;
 724	}
 725
 726	return 0;
 727}
 728
 729static int octnet_id_active(struct net_device *netdev, int val)
 730{
 731	struct lio *lio = GET_LIO(netdev);
 732	struct octeon_device *oct = lio->oct_dev;
 733	struct octnic_ctrl_pkt nctrl;
 734	int ret = 0;
 735
 736	memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
 737
 738	nctrl.ncmd.u64 = 0;
 739	nctrl.ncmd.s.cmd = OCTNET_CMD_ID_ACTIVE;
 740	nctrl.ncmd.s.param1 = val;
 741	nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
 742	nctrl.netpndev = (u64)netdev;
 743	nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
 744
 745	ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
 746	if (ret) {
 747		dev_err(&oct->pci_dev->dev,
 748			"Failed to configure gpio value, ret=%d\n", ret);
 749		return -EINVAL;
 750	}
 751
 752	return 0;
 753}
 754
 755/* This routine provides PHY access routines for
 756 * mdio  clause45 .
 757 */
 758static int
 759octnet_mdio45_access(struct lio *lio, int op, int loc, int *value)
 760{
 761	struct octeon_device *oct_dev = lio->oct_dev;
 762	struct octeon_soft_command *sc;
 763	struct oct_mdio_cmd_resp *mdio_cmd_rsp;
 764	struct oct_mdio_cmd *mdio_cmd;
 765	int retval = 0;
 766
 767	sc = (struct octeon_soft_command *)
 768		octeon_alloc_soft_command(oct_dev,
 769					  sizeof(struct oct_mdio_cmd),
 770					  sizeof(struct oct_mdio_cmd_resp), 0);
 771
 772	if (!sc)
 773		return -ENOMEM;
 774
 775	mdio_cmd_rsp = (struct oct_mdio_cmd_resp *)sc->virtrptr;
 776	mdio_cmd = (struct oct_mdio_cmd *)sc->virtdptr;
 777
 778	mdio_cmd->op = op;
 779	mdio_cmd->mdio_addr = loc;
 780	if (op)
 781		mdio_cmd->value1 = *value;
 782	octeon_swap_8B_data((u64 *)mdio_cmd, sizeof(struct oct_mdio_cmd) / 8);
 783
 784	sc->iq_no = lio->linfo.txpciq[0].s.q_no;
 785
 786	octeon_prepare_soft_command(oct_dev, sc, OPCODE_NIC, OPCODE_NIC_MDIO45,
 787				    0, 0, 0);
 788
 789	init_completion(&sc->complete);
 790	sc->sc_status = OCTEON_REQUEST_PENDING;
 791
 792	retval = octeon_send_soft_command(oct_dev, sc);
 793	if (retval == IQ_SEND_FAILED) {
 794		dev_err(&oct_dev->pci_dev->dev,
 795			"octnet_mdio45_access instruction failed status: %x\n",
 796			retval);
 797		octeon_free_soft_command(oct_dev, sc);
 798		return -EBUSY;
 799	} else {
 800		/* Sleep on a wait queue till the cond flag indicates that the
 801		 * response arrived
 802		 */
 803		retval = wait_for_sc_completion_timeout(oct_dev, sc, 0);
 804		if (retval)
 805			return retval;
 806
 807		retval = mdio_cmd_rsp->status;
 808		if (retval) {
 809			dev_err(&oct_dev->pci_dev->dev,
 810				"octnet mdio45 access failed: %x\n", retval);
 811			WRITE_ONCE(sc->caller_is_done, true);
 812			return -EBUSY;
 813		}
 814
 815		octeon_swap_8B_data((u64 *)(&mdio_cmd_rsp->resp),
 816				    sizeof(struct oct_mdio_cmd) / 8);
 817
 818		if (!op)
 819			*value = mdio_cmd_rsp->resp.value1;
 820
 821		WRITE_ONCE(sc->caller_is_done, true);
 822	}
 823
 824	return retval;
 825}
 826
 827static int lio_set_phys_id(struct net_device *netdev,
 828			   enum ethtool_phys_id_state state)
 829{
 830	struct lio *lio = GET_LIO(netdev);
 831	struct octeon_device *oct = lio->oct_dev;
 832	struct oct_link_info *linfo;
 833	int value, ret;
 834	u32 cur_ver;
 835
 836	linfo = &lio->linfo;
 837	cur_ver = OCT_FW_VER(oct->fw_info.ver.maj,
 838			     oct->fw_info.ver.min,
 839			     oct->fw_info.ver.rev);
 840
 841	switch (state) {
 842	case ETHTOOL_ID_ACTIVE:
 843		if (oct->chip_id == OCTEON_CN66XX) {
 844			octnet_gpio_access(netdev, VITESSE_PHY_GPIO_CFG,
 845					   VITESSE_PHY_GPIO_DRIVEON);
 846			return 2;
 847
 848		} else if (oct->chip_id == OCTEON_CN68XX) {
 849			/* Save the current LED settings */
 850			ret = octnet_mdio45_access(lio, 0,
 851						   LIO68XX_LED_BEACON_ADDR,
 852						   &lio->phy_beacon_val);
 853			if (ret)
 854				return ret;
 855
 856			ret = octnet_mdio45_access(lio, 0,
 857						   LIO68XX_LED_CTRL_ADDR,
 858						   &lio->led_ctrl_val);
 859			if (ret)
 860				return ret;
 861
 862			/* Configure Beacon values */
 863			value = LIO68XX_LED_BEACON_CFGON;
 864			ret = octnet_mdio45_access(lio, 1,
 865						   LIO68XX_LED_BEACON_ADDR,
 866						   &value);
 867			if (ret)
 868				return ret;
 869
 870			value = LIO68XX_LED_CTRL_CFGON;
 871			ret = octnet_mdio45_access(lio, 1,
 872						   LIO68XX_LED_CTRL_ADDR,
 873						   &value);
 874			if (ret)
 875				return ret;
 876		} else if (oct->chip_id == OCTEON_CN23XX_PF_VID) {
 877			octnet_id_active(netdev, LED_IDENTIFICATION_ON);
 878			if (linfo->link.s.phy_type == LIO_PHY_PORT_TP &&
 879			    cur_ver > OCT_FW_VER(1, 7, 2))
 880				return 2;
 881			else
 882				return 0;
 883		} else {
 884			return -EINVAL;
 885		}
 886		break;
 887
 888	case ETHTOOL_ID_ON:
 889		if (oct->chip_id == OCTEON_CN23XX_PF_VID &&
 890		    linfo->link.s.phy_type == LIO_PHY_PORT_TP &&
 891		    cur_ver > OCT_FW_VER(1, 7, 2))
 892			octnet_id_active(netdev, LED_IDENTIFICATION_ON);
 893		else if (oct->chip_id == OCTEON_CN66XX)
 894			octnet_gpio_access(netdev, VITESSE_PHY_GPIO_CFG,
 895					   VITESSE_PHY_GPIO_HIGH);
 896		else
 897			return -EINVAL;
 898
 899		break;
 900
 901	case ETHTOOL_ID_OFF:
 902		if (oct->chip_id == OCTEON_CN23XX_PF_VID &&
 903		    linfo->link.s.phy_type == LIO_PHY_PORT_TP &&
 904		    cur_ver > OCT_FW_VER(1, 7, 2))
 905			octnet_id_active(netdev, LED_IDENTIFICATION_OFF);
 906		else if (oct->chip_id == OCTEON_CN66XX)
 907			octnet_gpio_access(netdev, VITESSE_PHY_GPIO_CFG,
 908					   VITESSE_PHY_GPIO_LOW);
 909		else
 910			return -EINVAL;
 911
 912		break;
 913
 914	case ETHTOOL_ID_INACTIVE:
 915		if (oct->chip_id == OCTEON_CN66XX) {
 916			octnet_gpio_access(netdev, VITESSE_PHY_GPIO_CFG,
 917					   VITESSE_PHY_GPIO_DRIVEOFF);
 918		} else if (oct->chip_id == OCTEON_CN68XX) {
 919			/* Restore LED settings */
 920			ret = octnet_mdio45_access(lio, 1,
 921						   LIO68XX_LED_CTRL_ADDR,
 922						   &lio->led_ctrl_val);
 923			if (ret)
 924				return ret;
 925
 926			ret = octnet_mdio45_access(lio, 1,
 927						   LIO68XX_LED_BEACON_ADDR,
 928						   &lio->phy_beacon_val);
 929			if (ret)
 930				return ret;
 931		} else if (oct->chip_id == OCTEON_CN23XX_PF_VID) {
 932			octnet_id_active(netdev, LED_IDENTIFICATION_OFF);
 933
 934			return 0;
 935		} else {
 936			return -EINVAL;
 937		}
 938		break;
 939
 940	default:
 941		return -EINVAL;
 942	}
 943
 944	return 0;
 945}
 946
 947static void
 948lio_ethtool_get_ringparam(struct net_device *netdev,
 949			  struct ethtool_ringparam *ering)
 
 
 950{
 951	struct lio *lio = GET_LIO(netdev);
 952	struct octeon_device *oct = lio->oct_dev;
 953	u32 tx_max_pending = 0, rx_max_pending = 0, tx_pending = 0,
 954	    rx_pending = 0;
 955
 956	if (ifstate_check(lio, LIO_IFSTATE_RESETTING))
 957		return;
 958
 959	if (OCTEON_CN6XXX(oct)) {
 960		struct octeon_config *conf6x = CHIP_CONF(oct, cn6xxx);
 961
 962		tx_max_pending = CN6XXX_MAX_IQ_DESCRIPTORS;
 963		rx_max_pending = CN6XXX_MAX_OQ_DESCRIPTORS;
 964		rx_pending = CFG_GET_NUM_RX_DESCS_NIC_IF(conf6x, lio->ifidx);
 965		tx_pending = CFG_GET_NUM_TX_DESCS_NIC_IF(conf6x, lio->ifidx);
 966	} else if (OCTEON_CN23XX_PF(oct) || OCTEON_CN23XX_VF(oct)) {
 967		tx_max_pending = CN23XX_MAX_IQ_DESCRIPTORS;
 968		rx_max_pending = CN23XX_MAX_OQ_DESCRIPTORS;
 969		rx_pending = oct->droq[0]->max_count;
 970		tx_pending = oct->instr_queue[0]->max_count;
 971	}
 972
 973	ering->tx_pending = tx_pending;
 974	ering->tx_max_pending = tx_max_pending;
 975	ering->rx_pending = rx_pending;
 976	ering->rx_max_pending = rx_max_pending;
 977	ering->rx_mini_pending = 0;
 978	ering->rx_jumbo_pending = 0;
 979	ering->rx_mini_max_pending = 0;
 980	ering->rx_jumbo_max_pending = 0;
 981}
 982
 983static int lio_23xx_reconfigure_queue_count(struct lio *lio)
 984{
 985	struct octeon_device *oct = lio->oct_dev;
 986	u32 resp_size, data_size;
 987	struct liquidio_if_cfg_resp *resp;
 988	struct octeon_soft_command *sc;
 989	union oct_nic_if_cfg if_cfg;
 990	struct lio_version *vdata;
 991	u32 ifidx_or_pfnum;
 992	int retval;
 993	int j;
 994
 995	resp_size = sizeof(struct liquidio_if_cfg_resp);
 996	data_size = sizeof(struct lio_version);
 997	sc = (struct octeon_soft_command *)
 998		octeon_alloc_soft_command(oct, data_size,
 999					  resp_size, 0);
1000	if (!sc) {
1001		dev_err(&oct->pci_dev->dev, "%s: Failed to allocate soft command\n",
1002			__func__);
1003		return -1;
1004	}
1005
1006	resp = (struct liquidio_if_cfg_resp *)sc->virtrptr;
1007	vdata = (struct lio_version *)sc->virtdptr;
1008
1009	vdata->major = (__force u16)cpu_to_be16(LIQUIDIO_BASE_MAJOR_VERSION);
1010	vdata->minor = (__force u16)cpu_to_be16(LIQUIDIO_BASE_MINOR_VERSION);
1011	vdata->micro = (__force u16)cpu_to_be16(LIQUIDIO_BASE_MICRO_VERSION);
1012
1013	ifidx_or_pfnum = oct->pf_num;
1014
1015	if_cfg.u64 = 0;
1016	if_cfg.s.num_iqueues = oct->sriov_info.num_pf_rings;
1017	if_cfg.s.num_oqueues = oct->sriov_info.num_pf_rings;
1018	if_cfg.s.base_queue = oct->sriov_info.pf_srn;
1019	if_cfg.s.gmx_port_id = oct->pf_num;
1020
1021	sc->iq_no = 0;
1022	octeon_prepare_soft_command(oct, sc, OPCODE_NIC,
1023				    OPCODE_NIC_QCOUNT_UPDATE, 0,
1024				    if_cfg.u64, 0);
1025
1026	init_completion(&sc->complete);
1027	sc->sc_status = OCTEON_REQUEST_PENDING;
1028
1029	retval = octeon_send_soft_command(oct, sc);
1030	if (retval == IQ_SEND_FAILED) {
1031		dev_err(&oct->pci_dev->dev,
1032			"Sending iq/oq config failed status: %x\n",
1033			retval);
1034		octeon_free_soft_command(oct, sc);
1035		return -EIO;
1036	}
1037
1038	retval = wait_for_sc_completion_timeout(oct, sc, 0);
1039	if (retval)
1040		return retval;
1041
1042	retval = resp->status;
1043	if (retval) {
1044		dev_err(&oct->pci_dev->dev,
1045			"iq/oq config failed: %x\n", retval);
1046		WRITE_ONCE(sc->caller_is_done, true);
1047		return -1;
1048	}
1049
1050	octeon_swap_8B_data((u64 *)(&resp->cfg_info),
1051			    (sizeof(struct liquidio_if_cfg_info)) >> 3);
1052
1053	lio->ifidx = ifidx_or_pfnum;
1054	lio->linfo.num_rxpciq = hweight64(resp->cfg_info.iqmask);
1055	lio->linfo.num_txpciq = hweight64(resp->cfg_info.iqmask);
1056	for (j = 0; j < lio->linfo.num_rxpciq; j++) {
1057		lio->linfo.rxpciq[j].u64 =
1058			resp->cfg_info.linfo.rxpciq[j].u64;
1059	}
1060
1061	for (j = 0; j < lio->linfo.num_txpciq; j++) {
1062		lio->linfo.txpciq[j].u64 =
1063			resp->cfg_info.linfo.txpciq[j].u64;
1064	}
1065
1066	lio->linfo.hw_addr = resp->cfg_info.linfo.hw_addr;
1067	lio->linfo.gmxport = resp->cfg_info.linfo.gmxport;
1068	lio->linfo.link.u64 = resp->cfg_info.linfo.link.u64;
1069	lio->txq = lio->linfo.txpciq[0].s.q_no;
1070	lio->rxq = lio->linfo.rxpciq[0].s.q_no;
1071
1072	dev_info(&oct->pci_dev->dev, "Queue count updated to %d\n",
1073		 lio->linfo.num_rxpciq);
1074
1075	WRITE_ONCE(sc->caller_is_done, true);
1076
1077	return 0;
1078}
1079
1080static int lio_reset_queues(struct net_device *netdev, uint32_t num_qs)
1081{
1082	struct lio *lio = GET_LIO(netdev);
1083	struct octeon_device *oct = lio->oct_dev;
1084	int i, queue_count_update = 0;
1085	struct napi_struct *napi, *n;
1086	int ret;
1087
1088	schedule_timeout_uninterruptible(msecs_to_jiffies(100));
1089
1090	if (wait_for_pending_requests(oct))
1091		dev_err(&oct->pci_dev->dev, "There were pending requests\n");
1092
1093	if (lio_wait_for_instr_fetch(oct))
1094		dev_err(&oct->pci_dev->dev, "IQ had pending instructions\n");
1095
1096	if (octeon_set_io_queues_off(oct)) {
1097		dev_err(&oct->pci_dev->dev, "Setting io queues off failed\n");
1098		return -1;
1099	}
1100
1101	/* Disable the input and output queues now. No more packets will
1102	 * arrive from Octeon.
1103	 */
1104	oct->fn_list.disable_io_queues(oct);
1105	/* Delete NAPI */
1106	list_for_each_entry_safe(napi, n, &netdev->napi_list, dev_list)
1107		netif_napi_del(napi);
1108
1109	if (num_qs != oct->num_iqs) {
1110		ret = netif_set_real_num_rx_queues(netdev, num_qs);
1111		if (ret) {
1112			dev_err(&oct->pci_dev->dev,
1113				"Setting real number rx failed\n");
1114			return ret;
1115		}
1116
1117		ret = netif_set_real_num_tx_queues(netdev, num_qs);
1118		if (ret) {
1119			dev_err(&oct->pci_dev->dev,
1120				"Setting real number tx failed\n");
1121			return ret;
1122		}
1123
1124		/* The value of queue_count_update decides whether it is the
1125		 * queue count or the descriptor count that is being
1126		 * re-configured.
1127		 */
1128		queue_count_update = 1;
1129	}
1130
1131	/* Re-configuration of queues can happen in two scenarios, SRIOV enabled
1132	 * and SRIOV disabled. Few things like recreating queue zero, resetting
1133	 * glists and IRQs are required for both. For the latter, some more
1134	 * steps like updating sriov_info for the octeon device need to be done.
1135	 */
1136	if (queue_count_update) {
1137		cleanup_rx_oom_poll_fn(netdev);
1138
1139		lio_delete_glists(lio);
1140
1141		/* Delete mbox for PF which is SRIOV disabled because sriov_info
1142		 * will be now changed.
1143		 */
1144		if ((OCTEON_CN23XX_PF(oct)) && !oct->sriov_info.sriov_enabled)
1145			oct->fn_list.free_mbox(oct);
1146	}
1147
1148	for (i = 0; i < MAX_OCTEON_OUTPUT_QUEUES(oct); i++) {
1149		if (!(oct->io_qmask.oq & BIT_ULL(i)))
1150			continue;
1151		octeon_delete_droq(oct, i);
1152	}
1153
1154	for (i = 0; i < MAX_OCTEON_INSTR_QUEUES(oct); i++) {
1155		if (!(oct->io_qmask.iq & BIT_ULL(i)))
1156			continue;
1157		octeon_delete_instr_queue(oct, i);
1158	}
1159
1160	if (queue_count_update) {
1161		/* For PF re-configure sriov related information */
1162		if ((OCTEON_CN23XX_PF(oct)) &&
1163		    !oct->sriov_info.sriov_enabled) {
1164			oct->sriov_info.num_pf_rings = num_qs;
1165			if (cn23xx_sriov_config(oct)) {
1166				dev_err(&oct->pci_dev->dev,
1167					"Queue reset aborted: SRIOV config failed\n");
1168				return -1;
1169			}
1170
1171			num_qs = oct->sriov_info.num_pf_rings;
1172		}
1173	}
1174
1175	if (oct->fn_list.setup_device_regs(oct)) {
1176		dev_err(&oct->pci_dev->dev, "Failed to configure device registers\n");
1177		return -1;
1178	}
1179
1180	/* The following are needed in case of queue count re-configuration and
1181	 * not for descriptor count re-configuration.
1182	 */
1183	if (queue_count_update) {
1184		if (octeon_setup_instr_queues(oct))
1185			return -1;
1186
1187		if (octeon_setup_output_queues(oct))
1188			return -1;
1189
1190		/* Recreating mbox for PF that is SRIOV disabled */
1191		if (OCTEON_CN23XX_PF(oct) && !oct->sriov_info.sriov_enabled) {
1192			if (oct->fn_list.setup_mbox(oct)) {
1193				dev_err(&oct->pci_dev->dev, "Mailbox setup failed\n");
1194				return -1;
1195			}
1196		}
1197
1198		/* Deleting and recreating IRQs whether the interface is SRIOV
1199		 * enabled or disabled.
1200		 */
1201		if (lio_irq_reallocate_irqs(oct, num_qs)) {
1202			dev_err(&oct->pci_dev->dev, "IRQs could not be allocated\n");
1203			return -1;
1204		}
1205
1206		/* Enable the input and output queues for this Octeon device */
1207		if (oct->fn_list.enable_io_queues(oct)) {
1208			dev_err(&oct->pci_dev->dev, "Failed to enable input/output queues\n");
1209			return -1;
1210		}
1211
1212		for (i = 0; i < oct->num_oqs; i++)
1213			writel(oct->droq[i]->max_count,
1214			       oct->droq[i]->pkts_credit_reg);
1215
1216		/* Informing firmware about the new queue count. It is required
1217		 * for firmware to allocate more number of queues than those at
1218		 * load time.
1219		 */
1220		if (OCTEON_CN23XX_PF(oct) && !oct->sriov_info.sriov_enabled) {
1221			if (lio_23xx_reconfigure_queue_count(lio))
1222				return -1;
1223		}
1224	}
1225
1226	/* Once firmware is aware of the new value, queues can be recreated */
1227	if (liquidio_setup_io_queues(oct, 0, num_qs, num_qs)) {
1228		dev_err(&oct->pci_dev->dev, "I/O queues creation failed\n");
1229		return -1;
1230	}
1231
1232	if (queue_count_update) {
1233		if (lio_setup_glists(oct, lio, num_qs)) {
1234			dev_err(&oct->pci_dev->dev, "Gather list allocation failed\n");
1235			return -1;
1236		}
1237
1238		if (setup_rx_oom_poll_fn(netdev)) {
1239			dev_err(&oct->pci_dev->dev, "lio_setup_rx_oom_poll_fn failed\n");
1240			return 1;
1241		}
1242
1243		/* Send firmware the information about new number of queues
1244		 * if the interface is a VF or a PF that is SRIOV enabled.
1245		 */
1246		if (oct->sriov_info.sriov_enabled || OCTEON_CN23XX_VF(oct))
1247			if (lio_send_queue_count_update(netdev, num_qs))
1248				return -1;
1249	}
1250
1251	return 0;
1252}
1253
1254static int lio_ethtool_set_ringparam(struct net_device *netdev,
1255				     struct ethtool_ringparam *ering)
 
 
 
1256{
1257	u32 rx_count, tx_count, rx_count_old, tx_count_old;
1258	struct lio *lio = GET_LIO(netdev);
1259	struct octeon_device *oct = lio->oct_dev;
1260	int stopped = 0;
1261
1262	if (!OCTEON_CN23XX_PF(oct) && !OCTEON_CN23XX_VF(oct))
1263		return -EINVAL;
1264
1265	if (ering->rx_mini_pending || ering->rx_jumbo_pending)
1266		return -EINVAL;
1267
1268	rx_count = clamp_t(u32, ering->rx_pending, CN23XX_MIN_OQ_DESCRIPTORS,
1269			   CN23XX_MAX_OQ_DESCRIPTORS);
1270	tx_count = clamp_t(u32, ering->tx_pending, CN23XX_MIN_IQ_DESCRIPTORS,
1271			   CN23XX_MAX_IQ_DESCRIPTORS);
1272
1273	rx_count_old = oct->droq[0]->max_count;
1274	tx_count_old = oct->instr_queue[0]->max_count;
1275
1276	if (rx_count == rx_count_old && tx_count == tx_count_old)
1277		return 0;
1278
1279	ifstate_set(lio, LIO_IFSTATE_RESETTING);
1280
1281	if (netif_running(netdev)) {
1282		netdev->netdev_ops->ndo_stop(netdev);
1283		stopped = 1;
1284	}
1285
1286	/* Change RX/TX DESCS  count */
1287	if (tx_count != tx_count_old)
1288		CFG_SET_NUM_TX_DESCS_NIC_IF(octeon_get_conf(oct), lio->ifidx,
1289					    tx_count);
1290	if (rx_count != rx_count_old)
1291		CFG_SET_NUM_RX_DESCS_NIC_IF(octeon_get_conf(oct), lio->ifidx,
1292					    rx_count);
1293
1294	if (lio_reset_queues(netdev, oct->num_iqs))
1295		goto err_lio_reset_queues;
1296
1297	if (stopped)
1298		netdev->netdev_ops->ndo_open(netdev);
1299
1300	ifstate_reset(lio, LIO_IFSTATE_RESETTING);
1301
1302	return 0;
1303
1304err_lio_reset_queues:
1305	if (tx_count != tx_count_old)
1306		CFG_SET_NUM_TX_DESCS_NIC_IF(octeon_get_conf(oct), lio->ifidx,
1307					    tx_count_old);
1308	if (rx_count != rx_count_old)
1309		CFG_SET_NUM_RX_DESCS_NIC_IF(octeon_get_conf(oct), lio->ifidx,
1310					    rx_count_old);
1311	return -EINVAL;
1312}
1313
1314static u32 lio_get_msglevel(struct net_device *netdev)
1315{
1316	struct lio *lio = GET_LIO(netdev);
1317
1318	return lio->msg_enable;
1319}
1320
1321static void lio_set_msglevel(struct net_device *netdev, u32 msglvl)
1322{
1323	struct lio *lio = GET_LIO(netdev);
1324
1325	if ((msglvl ^ lio->msg_enable) & NETIF_MSG_HW) {
1326		if (msglvl & NETIF_MSG_HW)
1327			liquidio_set_feature(netdev,
1328					     OCTNET_CMD_VERBOSE_ENABLE, 0);
1329		else
1330			liquidio_set_feature(netdev,
1331					     OCTNET_CMD_VERBOSE_DISABLE, 0);
1332	}
1333
1334	lio->msg_enable = msglvl;
1335}
1336
1337static void lio_vf_set_msglevel(struct net_device *netdev, u32 msglvl)
1338{
1339	struct lio *lio = GET_LIO(netdev);
1340
1341	lio->msg_enable = msglvl;
1342}
1343
1344static void
1345lio_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
1346{
1347	/* Notes: Not supporting any auto negotiation in these
1348	 * drivers. Just report pause frame support.
1349	 */
1350	struct lio *lio = GET_LIO(netdev);
1351	struct octeon_device *oct = lio->oct_dev;
1352
1353	pause->autoneg = 0;
1354
1355	pause->tx_pause = oct->tx_pause;
1356	pause->rx_pause = oct->rx_pause;
1357}
1358
1359static int
1360lio_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
1361{
1362	/* Notes: Not supporting any auto negotiation in these
1363	 * drivers.
1364	 */
1365	struct lio *lio = GET_LIO(netdev);
1366	struct octeon_device *oct = lio->oct_dev;
1367	struct octnic_ctrl_pkt nctrl;
1368	struct oct_link_info *linfo = &lio->linfo;
1369
1370	int ret = 0;
1371
1372	if (oct->chip_id != OCTEON_CN23XX_PF_VID)
1373		return -EINVAL;
1374
1375	if (linfo->link.s.duplex == 0) {
1376		/*no flow control for half duplex*/
1377		if (pause->rx_pause || pause->tx_pause)
1378			return -EINVAL;
1379	}
1380
1381	/*do not support autoneg of link flow control*/
1382	if (pause->autoneg == AUTONEG_ENABLE)
1383		return -EINVAL;
1384
1385	memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
1386
1387	nctrl.ncmd.u64 = 0;
1388	nctrl.ncmd.s.cmd = OCTNET_CMD_SET_FLOW_CTL;
1389	nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
1390	nctrl.netpndev = (u64)netdev;
1391	nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
1392
1393	if (pause->rx_pause) {
1394		/*enable rx pause*/
1395		nctrl.ncmd.s.param1 = 1;
1396	} else {
1397		/*disable rx pause*/
1398		nctrl.ncmd.s.param1 = 0;
1399	}
1400
1401	if (pause->tx_pause) {
1402		/*enable tx pause*/
1403		nctrl.ncmd.s.param2 = 1;
1404	} else {
1405		/*disable tx pause*/
1406		nctrl.ncmd.s.param2 = 0;
1407	}
1408
1409	ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
1410	if (ret) {
1411		dev_err(&oct->pci_dev->dev,
1412			"Failed to set pause parameter, ret=%d\n", ret);
1413		return -EINVAL;
1414	}
1415
1416	oct->rx_pause = pause->rx_pause;
1417	oct->tx_pause = pause->tx_pause;
1418
1419	return 0;
1420}
1421
1422static void
1423lio_get_ethtool_stats(struct net_device *netdev,
1424		      struct ethtool_stats *stats  __attribute__((unused)),
1425		      u64 *data)
1426{
1427	struct lio *lio = GET_LIO(netdev);
1428	struct octeon_device *oct_dev = lio->oct_dev;
1429	struct rtnl_link_stats64 lstats;
1430	int i = 0, j;
1431
1432	if (ifstate_check(lio, LIO_IFSTATE_RESETTING))
1433		return;
1434
1435	netdev->netdev_ops->ndo_get_stats64(netdev, &lstats);
1436	/*sum of oct->droq[oq_no]->stats->rx_pkts_received */
1437	data[i++] = lstats.rx_packets;
1438	/*sum of oct->instr_queue[iq_no]->stats.tx_done */
1439	data[i++] = lstats.tx_packets;
1440	/*sum of oct->droq[oq_no]->stats->rx_bytes_received */
1441	data[i++] = lstats.rx_bytes;
1442	/*sum of oct->instr_queue[iq_no]->stats.tx_tot_bytes */
1443	data[i++] = lstats.tx_bytes;
1444	data[i++] = lstats.rx_errors +
1445			oct_dev->link_stats.fromwire.fcs_err +
1446			oct_dev->link_stats.fromwire.jabber_err +
1447			oct_dev->link_stats.fromwire.l2_err +
1448			oct_dev->link_stats.fromwire.frame_err;
1449	data[i++] = lstats.tx_errors;
1450	/*sum of oct->droq[oq_no]->stats->rx_dropped +
1451	 *oct->droq[oq_no]->stats->dropped_nodispatch +
1452	 *oct->droq[oq_no]->stats->dropped_toomany +
1453	 *oct->droq[oq_no]->stats->dropped_nomem
1454	 */
1455	data[i++] = lstats.rx_dropped +
1456			oct_dev->link_stats.fromwire.fifo_err +
1457			oct_dev->link_stats.fromwire.dmac_drop +
1458			oct_dev->link_stats.fromwire.red_drops +
1459			oct_dev->link_stats.fromwire.fw_err_pko +
1460			oct_dev->link_stats.fromwire.fw_err_link +
1461			oct_dev->link_stats.fromwire.fw_err_drop;
1462	/*sum of oct->instr_queue[iq_no]->stats.tx_dropped */
1463	data[i++] = lstats.tx_dropped +
1464			oct_dev->link_stats.fromhost.max_collision_fail +
1465			oct_dev->link_stats.fromhost.max_deferral_fail +
1466			oct_dev->link_stats.fromhost.total_collisions +
1467			oct_dev->link_stats.fromhost.fw_err_pko +
1468			oct_dev->link_stats.fromhost.fw_err_link +
1469			oct_dev->link_stats.fromhost.fw_err_drop +
1470			oct_dev->link_stats.fromhost.fw_err_pki;
1471
1472	/* firmware tx stats */
1473	/*per_core_stats[cvmx_get_core_num()].link_stats[mdata->from_ifidx].
1474	 *fromhost.fw_total_sent
1475	 */
1476	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_total_sent);
1477	/*per_core_stats[i].link_stats[port].fromwire.fw_total_fwd */
1478	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_total_fwd);
1479	/*per_core_stats[j].link_stats[i].fromhost.fw_err_pko */
1480	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_err_pko);
1481	/*per_core_stats[j].link_stats[i].fromhost.fw_err_pki */
1482	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_err_pki);
1483	/*per_core_stats[j].link_stats[i].fromhost.fw_err_link */
1484	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_err_link);
1485	/*per_core_stats[cvmx_get_core_num()].link_stats[idx].fromhost.
1486	 *fw_err_drop
1487	 */
1488	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_err_drop);
1489
1490	/*per_core_stats[cvmx_get_core_num()].link_stats[idx].fromhost.fw_tso */
1491	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_tso);
1492	/*per_core_stats[cvmx_get_core_num()].link_stats[idx].fromhost.
1493	 *fw_tso_fwd
1494	 */
1495	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_tso_fwd);
1496	/*per_core_stats[cvmx_get_core_num()].link_stats[idx].fromhost.
1497	 *fw_err_tso
1498	 */
1499	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_err_tso);
1500	/*per_core_stats[cvmx_get_core_num()].link_stats[idx].fromhost.
1501	 *fw_tx_vxlan
1502	 */
1503	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_tx_vxlan);
1504
1505	/* Multicast packets sent by this port */
1506	data[i++] = oct_dev->link_stats.fromhost.fw_total_mcast_sent;
1507	data[i++] = oct_dev->link_stats.fromhost.fw_total_bcast_sent;
1508
1509	/* mac tx statistics */
1510	/*CVMX_BGXX_CMRX_TX_STAT5 */
1511	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.total_pkts_sent);
1512	/*CVMX_BGXX_CMRX_TX_STAT4 */
1513	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.total_bytes_sent);
1514	/*CVMX_BGXX_CMRX_TX_STAT15 */
1515	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.mcast_pkts_sent);
1516	/*CVMX_BGXX_CMRX_TX_STAT14 */
1517	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.bcast_pkts_sent);
1518	/*CVMX_BGXX_CMRX_TX_STAT17 */
1519	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.ctl_sent);
1520	/*CVMX_BGXX_CMRX_TX_STAT0 */
1521	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.total_collisions);
1522	/*CVMX_BGXX_CMRX_TX_STAT3 */
1523	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.one_collision_sent);
1524	/*CVMX_BGXX_CMRX_TX_STAT2 */
1525	data[i++] =
1526		CVM_CAST64(oct_dev->link_stats.fromhost.multi_collision_sent);
1527	/*CVMX_BGXX_CMRX_TX_STAT0 */
1528	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.max_collision_fail);
1529	/*CVMX_BGXX_CMRX_TX_STAT1 */
1530	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.max_deferral_fail);
1531	/*CVMX_BGXX_CMRX_TX_STAT16 */
1532	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fifo_err);
1533	/*CVMX_BGXX_CMRX_TX_STAT6 */
1534	data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.runts);
1535
1536	/* RX firmware stats */
1537	/*per_core_stats[cvmx_get_core_num()].link_stats[ifidx].fromwire.
1538	 *fw_total_rcvd
1539	 */
1540	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_total_rcvd);
1541	/*per_core_stats[cvmx_get_core_num()].link_stats[ifidx].fromwire.
1542	 *fw_total_fwd
1543	 */
1544	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_total_fwd);
1545	/* Multicast packets received on this port */
1546	data[i++] = oct_dev->link_stats.fromwire.fw_total_mcast;
1547	data[i++] = oct_dev->link_stats.fromwire.fw_total_bcast;
1548	/*per_core_stats[core_id].link_stats[ifidx].fromwire.jabber_err */
1549	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.jabber_err);
1550	/*per_core_stats[core_id].link_stats[ifidx].fromwire.l2_err */
1551	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.l2_err);
1552	/*per_core_stats[core_id].link_stats[ifidx].fromwire.frame_err */
1553	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.frame_err);
1554	/*per_core_stats[cvmx_get_core_num()].link_stats[ifidx].fromwire.
1555	 *fw_err_pko
1556	 */
1557	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_err_pko);
1558	/*per_core_stats[j].link_stats[i].fromwire.fw_err_link */
1559	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_err_link);
1560	/*per_core_stats[cvmx_get_core_num()].link_stats[lro_ctx->ifidx].
1561	 *fromwire.fw_err_drop
1562	 */
1563	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_err_drop);
1564
1565	/*per_core_stats[cvmx_get_core_num()].link_stats[lro_ctx->ifidx].
1566	 *fromwire.fw_rx_vxlan
1567	 */
1568	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_rx_vxlan);
1569	/*per_core_stats[cvmx_get_core_num()].link_stats[lro_ctx->ifidx].
1570	 *fromwire.fw_rx_vxlan_err
1571	 */
1572	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_rx_vxlan_err);
1573
1574	/* LRO */
1575	/*per_core_stats[cvmx_get_core_num()].link_stats[ifidx].fromwire.
1576	 *fw_lro_pkts
1577	 */
1578	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_lro_pkts);
1579	/*per_core_stats[cvmx_get_core_num()].link_stats[ifidx].fromwire.
1580	 *fw_lro_octs
1581	 */
1582	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_lro_octs);
1583	/*per_core_stats[j].link_stats[i].fromwire.fw_total_lro */
1584	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_total_lro);
1585	/*per_core_stats[j].link_stats[i].fromwire.fw_lro_aborts */
1586	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_lro_aborts);
1587	/*per_core_stats[cvmx_get_core_num()].link_stats[ifidx].fromwire.
1588	 *fw_lro_aborts_port
1589	 */
1590	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_lro_aborts_port);
1591	/*per_core_stats[cvmx_get_core_num()].link_stats[ifidx].fromwire.
1592	 *fw_lro_aborts_seq
1593	 */
1594	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_lro_aborts_seq);
1595	/*per_core_stats[cvmx_get_core_num()].link_stats[ifidx].fromwire.
1596	 *fw_lro_aborts_tsval
1597	 */
1598	data[i++] =
1599		CVM_CAST64(oct_dev->link_stats.fromwire.fw_lro_aborts_tsval);
1600	/*per_core_stats[cvmx_get_core_num()].link_stats[ifidx].fromwire.
1601	 *fw_lro_aborts_timer
1602	 */
1603	/* intrmod: packet forward rate */
1604	data[i++] =
1605		CVM_CAST64(oct_dev->link_stats.fromwire.fw_lro_aborts_timer);
1606	/*per_core_stats[j].link_stats[i].fromwire.fw_lro_aborts */
1607	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fwd_rate);
1608
1609	/* mac: link-level stats */
1610	/*CVMX_BGXX_CMRX_RX_STAT0 */
1611	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.total_rcvd);
1612	/*CVMX_BGXX_CMRX_RX_STAT1 */
1613	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.bytes_rcvd);
1614	/*CVMX_PKI_STATX_STAT5 */
1615	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.total_bcst);
1616	/*CVMX_PKI_STATX_STAT5 */
1617	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.total_mcst);
1618	/*wqe->word2.err_code or wqe->word2.err_level */
1619	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.runts);
1620	/*CVMX_BGXX_CMRX_RX_STAT2 */
1621	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.ctl_rcvd);
1622	/*CVMX_BGXX_CMRX_RX_STAT6 */
1623	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fifo_err);
1624	/*CVMX_BGXX_CMRX_RX_STAT4 */
1625	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.dmac_drop);
1626	/*wqe->word2.err_code or wqe->word2.err_level */
1627	data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fcs_err);
1628	/*lio->link_changes*/
1629	data[i++] = CVM_CAST64(lio->link_changes);
1630
1631	for (j = 0; j < MAX_OCTEON_INSTR_QUEUES(oct_dev); j++) {
1632		if (!(oct_dev->io_qmask.iq & BIT_ULL(j)))
1633			continue;
1634		/*packets to network port*/
1635		/*# of packets tx to network */
1636		data[i++] = CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_done);
1637		/*# of bytes tx to network */
1638		data[i++] =
1639			CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_tot_bytes);
1640		/*# of packets dropped */
1641		data[i++] =
1642			CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_dropped);
1643		/*# of tx fails due to queue full */
1644		data[i++] =
1645			CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_iq_busy);
1646		/*XXX gather entries sent */
1647		data[i++] =
1648			CVM_CAST64(oct_dev->instr_queue[j]->stats.sgentry_sent);
1649
1650		/*instruction to firmware: data and control */
1651		/*# of instructions to the queue */
1652		data[i++] =
1653			CVM_CAST64(oct_dev->instr_queue[j]->stats.instr_posted);
1654		/*# of instructions processed */
1655		data[i++] = CVM_CAST64(
1656				oct_dev->instr_queue[j]->stats.instr_processed);
1657		/*# of instructions could not be processed */
1658		data[i++] = CVM_CAST64(
1659				oct_dev->instr_queue[j]->stats.instr_dropped);
1660		/*bytes sent through the queue */
1661		data[i++] =
1662			CVM_CAST64(oct_dev->instr_queue[j]->stats.bytes_sent);
1663
1664		/*tso request*/
1665		data[i++] = CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_gso);
1666		/*vxlan request*/
1667		data[i++] = CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_vxlan);
1668		/*txq restart*/
1669		data[i++] =
1670			CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_restart);
1671	}
1672
1673	/* RX */
1674	for (j = 0; j < MAX_OCTEON_OUTPUT_QUEUES(oct_dev); j++) {
1675		if (!(oct_dev->io_qmask.oq & BIT_ULL(j)))
1676			continue;
1677
1678		/*packets send to TCP/IP network stack */
1679		/*# of packets to network stack */
1680		data[i++] =
1681			CVM_CAST64(oct_dev->droq[j]->stats.rx_pkts_received);
1682		/*# of bytes to network stack */
1683		data[i++] =
1684			CVM_CAST64(oct_dev->droq[j]->stats.rx_bytes_received);
1685		/*# of packets dropped */
1686		data[i++] = CVM_CAST64(oct_dev->droq[j]->stats.dropped_nomem +
1687				       oct_dev->droq[j]->stats.dropped_toomany +
1688				       oct_dev->droq[j]->stats.rx_dropped);
1689		data[i++] =
1690			CVM_CAST64(oct_dev->droq[j]->stats.dropped_nomem);
1691		data[i++] =
1692			CVM_CAST64(oct_dev->droq[j]->stats.dropped_toomany);
1693		data[i++] =
1694			CVM_CAST64(oct_dev->droq[j]->stats.rx_dropped);
1695
1696		/*control and data path*/
1697		data[i++] =
1698			CVM_CAST64(oct_dev->droq[j]->stats.pkts_received);
1699		data[i++] =
1700			CVM_CAST64(oct_dev->droq[j]->stats.bytes_received);
1701		data[i++] =
1702			CVM_CAST64(oct_dev->droq[j]->stats.dropped_nodispatch);
1703
1704		data[i++] =
1705			CVM_CAST64(oct_dev->droq[j]->stats.rx_vxlan);
1706		data[i++] =
1707			CVM_CAST64(oct_dev->droq[j]->stats.rx_alloc_failure);
1708	}
1709}
1710
1711static void lio_vf_get_ethtool_stats(struct net_device *netdev,
1712				     struct ethtool_stats *stats
1713				     __attribute__((unused)),
1714				     u64 *data)
1715{
1716	struct rtnl_link_stats64 lstats;
1717	struct lio *lio = GET_LIO(netdev);
1718	struct octeon_device *oct_dev = lio->oct_dev;
1719	int i = 0, j, vj;
1720
1721	if (ifstate_check(lio, LIO_IFSTATE_RESETTING))
1722		return;
1723
1724	netdev->netdev_ops->ndo_get_stats64(netdev, &lstats);
1725	/* sum of oct->droq[oq_no]->stats->rx_pkts_received */
1726	data[i++] = lstats.rx_packets;
1727	/* sum of oct->instr_queue[iq_no]->stats.tx_done */
1728	data[i++] = lstats.tx_packets;
1729	/* sum of oct->droq[oq_no]->stats->rx_bytes_received */
1730	data[i++] = lstats.rx_bytes;
1731	/* sum of oct->instr_queue[iq_no]->stats.tx_tot_bytes */
1732	data[i++] = lstats.tx_bytes;
1733	data[i++] = lstats.rx_errors;
1734	data[i++] = lstats.tx_errors;
1735	 /* sum of oct->droq[oq_no]->stats->rx_dropped +
1736	  * oct->droq[oq_no]->stats->dropped_nodispatch +
1737	  * oct->droq[oq_no]->stats->dropped_toomany +
1738	  * oct->droq[oq_no]->stats->dropped_nomem
1739	  */
1740	data[i++] = lstats.rx_dropped;
1741	/* sum of oct->instr_queue[iq_no]->stats.tx_dropped */
1742	data[i++] = lstats.tx_dropped +
1743		oct_dev->link_stats.fromhost.fw_err_drop;
1744
1745	data[i++] = oct_dev->link_stats.fromwire.fw_total_mcast;
1746	data[i++] = oct_dev->link_stats.fromhost.fw_total_mcast_sent;
1747	data[i++] = oct_dev->link_stats.fromwire.fw_total_bcast;
1748	data[i++] = oct_dev->link_stats.fromhost.fw_total_bcast_sent;
1749
1750	/* lio->link_changes */
1751	data[i++] = CVM_CAST64(lio->link_changes);
1752
1753	for (vj = 0; vj < oct_dev->num_iqs; vj++) {
1754		j = lio->linfo.txpciq[vj].s.q_no;
1755
1756		/* packets to network port */
1757		/* # of packets tx to network */
1758		data[i++] = CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_done);
1759		 /* # of bytes tx to network */
1760		data[i++] = CVM_CAST64(
1761				oct_dev->instr_queue[j]->stats.tx_tot_bytes);
1762		/* # of packets dropped */
1763		data[i++] = CVM_CAST64(
1764				oct_dev->instr_queue[j]->stats.tx_dropped);
1765		/* # of tx fails due to queue full */
1766		data[i++] = CVM_CAST64(
1767				oct_dev->instr_queue[j]->stats.tx_iq_busy);
1768		/* XXX gather entries sent */
1769		data[i++] = CVM_CAST64(
1770				oct_dev->instr_queue[j]->stats.sgentry_sent);
1771
1772		/* instruction to firmware: data and control */
1773		/* # of instructions to the queue */
1774		data[i++] = CVM_CAST64(
1775				oct_dev->instr_queue[j]->stats.instr_posted);
1776		/* # of instructions processed */
1777		data[i++] =
1778		    CVM_CAST64(oct_dev->instr_queue[j]->stats.instr_processed);
1779		/* # of instructions could not be processed */
1780		data[i++] =
1781		    CVM_CAST64(oct_dev->instr_queue[j]->stats.instr_dropped);
1782		/* bytes sent through the queue */
1783		data[i++] = CVM_CAST64(
1784				oct_dev->instr_queue[j]->stats.bytes_sent);
1785		/* tso request */
1786		data[i++] = CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_gso);
1787		/* vxlan request */
1788		data[i++] = CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_vxlan);
1789		/* txq restart */
1790		data[i++] = CVM_CAST64(
1791				oct_dev->instr_queue[j]->stats.tx_restart);
1792	}
1793
1794	/* RX */
1795	for (vj = 0; vj < oct_dev->num_oqs; vj++) {
1796		j = lio->linfo.rxpciq[vj].s.q_no;
1797
1798		/* packets send to TCP/IP network stack */
1799		/* # of packets to network stack */
1800		data[i++] = CVM_CAST64(
1801				oct_dev->droq[j]->stats.rx_pkts_received);
1802		/* # of bytes to network stack */
1803		data[i++] = CVM_CAST64(
1804				oct_dev->droq[j]->stats.rx_bytes_received);
1805		data[i++] = CVM_CAST64(oct_dev->droq[j]->stats.dropped_nomem +
1806				       oct_dev->droq[j]->stats.dropped_toomany +
1807				       oct_dev->droq[j]->stats.rx_dropped);
1808		data[i++] = CVM_CAST64(oct_dev->droq[j]->stats.dropped_nomem);
1809		data[i++] = CVM_CAST64(oct_dev->droq[j]->stats.dropped_toomany);
1810		data[i++] = CVM_CAST64(oct_dev->droq[j]->stats.rx_dropped);
1811
1812		/* control and data path */
1813		data[i++] = CVM_CAST64(oct_dev->droq[j]->stats.pkts_received);
1814		data[i++] = CVM_CAST64(oct_dev->droq[j]->stats.bytes_received);
1815		data[i++] =
1816			CVM_CAST64(oct_dev->droq[j]->stats.dropped_nodispatch);
1817
1818		data[i++] = CVM_CAST64(oct_dev->droq[j]->stats.rx_vxlan);
1819		data[i++] =
1820		    CVM_CAST64(oct_dev->droq[j]->stats.rx_alloc_failure);
1821	}
1822}
1823
1824static void lio_get_priv_flags_strings(struct lio *lio, u8 *data)
1825{
1826	struct octeon_device *oct_dev = lio->oct_dev;
1827	int i;
1828
1829	switch (oct_dev->chip_id) {
1830	case OCTEON_CN23XX_PF_VID:
1831	case OCTEON_CN23XX_VF_VID:
1832		for (i = 0; i < ARRAY_SIZE(oct_priv_flags_strings); i++) {
1833			sprintf(data, "%s", oct_priv_flags_strings[i]);
1834			data += ETH_GSTRING_LEN;
1835		}
1836		break;
1837	case OCTEON_CN68XX:
1838	case OCTEON_CN66XX:
1839		break;
1840	default:
1841		netif_info(lio, drv, lio->netdev, "Unknown Chip !!\n");
1842		break;
1843	}
1844}
1845
1846static void lio_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
1847{
1848	struct lio *lio = GET_LIO(netdev);
1849	struct octeon_device *oct_dev = lio->oct_dev;
1850	int num_iq_stats, num_oq_stats, i, j;
1851	int num_stats;
1852
1853	switch (stringset) {
1854	case ETH_SS_STATS:
1855		num_stats = ARRAY_SIZE(oct_stats_strings);
1856		for (j = 0; j < num_stats; j++) {
1857			sprintf(data, "%s", oct_stats_strings[j]);
1858			data += ETH_GSTRING_LEN;
1859		}
1860
1861		num_iq_stats = ARRAY_SIZE(oct_iq_stats_strings);
1862		for (i = 0; i < MAX_OCTEON_INSTR_QUEUES(oct_dev); i++) {
1863			if (!(oct_dev->io_qmask.iq & BIT_ULL(i)))
1864				continue;
1865			for (j = 0; j < num_iq_stats; j++) {
1866				sprintf(data, "tx-%d-%s", i,
1867					oct_iq_stats_strings[j]);
1868				data += ETH_GSTRING_LEN;
1869			}
1870		}
1871
1872		num_oq_stats = ARRAY_SIZE(oct_droq_stats_strings);
1873		for (i = 0; i < MAX_OCTEON_OUTPUT_QUEUES(oct_dev); i++) {
1874			if (!(oct_dev->io_qmask.oq & BIT_ULL(i)))
1875				continue;
1876			for (j = 0; j < num_oq_stats; j++) {
1877				sprintf(data, "rx-%d-%s", i,
1878					oct_droq_stats_strings[j]);
1879				data += ETH_GSTRING_LEN;
1880			}
1881		}
1882		break;
1883
1884	case ETH_SS_PRIV_FLAGS:
1885		lio_get_priv_flags_strings(lio, data);
1886		break;
1887	default:
1888		netif_info(lio, drv, lio->netdev, "Unknown Stringset !!\n");
1889		break;
1890	}
1891}
1892
1893static void lio_vf_get_strings(struct net_device *netdev, u32 stringset,
1894			       u8 *data)
1895{
1896	int num_iq_stats, num_oq_stats, i, j;
1897	struct lio *lio = GET_LIO(netdev);
1898	struct octeon_device *oct_dev = lio->oct_dev;
1899	int num_stats;
1900
1901	switch (stringset) {
1902	case ETH_SS_STATS:
1903		num_stats = ARRAY_SIZE(oct_vf_stats_strings);
1904		for (j = 0; j < num_stats; j++) {
1905			sprintf(data, "%s", oct_vf_stats_strings[j]);
1906			data += ETH_GSTRING_LEN;
1907		}
1908
1909		num_iq_stats = ARRAY_SIZE(oct_iq_stats_strings);
1910		for (i = 0; i < MAX_OCTEON_INSTR_QUEUES(oct_dev); i++) {
1911			if (!(oct_dev->io_qmask.iq & BIT_ULL(i)))
1912				continue;
1913			for (j = 0; j < num_iq_stats; j++) {
1914				sprintf(data, "tx-%d-%s", i,
1915					oct_iq_stats_strings[j]);
1916				data += ETH_GSTRING_LEN;
1917			}
1918		}
1919
1920		num_oq_stats = ARRAY_SIZE(oct_droq_stats_strings);
1921		for (i = 0; i < MAX_OCTEON_OUTPUT_QUEUES(oct_dev); i++) {
1922			if (!(oct_dev->io_qmask.oq & BIT_ULL(i)))
1923				continue;
1924			for (j = 0; j < num_oq_stats; j++) {
1925				sprintf(data, "rx-%d-%s", i,
1926					oct_droq_stats_strings[j]);
1927				data += ETH_GSTRING_LEN;
1928			}
1929		}
1930		break;
1931
1932	case ETH_SS_PRIV_FLAGS:
1933		lio_get_priv_flags_strings(lio, data);
1934		break;
1935	default:
1936		netif_info(lio, drv, lio->netdev, "Unknown Stringset !!\n");
1937		break;
1938	}
1939}
1940
1941static int lio_get_priv_flags_ss_count(struct lio *lio)
1942{
1943	struct octeon_device *oct_dev = lio->oct_dev;
1944
1945	switch (oct_dev->chip_id) {
1946	case OCTEON_CN23XX_PF_VID:
1947	case OCTEON_CN23XX_VF_VID:
1948		return ARRAY_SIZE(oct_priv_flags_strings);
1949	case OCTEON_CN68XX:
1950	case OCTEON_CN66XX:
1951		return -EOPNOTSUPP;
1952	default:
1953		netif_info(lio, drv, lio->netdev, "Unknown Chip !!\n");
1954		return -EOPNOTSUPP;
1955	}
1956}
1957
1958static int lio_get_sset_count(struct net_device *netdev, int sset)
1959{
1960	struct lio *lio = GET_LIO(netdev);
1961	struct octeon_device *oct_dev = lio->oct_dev;
1962
1963	switch (sset) {
1964	case ETH_SS_STATS:
1965		return (ARRAY_SIZE(oct_stats_strings) +
1966			ARRAY_SIZE(oct_iq_stats_strings) * oct_dev->num_iqs +
1967			ARRAY_SIZE(oct_droq_stats_strings) * oct_dev->num_oqs);
1968	case ETH_SS_PRIV_FLAGS:
1969		return lio_get_priv_flags_ss_count(lio);
1970	default:
1971		return -EOPNOTSUPP;
1972	}
1973}
1974
1975static int lio_vf_get_sset_count(struct net_device *netdev, int sset)
1976{
1977	struct lio *lio = GET_LIO(netdev);
1978	struct octeon_device *oct_dev = lio->oct_dev;
1979
1980	switch (sset) {
1981	case ETH_SS_STATS:
1982		return (ARRAY_SIZE(oct_vf_stats_strings) +
1983			ARRAY_SIZE(oct_iq_stats_strings) * oct_dev->num_iqs +
1984			ARRAY_SIZE(oct_droq_stats_strings) * oct_dev->num_oqs);
1985	case ETH_SS_PRIV_FLAGS:
1986		return lio_get_priv_flags_ss_count(lio);
1987	default:
1988		return -EOPNOTSUPP;
1989	}
1990}
1991
1992/*  get interrupt moderation parameters */
1993static int octnet_get_intrmod_cfg(struct lio *lio,
1994				  struct oct_intrmod_cfg *intr_cfg)
1995{
1996	struct octeon_soft_command *sc;
1997	struct oct_intrmod_resp *resp;
1998	int retval;
1999	struct octeon_device *oct_dev = lio->oct_dev;
2000
2001	/* Alloc soft command */
2002	sc = (struct octeon_soft_command *)
2003		octeon_alloc_soft_command(oct_dev,
2004					  0,
2005					  sizeof(struct oct_intrmod_resp), 0);
2006
2007	if (!sc)
2008		return -ENOMEM;
2009
2010	resp = (struct oct_intrmod_resp *)sc->virtrptr;
2011	memset(resp, 0, sizeof(struct oct_intrmod_resp));
2012
2013	sc->iq_no = lio->linfo.txpciq[0].s.q_no;
2014
2015	octeon_prepare_soft_command(oct_dev, sc, OPCODE_NIC,
2016				    OPCODE_NIC_INTRMOD_PARAMS, 0, 0, 0);
2017
2018	init_completion(&sc->complete);
2019	sc->sc_status = OCTEON_REQUEST_PENDING;
2020
2021	retval = octeon_send_soft_command(oct_dev, sc);
2022	if (retval == IQ_SEND_FAILED) {
2023		octeon_free_soft_command(oct_dev, sc);
2024		return -EINVAL;
2025	}
2026
2027	/* Sleep on a wait queue till the cond flag indicates that the
2028	 * response arrived or timed-out.
2029	 */
2030	retval = wait_for_sc_completion_timeout(oct_dev, sc, 0);
2031	if (retval)
2032		return -ENODEV;
2033
2034	if (resp->status) {
2035		dev_err(&oct_dev->pci_dev->dev,
2036			"Get interrupt moderation parameters failed\n");
2037		WRITE_ONCE(sc->caller_is_done, true);
2038		return -ENODEV;
2039	}
2040
2041	octeon_swap_8B_data((u64 *)&resp->intrmod,
2042			    (sizeof(struct oct_intrmod_cfg)) / 8);
2043	memcpy(intr_cfg, &resp->intrmod, sizeof(struct oct_intrmod_cfg));
2044	WRITE_ONCE(sc->caller_is_done, true);
2045
2046	return 0;
2047}
2048
2049/*  Configure interrupt moderation parameters */
2050static int octnet_set_intrmod_cfg(struct lio *lio,
2051				  struct oct_intrmod_cfg *intr_cfg)
2052{
2053	struct octeon_soft_command *sc;
2054	struct oct_intrmod_cfg *cfg;
2055	int retval;
2056	struct octeon_device *oct_dev = lio->oct_dev;
2057
2058	/* Alloc soft command */
2059	sc = (struct octeon_soft_command *)
2060		octeon_alloc_soft_command(oct_dev,
2061					  sizeof(struct oct_intrmod_cfg),
2062					  16, 0);
2063
2064	if (!sc)
2065		return -ENOMEM;
2066
2067	cfg = (struct oct_intrmod_cfg *)sc->virtdptr;
2068
2069	memcpy(cfg, intr_cfg, sizeof(struct oct_intrmod_cfg));
2070	octeon_swap_8B_data((u64 *)cfg, (sizeof(struct oct_intrmod_cfg)) / 8);
2071
2072	sc->iq_no = lio->linfo.txpciq[0].s.q_no;
2073
2074	octeon_prepare_soft_command(oct_dev, sc, OPCODE_NIC,
2075				    OPCODE_NIC_INTRMOD_CFG, 0, 0, 0);
2076
2077	init_completion(&sc->complete);
2078	sc->sc_status = OCTEON_REQUEST_PENDING;
2079
2080	retval = octeon_send_soft_command(oct_dev, sc);
2081	if (retval == IQ_SEND_FAILED) {
2082		octeon_free_soft_command(oct_dev, sc);
2083		return -EINVAL;
2084	}
2085
2086	/* Sleep on a wait queue till the cond flag indicates that the
2087	 * response arrived or timed-out.
2088	 */
2089	retval = wait_for_sc_completion_timeout(oct_dev, sc, 0);
2090	if (retval)
2091		return retval;
2092
2093	retval = sc->sc_status;
2094	if (retval == 0) {
2095		dev_info(&oct_dev->pci_dev->dev,
2096			 "Rx-Adaptive Interrupt moderation %s\n",
2097			 (intr_cfg->rx_enable) ?
2098			 "enabled" : "disabled");
2099		WRITE_ONCE(sc->caller_is_done, true);
2100		return 0;
2101	}
2102
2103	dev_err(&oct_dev->pci_dev->dev,
2104		"intrmod config failed. Status: %x\n", retval);
2105	WRITE_ONCE(sc->caller_is_done, true);
2106	return -ENODEV;
2107}
2108
2109static int lio_get_intr_coalesce(struct net_device *netdev,
2110				 struct ethtool_coalesce *intr_coal)
 
 
2111{
2112	struct lio *lio = GET_LIO(netdev);
2113	struct octeon_device *oct = lio->oct_dev;
2114	struct octeon_instr_queue *iq;
2115	struct oct_intrmod_cfg intrmod_cfg;
2116
2117	if (octnet_get_intrmod_cfg(lio, &intrmod_cfg))
2118		return -ENODEV;
2119
2120	switch (oct->chip_id) {
2121	case OCTEON_CN23XX_PF_VID:
2122	case OCTEON_CN23XX_VF_VID: {
2123		if (!intrmod_cfg.rx_enable) {
2124			intr_coal->rx_coalesce_usecs = oct->rx_coalesce_usecs;
2125			intr_coal->rx_max_coalesced_frames =
2126				oct->rx_max_coalesced_frames;
2127		}
2128		if (!intrmod_cfg.tx_enable)
2129			intr_coal->tx_max_coalesced_frames =
2130				oct->tx_max_coalesced_frames;
2131		break;
2132	}
2133	case OCTEON_CN68XX:
2134	case OCTEON_CN66XX: {
2135		struct octeon_cn6xxx *cn6xxx =
2136			(struct octeon_cn6xxx *)oct->chip;
2137
2138		if (!intrmod_cfg.rx_enable) {
2139			intr_coal->rx_coalesce_usecs =
2140				CFG_GET_OQ_INTR_TIME(cn6xxx->conf);
2141			intr_coal->rx_max_coalesced_frames =
2142				CFG_GET_OQ_INTR_PKT(cn6xxx->conf);
2143		}
2144		iq = oct->instr_queue[lio->linfo.txpciq[0].s.q_no];
2145		intr_coal->tx_max_coalesced_frames = iq->fill_threshold;
2146		break;
2147	}
2148	default:
2149		netif_info(lio, drv, lio->netdev, "Unknown Chip !!\n");
2150		return -EINVAL;
2151	}
2152	if (intrmod_cfg.rx_enable) {
2153		intr_coal->use_adaptive_rx_coalesce =
2154			intrmod_cfg.rx_enable;
2155		intr_coal->rate_sample_interval =
2156			intrmod_cfg.check_intrvl;
2157		intr_coal->pkt_rate_high =
2158			intrmod_cfg.maxpkt_ratethr;
2159		intr_coal->pkt_rate_low =
2160			intrmod_cfg.minpkt_ratethr;
2161		intr_coal->rx_max_coalesced_frames_high =
2162			intrmod_cfg.rx_maxcnt_trigger;
2163		intr_coal->rx_coalesce_usecs_high =
2164			intrmod_cfg.rx_maxtmr_trigger;
2165		intr_coal->rx_coalesce_usecs_low =
2166			intrmod_cfg.rx_mintmr_trigger;
2167		intr_coal->rx_max_coalesced_frames_low =
2168			intrmod_cfg.rx_mincnt_trigger;
2169	}
2170	if ((OCTEON_CN23XX_PF(oct) || OCTEON_CN23XX_VF(oct)) &&
2171	    (intrmod_cfg.tx_enable)) {
2172		intr_coal->use_adaptive_tx_coalesce =
2173			intrmod_cfg.tx_enable;
2174		intr_coal->tx_max_coalesced_frames_high =
2175			intrmod_cfg.tx_maxcnt_trigger;
2176		intr_coal->tx_max_coalesced_frames_low =
2177			intrmod_cfg.tx_mincnt_trigger;
2178	}
2179	return 0;
2180}
2181
2182/* Enable/Disable auto interrupt Moderation */
2183static int oct_cfg_adaptive_intr(struct lio *lio,
2184				 struct oct_intrmod_cfg *intrmod_cfg,
2185				 struct ethtool_coalesce *intr_coal)
2186{
2187	int ret = 0;
2188
2189	if (intrmod_cfg->rx_enable || intrmod_cfg->tx_enable) {
2190		intrmod_cfg->check_intrvl = intr_coal->rate_sample_interval;
2191		intrmod_cfg->maxpkt_ratethr = intr_coal->pkt_rate_high;
2192		intrmod_cfg->minpkt_ratethr = intr_coal->pkt_rate_low;
2193	}
2194	if (intrmod_cfg->rx_enable) {
2195		intrmod_cfg->rx_maxcnt_trigger =
2196			intr_coal->rx_max_coalesced_frames_high;
2197		intrmod_cfg->rx_maxtmr_trigger =
2198			intr_coal->rx_coalesce_usecs_high;
2199		intrmod_cfg->rx_mintmr_trigger =
2200			intr_coal->rx_coalesce_usecs_low;
2201		intrmod_cfg->rx_mincnt_trigger =
2202			intr_coal->rx_max_coalesced_frames_low;
2203	}
2204	if (intrmod_cfg->tx_enable) {
2205		intrmod_cfg->tx_maxcnt_trigger =
2206			intr_coal->tx_max_coalesced_frames_high;
2207		intrmod_cfg->tx_mincnt_trigger =
2208			intr_coal->tx_max_coalesced_frames_low;
2209	}
2210
2211	ret = octnet_set_intrmod_cfg(lio, intrmod_cfg);
2212
2213	return ret;
2214}
2215
2216static int
2217oct_cfg_rx_intrcnt(struct lio *lio,
2218		   struct oct_intrmod_cfg *intrmod,
2219		   struct ethtool_coalesce *intr_coal)
2220{
2221	struct octeon_device *oct = lio->oct_dev;
2222	u32 rx_max_coalesced_frames;
2223
2224	/* Config Cnt based interrupt values */
2225	switch (oct->chip_id) {
2226	case OCTEON_CN68XX:
2227	case OCTEON_CN66XX: {
2228		struct octeon_cn6xxx *cn6xxx =
2229			(struct octeon_cn6xxx *)oct->chip;
2230
2231		if (!intr_coal->rx_max_coalesced_frames)
2232			rx_max_coalesced_frames = CN6XXX_OQ_INTR_PKT;
2233		else
2234			rx_max_coalesced_frames =
2235				intr_coal->rx_max_coalesced_frames;
2236		octeon_write_csr(oct, CN6XXX_SLI_OQ_INT_LEVEL_PKTS,
2237				 rx_max_coalesced_frames);
2238		CFG_SET_OQ_INTR_PKT(cn6xxx->conf, rx_max_coalesced_frames);
2239		break;
2240	}
2241	case OCTEON_CN23XX_PF_VID: {
2242		int q_no;
2243
2244		if (!intr_coal->rx_max_coalesced_frames)
2245			rx_max_coalesced_frames = intrmod->rx_frames;
2246		else
2247			rx_max_coalesced_frames =
2248			    intr_coal->rx_max_coalesced_frames;
2249		for (q_no = 0; q_no < oct->num_oqs; q_no++) {
2250			q_no += oct->sriov_info.pf_srn;
2251			octeon_write_csr64(
2252			    oct, CN23XX_SLI_OQ_PKT_INT_LEVELS(q_no),
2253			    (octeon_read_csr64(
2254				 oct, CN23XX_SLI_OQ_PKT_INT_LEVELS(q_no)) &
2255			     (0x3fffff00000000UL)) |
2256				(rx_max_coalesced_frames - 1));
2257			/*consider setting resend bit*/
2258		}
2259		intrmod->rx_frames = rx_max_coalesced_frames;
2260		oct->rx_max_coalesced_frames = rx_max_coalesced_frames;
2261		break;
2262	}
2263	case OCTEON_CN23XX_VF_VID: {
2264		int q_no;
2265
2266		if (!intr_coal->rx_max_coalesced_frames)
2267			rx_max_coalesced_frames = intrmod->rx_frames;
2268		else
2269			rx_max_coalesced_frames =
2270			    intr_coal->rx_max_coalesced_frames;
2271		for (q_no = 0; q_no < oct->num_oqs; q_no++) {
2272			octeon_write_csr64(
2273			    oct, CN23XX_VF_SLI_OQ_PKT_INT_LEVELS(q_no),
2274			    (octeon_read_csr64(
2275				 oct, CN23XX_VF_SLI_OQ_PKT_INT_LEVELS(q_no)) &
2276			     (0x3fffff00000000UL)) |
2277				(rx_max_coalesced_frames - 1));
2278			/*consider writing to resend bit here*/
2279		}
2280		intrmod->rx_frames = rx_max_coalesced_frames;
2281		oct->rx_max_coalesced_frames = rx_max_coalesced_frames;
2282		break;
2283	}
2284	default:
2285		return -EINVAL;
2286	}
2287	return 0;
2288}
2289
2290static int oct_cfg_rx_intrtime(struct lio *lio,
2291			       struct oct_intrmod_cfg *intrmod,
2292			       struct ethtool_coalesce *intr_coal)
2293{
2294	struct octeon_device *oct = lio->oct_dev;
2295	u32 time_threshold, rx_coalesce_usecs;
2296
2297	/* Config Time based interrupt values */
2298	switch (oct->chip_id) {
2299	case OCTEON_CN68XX:
2300	case OCTEON_CN66XX: {
2301		struct octeon_cn6xxx *cn6xxx =
2302			(struct octeon_cn6xxx *)oct->chip;
2303		if (!intr_coal->rx_coalesce_usecs)
2304			rx_coalesce_usecs = CN6XXX_OQ_INTR_TIME;
2305		else
2306			rx_coalesce_usecs = intr_coal->rx_coalesce_usecs;
2307
2308		time_threshold = lio_cn6xxx_get_oq_ticks(oct,
2309							 rx_coalesce_usecs);
2310		octeon_write_csr(oct,
2311				 CN6XXX_SLI_OQ_INT_LEVEL_TIME,
2312				 time_threshold);
2313
2314		CFG_SET_OQ_INTR_TIME(cn6xxx->conf, rx_coalesce_usecs);
2315		break;
2316	}
2317	case OCTEON_CN23XX_PF_VID: {
2318		u64 time_threshold;
2319		int q_no;
2320
2321		if (!intr_coal->rx_coalesce_usecs)
2322			rx_coalesce_usecs = intrmod->rx_usecs;
2323		else
2324			rx_coalesce_usecs = intr_coal->rx_coalesce_usecs;
2325		time_threshold =
2326		    cn23xx_pf_get_oq_ticks(oct, (u32)rx_coalesce_usecs);
2327		for (q_no = 0; q_no < oct->num_oqs; q_no++) {
2328			q_no += oct->sriov_info.pf_srn;
2329			octeon_write_csr64(oct,
2330					   CN23XX_SLI_OQ_PKT_INT_LEVELS(q_no),
2331					   (intrmod->rx_frames |
2332					    ((u64)time_threshold << 32)));
2333			/*consider writing to resend bit here*/
2334		}
2335		intrmod->rx_usecs = rx_coalesce_usecs;
2336		oct->rx_coalesce_usecs = rx_coalesce_usecs;
2337		break;
2338	}
2339	case OCTEON_CN23XX_VF_VID: {
2340		u64 time_threshold;
2341		int q_no;
2342
2343		if (!intr_coal->rx_coalesce_usecs)
2344			rx_coalesce_usecs = intrmod->rx_usecs;
2345		else
2346			rx_coalesce_usecs = intr_coal->rx_coalesce_usecs;
2347
2348		time_threshold =
2349		    cn23xx_vf_get_oq_ticks(oct, (u32)rx_coalesce_usecs);
2350		for (q_no = 0; q_no < oct->num_oqs; q_no++) {
2351			octeon_write_csr64(
2352				oct, CN23XX_VF_SLI_OQ_PKT_INT_LEVELS(q_no),
2353				(intrmod->rx_frames |
2354				 ((u64)time_threshold << 32)));
2355			/*consider setting resend bit*/
2356		}
2357		intrmod->rx_usecs = rx_coalesce_usecs;
2358		oct->rx_coalesce_usecs = rx_coalesce_usecs;
2359		break;
2360	}
2361	default:
2362		return -EINVAL;
2363	}
2364
2365	return 0;
2366}
2367
2368static int
2369oct_cfg_tx_intrcnt(struct lio *lio,
2370		   struct oct_intrmod_cfg *intrmod,
2371		   struct ethtool_coalesce *intr_coal)
2372{
2373	struct octeon_device *oct = lio->oct_dev;
2374	u32 iq_intr_pkt;
2375	void __iomem *inst_cnt_reg;
2376	u64 val;
2377
2378	/* Config Cnt based interrupt values */
2379	switch (oct->chip_id) {
2380	case OCTEON_CN68XX:
2381	case OCTEON_CN66XX:
2382		break;
2383	case OCTEON_CN23XX_VF_VID:
2384	case OCTEON_CN23XX_PF_VID: {
2385		int q_no;
2386
2387		if (!intr_coal->tx_max_coalesced_frames)
2388			iq_intr_pkt = CN23XX_DEF_IQ_INTR_THRESHOLD &
2389				      CN23XX_PKT_IN_DONE_WMARK_MASK;
2390		else
2391			iq_intr_pkt = intr_coal->tx_max_coalesced_frames &
2392				      CN23XX_PKT_IN_DONE_WMARK_MASK;
2393		for (q_no = 0; q_no < oct->num_iqs; q_no++) {
2394			inst_cnt_reg = (oct->instr_queue[q_no])->inst_cnt_reg;
2395			val = readq(inst_cnt_reg);
2396			/*clear wmark and count.dont want to write count back*/
2397			val = (val & 0xFFFF000000000000ULL) |
2398			      ((u64)(iq_intr_pkt - 1)
2399			       << CN23XX_PKT_IN_DONE_WMARK_BIT_POS);
2400			writeq(val, inst_cnt_reg);
2401			/*consider setting resend bit*/
2402		}
2403		intrmod->tx_frames = iq_intr_pkt;
2404		oct->tx_max_coalesced_frames = iq_intr_pkt;
2405		break;
2406	}
2407	default:
2408		return -EINVAL;
2409	}
2410	return 0;
2411}
2412
2413static int lio_set_intr_coalesce(struct net_device *netdev,
2414				 struct ethtool_coalesce *intr_coal)
 
 
2415{
2416	struct lio *lio = GET_LIO(netdev);
2417	int ret;
2418	struct octeon_device *oct = lio->oct_dev;
2419	struct oct_intrmod_cfg intrmod = {0};
2420	u32 j, q_no;
2421	int db_max, db_min;
2422
2423	switch (oct->chip_id) {
2424	case OCTEON_CN68XX:
2425	case OCTEON_CN66XX:
2426		db_min = CN6XXX_DB_MIN;
2427		db_max = CN6XXX_DB_MAX;
2428		if ((intr_coal->tx_max_coalesced_frames >= db_min) &&
2429		    (intr_coal->tx_max_coalesced_frames <= db_max)) {
2430			for (j = 0; j < lio->linfo.num_txpciq; j++) {
2431				q_no = lio->linfo.txpciq[j].s.q_no;
2432				oct->instr_queue[q_no]->fill_threshold =
2433					intr_coal->tx_max_coalesced_frames;
2434			}
2435		} else {
2436			dev_err(&oct->pci_dev->dev,
2437				"LIQUIDIO: Invalid tx-frames:%d. Range is min:%d max:%d\n",
2438				intr_coal->tx_max_coalesced_frames,
2439				db_min, db_max);
2440			return -EINVAL;
2441		}
2442		break;
2443	case OCTEON_CN23XX_PF_VID:
2444	case OCTEON_CN23XX_VF_VID:
2445		break;
2446	default:
2447		return -EINVAL;
2448	}
2449
2450	intrmod.rx_enable = intr_coal->use_adaptive_rx_coalesce ? 1 : 0;
2451	intrmod.tx_enable = intr_coal->use_adaptive_tx_coalesce ? 1 : 0;
2452	intrmod.rx_frames = CFG_GET_OQ_INTR_PKT(octeon_get_conf(oct));
2453	intrmod.rx_usecs = CFG_GET_OQ_INTR_TIME(octeon_get_conf(oct));
2454	intrmod.tx_frames = CFG_GET_IQ_INTR_PKT(octeon_get_conf(oct));
2455
2456	ret = oct_cfg_adaptive_intr(lio, &intrmod, intr_coal);
2457
2458	if (!intr_coal->use_adaptive_rx_coalesce) {
2459		ret = oct_cfg_rx_intrtime(lio, &intrmod, intr_coal);
2460		if (ret)
2461			goto ret_intrmod;
2462
2463		ret = oct_cfg_rx_intrcnt(lio, &intrmod, intr_coal);
2464		if (ret)
2465			goto ret_intrmod;
2466	} else {
2467		oct->rx_coalesce_usecs =
2468			CFG_GET_OQ_INTR_TIME(octeon_get_conf(oct));
2469		oct->rx_max_coalesced_frames =
2470			CFG_GET_OQ_INTR_PKT(octeon_get_conf(oct));
2471	}
2472
2473	if (!intr_coal->use_adaptive_tx_coalesce) {
2474		ret = oct_cfg_tx_intrcnt(lio, &intrmod, intr_coal);
2475		if (ret)
2476			goto ret_intrmod;
2477	} else {
2478		oct->tx_max_coalesced_frames =
2479			CFG_GET_IQ_INTR_PKT(octeon_get_conf(oct));
2480	}
2481
2482	return 0;
2483ret_intrmod:
2484	return ret;
2485}
2486
 
2487static int lio_get_ts_info(struct net_device *netdev,
2488			   struct ethtool_ts_info *info)
2489{
2490	struct lio *lio = GET_LIO(netdev);
2491
2492	info->so_timestamping =
2493#ifdef PTP_HARDWARE_TIMESTAMPING
2494		SOF_TIMESTAMPING_TX_HARDWARE |
2495		SOF_TIMESTAMPING_RX_HARDWARE |
2496		SOF_TIMESTAMPING_RAW_HARDWARE |
2497		SOF_TIMESTAMPING_TX_SOFTWARE |
2498#endif
2499		SOF_TIMESTAMPING_RX_SOFTWARE |
2500		SOF_TIMESTAMPING_SOFTWARE;
2501
2502	if (lio->ptp_clock)
2503		info->phc_index = ptp_clock_index(lio->ptp_clock);
2504	else
2505		info->phc_index = -1;
2506
2507#ifdef PTP_HARDWARE_TIMESTAMPING
2508	info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
2509
2510	info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
2511			   (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
2512			   (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
2513			   (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT);
2514#endif
2515
2516	return 0;
2517}
 
2518
2519/* Return register dump len. */
2520static int lio_get_regs_len(struct net_device *dev)
2521{
2522	struct lio *lio = GET_LIO(dev);
2523	struct octeon_device *oct = lio->oct_dev;
2524
2525	switch (oct->chip_id) {
2526	case OCTEON_CN23XX_PF_VID:
2527		return OCT_ETHTOOL_REGDUMP_LEN_23XX;
2528	case OCTEON_CN23XX_VF_VID:
2529		return OCT_ETHTOOL_REGDUMP_LEN_23XX_VF;
2530	default:
2531		return OCT_ETHTOOL_REGDUMP_LEN;
2532	}
2533}
2534
2535static int cn23xx_read_csr_reg(char *s, struct octeon_device *oct)
2536{
2537	u32 reg;
2538	u8 pf_num = oct->pf_num;
2539	int len = 0;
2540	int i;
2541
2542	/* PCI  Window Registers */
2543
2544	len += sprintf(s + len, "\n\t Octeon CSR Registers\n\n");
2545
2546	/*0x29030 or 0x29040*/
2547	reg = CN23XX_SLI_PKT_MAC_RINFO64(oct->pcie_port, oct->pf_num);
2548	len += sprintf(s + len,
2549		       "\n[%08x] (SLI_PKT_MAC%d_PF%d_RINFO): %016llx\n",
2550		       reg, oct->pcie_port, oct->pf_num,
2551		       (u64)octeon_read_csr64(oct, reg));
2552
2553	/*0x27080 or 0x27090*/
2554	reg = CN23XX_SLI_MAC_PF_INT_ENB64(oct->pcie_port, oct->pf_num);
2555	len +=
2556	    sprintf(s + len, "\n[%08x] (SLI_MAC%d_PF%d_INT_ENB): %016llx\n",
2557		    reg, oct->pcie_port, oct->pf_num,
2558		    (u64)octeon_read_csr64(oct, reg));
2559
2560	/*0x27000 or 0x27010*/
2561	reg = CN23XX_SLI_MAC_PF_INT_SUM64(oct->pcie_port, oct->pf_num);
2562	len +=
2563	    sprintf(s + len, "\n[%08x] (SLI_MAC%d_PF%d_INT_SUM): %016llx\n",
2564		    reg, oct->pcie_port, oct->pf_num,
2565		    (u64)octeon_read_csr64(oct, reg));
2566
2567	/*0x29120*/
2568	reg = 0x29120;
2569	len += sprintf(s + len, "\n[%08x] (SLI_PKT_MEM_CTL): %016llx\n", reg,
2570		       (u64)octeon_read_csr64(oct, reg));
2571
2572	/*0x27300*/
2573	reg = 0x27300 + oct->pcie_port * CN23XX_MAC_INT_OFFSET +
2574	      (oct->pf_num) * CN23XX_PF_INT_OFFSET;
2575	len += sprintf(
2576	    s + len, "\n[%08x] (SLI_MAC%d_PF%d_PKT_VF_INT): %016llx\n", reg,
2577	    oct->pcie_port, oct->pf_num, (u64)octeon_read_csr64(oct, reg));
2578
2579	/*0x27200*/
2580	reg = 0x27200 + oct->pcie_port * CN23XX_MAC_INT_OFFSET +
2581	      (oct->pf_num) * CN23XX_PF_INT_OFFSET;
2582	len += sprintf(s + len,
2583		       "\n[%08x] (SLI_MAC%d_PF%d_PP_VF_INT): %016llx\n",
2584		       reg, oct->pcie_port, oct->pf_num,
2585		       (u64)octeon_read_csr64(oct, reg));
2586
2587	/*29130*/
2588	reg = CN23XX_SLI_PKT_CNT_INT;
2589	len += sprintf(s + len, "\n[%08x] (SLI_PKT_CNT_INT): %016llx\n", reg,
2590		       (u64)octeon_read_csr64(oct, reg));
2591
2592	/*0x29140*/
2593	reg = CN23XX_SLI_PKT_TIME_INT;
2594	len += sprintf(s + len, "\n[%08x] (SLI_PKT_TIME_INT): %016llx\n", reg,
2595		       (u64)octeon_read_csr64(oct, reg));
2596
2597	/*0x29160*/
2598	reg = 0x29160;
2599	len += sprintf(s + len, "\n[%08x] (SLI_PKT_INT): %016llx\n", reg,
2600		       (u64)octeon_read_csr64(oct, reg));
2601
2602	/*0x29180*/
2603	reg = CN23XX_SLI_OQ_WMARK;
2604	len += sprintf(s + len, "\n[%08x] (SLI_PKT_OUTPUT_WMARK): %016llx\n",
2605		       reg, (u64)octeon_read_csr64(oct, reg));
2606
2607	/*0x291E0*/
2608	reg = CN23XX_SLI_PKT_IOQ_RING_RST;
2609	len += sprintf(s + len, "\n[%08x] (SLI_PKT_RING_RST): %016llx\n", reg,
2610		       (u64)octeon_read_csr64(oct, reg));
2611
2612	/*0x29210*/
2613	reg = CN23XX_SLI_GBL_CONTROL;
2614	len += sprintf(s + len,
2615		       "\n[%08x] (SLI_PKT_GBL_CONTROL): %016llx\n", reg,
2616		       (u64)octeon_read_csr64(oct, reg));
2617
2618	/*0x29220*/
2619	reg = 0x29220;
2620	len += sprintf(s + len, "\n[%08x] (SLI_PKT_BIST_STATUS): %016llx\n",
2621		       reg, (u64)octeon_read_csr64(oct, reg));
2622
2623	/*PF only*/
2624	if (pf_num == 0) {
2625		/*0x29260*/
2626		reg = CN23XX_SLI_OUT_BP_EN_W1S;
2627		len += sprintf(s + len,
2628			       "\n[%08x] (SLI_PKT_OUT_BP_EN_W1S):  %016llx\n",
2629			       reg, (u64)octeon_read_csr64(oct, reg));
2630	} else if (pf_num == 1) {
2631		/*0x29270*/
2632		reg = CN23XX_SLI_OUT_BP_EN2_W1S;
2633		len += sprintf(s + len,
2634			       "\n[%08x] (SLI_PKT_OUT_BP_EN2_W1S): %016llx\n",
2635			       reg, (u64)octeon_read_csr64(oct, reg));
2636	}
2637
2638	for (i = 0; i < CN23XX_MAX_OUTPUT_QUEUES; i++) {
2639		reg = CN23XX_SLI_OQ_BUFF_INFO_SIZE(i);
2640		len +=
2641		    sprintf(s + len, "\n[%08x] (SLI_PKT%d_OUT_SIZE): %016llx\n",
2642			    reg, i, (u64)octeon_read_csr64(oct, reg));
2643	}
2644
2645	/*0x10040*/
2646	for (i = 0; i < CN23XX_MAX_INPUT_QUEUES; i++) {
2647		reg = CN23XX_SLI_IQ_INSTR_COUNT64(i);
2648		len += sprintf(s + len,
2649			       "\n[%08x] (SLI_PKT_IN_DONE%d_CNTS): %016llx\n",
2650			       reg, i, (u64)octeon_read_csr64(oct, reg));
2651	}
2652
2653	/*0x10080*/
2654	for (i = 0; i < CN23XX_MAX_OUTPUT_QUEUES; i++) {
2655		reg = CN23XX_SLI_OQ_PKTS_CREDIT(i);
2656		len += sprintf(s + len,
2657			       "\n[%08x] (SLI_PKT%d_SLIST_BAOFF_DBELL): %016llx\n",
2658			       reg, i, (u64)octeon_read_csr64(oct, reg));
2659	}
2660
2661	/*0x10090*/
2662	for (i = 0; i < CN23XX_MAX_OUTPUT_QUEUES; i++) {
2663		reg = CN23XX_SLI_OQ_SIZE(i);
2664		len += sprintf(
2665		    s + len, "\n[%08x] (SLI_PKT%d_SLIST_FIFO_RSIZE): %016llx\n",
2666		    reg, i, (u64)octeon_read_csr64(oct, reg));
2667	}
2668
2669	/*0x10050*/
2670	for (i = 0; i < CN23XX_MAX_OUTPUT_QUEUES; i++) {
2671		reg = CN23XX_SLI_OQ_PKT_CONTROL(i);
2672		len += sprintf(
2673			s + len,
2674			"\n[%08x] (SLI_PKT%d__OUTPUT_CONTROL): %016llx\n",
2675			reg, i, (u64)octeon_read_csr64(oct, reg));
2676	}
2677
2678	/*0x10070*/
2679	for (i = 0; i < CN23XX_MAX_OUTPUT_QUEUES; i++) {
2680		reg = CN23XX_SLI_OQ_BASE_ADDR64(i);
2681		len += sprintf(s + len,
2682			       "\n[%08x] (SLI_PKT%d_SLIST_BADDR): %016llx\n",
2683			       reg, i, (u64)octeon_read_csr64(oct, reg));
2684	}
2685
2686	/*0x100a0*/
2687	for (i = 0; i < CN23XX_MAX_OUTPUT_QUEUES; i++) {
2688		reg = CN23XX_SLI_OQ_PKT_INT_LEVELS(i);
2689		len += sprintf(s + len,
2690			       "\n[%08x] (SLI_PKT%d_INT_LEVELS): %016llx\n",
2691			       reg, i, (u64)octeon_read_csr64(oct, reg));
2692	}
2693
2694	/*0x100b0*/
2695	for (i = 0; i < CN23XX_MAX_OUTPUT_QUEUES; i++) {
2696		reg = CN23XX_SLI_OQ_PKTS_SENT(i);
2697		len += sprintf(s + len, "\n[%08x] (SLI_PKT%d_CNTS): %016llx\n",
2698			       reg, i, (u64)octeon_read_csr64(oct, reg));
2699	}
2700
2701	/*0x100c0*/
2702	for (i = 0; i < CN23XX_MAX_OUTPUT_QUEUES; i++) {
2703		reg = 0x100c0 + i * CN23XX_OQ_OFFSET;
2704		len += sprintf(s + len,
2705			       "\n[%08x] (SLI_PKT%d_ERROR_INFO): %016llx\n",
2706			       reg, i, (u64)octeon_read_csr64(oct, reg));
2707
2708		/*0x10000*/
2709		for (i = 0; i < CN23XX_MAX_INPUT_QUEUES; i++) {
2710			reg = CN23XX_SLI_IQ_PKT_CONTROL64(i);
2711			len += sprintf(
2712				s + len,
2713				"\n[%08x] (SLI_PKT%d_INPUT_CONTROL): %016llx\n",
2714				reg, i, (u64)octeon_read_csr64(oct, reg));
2715		}
2716
2717		/*0x10010*/
2718		for (i = 0; i < CN23XX_MAX_INPUT_QUEUES; i++) {
2719			reg = CN23XX_SLI_IQ_BASE_ADDR64(i);
2720			len += sprintf(
2721			    s + len,
2722			    "\n[%08x] (SLI_PKT%d_INSTR_BADDR): %016llx\n", reg,
2723			    i, (u64)octeon_read_csr64(oct, reg));
2724		}
2725
2726		/*0x10020*/
2727		for (i = 0; i < CN23XX_MAX_INPUT_QUEUES; i++) {
2728			reg = CN23XX_SLI_IQ_DOORBELL(i);
2729			len += sprintf(
2730			    s + len,
2731			    "\n[%08x] (SLI_PKT%d_INSTR_BAOFF_DBELL): %016llx\n",
2732			    reg, i, (u64)octeon_read_csr64(oct, reg));
2733		}
2734
2735		/*0x10030*/
2736		for (i = 0; i < CN23XX_MAX_INPUT_QUEUES; i++) {
2737			reg = CN23XX_SLI_IQ_SIZE(i);
2738			len += sprintf(
2739			    s + len,
2740			    "\n[%08x] (SLI_PKT%d_INSTR_FIFO_RSIZE): %016llx\n",
2741			    reg, i, (u64)octeon_read_csr64(oct, reg));
2742		}
2743
2744		/*0x10040*/
2745		for (i = 0; i < CN23XX_MAX_INPUT_QUEUES; i++)
2746			reg = CN23XX_SLI_IQ_INSTR_COUNT64(i);
2747		len += sprintf(s + len,
2748			       "\n[%08x] (SLI_PKT_IN_DONE%d_CNTS): %016llx\n",
2749			       reg, i, (u64)octeon_read_csr64(oct, reg));
2750	}
2751
2752	return len;
2753}
2754
2755static int cn23xx_vf_read_csr_reg(char *s, struct octeon_device *oct)
2756{
2757	int len = 0;
2758	u32 reg;
2759	int i;
2760
2761	/* PCI  Window Registers */
2762
2763	len += sprintf(s + len, "\n\t Octeon CSR Registers\n\n");
2764
2765	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2766		reg = CN23XX_VF_SLI_OQ_BUFF_INFO_SIZE(i);
2767		len += sprintf(s + len,
2768			       "\n[%08x] (SLI_PKT%d_OUT_SIZE): %016llx\n",
2769			       reg, i, (u64)octeon_read_csr64(oct, reg));
2770	}
2771
2772	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2773		reg = CN23XX_VF_SLI_IQ_INSTR_COUNT64(i);
2774		len += sprintf(s + len,
2775			       "\n[%08x] (SLI_PKT_IN_DONE%d_CNTS): %016llx\n",
2776			       reg, i, (u64)octeon_read_csr64(oct, reg));
2777	}
2778
2779	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2780		reg = CN23XX_VF_SLI_OQ_PKTS_CREDIT(i);
2781		len += sprintf(s + len,
2782			       "\n[%08x] (SLI_PKT%d_SLIST_BAOFF_DBELL): %016llx\n",
2783			       reg, i, (u64)octeon_read_csr64(oct, reg));
2784	}
2785
2786	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2787		reg = CN23XX_VF_SLI_OQ_SIZE(i);
2788		len += sprintf(s + len,
2789			       "\n[%08x] (SLI_PKT%d_SLIST_FIFO_RSIZE): %016llx\n",
2790			       reg, i, (u64)octeon_read_csr64(oct, reg));
2791	}
2792
2793	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2794		reg = CN23XX_VF_SLI_OQ_PKT_CONTROL(i);
2795		len += sprintf(s + len,
2796			       "\n[%08x] (SLI_PKT%d__OUTPUT_CONTROL): %016llx\n",
2797			       reg, i, (u64)octeon_read_csr64(oct, reg));
2798	}
2799
2800	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2801		reg = CN23XX_VF_SLI_OQ_BASE_ADDR64(i);
2802		len += sprintf(s + len,
2803			       "\n[%08x] (SLI_PKT%d_SLIST_BADDR): %016llx\n",
2804			       reg, i, (u64)octeon_read_csr64(oct, reg));
2805	}
2806
2807	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2808		reg = CN23XX_VF_SLI_OQ_PKT_INT_LEVELS(i);
2809		len += sprintf(s + len,
2810			       "\n[%08x] (SLI_PKT%d_INT_LEVELS): %016llx\n",
2811			       reg, i, (u64)octeon_read_csr64(oct, reg));
2812	}
2813
2814	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2815		reg = CN23XX_VF_SLI_OQ_PKTS_SENT(i);
2816		len += sprintf(s + len, "\n[%08x] (SLI_PKT%d_CNTS): %016llx\n",
2817			       reg, i, (u64)octeon_read_csr64(oct, reg));
2818	}
2819
2820	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2821		reg = 0x100c0 + i * CN23XX_VF_OQ_OFFSET;
2822		len += sprintf(s + len,
2823			       "\n[%08x] (SLI_PKT%d_ERROR_INFO): %016llx\n",
2824			       reg, i, (u64)octeon_read_csr64(oct, reg));
2825	}
2826
2827	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2828		reg = 0x100d0 + i * CN23XX_VF_IQ_OFFSET;
2829		len += sprintf(s + len,
2830			       "\n[%08x] (SLI_PKT%d_VF_INT_SUM): %016llx\n",
2831			       reg, i, (u64)octeon_read_csr64(oct, reg));
2832	}
2833
2834	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2835		reg = CN23XX_VF_SLI_IQ_PKT_CONTROL64(i);
2836		len += sprintf(s + len,
2837			       "\n[%08x] (SLI_PKT%d_INPUT_CONTROL): %016llx\n",
2838			       reg, i, (u64)octeon_read_csr64(oct, reg));
2839	}
2840
2841	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2842		reg = CN23XX_VF_SLI_IQ_BASE_ADDR64(i);
2843		len += sprintf(s + len,
2844			       "\n[%08x] (SLI_PKT%d_INSTR_BADDR): %016llx\n",
2845			       reg, i, (u64)octeon_read_csr64(oct, reg));
2846	}
2847
2848	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2849		reg = CN23XX_VF_SLI_IQ_DOORBELL(i);
2850		len += sprintf(s + len,
2851			       "\n[%08x] (SLI_PKT%d_INSTR_BAOFF_DBELL): %016llx\n",
2852			       reg, i, (u64)octeon_read_csr64(oct, reg));
2853	}
2854
2855	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2856		reg = CN23XX_VF_SLI_IQ_SIZE(i);
2857		len += sprintf(s + len,
2858			       "\n[%08x] (SLI_PKT%d_INSTR_FIFO_RSIZE): %016llx\n",
2859			       reg, i, (u64)octeon_read_csr64(oct, reg));
2860	}
2861
2862	for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
2863		reg = CN23XX_VF_SLI_IQ_INSTR_COUNT64(i);
2864		len += sprintf(s + len,
2865			       "\n[%08x] (SLI_PKT_IN_DONE%d_CNTS): %016llx\n",
2866			       reg, i, (u64)octeon_read_csr64(oct, reg));
2867	}
2868
2869	return len;
2870}
2871
2872static int cn6xxx_read_csr_reg(char *s, struct octeon_device *oct)
2873{
2874	u32 reg;
2875	int i, len = 0;
2876
2877	/* PCI  Window Registers */
2878
2879	len += sprintf(s + len, "\n\t Octeon CSR Registers\n\n");
2880	reg = CN6XXX_WIN_WR_ADDR_LO;
2881	len += sprintf(s + len, "\n[%02x] (WIN_WR_ADDR_LO): %08x\n",
2882		       CN6XXX_WIN_WR_ADDR_LO, octeon_read_csr(oct, reg));
2883	reg = CN6XXX_WIN_WR_ADDR_HI;
2884	len += sprintf(s + len, "[%02x] (WIN_WR_ADDR_HI): %08x\n",
2885		       CN6XXX_WIN_WR_ADDR_HI, octeon_read_csr(oct, reg));
2886	reg = CN6XXX_WIN_RD_ADDR_LO;
2887	len += sprintf(s + len, "[%02x] (WIN_RD_ADDR_LO): %08x\n",
2888		       CN6XXX_WIN_RD_ADDR_LO, octeon_read_csr(oct, reg));
2889	reg = CN6XXX_WIN_RD_ADDR_HI;
2890	len += sprintf(s + len, "[%02x] (WIN_RD_ADDR_HI): %08x\n",
2891		       CN6XXX_WIN_RD_ADDR_HI, octeon_read_csr(oct, reg));
2892	reg = CN6XXX_WIN_WR_DATA_LO;
2893	len += sprintf(s + len, "[%02x] (WIN_WR_DATA_LO): %08x\n",
2894		       CN6XXX_WIN_WR_DATA_LO, octeon_read_csr(oct, reg));
2895	reg = CN6XXX_WIN_WR_DATA_HI;
2896	len += sprintf(s + len, "[%02x] (WIN_WR_DATA_HI): %08x\n",
2897		       CN6XXX_WIN_WR_DATA_HI, octeon_read_csr(oct, reg));
2898	len += sprintf(s + len, "[%02x] (WIN_WR_MASK_REG): %08x\n",
2899		       CN6XXX_WIN_WR_MASK_REG,
2900		       octeon_read_csr(oct, CN6XXX_WIN_WR_MASK_REG));
2901
2902	/* PCI  Interrupt Register */
2903	len += sprintf(s + len, "\n[%x] (INT_ENABLE PORT 0): %08x\n",
2904		       CN6XXX_SLI_INT_ENB64_PORT0, octeon_read_csr(oct,
2905						CN6XXX_SLI_INT_ENB64_PORT0));
2906	len += sprintf(s + len, "\n[%x] (INT_ENABLE PORT 1): %08x\n",
2907		       CN6XXX_SLI_INT_ENB64_PORT1,
2908		       octeon_read_csr(oct, CN6XXX_SLI_INT_ENB64_PORT1));
2909	len += sprintf(s + len, "[%x] (INT_SUM): %08x\n", CN6XXX_SLI_INT_SUM64,
2910		       octeon_read_csr(oct, CN6XXX_SLI_INT_SUM64));
2911
2912	/* PCI  Output queue registers */
2913	for (i = 0; i < oct->num_oqs; i++) {
2914		reg = CN6XXX_SLI_OQ_PKTS_SENT(i);
2915		len += sprintf(s + len, "\n[%x] (PKTS_SENT_%d): %08x\n",
2916			       reg, i, octeon_read_csr(oct, reg));
2917		reg = CN6XXX_SLI_OQ_PKTS_CREDIT(i);
2918		len += sprintf(s + len, "[%x] (PKT_CREDITS_%d): %08x\n",
2919			       reg, i, octeon_read_csr(oct, reg));
2920	}
2921	reg = CN6XXX_SLI_OQ_INT_LEVEL_PKTS;
2922	len += sprintf(s + len, "\n[%x] (PKTS_SENT_INT_LEVEL): %08x\n",
2923		       reg, octeon_read_csr(oct, reg));
2924	reg = CN6XXX_SLI_OQ_INT_LEVEL_TIME;
2925	len += sprintf(s + len, "[%x] (PKTS_SENT_TIME): %08x\n",
2926		       reg, octeon_read_csr(oct, reg));
2927
2928	/* PCI  Input queue registers */
2929	for (i = 0; i <= 3; i++) {
2930		u32 reg;
2931
2932		reg = CN6XXX_SLI_IQ_DOORBELL(i);
2933		len += sprintf(s + len, "\n[%x] (INSTR_DOORBELL_%d): %08x\n",
2934			       reg, i, octeon_read_csr(oct, reg));
2935		reg = CN6XXX_SLI_IQ_INSTR_COUNT(i);
2936		len += sprintf(s + len, "[%x] (INSTR_COUNT_%d): %08x\n",
2937			       reg, i, octeon_read_csr(oct, reg));
2938	}
2939
2940	/* PCI  DMA registers */
2941
2942	len += sprintf(s + len, "\n[%x] (DMA_CNT_0): %08x\n",
2943		       CN6XXX_DMA_CNT(0),
2944		       octeon_read_csr(oct, CN6XXX_DMA_CNT(0)));
2945	reg = CN6XXX_DMA_PKT_INT_LEVEL(0);
2946	len += sprintf(s + len, "[%x] (DMA_INT_LEV_0): %08x\n",
2947		       CN6XXX_DMA_PKT_INT_LEVEL(0), octeon_read_csr(oct, reg));
2948	reg = CN6XXX_DMA_TIME_INT_LEVEL(0);
2949	len += sprintf(s + len, "[%x] (DMA_TIME_0): %08x\n",
2950		       CN6XXX_DMA_TIME_INT_LEVEL(0),
2951		       octeon_read_csr(oct, reg));
2952
2953	len += sprintf(s + len, "\n[%x] (DMA_CNT_1): %08x\n",
2954		       CN6XXX_DMA_CNT(1),
2955		       octeon_read_csr(oct, CN6XXX_DMA_CNT(1)));
2956	reg = CN6XXX_DMA_PKT_INT_LEVEL(1);
2957	len += sprintf(s + len, "[%x] (DMA_INT_LEV_1): %08x\n",
2958		       CN6XXX_DMA_PKT_INT_LEVEL(1),
2959		       octeon_read_csr(oct, reg));
2960	reg = CN6XXX_DMA_PKT_INT_LEVEL(1);
2961	len += sprintf(s + len, "[%x] (DMA_TIME_1): %08x\n",
2962		       CN6XXX_DMA_TIME_INT_LEVEL(1),
2963		       octeon_read_csr(oct, reg));
2964
2965	/* PCI  Index registers */
2966
2967	len += sprintf(s + len, "\n");
2968
2969	for (i = 0; i < 16; i++) {
2970		reg = lio_pci_readq(oct, CN6XXX_BAR1_REG(i, oct->pcie_port));
2971		len += sprintf(s + len, "[%llx] (BAR1_INDEX_%02d): %08x\n",
2972			       CN6XXX_BAR1_REG(i, oct->pcie_port), i, reg);
2973	}
2974
2975	return len;
2976}
2977
2978static int cn6xxx_read_config_reg(char *s, struct octeon_device *oct)
2979{
2980	u32 val;
2981	int i, len = 0;
2982
2983	/* PCI CONFIG Registers */
2984
2985	len += sprintf(s + len,
2986		       "\n\t Octeon Config space Registers\n\n");
2987
2988	for (i = 0; i <= 13; i++) {
2989		pci_read_config_dword(oct->pci_dev, (i * 4), &val);
2990		len += sprintf(s + len, "[0x%x] (Config[%d]): 0x%08x\n",
2991			       (i * 4), i, val);
2992	}
2993
2994	for (i = 30; i <= 34; i++) {
2995		pci_read_config_dword(oct->pci_dev, (i * 4), &val);
2996		len += sprintf(s + len, "[0x%x] (Config[%d]): 0x%08x\n",
2997			       (i * 4), i, val);
2998	}
2999
3000	return len;
3001}
3002
3003/*  Return register dump user app.  */
3004static void lio_get_regs(struct net_device *dev,
3005			 struct ethtool_regs *regs, void *regbuf)
3006{
3007	struct lio *lio = GET_LIO(dev);
3008	int len = 0;
3009	struct octeon_device *oct = lio->oct_dev;
3010
3011	regs->version = OCT_ETHTOOL_REGSVER;
3012
3013	switch (oct->chip_id) {
3014	case OCTEON_CN23XX_PF_VID:
3015		memset(regbuf, 0, OCT_ETHTOOL_REGDUMP_LEN_23XX);
3016		len += cn23xx_read_csr_reg(regbuf + len, oct);
3017		break;
3018	case OCTEON_CN23XX_VF_VID:
3019		memset(regbuf, 0, OCT_ETHTOOL_REGDUMP_LEN_23XX_VF);
3020		len += cn23xx_vf_read_csr_reg(regbuf + len, oct);
3021		break;
3022	case OCTEON_CN68XX:
3023	case OCTEON_CN66XX:
3024		memset(regbuf, 0, OCT_ETHTOOL_REGDUMP_LEN);
3025		len += cn6xxx_read_csr_reg(regbuf + len, oct);
3026		len += cn6xxx_read_config_reg(regbuf + len, oct);
3027		break;
3028	default:
3029		dev_err(&oct->pci_dev->dev, "%s Unknown chipid: %d\n",
3030			__func__, oct->chip_id);
3031	}
3032}
3033
3034static u32 lio_get_priv_flags(struct net_device *netdev)
3035{
3036	struct lio *lio = GET_LIO(netdev);
3037
3038	return lio->oct_dev->priv_flags;
3039}
3040
3041static int lio_set_priv_flags(struct net_device *netdev, u32 flags)
3042{
3043	struct lio *lio = GET_LIO(netdev);
3044	bool intr_by_tx_bytes = !!(flags & (0x1 << OCT_PRIV_FLAG_TX_BYTES));
3045
3046	lio_set_priv_flag(lio->oct_dev, OCT_PRIV_FLAG_TX_BYTES,
3047			  intr_by_tx_bytes);
3048	return 0;
3049}
3050
3051static int lio_get_fecparam(struct net_device *netdev,
3052			    struct ethtool_fecparam *fec)
3053{
3054	struct lio *lio = GET_LIO(netdev);
3055	struct octeon_device *oct = lio->oct_dev;
3056
3057	fec->active_fec = ETHTOOL_FEC_NONE;
3058	fec->fec = ETHTOOL_FEC_NONE;
3059
3060	if (oct->subsystem_id == OCTEON_CN2350_25GB_SUBSYS_ID ||
3061	    oct->subsystem_id == OCTEON_CN2360_25GB_SUBSYS_ID) {
3062		if (oct->no_speed_setting == 1)
3063			return 0;
3064
3065		liquidio_get_fec(lio);
3066		fec->fec = (ETHTOOL_FEC_RS | ETHTOOL_FEC_OFF);
3067		if (oct->props[lio->ifidx].fec == 1)
3068			fec->active_fec = ETHTOOL_FEC_RS;
3069		else
3070			fec->active_fec = ETHTOOL_FEC_OFF;
3071	}
3072
3073	return 0;
3074}
3075
3076static int lio_set_fecparam(struct net_device *netdev,
3077			    struct ethtool_fecparam *fec)
3078{
3079	struct lio *lio = GET_LIO(netdev);
3080	struct octeon_device *oct = lio->oct_dev;
3081
3082	if (oct->subsystem_id == OCTEON_CN2350_25GB_SUBSYS_ID ||
3083	    oct->subsystem_id == OCTEON_CN2360_25GB_SUBSYS_ID) {
3084		if (oct->no_speed_setting == 1)
3085			return -EOPNOTSUPP;
3086
3087		if (fec->fec & ETHTOOL_FEC_OFF)
3088			liquidio_set_fec(lio, 0);
3089		else if (fec->fec & ETHTOOL_FEC_RS)
3090			liquidio_set_fec(lio, 1);
3091		else
3092			return -EOPNOTSUPP;
3093	} else {
3094		return -EOPNOTSUPP;
3095	}
3096
3097	return 0;
3098}
3099
3100#define LIO_ETHTOOL_COALESCE	(ETHTOOL_COALESCE_RX_USECS |		\
3101				 ETHTOOL_COALESCE_MAX_FRAMES |		\
3102				 ETHTOOL_COALESCE_USE_ADAPTIVE |	\
3103				 ETHTOOL_COALESCE_RX_MAX_FRAMES_LOW |	\
3104				 ETHTOOL_COALESCE_TX_MAX_FRAMES_LOW |	\
3105				 ETHTOOL_COALESCE_RX_MAX_FRAMES_HIGH |	\
3106				 ETHTOOL_COALESCE_TX_MAX_FRAMES_HIGH |	\
3107				 ETHTOOL_COALESCE_PKT_RATE_RX_USECS)
3108
3109static const struct ethtool_ops lio_ethtool_ops = {
3110	.supported_coalesce_params = LIO_ETHTOOL_COALESCE,
3111	.get_link_ksettings	= lio_get_link_ksettings,
3112	.set_link_ksettings	= lio_set_link_ksettings,
3113	.get_fecparam		= lio_get_fecparam,
3114	.set_fecparam		= lio_set_fecparam,
3115	.get_link		= ethtool_op_get_link,
3116	.get_drvinfo		= lio_get_drvinfo,
3117	.get_ringparam		= lio_ethtool_get_ringparam,
3118	.set_ringparam		= lio_ethtool_set_ringparam,
3119	.get_channels		= lio_ethtool_get_channels,
3120	.set_channels		= lio_ethtool_set_channels,
3121	.set_phys_id		= lio_set_phys_id,
3122	.get_eeprom_len		= lio_get_eeprom_len,
3123	.get_eeprom		= lio_get_eeprom,
3124	.get_strings		= lio_get_strings,
3125	.get_ethtool_stats	= lio_get_ethtool_stats,
3126	.get_pauseparam		= lio_get_pauseparam,
3127	.set_pauseparam		= lio_set_pauseparam,
3128	.get_regs_len		= lio_get_regs_len,
3129	.get_regs		= lio_get_regs,
3130	.get_msglevel		= lio_get_msglevel,
3131	.set_msglevel		= lio_set_msglevel,
3132	.get_sset_count		= lio_get_sset_count,
3133	.get_coalesce		= lio_get_intr_coalesce,
3134	.set_coalesce		= lio_set_intr_coalesce,
3135	.get_priv_flags		= lio_get_priv_flags,
3136	.set_priv_flags		= lio_set_priv_flags,
 
3137	.get_ts_info		= lio_get_ts_info,
 
3138};
3139
3140static const struct ethtool_ops lio_vf_ethtool_ops = {
3141	.supported_coalesce_params = LIO_ETHTOOL_COALESCE,
3142	.get_link_ksettings	= lio_get_link_ksettings,
3143	.get_link		= ethtool_op_get_link,
3144	.get_drvinfo		= lio_get_vf_drvinfo,
3145	.get_ringparam		= lio_ethtool_get_ringparam,
3146	.set_ringparam          = lio_ethtool_set_ringparam,
3147	.get_channels		= lio_ethtool_get_channels,
3148	.set_channels		= lio_ethtool_set_channels,
3149	.get_strings		= lio_vf_get_strings,
3150	.get_ethtool_stats	= lio_vf_get_ethtool_stats,
3151	.get_regs_len		= lio_get_regs_len,
3152	.get_regs		= lio_get_regs,
3153	.get_msglevel		= lio_get_msglevel,
3154	.set_msglevel		= lio_vf_set_msglevel,
3155	.get_sset_count		= lio_vf_get_sset_count,
3156	.get_coalesce		= lio_get_intr_coalesce,
3157	.set_coalesce		= lio_set_intr_coalesce,
3158	.get_priv_flags		= lio_get_priv_flags,
3159	.set_priv_flags		= lio_set_priv_flags,
 
3160	.get_ts_info		= lio_get_ts_info,
 
3161};
3162
3163void liquidio_set_ethtool_ops(struct net_device *netdev)
3164{
3165	struct lio *lio = GET_LIO(netdev);
3166	struct octeon_device *oct = lio->oct_dev;
3167
3168	if (OCTEON_CN23XX_VF(oct))
3169		netdev->ethtool_ops = &lio_vf_ethtool_ops;
3170	else
3171		netdev->ethtool_ops = &lio_ethtool_ops;
3172}