1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef _EMAC_HW_H_
16#define _EMAC_HW_H_
17
18
19#define EMAC_EMAC_WRAPPER_CSR1 0x000000
20#define EMAC_EMAC_WRAPPER_CSR2 0x000004
21#define EMAC_EMAC_WRAPPER_TX_TS_LO 0x000104
22#define EMAC_EMAC_WRAPPER_TX_TS_HI 0x000108
23#define EMAC_EMAC_WRAPPER_TX_TS_INX 0x00010c
24
25
26enum emac_dma_order {
27 emac_dma_ord_in = 1,
28 emac_dma_ord_enh = 2,
29 emac_dma_ord_out = 4
30};
31
32enum emac_dma_req_block {
33 emac_dma_req_128 = 0,
34 emac_dma_req_256 = 1,
35 emac_dma_req_512 = 2,
36 emac_dma_req_1024 = 3,
37 emac_dma_req_2048 = 4,
38 emac_dma_req_4096 = 5
39};
40
41
42#define BITS_GET(val, lo, hi) ((le32_to_cpu(val) & GENMASK((hi), (lo))) >> lo)
43#define BITS_SET(val, lo, hi, new_val) \
44 val = cpu_to_le32((le32_to_cpu(val) & (~GENMASK((hi), (lo)))) | \
45 (((new_val) << (lo)) & GENMASK((hi), (lo))))
46
47
48struct emac_rrd {
49 u32 word[6];
50
51
52#define RRD_NOR(rrd) BITS_GET((rrd)->word[0], 16, 19)
53
54#define RRD_SI(rrd) BITS_GET((rrd)->word[0], 20, 31)
55
56#define RRD_CVALN_TAG(rrd) BITS_GET((rrd)->word[2], 0, 15)
57
58#define RRD_PKT_SIZE(rrd) BITS_GET((rrd)->word[3], 0, 13)
59
60#define RRD_L4F(rrd) BITS_GET((rrd)->word[3], 14, 14)
61
62#define RRD_CVTAG(rrd) BITS_GET((rrd)->word[3], 16, 16)
63
64
65
66#define RRD_UPDT(rrd) BITS_GET((rrd)->word[3], 31, 31)
67#define RRD_UPDT_SET(rrd, val) BITS_SET((rrd)->word[3], 31, 31, val)
68
69#define RRD_TS_LOW(rrd) BITS_GET((rrd)->word[4], 0, 29)
70
71#define RRD_TS_HI(rrd) le32_to_cpu((rrd)->word[5])
72};
73
74
75struct emac_tpd {
76 u32 word[4];
77
78
79#define TPD_BUF_LEN_SET(tpd, val) BITS_SET((tpd)->word[0], 0, 15, val)
80
81#define TPD_CSX_SET(tpd, val) BITS_SET((tpd)->word[1], 8, 8, val)
82
83#define TPD_LSO(tpd) BITS_GET((tpd)->word[1], 12, 12)
84#define TPD_LSO_SET(tpd, val) BITS_SET((tpd)->word[1], 12, 12, val)
85
86
87
88
89#define TPD_LSOV_SET(tpd, val) BITS_SET((tpd)->word[1], 13, 13, val)
90
91
92
93#define TPD_IPV4_SET(tpd, val) BITS_SET((tpd)->word[1], 16, 16, val)
94
95
96
97#define TPD_TYP_SET(tpd, val) BITS_SET((tpd)->word[1], 17, 17, val)
98
99#define TPD_BUFFER_ADDR_L_SET(tpd, val) ((tpd)->word[2] = cpu_to_le32(val))
100
101
102
103#define TPD_CVLAN_TAG_SET(tpd, val) BITS_SET((tpd)->word[3], 0, 15, val)
104
105
106#define TPD_INSTC_SET(tpd, val) BITS_SET((tpd)->word[3], 17, 17, val)
107
108
109
110
111#define TPD_BUFFER_ADDR_H_SET(tpd, val) BITS_SET((tpd)->word[3], 18, 31, val)
112
113
114
115#define TPD_PAYLOAD_OFFSET_SET(tpd, val) BITS_SET((tpd)->word[1], 0, 7, val)
116
117
118
119#define TPD_CXSUM_OFFSET_SET(tpd, val) BITS_SET((tpd)->word[1], 18, 25, val)
120
121
122#define TPD_TCPHDR_OFFSET_SET(tpd, val) BITS_SET((tpd)->word[1], 0, 7, val)
123
124
125#define TPD_MSS_SET(tpd, val) BITS_SET((tpd)->word[1], 18, 30, val)
126
127#define TPD_PKT_LEN_SET(tpd, val) ((tpd)->word[2] = cpu_to_le32(val))
128};
129
130
131
132
133struct emac_ring_header {
134 void *v_addr;
135 dma_addr_t dma_addr;
136 size_t size;
137 size_t used;
138};
139
140
141
142
143struct emac_buffer {
144 struct sk_buff *skb;
145 u16 length;
146 dma_addr_t dma_addr;
147};
148
149
150struct emac_rfd_ring {
151 struct emac_buffer *rfbuff;
152 u32 *v_addr;
153 dma_addr_t dma_addr;
154 size_t size;
155 unsigned int count;
156 unsigned int produce_idx;
157 unsigned int process_idx;
158 unsigned int consume_idx;
159};
160
161
162struct emac_rrd_ring {
163 u32 *v_addr;
164 dma_addr_t dma_addr;
165 size_t size;
166 unsigned int count;
167 unsigned int produce_idx;
168 unsigned int consume_idx;
169};
170
171
172struct emac_rx_queue {
173 struct net_device *netdev;
174 struct emac_rrd_ring rrd;
175 struct emac_rfd_ring rfd;
176 struct napi_struct napi;
177 struct emac_irq *irq;
178
179 u32 intr;
180 u32 produce_mask;
181 u32 process_mask;
182 u32 consume_mask;
183
184 u16 produce_reg;
185 u16 process_reg;
186 u16 consume_reg;
187
188 u8 produce_shift;
189 u8 process_shft;
190 u8 consume_shift;
191};
192
193
194struct emac_tpd_ring {
195 struct emac_buffer *tpbuff;
196 u32 *v_addr;
197 dma_addr_t dma_addr;
198
199 size_t size;
200 unsigned int count;
201 unsigned int produce_idx;
202 unsigned int consume_idx;
203 unsigned int last_produce_idx;
204};
205
206
207struct emac_tx_queue {
208 struct emac_tpd_ring tpd;
209
210 u32 produce_mask;
211 u32 consume_mask;
212
213 u16 max_packets;
214 u16 produce_reg;
215 u16 consume_reg;
216
217 u8 produce_shift;
218 u8 consume_shift;
219};
220
221struct emac_adapter;
222
223int emac_mac_up(struct emac_adapter *adpt);
224void emac_mac_down(struct emac_adapter *adpt);
225void emac_mac_reset(struct emac_adapter *adpt);
226void emac_mac_stop(struct emac_adapter *adpt);
227void emac_mac_mode_config(struct emac_adapter *adpt);
228void emac_mac_rx_process(struct emac_adapter *adpt, struct emac_rx_queue *rx_q,
229 int *num_pkts, int max_pkts);
230int emac_mac_tx_buf_send(struct emac_adapter *adpt, struct emac_tx_queue *tx_q,
231 struct sk_buff *skb);
232void emac_mac_tx_process(struct emac_adapter *adpt, struct emac_tx_queue *tx_q);
233void emac_mac_rx_tx_ring_init_all(struct platform_device *pdev,
234 struct emac_adapter *adpt);
235int emac_mac_rx_tx_rings_alloc_all(struct emac_adapter *adpt);
236void emac_mac_rx_tx_rings_free_all(struct emac_adapter *adpt);
237void emac_mac_multicast_addr_clear(struct emac_adapter *adpt);
238void emac_mac_multicast_addr_set(struct emac_adapter *adpt, u8 *addr);
239
240#endif
241