1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /* Applied Micro X-Gene SoC Ethernet Driver
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>
10 #ifndef __XGENE_ENET_MAIN_H__
11 #define __XGENE_ENET_MAIN_H__
13 #include <linux/acpi.h>
14 #include <linux/clk.h>
15 #include <linux/efi.h>
16 #include <linux/irq.h>
19 #include <linux/of_net.h>
20 #include <linux/of_mdio.h>
21 #include <linux/platform_device.h>
22 #include <linux/mdio/mdio-xgene.h>
23 #include <linux/module.h>
25 #include <linux/prefetch.h>
26 #include <linux/if_vlan.h>
27 #include <linux/phy.h>
28 #include "xgene_enet_hw.h"
29 #include "xgene_enet_cle.h"
30 #include "xgene_enet_ring2.h"
32 #define ETHER_MIN_PACKET 64
33 #define ETHER_STD_PACKET 1518
34 #define XGENE_ENET_STD_MTU 1536
35 #define XGENE_ENET_MAX_MTU 9600
36 #define SKB_BUFFER_SIZE (XGENE_ENET_STD_MTU - NET_IP_ALIGN)
38 #define BUFLEN_16K (16 * 1024)
39 #define NUM_PKT_BUF 1024
40 #define NUM_BUFPOOL 32
41 #define NUM_NXTBUFPOOL 8
42 #define MAX_EXP_BUFFS 256
44 #define XGENE_MIN_ENET_FRAME_SIZE 60
46 #define XGENE_MAX_ENET_IRQ 16
47 #define XGENE_NUM_RX_RING 8
48 #define XGENE_NUM_TX_RING 8
49 #define XGENE_NUM_TXC_RING 8
51 #define START_CPU_BUFNUM_0 0
52 #define START_ETH_BUFNUM_0 2
53 #define START_BP_BUFNUM_0 0x22
54 #define START_RING_NUM_0 8
55 #define START_CPU_BUFNUM_1 12
56 #define START_ETH_BUFNUM_1 10
57 #define START_BP_BUFNUM_1 0x2A
58 #define START_RING_NUM_1 264
60 #define XG_START_CPU_BUFNUM_1 12
61 #define XG_START_ETH_BUFNUM_1 2
62 #define XG_START_BP_BUFNUM_1 0x22
63 #define XG_START_RING_NUM_1 264
65 #define X2_START_CPU_BUFNUM_0 0
66 #define X2_START_ETH_BUFNUM_0 0
67 #define X2_START_BP_BUFNUM_0 0x20
68 #define X2_START_RING_NUM_0 0
69 #define X2_START_CPU_BUFNUM_1 0xc
70 #define X2_START_ETH_BUFNUM_1 0
71 #define X2_START_BP_BUFNUM_1 0x20
72 #define X2_START_RING_NUM_1 256
74 #define IRQ_ID_SIZE 16
76 #define PHY_POLL_LINK_ON (10 * HZ)
77 #define PHY_POLL_LINK_OFF (PHY_POLL_LINK_ON / 5)
84 enum xgene_enet_buf_len
{
90 /* software context of a descriptor ring */
91 struct xgene_enet_desc_ring
{
92 struct net_device
*ndev
;
100 char irq_name
[IRQ_ID_SIZE
];
102 u32 state
[X2_NUM_RING_CONFIG
];
103 void __iomem
*cmd_base
;
106 dma_addr_t irq_mbox_dma
;
113 struct sk_buff
*(*rx_skb
);
114 struct sk_buff
*(*cp_skb
);
115 dma_addr_t
*frag_dma_addr
;
116 struct page
*(*frag_page
);
117 enum xgene_enet_ring_cfgsize cfgsize
;
118 struct xgene_enet_desc_ring
*cp_ring
;
119 struct xgene_enet_desc_ring
*buf_pool
;
120 struct xgene_enet_desc_ring
*page_pool
;
121 struct napi_struct napi
;
124 struct xgene_enet_raw_desc
*raw_desc
;
125 struct xgene_enet_raw_desc16
*raw_desc16
;
136 u64 rx_length_errors
;
142 struct xgene_mac_ops
{
143 void (*init
)(struct xgene_enet_pdata
*pdata
);
144 void (*reset
)(struct xgene_enet_pdata
*pdata
);
145 void (*tx_enable
)(struct xgene_enet_pdata
*pdata
);
146 void (*rx_enable
)(struct xgene_enet_pdata
*pdata
);
147 void (*tx_disable
)(struct xgene_enet_pdata
*pdata
);
148 void (*rx_disable
)(struct xgene_enet_pdata
*pdata
);
149 void (*get_drop_cnt
)(struct xgene_enet_pdata
*pdata
, u32
*rx
, u32
*tx
);
150 void (*set_speed
)(struct xgene_enet_pdata
*pdata
);
151 void (*set_mac_addr
)(struct xgene_enet_pdata
*pdata
);
152 void (*set_framesize
)(struct xgene_enet_pdata
*pdata
, int framesize
);
153 void (*set_mss
)(struct xgene_enet_pdata
*pdata
, u16 mss
, u8 index
);
154 void (*link_state
)(struct work_struct
*work
);
155 void (*enable_tx_pause
)(struct xgene_enet_pdata
*pdata
, bool enable
);
156 void (*flowctl_rx
)(struct xgene_enet_pdata
*pdata
, bool enable
);
157 void (*flowctl_tx
)(struct xgene_enet_pdata
*pdata
, bool enable
);
160 struct xgene_port_ops
{
161 int (*reset
)(struct xgene_enet_pdata
*pdata
);
162 void (*clear
)(struct xgene_enet_pdata
*pdata
,
163 struct xgene_enet_desc_ring
*ring
);
164 void (*cle_bypass
)(struct xgene_enet_pdata
*pdata
,
165 u32 dst_ring_num
, u16 bufpool_id
, u16 nxtbufpool_id
);
166 void (*shutdown
)(struct xgene_enet_pdata
*pdata
);
169 struct xgene_ring_ops
{
171 u8 num_ring_id_shift
;
172 struct xgene_enet_desc_ring
* (*setup
)(struct xgene_enet_desc_ring
*);
173 void (*clear
)(struct xgene_enet_desc_ring
*);
174 void (*wr_cmd
)(struct xgene_enet_desc_ring
*, int);
175 u32 (*len
)(struct xgene_enet_desc_ring
*);
176 void (*coalesce
)(struct xgene_enet_desc_ring
*);
179 struct xgene_cle_ops
{
180 int (*cle_init
)(struct xgene_enet_pdata
*pdata
);
183 /* ethernet private data */
184 struct xgene_enet_pdata
{
185 struct net_device
*ndev
;
186 struct mii_bus
*mdio_bus
;
189 struct platform_device
*pdev
;
190 enum xgene_enet_id enet_id
;
191 struct xgene_enet_desc_ring
*tx_ring
[XGENE_NUM_TX_RING
];
192 struct xgene_enet_desc_ring
*rx_ring
[XGENE_NUM_RX_RING
];
193 u16 tx_level
[XGENE_NUM_TX_RING
];
194 u16 txc_level
[XGENE_NUM_TX_RING
];
198 u32 irqs
[XGENE_MAX_ENET_IRQ
];
202 void __iomem
*eth_csr_addr
;
203 void __iomem
*eth_ring_if_addr
;
204 void __iomem
*eth_diag_csr_addr
;
205 void __iomem
*mcx_mac_addr
;
206 void __iomem
*mcx_mac_csr_addr
;
207 void __iomem
*mcx_stats_addr
;
208 void __iomem
*base_addr
;
209 void __iomem
*pcs_addr
;
210 void __iomem
*ring_csr_addr
;
211 void __iomem
*ring_cmd_addr
;
213 enum xgene_enet_rm rm
;
214 struct xgene_enet_cle cle
;
218 spinlock_t stats_lock
; /* statistics lock */
219 const struct xgene_mac_ops
*mac_ops
;
220 spinlock_t mac_lock
; /* mac lock */
221 const struct xgene_port_ops
*port_ops
;
222 struct xgene_ring_ops
*ring_ops
;
223 const struct xgene_cle_ops
*cle_ops
;
224 struct delayed_work link_work
;
230 u32 mss
[NUM_MSS_REG
];
231 u32 mss_refcnt
[NUM_MSS_REG
];
232 spinlock_t mss_lock
; /* mss lock */
236 struct gpio_desc
*sfp_rdy
;
243 struct xgene_indirect_ctl
{
247 void __iomem
*cmd_done
;
250 static inline struct device
*ndev_to_dev(struct net_device
*ndev
)
252 return ndev
->dev
.parent
;
255 static inline u16
xgene_enet_dst_ring_num(struct xgene_enet_desc_ring
*ring
)
257 struct xgene_enet_pdata
*pdata
= netdev_priv(ring
->ndev
);
259 return ((u16
)pdata
->rm
<< 10) | ring
->num
;
262 void xgene_enet_set_ethtool_ops(struct net_device
*netdev
);
263 int xgene_extd_stats_init(struct xgene_enet_pdata
*pdata
);
265 #endif /* __XGENE_ENET_MAIN_H__ */