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