vnic_devcmd.h 7.9 KB

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