bnx2x_sriov.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  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. #define BNX2X_VF_MAX_TPA_AGG_QUEUES 8
  28. struct bnx2x_sriov {
  29. u32 first_vf_in_pf;
  30. /* standard SRIOV capability fields, mostly for debugging */
  31. int pos; /* capability position */
  32. int nres; /* number of resources */
  33. u32 cap; /* SR-IOV Capabilities */
  34. u16 ctrl; /* SR-IOV Control */
  35. u16 total; /* total VFs associated with the PF */
  36. u16 initial; /* initial VFs associated with the PF */
  37. u16 nr_virtfn; /* number of VFs available */
  38. u16 offset; /* first VF Routing ID offset */
  39. u16 stride; /* following VF stride */
  40. u32 pgsz; /* page size for BAR alignment */
  41. u8 link; /* Function Dependency Link */
  42. };
  43. /* bars */
  44. struct bnx2x_vf_bar {
  45. u64 bar;
  46. u32 size;
  47. };
  48. struct bnx2x_vf_bar_info {
  49. struct bnx2x_vf_bar bars[PCI_SRIOV_NUM_BARS];
  50. u8 nr_bars;
  51. };
  52. /* vf queue (used both for rx or tx) */
  53. struct bnx2x_vf_queue {
  54. struct eth_context *cxt;
  55. /* MACs object */
  56. struct bnx2x_vlan_mac_obj mac_obj;
  57. /* VLANs object */
  58. struct bnx2x_vlan_mac_obj vlan_obj;
  59. atomic_t vlan_count; /* 0 means vlan-0 is set ~ untagged */
  60. /* Queue Slow-path State object */
  61. struct bnx2x_queue_sp_obj sp_obj;
  62. u32 cid;
  63. u16 index;
  64. u16 sb_idx;
  65. };
  66. /* struct bnx2x_vfop_qctor_params - prepare queue construction parameters:
  67. * q-init, q-setup and SB index
  68. */
  69. struct bnx2x_vfop_qctor_params {
  70. struct bnx2x_queue_state_params qstate;
  71. struct bnx2x_queue_setup_params prep_qsetup;
  72. };
  73. /* VFOP parameters (one copy per VF) */
  74. union bnx2x_vfop_params {
  75. struct bnx2x_vlan_mac_ramrod_params vlan_mac;
  76. struct bnx2x_rx_mode_ramrod_params rx_mode;
  77. struct bnx2x_mcast_ramrod_params mcast;
  78. struct bnx2x_config_rss_params rss;
  79. struct bnx2x_vfop_qctor_params qctor;
  80. };
  81. /* forward */
  82. struct bnx2x_virtf;
  83. /* VFOP definitions */
  84. typedef void (*vfop_handler_t)(struct bnx2x *bp, struct bnx2x_virtf *vf);
  85. struct bnx2x_vfop_cmd {
  86. vfop_handler_t done;
  87. bool block;
  88. };
  89. /* VFOP queue filters command additional arguments */
  90. struct bnx2x_vfop_filter {
  91. struct list_head link;
  92. int type;
  93. #define BNX2X_VFOP_FILTER_MAC 1
  94. #define BNX2X_VFOP_FILTER_VLAN 2
  95. bool add;
  96. u8 *mac;
  97. u16 vid;
  98. };
  99. struct bnx2x_vfop_filters {
  100. int add_cnt;
  101. struct list_head head;
  102. struct bnx2x_vfop_filter filters[];
  103. };
  104. /* transient list allocated, built and saved until its
  105. * passed to the SP-VERBs layer.
  106. */
  107. struct bnx2x_vfop_args_mcast {
  108. int mc_num;
  109. struct bnx2x_mcast_list_elem *mc;
  110. };
  111. struct bnx2x_vfop_args_qctor {
  112. int qid;
  113. u16 sb_idx;
  114. };
  115. struct bnx2x_vfop_args_qdtor {
  116. int qid;
  117. struct eth_context *cxt;
  118. };
  119. struct bnx2x_vfop_args_defvlan {
  120. int qid;
  121. bool enable;
  122. u16 vid;
  123. u8 prio;
  124. };
  125. struct bnx2x_vfop_args_qx {
  126. int qid;
  127. bool en_add;
  128. };
  129. struct bnx2x_vfop_args_filters {
  130. struct bnx2x_vfop_filters *multi_filter;
  131. atomic_t *credit; /* non NULL means 'don't consume credit' */
  132. };
  133. union bnx2x_vfop_args {
  134. struct bnx2x_vfop_args_mcast mc_list;
  135. struct bnx2x_vfop_args_qctor qctor;
  136. struct bnx2x_vfop_args_qdtor qdtor;
  137. struct bnx2x_vfop_args_defvlan defvlan;
  138. struct bnx2x_vfop_args_qx qx;
  139. struct bnx2x_vfop_args_filters filters;
  140. };
  141. struct bnx2x_vfop {
  142. struct list_head link;
  143. int rc; /* return code */
  144. int state; /* next state */
  145. union bnx2x_vfop_args args; /* extra arguments */
  146. union bnx2x_vfop_params *op_p; /* ramrod params */
  147. /* state machine callbacks */
  148. vfop_handler_t transition;
  149. vfop_handler_t done;
  150. };
  151. /* vf context */
  152. struct bnx2x_virtf {
  153. u16 cfg_flags;
  154. #define VF_CFG_STATS 0x0001
  155. #define VF_CFG_FW_FC 0x0002
  156. #define VF_CFG_TPA 0x0004
  157. #define VF_CFG_INT_SIMD 0x0008
  158. #define VF_CACHE_LINE 0x0010
  159. u8 state;
  160. #define VF_FREE 0 /* VF ready to be acquired holds no resc */
  161. #define VF_ACQUIRED 1 /* VF aquired, but not initalized */
  162. #define VF_ENABLED 2 /* VF Enabled */
  163. #define VF_RESET 3 /* VF FLR'd, pending cleanup */
  164. /* non 0 during flr cleanup */
  165. u8 flr_clnup_stage;
  166. #define VF_FLR_CLN 1 /* reclaim resources and do 'final cleanup'
  167. * sans the end-wait
  168. */
  169. #define VF_FLR_ACK 2 /* ACK flr notification */
  170. #define VF_FLR_EPILOG 3 /* wait for VF remnants to dissipate in the HW
  171. * ~ final cleanup' end wait
  172. */
  173. /* dma */
  174. dma_addr_t fw_stat_map; /* valid iff VF_CFG_STATS */
  175. dma_addr_t spq_map;
  176. dma_addr_t bulletin_map;
  177. /* Allocated resources counters. Before the VF is acquired, the
  178. * counters hold the following values:
  179. *
  180. * - xxq_count = 0 as the queues memory is not allocated yet.
  181. *
  182. * - sb_count = The number of status blocks configured for this VF in
  183. * the IGU CAM. Initially read during probe.
  184. *
  185. * - xx_rules_count = The number of rules statically and equally
  186. * allocated for each VF, during PF load.
  187. */
  188. struct vf_pf_resc_request alloc_resc;
  189. #define vf_rxq_count(vf) ((vf)->alloc_resc.num_rxqs)
  190. #define vf_txq_count(vf) ((vf)->alloc_resc.num_txqs)
  191. #define vf_sb_count(vf) ((vf)->alloc_resc.num_sbs)
  192. #define vf_mac_rules_cnt(vf) ((vf)->alloc_resc.num_mac_filters)
  193. #define vf_vlan_rules_cnt(vf) ((vf)->alloc_resc.num_vlan_filters)
  194. #define vf_mc_rules_cnt(vf) ((vf)->alloc_resc.num_mc_filters)
  195. u8 sb_count; /* actual number of SBs */
  196. u8 igu_base_id; /* base igu status block id */
  197. struct bnx2x_vf_queue *vfqs;
  198. #define bnx2x_vfq(vf, nr, var) ((vf)->vfqs[(nr)].var)
  199. u8 index; /* index in the vf array */
  200. u8 abs_vfid;
  201. u8 sp_cl_id;
  202. u32 error; /* 0 means all's-well */
  203. /* BDF */
  204. unsigned int bus;
  205. unsigned int devfn;
  206. /* bars */
  207. struct bnx2x_vf_bar bars[PCI_SRIOV_NUM_BARS];
  208. /* set-mac ramrod state 1-pending, 0-done */
  209. unsigned long filter_state;
  210. /* leading rss client id ~~ the client id of the first rxq, must be
  211. * set for each txq.
  212. */
  213. int leading_rss;
  214. /* MCAST object */
  215. struct bnx2x_mcast_obj mcast_obj;
  216. /* RSS configuration object */
  217. struct bnx2x_rss_config_obj rss_conf_obj;
  218. /* slow-path operations */
  219. atomic_t op_in_progress;
  220. int op_rc;
  221. bool op_wait_blocking;
  222. struct list_head op_list_head;
  223. union bnx2x_vfop_params op_params;
  224. struct mutex op_mutex; /* one vfop at a time mutex */
  225. enum channel_tlvs op_current;
  226. };
  227. #define BNX2X_NR_VIRTFN(bp) ((bp)->vfdb->sriov.nr_virtfn)
  228. #define for_each_vf(bp, var) \
  229. for ((var) = 0; (var) < BNX2X_NR_VIRTFN(bp); (var)++)
  230. #define for_each_vfq(vf, var) \
  231. for ((var) = 0; (var) < vf_rxq_count(vf); (var)++)
  232. #define for_each_vf_sb(vf, var) \
  233. for ((var) = 0; (var) < vf_sb_count(vf); (var)++)
  234. #define is_vf_multi(vf) (vf_rxq_count(vf) > 1)
  235. #define HW_VF_HANDLE(bp, abs_vfid) \
  236. (u16)(BP_ABS_FUNC((bp)) | (1<<3) | ((u16)(abs_vfid) << 4))
  237. #define FW_PF_MAX_HANDLE 8
  238. #define FW_VF_HANDLE(abs_vfid) \
  239. (abs_vfid + FW_PF_MAX_HANDLE)
  240. /* locking and unlocking the channel mutex */
  241. void bnx2x_lock_vf_pf_channel(struct bnx2x *bp, struct bnx2x_virtf *vf,
  242. enum channel_tlvs tlv);
  243. void bnx2x_unlock_vf_pf_channel(struct bnx2x *bp, struct bnx2x_virtf *vf,
  244. enum channel_tlvs expected_tlv);
  245. /* VF mail box (aka vf-pf channel) */
  246. /* a container for the bi-directional vf<-->pf messages.
  247. * The actual response will be placed according to the offset parameter
  248. * provided in the request
  249. */
  250. #define MBX_MSG_ALIGN 8
  251. #define MBX_MSG_ALIGNED_SIZE (roundup(sizeof(struct bnx2x_vf_mbx_msg), \
  252. MBX_MSG_ALIGN))
  253. struct bnx2x_vf_mbx_msg {
  254. union vfpf_tlvs req;
  255. union pfvf_tlvs resp;
  256. };
  257. struct bnx2x_vf_mbx {
  258. struct bnx2x_vf_mbx_msg *msg;
  259. dma_addr_t msg_mapping;
  260. /* VF GPA address */
  261. u32 vf_addr_lo;
  262. u32 vf_addr_hi;
  263. struct vfpf_first_tlv first_tlv; /* saved VF request header */
  264. u8 flags;
  265. #define VF_MSG_INPROCESS 0x1 /* failsafe - the FW should prevent
  266. * more then one pending msg
  267. */
  268. };
  269. struct bnx2x_vf_sp {
  270. union {
  271. struct eth_classify_rules_ramrod_data e2;
  272. } mac_rdata;
  273. union {
  274. struct eth_classify_rules_ramrod_data e2;
  275. } vlan_rdata;
  276. union {
  277. struct eth_filter_rules_ramrod_data e2;
  278. } rx_mode_rdata;
  279. union {
  280. struct eth_multicast_rules_ramrod_data e2;
  281. } mcast_rdata;
  282. union {
  283. struct client_init_ramrod_data init_data;
  284. struct client_update_ramrod_data update_data;
  285. } q_data;
  286. };
  287. struct hw_dma {
  288. void *addr;
  289. dma_addr_t mapping;
  290. size_t size;
  291. };
  292. struct bnx2x_vfdb {
  293. #define BP_VFDB(bp) ((bp)->vfdb)
  294. /* vf array */
  295. struct bnx2x_virtf *vfs;
  296. #define BP_VF(bp, idx) (&((bp)->vfdb->vfs[(idx)]))
  297. #define bnx2x_vf(bp, idx, var) ((bp)->vfdb->vfs[(idx)].var)
  298. /* queue array - for all vfs */
  299. struct bnx2x_vf_queue *vfqs;
  300. /* vf HW contexts */
  301. struct hw_dma context[BNX2X_VF_CIDS/ILT_PAGE_CIDS];
  302. #define BP_VF_CXT_PAGE(bp, i) (&(bp)->vfdb->context[(i)])
  303. /* SR-IOV information */
  304. struct bnx2x_sriov sriov;
  305. struct hw_dma mbx_dma;
  306. #define BP_VF_MBX_DMA(bp) (&((bp)->vfdb->mbx_dma))
  307. struct bnx2x_vf_mbx mbxs[BNX2X_MAX_NUM_OF_VFS];
  308. #define BP_VF_MBX(bp, vfid) (&((bp)->vfdb->mbxs[(vfid)]))
  309. struct hw_dma sp_dma;
  310. #define bnx2x_vf_sp(bp, vf, field) ((bp)->vfdb->sp_dma.addr + \
  311. (vf)->index * sizeof(struct bnx2x_vf_sp) + \
  312. offsetof(struct bnx2x_vf_sp, field))
  313. #define bnx2x_vf_sp_map(bp, vf, field) ((bp)->vfdb->sp_dma.mapping + \
  314. (vf)->index * sizeof(struct bnx2x_vf_sp) + \
  315. offsetof(struct bnx2x_vf_sp, field))
  316. #define FLRD_VFS_DWORDS (BNX2X_MAX_NUM_OF_VFS / 32)
  317. u32 flrd_vfs[FLRD_VFS_DWORDS];
  318. };
  319. /* queue access */
  320. static inline struct bnx2x_vf_queue *vfq_get(struct bnx2x_virtf *vf, u8 index)
  321. {
  322. return &(vf->vfqs[index]);
  323. }
  324. static inline bool vfq_is_leading(struct bnx2x_vf_queue *vfq)
  325. {
  326. return (vfq->index == 0);
  327. }
  328. /* FW ids */
  329. static inline u8 vf_igu_sb(struct bnx2x_virtf *vf, u16 sb_idx)
  330. {
  331. return vf->igu_base_id + sb_idx;
  332. }
  333. static inline u8 vf_hc_qzone(struct bnx2x_virtf *vf, u16 sb_idx)
  334. {
  335. return vf_igu_sb(vf, sb_idx);
  336. }
  337. static u8 vfq_cl_id(struct bnx2x_virtf *vf, struct bnx2x_vf_queue *q)
  338. {
  339. return vf->igu_base_id + q->index;
  340. }
  341. static inline u8 vfq_stat_id(struct bnx2x_virtf *vf, struct bnx2x_vf_queue *q)
  342. {
  343. return vfq_cl_id(vf, q);
  344. }
  345. static inline u8 vfq_qzone_id(struct bnx2x_virtf *vf, struct bnx2x_vf_queue *q)
  346. {
  347. return vfq_cl_id(vf, q);
  348. }
  349. /* global iov routines */
  350. int bnx2x_iov_init_ilt(struct bnx2x *bp, u16 line);
  351. int bnx2x_iov_init_one(struct bnx2x *bp, int int_mode_param, int num_vfs_param);
  352. void bnx2x_iov_remove_one(struct bnx2x *bp);
  353. void bnx2x_iov_free_mem(struct bnx2x *bp);
  354. int bnx2x_iov_alloc_mem(struct bnx2x *bp);
  355. int bnx2x_iov_nic_init(struct bnx2x *bp);
  356. int bnx2x_iov_chip_cleanup(struct bnx2x *bp);
  357. void bnx2x_iov_init_dq(struct bnx2x *bp);
  358. void bnx2x_iov_init_dmae(struct bnx2x *bp);
  359. void bnx2x_iov_set_queue_sp_obj(struct bnx2x *bp, int vf_cid,
  360. struct bnx2x_queue_sp_obj **q_obj);
  361. void bnx2x_iov_sp_event(struct bnx2x *bp, int vf_cid, bool queue_work);
  362. int bnx2x_iov_eq_sp_event(struct bnx2x *bp, union event_ring_elem *elem);
  363. void bnx2x_iov_adjust_stats_req(struct bnx2x *bp);
  364. void bnx2x_iov_storm_stats_update(struct bnx2x *bp);
  365. void bnx2x_iov_sp_task(struct bnx2x *bp);
  366. /* global vf mailbox routines */
  367. void bnx2x_vf_mbx(struct bnx2x *bp, struct vf_pf_event_data *vfpf_event);
  368. void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid);
  369. /* CORE VF API */
  370. typedef u8 bnx2x_mac_addr_t[ETH_ALEN];
  371. /* acquire */
  372. int bnx2x_vf_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
  373. struct vf_pf_resc_request *resc);
  374. /* init */
  375. int bnx2x_vf_init(struct bnx2x *bp, struct bnx2x_virtf *vf,
  376. dma_addr_t *sb_map);
  377. /* VFOP generic helpers */
  378. #define bnx2x_vfop_default(state) do { \
  379. BNX2X_ERR("Bad state %d\n", (state)); \
  380. vfop->rc = -EINVAL; \
  381. goto op_err; \
  382. } while (0)
  383. enum {
  384. VFOP_DONE,
  385. VFOP_CONT,
  386. VFOP_VERIFY_PEND,
  387. };
  388. #define bnx2x_vfop_finalize(vf, rc, next) do { \
  389. if ((rc) < 0) \
  390. goto op_err; \
  391. else if ((rc) > 0) \
  392. goto op_pending; \
  393. else if ((next) == VFOP_DONE) \
  394. goto op_done; \
  395. else if ((next) == VFOP_VERIFY_PEND) \
  396. BNX2X_ERR("expected pending\n"); \
  397. else { \
  398. DP(BNX2X_MSG_IOV, "no ramrod. scheduling\n"); \
  399. atomic_set(&vf->op_in_progress, 1); \
  400. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0); \
  401. return; \
  402. } \
  403. } while (0)
  404. #define bnx2x_vfop_opset(first_state, trans_hndlr, done_hndlr) \
  405. do { \
  406. vfop->state = first_state; \
  407. vfop->op_p = &vf->op_params; \
  408. vfop->transition = trans_hndlr; \
  409. vfop->done = done_hndlr; \
  410. } while (0)
  411. static inline struct bnx2x_vfop *bnx2x_vfop_cur(struct bnx2x *bp,
  412. struct bnx2x_virtf *vf)
  413. {
  414. WARN(!mutex_is_locked(&vf->op_mutex), "about to access vf op linked list but mutex was not locked!");
  415. WARN_ON(list_empty(&vf->op_list_head));
  416. return list_first_entry(&vf->op_list_head, struct bnx2x_vfop, link);
  417. }
  418. static inline struct bnx2x_vfop *bnx2x_vfop_add(struct bnx2x *bp,
  419. struct bnx2x_virtf *vf)
  420. {
  421. struct bnx2x_vfop *vfop = kzalloc(sizeof(*vfop), GFP_KERNEL);
  422. WARN(!mutex_is_locked(&vf->op_mutex), "about to access vf op linked list but mutex was not locked!");
  423. if (vfop) {
  424. INIT_LIST_HEAD(&vfop->link);
  425. list_add(&vfop->link, &vf->op_list_head);
  426. }
  427. return vfop;
  428. }
  429. static inline void bnx2x_vfop_end(struct bnx2x *bp, struct bnx2x_virtf *vf,
  430. struct bnx2x_vfop *vfop)
  431. {
  432. /* rc < 0 - error, otherwise set to 0 */
  433. DP(BNX2X_MSG_IOV, "rc was %d\n", vfop->rc);
  434. if (vfop->rc >= 0)
  435. vfop->rc = 0;
  436. DP(BNX2X_MSG_IOV, "rc is now %d\n", vfop->rc);
  437. /* unlink the current op context and propagate error code
  438. * must be done before invoking the 'done()' handler
  439. */
  440. WARN(!mutex_is_locked(&vf->op_mutex),
  441. "about to access vf op linked list but mutex was not locked!");
  442. list_del(&vfop->link);
  443. if (list_empty(&vf->op_list_head)) {
  444. DP(BNX2X_MSG_IOV, "list was empty %d\n", vfop->rc);
  445. vf->op_rc = vfop->rc;
  446. DP(BNX2X_MSG_IOV, "copying rc vf->op_rc %d, vfop->rc %d\n",
  447. vf->op_rc, vfop->rc);
  448. } else {
  449. struct bnx2x_vfop *cur_vfop;
  450. DP(BNX2X_MSG_IOV, "list not empty %d\n", vfop->rc);
  451. cur_vfop = bnx2x_vfop_cur(bp, vf);
  452. cur_vfop->rc = vfop->rc;
  453. DP(BNX2X_MSG_IOV, "copying rc vf->op_rc %d, vfop->rc %d\n",
  454. vf->op_rc, vfop->rc);
  455. }
  456. /* invoke done handler */
  457. if (vfop->done) {
  458. DP(BNX2X_MSG_IOV, "calling done handler\n");
  459. vfop->done(bp, vf);
  460. } else {
  461. /* there is no done handler for the operation to unlock
  462. * the mutex. Must have gotten here from PF initiated VF RELEASE
  463. */
  464. bnx2x_unlock_vf_pf_channel(bp, vf, CHANNEL_TLV_PF_RELEASE_VF);
  465. }
  466. DP(BNX2X_MSG_IOV, "done handler complete. vf->op_rc %d, vfop->rc %d\n",
  467. vf->op_rc, vfop->rc);
  468. /* if this is the last nested op reset the wait_blocking flag
  469. * to release any blocking wrappers, only after 'done()' is invoked
  470. */
  471. if (list_empty(&vf->op_list_head)) {
  472. DP(BNX2X_MSG_IOV, "list was empty after done %d\n", vfop->rc);
  473. vf->op_wait_blocking = false;
  474. }
  475. kfree(vfop);
  476. }
  477. static inline int bnx2x_vfop_wait_blocking(struct bnx2x *bp,
  478. struct bnx2x_virtf *vf)
  479. {
  480. /* can take a while if any port is running */
  481. int cnt = 5000;
  482. might_sleep();
  483. while (cnt--) {
  484. if (vf->op_wait_blocking == false) {
  485. #ifdef BNX2X_STOP_ON_ERROR
  486. DP(BNX2X_MSG_IOV, "exit (cnt %d)\n", 5000 - cnt);
  487. #endif
  488. return 0;
  489. }
  490. usleep_range(1000, 2000);
  491. if (bp->panic)
  492. return -EIO;
  493. }
  494. /* timeout! */
  495. #ifdef BNX2X_STOP_ON_ERROR
  496. bnx2x_panic();
  497. #endif
  498. return -EBUSY;
  499. }
  500. static inline int bnx2x_vfop_transition(struct bnx2x *bp,
  501. struct bnx2x_virtf *vf,
  502. vfop_handler_t transition,
  503. bool block)
  504. {
  505. if (block)
  506. vf->op_wait_blocking = true;
  507. transition(bp, vf);
  508. if (block)
  509. return bnx2x_vfop_wait_blocking(bp, vf);
  510. return 0;
  511. }
  512. /* VFOP queue construction helpers */
  513. void bnx2x_vfop_qctor_dump_tx(struct bnx2x *bp, struct bnx2x_virtf *vf,
  514. struct bnx2x_queue_init_params *init_params,
  515. struct bnx2x_queue_setup_params *setup_params,
  516. u16 q_idx, u16 sb_idx);
  517. void bnx2x_vfop_qctor_dump_rx(struct bnx2x *bp, struct bnx2x_virtf *vf,
  518. struct bnx2x_queue_init_params *init_params,
  519. struct bnx2x_queue_setup_params *setup_params,
  520. u16 q_idx, u16 sb_idx);
  521. void bnx2x_vfop_qctor_prep(struct bnx2x *bp,
  522. struct bnx2x_virtf *vf,
  523. struct bnx2x_vf_queue *q,
  524. struct bnx2x_vfop_qctor_params *p,
  525. unsigned long q_type);
  526. int bnx2x_vfop_mac_list_cmd(struct bnx2x *bp,
  527. struct bnx2x_virtf *vf,
  528. struct bnx2x_vfop_cmd *cmd,
  529. struct bnx2x_vfop_filters *macs,
  530. int qid, bool drv_only);
  531. int bnx2x_vfop_vlan_set_cmd(struct bnx2x *bp,
  532. struct bnx2x_virtf *vf,
  533. struct bnx2x_vfop_cmd *cmd,
  534. int qid, u16 vid, bool add);
  535. int bnx2x_vfop_vlan_list_cmd(struct bnx2x *bp,
  536. struct bnx2x_virtf *vf,
  537. struct bnx2x_vfop_cmd *cmd,
  538. struct bnx2x_vfop_filters *vlans,
  539. int qid, bool drv_only);
  540. int bnx2x_vfop_qsetup_cmd(struct bnx2x *bp,
  541. struct bnx2x_virtf *vf,
  542. struct bnx2x_vfop_cmd *cmd,
  543. int qid);
  544. int bnx2x_vfop_qdown_cmd(struct bnx2x *bp,
  545. struct bnx2x_virtf *vf,
  546. struct bnx2x_vfop_cmd *cmd,
  547. int qid);
  548. int bnx2x_vfop_mcast_cmd(struct bnx2x *bp,
  549. struct bnx2x_virtf *vf,
  550. struct bnx2x_vfop_cmd *cmd,
  551. bnx2x_mac_addr_t *mcasts,
  552. int mcast_num, bool drv_only);
  553. int bnx2x_vfop_rxmode_cmd(struct bnx2x *bp,
  554. struct bnx2x_virtf *vf,
  555. struct bnx2x_vfop_cmd *cmd,
  556. int qid, unsigned long accept_flags);
  557. int bnx2x_vfop_close_cmd(struct bnx2x *bp,
  558. struct bnx2x_virtf *vf,
  559. struct bnx2x_vfop_cmd *cmd);
  560. int bnx2x_vfop_release_cmd(struct bnx2x *bp,
  561. struct bnx2x_virtf *vf,
  562. struct bnx2x_vfop_cmd *cmd);
  563. /* VF release ~ VF close + VF release-resources
  564. *
  565. * Release is the ultimate SW shutdown and is called whenever an
  566. * irrecoverable error is encountered.
  567. */
  568. void bnx2x_vf_release(struct bnx2x *bp, struct bnx2x_virtf *vf, bool block);
  569. int bnx2x_vf_idx_by_abs_fid(struct bnx2x *bp, u16 abs_vfid);
  570. u8 bnx2x_vf_max_queue_cnt(struct bnx2x *bp, struct bnx2x_virtf *vf);
  571. /* VF FLR helpers */
  572. int bnx2x_vf_flr_clnup_epilog(struct bnx2x *bp, u8 abs_vfid);
  573. void bnx2x_vf_enable_access(struct bnx2x *bp, u8 abs_vfid);
  574. void bnx2x_add_tlv(struct bnx2x *bp, void *tlvs_list, u16 offset, u16 type,
  575. u16 length);
  576. void bnx2x_vfpf_prep(struct bnx2x *bp, struct vfpf_first_tlv *first_tlv,
  577. u16 type, u16 length);
  578. void bnx2x_dp_tlv_list(struct bnx2x *bp, void *tlvs_list);
  579. bool bnx2x_tlv_supported(u16 tlvtype);
  580. #endif /* bnx2x_sriov.h */