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
);
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
);
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
);
71 static int mlx4_GID_HASH(struct mlx4_dev
*dev
, struct mlx4_cmd_mailbox
*mailbox
,
77 err
= mlx4_cmd_imm(dev
, mailbox
->dma
, &imm
, 0, op_mod
,
78 MLX4_CMD_MGID_HASH
, MLX4_CMD_TIME_CLASS_A
);
86 static struct mlx4_promisc_qp
*get_promisc_qp(struct mlx4_dev
*dev
, u8 pf_num
,
87 enum mlx4_steer_type steer
,
90 struct mlx4_steer
*s_steer
= &mlx4_priv(dev
)->steer
[pf_num
];
91 struct mlx4_promisc_qp
*pqp
;
93 list_for_each_entry(pqp
, &s_steer
->promisc_qps
[steer
], list
) {
102 * Add new entry to steering data structure.
103 * All promisc QPs should be added as well
105 static int new_steering_entry(struct mlx4_dev
*dev
, u8 vep_num
, u8 port
,
106 enum mlx4_steer_type steer
,
107 unsigned int index
, u32 qpn
)
109 struct mlx4_steer
*s_steer
;
110 struct mlx4_cmd_mailbox
*mailbox
;
111 struct mlx4_mgm
*mgm
;
113 struct mlx4_steer_index
*new_entry
;
114 struct mlx4_promisc_qp
*pqp
;
115 struct mlx4_promisc_qp
*dqp
= NULL
;
120 pf_num
= (dev
->caps
.num_ports
== 1) ? vep_num
: (vep_num
<< 1) | (port
- 1);
121 s_steer
= &mlx4_priv(dev
)->steer
[pf_num
];
122 new_entry
= kzalloc(sizeof *new_entry
, GFP_KERNEL
);
126 INIT_LIST_HEAD(&new_entry
->duplicates
);
127 new_entry
->index
= index
;
128 list_add_tail(&new_entry
->list
, &s_steer
->steer_entries
[steer
]);
130 /* If the given qpn is also a promisc qp,
131 * it should be inserted to duplicates list
133 pqp
= get_promisc_qp(dev
, pf_num
, steer
, qpn
);
135 dqp
= kmalloc(sizeof *dqp
, GFP_KERNEL
);
141 list_add_tail(&dqp
->list
, &new_entry
->duplicates
);
144 /* if no promisc qps for this vep, we are done */
145 if (list_empty(&s_steer
->promisc_qps
[steer
]))
148 /* now need to add all the promisc qps to the new
149 * steering entry, as they should also receive the packets
150 * destined to this address */
151 mailbox
= mlx4_alloc_cmd_mailbox(dev
);
152 if (IS_ERR(mailbox
)) {
158 err
= mlx4_READ_ENTRY(dev
, index
, mailbox
);
162 members_count
= be32_to_cpu(mgm
->members_count
) & 0xffffff;
163 prot
= be32_to_cpu(mgm
->members_count
) >> 30;
164 list_for_each_entry(pqp
, &s_steer
->promisc_qps
[steer
], list
) {
165 /* don't add already existing qpn */
168 if (members_count
== MLX4_QP_PER_MGM
) {
175 mgm
->qp
[members_count
++] = cpu_to_be32(pqp
->qpn
& MGM_QPN_MASK
);
177 /* update the qps count and update the entry with all the promisc qps*/
178 mgm
->members_count
= cpu_to_be32(members_count
| (prot
<< 30));
179 err
= mlx4_WRITE_ENTRY(dev
, index
, mailbox
);
182 mlx4_free_cmd_mailbox(dev
, mailbox
);
187 list_del(&dqp
->list
);
190 list_del(&new_entry
->list
);
195 /* update the data structures with existing steering entry */
196 static int existing_steering_entry(struct mlx4_dev
*dev
, u8 vep_num
, u8 port
,
197 enum mlx4_steer_type steer
,
198 unsigned int index
, u32 qpn
)
200 struct mlx4_steer
*s_steer
;
201 struct mlx4_steer_index
*tmp_entry
, *entry
= NULL
;
202 struct mlx4_promisc_qp
*pqp
;
203 struct mlx4_promisc_qp
*dqp
;
206 pf_num
= (dev
->caps
.num_ports
== 1) ? vep_num
: (vep_num
<< 1) | (port
- 1);
207 s_steer
= &mlx4_priv(dev
)->steer
[pf_num
];
209 pqp
= get_promisc_qp(dev
, pf_num
, steer
, qpn
);
211 return 0; /* nothing to do */
213 list_for_each_entry(tmp_entry
, &s_steer
->steer_entries
[steer
], list
) {
214 if (tmp_entry
->index
== index
) {
219 if (unlikely(!entry
)) {
220 mlx4_warn(dev
, "Steering entry at index %x is not registered\n", index
);
224 /* the given qpn is listed as a promisc qpn
225 * we need to add it as a duplicate to this entry
226 * for future references */
227 list_for_each_entry(dqp
, &entry
->duplicates
, list
) {
229 return 0; /* qp is already duplicated */
232 /* add the qp as a duplicate on this index */
233 dqp
= kmalloc(sizeof *dqp
, GFP_KERNEL
);
237 list_add_tail(&dqp
->list
, &entry
->duplicates
);
242 /* Check whether a qpn is a duplicate on steering entry
243 * If so, it should not be removed from mgm */
244 static bool check_duplicate_entry(struct mlx4_dev
*dev
, u8 vep_num
, u8 port
,
245 enum mlx4_steer_type steer
,
246 unsigned int index
, u32 qpn
)
248 struct mlx4_steer
*s_steer
;
249 struct mlx4_steer_index
*tmp_entry
, *entry
= NULL
;
250 struct mlx4_promisc_qp
*dqp
, *tmp_dqp
;
253 pf_num
= (dev
->caps
.num_ports
== 1) ? vep_num
: (vep_num
<< 1) | (port
- 1);
254 s_steer
= &mlx4_priv(dev
)->steer
[pf_num
];
256 /* if qp is not promisc, it cannot be duplicated */
257 if (!get_promisc_qp(dev
, pf_num
, steer
, qpn
))
260 /* The qp is promisc qp so it is a duplicate on this index
261 * Find the index entry, and remove the duplicate */
262 list_for_each_entry(tmp_entry
, &s_steer
->steer_entries
[steer
], list
) {
263 if (tmp_entry
->index
== index
) {
268 if (unlikely(!entry
)) {
269 mlx4_warn(dev
, "Steering entry for index %x is not registered\n", index
);
272 list_for_each_entry_safe(dqp
, tmp_dqp
, &entry
->duplicates
, list
) {
273 if (dqp
->qpn
== qpn
) {
274 list_del(&dqp
->list
);
281 /* I a steering entry contains only promisc QPs, it can be removed. */
282 static bool can_remove_steering_entry(struct mlx4_dev
*dev
, u8 vep_num
, u8 port
,
283 enum mlx4_steer_type steer
,
284 unsigned int index
, u32 tqpn
)
286 struct mlx4_steer
*s_steer
;
287 struct mlx4_cmd_mailbox
*mailbox
;
288 struct mlx4_mgm
*mgm
;
289 struct mlx4_steer_index
*entry
= NULL
, *tmp_entry
;
296 pf_num
= (dev
->caps
.num_ports
== 1) ? vep_num
: (vep_num
<< 1) | (port
- 1);
297 s_steer
= &mlx4_priv(dev
)->steer
[pf_num
];
299 mailbox
= mlx4_alloc_cmd_mailbox(dev
);
304 if (mlx4_READ_ENTRY(dev
, index
, mailbox
))
306 members_count
= be32_to_cpu(mgm
->members_count
) & 0xffffff;
307 for (i
= 0; i
< members_count
; i
++) {
308 qpn
= be32_to_cpu(mgm
->qp
[i
]) & MGM_QPN_MASK
;
309 if (!get_promisc_qp(dev
, pf_num
, steer
, qpn
) && qpn
!= tqpn
) {
310 /* the qp is not promisc, the entry can't be removed */
314 /* All the qps currently registered for this entry are promiscuous,
315 * Checking for duplicates */
317 list_for_each_entry_safe(entry
, tmp_entry
, &s_steer
->steer_entries
[steer
], list
) {
318 if (entry
->index
== index
) {
319 if (list_empty(&entry
->duplicates
)) {
320 list_del(&entry
->list
);
323 /* This entry contains duplicates so it shouldn't be removed */
331 mlx4_free_cmd_mailbox(dev
, mailbox
);
335 static int add_promisc_qp(struct mlx4_dev
*dev
, u8 vep_num
, u8 port
,
336 enum mlx4_steer_type steer
, u32 qpn
)
338 struct mlx4_steer
*s_steer
;
339 struct mlx4_cmd_mailbox
*mailbox
;
340 struct mlx4_mgm
*mgm
;
341 struct mlx4_steer_index
*entry
;
342 struct mlx4_promisc_qp
*pqp
;
343 struct mlx4_promisc_qp
*dqp
;
351 struct mlx4_priv
*priv
= mlx4_priv(dev
);
352 pf_num
= (dev
->caps
.num_ports
== 1) ? vep_num
: (vep_num
<< 1) | (port
- 1);
353 s_steer
= &mlx4_priv(dev
)->steer
[pf_num
];
355 mutex_lock(&priv
->mcg_table
.mutex
);
357 if (get_promisc_qp(dev
, pf_num
, steer
, qpn
)) {
358 err
= 0; /* Noting to do, already exists */
362 pqp
= kmalloc(sizeof *pqp
, GFP_KERNEL
);
369 mailbox
= mlx4_alloc_cmd_mailbox(dev
);
370 if (IS_ERR(mailbox
)) {
376 /* the promisc qp needs to be added for each one of the steering
377 * entries, if it already exists, needs to be added as a duplicate
379 list_for_each_entry(entry
, &s_steer
->steer_entries
[steer
], list
) {
380 err
= mlx4_READ_ENTRY(dev
, entry
->index
, mailbox
);
384 members_count
= be32_to_cpu(mgm
->members_count
) & 0xffffff;
385 prot
= be32_to_cpu(mgm
->members_count
) >> 30;
387 for (i
= 0; i
< members_count
; i
++) {
388 if ((be32_to_cpu(mgm
->qp
[i
]) & MGM_QPN_MASK
) == qpn
) {
389 /* Entry already exists, add to duplicates */
390 dqp
= kmalloc(sizeof *dqp
, GFP_KERNEL
);
394 list_add_tail(&dqp
->list
, &entry
->duplicates
);
399 /* Need to add the qpn to mgm */
400 if (members_count
== MLX4_QP_PER_MGM
) {
405 mgm
->qp
[members_count
++] = cpu_to_be32(qpn
& MGM_QPN_MASK
);
406 mgm
->members_count
= cpu_to_be32(members_count
| (prot
<< 30));
407 err
= mlx4_WRITE_ENTRY(dev
, entry
->index
, mailbox
);
411 last_index
= entry
->index
;
414 /* add the new qpn to list of promisc qps */
415 list_add_tail(&pqp
->list
, &s_steer
->promisc_qps
[steer
]);
416 /* now need to add all the promisc qps to default entry */
417 memset(mgm
, 0, sizeof *mgm
);
419 list_for_each_entry(dqp
, &s_steer
->promisc_qps
[steer
], list
)
420 mgm
->qp
[members_count
++] = cpu_to_be32(dqp
->qpn
& MGM_QPN_MASK
);
421 mgm
->members_count
= cpu_to_be32(members_count
| MLX4_PROT_ETH
<< 30);
423 err
= mlx4_WRITE_PROMISC(dev
, vep_num
, port
, steer
, mailbox
);
427 mlx4_free_cmd_mailbox(dev
, mailbox
);
428 mutex_unlock(&priv
->mcg_table
.mutex
);
432 list_del(&pqp
->list
);
434 mlx4_free_cmd_mailbox(dev
, mailbox
);
438 mutex_unlock(&priv
->mcg_table
.mutex
);
442 static int remove_promisc_qp(struct mlx4_dev
*dev
, u8 vep_num
, u8 port
,
443 enum mlx4_steer_type steer
, u32 qpn
)
445 struct mlx4_priv
*priv
= mlx4_priv(dev
);
446 struct mlx4_steer
*s_steer
;
447 struct mlx4_cmd_mailbox
*mailbox
;
448 struct mlx4_mgm
*mgm
;
449 struct mlx4_steer_index
*entry
;
450 struct mlx4_promisc_qp
*pqp
;
451 struct mlx4_promisc_qp
*dqp
;
454 bool back_to_list
= false;
459 pf_num
= (dev
->caps
.num_ports
== 1) ? vep_num
: (vep_num
<< 1) | (port
- 1);
460 s_steer
= &mlx4_priv(dev
)->steer
[pf_num
];
461 mutex_lock(&priv
->mcg_table
.mutex
);
463 pqp
= get_promisc_qp(dev
, pf_num
, steer
, qpn
);
464 if (unlikely(!pqp
)) {
465 mlx4_warn(dev
, "QP %x is not promiscuous QP\n", qpn
);
471 /*remove from list of promisc qps */
472 list_del(&pqp
->list
);
474 /* set the default entry not to include the removed one */
475 mailbox
= mlx4_alloc_cmd_mailbox(dev
);
476 if (IS_ERR(mailbox
)) {
483 list_for_each_entry(dqp
, &s_steer
->promisc_qps
[steer
], list
)
484 mgm
->qp
[members_count
++] = cpu_to_be32(dqp
->qpn
& MGM_QPN_MASK
);
485 mgm
->members_count
= cpu_to_be32(members_count
| MLX4_PROT_ETH
<< 30);
487 err
= mlx4_WRITE_PROMISC(dev
, vep_num
, port
, steer
, mailbox
);
491 /* remove the qp from all the steering entries*/
492 list_for_each_entry(entry
, &s_steer
->steer_entries
[steer
], list
) {
494 list_for_each_entry(dqp
, &entry
->duplicates
, list
) {
495 if (dqp
->qpn
== qpn
) {
501 /* a duplicate, no need to change the mgm,
502 * only update the duplicates list */
503 list_del(&dqp
->list
);
506 err
= mlx4_READ_ENTRY(dev
, entry
->index
, mailbox
);
509 members_count
= be32_to_cpu(mgm
->members_count
) & 0xffffff;
510 for (loc
= -1, i
= 0; i
< members_count
; ++i
)
511 if ((be32_to_cpu(mgm
->qp
[i
]) & MGM_QPN_MASK
) == qpn
)
514 mgm
->members_count
= cpu_to_be32(--members_count
|
515 (MLX4_PROT_ETH
<< 30));
516 mgm
->qp
[loc
] = mgm
->qp
[i
- 1];
519 err
= mlx4_WRITE_ENTRY(dev
, entry
->index
, mailbox
);
527 mlx4_free_cmd_mailbox(dev
, mailbox
);
530 list_add_tail(&pqp
->list
, &s_steer
->promisc_qps
[steer
]);
534 mutex_unlock(&priv
->mcg_table
.mutex
);
539 * Caller must hold MCG table semaphore. gid and mgm parameters must
540 * be properly aligned for command interface.
542 * Returns 0 unless a firmware command error occurs.
544 * If GID is found in MGM or MGM is empty, *index = *hash, *prev = -1
545 * and *mgm holds MGM entry.
547 * if GID is found in AMGM, *index = index in AMGM, *prev = index of
548 * previous entry in hash chain and *mgm holds AMGM entry.
550 * If no AMGM exists for given gid, *index = -1, *prev = index of last
551 * entry in hash chain and *mgm holds end of hash chain.
553 static int find_entry(struct mlx4_dev
*dev
, u8 port
,
554 u8
*gid
, enum mlx4_protocol prot
,
555 enum mlx4_steer_type steer
,
556 struct mlx4_cmd_mailbox
*mgm_mailbox
,
557 u16
*hash
, int *prev
, int *index
)
559 struct mlx4_cmd_mailbox
*mailbox
;
560 struct mlx4_mgm
*mgm
= mgm_mailbox
->buf
;
563 u8 op_mod
= (prot
== MLX4_PROT_ETH
) ?
564 !!(dev
->caps
.flags
& MLX4_DEV_CAP_FLAG_VEP_MC_STEER
) : 0;
566 mailbox
= mlx4_alloc_cmd_mailbox(dev
);
571 memcpy(mgid
, gid
, 16);
573 err
= mlx4_GID_HASH(dev
, mailbox
, hash
, op_mod
);
574 mlx4_free_cmd_mailbox(dev
, mailbox
);
579 mlx4_dbg(dev
, "Hash for %pI6 is %04x\n", gid
, *hash
);
585 err
= mlx4_READ_ENTRY(dev
, *index
, mgm_mailbox
);
589 if (!(be32_to_cpu(mgm
->members_count
) & 0xffffff)) {
590 if (*index
!= *hash
) {
591 mlx4_err(dev
, "Found zero MGID in AMGM.\n");
597 if (!memcmp(mgm
->gid
, gid
, 16) &&
598 be32_to_cpu(mgm
->members_count
) >> 30 == prot
)
602 *index
= be32_to_cpu(mgm
->next_gid_index
) >> 6;
609 int mlx4_qp_attach_common(struct mlx4_dev
*dev
, struct mlx4_qp
*qp
, u8 gid
[16],
610 int block_mcast_loopback
, enum mlx4_protocol prot
,
611 enum mlx4_steer_type steer
)
613 struct mlx4_priv
*priv
= mlx4_priv(dev
);
614 struct mlx4_cmd_mailbox
*mailbox
;
615 struct mlx4_mgm
*mgm
;
625 mailbox
= mlx4_alloc_cmd_mailbox(dev
);
627 return PTR_ERR(mailbox
);
630 mutex_lock(&priv
->mcg_table
.mutex
);
631 err
= find_entry(dev
, port
, gid
, prot
, steer
,
632 mailbox
, &hash
, &prev
, &index
);
637 if (!(be32_to_cpu(mgm
->members_count
) & 0xffffff)) {
639 memcpy(mgm
->gid
, gid
, 16);
644 index
= mlx4_bitmap_alloc(&priv
->mcg_table
.bitmap
);
646 mlx4_err(dev
, "No AMGM entries left\n");
650 index
+= dev
->caps
.num_mgms
;
652 memset(mgm
, 0, sizeof *mgm
);
653 memcpy(mgm
->gid
, gid
, 16);
656 members_count
= be32_to_cpu(mgm
->members_count
) & 0xffffff;
657 if (members_count
== MLX4_QP_PER_MGM
) {
658 mlx4_err(dev
, "MGM at index %x is full.\n", index
);
663 for (i
= 0; i
< members_count
; ++i
)
664 if ((be32_to_cpu(mgm
->qp
[i
]) & MGM_QPN_MASK
) == qp
->qpn
) {
665 mlx4_dbg(dev
, "QP %06x already a member of MGM\n", qp
->qpn
);
670 if (block_mcast_loopback
)
671 mgm
->qp
[members_count
++] = cpu_to_be32((qp
->qpn
& MGM_QPN_MASK
) |
672 (1U << MGM_BLCK_LB_BIT
));
674 mgm
->qp
[members_count
++] = cpu_to_be32(qp
->qpn
& MGM_QPN_MASK
);
676 mgm
->members_count
= cpu_to_be32(members_count
| (u32
) prot
<< 30);
678 err
= mlx4_WRITE_ENTRY(dev
, index
, mailbox
);
685 err
= mlx4_READ_ENTRY(dev
, prev
, mailbox
);
689 mgm
->next_gid_index
= cpu_to_be32(index
<< 6);
691 err
= mlx4_WRITE_ENTRY(dev
, prev
, mailbox
);
696 if (prot
== MLX4_PROT_ETH
) {
697 /* manage the steering entry for promisc mode */
699 new_steering_entry(dev
, 0, port
, steer
, index
, qp
->qpn
);
701 existing_steering_entry(dev
, 0, port
, steer
,
704 if (err
&& link
&& index
!= -1) {
705 if (index
< dev
->caps
.num_mgms
)
706 mlx4_warn(dev
, "Got AMGM index %d < %d",
707 index
, dev
->caps
.num_mgms
);
709 mlx4_bitmap_free(&priv
->mcg_table
.bitmap
,
710 index
- dev
->caps
.num_mgms
);
712 mutex_unlock(&priv
->mcg_table
.mutex
);
714 mlx4_free_cmd_mailbox(dev
, mailbox
);
718 int mlx4_qp_detach_common(struct mlx4_dev
*dev
, struct mlx4_qp
*qp
, u8 gid
[16],
719 enum mlx4_protocol prot
, enum mlx4_steer_type steer
)
721 struct mlx4_priv
*priv
= mlx4_priv(dev
);
722 struct mlx4_cmd_mailbox
*mailbox
;
723 struct mlx4_mgm
*mgm
;
730 bool removed_entry
= false;
732 mailbox
= mlx4_alloc_cmd_mailbox(dev
);
734 return PTR_ERR(mailbox
);
737 mutex_lock(&priv
->mcg_table
.mutex
);
739 err
= find_entry(dev
, port
, gid
, prot
, steer
,
740 mailbox
, &hash
, &prev
, &index
);
745 mlx4_err(dev
, "MGID %pI6 not found\n", gid
);
750 /* if this pq is also a promisc qp, it shouldn't be removed */
751 if (prot
== MLX4_PROT_ETH
&&
752 check_duplicate_entry(dev
, 0, port
, steer
, index
, qp
->qpn
))
755 members_count
= be32_to_cpu(mgm
->members_count
) & 0xffffff;
756 for (loc
= -1, i
= 0; i
< members_count
; ++i
)
757 if ((be32_to_cpu(mgm
->qp
[i
]) & MGM_QPN_MASK
) == qp
->qpn
)
761 mlx4_err(dev
, "QP %06x not found in MGM\n", qp
->qpn
);
767 mgm
->members_count
= cpu_to_be32(--members_count
| (u32
) prot
<< 30);
768 mgm
->qp
[loc
] = mgm
->qp
[i
- 1];
771 if (prot
== MLX4_PROT_ETH
)
772 removed_entry
= can_remove_steering_entry(dev
, 0, port
, steer
, index
, qp
->qpn
);
773 if (i
!= 1 && (prot
!= MLX4_PROT_ETH
|| !removed_entry
)) {
774 err
= mlx4_WRITE_ENTRY(dev
, index
, mailbox
);
778 /* We are going to delete the entry, members count should be 0 */
779 mgm
->members_count
= cpu_to_be32((u32
) prot
<< 30);
782 /* Remove entry from MGM */
783 int amgm_index
= be32_to_cpu(mgm
->next_gid_index
) >> 6;
785 err
= mlx4_READ_ENTRY(dev
, amgm_index
, mailbox
);
789 memset(mgm
->gid
, 0, 16);
791 err
= mlx4_WRITE_ENTRY(dev
, index
, mailbox
);
796 if (amgm_index
< dev
->caps
.num_mgms
)
797 mlx4_warn(dev
, "MGM entry %d had AMGM index %d < %d",
798 index
, amgm_index
, dev
->caps
.num_mgms
);
800 mlx4_bitmap_free(&priv
->mcg_table
.bitmap
,
801 amgm_index
- dev
->caps
.num_mgms
);
804 /* Remove entry from AMGM */
805 int cur_next_index
= be32_to_cpu(mgm
->next_gid_index
) >> 6;
806 err
= mlx4_READ_ENTRY(dev
, prev
, mailbox
);
810 mgm
->next_gid_index
= cpu_to_be32(cur_next_index
<< 6);
812 err
= mlx4_WRITE_ENTRY(dev
, prev
, mailbox
);
816 if (index
< dev
->caps
.num_mgms
)
817 mlx4_warn(dev
, "entry %d had next AMGM index %d < %d",
818 prev
, index
, dev
->caps
.num_mgms
);
820 mlx4_bitmap_free(&priv
->mcg_table
.bitmap
,
821 index
- dev
->caps
.num_mgms
);
825 mutex_unlock(&priv
->mcg_table
.mutex
);
827 mlx4_free_cmd_mailbox(dev
, mailbox
);
832 int mlx4_multicast_attach(struct mlx4_dev
*dev
, struct mlx4_qp
*qp
, u8 gid
[16],
833 int block_mcast_loopback
, enum mlx4_protocol prot
)
835 enum mlx4_steer_type steer
;
837 steer
= (is_valid_ether_addr(&gid
[10])) ? MLX4_UC_STEER
: MLX4_MC_STEER
;
839 if (prot
== MLX4_PROT_ETH
&&
840 !(dev
->caps
.flags
& MLX4_DEV_CAP_FLAG_VEP_MC_STEER
))
843 if (prot
== MLX4_PROT_ETH
)
844 gid
[7] |= (steer
<< 1);
846 return mlx4_qp_attach_common(dev
, qp
, gid
,
847 block_mcast_loopback
, prot
,
850 EXPORT_SYMBOL_GPL(mlx4_multicast_attach
);
852 int mlx4_multicast_detach(struct mlx4_dev
*dev
, struct mlx4_qp
*qp
, u8 gid
[16],
853 enum mlx4_protocol prot
)
855 enum mlx4_steer_type steer
;
857 steer
= (is_valid_ether_addr(&gid
[10])) ? MLX4_UC_STEER
: MLX4_MC_STEER
;
859 if (prot
== MLX4_PROT_ETH
&&
860 !(dev
->caps
.flags
& MLX4_DEV_CAP_FLAG_VEP_MC_STEER
))
863 if (prot
== MLX4_PROT_ETH
) {
864 gid
[7] |= (steer
<< 1);
867 return mlx4_qp_detach_common(dev
, qp
, gid
, prot
, steer
);
869 EXPORT_SYMBOL_GPL(mlx4_multicast_detach
);
872 int mlx4_multicast_promisc_add(struct mlx4_dev
*dev
, u32 qpn
, u8 port
)
874 if (!(dev
->caps
.flags
& MLX4_DEV_CAP_FLAG_VEP_MC_STEER
))
878 return add_promisc_qp(dev
, 0, port
, MLX4_MC_STEER
, qpn
);
880 EXPORT_SYMBOL_GPL(mlx4_multicast_promisc_add
);
882 int mlx4_multicast_promisc_remove(struct mlx4_dev
*dev
, u32 qpn
, u8 port
)
884 if (!(dev
->caps
.flags
& MLX4_DEV_CAP_FLAG_VEP_MC_STEER
))
888 return remove_promisc_qp(dev
, 0, port
, MLX4_MC_STEER
, qpn
);
890 EXPORT_SYMBOL_GPL(mlx4_multicast_promisc_remove
);
892 int mlx4_unicast_promisc_add(struct mlx4_dev
*dev
, u32 qpn
, u8 port
)
894 if (!(dev
->caps
.flags
& MLX4_DEV_CAP_FLAG_VEP_MC_STEER
))
898 return add_promisc_qp(dev
, 0, port
, MLX4_UC_STEER
, qpn
);
900 EXPORT_SYMBOL_GPL(mlx4_unicast_promisc_add
);
902 int mlx4_unicast_promisc_remove(struct mlx4_dev
*dev
, u32 qpn
, u8 port
)
904 if (!(dev
->caps
.flags
& MLX4_DEV_CAP_FLAG_VEP_MC_STEER
))
907 return remove_promisc_qp(dev
, 0, port
, MLX4_UC_STEER
, qpn
);
909 EXPORT_SYMBOL_GPL(mlx4_unicast_promisc_remove
);
911 int mlx4_init_mcg_table(struct mlx4_dev
*dev
)
913 struct mlx4_priv
*priv
= mlx4_priv(dev
);
916 err
= mlx4_bitmap_init(&priv
->mcg_table
.bitmap
, dev
->caps
.num_amgms
,
917 dev
->caps
.num_amgms
- 1, 0, 0);
921 mutex_init(&priv
->mcg_table
.mutex
);
926 void mlx4_cleanup_mcg_table(struct mlx4_dev
*dev
)
928 mlx4_bitmap_cleanup(&mlx4_priv(dev
)->mcg_table
.bitmap
);