2 * Copyright (c) 2006, 2007 Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2007, 2008 Mellanox Technologies. All rights reserved.
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 #include <linux/string.h>
35 #include <linux/etherdevice.h>
37 #include <linux/mlx4/cmd.h>
38 #include <linux/export.h>
42 #define MGM_QPN_MASK 0x00FFFFFF
43 #define MGM_BLCK_LB_BIT 30
45 static const u8 zero_gid[16]; /* automatically initialized to 0 */
47 static int mlx4_READ_ENTRY(struct mlx4_dev *dev, int index,
48 struct mlx4_cmd_mailbox *mailbox)
50 return mlx4_cmd_box(dev, 0, mailbox->dma, index, 0, MLX4_CMD_READ_MCG,
51 MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
54 static int mlx4_WRITE_ENTRY(struct mlx4_dev *dev, int index,
55 struct mlx4_cmd_mailbox *mailbox)
57 return mlx4_cmd(dev, mailbox->dma, index, 0, MLX4_CMD_WRITE_MCG,
58 MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
61 static int mlx4_WRITE_PROMISC(struct mlx4_dev *dev, u8 vep_num, u8 port, u8 steer,
62 struct mlx4_cmd_mailbox *mailbox)
66 in_mod = (u32) vep_num << 24 | (u32) port << 16 | steer << 1;
67 return mlx4_cmd(dev, mailbox->dma, in_mod, 0x1,
68 MLX4_CMD_WRITE_MCG, MLX4_CMD_TIME_CLASS_A,
72 static int mlx4_GID_HASH(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbox,
78 err = mlx4_cmd_imm(dev, mailbox->dma, &imm, 0, op_mod,
79 MLX4_CMD_MGID_HASH, MLX4_CMD_TIME_CLASS_A,
88 static struct mlx4_promisc_qp *get_promisc_qp(struct mlx4_dev *dev, u8 pf_num,
89 enum mlx4_steer_type steer,
92 struct mlx4_steer *s_steer = &mlx4_priv(dev)->steer[pf_num];
93 struct mlx4_promisc_qp *pqp;
95 list_for_each_entry(pqp, &s_steer->promisc_qps[steer], list) {
104 * Add new entry to steering data structure.
105 * All promisc QPs should be added as well
107 static int new_steering_entry(struct mlx4_dev *dev, u8 vep_num, u8 port,
108 enum mlx4_steer_type steer,
109 unsigned int index, u32 qpn)
111 struct mlx4_steer *s_steer;
112 struct mlx4_cmd_mailbox *mailbox;
113 struct mlx4_mgm *mgm;
115 struct mlx4_steer_index *new_entry;
116 struct mlx4_promisc_qp *pqp;
117 struct mlx4_promisc_qp *dqp = NULL;
122 pf_num = (dev->caps.num_ports == 1) ? vep_num : (vep_num << 1) | (port - 1);
123 s_steer = &mlx4_priv(dev)->steer[pf_num];
124 new_entry = kzalloc(sizeof *new_entry, GFP_KERNEL);
128 INIT_LIST_HEAD(&new_entry->duplicates);
129 new_entry->index = index;
130 list_add_tail(&new_entry->list, &s_steer->steer_entries[steer]);
132 /* If the given qpn is also a promisc qp,
133 * it should be inserted to duplicates list
135 pqp = get_promisc_qp(dev, pf_num, steer, qpn);
137 dqp = kmalloc(sizeof *dqp, GFP_KERNEL);
143 list_add_tail(&dqp->list, &new_entry->duplicates);
146 /* if no promisc qps for this vep, we are done */
147 if (list_empty(&s_steer->promisc_qps[steer]))
150 /* now need to add all the promisc qps to the new
151 * steering entry, as they should also receive the packets
152 * destined to this address */
153 mailbox = mlx4_alloc_cmd_mailbox(dev);
154 if (IS_ERR(mailbox)) {
160 err = mlx4_READ_ENTRY(dev, index, mailbox);
164 members_count = be32_to_cpu(mgm->members_count) & 0xffffff;
165 prot = be32_to_cpu(mgm->members_count) >> 30;
166 list_for_each_entry(pqp, &s_steer->promisc_qps[steer], list) {
167 /* don't add already existing qpn */
170 if (members_count == MLX4_QP_PER_MGM) {
177 mgm->qp[members_count++] = cpu_to_be32(pqp->qpn & MGM_QPN_MASK);
179 /* update the qps count and update the entry with all the promisc qps*/
180 mgm->members_count = cpu_to_be32(members_count | (prot << 30));
181 err = mlx4_WRITE_ENTRY(dev, index, mailbox);
184 mlx4_free_cmd_mailbox(dev, mailbox);
189 list_del(&dqp->list);
192 list_del(&new_entry->list);
197 /* update the data structures with existing steering entry */
198 static int existing_steering_entry(struct mlx4_dev *dev, u8 vep_num, u8 port,
199 enum mlx4_steer_type steer,
200 unsigned int index, u32 qpn)
202 struct mlx4_steer *s_steer;
203 struct mlx4_steer_index *tmp_entry, *entry = NULL;
204 struct mlx4_promisc_qp *pqp;
205 struct mlx4_promisc_qp *dqp;
208 pf_num = (dev->caps.num_ports == 1) ? vep_num : (vep_num << 1) | (port - 1);
209 s_steer = &mlx4_priv(dev)->steer[pf_num];
211 pqp = get_promisc_qp(dev, pf_num, steer, qpn);
213 return 0; /* nothing to do */
215 list_for_each_entry(tmp_entry, &s_steer->steer_entries[steer], list) {
216 if (tmp_entry->index == index) {
221 if (unlikely(!entry)) {
222 mlx4_warn(dev, "Steering entry at index %x is not registered\n", index);
226 /* the given qpn is listed as a promisc qpn
227 * we need to add it as a duplicate to this entry
228 * for future references */
229 list_for_each_entry(dqp, &entry->duplicates, list) {
231 return 0; /* qp is already duplicated */
234 /* add the qp as a duplicate on this index */
235 dqp = kmalloc(sizeof *dqp, GFP_KERNEL);
239 list_add_tail(&dqp->list, &entry->duplicates);
244 /* Check whether a qpn is a duplicate on steering entry
245 * If so, it should not be removed from mgm */
246 static bool check_duplicate_entry(struct mlx4_dev *dev, u8 vep_num, u8 port,
247 enum mlx4_steer_type steer,
248 unsigned int index, u32 qpn)
250 struct mlx4_steer *s_steer;
251 struct mlx4_steer_index *tmp_entry, *entry = NULL;
252 struct mlx4_promisc_qp *dqp, *tmp_dqp;
255 pf_num = (dev->caps.num_ports == 1) ? vep_num : (vep_num << 1) | (port - 1);
256 s_steer = &mlx4_priv(dev)->steer[pf_num];
258 /* if qp is not promisc, it cannot be duplicated */
259 if (!get_promisc_qp(dev, pf_num, steer, qpn))
262 /* The qp is promisc qp so it is a duplicate on this index
263 * Find the index entry, and remove the duplicate */
264 list_for_each_entry(tmp_entry, &s_steer->steer_entries[steer], list) {
265 if (tmp_entry->index == index) {
270 if (unlikely(!entry)) {
271 mlx4_warn(dev, "Steering entry for index %x is not registered\n", index);
274 list_for_each_entry_safe(dqp, tmp_dqp, &entry->duplicates, list) {
275 if (dqp->qpn == qpn) {
276 list_del(&dqp->list);
283 /* I a steering entry contains only promisc QPs, it can be removed. */
284 static bool can_remove_steering_entry(struct mlx4_dev *dev, u8 vep_num, u8 port,
285 enum mlx4_steer_type steer,
286 unsigned int index, u32 tqpn)
288 struct mlx4_steer *s_steer;
289 struct mlx4_cmd_mailbox *mailbox;
290 struct mlx4_mgm *mgm;
291 struct mlx4_steer_index *entry = NULL, *tmp_entry;
298 pf_num = (dev->caps.num_ports == 1) ? vep_num : (vep_num << 1) | (port - 1);
299 s_steer = &mlx4_priv(dev)->steer[pf_num];
301 mailbox = mlx4_alloc_cmd_mailbox(dev);
306 if (mlx4_READ_ENTRY(dev, index, mailbox))
308 members_count = be32_to_cpu(mgm->members_count) & 0xffffff;
309 for (i = 0; i < members_count; i++) {
310 qpn = be32_to_cpu(mgm->qp[i]) & MGM_QPN_MASK;
311 if (!get_promisc_qp(dev, pf_num, steer, qpn) && qpn != tqpn) {
312 /* the qp is not promisc, the entry can't be removed */
316 /* All the qps currently registered for this entry are promiscuous,
317 * Checking for duplicates */
319 list_for_each_entry_safe(entry, tmp_entry, &s_steer->steer_entries[steer], list) {
320 if (entry->index == index) {
321 if (list_empty(&entry->duplicates)) {
322 list_del(&entry->list);
325 /* This entry contains duplicates so it shouldn't be removed */
333 mlx4_free_cmd_mailbox(dev, mailbox);
337 static int add_promisc_qp(struct mlx4_dev *dev, u8 vep_num, u8 port,
338 enum mlx4_steer_type steer, u32 qpn)
340 struct mlx4_steer *s_steer;
341 struct mlx4_cmd_mailbox *mailbox;
342 struct mlx4_mgm *mgm;
343 struct mlx4_steer_index *entry;
344 struct mlx4_promisc_qp *pqp;
345 struct mlx4_promisc_qp *dqp;
353 struct mlx4_priv *priv = mlx4_priv(dev);
354 pf_num = (dev->caps.num_ports == 1) ? vep_num : (vep_num << 1) | (port - 1);
355 s_steer = &mlx4_priv(dev)->steer[pf_num];
357 mutex_lock(&priv->mcg_table.mutex);
359 if (get_promisc_qp(dev, pf_num, steer, qpn)) {
360 err = 0; /* Noting to do, already exists */
364 pqp = kmalloc(sizeof *pqp, GFP_KERNEL);
371 mailbox = mlx4_alloc_cmd_mailbox(dev);
372 if (IS_ERR(mailbox)) {
378 /* the promisc qp needs to be added for each one of the steering
379 * entries, if it already exists, needs to be added as a duplicate
381 list_for_each_entry(entry, &s_steer->steer_entries[steer], list) {
382 err = mlx4_READ_ENTRY(dev, entry->index, mailbox);
386 members_count = be32_to_cpu(mgm->members_count) & 0xffffff;
387 prot = be32_to_cpu(mgm->members_count) >> 30;
389 for (i = 0; i < members_count; i++) {
390 if ((be32_to_cpu(mgm->qp[i]) & MGM_QPN_MASK) == qpn) {
391 /* Entry already exists, add to duplicates */
392 dqp = kmalloc(sizeof *dqp, GFP_KERNEL);
396 list_add_tail(&dqp->list, &entry->duplicates);
401 /* Need to add the qpn to mgm */
402 if (members_count == MLX4_QP_PER_MGM) {
407 mgm->qp[members_count++] = cpu_to_be32(qpn & MGM_QPN_MASK);
408 mgm->members_count = cpu_to_be32(members_count | (prot << 30));
409 err = mlx4_WRITE_ENTRY(dev, entry->index, mailbox);
413 last_index = entry->index;
416 /* add the new qpn to list of promisc qps */
417 list_add_tail(&pqp->list, &s_steer->promisc_qps[steer]);
418 /* now need to add all the promisc qps to default entry */
419 memset(mgm, 0, sizeof *mgm);
421 list_for_each_entry(dqp, &s_steer->promisc_qps[steer], list)
422 mgm->qp[members_count++] = cpu_to_be32(dqp->qpn & MGM_QPN_MASK);
423 mgm->members_count = cpu_to_be32(members_count | MLX4_PROT_ETH << 30);
425 err = mlx4_WRITE_PROMISC(dev, vep_num, port, steer, mailbox);
429 mlx4_free_cmd_mailbox(dev, mailbox);
430 mutex_unlock(&priv->mcg_table.mutex);
434 list_del(&pqp->list);
436 mlx4_free_cmd_mailbox(dev, mailbox);
440 mutex_unlock(&priv->mcg_table.mutex);
444 static int remove_promisc_qp(struct mlx4_dev *dev, u8 vep_num, u8 port,
445 enum mlx4_steer_type steer, u32 qpn)
447 struct mlx4_priv *priv = mlx4_priv(dev);
448 struct mlx4_steer *s_steer;
449 struct mlx4_cmd_mailbox *mailbox;
450 struct mlx4_mgm *mgm;
451 struct mlx4_steer_index *entry;
452 struct mlx4_promisc_qp *pqp;
453 struct mlx4_promisc_qp *dqp;
456 bool back_to_list = false;
461 pf_num = (dev->caps.num_ports == 1) ? vep_num : (vep_num << 1) | (port - 1);
462 s_steer = &mlx4_priv(dev)->steer[pf_num];
463 mutex_lock(&priv->mcg_table.mutex);
465 pqp = get_promisc_qp(dev, pf_num, steer, qpn);
466 if (unlikely(!pqp)) {
467 mlx4_warn(dev, "QP %x is not promiscuous QP\n", qpn);
473 /*remove from list of promisc qps */
474 list_del(&pqp->list);
476 /* set the default entry not to include the removed one */
477 mailbox = mlx4_alloc_cmd_mailbox(dev);
478 if (IS_ERR(mailbox)) {
485 list_for_each_entry(dqp, &s_steer->promisc_qps[steer], list)
486 mgm->qp[members_count++] = cpu_to_be32(dqp->qpn & MGM_QPN_MASK);
487 mgm->members_count = cpu_to_be32(members_count | MLX4_PROT_ETH << 30);
489 err = mlx4_WRITE_PROMISC(dev, vep_num, port, steer, mailbox);
493 /* remove the qp from all the steering entries*/
494 list_for_each_entry(entry, &s_steer->steer_entries[steer], list) {
496 list_for_each_entry(dqp, &entry->duplicates, list) {
497 if (dqp->qpn == qpn) {
503 /* a duplicate, no need to change the mgm,
504 * only update the duplicates list */
505 list_del(&dqp->list);
508 err = mlx4_READ_ENTRY(dev, entry->index, mailbox);
511 members_count = be32_to_cpu(mgm->members_count) & 0xffffff;
512 for (loc = -1, i = 0; i < members_count; ++i)
513 if ((be32_to_cpu(mgm->qp[i]) & MGM_QPN_MASK) == qpn)
516 mgm->members_count = cpu_to_be32(--members_count |
517 (MLX4_PROT_ETH << 30));
518 mgm->qp[loc] = mgm->qp[i - 1];
521 err = mlx4_WRITE_ENTRY(dev, entry->index, mailbox);
529 mlx4_free_cmd_mailbox(dev, mailbox);
532 list_add_tail(&pqp->list, &s_steer->promisc_qps[steer]);
536 mutex_unlock(&priv->mcg_table.mutex);
541 * Caller must hold MCG table semaphore. gid and mgm parameters must
542 * be properly aligned for command interface.
544 * Returns 0 unless a firmware command error occurs.
546 * If GID is found in MGM or MGM is empty, *index = *hash, *prev = -1
547 * and *mgm holds MGM entry.
549 * if GID is found in AMGM, *index = index in AMGM, *prev = index of
550 * previous entry in hash chain and *mgm holds AMGM entry.
552 * If no AMGM exists for given gid, *index = -1, *prev = index of last
553 * entry in hash chain and *mgm holds end of hash chain.
555 static int find_entry(struct mlx4_dev *dev, u8 port,
556 u8 *gid, enum mlx4_protocol prot,
557 enum mlx4_steer_type steer,
558 struct mlx4_cmd_mailbox *mgm_mailbox,
559 u16 *hash, int *prev, int *index)
561 struct mlx4_cmd_mailbox *mailbox;
562 struct mlx4_mgm *mgm = mgm_mailbox->buf;
565 u8 op_mod = (prot == MLX4_PROT_ETH) ?
566 !!(dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_MC_STEER) : 0;
568 mailbox = mlx4_alloc_cmd_mailbox(dev);
573 memcpy(mgid, gid, 16);
575 err = mlx4_GID_HASH(dev, mailbox, hash, op_mod);
576 mlx4_free_cmd_mailbox(dev, mailbox);
581 mlx4_dbg(dev, "Hash for %pI6 is %04x\n", gid, *hash);
587 err = mlx4_READ_ENTRY(dev, *index, mgm_mailbox);
591 if (!(be32_to_cpu(mgm->members_count) & 0xffffff)) {
592 if (*index != *hash) {
593 mlx4_err(dev, "Found zero MGID in AMGM.\n");
599 if (!memcmp(mgm->gid, gid, 16) &&
600 be32_to_cpu(mgm->members_count) >> 30 == prot)
604 *index = be32_to_cpu(mgm->next_gid_index) >> 6;
611 int mlx4_qp_attach_common(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16],
612 int block_mcast_loopback, enum mlx4_protocol prot,
613 enum mlx4_steer_type steer)
615 struct mlx4_priv *priv = mlx4_priv(dev);
616 struct mlx4_cmd_mailbox *mailbox;
617 struct mlx4_mgm *mgm;
627 mailbox = mlx4_alloc_cmd_mailbox(dev);
629 return PTR_ERR(mailbox);
632 mutex_lock(&priv->mcg_table.mutex);
633 err = find_entry(dev, port, gid, prot, steer,
634 mailbox, &hash, &prev, &index);
639 if (!(be32_to_cpu(mgm->members_count) & 0xffffff)) {
641 memcpy(mgm->gid, gid, 16);
646 index = mlx4_bitmap_alloc(&priv->mcg_table.bitmap);
648 mlx4_err(dev, "No AMGM entries left\n");
652 index += dev->caps.num_mgms;
654 memset(mgm, 0, sizeof *mgm);
655 memcpy(mgm->gid, gid, 16);
658 members_count = be32_to_cpu(mgm->members_count) & 0xffffff;
659 if (members_count == MLX4_QP_PER_MGM) {
660 mlx4_err(dev, "MGM at index %x is full.\n", index);
665 for (i = 0; i < members_count; ++i)
666 if ((be32_to_cpu(mgm->qp[i]) & MGM_QPN_MASK) == qp->qpn) {
667 mlx4_dbg(dev, "QP %06x already a member of MGM\n", qp->qpn);
672 if (block_mcast_loopback)
673 mgm->qp[members_count++] = cpu_to_be32((qp->qpn & MGM_QPN_MASK) |
674 (1U << MGM_BLCK_LB_BIT));
676 mgm->qp[members_count++] = cpu_to_be32(qp->qpn & MGM_QPN_MASK);
678 mgm->members_count = cpu_to_be32(members_count | (u32) prot << 30);
680 err = mlx4_WRITE_ENTRY(dev, index, mailbox);
687 err = mlx4_READ_ENTRY(dev, prev, mailbox);
691 mgm->next_gid_index = cpu_to_be32(index << 6);
693 err = mlx4_WRITE_ENTRY(dev, prev, mailbox);
698 if (prot == MLX4_PROT_ETH) {
699 /* manage the steering entry for promisc mode */
701 new_steering_entry(dev, 0, port, steer, index, qp->qpn);
703 existing_steering_entry(dev, 0, port, steer,
706 if (err && link && index != -1) {
707 if (index < dev->caps.num_mgms)
708 mlx4_warn(dev, "Got AMGM index %d < %d",
709 index, dev->caps.num_mgms);
711 mlx4_bitmap_free(&priv->mcg_table.bitmap,
712 index - dev->caps.num_mgms);
714 mutex_unlock(&priv->mcg_table.mutex);
716 mlx4_free_cmd_mailbox(dev, mailbox);
720 int mlx4_qp_detach_common(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16],
721 enum mlx4_protocol prot, enum mlx4_steer_type steer)
723 struct mlx4_priv *priv = mlx4_priv(dev);
724 struct mlx4_cmd_mailbox *mailbox;
725 struct mlx4_mgm *mgm;
732 bool removed_entry = false;
734 mailbox = mlx4_alloc_cmd_mailbox(dev);
736 return PTR_ERR(mailbox);
739 mutex_lock(&priv->mcg_table.mutex);
741 err = find_entry(dev, port, gid, prot, steer,
742 mailbox, &hash, &prev, &index);
747 mlx4_err(dev, "MGID %pI6 not found\n", gid);
752 /* if this pq is also a promisc qp, it shouldn't be removed */
753 if (prot == MLX4_PROT_ETH &&
754 check_duplicate_entry(dev, 0, port, steer, index, qp->qpn))
757 members_count = be32_to_cpu(mgm->members_count) & 0xffffff;
758 for (loc = -1, i = 0; i < members_count; ++i)
759 if ((be32_to_cpu(mgm->qp[i]) & MGM_QPN_MASK) == qp->qpn)
763 mlx4_err(dev, "QP %06x not found in MGM\n", qp->qpn);
769 mgm->members_count = cpu_to_be32(--members_count | (u32) prot << 30);
770 mgm->qp[loc] = mgm->qp[i - 1];
773 if (prot == MLX4_PROT_ETH)
774 removed_entry = can_remove_steering_entry(dev, 0, port, steer, index, qp->qpn);
775 if (i != 1 && (prot != MLX4_PROT_ETH || !removed_entry)) {
776 err = mlx4_WRITE_ENTRY(dev, index, mailbox);
780 /* We are going to delete the entry, members count should be 0 */
781 mgm->members_count = cpu_to_be32((u32) prot << 30);
784 /* Remove entry from MGM */
785 int amgm_index = be32_to_cpu(mgm->next_gid_index) >> 6;
787 err = mlx4_READ_ENTRY(dev, amgm_index, mailbox);
791 memset(mgm->gid, 0, 16);
793 err = mlx4_WRITE_ENTRY(dev, index, mailbox);
798 if (amgm_index < dev->caps.num_mgms)
799 mlx4_warn(dev, "MGM entry %d had AMGM index %d < %d",
800 index, amgm_index, dev->caps.num_mgms);
802 mlx4_bitmap_free(&priv->mcg_table.bitmap,
803 amgm_index - dev->caps.num_mgms);
806 /* Remove entry from AMGM */
807 int cur_next_index = be32_to_cpu(mgm->next_gid_index) >> 6;
808 err = mlx4_READ_ENTRY(dev, prev, mailbox);
812 mgm->next_gid_index = cpu_to_be32(cur_next_index << 6);
814 err = mlx4_WRITE_ENTRY(dev, prev, mailbox);
818 if (index < dev->caps.num_mgms)
819 mlx4_warn(dev, "entry %d had next AMGM index %d < %d",
820 prev, index, dev->caps.num_mgms);
822 mlx4_bitmap_free(&priv->mcg_table.bitmap,
823 index - dev->caps.num_mgms);
827 mutex_unlock(&priv->mcg_table.mutex);
829 mlx4_free_cmd_mailbox(dev, mailbox);
834 int mlx4_multicast_attach(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16],
835 int block_mcast_loopback, enum mlx4_protocol prot)
837 enum mlx4_steer_type steer;
839 steer = (is_valid_ether_addr(&gid[10])) ? MLX4_UC_STEER : MLX4_MC_STEER;
841 if (prot == MLX4_PROT_ETH &&
842 !(dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_MC_STEER))
845 if (prot == MLX4_PROT_ETH)
846 gid[7] |= (steer << 1);
848 return mlx4_qp_attach_common(dev, qp, gid,
849 block_mcast_loopback, prot,
852 EXPORT_SYMBOL_GPL(mlx4_multicast_attach);
854 int mlx4_multicast_detach(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16],
855 enum mlx4_protocol prot)
857 enum mlx4_steer_type steer;
859 steer = (is_valid_ether_addr(&gid[10])) ? MLX4_UC_STEER : MLX4_MC_STEER;
861 if (prot == MLX4_PROT_ETH &&
862 !(dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_MC_STEER))
865 if (prot == MLX4_PROT_ETH) {
866 gid[7] |= (steer << 1);
869 return mlx4_qp_detach_common(dev, qp, gid, prot, steer);
871 EXPORT_SYMBOL_GPL(mlx4_multicast_detach);
874 int mlx4_multicast_promisc_add(struct mlx4_dev *dev, u32 qpn, u8 port)
876 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_MC_STEER))
880 return add_promisc_qp(dev, 0, port, MLX4_MC_STEER, qpn);
882 EXPORT_SYMBOL_GPL(mlx4_multicast_promisc_add);
884 int mlx4_multicast_promisc_remove(struct mlx4_dev *dev, u32 qpn, u8 port)
886 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_MC_STEER))
890 return remove_promisc_qp(dev, 0, port, MLX4_MC_STEER, qpn);
892 EXPORT_SYMBOL_GPL(mlx4_multicast_promisc_remove);
894 int mlx4_unicast_promisc_add(struct mlx4_dev *dev, u32 qpn, u8 port)
896 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_MC_STEER))
900 return add_promisc_qp(dev, 0, port, MLX4_UC_STEER, qpn);
902 EXPORT_SYMBOL_GPL(mlx4_unicast_promisc_add);
904 int mlx4_unicast_promisc_remove(struct mlx4_dev *dev, u32 qpn, u8 port)
906 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_MC_STEER))
909 return remove_promisc_qp(dev, 0, port, MLX4_UC_STEER, qpn);
911 EXPORT_SYMBOL_GPL(mlx4_unicast_promisc_remove);
913 int mlx4_init_mcg_table(struct mlx4_dev *dev)
915 struct mlx4_priv *priv = mlx4_priv(dev);
918 err = mlx4_bitmap_init(&priv->mcg_table.bitmap, dev->caps.num_amgms,
919 dev->caps.num_amgms - 1, 0, 0);
923 mutex_init(&priv->mcg_table.mutex);
928 void mlx4_cleanup_mcg_table(struct mlx4_dev *dev)
930 mlx4_bitmap_cleanup(&mlx4_priv(dev)->mcg_table.bitmap);