]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/ixl/iavf.h
ixl(4): Fix VLAN HW filtering
[FreeBSD/FreeBSD.git] / sys / dev / ixl / iavf.h
1 /******************************************************************************
2
3   Copyright (c) 2013-2018, Intel Corporation
4   All rights reserved.
5   
6   Redistribution and use in source and binary forms, with or without 
7   modification, are permitted provided that the following conditions are met:
8   
9    1. Redistributions of source code must retain the above copyright notice, 
10       this list of conditions and the following disclaimer.
11   
12    2. Redistributions in binary form must reproduce the above copyright 
13       notice, this list of conditions and the following disclaimer in the 
14       documentation and/or other materials provided with the distribution.
15   
16    3. Neither the name of the Intel Corporation nor the names of its 
17       contributors may be used to endorse or promote products derived from 
18       this software without specific prior written permission.
19   
20   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
22   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
23   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
24   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
25   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
26   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
27   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
28   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
29   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   POSSIBILITY OF SUCH DAMAGE.
31
32 ******************************************************************************/
33 /*$FreeBSD$*/
34
35
36 #ifndef _IAVF_H_
37 #define _IAVF_H_
38
39 #include "ixl.h"
40
41 #define IAVF_AQ_MAX_ERR         200
42 #define IAVF_MAX_FILTERS        128
43 #define IAVF_MAX_QUEUES         16
44 #define IAVF_AQ_TIMEOUT         (1 * hz)
45
46 /* MacVlan Flags */
47 #define IAVF_FILTER_USED        (u16)(1 << 0)
48 #define IAVF_FILTER_VLAN        (u16)(1 << 1)
49 #define IAVF_FILTER_ADD         (u16)(1 << 2)
50 #define IAVF_FILTER_DEL         (u16)(1 << 3)
51 #define IAVF_FILTER_MC          (u16)(1 << 4)
52
53 #define IAVF_FLAG_AQ_ENABLE_QUEUES            (u32)(1 << 0)
54 #define IAVF_FLAG_AQ_DISABLE_QUEUES           (u32)(1 << 1)
55 #define IAVF_FLAG_AQ_ADD_MAC_FILTER           (u32)(1 << 2)
56 #define IAVF_FLAG_AQ_ADD_VLAN_FILTER          (u32)(1 << 3)
57 #define IAVF_FLAG_AQ_DEL_MAC_FILTER           (u32)(1 << 4)
58 #define IAVF_FLAG_AQ_DEL_VLAN_FILTER          (u32)(1 << 5)
59 #define IAVF_FLAG_AQ_CONFIGURE_QUEUES         (u32)(1 << 6)
60 #define IAVF_FLAG_AQ_MAP_VECTORS              (u32)(1 << 7)
61 #define IAVF_FLAG_AQ_HANDLE_RESET             (u32)(1 << 8)
62 #define IAVF_FLAG_AQ_CONFIGURE_PROMISC        (u32)(1 << 9)
63 #define IAVF_FLAG_AQ_GET_STATS                (u32)(1 << 10)
64 #define IAVF_FLAG_AQ_CONFIG_RSS_KEY           (u32)(1 << 11)
65 #define IAVF_FLAG_AQ_SET_RSS_HENA             (u32)(1 << 12)
66 #define IAVF_FLAG_AQ_GET_RSS_HENA_CAPS        (u32)(1 << 13)
67 #define IAVF_FLAG_AQ_CONFIG_RSS_LUT           (u32)(1 << 14)
68
69 /* printf %b flag args */
70 #define IAVF_FLAGS \
71     "\20\1ENABLE_QUEUES\2DISABLE_QUEUES\3ADD_MAC_FILTER" \
72     "\4ADD_VLAN_FILTER\5DEL_MAC_FILTER\6DEL_VLAN_FILTER" \
73     "\7CONFIGURE_QUEUES\10MAP_VECTORS\11HANDLE_RESET" \
74     "\12CONFIGURE_PROMISC\13GET_STATS\14CONFIG_RSS_KEY" \
75     "\15SET_RSS_HENA\16GET_RSS_HENA_CAPS\17CONFIG_RSS_LUT"
76 #define IAVF_PRINTF_VF_OFFLOAD_FLAGS \
77     "\20\1L2" \
78     "\2IWARP" \
79     "\3RSVD" \
80     "\4RSS_AQ" \
81     "\5RSS_REG" \
82     "\6WB_ON_ITR" \
83     "\7REQ_QUEUES" \
84     "\21VLAN" \
85     "\22RX_POLLING" \
86     "\23RSS_PCTYPE_V2" \
87     "\24RSS_PF" \
88     "\25ENCAP" \
89     "\26ENCAP_CSUM" \
90     "\27RX_ENCAP_CSUM"
91
92 MALLOC_DECLARE(M_IAVF);
93
94 /* Driver state */
95 enum iavf_state_t {
96         IAVF_RESET_REQUIRED,
97         IAVF_RESET_PENDING,
98         IAVF_INIT_READY,
99         IAVF_RUNNING,
100 };
101
102 /* Structs */
103
104 struct iavf_mac_filter {
105         SLIST_ENTRY(iavf_mac_filter)  next;
106         u8      macaddr[ETHER_ADDR_LEN];
107         u16     flags;
108 };
109 SLIST_HEAD(mac_list, iavf_mac_filter);
110
111 struct iavf_vlan_filter {
112         SLIST_ENTRY(iavf_vlan_filter)  next;
113         u16     vlan;
114         u16     flags;
115 };
116 SLIST_HEAD(vlan_list, iavf_vlan_filter);
117
118 /* Software controller structure */
119 struct iavf_sc {
120         struct ixl_vsi          vsi;
121
122         struct i40e_hw          hw;
123         struct i40e_osdep       osdep;
124         device_t                dev;
125
126         struct resource         *pci_mem;
127
128         enum iavf_state_t       init_state;
129
130         struct ifmedia          media;
131         struct virtchnl_version_info    version;
132         enum ixl_dbg_mask       dbg_mask;
133         u16                     promisc_flags;
134
135         bool                            link_up;
136         enum virtchnl_link_speed        link_speed;
137
138         /* Tunable settings */
139         int                     tx_itr;
140         int                     rx_itr;
141         int                     dynamic_tx_itr;
142         int                     dynamic_rx_itr;
143
144         /* Filter lists */
145         struct mac_list         *mac_filters;
146         struct vlan_list        *vlan_filters;
147
148         /* Virtual comm channel */
149         struct virtchnl_vf_resource *vf_res;
150         struct virtchnl_vsi_resource *vsi_res;
151
152         /* Misc stats maintained by the driver */
153         u64                     admin_irq;
154
155         /* Buffer used for reading AQ responses */
156         u8                      aq_buffer[IXL_AQ_BUF_SZ];
157
158         /* State flag used in init/stop */
159         u32                     queues_enabled;
160         u8                      enable_queues_chan;
161         u8                      disable_queues_chan;
162 };
163
164 /*
165 ** This checks for a zero mac addr, something that will be likely
166 ** unless the Admin on the Host has created one.
167 */
168 static inline bool
169 iavf_check_ether_addr(u8 *addr)
170 {
171         bool status = TRUE;
172
173         if ((addr[0] == 0 && addr[1]== 0 && addr[2] == 0 &&
174             addr[3] == 0 && addr[4]== 0 && addr[5] == 0))
175                 status = FALSE;
176         return (status);
177 }
178
179 /* Debug printing */
180 #define iavf_dbg(sc, m, s, ...)         ixl_debug_core(sc->dev, sc->dbg_mask, m, s, ##__VA_ARGS__)
181 #define iavf_dbg_init(sc, s, ...)       ixl_debug_core(sc->dev, sc->dbg_mask, IAVF_DBG_INIT, s, ##__VA_ARGS__)
182 #define iavf_dbg_info(sc, s, ...)       ixl_debug_core(sc->dev, sc->dbg_mask, IAVF_DBG_INFO, s, ##__VA_ARGS__)
183 #define iavf_dbg_vc(sc, s, ...)         ixl_debug_core(sc->dev, sc->dbg_mask, IAVF_DBG_VC, s, ##__VA_ARGS__)
184 #define iavf_dbg_filter(sc, s, ...)     ixl_debug_core(sc->dev, sc->dbg_mask, IAVF_DBG_FILTER, s, ##__VA_ARGS__)
185
186 /*
187 ** VF Common function prototypes
188 */
189 void    iavf_if_init(if_ctx_t ctx);
190
191 int     iavf_send_api_ver(struct iavf_sc *);
192 int     iavf_verify_api_ver(struct iavf_sc *);
193 int     iavf_send_vf_config_msg(struct iavf_sc *);
194 int     iavf_get_vf_config(struct iavf_sc *);
195 void    iavf_init(void *);
196 int     iavf_reinit_locked(struct iavf_sc *);
197 int     iavf_configure_queues(struct iavf_sc *);
198 int     iavf_enable_queues(struct iavf_sc *);
199 int     iavf_disable_queues(struct iavf_sc *);
200 int     iavf_map_queues(struct iavf_sc *);
201 void    iavf_enable_intr(struct ixl_vsi *);
202 void    iavf_disable_intr(struct ixl_vsi *);
203 int     iavf_add_ether_filters(struct iavf_sc *);
204 int     iavf_del_ether_filters(struct iavf_sc *);
205 int     iavf_request_stats(struct iavf_sc *);
206 int     iavf_request_reset(struct iavf_sc *);
207 void    iavf_vc_completion(struct iavf_sc *,
208         enum virtchnl_ops, enum virtchnl_status_code,
209         u8 *, u16);
210 int     iavf_add_ether_filter(struct iavf_sc *);
211 int     iavf_add_vlans(struct iavf_sc *);
212 int     iavf_del_vlans(struct iavf_sc *);
213 void    iavf_update_stats_counters(struct iavf_sc *,
214                     struct i40e_eth_stats *);
215 void    iavf_update_link_status(struct iavf_sc *);
216 int     iavf_get_default_rss_key(u32 *, bool);
217 int     iavf_config_rss_key(struct iavf_sc *);
218 int     iavf_set_rss_hena(struct iavf_sc *);
219 int     iavf_config_rss_lut(struct iavf_sc *);
220 int     iavf_config_promisc_mode(struct iavf_sc *);
221
222 int     ixl_vc_send_cmd(struct iavf_sc *sc, uint32_t request);
223 char    *iavf_vc_speed_to_string(enum virtchnl_link_speed link_speed);
224 void    *ixl_vc_get_op_chan(struct iavf_sc *sc, uint32_t request);
225 #endif /* _IAVF_H_ */