2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005, 2006, 2007, 2008 Mellanox Technologies.
5 * Copyright (c) 2005, 2006, 2007 Cisco Systems, Inc. All rights reserved.
7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU
9 * General Public License (GPL) Version 2, available from the file
10 * COPYING in the main directory of this source tree, or the
11 * OpenIB.org BSD license below:
13 * Redistribution and use in source and binary forms, with or
14 * without modification, are permitted provided that the following
17 * - Redistributions of source code must retain the above
18 * copyright notice, this list of conditions and the following
21 * - Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials
24 * provided with the distribution.
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 #include <linux/sched.h>
37 #include <linux/pci.h>
38 #include <linux/errno.h>
39 #include <linux/kernel.h>
41 #include <linux/slab.h>
42 #include <linux/mlx4/cmd.h>
43 #include <linux/mlx4/qp.h>
44 #include <linux/if_ether.h>
45 #include <linux/etherdevice.h>
50 #define MLX4_MAC_VALID (1ull << 63)
53 struct list_head list;
59 struct list_head list;
74 struct list_head list;
76 enum mlx4_protocol prot;
77 enum mlx4_steer_type steer;
81 RES_QP_BUSY = RES_ANY_BUSY,
83 /* QP number was allocated */
86 /* ICM memory for QP context was mapped */
89 /* QP is in hw ownership */
94 struct res_common com;
99 struct list_head mcg_list;
104 enum res_mtt_states {
105 RES_MTT_BUSY = RES_ANY_BUSY,
109 static inline const char *mtt_states_str(enum res_mtt_states state)
112 case RES_MTT_BUSY: return "RES_MTT_BUSY";
113 case RES_MTT_ALLOCATED: return "RES_MTT_ALLOCATED";
114 default: return "Unknown";
119 struct res_common com;
124 enum res_mpt_states {
125 RES_MPT_BUSY = RES_ANY_BUSY,
132 struct res_common com;
138 RES_EQ_BUSY = RES_ANY_BUSY,
144 struct res_common com;
149 RES_CQ_BUSY = RES_ANY_BUSY,
155 struct res_common com;
160 enum res_srq_states {
161 RES_SRQ_BUSY = RES_ANY_BUSY,
167 struct res_common com;
173 enum res_counter_states {
174 RES_COUNTER_BUSY = RES_ANY_BUSY,
175 RES_COUNTER_ALLOCATED,
179 struct res_common com;
183 enum res_xrcdn_states {
184 RES_XRCD_BUSY = RES_ANY_BUSY,
189 struct res_common com;
193 enum res_fs_rule_states {
194 RES_FS_RULE_BUSY = RES_ANY_BUSY,
195 RES_FS_RULE_ALLOCATED,
199 struct res_common com;
202 static void *res_tracker_lookup(struct rb_root *root, u64 res_id)
204 struct rb_node *node = root->rb_node;
207 struct res_common *res = container_of(node, struct res_common,
210 if (res_id < res->res_id)
211 node = node->rb_left;
212 else if (res_id > res->res_id)
213 node = node->rb_right;
220 static int res_tracker_insert(struct rb_root *root, struct res_common *res)
222 struct rb_node **new = &(root->rb_node), *parent = NULL;
224 /* Figure out where to put new node */
226 struct res_common *this = container_of(*new, struct res_common,
230 if (res->res_id < this->res_id)
231 new = &((*new)->rb_left);
232 else if (res->res_id > this->res_id)
233 new = &((*new)->rb_right);
238 /* Add new node and rebalance tree. */
239 rb_link_node(&res->node, parent, new);
240 rb_insert_color(&res->node, root);
255 static const char *ResourceType(enum mlx4_resource rt)
258 case RES_QP: return "RES_QP";
259 case RES_CQ: return "RES_CQ";
260 case RES_SRQ: return "RES_SRQ";
261 case RES_MPT: return "RES_MPT";
262 case RES_MTT: return "RES_MTT";
263 case RES_MAC: return "RES_MAC";
264 case RES_EQ: return "RES_EQ";
265 case RES_COUNTER: return "RES_COUNTER";
266 case RES_FS_RULE: return "RES_FS_RULE";
267 case RES_XRCD: return "RES_XRCD";
268 default: return "Unknown resource type !!!";
272 int mlx4_init_resource_tracker(struct mlx4_dev *dev)
274 struct mlx4_priv *priv = mlx4_priv(dev);
278 priv->mfunc.master.res_tracker.slave_list =
279 kzalloc(dev->num_slaves * sizeof(struct slave_list),
281 if (!priv->mfunc.master.res_tracker.slave_list)
284 for (i = 0 ; i < dev->num_slaves; i++) {
285 for (t = 0; t < MLX4_NUM_OF_RESOURCE_TYPE; ++t)
286 INIT_LIST_HEAD(&priv->mfunc.master.res_tracker.
287 slave_list[i].res_list[t]);
288 mutex_init(&priv->mfunc.master.res_tracker.slave_list[i].mutex);
291 mlx4_dbg(dev, "Started init_resource_tracker: %ld slaves\n",
293 for (i = 0 ; i < MLX4_NUM_OF_RESOURCE_TYPE; i++)
294 priv->mfunc.master.res_tracker.res_tree[i] = RB_ROOT;
296 spin_lock_init(&priv->mfunc.master.res_tracker.lock);
300 void mlx4_free_resource_tracker(struct mlx4_dev *dev,
301 enum mlx4_res_tracker_free_type type)
303 struct mlx4_priv *priv = mlx4_priv(dev);
306 if (priv->mfunc.master.res_tracker.slave_list) {
307 if (type != RES_TR_FREE_STRUCTS_ONLY)
308 for (i = 0 ; i < dev->num_slaves; i++)
309 if (type == RES_TR_FREE_ALL ||
310 dev->caps.function != i)
311 mlx4_delete_all_resources_for_slave(dev, i);
313 if (type != RES_TR_FREE_SLAVES_ONLY) {
314 kfree(priv->mfunc.master.res_tracker.slave_list);
315 priv->mfunc.master.res_tracker.slave_list = NULL;
320 static void update_pkey_index(struct mlx4_dev *dev, int slave,
321 struct mlx4_cmd_mailbox *inbox)
323 u8 sched = *(u8 *)(inbox->buf + 64);
324 u8 orig_index = *(u8 *)(inbox->buf + 35);
326 struct mlx4_priv *priv = mlx4_priv(dev);
329 port = (sched >> 6 & 1) + 1;
331 new_index = priv->virt2phys_pkey[slave][port - 1][orig_index];
332 *(u8 *)(inbox->buf + 35) = new_index;
335 static void update_gid(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *inbox,
338 struct mlx4_qp_context *qp_ctx = inbox->buf + 8;
339 enum mlx4_qp_optpar optpar = be32_to_cpu(*(__be32 *) inbox->buf);
340 u32 ts = (be32_to_cpu(qp_ctx->flags) >> 16) & 0xff;
342 if (MLX4_QP_ST_UD == ts)
343 qp_ctx->pri_path.mgid_index = 0x80 | slave;
345 if (MLX4_QP_ST_RC == ts || MLX4_QP_ST_UC == ts) {
346 if (optpar & MLX4_QP_OPTPAR_PRIMARY_ADDR_PATH)
347 qp_ctx->pri_path.mgid_index = slave & 0x7F;
348 if (optpar & MLX4_QP_OPTPAR_ALT_ADDR_PATH)
349 qp_ctx->alt_path.mgid_index = slave & 0x7F;
353 static int mpt_mask(struct mlx4_dev *dev)
355 return dev->caps.num_mpts - 1;
358 static void *find_res(struct mlx4_dev *dev, int res_id,
359 enum mlx4_resource type)
361 struct mlx4_priv *priv = mlx4_priv(dev);
363 return res_tracker_lookup(&priv->mfunc.master.res_tracker.res_tree[type],
367 static int get_res(struct mlx4_dev *dev, int slave, u64 res_id,
368 enum mlx4_resource type,
371 struct res_common *r;
374 spin_lock_irq(mlx4_tlock(dev));
375 r = find_res(dev, res_id, type);
381 if (r->state == RES_ANY_BUSY) {
386 if (r->owner != slave) {
391 r->from_state = r->state;
392 r->state = RES_ANY_BUSY;
395 *((struct res_common **)res) = r;
398 spin_unlock_irq(mlx4_tlock(dev));
402 int mlx4_get_slave_from_resource_id(struct mlx4_dev *dev,
403 enum mlx4_resource type,
404 u64 res_id, int *slave)
407 struct res_common *r;
413 spin_lock(mlx4_tlock(dev));
415 r = find_res(dev, id, type);
420 spin_unlock(mlx4_tlock(dev));
425 static void put_res(struct mlx4_dev *dev, int slave, u64 res_id,
426 enum mlx4_resource type)
428 struct res_common *r;
430 spin_lock_irq(mlx4_tlock(dev));
431 r = find_res(dev, res_id, type);
433 r->state = r->from_state;
434 spin_unlock_irq(mlx4_tlock(dev));
437 static struct res_common *alloc_qp_tr(int id)
441 ret = kzalloc(sizeof *ret, GFP_KERNEL);
445 ret->com.res_id = id;
446 ret->com.state = RES_QP_RESERVED;
448 INIT_LIST_HEAD(&ret->mcg_list);
449 spin_lock_init(&ret->mcg_spl);
454 static struct res_common *alloc_mtt_tr(int id, int order)
458 ret = kzalloc(sizeof *ret, GFP_KERNEL);
462 ret->com.res_id = id;
464 ret->com.state = RES_MTT_ALLOCATED;
465 atomic_set(&ret->ref_count, 0);
470 static struct res_common *alloc_mpt_tr(int id, int key)
474 ret = kzalloc(sizeof *ret, GFP_KERNEL);
478 ret->com.res_id = id;
479 ret->com.state = RES_MPT_RESERVED;
485 static struct res_common *alloc_eq_tr(int id)
489 ret = kzalloc(sizeof *ret, GFP_KERNEL);
493 ret->com.res_id = id;
494 ret->com.state = RES_EQ_RESERVED;
499 static struct res_common *alloc_cq_tr(int id)
503 ret = kzalloc(sizeof *ret, GFP_KERNEL);
507 ret->com.res_id = id;
508 ret->com.state = RES_CQ_ALLOCATED;
509 atomic_set(&ret->ref_count, 0);
514 static struct res_common *alloc_srq_tr(int id)
518 ret = kzalloc(sizeof *ret, GFP_KERNEL);
522 ret->com.res_id = id;
523 ret->com.state = RES_SRQ_ALLOCATED;
524 atomic_set(&ret->ref_count, 0);
529 static struct res_common *alloc_counter_tr(int id)
531 struct res_counter *ret;
533 ret = kzalloc(sizeof *ret, GFP_KERNEL);
537 ret->com.res_id = id;
538 ret->com.state = RES_COUNTER_ALLOCATED;
543 static struct res_common *alloc_xrcdn_tr(int id)
545 struct res_xrcdn *ret;
547 ret = kzalloc(sizeof *ret, GFP_KERNEL);
551 ret->com.res_id = id;
552 ret->com.state = RES_XRCD_ALLOCATED;
557 static struct res_common *alloc_fs_rule_tr(u64 id)
559 struct res_fs_rule *ret;
561 ret = kzalloc(sizeof *ret, GFP_KERNEL);
565 ret->com.res_id = id;
566 ret->com.state = RES_FS_RULE_ALLOCATED;
571 static struct res_common *alloc_tr(u64 id, enum mlx4_resource type, int slave,
574 struct res_common *ret;
578 ret = alloc_qp_tr(id);
581 ret = alloc_mpt_tr(id, extra);
584 ret = alloc_mtt_tr(id, extra);
587 ret = alloc_eq_tr(id);
590 ret = alloc_cq_tr(id);
593 ret = alloc_srq_tr(id);
596 printk(KERN_ERR "implementation missing\n");
599 ret = alloc_counter_tr(id);
602 ret = alloc_xrcdn_tr(id);
605 ret = alloc_fs_rule_tr(id);
616 static int add_res_range(struct mlx4_dev *dev, int slave, u64 base, int count,
617 enum mlx4_resource type, int extra)
621 struct mlx4_priv *priv = mlx4_priv(dev);
622 struct res_common **res_arr;
623 struct mlx4_resource_tracker *tracker = &priv->mfunc.master.res_tracker;
624 struct rb_root *root = &tracker->res_tree[type];
626 res_arr = kzalloc(count * sizeof *res_arr, GFP_KERNEL);
630 for (i = 0; i < count; ++i) {
631 res_arr[i] = alloc_tr(base + i, type, slave, extra);
633 for (--i; i >= 0; --i)
641 spin_lock_irq(mlx4_tlock(dev));
642 for (i = 0; i < count; ++i) {
643 if (find_res(dev, base + i, type)) {
647 err = res_tracker_insert(root, res_arr[i]);
650 list_add_tail(&res_arr[i]->list,
651 &tracker->slave_list[slave].res_list[type]);
653 spin_unlock_irq(mlx4_tlock(dev));
659 for (--i; i >= base; --i)
660 rb_erase(&res_arr[i]->node, root);
662 spin_unlock_irq(mlx4_tlock(dev));
664 for (i = 0; i < count; ++i)
672 static int remove_qp_ok(struct res_qp *res)
674 if (res->com.state == RES_QP_BUSY)
676 else if (res->com.state != RES_QP_RESERVED)
682 static int remove_mtt_ok(struct res_mtt *res, int order)
684 if (res->com.state == RES_MTT_BUSY ||
685 atomic_read(&res->ref_count)) {
686 printk(KERN_DEBUG "%s-%d: state %s, ref_count %d\n",
688 mtt_states_str(res->com.state),
689 atomic_read(&res->ref_count));
691 } else if (res->com.state != RES_MTT_ALLOCATED)
693 else if (res->order != order)
699 static int remove_mpt_ok(struct res_mpt *res)
701 if (res->com.state == RES_MPT_BUSY)
703 else if (res->com.state != RES_MPT_RESERVED)
709 static int remove_eq_ok(struct res_eq *res)
711 if (res->com.state == RES_MPT_BUSY)
713 else if (res->com.state != RES_MPT_RESERVED)
719 static int remove_counter_ok(struct res_counter *res)
721 if (res->com.state == RES_COUNTER_BUSY)
723 else if (res->com.state != RES_COUNTER_ALLOCATED)
729 static int remove_xrcdn_ok(struct res_xrcdn *res)
731 if (res->com.state == RES_XRCD_BUSY)
733 else if (res->com.state != RES_XRCD_ALLOCATED)
739 static int remove_fs_rule_ok(struct res_fs_rule *res)
741 if (res->com.state == RES_FS_RULE_BUSY)
743 else if (res->com.state != RES_FS_RULE_ALLOCATED)
749 static int remove_cq_ok(struct res_cq *res)
751 if (res->com.state == RES_CQ_BUSY)
753 else if (res->com.state != RES_CQ_ALLOCATED)
759 static int remove_srq_ok(struct res_srq *res)
761 if (res->com.state == RES_SRQ_BUSY)
763 else if (res->com.state != RES_SRQ_ALLOCATED)
769 static int remove_ok(struct res_common *res, enum mlx4_resource type, int extra)
773 return remove_qp_ok((struct res_qp *)res);
775 return remove_cq_ok((struct res_cq *)res);
777 return remove_srq_ok((struct res_srq *)res);
779 return remove_mpt_ok((struct res_mpt *)res);
781 return remove_mtt_ok((struct res_mtt *)res, extra);
785 return remove_eq_ok((struct res_eq *)res);
787 return remove_counter_ok((struct res_counter *)res);
789 return remove_xrcdn_ok((struct res_xrcdn *)res);
791 return remove_fs_rule_ok((struct res_fs_rule *)res);
797 static int rem_res_range(struct mlx4_dev *dev, int slave, u64 base, int count,
798 enum mlx4_resource type, int extra)
802 struct mlx4_priv *priv = mlx4_priv(dev);
803 struct mlx4_resource_tracker *tracker = &priv->mfunc.master.res_tracker;
804 struct res_common *r;
806 spin_lock_irq(mlx4_tlock(dev));
807 for (i = base; i < base + count; ++i) {
808 r = res_tracker_lookup(&tracker->res_tree[type], i);
813 if (r->owner != slave) {
817 err = remove_ok(r, type, extra);
822 for (i = base; i < base + count; ++i) {
823 r = res_tracker_lookup(&tracker->res_tree[type], i);
824 rb_erase(&r->node, &tracker->res_tree[type]);
831 spin_unlock_irq(mlx4_tlock(dev));
836 static int qp_res_start_move_to(struct mlx4_dev *dev, int slave, int qpn,
837 enum res_qp_states state, struct res_qp **qp,
840 struct mlx4_priv *priv = mlx4_priv(dev);
841 struct mlx4_resource_tracker *tracker = &priv->mfunc.master.res_tracker;
845 spin_lock_irq(mlx4_tlock(dev));
846 r = res_tracker_lookup(&tracker->res_tree[RES_QP], qpn);
849 else if (r->com.owner != slave)
854 mlx4_dbg(dev, "%s: failed RES_QP, 0x%llx\n",
855 __func__, r->com.res_id);
859 case RES_QP_RESERVED:
860 if (r->com.state == RES_QP_MAPPED && !alloc)
863 mlx4_dbg(dev, "failed RES_QP, 0x%llx\n", r->com.res_id);
868 if ((r->com.state == RES_QP_RESERVED && alloc) ||
869 r->com.state == RES_QP_HW)
872 mlx4_dbg(dev, "failed RES_QP, 0x%llx\n",
880 if (r->com.state != RES_QP_MAPPED)
888 r->com.from_state = r->com.state;
889 r->com.to_state = state;
890 r->com.state = RES_QP_BUSY;
896 spin_unlock_irq(mlx4_tlock(dev));
901 static int mr_res_start_move_to(struct mlx4_dev *dev, int slave, int index,
902 enum res_mpt_states state, struct res_mpt **mpt)
904 struct mlx4_priv *priv = mlx4_priv(dev);
905 struct mlx4_resource_tracker *tracker = &priv->mfunc.master.res_tracker;
909 spin_lock_irq(mlx4_tlock(dev));
910 r = res_tracker_lookup(&tracker->res_tree[RES_MPT], index);
913 else if (r->com.owner != slave)
921 case RES_MPT_RESERVED:
922 if (r->com.state != RES_MPT_MAPPED)
927 if (r->com.state != RES_MPT_RESERVED &&
928 r->com.state != RES_MPT_HW)
933 if (r->com.state != RES_MPT_MAPPED)
941 r->com.from_state = r->com.state;
942 r->com.to_state = state;
943 r->com.state = RES_MPT_BUSY;
949 spin_unlock_irq(mlx4_tlock(dev));
954 static int eq_res_start_move_to(struct mlx4_dev *dev, int slave, int index,
955 enum res_eq_states state, struct res_eq **eq)
957 struct mlx4_priv *priv = mlx4_priv(dev);
958 struct mlx4_resource_tracker *tracker = &priv->mfunc.master.res_tracker;
962 spin_lock_irq(mlx4_tlock(dev));
963 r = res_tracker_lookup(&tracker->res_tree[RES_EQ], index);
966 else if (r->com.owner != slave)
974 case RES_EQ_RESERVED:
975 if (r->com.state != RES_EQ_HW)
980 if (r->com.state != RES_EQ_RESERVED)
989 r->com.from_state = r->com.state;
990 r->com.to_state = state;
991 r->com.state = RES_EQ_BUSY;
997 spin_unlock_irq(mlx4_tlock(dev));
1002 static int cq_res_start_move_to(struct mlx4_dev *dev, int slave, int cqn,
1003 enum res_cq_states state, struct res_cq **cq)
1005 struct mlx4_priv *priv = mlx4_priv(dev);
1006 struct mlx4_resource_tracker *tracker = &priv->mfunc.master.res_tracker;
1010 spin_lock_irq(mlx4_tlock(dev));
1011 r = res_tracker_lookup(&tracker->res_tree[RES_CQ], cqn);
1014 else if (r->com.owner != slave)
1022 case RES_CQ_ALLOCATED:
1023 if (r->com.state != RES_CQ_HW)
1025 else if (atomic_read(&r->ref_count))
1032 if (r->com.state != RES_CQ_ALLOCATED)
1043 r->com.from_state = r->com.state;
1044 r->com.to_state = state;
1045 r->com.state = RES_CQ_BUSY;
1051 spin_unlock_irq(mlx4_tlock(dev));
1056 static int srq_res_start_move_to(struct mlx4_dev *dev, int slave, int index,
1057 enum res_cq_states state, struct res_srq **srq)
1059 struct mlx4_priv *priv = mlx4_priv(dev);
1060 struct mlx4_resource_tracker *tracker = &priv->mfunc.master.res_tracker;
1064 spin_lock_irq(mlx4_tlock(dev));
1065 r = res_tracker_lookup(&tracker->res_tree[RES_SRQ], index);
1068 else if (r->com.owner != slave)
1076 case RES_SRQ_ALLOCATED:
1077 if (r->com.state != RES_SRQ_HW)
1079 else if (atomic_read(&r->ref_count))
1084 if (r->com.state != RES_SRQ_ALLOCATED)
1093 r->com.from_state = r->com.state;
1094 r->com.to_state = state;
1095 r->com.state = RES_SRQ_BUSY;
1101 spin_unlock_irq(mlx4_tlock(dev));
1106 static void res_abort_move(struct mlx4_dev *dev, int slave,
1107 enum mlx4_resource type, int id)
1109 struct mlx4_priv *priv = mlx4_priv(dev);
1110 struct mlx4_resource_tracker *tracker = &priv->mfunc.master.res_tracker;
1111 struct res_common *r;
1113 spin_lock_irq(mlx4_tlock(dev));
1114 r = res_tracker_lookup(&tracker->res_tree[type], id);
1115 if (r && (r->owner == slave))
1116 r->state = r->from_state;
1117 spin_unlock_irq(mlx4_tlock(dev));
1120 static void res_end_move(struct mlx4_dev *dev, int slave,
1121 enum mlx4_resource type, int id)
1123 struct mlx4_priv *priv = mlx4_priv(dev);
1124 struct mlx4_resource_tracker *tracker = &priv->mfunc.master.res_tracker;
1125 struct res_common *r;
1127 spin_lock_irq(mlx4_tlock(dev));
1128 r = res_tracker_lookup(&tracker->res_tree[type], id);
1129 if (r && (r->owner == slave))
1130 r->state = r->to_state;
1131 spin_unlock_irq(mlx4_tlock(dev));
1134 static int valid_reserved(struct mlx4_dev *dev, int slave, int qpn)
1136 return mlx4_is_qp_reserved(dev, qpn) &&
1137 (mlx4_is_master(dev) || mlx4_is_guest_proxy(dev, slave, qpn));
1140 static int fw_reserved(struct mlx4_dev *dev, int qpn)
1142 return qpn < dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW];
1145 static int qp_alloc_res(struct mlx4_dev *dev, int slave, int op, int cmd,
1146 u64 in_param, u64 *out_param)
1155 case RES_OP_RESERVE:
1156 count = get_param_l(&in_param);
1157 align = get_param_h(&in_param);
1158 err = __mlx4_qp_reserve_range(dev, count, align, &base);
1162 err = add_res_range(dev, slave, base, count, RES_QP, 0);
1164 __mlx4_qp_release_range(dev, base, count);
1167 set_param_l(out_param, base);
1169 case RES_OP_MAP_ICM:
1170 qpn = get_param_l(&in_param) & 0x7fffff;
1171 if (valid_reserved(dev, slave, qpn)) {
1172 err = add_res_range(dev, slave, qpn, 1, RES_QP, 0);
1177 err = qp_res_start_move_to(dev, slave, qpn, RES_QP_MAPPED,
1182 if (!fw_reserved(dev, qpn)) {
1183 err = __mlx4_qp_alloc_icm(dev, qpn);
1185 res_abort_move(dev, slave, RES_QP, qpn);
1190 res_end_move(dev, slave, RES_QP, qpn);
1200 static int mtt_alloc_res(struct mlx4_dev *dev, int slave, int op, int cmd,
1201 u64 in_param, u64 *out_param)
1207 if (op != RES_OP_RESERVE_AND_MAP)
1210 order = get_param_l(&in_param);
1211 base = __mlx4_alloc_mtt_range(dev, order);
1215 err = add_res_range(dev, slave, base, 1, RES_MTT, order);
1217 __mlx4_free_mtt_range(dev, base, order);
1219 set_param_l(out_param, base);
1224 static int mpt_alloc_res(struct mlx4_dev *dev, int slave, int op, int cmd,
1225 u64 in_param, u64 *out_param)
1230 struct res_mpt *mpt;
1233 case RES_OP_RESERVE:
1234 index = __mlx4_mr_reserve(dev);
1237 id = index & mpt_mask(dev);
1239 err = add_res_range(dev, slave, id, 1, RES_MPT, index);
1241 __mlx4_mr_release(dev, index);
1244 set_param_l(out_param, index);
1246 case RES_OP_MAP_ICM:
1247 index = get_param_l(&in_param);
1248 id = index & mpt_mask(dev);
1249 err = mr_res_start_move_to(dev, slave, id,
1250 RES_MPT_MAPPED, &mpt);
1254 err = __mlx4_mr_alloc_icm(dev, mpt->key);
1256 res_abort_move(dev, slave, RES_MPT, id);
1260 res_end_move(dev, slave, RES_MPT, id);
1266 static int cq_alloc_res(struct mlx4_dev *dev, int slave, int op, int cmd,
1267 u64 in_param, u64 *out_param)
1273 case RES_OP_RESERVE_AND_MAP:
1274 err = __mlx4_cq_alloc_icm(dev, &cqn);
1278 err = add_res_range(dev, slave, cqn, 1, RES_CQ, 0);
1280 __mlx4_cq_free_icm(dev, cqn);
1284 set_param_l(out_param, cqn);
1294 static int srq_alloc_res(struct mlx4_dev *dev, int slave, int op, int cmd,
1295 u64 in_param, u64 *out_param)
1301 case RES_OP_RESERVE_AND_MAP:
1302 err = __mlx4_srq_alloc_icm(dev, &srqn);
1306 err = add_res_range(dev, slave, srqn, 1, RES_SRQ, 0);
1308 __mlx4_srq_free_icm(dev, srqn);
1312 set_param_l(out_param, srqn);
1322 static int mac_add_to_slave(struct mlx4_dev *dev, int slave, u64 mac, int port)
1324 struct mlx4_priv *priv = mlx4_priv(dev);
1325 struct mlx4_resource_tracker *tracker = &priv->mfunc.master.res_tracker;
1326 struct mac_res *res;
1328 res = kzalloc(sizeof *res, GFP_KERNEL);
1332 res->port = (u8) port;
1333 list_add_tail(&res->list,
1334 &tracker->slave_list[slave].res_list[RES_MAC]);
1338 static void mac_del_from_slave(struct mlx4_dev *dev, int slave, u64 mac,
1341 struct mlx4_priv *priv = mlx4_priv(dev);
1342 struct mlx4_resource_tracker *tracker = &priv->mfunc.master.res_tracker;
1343 struct list_head *mac_list =
1344 &tracker->slave_list[slave].res_list[RES_MAC];
1345 struct mac_res *res, *tmp;
1347 list_for_each_entry_safe(res, tmp, mac_list, list) {
1348 if (res->mac == mac && res->port == (u8) port) {
1349 list_del(&res->list);
1356 static void rem_slave_macs(struct mlx4_dev *dev, int slave)
1358 struct mlx4_priv *priv = mlx4_priv(dev);
1359 struct mlx4_resource_tracker *tracker = &priv->mfunc.master.res_tracker;
1360 struct list_head *mac_list =
1361 &tracker->slave_list[slave].res_list[RES_MAC];
1362 struct mac_res *res, *tmp;
1364 list_for_each_entry_safe(res, tmp, mac_list, list) {
1365 list_del(&res->list);
1366 __mlx4_unregister_mac(dev, res->port, res->mac);
1371 static int mac_alloc_res(struct mlx4_dev *dev, int slave, int op, int cmd,
1372 u64 in_param, u64 *out_param)
1378 if (op != RES_OP_RESERVE_AND_MAP)
1381 port = get_param_l(out_param);
1384 err = __mlx4_register_mac(dev, port, mac);
1386 set_param_l(out_param, err);
1391 err = mac_add_to_slave(dev, slave, mac, port);
1393 __mlx4_unregister_mac(dev, port, mac);
1398 static int vlan_alloc_res(struct mlx4_dev *dev, int slave, int op, int cmd,
1399 u64 in_param, u64 *out_param)
1404 static int counter_alloc_res(struct mlx4_dev *dev, int slave, int op, int cmd,
1405 u64 in_param, u64 *out_param)
1410 if (op != RES_OP_RESERVE)
1413 err = __mlx4_counter_alloc(dev, &index);
1417 err = add_res_range(dev, slave, index, 1, RES_COUNTER, 0);
1419 __mlx4_counter_free(dev, index);
1421 set_param_l(out_param, index);
1426 static int xrcdn_alloc_res(struct mlx4_dev *dev, int slave, int op, int cmd,
1427 u64 in_param, u64 *out_param)
1432 if (op != RES_OP_RESERVE)
1435 err = __mlx4_xrcd_alloc(dev, &xrcdn);
1439 err = add_res_range(dev, slave, xrcdn, 1, RES_XRCD, 0);
1441 __mlx4_xrcd_free(dev, xrcdn);
1443 set_param_l(out_param, xrcdn);
1448 int mlx4_ALLOC_RES_wrapper(struct mlx4_dev *dev, int slave,
1449 struct mlx4_vhcr *vhcr,
1450 struct mlx4_cmd_mailbox *inbox,
1451 struct mlx4_cmd_mailbox *outbox,
1452 struct mlx4_cmd_info *cmd)
1455 int alop = vhcr->op_modifier;
1457 switch (vhcr->in_modifier) {
1459 err = qp_alloc_res(dev, slave, vhcr->op_modifier, alop,
1460 vhcr->in_param, &vhcr->out_param);
1464 err = mtt_alloc_res(dev, slave, vhcr->op_modifier, alop,
1465 vhcr->in_param, &vhcr->out_param);
1469 err = mpt_alloc_res(dev, slave, vhcr->op_modifier, alop,
1470 vhcr->in_param, &vhcr->out_param);
1474 err = cq_alloc_res(dev, slave, vhcr->op_modifier, alop,
1475 vhcr->in_param, &vhcr->out_param);
1479 err = srq_alloc_res(dev, slave, vhcr->op_modifier, alop,
1480 vhcr->in_param, &vhcr->out_param);
1484 err = mac_alloc_res(dev, slave, vhcr->op_modifier, alop,
1485 vhcr->in_param, &vhcr->out_param);
1489 err = vlan_alloc_res(dev, slave, vhcr->op_modifier, alop,
1490 vhcr->in_param, &vhcr->out_param);
1494 err = counter_alloc_res(dev, slave, vhcr->op_modifier, alop,
1495 vhcr->in_param, &vhcr->out_param);
1499 err = xrcdn_alloc_res(dev, slave, vhcr->op_modifier, alop,
1500 vhcr->in_param, &vhcr->out_param);
1511 static int qp_free_res(struct mlx4_dev *dev, int slave, int op, int cmd,
1520 case RES_OP_RESERVE:
1521 base = get_param_l(&in_param) & 0x7fffff;
1522 count = get_param_h(&in_param);
1523 err = rem_res_range(dev, slave, base, count, RES_QP, 0);
1526 __mlx4_qp_release_range(dev, base, count);
1528 case RES_OP_MAP_ICM:
1529 qpn = get_param_l(&in_param) & 0x7fffff;
1530 err = qp_res_start_move_to(dev, slave, qpn, RES_QP_RESERVED,
1535 if (!fw_reserved(dev, qpn))
1536 __mlx4_qp_free_icm(dev, qpn);
1538 res_end_move(dev, slave, RES_QP, qpn);
1540 if (valid_reserved(dev, slave, qpn))
1541 err = rem_res_range(dev, slave, qpn, 1, RES_QP, 0);
1550 static int mtt_free_res(struct mlx4_dev *dev, int slave, int op, int cmd,
1551 u64 in_param, u64 *out_param)
1557 if (op != RES_OP_RESERVE_AND_MAP)
1560 base = get_param_l(&in_param);
1561 order = get_param_h(&in_param);
1562 err = rem_res_range(dev, slave, base, 1, RES_MTT, order);
1564 __mlx4_free_mtt_range(dev, base, order);
1568 static int mpt_free_res(struct mlx4_dev *dev, int slave, int op, int cmd,
1574 struct res_mpt *mpt;
1577 case RES_OP_RESERVE:
1578 index = get_param_l(&in_param);
1579 id = index & mpt_mask(dev);
1580 err = get_res(dev, slave, id, RES_MPT, &mpt);
1584 put_res(dev, slave, id, RES_MPT);
1586 err = rem_res_range(dev, slave, id, 1, RES_MPT, 0);
1589 __mlx4_mr_release(dev, index);
1591 case RES_OP_MAP_ICM:
1592 index = get_param_l(&in_param);
1593 id = index & mpt_mask(dev);
1594 err = mr_res_start_move_to(dev, slave, id,
1595 RES_MPT_RESERVED, &mpt);
1599 __mlx4_mr_free_icm(dev, mpt->key);
1600 res_end_move(dev, slave, RES_MPT, id);
1610 static int cq_free_res(struct mlx4_dev *dev, int slave, int op, int cmd,
1611 u64 in_param, u64 *out_param)
1617 case RES_OP_RESERVE_AND_MAP:
1618 cqn = get_param_l(&in_param);
1619 err = rem_res_range(dev, slave, cqn, 1, RES_CQ, 0);
1623 __mlx4_cq_free_icm(dev, cqn);
1634 static int srq_free_res(struct mlx4_dev *dev, int slave, int op, int cmd,
1635 u64 in_param, u64 *out_param)
1641 case RES_OP_RESERVE_AND_MAP:
1642 srqn = get_param_l(&in_param);
1643 err = rem_res_range(dev, slave, srqn, 1, RES_SRQ, 0);
1647 __mlx4_srq_free_icm(dev, srqn);
1658 static int mac_free_res(struct mlx4_dev *dev, int slave, int op, int cmd,
1659 u64 in_param, u64 *out_param)
1665 case RES_OP_RESERVE_AND_MAP:
1666 port = get_param_l(out_param);
1667 mac_del_from_slave(dev, slave, in_param, port);
1668 __mlx4_unregister_mac(dev, port, in_param);
1679 static int vlan_free_res(struct mlx4_dev *dev, int slave, int op, int cmd,
1680 u64 in_param, u64 *out_param)
1685 static int counter_free_res(struct mlx4_dev *dev, int slave, int op, int cmd,
1686 u64 in_param, u64 *out_param)
1691 if (op != RES_OP_RESERVE)
1694 index = get_param_l(&in_param);
1695 err = rem_res_range(dev, slave, index, 1, RES_COUNTER, 0);
1699 __mlx4_counter_free(dev, index);
1704 static int xrcdn_free_res(struct mlx4_dev *dev, int slave, int op, int cmd,
1705 u64 in_param, u64 *out_param)
1710 if (op != RES_OP_RESERVE)
1713 xrcdn = get_param_l(&in_param);
1714 err = rem_res_range(dev, slave, xrcdn, 1, RES_XRCD, 0);
1718 __mlx4_xrcd_free(dev, xrcdn);
1723 int mlx4_FREE_RES_wrapper(struct mlx4_dev *dev, int slave,
1724 struct mlx4_vhcr *vhcr,
1725 struct mlx4_cmd_mailbox *inbox,
1726 struct mlx4_cmd_mailbox *outbox,
1727 struct mlx4_cmd_info *cmd)
1730 int alop = vhcr->op_modifier;
1732 switch (vhcr->in_modifier) {
1734 err = qp_free_res(dev, slave, vhcr->op_modifier, alop,
1739 err = mtt_free_res(dev, slave, vhcr->op_modifier, alop,
1740 vhcr->in_param, &vhcr->out_param);
1744 err = mpt_free_res(dev, slave, vhcr->op_modifier, alop,
1749 err = cq_free_res(dev, slave, vhcr->op_modifier, alop,
1750 vhcr->in_param, &vhcr->out_param);
1754 err = srq_free_res(dev, slave, vhcr->op_modifier, alop,
1755 vhcr->in_param, &vhcr->out_param);
1759 err = mac_free_res(dev, slave, vhcr->op_modifier, alop,
1760 vhcr->in_param, &vhcr->out_param);
1764 err = vlan_free_res(dev, slave, vhcr->op_modifier, alop,
1765 vhcr->in_param, &vhcr->out_param);
1769 err = counter_free_res(dev, slave, vhcr->op_modifier, alop,
1770 vhcr->in_param, &vhcr->out_param);
1774 err = xrcdn_free_res(dev, slave, vhcr->op_modifier, alop,
1775 vhcr->in_param, &vhcr->out_param);
1783 /* ugly but other choices are uglier */
1784 static int mr_phys_mpt(struct mlx4_mpt_entry *mpt)
1786 return (be32_to_cpu(mpt->flags) >> 9) & 1;
1789 static int mr_get_mtt_addr(struct mlx4_mpt_entry *mpt)
1791 return (int)be64_to_cpu(mpt->mtt_addr) & 0xfffffff8;
1794 static int mr_get_mtt_size(struct mlx4_mpt_entry *mpt)
1796 return be32_to_cpu(mpt->mtt_sz);
1799 static int qp_get_mtt_addr(struct mlx4_qp_context *qpc)
1801 return be32_to_cpu(qpc->mtt_base_addr_l) & 0xfffffff8;
1804 static int srq_get_mtt_addr(struct mlx4_srq_context *srqc)
1806 return be32_to_cpu(srqc->mtt_base_addr_l) & 0xfffffff8;
1809 static int qp_get_mtt_size(struct mlx4_qp_context *qpc)
1811 int page_shift = (qpc->log_page_size & 0x3f) + 12;
1812 int log_sq_size = (qpc->sq_size_stride >> 3) & 0xf;
1813 int log_sq_sride = qpc->sq_size_stride & 7;
1814 int log_rq_size = (qpc->rq_size_stride >> 3) & 0xf;
1815 int log_rq_stride = qpc->rq_size_stride & 7;
1816 int srq = (be32_to_cpu(qpc->srqn) >> 24) & 1;
1817 int rss = (be32_to_cpu(qpc->flags) >> 13) & 1;
1818 int xrc = (be32_to_cpu(qpc->local_qpn) >> 23) & 1;
1823 int page_offset = (be32_to_cpu(qpc->params2) >> 6) & 0x3f;
1825 sq_size = 1 << (log_sq_size + log_sq_sride + 4);
1826 rq_size = (srq|rss|xrc) ? 0 : (1 << (log_rq_size + log_rq_stride + 4));
1827 total_mem = sq_size + rq_size;
1829 roundup_pow_of_two((total_mem + (page_offset << 6)) >>
1835 static int check_mtt_range(struct mlx4_dev *dev, int slave, int start,
1836 int size, struct res_mtt *mtt)
1838 int res_start = mtt->com.res_id;
1839 int res_size = (1 << mtt->order);
1841 if (start < res_start || start + size > res_start + res_size)
1846 int mlx4_SW2HW_MPT_wrapper(struct mlx4_dev *dev, int slave,
1847 struct mlx4_vhcr *vhcr,
1848 struct mlx4_cmd_mailbox *inbox,
1849 struct mlx4_cmd_mailbox *outbox,
1850 struct mlx4_cmd_info *cmd)
1853 int index = vhcr->in_modifier;
1854 struct res_mtt *mtt;
1855 struct res_mpt *mpt;
1856 int mtt_base = mr_get_mtt_addr(inbox->buf) / dev->caps.mtt_entry_sz;
1860 id = index & mpt_mask(dev);
1861 err = mr_res_start_move_to(dev, slave, id, RES_MPT_HW, &mpt);
1865 phys = mr_phys_mpt(inbox->buf);
1867 err = get_res(dev, slave, mtt_base, RES_MTT, &mtt);
1871 err = check_mtt_range(dev, slave, mtt_base,
1872 mr_get_mtt_size(inbox->buf), mtt);
1879 err = mlx4_DMA_wrapper(dev, slave, vhcr, inbox, outbox, cmd);
1884 atomic_inc(&mtt->ref_count);
1885 put_res(dev, slave, mtt->com.res_id, RES_MTT);
1888 res_end_move(dev, slave, RES_MPT, id);
1893 put_res(dev, slave, mtt->com.res_id, RES_MTT);
1895 res_abort_move(dev, slave, RES_MPT, id);
1900 int mlx4_HW2SW_MPT_wrapper(struct mlx4_dev *dev, int slave,
1901 struct mlx4_vhcr *vhcr,
1902 struct mlx4_cmd_mailbox *inbox,
1903 struct mlx4_cmd_mailbox *outbox,
1904 struct mlx4_cmd_info *cmd)
1907 int index = vhcr->in_modifier;
1908 struct res_mpt *mpt;
1911 id = index & mpt_mask(dev);
1912 err = mr_res_start_move_to(dev, slave, id, RES_MPT_MAPPED, &mpt);
1916 err = mlx4_DMA_wrapper(dev, slave, vhcr, inbox, outbox, cmd);
1921 atomic_dec(&mpt->mtt->ref_count);
1923 res_end_move(dev, slave, RES_MPT, id);
1927 res_abort_move(dev, slave, RES_MPT, id);
1932 int mlx4_QUERY_MPT_wrapper(struct mlx4_dev *dev, int slave,
1933 struct mlx4_vhcr *vhcr,
1934 struct mlx4_cmd_mailbox *inbox,
1935 struct mlx4_cmd_mailbox *outbox,
1936 struct mlx4_cmd_info *cmd)
1939 int index = vhcr->in_modifier;
1940 struct res_mpt *mpt;
1943 id = index & mpt_mask(dev);
1944 err = get_res(dev, slave, id, RES_MPT, &mpt);
1948 if (mpt->com.from_state != RES_MPT_HW) {
1953 err = mlx4_DMA_wrapper(dev, slave, vhcr, inbox, outbox, cmd);
1956 put_res(dev, slave, id, RES_MPT);
1960 static int qp_get_rcqn(struct mlx4_qp_context *qpc)
1962 return be32_to_cpu(qpc->cqn_recv) & 0xffffff;
1965 static int qp_get_scqn(struct mlx4_qp_context *qpc)
1967 return be32_to_cpu(qpc->cqn_send) & 0xffffff;
1970 static u32 qp_get_srqn(struct mlx4_qp_context *qpc)
1972 return be32_to_cpu(qpc->srqn) & 0x1ffffff;
1975 static void adjust_proxy_tun_qkey(struct mlx4_dev *dev, struct mlx4_vhcr *vhcr,
1976 struct mlx4_qp_context *context)
1978 u32 qpn = vhcr->in_modifier & 0xffffff;
1981 if (mlx4_get_parav_qkey(dev, qpn, &qkey))
1984 /* adjust qkey in qp context */
1985 context->qkey = cpu_to_be32(qkey);
1988 int mlx4_RST2INIT_QP_wrapper(struct mlx4_dev *dev, int slave,
1989 struct mlx4_vhcr *vhcr,
1990 struct mlx4_cmd_mailbox *inbox,
1991 struct mlx4_cmd_mailbox *outbox,
1992 struct mlx4_cmd_info *cmd)
1995 int qpn = vhcr->in_modifier & 0x7fffff;
1996 struct res_mtt *mtt;
1998 struct mlx4_qp_context *qpc = inbox->buf + 8;
1999 int mtt_base = qp_get_mtt_addr(qpc) / dev->caps.mtt_entry_sz;
2000 int mtt_size = qp_get_mtt_size(qpc);
2003 int rcqn = qp_get_rcqn(qpc);
2004 int scqn = qp_get_scqn(qpc);
2005 u32 srqn = qp_get_srqn(qpc) & 0xffffff;
2006 int use_srq = (qp_get_srqn(qpc) >> 24) & 1;
2007 struct res_srq *srq;
2008 int local_qpn = be32_to_cpu(qpc->local_qpn) & 0xffffff;
2010 err = qp_res_start_move_to(dev, slave, qpn, RES_QP_HW, &qp, 0);
2013 qp->local_qpn = local_qpn;
2015 err = get_res(dev, slave, mtt_base, RES_MTT, &mtt);
2019 err = check_mtt_range(dev, slave, mtt_base, mtt_size, mtt);
2023 err = get_res(dev, slave, rcqn, RES_CQ, &rcq);
2028 err = get_res(dev, slave, scqn, RES_CQ, &scq);
2035 err = get_res(dev, slave, srqn, RES_SRQ, &srq);
2040 adjust_proxy_tun_qkey(dev, vhcr, qpc);
2041 update_pkey_index(dev, slave, inbox);
2042 err = mlx4_DMA_wrapper(dev, slave, vhcr, inbox, outbox, cmd);
2045 atomic_inc(&mtt->ref_count);
2047 atomic_inc(&rcq->ref_count);
2049 atomic_inc(&scq->ref_count);
2053 put_res(dev, slave, scqn, RES_CQ);
2056 atomic_inc(&srq->ref_count);
2057 put_res(dev, slave, srqn, RES_SRQ);
2060 put_res(dev, slave, rcqn, RES_CQ);
2061 put_res(dev, slave, mtt_base, RES_MTT);
2062 res_end_move(dev, slave, RES_QP, qpn);
2068 put_res(dev, slave, srqn, RES_SRQ);
2071 put_res(dev, slave, scqn, RES_CQ);
2073 put_res(dev, slave, rcqn, RES_CQ);
2075 put_res(dev, slave, mtt_base, RES_MTT);
2077 res_abort_move(dev, slave, RES_QP, qpn);
2082 static int eq_get_mtt_addr(struct mlx4_eq_context *eqc)
2084 return be32_to_cpu(eqc->mtt_base_addr_l) & 0xfffffff8;
2087 static int eq_get_mtt_size(struct mlx4_eq_context *eqc)
2089 int log_eq_size = eqc->log_eq_size & 0x1f;
2090 int page_shift = (eqc->log_page_size & 0x3f) + 12;
2092 if (log_eq_size + 5 < page_shift)
2095 return 1 << (log_eq_size + 5 - page_shift);
2098 static int cq_get_mtt_addr(struct mlx4_cq_context *cqc)
2100 return be32_to_cpu(cqc->mtt_base_addr_l) & 0xfffffff8;
2103 static int cq_get_mtt_size(struct mlx4_cq_context *cqc)
2105 int log_cq_size = (be32_to_cpu(cqc->logsize_usrpage) >> 24) & 0x1f;
2106 int page_shift = (cqc->log_page_size & 0x3f) + 12;
2108 if (log_cq_size + 5 < page_shift)
2111 return 1 << (log_cq_size + 5 - page_shift);
2114 int mlx4_SW2HW_EQ_wrapper(struct mlx4_dev *dev, int slave,
2115 struct mlx4_vhcr *vhcr,
2116 struct mlx4_cmd_mailbox *inbox,
2117 struct mlx4_cmd_mailbox *outbox,
2118 struct mlx4_cmd_info *cmd)
2121 int eqn = vhcr->in_modifier;
2122 int res_id = (slave << 8) | eqn;
2123 struct mlx4_eq_context *eqc = inbox->buf;
2124 int mtt_base = eq_get_mtt_addr(eqc) / dev->caps.mtt_entry_sz;
2125 int mtt_size = eq_get_mtt_size(eqc);
2127 struct res_mtt *mtt;
2129 err = add_res_range(dev, slave, res_id, 1, RES_EQ, 0);
2132 err = eq_res_start_move_to(dev, slave, res_id, RES_EQ_HW, &eq);
2136 err = get_res(dev, slave, mtt_base, RES_MTT, &mtt);
2140 err = check_mtt_range(dev, slave, mtt_base, mtt_size, mtt);
2144 err = mlx4_DMA_wrapper(dev, slave, vhcr, inbox, outbox, cmd);
2148 atomic_inc(&mtt->ref_count);
2150 put_res(dev, slave, mtt->com.res_id, RES_MTT);
2151 res_end_move(dev, slave, RES_EQ, res_id);
2155 put_res(dev, slave, mtt->com.res_id, RES_MTT);
2157 res_abort_move(dev, slave, RES_EQ, res_id);
2159 rem_res_range(dev, slave, res_id, 1, RES_EQ, 0);
2163 static int get_containing_mtt(struct mlx4_dev *dev, int slave, int start,
2164 int len, struct res_mtt **res)
2166 struct mlx4_priv *priv = mlx4_priv(dev);
2167 struct mlx4_resource_tracker *tracker = &priv->mfunc.master.res_tracker;
2168 struct res_mtt *mtt;
2171 spin_lock_irq(mlx4_tlock(dev));
2172 list_for_each_entry(mtt, &tracker->slave_list[slave].res_list[RES_MTT],
2174 if (!check_mtt_range(dev, slave, start, len, mtt)) {
2176 mtt->com.from_state = mtt->com.state;
2177 mtt->com.state = RES_MTT_BUSY;
2182 spin_unlock_irq(mlx4_tlock(dev));
2187 static int verify_qp_parameters(struct mlx4_dev *dev,
2188 struct mlx4_cmd_mailbox *inbox,
2189 enum qp_transition transition, u8 slave)
2192 struct mlx4_qp_context *qp_ctx;
2193 enum mlx4_qp_optpar optpar;
2195 qp_ctx = inbox->buf + 8;
2196 qp_type = (be32_to_cpu(qp_ctx->flags) >> 16) & 0xff;
2197 optpar = be32_to_cpu(*(__be32 *) inbox->buf);
2202 switch (transition) {
2203 case QP_TRANS_INIT2RTR:
2204 case QP_TRANS_RTR2RTS:
2205 case QP_TRANS_RTS2RTS:
2206 case QP_TRANS_SQD2SQD:
2207 case QP_TRANS_SQD2RTS:
2208 if (slave != mlx4_master_func_num(dev))
2209 /* slaves have only gid index 0 */
2210 if (optpar & MLX4_QP_OPTPAR_PRIMARY_ADDR_PATH)
2211 if (qp_ctx->pri_path.mgid_index)
2213 if (optpar & MLX4_QP_OPTPAR_ALT_ADDR_PATH)
2214 if (qp_ctx->alt_path.mgid_index)
2229 int mlx4_WRITE_MTT_wrapper(struct mlx4_dev *dev, int slave,
2230 struct mlx4_vhcr *vhcr,
2231 struct mlx4_cmd_mailbox *inbox,
2232 struct mlx4_cmd_mailbox *outbox,
2233 struct mlx4_cmd_info *cmd)
2235 struct mlx4_mtt mtt;
2236 __be64 *page_list = inbox->buf;
2237 u64 *pg_list = (u64 *)page_list;
2239 struct res_mtt *rmtt = NULL;
2240 int start = be64_to_cpu(page_list[0]);
2241 int npages = vhcr->in_modifier;
2244 err = get_containing_mtt(dev, slave, start, npages, &rmtt);
2248 /* Call the SW implementation of write_mtt:
2249 * - Prepare a dummy mtt struct
2250 * - Translate inbox contents to simple addresses in host endianess */
2251 mtt.offset = 0; /* TBD this is broken but I don't handle it since
2252 we don't really use it */
2255 for (i = 0; i < npages; ++i)
2256 pg_list[i + 2] = (be64_to_cpu(page_list[i + 2]) & ~1ULL);
2258 err = __mlx4_write_mtt(dev, &mtt, be64_to_cpu(page_list[0]), npages,
2259 ((u64 *)page_list + 2));
2262 put_res(dev, slave, rmtt->com.res_id, RES_MTT);
2267 int mlx4_HW2SW_EQ_wrapper(struct mlx4_dev *dev, int slave,
2268 struct mlx4_vhcr *vhcr,
2269 struct mlx4_cmd_mailbox *inbox,
2270 struct mlx4_cmd_mailbox *outbox,
2271 struct mlx4_cmd_info *cmd)
2273 int eqn = vhcr->in_modifier;
2274 int res_id = eqn | (slave << 8);
2278 err = eq_res_start_move_to(dev, slave, res_id, RES_EQ_RESERVED, &eq);
2282 err = get_res(dev, slave, eq->mtt->com.res_id, RES_MTT, NULL);
2286 err = mlx4_DMA_wrapper(dev, slave, vhcr, inbox, outbox, cmd);
2290 atomic_dec(&eq->mtt->ref_count);
2291 put_res(dev, slave, eq->mtt->com.res_id, RES_MTT);
2292 res_end_move(dev, slave, RES_EQ, res_id);
2293 rem_res_range(dev, slave, res_id, 1, RES_EQ, 0);
2298 put_res(dev, slave, eq->mtt->com.res_id, RES_MTT);
2300 res_abort_move(dev, slave, RES_EQ, res_id);
2305 int mlx4_GEN_EQE(struct mlx4_dev *dev, int slave, struct mlx4_eqe *eqe)
2307 struct mlx4_priv *priv = mlx4_priv(dev);
2308 struct mlx4_slave_event_eq_info *event_eq;
2309 struct mlx4_cmd_mailbox *mailbox;
2310 u32 in_modifier = 0;
2315 if (!priv->mfunc.master.slave_state)
2318 event_eq = &priv->mfunc.master.slave_state[slave].event_eq[eqe->type];
2320 /* Create the event only if the slave is registered */
2321 if (event_eq->eqn < 0)
2324 mutex_lock(&priv->mfunc.master.gen_eqe_mutex[slave]);
2325 res_id = (slave << 8) | event_eq->eqn;
2326 err = get_res(dev, slave, res_id, RES_EQ, &req);
2330 if (req->com.from_state != RES_EQ_HW) {
2335 mailbox = mlx4_alloc_cmd_mailbox(dev);
2336 if (IS_ERR(mailbox)) {
2337 err = PTR_ERR(mailbox);
2341 if (eqe->type == MLX4_EVENT_TYPE_CMD) {
2343 eqe->event.cmd.token = cpu_to_be16(event_eq->token);
2346 memcpy(mailbox->buf, (u8 *) eqe, 28);
2348 in_modifier = (slave & 0xff) | ((event_eq->eqn & 0xff) << 16);
2350 err = mlx4_cmd(dev, mailbox->dma, in_modifier, 0,
2351 MLX4_CMD_GEN_EQE, MLX4_CMD_TIME_CLASS_B,
2354 put_res(dev, slave, res_id, RES_EQ);
2355 mutex_unlock(&priv->mfunc.master.gen_eqe_mutex[slave]);
2356 mlx4_free_cmd_mailbox(dev, mailbox);
2360 put_res(dev, slave, res_id, RES_EQ);
2363 mutex_unlock(&priv->mfunc.master.gen_eqe_mutex[slave]);
2367 int mlx4_QUERY_EQ_wrapper(struct mlx4_dev *dev, int slave,
2368 struct mlx4_vhcr *vhcr,
2369 struct mlx4_cmd_mailbox *inbox,
2370 struct mlx4_cmd_mailbox *outbox,
2371 struct mlx4_cmd_info *cmd)
2373 int eqn = vhcr->in_modifier;
2374 int res_id = eqn | (slave << 8);
2378 err = get_res(dev, slave, res_id, RES_EQ, &eq);
2382 if (eq->com.from_state != RES_EQ_HW) {
2387 err = mlx4_DMA_wrapper(dev, slave, vhcr, inbox, outbox, cmd);
2390 put_res(dev, slave, res_id, RES_EQ);
2394 int mlx4_SW2HW_CQ_wrapper(struct mlx4_dev *dev, int slave,
2395 struct mlx4_vhcr *vhcr,
2396 struct mlx4_cmd_mailbox *inbox,
2397 struct mlx4_cmd_mailbox *outbox,
2398 struct mlx4_cmd_info *cmd)
2401 int cqn = vhcr->in_modifier;
2402 struct mlx4_cq_context *cqc = inbox->buf;
2403 int mtt_base = cq_get_mtt_addr(cqc) / dev->caps.mtt_entry_sz;
2405 struct res_mtt *mtt;
2407 err = cq_res_start_move_to(dev, slave, cqn, RES_CQ_HW, &cq);
2410 err = get_res(dev, slave, mtt_base, RES_MTT, &mtt);
2413 err = check_mtt_range(dev, slave, mtt_base, cq_get_mtt_size(cqc), mtt);
2416 err = mlx4_DMA_wrapper(dev, slave, vhcr, inbox, outbox, cmd);
2419 atomic_inc(&mtt->ref_count);
2421 put_res(dev, slave, mtt->com.res_id, RES_MTT);
2422 res_end_move(dev, slave, RES_CQ, cqn);
2426 put_res(dev, slave, mtt->com.res_id, RES_MTT);
2428 res_abort_move(dev, slave, RES_CQ, cqn);
2432 int mlx4_HW2SW_CQ_wrapper(struct mlx4_dev *dev, int slave,
2433 struct mlx4_vhcr *vhcr,
2434 struct mlx4_cmd_mailbox *inbox,
2435 struct mlx4_cmd_mailbox *outbox,
2436 struct mlx4_cmd_info *cmd)
2439 int cqn = vhcr->in_modifier;
2442 err = cq_res_start_move_to(dev, slave, cqn, RES_CQ_ALLOCATED, &cq);
2445 err = mlx4_DMA_wrapper(dev, slave, vhcr, inbox, outbox, cmd);
2448 atomic_dec(&cq->mtt->ref_count);
2449 res_end_move(dev, slave, RES_CQ, cqn);
2453 res_abort_move(dev, slave, RES_CQ, cqn);
2457 int mlx4_QUERY_CQ_wrapper(struct mlx4_dev *dev, int slave,
2458 struct mlx4_vhcr *vhcr,
2459 struct mlx4_cmd_mailbox *inbox,
2460 struct mlx4_cmd_mailbox *outbox,
2461 struct mlx4_cmd_info *cmd)
2463 int cqn = vhcr->in_modifier;
2467 err = get_res(dev, slave, cqn, RES_CQ, &cq);
2471 if (cq->com.from_state != RES_CQ_HW)
2474 err = mlx4_DMA_wrapper(dev, slave, vhcr, inbox, outbox, cmd);
2476 put_res(dev, slave, cqn, RES_CQ);
2481 static int handle_resize(struct mlx4_dev *dev, int slave,
2482 struct mlx4_vhcr *vhcr,
2483 struct mlx4_cmd_mailbox *inbox,
2484 struct mlx4_cmd_mailbox *outbox,
2485 struct mlx4_cmd_info *cmd,
2489 struct res_mtt *orig_mtt;
2490 struct res_mtt *mtt;
2491 struct mlx4_cq_context *cqc = inbox->buf;
2492 int mtt_base = cq_get_mtt_addr(cqc) / dev->caps.mtt_entry_sz;
2494 err = get_res(dev, slave, cq->mtt->com.res_id, RES_MTT, &orig_mtt);
2498 if (orig_mtt != cq->mtt) {
2503 err = get_res(dev, slave, mtt_base, RES_MTT, &mtt);
2507 err = check_mtt_range(dev, slave, mtt_base, cq_get_mtt_size(cqc), mtt);
2510 err = mlx4_DMA_wrapper(dev, slave, vhcr, inbox, outbox, cmd);
2513 atomic_dec(&orig_mtt->ref_count);
2514 put_res(dev, slave, orig_mtt->com.res_id, RES_MTT);
2515 atomic_inc(&mtt->ref_count);
2517 put_res(dev, slave, mtt->com.res_id, RES_MTT);
2521 put_res(dev, slave, mtt->com.res_id, RES_MTT);
2523 put_res(dev, slave, orig_mtt->com.res_id, RES_MTT);
2529 int mlx4_MODIFY_CQ_wrapper(struct mlx4_dev *dev, int slave,
2530 struct mlx4_vhcr *vhcr,
2531 struct mlx4_cmd_mailbox *inbox,
2532 struct mlx4_cmd_mailbox *outbox,
2533 struct mlx4_cmd_info *cmd)
2535 int cqn = vhcr->in_modifier;
2539 err = get_res(dev, slave, cqn, RES_CQ, &cq);
2543 if (cq->com.from_state != RES_CQ_HW)
2546 if (vhcr->op_modifier == 0) {
2547 err = handle_resize(dev, slave, vhcr, inbox, outbox, cmd, cq);
2551 err = mlx4_DMA_wrapper(dev, slave, vhcr, inbox, outbox, cmd);
2553 put_res(dev, slave, cqn, RES_CQ);
2558 static int srq_get_mtt_size(struct mlx4_srq_context *srqc)
2560 int log_srq_size = (be32_to_cpu(srqc->state_logsize_srqn) >> 24) & 0xf;
2561 int log_rq_stride = srqc->logstride & 7;
2562 int page_shift = (srqc->log_page_size & 0x3f) + 12;
2564 if (log_srq_size + log_rq_stride + 4 < page_shift)
2567 return 1 << (log_srq_size + log_rq_stride + 4 - page_shift);
2570 int mlx4_SW2HW_SRQ_wrapper(struct mlx4_dev *dev, int slave,
2571 struct mlx4_vhcr *vhcr,
2572 struct mlx4_cmd_mailbox *inbox,
2573 struct mlx4_cmd_mailbox *outbox,
2574 struct mlx4_cmd_info *cmd)
2577 int srqn = vhcr->in_modifier;
2578 struct res_mtt *mtt;
2579 struct res_srq *srq;
2580 struct mlx4_srq_context *srqc = inbox->buf;
2581 int mtt_base = srq_get_mtt_addr(srqc) / dev->caps.mtt_entry_sz;
2583 if (srqn != (be32_to_cpu(srqc->state_logsize_srqn) & 0xffffff))
2586 err = srq_res_start_move_to(dev, slave, srqn, RES_SRQ_HW, &srq);
2589 err = get_res(dev, slave, mtt_base, RES_MTT, &mtt);
2592 err = check_mtt_range(dev, slave, mtt_base, srq_get_mtt_size(srqc),
2597 err = mlx4_DMA_wrapper(dev, slave, vhcr, inbox, outbox, cmd);
2601 atomic_inc(&mtt->ref_count);
2603 put_res(dev, slave, mtt->com.res_id, RES_MTT);
2604 res_end_move(dev, slave, RES_SRQ, srqn);
2608 put_res(dev, slave, mtt->com.res_id, RES_MTT);
2610 res_abort_move(dev, slave, RES_SRQ, srqn);
2615 int mlx4_HW2SW_SRQ_wrapper(struct mlx4_dev *dev, int slave,
2616 struct mlx4_vhcr *vhcr,
2617 struct mlx4_cmd_mailbox *inbox,
2618 struct mlx4_cmd_mailbox *outbox,
2619 struct mlx4_cmd_info *cmd)
2622 int srqn = vhcr->in_modifier;
2623 struct res_srq *srq;
2625 err = srq_res_start_move_to(dev, slave, srqn, RES_SRQ_ALLOCATED, &srq);
2628 err = mlx4_DMA_wrapper(dev, slave, vhcr, inbox, outbox, cmd);
2631 atomic_dec(&srq->mtt->ref_count);
2633 atomic_dec(&srq->cq->ref_count);
2634 res_end_move(dev, slave, RES_SRQ, srqn);
2639 res_abort_move(dev, slave, RES_SRQ, srqn);
2644 int mlx4_QUERY_SRQ_wrapper(struct mlx4_dev *dev, int slave,
2645 struct mlx4_vhcr *vhcr,
2646 struct mlx4_cmd_mailbox *inbox,
2647 struct mlx4_cmd_mailbox *outbox,
2648 struct mlx4_cmd_info *cmd)
2651 int srqn = vhcr->in_modifier;
2652 struct res_srq *srq;
2654 err = get_res(dev, slave, srqn, RES_SRQ, &srq);
2657 if (srq->com.from_state != RES_SRQ_HW) {
2661 err = mlx4_DMA_wrapper(dev, slave, vhcr, inbox, outbox, cmd);
2663 put_res(dev, slave, srqn, RES_SRQ);
2667 int mlx4_ARM_SRQ_wrapper(struct mlx4_dev *dev, int slave,
2668 struct mlx4_vhcr *vhcr,
2669 struct mlx4_cmd_mailbox *inbox,
2670 struct mlx4_cmd_mailbox *outbox,
2671 struct mlx4_cmd_info *cmd)
2674 int srqn = vhcr->in_modifier;
2675 struct res_srq *srq;
2677 err = get_res(dev, slave, srqn, RES_SRQ, &srq);
2681 if (srq->com.from_state != RES_SRQ_HW) {
2686 err = mlx4_DMA_wrapper(dev, slave, vhcr, inbox, outbox, cmd);
2688 put_res(dev, slave, srqn, RES_SRQ);
2692 int mlx4_GEN_QP_wrapper(struct mlx4_dev *dev, int slave,
2693 struct mlx4_vhcr *vhcr,
2694 struct mlx4_cmd_mailbox *inbox,
2695 struct mlx4_cmd_mailbox *outbox,
2696 struct mlx4_cmd_info *cmd)
2699 int qpn = vhcr->in_modifier & 0x7fffff;
2702 err = get_res(dev, slave, qpn, RES_QP, &qp);
2705 if (qp->com.from_state != RES_QP_HW) {
2710 err = mlx4_DMA_wrapper(dev, slave, vhcr, inbox, outbox, cmd);
2712 put_res(dev, slave, qpn, RES_QP);
2716 int mlx4_INIT2INIT_QP_wrapper(struct mlx4_dev *dev, int slave,
2717 struct mlx4_vhcr *vhcr,
2718 struct mlx4_cmd_mailbox *inbox,
2719 struct mlx4_cmd_mailbox *outbox,
2720 struct mlx4_cmd_info *cmd)
2722 struct mlx4_qp_context *context = inbox->buf + 8;
2723 adjust_proxy_tun_qkey(dev, vhcr, context);
2724 update_pkey_index(dev, slave, inbox);
2725 return mlx4_GEN_QP_wrapper(dev, slave, vhcr, inbox, outbox, cmd);
2728 int mlx4_INIT2RTR_QP_wrapper(struct mlx4_dev *dev, int slave,
2729 struct mlx4_vhcr *vhcr,
2730 struct mlx4_cmd_mailbox *inbox,
2731 struct mlx4_cmd_mailbox *outbox,
2732 struct mlx4_cmd_info *cmd)
2735 struct mlx4_qp_context *qpc = inbox->buf + 8;
2737 err = verify_qp_parameters(dev, inbox, QP_TRANS_INIT2RTR, slave);
2741 update_pkey_index(dev, slave, inbox);
2742 update_gid(dev, inbox, (u8)slave);
2743 adjust_proxy_tun_qkey(dev, vhcr, qpc);
2745 return mlx4_GEN_QP_wrapper(dev, slave, vhcr, inbox, outbox, cmd);
2748 int mlx4_RTR2RTS_QP_wrapper(struct mlx4_dev *dev, int slave,
2749 struct mlx4_vhcr *vhcr,
2750 struct mlx4_cmd_mailbox *inbox,
2751 struct mlx4_cmd_mailbox *outbox,
2752 struct mlx4_cmd_info *cmd)
2755 struct mlx4_qp_context *context = inbox->buf + 8;
2757 err = verify_qp_parameters(dev, inbox, QP_TRANS_RTR2RTS, slave);
2761 update_pkey_index(dev, slave, inbox);
2762 update_gid(dev, inbox, (u8)slave);
2763 adjust_proxy_tun_qkey(dev, vhcr, context);
2764 return mlx4_GEN_QP_wrapper(dev, slave, vhcr, inbox, outbox, cmd);
2767 int mlx4_RTS2RTS_QP_wrapper(struct mlx4_dev *dev, int slave,
2768 struct mlx4_vhcr *vhcr,
2769 struct mlx4_cmd_mailbox *inbox,
2770 struct mlx4_cmd_mailbox *outbox,
2771 struct mlx4_cmd_info *cmd)
2774 struct mlx4_qp_context *context = inbox->buf + 8;
2776 err = verify_qp_parameters(dev, inbox, QP_TRANS_RTS2RTS, slave);
2780 update_pkey_index(dev, slave, inbox);
2781 update_gid(dev, inbox, (u8)slave);
2782 adjust_proxy_tun_qkey(dev, vhcr, context);
2783 return mlx4_GEN_QP_wrapper(dev, slave, vhcr, inbox, outbox, cmd);
2787 int mlx4_SQERR2RTS_QP_wrapper(struct mlx4_dev *dev, int slave,
2788 struct mlx4_vhcr *vhcr,
2789 struct mlx4_cmd_mailbox *inbox,
2790 struct mlx4_cmd_mailbox *outbox,
2791 struct mlx4_cmd_info *cmd)
2793 struct mlx4_qp_context *context = inbox->buf + 8;
2794 adjust_proxy_tun_qkey(dev, vhcr, context);
2795 return mlx4_GEN_QP_wrapper(dev, slave, vhcr, inbox, outbox, cmd);
2798 int mlx4_SQD2SQD_QP_wrapper(struct mlx4_dev *dev, int slave,
2799 struct mlx4_vhcr *vhcr,
2800 struct mlx4_cmd_mailbox *inbox,
2801 struct mlx4_cmd_mailbox *outbox,
2802 struct mlx4_cmd_info *cmd)
2805 struct mlx4_qp_context *context = inbox->buf + 8;
2807 err = verify_qp_parameters(dev, inbox, QP_TRANS_SQD2SQD, slave);
2811 adjust_proxy_tun_qkey(dev, vhcr, context);
2812 update_gid(dev, inbox, (u8)slave);
2813 update_pkey_index(dev, slave, inbox);
2814 return mlx4_GEN_QP_wrapper(dev, slave, vhcr, inbox, outbox, cmd);
2817 int mlx4_SQD2RTS_QP_wrapper(struct mlx4_dev *dev, int slave,
2818 struct mlx4_vhcr *vhcr,
2819 struct mlx4_cmd_mailbox *inbox,
2820 struct mlx4_cmd_mailbox *outbox,
2821 struct mlx4_cmd_info *cmd)
2824 struct mlx4_qp_context *context = inbox->buf + 8;
2826 err = verify_qp_parameters(dev, inbox, QP_TRANS_SQD2RTS, slave);
2830 adjust_proxy_tun_qkey(dev, vhcr, context);
2831 update_gid(dev, inbox, (u8)slave);
2832 update_pkey_index(dev, slave, inbox);
2833 return mlx4_GEN_QP_wrapper(dev, slave, vhcr, inbox, outbox, cmd);
2836 int mlx4_2RST_QP_wrapper(struct mlx4_dev *dev, int slave,
2837 struct mlx4_vhcr *vhcr,
2838 struct mlx4_cmd_mailbox *inbox,
2839 struct mlx4_cmd_mailbox *outbox,
2840 struct mlx4_cmd_info *cmd)
2843 int qpn = vhcr->in_modifier & 0x7fffff;
2846 err = qp_res_start_move_to(dev, slave, qpn, RES_QP_MAPPED, &qp, 0);
2849 err = mlx4_DMA_wrapper(dev, slave, vhcr, inbox, outbox, cmd);
2853 atomic_dec(&qp->mtt->ref_count);
2854 atomic_dec(&qp->rcq->ref_count);
2855 atomic_dec(&qp->scq->ref_count);
2857 atomic_dec(&qp->srq->ref_count);
2858 res_end_move(dev, slave, RES_QP, qpn);
2862 res_abort_move(dev, slave, RES_QP, qpn);
2867 static struct res_gid *find_gid(struct mlx4_dev *dev, int slave,
2868 struct res_qp *rqp, u8 *gid)
2870 struct res_gid *res;
2872 list_for_each_entry(res, &rqp->mcg_list, list) {
2873 if (!memcmp(res->gid, gid, 16))
2879 static int add_mcg_res(struct mlx4_dev *dev, int slave, struct res_qp *rqp,
2880 u8 *gid, enum mlx4_protocol prot,
2881 enum mlx4_steer_type steer)
2883 struct res_gid *res;
2886 res = kzalloc(sizeof *res, GFP_KERNEL);
2890 spin_lock_irq(&rqp->mcg_spl);
2891 if (find_gid(dev, slave, rqp, gid)) {
2895 memcpy(res->gid, gid, 16);
2898 list_add_tail(&res->list, &rqp->mcg_list);
2901 spin_unlock_irq(&rqp->mcg_spl);
2906 static int rem_mcg_res(struct mlx4_dev *dev, int slave, struct res_qp *rqp,
2907 u8 *gid, enum mlx4_protocol prot,
2908 enum mlx4_steer_type steer)
2910 struct res_gid *res;
2913 spin_lock_irq(&rqp->mcg_spl);
2914 res = find_gid(dev, slave, rqp, gid);
2915 if (!res || res->prot != prot || res->steer != steer)
2918 list_del(&res->list);
2922 spin_unlock_irq(&rqp->mcg_spl);
2927 int mlx4_QP_ATTACH_wrapper(struct mlx4_dev *dev, int slave,
2928 struct mlx4_vhcr *vhcr,
2929 struct mlx4_cmd_mailbox *inbox,
2930 struct mlx4_cmd_mailbox *outbox,
2931 struct mlx4_cmd_info *cmd)
2933 struct mlx4_qp qp; /* dummy for calling attach/detach */
2934 u8 *gid = inbox->buf;
2935 enum mlx4_protocol prot = (vhcr->in_modifier >> 28) & 0x7;
2939 int attach = vhcr->op_modifier;
2940 int block_loopback = vhcr->in_modifier >> 31;
2941 u8 steer_type_mask = 2;
2942 enum mlx4_steer_type type = (gid[7] & steer_type_mask) >> 1;
2944 qpn = vhcr->in_modifier & 0xffffff;
2945 err = get_res(dev, slave, qpn, RES_QP, &rqp);
2951 err = add_mcg_res(dev, slave, rqp, gid, prot, type);
2955 err = mlx4_qp_attach_common(dev, &qp, gid,
2956 block_loopback, prot, type);
2960 err = rem_mcg_res(dev, slave, rqp, gid, prot, type);
2963 err = mlx4_qp_detach_common(dev, &qp, gid, prot, type);
2966 put_res(dev, slave, qpn, RES_QP);
2970 /* ignore error return below, already in error */
2971 (void) rem_mcg_res(dev, slave, rqp, gid, prot, type);
2973 put_res(dev, slave, qpn, RES_QP);
2979 * MAC validation for Flow Steering rules.
2980 * VF can attach rules only with a mac address which is assigned to it.
2982 static int validate_eth_header_mac(int slave, struct _rule_hw *eth_header,
2983 struct list_head *rlist)
2985 struct mac_res *res, *tmp;
2988 /* make sure it isn't multicast or broadcast mac*/
2989 if (!is_multicast_ether_addr(eth_header->eth.dst_mac) &&
2990 !is_broadcast_ether_addr(eth_header->eth.dst_mac)) {
2991 list_for_each_entry_safe(res, tmp, rlist, list) {
2992 be_mac = cpu_to_be64(res->mac << 16);
2993 if (!memcmp(&be_mac, eth_header->eth.dst_mac, ETH_ALEN))
2996 pr_err("MAC %pM doesn't belong to VF %d, Steering rule rejected\n",
2997 eth_header->eth.dst_mac, slave);
3004 * In case of missing eth header, append eth header with a MAC address
3005 * assigned to the VF.
3007 static int add_eth_header(struct mlx4_dev *dev, int slave,
3008 struct mlx4_cmd_mailbox *inbox,
3009 struct list_head *rlist, int header_id)
3011 struct mac_res *res, *tmp;
3013 struct mlx4_net_trans_rule_hw_ctrl *ctrl;
3014 struct mlx4_net_trans_rule_hw_eth *eth_header;
3015 struct mlx4_net_trans_rule_hw_ipv4 *ip_header;
3016 struct mlx4_net_trans_rule_hw_tcp_udp *l4_header;
3018 __be64 mac_msk = cpu_to_be64(MLX4_MAC_MASK << 16);
3020 ctrl = (struct mlx4_net_trans_rule_hw_ctrl *)inbox->buf;
3021 port = be32_to_cpu(ctrl->vf_vep_port) & 0xff;
3022 eth_header = (struct mlx4_net_trans_rule_hw_eth *)(ctrl + 1);
3024 /* Clear a space in the inbox for eth header */
3025 switch (header_id) {
3026 case MLX4_NET_TRANS_RULE_ID_IPV4:
3028 (struct mlx4_net_trans_rule_hw_ipv4 *)(eth_header + 1);
3029 memmove(ip_header, eth_header,
3030 sizeof(*ip_header) + sizeof(*l4_header));
3032 case MLX4_NET_TRANS_RULE_ID_TCP:
3033 case MLX4_NET_TRANS_RULE_ID_UDP:
3034 l4_header = (struct mlx4_net_trans_rule_hw_tcp_udp *)
3036 memmove(l4_header, eth_header, sizeof(*l4_header));
3041 list_for_each_entry_safe(res, tmp, rlist, list) {
3042 if (port == res->port) {
3043 be_mac = cpu_to_be64(res->mac << 16);
3048 pr_err("Failed adding eth header to FS rule, Can't find matching MAC for port %d .\n",
3053 memset(eth_header, 0, sizeof(*eth_header));
3054 eth_header->size = sizeof(*eth_header) >> 2;
3055 eth_header->id = cpu_to_be16(__sw_id_hw[MLX4_NET_TRANS_RULE_ID_ETH]);
3056 memcpy(eth_header->dst_mac, &be_mac, ETH_ALEN);
3057 memcpy(eth_header->dst_mac_msk, &mac_msk, ETH_ALEN);
3063 int mlx4_QP_FLOW_STEERING_ATTACH_wrapper(struct mlx4_dev *dev, int slave,
3064 struct mlx4_vhcr *vhcr,
3065 struct mlx4_cmd_mailbox *inbox,
3066 struct mlx4_cmd_mailbox *outbox,
3067 struct mlx4_cmd_info *cmd)
3070 struct mlx4_priv *priv = mlx4_priv(dev);
3071 struct mlx4_resource_tracker *tracker = &priv->mfunc.master.res_tracker;
3072 struct list_head *rlist = &tracker->slave_list[slave].res_list[RES_MAC];
3074 struct mlx4_net_trans_rule_hw_ctrl *ctrl;
3075 struct _rule_hw *rule_header;
3078 if (dev->caps.steering_mode !=
3079 MLX4_STEERING_MODE_DEVICE_MANAGED)
3082 ctrl = (struct mlx4_net_trans_rule_hw_ctrl *)inbox->buf;
3083 rule_header = (struct _rule_hw *)(ctrl + 1);
3084 header_id = map_hw_to_sw_id(be16_to_cpu(rule_header->id));
3086 switch (header_id) {
3087 case MLX4_NET_TRANS_RULE_ID_ETH:
3088 if (validate_eth_header_mac(slave, rule_header, rlist))
3091 case MLX4_NET_TRANS_RULE_ID_IB:
3093 case MLX4_NET_TRANS_RULE_ID_IPV4:
3094 case MLX4_NET_TRANS_RULE_ID_TCP:
3095 case MLX4_NET_TRANS_RULE_ID_UDP:
3096 pr_warn("Can't attach FS rule without L2 headers, adding L2 header.\n");
3097 if (add_eth_header(dev, slave, inbox, rlist, header_id))
3099 vhcr->in_modifier +=
3100 sizeof(struct mlx4_net_trans_rule_hw_eth) >> 2;
3103 pr_err("Corrupted mailbox.\n");
3107 err = mlx4_cmd_imm(dev, inbox->dma, &vhcr->out_param,
3108 vhcr->in_modifier, 0,
3109 MLX4_QP_FLOW_STEERING_ATTACH, MLX4_CMD_TIME_CLASS_A,
3114 err = add_res_range(dev, slave, vhcr->out_param, 1, RES_FS_RULE, 0);
3116 mlx4_err(dev, "Fail to add flow steering resources.\n ");
3118 mlx4_cmd(dev, vhcr->out_param, 0, 0,
3119 MLX4_QP_FLOW_STEERING_ATTACH, MLX4_CMD_TIME_CLASS_A,
3125 int mlx4_QP_FLOW_STEERING_DETACH_wrapper(struct mlx4_dev *dev, int slave,
3126 struct mlx4_vhcr *vhcr,
3127 struct mlx4_cmd_mailbox *inbox,
3128 struct mlx4_cmd_mailbox *outbox,
3129 struct mlx4_cmd_info *cmd)
3133 if (dev->caps.steering_mode !=
3134 MLX4_STEERING_MODE_DEVICE_MANAGED)
3137 err = rem_res_range(dev, slave, vhcr->in_param, 1, RES_FS_RULE, 0);
3139 mlx4_err(dev, "Fail to remove flow steering resources.\n ");
3143 err = mlx4_cmd(dev, vhcr->in_param, 0, 0,
3144 MLX4_QP_FLOW_STEERING_DETACH, MLX4_CMD_TIME_CLASS_A,
3150 BUSY_MAX_RETRIES = 10
3153 int mlx4_QUERY_IF_STAT_wrapper(struct mlx4_dev *dev, int slave,
3154 struct mlx4_vhcr *vhcr,
3155 struct mlx4_cmd_mailbox *inbox,
3156 struct mlx4_cmd_mailbox *outbox,
3157 struct mlx4_cmd_info *cmd)
3160 int index = vhcr->in_modifier & 0xffff;
3162 err = get_res(dev, slave, index, RES_COUNTER, NULL);
3166 err = mlx4_DMA_wrapper(dev, slave, vhcr, inbox, outbox, cmd);
3167 put_res(dev, slave, index, RES_COUNTER);
3171 static void detach_qp(struct mlx4_dev *dev, int slave, struct res_qp *rqp)
3173 struct res_gid *rgid;
3174 struct res_gid *tmp;
3175 struct mlx4_qp qp; /* dummy for calling attach/detach */
3177 list_for_each_entry_safe(rgid, tmp, &rqp->mcg_list, list) {
3178 qp.qpn = rqp->local_qpn;
3179 (void) mlx4_qp_detach_common(dev, &qp, rgid->gid, rgid->prot,
3181 list_del(&rgid->list);
3186 static int _move_all_busy(struct mlx4_dev *dev, int slave,
3187 enum mlx4_resource type, int print)
3189 struct mlx4_priv *priv = mlx4_priv(dev);
3190 struct mlx4_resource_tracker *tracker =
3191 &priv->mfunc.master.res_tracker;
3192 struct list_head *rlist = &tracker->slave_list[slave].res_list[type];
3193 struct res_common *r;
3194 struct res_common *tmp;
3198 spin_lock_irq(mlx4_tlock(dev));
3199 list_for_each_entry_safe(r, tmp, rlist, list) {
3200 if (r->owner == slave) {
3202 if (r->state == RES_ANY_BUSY) {
3205 "%s id 0x%llx is busy\n",
3210 r->from_state = r->state;
3211 r->state = RES_ANY_BUSY;
3217 spin_unlock_irq(mlx4_tlock(dev));
3222 static int move_all_busy(struct mlx4_dev *dev, int slave,
3223 enum mlx4_resource type)
3225 unsigned long begin;
3230 busy = _move_all_busy(dev, slave, type, 0);
3231 if (time_after(jiffies, begin + 5 * HZ))
3238 busy = _move_all_busy(dev, slave, type, 1);
3242 static void rem_slave_qps(struct mlx4_dev *dev, int slave)
3244 struct mlx4_priv *priv = mlx4_priv(dev);
3245 struct mlx4_resource_tracker *tracker = &priv->mfunc.master.res_tracker;
3246 struct list_head *qp_list =
3247 &tracker->slave_list[slave].res_list[RES_QP];
3255 err = move_all_busy(dev, slave, RES_QP);
3257 mlx4_warn(dev, "rem_slave_qps: Could not move all qps to busy"
3258 "for slave %d\n", slave);
3260 spin_lock_irq(mlx4_tlock(dev));
3261 list_for_each_entry_safe(qp, tmp, qp_list, com.list) {
3262 spin_unlock_irq(mlx4_tlock(dev));
3263 if (qp->com.owner == slave) {
3264 qpn = qp->com.res_id;
3265 detach_qp(dev, slave, qp);
3266 state = qp->com.from_state;
3267 while (state != 0) {
3269 case RES_QP_RESERVED:
3270 spin_lock_irq(mlx4_tlock(dev));
3271 rb_erase(&qp->com.node,
3272 &tracker->res_tree[RES_QP]);
3273 list_del(&qp->com.list);
3274 spin_unlock_irq(mlx4_tlock(dev));
3279 if (!valid_reserved(dev, slave, qpn))
3280 __mlx4_qp_free_icm(dev, qpn);
3281 state = RES_QP_RESERVED;
3285 err = mlx4_cmd(dev, in_param,
3288 MLX4_CMD_TIME_CLASS_A,
3291 mlx4_dbg(dev, "rem_slave_qps: failed"
3292 " to move slave %d qpn %d to"
3295 atomic_dec(&qp->rcq->ref_count);
3296 atomic_dec(&qp->scq->ref_count);
3297 atomic_dec(&qp->mtt->ref_count);
3299 atomic_dec(&qp->srq->ref_count);
3300 state = RES_QP_MAPPED;
3307 spin_lock_irq(mlx4_tlock(dev));
3309 spin_unlock_irq(mlx4_tlock(dev));
3312 static void rem_slave_srqs(struct mlx4_dev *dev, int slave)
3314 struct mlx4_priv *priv = mlx4_priv(dev);
3315 struct mlx4_resource_tracker *tracker = &priv->mfunc.master.res_tracker;
3316 struct list_head *srq_list =
3317 &tracker->slave_list[slave].res_list[RES_SRQ];
3318 struct res_srq *srq;
3319 struct res_srq *tmp;
3326 err = move_all_busy(dev, slave, RES_SRQ);
3328 mlx4_warn(dev, "rem_slave_srqs: Could not move all srqs to "
3329 "busy for slave %d\n", slave);
3331 spin_lock_irq(mlx4_tlock(dev));
3332 list_for_each_entry_safe(srq, tmp, srq_list, com.list) {
3333 spin_unlock_irq(mlx4_tlock(dev));
3334 if (srq->com.owner == slave) {
3335 srqn = srq->com.res_id;
3336 state = srq->com.from_state;
3337 while (state != 0) {
3339 case RES_SRQ_ALLOCATED:
3340 __mlx4_srq_free_icm(dev, srqn);
3341 spin_lock_irq(mlx4_tlock(dev));
3342 rb_erase(&srq->com.node,
3343 &tracker->res_tree[RES_SRQ]);
3344 list_del(&srq->com.list);
3345 spin_unlock_irq(mlx4_tlock(dev));
3352 err = mlx4_cmd(dev, in_param, srqn, 1,
3354 MLX4_CMD_TIME_CLASS_A,
3357 mlx4_dbg(dev, "rem_slave_srqs: failed"
3358 " to move slave %d srq %d to"
3362 atomic_dec(&srq->mtt->ref_count);
3364 atomic_dec(&srq->cq->ref_count);
3365 state = RES_SRQ_ALLOCATED;
3373 spin_lock_irq(mlx4_tlock(dev));
3375 spin_unlock_irq(mlx4_tlock(dev));
3378 static void rem_slave_cqs(struct mlx4_dev *dev, int slave)
3380 struct mlx4_priv *priv = mlx4_priv(dev);
3381 struct mlx4_resource_tracker *tracker = &priv->mfunc.master.res_tracker;
3382 struct list_head *cq_list =
3383 &tracker->slave_list[slave].res_list[RES_CQ];
3392 err = move_all_busy(dev, slave, RES_CQ);
3394 mlx4_warn(dev, "rem_slave_cqs: Could not move all cqs to "
3395 "busy for slave %d\n", slave);
3397 spin_lock_irq(mlx4_tlock(dev));
3398 list_for_each_entry_safe(cq, tmp, cq_list, com.list) {
3399 spin_unlock_irq(mlx4_tlock(dev));
3400 if (cq->com.owner == slave && !atomic_read(&cq->ref_count)) {
3401 cqn = cq->com.res_id;
3402 state = cq->com.from_state;
3403 while (state != 0) {
3405 case RES_CQ_ALLOCATED:
3406 __mlx4_cq_free_icm(dev, cqn);
3407 spin_lock_irq(mlx4_tlock(dev));
3408 rb_erase(&cq->com.node,
3409 &tracker->res_tree[RES_CQ]);
3410 list_del(&cq->com.list);
3411 spin_unlock_irq(mlx4_tlock(dev));
3418 err = mlx4_cmd(dev, in_param, cqn, 1,
3420 MLX4_CMD_TIME_CLASS_A,
3423 mlx4_dbg(dev, "rem_slave_cqs: failed"
3424 " to move slave %d cq %d to"
3427 atomic_dec(&cq->mtt->ref_count);
3428 state = RES_CQ_ALLOCATED;
3436 spin_lock_irq(mlx4_tlock(dev));
3438 spin_unlock_irq(mlx4_tlock(dev));
3441 static void rem_slave_mrs(struct mlx4_dev *dev, int slave)
3443 struct mlx4_priv *priv = mlx4_priv(dev);
3444 struct mlx4_resource_tracker *tracker = &priv->mfunc.master.res_tracker;
3445 struct list_head *mpt_list =
3446 &tracker->slave_list[slave].res_list[RES_MPT];
3447 struct res_mpt *mpt;
3448 struct res_mpt *tmp;
3455 err = move_all_busy(dev, slave, RES_MPT);
3457 mlx4_warn(dev, "rem_slave_mrs: Could not move all mpts to "
3458 "busy for slave %d\n", slave);
3460 spin_lock_irq(mlx4_tlock(dev));
3461 list_for_each_entry_safe(mpt, tmp, mpt_list, com.list) {
3462 spin_unlock_irq(mlx4_tlock(dev));
3463 if (mpt->com.owner == slave) {
3464 mptn = mpt->com.res_id;
3465 state = mpt->com.from_state;
3466 while (state != 0) {
3468 case RES_MPT_RESERVED:
3469 __mlx4_mr_release(dev, mpt->key);
3470 spin_lock_irq(mlx4_tlock(dev));
3471 rb_erase(&mpt->com.node,
3472 &tracker->res_tree[RES_MPT]);
3473 list_del(&mpt->com.list);
3474 spin_unlock_irq(mlx4_tlock(dev));
3479 case RES_MPT_MAPPED:
3480 __mlx4_mr_free_icm(dev, mpt->key);
3481 state = RES_MPT_RESERVED;
3486 err = mlx4_cmd(dev, in_param, mptn, 0,
3488 MLX4_CMD_TIME_CLASS_A,
3491 mlx4_dbg(dev, "rem_slave_mrs: failed"
3492 " to move slave %d mpt %d to"
3496 atomic_dec(&mpt->mtt->ref_count);
3497 state = RES_MPT_MAPPED;
3504 spin_lock_irq(mlx4_tlock(dev));
3506 spin_unlock_irq(mlx4_tlock(dev));
3509 static void rem_slave_mtts(struct mlx4_dev *dev, int slave)
3511 struct mlx4_priv *priv = mlx4_priv(dev);
3512 struct mlx4_resource_tracker *tracker =
3513 &priv->mfunc.master.res_tracker;
3514 struct list_head *mtt_list =
3515 &tracker->slave_list[slave].res_list[RES_MTT];
3516 struct res_mtt *mtt;
3517 struct res_mtt *tmp;
3523 err = move_all_busy(dev, slave, RES_MTT);
3525 mlx4_warn(dev, "rem_slave_mtts: Could not move all mtts to "
3526 "busy for slave %d\n", slave);
3528 spin_lock_irq(mlx4_tlock(dev));
3529 list_for_each_entry_safe(mtt, tmp, mtt_list, com.list) {
3530 spin_unlock_irq(mlx4_tlock(dev));
3531 if (mtt->com.owner == slave) {
3532 base = mtt->com.res_id;
3533 state = mtt->com.from_state;
3534 while (state != 0) {
3536 case RES_MTT_ALLOCATED:
3537 __mlx4_free_mtt_range(dev, base,
3539 spin_lock_irq(mlx4_tlock(dev));
3540 rb_erase(&mtt->com.node,
3541 &tracker->res_tree[RES_MTT]);
3542 list_del(&mtt->com.list);
3543 spin_unlock_irq(mlx4_tlock(dev));
3553 spin_lock_irq(mlx4_tlock(dev));
3555 spin_unlock_irq(mlx4_tlock(dev));
3558 static void rem_slave_fs_rule(struct mlx4_dev *dev, int slave)
3560 struct mlx4_priv *priv = mlx4_priv(dev);
3561 struct mlx4_resource_tracker *tracker =
3562 &priv->mfunc.master.res_tracker;
3563 struct list_head *fs_rule_list =
3564 &tracker->slave_list[slave].res_list[RES_FS_RULE];
3565 struct res_fs_rule *fs_rule;
3566 struct res_fs_rule *tmp;
3571 err = move_all_busy(dev, slave, RES_FS_RULE);
3573 mlx4_warn(dev, "rem_slave_fs_rule: Could not move all mtts to busy for slave %d\n",
3576 spin_lock_irq(mlx4_tlock(dev));
3577 list_for_each_entry_safe(fs_rule, tmp, fs_rule_list, com.list) {
3578 spin_unlock_irq(mlx4_tlock(dev));
3579 if (fs_rule->com.owner == slave) {
3580 base = fs_rule->com.res_id;
3581 state = fs_rule->com.from_state;
3582 while (state != 0) {
3584 case RES_FS_RULE_ALLOCATED:
3586 err = mlx4_cmd(dev, base, 0, 0,
3587 MLX4_QP_FLOW_STEERING_DETACH,
3588 MLX4_CMD_TIME_CLASS_A,
3591 spin_lock_irq(mlx4_tlock(dev));
3592 rb_erase(&fs_rule->com.node,
3593 &tracker->res_tree[RES_FS_RULE]);
3594 list_del(&fs_rule->com.list);
3595 spin_unlock_irq(mlx4_tlock(dev));
3605 spin_lock_irq(mlx4_tlock(dev));
3607 spin_unlock_irq(mlx4_tlock(dev));
3610 static void rem_slave_eqs(struct mlx4_dev *dev, int slave)
3612 struct mlx4_priv *priv = mlx4_priv(dev);
3613 struct mlx4_resource_tracker *tracker = &priv->mfunc.master.res_tracker;
3614 struct list_head *eq_list =
3615 &tracker->slave_list[slave].res_list[RES_EQ];
3622 struct mlx4_cmd_mailbox *mailbox;
3624 err = move_all_busy(dev, slave, RES_EQ);
3626 mlx4_warn(dev, "rem_slave_eqs: Could not move all eqs to "
3627 "busy for slave %d\n", slave);
3629 spin_lock_irq(mlx4_tlock(dev));
3630 list_for_each_entry_safe(eq, tmp, eq_list, com.list) {
3631 spin_unlock_irq(mlx4_tlock(dev));
3632 if (eq->com.owner == slave) {
3633 eqn = eq->com.res_id;
3634 state = eq->com.from_state;
3635 while (state != 0) {
3637 case RES_EQ_RESERVED:
3638 spin_lock_irq(mlx4_tlock(dev));
3639 rb_erase(&eq->com.node,
3640 &tracker->res_tree[RES_EQ]);
3641 list_del(&eq->com.list);
3642 spin_unlock_irq(mlx4_tlock(dev));
3648 mailbox = mlx4_alloc_cmd_mailbox(dev);
3649 if (IS_ERR(mailbox)) {
3653 err = mlx4_cmd_box(dev, slave, 0,
3656 MLX4_CMD_TIME_CLASS_A,
3659 mlx4_dbg(dev, "rem_slave_eqs: failed"
3660 " to move slave %d eqs %d to"
3661 " SW ownership\n", slave, eqn);
3662 mlx4_free_cmd_mailbox(dev, mailbox);
3663 atomic_dec(&eq->mtt->ref_count);
3664 state = RES_EQ_RESERVED;
3672 spin_lock_irq(mlx4_tlock(dev));
3674 spin_unlock_irq(mlx4_tlock(dev));
3677 static void rem_slave_counters(struct mlx4_dev *dev, int slave)
3679 struct mlx4_priv *priv = mlx4_priv(dev);
3680 struct mlx4_resource_tracker *tracker = &priv->mfunc.master.res_tracker;
3681 struct list_head *counter_list =
3682 &tracker->slave_list[slave].res_list[RES_COUNTER];
3683 struct res_counter *counter;
3684 struct res_counter *tmp;
3688 err = move_all_busy(dev, slave, RES_COUNTER);
3690 mlx4_warn(dev, "rem_slave_counters: Could not move all counters to "
3691 "busy for slave %d\n", slave);
3693 spin_lock_irq(mlx4_tlock(dev));
3694 list_for_each_entry_safe(counter, tmp, counter_list, com.list) {
3695 if (counter->com.owner == slave) {
3696 index = counter->com.res_id;
3697 rb_erase(&counter->com.node,
3698 &tracker->res_tree[RES_COUNTER]);
3699 list_del(&counter->com.list);
3701 __mlx4_counter_free(dev, index);
3704 spin_unlock_irq(mlx4_tlock(dev));
3707 static void rem_slave_xrcdns(struct mlx4_dev *dev, int slave)
3709 struct mlx4_priv *priv = mlx4_priv(dev);
3710 struct mlx4_resource_tracker *tracker = &priv->mfunc.master.res_tracker;
3711 struct list_head *xrcdn_list =
3712 &tracker->slave_list[slave].res_list[RES_XRCD];
3713 struct res_xrcdn *xrcd;
3714 struct res_xrcdn *tmp;
3718 err = move_all_busy(dev, slave, RES_XRCD);
3720 mlx4_warn(dev, "rem_slave_xrcdns: Could not move all xrcdns to "
3721 "busy for slave %d\n", slave);
3723 spin_lock_irq(mlx4_tlock(dev));
3724 list_for_each_entry_safe(xrcd, tmp, xrcdn_list, com.list) {
3725 if (xrcd->com.owner == slave) {
3726 xrcdn = xrcd->com.res_id;
3727 rb_erase(&xrcd->com.node, &tracker->res_tree[RES_XRCD]);
3728 list_del(&xrcd->com.list);
3730 __mlx4_xrcd_free(dev, xrcdn);
3733 spin_unlock_irq(mlx4_tlock(dev));
3736 void mlx4_delete_all_resources_for_slave(struct mlx4_dev *dev, int slave)
3738 struct mlx4_priv *priv = mlx4_priv(dev);
3740 mutex_lock(&priv->mfunc.master.res_tracker.slave_list[slave].mutex);
3742 rem_slave_macs(dev, slave);
3743 rem_slave_qps(dev, slave);
3744 rem_slave_srqs(dev, slave);
3745 rem_slave_cqs(dev, slave);
3746 rem_slave_mrs(dev, slave);
3747 rem_slave_eqs(dev, slave);
3748 rem_slave_mtts(dev, slave);
3749 rem_slave_counters(dev, slave);
3750 rem_slave_xrcdns(dev, slave);
3751 rem_slave_fs_rule(dev, slave);
3752 mutex_unlock(&priv->mfunc.master.res_tracker.slave_list[slave].mutex);