summaryrefslogtreecommitdiff
path: root/lib/igb/igb_internal.h
blob: b99ee0636a36cea20cfdbe5670022903be31e0cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/******************************************************************************

  Copyright (c) 2001-2016, Intel Corporation
  All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions are met:

   1. Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.

   2. Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.

   3. Neither the name of the Intel Corporation nor the names of its
      contributors may be used to endorse or promote products derived from
      this software without specific prior written permission.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  POSSIBILITY OF SUCH DAMAGE.

******************************************************************************/
/*$FreeBSD$*/

#ifndef _IGB_INTERNAL_H_DEFINED_
#define _IGB_INTERNAL_H_DEFINED_

#include "igb.h"

/*
 * Micellaneous constants
 */
#define IGB_VENDOR_ID			0x8086

#define IGB_DEFAULT_PBA			0x00000030

#define PCI_ANY_ID                      (~0U)
#define ETHER_ALIGN                     2
#define IGB_TX_BUFFER_SIZE		((uint32_t) 1514)


#define IGB_RX_PTHRESH		8
#define IGB_RX_HTHRESH		8
#define IGB_RX_WTHRESH          4

#define IGB_TX_PTHRESH		8
#define IGB_TX_HTHRESH		1
#define IGB_TX_WTHRESH		16

/*
 * TDBA/RDBA should be aligned on 16 byte boundary. But TDLEN/RDLEN should be
 * multiple of 128 bytes. So we align TDBA/RDBA on 128 byte boundary. This will
 * also optimize cache line size effect. H/W supports up to cache line size 128.
 */
#define IGB_DBA_ALIGN			128

#define SPEED_MODE_BIT (1<<21)		/* On PCI-E MACs only */

#define IGB_MAX_SCATTER		64
#define IGB_VFTA_SIZE		128
#define IGB_BR_SIZE		4096	/* ring buf size */
#define IGB_TSO_SIZE		(65535 + sizeof(struct ether_vlan_header))
#define IGB_TSO_SEG_SIZE	4096	/* Max dma segment size */
#define IGB_HDR_BUF		128
#define IGB_PKTTYPE_MASK	0x0000FFF0
#define ETH_ZLEN		60
#define ETH_ADDR_LEN		6


/* Queue bit defines */
#define IGB_QUEUE_IDLE                  1
#define IGB_QUEUE_WORKING               2
#define IGB_QUEUE_HUNG                  4
#define IGB_QUEUE_DEPLETED              8

/*
 * This parameter controls when the driver calls the routine to reclaim
 * transmit descriptors. Cleaning earlier seems a win.
 **/
#define IGB_TX_CLEANUP_THRESHOLD        (adapter->num_tx_desc / 2)
#define IGB_QUEUE_THRESHOLD		(2)

/* Precision Time Sync (IEEE 1588) defines */
#define ETHERTYPE_IEEE1588	0x88F7
#define PICOSECS_PER_TICK	20833
#define TSYNC_PORT		319 /* UDP port for the protocol */

struct igb_tx_buffer {
	int next_eop; /* Index of the desc to watch */
	struct igb_packet *packet; /* app-relevant handle */
};

/*
 * Transmit ring: one per queue
 */
struct tx_ring {
	struct adapter *adapter;
	u32 me;
	struct resource txdma;
	struct e1000_tx_desc *tx_base;
	struct igb_tx_buffer *tx_buffers;
	u32 next_avail_desc;
	u32 next_to_clean;

	u16 tx_avail;

	u32 bytes;
	u32 packets;

	int tdt;
	int tdh;
	u64 no_desc_avail;
	u64 tx_packets;
	int queue_status;
};

struct igb_rx_buffer {
	int next_eop; /* Index of the desc to watch */
	struct igb_packet *packet; /* app-relevant handle */
};

/*
 * Receive ring: one per queue
 */
struct rx_ring {
	struct adapter *adapter;
	u32 me;
	struct resource rxdma;
	union e1000_adv_rx_desc *rx_base;
	bool hdr_split;
	u32 next_to_refresh;
	u32 next_to_check;
	struct igb_rx_buffer *rx_buffers;
	u32 bytes;
	u32 packets;
	int rdt;
	int rdh;

	/* Soft stats */
	u64 rx_split_packets;
	u64 rx_discarded;
	u64 rx_packets;
	u64 rx_bytes;

	sem_t lock;
};

struct adapter {
	struct e1000_hw hw;

	pthread_mutex_t *memlock;

	int ldev; /* file descriptor to igb */

	struct resource csr;
	int max_frame_size;
	int min_frame_size;
	int igb_insert_vlan_header;
	u16 num_queues;

	/* Interface queues */
	struct igb_queue *queues;

	/*
	 * rings
	 */
	struct tx_ring *tx_rings;
	u16 num_tx_desc;
	struct rx_ring *rx_rings;
	u16 num_rx_desc;
#ifdef IGB_IEEE1588
	/* IEEE 1588 precision time support */
	struct cyclecounter cycles;
	struct nettimer clock;
	struct nettime_compare compare;
	struct hwtstamp_ctrl hwtstamp;
#endif
	int active;
};

/*
 * vendor_info_array
 *
 * This array contains the list of Subvendor/Subdevice IDs on which the driver
 * should load.
 *
 */
typedef struct _igb_vendor_info_t {
	unsigned int vendor_id;
	unsigned int device_id;
	unsigned int subvendor_id;
	unsigned int subdevice_id;
	unsigned int index;
} igb_vendor_info_t;

/* external API requirements */
#define IGB_BIND       _IOW('E', 200, int)
#define IGB_UNBIND     _IOW('E', 201, int)
#define IGB_MAPRING    _IOW('E', 202, int)
#define IGB_MAP_TX_RING    IGB_MAPRING
#define IGB_UNMAPRING  _IOW('E', 203, int)
#define IGB_UNMAP_TX_RING  IGB_UNMAPRING
#define IGB_MAPBUF     _IOW('E', 204, int)
#define IGB_UNMAPBUF   _IOW('E', 205, int)
#define IGB_LINKSPEED  _IOW('E', 206, int)
#define IGB_MAP_RX_RING    _IOW('E', 207, int)
#define IGB_UNMAP_RX_RING  _IOW('E', 208, int)

#define IGB_BIND_NAMESZ 24

struct igb_bind_cmd {
	char iface[IGB_BIND_NAMESZ];
	unsigned mmap_size;
};

struct igb_buf_cmd {
	u_int64_t physaddr; /* dma_addr_t is 64-bit */
	unsigned int queue;
	unsigned int mmap_size;
};

struct igb_link_cmd {
	u_int32_t up; /* dma_addr_t is 64-bit */
	u_int32_t speed;
	u_int32_t duplex;
};


#endif /* _IGB_H_DEFINED_ */