/* * Copyright (c) 2006, 2007 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2007, 2008 Mellanox Technologies. All rights reserved. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the GNU * General Public License (GPL) Version 2, available from the file * COPYING in the main directory of this source tree, or the * OpenIB.org BSD license below: * * Redistribution and use in source and binary forms, with or * without modification, are permitted provided that the following * conditions are met: * * - Redistributions of source code must retain the above * copyright notice, this list of conditions and the following * disclaimer. * * - Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials * provided with the distribution. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE.
*/
/* If the given qpn is also a promisc qp, * it should be inserted to duplicates list
*/
pqp = get_promisc_qp(dev, port, steer, qpn); if (pqp) {
dqp = kmalloc(sizeof(*dqp), GFP_KERNEL); if (!dqp) {
err = -ENOMEM; goto out_alloc;
}
dqp->qpn = qpn;
list_add_tail(&dqp->list, &new_entry->duplicates);
}
/* if no promisc qps for this vep, we are done */ if (list_empty(&s_steer->promisc_qps[steer])) return 0;
/* now need to add all the promisc qps to the new * steering entry, as they should also receive the packets
* destined to this address */
mailbox = mlx4_alloc_cmd_mailbox(dev); if (IS_ERR(mailbox)) {
err = -ENOMEM; goto out_alloc;
}
mgm = mailbox->buf;
err = mlx4_READ_ENTRY(dev, index, mailbox); if (err) goto out_mailbox;
members_count = be32_to_cpu(mgm->members_count) & 0xffffff;
prot = be32_to_cpu(mgm->members_count) >> 30;
list_for_each_entry(pqp, &s_steer->promisc_qps[steer], list) { /* don't add already existing qpn */ if (pqp->qpn == qpn) continue; if (members_count == dev->caps.num_qp_per_mgm) { /* out of space */
err = -ENOMEM; goto out_mailbox;
}
/* add the qpn */
mgm->qp[members_count++] = cpu_to_be32(pqp->qpn & MGM_QPN_MASK);
} /* update the qps count and update the entry with all the promisc qps*/
mgm->members_count = cpu_to_be32(members_count | (prot << 30));
err = mlx4_WRITE_ENTRY(dev, index, mailbox);
out_mailbox:
mlx4_free_cmd_mailbox(dev, mailbox); if (!err) return 0;
out_alloc: if (dqp) {
list_del(&dqp->list);
kfree(dqp);
}
list_del(&new_entry->list);
kfree(new_entry); return err;
}
if (port < 1 || port > dev->caps.num_ports) return -EINVAL;
s_steer = &mlx4_priv(dev)->steer[port - 1];
pqp = get_promisc_qp(dev, port, steer, qpn); if (!pqp) return 0; /* nothing to do */
list_for_each_entry(tmp_entry, &s_steer->steer_entries[steer], list) { if (tmp_entry->index == index) {
entry = tmp_entry; break;
}
} if (unlikely(!entry)) {
mlx4_warn(dev, "Steering entry at index %x is not registered\n", index); return -EINVAL;
}
/* the given qpn is listed as a promisc qpn * we need to add it as a duplicate to this entry
* for future references */
list_for_each_entry(dqp, &entry->duplicates, list) { if (qpn == dqp->qpn) return 0; /* qp is already duplicated */
}
/* add the qp as a duplicate on this index */
dqp = kmalloc(sizeof(*dqp), GFP_KERNEL); if (!dqp) return -ENOMEM;
dqp->qpn = qpn;
list_add_tail(&dqp->list, &entry->duplicates);
return 0;
}
/* Check whether a qpn is a duplicate on steering entry
* If so, it should not be removed from mgm */ staticbool check_duplicate_entry(struct mlx4_dev *dev, u8 port, enum mlx4_steer_type steer, unsignedint index, u32 qpn)
{ struct mlx4_steer *s_steer; struct mlx4_steer_index *tmp_entry, *entry = NULL; struct mlx4_promisc_qp *dqp, *tmp_dqp;
if (port < 1 || port > dev->caps.num_ports) returnfalse;
s_steer = &mlx4_priv(dev)->steer[port - 1];
/* if qp is not promisc, it cannot be duplicated */ if (!get_promisc_qp(dev, port, steer, qpn)) returnfalse;
/* The qp is promisc qp so it is a duplicate on this index
* Find the index entry, and remove the duplicate */
list_for_each_entry(tmp_entry, &s_steer->steer_entries[steer], list) { if (tmp_entry->index == index) {
entry = tmp_entry; break;
}
} if (unlikely(!entry)) {
mlx4_warn(dev, "Steering entry for index %x is not registered\n", index); returnfalse;
}
list_for_each_entry_safe(dqp, tmp_dqp, &entry->duplicates, list) { if (dqp->qpn == qpn) {
list_del(&dqp->list);
kfree(dqp);
}
} returntrue;
}
/* Returns true if all the QPs != tqpn contained in this entry * are Promisc QPs. Returns false otherwise.
*/ staticbool promisc_steering_entry(struct mlx4_dev *dev, u8 port, enum mlx4_steer_type steer, unsignedint index, u32 tqpn,
u32 *members_count)
{ struct mlx4_cmd_mailbox *mailbox; struct mlx4_mgm *mgm;
u32 m_count; bool ret = false; int i;
if (port < 1 || port > dev->caps.num_ports) returnfalse;
mailbox = mlx4_alloc_cmd_mailbox(dev); if (IS_ERR(mailbox)) returnfalse;
mgm = mailbox->buf;
if (mlx4_READ_ENTRY(dev, index, mailbox)) goto out;
m_count = be32_to_cpu(mgm->members_count) & 0xffffff; if (members_count)
*members_count = m_count;
for (i = 0; i < m_count; i++) {
u32 qpn = be32_to_cpu(mgm->qp[i]) & MGM_QPN_MASK; if (!get_promisc_qp(dev, port, steer, qpn) && qpn != tqpn) { /* the qp is not promisc, the entry can't be removed */ goto out;
}
}
ret = true;
out:
mlx4_free_cmd_mailbox(dev, mailbox); return ret;
}
/* IF a steering entry contains only promisc QPs, it can be removed. */ staticbool can_remove_steering_entry(struct mlx4_dev *dev, u8 port, enum mlx4_steer_type steer, unsignedint index, u32 tqpn)
{ struct mlx4_steer *s_steer; struct mlx4_steer_index *entry = NULL, *tmp_entry;
u32 members_count; bool ret = false;
if (port < 1 || port > dev->caps.num_ports) returnfalse;
s_steer = &mlx4_priv(dev)->steer[port - 1];
if (!promisc_steering_entry(dev, port, steer, index,
tqpn, &members_count)) goto out;
/* All the qps currently registered for this entry are promiscuous,
* Checking for duplicates */
ret = true;
list_for_each_entry_safe(entry, tmp_entry, &s_steer->steer_entries[steer], list) { if (entry->index == index) { if (list_empty(&entry->duplicates) ||
members_count == 1) { struct mlx4_promisc_qp *pqp, *tmp_pqp; /* If there is only 1 entry in duplicates then * this is the QP we want to delete, going over * the list and deleting the entry.
*/
list_del(&entry->list);
list_for_each_entry_safe(pqp, tmp_pqp,
&entry->duplicates,
list) {
list_del(&pqp->list);
kfree(pqp);
}
kfree(entry);
} else { /* This entry contains duplicates so it shouldn't be removed */
ret = false; goto out;
}
}
}
if (!(mlx4_is_mfunc(dev) && steer == MLX4_UC_STEER)) { /* The promisc QP needs to be added for each one of the steering * entries. If it already exists, needs to be added as * a duplicate for this entry.
*/
list_for_each_entry(entry,
&s_steer->steer_entries[steer],
list) {
err = mlx4_READ_ENTRY(dev, entry->index, mailbox); if (err) goto out_mailbox;
members_count = be32_to_cpu(mgm->members_count) &
0xffffff;
prot = be32_to_cpu(mgm->members_count) >> 30;
found = false; for (i = 0; i < members_count; i++) { if ((be32_to_cpu(mgm->qp[i]) &
MGM_QPN_MASK) == qpn) { /* Entry already exists. * Add to duplicates.
*/
dqp = kmalloc(sizeof(*dqp), GFP_KERNEL); if (!dqp) {
err = -ENOMEM; goto out_mailbox;
}
dqp->qpn = qpn;
list_add_tail(&dqp->list,
&entry->duplicates);
found = true;
}
} if (!found) { /* Need to add the qpn to mgm */ if (members_count ==
dev->caps.num_qp_per_mgm) { /* entry is full */
err = -ENOMEM; goto out_mailbox;
}
mgm->qp[members_count++] =
cpu_to_be32(qpn & MGM_QPN_MASK);
mgm->members_count =
cpu_to_be32(members_count |
(prot << 30));
err = mlx4_WRITE_ENTRY(dev, entry->index,
mailbox); if (err) goto out_mailbox;
}
}
}
/* add the new qpn to list of promisc qps */
list_add_tail(&pqp->list, &s_steer->promisc_qps[steer]); /* now need to add all the promisc qps to default entry */
memset(mgm, 0, sizeof(*mgm));
members_count = 0;
list_for_each_entry(dqp, &s_steer->promisc_qps[steer], list) { if (members_count == dev->caps.num_qp_per_mgm) { /* entry is full */
err = -ENOMEM; goto out_list;
}
mgm->qp[members_count++] = cpu_to_be32(dqp->qpn & MGM_QPN_MASK);
}
mgm->members_count = cpu_to_be32(members_count | MLX4_PROT_ETH << 30);
err = mlx4_WRITE_PROMISC(dev, port, steer, mailbox); if (err) goto out_list;
pqp = get_promisc_qp(dev, port, steer, qpn); if (unlikely(!pqp)) {
mlx4_warn(dev, "QP %x is not promiscuous QP\n", qpn); /* nothing to do */
err = 0; goto out_mutex;
}
/*remove from list of promisc qps */
list_del(&pqp->list);
/* set the default entry not to include the removed one */
mailbox = mlx4_alloc_cmd_mailbox(dev); if (IS_ERR(mailbox)) {
err = -ENOMEM;
back_to_list = true; goto out_list;
}
mgm = mailbox->buf;
members_count = 0;
list_for_each_entry(dqp, &s_steer->promisc_qps[steer], list)
mgm->qp[members_count++] = cpu_to_be32(dqp->qpn & MGM_QPN_MASK);
mgm->members_count = cpu_to_be32(members_count | MLX4_PROT_ETH << 30);
err = mlx4_WRITE_PROMISC(dev, port, steer, mailbox); if (err) goto out_mailbox;
if (!(mlx4_is_mfunc(dev) && steer == MLX4_UC_STEER)) { /* Remove the QP from all the steering entries */
list_for_each_entry_safe(entry, tmp_entry,
&s_steer->steer_entries[steer],
list) {
found = false;
list_for_each_entry(dqp, &entry->duplicates, list) { if (dqp->qpn == qpn) {
found = true; break;
}
} if (found) { /* A duplicate, no need to change the MGM, * only update the duplicates list
*/
list_del(&dqp->list);
kfree(dqp);
} else { int loc = -1;
err = mlx4_READ_ENTRY(dev,
entry->index,
mailbox); if (err) goto out_mailbox;
members_count =
be32_to_cpu(mgm->members_count) &
0xffffff; if (!members_count) {
mlx4_warn(dev, "QP %06x wasn't found in entry %x mcount=0. deleting entry...\n",
qpn, entry->index);
list_del(&entry->list);
kfree(entry); continue;
}
for (i = 0; i < members_count; ++i) if ((be32_to_cpu(mgm->qp[i]) &
MGM_QPN_MASK) == qpn) {
loc = i; break;
}
if (loc < 0) {
mlx4_err(dev, "QP %06x wasn't found in entry %d\n",
qpn, entry->index);
err = -EINVAL; goto out_mailbox;
}
/* Copy the last QP in this MGM * over removed QP
*/
mgm->qp[loc] = mgm->qp[members_count - 1];
mgm->qp[members_count - 1] = 0;
mgm->members_count =
cpu_to_be32(--members_count |
(MLX4_PROT_ETH << 30));
/* * Caller must hold MCG table semaphore. gid and mgm parameters must * be properly aligned for command interface. * * Returns 0 unless a firmware command error occurs. * * If GID is found in MGM or MGM is empty, *index = *hash, *prev = -1 * and *mgm holds MGM entry. * * if GID is found in AMGM, *index = index in AMGM, *prev = index of * previous entry in hash chain and *mgm holds AMGM entry. * * If no AMGM exists for given gid, *index = -1, *prev = index of last * entry in hash chain and *mgm holds end of hash chain.
*/ staticint find_entry(struct mlx4_dev *dev, u8 port,
u8 *gid, enum mlx4_protocol prot, struct mlx4_cmd_mailbox *mgm_mailbox, int *prev, int *index)
{ struct mlx4_cmd_mailbox *mailbox; struct mlx4_mgm *mgm = mgm_mailbox->buf;
u8 *mgid; int err;
u16 hash;
u8 op_mod = (prot == MLX4_PROT_ETH) ?
!!(dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_MC_STEER) : 0;
mailbox = mlx4_alloc_cmd_mailbox(dev); if (IS_ERR(mailbox)) return -ENOMEM;
mgid = mailbox->buf;
members_count = be32_to_cpu(mgm->members_count) & 0xffffff; if (members_count == dev->caps.num_qp_per_mgm) {
mlx4_err(dev, "MGM at index %x is full\n", index);
err = -ENOMEM; goto out;
}
for (i = 0; i < members_count; ++i) if ((be32_to_cpu(mgm->qp[i]) & MGM_QPN_MASK) == qp->qpn) {
mlx4_dbg(dev, "QP %06x already a member of MGM\n", qp->qpn);
err = 0; goto out;
}
if (index == -1) {
mlx4_err(dev, "MGID %pI6 not found\n", gid);
err = -EINVAL; goto out;
}
/* If this QP is also a promisc QP, it shouldn't be removed only if * at least one none promisc QP is also attached to this MCG
*/ if (prot == MLX4_PROT_ETH &&
check_duplicate_entry(dev, port, steer, index, qp->qpn) &&
!promisc_steering_entry(dev, port, steer, index, qp->qpn, NULL)) goto out;
members_count = be32_to_cpu(mgm->members_count) & 0xffffff; for (i = 0; i < members_count; ++i) if ((be32_to_cpu(mgm->qp[i]) & MGM_QPN_MASK) == qp->qpn) {
loc = i; break;
}
if (loc == -1) {
mlx4_err(dev, "QP %06x not found in MGM\n", qp->qpn);
err = -EINVAL; goto out;
}
/* copy the last QP in this MGM over removed QP */
mgm->qp[loc] = mgm->qp[members_count - 1];
mgm->qp[members_count - 1] = 0;
mgm->members_count = cpu_to_be32(--members_count | (u32) prot << 30);
err = mlx4_WRITE_ENTRY(dev, prev, mailbox); if (err) goto out;
if (index < dev->caps.num_mgms)
mlx4_warn(dev, "entry %d had next AMGM index %d < %d\n",
prev, index, dev->caps.num_mgms); else
mlx4_bitmap_free(&priv->mcg_table.bitmap,
index - dev->caps.num_mgms, MLX4_USE_RR);
}
out:
mutex_unlock(&priv->mcg_table.mutex);
mlx4_free_cmd_mailbox(dev, mailbox); if (err && dev->persist->state & MLX4_DEVICE_STATE_INTERNAL_ERROR) /* In case device is under an error, return success as a closing command */
err = 0; return err;
}
int mlx4_init_mcg_table(struct mlx4_dev *dev)
{ struct mlx4_priv *priv = mlx4_priv(dev); int err;
/* No need for mcg_table when fw managed the mcg table*/ if (dev->caps.steering_mode ==
MLX4_STEERING_MODE_DEVICE_MANAGED) return 0;
err = mlx4_bitmap_init(&priv->mcg_table.bitmap, dev->caps.num_amgms,
dev->caps.num_amgms - 1, 0, 0); if (err) return err;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.