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 	u32 priv_flags;
63 	u8  tcs;
64 	struct aq_rss_parameters aq_rss;
65 	u32 eee_speeds;
66 };
67 
68 #define AQ_NIC_FLAG_STARTED     0x00000004U
69 #define AQ_NIC_FLAG_STOPPING    0x00000008U
70 #define AQ_NIC_FLAG_RESETTING   0x00000010U
71 #define AQ_NIC_FLAG_CLOSING     0x00000020U
72 #define AQ_NIC_PTP_DPATH_UP     0x02000000U
73 #define AQ_NIC_LINK_DOWN        0x04000000U
74 #define AQ_NIC_FLAG_ERR_UNPLUG  0x40000000U
75 #define AQ_NIC_FLAG_ERR_HW      0x80000000U
76 
77 #define AQ_NIC_WOL_MODES        (WAKE_MAGIC |\
78 				 WAKE_PHY)
79 
80 #define AQ_NIC_TCVEC2RING(_NIC_, _TC_, _VEC_) \
81 	((_TC_) * AQ_CFG_TCS_MAX + (_VEC_))
82 
83 struct aq_hw_rx_fl2 {
84 	struct aq_rx_filter_vlan aq_vlans[AQ_VLAN_MAX_FILTERS];
85 };
86 
87 struct aq_hw_rx_fl3l4 {
88 	u8 active_ipv4;
89 	u8 active_ipv6:2;
90 	u8 is_ipv6;
91 	u8 reserved_count;
92 };
93 
94 struct aq_hw_rx_fltrs_s {
95 	struct hlist_head     filter_list;
96 	u16                   active_filters;
97 	struct aq_hw_rx_fl2   fl2;
98 	struct aq_hw_rx_fl3l4 fl3l4;
99 	/*filter ether type */
100 	u8 fet_reserved_count;
101 };
102 
103 struct aq_nic_s {
104 	atomic_t flags;
105 	u32 msg_enable;
106 	struct aq_vec_s *aq_vec[AQ_CFG_VECS_MAX];
107 	struct aq_ring_s *aq_ring_tx[AQ_CFG_VECS_MAX * AQ_CFG_TCS_MAX];
108 	struct aq_hw_s *aq_hw;
109 	struct net_device *ndev;
110 	unsigned int aq_vecs;
111 	unsigned int packet_filter;
112 	unsigned int power_state;
113 	u8 port;
114 	const struct aq_hw_ops *aq_hw_ops;
115 	const struct aq_fw_ops *aq_fw_ops;
116 	struct aq_nic_cfg_s aq_nic_cfg;
117 	struct timer_list service_timer;
118 	struct work_struct service_task;
119 	struct timer_list polling_timer;
120 	struct aq_hw_link_status_s link_status;
121 	struct {
122 		u32 count;
123 		u8 ar[AQ_HW_MULTICAST_ADDRESS_MAX][ETH_ALEN];
124 	} mc_list;
125 	/* Bitmask of currently assigned vlans from linux */
126 	unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
127 
128 	struct pci_dev *pdev;
129 	unsigned int msix_entry_mask;
130 	u32 irqvecs;
131 	/* mutex to serialize FW interface access operations */
132 	struct mutex fwreq_mutex;
133 #if IS_ENABLED(CONFIG_MACSEC)
134 	struct aq_macsec_cfg *macsec_cfg;
135 #endif
136 	/* PTP support */
137 	struct aq_ptp_s *aq_ptp;
138 	struct aq_hw_rx_fltrs_s aq_hw_rx_fltrs;
139 };
140 
141 static inline struct device *aq_nic_get_dev(struct aq_nic_s *self)
142 {
143 	return self->ndev->dev.parent;
144 }
145 
146 void aq_nic_ndev_init(struct aq_nic_s *self);
147 struct aq_nic_s *aq_nic_alloc_hot(struct net_device *ndev);
148 void aq_nic_set_tx_ring(struct aq_nic_s *self, unsigned int idx,
149 			struct aq_ring_s *ring);
150 struct net_device *aq_nic_get_ndev(struct aq_nic_s *self);
151 int aq_nic_init(struct aq_nic_s *self);
152 void aq_nic_cfg_start(struct aq_nic_s *self);
153 int aq_nic_ndev_register(struct aq_nic_s *self);
154 void aq_nic_ndev_free(struct aq_nic_s *self);
155 int aq_nic_start(struct aq_nic_s *self);
156 unsigned int aq_nic_map_skb(struct aq_nic_s *self, struct sk_buff *skb,
157 			    struct aq_ring_s *ring);
158 int aq_nic_xmit(struct aq_nic_s *self, struct sk_buff *skb);
159 int aq_nic_get_regs(struct aq_nic_s *self, struct ethtool_regs *regs, void *p);
160 int aq_nic_get_regs_count(struct aq_nic_s *self);
161 u64 *aq_nic_get_stats(struct aq_nic_s *self, u64 *data);
162 int aq_nic_stop(struct aq_nic_s *self);
163 void aq_nic_deinit(struct aq_nic_s *self, bool link_down);
164 void aq_nic_set_power(struct aq_nic_s *self);
165 void aq_nic_free_hot_resources(struct aq_nic_s *self);
166 void aq_nic_free_vectors(struct aq_nic_s *self);
167 int aq_nic_set_mtu(struct aq_nic_s *self, int new_mtu);
168 int aq_nic_set_mac(struct aq_nic_s *self, struct net_device *ndev);
169 int aq_nic_set_packet_filter(struct aq_nic_s *self, unsigned int flags);
170 int aq_nic_set_multicast_list(struct aq_nic_s *self, struct net_device *ndev);
171 unsigned int aq_nic_get_link_speed(struct aq_nic_s *self);
172 void aq_nic_get_link_ksettings(struct aq_nic_s *self,
173 			       struct ethtool_link_ksettings *cmd);
174 int aq_nic_set_link_ksettings(struct aq_nic_s *self,
175 			      const struct ethtool_link_ksettings *cmd);
176 struct aq_nic_cfg_s *aq_nic_get_cfg(struct aq_nic_s *self);
177 u32 aq_nic_get_fw_version(struct aq_nic_s *self);
178 int aq_nic_set_loopback(struct aq_nic_s *self);
179 int aq_nic_update_interrupt_moderation_settings(struct aq_nic_s *self);
180 void aq_nic_shutdown(struct aq_nic_s *self);
181 u8 aq_nic_reserve_filter(struct aq_nic_s *self, enum aq_rx_filter_type type);
182 void aq_nic_release_filter(struct aq_nic_s *self, enum aq_rx_filter_type type,
183 			   u32 location);
184 #endif /* AQ_NIC_H */
185