summaryrefslogtreecommitdiff
path: root/usr/src/uts/intel/io/amd8111s/amd8111s_main.h
blob: 00f430273fb01fa306b054f44cc601455f4e9013 (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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/*
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef AMD8111S_MAIN_H
#define	AMD8111S_MAIN_H

/*
 * Copyright (c) 2001-2006 Advanced Micro Devices, Inc.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * + Redistributions of source code must retain the above copyright notice,
 * + this list of conditions and the following disclaimer.
 *
 * + 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.
 *
 * + Neither the name of Advanced Micro Devices, Inc. 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 ADVANCED MICRO DEVICES, INC. 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.
 *
 * Import/Export/Re-Export/Use/Release/Transfer Restrictions and
 * Compliance with Applicable Laws.  Notice is hereby given that
 * the software may be subject to restrictions on use, release,
 * transfer, importation, exportation and/or re-exportation under
 * the laws and regulations of the United States or other
 * countries ("Applicable Laws"), which include but are not
 * limited to U.S. export control laws such as the Export
 * Administration Regulations and national security controls as
 * defined thereunder, as well as State Department controls under
 * the U.S. Munitions List.  Permission to use and/or
 * redistribute the software is conditioned upon compliance with
 * all Applicable Laws, including U.S. export control laws
 * regarding specifically designated persons, countries and
 * nationals of countries subject to national security controls.
 */

#include <sys/types.h>
#include <sys/errno.h>
#include <sys/kmem.h>
#include <sys/conf.h>
#include <sys/stat.h>
#include <sys/note.h>
#include <sys/modctl.h>

#include <sys/stream.h>
#include <sys/strsubr.h>
#include <sys/strsun.h>

#include <sys/dditypes.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>

#include <sys/pci.h>

#include <sys/ethernet.h>
#include <sys/dlpi.h>
#include <sys/mac_provider.h>
#include <sys/mac_ether.h>
#include <sys/netlb.h>
#include "amd8111s_hw.h"

#define	MEM_REQ_MAX		100
#define	MEMSET			4

#define	IOC_LINESIZE	40

/*
 * Loopback definitions
 */
#define	AMD8111S_LB_NONE			0
#define	AMD8111S_LB_EXTERNAL_1000		1
#define	AMD8111S_LB_EXTERNAL_100		2
#define	AMD8111S_LB_EXTERNAL_10			3
#define	AMD8111S_LB_INTERNAL_PHY		4
#define	AMD8111S_LB_INTERNAL_MAC		5

/* ((2 ^ (32 - 1)) * 8) / (10 ^ 8) >= 100 */
#define	AMD8111S_DUMP_MIB_SECONDS_THRESHOLD	100
#define	AMD8111S_DUMP_MIB_BYTES_THRESHOLD	0x80000000

/* Bit flags for 'attach_progress' */
#define	AMD8111S_ATTACH_PCI		0x0001	/* pci_config_setup() */
#define	AMD8111S_ATTACH_RESOURCE	0x0002	/* odlInit() */
#define	AMD8111S_ATTACH_REGS		0x0004	/* ddi_regs_map_setup() */
#define	AMD8111S_ATTACH_INTRADDED	0x0010	/* intr_add() */
#define	AMD8111S_ATTACH_MACREGED	0x0020	/* mac_register() */
#define	AMD8111S_ATTACH_RESCHED		0x0040	/* soft_intr() */

#define	AMD8111S_TRY_SEND		0x0001
#define	AMD8111S_SEND_READY		0x0002

#define	NEXT(buf, ptr) \
	(buf.ptr + 1 >= buf.msg_buf + \
	buf.ring_size ? \
	buf.msg_buf : \
	buf.ptr + 1)
/*
 * (Internal) return values from ioctl subroutines
 */
enum ioc_reply {
	IOC_INVAL = -1,				/* bad, NAK with EINVAL	*/
	IOC_DONE,				/* OK, reply sent	*/
	IOC_ACK,				/* OK, just send ACK	*/
	IOC_REPLY,				/* OK, just send reply	*/
	IOC_RESTART_ACK,			/* OK, restart & ACK	*/
	IOC_RESTART_REPLY			/* OK, restart & reply	*/
};

typedef int (*TIMERfUNC) (struct LayerPointers *);

struct TimerStructure {
	int Type;
	int Period;	/* in milliseconds */
	timeout_id_t TimerHandle;
	int (*TimerFunptr)(struct LayerPointers *);
	struct LayerPointers *pLayerPointers;
};

struct amd8111s_statistics
{
	uint64_t intr_TINT0;	/* # of TINT0 (Tx interrupts) */
	uint64_t intr_RINT0;	/* # of RINT0 (Rx interrupts) */
	uint64_t intr_STINT;	/* # of STINT (Software Timer Intr) */
	uint64_t intr_OTHER;	/* Intr caused by other device */

	uint64_t tx_ok_packets;
	uint64_t tx_no_descriptor;
	uint64_t tx_no_buffer;
	uint64_t tx_rescheduled;
	uint64_t tx_unrescheduled;

	/* # of call amd8111s_dump_mib function */
	uint64_t mib_dump_counter;

	/*
	 * From MIB registers (TX)
	 */
	uint64_t tx_mib_packets;		/* # of packets */
	uint64_t tx_mib_multicst_packets;	/* # of multicast packets */
	uint64_t tx_mib_broadcst_packets;	/* # of broadcast packets */
	uint64_t tx_mib_flowctrl_packets;	/* # of flow ctrl packets */

	uint64_t tx_mib_bytes;			/* # of all Tx bytes */

	/* Packet drop due to Tx FIFO underrun */
	uint64_t tx_mib_underrun_packets;
	uint64_t tx_mib_collision_packets;
	/* Packets successfully transmitted after experiencing one collision */
	uint64_t tx_mib_one_coll_packets;
	uint64_t tx_mib_multi_coll_packets;
	/* # of late collisions that occur */
	uint64_t tx_mib_late_coll_packets;
	uint64_t tx_mib_ex_coll_packets;	/* excessive collision */
	uint64_t tx_mib_oversize_packets;
	uint64_t tx_mib_defer_trans_packets;	/* defer transmit */


	/*
	 * Some error counter after "ifconfig amd8111sX unplumb"
	 */
	/*
	 * Count Tx mp number from GLD even after NIC has been unplumbed.
	 * This value should always be 0.
	 */
	uint64_t tx_afterunplumb;
	/*
	 * We drain all pending tx packets during unplumb operation. This
	 * variable is to count the drain time.
	 *	30 means success; =30 means fail
	 */
	uint64_t tx_draintime;

	uint64_t rx_ok_packets;		/* # of all good packets */
	uint64_t rx_allocfail;		/* alloc memory fail during Rx */
	uint64_t rx_error_zerosize;

	uint64_t rx_0_packets;
	uint64_t rx_1_15_packets;
	uint64_t rx_16_31_packets;
	uint64_t rx_32_47_packets;
	uint64_t rx_48_63_packets;
	uint64_t rx_double_overflow;

	uint64_t rx_desc_err;
	uint64_t rx_desc_err_FRAM;	/* Framing error */
	uint64_t rx_desc_err_OFLO;	/* Overflow error */
	uint64_t rx_desc_err_CRC;	/* CRC error */
	uint64_t rx_desc_err_BUFF;	/* BCRC error */

	/*
	 * From MIB registers (RX)
	 */
	uint64_t rx_mib_unicst_packets;		/* # of unicast packets */
	uint64_t rx_mib_multicst_packets;	/* # of multicast packets */
	uint64_t rx_mib_broadcst_packets;	/* # of broadcast packets */
	uint64_t rx_mib_macctrl_packets;	/* # of mac ctrl packets */
	uint64_t rx_mib_flowctrl_packets;	/* # of flow ctrl packets */

	uint64_t rx_mib_bytes;			/* # of all Rx bytes */
	uint64_t rx_mib_good_bytes;			/* # of all Rx bytes */
	/*
	 * The total number of valid frames received that are less than 64
	 * bytes long (include the FCS).
	 */
	uint64_t rx_mib_undersize_packets;
	/*
	 * The total number of valid frames received that are greater than the
	 * maximum valid frame size (include the FCS).
	 */
	uint64_t rx_mib_oversize_packets;

	uint64_t rx_mib_align_err_packets;
	uint64_t rx_mib_fcs_err_packets;	/* has a bad FCS */
	/* Invalid data symbol (RX_ER) */
	uint64_t rx_mib_symbol_err_packets;
	/* Packets that were dropped because no descriptor was available */
	uint64_t rx_mib_drop_packets;
	/*
	 * Packets that were dropped due to lack of resources. This includes
	 * the number of times a packet was dropped due to receive FIFO
	 * overflow and lack of receive descriptor.
	 */
	uint64_t rx_mib_miss_packets;
};

struct amd8111s_msgbuf {
	uint64_t phy_addr;
	caddr_t vir_addr;
	uint32_t msg_size;
	ddi_dma_handle_t p_hdl;
	uint32_t offset;
};

struct amd8111s_dma_ringbuf {
	ddi_dma_handle_t *dma_hdl;
	ddi_acc_handle_t *acc_hdl;
	ddi_dma_cookie_t *dma_cookie;
	caddr_t		 *trunk_addr;
	uint32_t buf_sz;
	uint32_t trunk_sz;
	uint32_t trunk_num;
	struct amd8111s_msgbuf	*msg_buf;
	uint32_t ring_size;
	uint32_t dma_buf_sz;
	struct amd8111s_msgbuf *free;
	struct amd8111s_msgbuf *next;
	struct amd8111s_msgbuf *curr;

	kmutex_t ring_lock;
};

struct odl {
	dev_info_t *devinfo;

	mac_handle_t mh;		/* mac module handle */

	struct amd8111s_statistics statistics;

	/* Locks */
	kmutex_t mdlSendLock;
	kmutex_t mdlRcvLock;
	kmutex_t timer_lock;
	kmutex_t send_cv_lock;
	kcondvar_t send_cv;

	ddi_softintr_t drain_id;
	/*
	 * The chip_lock assures that the Rx/Tx process must be stopped while
	 * other functions change the hardware configuration, such as attach()
	 * detach() etc are executed.
	 */
	krwlock_t chip_lock;

	/*
	 * HW operators and parameters on attach period
	 */
	ddi_iblock_cookie_t iblock;	/* HW: interrupt block cookie */
	ddi_acc_handle_t MemBasehandle;

	/* For pci configuration */
	ddi_acc_handle_t pci_handle;	/* HW: access handle of PCI space */
	uint16_t vendor_id;
	uint16_t device_id;

	/*
	 * FreeQ: Transfer Rx Buffer parameters from top layer to low layers.
	 * Format of parameter:
	 *	(struct RxBufInfo *, physical address)
	 */
	unsigned long FreeQ[2 * RX_RING_SIZE];
	unsigned long *FreeQStart;
	unsigned long *FreeQEnd;
	long *FreeQWrite;
	long *FreeQRead;

	/* For Rx descriptors */
	ddi_dma_handle_t rx_desc_dma_handle;
	ddi_acc_handle_t rx_desc_acc_handle;
	ddi_dma_cookie_t rx_desc_dma_cookie;

	/* For Tx descriptors */
	ddi_dma_handle_t tx_desc_dma_handle;
	ddi_acc_handle_t tx_desc_acc_handle;
	ddi_dma_cookie_t tx_desc_dma_cookie;

	/* For Tx buffers */
	struct amd8111s_dma_ringbuf tx_buf;

	/* For Rx buffers */
	struct amd8111s_dma_ringbuf rx_buf;

	ether_addr_t MacAddress;	/* Mac address */

	/* Multicast addresses table */
	UCHAR MulticastAddresses
	    [MAX_MULTICAST_ADDRESSES][ETH_LENGTH_OF_ADDRESS];

	link_state_t LinkStatus;

	/* Timer */
	timeout_id_t Timer_id;
	int (*TimerFunc)(struct LayerPointers *);
	int timer_run;
	int timer_linkdown;

	unsigned int dump_mib_seconds;

	uint32_t loopback_mode;
	unsigned int rx_fcs_stripped;

	unsigned int rx_overflow_counter;
	unsigned int pause_interval;

};

#endif	/* AMD8111S_MAIN_H */