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>
27 /* Maximum Ethernet frame size supported by Keystone switch */
28 #define NETCP_MAX_FRAME_SIZE 9504
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
40 struct netcp_tx_pipe
{
41 struct netcp_device
*netcp_device
;
43 unsigned int dma_queue_id
;
44 /* To port for packet forwarded to switch. Used only by ethss */
46 #define SWITCH_TO_PORT_IN_TAGINFO BIT(0)
49 const char *dma_chan_name
;
52 #define ADDR_NEW BIT(0)
53 #define ADDR_VALID BIT(1)
55 enum netcp_addr_type
{
64 struct netcp_intf
*netcp
;
65 unsigned char addr
[ETH_ALEN
];
66 enum netcp_addr_type type
;
68 struct list_head node
;
73 struct device
*ndev_dev
;
74 struct net_device
*ndev
;
76 unsigned int tx_compl_qid
;
78 struct list_head txhook_list_head
;
79 unsigned int tx_pause_threshold
;
82 unsigned int tx_resume_threshold
;
85 struct list_head rxhook_list_head
;
86 unsigned int rx_queue_id
;
87 void *rx_fdq
[KNAV_DMA_FDQ_PER_CHAN
];
88 struct napi_struct rx_napi
;
89 struct napi_struct tx_napi
;
92 const char *dma_chan_name
;
94 u32 rx_pool_region_id
;
96 u32 tx_pool_region_id
;
97 struct list_head module_head
;
98 struct list_head interface_list
;
99 struct list_head addr_list
;
100 bool netdev_registered
;
101 bool primary_module_attached
;
103 /* Lock used for protecting Rx/Tx hook list management */
105 struct netcp_device
*netcp_device
;
106 struct device_node
*node_interface
;
108 /* DMA configuration data */
110 u32 rx_queue_depths
[KNAV_DMA_FDQ_PER_CHAN
];
113 #define NETCP_PSDATA_LEN KNAV_DMA_NUM_PS_WORDS
114 struct netcp_packet
{
118 unsigned int psdata_len
;
119 struct netcp_intf
*netcp
;
120 struct netcp_tx_pipe
*tx_pipe
;
121 bool rxtstamp_complete
;
124 int (*txtstamp_complete
)(void *ctx
, struct netcp_packet
*pkt
);
127 static inline u32
*netcp_push_psdata(struct netcp_packet
*p_info
,
133 if ((bytes
& 0x03) != 0)
137 if ((p_info
->psdata_len
+ words
) > NETCP_PSDATA_LEN
)
140 p_info
->psdata_len
+= words
;
141 buf
= &p_info
->psdata
[NETCP_PSDATA_LEN
- p_info
->psdata_len
];
145 static inline int netcp_align_psdata(struct netcp_packet
*p_info
,
146 unsigned int byte_align
)
150 switch (byte_align
) {
160 padding
= (p_info
->psdata_len
<< 2) % 8;
163 padding
= (p_info
->psdata_len
<< 2) % 16;
166 padding
= (p_info
->psdata_len
<< 2) % byte_align
;
172 struct netcp_module
{
174 struct module
*owner
;
177 /* probe/remove: called once per NETCP instance */
178 int (*probe
)(struct netcp_device
*netcp_device
,
179 struct device
*device
, struct device_node
*node
,
181 int (*remove
)(struct netcp_device
*netcp_device
, void *inst_priv
);
183 /* attach/release: called once per network interface */
184 int (*attach
)(void *inst_priv
, struct net_device
*ndev
,
185 struct device_node
*node
, void **intf_priv
);
186 int (*release
)(void *intf_priv
);
187 int (*open
)(void *intf_priv
, struct net_device
*ndev
);
188 int (*close
)(void *intf_priv
, struct net_device
*ndev
);
189 int (*add_addr
)(void *intf_priv
, struct netcp_addr
*naddr
);
190 int (*del_addr
)(void *intf_priv
, struct netcp_addr
*naddr
);
191 int (*add_vid
)(void *intf_priv
, int vid
);
192 int (*del_vid
)(void *intf_priv
, int vid
);
193 int (*ioctl
)(void *intf_priv
, struct ifreq
*req
, int cmd
);
195 /* used internally */
196 struct list_head module_list
;
197 struct list_head interface_list
;
200 int netcp_register_module(struct netcp_module
*module
);
201 void netcp_unregister_module(struct netcp_module
*module
);
202 void *netcp_module_get_intf_data(struct netcp_module
*module
,
203 struct netcp_intf
*intf
);
205 int netcp_txpipe_init(struct netcp_tx_pipe
*tx_pipe
,
206 struct netcp_device
*netcp_device
,
207 const char *dma_chan_name
, unsigned int dma_queue_id
);
208 int netcp_txpipe_open(struct netcp_tx_pipe
*tx_pipe
);
209 int netcp_txpipe_close(struct netcp_tx_pipe
*tx_pipe
);
211 typedef int netcp_hook_rtn(int order
, void *data
, struct netcp_packet
*packet
);
212 int netcp_register_txhook(struct netcp_intf
*netcp_priv
, int order
,
213 netcp_hook_rtn
*hook_rtn
, void *hook_data
);
214 int netcp_unregister_txhook(struct netcp_intf
*netcp_priv
, int order
,
215 netcp_hook_rtn
*hook_rtn
, void *hook_data
);
216 int netcp_register_rxhook(struct netcp_intf
*netcp_priv
, int order
,
217 netcp_hook_rtn
*hook_rtn
, void *hook_data
);
218 int netcp_unregister_rxhook(struct netcp_intf
*netcp_priv
, int order
,
219 netcp_hook_rtn
*hook_rtn
, void *hook_data
);
220 void *netcp_device_find_module(struct netcp_device
*netcp_device
,
223 /* SGMII functions */
224 int netcp_sgmii_reset(void __iomem
*sgmii_ofs
, int port
);
225 bool netcp_sgmii_rtreset(void __iomem
*sgmii_ofs
, int port
, bool set
);
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
);
229 /* XGBE SERDES init functions */
230 int netcp_xgbe_serdes_init(void __iomem
*serdes_regs
, void __iomem
*xgbe_regs
);
232 #endif /* __NETCP_H__ */