1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*******************************************************************************
3 
4   Intel(R) 82576 Virtual Function Linux driver
5   Copyright(c) 2009 - 2012 Intel Corporation.
6 
7   This program is free software; you can redistribute it and/or modify it
8   under the terms and conditions of the GNU General Public License,
9   version 2, as published by the Free Software Foundation.
10 
11   This program is distributed in the hope it will be useful, but WITHOUT
12   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14   more details.
15 
16   You should have received a copy of the GNU General Public License along with
17   this program; if not, see <http://www.gnu.org/licenses/>.
18 
19   The full GNU General Public License is included in this distribution in
20   the file called "COPYING".
21 
22   Contact Information:
23   e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 
26 *******************************************************************************/
27 
28 /* Linux PRO/1000 Ethernet Driver main header file */
29 
30 #ifndef _IGBVF_H_
31 #define _IGBVF_H_
32 
33 #include <linux/types.h>
34 #include <linux/timer.h>
35 #include <linux/io.h>
36 #include <linux/netdevice.h>
37 #include <linux/if_vlan.h>
38 
39 #include "vf.h"
40 
41 /* Forward declarations */
42 struct igbvf_info;
43 struct igbvf_adapter;
44 
45 /* Interrupt defines */
46 #define IGBVF_START_ITR		488 /* ~8000 ints/sec */
47 #define IGBVF_4K_ITR		980
48 #define IGBVF_20K_ITR		196
49 #define IGBVF_70K_ITR		56
50 
51 enum latency_range {
52 	lowest_latency = 0,
53 	low_latency = 1,
54 	bulk_latency = 2,
55 	latency_invalid = 255
56 };
57 
58 /* Interrupt modes, as used by the IntMode parameter */
59 #define IGBVF_INT_MODE_LEGACY	0
60 #define IGBVF_INT_MODE_MSI	1
61 #define IGBVF_INT_MODE_MSIX	2
62 
63 /* Tx/Rx descriptor defines */
64 #define IGBVF_DEFAULT_TXD	256
65 #define IGBVF_MAX_TXD		4096
66 #define IGBVF_MIN_TXD		80
67 
68 #define IGBVF_DEFAULT_RXD	256
69 #define IGBVF_MAX_RXD		4096
70 #define IGBVF_MIN_RXD		80
71 
72 #define IGBVF_MIN_ITR_USECS	10 /* 100000 irq/sec */
73 #define IGBVF_MAX_ITR_USECS	10000 /* 100    irq/sec */
74 
75 /* RX descriptor control thresholds.
76  * PTHRESH - MAC will consider prefetch if it has fewer than this number of
77  *	   descriptors available in its onboard memory.
78  *	   Setting this to 0 disables RX descriptor prefetch.
79  * HTHRESH - MAC will only prefetch if there are at least this many descriptors
80  *	   available in host memory.
81  *	   If PTHRESH is 0, this should also be 0.
82  * WTHRESH - RX descriptor writeback threshold - MAC will delay writing back
83  *	   descriptors until either it has this many to write back, or the
84  *	   ITR timer expires.
85  */
86 #define IGBVF_RX_PTHRESH	16
87 #define IGBVF_RX_HTHRESH	8
88 #define IGBVF_RX_WTHRESH	1
89 
90 /* this is the size past which hardware will drop packets when setting LPE=0 */
91 #define MAXIMUM_ETHERNET_VLAN_SIZE	1522
92 
93 #define IGBVF_FC_PAUSE_TIME	0x0680 /* 858 usec */
94 
95 /* How many Tx Descriptors do we need to call netif_wake_queue ? */
96 #define IGBVF_TX_QUEUE_WAKE	32
97 /* How many Rx Buffers do we bundle into one write to the hardware ? */
98 #define IGBVF_RX_BUFFER_WRITE	16 /* Must be power of 2 */
99 
100 #define AUTO_ALL_MODES		0
101 #define IGBVF_EEPROM_APME	0x0400
102 
103 #define IGBVF_MNG_VLAN_NONE	(-1)
104 
105 #define IGBVF_MAX_MAC_FILTERS	3
106 
107 /* Number of packet split data buffers (not including the header buffer) */
108 #define PS_PAGE_BUFFERS		(MAX_PS_BUFFERS - 1)
109 
110 enum igbvf_boards {
111 	board_vf,
112 	board_i350_vf,
113 };
114 
115 struct igbvf_queue_stats {
116 	u64 packets;
117 	u64 bytes;
118 };
119 
120 /* wrappers around a pointer to a socket buffer,
121  * so a DMA handle can be stored along with the buffer
122  */
123 struct igbvf_buffer {
124 	dma_addr_t dma;
125 	struct sk_buff *skb;
126 	union {
127 		/* Tx */
128 		struct {
129 			unsigned long time_stamp;
130 			union e1000_adv_tx_desc *next_to_watch;
131 			u16 length;
132 			u16 mapped_as_page;
133 		};
134 		/* Rx */
135 		struct {
136 			struct page *page;
137 			u64 page_dma;
138 			unsigned int page_offset;
139 		};
140 	};
141 };
142 
143 union igbvf_desc {
144 	union e1000_adv_rx_desc rx_desc;
145 	union e1000_adv_tx_desc tx_desc;
146 	struct e1000_adv_tx_context_desc tx_context_desc;
147 };
148 
149 struct igbvf_ring {
150 	struct igbvf_adapter *adapter;  /* backlink */
151 	union igbvf_desc *desc;	/* pointer to ring memory  */
152 	dma_addr_t dma;		/* phys address of ring    */
153 	unsigned int size;	/* length of ring in bytes */
154 	unsigned int count;	/* number of desc. in ring */
155 
156 	u16 next_to_use;
157 	u16 next_to_clean;
158 
159 	u16 head;
160 	u16 tail;
161 
162 	/* array of buffer information structs */
163 	struct igbvf_buffer *buffer_info;
164 	struct napi_struct napi;
165 
166 	char name[IFNAMSIZ + 5];
167 	u32 eims_value;
168 	u32 itr_val;
169 	enum latency_range itr_range;
170 	u16 itr_register;
171 	int set_itr;
172 
173 	struct sk_buff *rx_skb_top;
174 
175 	struct igbvf_queue_stats stats;
176 };
177 
178 /* board specific private data structure */
179 struct igbvf_adapter {
180 	struct timer_list watchdog_timer;
181 	struct timer_list blink_timer;
182 
183 	struct work_struct reset_task;
184 	struct work_struct watchdog_task;
185 
186 	const struct igbvf_info *ei;
187 
188 	unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
189 	u32 bd_number;
190 	u32 rx_buffer_len;
191 	u32 polling_interval;
192 	u16 mng_vlan_id;
193 	u16 link_speed;
194 	u16 link_duplex;
195 
196 	spinlock_t tx_queue_lock; /* prevent concurrent tail updates */
197 
198 	/* track device up/down/testing state */
199 	unsigned long state;
200 
201 	/* Interrupt Throttle Rate */
202 	u32 requested_itr; /* ints/sec or adaptive */
203 	u32 current_itr; /* Actual ITR register value, not ints/sec */
204 
205 	/* Tx */
206 	struct igbvf_ring *tx_ring /* One per active queue */
207 	____cacheline_aligned_in_smp;
208 
209 	unsigned int restart_queue;
210 	u32 txd_cmd;
211 
212 	u32 tx_int_delay;
213 	u32 tx_abs_int_delay;
214 
215 	unsigned int total_tx_bytes;
216 	unsigned int total_tx_packets;
217 	unsigned int total_rx_bytes;
218 	unsigned int total_rx_packets;
219 
220 	/* Tx stats */
221 	u32 tx_timeout_count;
222 	u32 tx_fifo_head;
223 	u32 tx_head_addr;
224 	u32 tx_fifo_size;
225 	u32 tx_dma_failed;
226 
227 	/* Rx */
228 	struct igbvf_ring *rx_ring;
229 
230 	u32 rx_int_delay;
231 	u32 rx_abs_int_delay;
232 
233 	/* Rx stats */
234 	u64 hw_csum_err;
235 	u64 hw_csum_good;
236 	u64 rx_hdr_split;
237 	u32 alloc_rx_buff_failed;
238 	u32 rx_dma_failed;
239 
240 	unsigned int rx_ps_hdr_size;
241 	u32 max_frame_size;
242 	u32 min_frame_size;
243 
244 	/* OS defined structs */
245 	struct net_device *netdev;
246 	struct pci_dev *pdev;
247 	spinlock_t stats_lock; /* prevent concurrent stats updates */
248 
249 	/* structs defined in e1000_hw.h */
250 	struct e1000_hw hw;
251 
252 	/* The VF counters don't clear on read so we have to get a base
253 	 * count on driver start up and always subtract that base on
254 	 * on the first update, thus the flag..
255 	 */
256 	struct e1000_vf_stats stats;
257 	u64 zero_base;
258 
259 	struct igbvf_ring test_tx_ring;
260 	struct igbvf_ring test_rx_ring;
261 	u32 test_icr;
262 
263 	u32 msg_enable;
264 	struct msix_entry *msix_entries;
265 	int int_mode;
266 	u32 eims_enable_mask;
267 	u32 eims_other;
268 	u32 int_counter0;
269 	u32 int_counter1;
270 
271 	u32 eeprom_wol;
272 	u32 wol;
273 	u32 pba;
274 
275 	bool fc_autoneg;
276 
277 	unsigned long led_status;
278 
279 	unsigned int flags;
280 	unsigned long last_reset;
281 };
282 
283 struct igbvf_info {
284 	enum e1000_mac_type	mac;
285 	unsigned int		flags;
286 	u32			pba;
287 	void			(*init_ops)(struct e1000_hw *);
288 	s32			(*get_variants)(struct igbvf_adapter *);
289 };
290 
291 /* hardware capability, feature, and workaround flags */
292 #define IGBVF_FLAG_RX_CSUM_DISABLED	BIT(0)
293 #define IGBVF_FLAG_RX_LB_VLAN_BSWAP	BIT(1)
294 #define IGBVF_RX_DESC_ADV(R, i)     \
295 	(&((((R).desc))[i].rx_desc))
296 #define IGBVF_TX_DESC_ADV(R, i)     \
297 	(&((((R).desc))[i].tx_desc))
298 #define IGBVF_TX_CTXTDESC_ADV(R, i) \
299 	(&((((R).desc))[i].tx_context_desc))
300 
301 enum igbvf_state_t {
302 	__IGBVF_TESTING,
303 	__IGBVF_RESETTING,
304 	__IGBVF_DOWN
305 };
306 
307 extern char igbvf_driver_name[];
308 extern const char igbvf_driver_version[];
309 
310 void igbvf_check_options(struct igbvf_adapter *);
311 void igbvf_set_ethtool_ops(struct net_device *);
312 
313 int igbvf_up(struct igbvf_adapter *);
314 void igbvf_down(struct igbvf_adapter *);
315 void igbvf_reinit_locked(struct igbvf_adapter *);
316 int igbvf_setup_rx_resources(struct igbvf_adapter *, struct igbvf_ring *);
317 int igbvf_setup_tx_resources(struct igbvf_adapter *, struct igbvf_ring *);
318 void igbvf_free_rx_resources(struct igbvf_ring *);
319 void igbvf_free_tx_resources(struct igbvf_ring *);
320 void igbvf_update_stats(struct igbvf_adapter *);
321 
322 extern unsigned int copybreak;
323 
324 #endif /* _IGBVF_H_ */
325