xgene_enet_main.h 7.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/* Applied Micro X-Gene SoC Ethernet Driver
 *
 * Copyright (c) 2014, Applied Micro Circuits Corporation
 * Authors: Iyappan Subramanian <isubramanian@apm.com>
 *	    Ravi Patel <rapatel@apm.com>
 *	    Keyur Chudgar <kchudgar@apm.com>
 *
 * This program is free software; you can redistribute  it and/or modify it
 * under  the terms of  the GNU General  Public License as published by the
 * Free Software Foundation;  either version 2 of the  License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __XGENE_ENET_MAIN_H__
#define __XGENE_ENET_MAIN_H__

25
#include <linux/acpi.h>
26
#include <linux/clk.h>
27
#include <linux/efi.h>
28
#include <linux/irq.h>
29
#include <linux/io.h>
30 31 32 33 34 35 36 37 38
#include <linux/of_platform.h>
#include <linux/of_net.h>
#include <linux/of_mdio.h>
#include <linux/module.h>
#include <net/ip.h>
#include <linux/prefetch.h>
#include <linux/if_vlan.h>
#include <linux/phy.h>
#include "xgene_enet_hw.h"
39
#include "xgene_enet_cle.h"
40
#include "xgene_enet_ring2.h"
41
#include "../../../phy/mdio-xgene.h"
42 43

#define XGENE_DRV_VERSION	"v1.0"
44
#define ETHER_MIN_PACKET	64
45 46 47 48
#define XGENE_ENET_STD_MTU	1536
#define XGENE_ENET_MAX_MTU	9600
#define SKB_BUFFER_SIZE		(XGENE_ENET_STD_MTU - NET_IP_ALIGN)

49
#define BUFLEN_16K	(16 * 1024)
50
#define NUM_PKT_BUF	1024
51
#define NUM_BUFPOOL	32
52
#define NUM_NXTBUFPOOL	8
53
#define MAX_EXP_BUFFS	256
54
#define NUM_MSS_REG	4
55
#define XGENE_MIN_ENET_FRAME_SIZE	60
56

57 58 59 60
#define XGENE_MAX_ENET_IRQ	16
#define XGENE_NUM_RX_RING	8
#define XGENE_NUM_TX_RING	8
#define XGENE_NUM_TXC_RING	8
61

62 63 64 65 66 67 68 69
#define START_CPU_BUFNUM_0	0
#define START_ETH_BUFNUM_0	2
#define START_BP_BUFNUM_0	0x22
#define START_RING_NUM_0	8
#define START_CPU_BUFNUM_1	12
#define START_ETH_BUFNUM_1	10
#define START_BP_BUFNUM_1	0x2A
#define START_RING_NUM_1	264
70

71 72 73 74 75
#define XG_START_CPU_BUFNUM_1	12
#define XG_START_ETH_BUFNUM_1	2
#define XG_START_BP_BUFNUM_1	0x22
#define XG_START_RING_NUM_1	264

76 77 78 79 80 81 82 83 84
#define X2_START_CPU_BUFNUM_0	0
#define X2_START_ETH_BUFNUM_0	0
#define X2_START_BP_BUFNUM_0	0x20
#define X2_START_RING_NUM_0	0
#define X2_START_CPU_BUFNUM_1	0xc
#define X2_START_ETH_BUFNUM_1	0
#define X2_START_BP_BUFNUM_1	0x20
#define X2_START_RING_NUM_1	256

85 86
#define IRQ_ID_SIZE		16

87 88 89
#define PHY_POLL_LINK_ON	(10 * HZ)
#define PHY_POLL_LINK_OFF	(PHY_POLL_LINK_ON / 5)

90 91 92 93 94
enum xgene_enet_id {
	XGENE_ENET1 = 1,
	XGENE_ENET2
};

95 96 97 98 99 100
enum xgene_enet_buf_len {
	SIZE_2K = 2048,
	SIZE_4K = 4096,
	SIZE_16K = 16384
};

101 102 103 104 105 106 107
/* software context of a descriptor ring */
struct xgene_enet_desc_ring {
	struct net_device *ndev;
	u16 id;
	u16 num;
	u16 head;
	u16 tail;
108
	u16 exp_buf_tail;
109 110
	u16 slots;
	u16 irq;
111
	char irq_name[IRQ_ID_SIZE];
112
	u32 size;
113
	u32 state[X2_NUM_RING_CONFIG];
114 115 116
	void __iomem *cmd_base;
	void __iomem *cmd;
	dma_addr_t dma;
117 118
	dma_addr_t irq_mbox_dma;
	void *irq_mbox_addr;
119
	u16 dst_ring_num;
120 121
	u16 nbufpool;
	int npagepool;
122
	u8 index;
123
	u32 flags;
124 125
	struct sk_buff *(*rx_skb);
	struct sk_buff *(*cp_skb);
126
	dma_addr_t *frag_dma_addr;
127
	struct page *(*frag_page);
128 129 130
	enum xgene_enet_ring_cfgsize cfgsize;
	struct xgene_enet_desc_ring *cp_ring;
	struct xgene_enet_desc_ring *buf_pool;
131
	struct xgene_enet_desc_ring *page_pool;
132 133 134 135 136 137
	struct napi_struct napi;
	union {
		void *desc_addr;
		struct xgene_enet_raw_desc *raw_desc;
		struct xgene_enet_raw_desc16 *raw_desc16;
	};
138
	__le64 *exp_bufs;
139 140
	u64 tx_packets;
	u64 tx_bytes;
141 142
	u64 tx_dropped;
	u64 tx_errors;
143 144 145 146 147 148 149 150
	u64 rx_packets;
	u64 rx_bytes;
	u64 rx_dropped;
	u64 rx_errors;
	u64 rx_length_errors;
	u64 rx_crc_errors;
	u64 rx_frame_errors;
	u64 rx_fifo_errors;
151 152
};

153 154 155 156 157 158 159
struct xgene_mac_ops {
	void (*init)(struct xgene_enet_pdata *pdata);
	void (*reset)(struct xgene_enet_pdata *pdata);
	void (*tx_enable)(struct xgene_enet_pdata *pdata);
	void (*rx_enable)(struct xgene_enet_pdata *pdata);
	void (*tx_disable)(struct xgene_enet_pdata *pdata);
	void (*rx_disable)(struct xgene_enet_pdata *pdata);
160
	void (*get_drop_cnt)(struct xgene_enet_pdata *pdata, u32 *rx, u32 *tx);
161
	void (*set_speed)(struct xgene_enet_pdata *pdata);
162
	void (*set_mac_addr)(struct xgene_enet_pdata *pdata);
163
	void (*set_framesize)(struct xgene_enet_pdata *pdata, int framesize);
164
	void (*set_mss)(struct xgene_enet_pdata *pdata, u16 mss, u8 index);
165
	void (*link_state)(struct work_struct *work);
166 167 168
	void (*enable_tx_pause)(struct xgene_enet_pdata *pdata, bool enable);
	void (*flowctl_rx)(struct xgene_enet_pdata *pdata, bool enable);
	void (*flowctl_tx)(struct xgene_enet_pdata *pdata, bool enable);
169 170 171
};

struct xgene_port_ops {
172
	int (*reset)(struct xgene_enet_pdata *pdata);
173 174
	void (*clear)(struct xgene_enet_pdata *pdata,
		      struct xgene_enet_desc_ring *ring);
175
	void (*cle_bypass)(struct xgene_enet_pdata *pdata,
176
			   u32 dst_ring_num, u16 bufpool_id, u16 nxtbufpool_id);
177 178 179
	void (*shutdown)(struct xgene_enet_pdata *pdata);
};

180 181 182 183 184 185 186
struct xgene_ring_ops {
	u8 num_ring_config;
	u8 num_ring_id_shift;
	struct xgene_enet_desc_ring * (*setup)(struct xgene_enet_desc_ring *);
	void (*clear)(struct xgene_enet_desc_ring *);
	void (*wr_cmd)(struct xgene_enet_desc_ring *, int);
	u32 (*len)(struct xgene_enet_desc_ring *);
187
	void (*coalesce)(struct xgene_enet_desc_ring *);
188 189
};

190 191 192 193
struct xgene_cle_ops {
	int (*cle_init)(struct xgene_enet_pdata *pdata);
};

194 195 196 197 198 199 200
/* ethernet private data */
struct xgene_enet_pdata {
	struct net_device *ndev;
	struct mii_bus *mdio_bus;
	int phy_speed;
	struct clk *clk;
	struct platform_device *pdev;
201
	enum xgene_enet_id enet_id;
202 203 204 205
	struct xgene_enet_desc_ring *tx_ring[XGENE_NUM_TX_RING];
	struct xgene_enet_desc_ring *rx_ring[XGENE_NUM_RX_RING];
	u16 tx_level[XGENE_NUM_TX_RING];
	u16 txc_level[XGENE_NUM_TX_RING];
206 207 208
	char *dev_name;
	u32 rx_buff_cnt;
	u32 tx_qcnt_hi;
209 210 211
	u32 irqs[XGENE_MAX_ENET_IRQ];
	u8 rxq_cnt;
	u8 txq_cnt;
212
	u8 cq_cnt;
213 214 215 216 217
	void __iomem *eth_csr_addr;
	void __iomem *eth_ring_if_addr;
	void __iomem *eth_diag_csr_addr;
	void __iomem *mcx_mac_addr;
	void __iomem *mcx_mac_csr_addr;
218
	void __iomem *mcx_stats_addr;
219
	void __iomem *base_addr;
220
	void __iomem *pcs_addr;
221 222 223
	void __iomem *ring_csr_addr;
	void __iomem *ring_cmd_addr;
	int phy_mode;
224
	enum xgene_enet_rm rm;
225
	struct xgene_enet_cle cle;
226 227
	u64 *extd_stats;
	spinlock_t stats_lock; /* statistics lock */
228
	const struct xgene_mac_ops *mac_ops;
229
	spinlock_t mac_lock; /* mac lock */
230
	const struct xgene_port_ops *port_ops;
231
	struct xgene_ring_ops *ring_ops;
232
	const struct xgene_cle_ops *cle_ops;
233
	struct delayed_work link_work;
234 235 236 237 238
	u32 port_id;
	u8 cpu_bufnum;
	u8 eth_bufnum;
	u8 bp_bufnum;
	u16 ring_num;
239 240 241
	u32 mss[NUM_MSS_REG];
	u32 mss_refcnt[NUM_MSS_REG];
	spinlock_t mss_lock;  /* mss lock */
242 243
	u8 tx_delay;
	u8 rx_delay;
244
	bool mdio_driver;
245
	struct gpio_desc *sfp_rdy;
246
	bool sfp_gpio_en;
247 248 249
	u32 pause_autoneg;
	bool tx_pause;
	bool rx_pause;
250 251
};

252 253 254 255 256 257 258
struct xgene_indirect_ctl {
	void __iomem *addr;
	void __iomem *ctl;
	void __iomem *cmd;
	void __iomem *cmd_done;
};

259 260 261 262 263
static inline struct device *ndev_to_dev(struct net_device *ndev)
{
	return ndev->dev.parent;
}

264 265 266 267 268 269 270
static inline u16 xgene_enet_dst_ring_num(struct xgene_enet_desc_ring *ring)
{
	struct xgene_enet_pdata *pdata = netdev_priv(ring->ndev);

	return ((u16)pdata->rm << 10) | ring->num;
}

271
void xgene_enet_set_ethtool_ops(struct net_device *netdev);
272
int xgene_extd_stats_init(struct xgene_enet_pdata *pdata);
273 274

#endif /* __XGENE_ENET_MAIN_H__ */