diff options
author | Saeed Mahameed <saeedm@mellanox.com> | 2015-04-02 10:07:32 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-04-02 16:33:42 -0400 |
commit | 233d05d28ad942929b6b4fbc48aa8dd083c16484 (patch) | |
tree | 342d60a038d65bed539d3d5c000be459cf040e01 | |
parent | 4ae6c18c59f1419202ab5e2a918e551099d88f9f (diff) |
net/mlx5_core: Move completion eqs from mlx5_ib to mlx5_core
Preparation for ethernet driver.
These functions will be used in drivers other than mlx5_ib.
Signed-off-by: Achiad Shochat <achiad@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
Signed-off-by: Eli Cohen <eli@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | drivers/infiniband/hw/mlx5/cq.c | 2 | ||||
-rw-r--r-- | drivers/infiniband/hw/mlx5/main.c | 104 | ||||
-rw-r--r-- | drivers/infiniband/hw/mlx5/mlx5_ib.h | 3 | ||||
-rw-r--r-- | drivers/net/ethernet/mellanox/mlx5/core/main.c | 91 | ||||
-rw-r--r-- | include/linux/mlx5/driver.h | 3 |
5 files changed, 98 insertions, 105 deletions
diff --git a/drivers/infiniband/hw/mlx5/cq.c b/drivers/infiniband/hw/mlx5/cq.c index 6efd9f73ff60..c94e2651820d 100644 --- a/drivers/infiniband/hw/mlx5/cq.c +++ b/drivers/infiniband/hw/mlx5/cq.c | |||
@@ -780,7 +780,7 @@ struct ib_cq *mlx5_ib_create_cq(struct ib_device *ibdev, int entries, | |||
780 | cq->cqe_size = cqe_size; | 780 | cq->cqe_size = cqe_size; |
781 | cqb->ctx.cqe_sz_flags = cqe_sz_to_mlx_sz(cqe_size) << 5; | 781 | cqb->ctx.cqe_sz_flags = cqe_sz_to_mlx_sz(cqe_size) << 5; |
782 | cqb->ctx.log_sz_usr_page = cpu_to_be32((ilog2(entries) << 24) | index); | 782 | cqb->ctx.log_sz_usr_page = cpu_to_be32((ilog2(entries) << 24) | index); |
783 | err = mlx5_vector2eqn(dev, vector, &eqn, &irqn); | 783 | err = mlx5_vector2eqn(dev->mdev, vector, &eqn, &irqn); |
784 | if (err) | 784 | if (err) |
785 | goto err_cqb; | 785 | goto err_cqb; |
786 | 786 | ||
diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c index 45816b10af5e..e59e2a1f8726 100644 --- a/drivers/infiniband/hw/mlx5/main.c +++ b/drivers/infiniband/hw/mlx5/main.c | |||
@@ -62,95 +62,6 @@ static char mlx5_version[] = | |||
62 | DRIVER_NAME ": Mellanox Connect-IB Infiniband driver v" | 62 | DRIVER_NAME ": Mellanox Connect-IB Infiniband driver v" |
63 | DRIVER_VERSION " (" DRIVER_RELDATE ")\n"; | 63 | DRIVER_VERSION " (" DRIVER_RELDATE ")\n"; |
64 | 64 | ||
65 | int mlx5_vector2eqn(struct mlx5_ib_dev *dev, int vector, int *eqn, int *irqn) | ||
66 | { | ||
67 | struct mlx5_eq_table *table = &dev->mdev->priv.eq_table; | ||
68 | struct mlx5_eq *eq, *n; | ||
69 | int err = -ENOENT; | ||
70 | |||
71 | spin_lock(&table->lock); | ||
72 | list_for_each_entry_safe(eq, n, &dev->eqs_list, list) { | ||
73 | if (eq->index == vector) { | ||
74 | *eqn = eq->eqn; | ||
75 | *irqn = eq->irqn; | ||
76 | err = 0; | ||
77 | break; | ||
78 | } | ||
79 | } | ||
80 | spin_unlock(&table->lock); | ||
81 | |||
82 | return err; | ||
83 | } | ||
84 | |||
85 | static int alloc_comp_eqs(struct mlx5_ib_dev *dev) | ||
86 | { | ||
87 | struct mlx5_eq_table *table = &dev->mdev->priv.eq_table; | ||
88 | char name[MLX5_MAX_EQ_NAME]; | ||
89 | struct mlx5_eq *eq, *n; | ||
90 | int ncomp_vec; | ||
91 | int nent; | ||
92 | int err; | ||
93 | int i; | ||
94 | |||
95 | INIT_LIST_HEAD(&dev->eqs_list); | ||
96 | ncomp_vec = table->num_comp_vectors; | ||
97 | nent = MLX5_COMP_EQ_SIZE; | ||
98 | for (i = 0; i < ncomp_vec; i++) { | ||
99 | eq = kzalloc(sizeof(*eq), GFP_KERNEL); | ||
100 | if (!eq) { | ||
101 | err = -ENOMEM; | ||
102 | goto clean; | ||
103 | } | ||
104 | |||
105 | snprintf(name, MLX5_MAX_EQ_NAME, "mlx5_comp%d", i); | ||
106 | err = mlx5_create_map_eq(dev->mdev, eq, | ||
107 | i + MLX5_EQ_VEC_COMP_BASE, nent, 0, | ||
108 | name, &dev->mdev->priv.uuari.uars[0]); | ||
109 | if (err) { | ||
110 | kfree(eq); | ||
111 | goto clean; | ||
112 | } | ||
113 | mlx5_ib_dbg(dev, "allocated completion EQN %d\n", eq->eqn); | ||
114 | eq->index = i; | ||
115 | spin_lock(&table->lock); | ||
116 | list_add_tail(&eq->list, &dev->eqs_list); | ||
117 | spin_unlock(&table->lock); | ||
118 | } | ||
119 | |||
120 | dev->num_comp_vectors = ncomp_vec; | ||
121 | return 0; | ||
122 | |||
123 | clean: | ||
124 | spin_lock(&table->lock); | ||
125 | list_for_each_entry_safe(eq, n, &dev->eqs_list, list) { | ||
126 | list_del(&eq->list); | ||
127 | spin_unlock(&table->lock); | ||
128 | if (mlx5_destroy_unmap_eq(dev->mdev, eq)) | ||
129 | mlx5_ib_warn(dev, "failed to destroy EQ 0x%x\n", eq->eqn); | ||
130 | kfree(eq); | ||
131 | spin_lock(&table->lock); | ||
132 | } | ||
133 | spin_unlock(&table->lock); | ||
134 | return err; | ||
135 | } | ||
136 | |||
137 | static void free_comp_eqs(struct mlx5_ib_dev *dev) | ||
138 | { | ||
139 | struct mlx5_eq_table *table = &dev->mdev->priv.eq_table; | ||
140 | struct mlx5_eq *eq, *n; | ||
141 | |||
142 | spin_lock(&table->lock); | ||
143 | list_for_each_entry_safe(eq, n, &dev->eqs_list, list) { | ||
144 | list_del(&eq->list); | ||
145 | spin_unlock(&table->lock); | ||
146 | if (mlx5_destroy_unmap_eq(dev->mdev, eq)) | ||
147 | mlx5_ib_warn(dev, "failed to destroy EQ 0x%x\n", eq->eqn); | ||
148 | kfree(eq); | ||
149 | spin_lock(&table->lock); | ||
150 | } | ||
151 | spin_unlock(&table->lock); | ||
152 | } | ||
153 | |||
154 | static int mlx5_ib_query_device(struct ib_device *ibdev, | 65 | static int mlx5_ib_query_device(struct ib_device *ibdev, |
155 | struct ib_device_attr *props) | 66 | struct ib_device_attr *props) |
156 | { | 67 | { |
@@ -1291,10 +1202,6 @@ static void *mlx5_ib_add(struct mlx5_core_dev *mdev) | |||
1291 | 1202 | ||
1292 | get_ext_port_caps(dev); | 1203 | get_ext_port_caps(dev); |
1293 | 1204 | ||
1294 | err = alloc_comp_eqs(dev); | ||
1295 | if (err) | ||
1296 | goto err_dealloc; | ||
1297 | |||
1298 | MLX5_INIT_DOORBELL_LOCK(&dev->uar_lock); | 1205 | MLX5_INIT_DOORBELL_LOCK(&dev->uar_lock); |
1299 | 1206 | ||
1300 | strlcpy(dev->ib_dev.name, "mlx5_%d", IB_DEVICE_NAME_MAX); | 1207 | strlcpy(dev->ib_dev.name, "mlx5_%d", IB_DEVICE_NAME_MAX); |
@@ -1303,7 +1210,8 @@ static void *mlx5_ib_add(struct mlx5_core_dev *mdev) | |||
1303 | dev->ib_dev.local_dma_lkey = mdev->caps.gen.reserved_lkey; | 1210 | dev->ib_dev.local_dma_lkey = mdev->caps.gen.reserved_lkey; |
1304 | dev->num_ports = mdev->caps.gen.num_ports; | 1211 | dev->num_ports = mdev->caps.gen.num_ports; |
1305 | dev->ib_dev.phys_port_cnt = dev->num_ports; | 1212 | dev->ib_dev.phys_port_cnt = dev->num_ports; |
1306 | dev->ib_dev.num_comp_vectors = dev->num_comp_vectors; | 1213 | dev->ib_dev.num_comp_vectors = |
1214 | dev->mdev->priv.eq_table.num_comp_vectors; | ||
1307 | dev->ib_dev.dma_device = &mdev->pdev->dev; | 1215 | dev->ib_dev.dma_device = &mdev->pdev->dev; |
1308 | 1216 | ||
1309 | dev->ib_dev.uverbs_abi_ver = MLX5_IB_UVERBS_ABI_VERSION; | 1217 | dev->ib_dev.uverbs_abi_ver = MLX5_IB_UVERBS_ABI_VERSION; |
@@ -1390,13 +1298,13 @@ static void *mlx5_ib_add(struct mlx5_core_dev *mdev) | |||
1390 | 1298 | ||
1391 | err = init_node_data(dev); | 1299 | err = init_node_data(dev); |
1392 | if (err) | 1300 | if (err) |
1393 | goto err_eqs; | 1301 | goto err_dealloc; |
1394 | 1302 | ||
1395 | mutex_init(&dev->cap_mask_mutex); | 1303 | mutex_init(&dev->cap_mask_mutex); |
1396 | 1304 | ||
1397 | err = create_dev_resources(&dev->devr); | 1305 | err = create_dev_resources(&dev->devr); |
1398 | if (err) | 1306 | if (err) |
1399 | goto err_eqs; | 1307 | goto err_dealloc; |
1400 | 1308 | ||
1401 | err = mlx5_ib_odp_init_one(dev); | 1309 | err = mlx5_ib_odp_init_one(dev); |
1402 | if (err) | 1310 | if (err) |
@@ -1433,9 +1341,6 @@ err_odp: | |||
1433 | err_rsrc: | 1341 | err_rsrc: |
1434 | destroy_dev_resources(&dev->devr); | 1342 | destroy_dev_resources(&dev->devr); |
1435 | 1343 | ||
1436 | err_eqs: | ||
1437 | free_comp_eqs(dev); | ||
1438 | |||
1439 | err_dealloc: | 1344 | err_dealloc: |
1440 | ib_dealloc_device((struct ib_device *)dev); | 1345 | ib_dealloc_device((struct ib_device *)dev); |
1441 | 1346 | ||
@@ -1450,7 +1355,6 @@ static void mlx5_ib_remove(struct mlx5_core_dev *mdev, void *context) | |||
1450 | destroy_umrc_res(dev); | 1355 | destroy_umrc_res(dev); |
1451 | mlx5_ib_odp_remove_one(dev); | 1356 | mlx5_ib_odp_remove_one(dev); |
1452 | destroy_dev_resources(&dev->devr); | 1357 | destroy_dev_resources(&dev->devr); |
1453 | free_comp_eqs(dev); | ||
1454 | ib_dealloc_device(&dev->ib_dev); | 1358 | ib_dealloc_device(&dev->ib_dev); |
1455 | } | 1359 | } |
1456 | 1360 | ||
diff --git a/drivers/infiniband/hw/mlx5/mlx5_ib.h b/drivers/infiniband/hw/mlx5/mlx5_ib.h index 8f94f69fbea5..dff1cfcdf476 100644 --- a/drivers/infiniband/hw/mlx5/mlx5_ib.h +++ b/drivers/infiniband/hw/mlx5/mlx5_ib.h | |||
@@ -421,9 +421,7 @@ struct mlx5_ib_dev { | |||
421 | struct ib_device ib_dev; | 421 | struct ib_device ib_dev; |
422 | struct mlx5_core_dev *mdev; | 422 | struct mlx5_core_dev *mdev; |
423 | MLX5_DECLARE_DOORBELL_LOCK(uar_lock); | 423 | MLX5_DECLARE_DOORBELL_LOCK(uar_lock); |
424 | struct list_head eqs_list; | ||
425 | int num_ports; | 424 | int num_ports; |
426 | int num_comp_vectors; | ||
427 | /* serialize update of capability mask | 425 | /* serialize update of capability mask |
428 | */ | 426 | */ |
429 | struct mutex cap_mask_mutex; | 427 | struct mutex cap_mask_mutex; |
@@ -594,7 +592,6 @@ struct ib_xrcd *mlx5_ib_alloc_xrcd(struct ib_device *ibdev, | |||
594 | struct ib_ucontext *context, | 592 | struct ib_ucontext *context, |
595 | struct ib_udata *udata); | 593 | struct ib_udata *udata); |
596 | int mlx5_ib_dealloc_xrcd(struct ib_xrcd *xrcd); | 594 | int mlx5_ib_dealloc_xrcd(struct ib_xrcd *xrcd); |
597 | int mlx5_vector2eqn(struct mlx5_ib_dev *dev, int vector, int *eqn, int *irqn); | ||
598 | int mlx5_ib_get_buf_offset(u64 addr, int page_shift, u32 *offset); | 595 | int mlx5_ib_get_buf_offset(u64 addr, int page_shift, u32 *offset); |
599 | int mlx5_query_ext_port_caps(struct mlx5_ib_dev *dev, u8 port); | 596 | int mlx5_query_ext_port_caps(struct mlx5_ib_dev *dev, u8 port); |
600 | int mlx5_ib_query_port(struct ib_device *ibdev, u8 port, | 597 | int mlx5_ib_query_port(struct ib_device *ibdev, u8 port, |
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/ethernet/mellanox/mlx5/core/main.c index fe41a7c2c629..cfc29027f07a 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c | |||
@@ -507,6 +507,87 @@ static int mlx5_core_disable_hca(struct mlx5_core_dev *dev) | |||
507 | return 0; | 507 | return 0; |
508 | } | 508 | } |
509 | 509 | ||
510 | int mlx5_vector2eqn(struct mlx5_core_dev *dev, int vector, int *eqn, int *irqn) | ||
511 | { | ||
512 | struct mlx5_eq_table *table = &dev->priv.eq_table; | ||
513 | struct mlx5_eq *eq, *n; | ||
514 | int err = -ENOENT; | ||
515 | |||
516 | spin_lock(&table->lock); | ||
517 | list_for_each_entry_safe(eq, n, &table->comp_eqs_list, list) { | ||
518 | if (eq->index == vector) { | ||
519 | *eqn = eq->eqn; | ||
520 | *irqn = eq->irqn; | ||
521 | err = 0; | ||
522 | break; | ||
523 | } | ||
524 | } | ||
525 | spin_unlock(&table->lock); | ||
526 | |||
527 | return err; | ||
528 | } | ||
529 | EXPORT_SYMBOL(mlx5_vector2eqn); | ||
530 | |||
531 | static void free_comp_eqs(struct mlx5_core_dev *dev) | ||
532 | { | ||
533 | struct mlx5_eq_table *table = &dev->priv.eq_table; | ||
534 | struct mlx5_eq *eq, *n; | ||
535 | |||
536 | spin_lock(&table->lock); | ||
537 | list_for_each_entry_safe(eq, n, &table->comp_eqs_list, list) { | ||
538 | list_del(&eq->list); | ||
539 | spin_unlock(&table->lock); | ||
540 | if (mlx5_destroy_unmap_eq(dev, eq)) | ||
541 | mlx5_core_warn(dev, "failed to destroy EQ 0x%x\n", | ||
542 | eq->eqn); | ||
543 | kfree(eq); | ||
544 | spin_lock(&table->lock); | ||
545 | } | ||
546 | spin_unlock(&table->lock); | ||
547 | } | ||
548 | |||
549 | static int alloc_comp_eqs(struct mlx5_core_dev *dev) | ||
550 | { | ||
551 | struct mlx5_eq_table *table = &dev->priv.eq_table; | ||
552 | char name[MLX5_MAX_EQ_NAME]; | ||
553 | struct mlx5_eq *eq; | ||
554 | int ncomp_vec; | ||
555 | int nent; | ||
556 | int err; | ||
557 | int i; | ||
558 | |||
559 | INIT_LIST_HEAD(&table->comp_eqs_list); | ||
560 | ncomp_vec = table->num_comp_vectors; | ||
561 | nent = MLX5_COMP_EQ_SIZE; | ||
562 | for (i = 0; i < ncomp_vec; i++) { | ||
563 | eq = kzalloc(sizeof(*eq), GFP_KERNEL); | ||
564 | if (!eq) { | ||
565 | err = -ENOMEM; | ||
566 | goto clean; | ||
567 | } | ||
568 | |||
569 | snprintf(name, MLX5_MAX_EQ_NAME, "mlx5_comp%d", i); | ||
570 | err = mlx5_create_map_eq(dev, eq, | ||
571 | i + MLX5_EQ_VEC_COMP_BASE, nent, 0, | ||
572 | name, &dev->priv.uuari.uars[0]); | ||
573 | if (err) { | ||
574 | kfree(eq); | ||
575 | goto clean; | ||
576 | } | ||
577 | mlx5_core_dbg(dev, "allocated completion EQN %d\n", eq->eqn); | ||
578 | eq->index = i; | ||
579 | spin_lock(&table->lock); | ||
580 | list_add_tail(&eq->list, &table->comp_eqs_list); | ||
581 | spin_unlock(&table->lock); | ||
582 | } | ||
583 | |||
584 | return 0; | ||
585 | |||
586 | clean: | ||
587 | free_comp_eqs(dev); | ||
588 | return err; | ||
589 | } | ||
590 | |||
510 | static int mlx5_dev_init(struct mlx5_core_dev *dev, struct pci_dev *pdev) | 591 | static int mlx5_dev_init(struct mlx5_core_dev *dev, struct pci_dev *pdev) |
511 | { | 592 | { |
512 | struct mlx5_priv *priv = &dev->priv; | 593 | struct mlx5_priv *priv = &dev->priv; |
@@ -643,6 +724,12 @@ static int mlx5_dev_init(struct mlx5_core_dev *dev, struct pci_dev *pdev) | |||
643 | goto err_free_uar; | 724 | goto err_free_uar; |
644 | } | 725 | } |
645 | 726 | ||
727 | err = alloc_comp_eqs(dev); | ||
728 | if (err) { | ||
729 | dev_err(&pdev->dev, "Failed to alloc completion EQs\n"); | ||
730 | goto err_stop_eqs; | ||
731 | } | ||
732 | |||
646 | MLX5_INIT_DOORBELL_LOCK(&priv->cq_uar_lock); | 733 | MLX5_INIT_DOORBELL_LOCK(&priv->cq_uar_lock); |
647 | 734 | ||
648 | mlx5_init_cq_table(dev); | 735 | mlx5_init_cq_table(dev); |
@@ -652,6 +739,9 @@ static int mlx5_dev_init(struct mlx5_core_dev *dev, struct pci_dev *pdev) | |||
652 | 739 | ||
653 | return 0; | 740 | return 0; |
654 | 741 | ||
742 | err_stop_eqs: | ||
743 | mlx5_stop_eqs(dev); | ||
744 | |||
655 | err_free_uar: | 745 | err_free_uar: |
656 | mlx5_free_uuars(dev, &priv->uuari); | 746 | mlx5_free_uuars(dev, &priv->uuari); |
657 | 747 | ||
@@ -703,6 +793,7 @@ static void mlx5_dev_cleanup(struct mlx5_core_dev *dev) | |||
703 | mlx5_cleanup_srq_table(dev); | 793 | mlx5_cleanup_srq_table(dev); |
704 | mlx5_cleanup_qp_table(dev); | 794 | mlx5_cleanup_qp_table(dev); |
705 | mlx5_cleanup_cq_table(dev); | 795 | mlx5_cleanup_cq_table(dev); |
796 | free_comp_eqs(dev); | ||
706 | mlx5_stop_eqs(dev); | 797 | mlx5_stop_eqs(dev); |
707 | mlx5_free_uuars(dev, &priv->uuari); | 798 | mlx5_free_uuars(dev, &priv->uuari); |
708 | mlx5_eq_cleanup(dev); | 799 | mlx5_eq_cleanup(dev); |
diff --git a/include/linux/mlx5/driver.h b/include/linux/mlx5/driver.h index 8fedd39a9a60..f250f6580dad 100644 --- a/include/linux/mlx5/driver.h +++ b/include/linux/mlx5/driver.h | |||
@@ -410,7 +410,7 @@ struct mlx5_core_srq { | |||
410 | struct mlx5_eq_table { | 410 | struct mlx5_eq_table { |
411 | void __iomem *update_ci; | 411 | void __iomem *update_ci; |
412 | void __iomem *update_arm_ci; | 412 | void __iomem *update_arm_ci; |
413 | struct list_head *comp_eq_head; | 413 | struct list_head comp_eqs_list; |
414 | struct mlx5_eq pages_eq; | 414 | struct mlx5_eq pages_eq; |
415 | struct mlx5_eq async_eq; | 415 | struct mlx5_eq async_eq; |
416 | struct mlx5_eq cmd_eq; | 416 | struct mlx5_eq cmd_eq; |
@@ -725,6 +725,7 @@ int mlx5_create_map_eq(struct mlx5_core_dev *dev, struct mlx5_eq *eq, u8 vecidx, | |||
725 | int mlx5_destroy_unmap_eq(struct mlx5_core_dev *dev, struct mlx5_eq *eq); | 725 | int mlx5_destroy_unmap_eq(struct mlx5_core_dev *dev, struct mlx5_eq *eq); |
726 | int mlx5_start_eqs(struct mlx5_core_dev *dev); | 726 | int mlx5_start_eqs(struct mlx5_core_dev *dev); |
727 | int mlx5_stop_eqs(struct mlx5_core_dev *dev); | 727 | int mlx5_stop_eqs(struct mlx5_core_dev *dev); |
728 | int mlx5_vector2eqn(struct mlx5_core_dev *dev, int vector, int *eqn, int *irqn); | ||
728 | int mlx5_core_attach_mcg(struct mlx5_core_dev *dev, union ib_gid *mgid, u32 qpn); | 729 | int mlx5_core_attach_mcg(struct mlx5_core_dev *dev, union ib_gid *mgid, u32 qpn); |
729 | int mlx5_core_detach_mcg(struct mlx5_core_dev *dev, union ib_gid *mgid, u32 qpn); | 730 | int mlx5_core_detach_mcg(struct mlx5_core_dev *dev, union ib_gid *mgid, u32 qpn); |
730 | 731 | ||