IB/mlx4: Initialize SR-IOV IB support for slaves in master context
[cascardo/linux.git] / drivers / infiniband / hw / mlx4 / mlx4_ib.h
index c136bb6..137941d 100644 (file)
@@ -133,8 +133,10 @@ struct mlx4_ib_wq {
 };
 
 enum mlx4_ib_qp_flags {
-       MLX4_IB_QP_LSO                          = 1 << 0,
-       MLX4_IB_QP_BLOCK_MULTICAST_LOOPBACK     = 1 << 1,
+       MLX4_IB_QP_LSO = IB_QP_CREATE_IPOIB_UD_LSO,
+       MLX4_IB_QP_BLOCK_MULTICAST_LOOPBACK = IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK,
+       MLX4_IB_SRIOV_TUNNEL_QP = 1 << 30,
+       MLX4_IB_SRIOV_SQP = 1 << 31,
 };
 
 struct mlx4_ib_gid_entry {
@@ -144,6 +146,72 @@ struct mlx4_ib_gid_entry {
        u8                      port;
 };
 
+enum mlx4_ib_qp_type {
+       /*
+        * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
+        * here (and in that order) since the MAD layer uses them as
+        * indices into a 2-entry table.
+        */
+       MLX4_IB_QPT_SMI = IB_QPT_SMI,
+       MLX4_IB_QPT_GSI = IB_QPT_GSI,
+
+       MLX4_IB_QPT_RC = IB_QPT_RC,
+       MLX4_IB_QPT_UC = IB_QPT_UC,
+       MLX4_IB_QPT_UD = IB_QPT_UD,
+       MLX4_IB_QPT_RAW_IPV6 = IB_QPT_RAW_IPV6,
+       MLX4_IB_QPT_RAW_ETHERTYPE = IB_QPT_RAW_ETHERTYPE,
+       MLX4_IB_QPT_RAW_PACKET = IB_QPT_RAW_PACKET,
+       MLX4_IB_QPT_XRC_INI = IB_QPT_XRC_INI,
+       MLX4_IB_QPT_XRC_TGT = IB_QPT_XRC_TGT,
+
+       MLX4_IB_QPT_PROXY_SMI_OWNER     = 1 << 16,
+       MLX4_IB_QPT_PROXY_SMI           = 1 << 17,
+       MLX4_IB_QPT_PROXY_GSI           = 1 << 18,
+       MLX4_IB_QPT_TUN_SMI_OWNER       = 1 << 19,
+       MLX4_IB_QPT_TUN_SMI             = 1 << 20,
+       MLX4_IB_QPT_TUN_GSI             = 1 << 21,
+};
+
+#define MLX4_IB_QPT_ANY_SRIOV  (MLX4_IB_QPT_PROXY_SMI_OWNER | \
+       MLX4_IB_QPT_PROXY_SMI | MLX4_IB_QPT_PROXY_GSI | MLX4_IB_QPT_TUN_SMI_OWNER | \
+       MLX4_IB_QPT_TUN_SMI | MLX4_IB_QPT_TUN_GSI)
+
+enum {
+       MLX4_NUM_TUNNEL_BUFS            = 256,
+};
+
+struct mlx4_ib_tunnel_header {
+       struct mlx4_av av;
+       __be32 remote_qpn;
+       __be32 qkey;
+       __be16 vlan;
+       u8 mac[6];
+       __be16 pkey_index;
+       u8 reserved[6];
+};
+
+struct mlx4_ib_buf {
+       void *addr;
+       dma_addr_t map;
+};
+
+struct mlx4_rcv_tunnel_hdr {
+       __be32 flags_src_qp; /* flags[6:5] is defined for VLANs:
+                             * 0x0 - no vlan was in the packet
+                             * 0x01 - C-VLAN was in the packet */
+       u8 g_ml_path; /* gid bit stands for ipv6/4 header in RoCE */
+       u8 reserved;
+       __be16 pkey_index;
+       __be16 sl_vid;
+       __be16 slid_mac_47_32;
+       __be32 mac_31_0;
+};
+
+struct mlx4_ib_proxy_sqp_hdr {
+       struct ib_grh grh;
+       struct mlx4_rcv_tunnel_hdr tun;
+}  __packed;
+
 struct mlx4_ib_qp {
        struct ib_qp            ibqp;
        struct mlx4_qp          mqp;
@@ -159,6 +227,7 @@ struct mlx4_ib_qp {
        int                     sq_spare_wqes;
        struct mlx4_ib_wq       sq;
 
+       enum mlx4_ib_qp_type    mlx4_ib_qp_type;
        struct ib_umem         *umem;
        struct mlx4_mtt         mtt;
        int                     buf_size;
@@ -174,6 +243,8 @@ struct mlx4_ib_qp {
        int                     mlx_type;
        struct list_head        gid_list;
        struct list_head        steering_rules;
+       struct mlx4_ib_buf      *sqp_proxy_rcv;
+
 };
 
 struct mlx4_ib_srq {
@@ -196,6 +267,72 @@ struct mlx4_ib_ah {
        union mlx4_ext_av       av;
 };
 
+struct mlx4_ib_demux_work {
+       struct work_struct      work;
+       struct mlx4_ib_dev     *dev;
+       int                     slave;
+       int                     do_init;
+       u8                      port;
+
+};
+
+struct mlx4_ib_tun_tx_buf {
+       struct mlx4_ib_buf buf;
+       struct ib_ah *ah;
+};
+
+struct mlx4_ib_demux_pv_qp {
+       struct ib_qp *qp;
+       enum ib_qp_type proxy_qpt;
+       struct mlx4_ib_buf *ring;
+       struct mlx4_ib_tun_tx_buf *tx_ring;
+       spinlock_t tx_lock;
+       unsigned tx_ix_head;
+       unsigned tx_ix_tail;
+};
+
+enum mlx4_ib_demux_pv_state {
+       DEMUX_PV_STATE_DOWN,
+       DEMUX_PV_STATE_STARTING,
+       DEMUX_PV_STATE_ACTIVE,
+       DEMUX_PV_STATE_DOWNING,
+};
+
+struct mlx4_ib_demux_pv_ctx {
+       int port;
+       int slave;
+       enum mlx4_ib_demux_pv_state state;
+       int has_smi;
+       struct ib_device *ib_dev;
+       struct ib_cq *cq;
+       struct ib_pd *pd;
+       struct ib_mr *mr;
+       struct work_struct work;
+       struct workqueue_struct *wq;
+       struct mlx4_ib_demux_pv_qp qp[2];
+};
+
+struct mlx4_ib_demux_ctx {
+       struct ib_device *ib_dev;
+       int port;
+       struct workqueue_struct *wq;
+       struct workqueue_struct *ud_wq;
+       spinlock_t ud_lock;
+       __be64 subnet_prefix;
+       __be64 guid_cache[128];
+       struct mlx4_ib_dev *dev;
+       struct mlx4_ib_demux_pv_ctx **tun;
+};
+
+struct mlx4_ib_sriov {
+       struct mlx4_ib_demux_ctx demux[MLX4_MAX_PORTS];
+       struct mlx4_ib_demux_pv_ctx *sqps[MLX4_MAX_PORTS];
+       /* when using this spinlock you should use "irq" because
+        * it may be called from interrupt context.*/
+       spinlock_t going_down_lock;
+       int is_going_down;
+};
+
 struct mlx4_ib_iboe {
        spinlock_t              lock;
        struct net_device      *netdevs[MLX4_MAX_PORTS];
@@ -203,6 +340,13 @@ struct mlx4_ib_iboe {
        union ib_gid            gid_table[MLX4_MAX_PORTS][128];
 };
 
+struct pkey_mgt {
+       u8                      virt2phys_pkey[MLX4_MFUNC_MAX][MLX4_MAX_PORTS][MLX4_MAX_PORT_PKEYS];
+       u16                     phys_pkey_cache[MLX4_MAX_PORTS][MLX4_MAX_PORT_PKEYS];
+       struct list_head        pkey_port_list[MLX4_MFUNC_MAX];
+       struct kobject         *device_parent[MLX4_MFUNC_MAX];
+};
+
 struct mlx4_ib_dev {
        struct ib_device        ib_dev;
        struct mlx4_dev        *dev;
@@ -216,6 +360,7 @@ struct mlx4_ib_dev {
        struct ib_mad_agent    *send_agent[MLX4_MAX_PORTS][2];
        struct ib_ah           *sm_ah[MLX4_MAX_PORTS];
        spinlock_t              sm_lock;
+       struct mlx4_ib_sriov    sriov;
 
        struct mutex            cap_mask_mutex;
        bool                    ib_active;
@@ -223,6 +368,7 @@ struct mlx4_ib_dev {
        int                     counters[MLX4_MAX_PORTS];
        int                    *eq_table;
        int                     eq_added;
+       struct pkey_mgt         pkeys;
 };
 
 struct ib_event_work {
@@ -231,6 +377,13 @@ struct ib_event_work {
        struct mlx4_eqe         ib_eqe;
 };
 
+struct mlx4_ib_qp_tunnel_init_attr {
+       struct ib_qp_init_attr init_attr;
+       int slave;
+       enum ib_qp_type proxy_qp_type;
+       u8 port;
+};
+
 static inline struct mlx4_ib_dev *to_mdev(struct ib_device *ibdev)
 {
        return container_of(ibdev, struct mlx4_ib_dev, ib_dev);
@@ -300,6 +453,9 @@ static inline struct mlx4_ib_ah *to_mah(struct ib_ah *ibah)
        return container_of(ibah, struct mlx4_ib_ah, ibah);
 }
 
+int mlx4_ib_init_sriov(struct mlx4_ib_dev *dev);
+void mlx4_ib_close_sriov(struct mlx4_ib_dev *dev);
+
 int mlx4_ib_db_map_user(struct mlx4_ib_ucontext *context, unsigned long virt,
                        struct mlx4_db *db);
 void mlx4_ib_db_unmap_user(struct mlx4_ib_ucontext *context, struct mlx4_db *db);
@@ -391,4 +547,6 @@ int mlx4_ib_add_mc(struct mlx4_ib_dev *mdev, struct mlx4_ib_qp *mqp,
 void mlx4_ib_dispatch_event(struct mlx4_ib_dev *dev, u8 port_num,
                            enum ib_event_type type);
 
+void mlx4_ib_tunnels_update_work(struct work_struct *work);
+
 #endif /* MLX4_IB_H */