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_ptp_s;
21 enum aq_rx_filter_type;
22 
23 enum aq_fc_mode {
24 	AQ_NIC_FC_OFF = 0,
25 	AQ_NIC_FC_TX,
26 	AQ_NIC_FC_RX,
27 	AQ_NIC_FC_FULL,
28 };
29 
30 struct aq_fc_info {
31 	enum aq_fc_mode req;
32 	enum aq_fc_mode cur;
33 };
34 
35 struct aq_nic_cfg_s {
36 	const struct aq_hw_caps_s *aq_hw_caps;
37 	u64 features;
38 	u32 rxds;		/* rx ring size, descriptors # */
39 	u32 txds;		/* tx ring size, descriptors # */
40 	u32 vecs;		/* allocated rx/tx vectors */
41 	u32 link_irq_vec;
42 	u32 irq_type;
43 	u32 itr;
44 	u16 rx_itr;
45 	u16 tx_itr;
46 	u32 rxpageorder;
47 	u32 num_rss_queues;
48 	u32 mtu;
49 	struct aq_fc_info fc;
50 	u32 link_speed_msk;
51 	u32 wol;
52 	u8 is_vlan_rx_strip;
53 	u8 is_vlan_tx_insert;
54 	bool is_vlan_force_promisc;
55 	u16 is_mc_list_enabled;
56 	u16 mc_list_count;
57 	bool is_autoneg;
58 	bool is_polling;
59 	bool is_rss;
60 	bool is_lro;
61 	u32 priv_flags;
62 	u8  tcs;
63 	struct aq_rss_parameters aq_rss;
64 	u32 eee_speeds;
65 };
66 
67 #define AQ_NIC_FLAG_STARTED     0x00000004U
68 #define AQ_NIC_FLAG_STOPPING    0x00000008U
69 #define AQ_NIC_FLAG_RESETTING   0x00000010U
70 #define AQ_NIC_FLAG_CLOSING     0x00000020U
71 #define AQ_NIC_PTP_DPATH_UP     0x02000000U
72 #define AQ_NIC_LINK_DOWN        0x04000000U
73 #define AQ_NIC_FLAG_ERR_UNPLUG  0x40000000U
74 #define AQ_NIC_FLAG_ERR_HW      0x80000000U
75 
76 #define AQ_NIC_WOL_MODES        (WAKE_MAGIC |\
77 				 WAKE_PHY)
78 
79 #define AQ_NIC_TCVEC2RING(_NIC_, _TC_, _VEC_) \
80 	((_TC_) * AQ_CFG_TCS_MAX + (_VEC_))
81 
82 struct aq_hw_rx_fl2 {
83 	struct aq_rx_filter_vlan aq_vlans[AQ_VLAN_MAX_FILTERS];
84 };
85 
86 struct aq_hw_rx_fl3l4 {
87 	u8 active_ipv4;
88 	u8 active_ipv6:2;
89 	u8 is_ipv6;
90 	u8 reserved_count;
91 };
92 
93 struct aq_hw_rx_fltrs_s {
94 	struct hlist_head     filter_list;
95 	u16                   active_filters;
96 	struct aq_hw_rx_fl2   fl2;
97 	struct aq_hw_rx_fl3l4 fl3l4;
98 	/*filter ether type */
99 	u8 fet_reserved_count;
100 };
101 
102 struct aq_nic_s {
103 	atomic_t flags;
104 	u32 msg_enable;
105 	struct aq_vec_s *aq_vec[AQ_CFG_VECS_MAX];
106 	struct aq_ring_s *aq_ring_tx[AQ_CFG_VECS_MAX * AQ_CFG_TCS_MAX];
107 	struct aq_hw_s *aq_hw;
108 	struct net_device *ndev;
109 	unsigned int aq_vecs;
110 	unsigned int packet_filter;
111 	unsigned int power_state;
112 	u8 port;
113 	const struct aq_hw_ops *aq_hw_ops;
114 	const struct aq_fw_ops *aq_fw_ops;
115 	struct aq_nic_cfg_s aq_nic_cfg;
116 	struct timer_list service_timer;
117 	struct work_struct service_task;
118 	struct timer_list polling_timer;
119 	struct aq_hw_link_status_s link_status;
120 	struct {
121 		u32 count;
122 		u8 ar[AQ_HW_MULTICAST_ADDRESS_MAX][ETH_ALEN];
123 	} mc_list;
124 	/* Bitmask of currently assigned vlans from linux */
125 	unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
126 
127 	struct pci_dev *pdev;
128 	unsigned int msix_entry_mask;
129 	u32 irqvecs;
130 	/* mutex to serialize FW interface access operations */
131 	struct mutex fwreq_mutex;
132 	/* PTP support */
133 	struct aq_ptp_s *aq_ptp;
134 	struct aq_hw_rx_fltrs_s aq_hw_rx_fltrs;
135 };
136 
137 static inline struct device *aq_nic_get_dev(struct aq_nic_s *self)
138 {
139 	return self->ndev->dev.parent;
140 }
141 
142 void aq_nic_ndev_init(struct aq_nic_s *self);
143 struct aq_nic_s *aq_nic_alloc_hot(struct net_device *ndev);
144 void aq_nic_set_tx_ring(struct aq_nic_s *self, unsigned int idx,
145 			struct aq_ring_s *ring);
146 struct net_device *aq_nic_get_ndev(struct aq_nic_s *self);
147 int aq_nic_init(struct aq_nic_s *self);
148 void aq_nic_cfg_start(struct aq_nic_s *self);
149 int aq_nic_ndev_register(struct aq_nic_s *self);
150 void aq_nic_ndev_free(struct aq_nic_s *self);
151 int aq_nic_start(struct aq_nic_s *self);
152 unsigned int aq_nic_map_skb(struct aq_nic_s *self, struct sk_buff *skb,
153 			    struct aq_ring_s *ring);
154 int aq_nic_xmit(struct aq_nic_s *self, struct sk_buff *skb);
155 int aq_nic_get_regs(struct aq_nic_s *self, struct ethtool_regs *regs, void *p);
156 int aq_nic_get_regs_count(struct aq_nic_s *self);
157 void aq_nic_get_stats(struct aq_nic_s *self, u64 *data);
158 int aq_nic_stop(struct aq_nic_s *self);
159 void aq_nic_deinit(struct aq_nic_s *self, bool link_down);
160 void aq_nic_set_power(struct aq_nic_s *self);
161 void aq_nic_free_hot_resources(struct aq_nic_s *self);
162 void aq_nic_free_vectors(struct aq_nic_s *self);
163 int aq_nic_set_mtu(struct aq_nic_s *self, int new_mtu);
164 int aq_nic_set_mac(struct aq_nic_s *self, struct net_device *ndev);
165 int aq_nic_set_packet_filter(struct aq_nic_s *self, unsigned int flags);
166 int aq_nic_set_multicast_list(struct aq_nic_s *self, struct net_device *ndev);
167 unsigned int aq_nic_get_link_speed(struct aq_nic_s *self);
168 void aq_nic_get_link_ksettings(struct aq_nic_s *self,
169 			       struct ethtool_link_ksettings *cmd);
170 int aq_nic_set_link_ksettings(struct aq_nic_s *self,
171 			      const struct ethtool_link_ksettings *cmd);
172 struct aq_nic_cfg_s *aq_nic_get_cfg(struct aq_nic_s *self);
173 u32 aq_nic_get_fw_version(struct aq_nic_s *self);
174 int aq_nic_set_loopback(struct aq_nic_s *self);
175 int aq_nic_update_interrupt_moderation_settings(struct aq_nic_s *self);
176 void aq_nic_shutdown(struct aq_nic_s *self);
177 u8 aq_nic_reserve_filter(struct aq_nic_s *self, enum aq_rx_filter_type type);
178 void aq_nic_release_filter(struct aq_nic_s *self, enum aq_rx_filter_type type,
179 			   u32 location);
180 #endif /* AQ_NIC_H */
181