xref: /illumos-gate/usr/src/uts/common/io/chxge/com/common.h (revision 2d6eb4a5)
1d39a76e7Sxw /*
2d39a76e7Sxw  * CDDL HEADER START
3d39a76e7Sxw  *
4d39a76e7Sxw  * The contents of this file are subject to the terms of the
5d39a76e7Sxw  * Common Development and Distribution License (the "License").
6d39a76e7Sxw  * You may not use this file except in compliance with the License.
7d39a76e7Sxw  *
8d39a76e7Sxw  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9d39a76e7Sxw  * or http://www.opensolaris.org/os/licensing.
10d39a76e7Sxw  * See the License for the specific language governing permissions
11d39a76e7Sxw  * and limitations under the License.
12d39a76e7Sxw  *
13d39a76e7Sxw  * When distributing Covered Code, include this CDDL HEADER in each
14d39a76e7Sxw  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15d39a76e7Sxw  * If applicable, add the following below this CDDL HEADER, with the
16d39a76e7Sxw  * fields enclosed by brackets "[]" replaced with your own identifying
17d39a76e7Sxw  * information: Portions Copyright [yyyy] [name of copyright owner]
18d39a76e7Sxw  *
19d39a76e7Sxw  * CDDL HEADER END
20d39a76e7Sxw  */
21d39a76e7Sxw 
22d39a76e7Sxw /*
23d39a76e7Sxw  * Copyright (C) 2003-2005 Chelsio Communications.  All rights reserved.
24d39a76e7Sxw  */
25d39a76e7Sxw 
26d39a76e7Sxw #ifndef CHELSIO_COMMON_H
27d39a76e7Sxw #define CHELSIO_COMMON_H
28d39a76e7Sxw 
29d39a76e7Sxw #define DIMOF(x) (sizeof(x)/sizeof(x[0]))
30d39a76e7Sxw 
31d39a76e7Sxw #define NMTUS      8
32d39a76e7Sxw #define MAX_NPORTS 4
33d39a76e7Sxw #define TCB_SIZE   128
34d39a76e7Sxw 
35d39a76e7Sxw enum {
36d39a76e7Sxw 	CHBT_BOARD_7500,
37d39a76e7Sxw 	CHBT_BOARD_8000,
38d39a76e7Sxw 	CHBT_BOARD_CHT101,
39d39a76e7Sxw 	CHBT_BOARD_CHT110,
40d39a76e7Sxw 	CHBT_BOARD_CHT210,
41d39a76e7Sxw 	CHBT_BOARD_CHT204,
42d39a76e7Sxw 	CHBT_BOARD_CHT204V,
43d39a76e7Sxw 	CHBT_BOARD_N110,
44d39a76e7Sxw 	CHBT_BOARD_N210,
45d39a76e7Sxw 	CHBT_BOARD_COUGAR,
46d39a76e7Sxw 	CHBT_BOARD_6800,
47d39a76e7Sxw 	CHBT_BOARD_SIMUL
48d39a76e7Sxw };
49d39a76e7Sxw 
50d39a76e7Sxw enum {
51d39a76e7Sxw 	CHBT_TERM_FPGA,
52d39a76e7Sxw 	CHBT_TERM_T1,
53d39a76e7Sxw 	CHBT_TERM_T2,
54d39a76e7Sxw 	CHBT_TERM_T3
55d39a76e7Sxw };
56d39a76e7Sxw 
57d39a76e7Sxw enum {
58d39a76e7Sxw 	CHBT_MAC_CHELSIO_A,
59d39a76e7Sxw 	CHBT_MAC_IXF1010,
60d39a76e7Sxw 	CHBT_MAC_PM3393,
61d39a76e7Sxw 	CHBT_MAC_VSC7321,
62d39a76e7Sxw 	CHBT_MAC_DUMMY
63d39a76e7Sxw };
64d39a76e7Sxw 
65d39a76e7Sxw enum {
66d39a76e7Sxw 	CHBT_PHY_88E1041,
67d39a76e7Sxw 	CHBT_PHY_88E1111,
68d39a76e7Sxw 	CHBT_PHY_88X2010,
69d39a76e7Sxw 	CHBT_PHY_XPAK,
70d39a76e7Sxw 	CHBT_PHY_MY3126,
71d39a76e7Sxw 	CHBT_PHY_DUMMY
72d39a76e7Sxw };
73d39a76e7Sxw 
74d39a76e7Sxw enum {
75d39a76e7Sxw 	PAUSE_RX = 1,
76d39a76e7Sxw 	PAUSE_TX = 2,
77d39a76e7Sxw 	PAUSE_AUTONEG = 4
78d39a76e7Sxw };
79d39a76e7Sxw 
80d39a76e7Sxw /* Revisions of T1 chip */
81d39a76e7Sxw #define TERM_T1A     0
82d39a76e7Sxw #define TERM_T1B     1
83d39a76e7Sxw #define TERM_T2      3
84d39a76e7Sxw 
85d39a76e7Sxw struct tp_params {
86d39a76e7Sxw 	unsigned int pm_size;
87d39a76e7Sxw 	unsigned int cm_size;
88d39a76e7Sxw         unsigned int pm_rx_base;
89d39a76e7Sxw         unsigned int pm_tx_base;
90d39a76e7Sxw         unsigned int pm_rx_pg_size;
91d39a76e7Sxw         unsigned int pm_tx_pg_size;
92d39a76e7Sxw         unsigned int pm_rx_num_pgs;
93d39a76e7Sxw         unsigned int pm_tx_num_pgs;
94d39a76e7Sxw 	unsigned int use_5tuple_mode;
95d39a76e7Sxw };
96d39a76e7Sxw 
97d39a76e7Sxw struct sge_params {
98d39a76e7Sxw         unsigned int cmdQ_size[2];
99d39a76e7Sxw         unsigned int freelQ_size[2];
100d39a76e7Sxw 	unsigned int large_buf_capacity;
101d39a76e7Sxw 	unsigned int rx_coalesce_usecs;
102d39a76e7Sxw 	unsigned int last_rx_coalesce_raw;
103d39a76e7Sxw 	unsigned int default_rx_coalesce_usecs;
104d39a76e7Sxw 	unsigned int sample_interval_usecs;
105d39a76e7Sxw 	unsigned int coalesce_enable;
106d39a76e7Sxw 	unsigned int polling;
107d39a76e7Sxw };
108d39a76e7Sxw 
109d39a76e7Sxw struct mc5_params {
110d39a76e7Sxw 	unsigned int mode;       /* selects MC5 width */
111d39a76e7Sxw 	unsigned int nservers;   /* size of server region */
112d39a76e7Sxw 	unsigned int nroutes;    /* size of routing region */
113d39a76e7Sxw };
114d39a76e7Sxw 
115d39a76e7Sxw /* Default MC5 region sizes */
116d39a76e7Sxw #define DEFAULT_SERVER_REGION_LEN 256
117d39a76e7Sxw #define DEFAULT_RT_REGION_LEN 1024
118d39a76e7Sxw 
119d39a76e7Sxw struct pci_params {
120d39a76e7Sxw 	unsigned short speed;
121d39a76e7Sxw 	unsigned char  width;
122d39a76e7Sxw 	unsigned char  is_pcix;
123d39a76e7Sxw };
124*2d6eb4a5SToomas Soome 
125d39a76e7Sxw struct adapter_params {
126d39a76e7Sxw 	struct sge_params sge;
127d39a76e7Sxw 	struct mc5_params mc5;
128d39a76e7Sxw 	struct tp_params  tp;
129d39a76e7Sxw 	struct pci_params pci;
130d39a76e7Sxw 
131d39a76e7Sxw 	const struct board_info *brd_info;
132d39a76e7Sxw 
133d39a76e7Sxw 	unsigned short mtus[NMTUS];
134d39a76e7Sxw 	unsigned int   nports;         /* # of ethernet ports */
135d39a76e7Sxw 	unsigned int   stats_update_period;
136d39a76e7Sxw 	unsigned short chip_revision;
137d39a76e7Sxw 	unsigned char  chip_version;
138d39a76e7Sxw 	unsigned char  is_asic;
139d39a76e7Sxw };
140*2d6eb4a5SToomas Soome 
141d39a76e7Sxw struct pci_err_cnt {
142d39a76e7Sxw 	unsigned int master_parity_err;
143d39a76e7Sxw 	unsigned int sig_target_abort;
144d39a76e7Sxw 	unsigned int rcv_target_abort;
145d39a76e7Sxw 	unsigned int rcv_master_abort;
146d39a76e7Sxw 	unsigned int sig_sys_err;
147d39a76e7Sxw 	unsigned int det_parity_err;
148d39a76e7Sxw 	unsigned int pio_parity_err;
149d39a76e7Sxw 	unsigned int wf_parity_err;
150d39a76e7Sxw 	unsigned int rf_parity_err;
151d39a76e7Sxw 	unsigned int cf_parity_err;
152d39a76e7Sxw };
153d39a76e7Sxw 
154d39a76e7Sxw struct link_config {
155d39a76e7Sxw 	unsigned int   supported;        /* link capabilities */
156d39a76e7Sxw 	unsigned int   advertising;      /* advertised capabilities */
157d39a76e7Sxw         unsigned short requested_speed;  /* speed user has requested */
158d39a76e7Sxw 	unsigned short speed;            /* actual link speed */
159d39a76e7Sxw         unsigned char  requested_duplex; /* duplex user has requested */
160d39a76e7Sxw 	unsigned char  duplex;           /* actual link duplex */
161d39a76e7Sxw 	unsigned char  requested_fc;     /* flow control user has requested */
162d39a76e7Sxw 	unsigned char  fc;               /* actual link flow control */
163d39a76e7Sxw 	unsigned char  autoneg;          /* autonegotiating? */
164d39a76e7Sxw };
165d39a76e7Sxw 
166d39a76e7Sxw #define SPEED_INVALID   0xffff
167d39a76e7Sxw #define DUPLEX_INVALID  0xff
168d39a76e7Sxw 
169d39a76e7Sxw struct mdio_ops;
170d39a76e7Sxw struct gmac;
171d39a76e7Sxw struct gphy;
172d39a76e7Sxw 
173d39a76e7Sxw struct board_info {
174d39a76e7Sxw 	unsigned char           board;
175d39a76e7Sxw 	unsigned char           port_number;
176d39a76e7Sxw 	unsigned long           caps;
177d39a76e7Sxw 	unsigned char           chip_term;
178d39a76e7Sxw 	unsigned char           chip_mac;
179d39a76e7Sxw 	unsigned char           chip_phy;
180d39a76e7Sxw 	unsigned int            clock_core;
181d39a76e7Sxw 	unsigned int            clock_mc3;
182d39a76e7Sxw 	unsigned int            clock_mc4;
183d39a76e7Sxw 	unsigned int            espi_nports;
184d39a76e7Sxw 	unsigned int            clock_cspi;
185d39a76e7Sxw 	unsigned int            clock_elmer0;
186d39a76e7Sxw 	unsigned char           mdio_mdien;
187d39a76e7Sxw 	unsigned char           mdio_mdiinv;
188d39a76e7Sxw 	unsigned char           mdio_mdc;
189d39a76e7Sxw 	unsigned char           mdio_phybaseaddr;
190d39a76e7Sxw 	struct gmac            *gmac;
191d39a76e7Sxw 	struct gphy            *gphy;
192d39a76e7Sxw 	struct mdio_ops	       *mdio_ops;
193d39a76e7Sxw 	const char             *desc;
194d39a76e7Sxw };
195d39a76e7Sxw 
196d39a76e7Sxw #include "osdep.h"
197d39a76e7Sxw 
198d39a76e7Sxw #ifndef PCI_VENDOR_ID_CHELSIO
199d39a76e7Sxw #define PCI_VENDOR_ID_CHELSIO 0x1425
200d39a76e7Sxw #endif
201d39a76e7Sxw 
202d39a76e7Sxw extern struct pci_device_id t1_pci_tbl[];
203d39a76e7Sxw 
t1_is_asic(const adapter_t * adapter)204d39a76e7Sxw static inline int t1_is_asic(const adapter_t *adapter)
205d39a76e7Sxw {
206d39a76e7Sxw 	return adapter->params.is_asic;
207d39a76e7Sxw }
208d39a76e7Sxw 
adapter_matches_type(const adapter_t * adapter,int version,int revision)209d39a76e7Sxw static inline int adapter_matches_type(const adapter_t *adapter,
210d39a76e7Sxw 				       int version, int revision)
211d39a76e7Sxw {
212d39a76e7Sxw 	return adapter->params.chip_version == version &&
213d39a76e7Sxw 		adapter->params.chip_revision == revision;
214d39a76e7Sxw }
215d39a76e7Sxw 
216d39a76e7Sxw #define t1_is_T1B(adap) adapter_matches_type(adap, CHBT_TERM_T1, TERM_T1B)
217d39a76e7Sxw #define is_T2(adap)     adapter_matches_type(adap, CHBT_TERM_T2, TERM_T2)
218d39a76e7Sxw 
219d39a76e7Sxw /* Returns true if an adapter supports VLAN acceleration and TSO */
vlan_tso_capable(const adapter_t * adapter)220d39a76e7Sxw static inline int vlan_tso_capable(const adapter_t *adapter)
221d39a76e7Sxw {
222d39a76e7Sxw 	return !t1_is_T1B(adapter);
223d39a76e7Sxw }
224d39a76e7Sxw 
225d39a76e7Sxw #define for_each_port(adapter, iter) \
226d39a76e7Sxw 	for (iter = 0; iter < (adapter)->params.nports; ++iter)
227d39a76e7Sxw 
228d39a76e7Sxw #define board_info(adapter) ((adapter)->params.brd_info)
229d39a76e7Sxw #define is_10G(adapter) (board_info(adapter)->caps & SUPPORTED_10000baseT_Full)
230d39a76e7Sxw 
core_ticks_per_usec(const adapter_t * adap)231d39a76e7Sxw static inline unsigned int core_ticks_per_usec(const adapter_t *adap)
232d39a76e7Sxw {
233d39a76e7Sxw 	return board_info(adap)->clock_core / 1000000;
234d39a76e7Sxw }
235d39a76e7Sxw 
236d39a76e7Sxw int __t1_tpi_read(adapter_t *adapter, u32 addr, u32 *valp);
237d39a76e7Sxw int __t1_tpi_write(adapter_t *adapter, u32 addr, u32 value);
238d39a76e7Sxw int t1_tpi_write(adapter_t *adapter, u32 addr, u32 value);
239d39a76e7Sxw int t1_tpi_read(adapter_t *adapter, u32 addr, u32 *value);
240d39a76e7Sxw int t1_wait_op_done(adapter_t *adapter, int reg, u32 mask, int polarity,
241d39a76e7Sxw                     int attempts, int delay);
242d39a76e7Sxw 
243d39a76e7Sxw void t1_interrupts_enable(adapter_t *adapter);
244d39a76e7Sxw void t1_interrupts_disable(adapter_t *adapter);
245d39a76e7Sxw void t1_interrupts_clear(adapter_t *adapter);
246d39a76e7Sxw int elmer0_ext_intr_handler(adapter_t *adapter);
247d39a76e7Sxw int t1_slow_intr_handler(adapter_t *adapter);
248d39a76e7Sxw 
249d39a76e7Sxw int t1_link_start(struct cphy *phy, struct cmac *mac, struct link_config *lc);
250d39a76e7Sxw const struct board_info *t1_get_board_info(unsigned int board_id);
251d39a76e7Sxw const struct board_info *t1_get_board_info_from_ids(unsigned int devid,
252d39a76e7Sxw 						    unsigned short ssid);
253d39a76e7Sxw int t1_seeprom_read(adapter_t *adapter, u32 addr, u32 *data);
254d39a76e7Sxw int t1_get_board_rev(adapter_t *adapter, const struct board_info *bi,
255d39a76e7Sxw 		     struct adapter_params *p);
256d39a76e7Sxw int t1_init_hw_modules(adapter_t *adapter);
257d39a76e7Sxw int t1_init_sw_modules(adapter_t *adapter, const struct board_info *bi);
258d39a76e7Sxw void t1_free_sw_modules(adapter_t *adapter);
259d39a76e7Sxw void t1_fatal_err(adapter_t *adapter);
260d39a76e7Sxw void link_changed(adapter_t *adapter, int port_id);
261d39a76e7Sxw void init_mtus(unsigned short mtus[]);
262d39a76e7Sxw #endif /* CHELSIO_COMMON_H */
263