xref: /linux/drivers/net/ethernet/aquantia/atlantic/aq_nic.h (revision b9e989262a3e2e9b795361a7e7978d64851eb98f)
175a6faf6SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
297bde5c4SDavid VomLehn /*
397bde5c4SDavid VomLehn  * aQuantia Corporation Network Driver
41a64f8dcSEgor Pomozov  * Copyright (C) 2014-2019 aQuantia Corporation. All rights reserved
597bde5c4SDavid VomLehn  */
697bde5c4SDavid VomLehn 
797bde5c4SDavid VomLehn /* File aq_nic.h: Declaration of common code for NIC. */
897bde5c4SDavid VomLehn 
997bde5c4SDavid VomLehn #ifndef AQ_NIC_H
1097bde5c4SDavid VomLehn #define AQ_NIC_H
1197bde5c4SDavid VomLehn 
1297bde5c4SDavid VomLehn #include "aq_common.h"
1397bde5c4SDavid VomLehn #include "aq_rss.h"
141a713f87SIgor Russkikh #include "aq_hw.h"
1597bde5c4SDavid VomLehn 
1697bde5c4SDavid VomLehn struct aq_ring_s;
1797bde5c4SDavid VomLehn struct aq_hw_ops;
18db550615SIgor Russkikh struct aq_fw_s;
19db550615SIgor Russkikh struct aq_vec_s;
2062c1c2e6SDmitry Bogdanov struct aq_macsec_cfg;
211a64f8dcSEgor Pomozov struct aq_ptp_s;
225a1bf9efSDmitry Bezrukov enum aq_rx_filter_type;
2397bde5c4SDavid VomLehn 
248009bb19SNikita Danilov enum aq_fc_mode {
258009bb19SNikita Danilov 	AQ_NIC_FC_OFF = 0,
268009bb19SNikita Danilov 	AQ_NIC_FC_TX,
278009bb19SNikita Danilov 	AQ_NIC_FC_RX,
288009bb19SNikita Danilov 	AQ_NIC_FC_FULL,
298009bb19SNikita Danilov };
308009bb19SNikita Danilov 
318009bb19SNikita Danilov struct aq_fc_info {
328009bb19SNikita Danilov 	enum aq_fc_mode req;
338009bb19SNikita Danilov 	enum aq_fc_mode cur;
348009bb19SNikita Danilov };
358009bb19SNikita Danilov 
3697bde5c4SDavid VomLehn struct aq_nic_cfg_s {
374cbc9f92SIgor Russkikh 	const struct aq_hw_caps_s *aq_hw_caps;
38bbb67a44SDmitry Bogdanov 	u64 features;
3997bde5c4SDavid VomLehn 	u32 rxds;		/* rx ring size, descriptors # */
4097bde5c4SDavid VomLehn 	u32 txds;		/* tx ring size, descriptors # */
413dd3e236SIgor Russkikh 	u32 vecs;		/* allocated rx/tx vectors */
423dd3e236SIgor Russkikh 	u32 link_irq_vec;
4397bde5c4SDavid VomLehn 	u32 irq_type;
4497bde5c4SDavid VomLehn 	u32 itr;
45b82ee71aSIgor Russkikh 	u16 rx_itr;
46b82ee71aSIgor Russkikh 	u16 tx_itr;
4746f4c29dSIgor Russkikh 	u32 rxpageorder;
4897bde5c4SDavid VomLehn 	u32 num_rss_queues;
4997bde5c4SDavid VomLehn 	u32 mtu;
508009bb19SNikita Danilov 	struct aq_fc_info fc;
5197bde5c4SDavid VomLehn 	u32 link_speed_msk;
520e1a0ddeSYana Esina 	u32 wol;
53d3ed7c5cSIgor Russkikh 	u8 is_vlan_rx_strip;
54d3ed7c5cSIgor Russkikh 	u8 is_vlan_tx_insert;
5548dd73d0SDmitry Bogdanov 	bool is_vlan_force_promisc;
5697bde5c4SDavid VomLehn 	u16 is_mc_list_enabled;
5797bde5c4SDavid VomLehn 	u16 mc_list_count;
5897bde5c4SDavid VomLehn 	bool is_autoneg;
5997bde5c4SDavid VomLehn 	bool is_polling;
6097bde5c4SDavid VomLehn 	bool is_rss;
6197bde5c4SDavid VomLehn 	bool is_lro;
62a83fe6b6SDmitry Bezrukov 	bool is_qos;
630aa7bc3eSDmitry Bezrukov 	bool is_ptp;
640aa7bc3eSDmitry Bezrukov 	enum aq_tc_mode tc_mode;
65ea4b4d7fSIgor Russkikh 	u32 priv_flags;
6697bde5c4SDavid VomLehn 	u8  tcs;
67a83fe6b6SDmitry Bezrukov 	u8 prio_tc_map[8];
6897bde5c4SDavid VomLehn 	struct aq_rss_parameters aq_rss;
6992ab6407SYana Esina 	u32 eee_speeds;
7097bde5c4SDavid VomLehn };
7197bde5c4SDavid VomLehn 
7297bde5c4SDavid VomLehn #define AQ_NIC_FLAG_STARTED     0x00000004U
7397bde5c4SDavid VomLehn #define AQ_NIC_FLAG_STOPPING    0x00000008U
7497bde5c4SDavid VomLehn #define AQ_NIC_FLAG_RESETTING   0x00000010U
7597bde5c4SDavid VomLehn #define AQ_NIC_FLAG_CLOSING     0x00000020U
7604a18399SEgor Pomozov #define AQ_NIC_PTP_DPATH_UP     0x02000000U
7797bde5c4SDavid VomLehn #define AQ_NIC_LINK_DOWN        0x04000000U
7897bde5c4SDavid VomLehn #define AQ_NIC_FLAG_ERR_UNPLUG  0x40000000U
7997bde5c4SDavid VomLehn #define AQ_NIC_FLAG_ERR_HW      0x80000000U
8097bde5c4SDavid VomLehn 
81837c6378SNikita Danilov #define AQ_NIC_WOL_MODES        (WAKE_MAGIC |\
82837c6378SNikita Danilov 				 WAKE_PHY)
830e1a0ddeSYana Esina 
84*b9e98926SMark Starovoytov #define AQ_NIC_CFG_RING_PER_TC(_NIC_CFG_) \
85*b9e98926SMark Starovoytov 	(((_NIC_CFG_)->tc_mode == AQ_TC_MODE_4TCS) ? 8 : 4)
86a83fe6b6SDmitry Bezrukov 
87*b9e98926SMark Starovoytov #define AQ_NIC_CFG_TCVEC2RING(_NIC_CFG_, _TC_, _VEC_) \
88*b9e98926SMark Starovoytov 	((_TC_) * AQ_NIC_CFG_RING_PER_TC(_NIC_CFG_) + (_VEC_))
89a83fe6b6SDmitry Bezrukov 
90a83fe6b6SDmitry Bezrukov #define AQ_NIC_RING2QMAP(_NIC_, _ID_) \
91*b9e98926SMark Starovoytov 	((_ID_) / AQ_NIC_CFG_RING_PER_TC(&(_NIC_)->aq_nic_cfg) * \
92*b9e98926SMark Starovoytov 		(_NIC_)->aq_vecs + \
93*b9e98926SMark Starovoytov 	((_ID_) % AQ_NIC_CFG_RING_PER_TC(&(_NIC_)->aq_nic_cfg)))
9497bde5c4SDavid VomLehn 
9554bcb3d1SDmitry Bogdanov struct aq_hw_rx_fl2 {
9654bcb3d1SDmitry Bogdanov 	struct aq_rx_filter_vlan aq_vlans[AQ_VLAN_MAX_FILTERS];
9754bcb3d1SDmitry Bogdanov };
9854bcb3d1SDmitry Bogdanov 
99a6ed6f22SDmitry Bogdanov struct aq_hw_rx_fl3l4 {
100a6ed6f22SDmitry Bogdanov 	u8 active_ipv4;
101a6ed6f22SDmitry Bogdanov 	u8 active_ipv6:2;
102a6ed6f22SDmitry Bogdanov 	u8 is_ipv6;
1035a1bf9efSDmitry Bezrukov 	u8 reserved_count;
104a6ed6f22SDmitry Bogdanov };
105a6ed6f22SDmitry Bogdanov 
1068d0bcb01SDmitry Bogdanov struct aq_hw_rx_fltrs_s {
1078d0bcb01SDmitry Bogdanov 	struct hlist_head     filter_list;
1088d0bcb01SDmitry Bogdanov 	u16                   active_filters;
10954bcb3d1SDmitry Bogdanov 	struct aq_hw_rx_fl2   fl2;
110a6ed6f22SDmitry Bogdanov 	struct aq_hw_rx_fl3l4 fl3l4;
1115a1bf9efSDmitry Bezrukov 	/*filter ether type */
1125a1bf9efSDmitry Bezrukov 	u8 fet_reserved_count;
1138d0bcb01SDmitry Bogdanov };
1148d0bcb01SDmitry Bogdanov 
115db550615SIgor Russkikh struct aq_nic_s {
116db550615SIgor Russkikh 	atomic_t flags;
11758128fa0SNikita Danilov 	u32 msg_enable;
118db550615SIgor Russkikh 	struct aq_vec_s *aq_vec[AQ_CFG_VECS_MAX];
119a83fe6b6SDmitry Bezrukov 	struct aq_ring_s *aq_ring_tx[AQ_HW_QUEUES_MAX];
120db550615SIgor Russkikh 	struct aq_hw_s *aq_hw;
121db550615SIgor Russkikh 	struct net_device *ndev;
122db550615SIgor Russkikh 	unsigned int aq_vecs;
123db550615SIgor Russkikh 	unsigned int packet_filter;
124db550615SIgor Russkikh 	unsigned int power_state;
125db550615SIgor Russkikh 	u8 port;
1268fcb98f4SIgor Russkikh 	const struct aq_hw_ops *aq_hw_ops;
1270c58c35fSIgor Russkikh 	const struct aq_fw_ops *aq_fw_ops;
128db550615SIgor Russkikh 	struct aq_nic_cfg_s aq_nic_cfg;
129db550615SIgor Russkikh 	struct timer_list service_timer;
13049544935SIgor Russkikh 	struct work_struct service_task;
131db550615SIgor Russkikh 	struct timer_list polling_timer;
132db550615SIgor Russkikh 	struct aq_hw_link_status_s link_status;
133db550615SIgor Russkikh 	struct {
134db550615SIgor Russkikh 		u32 count;
13594b3b542SIgor Russkikh 		u8 ar[AQ_HW_MULTICAST_ADDRESS_MAX][ETH_ALEN];
136db550615SIgor Russkikh 	} mc_list;
1377975d2afSDmitry Bogdanov 	/* Bitmask of currently assigned vlans from linux */
1387975d2afSDmitry Bogdanov 	unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
139db550615SIgor Russkikh 
140db550615SIgor Russkikh 	struct pci_dev *pdev;
141db550615SIgor Russkikh 	unsigned int msix_entry_mask;
142a09bd81bSIgor Russkikh 	u32 irqvecs;
143f5dce08aSNikita Danilov 	/* mutex to serialize FW interface access operations */
144f5dce08aSNikita Danilov 	struct mutex fwreq_mutex;
14562c1c2e6SDmitry Bogdanov #if IS_ENABLED(CONFIG_MACSEC)
14662c1c2e6SDmitry Bogdanov 	struct aq_macsec_cfg *macsec_cfg;
14762c1c2e6SDmitry Bogdanov #endif
1481a64f8dcSEgor Pomozov 	/* PTP support */
1491a64f8dcSEgor Pomozov 	struct aq_ptp_s *aq_ptp;
1508d0bcb01SDmitry Bogdanov 	struct aq_hw_rx_fltrs_s aq_hw_rx_fltrs;
151db550615SIgor Russkikh };
152db550615SIgor Russkikh 
153db550615SIgor Russkikh static inline struct device *aq_nic_get_dev(struct aq_nic_s *self)
154db550615SIgor Russkikh {
155db550615SIgor Russkikh 	return self->ndev->dev.parent;
156db550615SIgor Russkikh }
157db550615SIgor Russkikh 
15823ee07adSIgor Russkikh void aq_nic_ndev_init(struct aq_nic_s *self);
15997bde5c4SDavid VomLehn struct aq_nic_s *aq_nic_alloc_hot(struct net_device *ndev);
16097bde5c4SDavid VomLehn void aq_nic_set_tx_ring(struct aq_nic_s *self, unsigned int idx,
16197bde5c4SDavid VomLehn 			struct aq_ring_s *ring);
16297bde5c4SDavid VomLehn struct net_device *aq_nic_get_ndev(struct aq_nic_s *self);
16397bde5c4SDavid VomLehn int aq_nic_init(struct aq_nic_s *self);
16423ee07adSIgor Russkikh void aq_nic_cfg_start(struct aq_nic_s *self);
16597bde5c4SDavid VomLehn int aq_nic_ndev_register(struct aq_nic_s *self);
16697bde5c4SDavid VomLehn void aq_nic_ndev_free(struct aq_nic_s *self);
16797bde5c4SDavid VomLehn int aq_nic_start(struct aq_nic_s *self);
16804a18399SEgor Pomozov unsigned int aq_nic_map_skb(struct aq_nic_s *self, struct sk_buff *skb,
16904a18399SEgor Pomozov 			    struct aq_ring_s *ring);
17097bde5c4SDavid VomLehn int aq_nic_xmit(struct aq_nic_s *self, struct sk_buff *skb);
17197bde5c4SDavid VomLehn int aq_nic_get_regs(struct aq_nic_s *self, struct ethtool_regs *regs, void *p);
17297bde5c4SDavid VomLehn int aq_nic_get_regs_count(struct aq_nic_s *self);
173aec0f1aaSDmitry Bogdanov u64 *aq_nic_get_stats(struct aq_nic_s *self, u64 *data);
17497bde5c4SDavid VomLehn int aq_nic_stop(struct aq_nic_s *self);
175837c6378SNikita Danilov void aq_nic_deinit(struct aq_nic_s *self, bool link_down);
176837c6378SNikita Danilov void aq_nic_set_power(struct aq_nic_s *self);
17797bde5c4SDavid VomLehn void aq_nic_free_hot_resources(struct aq_nic_s *self);
17823ee07adSIgor Russkikh void aq_nic_free_vectors(struct aq_nic_s *self);
17997bde5c4SDavid VomLehn int aq_nic_set_mtu(struct aq_nic_s *self, int new_mtu);
18097bde5c4SDavid VomLehn int aq_nic_set_mac(struct aq_nic_s *self, struct net_device *ndev);
18197bde5c4SDavid VomLehn int aq_nic_set_packet_filter(struct aq_nic_s *self, unsigned int flags);
18297bde5c4SDavid VomLehn int aq_nic_set_multicast_list(struct aq_nic_s *self, struct net_device *ndev);
18397bde5c4SDavid VomLehn unsigned int aq_nic_get_link_speed(struct aq_nic_s *self);
184f8244ab5SPhilippe Reynes void aq_nic_get_link_ksettings(struct aq_nic_s *self,
185f8244ab5SPhilippe Reynes 			       struct ethtool_link_ksettings *cmd);
186f8244ab5SPhilippe Reynes int aq_nic_set_link_ksettings(struct aq_nic_s *self,
187f8244ab5SPhilippe Reynes 			      const struct ethtool_link_ksettings *cmd);
18897bde5c4SDavid VomLehn struct aq_nic_cfg_s *aq_nic_get_cfg(struct aq_nic_s *self);
18997bde5c4SDavid VomLehn u32 aq_nic_get_fw_version(struct aq_nic_s *self);
190ea4b4d7fSIgor Russkikh int aq_nic_set_loopback(struct aq_nic_s *self);
191b82ee71aSIgor Russkikh int aq_nic_update_interrupt_moderation_settings(struct aq_nic_s *self);
19290869ddfSIgor Russkikh void aq_nic_shutdown(struct aq_nic_s *self);
1935a1bf9efSDmitry Bezrukov u8 aq_nic_reserve_filter(struct aq_nic_s *self, enum aq_rx_filter_type type);
1945a1bf9efSDmitry Bezrukov void aq_nic_release_filter(struct aq_nic_s *self, enum aq_rx_filter_type type,
1955a1bf9efSDmitry Bezrukov 			   u32 location);
196a83fe6b6SDmitry Bezrukov int aq_nic_setup_tc_mqprio(struct aq_nic_s *self, u32 tcs, u8 *prio_tc_map);
19797bde5c4SDavid VomLehn #endif /* AQ_NIC_H */
198