bnx2x_sriov.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /* bnx2x_sriov.h: Broadcom Everest network driver.
  2. *
  3. * Copyright 2009-2012 Broadcom Corporation
  4. *
  5. * Unless you and Broadcom execute a separate written software license
  6. * agreement governing use of this software, this software is licensed to you
  7. * under the terms of the GNU General Public License version 2, available
  8. * at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL").
  9. *
  10. * Notwithstanding the above, under no circumstances may you combine this
  11. * software in any way with any other Broadcom software provided under a
  12. * license other than the GPL, without Broadcom's express prior written
  13. * consent.
  14. *
  15. * Maintained by: Eilon Greenstein <eilong@broadcom.com>
  16. * Written by: Shmulik Ravid <shmulikr@broadcom.com>
  17. * Ariel Elior <ariele@broadcom.com>
  18. */
  19. #ifndef BNX2X_SRIOV_H
  20. #define BNX2X_SRIOV_H
  21. /* The bnx2x device structure holds vfdb structure described below.
  22. * The VF array is indexed by the relative vfid.
  23. */
  24. struct bnx2x_sriov {
  25. u32 first_vf_in_pf;
  26. /* standard SRIOV capability fields, mostly for debugging */
  27. int pos; /* capability position */
  28. int nres; /* number of resources */
  29. u32 cap; /* SR-IOV Capabilities */
  30. u16 ctrl; /* SR-IOV Control */
  31. u16 total; /* total VFs associated with the PF */
  32. u16 initial; /* initial VFs associated with the PF */
  33. u16 nr_virtfn; /* number of VFs available */
  34. u16 offset; /* first VF Routing ID offset */
  35. u16 stride; /* following VF stride */
  36. u32 pgsz; /* page size for BAR alignment */
  37. u8 link; /* Function Dependency Link */
  38. };
  39. /* bars */
  40. struct bnx2x_vf_bar {
  41. u64 bar;
  42. u32 size;
  43. };
  44. /* vf queue (used both for rx or tx) */
  45. struct bnx2x_vf_queue {
  46. struct eth_context *cxt;
  47. /* MACs object */
  48. struct bnx2x_vlan_mac_obj mac_obj;
  49. /* VLANs object */
  50. struct bnx2x_vlan_mac_obj vlan_obj;
  51. atomic_t vlan_count; /* 0 means vlan-0 is set ~ untagged */
  52. /* Queue Slow-path State object */
  53. struct bnx2x_queue_sp_obj sp_obj;
  54. u32 cid;
  55. u16 index;
  56. u16 sb_idx;
  57. };
  58. /* struct bnx2x_vfop_qctor_params - prepare queue construction parameters:
  59. * q-init, q-setup and SB index
  60. */
  61. struct bnx2x_vfop_qctor_params {
  62. struct bnx2x_queue_state_params qstate;
  63. struct bnx2x_queue_setup_params prep_qsetup;
  64. };
  65. /* VFOP parameters (one copy per VF) */
  66. union bnx2x_vfop_params {
  67. struct bnx2x_vlan_mac_ramrod_params vlan_mac;
  68. struct bnx2x_rx_mode_ramrod_params rx_mode;
  69. struct bnx2x_mcast_ramrod_params mcast;
  70. struct bnx2x_config_rss_params rss;
  71. struct bnx2x_vfop_qctor_params qctor;
  72. };
  73. /* forward */
  74. struct bnx2x_virtf;
  75. /* vf context */
  76. struct bnx2x_virtf {
  77. u16 cfg_flags;
  78. #define VF_CFG_STATS 0x0001
  79. #define VF_CFG_FW_FC 0x0002
  80. #define VF_CFG_TPA 0x0004
  81. #define VF_CFG_INT_SIMD 0x0008
  82. #define VF_CACHE_LINE 0x0010
  83. u8 state;
  84. #define VF_FREE 0 /* VF ready to be acquired holds no resc */
  85. #define VF_ACQUIRED 1 /* VF aquired, but not initalized */
  86. #define VF_ENABLED 2 /* VF Enabled */
  87. #define VF_RESET 3 /* VF FLR'd, pending cleanup */
  88. /* non 0 during flr cleanup */
  89. u8 flr_clnup_stage;
  90. #define VF_FLR_CLN 1 /* reclaim resources and do 'final cleanup'
  91. * sans the end-wait
  92. */
  93. #define VF_FLR_ACK 2 /* ACK flr notification */
  94. #define VF_FLR_EPILOG 3 /* wait for VF remnants to dissipate in the HW
  95. * ~ final cleanup' end wait
  96. */
  97. /* dma */
  98. dma_addr_t fw_stat_map; /* valid iff VF_CFG_STATS */
  99. dma_addr_t spq_map;
  100. dma_addr_t bulletin_map;
  101. /* Allocated resources counters. Before the VF is acquired, the
  102. * counters hold the following values:
  103. *
  104. * - xxq_count = 0 as the queues memory is not allocated yet.
  105. *
  106. * - sb_count = The number of status blocks configured for this VF in
  107. * the IGU CAM. Initially read during probe.
  108. *
  109. * - xx_rules_count = The number of rules statically and equally
  110. * allocated for each VF, during PF load.
  111. */
  112. struct vf_pf_resc_request alloc_resc;
  113. #define vf_rxq_count(vf) ((vf)->alloc_resc.num_rxqs)
  114. #define vf_txq_count(vf) ((vf)->alloc_resc.num_txqs)
  115. #define vf_sb_count(vf) ((vf)->alloc_resc.num_sbs)
  116. #define vf_mac_rules_cnt(vf) ((vf)->alloc_resc.num_mac_filters)
  117. #define vf_vlan_rules_cnt(vf) ((vf)->alloc_resc.num_vlan_filters)
  118. #define vf_mc_rules_cnt(vf) ((vf)->alloc_resc.num_mc_filters)
  119. u8 sb_count; /* actual number of SBs */
  120. u8 igu_base_id; /* base igu status block id */
  121. struct bnx2x_vf_queue *vfqs;
  122. #define bnx2x_vfq(vf, nr, var) ((vf)->vfqs[(nr)].var)
  123. u8 index; /* index in the vf array */
  124. u8 abs_vfid;
  125. u8 sp_cl_id;
  126. u32 error; /* 0 means all's-well */
  127. /* BDF */
  128. unsigned int bus;
  129. unsigned int devfn;
  130. /* bars */
  131. struct bnx2x_vf_bar bars[PCI_SRIOV_NUM_BARS];
  132. /* set-mac ramrod state 1-pending, 0-done */
  133. unsigned long filter_state;
  134. /* leading rss client id ~~ the client id of the first rxq, must be
  135. * set for each txq.
  136. */
  137. int leading_rss;
  138. /* MCAST object */
  139. struct bnx2x_mcast_obj mcast_obj;
  140. /* RSS configuration object */
  141. struct bnx2x_rss_config_obj rss_conf_obj;
  142. /* slow-path operations */
  143. atomic_t op_in_progress;
  144. int op_rc;
  145. bool op_wait_blocking;
  146. struct list_head op_list_head;
  147. union bnx2x_vfop_params op_params;
  148. struct mutex op_mutex; /* one vfop at a time mutex */
  149. enum channel_tlvs op_current;
  150. };
  151. #define BNX2X_NR_VIRTFN(bp) ((bp)->vfdb->sriov.nr_virtfn)
  152. #define for_each_vf(bp, var) \
  153. for ((var) = 0; (var) < BNX2X_NR_VIRTFN(bp); (var)++)
  154. #define HW_VF_HANDLE(bp, abs_vfid) \
  155. (u16)(BP_ABS_FUNC((bp)) | (1<<3) | ((u16)(abs_vfid) << 4))
  156. #define FW_PF_MAX_HANDLE 8
  157. #define FW_VF_HANDLE(abs_vfid) \
  158. (abs_vfid + FW_PF_MAX_HANDLE)
  159. /* VF mail box (aka vf-pf channel) */
  160. /* a container for the bi-directional vf<-->pf messages.
  161. * The actual response will be placed according to the offset parameter
  162. * provided in the request
  163. */
  164. #define MBX_MSG_ALIGN 8
  165. #define MBX_MSG_ALIGNED_SIZE (roundup(sizeof(struct bnx2x_vf_mbx_msg), \
  166. MBX_MSG_ALIGN))
  167. struct bnx2x_vf_mbx_msg {
  168. union vfpf_tlvs req;
  169. union pfvf_tlvs resp;
  170. };
  171. struct bnx2x_vf_mbx {
  172. struct bnx2x_vf_mbx_msg *msg;
  173. dma_addr_t msg_mapping;
  174. /* VF GPA address */
  175. u32 vf_addr_lo;
  176. u32 vf_addr_hi;
  177. struct vfpf_first_tlv first_tlv; /* saved VF request header */
  178. u8 flags;
  179. #define VF_MSG_INPROCESS 0x1 /* failsafe - the FW should prevent
  180. * more then one pending msg
  181. */
  182. };
  183. struct bnx2x_vf_sp {
  184. union {
  185. struct eth_classify_rules_ramrod_data e2;
  186. } mac_rdata;
  187. union {
  188. struct eth_classify_rules_ramrod_data e2;
  189. } vlan_rdata;
  190. union {
  191. struct eth_filter_rules_ramrod_data e2;
  192. } rx_mode_rdata;
  193. union {
  194. struct eth_multicast_rules_ramrod_data e2;
  195. } mcast_rdata;
  196. union {
  197. struct client_init_ramrod_data init_data;
  198. struct client_update_ramrod_data update_data;
  199. } q_data;
  200. };
  201. struct hw_dma {
  202. void *addr;
  203. dma_addr_t mapping;
  204. size_t size;
  205. };
  206. struct bnx2x_vfdb {
  207. #define BP_VFDB(bp) ((bp)->vfdb)
  208. /* vf array */
  209. struct bnx2x_virtf *vfs;
  210. #define BP_VF(bp, idx) (&((bp)->vfdb->vfs[(idx)]))
  211. #define bnx2x_vf(bp, idx, var) ((bp)->vfdb->vfs[(idx)].var)
  212. /* queue array - for all vfs */
  213. struct bnx2x_vf_queue *vfqs;
  214. /* vf HW contexts */
  215. struct hw_dma context[BNX2X_VF_CIDS/ILT_PAGE_CIDS];
  216. #define BP_VF_CXT_PAGE(bp, i) (&(bp)->vfdb->context[(i)])
  217. /* SR-IOV information */
  218. struct bnx2x_sriov sriov;
  219. struct hw_dma mbx_dma;
  220. #define BP_VF_MBX_DMA(bp) (&((bp)->vfdb->mbx_dma))
  221. struct bnx2x_vf_mbx mbxs[BNX2X_MAX_NUM_OF_VFS];
  222. #define BP_VF_MBX(bp, vfid) (&((bp)->vfdb->mbxs[(vfid)]))
  223. struct hw_dma sp_dma;
  224. #define bnx2x_vf_sp(bp, vf, field) ((bp)->vfdb->sp_dma.addr + \
  225. (vf)->index * sizeof(struct bnx2x_vf_sp) + \
  226. offsetof(struct bnx2x_vf_sp, field))
  227. #define bnx2x_vf_sp_map(bp, vf, field) ((bp)->vfdb->sp_dma.mapping + \
  228. (vf)->index * sizeof(struct bnx2x_vf_sp) + \
  229. offsetof(struct bnx2x_vf_sp, field))
  230. #define FLRD_VFS_DWORDS (BNX2X_MAX_NUM_OF_VFS / 32)
  231. u32 flrd_vfs[FLRD_VFS_DWORDS];
  232. };
  233. static inline u8 vf_igu_sb(struct bnx2x_virtf *vf, u16 sb_idx)
  234. {
  235. return vf->igu_base_id + sb_idx;
  236. }
  237. /* global iov routines */
  238. int bnx2x_iov_init_ilt(struct bnx2x *bp, u16 line);
  239. int bnx2x_iov_init_one(struct bnx2x *bp, int int_mode_param, int num_vfs_param);
  240. void bnx2x_iov_remove_one(struct bnx2x *bp);
  241. void bnx2x_iov_free_mem(struct bnx2x *bp);
  242. int bnx2x_iov_alloc_mem(struct bnx2x *bp);
  243. int bnx2x_iov_nic_init(struct bnx2x *bp);
  244. void bnx2x_iov_init_dq(struct bnx2x *bp);
  245. void bnx2x_iov_init_dmae(struct bnx2x *bp);
  246. void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid);
  247. int bnx2x_vf_idx_by_abs_fid(struct bnx2x *bp, u16 abs_vfid);
  248. /* VF FLR helpers */
  249. int bnx2x_vf_flr_clnup_epilog(struct bnx2x *bp, u8 abs_vfid);
  250. void bnx2x_vf_enable_access(struct bnx2x *bp, u8 abs_vfid);
  251. void bnx2x_add_tlv(struct bnx2x *bp, void *tlvs_list, u16 offset, u16 type,
  252. u16 length);
  253. void bnx2x_vfpf_prep(struct bnx2x *bp, struct vfpf_first_tlv *first_tlv,
  254. u16 type, u16 length);
  255. void bnx2x_dp_tlv_list(struct bnx2x *bp, void *tlvs_list);
  256. #endif /* bnx2x_sriov.h */