1 /* SPDX-License-Identifier: GPL-2.0 */
6 #include <linux/netdevice.h>
7 #include <linux/types.h>
8 #include <linux/list.h>
10 #include <linux/dma-mapping.h>
12 #include <linux/fs_enet_pd.h>
18 #if defined(CONFIG_FS_ENET_HAS_FEC)
21 #if defined(CONFIG_FS_ENET_MPC5121_FEC)
22 /* MPC5121 FEC has different register layout */
25 u32 fec_ievent; /* Interrupt event reg */
26 u32 fec_imask; /* Interrupt mask reg */
28 u32 fec_r_des_active; /* Receive descriptor reg */
29 u32 fec_x_des_active; /* Transmit descriptor reg */
31 u32 fec_ecntrl; /* Ethernet control reg */
33 u32 fec_mii_data; /* MII manage frame reg */
34 u32 fec_mii_speed; /* MII speed control reg */
36 u32 fec_mib_ctrlstat; /* MIB control/status reg */
38 u32 fec_r_cntrl; /* Receive control reg */
39 u32 fec_reserved6[15];
40 u32 fec_x_cntrl; /* Transmit Control reg */
42 u32 fec_addr_low; /* Low 32bits MAC address */
43 u32 fec_addr_high; /* High 16bits MAC address */
44 u32 fec_opd; /* Opcode + Pause duration */
45 u32 fec_reserved8[10];
46 u32 fec_hash_table_high; /* High 32bits hash table */
47 u32 fec_hash_table_low; /* Low 32bits hash table */
48 u32 fec_grp_hash_table_high; /* High 32bits hash table */
49 u32 fec_grp_hash_table_low; /* Low 32bits hash table */
51 u32 fec_x_wmrk; /* FIFO transmit water mark */
53 u32 fec_r_bound; /* FIFO receive bound reg */
54 u32 fec_r_fstart; /* FIFO receive start reg */
55 u32 fec_reserved11[11];
56 u32 fec_r_des_start; /* Receive descriptor ring */
57 u32 fec_x_des_start; /* Transmit descriptor ring */
58 u32 fec_r_buff_size; /* Maximum receive buff size */
59 u32 fec_reserved12[26];
60 u32 fec_dma_control; /* DMA Endian and other ctrl */
65 struct fec __iomem *fecp;
76 int (*setup_data)(struct net_device *dev);
77 int (*allocate_bd)(struct net_device *dev);
78 void (*free_bd)(struct net_device *dev);
79 void (*cleanup_data)(struct net_device *dev);
80 void (*set_multicast_list)(struct net_device *dev);
81 void (*adjust_link)(struct net_device *dev);
82 void (*restart)(struct net_device *dev);
83 void (*stop)(struct net_device *dev);
84 void (*napi_clear_event)(struct net_device *dev);
85 void (*napi_enable)(struct net_device *dev);
86 void (*napi_disable)(struct net_device *dev);
87 void (*rx_bd_done)(struct net_device *dev);
88 void (*tx_kickstart)(struct net_device *dev);
89 u32 (*get_int_events)(struct net_device *dev);
90 void (*clear_int_events)(struct net_device *dev, u32 int_events);
91 void (*ev_error)(struct net_device *dev, u32 int_events);
92 int (*get_regs)(struct net_device *dev, void *p, int *sizep);
93 int (*get_regs_len)(struct net_device *dev);
94 void (*tx_restart)(struct net_device *dev);
100 void (*startup) (struct net_device * dev);
101 void (*shutdown) (struct net_device * dev);
102 void (*ack_int) (struct net_device * dev);
105 /* The FEC stores dest/src/type, data, and checksum for receive packets.
107 #define MAX_MTU 1508 /* Allow fullsized pppoe packets over VLAN */
108 #define MIN_MTU 46 /* this is data size */
111 #define PKT_MAXBUF_SIZE (MAX_MTU+ETH_HLEN+CRC_LEN)
112 #define PKT_MINBUF_SIZE (MIN_MTU+ETH_HLEN+CRC_LEN)
114 /* Must be a multiple of 32 (to cover both FEC & FCC) */
115 #define PKT_MAXBLR_SIZE ((PKT_MAXBUF_SIZE + 31) & ~31)
116 /* This is needed so that invalidate_xxx wont invalidate too much */
117 #define ENET_RX_ALIGN 16
118 #define ENET_RX_FRSIZE L1_CACHE_ALIGN(PKT_MAXBUF_SIZE + ENET_RX_ALIGN - 1)
120 struct fs_enet_private {
121 struct napi_struct napi;
122 struct device *dev; /* pointer back to the device (must be initialized first) */
123 struct net_device *ndev;
124 spinlock_t lock; /* during all ops except TX pckt processing */
125 spinlock_t tx_lock; /* during fs_start_xmit and fs_tx */
126 struct fs_platform_info *fpi;
127 struct work_struct timeout_work;
128 const struct fs_ops *ops;
129 int rx_ring, tx_ring;
130 dma_addr_t ring_mem_addr;
131 void __iomem *ring_base;
132 struct sk_buff **rx_skbuff;
133 struct sk_buff **tx_skbuff;
134 char *mapped_as_page;
135 cbd_t __iomem *rx_bd_base; /* Address of Rx and Tx buffers. */
136 cbd_t __iomem *tx_bd_base;
137 cbd_t __iomem *dirty_tx; /* ring entries to be free()ed. */
138 cbd_t __iomem *cur_rx;
139 cbd_t __iomem *cur_tx;
141 const struct phy_info *phy;
143 struct mii_if_info mii_if;
144 unsigned int last_mii_status;
147 int oldduplex, oldspeed, oldlink; /* current settings */
150 u32 ev_napi; /* mask of NAPI events */
151 u32 ev; /* event mask */
152 u32 ev_err; /* error event mask */
154 u16 bd_rx_empty; /* mask of BD rx empty */
155 u16 bd_rx_err; /* mask of BD rx errors */
159 int idx; /* FEC1 = 0, FEC2 = 1 */
160 void __iomem *fecp; /* hw registers */
161 u32 hthi, htlo; /* state for multicast */
165 int idx; /* FCC1-3 = 0-2 */
166 void __iomem *fccp; /* hw registers */
167 void __iomem *ep; /* parameter ram */
168 void __iomem *fcccp; /* hw registers cont. */
169 void __iomem *mem; /* FCC DPRAM */
170 u32 gaddrh, gaddrl; /* group address */
174 int idx; /* FEC1 = 0, FEC2 = 1 */
175 void __iomem *sccp; /* hw registers */
176 void __iomem *ep; /* parameter ram */
177 u32 hthi, htlo; /* state for multicast */
183 /***************************************************************************/
185 void fs_init_bds(struct net_device *dev);
186 void fs_cleanup_bds(struct net_device *dev);
188 /***************************************************************************/
190 #define DRV_MODULE_NAME "fs_enet"
191 #define PFX DRV_MODULE_NAME ": "
193 /***************************************************************************/
195 int fs_enet_platform_init(void);
196 void fs_enet_platform_cleanup(void);
198 /***************************************************************************/
199 /* buffer descriptor access macros */
202 #if defined(CONFIG_CPM1)
203 /* for a CPM1 __raw_xxx's are sufficient */
204 #define __cbd_out32(addr, x) __raw_writel(x, addr)
205 #define __cbd_out16(addr, x) __raw_writew(x, addr)
206 #define __cbd_in32(addr) __raw_readl(addr)
207 #define __cbd_in16(addr) __raw_readw(addr)
209 /* for others play it safe */
210 #define __cbd_out32(addr, x) out_be32(addr, x)
211 #define __cbd_out16(addr, x) out_be16(addr, x)
212 #define __cbd_in32(addr) in_be32(addr)
213 #define __cbd_in16(addr) in_be16(addr)
217 #define CBDW_SC(_cbd, _sc) __cbd_out16(&(_cbd)->cbd_sc, (_sc))
218 #define CBDW_DATLEN(_cbd, _datlen) __cbd_out16(&(_cbd)->cbd_datlen, (_datlen))
219 #define CBDW_BUFADDR(_cbd, _bufaddr) __cbd_out32(&(_cbd)->cbd_bufaddr, (_bufaddr))
222 #define CBDR_SC(_cbd) __cbd_in16(&(_cbd)->cbd_sc)
223 #define CBDR_DATLEN(_cbd) __cbd_in16(&(_cbd)->cbd_datlen)
224 #define CBDR_BUFADDR(_cbd) __cbd_in32(&(_cbd)->cbd_bufaddr)
227 #define CBDS_SC(_cbd, _sc) CBDW_SC(_cbd, CBDR_SC(_cbd) | (_sc))
230 #define CBDC_SC(_cbd, _sc) CBDW_SC(_cbd, CBDR_SC(_cbd) & ~(_sc))
232 /*******************************************************************/
234 extern const struct fs_ops fs_fec_ops;
235 extern const struct fs_ops fs_fcc_ops;
236 extern const struct fs_ops fs_scc_ops;
238 /*******************************************************************/