summaryrefslogtreecommitdiff
path: root/minix/drivers/net/ip1000/ip1000.h
blob: 7ed366505a17eee234784eb9a4dbdbca5c152e4d (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
#ifndef _NDR_H
#define _NDR_H

/* ======= General Parameter ======= */
/* Global configure */

#include <minix/drivers.h>

#define DRIVER_NAME		"IP1000"

/* Rx/Tx buffer parameter */
#define RX_BUF_SIZE		1536
#define TX_BUF_SIZE		1536
#define RX_BUFFER_NUM	64
#define TX_BUFFER_NUM	64

/* Interrupt status */
#define INTR_STS_LINK	0x0100
#define INTR_STS_RX		0x0400
#define INTR_STS_TX		0x0200

/* Link status */
#define LINK_UP			1
#define LINK_DOWN		0
#define LINK_UNKNOWN	-1

/* Interrupt control */
#define INTR_ENABLE		1
#define INTR_DISABLE	0

/* Rx status */
#define RX_ERROR		1
#define RX_OK			0
#define RX_SUSPEND		-1

/* Tx status */
#define TX_ERROR		1
#define TX_OK			0
#define TX_SUSPEND		-1

/* Rx/Tx control */
#define RX_TX_ENABLE	1
#define RX_TX_DISABLE	0

/* ======= Self-defined Parameter ======= */
#define RFI_FRAG_LEN		0xffff000000000000ULL
#define RFS_FRAME_LEN		0x000000000000ffffULL
#define RFS_FRAME_START		0x0000000020000000ULL
#define RFS_FRAME_END		0x0000000040000000ULL
#define RFS_RFD_DONE		0x0000000080000000ULL
#define RFS_ERROR			0x00000000003f0000ULL
#define RFS_NORMAL			(RFS_RFD_DONE | RFS_FRAME_START | RFS_FRAME_END)

#define TFI_FRAG_LEN		0xffff000000000000ULL
#define TFS_FRAMEID			0x000000000000ffffULL
#define TFS_WORD_ALIGN		0x0000000000030000ULL
#define TFS_TX_DMA_INDICATE	0x0000000000800000ULL
#define TFS_FRAG_COUNT		0x000000000f000000ULL
#define TFS_TFD_DONE		0x0000000080000000ULL

#define REG_DMA_CTRL		0x00
#define REG_TX_DESC_BASEL	0x10
#define REG_TX_DESC_BASEU	0x14
#define REG_TX_DMA_BTH		0x18
#define REG_TX_DMA_UTH		0x19
#define REG_TX_DMA_PERIOD	0x1a
#define REG_RX_DESC_BASEL	0x1c
#define REG_RX_DESC_BASEU	0x20
#define REG_RX_DMA_BTH		0x24
#define REG_RX_DMA_UTH		0x25
#define REG_RX_DMA_PERIOD	0x26
#define REG_ASIC_CTRL		0x30
#define REG_FLOW_OFF_TH		0x3c
#define REG_FLOW_ON_TH		0x3e
#define REG_EEPROM_DATA		0x48
#define REG_EEPROM_CTRL		0x4a
#define REG_ISR				0x5a
#define REG_IMR				0x5c
#define REG_MAC_CTRL		0x6c
#define REG_PHY_SET			0x75
#define REG_PHY_CTRL		0x76
#define REG_STA_ADDR0		0x78
#define REG_STA_ADDR1		0x7a
#define REG_STA_ADDR2		0x7c
#define REG_MAX_FRAME		0x86
#define REG_RCR				0x88

#define AC_LED_MODE		0x00004000
#define AC_GB_RESET		0x00010000
#define AC_RX_RESET		0x00020000
#define AC_TX_RESET		0x00040000
#define AC_DMA			0x00080000
#define AC_FIFO			0x00100000
#define AC_NETWORK		0x00200000
#define AC_HOST			0x00400000
#define AC_AUTO_INIT	0x00800000
#define AC_RESET_BUSY	0x04000000
#define AC_LED_SPEED	0x08000000
#define AC_LED_MODE_B1	0x20000000
#define AC_RESET_ALL	(AC_GB_RESET | AC_RX_RESET | AC_TX_RESET | AC_DMA | \
						AC_FIFO | AC_NETWORK | AC_HOST | AC_AUTO_INIT)

#define MC_DUPLEX_SEL	0x00000020
#define MC_TX_FC_ENA	0x00000080
#define MC_RX_FC_ENA	0x00000100
#define MC_STAT_DISABLE	0x00400000
#define MC_TX_ENABLE	0x01000000
#define MC_TX_DISABLE	0x02000000
#define MC_RX_ENABLE	0x08000000
#define MC_RX_DISABLE	0x10000000
#define MC_PAUSED		0x40000000

#define PC_DUPLEX_STS		0x10
#define PC_LINK_SPEED		0xc0
#define PC_LINK_SPEED10		0x40
#define PC_LINK_SPEED100	0x80
#define PC_LINK_SPEED1000	0xc0

#define CMD_INTR_ENABLE		0x17e6
#define CMD_RCR_UNICAST		0x01
#define CMD_RCR_MULTICAST	0x02
#define CMD_RCR_BROADCAST	0x04
#define CMD_TX_START		0x1000

#define EC_READ		0x0200
#define EC_BUSY		0x8000

static u16_t PhyParam[] = {
	(0x4000|(07*4)), 31, 0x0001, 27, 0x01e0, 31, 0x0002, 27, 0xeb8e, 31, 0x0000,
					30, 0x005e, 9, 0x0700,
	(0x4100|(07*4)), 31, 0x0001, 27, 0x01e0, 31, 0x0002, 27, 0xeb8e, 31, 0x0000,
					30, 0x005e, 9, 0x0700,
	(0x4200|(07*4)), 31, 0x0001, 27, 0x01e0, 31, 0x0002, 27, 0xeb8e, 31, 0x0000,
					30, 0x005e, 9, 0x0700,
	(0x4300|(07*4)), 31, 0x0001, 27, 0x01e0, 31, 0x0002, 27, 0xeb8e, 31, 0x0000,
					30, 0x005e, 9, 0x0700, 0x0000
};

/* ======= Data Descriptor ======= */
typedef struct NDR_desc {
	u64_t next;
	u64_t status;
	u64_t frag_info;
} NDR_desc;

/* Driver Data Structure */
typedef struct NDR_driver {
	char *dev_name;			/* Device name */
	u16_t vid, did;			/* Vendor and device ID */
	u32_t devind;			/* Device index */
	u32_t base[6];			/* Base address */
	char irq;				/* IRQ number */
	char revision;			/* Revision ID */

	int mode;
	int link;				/* Whether link-up */
	int recv_flag;			/* Receive flag */
	int send_flag;			/* Send flag */
	int tx_busy;			/* Whether Tx is busy */

	/* Buffer */
	size_t buf_size;
	char *buf;

	/* Rx data */
	int rx_head;
	struct {
		phys_bytes buf_dma;
		char *buf;
	} rx[RX_BUFFER_NUM];

	/* Tx data */
	int tx_head;
	int tx_tail;
	struct {
		int busy;
		phys_bytes buf_dma;
		char *buf;
	} tx[TX_BUFFER_NUM];
	int tx_busy_num;			/* Number of busy Tx buffer */

	NDR_desc *rx_desc;			/* Rx descriptor buffer */
	phys_bytes rx_desc_dma;		/* Rx descriptor DMA buffer */
	NDR_desc *tx_desc;			/* Tx descriptor buffer */
	phys_bytes tx_desc_dma;		/* Tx descriptor DMA buffer */

	int hook;			/* IRQ hook id at kernel */
} NDR_driver;

#endif