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