bnx2x_sriov.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  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 bulletin_dma;
  310. #define BP_VF_BULLETIN_DMA(bp) (&((bp)->vfdb->bulletin_dma))
  311. #define BP_VF_BULLETIN(bp, vf) \
  312. (((struct pf_vf_bulletin_content *)(BP_VF_BULLETIN_DMA(bp)->addr)) \
  313. + (vf))
  314. struct hw_dma sp_dma;
  315. #define bnx2x_vf_sp(bp, vf, field) ((bp)->vfdb->sp_dma.addr + \
  316. (vf)->index * sizeof(struct bnx2x_vf_sp) + \
  317. offsetof(struct bnx2x_vf_sp, field))
  318. #define bnx2x_vf_sp_map(bp, vf, field) ((bp)->vfdb->sp_dma.mapping + \
  319. (vf)->index * sizeof(struct bnx2x_vf_sp) + \
  320. offsetof(struct bnx2x_vf_sp, field))
  321. #define FLRD_VFS_DWORDS (BNX2X_MAX_NUM_OF_VFS / 32)
  322. u32 flrd_vfs[FLRD_VFS_DWORDS];
  323. };
  324. /* queue access */
  325. static inline struct bnx2x_vf_queue *vfq_get(struct bnx2x_virtf *vf, u8 index)
  326. {
  327. return &(vf->vfqs[index]);
  328. }
  329. static inline bool vfq_is_leading(struct bnx2x_vf_queue *vfq)
  330. {
  331. return (vfq->index == 0);
  332. }
  333. /* FW ids */
  334. static inline u8 vf_igu_sb(struct bnx2x_virtf *vf, u16 sb_idx)
  335. {
  336. return vf->igu_base_id + sb_idx;
  337. }
  338. static inline u8 vf_hc_qzone(struct bnx2x_virtf *vf, u16 sb_idx)
  339. {
  340. return vf_igu_sb(vf, sb_idx);
  341. }
  342. static u8 vfq_cl_id(struct bnx2x_virtf *vf, struct bnx2x_vf_queue *q)
  343. {
  344. return vf->igu_base_id + q->index;
  345. }
  346. static inline u8 vfq_stat_id(struct bnx2x_virtf *vf, struct bnx2x_vf_queue *q)
  347. {
  348. return vfq_cl_id(vf, q);
  349. }
  350. static inline u8 vfq_qzone_id(struct bnx2x_virtf *vf, struct bnx2x_vf_queue *q)
  351. {
  352. return vfq_cl_id(vf, q);
  353. }
  354. /* global iov routines */
  355. int bnx2x_iov_init_ilt(struct bnx2x *bp, u16 line);
  356. int bnx2x_iov_init_one(struct bnx2x *bp, int int_mode_param, int num_vfs_param);
  357. void bnx2x_iov_remove_one(struct bnx2x *bp);
  358. void bnx2x_iov_free_mem(struct bnx2x *bp);
  359. int bnx2x_iov_alloc_mem(struct bnx2x *bp);
  360. int bnx2x_iov_nic_init(struct bnx2x *bp);
  361. int bnx2x_iov_chip_cleanup(struct bnx2x *bp);
  362. void bnx2x_iov_init_dq(struct bnx2x *bp);
  363. void bnx2x_iov_init_dmae(struct bnx2x *bp);
  364. void bnx2x_iov_set_queue_sp_obj(struct bnx2x *bp, int vf_cid,
  365. struct bnx2x_queue_sp_obj **q_obj);
  366. void bnx2x_iov_sp_event(struct bnx2x *bp, int vf_cid, bool queue_work);
  367. int bnx2x_iov_eq_sp_event(struct bnx2x *bp, union event_ring_elem *elem);
  368. void bnx2x_iov_adjust_stats_req(struct bnx2x *bp);
  369. void bnx2x_iov_storm_stats_update(struct bnx2x *bp);
  370. void bnx2x_iov_sp_task(struct bnx2x *bp);
  371. /* global vf mailbox routines */
  372. void bnx2x_vf_mbx(struct bnx2x *bp, struct vf_pf_event_data *vfpf_event);
  373. void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid);
  374. /* CORE VF API */
  375. typedef u8 bnx2x_mac_addr_t[ETH_ALEN];
  376. /* acquire */
  377. int bnx2x_vf_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
  378. struct vf_pf_resc_request *resc);
  379. /* init */
  380. int bnx2x_vf_init(struct bnx2x *bp, struct bnx2x_virtf *vf,
  381. dma_addr_t *sb_map);
  382. /* VFOP generic helpers */
  383. #define bnx2x_vfop_default(state) do { \
  384. BNX2X_ERR("Bad state %d\n", (state)); \
  385. vfop->rc = -EINVAL; \
  386. goto op_err; \
  387. } while (0)
  388. enum {
  389. VFOP_DONE,
  390. VFOP_CONT,
  391. VFOP_VERIFY_PEND,
  392. };
  393. #define bnx2x_vfop_finalize(vf, rc, next) do { \
  394. if ((rc) < 0) \
  395. goto op_err; \
  396. else if ((rc) > 0) \
  397. goto op_pending; \
  398. else if ((next) == VFOP_DONE) \
  399. goto op_done; \
  400. else if ((next) == VFOP_VERIFY_PEND) \
  401. BNX2X_ERR("expected pending\n"); \
  402. else { \
  403. DP(BNX2X_MSG_IOV, "no ramrod. scheduling\n"); \
  404. atomic_set(&vf->op_in_progress, 1); \
  405. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0); \
  406. return; \
  407. } \
  408. } while (0)
  409. #define bnx2x_vfop_opset(first_state, trans_hndlr, done_hndlr) \
  410. do { \
  411. vfop->state = first_state; \
  412. vfop->op_p = &vf->op_params; \
  413. vfop->transition = trans_hndlr; \
  414. vfop->done = done_hndlr; \
  415. } while (0)
  416. static inline struct bnx2x_vfop *bnx2x_vfop_cur(struct bnx2x *bp,
  417. struct bnx2x_virtf *vf)
  418. {
  419. WARN(!mutex_is_locked(&vf->op_mutex), "about to access vf op linked list but mutex was not locked!");
  420. WARN_ON(list_empty(&vf->op_list_head));
  421. return list_first_entry(&vf->op_list_head, struct bnx2x_vfop, link);
  422. }
  423. static inline struct bnx2x_vfop *bnx2x_vfop_add(struct bnx2x *bp,
  424. struct bnx2x_virtf *vf)
  425. {
  426. struct bnx2x_vfop *vfop = kzalloc(sizeof(*vfop), GFP_KERNEL);
  427. WARN(!mutex_is_locked(&vf->op_mutex), "about to access vf op linked list but mutex was not locked!");
  428. if (vfop) {
  429. INIT_LIST_HEAD(&vfop->link);
  430. list_add(&vfop->link, &vf->op_list_head);
  431. }
  432. return vfop;
  433. }
  434. static inline void bnx2x_vfop_end(struct bnx2x *bp, struct bnx2x_virtf *vf,
  435. struct bnx2x_vfop *vfop)
  436. {
  437. /* rc < 0 - error, otherwise set to 0 */
  438. DP(BNX2X_MSG_IOV, "rc was %d\n", vfop->rc);
  439. if (vfop->rc >= 0)
  440. vfop->rc = 0;
  441. DP(BNX2X_MSG_IOV, "rc is now %d\n", vfop->rc);
  442. /* unlink the current op context and propagate error code
  443. * must be done before invoking the 'done()' handler
  444. */
  445. WARN(!mutex_is_locked(&vf->op_mutex),
  446. "about to access vf op linked list but mutex was not locked!");
  447. list_del(&vfop->link);
  448. if (list_empty(&vf->op_list_head)) {
  449. DP(BNX2X_MSG_IOV, "list was empty %d\n", vfop->rc);
  450. vf->op_rc = vfop->rc;
  451. DP(BNX2X_MSG_IOV, "copying rc vf->op_rc %d, vfop->rc %d\n",
  452. vf->op_rc, vfop->rc);
  453. } else {
  454. struct bnx2x_vfop *cur_vfop;
  455. DP(BNX2X_MSG_IOV, "list not empty %d\n", vfop->rc);
  456. cur_vfop = bnx2x_vfop_cur(bp, vf);
  457. cur_vfop->rc = vfop->rc;
  458. DP(BNX2X_MSG_IOV, "copying rc vf->op_rc %d, vfop->rc %d\n",
  459. vf->op_rc, vfop->rc);
  460. }
  461. /* invoke done handler */
  462. if (vfop->done) {
  463. DP(BNX2X_MSG_IOV, "calling done handler\n");
  464. vfop->done(bp, vf);
  465. } else {
  466. /* there is no done handler for the operation to unlock
  467. * the mutex. Must have gotten here from PF initiated VF RELEASE
  468. */
  469. bnx2x_unlock_vf_pf_channel(bp, vf, CHANNEL_TLV_PF_RELEASE_VF);
  470. }
  471. DP(BNX2X_MSG_IOV, "done handler complete. vf->op_rc %d, vfop->rc %d\n",
  472. vf->op_rc, vfop->rc);
  473. /* if this is the last nested op reset the wait_blocking flag
  474. * to release any blocking wrappers, only after 'done()' is invoked
  475. */
  476. if (list_empty(&vf->op_list_head)) {
  477. DP(BNX2X_MSG_IOV, "list was empty after done %d\n", vfop->rc);
  478. vf->op_wait_blocking = false;
  479. }
  480. kfree(vfop);
  481. }
  482. static inline int bnx2x_vfop_wait_blocking(struct bnx2x *bp,
  483. struct bnx2x_virtf *vf)
  484. {
  485. /* can take a while if any port is running */
  486. int cnt = 5000;
  487. might_sleep();
  488. while (cnt--) {
  489. if (vf->op_wait_blocking == false) {
  490. #ifdef BNX2X_STOP_ON_ERROR
  491. DP(BNX2X_MSG_IOV, "exit (cnt %d)\n", 5000 - cnt);
  492. #endif
  493. return 0;
  494. }
  495. usleep_range(1000, 2000);
  496. if (bp->panic)
  497. return -EIO;
  498. }
  499. /* timeout! */
  500. #ifdef BNX2X_STOP_ON_ERROR
  501. bnx2x_panic();
  502. #endif
  503. return -EBUSY;
  504. }
  505. static inline int bnx2x_vfop_transition(struct bnx2x *bp,
  506. struct bnx2x_virtf *vf,
  507. vfop_handler_t transition,
  508. bool block)
  509. {
  510. if (block)
  511. vf->op_wait_blocking = true;
  512. transition(bp, vf);
  513. if (block)
  514. return bnx2x_vfop_wait_blocking(bp, vf);
  515. return 0;
  516. }
  517. /* VFOP queue construction helpers */
  518. void bnx2x_vfop_qctor_dump_tx(struct bnx2x *bp, struct bnx2x_virtf *vf,
  519. struct bnx2x_queue_init_params *init_params,
  520. struct bnx2x_queue_setup_params *setup_params,
  521. u16 q_idx, u16 sb_idx);
  522. void bnx2x_vfop_qctor_dump_rx(struct bnx2x *bp, struct bnx2x_virtf *vf,
  523. struct bnx2x_queue_init_params *init_params,
  524. struct bnx2x_queue_setup_params *setup_params,
  525. u16 q_idx, u16 sb_idx);
  526. void bnx2x_vfop_qctor_prep(struct bnx2x *bp,
  527. struct bnx2x_virtf *vf,
  528. struct bnx2x_vf_queue *q,
  529. struct bnx2x_vfop_qctor_params *p,
  530. unsigned long q_type);
  531. int bnx2x_vfop_mac_list_cmd(struct bnx2x *bp,
  532. struct bnx2x_virtf *vf,
  533. struct bnx2x_vfop_cmd *cmd,
  534. struct bnx2x_vfop_filters *macs,
  535. int qid, bool drv_only);
  536. int bnx2x_vfop_vlan_set_cmd(struct bnx2x *bp,
  537. struct bnx2x_virtf *vf,
  538. struct bnx2x_vfop_cmd *cmd,
  539. int qid, u16 vid, bool add);
  540. int bnx2x_vfop_vlan_list_cmd(struct bnx2x *bp,
  541. struct bnx2x_virtf *vf,
  542. struct bnx2x_vfop_cmd *cmd,
  543. struct bnx2x_vfop_filters *vlans,
  544. int qid, bool drv_only);
  545. int bnx2x_vfop_qsetup_cmd(struct bnx2x *bp,
  546. struct bnx2x_virtf *vf,
  547. struct bnx2x_vfop_cmd *cmd,
  548. int qid);
  549. int bnx2x_vfop_qdown_cmd(struct bnx2x *bp,
  550. struct bnx2x_virtf *vf,
  551. struct bnx2x_vfop_cmd *cmd,
  552. int qid);
  553. int bnx2x_vfop_mcast_cmd(struct bnx2x *bp,
  554. struct bnx2x_virtf *vf,
  555. struct bnx2x_vfop_cmd *cmd,
  556. bnx2x_mac_addr_t *mcasts,
  557. int mcast_num, bool drv_only);
  558. int bnx2x_vfop_rxmode_cmd(struct bnx2x *bp,
  559. struct bnx2x_virtf *vf,
  560. struct bnx2x_vfop_cmd *cmd,
  561. int qid, unsigned long accept_flags);
  562. int bnx2x_vfop_close_cmd(struct bnx2x *bp,
  563. struct bnx2x_virtf *vf,
  564. struct bnx2x_vfop_cmd *cmd);
  565. int bnx2x_vfop_release_cmd(struct bnx2x *bp,
  566. struct bnx2x_virtf *vf,
  567. struct bnx2x_vfop_cmd *cmd);
  568. /* VF release ~ VF close + VF release-resources
  569. *
  570. * Release is the ultimate SW shutdown and is called whenever an
  571. * irrecoverable error is encountered.
  572. */
  573. void bnx2x_vf_release(struct bnx2x *bp, struct bnx2x_virtf *vf, bool block);
  574. int bnx2x_vf_idx_by_abs_fid(struct bnx2x *bp, u16 abs_vfid);
  575. u8 bnx2x_vf_max_queue_cnt(struct bnx2x *bp, struct bnx2x_virtf *vf);
  576. /* FLR routines */
  577. /* VF FLR helpers */
  578. int bnx2x_vf_flr_clnup_epilog(struct bnx2x *bp, u8 abs_vfid);
  579. void bnx2x_vf_enable_access(struct bnx2x *bp, u8 abs_vfid);
  580. /* Handles an FLR (or VF_DISABLE) notification form the MCP */
  581. void bnx2x_vf_handle_flr_event(struct bnx2x *bp);
  582. void bnx2x_add_tlv(struct bnx2x *bp, void *tlvs_list, u16 offset, u16 type,
  583. u16 length);
  584. void bnx2x_vfpf_prep(struct bnx2x *bp, struct vfpf_first_tlv *first_tlv,
  585. u16 type, u16 length);
  586. void bnx2x_dp_tlv_list(struct bnx2x *bp, void *tlvs_list);
  587. bool bnx2x_tlv_supported(u16 tlvtype);
  588. u32 bnx2x_crc_vf_bulletin(struct bnx2x *bp,
  589. struct pf_vf_bulletin_content *bulletin);
  590. int bnx2x_post_vf_bulletin(struct bnx2x *bp, int vf);
  591. enum sample_bulletin_result {
  592. PFVF_BULLETIN_UNCHANGED,
  593. PFVF_BULLETIN_UPDATED,
  594. PFVF_BULLETIN_CRC_ERR
  595. };
  596. enum sample_bulletin_result bnx2x_sample_bulletin(struct bnx2x *bp);
  597. #endif /* bnx2x_sriov.h */