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/types.h>
8 #include <linux/phylink.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 
16 struct fbnic_net {
17 	struct fbnic_ring *tx[FBNIC_MAX_TXQS];
18 	struct fbnic_ring *rx[FBNIC_MAX_RXQS];
19 
20 	struct fbnic_napi_vector *napi[FBNIC_MAX_NAPI_VECTORS];
21 
22 	struct net_device *netdev;
23 	struct fbnic_dev *fbd;
24 
25 	u32 txq_size;
26 	u32 hpq_size;
27 	u32 ppq_size;
28 	u32 rcq_size;
29 
30 	u16 num_napi;
31 
32 	struct phylink *phylink;
33 	struct phylink_config phylink_config;
34 	struct phylink_pcs phylink_pcs;
35 
36 	/* TBD: Remove these when phylink supports FEC and lane config */
37 	u8 fec;
38 	u8 link_mode;
39 
40 	/* Cached top bits of the HW time counter for 40b -> 64b conversion */
41 	u32 time_high;
42 	/* Protect readers of @time_offset, writers take @time_lock. */
43 	struct u64_stats_sync time_seq;
44 	/* Offset in ns between free running NIC PHC and time set via PTP
45 	 * clock callbacks
46 	 */
47 	s64 time_offset;
48 
49 	u16 num_tx_queues;
50 	u16 num_rx_queues;
51 
52 	u8 indir_tbl[FBNIC_RPC_RSS_TBL_COUNT][FBNIC_RPC_RSS_TBL_SIZE];
53 	u32 rss_key[FBNIC_RPC_RSS_KEY_DWORD_LEN];
54 	u32 rss_flow_hash[FBNIC_NUM_HASH_OPT];
55 
56 	/* Storage for stats after ring destruction */
57 	struct fbnic_queue_stats tx_stats;
58 	struct fbnic_queue_stats rx_stats;
59 	u64 link_down_events;
60 
61 	/* Time stampinn filter config */
62 	struct kernel_hwtstamp_config hwtstamp_config;
63 };
64 
65 int __fbnic_open(struct fbnic_net *fbn);
66 void fbnic_up(struct fbnic_net *fbn);
67 void fbnic_down(struct fbnic_net *fbn);
68 void fbnic_down_noidle(struct fbnic_net *fbn);
69 
70 struct net_device *fbnic_netdev_alloc(struct fbnic_dev *fbd);
71 void fbnic_netdev_free(struct fbnic_dev *fbd);
72 int fbnic_netdev_register(struct net_device *netdev);
73 void fbnic_netdev_unregister(struct net_device *netdev);
74 void fbnic_reset_queues(struct fbnic_net *fbn,
75 			unsigned int tx, unsigned int rx);
76 void fbnic_set_ethtool_ops(struct net_device *dev);
77 
78 int fbnic_ptp_setup(struct fbnic_dev *fbd);
79 void fbnic_ptp_destroy(struct fbnic_dev *fbd);
80 void fbnic_time_init(struct fbnic_net *fbn);
81 int fbnic_time_start(struct fbnic_net *fbn);
82 void fbnic_time_stop(struct fbnic_net *fbn);
83 
84 void __fbnic_set_rx_mode(struct net_device *netdev);
85 void fbnic_clear_rx_mode(struct net_device *netdev);
86 
87 int fbnic_phylink_init(struct net_device *netdev);
88 #endif /* _FBNIC_NETDEV_H_ */
89