blob: 53b1f947838320ded878c557882b5b05acddeff7 [file] [log] [blame]
Christoph Lameter8199d3a2005-03-30 13:34:31 -08001/*****************************************************************************
2 * *
3 * File: common.h *
Scott Bardone559fb512005-06-23 01:40:19 -04004 * $Revision: 1.21 $ *
5 * $Date: 2005/06/22 00:43:25 $ *
Christoph Lameter8199d3a2005-03-30 13:34:31 -08006 * Description: *
7 * part of the Chelsio 10Gb Ethernet Driver. *
8 * *
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. *
12 * *
13 * You should have received a copy of the GNU General Public License along *
Jeff Kirsher0ab75ae2013-12-06 06:28:43 -080014 * with this program; if not, see <http://www.gnu.org/licenses/>. *
Christoph Lameter8199d3a2005-03-30 13:34:31 -080015 * *
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED *
17 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF *
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. *
19 * *
20 * http://www.chelsio.com *
21 * *
22 * Copyright (c) 2003 - 2005 Chelsio Communications, Inc. *
23 * All rights reserved. *
24 * *
25 * Maintainers: maintainers@chelsio.com *
26 * *
27 * Authors: Dimitrios Michailidis <dm@chelsio.com> *
28 * Tina Yang <tainay@chelsio.com> *
29 * Felix Marti <felix@chelsio.com> *
30 * Scott Bardone <sbardone@chelsio.com> *
31 * Kurt Ottaway <kottaway@chelsio.com> *
32 * Frank DiMambro <frank@chelsio.com> *
33 * *
34 * History: *
35 * *
36 ****************************************************************************/
37
Joe Perchesc1f51212010-02-22 16:56:57 +000038#define pr_fmt(fmt) "cxgb: " fmt
39
Scott Bardone559fb512005-06-23 01:40:19 -040040#ifndef _CXGB_COMMON_H_
41#define _CXGB_COMMON_H_
Christoph Lameter8199d3a2005-03-30 13:34:31 -080042
Scott Bardone559fb512005-06-23 01:40:19 -040043#include <linux/module.h>
44#include <linux/netdevice.h>
45#include <linux/types.h>
46#include <linux/delay.h>
47#include <linux/pci.h>
48#include <linux/ethtool.h>
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -080049#include <linux/if_vlan.h>
Ben Hutchings23c33202009-04-29 08:06:34 +000050#include <linux/mdio.h>
Scott Bardone559fb512005-06-23 01:40:19 -040051#include <linux/crc32.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090052#include <linux/slab.h>
Scott Bardone559fb512005-06-23 01:40:19 -040053#include <asm/io.h>
54#include <linux/pci_ids.h>
Christoph Lameter8199d3a2005-03-30 13:34:31 -080055
Scott Bardone559fb512005-06-23 01:40:19 -040056#define DRV_DESCRIPTION "Chelsio 10Gb Ethernet Driver"
57#define DRV_NAME "cxgb"
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -080058#define DRV_VERSION "2.2"
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -080059
Scott Bardone559fb512005-06-23 01:40:19 -040060#define CH_DEVICE(devid, ssid, idx) \
61 { PCI_VENDOR_ID_CHELSIO, devid, PCI_ANY_ID, ssid, 0, 0, idx }
62
63#define SUPPORTED_PAUSE (1 << 13)
64#define SUPPORTED_LOOPBACK (1 << 15)
65
66#define ADVERTISED_PAUSE (1 << 13)
67#define ADVERTISED_ASYM_PAUSE (1 << 14)
68
69typedef struct adapter adapter_t;
70
Scott Bardone559fb512005-06-23 01:40:19 -040071struct t1_rx_mode {
Jiri Pirko305b0162010-02-17 11:56:45 +000072 struct net_device *dev;
Scott Bardone559fb512005-06-23 01:40:19 -040073};
74
75#define t1_rx_mode_promisc(rm) (rm->dev->flags & IFF_PROMISC)
76#define t1_rx_mode_allmulti(rm) (rm->dev->flags & IFF_ALLMULTI)
Jiri Pirko4cd24ea2010-02-08 04:30:35 +000077#define t1_rx_mode_mc_cnt(rm) (netdev_mc_count(rm->dev))
Jiri Pirko305b0162010-02-17 11:56:45 +000078#define t1_get_netdev(rm) (rm->dev)
Scott Bardone559fb512005-06-23 01:40:19 -040079
80#define MAX_NPORTS 4
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -080081#define PORT_MASK ((1 << MAX_NPORTS) - 1)
82#define NMTUS 8
83#define TCB_SIZE 128
Scott Bardone559fb512005-06-23 01:40:19 -040084
85#define SPEED_INVALID 0xffff
86#define DUPLEX_INVALID 0xff
Christoph Lameter8199d3a2005-03-30 13:34:31 -080087
88enum {
Christoph Lameter8199d3a2005-03-30 13:34:31 -080089 CHBT_BOARD_N110,
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -080090 CHBT_BOARD_N210,
91 CHBT_BOARD_7500,
92 CHBT_BOARD_8000,
93 CHBT_BOARD_CHT101,
94 CHBT_BOARD_CHT110,
95 CHBT_BOARD_CHT210,
96 CHBT_BOARD_CHT204,
97 CHBT_BOARD_CHT204V,
98 CHBT_BOARD_CHT204E,
99 CHBT_BOARD_CHN204,
100 CHBT_BOARD_COUGAR,
101 CHBT_BOARD_6800,
102 CHBT_BOARD_SIMUL,
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800103};
104
105enum {
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800106 CHBT_TERM_FPGA,
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800107 CHBT_TERM_T1,
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800108 CHBT_TERM_T2,
109 CHBT_TERM_T3
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800110};
111
112enum {
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800113 CHBT_MAC_CHELSIO_A,
114 CHBT_MAC_IXF1010,
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800115 CHBT_MAC_PM3393,
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800116 CHBT_MAC_VSC7321,
117 CHBT_MAC_DUMMY
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800118};
119
120enum {
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800121 CHBT_PHY_88E1041,
122 CHBT_PHY_88E1111,
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800123 CHBT_PHY_88X2010,
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800124 CHBT_PHY_XPAK,
125 CHBT_PHY_MY3126,
126 CHBT_PHY_8244,
127 CHBT_PHY_DUMMY
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800128};
129
130enum {
Scott Bardone559fb512005-06-23 01:40:19 -0400131 PAUSE_RX = 1 << 0,
132 PAUSE_TX = 1 << 1,
133 PAUSE_AUTONEG = 1 << 2
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800134};
135
136/* Revisions of T1 chip */
Scott Bardone559fb512005-06-23 01:40:19 -0400137enum {
138 TERM_T1A = 0,
139 TERM_T1B = 1,
140 TERM_T2 = 3
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800141};
142
143struct sge_params {
144 unsigned int cmdQ_size[2];
145 unsigned int freelQ_size[2];
146 unsigned int large_buf_capacity;
147 unsigned int rx_coalesce_usecs;
148 unsigned int last_rx_coalesce_raw;
149 unsigned int default_rx_coalesce_usecs;
150 unsigned int sample_interval_usecs;
151 unsigned int coalesce_enable;
152 unsigned int polling;
153};
154
Scott Bardone559fb512005-06-23 01:40:19 -0400155struct chelsio_pci_params {
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800156 unsigned short speed;
157 unsigned char width;
158 unsigned char is_pcix;
159};
160
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800161struct tp_params {
162 unsigned int pm_size;
163 unsigned int cm_size;
164 unsigned int pm_rx_base;
165 unsigned int pm_tx_base;
166 unsigned int pm_rx_pg_size;
167 unsigned int pm_tx_pg_size;
168 unsigned int pm_rx_num_pgs;
169 unsigned int pm_tx_num_pgs;
170 unsigned int rx_coalescing_size;
171 unsigned int use_5tuple_mode;
172};
173
174struct mc5_params {
175 unsigned int mode; /* selects MC5 width */
176 unsigned int nservers; /* size of server region */
177 unsigned int nroutes; /* size of routing region */
178};
179
180/* Default MC5 region sizes */
181#define DEFAULT_SERVER_REGION_LEN 256
182#define DEFAULT_RT_REGION_LEN 1024
183
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800184struct adapter_params {
185 struct sge_params sge;
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800186 struct mc5_params mc5;
187 struct tp_params tp;
Scott Bardone559fb512005-06-23 01:40:19 -0400188 struct chelsio_pci_params pci;
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800189
190 const struct board_info *brd_info;
191
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800192 unsigned short mtus[NMTUS];
Scott Bardone559fb512005-06-23 01:40:19 -0400193 unsigned int nports; /* # of ethernet ports */
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800194 unsigned int stats_update_period;
195 unsigned short chip_revision;
196 unsigned char chip_version;
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800197 unsigned char is_asic;
Stephen Hemminger325dde42006-12-01 16:36:20 -0800198 unsigned char has_msi;
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800199};
200
201struct link_config {
202 unsigned int supported; /* link capabilities */
203 unsigned int advertising; /* advertised capabilities */
204 unsigned short requested_speed; /* speed user has requested */
205 unsigned short speed; /* actual link speed */
206 unsigned char requested_duplex; /* duplex user has requested */
207 unsigned char duplex; /* actual link duplex */
208 unsigned char requested_fc; /* flow control user has requested */
209 unsigned char fc; /* actual link flow control */
210 unsigned char autoneg; /* autonegotiating? */
211};
212
Scott Bardone559fb512005-06-23 01:40:19 -0400213struct cmac;
214struct cphy;
215
216struct port_info {
217 struct net_device *dev;
218 struct cmac *mac;
219 struct cphy *phy;
220 struct link_config link_config;
221 struct net_device_stats netstats;
222};
223
224struct sge;
225struct peespi;
226
227struct adapter {
viro@ftp.linux.org.uk91fb4c92005-09-05 03:25:48 +0100228 u8 __iomem *regs;
Scott Bardone559fb512005-06-23 01:40:19 -0400229 struct pci_dev *pdev;
230 unsigned long registered_device_map;
231 unsigned long open_device_map;
232 unsigned long flags;
233
234 const char *name;
235 int msg_enable;
236 u32 mmio_len;
237
238 struct work_struct ext_intr_handler_task;
239 struct adapter_params params;
240
Scott Bardone559fb512005-06-23 01:40:19 -0400241 /* Terminator modules. */
242 struct sge *sge;
243 struct peespi *espi;
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800244 struct petp *tp;
Scott Bardone559fb512005-06-23 01:40:19 -0400245
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700246 struct napi_struct napi;
Scott Bardone559fb512005-06-23 01:40:19 -0400247 struct port_info port[MAX_NPORTS];
David Howellsc4028952006-11-22 14:57:56 +0000248 struct delayed_work stats_update_task;
Scott Bardone559fb512005-06-23 01:40:19 -0400249 struct timer_list stats_update_timer;
250
Scott Bardone559fb512005-06-23 01:40:19 -0400251 spinlock_t tpi_lock;
252 spinlock_t work_lock;
Stephen Hemminger352c4172006-12-01 16:36:17 -0800253 spinlock_t mac_lock;
254
Scott Bardone559fb512005-06-23 01:40:19 -0400255 /* guards async operations */
256 spinlock_t async_lock ____cacheline_aligned;
257 u32 slow_intr_mask;
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800258 int t1powersave;
Scott Bardone559fb512005-06-23 01:40:19 -0400259};
260
261enum { /* adapter flags */
262 FULL_INIT_DONE = 1 << 0,
Scott Bardone559fb512005-06-23 01:40:19 -0400263};
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800264
265struct mdio_ops;
266struct gmac;
267struct gphy;
268
269struct board_info {
270 unsigned char board;
271 unsigned char port_number;
272 unsigned long caps;
273 unsigned char chip_term;
274 unsigned char chip_mac;
275 unsigned char chip_phy;
276 unsigned int clock_core;
277 unsigned int clock_mc3;
278 unsigned int clock_mc4;
279 unsigned int espi_nports;
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800280 unsigned int clock_elmer0;
281 unsigned char mdio_mdien;
282 unsigned char mdio_mdiinv;
283 unsigned char mdio_mdc;
284 unsigned char mdio_phybaseaddr;
Stephen Hemminger459e5362007-02-20 15:58:02 -0800285 const struct gmac *gmac;
286 const struct gphy *gphy;
287 const struct mdio_ops *mdio_ops;
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800288 const char *desc;
289};
290
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800291static inline int t1_is_asic(const adapter_t *adapter)
292{
293 return adapter->params.is_asic;
294}
295
Alexey Dobriyana3aa1882010-01-07 11:58:11 +0000296extern const struct pci_device_id t1_pci_tbl[];
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800297
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800298static inline int adapter_matches_type(const adapter_t *adapter,
299 int version, int revision)
300{
301 return adapter->params.chip_version == version &&
302 adapter->params.chip_revision == revision;
303}
304
305#define t1_is_T1B(adap) adapter_matches_type(adap, CHBT_TERM_T1, TERM_T1B)
306#define is_T2(adap) adapter_matches_type(adap, CHBT_TERM_T2, TERM_T2)
307
308/* Returns true if an adapter supports VLAN acceleration and TSO */
309static inline int vlan_tso_capable(const adapter_t *adapter)
310{
311 return !t1_is_T1B(adapter);
312}
313
314#define for_each_port(adapter, iter) \
315 for (iter = 0; iter < (adapter)->params.nports; ++iter)
316
317#define board_info(adapter) ((adapter)->params.brd_info)
318#define is_10G(adapter) (board_info(adapter)->caps & SUPPORTED_10000baseT_Full)
319
320static inline unsigned int core_ticks_per_usec(const adapter_t *adap)
321{
322 return board_info(adap)->clock_core / 1000000;
323}
324
Joe Perches22018e42013-09-23 15:11:35 -0700325int __t1_tpi_read(adapter_t *adapter, u32 addr, u32 *valp);
326int __t1_tpi_write(adapter_t *adapter, u32 addr, u32 value);
327int t1_tpi_write(adapter_t *adapter, u32 addr, u32 value);
328int t1_tpi_read(adapter_t *adapter, u32 addr, u32 *value);
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800329
Joe Perches22018e42013-09-23 15:11:35 -0700330void t1_interrupts_enable(adapter_t *adapter);
331void t1_interrupts_disable(adapter_t *adapter);
332void t1_interrupts_clear(adapter_t *adapter);
333int t1_elmer0_ext_intr_handler(adapter_t *adapter);
334void t1_elmer0_ext_intr(adapter_t *adapter);
335int t1_slow_intr_handler(adapter_t *adapter);
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800336
Joe Perches22018e42013-09-23 15:11:35 -0700337int t1_link_start(struct cphy *phy, struct cmac *mac, struct link_config *lc);
338const struct board_info *t1_get_board_info(unsigned int board_id);
339const struct board_info *t1_get_board_info_from_ids(unsigned int devid,
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800340 unsigned short ssid);
Joe Perches22018e42013-09-23 15:11:35 -0700341int t1_seeprom_read(adapter_t *adapter, u32 addr, __le32 *data);
342int t1_get_board_rev(adapter_t *adapter, const struct board_info *bi,
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800343 struct adapter_params *p);
Joe Perches22018e42013-09-23 15:11:35 -0700344int t1_init_hw_modules(adapter_t *adapter);
345int t1_init_sw_modules(adapter_t *adapter, const struct board_info *bi);
346void t1_free_sw_modules(adapter_t *adapter);
347void t1_fatal_err(adapter_t *adapter);
348void t1_link_changed(adapter_t *adapter, int port_id);
349void t1_link_negotiated(adapter_t *adapter, int port_id, int link_stat,
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800350 int speed, int duplex, int pause);
Scott Bardone559fb512005-06-23 01:40:19 -0400351#endif /* _CXGB_COMMON_H_ */