net/mlx4_core: Fix mpt_entry initialization in mlx4_mr_rereg_mem_write()
[cascardo/linux.git] / drivers / net / ethernet / mellanox / mlx4 / resource_tracker.c
index 4efbd1e..486e3d2 100644 (file)
@@ -309,12 +309,13 @@ static inline int mlx4_grant_resource(struct mlx4_dev *dev, int slave,
        int allocated, free, reserved, guaranteed, from_free;
        int from_rsvd;
 
-       if (slave > dev->num_vfs)
+       if (slave > dev->persist->num_vfs)
                return -EINVAL;
 
        spin_lock(&res_alloc->alloc_lock);
        allocated = (port > 0) ?
-               res_alloc->allocated[(port - 1) * (dev->num_vfs + 1) + slave] :
+               res_alloc->allocated[(port - 1) *
+               (dev->persist->num_vfs + 1) + slave] :
                res_alloc->allocated[slave];
        free = (port > 0) ? res_alloc->res_port_free[port - 1] :
                res_alloc->res_free;
@@ -352,7 +353,8 @@ static inline int mlx4_grant_resource(struct mlx4_dev *dev, int slave,
        if (!err) {
                /* grant the request */
                if (port > 0) {
-                       res_alloc->allocated[(port - 1) * (dev->num_vfs + 1) + slave] += count;
+                       res_alloc->allocated[(port - 1) *
+                       (dev->persist->num_vfs + 1) + slave] += count;
                        res_alloc->res_port_free[port - 1] -= count;
                        res_alloc->res_port_rsvd[port - 1] -= from_rsvd;
                } else {
@@ -376,13 +378,14 @@ static inline void mlx4_release_resource(struct mlx4_dev *dev, int slave,
                &priv->mfunc.master.res_tracker.res_alloc[res_type];
        int allocated, guaranteed, from_rsvd;
 
-       if (slave > dev->num_vfs)
+       if (slave > dev->persist->num_vfs)
                return;
 
        spin_lock(&res_alloc->alloc_lock);
 
        allocated = (port > 0) ?
-               res_alloc->allocated[(port - 1) * (dev->num_vfs + 1) + slave] :
+               res_alloc->allocated[(port - 1) *
+               (dev->persist->num_vfs + 1) + slave] :
                res_alloc->allocated[slave];
        guaranteed = res_alloc->guaranteed[slave];
 
@@ -397,7 +400,8 @@ static inline void mlx4_release_resource(struct mlx4_dev *dev, int slave,
        }
 
        if (port > 0) {
-               res_alloc->allocated[(port - 1) * (dev->num_vfs + 1) + slave] -= count;
+               res_alloc->allocated[(port - 1) *
+               (dev->persist->num_vfs + 1) + slave] -= count;
                res_alloc->res_port_free[port - 1] += count;
                res_alloc->res_port_rsvd[port - 1] += from_rsvd;
        } else {
@@ -415,7 +419,8 @@ static inline void initialize_res_quotas(struct mlx4_dev *dev,
                                         enum mlx4_resource res_type,
                                         int vf, int num_instances)
 {
-       res_alloc->guaranteed[vf] = num_instances / (2 * (dev->num_vfs + 1));
+       res_alloc->guaranteed[vf] = num_instances /
+                                   (2 * (dev->persist->num_vfs + 1));
        res_alloc->quota[vf] = (num_instances / 2) + res_alloc->guaranteed[vf];
        if (vf == mlx4_master_func_num(dev)) {
                res_alloc->res_free = num_instances;
@@ -486,21 +491,26 @@ int mlx4_init_resource_tracker(struct mlx4_dev *dev)
        for (i = 0; i < MLX4_NUM_OF_RESOURCE_TYPE; i++) {
                struct resource_allocator *res_alloc =
                        &priv->mfunc.master.res_tracker.res_alloc[i];
-               res_alloc->quota = kmalloc((dev->num_vfs + 1) * sizeof(int), GFP_KERNEL);
-               res_alloc->guaranteed = kmalloc((dev->num_vfs + 1) * sizeof(int), GFP_KERNEL);
+               res_alloc->quota = kmalloc((dev->persist->num_vfs + 1) *
+                                          sizeof(int), GFP_KERNEL);
+               res_alloc->guaranteed = kmalloc((dev->persist->num_vfs + 1) *
+                                               sizeof(int), GFP_KERNEL);
                if (i == RES_MAC || i == RES_VLAN)
                        res_alloc->allocated = kzalloc(MLX4_MAX_PORTS *
-                                                      (dev->num_vfs + 1) * sizeof(int),
-                                                       GFP_KERNEL);
+                                                      (dev->persist->num_vfs
+                                                      + 1) *
+                                                      sizeof(int), GFP_KERNEL);
                else
-                       res_alloc->allocated = kzalloc((dev->num_vfs + 1) * sizeof(int), GFP_KERNEL);
+                       res_alloc->allocated = kzalloc((dev->persist->
+                                                       num_vfs + 1) *
+                                                      sizeof(int), GFP_KERNEL);
 
                if (!res_alloc->quota || !res_alloc->guaranteed ||
                    !res_alloc->allocated)
                        goto no_mem_err;
 
                spin_lock_init(&res_alloc->alloc_lock);
-               for (t = 0; t < dev->num_vfs + 1; t++) {
+               for (t = 0; t < dev->persist->num_vfs + 1; t++) {
                        struct mlx4_active_ports actv_ports =
                                mlx4_get_active_ports(dev, t);
                        switch (i) {
@@ -2531,7 +2541,7 @@ int mlx4_SW2HW_MPT_wrapper(struct mlx4_dev *dev, int slave,
        /* Make sure that the PD bits related to the slave id are zeros. */
        pd = mr_get_pd(inbox->buf);
        pd_slave = (pd >> 17) & 0x7f;
-       if (pd_slave != 0 && pd_slave != slave) {
+       if (pd_slave != 0 && --pd_slave != slave) {
                err = -EPERM;
                goto ex_abort;
        }
@@ -2934,6 +2944,9 @@ static int verify_qp_parameters(struct mlx4_dev *dev,
        qp_type = (be32_to_cpu(qp_ctx->flags) >> 16) & 0xff;
        optpar  = be32_to_cpu(*(__be32 *) inbox->buf);
 
+       if (slave != mlx4_master_func_num(dev))
+               qp_ctx->params2 &= ~MLX4_QP_BIT_FPP;
+
        switch (qp_type) {
        case MLX4_QP_ST_RC:
        case MLX4_QP_ST_XRC:
@@ -4667,7 +4680,6 @@ static void rem_slave_eqs(struct mlx4_dev *dev, int slave)
        int state;
        LIST_HEAD(tlist);
        int eqn;
-       struct mlx4_cmd_mailbox *mailbox;
 
        err = move_all_busy(dev, slave, RES_EQ);
        if (err)
@@ -4693,20 +4705,13 @@ static void rem_slave_eqs(struct mlx4_dev *dev, int slave)
                                        break;
 
                                case RES_EQ_HW:
-                                       mailbox = mlx4_alloc_cmd_mailbox(dev);
-                                       if (IS_ERR(mailbox)) {
-                                               cond_resched();
-                                               continue;
-                                       }
-                                       err = mlx4_cmd_box(dev, slave, 0,
-                                                          eqn & 0xff, 0,
-                                                          MLX4_CMD_HW2SW_EQ,
-                                                          MLX4_CMD_TIME_CLASS_A,
-                                                          MLX4_CMD_NATIVE);
+                                       err = mlx4_cmd(dev, slave, eqn & 0xff,
+                                                      1, MLX4_CMD_HW2SW_EQ,
+                                                      MLX4_CMD_TIME_CLASS_A,
+                                                      MLX4_CMD_NATIVE);
                                        if (err)
                                                mlx4_dbg(dev, "rem_slave_eqs: failed to move slave %d eqs %d to SW ownership\n",
                                                         slave, eqn);
-                                       mlx4_free_cmd_mailbox(dev, mailbox);
                                        atomic_dec(&eq->mtt->ref_count);
                                        state = RES_EQ_RESERVED;
                                        break;