^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Copyright (c) 2012 Mellanox Technologies. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * This software is available to you under a choice of one of two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * licenses. You may choose to be licensed under the terms of the GNU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * General Public License (GPL) Version 2, available from the file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * COPYING in the main directory of this source tree, or the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * OpenIB.org BSD license below:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Redistribution and use in source and binary forms, with or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * without modification, are permitted provided that the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * conditions are met:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * - Redistributions of source code must retain the above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * copyright notice, this list of conditions and the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * disclaimer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * - Redistributions in binary form must reproduce the above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * copyright notice, this list of conditions and the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * disclaimer in the documentation and/or other materials
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * provided with the distribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * SOFTWARE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <rdma/ib_mad.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <rdma/ib_smi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <rdma/ib_cache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <rdma/ib_sa.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/mlx4/cmd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <linux/rbtree.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include "mlx4_ib.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define MAX_VFS 80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define MAX_PEND_REQS_PER_FUNC 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define MAD_TIMEOUT_MS 2000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define mcg_warn(fmt, arg...) pr_warn("MCG WARNING: " fmt, ##arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define mcg_error(fmt, arg...) pr_err(fmt, ##arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define mcg_warn_group(group, format, arg...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) pr_warn("%s-%d: %16s (port %d): WARNING: " format, __func__, __LINE__,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) (group)->name, group->demux->port, ## arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define mcg_debug_group(group, format, arg...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) pr_debug("%s-%d: %16s (port %d): WARNING: " format, __func__, __LINE__,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) (group)->name, (group)->demux->port, ## arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define mcg_error_group(group, format, arg...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) pr_err(" %16s: " format, (group)->name, ## arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static union ib_gid mgid0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static struct workqueue_struct *clean_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) enum mcast_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) MCAST_NOT_MEMBER = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) MCAST_MEMBER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) enum mcast_group_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) MCAST_IDLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) MCAST_JOIN_SENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) MCAST_LEAVE_SENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) MCAST_RESP_READY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct mcast_member {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) enum mcast_state state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) uint8_t join_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) int num_pend_reqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct list_head pending;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct ib_sa_mcmember_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) union ib_gid mgid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) union ib_gid port_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) __be32 qkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) __be16 mlid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) u8 mtusel_mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) u8 tclass;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) __be16 pkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) u8 ratesel_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) u8 lifetmsel_lifetm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) __be32 sl_flowlabel_hoplimit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) u8 scope_join_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) u8 proxy_join;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) u8 reserved[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) } __packed __aligned(4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct mcast_group {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) struct ib_sa_mcmember_data rec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) struct rb_node node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct list_head mgid0_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct mlx4_ib_demux_ctx *demux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct mcast_member func[MAX_VFS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct mutex lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct work_struct work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct list_head pending_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) int members[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) enum mcast_group_state state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) enum mcast_group_state prev_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct ib_sa_mad response_sa_mad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) __be64 last_req_tid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) char name[33]; /* MGID string */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct device_attribute dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) /* refcount is the reference count for the following:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 1. Each queued request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 2. Each invocation of the worker thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 3. Membership of the port at the SA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) atomic_t refcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) /* delayed work to clean pending SM request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) struct delayed_work timeout_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct list_head cleanup_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct mcast_req {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) int func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct ib_sa_mad sa_mad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct list_head group_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct list_head func_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) struct mcast_group *group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) int clean;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) #define safe_atomic_dec(ref) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) do {\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (atomic_dec_and_test(ref)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) mcg_warn_group(group, "did not expect to reach zero\n"); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static const char *get_state_string(enum mcast_group_state state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) switch (state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) case MCAST_IDLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) return "MCAST_IDLE";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) case MCAST_JOIN_SENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) return "MCAST_JOIN_SENT";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) case MCAST_LEAVE_SENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return "MCAST_LEAVE_SENT";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) case MCAST_RESP_READY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) return "MCAST_RESP_READY";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) return "Invalid State";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static struct mcast_group *mcast_find(struct mlx4_ib_demux_ctx *ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) union ib_gid *mgid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct rb_node *node = ctx->mcg_table.rb_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) struct mcast_group *group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) while (node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) group = rb_entry(node, struct mcast_group, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) ret = memcmp(mgid->raw, group->rec.mgid.raw, sizeof *mgid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) return group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) node = node->rb_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) node = node->rb_right;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static struct mcast_group *mcast_insert(struct mlx4_ib_demux_ctx *ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) struct mcast_group *group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) struct rb_node **link = &ctx->mcg_table.rb_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) struct rb_node *parent = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct mcast_group *cur_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) while (*link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) parent = *link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) cur_group = rb_entry(parent, struct mcast_group, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) ret = memcmp(group->rec.mgid.raw, cur_group->rec.mgid.raw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) sizeof group->rec.mgid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) link = &(*link)->rb_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) else if (ret > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) link = &(*link)->rb_right;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) return cur_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) rb_link_node(&group->node, parent, link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) rb_insert_color(&group->node, &ctx->mcg_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static int send_mad_to_wire(struct mlx4_ib_demux_ctx *ctx, struct ib_mad *mad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) struct mlx4_ib_dev *dev = ctx->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) struct rdma_ah_attr ah_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) spin_lock_irqsave(&dev->sm_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) if (!dev->sm_ah[ctx->port - 1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) /* port is not yet Active, sm_ah not ready */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) spin_unlock_irqrestore(&dev->sm_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) mlx4_ib_query_ah(dev->sm_ah[ctx->port - 1], &ah_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) spin_unlock_irqrestore(&dev->sm_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) return mlx4_ib_send_to_wire(dev, mlx4_master_func_num(dev->dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) ctx->port, IB_QPT_GSI, 0, 1, IB_QP1_QKEY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) &ah_attr, NULL, 0xffff, mad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) static int send_mad_to_slave(int slave, struct mlx4_ib_demux_ctx *ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) struct ib_mad *mad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) struct mlx4_ib_dev *dev = ctx->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) struct ib_mad_agent *agent = dev->send_agent[ctx->port - 1][1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) struct ib_wc wc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) struct rdma_ah_attr ah_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) /* Our agent might not yet be registered when mads start to arrive */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) if (!agent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) rdma_query_ah(dev->sm_ah[ctx->port - 1], &ah_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (ib_find_cached_pkey(&dev->ib_dev, ctx->port, IB_DEFAULT_PKEY_FULL, &wc.pkey_index))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) wc.sl = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) wc.dlid_path_bits = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) wc.port_num = ctx->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) wc.slid = rdma_ah_get_dlid(&ah_attr); /* opensm lid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) wc.src_qp = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) return mlx4_ib_send_to_slave(dev, slave, ctx->port, IB_QPT_GSI, &wc, NULL, mad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) static int send_join_to_wire(struct mcast_group *group, struct ib_sa_mad *sa_mad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) struct ib_sa_mad mad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) struct ib_sa_mcmember_data *sa_mad_data = (struct ib_sa_mcmember_data *)&mad.data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) /* we rely on a mad request as arrived from a VF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) memcpy(&mad, sa_mad, sizeof mad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) /* fix port GID to be the real one (slave 0) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) sa_mad_data->port_gid.global.interface_id = group->demux->guid_cache[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) /* assign our own TID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) mad.mad_hdr.tid = mlx4_ib_get_new_demux_tid(group->demux);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) group->last_req_tid = mad.mad_hdr.tid; /* keep it for later validation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) ret = send_mad_to_wire(group->demux, (struct ib_mad *)&mad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) /* set timeout handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) /* calls mlx4_ib_mcg_timeout_handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) queue_delayed_work(group->demux->mcg_wq, &group->timeout_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) msecs_to_jiffies(MAD_TIMEOUT_MS));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) static int send_leave_to_wire(struct mcast_group *group, u8 join_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) struct ib_sa_mad mad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) struct ib_sa_mcmember_data *sa_data = (struct ib_sa_mcmember_data *)&mad.data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) memset(&mad, 0, sizeof mad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) mad.mad_hdr.base_version = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) mad.mad_hdr.mgmt_class = IB_MGMT_CLASS_SUBN_ADM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) mad.mad_hdr.class_version = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) mad.mad_hdr.method = IB_SA_METHOD_DELETE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) mad.mad_hdr.status = cpu_to_be16(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) mad.mad_hdr.class_specific = cpu_to_be16(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) mad.mad_hdr.tid = mlx4_ib_get_new_demux_tid(group->demux);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) group->last_req_tid = mad.mad_hdr.tid; /* keep it for later validation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) mad.mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_MC_MEMBER_REC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) mad.mad_hdr.attr_mod = cpu_to_be32(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) mad.sa_hdr.sm_key = 0x0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) mad.sa_hdr.attr_offset = cpu_to_be16(7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) mad.sa_hdr.comp_mask = IB_SA_MCMEMBER_REC_MGID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) IB_SA_MCMEMBER_REC_PORT_GID | IB_SA_MCMEMBER_REC_JOIN_STATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) *sa_data = group->rec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) sa_data->scope_join_state = join_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) ret = send_mad_to_wire(group->demux, (struct ib_mad *)&mad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) group->state = MCAST_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) /* set timeout handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) /* calls mlx4_ib_mcg_timeout_handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) queue_delayed_work(group->demux->mcg_wq, &group->timeout_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) msecs_to_jiffies(MAD_TIMEOUT_MS));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) static int send_reply_to_slave(int slave, struct mcast_group *group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) struct ib_sa_mad *req_sa_mad, u16 status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) struct ib_sa_mad mad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) struct ib_sa_mcmember_data *sa_data = (struct ib_sa_mcmember_data *)&mad.data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) struct ib_sa_mcmember_data *req_sa_data = (struct ib_sa_mcmember_data *)&req_sa_mad->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) memset(&mad, 0, sizeof mad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) mad.mad_hdr.base_version = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) mad.mad_hdr.mgmt_class = IB_MGMT_CLASS_SUBN_ADM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) mad.mad_hdr.class_version = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) mad.mad_hdr.method = IB_MGMT_METHOD_GET_RESP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) mad.mad_hdr.status = cpu_to_be16(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) mad.mad_hdr.class_specific = cpu_to_be16(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) mad.mad_hdr.tid = req_sa_mad->mad_hdr.tid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) *(u8 *)&mad.mad_hdr.tid = 0; /* resetting tid to 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) mad.mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_MC_MEMBER_REC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) mad.mad_hdr.attr_mod = cpu_to_be32(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) mad.sa_hdr.sm_key = req_sa_mad->sa_hdr.sm_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) mad.sa_hdr.attr_offset = cpu_to_be16(7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) mad.sa_hdr.comp_mask = 0; /* ignored on responses, see IBTA spec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) *sa_data = group->rec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) /* reconstruct VF's requested join_state and port_gid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) sa_data->scope_join_state &= 0xf0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) sa_data->scope_join_state |= (group->func[slave].join_state & 0x0f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) memcpy(&sa_data->port_gid, &req_sa_data->port_gid, sizeof req_sa_data->port_gid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) ret = send_mad_to_slave(slave, group->demux, (struct ib_mad *)&mad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) static int check_selector(ib_sa_comp_mask comp_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) ib_sa_comp_mask selector_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) ib_sa_comp_mask value_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) u8 src_value, u8 dst_value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) u8 selector = dst_value >> 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) dst_value &= 0x3f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) src_value &= 0x3f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) if (!(comp_mask & selector_mask) || !(comp_mask & value_mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) switch (selector) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) case IB_SA_GT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) err = (src_value <= dst_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) case IB_SA_LT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) err = (src_value >= dst_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) case IB_SA_EQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) err = (src_value != dst_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) static u16 cmp_rec(struct ib_sa_mcmember_data *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) struct ib_sa_mcmember_data *dst, ib_sa_comp_mask comp_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) /* src is group record, dst is request record */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) /* MGID must already match */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) /* Port_GID we always replace to our Port_GID, so it is a match */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) #define MAD_STATUS_REQ_INVALID 0x0200
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) if (comp_mask & IB_SA_MCMEMBER_REC_QKEY && src->qkey != dst->qkey)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) return MAD_STATUS_REQ_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) if (comp_mask & IB_SA_MCMEMBER_REC_MLID && src->mlid != dst->mlid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) return MAD_STATUS_REQ_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) if (check_selector(comp_mask, IB_SA_MCMEMBER_REC_MTU_SELECTOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) IB_SA_MCMEMBER_REC_MTU,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) src->mtusel_mtu, dst->mtusel_mtu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) return MAD_STATUS_REQ_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) if (comp_mask & IB_SA_MCMEMBER_REC_TRAFFIC_CLASS &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) src->tclass != dst->tclass)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) return MAD_STATUS_REQ_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) if (comp_mask & IB_SA_MCMEMBER_REC_PKEY && src->pkey != dst->pkey)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) return MAD_STATUS_REQ_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) if (check_selector(comp_mask, IB_SA_MCMEMBER_REC_RATE_SELECTOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) IB_SA_MCMEMBER_REC_RATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) src->ratesel_rate, dst->ratesel_rate))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) return MAD_STATUS_REQ_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) if (check_selector(comp_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME_SELECTOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) src->lifetmsel_lifetm, dst->lifetmsel_lifetm))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) return MAD_STATUS_REQ_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) if (comp_mask & IB_SA_MCMEMBER_REC_SL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) (be32_to_cpu(src->sl_flowlabel_hoplimit) & 0xf0000000) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) (be32_to_cpu(dst->sl_flowlabel_hoplimit) & 0xf0000000))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) return MAD_STATUS_REQ_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) if (comp_mask & IB_SA_MCMEMBER_REC_FLOW_LABEL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) (be32_to_cpu(src->sl_flowlabel_hoplimit) & 0x0fffff00) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) (be32_to_cpu(dst->sl_flowlabel_hoplimit) & 0x0fffff00))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) return MAD_STATUS_REQ_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) if (comp_mask & IB_SA_MCMEMBER_REC_HOP_LIMIT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) (be32_to_cpu(src->sl_flowlabel_hoplimit) & 0x000000ff) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) (be32_to_cpu(dst->sl_flowlabel_hoplimit) & 0x000000ff))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) return MAD_STATUS_REQ_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) if (comp_mask & IB_SA_MCMEMBER_REC_SCOPE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) (src->scope_join_state & 0xf0) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) (dst->scope_join_state & 0xf0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) return MAD_STATUS_REQ_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) /* join_state checked separately, proxy_join ignored */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) /* release group, return 1 if this was last release and group is destroyed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) * timout work is canceled sync */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) static int release_group(struct mcast_group *group, int from_timeout_handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) struct mlx4_ib_demux_ctx *ctx = group->demux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) int nzgroup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) mutex_lock(&ctx->mcg_table_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) mutex_lock(&group->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) if (atomic_dec_and_test(&group->refcount)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) if (!from_timeout_handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) if (group->state != MCAST_IDLE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) !cancel_delayed_work(&group->timeout_work)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) atomic_inc(&group->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) mutex_unlock(&group->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) mutex_unlock(&ctx->mcg_table_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) nzgroup = memcmp(&group->rec.mgid, &mgid0, sizeof mgid0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) if (nzgroup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) del_sysfs_port_mcg_attr(ctx->dev, ctx->port, &group->dentry.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) if (!list_empty(&group->pending_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) mcg_warn_group(group, "releasing a group with non empty pending list\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) if (nzgroup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) rb_erase(&group->node, &ctx->mcg_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) list_del_init(&group->mgid0_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) mutex_unlock(&group->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) mutex_unlock(&ctx->mcg_table_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) kfree(group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) mutex_unlock(&group->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) mutex_unlock(&ctx->mcg_table_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) static void adjust_membership(struct mcast_group *group, u8 join_state, int inc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) for (i = 0; i < 3; i++, join_state >>= 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) if (join_state & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) group->members[i] += inc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) static u8 get_leave_state(struct mcast_group *group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) u8 leave_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) for (i = 0; i < 3; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) if (!group->members[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) leave_state |= (1 << i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) return leave_state & (group->rec.scope_join_state & 0xf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) static int join_group(struct mcast_group *group, int slave, u8 join_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) u8 join_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) /* remove bits that slave is already member of, and adjust */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) join_state = join_mask & (~group->func[slave].join_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) adjust_membership(group, join_state, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) group->func[slave].join_state |= join_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) if (group->func[slave].state != MCAST_MEMBER && join_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) group->func[slave].state = MCAST_MEMBER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) static int leave_group(struct mcast_group *group, int slave, u8 leave_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) adjust_membership(group, leave_state, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) group->func[slave].join_state &= ~leave_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) if (!group->func[slave].join_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) group->func[slave].state = MCAST_NOT_MEMBER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) static int check_leave(struct mcast_group *group, int slave, u8 leave_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) if (group->func[slave].state != MCAST_MEMBER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) return MAD_STATUS_REQ_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) /* make sure we're not deleting unset bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) if (~group->func[slave].join_state & leave_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) return MAD_STATUS_REQ_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) if (!leave_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) return MAD_STATUS_REQ_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) static void mlx4_ib_mcg_timeout_handler(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) struct delayed_work *delay = to_delayed_work(work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) struct mcast_group *group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) struct mcast_req *req = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) group = container_of(delay, typeof(*group), timeout_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) mutex_lock(&group->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) if (group->state == MCAST_JOIN_SENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) if (!list_empty(&group->pending_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) req = list_first_entry(&group->pending_list, struct mcast_req, group_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) list_del(&req->group_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) list_del(&req->func_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) --group->func[req->func].num_pend_reqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) mutex_unlock(&group->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) kfree(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) if (memcmp(&group->rec.mgid, &mgid0, sizeof mgid0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) if (release_group(group, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) kfree(group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) mutex_lock(&group->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) mcg_warn_group(group, "DRIVER BUG\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) } else if (group->state == MCAST_LEAVE_SENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) if (group->rec.scope_join_state & 0xf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) group->rec.scope_join_state &= 0xf0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) group->state = MCAST_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) mutex_unlock(&group->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) if (release_group(group, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) mutex_lock(&group->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) mcg_warn_group(group, "invalid state %s\n", get_state_string(group->state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) group->state = MCAST_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) atomic_inc(&group->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) if (!queue_work(group->demux->mcg_wq, &group->work))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) safe_atomic_dec(&group->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) mutex_unlock(&group->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) static int handle_leave_req(struct mcast_group *group, u8 leave_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) struct mcast_req *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) u16 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) if (req->clean)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) leave_mask = group->func[req->func].join_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) status = check_leave(group, req->func, leave_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) if (!status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) leave_group(group, req->func, leave_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) if (!req->clean)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) send_reply_to_slave(req->func, group, &req->sa_mad, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) --group->func[req->func].num_pend_reqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) list_del(&req->group_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) list_del(&req->func_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) kfree(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) static int handle_join_req(struct mcast_group *group, u8 join_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) struct mcast_req *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) u8 group_join_state = group->rec.scope_join_state & 0xf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) int ref = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) u16 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) struct ib_sa_mcmember_data *sa_data = (struct ib_sa_mcmember_data *)req->sa_mad.data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) if (join_mask == (group_join_state & join_mask)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) /* port's membership need not change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) status = cmp_rec(&group->rec, sa_data, req->sa_mad.sa_hdr.comp_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) if (!status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) join_group(group, req->func, join_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) --group->func[req->func].num_pend_reqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) send_reply_to_slave(req->func, group, &req->sa_mad, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) list_del(&req->group_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) list_del(&req->func_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) kfree(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) ++ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) /* port's membership needs to be updated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) group->prev_state = group->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) if (send_join_to_wire(group, &req->sa_mad)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) --group->func[req->func].num_pend_reqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) list_del(&req->group_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) list_del(&req->func_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) kfree(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) ref = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) group->state = group->prev_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) group->state = MCAST_JOIN_SENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) return ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) static void mlx4_ib_mcg_work_handler(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) struct mcast_group *group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) struct mcast_req *req = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) struct ib_sa_mcmember_data *sa_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) u8 req_join_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) int rc = 1; /* release_count - this is for the scheduled work */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) u16 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) u8 method;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) group = container_of(work, typeof(*group), work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) mutex_lock(&group->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) /* First, let's see if a response from SM is waiting regarding this group.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) * If so, we need to update the group's REC. If this is a bad response, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) * may need to send a bad response to a VF waiting for it. If VF is waiting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) * and this is a good response, the VF will be answered later in this func. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) if (group->state == MCAST_RESP_READY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) /* cancels mlx4_ib_mcg_timeout_handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) cancel_delayed_work(&group->timeout_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) status = be16_to_cpu(group->response_sa_mad.mad_hdr.status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) method = group->response_sa_mad.mad_hdr.method;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) if (group->last_req_tid != group->response_sa_mad.mad_hdr.tid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) mcg_warn_group(group, "Got MAD response to existing MGID but wrong TID, dropping. Resp TID=%llx, group TID=%llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) be64_to_cpu(group->response_sa_mad.mad_hdr.tid),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) be64_to_cpu(group->last_req_tid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) group->state = group->prev_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) goto process_requests;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) if (!list_empty(&group->pending_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) req = list_first_entry(&group->pending_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) struct mcast_req, group_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) if (method == IB_MGMT_METHOD_GET_RESP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) if (req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) send_reply_to_slave(req->func, group, &req->sa_mad, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) --group->func[req->func].num_pend_reqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) list_del(&req->group_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) list_del(&req->func_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) kfree(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) ++rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) mcg_warn_group(group, "no request for failed join\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) } else if (method == IB_SA_METHOD_DELETE_RESP && group->demux->flushing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) ++rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) u8 resp_join_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) u8 cur_join_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) resp_join_state = ((struct ib_sa_mcmember_data *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) group->response_sa_mad.data)->scope_join_state & 0xf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) cur_join_state = group->rec.scope_join_state & 0xf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) if (method == IB_MGMT_METHOD_GET_RESP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) /* successfull join */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) if (!cur_join_state && resp_join_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) --rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) } else if (!resp_join_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) ++rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) memcpy(&group->rec, group->response_sa_mad.data, sizeof group->rec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) group->state = MCAST_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) process_requests:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) /* We should now go over pending join/leave requests, as long as we are idle. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) while (!list_empty(&group->pending_list) && group->state == MCAST_IDLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) req = list_first_entry(&group->pending_list, struct mcast_req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) group_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) sa_data = (struct ib_sa_mcmember_data *)req->sa_mad.data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) req_join_state = sa_data->scope_join_state & 0xf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) /* For a leave request, we will immediately answer the VF, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) * update our internal counters. The actual leave will be sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) * to SM later, if at all needed. We dequeue the request now. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) if (req->sa_mad.mad_hdr.method == IB_SA_METHOD_DELETE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) rc += handle_leave_req(group, req_join_state, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) rc += handle_join_req(group, req_join_state, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) /* Handle leaves */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) if (group->state == MCAST_IDLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) req_join_state = get_leave_state(group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) if (req_join_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) group->rec.scope_join_state &= ~req_join_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) group->prev_state = group->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) if (send_leave_to_wire(group, req_join_state)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) group->state = group->prev_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) ++rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) group->state = MCAST_LEAVE_SENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) if (!list_empty(&group->pending_list) && group->state == MCAST_IDLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) goto process_requests;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) mutex_unlock(&group->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) while (rc--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) release_group(group, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) static struct mcast_group *search_relocate_mgid0_group(struct mlx4_ib_demux_ctx *ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) __be64 tid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) union ib_gid *new_mgid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) struct mcast_group *group = NULL, *cur_group, *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) struct mcast_req *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) mutex_lock(&ctx->mcg_table_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) list_for_each_entry_safe(group, n, &ctx->mcg_mgid0_list, mgid0_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) mutex_lock(&group->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) if (group->last_req_tid == tid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) if (memcmp(new_mgid, &mgid0, sizeof mgid0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) group->rec.mgid = *new_mgid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) sprintf(group->name, "%016llx%016llx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) be64_to_cpu(group->rec.mgid.global.subnet_prefix),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) be64_to_cpu(group->rec.mgid.global.interface_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) list_del_init(&group->mgid0_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) cur_group = mcast_insert(ctx, group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) if (cur_group) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) /* A race between our code and SM. Silently cleaning the new one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) req = list_first_entry(&group->pending_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) struct mcast_req, group_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) --group->func[req->func].num_pend_reqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) list_del(&req->group_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) list_del(&req->func_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) kfree(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) mutex_unlock(&group->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) mutex_unlock(&ctx->mcg_table_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) release_group(group, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) atomic_inc(&group->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) add_sysfs_port_mcg_attr(ctx->dev, ctx->port, &group->dentry.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) mutex_unlock(&group->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) mutex_unlock(&ctx->mcg_table_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) return group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) struct mcast_req *tmp1, *tmp2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) list_del(&group->mgid0_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) if (!list_empty(&group->pending_list) && group->state != MCAST_IDLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) cancel_delayed_work_sync(&group->timeout_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) list_for_each_entry_safe(tmp1, tmp2, &group->pending_list, group_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) list_del(&tmp1->group_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) kfree(tmp1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) mutex_unlock(&group->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) mutex_unlock(&ctx->mcg_table_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) kfree(group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) mutex_unlock(&group->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) mutex_unlock(&ctx->mcg_table_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) static ssize_t sysfs_show_group(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) struct device_attribute *attr, char *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) static struct mcast_group *acquire_group(struct mlx4_ib_demux_ctx *ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) union ib_gid *mgid, int create)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) struct mcast_group *group, *cur_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) int is_mgid0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) is_mgid0 = !memcmp(&mgid0, mgid, sizeof mgid0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) if (!is_mgid0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) group = mcast_find(ctx, mgid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) if (group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) if (!create)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) return ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) group = kzalloc(sizeof(*group), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) if (!group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) group->demux = ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) group->rec.mgid = *mgid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) INIT_LIST_HEAD(&group->pending_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) INIT_LIST_HEAD(&group->mgid0_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) for (i = 0; i < MAX_VFS; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) INIT_LIST_HEAD(&group->func[i].pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) INIT_WORK(&group->work, mlx4_ib_mcg_work_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) INIT_DELAYED_WORK(&group->timeout_work, mlx4_ib_mcg_timeout_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) mutex_init(&group->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) sprintf(group->name, "%016llx%016llx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) be64_to_cpu(group->rec.mgid.global.subnet_prefix),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) be64_to_cpu(group->rec.mgid.global.interface_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) sysfs_attr_init(&group->dentry.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) group->dentry.show = sysfs_show_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) group->dentry.store = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) group->dentry.attr.name = group->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) group->dentry.attr.mode = 0400;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) group->state = MCAST_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) if (is_mgid0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) list_add(&group->mgid0_list, &ctx->mcg_mgid0_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) cur_group = mcast_insert(ctx, group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) if (cur_group) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) mcg_warn("group just showed up %s - confused\n", cur_group->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) kfree(group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) add_sysfs_port_mcg_attr(ctx->dev, ctx->port, &group->dentry.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) atomic_inc(&group->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) return group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) static void queue_req(struct mcast_req *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) struct mcast_group *group = req->group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) atomic_inc(&group->refcount); /* for the request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) atomic_inc(&group->refcount); /* for scheduling the work */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) list_add_tail(&req->group_list, &group->pending_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) list_add_tail(&req->func_list, &group->func[req->func].pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) /* calls mlx4_ib_mcg_work_handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) if (!queue_work(group->demux->mcg_wq, &group->work))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) safe_atomic_dec(&group->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) int mlx4_ib_mcg_demux_handler(struct ib_device *ibdev, int port, int slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) struct ib_sa_mad *mad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) struct mlx4_ib_dev *dev = to_mdev(ibdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) struct ib_sa_mcmember_data *rec = (struct ib_sa_mcmember_data *)mad->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) struct mlx4_ib_demux_ctx *ctx = &dev->sriov.demux[port - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) struct mcast_group *group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) switch (mad->mad_hdr.method) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) case IB_MGMT_METHOD_GET_RESP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) case IB_SA_METHOD_DELETE_RESP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) mutex_lock(&ctx->mcg_table_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) group = acquire_group(ctx, &rec->mgid, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) mutex_unlock(&ctx->mcg_table_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) if (IS_ERR(group)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) if (mad->mad_hdr.method == IB_MGMT_METHOD_GET_RESP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) __be64 tid = mad->mad_hdr.tid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) *(u8 *)(&tid) = (u8)slave; /* in group we kept the modified TID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) group = search_relocate_mgid0_group(ctx, tid, &rec->mgid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) group = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) if (!group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) mutex_lock(&group->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) group->response_sa_mad = *mad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) group->prev_state = group->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) group->state = MCAST_RESP_READY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) /* calls mlx4_ib_mcg_work_handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) atomic_inc(&group->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) if (!queue_work(ctx->mcg_wq, &group->work))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) safe_atomic_dec(&group->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) mutex_unlock(&group->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) release_group(group, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) return 1; /* consumed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) case IB_MGMT_METHOD_SET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) case IB_SA_METHOD_GET_TABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) case IB_SA_METHOD_GET_TABLE_RESP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) case IB_SA_METHOD_DELETE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) return 0; /* not consumed, pass-through to guest over tunnel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) mcg_warn("In demux, port %d: unexpected MCMember method: 0x%x, dropping\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) port, mad->mad_hdr.method);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) return 1; /* consumed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) int mlx4_ib_mcg_multiplex_handler(struct ib_device *ibdev, int port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) int slave, struct ib_sa_mad *sa_mad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) struct mlx4_ib_dev *dev = to_mdev(ibdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) struct ib_sa_mcmember_data *rec = (struct ib_sa_mcmember_data *)sa_mad->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) struct mlx4_ib_demux_ctx *ctx = &dev->sriov.demux[port - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) struct mcast_group *group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) struct mcast_req *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) int may_create = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) if (ctx->flushing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) switch (sa_mad->mad_hdr.method) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) case IB_MGMT_METHOD_SET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) may_create = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) case IB_SA_METHOD_DELETE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) req = kzalloc(sizeof *req, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) if (!req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) req->func = slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) req->sa_mad = *sa_mad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) mutex_lock(&ctx->mcg_table_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) group = acquire_group(ctx, &rec->mgid, may_create);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) mutex_unlock(&ctx->mcg_table_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) if (IS_ERR(group)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) kfree(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) return PTR_ERR(group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) mutex_lock(&group->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) if (group->func[slave].num_pend_reqs > MAX_PEND_REQS_PER_FUNC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) mutex_unlock(&group->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) mcg_debug_group(group, "Port %d, Func %d has too many pending requests (%d), dropping\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) port, slave, MAX_PEND_REQS_PER_FUNC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) release_group(group, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) kfree(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) ++group->func[slave].num_pend_reqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) req->group = group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) queue_req(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) mutex_unlock(&group->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) release_group(group, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) return 1; /* consumed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) case IB_SA_METHOD_GET_TABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) case IB_MGMT_METHOD_GET_RESP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) case IB_SA_METHOD_GET_TABLE_RESP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) case IB_SA_METHOD_DELETE_RESP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) return 0; /* not consumed, pass-through */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) mcg_warn("In multiplex, port %d, func %d: unexpected MCMember method: 0x%x, dropping\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) port, slave, sa_mad->mad_hdr.method);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) return 1; /* consumed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) static ssize_t sysfs_show_group(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) struct mcast_group *group =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) container_of(attr, struct mcast_group, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) struct mcast_req *req = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) char pending_str[40];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) char state_str[40];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) ssize_t len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) int f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) if (group->state == MCAST_IDLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) sprintf(state_str, "%s", get_state_string(group->state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) sprintf(state_str, "%s(TID=0x%llx)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) get_state_string(group->state),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) be64_to_cpu(group->last_req_tid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) if (list_empty(&group->pending_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) sprintf(pending_str, "No");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) req = list_first_entry(&group->pending_list, struct mcast_req, group_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) sprintf(pending_str, "Yes(TID=0x%llx)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) be64_to_cpu(req->sa_mad.mad_hdr.tid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) len += sprintf(buf + len, "%1d [%02d,%02d,%02d] %4d %4s %5s ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) group->rec.scope_join_state & 0xf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) group->members[2], group->members[1], group->members[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) atomic_read(&group->refcount),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) pending_str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) state_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) for (f = 0; f < MAX_VFS; ++f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) if (group->func[f].state == MCAST_MEMBER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) len += sprintf(buf + len, "%d[%1x] ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) f, group->func[f].join_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) len += sprintf(buf + len, "\t\t(%4hx %4x %2x %2x %2x %2x %2x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) "%4x %4x %2x %2x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) be16_to_cpu(group->rec.pkey),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) be32_to_cpu(group->rec.qkey),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) (group->rec.mtusel_mtu & 0xc0) >> 6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) group->rec.mtusel_mtu & 0x3f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) group->rec.tclass,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) (group->rec.ratesel_rate & 0xc0) >> 6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) group->rec.ratesel_rate & 0x3f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) (be32_to_cpu(group->rec.sl_flowlabel_hoplimit) & 0xf0000000) >> 28,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) (be32_to_cpu(group->rec.sl_flowlabel_hoplimit) & 0x0fffff00) >> 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) be32_to_cpu(group->rec.sl_flowlabel_hoplimit) & 0x000000ff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) group->rec.proxy_join);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) char name[20];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) atomic_set(&ctx->tid, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) sprintf(name, "mlx4_ib_mcg%d", ctx->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) ctx->mcg_wq = alloc_ordered_workqueue(name, WQ_MEM_RECLAIM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) if (!ctx->mcg_wq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) mutex_init(&ctx->mcg_table_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) ctx->mcg_table = RB_ROOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) INIT_LIST_HEAD(&ctx->mcg_mgid0_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) ctx->flushing = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) static void force_clean_group(struct mcast_group *group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) struct mcast_req *req, *tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) list_for_each_entry_safe(req, tmp, &group->pending_list, group_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) list_del(&req->group_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) kfree(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) del_sysfs_port_mcg_attr(group->demux->dev, group->demux->port, &group->dentry.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) rb_erase(&group->node, &group->demux->mcg_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) kfree(group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) static void _mlx4_ib_mcg_port_cleanup(struct mlx4_ib_demux_ctx *ctx, int destroy_wq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) struct rb_node *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) struct mcast_group *group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) unsigned long end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) for (i = 0; i < MAX_VFS; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) clean_vf_mcast(ctx, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) end = jiffies + msecs_to_jiffies(MAD_TIMEOUT_MS + 3000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) mutex_lock(&ctx->mcg_table_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) for (p = rb_first(&ctx->mcg_table); p; p = rb_next(p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) ++count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) mutex_unlock(&ctx->mcg_table_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) if (!count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) usleep_range(1000, 2000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) } while (time_after(end, jiffies));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) flush_workqueue(ctx->mcg_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) if (destroy_wq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) destroy_workqueue(ctx->mcg_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) mutex_lock(&ctx->mcg_table_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) while ((p = rb_first(&ctx->mcg_table)) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) group = rb_entry(p, struct mcast_group, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) if (atomic_read(&group->refcount))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) mcg_debug_group(group, "group refcount %d!!! (pointer %p)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) atomic_read(&group->refcount), group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) force_clean_group(group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) mutex_unlock(&ctx->mcg_table_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) struct clean_work {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) struct work_struct work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) struct mlx4_ib_demux_ctx *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) int destroy_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) static void mcg_clean_task(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) struct clean_work *cw = container_of(work, struct clean_work, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) _mlx4_ib_mcg_port_cleanup(cw->ctx, cw->destroy_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) cw->ctx->flushing = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) kfree(cw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) void mlx4_ib_mcg_port_cleanup(struct mlx4_ib_demux_ctx *ctx, int destroy_wq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) struct clean_work *work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) if (ctx->flushing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) ctx->flushing = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) if (destroy_wq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) _mlx4_ib_mcg_port_cleanup(ctx, destroy_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) ctx->flushing = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) work = kmalloc(sizeof *work, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) if (!work) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) ctx->flushing = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) work->ctx = ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) work->destroy_wq = destroy_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) INIT_WORK(&work->work, mcg_clean_task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) queue_work(clean_wq, &work->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) static void build_leave_mad(struct mcast_req *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) struct ib_sa_mad *mad = &req->sa_mad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) mad->mad_hdr.method = IB_SA_METHOD_DELETE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) static void clear_pending_reqs(struct mcast_group *group, int vf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) struct mcast_req *req, *tmp, *group_first = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) int clear;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) int pend = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) if (!list_empty(&group->pending_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) group_first = list_first_entry(&group->pending_list, struct mcast_req, group_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) list_for_each_entry_safe(req, tmp, &group->func[vf].pending, func_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) clear = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) if (group_first == req &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) (group->state == MCAST_JOIN_SENT ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) group->state == MCAST_LEAVE_SENT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) clear = cancel_delayed_work(&group->timeout_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) pend = !clear;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) group->state = MCAST_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) if (clear) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) --group->func[vf].num_pend_reqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) list_del(&req->group_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) list_del(&req->func_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) kfree(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) atomic_dec(&group->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) if (!pend && (!list_empty(&group->func[vf].pending) || group->func[vf].num_pend_reqs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) mcg_warn_group(group, "DRIVER BUG: list_empty %d, num_pend_reqs %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) list_empty(&group->func[vf].pending), group->func[vf].num_pend_reqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) static int push_deleteing_req(struct mcast_group *group, int slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) struct mcast_req *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) struct mcast_req *pend_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) if (!group->func[slave].join_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) req = kzalloc(sizeof *req, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) if (!req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) if (!list_empty(&group->func[slave].pending)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) pend_req = list_entry(group->func[slave].pending.prev, struct mcast_req, group_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) if (pend_req->clean) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) kfree(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) req->clean = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) req->func = slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) req->group = group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) ++group->func[slave].num_pend_reqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) build_leave_mad(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) queue_req(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) void clean_vf_mcast(struct mlx4_ib_demux_ctx *ctx, int slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) struct mcast_group *group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) struct rb_node *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) mutex_lock(&ctx->mcg_table_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) for (p = rb_first(&ctx->mcg_table); p; p = rb_next(p)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) group = rb_entry(p, struct mcast_group, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) mutex_lock(&group->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) if (atomic_read(&group->refcount)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) /* clear pending requests of this VF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) clear_pending_reqs(group, slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) push_deleteing_req(group, slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) mutex_unlock(&group->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) mutex_unlock(&ctx->mcg_table_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) int mlx4_ib_mcg_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) clean_wq = alloc_ordered_workqueue("mlx4_ib_mcg", WQ_MEM_RECLAIM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) if (!clean_wq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) void mlx4_ib_mcg_destroy(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) destroy_workqueue(clean_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) }