xref: /openbmc/linux/drivers/net/ethernet/ti/netcp.h (revision 99b7e93c)
1 /*
2  * NetCP driver local header
3  *
4  * Copyright (C) 2014 Texas Instruments Incorporated
5  * Authors:	Sandeep Nair <sandeep_n@ti.com>
6  *		Sandeep Paulraj <s-paulraj@ti.com>
7  *		Cyril Chemparathy <cyril@ti.com>
8  *		Santosh Shilimkar <santosh.shilimkar@ti.com>
9  *		Wingman Kwok <w-kwok2@ti.com>
10  *		Murali Karicheri <m-karicheri2@ti.com>
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License as
14  * published by the Free Software Foundation version 2.
15  *
16  * This program is distributed "as is" WITHOUT ANY WARRANTY of any
17  * kind, whether express or implied; without even the implied warranty
18  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  */
21 #ifndef __NETCP_H__
22 #define __NETCP_H__
23 
24 #include <linux/netdevice.h>
25 #include <linux/soc/ti/knav_dma.h>
26 
27 /* Maximum Ethernet frame size supported by Keystone switch */
28 #define NETCP_MAX_FRAME_SIZE		9504
29 
30 #define SGMII_LINK_MAC_MAC_AUTONEG	0
31 #define SGMII_LINK_MAC_PHY		1
32 #define SGMII_LINK_MAC_MAC_FORCED	2
33 #define SGMII_LINK_MAC_FIBER		3
34 #define SGMII_LINK_MAC_PHY_NO_MDIO	4
35 #define XGMII_LINK_MAC_PHY		10
36 #define XGMII_LINK_MAC_MAC_FORCED	11
37 
38 struct netcp_device;
39 
40 struct netcp_tx_pipe {
41 	struct netcp_device	*netcp_device;
42 	void			*dma_queue;
43 	unsigned int		dma_queue_id;
44 	/* To port for packet forwarded to switch. Used only by ethss */
45 	u8			switch_to_port;
46 #define	SWITCH_TO_PORT_IN_TAGINFO	BIT(0)
47 	u8			flags;
48 	void			*dma_channel;
49 	const char		*dma_chan_name;
50 };
51 
52 #define ADDR_NEW			BIT(0)
53 #define ADDR_VALID			BIT(1)
54 
55 enum netcp_addr_type {
56 	ADDR_ANY,
57 	ADDR_DEV,
58 	ADDR_UCAST,
59 	ADDR_MCAST,
60 	ADDR_BCAST
61 };
62 
63 struct netcp_addr {
64 	struct netcp_intf	*netcp;
65 	unsigned char		addr[ETH_ALEN];
66 	enum netcp_addr_type	type;
67 	unsigned int		flags;
68 	struct list_head	node;
69 };
70 
71 struct netcp_intf {
72 	struct device		*dev;
73 	struct device		*ndev_dev;
74 	struct net_device	*ndev;
75 	bool			big_endian;
76 	unsigned int		tx_compl_qid;
77 	void			*tx_pool;
78 	struct list_head	txhook_list_head;
79 	unsigned int		tx_pause_threshold;
80 	void			*tx_compl_q;
81 
82 	unsigned int		tx_resume_threshold;
83 	void			*rx_queue;
84 	void			*rx_pool;
85 	struct list_head	rxhook_list_head;
86 	unsigned int		rx_queue_id;
87 	void			*rx_fdq[KNAV_DMA_FDQ_PER_CHAN];
88 	u32			rx_buffer_sizes[KNAV_DMA_FDQ_PER_CHAN];
89 	struct napi_struct	rx_napi;
90 	struct napi_struct	tx_napi;
91 
92 	void			*rx_channel;
93 	const char		*dma_chan_name;
94 	u32			rx_pool_size;
95 	u32			rx_pool_region_id;
96 	u32			tx_pool_size;
97 	u32			tx_pool_region_id;
98 	struct list_head	module_head;
99 	struct list_head	interface_list;
100 	struct list_head	addr_list;
101 	bool			netdev_registered;
102 	bool			primary_module_attached;
103 
104 	/* Lock used for protecting Rx/Tx hook list management */
105 	spinlock_t		lock;
106 	struct netcp_device	*netcp_device;
107 	struct device_node	*node_interface;
108 
109 	/* DMA configuration data */
110 	u32			msg_enable;
111 	u32			rx_queue_depths[KNAV_DMA_FDQ_PER_CHAN];
112 };
113 
114 #define	NETCP_PSDATA_LEN		KNAV_DMA_NUM_PS_WORDS
115 struct netcp_packet {
116 	struct sk_buff		*skb;
117 	u32			*epib;
118 	u32			*psdata;
119 	unsigned int		psdata_len;
120 	struct netcp_intf	*netcp;
121 	struct netcp_tx_pipe	*tx_pipe;
122 	bool			rxtstamp_complete;
123 	void			*ts_context;
124 
125 	int	(*txtstamp_complete)(void *ctx, struct netcp_packet *pkt);
126 };
127 
128 static inline u32 *netcp_push_psdata(struct netcp_packet *p_info,
129 				     unsigned int bytes)
130 {
131 	u32 *buf;
132 	unsigned int words;
133 
134 	if ((bytes & 0x03) != 0)
135 		return NULL;
136 	words = bytes >> 2;
137 
138 	if ((p_info->psdata_len + words) > NETCP_PSDATA_LEN)
139 		return NULL;
140 
141 	p_info->psdata_len += words;
142 	buf = &p_info->psdata[NETCP_PSDATA_LEN - p_info->psdata_len];
143 	return buf;
144 }
145 
146 static inline int netcp_align_psdata(struct netcp_packet *p_info,
147 				     unsigned int byte_align)
148 {
149 	int padding;
150 
151 	switch (byte_align) {
152 	case 0:
153 		padding = -EINVAL;
154 		break;
155 	case 1:
156 	case 2:
157 	case 4:
158 		padding = 0;
159 		break;
160 	case 8:
161 		padding = (p_info->psdata_len << 2) % 8;
162 		break;
163 	case 16:
164 		padding = (p_info->psdata_len << 2) % 16;
165 		break;
166 	default:
167 		padding = (p_info->psdata_len << 2) % byte_align;
168 		break;
169 	}
170 	return padding;
171 }
172 
173 struct netcp_module {
174 	const char		*name;
175 	struct module		*owner;
176 	bool			primary;
177 
178 	/* probe/remove: called once per NETCP instance */
179 	int	(*probe)(struct netcp_device *netcp_device,
180 			 struct device *device, struct device_node *node,
181 			 void **inst_priv);
182 	int	(*remove)(struct netcp_device *netcp_device, void *inst_priv);
183 
184 	/* attach/release: called once per network interface */
185 	int	(*attach)(void *inst_priv, struct net_device *ndev,
186 			  struct device_node *node, void **intf_priv);
187 	int	(*release)(void *intf_priv);
188 	int	(*open)(void *intf_priv, struct net_device *ndev);
189 	int	(*close)(void *intf_priv, struct net_device *ndev);
190 	int	(*add_addr)(void *intf_priv, struct netcp_addr *naddr);
191 	int	(*del_addr)(void *intf_priv, struct netcp_addr *naddr);
192 	int	(*add_vid)(void *intf_priv, int vid);
193 	int	(*del_vid)(void *intf_priv, int vid);
194 	int	(*ioctl)(void *intf_priv, struct ifreq *req, int cmd);
195 
196 	/* used internally */
197 	struct list_head	module_list;
198 	struct list_head	interface_list;
199 };
200 
201 int netcp_register_module(struct netcp_module *module);
202 void netcp_unregister_module(struct netcp_module *module);
203 void *netcp_module_get_intf_data(struct netcp_module *module,
204 				 struct netcp_intf *intf);
205 
206 int netcp_txpipe_init(struct netcp_tx_pipe *tx_pipe,
207 		      struct netcp_device *netcp_device,
208 		      const char *dma_chan_name, unsigned int dma_queue_id);
209 int netcp_txpipe_open(struct netcp_tx_pipe *tx_pipe);
210 int netcp_txpipe_close(struct netcp_tx_pipe *tx_pipe);
211 
212 typedef int netcp_hook_rtn(int order, void *data, struct netcp_packet *packet);
213 int netcp_register_txhook(struct netcp_intf *netcp_priv, int order,
214 			  netcp_hook_rtn *hook_rtn, void *hook_data);
215 int netcp_unregister_txhook(struct netcp_intf *netcp_priv, int order,
216 			    netcp_hook_rtn *hook_rtn, void *hook_data);
217 int netcp_register_rxhook(struct netcp_intf *netcp_priv, int order,
218 			  netcp_hook_rtn *hook_rtn, void *hook_data);
219 int netcp_unregister_rxhook(struct netcp_intf *netcp_priv, int order,
220 			    netcp_hook_rtn *hook_rtn, void *hook_data);
221 void *netcp_device_find_module(struct netcp_device *netcp_device,
222 			       const char *name);
223 
224 /* SGMII functions */
225 int netcp_sgmii_reset(void __iomem *sgmii_ofs, int port);
226 int netcp_sgmii_get_port_link(void __iomem *sgmii_ofs, int port);
227 int netcp_sgmii_config(void __iomem *sgmii_ofs, int port, u32 interface);
228 
229 /* XGBE SERDES init functions */
230 int netcp_xgbe_serdes_init(void __iomem *serdes_regs, void __iomem *xgbe_regs);
231 
232 #endif	/* __NETCP_H__ */
233