1 /*
2  * Copyright 2008-2010 Cisco Systems, Inc.  All rights reserved.
3  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
4  *
5  * This program is free software; you may redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; version 2 of the License.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
10  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
11  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
12  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
13  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
14  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
15  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
16  * SOFTWARE.
17  *
18  */
19 
20 #ifndef _VNIC_DEVCMD_H_
21 #define _VNIC_DEVCMD_H_
22 
23 #define _CMD_NBITS      14
24 #define _CMD_VTYPEBITS	10
25 #define _CMD_FLAGSBITS  6
26 #define _CMD_DIRBITS	2
27 
28 #define _CMD_NMASK      ((1 << _CMD_NBITS)-1)
29 #define _CMD_VTYPEMASK  ((1 << _CMD_VTYPEBITS)-1)
30 #define _CMD_FLAGSMASK  ((1 << _CMD_FLAGSBITS)-1)
31 #define _CMD_DIRMASK    ((1 << _CMD_DIRBITS)-1)
32 
33 #define _CMD_NSHIFT     0
34 #define _CMD_VTYPESHIFT (_CMD_NSHIFT+_CMD_NBITS)
35 #define _CMD_FLAGSSHIFT (_CMD_VTYPESHIFT+_CMD_VTYPEBITS)
36 #define _CMD_DIRSHIFT   (_CMD_FLAGSSHIFT+_CMD_FLAGSBITS)
37 
38 /*
39  * Direction bits (from host perspective).
40  */
41 #define _CMD_DIR_NONE   0U
42 #define _CMD_DIR_WRITE  1U
43 #define _CMD_DIR_READ   2U
44 #define _CMD_DIR_RW     (_CMD_DIR_WRITE | _CMD_DIR_READ)
45 
46 /*
47  * Flag bits.
48  */
49 #define _CMD_FLAGS_NONE 0U
50 #define _CMD_FLAGS_NOWAIT 1U
51 
52 /*
53  * vNIC type bits.
54  */
55 #define _CMD_VTYPE_NONE  0U
56 #define _CMD_VTYPE_ENET  1U
57 #define _CMD_VTYPE_FC    2U
58 #define _CMD_VTYPE_SCSI  4U
59 #define _CMD_VTYPE_ALL   (_CMD_VTYPE_ENET | _CMD_VTYPE_FC | _CMD_VTYPE_SCSI)
60 
61 /*
62  * Used to create cmds..
63 */
64 #define _CMDCF(dir, flags, vtype, nr)  \
65 	(((dir)   << _CMD_DIRSHIFT) | \
66 	((flags) << _CMD_FLAGSSHIFT) | \
67 	((vtype) << _CMD_VTYPESHIFT) | \
68 	((nr)    << _CMD_NSHIFT))
69 #define _CMDC(dir, vtype, nr)    _CMDCF(dir, 0, vtype, nr)
70 #define _CMDCNW(dir, vtype, nr)  _CMDCF(dir, _CMD_FLAGS_NOWAIT, vtype, nr)
71 
72 /*
73  * Used to decode cmds..
74 */
75 #define _CMD_DIR(cmd)            (((cmd) >> _CMD_DIRSHIFT) & _CMD_DIRMASK)
76 #define _CMD_FLAGS(cmd)          (((cmd) >> _CMD_FLAGSSHIFT) & _CMD_FLAGSMASK)
77 #define _CMD_VTYPE(cmd)          (((cmd) >> _CMD_VTYPESHIFT) & _CMD_VTYPEMASK)
78 #define _CMD_N(cmd)              (((cmd) >> _CMD_NSHIFT) & _CMD_NMASK)
79 
80 enum vnic_devcmd_cmd {
81 	CMD_NONE                = _CMDC(_CMD_DIR_NONE, _CMD_VTYPE_NONE, 0),
82 
83 	/*
84 	 * mcpu fw info in mem:
85 	 * in:
86 	 *   (u64)a0=paddr to struct vnic_devcmd_fw_info
87 	 * action:
88 	 *   Fills in struct vnic_devcmd_fw_info (128 bytes)
89 	 * note:
90 	 *   An old definition of CMD_MCPU_FW_INFO
91 	 */
92 	CMD_MCPU_FW_INFO_OLD    = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 1),
93 
94 	/*
95 	 * mcpu fw info in mem:
96 	 * in:
97 	 *   (u64)a0=paddr to struct vnic_devcmd_fw_info
98 	 *   (u16)a1=size of the structure
99 	 * out:
100 	 *	 (u16)a1=0                          for in:a1 = 0,
101 	 *	         data size actually written for other values.
102 	 * action:
103 	 *   Fills in first 128 bytes of vnic_devcmd_fw_info for in:a1 = 0,
104 	 *            first in:a1 bytes               for 0 < in:a1 <= 132,
105 	 *            132 bytes                       for other values of in:a1.
106 	 * note:
107 	 *   CMD_MCPU_FW_INFO and CMD_MCPU_FW_INFO_OLD have the same enum 1
108 	 *   for source compatibility.
109 	 */
110 	CMD_MCPU_FW_INFO        = _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ALL, 1),
111 
112 	/* dev-specific block member:
113 	 *    in: (u16)a0=offset,(u8)a1=size
114 	 *    out: a0=value */
115 	CMD_DEV_SPEC            = _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ALL, 2),
116 
117 	/* stats clear */
118 	CMD_STATS_CLEAR         = _CMDCNW(_CMD_DIR_NONE, _CMD_VTYPE_ALL, 3),
119 
120 	/* stats dump in mem: (u64)a0=paddr to stats area,
121 	 *                    (u16)a1=sizeof stats area */
122 	CMD_STATS_DUMP          = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 4),
123 
124 	/* set Rx packet filter: (u32)a0=filters (see CMD_PFILTER_*) */
125 	CMD_PACKET_FILTER	= _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 7),
126 
127 	/* set Rx packet filter for all: (u32)a0=filters (see CMD_PFILTER_*) */
128 	CMD_PACKET_FILTER_ALL   = _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 7),
129 
130 	/* hang detection notification */
131 	CMD_HANG_NOTIFY         = _CMDC(_CMD_DIR_NONE, _CMD_VTYPE_ALL, 8),
132 
133 	/* MAC address in (u48)a0 */
134 	CMD_GET_MAC_ADDR        = _CMDC(_CMD_DIR_READ,
135 					_CMD_VTYPE_ENET | _CMD_VTYPE_FC, 9),
136 
137 	/* add addr from (u48)a0 */
138 	CMD_ADDR_ADD            = _CMDCNW(_CMD_DIR_WRITE,
139 					_CMD_VTYPE_ENET | _CMD_VTYPE_FC, 12),
140 
141 	/* del addr from (u48)a0 */
142 	CMD_ADDR_DEL            = _CMDCNW(_CMD_DIR_WRITE,
143 					_CMD_VTYPE_ENET | _CMD_VTYPE_FC, 13),
144 
145 	/* add VLAN id in (u16)a0 */
146 	CMD_VLAN_ADD            = _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 14),
147 
148 	/* del VLAN id in (u16)a0 */
149 	CMD_VLAN_DEL            = _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 15),
150 
151 	/* nic_cfg in (u32)a0 */
152 	CMD_NIC_CFG             = _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 16),
153 
154 	/* union vnic_rss_key in mem: (u64)a0=paddr, (u16)a1=len */
155 	CMD_RSS_KEY             = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 17),
156 
157 	/* union vnic_rss_cpu in mem: (u64)a0=paddr, (u16)a1=len */
158 	CMD_RSS_CPU             = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 18),
159 
160 	/* initiate softreset */
161 	CMD_SOFT_RESET          = _CMDCNW(_CMD_DIR_NONE, _CMD_VTYPE_ALL, 19),
162 
163 	/* softreset status:
164 	 *    out: a0=0 reset complete, a0=1 reset in progress */
165 	CMD_SOFT_RESET_STATUS   = _CMDC(_CMD_DIR_READ, _CMD_VTYPE_ALL, 20),
166 
167 	/* set struct vnic_devcmd_notify buffer in mem:
168 	 * in:
169 	 *   (u64)a0=paddr to notify (set paddr=0 to unset)
170 	 *   (u32)a1 & 0x00000000ffffffff=sizeof(struct vnic_devcmd_notify)
171 	 *   (u16)a1 & 0x0000ffff00000000=intr num (-1 for no intr)
172 	 * out:
173 	 *   (u32)a1 = effective size
174 	 */
175 	CMD_NOTIFY              = _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ALL, 21),
176 
177 	/* UNDI API: (u64)a0=paddr to s_PXENV_UNDI_ struct,
178 	 *           (u8)a1=PXENV_UNDI_xxx */
179 	CMD_UNDI                = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 22),
180 
181 	/* initiate open sequence (u32)a0=flags (see CMD_OPENF_*) */
182 	CMD_OPEN		= _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 23),
183 
184 	/* open status:
185 	 *    out: a0=0 open complete, a0=1 open in progress */
186 	CMD_OPEN_STATUS		= _CMDC(_CMD_DIR_READ, _CMD_VTYPE_ALL, 24),
187 
188 	/* close vnic */
189 	CMD_CLOSE		= _CMDC(_CMD_DIR_NONE, _CMD_VTYPE_ALL, 25),
190 
191 	/* initialize virtual link: (u32)a0=flags (see CMD_INITF_*) */
192 /***** Replaced by CMD_INIT *****/
193 	CMD_INIT_v1		= _CMDCNW(_CMD_DIR_READ, _CMD_VTYPE_ALL, 26),
194 
195 	/* variant of CMD_INIT, with provisioning info
196 	 *     (u64)a0=paddr of vnic_devcmd_provinfo
197 	 *     (u32)a1=sizeof provision info */
198 	CMD_INIT_PROV_INFO	= _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 27),
199 
200 	/* enable virtual link */
201 	CMD_ENABLE		= _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 28),
202 
203 	/* enable virtual link, waiting variant. */
204 	CMD_ENABLE_WAIT		= _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 28),
205 
206 	/* disable virtual link */
207 	CMD_DISABLE		= _CMDC(_CMD_DIR_NONE, _CMD_VTYPE_ALL, 29),
208 
209 	/* stats dump sum of all vnic stats on same uplink in mem:
210 	 *     (u64)a0=paddr
211 	 *     (u16)a1=sizeof stats area */
212 	CMD_STATS_DUMP_ALL	= _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 30),
213 
214 	/* init status:
215 	 *    out: a0=0 init complete, a0=1 init in progress
216 	 *         if a0=0, a1=errno */
217 	CMD_INIT_STATUS		= _CMDC(_CMD_DIR_READ, _CMD_VTYPE_ALL, 31),
218 
219 	/* INT13 API: (u64)a0=paddr to vnic_int13_params struct
220 	 *            (u32)a1=INT13_CMD_xxx */
221 	CMD_INT13               = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_FC, 32),
222 
223 	/* logical uplink enable/disable: (u64)a0: 0/1=disable/enable */
224 	CMD_LOGICAL_UPLINK      = _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 33),
225 
226 	/* undo initialize of virtual link */
227 	CMD_DEINIT		= _CMDCNW(_CMD_DIR_NONE, _CMD_VTYPE_ALL, 34),
228 
229 	/* initialize virtual link: (u32)a0=flags (see CMD_INITF_*) */
230 	CMD_INIT		= _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 35),
231 
232 	/* check fw capability of a cmd:
233 	 * in:  (u32)a0=cmd
234 	 * out: (u32)a0=errno, 0:valid cmd, a1=supported VNIC_STF_* bits */
235 	CMD_CAPABILITY		= _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ALL, 36),
236 
237 	/* persistent binding info
238 	 * in:  (u64)a0=paddr of arg
239 	 *      (u32)a1=CMD_PERBI_XXX */
240 	CMD_PERBI		= _CMDC(_CMD_DIR_RW, _CMD_VTYPE_FC, 37),
241 
242 	/* Interrupt Assert Register functionality
243 	 * in: (u16)a0=interrupt number to assert
244 	 */
245 	CMD_IAR			= _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 38),
246 
247 	/* initiate hangreset, like softreset after hang detected */
248 	CMD_HANG_RESET		= _CMDC(_CMD_DIR_NONE, _CMD_VTYPE_ALL, 39),
249 
250 	/* hangreset status:
251 	 *    out: a0=0 reset complete, a0=1 reset in progress */
252 	CMD_HANG_RESET_STATUS   = _CMDC(_CMD_DIR_READ, _CMD_VTYPE_ALL, 40),
253 
254 	/*
255 	 * Set hw ingress packet vlan rewrite mode:
256 	 * in:  (u32)a0=new vlan rewrite mode
257 	 * out: (u32)a0=old vlan rewrite mode */
258 	CMD_IG_VLAN_REWRITE_MODE = _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ENET, 41),
259 
260 	/*
261 	 * in:  (u16)a0=bdf of target vnic
262 	 *      (u32)a1=cmd to proxy
263 	 *      a2-a15=args to cmd in a1
264 	 * out: (u32)a0=status of proxied cmd
265 	 *      a1-a15=out args of proxied cmd */
266 	CMD_PROXY_BY_BDF =	_CMDC(_CMD_DIR_RW, _CMD_VTYPE_ALL, 42),
267 
268 	/*
269 	 * As for BY_BDF except a0 is index of hvnlink subordinate vnic
270 	 * or SR-IOV virtual vnic
271 	 */
272 	CMD_PROXY_BY_INDEX =    _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ALL, 43),
273 
274 	/*
275 	 * For HPP toggle:
276 	 * adapter-info-get
277 	 * in:  (u64)a0=phsical address of buffer passed in from caller.
278 	 *      (u16)a1=size of buffer specified in a0.
279 	 * out: (u64)a0=phsical address of buffer passed in from caller.
280 	 *      (u16)a1=actual bytes from VIF-CONFIG-INFO TLV, or
281 	 *              0 if no VIF-CONFIG-INFO TLV was ever received. */
282 	CMD_CONFIG_INFO_GET     = _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ALL, 44),
283 
284 	/* INT13 API: (u64)a0=paddr to vnic_int13_params struct
285 	 *            (u32)a1=INT13_CMD_xxx
286 	 */
287 	CMD_INT13_ALL = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 45),
288 
289 	/* Set default vlan:
290 	 * in: (u16)a0=new default vlan
291 	 *     (u16)a1=zero for overriding vlan with param a0,
292 	 *		       non-zero for resetting vlan to the default
293 	 * out: (u16)a0=old default vlan
294 	 */
295 	CMD_SET_DEFAULT_VLAN = _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ALL, 46),
296 
297 	/* init_prov_info2:
298 	 * Variant of CMD_INIT_PROV_INFO, where it will not try to enable
299 	 * the vnic until CMD_ENABLE2 is issued.
300 	 *     (u64)a0=paddr of vnic_devcmd_provinfo
301 	 *     (u32)a1=sizeof provision info
302 	 */
303 	CMD_INIT_PROV_INFO2  = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 47),
304 
305 	/* enable2:
306 	 *      (u32)a0=0                  ==> standby
307 	 *             =CMD_ENABLE2_ACTIVE ==> active
308 	 */
309 	CMD_ENABLE2 = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 48),
310 
311 	/*
312 	 * cmd_status:
313 	 *     Returns the status of the specified command
314 	 * Input:
315 	 *     a0 = command for which status is being queried.
316 	 *          Possible values are:
317 	 *              CMD_SOFT_RESET
318 	 *              CMD_HANG_RESET
319 	 *              CMD_OPEN
320 	 *              CMD_INIT
321 	 *              CMD_INIT_PROV_INFO
322 	 *              CMD_DEINIT
323 	 *              CMD_INIT_PROV_INFO2
324 	 *              CMD_ENABLE2
325 	 * Output:
326 	 *     if status == STAT_ERROR
327 	 *        a0 = ERR_ENOTSUPPORTED - status for command in a0 is
328 	 *                                 not supported
329 	 *     if status == STAT_NONE
330 	 *        a0 = status of the devcmd specified in a0 as follows.
331 	 *             ERR_SUCCESS   - command in a0 completed successfully
332 	 *             ERR_EINPROGRESS - command in a0 is still in progress
333 	 */
334 	CMD_STATUS = _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ALL, 49),
335 
336 	/*
337 	 * Returns interrupt coalescing timer conversion factors.
338 	 * After calling this devcmd, ENIC driver can convert
339 	 * interrupt coalescing timer in usec into CPU cycles as follows:
340 	 *
341 	 *   intr_timer_cycles = intr_timer_usec * multiplier / divisor
342 	 *
343 	 * Interrupt coalescing timer in usecs can be obtained from
344 	 * CPU cycles as follows:
345 	 *
346 	 *   intr_timer_usec = intr_timer_cycles * divisor / multiplier
347 	 *
348 	 * in: none
349 	 * out: (u32)a0 = multiplier
350 	 *      (u32)a1 = divisor
351 	 *      (u32)a2 = maximum timer value in usec
352 	 */
353 	CMD_INTR_COAL_CONVERT = _CMDC(_CMD_DIR_READ, _CMD_VTYPE_ALL, 50),
354 
355 	/*
356 	 * Set the predefined mac address as default
357 	 * in:
358 	 *   (u48)a0 = mac addr
359 	 */
360 	CMD_SET_MAC_ADDR = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 55),
361 
362 	/* Update the provisioning info of the given VIF
363 	 *     (u64)a0=paddr of vnic_devcmd_provinfo
364 	 *     (u32)a1=sizeof provision info
365 	 */
366 	CMD_PROV_INFO_UPDATE = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 56),
367 
368 	/* Initialization for the devcmd2 interface.
369 	 * in: (u64) a0 = host result buffer physical address
370 	 * in: (u16) a1 = number of entries in result buffer
371 	 */
372 	CMD_INITIALIZE_DEVCMD2 = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 57),
373 
374 	/* Add a filter.
375 	 * in: (u64) a0= filter address
376 	 *     (u32) a1= size of filter
377 	 * out: (u32) a0=filter identifier
378 	 */
379 	CMD_ADD_FILTER = _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ENET, 58),
380 
381 	/* Delete a filter.
382 	 * in: (u32) a0=filter identifier
383 	 */
384 	CMD_DEL_FILTER = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 59),
385 
386 	/* Enable a Queue Pair in User space NIC
387 	 * in: (u32) a0=Queue Pair number
388 	 *     (u32) a1= command
389 	 */
390 	CMD_QP_ENABLE = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 60),
391 
392 	/* Disable a Queue Pair in User space NIC
393 	 * in: (u32) a0=Queue Pair number
394 	 *     (u32) a1= command
395 	 */
396 	CMD_QP_DISABLE = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 61),
397 
398 	/* Stats dump Queue Pair in User space NIC
399 	 * in: (u32) a0=Queue Pair number
400 	 *     (u64) a1=host buffer addr for status dump
401 	 *     (u32) a2=length of the buffer
402 	 */
403 	CMD_QP_STATS_DUMP = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 62),
404 
405 	/* Clear stats for Queue Pair in User space NIC
406 	 * in: (u32) a0=Queue Pair number
407 	 */
408 	CMD_QP_STATS_CLEAR = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 63),
409 };
410 
411 /* CMD_ENABLE2 flags */
412 #define CMD_ENABLE2_STANDBY 0x0
413 #define CMD_ENABLE2_ACTIVE  0x1
414 
415 /* flags for CMD_OPEN */
416 #define CMD_OPENF_OPROM		0x1	/* open coming from option rom */
417 
418 /* flags for CMD_INIT */
419 #define CMD_INITF_DEFAULT_MAC	0x1	/* init with default mac addr */
420 
421 /* flags for CMD_PACKET_FILTER */
422 #define CMD_PFILTER_DIRECTED		0x01
423 #define CMD_PFILTER_MULTICAST		0x02
424 #define CMD_PFILTER_BROADCAST		0x04
425 #define CMD_PFILTER_PROMISCUOUS		0x08
426 #define CMD_PFILTER_ALL_MULTICAST	0x10
427 
428 /* Commands for CMD_QP_ENABLE/CM_QP_DISABLE */
429 #define CMD_QP_RQWQ                     0x0
430 
431 /* rewrite modes for CMD_IG_VLAN_REWRITE_MODE */
432 #define IG_VLAN_REWRITE_MODE_DEFAULT_TRUNK              0
433 #define IG_VLAN_REWRITE_MODE_UNTAG_DEFAULT_VLAN         1
434 #define IG_VLAN_REWRITE_MODE_PRIORITY_TAG_DEFAULT_VLAN  2
435 #define IG_VLAN_REWRITE_MODE_PASS_THRU                  3
436 
437 enum vnic_devcmd_status {
438 	STAT_NONE = 0,
439 	STAT_BUSY = 1 << 0,	/* cmd in progress */
440 	STAT_ERROR = 1 << 1,	/* last cmd caused error (code in a0) */
441 };
442 
443 enum vnic_devcmd_error {
444 	ERR_SUCCESS = 0,
445 	ERR_EINVAL = 1,
446 	ERR_EFAULT = 2,
447 	ERR_EPERM = 3,
448 	ERR_EBUSY = 4,
449 	ERR_ECMDUNKNOWN = 5,
450 	ERR_EBADSTATE = 6,
451 	ERR_ENOMEM = 7,
452 	ERR_ETIMEDOUT = 8,
453 	ERR_ELINKDOWN = 9,
454 	ERR_EMAXRES = 10,
455 	ERR_ENOTSUPPORTED = 11,
456 	ERR_EINPROGRESS = 12,
457 	ERR_MAX
458 };
459 
460 /*
461  * note: hw_version and asic_rev refer to the same thing,
462  *       but have different formats. hw_version is
463  *       a 32-byte string (e.g. "A2") and asic_rev is
464  *       a 16-bit integer (e.g. 0xA2).
465  */
466 struct vnic_devcmd_fw_info {
467 	char fw_version[32];
468 	char fw_build[32];
469 	char hw_version[32];
470 	char hw_serial_number[32];
471 	u16 asic_type;
472 	u16 asic_rev;
473 };
474 
475 struct vnic_devcmd_notify {
476 	u32 csum;		/* checksum over following words */
477 
478 	u32 link_state;		/* link up == 1 */
479 	u32 port_speed;		/* effective port speed (rate limit) */
480 	u32 mtu;		/* MTU */
481 	u32 msglvl;		/* requested driver msg lvl */
482 	u32 uif;		/* uplink interface */
483 	u32 status;		/* status bits (see VNIC_STF_*) */
484 	u32 error;		/* error code (see ERR_*) for first ERR */
485 	u32 link_down_cnt;	/* running count of link down transitions */
486 	u32 perbi_rebuild_cnt;	/* running count of perbi rebuilds */
487 };
488 #define VNIC_STF_FATAL_ERR	0x0001	/* fatal fw error */
489 #define VNIC_STF_STD_PAUSE	0x0002	/* standard link-level pause on */
490 #define VNIC_STF_PFC_PAUSE	0x0004	/* priority flow control pause on */
491 /* all supported status flags */
492 #define VNIC_STF_ALL		(VNIC_STF_FATAL_ERR |\
493 				 VNIC_STF_STD_PAUSE |\
494 				 VNIC_STF_PFC_PAUSE |\
495 				 0)
496 
497 struct vnic_devcmd_provinfo {
498 	u8 oui[3];
499 	u8 type;
500 	u8 data[0];
501 };
502 
503 /* These are used in flags field of different filters to denote
504  * valid fields used.
505  */
506 #define FILTER_FIELD_VALID(fld) (1 << (fld - 1))
507 
508 #define FILTER_FIELDS_USNIC ( \
509 			FILTER_FIELD_VALID(1) | \
510 			FILTER_FIELD_VALID(2) | \
511 			FILTER_FIELD_VALID(3) | \
512 			FILTER_FIELD_VALID(4))
513 
514 #define FILTER_FIELDS_IPV4_5TUPLE ( \
515 			FILTER_FIELD_VALID(1) | \
516 			FILTER_FIELD_VALID(2) | \
517 			FILTER_FIELD_VALID(3) | \
518 			FILTER_FIELD_VALID(4) | \
519 			FILTER_FIELD_VALID(5))
520 
521 #define FILTER_FIELDS_MAC_VLAN ( \
522 			FILTER_FIELD_VALID(1) | \
523 			FILTER_FIELD_VALID(2))
524 
525 #define FILTER_FIELD_USNIC_VLAN    FILTER_FIELD_VALID(1)
526 #define FILTER_FIELD_USNIC_ETHTYPE FILTER_FIELD_VALID(2)
527 #define FILTER_FIELD_USNIC_PROTO   FILTER_FIELD_VALID(3)
528 #define FILTER_FIELD_USNIC_ID      FILTER_FIELD_VALID(4)
529 
530 struct filter_usnic_id {
531 	u32 flags;
532 	u16 vlan;
533 	u16 ethtype;
534 	u8 proto_version;
535 	u32 usnic_id;
536 } __packed;
537 
538 #define FILTER_FIELD_5TUP_PROTO  FILTER_FIELD_VALID(1)
539 #define FILTER_FIELD_5TUP_SRC_AD FILTER_FIELD_VALID(2)
540 #define FILTER_FIELD_5TUP_DST_AD FILTER_FIELD_VALID(3)
541 #define FILTER_FIELD_5TUP_SRC_PT FILTER_FIELD_VALID(4)
542 #define FILTER_FIELD_5TUP_DST_PT FILTER_FIELD_VALID(5)
543 
544 /* Enums for the protocol field. */
545 enum protocol_e {
546 	PROTO_UDP = 0,
547 	PROTO_TCP = 1,
548 };
549 
550 struct filter_ipv4_5tuple {
551 	u32 flags;
552 	u32 protocol;
553 	u32 src_addr;
554 	u32 dst_addr;
555 	u16 src_port;
556 	u16 dst_port;
557 } __packed;
558 
559 #define FILTER_FIELD_VMQ_VLAN   FILTER_FIELD_VALID(1)
560 #define FILTER_FIELD_VMQ_MAC    FILTER_FIELD_VALID(2)
561 
562 struct filter_mac_vlan {
563 	u32 flags;
564 	u16 vlan;
565 	u8 mac_addr[6];
566 } __packed;
567 
568 /* Specifies the filter_action type. */
569 enum {
570 	FILTER_ACTION_RQ_STEERING = 0,
571 	FILTER_ACTION_MAX
572 };
573 
574 struct filter_action {
575 	u32 type;
576 	union {
577 		u32 rq_idx;
578 	} u;
579 } __packed;
580 
581 /* Specifies the filter type. */
582 enum filter_type {
583 	FILTER_USNIC_ID = 0,
584 	FILTER_IPV4_5TUPLE = 1,
585 	FILTER_MAC_VLAN = 2,
586 	FILTER_MAX
587 };
588 
589 struct filter {
590 	u32 type;
591 	union {
592 		struct filter_usnic_id usnic;
593 		struct filter_ipv4_5tuple ipv4;
594 		struct filter_mac_vlan mac_vlan;
595 	} u;
596 } __packed;
597 
598 enum {
599 	CLSF_TLV_FILTER = 0,
600 	CLSF_TLV_ACTION = 1,
601 };
602 
603 /* Maximum size of buffer to CMD_ADD_FILTER */
604 #define FILTER_MAX_BUF_SIZE 100
605 
606 struct filter_tlv {
607 	u_int32_t type;
608 	u_int32_t length;
609 	u_int32_t val[0];
610 };
611 
612 enum {
613 	CLSF_ADD = 0,
614 	CLSF_DEL = 1,
615 };
616 
617 /*
618  * Writing cmd register causes STAT_BUSY to get set in status register.
619  * When cmd completes, STAT_BUSY will be cleared.
620  *
621  * If cmd completed successfully STAT_ERROR will be clear
622  * and args registers contain cmd-specific results.
623  *
624  * If cmd error, STAT_ERROR will be set and args[0] contains error code.
625  *
626  * status register is read-only.  While STAT_BUSY is set,
627  * all other register contents are read-only.
628  */
629 
630 /* Make sizeof(vnic_devcmd) a power-of-2 for I/O BAR. */
631 #define VNIC_DEVCMD_NARGS 15
632 struct vnic_devcmd {
633 	u32 status;			/* RO */
634 	u32 cmd;			/* RW */
635 	u64 args[VNIC_DEVCMD_NARGS];	/* RW cmd args (little-endian) */
636 };
637 
638 #define DEVCMD2_FNORESULT	0x1	/* Don't copy result to host */
639 
640 #define VNIC_DEVCMD2_NARGS	VNIC_DEVCMD_NARGS
641 struct vnic_devcmd2 {
642 	u16 pad;
643 	u16 flags;
644 	u32 cmd;
645 	u64 args[VNIC_DEVCMD2_NARGS];
646 };
647 
648 #define VNIC_DEVCMD2_NRESULTS	VNIC_DEVCMD_NARGS
649 struct devcmd2_result {
650 	u64 results[VNIC_DEVCMD2_NRESULTS];
651 	u32 pad;
652 	u16 completed_index;
653 	u8  error;
654 	u8  color;
655 };
656 
657 #define DEVCMD2_RING_SIZE	32
658 #define DEVCMD2_DESC_SIZE	128
659 
660 #endif /* _VNIC_DEVCMD_H_ */
661