Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net/mlx5_core: Identify resources by their type

This patch puts a common part as the first field of mlx5_core_qp. This field is
used to identify which resource generated an event. This is required since upcoming
new resource types such as DC targets are allocated for the same numerical space
as regular QPs and may generate the same events. By searching the resource in the
same table we can then look at the common field to identify the resource.

Signed-off-by: Eli Cohen <eli@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Eli Cohen and committed by
David S. Miller
5903325a b775516b

+60 -25
+6 -6
drivers/net/ethernet/mellanox/mlx5/core/eq.c
··· 198 198 int eqes_found = 0; 199 199 int set_ci = 0; 200 200 u32 cqn; 201 - u32 srqn; 201 + u32 rsn; 202 202 u8 port; 203 203 204 204 while ((eqe = next_eqe_sw(eq))) { ··· 224 224 case MLX5_EVENT_TYPE_PATH_MIG_FAILED: 225 225 case MLX5_EVENT_TYPE_WQ_INVAL_REQ_ERROR: 226 226 case MLX5_EVENT_TYPE_WQ_ACCESS_ERROR: 227 + rsn = be32_to_cpu(eqe->data.qp_srq.qp_srq_n) & 0xffffff; 227 228 mlx5_core_dbg(dev, "event %s(%d) arrived\n", 228 229 eqe_type_str(eqe->type), eqe->type); 229 - mlx5_qp_event(dev, be32_to_cpu(eqe->data.qp_srq.qp_srq_n) & 0xffffff, 230 - eqe->type); 230 + mlx5_rsc_event(dev, rsn, eqe->type); 231 231 break; 232 232 233 233 case MLX5_EVENT_TYPE_SRQ_RQ_LIMIT: 234 234 case MLX5_EVENT_TYPE_SRQ_CATAS_ERROR: 235 - srqn = be32_to_cpu(eqe->data.qp_srq.qp_srq_n) & 0xffffff; 235 + rsn = be32_to_cpu(eqe->data.qp_srq.qp_srq_n) & 0xffffff; 236 236 mlx5_core_dbg(dev, "SRQ event %s(%d): srqn 0x%x\n", 237 - eqe_type_str(eqe->type), eqe->type, srqn); 238 - mlx5_srq_event(dev, srqn, eqe->type); 237 + eqe_type_str(eqe->type), eqe->type, rsn); 238 + mlx5_srq_event(dev, rsn, eqe->type); 239 239 break; 240 240 241 241 case MLX5_EVENT_TYPE_CMD:
+41 -16
drivers/net/ethernet/mellanox/mlx5/core/qp.c
··· 39 39 40 40 #include "mlx5_core.h" 41 41 42 - void mlx5_qp_event(struct mlx5_core_dev *dev, u32 qpn, int event_type) 42 + static struct mlx5_core_rsc_common *mlx5_get_rsc(struct mlx5_core_dev *dev, 43 + u32 rsn) 43 44 { 44 45 struct mlx5_qp_table *table = &dev->priv.qp_table; 45 - struct mlx5_core_qp *qp; 46 + struct mlx5_core_rsc_common *common; 46 47 47 48 spin_lock(&table->lock); 48 49 49 - qp = radix_tree_lookup(&table->tree, qpn); 50 - if (qp) 51 - atomic_inc(&qp->refcount); 50 + common = radix_tree_lookup(&table->tree, rsn); 51 + if (common) 52 + atomic_inc(&common->refcount); 52 53 53 54 spin_unlock(&table->lock); 54 55 55 - if (!qp) { 56 - mlx5_core_warn(dev, "Async event for bogus QP 0x%x\n", qpn); 56 + if (!common) { 57 + mlx5_core_warn(dev, "Async event for bogus resource 0x%x\n", 58 + rsn); 59 + return NULL; 60 + } 61 + return common; 62 + } 63 + 64 + void mlx5_core_put_rsc(struct mlx5_core_rsc_common *common) 65 + { 66 + if (atomic_dec_and_test(&common->refcount)) 67 + complete(&common->free); 68 + } 69 + 70 + void mlx5_rsc_event(struct mlx5_core_dev *dev, u32 rsn, int event_type) 71 + { 72 + struct mlx5_core_rsc_common *common = mlx5_get_rsc(dev, rsn); 73 + struct mlx5_core_qp *qp; 74 + 75 + if (!common) 57 76 return; 77 + 78 + switch (common->res) { 79 + case MLX5_RES_QP: 80 + qp = (struct mlx5_core_qp *)common; 81 + qp->event(qp, event_type); 82 + break; 83 + 84 + default: 85 + mlx5_core_warn(dev, "invalid resource type for 0x%x\n", rsn); 58 86 } 59 87 60 - qp->event(qp, event_type); 61 - 62 - if (atomic_dec_and_test(&qp->refcount)) 63 - complete(&qp->free); 88 + mlx5_core_put_rsc(common); 64 89 } 65 90 66 91 int mlx5_core_create_qp(struct mlx5_core_dev *dev, ··· 117 92 qp->qpn = be32_to_cpu(out.qpn) & 0xffffff; 118 93 mlx5_core_dbg(dev, "qpn = 0x%x\n", qp->qpn); 119 94 95 + qp->common.res = MLX5_RES_QP; 120 96 spin_lock_irq(&table->lock); 121 97 err = radix_tree_insert(&table->tree, qp->qpn, qp); 122 98 spin_unlock_irq(&table->lock); ··· 132 106 qp->qpn); 133 107 134 108 qp->pid = current->pid; 135 - atomic_set(&qp->refcount, 1); 109 + atomic_set(&qp->common.refcount, 1); 136 110 atomic_inc(&dev->num_qps); 137 - init_completion(&qp->free); 111 + init_completion(&qp->common.free); 138 112 139 113 return 0; 140 114 ··· 164 138 radix_tree_delete(&table->tree, qp->qpn); 165 139 spin_unlock_irqrestore(&table->lock, flags); 166 140 167 - if (atomic_dec_and_test(&qp->refcount)) 168 - complete(&qp->free); 169 - wait_for_completion(&qp->free); 141 + mlx5_core_put_rsc((struct mlx5_core_rsc_common *)qp); 142 + wait_for_completion(&qp->common.free); 170 143 171 144 memset(&in, 0, sizeof(in)); 172 145 memset(&out, 0, sizeof(out));
+12 -1
include/linux/mlx5/driver.h
··· 375 375 u32 pd; 376 376 }; 377 377 378 + enum mlx5_res_type { 379 + MLX5_RES_QP, 380 + }; 381 + 382 + struct mlx5_core_rsc_common { 383 + enum mlx5_res_type res; 384 + atomic_t refcount; 385 + struct completion free; 386 + }; 387 + 378 388 struct mlx5_core_srq { 379 389 u32 srqn; 380 390 int max; ··· 710 700 void mlx5_eq_cleanup(struct mlx5_core_dev *dev); 711 701 void mlx5_fill_page_array(struct mlx5_buf *buf, __be64 *pas); 712 702 void mlx5_cq_completion(struct mlx5_core_dev *dev, u32 cqn); 713 - void mlx5_qp_event(struct mlx5_core_dev *dev, u32 qpn, int event_type); 703 + void mlx5_rsc_event(struct mlx5_core_dev *dev, u32 rsn, int event_type); 714 704 void mlx5_srq_event(struct mlx5_core_dev *dev, u32 srqn, int event_type); 715 705 struct mlx5_core_srq *mlx5_core_get_srq(struct mlx5_core_dev *dev, u32 srqn); 716 706 void mlx5_cmd_comp_handler(struct mlx5_core_dev *dev, unsigned long vector); ··· 747 737 int mlx5_core_create_psv(struct mlx5_core_dev *dev, u32 pdn, 748 738 int npsvs, u32 *sig_index); 749 739 int mlx5_core_destroy_psv(struct mlx5_core_dev *dev, int psv_num); 740 + void mlx5_core_put_rsc(struct mlx5_core_rsc_common *common); 750 741 751 742 static inline u32 mlx5_mkey_to_idx(u32 mkey) 752 743 {
+1 -2
include/linux/mlx5/qp.h
··· 342 342 }; 343 343 344 344 struct mlx5_core_qp { 345 + struct mlx5_core_rsc_common common; /* must be first */ 345 346 void (*event) (struct mlx5_core_qp *, int); 346 347 int qpn; 347 - atomic_t refcount; 348 - struct completion free; 349 348 struct mlx5_rsc_debug *dbg; 350 349 int pid; 351 350 };