blob: e7ec96c964a9fa0a3c2ee2a6f87a9badf46aef28 [file] [log] [blame]
Pantelis Antoniou48257c42005-10-28 16:25:58 -04001#ifndef FS_ENET_H
2#define FS_ENET_H
3
4#include <linux/mii.h>
5#include <linux/netdevice.h>
6#include <linux/types.h>
Pantelis Antoniou48257c42005-10-28 16:25:58 -04007#include <linux/list.h>
8
9#include <linux/fs_enet_pd.h>
10
11#include <asm/dma-mapping.h>
12
13#ifdef CONFIG_CPM1
14#include <asm/commproc.h>
15#endif
16
17#ifdef CONFIG_CPM2
18#include <asm/cpm2.h>
19#endif
20
21/* hw driver ops */
22struct fs_ops {
23 int (*setup_data)(struct net_device *dev);
24 int (*allocate_bd)(struct net_device *dev);
25 void (*free_bd)(struct net_device *dev);
26 void (*cleanup_data)(struct net_device *dev);
27 void (*set_multicast_list)(struct net_device *dev);
28 void (*restart)(struct net_device *dev);
29 void (*stop)(struct net_device *dev);
30 void (*pre_request_irq)(struct net_device *dev, int irq);
31 void (*post_free_irq)(struct net_device *dev, int irq);
32 void (*napi_clear_rx_event)(struct net_device *dev);
33 void (*napi_enable_rx)(struct net_device *dev);
34 void (*napi_disable_rx)(struct net_device *dev);
35 void (*rx_bd_done)(struct net_device *dev);
36 void (*tx_kickstart)(struct net_device *dev);
37 u32 (*get_int_events)(struct net_device *dev);
38 void (*clear_int_events)(struct net_device *dev, u32 int_events);
39 void (*ev_error)(struct net_device *dev, u32 int_events);
40 int (*get_regs)(struct net_device *dev, void *p, int *sizep);
41 int (*get_regs_len)(struct net_device *dev);
42 void (*tx_restart)(struct net_device *dev);
43};
44
45struct phy_info {
46 unsigned int id;
47 const char *name;
48 void (*startup) (struct net_device * dev);
49 void (*shutdown) (struct net_device * dev);
50 void (*ack_int) (struct net_device * dev);
51};
52
53/* The FEC stores dest/src/type, data, and checksum for receive packets.
54 */
55#define MAX_MTU 1508 /* Allow fullsized pppoe packets over VLAN */
56#define MIN_MTU 46 /* this is data size */
57#define CRC_LEN 4
58
59#define PKT_MAXBUF_SIZE (MAX_MTU+ETH_HLEN+CRC_LEN)
60#define PKT_MINBUF_SIZE (MIN_MTU+ETH_HLEN+CRC_LEN)
61
62/* Must be a multiple of 32 (to cover both FEC & FCC) */
63#define PKT_MAXBLR_SIZE ((PKT_MAXBUF_SIZE + 31) & ~31)
64/* This is needed so that invalidate_xxx wont invalidate too much */
65#define ENET_RX_FRSIZE L1_CACHE_ALIGN(PKT_MAXBUF_SIZE)
66
67struct fs_enet_mii_bus {
68 struct list_head list;
69 spinlock_t mii_lock;
70 const struct fs_mii_bus_info *bus_info;
71 int refs;
72 u32 usage_map;
73
74 int (*mii_read)(struct fs_enet_mii_bus *bus,
75 int phy_id, int location);
76
77 void (*mii_write)(struct fs_enet_mii_bus *bus,
78 int phy_id, int location, int value);
79
80 union {
81 struct {
82 unsigned int mii_speed;
83 void *fecp;
84 } fec;
85
86 struct {
87 /* note that the actual port size may */
88 /* be different; cpm(s) handle it OK */
89 u8 mdio_msk;
90 u8 *mdio_dir;
91 u8 *mdio_dat;
92 u8 mdc_msk;
93 u8 *mdc_dir;
94 u8 *mdc_dat;
95 } bitbang;
96
97 struct {
98 u16 lpa;
99 } fixed;
100 };
101};
102
103int fs_mii_bitbang_init(struct fs_enet_mii_bus *bus);
104int fs_mii_fixed_init(struct fs_enet_mii_bus *bus);
105int fs_mii_fec_init(struct fs_enet_mii_bus *bus);
106
107struct fs_enet_private {
108 struct device *dev; /* pointer back to the device (must be initialized first) */
109 spinlock_t lock; /* during all ops except TX pckt processing */
110 spinlock_t tx_lock; /* during fs_start_xmit and fs_tx */
111 const struct fs_platform_info *fpi;
112 const struct fs_ops *ops;
113 int rx_ring, tx_ring;
114 dma_addr_t ring_mem_addr;
115 void *ring_base;
116 struct sk_buff **rx_skbuff;
117 struct sk_buff **tx_skbuff;
118 cbd_t *rx_bd_base; /* Address of Rx and Tx buffers. */
119 cbd_t *tx_bd_base;
120 cbd_t *dirty_tx; /* ring entries to be free()ed. */
121 cbd_t *cur_rx;
122 cbd_t *cur_tx;
123 int tx_free;
124 struct net_device_stats stats;
125 struct timer_list phy_timer_list;
126 const struct phy_info *phy;
127 u32 msg_enable;
128 struct mii_if_info mii_if;
129 unsigned int last_mii_status;
130 struct fs_enet_mii_bus *mii_bus;
131 int interrupt;
132
133 int duplex, speed; /* current settings */
134
135 /* event masks */
136 u32 ev_napi_rx; /* mask of NAPI rx events */
137 u32 ev_rx; /* rx event mask */
138 u32 ev_tx; /* tx event mask */
139 u32 ev_err; /* error event mask */
140
141 u16 bd_rx_empty; /* mask of BD rx empty */
142 u16 bd_rx_err; /* mask of BD rx errors */
143
144 union {
145 struct {
146 int idx; /* FEC1 = 0, FEC2 = 1 */
147 void *fecp; /* hw registers */
148 u32 hthi, htlo; /* state for multicast */
149 } fec;
150
151 struct {
152 int idx; /* FCC1-3 = 0-2 */
153 void *fccp; /* hw registers */
154 void *ep; /* parameter ram */
155 void *fcccp; /* hw registers cont. */
156 void *mem; /* FCC DPRAM */
157 u32 gaddrh, gaddrl; /* group address */
158 } fcc;
159
160 struct {
161 int idx; /* FEC1 = 0, FEC2 = 1 */
162 void *sccp; /* hw registers */
163 void *ep; /* parameter ram */
164 u32 hthi, htlo; /* state for multicast */
165 } scc;
166
167 };
168};
169
170/***************************************************************************/
171
172int fs_mii_read(struct net_device *dev, int phy_id, int location);
173void fs_mii_write(struct net_device *dev, int phy_id, int location, int value);
174
175void fs_mii_startup(struct net_device *dev);
176void fs_mii_shutdown(struct net_device *dev);
177void fs_mii_ack_int(struct net_device *dev);
178
179void fs_mii_link_status_change_check(struct net_device *dev, int init_media);
180
181void fs_init_bds(struct net_device *dev);
182void fs_cleanup_bds(struct net_device *dev);
183
184/***************************************************************************/
185
186#define DRV_MODULE_NAME "fs_enet"
187#define PFX DRV_MODULE_NAME ": "
188#define DRV_MODULE_VERSION "1.0"
189#define DRV_MODULE_RELDATE "Aug 8, 2005"
190
191/***************************************************************************/
192
193int fs_enet_platform_init(void);
194void fs_enet_platform_cleanup(void);
195
196/***************************************************************************/
197
198/* buffer descriptor access macros */
199
200/* access macros */
201#if defined(CONFIG_CPM1)
202/* for a a CPM1 __raw_xxx's are sufficient */
203#define __cbd_out32(addr, x) __raw_writel(x, addr)
204#define __cbd_out16(addr, x) __raw_writew(x, addr)
205#define __cbd_in32(addr) __raw_readl(addr)
206#define __cbd_in16(addr) __raw_readw(addr)
207#else
208/* for others play it safe */
209#define __cbd_out32(addr, x) out_be32(addr, x)
210#define __cbd_out16(addr, x) out_be16(addr, x)
211#define __cbd_in32(addr) in_be32(addr)
212#define __cbd_in16(addr) in_be16(addr)
213#endif
214
215/* write */
216#define CBDW_SC(_cbd, _sc) __cbd_out16(&(_cbd)->cbd_sc, (_sc))
217#define CBDW_DATLEN(_cbd, _datlen) __cbd_out16(&(_cbd)->cbd_datlen, (_datlen))
218#define CBDW_BUFADDR(_cbd, _bufaddr) __cbd_out32(&(_cbd)->cbd_bufaddr, (_bufaddr))
219
220/* read */
221#define CBDR_SC(_cbd) __cbd_in16(&(_cbd)->cbd_sc)
222#define CBDR_DATLEN(_cbd) __cbd_in16(&(_cbd)->cbd_datlen)
223#define CBDR_BUFADDR(_cbd) __cbd_in32(&(_cbd)->cbd_bufaddr)
224
225/* set bits */
226#define CBDS_SC(_cbd, _sc) CBDW_SC(_cbd, CBDR_SC(_cbd) | (_sc))
227
228/* clear bits */
229#define CBDC_SC(_cbd, _sc) CBDW_SC(_cbd, CBDR_SC(_cbd) & ~(_sc))
230
231/*******************************************************************/
232
233extern const struct fs_ops fs_fec_ops;
234extern const struct fs_ops fs_fcc_ops;
235extern const struct fs_ops fs_scc_ops;
236
237/*******************************************************************/
238
239/* handy pointer to the immap */
240extern void *fs_enet_immap;
241
242/*******************************************************************/
243
244#endif