bnx2x_sriov.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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. #include "bnx2x_vfpf.h"
  22. #include "bnx2x_cmn.h"
  23. /* The bnx2x device structure holds vfdb structure described below.
  24. * The VF array is indexed by the relative vfid.
  25. */
  26. #define BNX2X_VF_MAX_QUEUES 16
  27. struct bnx2x_sriov {
  28. u32 first_vf_in_pf;
  29. /* standard SRIOV capability fields, mostly for debugging */
  30. int pos; /* capability position */
  31. int nres; /* number of resources */
  32. u32 cap; /* SR-IOV Capabilities */
  33. u16 ctrl; /* SR-IOV Control */
  34. u16 total; /* total VFs associated with the PF */
  35. u16 initial; /* initial VFs associated with the PF */
  36. u16 nr_virtfn; /* number of VFs available */
  37. u16 offset; /* first VF Routing ID offset */
  38. u16 stride; /* following VF stride */
  39. u32 pgsz; /* page size for BAR alignment */
  40. u8 link; /* Function Dependency Link */
  41. };
  42. /* bars */
  43. struct bnx2x_vf_bar {
  44. u64 bar;
  45. u32 size;
  46. };
  47. /* vf queue (used both for rx or tx) */
  48. struct bnx2x_vf_queue {
  49. struct eth_context *cxt;
  50. /* MACs object */
  51. struct bnx2x_vlan_mac_obj mac_obj;
  52. /* VLANs object */
  53. struct bnx2x_vlan_mac_obj vlan_obj;
  54. atomic_t vlan_count; /* 0 means vlan-0 is set ~ untagged */
  55. /* Queue Slow-path State object */
  56. struct bnx2x_queue_sp_obj sp_obj;
  57. u32 cid;
  58. u16 index;
  59. u16 sb_idx;
  60. };
  61. /* struct bnx2x_vfop_qctor_params - prepare queue construction parameters:
  62. * q-init, q-setup and SB index
  63. */
  64. struct bnx2x_vfop_qctor_params {
  65. struct bnx2x_queue_state_params qstate;
  66. struct bnx2x_queue_setup_params prep_qsetup;
  67. };
  68. /* VFOP parameters (one copy per VF) */
  69. union bnx2x_vfop_params {
  70. struct bnx2x_vlan_mac_ramrod_params vlan_mac;
  71. struct bnx2x_rx_mode_ramrod_params rx_mode;
  72. struct bnx2x_mcast_ramrod_params mcast;
  73. struct bnx2x_config_rss_params rss;
  74. struct bnx2x_vfop_qctor_params qctor;
  75. };
  76. /* forward */
  77. struct bnx2x_virtf;
  78. /* VFOP definitions */
  79. typedef void (*vfop_handler_t)(struct bnx2x *bp, struct bnx2x_virtf *vf);
  80. /* VFOP queue filters command additional arguments */
  81. struct bnx2x_vfop_filter {
  82. struct list_head link;
  83. int type;
  84. #define BNX2X_VFOP_FILTER_MAC 1
  85. #define BNX2X_VFOP_FILTER_VLAN 2
  86. bool add;
  87. u8 *mac;
  88. u16 vid;
  89. };
  90. struct bnx2x_vfop_filters {
  91. int add_cnt;
  92. struct list_head head;
  93. struct bnx2x_vfop_filter filters[];
  94. };
  95. /* transient list allocated, built and saved until its
  96. * passed to the SP-VERBs layer.
  97. */
  98. struct bnx2x_vfop_args_mcast {
  99. int mc_num;
  100. struct bnx2x_mcast_list_elem *mc;
  101. };
  102. struct bnx2x_vfop_args_qctor {
  103. int qid;
  104. u16 sb_idx;
  105. };
  106. struct bnx2x_vfop_args_qdtor {
  107. int qid;
  108. struct eth_context *cxt;
  109. };
  110. struct bnx2x_vfop_args_defvlan {
  111. int qid;
  112. bool enable;
  113. u16 vid;
  114. u8 prio;
  115. };
  116. struct bnx2x_vfop_args_qx {
  117. int qid;
  118. bool en_add;
  119. };
  120. struct bnx2x_vfop_args_filters {
  121. struct bnx2x_vfop_filters *multi_filter;
  122. atomic_t *credit; /* non NULL means 'don't consume credit' */
  123. };
  124. union bnx2x_vfop_args {
  125. struct bnx2x_vfop_args_mcast mc_list;
  126. struct bnx2x_vfop_args_qctor qctor;
  127. struct bnx2x_vfop_args_qdtor qdtor;
  128. struct bnx2x_vfop_args_defvlan defvlan;
  129. struct bnx2x_vfop_args_qx qx;
  130. struct bnx2x_vfop_args_filters filters;
  131. };
  132. struct bnx2x_vfop {
  133. struct list_head link;
  134. int rc; /* return code */
  135. int state; /* next state */
  136. union bnx2x_vfop_args args; /* extra arguments */
  137. union bnx2x_vfop_params *op_p; /* ramrod params */
  138. /* state machine callbacks */
  139. vfop_handler_t transition;
  140. vfop_handler_t done;
  141. };
  142. /* vf context */
  143. struct bnx2x_virtf {
  144. u16 cfg_flags;
  145. #define VF_CFG_STATS 0x0001
  146. #define VF_CFG_FW_FC 0x0002
  147. #define VF_CFG_TPA 0x0004
  148. #define VF_CFG_INT_SIMD 0x0008
  149. #define VF_CACHE_LINE 0x0010
  150. u8 state;
  151. #define VF_FREE 0 /* VF ready to be acquired holds no resc */
  152. #define VF_ACQUIRED 1 /* VF aquired, but not initalized */
  153. #define VF_ENABLED 2 /* VF Enabled */
  154. #define VF_RESET 3 /* VF FLR'd, pending cleanup */
  155. /* non 0 during flr cleanup */
  156. u8 flr_clnup_stage;
  157. #define VF_FLR_CLN 1 /* reclaim resources and do 'final cleanup'
  158. * sans the end-wait
  159. */
  160. #define VF_FLR_ACK 2 /* ACK flr notification */
  161. #define VF_FLR_EPILOG 3 /* wait for VF remnants to dissipate in the HW
  162. * ~ final cleanup' end wait
  163. */
  164. /* dma */
  165. dma_addr_t fw_stat_map; /* valid iff VF_CFG_STATS */
  166. dma_addr_t spq_map;
  167. dma_addr_t bulletin_map;
  168. /* Allocated resources counters. Before the VF is acquired, the
  169. * counters hold the following values:
  170. *
  171. * - xxq_count = 0 as the queues memory is not allocated yet.
  172. *
  173. * - sb_count = The number of status blocks configured for this VF in
  174. * the IGU CAM. Initially read during probe.
  175. *
  176. * - xx_rules_count = The number of rules statically and equally
  177. * allocated for each VF, during PF load.
  178. */
  179. struct vf_pf_resc_request alloc_resc;
  180. #define vf_rxq_count(vf) ((vf)->alloc_resc.num_rxqs)
  181. #define vf_txq_count(vf) ((vf)->alloc_resc.num_txqs)
  182. #define vf_sb_count(vf) ((vf)->alloc_resc.num_sbs)
  183. #define vf_mac_rules_cnt(vf) ((vf)->alloc_resc.num_mac_filters)
  184. #define vf_vlan_rules_cnt(vf) ((vf)->alloc_resc.num_vlan_filters)
  185. #define vf_mc_rules_cnt(vf) ((vf)->alloc_resc.num_mc_filters)
  186. u8 sb_count; /* actual number of SBs */
  187. u8 igu_base_id; /* base igu status block id */
  188. struct bnx2x_vf_queue *vfqs;
  189. #define bnx2x_vfq(vf, nr, var) ((vf)->vfqs[(nr)].var)
  190. u8 index; /* index in the vf array */
  191. u8 abs_vfid;
  192. u8 sp_cl_id;
  193. u32 error; /* 0 means all's-well */
  194. /* BDF */
  195. unsigned int bus;
  196. unsigned int devfn;
  197. /* bars */
  198. struct bnx2x_vf_bar bars[PCI_SRIOV_NUM_BARS];
  199. /* set-mac ramrod state 1-pending, 0-done */
  200. unsigned long filter_state;
  201. /* leading rss client id ~~ the client id of the first rxq, must be
  202. * set for each txq.
  203. */
  204. int leading_rss;
  205. /* MCAST object */
  206. struct bnx2x_mcast_obj mcast_obj;
  207. /* RSS configuration object */
  208. struct bnx2x_rss_config_obj rss_conf_obj;
  209. /* slow-path operations */
  210. atomic_t op_in_progress;
  211. int op_rc;
  212. bool op_wait_blocking;
  213. struct list_head op_list_head;
  214. union bnx2x_vfop_params op_params;
  215. struct mutex op_mutex; /* one vfop at a time mutex */
  216. enum channel_tlvs op_current;
  217. };
  218. #define BNX2X_NR_VIRTFN(bp) ((bp)->vfdb->sriov.nr_virtfn)
  219. #define for_each_vf(bp, var) \
  220. for ((var) = 0; (var) < BNX2X_NR_VIRTFN(bp); (var)++)
  221. #define for_each_vfq(vf, var) \
  222. for ((var) = 0; (var) < vf_rxq_count(vf); (var)++)
  223. #define for_each_vf_sb(vf, var) \
  224. for ((var) = 0; (var) < vf_sb_count(vf); (var)++)
  225. #define is_vf_multi(vf) (vf_rxq_count(vf) > 1)
  226. #define HW_VF_HANDLE(bp, abs_vfid) \
  227. (u16)(BP_ABS_FUNC((bp)) | (1<<3) | ((u16)(abs_vfid) << 4))
  228. #define FW_PF_MAX_HANDLE 8
  229. #define FW_VF_HANDLE(abs_vfid) \
  230. (abs_vfid + FW_PF_MAX_HANDLE)
  231. /* locking and unlocking the channel mutex */
  232. void bnx2x_lock_vf_pf_channel(struct bnx2x *bp, struct bnx2x_virtf *vf,
  233. enum channel_tlvs tlv);
  234. void bnx2x_unlock_vf_pf_channel(struct bnx2x *bp, struct bnx2x_virtf *vf,
  235. enum channel_tlvs expected_tlv);
  236. /* VF mail box (aka vf-pf channel) */
  237. /* a container for the bi-directional vf<-->pf messages.
  238. * The actual response will be placed according to the offset parameter
  239. * provided in the request
  240. */
  241. #define MBX_MSG_ALIGN 8
  242. #define MBX_MSG_ALIGNED_SIZE (roundup(sizeof(struct bnx2x_vf_mbx_msg), \
  243. MBX_MSG_ALIGN))
  244. struct bnx2x_vf_mbx_msg {
  245. union vfpf_tlvs req;
  246. union pfvf_tlvs resp;
  247. };
  248. struct bnx2x_vf_mbx {
  249. struct bnx2x_vf_mbx_msg *msg;
  250. dma_addr_t msg_mapping;
  251. /* VF GPA address */
  252. u32 vf_addr_lo;
  253. u32 vf_addr_hi;
  254. struct vfpf_first_tlv first_tlv; /* saved VF request header */
  255. u8 flags;
  256. #define VF_MSG_INPROCESS 0x1 /* failsafe - the FW should prevent
  257. * more then one pending msg
  258. */
  259. };
  260. struct bnx2x_vf_sp {
  261. union {
  262. struct eth_classify_rules_ramrod_data e2;
  263. } mac_rdata;
  264. union {
  265. struct eth_classify_rules_ramrod_data e2;
  266. } vlan_rdata;
  267. union {
  268. struct eth_filter_rules_ramrod_data e2;
  269. } rx_mode_rdata;
  270. union {
  271. struct eth_multicast_rules_ramrod_data e2;
  272. } mcast_rdata;
  273. union {
  274. struct client_init_ramrod_data init_data;
  275. struct client_update_ramrod_data update_data;
  276. } q_data;
  277. };
  278. struct hw_dma {
  279. void *addr;
  280. dma_addr_t mapping;
  281. size_t size;
  282. };
  283. struct bnx2x_vfdb {
  284. #define BP_VFDB(bp) ((bp)->vfdb)
  285. /* vf array */
  286. struct bnx2x_virtf *vfs;
  287. #define BP_VF(bp, idx) (&((bp)->vfdb->vfs[(idx)]))
  288. #define bnx2x_vf(bp, idx, var) ((bp)->vfdb->vfs[(idx)].var)
  289. /* queue array - for all vfs */
  290. struct bnx2x_vf_queue *vfqs;
  291. /* vf HW contexts */
  292. struct hw_dma context[BNX2X_VF_CIDS/ILT_PAGE_CIDS];
  293. #define BP_VF_CXT_PAGE(bp, i) (&(bp)->vfdb->context[(i)])
  294. /* SR-IOV information */
  295. struct bnx2x_sriov sriov;
  296. struct hw_dma mbx_dma;
  297. #define BP_VF_MBX_DMA(bp) (&((bp)->vfdb->mbx_dma))
  298. struct bnx2x_vf_mbx mbxs[BNX2X_MAX_NUM_OF_VFS];
  299. #define BP_VF_MBX(bp, vfid) (&((bp)->vfdb->mbxs[(vfid)]))
  300. struct hw_dma sp_dma;
  301. #define bnx2x_vf_sp(bp, vf, field) ((bp)->vfdb->sp_dma.addr + \
  302. (vf)->index * sizeof(struct bnx2x_vf_sp) + \
  303. offsetof(struct bnx2x_vf_sp, field))
  304. #define bnx2x_vf_sp_map(bp, vf, field) ((bp)->vfdb->sp_dma.mapping + \
  305. (vf)->index * sizeof(struct bnx2x_vf_sp) + \
  306. offsetof(struct bnx2x_vf_sp, field))
  307. #define FLRD_VFS_DWORDS (BNX2X_MAX_NUM_OF_VFS / 32)
  308. u32 flrd_vfs[FLRD_VFS_DWORDS];
  309. };
  310. /* queue access */
  311. static inline struct bnx2x_vf_queue *vfq_get(struct bnx2x_virtf *vf, u8 index)
  312. {
  313. return &(vf->vfqs[index]);
  314. }
  315. static inline bool vfq_is_leading(struct bnx2x_vf_queue *vfq)
  316. {
  317. return (vfq->index == 0);
  318. }
  319. /* FW ids */
  320. static inline u8 vf_igu_sb(struct bnx2x_virtf *vf, u16 sb_idx)
  321. {
  322. return vf->igu_base_id + sb_idx;
  323. }
  324. static inline u8 vf_hc_qzone(struct bnx2x_virtf *vf, u16 sb_idx)
  325. {
  326. return vf_igu_sb(vf, sb_idx);
  327. }
  328. static u8 vfq_cl_id(struct bnx2x_virtf *vf, struct bnx2x_vf_queue *q)
  329. {
  330. return vf->igu_base_id + q->index;
  331. }
  332. static inline u8 vfq_qzone_id(struct bnx2x_virtf *vf, struct bnx2x_vf_queue *q)
  333. {
  334. return vfq_cl_id(vf, q);
  335. }
  336. /* global iov routines */
  337. int bnx2x_iov_init_ilt(struct bnx2x *bp, u16 line);
  338. int bnx2x_iov_init_one(struct bnx2x *bp, int int_mode_param, int num_vfs_param);
  339. void bnx2x_iov_remove_one(struct bnx2x *bp);
  340. void bnx2x_iov_free_mem(struct bnx2x *bp);
  341. int bnx2x_iov_alloc_mem(struct bnx2x *bp);
  342. int bnx2x_iov_nic_init(struct bnx2x *bp);
  343. void bnx2x_iov_init_dq(struct bnx2x *bp);
  344. void bnx2x_iov_init_dmae(struct bnx2x *bp);
  345. void bnx2x_iov_set_queue_sp_obj(struct bnx2x *bp, int vf_cid,
  346. struct bnx2x_queue_sp_obj **q_obj);
  347. void bnx2x_iov_sp_event(struct bnx2x *bp, int vf_cid, bool queue_work);
  348. int bnx2x_iov_eq_sp_event(struct bnx2x *bp, union event_ring_elem *elem);
  349. void bnx2x_iov_adjust_stats_req(struct bnx2x *bp);
  350. void bnx2x_iov_storm_stats_update(struct bnx2x *bp);
  351. void bnx2x_iov_sp_task(struct bnx2x *bp);
  352. /* global vf mailbox routines */
  353. void bnx2x_vf_mbx(struct bnx2x *bp, struct vf_pf_event_data *vfpf_event);
  354. void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid);
  355. /* acquire */
  356. int bnx2x_vf_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
  357. struct vf_pf_resc_request *resc);
  358. /* init */
  359. int bnx2x_vf_init(struct bnx2x *bp, struct bnx2x_virtf *vf,
  360. dma_addr_t *sb_map);
  361. static inline struct bnx2x_vfop *bnx2x_vfop_cur(struct bnx2x *bp,
  362. struct bnx2x_virtf *vf)
  363. {
  364. WARN(!mutex_is_locked(&vf->op_mutex), "about to access vf op linked list but mutex was not locked!");
  365. WARN_ON(list_empty(&vf->op_list_head));
  366. return list_first_entry(&vf->op_list_head, struct bnx2x_vfop, link);
  367. }
  368. int bnx2x_vf_idx_by_abs_fid(struct bnx2x *bp, u16 abs_vfid);
  369. u8 bnx2x_vf_max_queue_cnt(struct bnx2x *bp, struct bnx2x_virtf *vf);
  370. /* VF FLR helpers */
  371. int bnx2x_vf_flr_clnup_epilog(struct bnx2x *bp, u8 abs_vfid);
  372. void bnx2x_vf_enable_access(struct bnx2x *bp, u8 abs_vfid);
  373. void bnx2x_add_tlv(struct bnx2x *bp, void *tlvs_list, u16 offset, u16 type,
  374. u16 length);
  375. void bnx2x_vfpf_prep(struct bnx2x *bp, struct vfpf_first_tlv *first_tlv,
  376. u16 type, u16 length);
  377. void bnx2x_dp_tlv_list(struct bnx2x *bp, void *tlvs_list);
  378. bool bnx2x_tlv_supported(u16 tlvtype);
  379. #endif /* bnx2x_sriov.h */