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#ifndef __IBM_NEWEMAC_CORE_H
26#define __IBM_NEWEMAC_CORE_H
27
28#include <linux/module.h>
29#include <linux/list.h>
30#include <linux/kernel.h>
31#include <linux/interrupt.h>
32#include <linux/netdevice.h>
33#include <linux/dma-mapping.h>
34#include <linux/spinlock.h>
35#include <linux/of_platform.h>
36#include <linux/slab.h>
37
38#include <asm/io.h>
39#include <asm/dcr.h>
40
41#include "emac.h"
42#include "phy.h"
43#include "zmii.h"
44#include "rgmii.h"
45#include "mal.h"
46#include "tah.h"
47#include "debug.h"
48
49#define NUM_TX_BUFF CONFIG_IBM_EMAC_TXB
50#define NUM_RX_BUFF CONFIG_IBM_EMAC_RXB
51
52
53#if NUM_TX_BUFF > 256 || NUM_RX_BUFF > 256
54#error Invalid number of buffer descriptors (greater than 256)
55#endif
56
57#define EMAC_MIN_MTU 46
58
59
60#define EMAC_MTU_OVERHEAD (6 * 2 + 2 + 4)
61
62
63static inline int emac_rx_size(int mtu)
64{
65 if (mtu > ETH_DATA_LEN)
66 return MAL_MAX_RX_SIZE;
67 else
68 return mal_rx_size(ETH_DATA_LEN + EMAC_MTU_OVERHEAD);
69}
70
71#define EMAC_DMA_ALIGN(x) ALIGN((x), dma_get_cache_alignment())
72
73#define EMAC_RX_SKB_HEADROOM \
74 EMAC_DMA_ALIGN(CONFIG_IBM_EMAC_RX_SKB_HEADROOM)
75
76
77static inline int emac_rx_skb_size(int mtu)
78{
79 int size = max(mtu + EMAC_MTU_OVERHEAD, emac_rx_size(mtu));
80 return EMAC_DMA_ALIGN(size + 2) + EMAC_RX_SKB_HEADROOM;
81}
82
83
84static inline int emac_rx_sync_size(int mtu)
85{
86 return EMAC_DMA_ALIGN(emac_rx_size(mtu) + 2);
87}
88
89
90
91
92
93
94
95
96
97
98
99
100struct emac_stats {
101 u64 rx_packets;
102 u64 rx_bytes;
103 u64 tx_packets;
104 u64 tx_bytes;
105 u64 rx_packets_csum;
106 u64 tx_packets_csum;
107};
108
109
110struct emac_error_stats {
111 u64 tx_undo;
112
113
114 u64 rx_dropped_stack;
115 u64 rx_dropped_oom;
116 u64 rx_dropped_error;
117 u64 rx_dropped_resize;
118 u64 rx_dropped_mtu;
119 u64 rx_stopped;
120
121 u64 rx_bd_errors;
122 u64 rx_bd_overrun;
123 u64 rx_bd_bad_packet;
124 u64 rx_bd_runt_packet;
125 u64 rx_bd_short_event;
126 u64 rx_bd_alignment_error;
127 u64 rx_bd_bad_fcs;
128 u64 rx_bd_packet_too_long;
129 u64 rx_bd_out_of_range;
130 u64 rx_bd_in_range;
131
132 u64 rx_parity;
133 u64 rx_fifo_overrun;
134 u64 rx_overrun;
135 u64 rx_bad_packet;
136 u64 rx_runt_packet;
137 u64 rx_short_event;
138 u64 rx_alignment_error;
139 u64 rx_bad_fcs;
140 u64 rx_packet_too_long;
141 u64 rx_out_of_range;
142 u64 rx_in_range;
143
144
145 u64 tx_dropped;
146
147 u64 tx_bd_errors;
148 u64 tx_bd_bad_fcs;
149 u64 tx_bd_carrier_loss;
150 u64 tx_bd_excessive_deferral;
151 u64 tx_bd_excessive_collisions;
152 u64 tx_bd_late_collision;
153 u64 tx_bd_multple_collisions;
154 u64 tx_bd_single_collision;
155 u64 tx_bd_underrun;
156 u64 tx_bd_sqe;
157
158 u64 tx_parity;
159 u64 tx_underrun;
160 u64 tx_sqe;
161 u64 tx_errors;
162};
163
164#define EMAC_ETHTOOL_STATS_COUNT ((sizeof(struct emac_stats) + \
165 sizeof(struct emac_error_stats)) \
166 / sizeof(u64))
167
168struct emac_instance {
169 struct net_device *ndev;
170 struct resource rsrc_regs;
171 struct emac_regs __iomem *emacp;
172 struct platform_device *ofdev;
173 struct device_node **blist;
174
175
176 u32 mal_ph;
177 struct platform_device *mal_dev;
178 u32 mal_rx_chan;
179 u32 mal_tx_chan;
180 struct mal_instance *mal;
181 struct mal_commac commac;
182
183
184 int phy_mode;
185 u32 phy_map;
186 u32 phy_address;
187 u32 phy_feat_exc;
188 struct mii_phy phy;
189 struct mutex link_lock;
190 struct delayed_work link_work;
191 int link_polling;
192
193
194 u32 gpcs_address;
195
196
197 u32 mdio_ph;
198 struct platform_device *mdio_dev;
199 struct emac_instance *mdio_instance;
200 struct mutex mdio_lock;
201
202
203 struct mii_bus *mii_bus;
204 struct phy_device *phy_dev;
205
206
207 u32 zmii_ph;
208 u32 zmii_port;
209 struct platform_device *zmii_dev;
210
211
212 u32 rgmii_ph;
213 u32 rgmii_port;
214 struct platform_device *rgmii_dev;
215
216
217 u32 tah_ph;
218 u32 tah_port;
219 struct platform_device *tah_dev;
220
221
222 int wol_irq;
223 int emac_irq;
224
225
226 u32 opb_bus_freq;
227
228
229 u32 cell_index;
230
231
232 u32 max_mtu;
233
234
235 unsigned int features;
236
237
238 u32 tx_fifo_size;
239 u32 tx_fifo_size_gige;
240 u32 rx_fifo_size;
241 u32 rx_fifo_size_gige;
242 u32 fifo_entry_size;
243 u32 mal_burst_size;
244
245
246 u32 xaht_slots_shift;
247 u32 xaht_width_shift;
248
249
250
251 struct mal_descriptor *tx_desc;
252 int tx_cnt;
253 int tx_slot;
254 int ack_slot;
255
256 struct mal_descriptor *rx_desc;
257 int rx_slot;
258 struct sk_buff *rx_sg_skb;
259 int rx_skb_size;
260 int rx_sync_size;
261
262 struct sk_buff *tx_skb[NUM_TX_BUFF];
263 struct sk_buff *rx_skb[NUM_RX_BUFF];
264
265
266
267 struct emac_error_stats estats;
268 struct net_device_stats nstats;
269 struct emac_stats stats;
270
271
272
273 int reset_failed;
274 int stop_timeout;
275 int no_mcast;
276 int mcast_pending;
277 int opened;
278 struct work_struct reset_work;
279 spinlock_t lock;
280};
281
282
283
284
285
286
287
288
289#define EMAC_FTR_NO_FLOW_CONTROL_40x 0x00000001
290
291
292
293#define EMAC_FTR_EMAC4 0x00000002
294
295
296
297
298#define EMAC_FTR_STACR_OC_INVERT 0x00000004
299
300
301
302#define EMAC_FTR_HAS_TAH 0x00000008
303
304
305
306#define EMAC_FTR_HAS_ZMII 0x00000010
307
308
309
310#define EMAC_FTR_HAS_RGMII 0x00000020
311
312
313
314#define EMAC_FTR_HAS_NEW_STACR 0x00000040
315
316
317
318#define EMAC_FTR_440GX_PHY_CLK_FIX 0x00000080
319
320
321
322#define EMAC_FTR_440EP_PHY_CLK_FIX 0x00000100
323
324
325
326#define EMAC_FTR_EMAC4SYNC 0x00000200
327
328
329
330#define EMAC_FTR_460EX_PHY_CLK_FIX 0x00000400
331
332
333
334#define EMAC_APM821XX_REQ_JUMBO_FRAME_SIZE 0x00000800
335
336
337
338#define EMAC_FTR_APM821XX_NO_HALF_DUPLEX 0x00001000
339
340
341
342
343
344enum {
345 EMAC_FTRS_ALWAYS = 0,
346
347 EMAC_FTRS_POSSIBLE =
348#ifdef CONFIG_IBM_EMAC_EMAC4
349 EMAC_FTR_EMAC4 | EMAC_FTR_EMAC4SYNC |
350 EMAC_FTR_HAS_NEW_STACR |
351 EMAC_FTR_STACR_OC_INVERT | EMAC_FTR_440GX_PHY_CLK_FIX |
352#endif
353#ifdef CONFIG_IBM_EMAC_TAH
354 EMAC_FTR_HAS_TAH |
355#endif
356#ifdef CONFIG_IBM_EMAC_ZMII
357 EMAC_FTR_HAS_ZMII |
358#endif
359#ifdef CONFIG_IBM_EMAC_RGMII
360 EMAC_FTR_HAS_RGMII |
361#endif
362#ifdef CONFIG_IBM_EMAC_NO_FLOW_CTRL
363 EMAC_FTR_NO_FLOW_CONTROL_40x |
364#endif
365 EMAC_FTR_460EX_PHY_CLK_FIX |
366 EMAC_FTR_440EP_PHY_CLK_FIX |
367 EMAC_APM821XX_REQ_JUMBO_FRAME_SIZE |
368 EMAC_FTR_APM821XX_NO_HALF_DUPLEX,
369};
370
371static inline int emac_has_feature(struct emac_instance *dev,
372 unsigned long feature)
373{
374 return (EMAC_FTRS_ALWAYS & feature) ||
375 (EMAC_FTRS_POSSIBLE & dev->features & feature);
376}
377
378
379
380
381
382
383
384
385
386
387
388
389#define EMAC4_XAHT_SLOTS_SHIFT 6
390#define EMAC4_XAHT_WIDTH_SHIFT 4
391
392#define EMAC4SYNC_XAHT_SLOTS_SHIFT 8
393#define EMAC4SYNC_XAHT_WIDTH_SHIFT 5
394
395#define EMAC_XAHT_SLOTS(dev) (1 << (dev)->xaht_slots_shift)
396#define EMAC_XAHT_WIDTH(dev) (1 << (dev)->xaht_width_shift)
397#define EMAC_XAHT_REGS(dev) (1 << ((dev)->xaht_slots_shift - \
398 (dev)->xaht_width_shift))
399
400#define EMAC_XAHT_CRC_TO_SLOT(dev, crc) \
401 ((EMAC_XAHT_SLOTS(dev) - 1) - \
402 ((crc) >> ((sizeof (u32) * BITS_PER_BYTE) - \
403 (dev)->xaht_slots_shift)))
404
405#define EMAC_XAHT_SLOT_TO_REG(dev, slot) \
406 ((slot) >> (dev)->xaht_width_shift)
407
408#define EMAC_XAHT_SLOT_TO_MASK(dev, slot) \
409 ((u32)(1 << (EMAC_XAHT_WIDTH(dev) - 1)) >> \
410 ((slot) & (u32)(EMAC_XAHT_WIDTH(dev) - 1)))
411
412static inline u32 *emac_xaht_base(struct emac_instance *dev)
413{
414 struct emac_regs __iomem *p = dev->emacp;
415 int offset;
416
417
418
419
420 if (emac_has_feature(dev, EMAC_FTR_EMAC4SYNC))
421 offset = offsetof(struct emac_regs, u1.emac4sync.iaht1);
422 else
423 offset = offsetof(struct emac_regs, u0.emac4.iaht1);
424
425 return (u32 *)((ptrdiff_t)p + offset);
426}
427
428static inline u32 *emac_gaht_base(struct emac_instance *dev)
429{
430
431
432
433 return emac_xaht_base(dev) + EMAC_XAHT_REGS(dev);
434}
435
436static inline u32 *emac_iaht_base(struct emac_instance *dev)
437{
438
439
440
441 return emac_xaht_base(dev);
442}
443
444
445
446
447
448
449
450
451
452
453
454#define EMAC_ETHTOOL_REGS_ZMII 0x00000001
455#define EMAC_ETHTOOL_REGS_RGMII 0x00000002
456#define EMAC_ETHTOOL_REGS_TAH 0x00000004
457
458struct emac_ethtool_regs_hdr {
459 u32 components;
460};
461
462struct emac_ethtool_regs_subhdr {
463 u32 version;
464 u32 index;
465};
466
467#define EMAC_ETHTOOL_REGS_VER 3
468#define EMAC4_ETHTOOL_REGS_VER 4
469#define EMAC4SYNC_ETHTOOL_REGS_VER 5
470
471#endif
472