1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* Copyright (c) Meta Platforms, Inc. and affiliates. */ 3 4 #ifndef _FBNIC_NETDEV_H_ 5 #define _FBNIC_NETDEV_H_ 6 7 #include <linux/phylink.h> 8 #include <linux/types.h> 9 10 #include "fbnic_csr.h" 11 #include "fbnic_rpc.h" 12 #include "fbnic_txrx.h" 13 14 #define FBNIC_MAX_NAPI_VECTORS 128u 15 #define FBNIC_MIN_RXD_PER_FRAME 2 16 17 /* Natively supported tunnel GSO features (not thru GSO_PARTIAL) */ 18 #define FBNIC_TUN_GSO_FEATURES NETIF_F_GSO_IPXIP6 19 20 struct fbnic_net { 21 struct bpf_prog *xdp_prog; 22 23 struct fbnic_ring *tx[FBNIC_MAX_TXQS + FBNIC_MAX_XDPQS]; 24 struct fbnic_ring *rx[FBNIC_MAX_RXQS]; 25 26 struct fbnic_napi_vector *napi[FBNIC_MAX_NAPI_VECTORS]; 27 28 struct net_device *netdev; 29 struct fbnic_dev *fbd; 30 31 u32 txq_size; 32 u32 hpq_size; 33 u32 ppq_size; 34 u32 rcq_size; 35 36 u32 hds_thresh; 37 38 u16 rx_usecs; 39 u16 tx_usecs; 40 41 u32 rx_max_frames; 42 43 u16 num_napi; 44 45 struct phylink *phylink; 46 struct phylink_config phylink_config; 47 struct phylink_pcs phylink_pcs; 48 49 u8 aui; 50 u8 fec; 51 52 /* Cached top bits of the HW time counter for 40b -> 64b conversion */ 53 u32 time_high; 54 /* Protect readers of @time_offset, writers take @time_lock. */ 55 struct u64_stats_sync time_seq; 56 /* Offset in ns between free running NIC PHC and time set via PTP 57 * clock callbacks 58 */ 59 s64 time_offset; 60 61 u16 num_tx_queues; 62 u16 num_rx_queues; 63 64 u8 indir_tbl[FBNIC_RPC_RSS_TBL_COUNT][FBNIC_RPC_RSS_TBL_SIZE]; 65 u32 rss_key[FBNIC_RPC_RSS_KEY_DWORD_LEN]; 66 u32 rss_flow_hash[FBNIC_NUM_HASH_OPT]; 67 68 /* Storage for stats after ring destruction */ 69 struct fbnic_queue_stats tx_stats; 70 struct fbnic_queue_stats rx_stats; 71 struct fbnic_queue_stats bdq_stats; 72 u64 link_down_events; 73 74 /* Time stamping filter config */ 75 struct kernel_hwtstamp_config hwtstamp_config; 76 }; 77 78 int __fbnic_open(struct fbnic_net *fbn); 79 void fbnic_up(struct fbnic_net *fbn); 80 void fbnic_down(struct fbnic_net *fbn); 81 void fbnic_down_noidle(struct fbnic_net *fbn); 82 83 struct net_device *fbnic_netdev_alloc(struct fbnic_dev *fbd); 84 void fbnic_netdev_free(struct fbnic_dev *fbd); 85 int fbnic_netdev_register(struct net_device *netdev); 86 void fbnic_netdev_unregister(struct net_device *netdev); 87 void fbnic_reset_queues(struct fbnic_net *fbn, 88 unsigned int tx, unsigned int rx); 89 90 void fbnic_set_ethtool_ops(struct net_device *dev); 91 92 int fbnic_ptp_setup(struct fbnic_dev *fbd); 93 void fbnic_ptp_destroy(struct fbnic_dev *fbd); 94 void fbnic_time_init(struct fbnic_net *fbn); 95 int fbnic_time_start(struct fbnic_net *fbn); 96 void fbnic_time_stop(struct fbnic_net *fbn); 97 98 void __fbnic_set_rx_mode(struct fbnic_dev *fbd); 99 void fbnic_clear_rx_mode(struct fbnic_dev *fbd); 100 101 void fbnic_phylink_get_pauseparam(struct net_device *netdev, 102 struct ethtool_pauseparam *pause); 103 int fbnic_phylink_set_pauseparam(struct net_device *netdev, 104 struct ethtool_pauseparam *pause); 105 int fbnic_phylink_ethtool_ksettings_get(struct net_device *netdev, 106 struct ethtool_link_ksettings *cmd); 107 int fbnic_phylink_get_fecparam(struct net_device *netdev, 108 struct ethtool_fecparam *fecparam); 109 int fbnic_phylink_init(struct net_device *netdev); 110 111 bool fbnic_check_split_frames(struct bpf_prog *prog, 112 unsigned int mtu, u32 hds_threshold); 113 #endif /* _FBNIC_NETDEV_H_ */ 114