1270631Sjfv/******************************************************************************
2270631Sjfv
3270631Sjfv  Copyright (c) 2013-2014, Intel Corporation
4270631Sjfv  All rights reserved.
5270631Sjfv
6270631Sjfv  Redistribution and use in source and binary forms, with or without
7270631Sjfv  modification, are permitted provided that the following conditions are met:
8270631Sjfv
9270631Sjfv   1. Redistributions of source code must retain the above copyright notice,
10270631Sjfv      this list of conditions and the following disclaimer.
11270631Sjfv
12270631Sjfv   2. Redistributions in binary form must reproduce the above copyright
13270631Sjfv      notice, this list of conditions and the following disclaimer in the
14270631Sjfv      documentation and/or other materials provided with the distribution.
15270631Sjfv
16270631Sjfv   3. Neither the name of the Intel Corporation nor the names of its
17270631Sjfv      contributors may be used to endorse or promote products derived from
18270631Sjfv      this software without specific prior written permission.
19270631Sjfv
20270631Sjfv  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21270631Sjfv  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22270631Sjfv  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23270631Sjfv  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24270631Sjfv  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25270631Sjfv  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26270631Sjfv  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27270631Sjfv  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28270631Sjfv  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29270631Sjfv  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30270631Sjfv  POSSIBILITY OF SUCH DAMAGE.
31270631Sjfv
32270631Sjfv******************************************************************************/
33270631Sjfv/*$FreeBSD: releng/10.2/sys/dev/ixl/ixlv.h 274360 2014-11-10 23:56:06Z jfv $*/
34270631Sjfv
35270631Sjfv
36270631Sjfv#ifndef _IXLV_H_
37270631Sjfv#define _IXLV_H_
38270631Sjfv
39274360Sjfv#include "ixlv_vc_mgr.h"
40274360Sjfv
41274360Sjfv#define IXLV_AQ_MAX_ERR		1000
42270631Sjfv#define IXLV_MAX_FILTERS	128
43274360Sjfv#define IXLV_MAX_QUEUES		16
44274360Sjfv#define IXLV_AQ_TIMEOUT		(1 * hz)
45274360Sjfv#define IXLV_CALLOUT_TIMO	(hz / 50)	/* 20 msec */
46270631Sjfv
47270631Sjfv#define IXLV_FLAG_AQ_ENABLE_QUEUES            (u32)(1)
48270631Sjfv#define IXLV_FLAG_AQ_DISABLE_QUEUES           (u32)(1 << 1)
49270631Sjfv#define IXLV_FLAG_AQ_ADD_MAC_FILTER           (u32)(1 << 2)
50270631Sjfv#define IXLV_FLAG_AQ_ADD_VLAN_FILTER          (u32)(1 << 3)
51270631Sjfv#define IXLV_FLAG_AQ_DEL_MAC_FILTER           (u32)(1 << 4)
52270631Sjfv#define IXLV_FLAG_AQ_DEL_VLAN_FILTER          (u32)(1 << 5)
53270631Sjfv#define IXLV_FLAG_AQ_CONFIGURE_QUEUES         (u32)(1 << 6)
54270631Sjfv#define IXLV_FLAG_AQ_MAP_VECTORS              (u32)(1 << 7)
55270631Sjfv#define IXLV_FLAG_AQ_HANDLE_RESET             (u32)(1 << 8)
56274360Sjfv#define IXLV_FLAG_AQ_CONFIGURE_PROMISC        (u32)(1 << 9)
57274360Sjfv#define IXLV_FLAG_AQ_GET_STATS                (u32)(1 << 10)
58270631Sjfv
59270631Sjfv/* printf %b arg */
60270631Sjfv#define IXLV_FLAGS \
61270631Sjfv    "\20\1ENABLE_QUEUES\2DISABLE_QUEUES\3ADD_MAC_FILTER" \
62270631Sjfv    "\4ADD_VLAN_FILTER\5DEL_MAC_FILTER\6DEL_VLAN_FILTER" \
63270631Sjfv    "\7CONFIGURE_QUEUES\10MAP_VECTORS\11HANDLE_RESET" \
64270631Sjfv    "\12CONFIGURE_PROMISC\13GET_STATS"
65270631Sjfv
66274360Sjfv/* Hack for compatibility with 1.0.x linux pf driver */
67274360Sjfv#define I40E_VIRTCHNL_OP_EVENT 17
68274360Sjfv
69270631Sjfv/* Driver state */
70270631Sjfvenum ixlv_state_t {
71270631Sjfv	IXLV_START,
72270631Sjfv	IXLV_FAILED,
73270631Sjfv	IXLV_RESET_REQUIRED,
74270631Sjfv	IXLV_RESET_PENDING,
75270631Sjfv	IXLV_VERSION_CHECK,
76270631Sjfv	IXLV_GET_RESOURCES,
77270631Sjfv	IXLV_INIT_READY,
78270631Sjfv	IXLV_INIT_START,
79270631Sjfv	IXLV_INIT_CONFIG,
80270631Sjfv	IXLV_INIT_MAPPING,
81270631Sjfv	IXLV_INIT_ENABLE,
82270631Sjfv	IXLV_INIT_COMPLETE,
83270631Sjfv	IXLV_RUNNING,
84270631Sjfv};
85270631Sjfv
86270631Sjfvstruct ixlv_mac_filter {
87270631Sjfv	SLIST_ENTRY(ixlv_mac_filter)  next;
88270631Sjfv	u8      macaddr[ETHER_ADDR_LEN];
89270631Sjfv	u16     flags;
90270631Sjfv};
91270631SjfvSLIST_HEAD(mac_list, ixlv_mac_filter);
92270631Sjfv
93270631Sjfvstruct ixlv_vlan_filter {
94270631Sjfv	SLIST_ENTRY(ixlv_vlan_filter)  next;
95270631Sjfv	u16     vlan;
96270631Sjfv	u16     flags;
97270631Sjfv};
98270631SjfvSLIST_HEAD(vlan_list, ixlv_vlan_filter);
99270631Sjfv
100270631Sjfv/* Software controller structure */
101270631Sjfvstruct ixlv_sc {
102270631Sjfv	struct i40e_hw		hw;
103270631Sjfv	struct i40e_osdep	osdep;
104270631Sjfv	struct device		*dev;
105270631Sjfv
106270631Sjfv	struct resource		*pci_mem;
107270631Sjfv	struct resource		*msix_mem;
108270631Sjfv
109270631Sjfv	enum ixlv_state_t	init_state;
110270631Sjfv
111270631Sjfv	/*
112270631Sjfv	 * Interrupt resources
113270631Sjfv	 */
114270631Sjfv	void			*tag;
115270631Sjfv	struct resource 	*res; /* For the AQ */
116270631Sjfv
117270631Sjfv	struct ifmedia		media;
118270631Sjfv	struct callout		timer;
119270631Sjfv	int			msix;
120270631Sjfv	int			if_flags;
121270631Sjfv
122270631Sjfv	struct mtx		mtx;
123270631Sjfv
124270631Sjfv	u32			qbase;
125270631Sjfv	u32 			admvec;
126270631Sjfv	struct timeout_task	timeout;
127270631Sjfv	struct task     	aq_irq;
128270631Sjfv	struct task     	aq_sched;
129270631Sjfv	struct taskqueue	*tq;
130270631Sjfv
131270631Sjfv	struct ixl_vsi		vsi;
132270631Sjfv
133274360Sjfv	/* Filter lists */
134270631Sjfv	struct mac_list		*mac_filters;
135270631Sjfv	struct vlan_list	*vlan_filters;
136270631Sjfv
137270631Sjfv	/* Promiscuous mode */
138270631Sjfv	u32			promiscuous_flags;
139270631Sjfv
140270631Sjfv	/* Admin queue task flags */
141270631Sjfv	u32			aq_wait_count;
142270631Sjfv
143274360Sjfv	struct ixl_vc_mgr	vc_mgr;
144274360Sjfv	struct ixl_vc_cmd	add_mac_cmd;
145274360Sjfv	struct ixl_vc_cmd	del_mac_cmd;
146274360Sjfv	struct ixl_vc_cmd	config_queues_cmd;
147274360Sjfv	struct ixl_vc_cmd	map_vectors_cmd;
148274360Sjfv	struct ixl_vc_cmd	enable_queues_cmd;
149274360Sjfv	struct ixl_vc_cmd	add_vlan_cmd;
150274360Sjfv	struct ixl_vc_cmd	del_vlan_cmd;
151274360Sjfv	struct ixl_vc_cmd	add_multi_cmd;
152274360Sjfv	struct ixl_vc_cmd	del_multi_cmd;
153274360Sjfv
154270631Sjfv	/* Virtual comm channel */
155270631Sjfv	struct i40e_virtchnl_vf_resource *vf_res;
156270631Sjfv	struct i40e_virtchnl_vsi_resource *vsi_res;
157270631Sjfv
158270631Sjfv	/* Misc stats maintained by the driver */
159270631Sjfv	u64			watchdog_events;
160270631Sjfv	u64			admin_irq;
161270631Sjfv
162274360Sjfv	u8			aq_buffer[IXL_AQ_BUF_SZ];
163270631Sjfv};
164270631Sjfv
165274360Sjfv#define IXLV_CORE_LOCK_ASSERT(sc)	mtx_assert(&(sc)->mtx, MA_OWNED)
166270631Sjfv/*
167270631Sjfv** This checks for a zero mac addr, something that will be likely
168270631Sjfv** unless the Admin on the Host has created one.
169270631Sjfv*/
170270631Sjfvstatic inline bool
171270631Sjfvixlv_check_ether_addr(u8 *addr)
172270631Sjfv{
173270631Sjfv	bool status = TRUE;
174270631Sjfv
175270631Sjfv	if ((addr[0] == 0 && addr[1]== 0 && addr[2] == 0 &&
176270631Sjfv	    addr[3] == 0 && addr[4]== 0 && addr[5] == 0))
177270631Sjfv		status = FALSE;
178270631Sjfv	return (status);
179270631Sjfv}
180274360Sjfv
181270631Sjfv/*
182270631Sjfv** VF Common function prototypes
183270631Sjfv*/
184270631Sjfvint	ixlv_send_api_ver(struct ixlv_sc *);
185270631Sjfvint	ixlv_verify_api_ver(struct ixlv_sc *);
186270631Sjfvint	ixlv_send_vf_config_msg(struct ixlv_sc *);
187270631Sjfvint	ixlv_get_vf_config(struct ixlv_sc *);
188270631Sjfvvoid	ixlv_init(void *);
189270631Sjfvint	ixlv_reinit_locked(struct ixlv_sc *);
190270631Sjfvvoid	ixlv_configure_queues(struct ixlv_sc *);
191270631Sjfvvoid	ixlv_enable_queues(struct ixlv_sc *);
192270631Sjfvvoid	ixlv_disable_queues(struct ixlv_sc *);
193270631Sjfvvoid	ixlv_map_queues(struct ixlv_sc *);
194270631Sjfvvoid	ixlv_enable_intr(struct ixl_vsi *);
195270631Sjfvvoid	ixlv_disable_intr(struct ixl_vsi *);
196270631Sjfvvoid	ixlv_add_ether_filters(struct ixlv_sc *);
197270631Sjfvvoid	ixlv_del_ether_filters(struct ixlv_sc *);
198270631Sjfvvoid	ixlv_request_stats(struct ixlv_sc *);
199270631Sjfvvoid	ixlv_request_reset(struct ixlv_sc *);
200270631Sjfvvoid	ixlv_vc_completion(struct ixlv_sc *,
201270631Sjfv	enum i40e_virtchnl_ops, i40e_status, u8 *, u16);
202270631Sjfvvoid	ixlv_add_ether_filter(struct ixlv_sc *);
203270631Sjfvvoid	ixlv_add_vlans(struct ixlv_sc *);
204270631Sjfvvoid	ixlv_del_vlans(struct ixlv_sc *);
205270631Sjfvvoid	ixlv_update_stats_counters(struct ixlv_sc *,
206270631Sjfv		    struct i40e_eth_stats *);
207274360Sjfvvoid	ixlv_update_link_status(struct ixlv_sc *);
208270631Sjfv
209270631Sjfv#endif /* _IXLV_H_ */
210