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