xref: /freebsd/sys/dev/ixl/ixl_pf.h (revision fed1ca4b719c56c930f2259d80663cd34be812bb)
1 /******************************************************************************
2 
3   Copyright (c) 2013-2015, 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 _IXL_PF_H_
37 #define _IXL_PF_H_
38 
39 #define	VF_FLAG_ENABLED			0x01
40 #define	VF_FLAG_SET_MAC_CAP		0x02
41 #define	VF_FLAG_VLAN_CAP		0x04
42 #define	VF_FLAG_PROMISC_CAP		0x08
43 #define	VF_FLAG_MAC_ANTI_SPOOF		0x10
44 
45 #define IXL_PF_STATE_EMPR_RESETTING	(1 << 0)
46 
47 struct ixl_vf {
48 	struct ixl_vsi		vsi;
49 	uint32_t		vf_flags;
50 
51 	uint8_t			mac[ETHER_ADDR_LEN];
52 	uint16_t		vf_num;
53 	uint32_t		version;
54 
55 	struct sysctl_ctx_list	ctx;
56 };
57 
58 /* Physical controller structure */
59 struct ixl_pf {
60 	struct i40e_hw		hw;
61 	struct i40e_osdep	osdep;
62 	struct device		*dev;
63 
64 	struct resource		*pci_mem;
65 	struct resource		*msix_mem;
66 
67 	/*
68 	 * Interrupt resources: this set is
69 	 * either used for legacy, or for Link
70 	 * when doing MSIX
71 	 */
72 	void			*tag;
73 	struct resource 	*res;
74 
75 	struct callout		timer;
76 	int			msix;
77 	int			if_flags;
78 	int			state;
79 
80 	struct mtx		pf_mtx;
81 
82 	u32			qbase;
83 	u32 			admvec;
84 	struct task     	adminq;
85 	struct taskqueue	*tq;
86 
87 	bool			link_up;
88 	u32			link_speed;
89 	int			advertised_speed;
90 	int			fc; /* local flow ctrl setting */
91 
92 	/*
93 	** Network interfaces
94 	**   These are the traffic class holders, and
95 	**   will have a stack interface and queues
96 	**   associated with them.
97 	** NOTE: The PF has only a single interface,
98 	**   so it is embedded in the PF struct.
99 	*/
100 	struct ixl_vsi		vsi;
101 
102 	/* Misc stats maintained by the driver */
103 	u64			watchdog_events;
104 	u64			admin_irq;
105 
106 	/* Statistics from hw */
107 	struct i40e_hw_port_stats 	stats;
108 	struct i40e_hw_port_stats	stats_offsets;
109 	bool 				stat_offsets_loaded;
110 
111 	struct ixl_vf		*vfs;
112 	int			num_vfs;
113 	uint16_t		veb_seid;
114 	struct task		vflr_task;
115 	int			vc_debug_lvl;
116 };
117 
118 /*
119  * Defines used for NVM update ioctls.
120  * This value is used in the Solaris tool, too.
121  */
122 #define I40E_NVM_ACCESS \
123      (((((((('E' << 4) + '1') << 4) + 'K') << 4) + 'G') << 4) | 5)
124 
125 #define IXL_DEFAULT_PHY_INT_MASK \
126      ((~(I40E_AQ_EVENT_LINK_UPDOWN | I40E_AQ_EVENT_MODULE_QUAL_FAIL \
127       | I40E_AQ_EVENT_MEDIA_NA)) & 0x3FF)
128 
129 /*** Sysctl help messages; displayed with "sysctl -d" ***/
130 
131 #define IXL_SYSCTL_HELP_SET_ADVERTISE	\
132 "\nControl advertised link speed.\n"	\
133 "Flags:\n"				\
134 "\t 0x1 - advertise 100M\n"		\
135 "\t 0x2 - advertise 1G\n"		\
136 "\t 0x4 - advertise 10G\n"		\
137 "\t 0x8 - advertise 20G\n"		\
138 "\t0x10 - advertise 40G\n\n"		\
139 "Set to 0 to disable link."
140 
141 #define IXL_SYSCTL_HELP_FC				\
142 "\nSet flow control mode using the values below.\n" 	\
143 "\t0 - off\n" 						\
144 "\t1 - rx pause\n" 					\
145 "\t2 - tx pause\n"					\
146 "\t3 - tx and rx pause"
147 
148 #define IXL_SYSCTL_HELP_LINK_STATUS					\
149 "\nExecutes a \"Get Link Status\" command on the Admin Queue, and displays" \
150 " the response."			\
151 
152 /*** Functions / Macros ***/
153 
154 /*
155 ** Put the NVM, EEtrackID, and OEM version information into a string
156 */
157 static void
158 ixl_nvm_version_str(struct i40e_hw *hw, struct sbuf *buf)
159 {
160 	u8 oem_ver = (u8)(hw->nvm.oem_ver >> 24);
161 	u16 oem_build = (u16)((hw->nvm.oem_ver >> 16) & 0xFFFF);
162 	u8 oem_patch = (u8)(hw->nvm.oem_ver & 0xFF);
163 
164 	sbuf_printf(buf,
165 	    "nvm %x.%02x etid %08x oem %d.%d.%d",
166 	    (hw->nvm.version & IXL_NVM_VERSION_HI_MASK) >>
167 	    IXL_NVM_VERSION_HI_SHIFT,
168 	    (hw->nvm.version & IXL_NVM_VERSION_LO_MASK) >>
169 	    IXL_NVM_VERSION_LO_SHIFT,
170 	    hw->nvm.eetrack,
171 	    oem_ver, oem_build, oem_patch);
172 }
173 
174 static void
175 ixl_print_nvm_version(struct ixl_pf *pf)
176 {
177 	struct i40e_hw *hw = &pf->hw;
178 	device_t dev = pf->dev;
179 	struct sbuf *sbuf;
180 
181 	sbuf = sbuf_new_auto();
182 	ixl_nvm_version_str(hw, sbuf);
183 	sbuf_finish(sbuf);
184 	device_printf(dev, "%s\n", sbuf_data(sbuf));
185 	sbuf_delete(sbuf);
186 }
187 
188 #define	I40E_VC_DEBUG(pf, level, ...) \
189 	do { \
190 		if ((pf)->vc_debug_lvl >= (level)) \
191 			device_printf((pf)->dev, __VA_ARGS__); \
192 	} while (0)
193 
194 #define	i40e_send_vf_nack(pf, vf, op, st) \
195 	ixl_send_vf_nack_msg((pf), (vf), (op), (st), __FILE__, __LINE__)
196 
197 #define IXL_PF_LOCK_INIT(_sc, _name) \
198         mtx_init(&(_sc)->pf_mtx, _name, "IXL PF Lock", MTX_DEF)
199 #define IXL_PF_LOCK(_sc)              mtx_lock(&(_sc)->pf_mtx)
200 #define IXL_PF_UNLOCK(_sc)            mtx_unlock(&(_sc)->pf_mtx)
201 #define IXL_PF_LOCK_DESTROY(_sc)      mtx_destroy(&(_sc)->pf_mtx)
202 #define IXL_PF_LOCK_ASSERT(_sc)       mtx_assert(&(_sc)->pf_mtx, MA_OWNED)
203 
204 #endif /* _IXL_PF_H_ */
205