bnx2x_sriov.h 23 KB

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