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