xref: /openbmc/linux/drivers/scsi/snic/vnic_devcmd.h (revision f5c27da4)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright 2014 Cisco Systems, Inc.  All rights reserved. */
3 
4 #ifndef _VNIC_DEVCMD_H_
5 #define _VNIC_DEVCMD_H_
6 
7 #define _CMD_NBITS      14
8 #define _CMD_VTYPEBITS	10
9 #define _CMD_FLAGSBITS  6
10 #define _CMD_DIRBITS	2
11 
12 #define _CMD_NMASK      ((1 << _CMD_NBITS)-1)
13 #define _CMD_VTYPEMASK  ((1 << _CMD_VTYPEBITS)-1)
14 #define _CMD_FLAGSMASK  ((1 << _CMD_FLAGSBITS)-1)
15 #define _CMD_DIRMASK    ((1 << _CMD_DIRBITS)-1)
16 
17 #define _CMD_NSHIFT     0
18 #define _CMD_VTYPESHIFT (_CMD_NSHIFT+_CMD_NBITS)
19 #define _CMD_FLAGSSHIFT (_CMD_VTYPESHIFT+_CMD_VTYPEBITS)
20 #define _CMD_DIRSHIFT   (_CMD_FLAGSSHIFT+_CMD_FLAGSBITS)
21 
22 /*
23  * Direction bits (from host perspective).
24  */
25 #define _CMD_DIR_NONE   0U
26 #define _CMD_DIR_WRITE  1U
27 #define _CMD_DIR_READ   2U
28 #define _CMD_DIR_RW     (_CMD_DIR_WRITE | _CMD_DIR_READ)
29 
30 /*
31  * Flag bits.
32  */
33 #define _CMD_FLAGS_NONE 0U
34 #define _CMD_FLAGS_NOWAIT 1U
35 
36 /*
37  * vNIC type bits.
38  */
39 #define _CMD_VTYPE_NONE  0U
40 #define _CMD_VTYPE_ENET  1U
41 #define _CMD_VTYPE_FC    2U
42 #define _CMD_VTYPE_SCSI  4U
43 #define _CMD_VTYPE_ALL   (_CMD_VTYPE_ENET | _CMD_VTYPE_FC | _CMD_VTYPE_SCSI)
44 
45 /*
46  * Used to create cmds..
47 */
48 #define _CMDCF(dir, flags, vtype, nr)  \
49 	(((dir)   << _CMD_DIRSHIFT) | \
50 	((flags) << _CMD_FLAGSSHIFT) | \
51 	((vtype) << _CMD_VTYPESHIFT) | \
52 	((nr)    << _CMD_NSHIFT))
53 #define _CMDC(dir, vtype, nr)    _CMDCF(dir, 0, vtype, nr)
54 #define _CMDCNW(dir, vtype, nr)  _CMDCF(dir, _CMD_FLAGS_NOWAIT, vtype, nr)
55 
56 /*
57  * Used to decode cmds..
58 */
59 #define _CMD_DIR(cmd)            (((cmd) >> _CMD_DIRSHIFT) & _CMD_DIRMASK)
60 #define _CMD_FLAGS(cmd)          (((cmd) >> _CMD_FLAGSSHIFT) & _CMD_FLAGSMASK)
61 #define _CMD_VTYPE(cmd)          (((cmd) >> _CMD_VTYPESHIFT) & _CMD_VTYPEMASK)
62 #define _CMD_N(cmd)              (((cmd) >> _CMD_NSHIFT) & _CMD_NMASK)
63 
64 enum vnic_devcmd_cmd {
65 	CMD_NONE                = _CMDC(_CMD_DIR_NONE, _CMD_VTYPE_NONE, 0),
66 
67 	/* mcpu fw info in mem: (u64)a0=paddr to struct vnic_devcmd_fw_info */
68 	CMD_MCPU_FW_INFO        = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 1),
69 
70 	/* dev-specific block member:
71 	 *    in: (u16)a0=offset,(u8)a1=size
72 	 *    out: a0=value */
73 	CMD_DEV_SPEC            = _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ALL, 2),
74 
75 	/* stats clear */
76 	CMD_STATS_CLEAR         = _CMDCNW(_CMD_DIR_NONE, _CMD_VTYPE_ALL, 3),
77 
78 	/* stats dump in mem: (u64)a0=paddr to stats area,
79 	 *                    (u16)a1=sizeof stats area */
80 	CMD_STATS_DUMP          = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 4),
81 
82 	/* nic_cfg in (u32)a0 */
83 	CMD_NIC_CFG             = _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 16),
84 
85 	/* set struct vnic_devcmd_notify buffer in mem:
86 	 * in:
87 	 *   (u64)a0=paddr to notify (set paddr=0 to unset)
88 	 *   (u32)a1 & 0x00000000ffffffff=sizeof(struct vnic_devcmd_notify)
89 	 *   (u16)a1 & 0x0000ffff00000000=intr num (-1 for no intr)
90 	 * out:
91 	 *   (u32)a1 = effective size
92 	 */
93 	CMD_NOTIFY              = _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ALL, 21),
94 
95 	/* initiate open sequence (u32)a0=flags (see CMD_OPENF_*) */
96 	CMD_OPEN		= _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 23),
97 
98 	/* open status:
99 	 *    out: a0=0 open complete, a0=1 open in progress */
100 	CMD_OPEN_STATUS		= _CMDC(_CMD_DIR_READ, _CMD_VTYPE_ALL, 24),
101 
102 	/* close vnic */
103 	CMD_CLOSE		= _CMDC(_CMD_DIR_NONE, _CMD_VTYPE_ALL, 25),
104 
105 	/* initialize virtual link: (u32)a0=flags (see CMD_INITF_*) */
106 	CMD_INIT		= _CMDCNW(_CMD_DIR_READ, _CMD_VTYPE_ALL, 26),
107 
108 	/* enable virtual link */
109 	CMD_ENABLE		= _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 28),
110 
111 	/* enable virtual link, waiting variant. */
112 	CMD_ENABLE_WAIT		= _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 28),
113 
114 	/* disable virtual link */
115 	CMD_DISABLE		= _CMDC(_CMD_DIR_NONE, _CMD_VTYPE_ALL, 29),
116 
117 	/* stats dump all vnics on uplink in mem: (u64)a0=paddr (u32)a1=uif */
118 	CMD_STATS_DUMP_ALL	= _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 30),
119 
120 	/* init status:
121 	 *    out: a0=0 init complete, a0=1 init in progress
122 	 *         if a0=0, a1=errno */
123 	CMD_INIT_STATUS		= _CMDC(_CMD_DIR_READ, _CMD_VTYPE_ALL, 31),
124 
125 	/* undo initialize of virtual link */
126 	CMD_DEINIT		= _CMDCNW(_CMD_DIR_NONE, _CMD_VTYPE_ALL, 34),
127 
128 	/* check fw capability of a cmd:
129 	 * in:  (u32)a0=cmd
130 	 * out: (u32)a0=errno, 0:valid cmd, a1=supported VNIC_STF_* bits */
131 	CMD_CAPABILITY      = _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ALL, 36),
132 
133 	/*
134 	 * Initialization for the devcmd2 interface.
135 	 * in: (u64) a0=host result buffer physical address
136 	 * in: (u16) a1=number of entries in result buffer
137 	 */
138 	CMD_INITIALIZE_DEVCMD2 = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 57)
139 };
140 
141 /* flags for CMD_OPEN */
142 #define CMD_OPENF_OPROM		0x1	/* open coming from option rom */
143 
144 /* flags for CMD_INIT */
145 #define CMD_INITF_DEFAULT_MAC	0x1	/* init with default mac addr */
146 
147 /* flags for CMD_PACKET_FILTER */
148 #define CMD_PFILTER_DIRECTED		0x01
149 #define CMD_PFILTER_MULTICAST		0x02
150 #define CMD_PFILTER_BROADCAST		0x04
151 #define CMD_PFILTER_PROMISCUOUS		0x08
152 #define CMD_PFILTER_ALL_MULTICAST	0x10
153 
154 enum vnic_devcmd_status {
155 	STAT_NONE = 0,
156 	STAT_BUSY = 1 << 0,	/* cmd in progress */
157 	STAT_ERROR = 1 << 1,	/* last cmd caused error (code in a0) */
158 };
159 
160 enum vnic_devcmd_error {
161 	ERR_SUCCESS = 0,
162 	ERR_EINVAL = 1,
163 	ERR_EFAULT = 2,
164 	ERR_EPERM = 3,
165 	ERR_EBUSY = 4,
166 	ERR_ECMDUNKNOWN = 5,
167 	ERR_EBADSTATE = 6,
168 	ERR_ENOMEM = 7,
169 	ERR_ETIMEDOUT = 8,
170 	ERR_ELINKDOWN = 9,
171 };
172 
173 struct vnic_devcmd_fw_info {
174 	char fw_version[32];
175 	char fw_build[32];
176 	char hw_version[32];
177 	char hw_serial_number[32];
178 };
179 
180 struct vnic_devcmd_notify {
181 	u32 csum;		/* checksum over following words */
182 
183 	u32 link_state;		/* link up == 1 */
184 	u32 port_speed;		/* effective port speed (rate limit) */
185 	u32 mtu;		/* MTU */
186 	u32 msglvl;		/* requested driver msg lvl */
187 	u32 uif;		/* uplink interface */
188 	u32 status;		/* status bits (see VNIC_STF_*) */
189 	u32 error;		/* error code (see ERR_*) for first ERR */
190 	u32 link_down_cnt;	/* running count of link down transitions */
191 };
192 #define VNIC_STF_FATAL_ERR	0x0001	/* fatal fw error */
193 
194 struct vnic_devcmd_provinfo {
195 	u8 oui[3];
196 	u8 type;
197 	u8 data[];
198 };
199 
200 /*
201  * Writing cmd register causes STAT_BUSY to get set in status register.
202  * When cmd completes, STAT_BUSY will be cleared.
203  *
204  * If cmd completed successfully STAT_ERROR will be clear
205  * and args registers contain cmd-specific results.
206  *
207  * If cmd error, STAT_ERROR will be set and args[0] contains error code.
208  *
209  * status register is read-only.  While STAT_BUSY is set,
210  * all other register contents are read-only.
211  */
212 
213 /* Make sizeof(vnic_devcmd) a power-of-2 for I/O BAR. */
214 #define VNIC_DEVCMD_NARGS 15
215 struct vnic_devcmd {
216 	u32 status;			/* RO */
217 	u32 cmd;			/* RW */
218 	u64 args[VNIC_DEVCMD_NARGS];	/* RW cmd args (little-endian) */
219 };
220 
221 
222 /*
223  * Version 2 of the interface.
224  *
225  * Some things are carried over, notably the vnic_devcmd_cmd enum.
226  */
227 
228 /*
229  * Flags for vnic_devcmd2.flags
230  */
231 
232 #define DEVCMD2_FNORESULT       0x1     /* Don't copy result to host */
233 
234 #define VNIC_DEVCMD2_NARGS      VNIC_DEVCMD_NARGS
235 struct vnic_devcmd2 {
236 	u16 pad;
237 	u16 flags;
238 	u32 cmd;                /* same command #defines as original */
239 	u64 args[VNIC_DEVCMD2_NARGS];
240 };
241 
242 #define VNIC_DEVCMD2_NRESULTS   VNIC_DEVCMD_NARGS
243 struct devcmd2_result {
244 	u64 results[VNIC_DEVCMD2_NRESULTS];
245 	u32 pad;
246 	u16 completed_index;    /* into copy WQ */
247 	u8  error;              /* same error codes as original */
248 	u8  color;              /* 0 or 1 as with completion queues */
249 };
250 
251 #define DEVCMD2_RING_SIZE   32
252 #define DEVCMD2_DESC_SIZE   128
253 
254 #define DEVCMD2_RESULTS_SIZE_MAX   ((1 << 16) - 1)
255 
256 #endif /* _VNIC_DEVCMD_H_ */
257