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