116f8bd4bSCasey Leedom /*
216f8bd4bSCasey Leedom * This file is part of the Chelsio T4 PCI-E SR-IOV Virtual Function Ethernet
316f8bd4bSCasey Leedom * driver for Linux.
416f8bd4bSCasey Leedom *
516f8bd4bSCasey Leedom * Copyright (c) 2009-2010 Chelsio Communications, Inc. All rights reserved.
616f8bd4bSCasey Leedom *
716f8bd4bSCasey Leedom * This software is available to you under a choice of one of two
816f8bd4bSCasey Leedom * licenses. You may choose to be licensed under the terms of the GNU
916f8bd4bSCasey Leedom * General Public License (GPL) Version 2, available from the file
1016f8bd4bSCasey Leedom * COPYING in the main directory of this source tree, or the
1116f8bd4bSCasey Leedom * OpenIB.org BSD license below:
1216f8bd4bSCasey Leedom *
1316f8bd4bSCasey Leedom * Redistribution and use in source and binary forms, with or
1416f8bd4bSCasey Leedom * without modification, are permitted provided that the following
1516f8bd4bSCasey Leedom * conditions are met:
1616f8bd4bSCasey Leedom *
1716f8bd4bSCasey Leedom * - Redistributions of source code must retain the above
1816f8bd4bSCasey Leedom * copyright notice, this list of conditions and the following
1916f8bd4bSCasey Leedom * disclaimer.
2016f8bd4bSCasey Leedom *
2116f8bd4bSCasey Leedom * - Redistributions in binary form must reproduce the above
2216f8bd4bSCasey Leedom * copyright notice, this list of conditions and the following
2316f8bd4bSCasey Leedom * disclaimer in the documentation and/or other materials
2416f8bd4bSCasey Leedom * provided with the distribution.
2516f8bd4bSCasey Leedom *
2616f8bd4bSCasey Leedom * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2716f8bd4bSCasey Leedom * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2816f8bd4bSCasey Leedom * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2916f8bd4bSCasey Leedom * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
3016f8bd4bSCasey Leedom * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
3116f8bd4bSCasey Leedom * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
3216f8bd4bSCasey Leedom * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3316f8bd4bSCasey Leedom * SOFTWARE.
3416f8bd4bSCasey Leedom */
3516f8bd4bSCasey Leedom
3616f8bd4bSCasey Leedom #ifndef __T4VF_COMMON_H__
3716f8bd4bSCasey Leedom #define __T4VF_COMMON_H__
3816f8bd4bSCasey Leedom
39ae7b7576SHariprasad Shenai #include "../cxgb4/t4_hw.h"
4016f8bd4bSCasey Leedom #include "../cxgb4/t4fw_api.h"
4116f8bd4bSCasey Leedom
42622c62b5SSantosh Rastapur #define CHELSIO_CHIP_CODE(version, revision) (((version) << 4) | (revision))
4370ee3666SHariprasad Shenai #define CHELSIO_CHIP_VERSION(code) (((code) >> 4) & 0xf)
44622c62b5SSantosh Rastapur #define CHELSIO_CHIP_RELEASE(code) ((code) & 0xf)
45622c62b5SSantosh Rastapur
4670ee3666SHariprasad Shenai /* All T4 and later chips have their PCI-E Device IDs encoded as 0xVFPP where:
4770ee3666SHariprasad Shenai *
4870ee3666SHariprasad Shenai * V = "4" for T4; "5" for T5, etc. or
4970ee3666SHariprasad Shenai * = "a" for T4 FPGA; "b" for T4 FPGA, etc.
5070ee3666SHariprasad Shenai * F = "0" for PF 0..3; "4".."7" for PF4..7; and "8" for VFs
5170ee3666SHariprasad Shenai * PP = adapter product designation
5270ee3666SHariprasad Shenai */
53622c62b5SSantosh Rastapur #define CHELSIO_T4 0x4
54622c62b5SSantosh Rastapur #define CHELSIO_T5 0x5
5541fc2e41SHariprasad Shenai #define CHELSIO_T6 0x6
56622c62b5SSantosh Rastapur
57622c62b5SSantosh Rastapur enum chip_type {
5870ee3666SHariprasad Shenai T4_A1 = CHELSIO_CHIP_CODE(CHELSIO_T4, 1),
5970ee3666SHariprasad Shenai T4_A2 = CHELSIO_CHIP_CODE(CHELSIO_T4, 2),
60622c62b5SSantosh Rastapur T4_FIRST_REV = T4_A1,
6170ee3666SHariprasad Shenai T4_LAST_REV = T4_A2,
62622c62b5SSantosh Rastapur
6370ee3666SHariprasad Shenai T5_A0 = CHELSIO_CHIP_CODE(CHELSIO_T5, 0),
6470ee3666SHariprasad Shenai T5_A1 = CHELSIO_CHIP_CODE(CHELSIO_T5, 1),
6570ee3666SHariprasad Shenai T5_FIRST_REV = T5_A0,
66622c62b5SSantosh Rastapur T5_LAST_REV = T5_A1,
67622c62b5SSantosh Rastapur };
68622c62b5SSantosh Rastapur
6916f8bd4bSCasey Leedom /*
7016f8bd4bSCasey Leedom * The "len16" field of a Firmware Command Structure ...
7116f8bd4bSCasey Leedom */
72e2ac9628SHariprasad Shenai #define FW_LEN16(fw_struct) FW_CMD_LEN16_V(sizeof(fw_struct) / 16)
7316f8bd4bSCasey Leedom
7416f8bd4bSCasey Leedom /*
7516f8bd4bSCasey Leedom * Per-VF statistics.
7616f8bd4bSCasey Leedom */
7716f8bd4bSCasey Leedom struct t4vf_port_stats {
7816f8bd4bSCasey Leedom /*
7916f8bd4bSCasey Leedom * TX statistics.
8016f8bd4bSCasey Leedom */
8116f8bd4bSCasey Leedom u64 tx_bcast_bytes; /* broadcast */
8216f8bd4bSCasey Leedom u64 tx_bcast_frames;
8316f8bd4bSCasey Leedom u64 tx_mcast_bytes; /* multicast */
8416f8bd4bSCasey Leedom u64 tx_mcast_frames;
8516f8bd4bSCasey Leedom u64 tx_ucast_bytes; /* unicast */
8616f8bd4bSCasey Leedom u64 tx_ucast_frames;
8716f8bd4bSCasey Leedom u64 tx_drop_frames; /* TX dropped frames */
8816f8bd4bSCasey Leedom u64 tx_offload_bytes; /* offload */
8916f8bd4bSCasey Leedom u64 tx_offload_frames;
9016f8bd4bSCasey Leedom
9116f8bd4bSCasey Leedom /*
9216f8bd4bSCasey Leedom * RX statistics.
9316f8bd4bSCasey Leedom */
9416f8bd4bSCasey Leedom u64 rx_bcast_bytes; /* broadcast */
9516f8bd4bSCasey Leedom u64 rx_bcast_frames;
9616f8bd4bSCasey Leedom u64 rx_mcast_bytes; /* multicast */
9716f8bd4bSCasey Leedom u64 rx_mcast_frames;
9816f8bd4bSCasey Leedom u64 rx_ucast_bytes;
9916f8bd4bSCasey Leedom u64 rx_ucast_frames; /* unicast */
10016f8bd4bSCasey Leedom
10116f8bd4bSCasey Leedom u64 rx_err_frames; /* RX error frames */
10216f8bd4bSCasey Leedom };
10316f8bd4bSCasey Leedom
10416f8bd4bSCasey Leedom /*
10516f8bd4bSCasey Leedom * Per-"port" (Virtual Interface) link configuration ...
10616f8bd4bSCasey Leedom */
107c3168cabSGanesh Goudar typedef u16 fw_port_cap16_t; /* 16-bit Port Capabilities integral value */
108c3168cabSGanesh Goudar typedef u32 fw_port_cap32_t; /* 32-bit Port Capabilities integral value */
109c3168cabSGanesh Goudar
110c3168cabSGanesh Goudar enum fw_caps {
111c3168cabSGanesh Goudar FW_CAPS_UNKNOWN = 0, /* 0'ed out initial state */
112c3168cabSGanesh Goudar FW_CAPS16 = 1, /* old Firmware: 16-bit Port Capabilities */
113c3168cabSGanesh Goudar FW_CAPS32 = 2, /* new Firmware: 32-bit Port Capabilities */
11416f8bd4bSCasey Leedom };
11516f8bd4bSCasey Leedom
116c3168cabSGanesh Goudar enum cc_pause {
11716f8bd4bSCasey Leedom PAUSE_RX = 1 << 0,
11816f8bd4bSCasey Leedom PAUSE_TX = 1 << 1,
11916f8bd4bSCasey Leedom PAUSE_AUTONEG = 1 << 2
12016f8bd4bSCasey Leedom };
12116f8bd4bSCasey Leedom
122c3168cabSGanesh Goudar enum cc_fec {
123c3168cabSGanesh Goudar FEC_AUTO = 1 << 0, /* IEEE 802.3 "automatic" */
124c3168cabSGanesh Goudar FEC_RS = 1 << 1, /* Reed-Solomon */
125c3168cabSGanesh Goudar FEC_BASER_RS = 1 << 2, /* BaseR/Reed-Solomon */
126c3168cabSGanesh Goudar };
127c3168cabSGanesh Goudar
128c3168cabSGanesh Goudar struct link_config {
129c3168cabSGanesh Goudar fw_port_cap32_t pcaps; /* link capabilities */
130c3168cabSGanesh Goudar fw_port_cap32_t acaps; /* advertised capabilities */
131c3168cabSGanesh Goudar fw_port_cap32_t lpacaps; /* peer advertised capabilities */
132c3168cabSGanesh Goudar
133c3168cabSGanesh Goudar fw_port_cap32_t speed_caps; /* speed(s) user has requested */
134c3168cabSGanesh Goudar u32 speed; /* actual link speed */
135c3168cabSGanesh Goudar
136c3168cabSGanesh Goudar enum cc_pause requested_fc; /* flow control user has requested */
137c3168cabSGanesh Goudar enum cc_pause fc; /* actual link flow control */
1380caeaf6aSRahul Lakkireddy enum cc_pause advertised_fc; /* actual advertised flow control */
139c3168cabSGanesh Goudar
140c3168cabSGanesh Goudar enum cc_fec auto_fec; /* Forward Error Correction: */
141c3168cabSGanesh Goudar enum cc_fec requested_fec; /* "automatic" (IEEE 802.3), */
142c3168cabSGanesh Goudar enum cc_fec fec; /* requested, and actual in use */
143c3168cabSGanesh Goudar
144c3168cabSGanesh Goudar unsigned char autoneg; /* autonegotiating? */
145c3168cabSGanesh Goudar
146c3168cabSGanesh Goudar unsigned char link_ok; /* link up? */
147c3168cabSGanesh Goudar unsigned char link_down_rc; /* link down reason */
148c3168cabSGanesh Goudar };
149c3168cabSGanesh Goudar
150c3168cabSGanesh Goudar /* Return true if the Link Configuration supports "High Speeds" (those greater
151c3168cabSGanesh Goudar * than 1Gb/s).
152c3168cabSGanesh Goudar */
is_x_10g_port(const struct link_config * lc)153c3168cabSGanesh Goudar static inline bool is_x_10g_port(const struct link_config *lc)
154c3168cabSGanesh Goudar {
155c3168cabSGanesh Goudar fw_port_cap32_t speeds, high_speeds;
156c3168cabSGanesh Goudar
157c3168cabSGanesh Goudar speeds = FW_PORT_CAP32_SPEED_V(FW_PORT_CAP32_SPEED_G(lc->pcaps));
158c3168cabSGanesh Goudar high_speeds =
159c3168cabSGanesh Goudar speeds & ~(FW_PORT_CAP32_SPEED_100M | FW_PORT_CAP32_SPEED_1G);
160c3168cabSGanesh Goudar
161c3168cabSGanesh Goudar return high_speeds != 0;
162c3168cabSGanesh Goudar }
163c3168cabSGanesh Goudar
16416f8bd4bSCasey Leedom /*
16516f8bd4bSCasey Leedom * General device parameters ...
16616f8bd4bSCasey Leedom */
16716f8bd4bSCasey Leedom struct dev_params {
16816f8bd4bSCasey Leedom u32 fwrev; /* firmware version */
16916f8bd4bSCasey Leedom u32 tprev; /* TP Microcode Version */
17016f8bd4bSCasey Leedom };
17116f8bd4bSCasey Leedom
17216f8bd4bSCasey Leedom /*
17316f8bd4bSCasey Leedom * Scatter Gather Engine parameters. These are almost all determined by the
17416f8bd4bSCasey Leedom * Physical Function Driver. We just need to grab them to see within which
17516f8bd4bSCasey Leedom * environment we're playing ...
17616f8bd4bSCasey Leedom */
17716f8bd4bSCasey Leedom struct sge_params {
17816f8bd4bSCasey Leedom u32 sge_control; /* padding, boundaries, lengths, etc. */
179ce8f407aSHariprasad Shenai u32 sge_control2; /* T5: more of the same */
180e0a8b34aSHariprasad Shenai u32 sge_host_page_size; /* PF0-7 page sizes */
181e0a8b34aSHariprasad Shenai u32 sge_egress_queues_per_page; /* PF0-7 egress queues/page */
182e0a8b34aSHariprasad Shenai u32 sge_ingress_queues_per_page;/* PF0-7 ingress queues/page */
183e85c9a7aSHariprasad Shenai u32 sge_vf_hps; /* host page size for our vf */
184e0a8b34aSHariprasad Shenai u32 sge_vf_eq_qpp; /* egress queues/page for our VF */
185e0a8b34aSHariprasad Shenai u32 sge_vf_iq_qpp; /* ingress queues/page for our VF */
18616f8bd4bSCasey Leedom u32 sge_fl_buffer_size[16]; /* free list buffer sizes */
18716f8bd4bSCasey Leedom u32 sge_ingress_rx_threshold; /* RX counter interrupt threshold[4] */
18850d21a66SHariprasad Shenai u32 sge_congestion_control; /* congestion thresholds, etc. */
18916f8bd4bSCasey Leedom u32 sge_timer_value_0_and_1; /* interrupt coalescing timer values */
19016f8bd4bSCasey Leedom u32 sge_timer_value_2_and_3;
19116f8bd4bSCasey Leedom u32 sge_timer_value_4_and_5;
19216f8bd4bSCasey Leedom };
19316f8bd4bSCasey Leedom
19416f8bd4bSCasey Leedom /*
19516f8bd4bSCasey Leedom * Vital Product Data parameters.
19616f8bd4bSCasey Leedom */
19716f8bd4bSCasey Leedom struct vpd_params {
19816f8bd4bSCasey Leedom u32 cclk; /* Core Clock (KHz) */
19916f8bd4bSCasey Leedom };
20016f8bd4bSCasey Leedom
20141fc2e41SHariprasad Shenai /* Stores chip specific parameters */
20241fc2e41SHariprasad Shenai struct arch_specific_params {
20341fc2e41SHariprasad Shenai u32 sge_fl_db;
20441fc2e41SHariprasad Shenai u16 mps_tcam_size;
20541fc2e41SHariprasad Shenai };
20641fc2e41SHariprasad Shenai
20716f8bd4bSCasey Leedom /*
20816f8bd4bSCasey Leedom * Global Receive Side Scaling (RSS) parameters in host-native format.
20916f8bd4bSCasey Leedom */
21016f8bd4bSCasey Leedom struct rss_params {
21116f8bd4bSCasey Leedom unsigned int mode; /* RSS mode */
21216f8bd4bSCasey Leedom union {
21316f8bd4bSCasey Leedom struct {
21465495745SHarvey Harrison unsigned int synmapen:1; /* SYN Map Enable */
21565495745SHarvey Harrison unsigned int syn4tupenipv6:1; /* enable hashing 4-tuple IPv6 SYNs */
21665495745SHarvey Harrison unsigned int syn2tupenipv6:1; /* enable hashing 2-tuple IPv6 SYNs */
21765495745SHarvey Harrison unsigned int syn4tupenipv4:1; /* enable hashing 4-tuple IPv4 SYNs */
21865495745SHarvey Harrison unsigned int syn2tupenipv4:1; /* enable hashing 2-tuple IPv4 SYNs */
21965495745SHarvey Harrison unsigned int ofdmapen:1; /* Offload Map Enable */
22065495745SHarvey Harrison unsigned int tnlmapen:1; /* Tunnel Map Enable */
22165495745SHarvey Harrison unsigned int tnlalllookup:1; /* Tunnel All Lookup */
22265495745SHarvey Harrison unsigned int hashtoeplitz:1; /* use Toeplitz hash */
22316f8bd4bSCasey Leedom } basicvirtual;
22416f8bd4bSCasey Leedom } u;
22516f8bd4bSCasey Leedom };
22616f8bd4bSCasey Leedom
22716f8bd4bSCasey Leedom /*
22816f8bd4bSCasey Leedom * Virtual Interface RSS Configuration in host-native format.
22916f8bd4bSCasey Leedom */
23016f8bd4bSCasey Leedom union rss_vi_config {
23116f8bd4bSCasey Leedom struct {
23216f8bd4bSCasey Leedom u16 defaultq; /* Ingress Queue ID for !tnlalllookup */
23365495745SHarvey Harrison unsigned int ip6fourtupen:1; /* hash 4-tuple IPv6 ingress packets */
23465495745SHarvey Harrison unsigned int ip6twotupen:1; /* hash 2-tuple IPv6 ingress packets */
23565495745SHarvey Harrison unsigned int ip4fourtupen:1; /* hash 4-tuple IPv4 ingress packets */
23665495745SHarvey Harrison unsigned int ip4twotupen:1; /* hash 2-tuple IPv4 ingress packets */
23716f8bd4bSCasey Leedom int udpen; /* hash 4-tuple UDP ingress packets */
23816f8bd4bSCasey Leedom } basicvirtual;
23916f8bd4bSCasey Leedom };
24016f8bd4bSCasey Leedom
24116f8bd4bSCasey Leedom /*
24216f8bd4bSCasey Leedom * Maximum resources provisioned for a PCI VF.
24316f8bd4bSCasey Leedom */
24416f8bd4bSCasey Leedom struct vf_resources {
24516f8bd4bSCasey Leedom unsigned int nvi; /* N virtual interfaces */
24616f8bd4bSCasey Leedom unsigned int neq; /* N egress Qs */
24716f8bd4bSCasey Leedom unsigned int nethctrl; /* N egress ETH or CTRL Qs */
24816f8bd4bSCasey Leedom unsigned int niqflint; /* N ingress Qs/w free list(s) & intr */
24916f8bd4bSCasey Leedom unsigned int niq; /* N ingress Qs */
25016f8bd4bSCasey Leedom unsigned int tc; /* PCI-E traffic class */
25116f8bd4bSCasey Leedom unsigned int pmask; /* port access rights mask */
25216f8bd4bSCasey Leedom unsigned int nexactf; /* N exact MPS filters */
25316f8bd4bSCasey Leedom unsigned int r_caps; /* read capabilities */
25416f8bd4bSCasey Leedom unsigned int wx_caps; /* write/execute capabilities */
25516f8bd4bSCasey Leedom };
25616f8bd4bSCasey Leedom
25716f8bd4bSCasey Leedom /*
25816f8bd4bSCasey Leedom * Per-"adapter" (Virtual Function) parameters.
25916f8bd4bSCasey Leedom */
26016f8bd4bSCasey Leedom struct adapter_params {
26116f8bd4bSCasey Leedom struct dev_params dev; /* general device parameters */
26216f8bd4bSCasey Leedom struct sge_params sge; /* Scatter Gather Engine */
26316f8bd4bSCasey Leedom struct vpd_params vpd; /* Vital Product Data */
26416f8bd4bSCasey Leedom struct rss_params rss; /* Receive Side Scaling */
26516f8bd4bSCasey Leedom struct vf_resources vfres; /* Virtual Function Resource limits */
26641fc2e41SHariprasad Shenai struct arch_specific_params arch; /* chip specific params */
26770ee3666SHariprasad Shenai enum chip_type chip; /* chip code */
26816f8bd4bSCasey Leedom u8 nports; /* # of Ethernet "ports" */
269c3168cabSGanesh Goudar u8 fw_caps_support; /* 32-bit Port Capabilities */
27016f8bd4bSCasey Leedom };
27116f8bd4bSCasey Leedom
272ae7b7576SHariprasad Shenai /* Firmware Mailbox Command/Reply log. All values are in Host-Endian format.
273ae7b7576SHariprasad Shenai * The access and execute times are signed in order to accommodate negative
274ae7b7576SHariprasad Shenai * error returns.
275ae7b7576SHariprasad Shenai */
276ae7b7576SHariprasad Shenai struct mbox_cmd {
277ae7b7576SHariprasad Shenai u64 cmd[MBOX_LEN / 8]; /* a Firmware Mailbox Command/Reply */
278ae7b7576SHariprasad Shenai u64 timestamp; /* OS-dependent timestamp */
279ae7b7576SHariprasad Shenai u32 seqno; /* sequence number */
280ae7b7576SHariprasad Shenai s16 access; /* time (ms) to access mailbox */
281ae7b7576SHariprasad Shenai s16 execute; /* time (ms) to execute */
282ae7b7576SHariprasad Shenai };
283ae7b7576SHariprasad Shenai
284ae7b7576SHariprasad Shenai struct mbox_cmd_log {
285ae7b7576SHariprasad Shenai unsigned int size; /* number of entries in the log */
286ae7b7576SHariprasad Shenai unsigned int cursor; /* next position in the log to write */
287ae7b7576SHariprasad Shenai u32 seqno; /* next sequence number */
288ae7b7576SHariprasad Shenai /* variable length mailbox command log starts here */
289ae7b7576SHariprasad Shenai };
290ae7b7576SHariprasad Shenai
291ae7b7576SHariprasad Shenai /* Given a pointer to a Firmware Mailbox Command Log and a log entry index,
292ae7b7576SHariprasad Shenai * return a pointer to the specified entry.
293ae7b7576SHariprasad Shenai */
mbox_cmd_log_entry(struct mbox_cmd_log * log,unsigned int entry_idx)294ae7b7576SHariprasad Shenai static inline struct mbox_cmd *mbox_cmd_log_entry(struct mbox_cmd_log *log,
295ae7b7576SHariprasad Shenai unsigned int entry_idx)
296ae7b7576SHariprasad Shenai {
297ae7b7576SHariprasad Shenai return &((struct mbox_cmd *)&(log)[1])[entry_idx];
298ae7b7576SHariprasad Shenai }
299ae7b7576SHariprasad Shenai
30016f8bd4bSCasey Leedom #include "adapter.h"
30116f8bd4bSCasey Leedom
30216f8bd4bSCasey Leedom #ifndef PCI_VENDOR_ID_CHELSIO
30316f8bd4bSCasey Leedom # define PCI_VENDOR_ID_CHELSIO 0x1425
30416f8bd4bSCasey Leedom #endif
30516f8bd4bSCasey Leedom
30616f8bd4bSCasey Leedom #define for_each_port(adapter, iter) \
30716f8bd4bSCasey Leedom for (iter = 0; iter < (adapter)->params.nports; iter++)
30816f8bd4bSCasey Leedom
core_ticks_per_usec(const struct adapter * adapter)30916f8bd4bSCasey Leedom static inline unsigned int core_ticks_per_usec(const struct adapter *adapter)
31016f8bd4bSCasey Leedom {
31116f8bd4bSCasey Leedom return adapter->params.vpd.cclk / 1000;
31216f8bd4bSCasey Leedom }
31316f8bd4bSCasey Leedom
us_to_core_ticks(const struct adapter * adapter,unsigned int us)31416f8bd4bSCasey Leedom static inline unsigned int us_to_core_ticks(const struct adapter *adapter,
31516f8bd4bSCasey Leedom unsigned int us)
31616f8bd4bSCasey Leedom {
31716f8bd4bSCasey Leedom return (us * adapter->params.vpd.cclk) / 1000;
31816f8bd4bSCasey Leedom }
31916f8bd4bSCasey Leedom
core_ticks_to_us(const struct adapter * adapter,unsigned int ticks)32016f8bd4bSCasey Leedom static inline unsigned int core_ticks_to_us(const struct adapter *adapter,
32116f8bd4bSCasey Leedom unsigned int ticks)
32216f8bd4bSCasey Leedom {
32316f8bd4bSCasey Leedom return (ticks * 1000) / adapter->params.vpd.cclk;
32416f8bd4bSCasey Leedom }
32516f8bd4bSCasey Leedom
32616f8bd4bSCasey Leedom int t4vf_wr_mbox_core(struct adapter *, const void *, int, void *, bool);
32716f8bd4bSCasey Leedom
t4vf_wr_mbox(struct adapter * adapter,const void * cmd,int size,void * rpl)32816f8bd4bSCasey Leedom static inline int t4vf_wr_mbox(struct adapter *adapter, const void *cmd,
32916f8bd4bSCasey Leedom int size, void *rpl)
33016f8bd4bSCasey Leedom {
33116f8bd4bSCasey Leedom return t4vf_wr_mbox_core(adapter, cmd, size, rpl, true);
33216f8bd4bSCasey Leedom }
33316f8bd4bSCasey Leedom
t4vf_wr_mbox_ns(struct adapter * adapter,const void * cmd,int size,void * rpl)33416f8bd4bSCasey Leedom static inline int t4vf_wr_mbox_ns(struct adapter *adapter, const void *cmd,
33516f8bd4bSCasey Leedom int size, void *rpl)
33616f8bd4bSCasey Leedom {
33716f8bd4bSCasey Leedom return t4vf_wr_mbox_core(adapter, cmd, size, rpl, false);
33816f8bd4bSCasey Leedom }
33916f8bd4bSCasey Leedom
340e0a8b34aSHariprasad Shenai #define CHELSIO_PCI_ID_VER(dev_id) ((dev_id) >> 12)
341e0a8b34aSHariprasad Shenai
is_t4(enum chip_type chip)342622c62b5SSantosh Rastapur static inline int is_t4(enum chip_type chip)
343622c62b5SSantosh Rastapur {
34470ee3666SHariprasad Shenai return CHELSIO_CHIP_VERSION(chip) == CHELSIO_T4;
345622c62b5SSantosh Rastapur }
346622c62b5SSantosh Rastapur
347fe5d2709SHariprasad Shenai /**
348fe5d2709SHariprasad Shenai * hash_mac_addr - return the hash value of a MAC address
349fe5d2709SHariprasad Shenai * @addr: the 48-bit Ethernet MAC address
350fe5d2709SHariprasad Shenai *
351fe5d2709SHariprasad Shenai * Hashes a MAC address according to the hash function used by hardware
352fe5d2709SHariprasad Shenai * inexact (hash) address matching.
353fe5d2709SHariprasad Shenai */
hash_mac_addr(const u8 * addr)354fe5d2709SHariprasad Shenai static inline int hash_mac_addr(const u8 *addr)
355fe5d2709SHariprasad Shenai {
356fe5d2709SHariprasad Shenai u32 a = ((u32)addr[0] << 16) | ((u32)addr[1] << 8) | addr[2];
357fe5d2709SHariprasad Shenai u32 b = ((u32)addr[3] << 16) | ((u32)addr[4] << 8) | addr[5];
358fe5d2709SHariprasad Shenai
359fe5d2709SHariprasad Shenai a ^= b;
360fe5d2709SHariprasad Shenai a ^= (a >> 12);
361fe5d2709SHariprasad Shenai a ^= (a >> 6);
362fe5d2709SHariprasad Shenai return a & 0x3f;
363fe5d2709SHariprasad Shenai }
364fe5d2709SHariprasad Shenai
365d289f864SBill Pemberton int t4vf_wait_dev_ready(struct adapter *);
366d289f864SBill Pemberton int t4vf_port_init(struct adapter *, int);
36716f8bd4bSCasey Leedom
368e68e6133SCasey Leedom int t4vf_fw_reset(struct adapter *);
36916f8bd4bSCasey Leedom int t4vf_set_params(struct adapter *, unsigned int, const u32 *, const u32 *);
37016f8bd4bSCasey Leedom
371cb440364SHariprasad Shenai int t4vf_fl_pkt_align(struct adapter *adapter);
372e85c9a7aSHariprasad Shenai enum t4_bar2_qtype { T4_BAR2_QTYPE_EGRESS, T4_BAR2_QTYPE_INGRESS };
373b2612722SHariprasad Shenai int t4vf_bar2_sge_qregs(struct adapter *adapter,
374e85c9a7aSHariprasad Shenai unsigned int qid,
375e85c9a7aSHariprasad Shenai enum t4_bar2_qtype qtype,
376e85c9a7aSHariprasad Shenai u64 *pbar2_qoffset,
377e85c9a7aSHariprasad Shenai unsigned int *pbar2_qid);
378e85c9a7aSHariprasad Shenai
379858aa65cSHariprasad Shenai unsigned int t4vf_get_pf_from_vf(struct adapter *);
38016f8bd4bSCasey Leedom int t4vf_get_sge_params(struct adapter *);
38116f8bd4bSCasey Leedom int t4vf_get_vpd_params(struct adapter *);
38216f8bd4bSCasey Leedom int t4vf_get_dev_params(struct adapter *);
38316f8bd4bSCasey Leedom int t4vf_get_rss_glb_config(struct adapter *);
38416f8bd4bSCasey Leedom int t4vf_get_vfres(struct adapter *);
38516f8bd4bSCasey Leedom
38616f8bd4bSCasey Leedom int t4vf_read_rss_vi_config(struct adapter *, unsigned int,
38716f8bd4bSCasey Leedom union rss_vi_config *);
38816f8bd4bSCasey Leedom int t4vf_write_rss_vi_config(struct adapter *, unsigned int,
38916f8bd4bSCasey Leedom union rss_vi_config *);
39016f8bd4bSCasey Leedom int t4vf_config_rss_range(struct adapter *, unsigned int, int, int,
39116f8bd4bSCasey Leedom const u16 *, int);
39216f8bd4bSCasey Leedom
39316f8bd4bSCasey Leedom int t4vf_alloc_vi(struct adapter *, int);
39416f8bd4bSCasey Leedom int t4vf_free_vi(struct adapter *, int);
395e2f4f4e9SArjun Vynipadath int t4vf_enable_vi(struct adapter *adapter, unsigned int viid, bool rx_en,
396e2f4f4e9SArjun Vynipadath bool tx_en);
397e2f4f4e9SArjun Vynipadath int t4vf_enable_pi(struct adapter *adapter, struct port_info *pi, bool rx_en,
398e2f4f4e9SArjun Vynipadath bool tx_en);
39916f8bd4bSCasey Leedom int t4vf_identify_port(struct adapter *, unsigned int, unsigned int);
40016f8bd4bSCasey Leedom
40116f8bd4bSCasey Leedom int t4vf_set_rxmode(struct adapter *, unsigned int, int, int, int, int, int,
40216f8bd4bSCasey Leedom bool);
40316f8bd4bSCasey Leedom int t4vf_alloc_mac_filt(struct adapter *, unsigned int, bool, unsigned int,
40416f8bd4bSCasey Leedom const u8 **, u16 *, u64 *, bool);
405fe5d2709SHariprasad Shenai int t4vf_free_mac_filt(struct adapter *, unsigned int, unsigned int naddr,
406fe5d2709SHariprasad Shenai const u8 **, bool);
40716f8bd4bSCasey Leedom int t4vf_change_mac(struct adapter *, unsigned int, int, const u8 *, bool);
40816f8bd4bSCasey Leedom int t4vf_set_addr_hash(struct adapter *, unsigned int, bool, u64, bool);
40916f8bd4bSCasey Leedom int t4vf_get_port_stats(struct adapter *, int, struct t4vf_port_stats *);
41016f8bd4bSCasey Leedom
41116f8bd4bSCasey Leedom int t4vf_iq_free(struct adapter *, unsigned int, unsigned int, unsigned int,
41216f8bd4bSCasey Leedom unsigned int);
41316f8bd4bSCasey Leedom int t4vf_eth_eq_free(struct adapter *, unsigned int);
41416f8bd4bSCasey Leedom
415c3168cabSGanesh Goudar int t4vf_update_port_info(struct port_info *pi);
41616f8bd4bSCasey Leedom int t4vf_handle_fw_rpl(struct adapter *, const __be64 *);
417e0a8b34aSHariprasad Shenai int t4vf_prep_adapter(struct adapter *);
418*e0cdac65SNirranjan Kirubaharan int t4vf_get_vf_mac_acl(struct adapter *adapter, unsigned int port,
419858aa65cSHariprasad Shenai unsigned int *naddr, u8 *addr);
4209d5fd927SGanesh Goudar int t4vf_get_vf_vlan_acl(struct adapter *adapter);
42116f8bd4bSCasey Leedom
42216f8bd4bSCasey Leedom #endif /* __T4VF_COMMON_H__ */
423