xref: /openbmc/linux/drivers/net/ethernet/atheros/alx/alx.h (revision 762f99f4f3cb41a775b5157dd761217beba65873)
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 {
53bccffcf7STobias Regnery 	struct net_device *netdev;
54bccffcf7STobias Regnery 	struct device *dev;
55bccffcf7STobias Regnery 	struct alx_napi *np;
56bccffcf7STobias 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 
65bccffcf7STobias Regnery 	u16 count;
66ab69bde6SJohannes Berg 	u16 write_idx, read_idx;
67ab69bde6SJohannes Berg 	u16 rrd_read_idx;
68bccffcf7STobias Regnery 	u16 queue_idx;
69ab69bde6SJohannes Berg };
70ab69bde6SJohannes Berg #define ALX_RX_ALLOC_THRESH	32
71ab69bde6SJohannes Berg 
72ab69bde6SJohannes Berg struct alx_tx_queue {
73bccffcf7STobias Regnery 	struct net_device *netdev;
74bccffcf7STobias Regnery 	struct device *dev;
75bccffcf7STobias Regnery 
76ab69bde6SJohannes Berg 	struct alx_txd *tpd;
77ab69bde6SJohannes Berg 	dma_addr_t tpd_dma;
78bccffcf7STobias Regnery 
79ab69bde6SJohannes Berg 	struct alx_buffer *bufs;
80bccffcf7STobias Regnery 
81bccffcf7STobias Regnery 	u16 count;
82ab69bde6SJohannes Berg 	u16 write_idx, read_idx;
83bccffcf7STobias Regnery 	u16 queue_idx;
84bccffcf7STobias 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 
93bccffcf7STobias Regnery struct alx_napi {
94bccffcf7STobias Regnery 	struct napi_struct	napi;
95bccffcf7STobias Regnery 	struct alx_priv		*alx;
96bccffcf7STobias Regnery 	struct alx_rx_queue	*rxq;
97bccffcf7STobias Regnery 	struct alx_tx_queue	*txq;
98bccffcf7STobias Regnery 	int			vec_idx;
99bccffcf7STobias Regnery 	u32			vec_mask;
100bccffcf7STobias Regnery 	char			irq_lbl[IFNAMSIZ + 8];
101bccffcf7STobias Regnery };
102bccffcf7STobias Regnery 
103bccffcf7STobias Regnery #define ALX_MAX_NAPIS 8
104bccffcf7STobias Regnery 
105ab69bde6SJohannes Berg struct alx_priv {
106ab69bde6SJohannes Berg 	struct net_device *dev;
107ab69bde6SJohannes Berg 
108ab69bde6SJohannes Berg 	struct alx_hw hw;
109ab69bde6SJohannes Berg 
110dc39a78bSTobias Regnery 	/* msi-x vectors */
111dc39a78bSTobias Regnery 	int num_vec;
112dc39a78bSTobias Regnery 
113ab69bde6SJohannes Berg 	/* all descriptor memory */
114ab69bde6SJohannes Berg 	struct {
115ab69bde6SJohannes Berg 		dma_addr_t dma;
116ab69bde6SJohannes Berg 		void *virt;
1174a134c39SJohannes Berg 		unsigned int size;
118ab69bde6SJohannes Berg 	} descmem;
119ab69bde6SJohannes Berg 
120bccffcf7STobias Regnery 	struct alx_napi *qnapi[ALX_MAX_NAPIS];
121bccffcf7STobias Regnery 	int num_txq;
122bccffcf7STobias Regnery 	int num_rxq;
123bccffcf7STobias Regnery 	int num_napi;
124bccffcf7STobias Regnery 
125ab69bde6SJohannes Berg 	/* protect int_mask updates */
126ab69bde6SJohannes Berg 	spinlock_t irq_lock;
127ab69bde6SJohannes Berg 	u32 int_mask;
128ab69bde6SJohannes Berg 
1294a134c39SJohannes Berg 	unsigned int tx_ringsz;
1304a134c39SJohannes Berg 	unsigned int rx_ringsz;
1314a134c39SJohannes Berg 	unsigned int rxbuf_size;
132ab69bde6SJohannes Berg 
133ab69bde6SJohannes Berg 	struct work_struct link_check_wk;
134ab69bde6SJohannes Berg 	struct work_struct reset_wk;
135ab69bde6SJohannes Berg 
136ab69bde6SJohannes Berg 	u16 msg_enable;
137ab69bde6SJohannes Berg 
138f1b6b106SSabrina Dubroca 	/* protects hw.stats */
139f1b6b106SSabrina Dubroca 	spinlock_t stats_lock;
140*4a5fe57eSJohannes Berg 
141*4a5fe57eSJohannes Berg 	struct mutex mtx;
142ab69bde6SJohannes Berg };
143ab69bde6SJohannes Berg 
144ab69bde6SJohannes Berg extern const struct ethtool_ops alx_ethtool_ops;
145ab69bde6SJohannes Berg 
146ab69bde6SJohannes Berg #endif
147