Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* Copyright (C) 2021 Gerhard Engleder <gerhard@engleder-embedded.com> */
0003 
0004 #ifndef _TSNEP_H
0005 #define _TSNEP_H
0006 
0007 #include "tsnep_hw.h"
0008 
0009 #include <linux/platform_device.h>
0010 #include <linux/dma-mapping.h>
0011 #include <linux/etherdevice.h>
0012 #include <linux/phy.h>
0013 #include <linux/ethtool.h>
0014 #include <linux/net_tstamp.h>
0015 #include <linux/ptp_clock_kernel.h>
0016 #include <linux/miscdevice.h>
0017 
0018 #define TSNEP "tsnep"
0019 
0020 #define TSNEP_RING_SIZE 256
0021 #define TSNEP_RING_ENTRIES_PER_PAGE (PAGE_SIZE / TSNEP_DESC_SIZE)
0022 #define TSNEP_RING_PAGE_COUNT (TSNEP_RING_SIZE / TSNEP_RING_ENTRIES_PER_PAGE)
0023 
0024 #define TSNEP_QUEUES 1
0025 
0026 struct tsnep_gcl {
0027     void __iomem *addr;
0028 
0029     u64 base_time;
0030     u64 cycle_time;
0031     u64 cycle_time_extension;
0032 
0033     struct tsnep_gcl_operation operation[TSNEP_GCL_COUNT];
0034     int count;
0035 
0036     u64 change_limit;
0037 
0038     u64 start_time;
0039     bool change;
0040 };
0041 
0042 struct tsnep_tx_entry {
0043     struct tsnep_tx_desc *desc;
0044     struct tsnep_tx_desc_wb *desc_wb;
0045     dma_addr_t desc_dma;
0046     bool owner_user_flag;
0047 
0048     u32 properties;
0049 
0050     struct sk_buff *skb;
0051     size_t len;
0052     DEFINE_DMA_UNMAP_ADDR(dma);
0053 };
0054 
0055 struct tsnep_tx {
0056     struct tsnep_adapter *adapter;
0057     void __iomem *addr;
0058 
0059     void *page[TSNEP_RING_PAGE_COUNT];
0060     dma_addr_t page_dma[TSNEP_RING_PAGE_COUNT];
0061 
0062     /* TX ring lock */
0063     spinlock_t lock;
0064     struct tsnep_tx_entry entry[TSNEP_RING_SIZE];
0065     int write;
0066     int read;
0067     u32 owner_counter;
0068     int increment_owner_counter;
0069 
0070     u32 packets;
0071     u32 bytes;
0072     u32 dropped;
0073 };
0074 
0075 struct tsnep_rx_entry {
0076     struct tsnep_rx_desc *desc;
0077     struct tsnep_rx_desc_wb *desc_wb;
0078     dma_addr_t desc_dma;
0079 
0080     u32 properties;
0081 
0082     struct sk_buff *skb;
0083     size_t len;
0084     DEFINE_DMA_UNMAP_ADDR(dma);
0085 };
0086 
0087 struct tsnep_rx {
0088     struct tsnep_adapter *adapter;
0089     void __iomem *addr;
0090 
0091     void *page[TSNEP_RING_PAGE_COUNT];
0092     dma_addr_t page_dma[TSNEP_RING_PAGE_COUNT];
0093 
0094     struct tsnep_rx_entry entry[TSNEP_RING_SIZE];
0095     int read;
0096     u32 owner_counter;
0097     int increment_owner_counter;
0098 
0099     u32 packets;
0100     u32 bytes;
0101     u32 dropped;
0102     u32 multicast;
0103 };
0104 
0105 struct tsnep_queue {
0106     struct tsnep_adapter *adapter;
0107 
0108     struct tsnep_tx *tx;
0109     struct tsnep_rx *rx;
0110 
0111     struct napi_struct napi;
0112 
0113     u32 irq_mask;
0114 };
0115 
0116 struct tsnep_adapter {
0117     struct net_device *netdev;
0118     u8 mac_address[ETH_ALEN];
0119     struct mii_bus *mdiobus;
0120     bool suppress_preamble;
0121     phy_interface_t phy_mode;
0122     struct phy_device *phydev;
0123     int msg_enable;
0124 
0125     struct platform_device *pdev;
0126     struct device *dmadev;
0127     void __iomem *addr;
0128     int irq;
0129 
0130     bool gate_control;
0131     /* gate control lock */
0132     struct mutex gate_control_lock;
0133     bool gate_control_active;
0134     struct tsnep_gcl gcl[2];
0135     int next_gcl;
0136 
0137     struct hwtstamp_config hwtstamp_config;
0138     struct ptp_clock *ptp_clock;
0139     struct ptp_clock_info ptp_clock_info;
0140     /* ptp clock lock */
0141     spinlock_t ptp_lock;
0142 
0143     int num_tx_queues;
0144     struct tsnep_tx tx[TSNEP_MAX_QUEUES];
0145     int num_rx_queues;
0146     struct tsnep_rx rx[TSNEP_MAX_QUEUES];
0147 
0148     int num_queues;
0149     struct tsnep_queue queue[TSNEP_MAX_QUEUES];
0150 };
0151 
0152 extern const struct ethtool_ops tsnep_ethtool_ops;
0153 
0154 int tsnep_ptp_init(struct tsnep_adapter *adapter);
0155 void tsnep_ptp_cleanup(struct tsnep_adapter *adapter);
0156 int tsnep_ptp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
0157 
0158 int tsnep_tc_init(struct tsnep_adapter *adapter);
0159 void tsnep_tc_cleanup(struct tsnep_adapter *adapter);
0160 int tsnep_tc_setup(struct net_device *netdev, enum tc_setup_type type,
0161            void *type_data);
0162 
0163 #if IS_ENABLED(CONFIG_TSNEP_SELFTESTS)
0164 int tsnep_ethtool_get_test_count(void);
0165 void tsnep_ethtool_get_test_strings(u8 *data);
0166 void tsnep_ethtool_self_test(struct net_device *netdev,
0167                  struct ethtool_test *eth_test, u64 *data);
0168 #else
0169 static inline int tsnep_ethtool_get_test_count(void)
0170 {
0171     return -EOPNOTSUPP;
0172 }
0173 
0174 static inline void tsnep_ethtool_get_test_strings(u8 *data)
0175 {
0176     /* not enabled */
0177 }
0178 
0179 static inline void tsnep_ethtool_self_test(struct net_device *dev,
0180                        struct ethtool_test *eth_test,
0181                        u64 *data)
0182 {
0183     /* not enabled */
0184 }
0185 #endif /* CONFIG_TSNEP_SELFTESTS */
0186 
0187 void tsnep_get_system_time(struct tsnep_adapter *adapter, u64 *time);
0188 
0189 #endif /* _TSNEP_H */