xref: /openbmc/linux/drivers/net/ethernet/atheros/alx/alx.h (revision bccffcf7154420c1cbd9e3c2702e2ec4ff0bc319)
1ab69bde6SJohannes Berg /*
2ab69bde6SJohannes Berg  * Copyright (c) 2013 Johannes Berg <johannes@sipsolutions.net>
3ab69bde6SJohannes Berg  *
4ab69bde6SJohannes Berg  *  This file is free software: you may copy, redistribute and/or modify it
5ab69bde6SJohannes Berg  *  under the terms of the GNU General Public License as published by the
6ab69bde6SJohannes Berg  *  Free Software Foundation, either version 2 of the License, or (at your
7ab69bde6SJohannes Berg  *  option) any later version.
8ab69bde6SJohannes Berg  *
9ab69bde6SJohannes Berg  *  This file is distributed in the hope that it will be useful, but
10ab69bde6SJohannes Berg  *  WITHOUT ANY WARRANTY; without even the implied warranty of
11ab69bde6SJohannes Berg  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12ab69bde6SJohannes Berg  *  General Public License for more details.
13ab69bde6SJohannes Berg  *
14ab69bde6SJohannes Berg  *  You should have received a copy of the GNU General Public License
15ab69bde6SJohannes Berg  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16ab69bde6SJohannes Berg  *
17ab69bde6SJohannes Berg  * This file incorporates work covered by the following copyright and
18ab69bde6SJohannes Berg  * permission notice:
19ab69bde6SJohannes Berg  *
20ab69bde6SJohannes Berg  * Copyright (c) 2012 Qualcomm Atheros, Inc.
21ab69bde6SJohannes Berg  *
22ab69bde6SJohannes Berg  * Permission to use, copy, modify, and/or distribute this software for any
23ab69bde6SJohannes Berg  * purpose with or without fee is hereby granted, provided that the above
24ab69bde6SJohannes Berg  * copyright notice and this permission notice appear in all copies.
25ab69bde6SJohannes Berg  *
26ab69bde6SJohannes Berg  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
27ab69bde6SJohannes Berg  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
28ab69bde6SJohannes Berg  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
29ab69bde6SJohannes Berg  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
30ab69bde6SJohannes Berg  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
31ab69bde6SJohannes Berg  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
32ab69bde6SJohannes Berg  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
33ab69bde6SJohannes Berg  */
34ab69bde6SJohannes Berg 
35ab69bde6SJohannes Berg #ifndef _ALX_H_
36ab69bde6SJohannes Berg #define _ALX_H_
37ab69bde6SJohannes Berg 
38ab69bde6SJohannes Berg #include <linux/types.h>
39ab69bde6SJohannes Berg #include <linux/etherdevice.h>
40ab69bde6SJohannes Berg #include <linux/dma-mapping.h>
41ab69bde6SJohannes Berg #include <linux/spinlock.h>
42ab69bde6SJohannes Berg #include "hw.h"
43ab69bde6SJohannes Berg 
44ab69bde6SJohannes Berg #define ALX_WATCHDOG_TIME   (5 * HZ)
45ab69bde6SJohannes Berg 
46ab69bde6SJohannes Berg struct alx_buffer {
47ab69bde6SJohannes Berg 	struct sk_buff *skb;
48ab69bde6SJohannes Berg 	DEFINE_DMA_UNMAP_ADDR(dma);
49ab69bde6SJohannes Berg 	DEFINE_DMA_UNMAP_LEN(size);
50ab69bde6SJohannes Berg };
51ab69bde6SJohannes Berg 
52ab69bde6SJohannes Berg struct alx_rx_queue {
53*bccffcf7STobias Regnery 	struct net_device *netdev;
54*bccffcf7STobias Regnery 	struct device *dev;
55*bccffcf7STobias Regnery 	struct alx_napi *np;
56*bccffcf7STobias Regnery 
57ab69bde6SJohannes Berg 	struct alx_rrd *rrd;
58ab69bde6SJohannes Berg 	dma_addr_t rrd_dma;
59ab69bde6SJohannes Berg 
60ab69bde6SJohannes Berg 	struct alx_rfd *rfd;
61ab69bde6SJohannes Berg 	dma_addr_t rfd_dma;
62ab69bde6SJohannes Berg 
63ab69bde6SJohannes Berg 	struct alx_buffer *bufs;
64ab69bde6SJohannes Berg 
65*bccffcf7STobias Regnery 	u16 count;
66ab69bde6SJohannes Berg 	u16 write_idx, read_idx;
67ab69bde6SJohannes Berg 	u16 rrd_read_idx;
68*bccffcf7STobias Regnery 	u16 queue_idx;
69ab69bde6SJohannes Berg };
70ab69bde6SJohannes Berg #define ALX_RX_ALLOC_THRESH	32
71ab69bde6SJohannes Berg 
72ab69bde6SJohannes Berg struct alx_tx_queue {
73*bccffcf7STobias Regnery 	struct net_device *netdev;
74*bccffcf7STobias Regnery 	struct device *dev;
75*bccffcf7STobias Regnery 
76ab69bde6SJohannes Berg 	struct alx_txd *tpd;
77ab69bde6SJohannes Berg 	dma_addr_t tpd_dma;
78*bccffcf7STobias Regnery 
79ab69bde6SJohannes Berg 	struct alx_buffer *bufs;
80*bccffcf7STobias Regnery 
81*bccffcf7STobias Regnery 	u16 count;
82ab69bde6SJohannes Berg 	u16 write_idx, read_idx;
83*bccffcf7STobias Regnery 	u16 queue_idx;
84*bccffcf7STobias Regnery 	u16 p_reg, c_reg;
85ab69bde6SJohannes Berg };
86ab69bde6SJohannes Berg 
87ab69bde6SJohannes Berg #define ALX_DEFAULT_TX_WORK 128
88ab69bde6SJohannes Berg 
89ab69bde6SJohannes Berg enum alx_device_quirks {
90ab69bde6SJohannes Berg 	ALX_DEV_QUIRK_MSI_INTX_DISABLE_BUG = BIT(0),
91ab69bde6SJohannes Berg };
92ab69bde6SJohannes Berg 
93*bccffcf7STobias Regnery struct alx_napi {
94*bccffcf7STobias Regnery 	struct napi_struct	napi;
95*bccffcf7STobias Regnery 	struct alx_priv		*alx;
96*bccffcf7STobias Regnery 	struct alx_rx_queue	*rxq;
97*bccffcf7STobias Regnery 	struct alx_tx_queue	*txq;
98*bccffcf7STobias Regnery 	int			vec_idx;
99*bccffcf7STobias Regnery 	u32			vec_mask;
100*bccffcf7STobias Regnery 	char			irq_lbl[IFNAMSIZ + 8];
101*bccffcf7STobias Regnery };
102*bccffcf7STobias Regnery 
103*bccffcf7STobias Regnery #define ALX_MAX_NAPIS 8
104*bccffcf7STobias Regnery 
1059ee7b683STobias Regnery #define ALX_FLAG_USING_MSIX	BIT(0)
1069ee7b683STobias Regnery #define ALX_FLAG_USING_MSI	BIT(1)
1079ee7b683STobias Regnery 
108ab69bde6SJohannes Berg struct alx_priv {
109ab69bde6SJohannes Berg 	struct net_device *dev;
110ab69bde6SJohannes Berg 
111ab69bde6SJohannes Berg 	struct alx_hw hw;
112ab69bde6SJohannes Berg 
113dc39a78bSTobias Regnery 	/* msi-x vectors */
114dc39a78bSTobias Regnery 	int num_vec;
115dc39a78bSTobias Regnery 	struct msix_entry *msix_entries;
116dc39a78bSTobias Regnery 	char irq_lbl[IFNAMSIZ + 8];
117dc39a78bSTobias Regnery 
118ab69bde6SJohannes Berg 	/* all descriptor memory */
119ab69bde6SJohannes Berg 	struct {
120ab69bde6SJohannes Berg 		dma_addr_t dma;
121ab69bde6SJohannes Berg 		void *virt;
1224a134c39SJohannes Berg 		unsigned int size;
123ab69bde6SJohannes Berg 	} descmem;
124ab69bde6SJohannes Berg 
125*bccffcf7STobias Regnery 	struct alx_napi *qnapi[ALX_MAX_NAPIS];
126*bccffcf7STobias Regnery 	int num_txq;
127*bccffcf7STobias Regnery 	int num_rxq;
128*bccffcf7STobias Regnery 	int num_napi;
129*bccffcf7STobias Regnery 
130ab69bde6SJohannes Berg 	/* protect int_mask updates */
131ab69bde6SJohannes Berg 	spinlock_t irq_lock;
132ab69bde6SJohannes Berg 	u32 int_mask;
133ab69bde6SJohannes Berg 
1344a134c39SJohannes Berg 	unsigned int tx_ringsz;
1354a134c39SJohannes Berg 	unsigned int rx_ringsz;
1364a134c39SJohannes Berg 	unsigned int rxbuf_size;
137ab69bde6SJohannes Berg 
138ab69bde6SJohannes Berg 	struct napi_struct napi;
139ab69bde6SJohannes Berg 	struct alx_tx_queue txq;
140ab69bde6SJohannes Berg 	struct alx_rx_queue rxq;
141ab69bde6SJohannes Berg 
142ab69bde6SJohannes Berg 	struct work_struct link_check_wk;
143ab69bde6SJohannes Berg 	struct work_struct reset_wk;
144ab69bde6SJohannes Berg 
145ab69bde6SJohannes Berg 	u16 msg_enable;
146ab69bde6SJohannes Berg 
1479ee7b683STobias Regnery 	int flags;
148f1b6b106SSabrina Dubroca 
149f1b6b106SSabrina Dubroca 	/* protects hw.stats */
150f1b6b106SSabrina Dubroca 	spinlock_t stats_lock;
151ab69bde6SJohannes Berg };
152ab69bde6SJohannes Berg 
153ab69bde6SJohannes Berg extern const struct ethtool_ops alx_ethtool_ops;
154ab69bde6SJohannes Berg extern const char alx_drv_name[];
155ab69bde6SJohannes Berg 
156ab69bde6SJohannes Berg #endif
157