• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Atlantic Network Driver
3  *
4  * Copyright (C) 2014-2019 aQuantia Corporation
5  * Copyright (C) 2019-2020 Marvell International Ltd.
6  */
7 
8 /* File aq_nic.h: Declaration of common code for NIC. */
9 
10 #ifndef AQ_NIC_H
11 #define AQ_NIC_H
12 
13 #include <linux/ethtool.h>
14 #include <net/xdp.h>
15 #include <linux/bpf.h>
16 
17 #include "aq_common.h"
18 #include "aq_rss.h"
19 #include "aq_hw.h"
20 
21 struct aq_ring_s;
22 struct aq_hw_ops;
23 struct aq_fw_s;
24 struct aq_vec_s;
25 struct aq_macsec_cfg;
26 struct aq_ptp_s;
27 enum aq_rx_filter_type;
28 
29 enum aq_fc_mode {
30 	AQ_NIC_FC_OFF = 0,
31 	AQ_NIC_FC_TX,
32 	AQ_NIC_FC_RX,
33 	AQ_NIC_FC_FULL,
34 };
35 
36 struct aq_fc_info {
37 	enum aq_fc_mode req;
38 	enum aq_fc_mode cur;
39 };
40 
41 struct aq_nic_cfg_s {
42 	const struct aq_hw_caps_s *aq_hw_caps;
43 	u64 features;
44 	u32 rxds;		/* rx ring size, descriptors # */
45 	u32 txds;		/* tx ring size, descriptors # */
46 	u32 vecs;		/* allocated rx/tx vectors */
47 	u32 link_irq_vec;
48 	u32 irq_type;
49 	u32 itr;
50 	u16 rx_itr;
51 	u16 tx_itr;
52 	u32 rxpageorder;
53 	u32 num_rss_queues;
54 	u32 mtu;
55 	struct aq_fc_info fc;
56 	u32 link_speed_msk;
57 	u32 wol;
58 	u8 is_vlan_rx_strip;
59 	u8 is_vlan_tx_insert;
60 	bool is_vlan_force_promisc;
61 	u16 is_mc_list_enabled;
62 	u16 mc_list_count;
63 	bool is_autoneg;
64 	bool is_polling;
65 	bool is_rss;
66 	bool is_lro;
67 	bool is_qos;
68 	bool is_ptp;
69 	bool is_media_detect;
70 	int downshift_counter;
71 	enum aq_tc_mode tc_mode;
72 	u32 priv_flags;
73 	u8  tcs;
74 	u8 prio_tc_map[8];
75 	u32 tc_max_rate[AQ_CFG_TCS_MAX];
76 	unsigned long tc_min_rate_msk;
77 	u32 tc_min_rate[AQ_CFG_TCS_MAX];
78 	struct aq_rss_parameters aq_rss;
79 	u32 eee_speeds;
80 };
81 
82 #define AQ_NIC_FLAG_STARTED     0x00000004U
83 #define AQ_NIC_FLAG_STOPPING    0x00000008U
84 #define AQ_NIC_FLAG_RESETTING   0x00000010U
85 #define AQ_NIC_FLAG_CLOSING     0x00000020U
86 #define AQ_NIC_PTP_DPATH_UP     0x02000000U
87 #define AQ_NIC_LINK_DOWN        0x04000000U
88 #define AQ_NIC_FLAG_ERR_UNPLUG  0x40000000U
89 #define AQ_NIC_FLAG_ERR_HW      0x80000000U
90 
91 #define AQ_NIC_QUIRK_BAD_PTP    BIT(0)
92 
93 #define AQ_NIC_WOL_MODES        (WAKE_MAGIC |\
94 				 WAKE_PHY)
95 
96 #define AQ_NIC_CFG_RING_PER_TC(_NIC_CFG_) \
97 	(((_NIC_CFG_)->tc_mode == AQ_TC_MODE_4TCS) ? 8 : 4)
98 
99 #define AQ_NIC_CFG_TCVEC2RING(_NIC_CFG_, _TC_, _VEC_) \
100 	((_TC_) * AQ_NIC_CFG_RING_PER_TC(_NIC_CFG_) + (_VEC_))
101 
102 #define AQ_NIC_RING2QMAP(_NIC_, _ID_) \
103 	((_ID_) / AQ_NIC_CFG_RING_PER_TC(&(_NIC_)->aq_nic_cfg) * \
104 		(_NIC_)->aq_vecs + \
105 	((_ID_) % AQ_NIC_CFG_RING_PER_TC(&(_NIC_)->aq_nic_cfg)))
106 
107 struct aq_hw_rx_fl2 {
108 	struct aq_rx_filter_vlan aq_vlans[AQ_VLAN_MAX_FILTERS];
109 };
110 
111 struct aq_hw_rx_fl3l4 {
112 	u8 active_ipv4;
113 	u8 active_ipv6:2;
114 	u8 is_ipv6;
115 	u8 reserved_count;
116 };
117 
118 struct aq_hw_rx_fltrs_s {
119 	struct hlist_head     filter_list;
120 	u16                   active_filters;
121 	struct aq_hw_rx_fl2   fl2;
122 	struct aq_hw_rx_fl3l4 fl3l4;
123 	/* filter ether type */
124 	u8 fet_reserved_count;
125 };
126 
127 struct aq_nic_s {
128 	atomic_t flags;
129 	u32 msg_enable;
130 	struct aq_vec_s *aq_vec[AQ_CFG_VECS_MAX];
131 	struct aq_ring_s *aq_ring_tx[AQ_HW_QUEUES_MAX];
132 	struct aq_hw_s *aq_hw;
133 	struct bpf_prog *xdp_prog;
134 	struct net_device *ndev;
135 	unsigned int aq_vecs;
136 	unsigned int packet_filter;
137 	unsigned int power_state;
138 	u8 port;
139 	const struct aq_hw_ops *aq_hw_ops;
140 	const struct aq_fw_ops *aq_fw_ops;
141 	struct aq_nic_cfg_s aq_nic_cfg;
142 	struct timer_list service_timer;
143 	struct work_struct service_task;
144 	struct timer_list polling_timer;
145 	struct aq_hw_link_status_s link_status;
146 	struct {
147 		u32 count;
148 		u8 ar[AQ_HW_MULTICAST_ADDRESS_MAX][ETH_ALEN];
149 	} mc_list;
150 	/* Bitmask of currently assigned vlans from linux */
151 	unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
152 
153 	struct pci_dev *pdev;
154 	unsigned int msix_entry_mask;
155 	u32 irqvecs;
156 	/* mutex to serialize FW interface access operations */
157 	struct mutex fwreq_mutex;
158 #if IS_ENABLED(CONFIG_MACSEC)
159 	struct aq_macsec_cfg *macsec_cfg;
160 	/* mutex to protect data in macsec_cfg */
161 	struct mutex macsec_mutex;
162 #endif
163 	/* PTP support */
164 	struct aq_ptp_s *aq_ptp;
165 	struct aq_hw_rx_fltrs_s aq_hw_rx_fltrs;
166 };
167 
aq_nic_get_dev(struct aq_nic_s * self)168 static inline struct device *aq_nic_get_dev(struct aq_nic_s *self)
169 {
170 	return self->ndev->dev.parent;
171 }
172 
173 void aq_nic_ndev_init(struct aq_nic_s *self);
174 struct aq_nic_s *aq_nic_alloc_hot(struct net_device *ndev);
175 void aq_nic_set_tx_ring(struct aq_nic_s *self, unsigned int idx,
176 			struct aq_ring_s *ring);
177 struct net_device *aq_nic_get_ndev(struct aq_nic_s *self);
178 int aq_nic_init(struct aq_nic_s *self);
179 void aq_nic_cfg_start(struct aq_nic_s *self);
180 int aq_nic_ndev_register(struct aq_nic_s *self);
181 void aq_nic_ndev_free(struct aq_nic_s *self);
182 int aq_nic_start(struct aq_nic_s *self);
183 unsigned int aq_nic_map_skb(struct aq_nic_s *self, struct sk_buff *skb,
184 			    struct aq_ring_s *ring);
185 int aq_nic_xmit_xdpf(struct aq_nic_s *aq_nic, struct aq_ring_s *tx_ring,
186 		     struct xdp_frame *xdpf);
187 int aq_nic_xmit(struct aq_nic_s *self, struct sk_buff *skb);
188 int aq_nic_get_regs(struct aq_nic_s *self, struct ethtool_regs *regs, void *p);
189 int aq_nic_get_regs_count(struct aq_nic_s *self);
190 u64 *aq_nic_get_stats(struct aq_nic_s *self, u64 *data);
191 int aq_nic_stop(struct aq_nic_s *self);
192 void aq_nic_deinit(struct aq_nic_s *self, bool link_down);
193 void aq_nic_set_power(struct aq_nic_s *self);
194 void aq_nic_free_hot_resources(struct aq_nic_s *self);
195 void aq_nic_free_vectors(struct aq_nic_s *self);
196 int aq_nic_realloc_vectors(struct aq_nic_s *self);
197 int aq_nic_set_mtu(struct aq_nic_s *self, int new_mtu);
198 int aq_nic_set_mac(struct aq_nic_s *self, struct net_device *ndev);
199 int aq_nic_set_packet_filter(struct aq_nic_s *self, unsigned int flags);
200 int aq_nic_set_multicast_list(struct aq_nic_s *self, struct net_device *ndev);
201 unsigned int aq_nic_get_link_speed(struct aq_nic_s *self);
202 void aq_nic_get_link_ksettings(struct aq_nic_s *self,
203 			       struct ethtool_link_ksettings *cmd);
204 int aq_nic_set_link_ksettings(struct aq_nic_s *self,
205 			      const struct ethtool_link_ksettings *cmd);
206 struct aq_nic_cfg_s *aq_nic_get_cfg(struct aq_nic_s *self);
207 u32 aq_nic_get_fw_version(struct aq_nic_s *self);
208 int aq_nic_set_loopback(struct aq_nic_s *self);
209 int aq_nic_set_downshift(struct aq_nic_s *self, int val);
210 int aq_nic_set_media_detect(struct aq_nic_s *self, int val);
211 int aq_nic_update_interrupt_moderation_settings(struct aq_nic_s *self);
212 void aq_nic_shutdown(struct aq_nic_s *self);
213 u8 aq_nic_reserve_filter(struct aq_nic_s *self, enum aq_rx_filter_type type);
214 void aq_nic_release_filter(struct aq_nic_s *self, enum aq_rx_filter_type type,
215 			   u32 location);
216 int aq_nic_setup_tc_mqprio(struct aq_nic_s *self, u32 tcs, u8 *prio_tc_map);
217 int aq_nic_setup_tc_max_rate(struct aq_nic_s *self, const unsigned int tc,
218 			     const u32 max_rate);
219 int aq_nic_setup_tc_min_rate(struct aq_nic_s *self, const unsigned int tc,
220 			     const u32 min_rate);
221 #endif /* AQ_NIC_H */
222