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