18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * This file is part of the Chelsio T4 PCI-E SR-IOV Virtual Function Ethernet
38c2ecf20Sopenharmony_ci * driver for Linux.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (c) 2009-2010 Chelsio Communications, Inc. All rights reserved.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * This software is available to you under a choice of one of two
88c2ecf20Sopenharmony_ci * licenses.  You may choose to be licensed under the terms of the GNU
98c2ecf20Sopenharmony_ci * General Public License (GPL) Version 2, available from the file
108c2ecf20Sopenharmony_ci * COPYING in the main directory of this source tree, or the
118c2ecf20Sopenharmony_ci * OpenIB.org BSD license below:
128c2ecf20Sopenharmony_ci *
138c2ecf20Sopenharmony_ci *     Redistribution and use in source and binary forms, with or
148c2ecf20Sopenharmony_ci *     without modification, are permitted provided that the following
158c2ecf20Sopenharmony_ci *     conditions are met:
168c2ecf20Sopenharmony_ci *
178c2ecf20Sopenharmony_ci *      - Redistributions of source code must retain the above
188c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
198c2ecf20Sopenharmony_ci *        disclaimer.
208c2ecf20Sopenharmony_ci *
218c2ecf20Sopenharmony_ci *      - Redistributions in binary form must reproduce the above
228c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
238c2ecf20Sopenharmony_ci *        disclaimer in the documentation and/or other materials
248c2ecf20Sopenharmony_ci *        provided with the distribution.
258c2ecf20Sopenharmony_ci *
268c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
278c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
288c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
298c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
308c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
318c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
328c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
338c2ecf20Sopenharmony_ci * SOFTWARE.
348c2ecf20Sopenharmony_ci */
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#ifndef __T4VF_COMMON_H__
378c2ecf20Sopenharmony_ci#define __T4VF_COMMON_H__
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#include "../cxgb4/t4_hw.h"
408c2ecf20Sopenharmony_ci#include "../cxgb4/t4fw_api.h"
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#define CHELSIO_CHIP_CODE(version, revision) (((version) << 4) | (revision))
438c2ecf20Sopenharmony_ci#define CHELSIO_CHIP_VERSION(code) (((code) >> 4) & 0xf)
448c2ecf20Sopenharmony_ci#define CHELSIO_CHIP_RELEASE(code) ((code) & 0xf)
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci/* All T4 and later chips have their PCI-E Device IDs encoded as 0xVFPP where:
478c2ecf20Sopenharmony_ci *
488c2ecf20Sopenharmony_ci *   V  = "4" for T4; "5" for T5, etc. or
498c2ecf20Sopenharmony_ci *      = "a" for T4 FPGA; "b" for T4 FPGA, etc.
508c2ecf20Sopenharmony_ci *   F  = "0" for PF 0..3; "4".."7" for PF4..7; and "8" for VFs
518c2ecf20Sopenharmony_ci *   PP = adapter product designation
528c2ecf20Sopenharmony_ci */
538c2ecf20Sopenharmony_ci#define CHELSIO_T4		0x4
548c2ecf20Sopenharmony_ci#define CHELSIO_T5		0x5
558c2ecf20Sopenharmony_ci#define CHELSIO_T6		0x6
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_cienum chip_type {
588c2ecf20Sopenharmony_ci	T4_A1 = CHELSIO_CHIP_CODE(CHELSIO_T4, 1),
598c2ecf20Sopenharmony_ci	T4_A2 = CHELSIO_CHIP_CODE(CHELSIO_T4, 2),
608c2ecf20Sopenharmony_ci	T4_FIRST_REV	= T4_A1,
618c2ecf20Sopenharmony_ci	T4_LAST_REV	= T4_A2,
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci	T5_A0 = CHELSIO_CHIP_CODE(CHELSIO_T5, 0),
648c2ecf20Sopenharmony_ci	T5_A1 = CHELSIO_CHIP_CODE(CHELSIO_T5, 1),
658c2ecf20Sopenharmony_ci	T5_FIRST_REV	= T5_A0,
668c2ecf20Sopenharmony_ci	T5_LAST_REV	= T5_A1,
678c2ecf20Sopenharmony_ci};
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci/*
708c2ecf20Sopenharmony_ci * The "len16" field of a Firmware Command Structure ...
718c2ecf20Sopenharmony_ci */
728c2ecf20Sopenharmony_ci#define FW_LEN16(fw_struct) FW_CMD_LEN16_V(sizeof(fw_struct) / 16)
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci/*
758c2ecf20Sopenharmony_ci * Per-VF statistics.
768c2ecf20Sopenharmony_ci */
778c2ecf20Sopenharmony_cistruct t4vf_port_stats {
788c2ecf20Sopenharmony_ci	/*
798c2ecf20Sopenharmony_ci	 * TX statistics.
808c2ecf20Sopenharmony_ci	 */
818c2ecf20Sopenharmony_ci	u64 tx_bcast_bytes;		/* broadcast */
828c2ecf20Sopenharmony_ci	u64 tx_bcast_frames;
838c2ecf20Sopenharmony_ci	u64 tx_mcast_bytes;		/* multicast */
848c2ecf20Sopenharmony_ci	u64 tx_mcast_frames;
858c2ecf20Sopenharmony_ci	u64 tx_ucast_bytes;		/* unicast */
868c2ecf20Sopenharmony_ci	u64 tx_ucast_frames;
878c2ecf20Sopenharmony_ci	u64 tx_drop_frames;		/* TX dropped frames */
888c2ecf20Sopenharmony_ci	u64 tx_offload_bytes;		/* offload */
898c2ecf20Sopenharmony_ci	u64 tx_offload_frames;
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci	/*
928c2ecf20Sopenharmony_ci	 * RX statistics.
938c2ecf20Sopenharmony_ci	 */
948c2ecf20Sopenharmony_ci	u64 rx_bcast_bytes;		/* broadcast */
958c2ecf20Sopenharmony_ci	u64 rx_bcast_frames;
968c2ecf20Sopenharmony_ci	u64 rx_mcast_bytes;		/* multicast */
978c2ecf20Sopenharmony_ci	u64 rx_mcast_frames;
988c2ecf20Sopenharmony_ci	u64 rx_ucast_bytes;
998c2ecf20Sopenharmony_ci	u64 rx_ucast_frames;		/* unicast */
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci	u64 rx_err_frames;		/* RX error frames */
1028c2ecf20Sopenharmony_ci};
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci/*
1058c2ecf20Sopenharmony_ci * Per-"port" (Virtual Interface) link configuration ...
1068c2ecf20Sopenharmony_ci */
1078c2ecf20Sopenharmony_citypedef u16 fw_port_cap16_t;    /* 16-bit Port Capabilities integral value */
1088c2ecf20Sopenharmony_citypedef u32 fw_port_cap32_t;    /* 32-bit Port Capabilities integral value */
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_cienum fw_caps {
1118c2ecf20Sopenharmony_ci	FW_CAPS_UNKNOWN	= 0,	/* 0'ed out initial state */
1128c2ecf20Sopenharmony_ci	FW_CAPS16	= 1,	/* old Firmware: 16-bit Port Capabilities */
1138c2ecf20Sopenharmony_ci	FW_CAPS32	= 2,	/* new Firmware: 32-bit Port Capabilities */
1148c2ecf20Sopenharmony_ci};
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_cienum cc_pause {
1178c2ecf20Sopenharmony_ci	PAUSE_RX	= 1 << 0,
1188c2ecf20Sopenharmony_ci	PAUSE_TX	= 1 << 1,
1198c2ecf20Sopenharmony_ci	PAUSE_AUTONEG	= 1 << 2
1208c2ecf20Sopenharmony_ci};
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_cienum cc_fec {
1238c2ecf20Sopenharmony_ci	FEC_AUTO	= 1 << 0,	/* IEEE 802.3 "automatic" */
1248c2ecf20Sopenharmony_ci	FEC_RS		= 1 << 1,	/* Reed-Solomon */
1258c2ecf20Sopenharmony_ci	FEC_BASER_RS	= 1 << 2,	/* BaseR/Reed-Solomon */
1268c2ecf20Sopenharmony_ci};
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_cistruct link_config {
1298c2ecf20Sopenharmony_ci	fw_port_cap32_t pcaps;		/* link capabilities */
1308c2ecf20Sopenharmony_ci	fw_port_cap32_t	acaps;		/* advertised capabilities */
1318c2ecf20Sopenharmony_ci	fw_port_cap32_t	lpacaps;	/* peer advertised capabilities */
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci	fw_port_cap32_t	speed_caps;	/* speed(s) user has requested */
1348c2ecf20Sopenharmony_ci	u32		speed;		/* actual link speed */
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci	enum cc_pause	requested_fc;	/* flow control user has requested */
1378c2ecf20Sopenharmony_ci	enum cc_pause	fc;		/* actual link flow control */
1388c2ecf20Sopenharmony_ci	enum cc_pause   advertised_fc;  /* actual advertised flow control */
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci	enum cc_fec	auto_fec;	/* Forward Error Correction: */
1418c2ecf20Sopenharmony_ci	enum cc_fec	requested_fec;	/*   "automatic" (IEEE 802.3), */
1428c2ecf20Sopenharmony_ci	enum cc_fec	fec;		/*   requested, and actual in use */
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci	unsigned char	autoneg;	/* autonegotiating? */
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci	unsigned char	link_ok;	/* link up? */
1478c2ecf20Sopenharmony_ci	unsigned char	link_down_rc;	/* link down reason */
1488c2ecf20Sopenharmony_ci};
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci/* Return true if the Link Configuration supports "High Speeds" (those greater
1518c2ecf20Sopenharmony_ci * than 1Gb/s).
1528c2ecf20Sopenharmony_ci */
1538c2ecf20Sopenharmony_cistatic inline bool is_x_10g_port(const struct link_config *lc)
1548c2ecf20Sopenharmony_ci{
1558c2ecf20Sopenharmony_ci	fw_port_cap32_t speeds, high_speeds;
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci	speeds = FW_PORT_CAP32_SPEED_V(FW_PORT_CAP32_SPEED_G(lc->pcaps));
1588c2ecf20Sopenharmony_ci	high_speeds =
1598c2ecf20Sopenharmony_ci		speeds & ~(FW_PORT_CAP32_SPEED_100M | FW_PORT_CAP32_SPEED_1G);
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci	return high_speeds != 0;
1628c2ecf20Sopenharmony_ci}
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci/*
1658c2ecf20Sopenharmony_ci * General device parameters ...
1668c2ecf20Sopenharmony_ci */
1678c2ecf20Sopenharmony_cistruct dev_params {
1688c2ecf20Sopenharmony_ci	u32 fwrev;			/* firmware version */
1698c2ecf20Sopenharmony_ci	u32 tprev;			/* TP Microcode Version */
1708c2ecf20Sopenharmony_ci};
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci/*
1738c2ecf20Sopenharmony_ci * Scatter Gather Engine parameters.  These are almost all determined by the
1748c2ecf20Sopenharmony_ci * Physical Function Driver.  We just need to grab them to see within which
1758c2ecf20Sopenharmony_ci * environment we're playing ...
1768c2ecf20Sopenharmony_ci */
1778c2ecf20Sopenharmony_cistruct sge_params {
1788c2ecf20Sopenharmony_ci	u32 sge_control;		/* padding, boundaries, lengths, etc. */
1798c2ecf20Sopenharmony_ci	u32 sge_control2;		/* T5: more of the same */
1808c2ecf20Sopenharmony_ci	u32 sge_host_page_size;		/* PF0-7 page sizes */
1818c2ecf20Sopenharmony_ci	u32 sge_egress_queues_per_page;	/* PF0-7 egress queues/page */
1828c2ecf20Sopenharmony_ci	u32 sge_ingress_queues_per_page;/* PF0-7 ingress queues/page */
1838c2ecf20Sopenharmony_ci	u32 sge_vf_hps;                 /* host page size for our vf */
1848c2ecf20Sopenharmony_ci	u32 sge_vf_eq_qpp;		/* egress queues/page for our VF */
1858c2ecf20Sopenharmony_ci	u32 sge_vf_iq_qpp;		/* ingress queues/page for our VF */
1868c2ecf20Sopenharmony_ci	u32 sge_fl_buffer_size[16];	/* free list buffer sizes */
1878c2ecf20Sopenharmony_ci	u32 sge_ingress_rx_threshold;	/* RX counter interrupt threshold[4] */
1888c2ecf20Sopenharmony_ci	u32 sge_congestion_control;     /* congestion thresholds, etc. */
1898c2ecf20Sopenharmony_ci	u32 sge_timer_value_0_and_1;	/* interrupt coalescing timer values */
1908c2ecf20Sopenharmony_ci	u32 sge_timer_value_2_and_3;
1918c2ecf20Sopenharmony_ci	u32 sge_timer_value_4_and_5;
1928c2ecf20Sopenharmony_ci};
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci/*
1958c2ecf20Sopenharmony_ci * Vital Product Data parameters.
1968c2ecf20Sopenharmony_ci */
1978c2ecf20Sopenharmony_cistruct vpd_params {
1988c2ecf20Sopenharmony_ci	u32 cclk;			/* Core Clock (KHz) */
1998c2ecf20Sopenharmony_ci};
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci/* Stores chip specific parameters */
2028c2ecf20Sopenharmony_cistruct arch_specific_params {
2038c2ecf20Sopenharmony_ci	u32 sge_fl_db;
2048c2ecf20Sopenharmony_ci	u16 mps_tcam_size;
2058c2ecf20Sopenharmony_ci};
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci/*
2088c2ecf20Sopenharmony_ci * Global Receive Side Scaling (RSS) parameters in host-native format.
2098c2ecf20Sopenharmony_ci */
2108c2ecf20Sopenharmony_cistruct rss_params {
2118c2ecf20Sopenharmony_ci	unsigned int mode;		/* RSS mode */
2128c2ecf20Sopenharmony_ci	union {
2138c2ecf20Sopenharmony_ci	    struct {
2148c2ecf20Sopenharmony_ci		unsigned int synmapen:1;	/* SYN Map Enable */
2158c2ecf20Sopenharmony_ci		unsigned int syn4tupenipv6:1;	/* enable hashing 4-tuple IPv6 SYNs */
2168c2ecf20Sopenharmony_ci		unsigned int syn2tupenipv6:1;	/* enable hashing 2-tuple IPv6 SYNs */
2178c2ecf20Sopenharmony_ci		unsigned int syn4tupenipv4:1;	/* enable hashing 4-tuple IPv4 SYNs */
2188c2ecf20Sopenharmony_ci		unsigned int syn2tupenipv4:1;	/* enable hashing 2-tuple IPv4 SYNs */
2198c2ecf20Sopenharmony_ci		unsigned int ofdmapen:1;	/* Offload Map Enable */
2208c2ecf20Sopenharmony_ci		unsigned int tnlmapen:1;	/* Tunnel Map Enable */
2218c2ecf20Sopenharmony_ci		unsigned int tnlalllookup:1;	/* Tunnel All Lookup */
2228c2ecf20Sopenharmony_ci		unsigned int hashtoeplitz:1;	/* use Toeplitz hash */
2238c2ecf20Sopenharmony_ci	    } basicvirtual;
2248c2ecf20Sopenharmony_ci	} u;
2258c2ecf20Sopenharmony_ci};
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_ci/*
2288c2ecf20Sopenharmony_ci * Virtual Interface RSS Configuration in host-native format.
2298c2ecf20Sopenharmony_ci */
2308c2ecf20Sopenharmony_ciunion rss_vi_config {
2318c2ecf20Sopenharmony_ci    struct {
2328c2ecf20Sopenharmony_ci	u16 defaultq;			/* Ingress Queue ID for !tnlalllookup */
2338c2ecf20Sopenharmony_ci	unsigned int ip6fourtupen:1;	/* hash 4-tuple IPv6 ingress packets */
2348c2ecf20Sopenharmony_ci	unsigned int ip6twotupen:1;	/* hash 2-tuple IPv6 ingress packets */
2358c2ecf20Sopenharmony_ci	unsigned int ip4fourtupen:1;	/* hash 4-tuple IPv4 ingress packets */
2368c2ecf20Sopenharmony_ci	unsigned int ip4twotupen:1;	/* hash 2-tuple IPv4 ingress packets */
2378c2ecf20Sopenharmony_ci	int udpen;			/* hash 4-tuple UDP ingress packets */
2388c2ecf20Sopenharmony_ci    } basicvirtual;
2398c2ecf20Sopenharmony_ci};
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_ci/*
2428c2ecf20Sopenharmony_ci * Maximum resources provisioned for a PCI VF.
2438c2ecf20Sopenharmony_ci */
2448c2ecf20Sopenharmony_cistruct vf_resources {
2458c2ecf20Sopenharmony_ci	unsigned int nvi;		/* N virtual interfaces */
2468c2ecf20Sopenharmony_ci	unsigned int neq;		/* N egress Qs */
2478c2ecf20Sopenharmony_ci	unsigned int nethctrl;		/* N egress ETH or CTRL Qs */
2488c2ecf20Sopenharmony_ci	unsigned int niqflint;		/* N ingress Qs/w free list(s) & intr */
2498c2ecf20Sopenharmony_ci	unsigned int niq;		/* N ingress Qs */
2508c2ecf20Sopenharmony_ci	unsigned int tc;		/* PCI-E traffic class */
2518c2ecf20Sopenharmony_ci	unsigned int pmask;		/* port access rights mask */
2528c2ecf20Sopenharmony_ci	unsigned int nexactf;		/* N exact MPS filters */
2538c2ecf20Sopenharmony_ci	unsigned int r_caps;		/* read capabilities */
2548c2ecf20Sopenharmony_ci	unsigned int wx_caps;		/* write/execute capabilities */
2558c2ecf20Sopenharmony_ci};
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci/*
2588c2ecf20Sopenharmony_ci * Per-"adapter" (Virtual Function) parameters.
2598c2ecf20Sopenharmony_ci */
2608c2ecf20Sopenharmony_cistruct adapter_params {
2618c2ecf20Sopenharmony_ci	struct dev_params dev;		/* general device parameters */
2628c2ecf20Sopenharmony_ci	struct sge_params sge;		/* Scatter Gather Engine */
2638c2ecf20Sopenharmony_ci	struct vpd_params vpd;		/* Vital Product Data */
2648c2ecf20Sopenharmony_ci	struct rss_params rss;		/* Receive Side Scaling */
2658c2ecf20Sopenharmony_ci	struct vf_resources vfres;	/* Virtual Function Resource limits */
2668c2ecf20Sopenharmony_ci	struct arch_specific_params arch; /* chip specific params */
2678c2ecf20Sopenharmony_ci	enum chip_type chip;		/* chip code */
2688c2ecf20Sopenharmony_ci	u8 nports;			/* # of Ethernet "ports" */
2698c2ecf20Sopenharmony_ci	u8 fw_caps_support;		/* 32-bit Port Capabilities */
2708c2ecf20Sopenharmony_ci};
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_ci/* Firmware Mailbox Command/Reply log.  All values are in Host-Endian format.
2738c2ecf20Sopenharmony_ci * The access and execute times are signed in order to accommodate negative
2748c2ecf20Sopenharmony_ci * error returns.
2758c2ecf20Sopenharmony_ci */
2768c2ecf20Sopenharmony_cistruct mbox_cmd {
2778c2ecf20Sopenharmony_ci	u64 cmd[MBOX_LEN / 8];		/* a Firmware Mailbox Command/Reply */
2788c2ecf20Sopenharmony_ci	u64 timestamp;			/* OS-dependent timestamp */
2798c2ecf20Sopenharmony_ci	u32 seqno;			/* sequence number */
2808c2ecf20Sopenharmony_ci	s16 access;			/* time (ms) to access mailbox */
2818c2ecf20Sopenharmony_ci	s16 execute;			/* time (ms) to execute */
2828c2ecf20Sopenharmony_ci};
2838c2ecf20Sopenharmony_ci
2848c2ecf20Sopenharmony_cistruct mbox_cmd_log {
2858c2ecf20Sopenharmony_ci	unsigned int size;		/* number of entries in the log */
2868c2ecf20Sopenharmony_ci	unsigned int cursor;		/* next position in the log to write */
2878c2ecf20Sopenharmony_ci	u32 seqno;			/* next sequence number */
2888c2ecf20Sopenharmony_ci	/* variable length mailbox command log starts here */
2898c2ecf20Sopenharmony_ci};
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_ci/* Given a pointer to a Firmware Mailbox Command Log and a log entry index,
2928c2ecf20Sopenharmony_ci * return a pointer to the specified entry.
2938c2ecf20Sopenharmony_ci */
2948c2ecf20Sopenharmony_cistatic inline struct mbox_cmd *mbox_cmd_log_entry(struct mbox_cmd_log *log,
2958c2ecf20Sopenharmony_ci						  unsigned int entry_idx)
2968c2ecf20Sopenharmony_ci{
2978c2ecf20Sopenharmony_ci	return &((struct mbox_cmd *)&(log)[1])[entry_idx];
2988c2ecf20Sopenharmony_ci}
2998c2ecf20Sopenharmony_ci
3008c2ecf20Sopenharmony_ci#include "adapter.h"
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_ci#ifndef PCI_VENDOR_ID_CHELSIO
3038c2ecf20Sopenharmony_ci# define PCI_VENDOR_ID_CHELSIO 0x1425
3048c2ecf20Sopenharmony_ci#endif
3058c2ecf20Sopenharmony_ci
3068c2ecf20Sopenharmony_ci#define for_each_port(adapter, iter) \
3078c2ecf20Sopenharmony_ci	for (iter = 0; iter < (adapter)->params.nports; iter++)
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_cistatic inline unsigned int core_ticks_per_usec(const struct adapter *adapter)
3108c2ecf20Sopenharmony_ci{
3118c2ecf20Sopenharmony_ci	return adapter->params.vpd.cclk / 1000;
3128c2ecf20Sopenharmony_ci}
3138c2ecf20Sopenharmony_ci
3148c2ecf20Sopenharmony_cistatic inline unsigned int us_to_core_ticks(const struct adapter *adapter,
3158c2ecf20Sopenharmony_ci					    unsigned int us)
3168c2ecf20Sopenharmony_ci{
3178c2ecf20Sopenharmony_ci	return (us * adapter->params.vpd.cclk) / 1000;
3188c2ecf20Sopenharmony_ci}
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_cistatic inline unsigned int core_ticks_to_us(const struct adapter *adapter,
3218c2ecf20Sopenharmony_ci					    unsigned int ticks)
3228c2ecf20Sopenharmony_ci{
3238c2ecf20Sopenharmony_ci	return (ticks * 1000) / adapter->params.vpd.cclk;
3248c2ecf20Sopenharmony_ci}
3258c2ecf20Sopenharmony_ci
3268c2ecf20Sopenharmony_ciint t4vf_wr_mbox_core(struct adapter *, const void *, int, void *, bool);
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_cistatic inline int t4vf_wr_mbox(struct adapter *adapter, const void *cmd,
3298c2ecf20Sopenharmony_ci			       int size, void *rpl)
3308c2ecf20Sopenharmony_ci{
3318c2ecf20Sopenharmony_ci	return t4vf_wr_mbox_core(adapter, cmd, size, rpl, true);
3328c2ecf20Sopenharmony_ci}
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_cistatic inline int t4vf_wr_mbox_ns(struct adapter *adapter, const void *cmd,
3358c2ecf20Sopenharmony_ci				  int size, void *rpl)
3368c2ecf20Sopenharmony_ci{
3378c2ecf20Sopenharmony_ci	return t4vf_wr_mbox_core(adapter, cmd, size, rpl, false);
3388c2ecf20Sopenharmony_ci}
3398c2ecf20Sopenharmony_ci
3408c2ecf20Sopenharmony_ci#define CHELSIO_PCI_ID_VER(dev_id)  ((dev_id) >> 12)
3418c2ecf20Sopenharmony_ci
3428c2ecf20Sopenharmony_cistatic inline int is_t4(enum chip_type chip)
3438c2ecf20Sopenharmony_ci{
3448c2ecf20Sopenharmony_ci	return CHELSIO_CHIP_VERSION(chip) == CHELSIO_T4;
3458c2ecf20Sopenharmony_ci}
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ci/**
3488c2ecf20Sopenharmony_ci *	hash_mac_addr - return the hash value of a MAC address
3498c2ecf20Sopenharmony_ci *	@addr: the 48-bit Ethernet MAC address
3508c2ecf20Sopenharmony_ci *
3518c2ecf20Sopenharmony_ci *	Hashes a MAC address according to the hash function used by hardware
3528c2ecf20Sopenharmony_ci *	inexact (hash) address matching.
3538c2ecf20Sopenharmony_ci */
3548c2ecf20Sopenharmony_cistatic inline int hash_mac_addr(const u8 *addr)
3558c2ecf20Sopenharmony_ci{
3568c2ecf20Sopenharmony_ci	u32 a = ((u32)addr[0] << 16) | ((u32)addr[1] << 8) | addr[2];
3578c2ecf20Sopenharmony_ci	u32 b = ((u32)addr[3] << 16) | ((u32)addr[4] << 8) | addr[5];
3588c2ecf20Sopenharmony_ci
3598c2ecf20Sopenharmony_ci	a ^= b;
3608c2ecf20Sopenharmony_ci	a ^= (a >> 12);
3618c2ecf20Sopenharmony_ci	a ^= (a >> 6);
3628c2ecf20Sopenharmony_ci	return a & 0x3f;
3638c2ecf20Sopenharmony_ci}
3648c2ecf20Sopenharmony_ci
3658c2ecf20Sopenharmony_ciint t4vf_wait_dev_ready(struct adapter *);
3668c2ecf20Sopenharmony_ciint t4vf_port_init(struct adapter *, int);
3678c2ecf20Sopenharmony_ci
3688c2ecf20Sopenharmony_ciint t4vf_fw_reset(struct adapter *);
3698c2ecf20Sopenharmony_ciint t4vf_set_params(struct adapter *, unsigned int, const u32 *, const u32 *);
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ciint t4vf_fl_pkt_align(struct adapter *adapter);
3728c2ecf20Sopenharmony_cienum t4_bar2_qtype { T4_BAR2_QTYPE_EGRESS, T4_BAR2_QTYPE_INGRESS };
3738c2ecf20Sopenharmony_ciint t4vf_bar2_sge_qregs(struct adapter *adapter,
3748c2ecf20Sopenharmony_ci			unsigned int qid,
3758c2ecf20Sopenharmony_ci			enum t4_bar2_qtype qtype,
3768c2ecf20Sopenharmony_ci			u64 *pbar2_qoffset,
3778c2ecf20Sopenharmony_ci			unsigned int *pbar2_qid);
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_ciunsigned int t4vf_get_pf_from_vf(struct adapter *);
3808c2ecf20Sopenharmony_ciint t4vf_get_sge_params(struct adapter *);
3818c2ecf20Sopenharmony_ciint t4vf_get_vpd_params(struct adapter *);
3828c2ecf20Sopenharmony_ciint t4vf_get_dev_params(struct adapter *);
3838c2ecf20Sopenharmony_ciint t4vf_get_rss_glb_config(struct adapter *);
3848c2ecf20Sopenharmony_ciint t4vf_get_vfres(struct adapter *);
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_ciint t4vf_read_rss_vi_config(struct adapter *, unsigned int,
3878c2ecf20Sopenharmony_ci			    union rss_vi_config *);
3888c2ecf20Sopenharmony_ciint t4vf_write_rss_vi_config(struct adapter *, unsigned int,
3898c2ecf20Sopenharmony_ci			     union rss_vi_config *);
3908c2ecf20Sopenharmony_ciint t4vf_config_rss_range(struct adapter *, unsigned int, int, int,
3918c2ecf20Sopenharmony_ci			  const u16 *, int);
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_ciint t4vf_alloc_vi(struct adapter *, int);
3948c2ecf20Sopenharmony_ciint t4vf_free_vi(struct adapter *, int);
3958c2ecf20Sopenharmony_ciint t4vf_enable_vi(struct adapter *adapter, unsigned int viid, bool rx_en,
3968c2ecf20Sopenharmony_ci		   bool tx_en);
3978c2ecf20Sopenharmony_ciint t4vf_enable_pi(struct adapter *adapter, struct port_info *pi, bool rx_en,
3988c2ecf20Sopenharmony_ci		   bool tx_en);
3998c2ecf20Sopenharmony_ciint t4vf_identify_port(struct adapter *, unsigned int, unsigned int);
4008c2ecf20Sopenharmony_ci
4018c2ecf20Sopenharmony_ciint t4vf_set_rxmode(struct adapter *, unsigned int, int, int, int, int, int,
4028c2ecf20Sopenharmony_ci		    bool);
4038c2ecf20Sopenharmony_ciint t4vf_alloc_mac_filt(struct adapter *, unsigned int, bool, unsigned int,
4048c2ecf20Sopenharmony_ci			const u8 **, u16 *, u64 *, bool);
4058c2ecf20Sopenharmony_ciint t4vf_free_mac_filt(struct adapter *, unsigned int, unsigned int naddr,
4068c2ecf20Sopenharmony_ci		       const u8 **, bool);
4078c2ecf20Sopenharmony_ciint t4vf_change_mac(struct adapter *, unsigned int, int, const u8 *, bool);
4088c2ecf20Sopenharmony_ciint t4vf_set_addr_hash(struct adapter *, unsigned int, bool, u64, bool);
4098c2ecf20Sopenharmony_ciint t4vf_get_port_stats(struct adapter *, int, struct t4vf_port_stats *);
4108c2ecf20Sopenharmony_ci
4118c2ecf20Sopenharmony_ciint t4vf_iq_free(struct adapter *, unsigned int, unsigned int, unsigned int,
4128c2ecf20Sopenharmony_ci		 unsigned int);
4138c2ecf20Sopenharmony_ciint t4vf_eth_eq_free(struct adapter *, unsigned int);
4148c2ecf20Sopenharmony_ci
4158c2ecf20Sopenharmony_ciint t4vf_update_port_info(struct port_info *pi);
4168c2ecf20Sopenharmony_ciint t4vf_handle_fw_rpl(struct adapter *, const __be64 *);
4178c2ecf20Sopenharmony_ciint t4vf_prep_adapter(struct adapter *);
4188c2ecf20Sopenharmony_ciint t4vf_get_vf_mac_acl(struct adapter *adapter, unsigned int port,
4198c2ecf20Sopenharmony_ci			unsigned int *naddr, u8 *addr);
4208c2ecf20Sopenharmony_ciint t4vf_get_vf_vlan_acl(struct adapter *adapter);
4218c2ecf20Sopenharmony_ci
4228c2ecf20Sopenharmony_ci#endif /* __T4VF_COMMON_H__ */
423