Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wirel...
[linux-drm-fsl-dcu.git] / drivers / net / ethernet / chelsio / cxgb / common.h
1 /*****************************************************************************
2  *                                                                           *
3  * File: common.h                                                            *
4  * $Revision: 1.21 $                                                         *
5  * $Date: 2005/06/22 00:43:25 $                                              *
6  * 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   *
14  * with this program; if not, see <http://www.gnu.org/licenses/>.            *
15  *                                                                           *
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
38 #define pr_fmt(fmt) "cxgb: " fmt
39
40 #ifndef _CXGB_COMMON_H_
41 #define _CXGB_COMMON_H_
42
43 #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>
49 #include <linux/if_vlan.h>
50 #include <linux/mdio.h>
51 #include <linux/crc32.h>
52 #include <linux/init.h>
53 #include <linux/slab.h>
54 #include <asm/io.h>
55 #include <linux/pci_ids.h>
56
57 #define DRV_DESCRIPTION "Chelsio 10Gb Ethernet Driver"
58 #define DRV_NAME "cxgb"
59 #define DRV_VERSION "2.2"
60
61 #define CH_DEVICE(devid, ssid, idx) \
62         { PCI_VENDOR_ID_CHELSIO, devid, PCI_ANY_ID, ssid, 0, 0, idx }
63
64 #define SUPPORTED_PAUSE       (1 << 13)
65 #define SUPPORTED_LOOPBACK    (1 << 15)
66
67 #define ADVERTISED_PAUSE      (1 << 13)
68 #define ADVERTISED_ASYM_PAUSE (1 << 14)
69
70 typedef struct adapter adapter_t;
71
72 struct t1_rx_mode {
73        struct net_device *dev;
74 };
75
76 #define t1_rx_mode_promisc(rm)  (rm->dev->flags & IFF_PROMISC)
77 #define t1_rx_mode_allmulti(rm) (rm->dev->flags & IFF_ALLMULTI)
78 #define t1_rx_mode_mc_cnt(rm)   (netdev_mc_count(rm->dev))
79 #define t1_get_netdev(rm)       (rm->dev)
80
81 #define MAX_NPORTS 4
82 #define PORT_MASK ((1 << MAX_NPORTS) - 1)
83 #define NMTUS      8
84 #define TCB_SIZE   128
85
86 #define SPEED_INVALID 0xffff
87 #define DUPLEX_INVALID 0xff
88
89 enum {
90         CHBT_BOARD_N110,
91         CHBT_BOARD_N210,
92         CHBT_BOARD_7500,
93         CHBT_BOARD_8000,
94         CHBT_BOARD_CHT101,
95         CHBT_BOARD_CHT110,
96         CHBT_BOARD_CHT210,
97         CHBT_BOARD_CHT204,
98         CHBT_BOARD_CHT204V,
99         CHBT_BOARD_CHT204E,
100         CHBT_BOARD_CHN204,
101         CHBT_BOARD_COUGAR,
102         CHBT_BOARD_6800,
103         CHBT_BOARD_SIMUL,
104 };
105
106 enum {
107         CHBT_TERM_FPGA,
108         CHBT_TERM_T1,
109         CHBT_TERM_T2,
110         CHBT_TERM_T3
111 };
112
113 enum {
114         CHBT_MAC_CHELSIO_A,
115         CHBT_MAC_IXF1010,
116         CHBT_MAC_PM3393,
117         CHBT_MAC_VSC7321,
118         CHBT_MAC_DUMMY
119 };
120
121 enum {
122         CHBT_PHY_88E1041,
123         CHBT_PHY_88E1111,
124         CHBT_PHY_88X2010,
125         CHBT_PHY_XPAK,
126         CHBT_PHY_MY3126,
127         CHBT_PHY_8244,
128         CHBT_PHY_DUMMY
129 };
130
131 enum {
132         PAUSE_RX      = 1 << 0,
133         PAUSE_TX      = 1 << 1,
134         PAUSE_AUTONEG = 1 << 2
135 };
136
137 /* Revisions of T1 chip */
138 enum {
139         TERM_T1A   = 0,
140         TERM_T1B   = 1,
141         TERM_T2    = 3
142 };
143
144 struct sge_params {
145         unsigned int cmdQ_size[2];
146         unsigned int freelQ_size[2];
147         unsigned int large_buf_capacity;
148         unsigned int rx_coalesce_usecs;
149         unsigned int last_rx_coalesce_raw;
150         unsigned int default_rx_coalesce_usecs;
151         unsigned int sample_interval_usecs;
152         unsigned int coalesce_enable;
153         unsigned int polling;
154 };
155
156 struct chelsio_pci_params {
157         unsigned short speed;
158         unsigned char  width;
159         unsigned char  is_pcix;
160 };
161
162 struct tp_params {
163         unsigned int pm_size;
164         unsigned int cm_size;
165         unsigned int pm_rx_base;
166         unsigned int pm_tx_base;
167         unsigned int pm_rx_pg_size;
168         unsigned int pm_tx_pg_size;
169         unsigned int pm_rx_num_pgs;
170         unsigned int pm_tx_num_pgs;
171         unsigned int rx_coalescing_size;
172         unsigned int use_5tuple_mode;
173 };
174
175 struct mc5_params {
176         unsigned int mode;       /* selects MC5 width */
177         unsigned int nservers;   /* size of server region */
178         unsigned int nroutes;    /* size of routing region */
179 };
180
181 /* Default MC5 region sizes */
182 #define DEFAULT_SERVER_REGION_LEN 256
183 #define DEFAULT_RT_REGION_LEN 1024
184
185 struct adapter_params {
186         struct sge_params sge;
187         struct mc5_params mc5;
188         struct tp_params  tp;
189         struct chelsio_pci_params pci;
190
191         const struct board_info *brd_info;
192
193         unsigned short mtus[NMTUS];
194         unsigned int   nports;          /* # of ethernet ports */
195         unsigned int   stats_update_period;
196         unsigned short chip_revision;
197         unsigned char  chip_version;
198         unsigned char  is_asic;
199         unsigned char  has_msi;
200 };
201
202 struct link_config {
203         unsigned int   supported;        /* link capabilities */
204         unsigned int   advertising;      /* advertised capabilities */
205         unsigned short requested_speed;  /* speed user has requested */
206         unsigned short speed;            /* actual link speed */
207         unsigned char  requested_duplex; /* duplex user has requested */
208         unsigned char  duplex;           /* actual link duplex */
209         unsigned char  requested_fc;     /* flow control user has requested */
210         unsigned char  fc;               /* actual link flow control */
211         unsigned char  autoneg;          /* autonegotiating? */
212 };
213
214 struct cmac;
215 struct cphy;
216
217 struct port_info {
218         struct net_device *dev;
219         struct cmac *mac;
220         struct cphy *phy;
221         struct link_config link_config;
222         struct net_device_stats netstats;
223 };
224
225 struct sge;
226 struct peespi;
227
228 struct adapter {
229         u8 __iomem *regs;
230         struct pci_dev *pdev;
231         unsigned long registered_device_map;
232         unsigned long open_device_map;
233         unsigned long flags;
234
235         const char *name;
236         int msg_enable;
237         u32 mmio_len;
238
239         struct work_struct ext_intr_handler_task;
240         struct adapter_params params;
241
242         /* Terminator modules. */
243         struct sge    *sge;
244         struct peespi *espi;
245         struct petp   *tp;
246
247         struct napi_struct napi;
248         struct port_info port[MAX_NPORTS];
249         struct delayed_work stats_update_task;
250         struct timer_list stats_update_timer;
251
252         spinlock_t tpi_lock;
253         spinlock_t work_lock;
254         spinlock_t mac_lock;
255
256         /* guards async operations */
257         spinlock_t async_lock ____cacheline_aligned;
258         u32 slow_intr_mask;
259         int t1powersave;
260 };
261
262 enum {                                           /* adapter flags */
263         FULL_INIT_DONE        = 1 << 0,
264 };
265
266 struct mdio_ops;
267 struct gmac;
268 struct gphy;
269
270 struct board_info {
271         unsigned char           board;
272         unsigned char           port_number;
273         unsigned long           caps;
274         unsigned char           chip_term;
275         unsigned char           chip_mac;
276         unsigned char           chip_phy;
277         unsigned int            clock_core;
278         unsigned int            clock_mc3;
279         unsigned int            clock_mc4;
280         unsigned int            espi_nports;
281         unsigned int            clock_elmer0;
282         unsigned char           mdio_mdien;
283         unsigned char           mdio_mdiinv;
284         unsigned char           mdio_mdc;
285         unsigned char           mdio_phybaseaddr;
286         const struct gmac      *gmac;
287         const struct gphy      *gphy;
288         const struct mdio_ops  *mdio_ops;
289         const char             *desc;
290 };
291
292 static inline int t1_is_asic(const adapter_t *adapter)
293 {
294         return adapter->params.is_asic;
295 }
296
297 extern const struct pci_device_id t1_pci_tbl[];
298
299 static inline int adapter_matches_type(const adapter_t *adapter,
300                                        int version, int revision)
301 {
302         return adapter->params.chip_version == version &&
303                adapter->params.chip_revision == revision;
304 }
305
306 #define t1_is_T1B(adap) adapter_matches_type(adap, CHBT_TERM_T1, TERM_T1B)
307 #define is_T2(adap)     adapter_matches_type(adap, CHBT_TERM_T2, TERM_T2)
308
309 /* Returns true if an adapter supports VLAN acceleration and TSO */
310 static inline int vlan_tso_capable(const adapter_t *adapter)
311 {
312         return !t1_is_T1B(adapter);
313 }
314
315 #define for_each_port(adapter, iter) \
316         for (iter = 0; iter < (adapter)->params.nports; ++iter)
317
318 #define board_info(adapter) ((adapter)->params.brd_info)
319 #define is_10G(adapter) (board_info(adapter)->caps & SUPPORTED_10000baseT_Full)
320
321 static inline unsigned int core_ticks_per_usec(const adapter_t *adap)
322 {
323         return board_info(adap)->clock_core / 1000000;
324 }
325
326 int __t1_tpi_read(adapter_t *adapter, u32 addr, u32 *valp);
327 int __t1_tpi_write(adapter_t *adapter, u32 addr, u32 value);
328 int t1_tpi_write(adapter_t *adapter, u32 addr, u32 value);
329 int t1_tpi_read(adapter_t *adapter, u32 addr, u32 *value);
330
331 void t1_interrupts_enable(adapter_t *adapter);
332 void t1_interrupts_disable(adapter_t *adapter);
333 void t1_interrupts_clear(adapter_t *adapter);
334 int t1_elmer0_ext_intr_handler(adapter_t *adapter);
335 void t1_elmer0_ext_intr(adapter_t *adapter);
336 int t1_slow_intr_handler(adapter_t *adapter);
337
338 int t1_link_start(struct cphy *phy, struct cmac *mac, struct link_config *lc);
339 const struct board_info *t1_get_board_info(unsigned int board_id);
340 const struct board_info *t1_get_board_info_from_ids(unsigned int devid,
341                                                     unsigned short ssid);
342 int t1_seeprom_read(adapter_t *adapter, u32 addr, __le32 *data);
343 int t1_get_board_rev(adapter_t *adapter, const struct board_info *bi,
344                      struct adapter_params *p);
345 int t1_init_hw_modules(adapter_t *adapter);
346 int t1_init_sw_modules(adapter_t *adapter, const struct board_info *bi);
347 void t1_free_sw_modules(adapter_t *adapter);
348 void t1_fatal_err(adapter_t *adapter);
349 void t1_link_changed(adapter_t *adapter, int port_id);
350 void t1_link_negotiated(adapter_t *adapter, int port_id, int link_stat,
351                             int speed, int duplex, int pause);
352 #endif /* _CXGB_COMMON_H_ */