xref: /freebsd/sys/dev/enic/vnic_devcmd.h (revision 7899f917b1c0ea178f1d2be0cfb452086d079d23)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2008-2017 Cisco Systems, Inc.  All rights reserved.
3  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
4  */
5 
6 #ifndef _VNIC_DEVCMD_H_
7 #define _VNIC_DEVCMD_H_
8 
9 #define _CMD_NBITS	14
10 #define _CMD_VTYPEBITS	10
11 #define _CMD_FLAGSBITS	6
12 #define _CMD_DIRBITS	2
13 
14 #define _CMD_NMASK	((1 << _CMD_NBITS)-1)
15 #define _CMD_VTYPEMASK	((1 << _CMD_VTYPEBITS)-1)
16 #define _CMD_FLAGSMASK  ((1 << _CMD_FLAGSBITS)-1)
17 #define _CMD_DIRMASK	((1 << _CMD_DIRBITS)-1)
18 
19 #define _CMD_NSHIFT	0
20 #define _CMD_VTYPESHIFT	(_CMD_NSHIFT+_CMD_NBITS)
21 #define _CMD_FLAGSSHIFT	(_CMD_VTYPESHIFT+_CMD_VTYPEBITS)
22 #define _CMD_DIRSHIFT	(_CMD_FLAGSSHIFT+_CMD_FLAGSBITS)
23 
24 /*
25  * Direction bits (from host perspective).
26  */
27 #define _CMD_DIR_NONE	0U
28 #define _CMD_DIR_WRITE	1U
29 #define _CMD_DIR_READ	2U
30 #define _CMD_DIR_RW	(_CMD_DIR_WRITE | _CMD_DIR_READ)
31 
32 /*
33  * Flag bits.
34  */
35 #define _CMD_FLAGS_NONE 0U
36 #define _CMD_FLAGS_NOWAIT 1U
37 
38 /*
39  * vNIC type bits.
40  */
41 #define _CMD_VTYPE_NONE	0U
42 #define _CMD_VTYPE_ENET	1U
43 #define _CMD_VTYPE_FC	2U
44 #define _CMD_VTYPE_SCSI	4U
45 #define _CMD_VTYPE_ALL	(_CMD_VTYPE_ENET | _CMD_VTYPE_FC | _CMD_VTYPE_SCSI)
46 
47 /*
48  * Used to create cmds..
49  */
50 #define _CMDCF(dir, flags, vtype, nr)  \
51 	(((dir)   << _CMD_DIRSHIFT) |  \
52 	((flags) << _CMD_FLAGSSHIFT) | \
53 	((vtype) << _CMD_VTYPESHIFT) | \
54 	((nr)    << _CMD_NSHIFT))
55 #define _CMDC(dir, vtype, nr)	_CMDCF(dir, 0, vtype, nr)
56 #define _CMDCNW(dir, vtype, nr)	_CMDCF(dir, _CMD_FLAGS_NOWAIT, vtype, nr)
57 
58 /*
59  * Used to decode cmds..
60  */
61 #define _CMD_DIR(cmd)	(((cmd) >> _CMD_DIRSHIFT) & _CMD_DIRMASK)
62 #define _CMD_FLAGS(cmd)	(((cmd) >> _CMD_FLAGSSHIFT) & _CMD_FLAGSMASK)
63 #define _CMD_VTYPE(cmd)	(((cmd) >> _CMD_VTYPESHIFT) & _CMD_VTYPEMASK)
64 #define _CMD_N(cmd)	(((cmd) >> _CMD_NSHIFT) & _CMD_NMASK)
65 
66 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
67 
68 enum vnic_devcmd_cmd {
69 	CMD_NONE                = _CMDC(_CMD_DIR_NONE, _CMD_VTYPE_NONE, 0),
70 
71 	/*
72 	 * mcpu fw info in mem:
73 	 * in:
74 	 *   (u64)a0=paddr to struct vnic_devcmd_fw_info
75 	 * action:
76 	 *   Fills in struct vnic_devcmd_fw_info (128 bytes)
77 	 * note:
78 	 *   An old definition of CMD_MCPU_FW_INFO
79 	 */
80 	CMD_MCPU_FW_INFO_OLD    = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 1),
81 
82 	/*
83 	 * mcpu fw info in mem:
84 	 * in:
85 	 *   (u64)a0=paddr to struct vnic_devcmd_fw_info
86 	 *   (u16)a1=size of the structure
87 	 * out:
88 	 *	 (u16)a1=0                          for in:a1 = 0,
89 	 *	         data size actually written for other values.
90 	 * action:
91 	 *   Fills in first 128 bytes of vnic_devcmd_fw_info for in:a1 = 0,
92 	 *            first in:a1 bytes               for 0 < in:a1 <= 132,
93 	 *            132 bytes                       for other values of in:a1.
94 	 * note:
95 	 *   CMD_MCPU_FW_INFO and CMD_MCPU_FW_INFO_OLD have the same enum 1
96 	 *   for source compatibility.
97 	 */
98 	CMD_MCPU_FW_INFO        = _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ALL, 1),
99 
100 	/* dev-specific block member:
101 	 *    in: (u16)a0=offset,(u8)a1=size
102 	 *    out: a0=value
103 	 */
104 	CMD_DEV_SPEC            = _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ALL, 2),
105 
106 	/* stats clear */
107 	CMD_STATS_CLEAR         = _CMDCNW(_CMD_DIR_NONE, _CMD_VTYPE_ALL, 3),
108 
109 	/* stats dump in mem: (u64)a0=paddr to stats area,
110 	 *                    (u16)a1=sizeof stats area */
111 	CMD_STATS_DUMP          = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 4),
112 
113 	/* set Rx packet filter: (u32)a0=filters (see CMD_PFILTER_*) */
114 	CMD_PACKET_FILTER	= _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 7),
115 
116 	/* set Rx packet filter for all: (u32)a0=filters (see CMD_PFILTER_*) */
117 	CMD_PACKET_FILTER_ALL   = _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 7),
118 
119 	/* hang detection notification */
120 	CMD_HANG_NOTIFY         = _CMDC(_CMD_DIR_NONE, _CMD_VTYPE_ALL, 8),
121 
122 	/* MAC address in (u48)a0 */
123 	CMD_MAC_ADDR            = _CMDC(_CMD_DIR_READ,
124 					_CMD_VTYPE_ENET | _CMD_VTYPE_FC, 9),
125 #define CMD_GET_MAC_ADDR CMD_MAC_ADDR   /* some uses are aliased */
126 
127 	/* add addr from (u48)a0 */
128 	CMD_ADDR_ADD            = _CMDCNW(_CMD_DIR_WRITE,
129 					_CMD_VTYPE_ENET | _CMD_VTYPE_FC, 12),
130 
131 	/* del addr from (u48)a0 */
132 	CMD_ADDR_DEL            = _CMDCNW(_CMD_DIR_WRITE,
133 					_CMD_VTYPE_ENET | _CMD_VTYPE_FC, 13),
134 
135 	/* add VLAN id in (u16)a0 */
136 	CMD_VLAN_ADD            = _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 14),
137 
138 	/* del VLAN id in (u16)a0 */
139 	CMD_VLAN_DEL            = _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 15),
140 
141 	/*
142 	 * nic_cfg in (u32)a0
143 	 *
144 	 * Capability query:
145 	 * out: (u64) a0= 1 if a1 is valid
146 	 *      (u64) a1= (NIC_CFG bits supported) | (flags << 32)
147 	 *                              (flags are CMD_NIC_CFG_CAPF_xxx)
148 	 */
149 	CMD_NIC_CFG             = _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 16),
150 
151 	/*
152 	 * nic_cfg_chk  (same as nic_cfg, but may return error)
153 	 * in (u32)a0
154 	 *
155 	 * Capability query:
156 	 * out: (u64) a0= 1 if a1 is valid
157 	 *      (u64) a1= (NIC_CFG bits supported) | (flags << 32)
158 	 *                              (flags are CMD_NIC_CFG_CAPF_xxx)
159 	 */
160 	CMD_NIC_CFG_CHK         = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 16),
161 
162 	/* union vnic_rss_key in mem: (u64)a0=paddr, (u16)a1=len */
163 	CMD_RSS_KEY             = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 17),
164 
165 	/* union vnic_rss_cpu in mem: (u64)a0=paddr, (u16)a1=len */
166 	CMD_RSS_CPU             = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 18),
167 
168 	/* initiate softreset */
169 	CMD_SOFT_RESET          = _CMDCNW(_CMD_DIR_NONE, _CMD_VTYPE_ALL, 19),
170 
171 	/* softreset status:
172 	 *    out: a0=0 reset complete, a0=1 reset in progress */
173 	CMD_SOFT_RESET_STATUS   = _CMDC(_CMD_DIR_READ, _CMD_VTYPE_ALL, 20),
174 
175 	/* set struct vnic_devcmd_notify buffer in mem:
176 	 * in:
177 	 *   (u64)a0=paddr to notify (set paddr=0 to unset)
178 	 *   (u32)a1 & 0x00000000ffffffff=sizeof(struct vnic_devcmd_notify)
179 	 *   (u16)a1 & 0x0000ffff00000000=intr num (-1 for no intr)
180 	 * out:
181 	 *   (u32)a1 = effective size
182 	 */
183 	CMD_NOTIFY              = _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ALL, 21),
184 
185 	/* UNDI API: (u64)a0=paddr to s_PXENV_UNDI_ struct,
186 	 *           (u8)a1=PXENV_UNDI_xxx */
187 	CMD_UNDI                = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 22),
188 
189 	/* initiate open sequence (u32)a0=flags (see CMD_OPENF_*) */
190 	CMD_OPEN		= _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 23),
191 
192 	/* open status:
193 	 *    out: a0=0 open complete, a0=1 open in progress */
194 	CMD_OPEN_STATUS		= _CMDC(_CMD_DIR_READ, _CMD_VTYPE_ALL, 24),
195 
196 	/* close vnic */
197 	CMD_CLOSE		= _CMDC(_CMD_DIR_NONE, _CMD_VTYPE_ALL, 25),
198 
199 	/* initialize virtual link: (u32)a0=flags (see CMD_INITF_*) */
200 /***** Replaced by CMD_INIT *****/
201 	CMD_INIT_v1		= _CMDCNW(_CMD_DIR_READ, _CMD_VTYPE_ALL, 26),
202 
203 	/* variant of CMD_INIT, with provisioning info
204 	 *     (u64)a0=paddr of vnic_devcmd_provinfo
205 	 *     (u32)a1=sizeof provision info */
206 	CMD_INIT_PROV_INFO	= _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 27),
207 
208 	/* enable virtual link */
209 	CMD_ENABLE		= _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 28),
210 
211 	/* enable virtual link, waiting variant. */
212 	CMD_ENABLE_WAIT		= _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 28),
213 
214 	/* disable virtual link */
215 	CMD_DISABLE		= _CMDC(_CMD_DIR_NONE, _CMD_VTYPE_ALL, 29),
216 
217 	/* stats dump sum of all vnic stats on same uplink in mem:
218 	 *     (u64)a0=paddr
219 	 *     (u16)a1=sizeof stats area */
220 	CMD_STATS_DUMP_ALL	= _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 30),
221 
222 	/* init status:
223 	 *    out: a0=0 init complete, a0=1 init in progress
224 	 *         if a0=0, a1=errno */
225 	CMD_INIT_STATUS		= _CMDC(_CMD_DIR_READ, _CMD_VTYPE_ALL, 31),
226 
227 	/* INT13 API: (u64)a0=paddr to vnic_int13_params struct
228 	 *            (u32)a1=INT13_CMD_xxx */
229 	CMD_INT13               = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_FC, 32),
230 
231 	/* logical uplink enable/disable: (u64)a0: 0/1=disable/enable */
232 	CMD_LOGICAL_UPLINK      = _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 33),
233 
234 	/* undo initialize of virtual link */
235 	CMD_DEINIT		= _CMDCNW(_CMD_DIR_NONE, _CMD_VTYPE_ALL, 34),
236 
237 	/* initialize virtual link: (u32)a0=flags (see CMD_INITF_*) */
238 	CMD_INIT		= _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 35),
239 
240 	/* check fw capability of a cmd:
241 	 * in:  (u32)a0=cmd
242 	 * out: (u32)a0=errno, 0:valid cmd, a1=supported VNIC_STF_* bits */
243 	CMD_CAPABILITY		= _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ALL, 36),
244 
245 	/* persistent binding info
246 	 * in:  (u64)a0=paddr of arg
247 	 *      (u32)a1=CMD_PERBI_XXX */
248 	CMD_PERBI		= _CMDC(_CMD_DIR_RW, _CMD_VTYPE_FC, 37),
249 
250 	/* Interrupt Assert Register functionality
251 	 * in: (u16)a0=interrupt number to assert
252 	 */
253 	CMD_IAR			= _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 38),
254 
255 	/* initiate hangreset, like softreset after hang detected */
256 	CMD_HANG_RESET		= _CMDC(_CMD_DIR_NONE, _CMD_VTYPE_ALL, 39),
257 
258 	/* hangreset status:
259 	 *    out: a0=0 reset complete, a0=1 reset in progress */
260 	CMD_HANG_RESET_STATUS   = _CMDC(_CMD_DIR_READ, _CMD_VTYPE_ALL, 40),
261 
262 	/*
263 	 * Set hw ingress packet vlan rewrite mode:
264 	 * in:  (u32)a0=new vlan rewrite mode
265 	 * out: (u32)a0=old vlan rewrite mode */
266 	CMD_IG_VLAN_REWRITE_MODE = _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ENET, 41),
267 
268 	/*
269 	 * in:  (u16)a0=bdf of target vnic
270 	 *      (u32)a1=cmd to proxy
271 	 *      a2-a15=args to cmd in a1
272 	 * out: (u32)a0=status of proxied cmd
273 	 *      a1-a15=out args of proxied cmd */
274 	CMD_PROXY_BY_BDF =	_CMDC(_CMD_DIR_RW, _CMD_VTYPE_ALL, 42),
275 
276 	/*
277 	 * As for BY_BDF except a0 is index of hvnlink subordinate vnic
278 	 * or SR-IOV virtual vnic
279 	 */
280 	CMD_PROXY_BY_INDEX =    _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ALL, 43),
281 
282 	/*
283 	 * For HPP toggle:
284 	 * adapter-info-get
285 	 * in:  (u64)a0=phsical address of buffer passed in from caller.
286 	 *      (u16)a1=size of buffer specified in a0.
287 	 * out: (u64)a0=phsical address of buffer passed in from caller.
288 	 *      (u16)a1=actual bytes from VIF-CONFIG-INFO TLV, or
289 	 *              0 if no VIF-CONFIG-INFO TLV was ever received. */
290 	CMD_CONFIG_INFO_GET = _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ALL, 44),
291 
292 	/*
293 	 * INT13 API: (u64)a0=paddr to vnic_int13_params struct
294 	 *            (u32)a1=INT13_CMD_xxx
295 	 */
296 	CMD_INT13_ALL = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 45),
297 
298 	/*
299 	 * Set default vlan:
300 	 * in: (u16)a0=new default vlan
301 	 *     (u16)a1=zero for overriding vlan with param a0,
302 	 *		       non-zero for resetting vlan to the default
303 	 * out: (u16)a0=old default vlan
304 	 */
305 	CMD_SET_DEFAULT_VLAN = _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ALL, 46),
306 
307 	/* init_prov_info2:
308 	 * Variant of CMD_INIT_PROV_INFO, where it will not try to enable
309 	 * the vnic until CMD_ENABLE2 is issued.
310 	 *     (u64)a0=paddr of vnic_devcmd_provinfo
311 	 *     (u32)a1=sizeof provision info */
312 	CMD_INIT_PROV_INFO2  = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 47),
313 
314 	/* enable2:
315 	 *      (u32)a0=0                  ==> standby
316 	 *             =CMD_ENABLE2_ACTIVE ==> active
317 	 */
318 	CMD_ENABLE2 = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 48),
319 
320 	/*
321 	 * cmd_status:
322 	 *     Returns the status of the specified command
323 	 * Input:
324 	 *     a0 = command for which status is being queried.
325 	 *          Possible values are:
326 	 *              CMD_SOFT_RESET
327 	 *              CMD_HANG_RESET
328 	 *              CMD_OPEN
329 	 *              CMD_INIT
330 	 *              CMD_INIT_PROV_INFO
331 	 *              CMD_DEINIT
332 	 *              CMD_INIT_PROV_INFO2
333 	 *              CMD_ENABLE2
334 	 * Output:
335 	 *     if status == STAT_ERROR
336 	 *        a0 = ERR_ENOTSUPPORTED - status for command in a0 is
337 	 *                                 not supported
338 	 *     if status == STAT_NONE
339 	 *        a0 = status of the devcmd specified in a0 as follows.
340 	 *             ERR_SUCCESS   - command in a0 completed successfully
341 	 *             ERR_EINPROGRESS - command in a0 is still in progress
342 	 */
343 	CMD_STATUS = _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ALL, 49),
344 
345 	/*
346 	 * Returns interrupt coalescing timer conversion factors.
347 	 * After calling this devcmd, ENIC driver can convert
348 	 * interrupt coalescing timer in usec into CPU cycles as follows:
349 	 *
350 	 *   intr_timer_cycles = intr_timer_usec * multiplier / divisor
351 	 *
352 	 * Interrupt coalescing timer in usecs can be be converted/obtained
353 	 * from CPU cycles as follows:
354 	 *
355 	 *   intr_timer_usec = intr_timer_cycles * divisor / multiplier
356 	 *
357 	 * in: none
358 	 * out: (u32)a0 = multiplier
359 	 *      (u32)a1 = divisor
360 	 *      (u32)a2 = maximum timer value in usec
361 	 */
362 	CMD_INTR_COAL_CONVERT = _CMDC(_CMD_DIR_READ, _CMD_VTYPE_ALL, 50),
363 
364 	/*
365 	 * ISCSI DUMP API:
366 	 * in: (u64)a0=paddr of the param or param itself
367 	 *     (u32)a1=ISCSI_CMD_xxx
368 	 */
369 	CMD_ISCSI_DUMP_REQ = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 51),
370 
371 	/*
372 	 * ISCSI DUMP STATUS API:
373 	 * in: (u32)a0=cmd tag
374 	 * in: (u32)a1=ISCSI_CMD_xxx
375 	 * out: (u32)a0=cmd status
376 	 */
377 	CMD_ISCSI_DUMP_STATUS = _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ALL, 52),
378 
379 	/*
380 	 * Subvnic migration from MQ <--> VF.
381 	 * Enable the LIF migration from MQ to VF and vice versa. MQ and VF
382 	 * indexes are statically bound at the time of initialization.
383 	 * Based on the direction of migration, the resources of either MQ or
384 	 * the VF shall be attached to the LIF.
385 	 * in:        (u32)a0=Direction of Migration
386 	 *					0=> Migrate to VF
387 	 *					1=> Migrate to MQ
388 	 *            (u32)a1=VF index (MQ index)
389 	 */
390 	CMD_MIGRATE_SUBVNIC = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 53),
391 
392 	/*
393 	 * Register / Deregister the notification block for MQ subvnics
394 	 * in:
395 	 *   (u64)a0=paddr to notify (set paddr=0 to unset)
396 	 *   (u32)a1 & 0x00000000ffffffff=sizeof(struct vnic_devcmd_notify)
397 	 *   (u16)a1 & 0x0000ffff00000000=intr num (-1 for no intr)
398 	 * out:
399 	 *   (u32)a1 = effective size
400 	 */
401 	CMD_SUBVNIC_NOTIFY = _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ALL, 54),
402 
403 	/*
404 	 * Set the predefined mac address as default
405 	 * in:
406 	 *   (u48)a0=mac addr
407 	 */
408 	CMD_SET_MAC_ADDR = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 55),
409 
410 	/* Update the provisioning info of the given VIF
411 	 *     (u64)a0=paddr of vnic_devcmd_provinfo
412 	 *     (u32)a1=sizeof provision info */
413 	CMD_PROV_INFO_UPDATE = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 56),
414 
415 	/*
416 	 * Initialization for the devcmd2 interface.
417 	 * in: (u64) a0=host result buffer physical address
418 	 * in: (u16) a1=number of entries in result buffer
419 	 */
420 	CMD_INITIALIZE_DEVCMD2 = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 57),
421 
422 	/*
423 	 * Add a filter.
424 	 * in: (u64) a0= filter address
425 	 *     (u32) a1= size of filter
426 	 * out: (u32) a0=filter identifier
427 	 *
428 	 * Capability query:
429 	 * out: (u64) a0= 1 if capability query supported
430 	 *      (u64) a1= MAX filter type supported
431 	 */
432 	CMD_ADD_FILTER = _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ENET, 58),
433 
434 	/*
435 	 * Delete a filter.
436 	 * in: (u32) a0=filter identifier
437 	 */
438 	CMD_DEL_FILTER = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 59),
439 
440 	/*
441 	 * Enable a Queue Pair in User space NIC
442 	 * in: (u32) a0=Queue Pair number
443 	 *     (u32) a1= command
444 	 */
445 	CMD_QP_ENABLE = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 60),
446 
447 	/*
448 	 * Disable a Queue Pair in User space NIC
449 	 * in: (u32) a0=Queue Pair number
450 	 *     (u32) a1= command
451 	 */
452 	CMD_QP_DISABLE = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 61),
453 
454 	/*
455 	 * Stats dump Queue Pair in User space NIC
456 	 * in: (u32) a0=Queue Pair number
457 	 *     (u64) a1=host buffer addr for status dump
458 	 *     (u32) a2=length of the buffer
459 	 */
460 	CMD_QP_STATS_DUMP = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 62),
461 
462 	/*
463 	 * Clear stats for Queue Pair in User space NIC
464 	 * in: (u32) a0=Queue Pair number
465 	 */
466 	CMD_QP_STATS_CLEAR = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 63),
467 
468 	/*
469 	 * UEFI BOOT API: (u64)a0= UEFI FLS_CMD_xxx
470 	 * (ui64)a1= paddr for the info buffer
471 	 */
472 	CMD_FC_REQ = _CMDC(_CMD_DIR_RW, _CMD_VTYPE_FC, 64),
473 
474 	/*
475 	 * Return the iSCSI config details required by the EFI Option ROM
476 	 * in:  (u32) a0=0 Get Boot Info for PXE eNIC as per pxe_boot_config_t
477 	 *            a0=1 Get Boot info for iSCSI enic as per
478 	 *            iscsi_boot_efi_cfg_t
479 	 * in:  (u64) a1=Host address where iSCSI config info is returned
480 	 */
481 	CMD_VNIC_BOOT_CONFIG_INFO = _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ALL, 65),
482 
483 	/*
484 	 * Create a Queue Pair (RoCE)
485 	 * in: (u32) a0 = Queue Pair number
486 	 *     (u32) a1 = Remote QP
487 	 *     (u32) a2 = RDMA-RQ
488 	 *     (u16) a3 = RQ Res Group
489 	 *     (u16) a4 = SQ Res Group
490 	 *     (u32) a5 = Protection Domain
491 	 *     (u64) a6 = Remote MAC
492 	 *     (u32) a7 = start PSN
493 	 *     (u16) a8 = MSS
494 	 *     (u32) a9 = protocol version
495 	 */
496 	CMD_RDMA_QP_CREATE = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 66),
497 
498 	/*
499 	 * Delete a Queue Pair (RoCE)
500 	 * in: (u32) a0 = Queue Pair number
501 	 */
502 	CMD_RDMA_QP_DELETE = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 67),
503 
504 	/*
505 	 * Retrieve a Queue Pair's status information (RoCE)
506 	 * in: (u32) a0 = Queue Pair number
507 	 *     (u64) a1 = host buffer addr for QP status struct
508 	 *     (u32) a2 = length of the buffer
509 	 */
510 	CMD_RDMA_QP_STATUS = _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ENET, 68),
511 
512 	/*
513 	 * Use this devcmd for agreeing on the highest common version supported
514 	 * by both driver and fw for by features who need such a facility.
515 	 *  in:  (u64) a0 = feature (driver requests for the supported versions
516 	 *                  on this feature)
517 	 *  out: (u64) a0 = bitmap of all supported versions for that feature
518 	 */
519 	CMD_GET_SUPP_FEATURE_VER = _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ENET, 69),
520 
521 	/*
522 	 * Initialize the RDMA notification work queue
523 	 * in: (u64) a0 = host buffer address
524 	 * in: (u16) a1 = number of entries in buffer
525 	 * in: (u16) a2 = resource group number
526 	 * in: (u16) a3 = CQ number to post completion
527 	 */
528 	CMD_RDMA_INIT_INFO_BUF = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 70),
529 
530 	/*
531 	 * De-init the RDMA notification work queue
532 	 * in: (u64) a0=resource group number
533 	 */
534 	CMD_RDMA_DEINIT_INFO_BUF = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 71),
535 
536 	/*
537 	 * Control (Enable/Disable) overlay offloads on the given vnic
538 	 * in: (u8) a0 = OVERLAY_FEATURE_NVGRE : NVGRE
539 	 *          a0 = OVERLAY_FEATURE_VXLAN : VxLAN
540 	 * in: (u8) a1 = OVERLAY_OFFLOAD_ENABLE : Enable or
541 	 *          a1 = OVERLAY_OFFLOAD_DISABLE : Disable or
542 	 *          a1 = OVERLAY_OFFLOAD_ENABLE_V2 : Enable with version 2
543 	 */
544 	CMD_OVERLAY_OFFLOAD_CTRL =
545 				_CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 72),
546 
547 	/*
548 	 * Configuration of overlay offloads feature on a given vNIC
549 	 * in: (u8) a0 = OVERLAY_CFG_VXLAN_PORT_UPDATE : VxLAN
550 	 * in: (u16) a1 = unsigned short int port information
551 	 */
552 	CMD_OVERLAY_OFFLOAD_CFG = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 73),
553 
554 	/*
555 	 * Return the configured name for the device
556 	 * in: (u64) a0=Host address where the name is copied
557 	 *     (u32) a1=Size of the buffer
558 	 */
559 	CMD_GET_CONFIG_NAME = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 74),
560 
561 	/*
562 	 * Enable group interrupt for the VF
563 	 * in: (u32) a0 = GRPINTR_ENABLE : enable
564 	 *           a0 = GRPINTR_DISABLE : disable
565 	 *           a0 = GRPINTR_UPD_VECT: update group vector addr
566 	 * in: (u32) a1 = interrupt group count
567 	 * in: (u64) a2 = Start of host buffer address for DMAing group
568 	 *           vector bitmap
569 	 * in: (u64) a3 = Stride between group vectors
570 	 */
571 	CMD_CONFIG_GRPINTR = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 75),
572 
573 	/*
574 	 * Set cq arrary base and size in a list of consective wqs and
575 	 * rqs for a device
576 	 * in: (u16) a0 = the wq relative index in the device.
577 	 *		-1 indicates skipping wq configuration
578 	 * in: (u16) a1 = the wcq relative index in the device
579 	 * in: (u16) a2 = the rq relative index in the device
580 	 *		-1 indicates skipping rq configuration
581 	 * in: (u16) a3 = the rcq relative index in the device
582 	 */
583 	CMD_CONFIG_CQ_ARRAY = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 76),
584 
585 	/*
586 	 * Add an advanced filter.
587 	 * in: (u64) a0= filter address
588 	 *     (u32) a1= size of filter
589 	 * out: (u32) a0=filter identifier
590 	 *
591 	 * Capability query:
592 	 * in:  (u64) a1= supported filter capability exchange modes
593 	 * out: (u64) a0= 1 if capability query supported
594 	 *      if (u64) a1 = 0: a1 = MAX filter type supported
595 	 *      if (u64) a1 & FILTER_CAP_MODE_V1_FLAG:
596 	 *                       a1 = bitmask of supported filters
597 	 *                       a2 = FILTER_CAP_MODE_V1
598 	 *                       a3 = bitmask of supported actions
599 	 */
600 	CMD_ADD_ADV_FILTER = _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ENET, 77),
601 
602 	/*
603 	 * Allocate a counter for use with CMD_ADD_FILTER
604 	 * out:(u32) a0 = counter index
605 	 */
606 	CMD_COUNTER_ALLOC = _CMDC(_CMD_DIR_READ, _CMD_VTYPE_ENET, 85),
607 
608 	/*
609 	 * Free a counter
610 	 * in: (u32) a0 = counter_id
611 	 */
612 	CMD_COUNTER_FREE = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 86),
613 
614 	/*
615 	 * Read a counter
616 	 * in: (u32) a0 = counter_id
617 	 *     (u32) a1 = clear counter if non-zero
618 	 * out:(u64) a0 = packet count
619 	 *     (u64) a1 = byte count
620 	 */
621 	CMD_COUNTER_QUERY = _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ENET, 87),
622 
623 	/*
624 	 * Configure periodic counter DMA.  This will trigger an immediate
625 	 * DMA of the counters (unless period == 0), and then schedule a DMA
626 	 * of the counters every <period> seconds until disdabled.
627 	 * Each new COUNTER_DMA_CONFIG will override all previous commands on
628 	 * this vnic.
629 	 * Setting a2 (period) = 0 will disable periodic DMAs
630 	 * If a0 (num_counters) != 0, an immediate DMA will always be done,
631 	 * irrespective of the value in a2.
632 	 * in: (u32) a0 = number of counters to DMA
633 	 *     (u64) a1 = host target DMA address
634 	 *     (u32) a2 = DMA period in milliseconds (0 to disable)
635 	 */
636 	CMD_COUNTER_DMA_CONFIG = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 88),
637 #define VNIC_COUNTER_DMA_MIN_PERIOD 500
638 
639 	/*
640 	 * Clear all counters on a vnic
641 	 */
642 	CMD_COUNTER_CLEAR_ALL = _CMDC(_CMD_DIR_NONE, _CMD_VTYPE_ENET, 89),
643 };
644 
645 /* Modes for exchanging advanced filter capabilities. The modes supported by
646  * the driver are passed in the CMD_ADD_ADV_FILTER capability command and the
647  * mode selected is returned.
648  *    V0: the maximum filter type supported is returned
649  *    V1: bitmasks of supported filters and actions are returned
650  */
651 enum filter_cap_mode {
652 	FILTER_CAP_MODE_V0 = 0,  /* Must always be 0 for legacy drivers */
653 	FILTER_CAP_MODE_V1 = 1,
654 };
655 #define FILTER_CAP_MODE_V1_FLAG (1 << FILTER_CAP_MODE_V1)
656 
657 /* CMD_ENABLE2 flags */
658 #define CMD_ENABLE2_STANDBY 0x0
659 #define CMD_ENABLE2_ACTIVE  0x1
660 
661 /* flags for CMD_OPEN */
662 #define CMD_OPENF_OPROM		0x1	/* open coming from option rom */
663 #define CMD_OPENF_IG_DESCCACHE	0x2	/* Do not flush IG DESC cache */
664 
665 /* flags for CMD_INIT */
666 #define CMD_INITF_DEFAULT_MAC	0x1	/* init with default mac addr */
667 
668 /* flags for CMD_NIC_CFG */
669 #define CMD_NIC_CFG_CAPF_UDP_WEAK	(1ULL << 0) /* Bodega-style UDP RSS */
670 
671 /* flags for CMD_PACKET_FILTER */
672 #define CMD_PFILTER_DIRECTED		0x01
673 #define CMD_PFILTER_MULTICAST		0x02
674 #define CMD_PFILTER_BROADCAST		0x04
675 #define CMD_PFILTER_PROMISCUOUS		0x08
676 #define CMD_PFILTER_ALL_MULTICAST	0x10
677 
678 /* Commands for CMD_QP_ENABLE/CM_QP_DISABLE */
679 #define CMD_QP_RQWQ                     0x0
680 
681 /* rewrite modes for CMD_IG_VLAN_REWRITE_MODE */
682 #define IG_VLAN_REWRITE_MODE_DEFAULT_TRUNK              0
683 #define IG_VLAN_REWRITE_MODE_UNTAG_DEFAULT_VLAN         1
684 #define IG_VLAN_REWRITE_MODE_PRIORITY_TAG_DEFAULT_VLAN  2
685 #define IG_VLAN_REWRITE_MODE_PASS_THRU                  3
686 
687 enum vnic_devcmd_status {
688 	STAT_NONE = 0,
689 	STAT_BUSY = 1 << 0,	/* cmd in progress */
690 	STAT_ERROR = 1 << 1,	/* last cmd caused error (code in a0) */
691 	STAT_FAILOVER = 1 << 2, /* always set on vnics in pci standby state
692 				 * if seen a failover to the standby happened
693 				 */
694 };
695 
696 enum vnic_devcmd_error {
697 	ERR_SUCCESS = 0,
698 	ERR_EINVAL = 1,
699 	ERR_EFAULT = 2,
700 	ERR_EPERM = 3,
701 	ERR_EBUSY = 4,
702 	ERR_ECMDUNKNOWN = 5,
703 	ERR_EBADSTATE = 6,
704 	ERR_ENOMEM = 7,
705 	ERR_ETIMEDOUT = 8,
706 	ERR_ELINKDOWN = 9,
707 	ERR_EMAXRES = 10,
708 	ERR_ENOTSUPPORTED = 11,
709 	ERR_EINPROGRESS = 12,
710 	ERR_MAX
711 };
712 
713 /*
714  * note: hw_version and asic_rev refer to the same thing,
715  *       but have different formats. hw_version is
716  *       a 32-byte string (e.g. "A2") and asic_rev is
717  *       a 16-bit integer (e.g. 0xA2).
718  */
719 struct vnic_devcmd_fw_info {
720 	char fw_version[32];
721 	char fw_build[32];
722 	char hw_version[32];
723 	char hw_serial_number[32];
724 	u16 asic_type;
725 	u16 asic_rev;
726 };
727 
728 enum fwinfo_asic_type {
729 	FWINFO_ASIC_TYPE_UNKNOWN,
730 	FWINFO_ASIC_TYPE_PALO,
731 	FWINFO_ASIC_TYPE_SERENO,
732 	FWINFO_ASIC_TYPE_CRUZ,
733 };
734 
735 struct vnic_devcmd_notify {
736 	u32 csum;		/* checksum over following words */
737 
738 	u32 link_state;		/* link up == 1 */
739 	u32 port_speed;		/* effective port speed (rate limit) */
740 	u32 mtu;		/* MTU */
741 	u32 msglvl;		/* requested driver msg lvl */
742 	u32 uif;		/* uplink interface */
743 	u32 status;		/* status bits (see VNIC_STF_*) */
744 	u32 error;		/* error code (see ERR_*) for first ERR */
745 	u32 link_down_cnt;	/* running count of link down transitions */
746 	u32 perbi_rebuild_cnt;	/* running count of perbi rebuilds */
747 };
748 #define VNIC_STF_FATAL_ERR	0x0001	/* fatal fw error */
749 #define VNIC_STF_STD_PAUSE	0x0002	/* standard link-level pause on */
750 #define VNIC_STF_PFC_PAUSE	0x0004	/* priority flow control pause on */
751 /* all supported status flags */
752 #define VNIC_STF_ALL		(VNIC_STF_FATAL_ERR |\
753 				 VNIC_STF_STD_PAUSE |\
754 				 VNIC_STF_PFC_PAUSE |\
755 				 0)
756 
757 struct vnic_devcmd_provinfo {
758 	u8 oui[3];
759 	u8 type;
760 	u8 data[0];
761 };
762 
763 /*
764  * These are used in flags field of different filters to denote
765  * valid fields used.
766  */
767 #define FILTER_FIELD_VALID(fld) (1 << (fld - 1))
768 
769 #define FILTER_FIELD_USNIC_VLAN    FILTER_FIELD_VALID(1)
770 #define FILTER_FIELD_USNIC_ETHTYPE FILTER_FIELD_VALID(2)
771 #define FILTER_FIELD_USNIC_PROTO   FILTER_FIELD_VALID(3)
772 #define FILTER_FIELD_USNIC_ID      FILTER_FIELD_VALID(4)
773 
774 #define FILTER_FIELDS_USNIC (FILTER_FIELD_USNIC_VLAN | \
775 			     FILTER_FIELD_USNIC_ETHTYPE | \
776 			     FILTER_FIELD_USNIC_PROTO | \
777 			     FILTER_FIELD_USNIC_ID)
778 
779 struct filter_usnic_id {
780 	u32 flags;
781 	u16 vlan;
782 	u16 ethtype;
783 	u8 proto_version;
784 	u32 usnic_id;
785 } __attribute__((packed));
786 
787 #define FILTER_FIELD_5TUP_PROTO  FILTER_FIELD_VALID(1)
788 #define FILTER_FIELD_5TUP_SRC_AD FILTER_FIELD_VALID(2)
789 #define FILTER_FIELD_5TUP_DST_AD FILTER_FIELD_VALID(3)
790 #define FILTER_FIELD_5TUP_SRC_PT FILTER_FIELD_VALID(4)
791 #define FILTER_FIELD_5TUP_DST_PT FILTER_FIELD_VALID(5)
792 
793 #define FILTER_FIELDS_IPV4_5TUPLE (FILTER_FIELD_5TUP_PROTO | \
794 				   FILTER_FIELD_5TUP_SRC_AD | \
795 				   FILTER_FIELD_5TUP_DST_AD | \
796 				   FILTER_FIELD_5TUP_SRC_PT | \
797 				   FILTER_FIELD_5TUP_DST_PT)
798 
799 /* Enums for the protocol field. */
800 enum protocol_e {
801 	PROTO_UDP = 0,
802 	PROTO_TCP = 1,
803 	PROTO_IPV4 = 2,
804 	PROTO_IPV6 = 3
805 };
806 
807 struct filter_ipv4_5tuple {
808 	u32 flags;
809 	u32 protocol;
810 	u32 src_addr;
811 	u32 dst_addr;
812 	u16 src_port;
813 	u16 dst_port;
814 } __attribute__((packed));
815 
816 #define FILTER_FIELD_VMQ_VLAN   FILTER_FIELD_VALID(1)
817 #define FILTER_FIELD_VMQ_MAC    FILTER_FIELD_VALID(2)
818 
819 #define FILTER_FIELDS_MAC_VLAN (FILTER_FIELD_VMQ_VLAN | \
820 				FILTER_FIELD_VMQ_MAC)
821 
822 #define FILTER_FIELDS_NVGRE    FILTER_FIELD_VMQ_MAC
823 
824 struct filter_mac_vlan {
825 	u32 flags;
826 	u16 vlan;
827 	u8 mac_addr[6];
828 } __attribute__((packed));
829 
830 #define FILTER_FIELD_VLAN_IP_3TUP_VLAN      FILTER_FIELD_VALID(1)
831 #define FILTER_FIELD_VLAN_IP_3TUP_L3_PROTO  FILTER_FIELD_VALID(2)
832 #define FILTER_FIELD_VLAN_IP_3TUP_DST_AD    FILTER_FIELD_VALID(3)
833 #define FILTER_FIELD_VLAN_IP_3TUP_L4_PROTO  FILTER_FIELD_VALID(4)
834 #define FILTER_FIELD_VLAN_IP_3TUP_DST_PT    FILTER_FIELD_VALID(5)
835 
836 #define FILTER_FIELDS_VLAN_IP_3TUP (FILTER_FIELD_VLAN_IP_3TUP_VLAN | \
837 				    FILTER_FIELD_VLAN_IP_3TUP_L3_PROTO | \
838 				    FILTER_FIELD_VLAN_IP_3TUP_DST_AD | \
839 				    FILTER_FIELD_VLAN_IP_3TUP_L4_PROTO | \
840 				    FILTER_FIELD_VLAN_IP_3TUP_DST_PT)
841 
842 struct filter_vlan_ip_3tuple {
843 	u32 flags;
844 	u16 vlan;
845 	u16 l3_protocol;
846 	union {
847 		u32 dst_addr_v4;
848 		u8 dst_addr_v6[16];
849 	} u;
850 	u32 l4_protocol;
851 	u16 dst_port;
852 } __attribute__((packed));
853 
854 #define FILTER_GENERIC_1_BYTES 64
855 
856 enum filter_generic_1_layer {
857 	FILTER_GENERIC_1_L2,
858 	FILTER_GENERIC_1_L3,
859 	FILTER_GENERIC_1_L4,
860 	FILTER_GENERIC_1_L5,
861 	FILTER_GENERIC_1_NUM_LAYERS
862 };
863 
864 #define FILTER_GENERIC_1_IPV4       (1 << 0)
865 #define FILTER_GENERIC_1_IPV6       (1 << 1)
866 #define FILTER_GENERIC_1_UDP        (1 << 2)
867 #define FILTER_GENERIC_1_TCP        (1 << 3)
868 #define FILTER_GENERIC_1_TCP_OR_UDP (1 << 4)
869 #define FILTER_GENERIC_1_IP4SUM_OK  (1 << 5)
870 #define FILTER_GENERIC_1_L4SUM_OK   (1 << 6)
871 #define FILTER_GENERIC_1_IPFRAG     (1 << 7)
872 
873 #define FILTER_GENERIC_1_KEY_LEN 64
874 
875 /*
876  * Version 1 of generic filter specification
877  * position is only 16 bits, reserving positions > 64k to be used by firmware
878  */
879 struct filter_generic_1 {
880 	u16 position;       /* lower position comes first */
881 	u32 mask_flags;
882 	u32 val_flags;
883 	u16 mask_vlan;
884 	u16 val_vlan;
885 	struct {
886 		u8 mask[FILTER_GENERIC_1_KEY_LEN]; /* 0 bit means "don't care"*/
887 		u8 val[FILTER_GENERIC_1_KEY_LEN];
888 	} __attribute__((packed)) layer[FILTER_GENERIC_1_NUM_LAYERS];
889 } __attribute__((packed));
890 
891 /* Specifies the filter_action type. */
892 enum {
893 	FILTER_ACTION_RQ_STEERING = 0,
894 	FILTER_ACTION_V2 = 1,
895 	FILTER_ACTION_MAX
896 };
897 
898 struct filter_action {
899 	u32 type;
900 	union {
901 		u32 rq_idx;
902 	} u;
903 } __attribute__((packed));
904 
905 #define FILTER_ACTION_RQ_STEERING_FLAG	(1 << 0)
906 #define FILTER_ACTION_FILTER_ID_FLAG	(1 << 1)
907 #define FILTER_ACTION_DROP_FLAG		(1 << 2)
908 #define FILTER_ACTION_COUNTER_FLAG      (1 << 3)
909 #define FILTER_ACTION_V2_ALL		(FILTER_ACTION_RQ_STEERING_FLAG \
910 					 | FILTER_ACTION_FILTER_ID_FLAG \
911 					 | FILTER_ACTION_DROP_FLAG \
912 					 | FILTER_ACTION_COUNTER_FLAG)
913 
914 /* Version 2 of filter action must be a strict extension of struct filter_action
915  * where the first fields exactly match in size and meaning.
916  */
917 struct filter_action_v2 {
918 	u32 type;
919 	u32 rq_idx;
920 	u32 flags;                     /* use FILTER_ACTION_XXX_FLAG defines */
921 	u16 filter_id;
922 	u32 counter_index;
923 	uint8_t reserved[28];         /* for future expansion */
924 } __attribute__((packed));
925 
926 /* Specifies the filter type. */
927 enum filter_type {
928 	FILTER_USNIC_ID = 0,
929 	FILTER_IPV4_5TUPLE = 1,
930 	FILTER_MAC_VLAN = 2,
931 	FILTER_VLAN_IP_3TUPLE = 3,
932 	FILTER_NVGRE_VMQ = 4,
933 	FILTER_USNIC_IP = 5,
934 	FILTER_DPDK_1 = 6,
935 	FILTER_MAX
936 };
937 
938 #define FILTER_USNIC_ID_FLAG		(1 << FILTER_USNIC_ID)
939 #define FILTER_IPV4_5TUPLE_FLAG		(1 << FILTER_IPV4_5TUPLE)
940 #define FILTER_MAC_VLAN_FLAG		(1 << FILTER_MAC_VLAN)
941 #define FILTER_VLAN_IP_3TUPLE_FLAG	(1 << FILTER_VLAN_IP_3TUPLE)
942 #define FILTER_NVGRE_VMQ_FLAG		(1 << FILTER_NVGRE_VMQ)
943 #define FILTER_USNIC_IP_FLAG		(1 << FILTER_USNIC_IP)
944 #define FILTER_DPDK_1_FLAG		(1 << FILTER_DPDK_1)
945 #define FILTER_V1_ALL			(FILTER_USNIC_ID_FLAG | \
946 					FILTER_IPV4_5TUPLE_FLAG | \
947 					FILTER_MAC_VLAN_FLAG | \
948 					FILTER_VLAN_IP_3TUPLE_FLAG | \
949 					FILTER_NVGRE_VMQ_FLAG | \
950 					FILTER_USNIC_IP_FLAG | \
951 					FILTER_DPDK_1_FLAG)
952 
953 struct filter {
954 	u32 type;
955 	union {
956 		struct filter_usnic_id usnic;
957 		struct filter_ipv4_5tuple ipv4;
958 		struct filter_mac_vlan mac_vlan;
959 		struct filter_vlan_ip_3tuple vlan_3tuple;
960 	} u;
961 } __attribute__((packed));
962 
963 /*
964  * This is a strict superset of "struct filter" and exists only
965  * because many drivers use "sizeof (struct filter)" in deciding TLV size.
966  * This new, larger struct filter would cause any code that uses that method
967  * to not work with older firmware, so we add filter_v2 to hold the
968  * new filter types.  Drivers should use vnic_filter_size() to determine
969  * the TLV size instead of sizeof (struct fiter_v2) to guard against future
970  * growth.
971  */
972 struct filter_v2 {
973 	u32 type;
974 	union {
975 		struct filter_usnic_id usnic;
976 		struct filter_ipv4_5tuple ipv4;
977 		struct filter_mac_vlan mac_vlan;
978 		struct filter_vlan_ip_3tuple vlan_3tuple;
979 		struct filter_generic_1 generic_1;
980 	} u;
981 } __attribute__((packed));
982 
983 enum {
984 	CLSF_TLV_FILTER = 0,
985 	CLSF_TLV_ACTION = 1,
986 };
987 
988 struct filter_tlv {
989 	uint32_t type;
990 	uint32_t length;
991 	uint32_t val[0];
992 };
993 
994 /* Data for CMD_ADD_FILTER is 2 TLV and filter + action structs */
995 #define FILTER_MAX_BUF_SIZE 100
996 #define FILTER_V2_MAX_BUF_SIZE (sizeof(struct filter_v2) + \
997 	sizeof(struct filter_action_v2) + \
998 	(2 * sizeof(struct filter_tlv)))
999 
1000 /*
1001  * Compute actual structure size given filter type.  To be "future-proof,"
1002  * drivers should use this instead of "sizeof (struct filter_v2)" when
1003  * computing length for TLV.
1004  */
1005 static inline uint32_t
1006 vnic_filter_size(struct filter_v2 *fp)
1007 {
1008 	uint32_t size;
1009 
1010 	switch (fp->type) {
1011 	case FILTER_USNIC_ID:
1012 		size = sizeof(fp->u.usnic);
1013 		break;
1014 	case FILTER_IPV4_5TUPLE:
1015 		size = sizeof(fp->u.ipv4);
1016 		break;
1017 	case FILTER_MAC_VLAN:
1018 	case FILTER_NVGRE_VMQ:
1019 		size = sizeof(fp->u.mac_vlan);
1020 		break;
1021 	case FILTER_VLAN_IP_3TUPLE:
1022 		size = sizeof(fp->u.vlan_3tuple);
1023 		break;
1024 	case FILTER_USNIC_IP:
1025 	case FILTER_DPDK_1:
1026 		size = sizeof(fp->u.generic_1);
1027 		break;
1028 	default:
1029 		size = sizeof(fp->u);
1030 		break;
1031 	}
1032 	size += sizeof(fp->type);
1033 	return size;
1034 }
1035 
1036 enum {
1037 	CLSF_ADD = 0,
1038 	CLSF_DEL = 1,
1039 };
1040 
1041 /*
1042  * Get the action structure size given action type. To be "future-proof,"
1043  * drivers should use this instead of "sizeof (struct filter_action_v2)"
1044  * when computing length for TLV.
1045  */
1046 static inline uint32_t
1047 vnic_action_size(struct filter_action_v2 *fap)
1048 {
1049 	uint32_t size;
1050 
1051 	switch (fap->type) {
1052 	case FILTER_ACTION_RQ_STEERING:
1053 		size = sizeof(struct filter_action);
1054 		break;
1055 	case FILTER_ACTION_V2:
1056 		size = sizeof(struct filter_action_v2);
1057 		break;
1058 	default:
1059 		size = sizeof(struct filter_action);
1060 		break;
1061 	}
1062 	return size;
1063 }
1064 
1065 /*
1066  * Writing cmd register causes STAT_BUSY to get set in status register.
1067  * When cmd completes, STAT_BUSY will be cleared.
1068  *
1069  * If cmd completed successfully STAT_ERROR will be clear
1070  * and args registers contain cmd-specific results.
1071  *
1072  * If cmd error, STAT_ERROR will be set and args[0] contains error code.
1073  *
1074  * status register is read-only.  While STAT_BUSY is set,
1075  * all other register contents are read-only.
1076  */
1077 
1078 /* Make sizeof(vnic_devcmd) a power-of-2 for I/O BAR. */
1079 #define VNIC_DEVCMD_NARGS 15
1080 struct vnic_devcmd {
1081 	u32 status;			/* RO */
1082 	u32 cmd;			/* RW */
1083 	u64 args[VNIC_DEVCMD_NARGS];	/* RW cmd args (little-endian) */
1084 };
1085 
1086 #define DEVCMD_STATUS 	0
1087 #define DEVCMD_CMD      4
1088 #define DEVCMD_ARGS(x)  (8 + (VNIC_DEVCMD_NARGS * x))
1089 
1090 /*
1091  * Version 2 of the interface.
1092  *
1093  * Some things are carried over, notably the vnic_devcmd_cmd enum.
1094  */
1095 
1096 /*
1097  * Flags for vnic_devcmd2.flags
1098  */
1099 
1100 #define DEVCMD2_FNORESULT       0x1     /* Don't copy result to host */
1101 
1102 #define VNIC_DEVCMD2_NARGS      VNIC_DEVCMD_NARGS
1103 struct vnic_devcmd2 {
1104 	u16 pad;
1105 	u16 flags;
1106 	u32 cmd;                /* same command #defines as original */
1107 	u64 args[VNIC_DEVCMD2_NARGS];
1108 };
1109 
1110 #define VNIC_DEVCMD2_NRESULTS   VNIC_DEVCMD_NARGS
1111 struct devcmd2_result {
1112 	u64 results[VNIC_DEVCMD2_NRESULTS];
1113 	u32 pad;
1114 	u16 completed_index;    /* into copy WQ */
1115 	u8  error;              /* same error codes as original */
1116 	u8  color;              /* 0 or 1 as with completion queues */
1117 };
1118 
1119 #define DEVCMD2_RING_SIZE   32
1120 #define DEVCMD2_DESC_SIZE   128
1121 
1122 #define DEVCMD2_RESULTS_SIZE_MAX   ((1 << 16) - 1)
1123 
1124 /* Overlay related definitions */
1125 
1126 /*
1127  * This enum lists the flag associated with each of the overlay features
1128  */
1129 typedef enum {
1130 	OVERLAY_FEATURE_NVGRE = 1,
1131 	OVERLAY_FEATURE_VXLAN,
1132 	OVERLAY_FEATURE_MAX,
1133 } overlay_feature_t;
1134 
1135 #define OVERLAY_OFFLOAD_ENABLE          0
1136 #define OVERLAY_OFFLOAD_DISABLE         1
1137 #define OVERLAY_OFFLOAD_ENABLE_V2       2
1138 
1139 #define OVERLAY_CFG_VXLAN_PORT_UPDATE 0
1140 
1141 /*
1142  * Use this enum to get the supported versions for each of these features
1143  * If you need to use the devcmd_get_supported_feature_version(), add
1144  * the new feature into this enum and install function handler in devcmd.c
1145  */
1146 typedef enum {
1147 	VIC_FEATURE_VXLAN,
1148 	VIC_FEATURE_RDMA,
1149 	VIC_FEATURE_MAX,
1150 } vic_feature_t;
1151 
1152 /*
1153  * These flags are used in args[1] of devcmd CMD_GET_SUPP_FEATURE_VER
1154  * to indicate the host driver about the VxLAN and Multi WQ features
1155  * supported
1156  */
1157 #define FEATURE_VXLAN_IPV6_INNER	(1 << 0)
1158 #define FEATURE_VXLAN_IPV6_OUTER	(1 << 1)
1159 #define FEATURE_VXLAN_MULTI_WQ		(1 << 2)
1160 
1161 #define FEATURE_VXLAN_IPV6		(FEATURE_VXLAN_IPV6_INNER | \
1162 					 FEATURE_VXLAN_IPV6_OUTER)
1163 
1164 /*
1165  * CMD_CONFIG_GRPINTR subcommands
1166  */
1167 typedef enum {
1168 	GRPINTR_ENABLE = 1,
1169 	GRPINTR_DISABLE,
1170 	GRPINTR_UPD_VECT,
1171 } grpintr_subcmd_t;
1172 
1173 /*
1174  * Structure for counter DMA
1175  * (DMAed by CMD_COUNTER_DMA_CONFIG)
1176  */
1177 struct vnic_counter_counts {
1178 	u64 vcc_packets;
1179 	u64 vcc_bytes;
1180 };
1181 
1182 #endif /* _VNIC_DEVCMD_H_ */
1183