0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef __NETCP_H__
0014 #define __NETCP_H__
0015
0016 #include <linux/netdevice.h>
0017 #include <linux/soc/ti/knav_dma.h>
0018 #include <linux/u64_stats_sync.h>
0019
0020
0021 #define NETCP_MAX_FRAME_SIZE 9504
0022
0023 #define SGMII_LINK_MAC_MAC_AUTONEG 0
0024 #define SGMII_LINK_MAC_PHY 1
0025 #define SGMII_LINK_MAC_MAC_FORCED 2
0026 #define SGMII_LINK_MAC_FIBER 3
0027 #define SGMII_LINK_MAC_PHY_NO_MDIO 4
0028 #define RGMII_LINK_MAC_PHY 5
0029 #define RGMII_LINK_MAC_PHY_NO_MDIO 7
0030 #define XGMII_LINK_MAC_PHY 10
0031 #define XGMII_LINK_MAC_MAC_FORCED 11
0032
0033 struct netcp_device;
0034
0035 struct netcp_tx_pipe {
0036 struct netcp_device *netcp_device;
0037 void *dma_queue;
0038 unsigned int dma_queue_id;
0039
0040 u8 switch_to_port;
0041 #define SWITCH_TO_PORT_IN_TAGINFO BIT(0)
0042 u8 flags;
0043 void *dma_channel;
0044 const char *dma_chan_name;
0045 };
0046
0047 #define ADDR_NEW BIT(0)
0048 #define ADDR_VALID BIT(1)
0049
0050 enum netcp_addr_type {
0051 ADDR_ANY,
0052 ADDR_DEV,
0053 ADDR_UCAST,
0054 ADDR_MCAST,
0055 ADDR_BCAST
0056 };
0057
0058 struct netcp_addr {
0059 struct netcp_intf *netcp;
0060 unsigned char addr[ETH_ALEN];
0061 enum netcp_addr_type type;
0062 unsigned int flags;
0063 struct list_head node;
0064 };
0065
0066 struct netcp_stats {
0067 struct u64_stats_sync syncp_rx ____cacheline_aligned_in_smp;
0068 u64 rx_packets;
0069 u64 rx_bytes;
0070 u32 rx_errors;
0071 u32 rx_dropped;
0072
0073 struct u64_stats_sync syncp_tx ____cacheline_aligned_in_smp;
0074 u64 tx_packets;
0075 u64 tx_bytes;
0076 u32 tx_errors;
0077 u32 tx_dropped;
0078 };
0079
0080 struct netcp_intf {
0081 struct device *dev;
0082 struct device *ndev_dev;
0083 struct net_device *ndev;
0084 bool big_endian;
0085 unsigned int tx_compl_qid;
0086 void *tx_pool;
0087 struct list_head txhook_list_head;
0088 unsigned int tx_pause_threshold;
0089 void *tx_compl_q;
0090
0091 unsigned int tx_resume_threshold;
0092 void *rx_queue;
0093 void *rx_pool;
0094 struct list_head rxhook_list_head;
0095 unsigned int rx_queue_id;
0096 void *rx_fdq[KNAV_DMA_FDQ_PER_CHAN];
0097 struct napi_struct rx_napi;
0098 struct napi_struct tx_napi;
0099 #define ETH_SW_CAN_REMOVE_ETH_FCS BIT(0)
0100 u32 hw_cap;
0101
0102
0103 struct netcp_stats stats;
0104
0105 void *rx_channel;
0106 const char *dma_chan_name;
0107 u32 rx_pool_size;
0108 u32 rx_pool_region_id;
0109 u32 tx_pool_size;
0110 u32 tx_pool_region_id;
0111 struct list_head module_head;
0112 struct list_head interface_list;
0113 struct list_head addr_list;
0114 bool netdev_registered;
0115 bool primary_module_attached;
0116
0117
0118 spinlock_t lock;
0119 struct netcp_device *netcp_device;
0120 struct device_node *node_interface;
0121
0122
0123 u32 msg_enable;
0124 u32 rx_queue_depths[KNAV_DMA_FDQ_PER_CHAN];
0125 };
0126
0127 #define NETCP_PSDATA_LEN KNAV_DMA_NUM_PS_WORDS
0128 struct netcp_packet {
0129 struct sk_buff *skb;
0130 __le32 *epib;
0131 u32 *psdata;
0132 u32 eflags;
0133 unsigned int psdata_len;
0134 struct netcp_intf *netcp;
0135 struct netcp_tx_pipe *tx_pipe;
0136 bool rxtstamp_complete;
0137 void *ts_context;
0138
0139 void (*txtstamp)(void *ctx, struct sk_buff *skb);
0140 };
0141
0142 static inline u32 *netcp_push_psdata(struct netcp_packet *p_info,
0143 unsigned int bytes)
0144 {
0145 u32 *buf;
0146 unsigned int words;
0147
0148 if ((bytes & 0x03) != 0)
0149 return NULL;
0150 words = bytes >> 2;
0151
0152 if ((p_info->psdata_len + words) > NETCP_PSDATA_LEN)
0153 return NULL;
0154
0155 p_info->psdata_len += words;
0156 buf = &p_info->psdata[NETCP_PSDATA_LEN - p_info->psdata_len];
0157 return buf;
0158 }
0159
0160 static inline int netcp_align_psdata(struct netcp_packet *p_info,
0161 unsigned int byte_align)
0162 {
0163 int padding;
0164
0165 switch (byte_align) {
0166 case 0:
0167 padding = -EINVAL;
0168 break;
0169 case 1:
0170 case 2:
0171 case 4:
0172 padding = 0;
0173 break;
0174 case 8:
0175 padding = (p_info->psdata_len << 2) % 8;
0176 break;
0177 case 16:
0178 padding = (p_info->psdata_len << 2) % 16;
0179 break;
0180 default:
0181 padding = (p_info->psdata_len << 2) % byte_align;
0182 break;
0183 }
0184 return padding;
0185 }
0186
0187 struct netcp_module {
0188 const char *name;
0189 struct module *owner;
0190 bool primary;
0191
0192
0193 int (*probe)(struct netcp_device *netcp_device,
0194 struct device *device, struct device_node *node,
0195 void **inst_priv);
0196 int (*remove)(struct netcp_device *netcp_device, void *inst_priv);
0197
0198
0199 int (*attach)(void *inst_priv, struct net_device *ndev,
0200 struct device_node *node, void **intf_priv);
0201 int (*release)(void *intf_priv);
0202 int (*open)(void *intf_priv, struct net_device *ndev);
0203 int (*close)(void *intf_priv, struct net_device *ndev);
0204 int (*add_addr)(void *intf_priv, struct netcp_addr *naddr);
0205 int (*del_addr)(void *intf_priv, struct netcp_addr *naddr);
0206 int (*add_vid)(void *intf_priv, int vid);
0207 int (*del_vid)(void *intf_priv, int vid);
0208 int (*ioctl)(void *intf_priv, struct ifreq *req, int cmd);
0209 int (*set_rx_mode)(void *intf_priv, bool promisc);
0210
0211
0212 struct list_head module_list;
0213 struct list_head interface_list;
0214 };
0215
0216 int netcp_register_module(struct netcp_module *module);
0217 void netcp_unregister_module(struct netcp_module *module);
0218 void *netcp_module_get_intf_data(struct netcp_module *module,
0219 struct netcp_intf *intf);
0220
0221 int netcp_txpipe_init(struct netcp_tx_pipe *tx_pipe,
0222 struct netcp_device *netcp_device,
0223 const char *dma_chan_name, unsigned int dma_queue_id);
0224 int netcp_txpipe_open(struct netcp_tx_pipe *tx_pipe);
0225 int netcp_txpipe_close(struct netcp_tx_pipe *tx_pipe);
0226
0227 typedef int netcp_hook_rtn(int order, void *data, struct netcp_packet *packet);
0228 int netcp_register_txhook(struct netcp_intf *netcp_priv, int order,
0229 netcp_hook_rtn *hook_rtn, void *hook_data);
0230 int netcp_unregister_txhook(struct netcp_intf *netcp_priv, int order,
0231 netcp_hook_rtn *hook_rtn, void *hook_data);
0232 int netcp_register_rxhook(struct netcp_intf *netcp_priv, int order,
0233 netcp_hook_rtn *hook_rtn, void *hook_data);
0234 int netcp_unregister_rxhook(struct netcp_intf *netcp_priv, int order,
0235 netcp_hook_rtn *hook_rtn, void *hook_data);
0236 void *netcp_device_find_module(struct netcp_device *netcp_device,
0237 const char *name);
0238
0239
0240 int netcp_sgmii_reset(void __iomem *sgmii_ofs, int port);
0241 bool netcp_sgmii_rtreset(void __iomem *sgmii_ofs, int port, bool set);
0242 int netcp_sgmii_get_port_link(void __iomem *sgmii_ofs, int port);
0243 int netcp_sgmii_config(void __iomem *sgmii_ofs, int port, u32 interface);
0244
0245
0246 int netcp_xgbe_serdes_init(void __iomem *serdes_regs, void __iomem *xgbe_regs);
0247
0248 #endif