1 /*****************************************************************************
5 * $Date: 2005/06/22 00:43:25 $ *
7 * part of the Chelsio 10Gb Ethernet Driver. *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License, version 2, as *
11 * published by the Free Software Foundation. *
13 * You should have received a copy of the GNU General Public License along *
14 * with this program; if not, write to the Free Software Foundation, Inc., *
15 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED *
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF *
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. *
21 * http://www.chelsio.com *
23 * Copyright (c) 2003 - 2005 Chelsio Communications, Inc. *
24 * All rights reserved. *
26 * Maintainers: maintainers@chelsio.com *
28 * Authors: Dimitrios Michailidis <dm@chelsio.com> *
29 * Tina Yang <tainay@chelsio.com> *
30 * Felix Marti <felix@chelsio.com> *
31 * Scott Bardone <sbardone@chelsio.com> *
32 * Kurt Ottaway <kottaway@chelsio.com> *
33 * Frank DiMambro <frank@chelsio.com> *
37 ****************************************************************************/
39 #ifndef _CXGB_COMMON_H_
40 #define _CXGB_COMMON_H_
42 #include <linux/module.h>
43 #include <linux/netdevice.h>
44 #include <linux/types.h>
45 #include <linux/delay.h>
46 #include <linux/pci.h>
47 #include <linux/ethtool.h>
48 #include <linux/if_vlan.h>
49 #include <linux/mii.h>
50 #include <linux/crc32.h>
51 #include <linux/init.h>
53 #include <linux/pci_ids.h>
55 #define DRV_DESCRIPTION "Chelsio 10Gb Ethernet Driver"
56 #define DRV_NAME "cxgb"
57 #define DRV_VERSION "2.2"
58 #define PFX DRV_NAME ": "
60 #define CH_ERR(fmt, ...) printk(KERN_ERR PFX fmt, ## __VA_ARGS__)
61 #define CH_WARN(fmt, ...) printk(KERN_WARNING PFX fmt, ## __VA_ARGS__)
62 #define CH_ALERT(fmt, ...) printk(KERN_ALERT PFX fmt, ## __VA_ARGS__)
65 * More powerful macro that selectively prints messages based on msg_enable.
66 * For info and debugging messages.
68 #define CH_MSG(adapter, level, category, fmt, ...) do { \
69 if ((adapter)->msg_enable & NETIF_MSG_##category) \
70 printk(KERN_##level PFX "%s: " fmt, (adapter)->name, \
75 # define CH_DBG(adapter, category, fmt, ...) \
76 CH_MSG(adapter, DEBUG, category, fmt, ## __VA_ARGS__)
78 # define CH_DBG(fmt, ...)
81 #define CH_DEVICE(devid, ssid, idx) \
82 { PCI_VENDOR_ID_CHELSIO, devid, PCI_ANY_ID, ssid, 0, 0, idx }
84 #define SUPPORTED_PAUSE (1 << 13)
85 #define SUPPORTED_LOOPBACK (1 << 15)
87 #define ADVERTISED_PAUSE (1 << 13)
88 #define ADVERTISED_ASYM_PAUSE (1 << 14)
90 typedef struct adapter adapter_t
;
93 struct net_device
*dev
;
95 struct dev_mc_list
*list
;
98 #define t1_rx_mode_promisc(rm) (rm->dev->flags & IFF_PROMISC)
99 #define t1_rx_mode_allmulti(rm) (rm->dev->flags & IFF_ALLMULTI)
100 #define t1_rx_mode_mc_cnt(rm) (rm->dev->mc_count)
102 static inline u8
*t1_get_next_mcaddr(struct t1_rx_mode
*rm
)
106 if (rm
->idx
++ < rm
->dev
->mc_count
) {
107 addr
= rm
->list
->dmi_addr
;
108 rm
->list
= rm
->list
->next
;
114 #define PORT_MASK ((1 << MAX_NPORTS) - 1)
118 #define SPEED_INVALID 0xffff
119 #define DUPLEX_INVALID 0xff
166 PAUSE_AUTONEG
= 1 << 2
169 /* Revisions of T1 chip */
177 unsigned int cmdQ_size
[2];
178 unsigned int freelQ_size
[2];
179 unsigned int large_buf_capacity
;
180 unsigned int rx_coalesce_usecs
;
181 unsigned int last_rx_coalesce_raw
;
182 unsigned int default_rx_coalesce_usecs
;
183 unsigned int sample_interval_usecs
;
184 unsigned int coalesce_enable
;
185 unsigned int polling
;
188 struct chelsio_pci_params
{
189 unsigned short speed
;
191 unsigned char is_pcix
;
195 unsigned int pm_size
;
196 unsigned int cm_size
;
197 unsigned int pm_rx_base
;
198 unsigned int pm_tx_base
;
199 unsigned int pm_rx_pg_size
;
200 unsigned int pm_tx_pg_size
;
201 unsigned int pm_rx_num_pgs
;
202 unsigned int pm_tx_num_pgs
;
203 unsigned int rx_coalescing_size
;
204 unsigned int use_5tuple_mode
;
208 unsigned int mode
; /* selects MC5 width */
209 unsigned int nservers
; /* size of server region */
210 unsigned int nroutes
; /* size of routing region */
213 /* Default MC5 region sizes */
214 #define DEFAULT_SERVER_REGION_LEN 256
215 #define DEFAULT_RT_REGION_LEN 1024
217 struct adapter_params
{
218 struct sge_params sge
;
219 struct mc5_params mc5
;
221 struct chelsio_pci_params pci
;
223 const struct board_info
*brd_info
;
225 unsigned short mtus
[NMTUS
];
226 unsigned int nports
; /* # of ethernet ports */
227 unsigned int stats_update_period
;
228 unsigned short chip_revision
;
229 unsigned char chip_version
;
230 unsigned char is_asic
;
231 unsigned char has_msi
;
235 unsigned int supported
; /* link capabilities */
236 unsigned int advertising
; /* advertised capabilities */
237 unsigned short requested_speed
; /* speed user has requested */
238 unsigned short speed
; /* actual link speed */
239 unsigned char requested_duplex
; /* duplex user has requested */
240 unsigned char duplex
; /* actual link duplex */
241 unsigned char requested_fc
; /* flow control user has requested */
242 unsigned char fc
; /* actual link flow control */
243 unsigned char autoneg
; /* autonegotiating? */
250 struct net_device
*dev
;
253 struct link_config link_config
;
254 struct net_device_stats netstats
;
262 struct pci_dev
*pdev
;
263 unsigned long registered_device_map
;
264 unsigned long open_device_map
;
271 struct work_struct ext_intr_handler_task
;
272 struct adapter_params params
;
274 struct vlan_group
*vlan_grp
;
276 /* Terminator modules. */
281 struct port_info port
[MAX_NPORTS
];
282 struct delayed_work stats_update_task
;
283 struct timer_list stats_update_timer
;
286 spinlock_t work_lock
;
289 /* guards async operations */
290 spinlock_t async_lock ____cacheline_aligned
;
295 enum { /* adapter flags */
296 FULL_INIT_DONE
= 1 << 0,
297 TSO_CAPABLE
= 1 << 2,
298 TCP_CSUM_CAPABLE
= 1 << 3,
299 UDP_CSUM_CAPABLE
= 1 << 4,
300 VLAN_ACCEL_CAPABLE
= 1 << 5,
301 RX_CSUM_ENABLED
= 1 << 6,
310 unsigned char port_number
;
312 unsigned char chip_term
;
313 unsigned char chip_mac
;
314 unsigned char chip_phy
;
315 unsigned int clock_core
;
316 unsigned int clock_mc3
;
317 unsigned int clock_mc4
;
318 unsigned int espi_nports
;
319 unsigned int clock_cspi
;
320 unsigned int clock_elmer0
;
321 unsigned char mdio_mdien
;
322 unsigned char mdio_mdiinv
;
323 unsigned char mdio_mdc
;
324 unsigned char mdio_phybaseaddr
;
325 const struct gmac
*gmac
;
326 const struct gphy
*gphy
;
327 const struct mdio_ops
*mdio_ops
;
331 static inline int t1_is_asic(const adapter_t
*adapter
)
333 return adapter
->params
.is_asic
;
336 extern struct pci_device_id t1_pci_tbl
[];
338 static inline int adapter_matches_type(const adapter_t
*adapter
,
339 int version
, int revision
)
341 return adapter
->params
.chip_version
== version
&&
342 adapter
->params
.chip_revision
== revision
;
345 #define t1_is_T1B(adap) adapter_matches_type(adap, CHBT_TERM_T1, TERM_T1B)
346 #define is_T2(adap) adapter_matches_type(adap, CHBT_TERM_T2, TERM_T2)
348 /* Returns true if an adapter supports VLAN acceleration and TSO */
349 static inline int vlan_tso_capable(const adapter_t
*adapter
)
351 return !t1_is_T1B(adapter
);
354 #define for_each_port(adapter, iter) \
355 for (iter = 0; iter < (adapter)->params.nports; ++iter)
357 #define board_info(adapter) ((adapter)->params.brd_info)
358 #define is_10G(adapter) (board_info(adapter)->caps & SUPPORTED_10000baseT_Full)
360 static inline unsigned int core_ticks_per_usec(const adapter_t
*adap
)
362 return board_info(adap
)->clock_core
/ 1000000;
365 extern int __t1_tpi_read(adapter_t
*adapter
, u32 addr
, u32
*valp
);
366 extern int __t1_tpi_write(adapter_t
*adapter
, u32 addr
, u32 value
);
367 extern int t1_tpi_write(adapter_t
*adapter
, u32 addr
, u32 value
);
368 extern int t1_tpi_read(adapter_t
*adapter
, u32 addr
, u32
*value
);
370 extern void t1_interrupts_enable(adapter_t
*adapter
);
371 extern void t1_interrupts_disable(adapter_t
*adapter
);
372 extern void t1_interrupts_clear(adapter_t
*adapter
);
373 extern int t1_elmer0_ext_intr_handler(adapter_t
*adapter
);
374 extern int t1_slow_intr_handler(adapter_t
*adapter
);
376 extern int t1_link_start(struct cphy
*phy
, struct cmac
*mac
, struct link_config
*lc
);
377 extern const struct board_info
*t1_get_board_info(unsigned int board_id
);
378 extern const struct board_info
*t1_get_board_info_from_ids(unsigned int devid
,
379 unsigned short ssid
);
380 extern int t1_seeprom_read(adapter_t
*adapter
, u32 addr
, u32
*data
);
381 extern int t1_get_board_rev(adapter_t
*adapter
, const struct board_info
*bi
,
382 struct adapter_params
*p
);
383 extern int t1_init_hw_modules(adapter_t
*adapter
);
384 extern int t1_init_sw_modules(adapter_t
*adapter
, const struct board_info
*bi
);
385 extern void t1_free_sw_modules(adapter_t
*adapter
);
386 extern void t1_fatal_err(adapter_t
*adapter
);
387 extern void t1_link_changed(adapter_t
*adapter
, int port_id
);
388 extern void t1_link_negotiated(adapter_t
*adapter
, int port_id
, int link_stat
,
389 int speed
, int duplex
, int pause
);
390 #endif /* _CXGB_COMMON_H_ */