blob: 906e9bc412f5a56a35174faeff4d7cd12443ee4c [file] [log] [blame]
Karicheri, Muralidharan84640e22015-01-15 19:12:50 -05001/*
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
38struct netcp_device;
39
40struct netcp_tx_pipe {
41 struct netcp_device *netcp_device;
42 void *dma_queue;
43 unsigned int dma_queue_id;
44 u8 dma_psflags;
45 void *dma_channel;
46 const char *dma_chan_name;
47};
48
49#define ADDR_NEW BIT(0)
50#define ADDR_VALID BIT(1)
51
52enum netcp_addr_type {
53 ADDR_ANY,
54 ADDR_DEV,
55 ADDR_UCAST,
56 ADDR_MCAST,
57 ADDR_BCAST
58};
59
60struct netcp_addr {
61 struct netcp_intf *netcp;
62 unsigned char addr[ETH_ALEN];
63 enum netcp_addr_type type;
64 unsigned int flags;
65 struct list_head node;
66};
67
68struct netcp_intf {
69 struct device *dev;
70 struct device *ndev_dev;
71 struct net_device *ndev;
72 bool big_endian;
73 unsigned int tx_compl_qid;
74 void *tx_pool;
75 struct list_head txhook_list_head;
76 unsigned int tx_pause_threshold;
77 void *tx_compl_q;
78
79 unsigned int tx_resume_threshold;
80 void *rx_queue;
81 void *rx_pool;
82 struct list_head rxhook_list_head;
83 unsigned int rx_queue_id;
84 void *rx_fdq[KNAV_DMA_FDQ_PER_CHAN];
85 u32 rx_buffer_sizes[KNAV_DMA_FDQ_PER_CHAN];
86 struct napi_struct rx_napi;
87 struct napi_struct tx_napi;
88
89 void *rx_channel;
90 const char *dma_chan_name;
91 u32 rx_pool_size;
92 u32 rx_pool_region_id;
93 u32 tx_pool_size;
94 u32 tx_pool_region_id;
95 struct list_head module_head;
96 struct list_head interface_list;
97 struct list_head addr_list;
98 bool netdev_registered;
99 bool primary_module_attached;
100
101 /* Lock used for protecting Rx/Tx hook list management */
102 spinlock_t lock;
103 struct netcp_device *netcp_device;
104 struct device_node *node_interface;
105
106 /* DMA configuration data */
107 u32 msg_enable;
108 u32 rx_queue_depths[KNAV_DMA_FDQ_PER_CHAN];
109};
110
111#define NETCP_PSDATA_LEN KNAV_DMA_NUM_PS_WORDS
112struct netcp_packet {
113 struct sk_buff *skb;
114 u32 *epib;
115 u32 *psdata;
116 unsigned int psdata_len;
117 struct netcp_intf *netcp;
118 struct netcp_tx_pipe *tx_pipe;
119 bool rxtstamp_complete;
120 void *ts_context;
121
122 int (*txtstamp_complete)(void *ctx, struct netcp_packet *pkt);
123};
124
125static inline u32 *netcp_push_psdata(struct netcp_packet *p_info,
126 unsigned int bytes)
127{
128 u32 *buf;
129 unsigned int words;
130
131 if ((bytes & 0x03) != 0)
132 return NULL;
133 words = bytes >> 2;
134
135 if ((p_info->psdata_len + words) > NETCP_PSDATA_LEN)
136 return NULL;
137
138 p_info->psdata_len += words;
139 buf = &p_info->psdata[NETCP_PSDATA_LEN - p_info->psdata_len];
140 return buf;
141}
142
143static inline int netcp_align_psdata(struct netcp_packet *p_info,
144 unsigned int byte_align)
145{
146 int padding;
147
148 switch (byte_align) {
149 case 0:
150 padding = -EINVAL;
151 break;
152 case 1:
153 case 2:
154 case 4:
155 padding = 0;
156 break;
157 case 8:
158 padding = (p_info->psdata_len << 2) % 8;
159 break;
160 case 16:
161 padding = (p_info->psdata_len << 2) % 16;
162 break;
163 default:
164 padding = (p_info->psdata_len << 2) % byte_align;
165 break;
166 }
167 return padding;
168}
169
170struct netcp_module {
171 const char *name;
172 struct module *owner;
173 bool primary;
174
175 /* probe/remove: called once per NETCP instance */
176 int (*probe)(struct netcp_device *netcp_device,
177 struct device *device, struct device_node *node,
178 void **inst_priv);
179 int (*remove)(struct netcp_device *netcp_device, void *inst_priv);
180
181 /* attach/release: called once per network interface */
182 int (*attach)(void *inst_priv, struct net_device *ndev,
183 struct device_node *node, void **intf_priv);
184 int (*release)(void *intf_priv);
185 int (*open)(void *intf_priv, struct net_device *ndev);
186 int (*close)(void *intf_priv, struct net_device *ndev);
187 int (*add_addr)(void *intf_priv, struct netcp_addr *naddr);
188 int (*del_addr)(void *intf_priv, struct netcp_addr *naddr);
189 int (*add_vid)(void *intf_priv, int vid);
190 int (*del_vid)(void *intf_priv, int vid);
191 int (*ioctl)(void *intf_priv, struct ifreq *req, int cmd);
192
193 /* used internally */
194 struct list_head module_list;
195 struct list_head interface_list;
196};
197
198int netcp_register_module(struct netcp_module *module);
199void netcp_unregister_module(struct netcp_module *module);
200void *netcp_module_get_intf_data(struct netcp_module *module,
201 struct netcp_intf *intf);
202
203int netcp_txpipe_init(struct netcp_tx_pipe *tx_pipe,
204 struct netcp_device *netcp_device,
205 const char *dma_chan_name, unsigned int dma_queue_id);
206int netcp_txpipe_open(struct netcp_tx_pipe *tx_pipe);
207int netcp_txpipe_close(struct netcp_tx_pipe *tx_pipe);
208
209typedef int netcp_hook_rtn(int order, void *data, struct netcp_packet *packet);
210int netcp_register_txhook(struct netcp_intf *netcp_priv, int order,
211 netcp_hook_rtn *hook_rtn, void *hook_data);
212int netcp_unregister_txhook(struct netcp_intf *netcp_priv, int order,
213 netcp_hook_rtn *hook_rtn, void *hook_data);
214int netcp_register_rxhook(struct netcp_intf *netcp_priv, int order,
215 netcp_hook_rtn *hook_rtn, void *hook_data);
216int netcp_unregister_rxhook(struct netcp_intf *netcp_priv, int order,
217 netcp_hook_rtn *hook_rtn, void *hook_data);
218void *netcp_device_find_module(struct netcp_device *netcp_device,
219 const char *name);
220
221/* SGMII functions */
222int netcp_sgmii_reset(void __iomem *sgmii_ofs, int port);
223int netcp_sgmii_get_port_link(void __iomem *sgmii_ofs, int port);
224int netcp_sgmii_config(void __iomem *sgmii_ofs, int port, u32 interface);
225
226/* XGBE SERDES init functions */
227int netcp_xgbe_serdes_init(void __iomem *serdes_regs, void __iomem *xgbe_regs);
228
229#endif /* __NETCP_H__ */