Linux Audio

Check our new training course

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