2 * NetCP driver local header
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>
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.
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.
24 #include <linux/netdevice.h>
25 #include <linux/soc/ti/knav_dma.h>
26 #include <linux/u64_stats_sync.h>
28 /* Maximum Ethernet frame size supported by Keystone switch */
29 #define NETCP_MAX_FRAME_SIZE 9504
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
41 struct netcp_tx_pipe
{
42 struct netcp_device
*netcp_device
;
44 unsigned int dma_queue_id
;
45 /* To port for packet forwarded to switch. Used only by ethss */
47 #define SWITCH_TO_PORT_IN_TAGINFO BIT(0)
50 const char *dma_chan_name
;
53 #define ADDR_NEW BIT(0)
54 #define ADDR_VALID BIT(1)
56 enum netcp_addr_type
{
65 struct netcp_intf
*netcp
;
66 unsigned char addr
[ETH_ALEN
];
67 enum netcp_addr_type type
;
69 struct list_head node
;
73 struct u64_stats_sync syncp_rx ____cacheline_aligned_in_smp
;
79 struct u64_stats_sync syncp_tx ____cacheline_aligned_in_smp
;
88 struct device
*ndev_dev
;
89 struct net_device
*ndev
;
91 unsigned int tx_compl_qid
;
93 struct list_head txhook_list_head
;
94 unsigned int tx_pause_threshold
;
97 unsigned int tx_resume_threshold
;
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)
108 /* 64-bit netcp stats */
109 struct netcp_stats stats
;
112 const char *dma_chan_name
;
114 u32 rx_pool_region_id
;
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
;
123 /* Lock used for protecting Rx/Tx hook list management */
125 struct netcp_device
*netcp_device
;
126 struct device_node
*node_interface
;
128 /* DMA configuration data */
130 u32 rx_queue_depths
[KNAV_DMA_FDQ_PER_CHAN
];
133 #define NETCP_PSDATA_LEN KNAV_DMA_NUM_PS_WORDS
134 struct netcp_packet
{
139 unsigned int psdata_len
;
140 struct netcp_intf
*netcp
;
141 struct netcp_tx_pipe
*tx_pipe
;
142 bool rxtstamp_complete
;
145 void (*txtstamp
)(void *ctx
, struct sk_buff
*skb
);
148 static inline u32
*netcp_push_psdata(struct netcp_packet
*p_info
,
154 if ((bytes
& 0x03) != 0)
158 if ((p_info
->psdata_len
+ words
) > NETCP_PSDATA_LEN
)
161 p_info
->psdata_len
+= words
;
162 buf
= &p_info
->psdata
[NETCP_PSDATA_LEN
- p_info
->psdata_len
];
166 static inline int netcp_align_psdata(struct netcp_packet
*p_info
,
167 unsigned int byte_align
)
171 switch (byte_align
) {
181 padding
= (p_info
->psdata_len
<< 2) % 8;
184 padding
= (p_info
->psdata_len
<< 2) % 16;
187 padding
= (p_info
->psdata_len
<< 2) % byte_align
;
193 struct netcp_module
{
195 struct module
*owner
;
198 /* probe/remove: called once per NETCP instance */
199 int (*probe
)(struct netcp_device
*netcp_device
,
200 struct device
*device
, struct device_node
*node
,
202 int (*remove
)(struct netcp_device
*netcp_device
, void *inst_priv
);
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
);
216 /* used internally */
217 struct list_head module_list
;
218 struct list_head interface_list
;
221 int netcp_register_module(struct netcp_module
*module
);
222 void netcp_unregister_module(struct netcp_module
*module
);
223 void *netcp_module_get_intf_data(struct netcp_module
*module
,
224 struct netcp_intf
*intf
);
226 int 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
);
229 int netcp_txpipe_open(struct netcp_tx_pipe
*tx_pipe
);
230 int netcp_txpipe_close(struct netcp_tx_pipe
*tx_pipe
);
232 typedef int netcp_hook_rtn(int order
, void *data
, struct netcp_packet
*packet
);
233 int netcp_register_txhook(struct netcp_intf
*netcp_priv
, int order
,
234 netcp_hook_rtn
*hook_rtn
, void *hook_data
);
235 int netcp_unregister_txhook(struct netcp_intf
*netcp_priv
, int order
,
236 netcp_hook_rtn
*hook_rtn
, void *hook_data
);
237 int netcp_register_rxhook(struct netcp_intf
*netcp_priv
, int order
,
238 netcp_hook_rtn
*hook_rtn
, void *hook_data
);
239 int netcp_unregister_rxhook(struct netcp_intf
*netcp_priv
, int order
,
240 netcp_hook_rtn
*hook_rtn
, void *hook_data
);
241 void *netcp_device_find_module(struct netcp_device
*netcp_device
,
244 /* SGMII functions */
245 int netcp_sgmii_reset(void __iomem
*sgmii_ofs
, int port
);
246 bool netcp_sgmii_rtreset(void __iomem
*sgmii_ofs
, int port
, bool set
);
247 int netcp_sgmii_get_port_link(void __iomem
*sgmii_ofs
, int port
);
248 int netcp_sgmii_config(void __iomem
*sgmii_ofs
, int port
, u32 interface
);
250 /* XGBE SERDES init functions */
251 int netcp_xgbe_serdes_init(void __iomem
*serdes_regs
, void __iomem
*xgbe_regs
);
253 #endif /* __NETCP_H__ */