Commit | Line | Data |
---|---|---|
1ccea77e | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
e6ad7673 IS |
2 | /* Applied Micro X-Gene SoC Ethernet Driver |
3 | * | |
4 | * Copyright (c) 2014, Applied Micro Circuits Corporation | |
5 | * Authors: Iyappan Subramanian <isubramanian@apm.com> | |
6 | * Ravi Patel <rapatel@apm.com> | |
7 | * Keyur Chudgar <kchudgar@apm.com> | |
e6ad7673 IS |
8 | */ |
9 | ||
10 | #ifndef __XGENE_ENET_MAIN_H__ | |
11 | #define __XGENE_ENET_MAIN_H__ | |
12 | ||
de7b5b3d | 13 | #include <linux/acpi.h> |
e6ad7673 | 14 | #include <linux/clk.h> |
de7b5b3d | 15 | #include <linux/efi.h> |
b5d7a069 | 16 | #include <linux/irq.h> |
de7b5b3d | 17 | #include <linux/io.h> |
e6ad7673 IS |
18 | #include <linux/of_platform.h> |
19 | #include <linux/of_net.h> | |
20 | #include <linux/of_mdio.h> | |
232e15e1 | 21 | #include <linux/mdio/mdio-xgene.h> |
e6ad7673 IS |
22 | #include <linux/module.h> |
23 | #include <net/ip.h> | |
24 | #include <linux/prefetch.h> | |
25 | #include <linux/if_vlan.h> | |
26 | #include <linux/phy.h> | |
27 | #include "xgene_enet_hw.h" | |
76f94a9c | 28 | #include "xgene_enet_cle.h" |
bc1b7c13 | 29 | #include "xgene_enet_ring2.h" |
e6ad7673 | 30 | |
4902a922 | 31 | #define ETHER_MIN_PACKET 64 |
61c759cd | 32 | #define ETHER_STD_PACKET 1518 |
a9380b0f IS |
33 | #define XGENE_ENET_STD_MTU 1536 |
34 | #define XGENE_ENET_MAX_MTU 9600 | |
35 | #define SKB_BUFFER_SIZE (XGENE_ENET_STD_MTU - NET_IP_ALIGN) | |
36 | ||
949c40bb | 37 | #define BUFLEN_16K (16 * 1024) |
a9380b0f | 38 | #define NUM_PKT_BUF 1024 |
e6ad7673 | 39 | #define NUM_BUFPOOL 32 |
a9380b0f | 40 | #define NUM_NXTBUFPOOL 8 |
9b00eb49 | 41 | #define MAX_EXP_BUFFS 256 |
e3978673 | 42 | #define NUM_MSS_REG 4 |
9b00eb49 | 43 | #define XGENE_MIN_ENET_FRAME_SIZE 60 |
ca626454 | 44 | |
1b090a48 IS |
45 | #define XGENE_MAX_ENET_IRQ 16 |
46 | #define XGENE_NUM_RX_RING 8 | |
47 | #define XGENE_NUM_TX_RING 8 | |
48 | #define XGENE_NUM_TXC_RING 8 | |
107dec27 | 49 | |
ca626454 KC |
50 | #define START_CPU_BUFNUM_0 0 |
51 | #define START_ETH_BUFNUM_0 2 | |
52 | #define START_BP_BUFNUM_0 0x22 | |
53 | #define START_RING_NUM_0 8 | |
54 | #define START_CPU_BUFNUM_1 12 | |
55 | #define START_ETH_BUFNUM_1 10 | |
56 | #define START_BP_BUFNUM_1 0x2A | |
57 | #define START_RING_NUM_1 264 | |
e6ad7673 | 58 | |
149e9ab4 IS |
59 | #define XG_START_CPU_BUFNUM_1 12 |
60 | #define XG_START_ETH_BUFNUM_1 2 | |
61 | #define XG_START_BP_BUFNUM_1 0x22 | |
62 | #define XG_START_RING_NUM_1 264 | |
63 | ||
bc1b7c13 IS |
64 | #define X2_START_CPU_BUFNUM_0 0 |
65 | #define X2_START_ETH_BUFNUM_0 0 | |
66 | #define X2_START_BP_BUFNUM_0 0x20 | |
67 | #define X2_START_RING_NUM_0 0 | |
bc1b7c13 IS |
68 | #define X2_START_CPU_BUFNUM_1 0xc |
69 | #define X2_START_ETH_BUFNUM_1 0 | |
70 | #define X2_START_BP_BUFNUM_1 0x20 | |
71 | #define X2_START_RING_NUM_1 256 | |
72 | ||
6772b653 | 73 | #define IRQ_ID_SIZE 16 |
6772b653 | 74 | |
32f784b5 IS |
75 | #define PHY_POLL_LINK_ON (10 * HZ) |
76 | #define PHY_POLL_LINK_OFF (PHY_POLL_LINK_ON / 5) | |
77 | ||
bc1b7c13 IS |
78 | enum xgene_enet_id { |
79 | XGENE_ENET1 = 1, | |
80 | XGENE_ENET2 | |
81 | }; | |
82 | ||
a9380b0f IS |
83 | enum xgene_enet_buf_len { |
84 | SIZE_2K = 2048, | |
85 | SIZE_4K = 4096, | |
86 | SIZE_16K = 16384 | |
87 | }; | |
88 | ||
e6ad7673 IS |
89 | /* software context of a descriptor ring */ |
90 | struct xgene_enet_desc_ring { | |
91 | struct net_device *ndev; | |
92 | u16 id; | |
93 | u16 num; | |
94 | u16 head; | |
95 | u16 tail; | |
9b00eb49 | 96 | u16 exp_buf_tail; |
e6ad7673 IS |
97 | u16 slots; |
98 | u16 irq; | |
6772b653 | 99 | char irq_name[IRQ_ID_SIZE]; |
e6ad7673 | 100 | u32 size; |
9dd3c797 | 101 | u32 state[X2_NUM_RING_CONFIG]; |
e6ad7673 IS |
102 | void __iomem *cmd_base; |
103 | void __iomem *cmd; | |
104 | dma_addr_t dma; | |
ed9b7da0 IS |
105 | dma_addr_t irq_mbox_dma; |
106 | void *irq_mbox_addr; | |
e6ad7673 | 107 | u16 dst_ring_num; |
a9380b0f IS |
108 | u16 nbufpool; |
109 | int npagepool; | |
107dec27 | 110 | u8 index; |
a9380b0f | 111 | u32 flags; |
e6ad7673 IS |
112 | struct sk_buff *(*rx_skb); |
113 | struct sk_buff *(*cp_skb); | |
9b00eb49 | 114 | dma_addr_t *frag_dma_addr; |
a9380b0f | 115 | struct page *(*frag_page); |
e6ad7673 IS |
116 | enum xgene_enet_ring_cfgsize cfgsize; |
117 | struct xgene_enet_desc_ring *cp_ring; | |
118 | struct xgene_enet_desc_ring *buf_pool; | |
d6d48969 | 119 | struct xgene_enet_desc_ring *page_pool; |
e6ad7673 IS |
120 | struct napi_struct napi; |
121 | union { | |
122 | void *desc_addr; | |
123 | struct xgene_enet_raw_desc *raw_desc; | |
124 | struct xgene_enet_raw_desc16 *raw_desc16; | |
125 | }; | |
9b00eb49 | 126 | __le64 *exp_bufs; |
3bb502f8 IS |
127 | u64 tx_packets; |
128 | u64 tx_bytes; | |
089f97c7 QN |
129 | u64 tx_dropped; |
130 | u64 tx_errors; | |
3bb502f8 IS |
131 | u64 rx_packets; |
132 | u64 rx_bytes; | |
133 | u64 rx_dropped; | |
134 | u64 rx_errors; | |
135 | u64 rx_length_errors; | |
136 | u64 rx_crc_errors; | |
137 | u64 rx_frame_errors; | |
138 | u64 rx_fifo_errors; | |
e6ad7673 IS |
139 | }; |
140 | ||
d0eb7458 IS |
141 | struct xgene_mac_ops { |
142 | void (*init)(struct xgene_enet_pdata *pdata); | |
143 | void (*reset)(struct xgene_enet_pdata *pdata); | |
144 | void (*tx_enable)(struct xgene_enet_pdata *pdata); | |
145 | void (*rx_enable)(struct xgene_enet_pdata *pdata); | |
146 | void (*tx_disable)(struct xgene_enet_pdata *pdata); | |
147 | void (*rx_disable)(struct xgene_enet_pdata *pdata); | |
ca6d550c | 148 | void (*get_drop_cnt)(struct xgene_enet_pdata *pdata, u32 *rx, u32 *tx); |
9a8c5dde | 149 | void (*set_speed)(struct xgene_enet_pdata *pdata); |
d0eb7458 | 150 | void (*set_mac_addr)(struct xgene_enet_pdata *pdata); |
350b4e33 | 151 | void (*set_framesize)(struct xgene_enet_pdata *pdata, int framesize); |
e3978673 | 152 | void (*set_mss)(struct xgene_enet_pdata *pdata, u16 mss, u8 index); |
dc8385f0 | 153 | void (*link_state)(struct work_struct *work); |
bb64fa09 IS |
154 | void (*enable_tx_pause)(struct xgene_enet_pdata *pdata, bool enable); |
155 | void (*flowctl_rx)(struct xgene_enet_pdata *pdata, bool enable); | |
156 | void (*flowctl_tx)(struct xgene_enet_pdata *pdata, bool enable); | |
d0eb7458 IS |
157 | }; |
158 | ||
159 | struct xgene_port_ops { | |
c3f4465d | 160 | int (*reset)(struct xgene_enet_pdata *pdata); |
cb11c062 IS |
161 | void (*clear)(struct xgene_enet_pdata *pdata, |
162 | struct xgene_enet_desc_ring *ring); | |
d0eb7458 | 163 | void (*cle_bypass)(struct xgene_enet_pdata *pdata, |
d6d48969 | 164 | u32 dst_ring_num, u16 bufpool_id, u16 nxtbufpool_id); |
d0eb7458 IS |
165 | void (*shutdown)(struct xgene_enet_pdata *pdata); |
166 | }; | |
167 | ||
81cefb81 IS |
168 | struct xgene_ring_ops { |
169 | u8 num_ring_config; | |
170 | u8 num_ring_id_shift; | |
171 | struct xgene_enet_desc_ring * (*setup)(struct xgene_enet_desc_ring *); | |
172 | void (*clear)(struct xgene_enet_desc_ring *); | |
173 | void (*wr_cmd)(struct xgene_enet_desc_ring *, int); | |
174 | u32 (*len)(struct xgene_enet_desc_ring *); | |
107dec27 | 175 | void (*coalesce)(struct xgene_enet_desc_ring *); |
81cefb81 IS |
176 | }; |
177 | ||
76f94a9c IS |
178 | struct xgene_cle_ops { |
179 | int (*cle_init)(struct xgene_enet_pdata *pdata); | |
180 | }; | |
181 | ||
e6ad7673 IS |
182 | /* ethernet private data */ |
183 | struct xgene_enet_pdata { | |
184 | struct net_device *ndev; | |
185 | struct mii_bus *mdio_bus; | |
e6ad7673 IS |
186 | int phy_speed; |
187 | struct clk *clk; | |
188 | struct platform_device *pdev; | |
bc1b7c13 | 189 | enum xgene_enet_id enet_id; |
107dec27 IS |
190 | struct xgene_enet_desc_ring *tx_ring[XGENE_NUM_TX_RING]; |
191 | struct xgene_enet_desc_ring *rx_ring[XGENE_NUM_RX_RING]; | |
192 | u16 tx_level[XGENE_NUM_TX_RING]; | |
193 | u16 txc_level[XGENE_NUM_TX_RING]; | |
e6ad7673 IS |
194 | char *dev_name; |
195 | u32 rx_buff_cnt; | |
196 | u32 tx_qcnt_hi; | |
107dec27 IS |
197 | u32 irqs[XGENE_MAX_ENET_IRQ]; |
198 | u8 rxq_cnt; | |
199 | u8 txq_cnt; | |
6772b653 | 200 | u8 cq_cnt; |
e6ad7673 IS |
201 | void __iomem *eth_csr_addr; |
202 | void __iomem *eth_ring_if_addr; | |
203 | void __iomem *eth_diag_csr_addr; | |
204 | void __iomem *mcx_mac_addr; | |
e6ad7673 | 205 | void __iomem *mcx_mac_csr_addr; |
2d07d8e4 | 206 | void __iomem *mcx_stats_addr; |
e6ad7673 | 207 | void __iomem *base_addr; |
3eb7cb9d | 208 | void __iomem *pcs_addr; |
e6ad7673 IS |
209 | void __iomem *ring_csr_addr; |
210 | void __iomem *ring_cmd_addr; | |
e6ad7673 | 211 | int phy_mode; |
0148d38d | 212 | enum xgene_enet_rm rm; |
76f94a9c | 213 | struct xgene_enet_cle cle; |
2d07d8e4 | 214 | u64 *extd_stats; |
eaef62a4 | 215 | u64 false_rflr; |
61c759cd | 216 | u64 vlan_rjbr; |
2d07d8e4 | 217 | spinlock_t stats_lock; /* statistics lock */ |
3cdb7309 | 218 | const struct xgene_mac_ops *mac_ops; |
ae1aed95 | 219 | spinlock_t mac_lock; /* mac lock */ |
3cdb7309 | 220 | const struct xgene_port_ops *port_ops; |
81cefb81 | 221 | struct xgene_ring_ops *ring_ops; |
b555a3d1 | 222 | const struct xgene_cle_ops *cle_ops; |
0148d38d | 223 | struct delayed_work link_work; |
ca626454 KC |
224 | u32 port_id; |
225 | u8 cpu_bufnum; | |
226 | u8 eth_bufnum; | |
227 | u8 bp_bufnum; | |
228 | u16 ring_num; | |
e3978673 IS |
229 | u32 mss[NUM_MSS_REG]; |
230 | u32 mss_refcnt[NUM_MSS_REG]; | |
231 | spinlock_t mss_lock; /* mss lock */ | |
16615a4c IS |
232 | u8 tx_delay; |
233 | u8 rx_delay; | |
8089a96f | 234 | bool mdio_driver; |
27ecf87c | 235 | struct gpio_desc *sfp_rdy; |
751d6fd1 | 236 | bool sfp_gpio_en; |
bb64fa09 IS |
237 | u32 pause_autoneg; |
238 | bool tx_pause; | |
239 | bool rx_pause; | |
e6ad7673 IS |
240 | }; |
241 | ||
32f784b5 IS |
242 | struct xgene_indirect_ctl { |
243 | void __iomem *addr; | |
244 | void __iomem *ctl; | |
245 | void __iomem *cmd; | |
246 | void __iomem *cmd_done; | |
247 | }; | |
248 | ||
e6ad7673 IS |
249 | static inline struct device *ndev_to_dev(struct net_device *ndev) |
250 | { | |
251 | return ndev->dev.parent; | |
252 | } | |
253 | ||
76f94a9c IS |
254 | static inline u16 xgene_enet_dst_ring_num(struct xgene_enet_desc_ring *ring) |
255 | { | |
256 | struct xgene_enet_pdata *pdata = netdev_priv(ring->ndev); | |
257 | ||
258 | return ((u16)pdata->rm << 10) | ring->num; | |
259 | } | |
260 | ||
e6ad7673 | 261 | void xgene_enet_set_ethtool_ops(struct net_device *netdev); |
2d07d8e4 | 262 | int xgene_extd_stats_init(struct xgene_enet_pdata *pdata); |
e6ad7673 IS |
263 | |
264 | #endif /* __XGENE_ENET_MAIN_H__ */ |