Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2006, 2007 Cisco Systems, Inc. All rights reserved. |
Jack Morgenstein | 51a379d | 2008-07-25 10:32:52 -0700 | [diff] [blame] | 3 | * Copyright (c) 2007, 2008 Mellanox Technologies. All rights reserved. |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 4 | * |
| 5 | * This software is available to you under a choice of one of two |
| 6 | * licenses. You may choose to be licensed under the terms of the GNU |
| 7 | * General Public License (GPL) Version 2, available from the file |
| 8 | * COPYING in the main directory of this source tree, or the |
| 9 | * OpenIB.org BSD license below: |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or |
| 12 | * without modification, are permitted provided that the following |
| 13 | * conditions are met: |
| 14 | * |
| 15 | * - Redistributions of source code must retain the above |
| 16 | * copyright notice, this list of conditions and the following |
| 17 | * disclaimer. |
| 18 | * |
| 19 | * - Redistributions in binary form must reproduce the above |
| 20 | * copyright notice, this list of conditions and the following |
| 21 | * disclaimer in the documentation and/or other materials |
| 22 | * provided with the distribution. |
| 23 | * |
| 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 25 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 26 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 27 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 28 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 29 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 30 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 31 | * SOFTWARE. |
| 32 | */ |
| 33 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 34 | #include <linux/string.h> |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 35 | #include <linux/etherdevice.h> |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 36 | |
| 37 | #include <linux/mlx4/cmd.h> |
Paul Gortmaker | ee40fa0 | 2011-05-27 16:14:23 -0400 | [diff] [blame] | 38 | #include <linux/export.h> |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 39 | |
| 40 | #include "mlx4.h" |
| 41 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 42 | static const u8 zero_gid[16]; /* automatically initialized to 0 */ |
| 43 | |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 44 | int mlx4_get_mgm_entry_size(struct mlx4_dev *dev) |
| 45 | { |
Jack Morgenstein | 3c439b5 | 2012-12-06 17:12:00 +0000 | [diff] [blame] | 46 | return 1 << dev->oper_log_mgm_entry_size; |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | int mlx4_get_qp_per_mgm(struct mlx4_dev *dev) |
| 50 | { |
| 51 | return 4 * (mlx4_get_mgm_entry_size(dev) / 16 - 2); |
| 52 | } |
| 53 | |
Hadar Hen Zion | 8fcfb4d | 2012-07-05 04:03:45 +0000 | [diff] [blame] | 54 | static int mlx4_QP_FLOW_STEERING_ATTACH(struct mlx4_dev *dev, |
| 55 | struct mlx4_cmd_mailbox *mailbox, |
| 56 | u32 size, |
| 57 | u64 *reg_id) |
| 58 | { |
| 59 | u64 imm; |
| 60 | int err = 0; |
| 61 | |
| 62 | err = mlx4_cmd_imm(dev, mailbox->dma, &imm, size, 0, |
| 63 | MLX4_QP_FLOW_STEERING_ATTACH, MLX4_CMD_TIME_CLASS_A, |
| 64 | MLX4_CMD_NATIVE); |
| 65 | if (err) |
| 66 | return err; |
| 67 | *reg_id = imm; |
| 68 | |
| 69 | return err; |
| 70 | } |
| 71 | |
| 72 | static int mlx4_QP_FLOW_STEERING_DETACH(struct mlx4_dev *dev, u64 regid) |
| 73 | { |
| 74 | int err = 0; |
| 75 | |
| 76 | err = mlx4_cmd(dev, regid, 0, 0, |
| 77 | MLX4_QP_FLOW_STEERING_DETACH, MLX4_CMD_TIME_CLASS_A, |
| 78 | MLX4_CMD_NATIVE); |
| 79 | |
| 80 | return err; |
| 81 | } |
| 82 | |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 83 | static int mlx4_READ_ENTRY(struct mlx4_dev *dev, int index, |
| 84 | struct mlx4_cmd_mailbox *mailbox) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 85 | { |
| 86 | return mlx4_cmd_box(dev, 0, mailbox->dma, index, 0, MLX4_CMD_READ_MCG, |
Jack Morgenstein | f9baff5 | 2011-12-13 04:10:51 +0000 | [diff] [blame] | 87 | MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 90 | static int mlx4_WRITE_ENTRY(struct mlx4_dev *dev, int index, |
| 91 | struct mlx4_cmd_mailbox *mailbox) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 92 | { |
| 93 | return mlx4_cmd(dev, mailbox->dma, index, 0, MLX4_CMD_WRITE_MCG, |
Jack Morgenstein | f9baff5 | 2011-12-13 04:10:51 +0000 | [diff] [blame] | 94 | MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 97 | static int mlx4_WRITE_PROMISC(struct mlx4_dev *dev, u8 port, u8 steer, |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 98 | struct mlx4_cmd_mailbox *mailbox) |
| 99 | { |
| 100 | u32 in_mod; |
| 101 | |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 102 | in_mod = (u32) port << 16 | steer << 1; |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 103 | return mlx4_cmd(dev, mailbox->dma, in_mod, 0x1, |
Jack Morgenstein | f9baff5 | 2011-12-13 04:10:51 +0000 | [diff] [blame] | 104 | MLX4_CMD_WRITE_MCG, MLX4_CMD_TIME_CLASS_A, |
| 105 | MLX4_CMD_NATIVE); |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 108 | static int mlx4_GID_HASH(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbox, |
| 109 | u16 *hash, u8 op_mod) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 110 | { |
| 111 | u64 imm; |
| 112 | int err; |
| 113 | |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 114 | err = mlx4_cmd_imm(dev, mailbox->dma, &imm, 0, op_mod, |
Jack Morgenstein | f9baff5 | 2011-12-13 04:10:51 +0000 | [diff] [blame] | 115 | MLX4_CMD_MGID_HASH, MLX4_CMD_TIME_CLASS_A, |
| 116 | MLX4_CMD_NATIVE); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 117 | |
| 118 | if (!err) |
| 119 | *hash = imm; |
| 120 | |
| 121 | return err; |
| 122 | } |
| 123 | |
Aviad Yehezkel | 60d31c1 | 2012-09-05 22:50:50 +0000 | [diff] [blame] | 124 | static struct mlx4_promisc_qp *get_promisc_qp(struct mlx4_dev *dev, u8 port, |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 125 | enum mlx4_steer_type steer, |
| 126 | u32 qpn) |
| 127 | { |
Matan Barak | 982290a | 2013-12-19 21:20:18 +0200 | [diff] [blame] | 128 | struct mlx4_steer *s_steer; |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 129 | struct mlx4_promisc_qp *pqp; |
| 130 | |
Matan Barak | 982290a | 2013-12-19 21:20:18 +0200 | [diff] [blame] | 131 | if (port < 1 || port > dev->caps.num_ports) |
| 132 | return NULL; |
| 133 | |
| 134 | s_steer = &mlx4_priv(dev)->steer[port - 1]; |
| 135 | |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 136 | list_for_each_entry(pqp, &s_steer->promisc_qps[steer], list) { |
| 137 | if (pqp->qpn == qpn) |
| 138 | return pqp; |
| 139 | } |
| 140 | /* not found */ |
| 141 | return NULL; |
| 142 | } |
| 143 | |
| 144 | /* |
| 145 | * Add new entry to steering data structure. |
| 146 | * All promisc QPs should be added as well |
| 147 | */ |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 148 | static int new_steering_entry(struct mlx4_dev *dev, u8 port, |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 149 | enum mlx4_steer_type steer, |
| 150 | unsigned int index, u32 qpn) |
| 151 | { |
| 152 | struct mlx4_steer *s_steer; |
| 153 | struct mlx4_cmd_mailbox *mailbox; |
| 154 | struct mlx4_mgm *mgm; |
| 155 | u32 members_count; |
| 156 | struct mlx4_steer_index *new_entry; |
| 157 | struct mlx4_promisc_qp *pqp; |
Mariusz Kozlowski | a14b289 | 2011-04-03 22:04:01 -0700 | [diff] [blame] | 158 | struct mlx4_promisc_qp *dqp = NULL; |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 159 | u32 prot; |
| 160 | int err; |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 161 | |
Matan Barak | 982290a | 2013-12-19 21:20:18 +0200 | [diff] [blame] | 162 | if (port < 1 || port > dev->caps.num_ports) |
| 163 | return -EINVAL; |
| 164 | |
Eugenia Emantayev | 4c41b36 | 2012-02-06 06:26:36 +0000 | [diff] [blame] | 165 | s_steer = &mlx4_priv(dev)->steer[port - 1]; |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 166 | new_entry = kzalloc(sizeof *new_entry, GFP_KERNEL); |
| 167 | if (!new_entry) |
| 168 | return -ENOMEM; |
| 169 | |
| 170 | INIT_LIST_HEAD(&new_entry->duplicates); |
| 171 | new_entry->index = index; |
| 172 | list_add_tail(&new_entry->list, &s_steer->steer_entries[steer]); |
| 173 | |
| 174 | /* If the given qpn is also a promisc qp, |
| 175 | * it should be inserted to duplicates list |
| 176 | */ |
Aviad Yehezkel | 60d31c1 | 2012-09-05 22:50:50 +0000 | [diff] [blame] | 177 | pqp = get_promisc_qp(dev, port, steer, qpn); |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 178 | if (pqp) { |
| 179 | dqp = kmalloc(sizeof *dqp, GFP_KERNEL); |
| 180 | if (!dqp) { |
| 181 | err = -ENOMEM; |
| 182 | goto out_alloc; |
| 183 | } |
| 184 | dqp->qpn = qpn; |
| 185 | list_add_tail(&dqp->list, &new_entry->duplicates); |
| 186 | } |
| 187 | |
| 188 | /* if no promisc qps for this vep, we are done */ |
| 189 | if (list_empty(&s_steer->promisc_qps[steer])) |
| 190 | return 0; |
| 191 | |
| 192 | /* now need to add all the promisc qps to the new |
| 193 | * steering entry, as they should also receive the packets |
| 194 | * destined to this address */ |
| 195 | mailbox = mlx4_alloc_cmd_mailbox(dev); |
| 196 | if (IS_ERR(mailbox)) { |
| 197 | err = -ENOMEM; |
| 198 | goto out_alloc; |
| 199 | } |
| 200 | mgm = mailbox->buf; |
| 201 | |
| 202 | err = mlx4_READ_ENTRY(dev, index, mailbox); |
| 203 | if (err) |
| 204 | goto out_mailbox; |
| 205 | |
| 206 | members_count = be32_to_cpu(mgm->members_count) & 0xffffff; |
| 207 | prot = be32_to_cpu(mgm->members_count) >> 30; |
| 208 | list_for_each_entry(pqp, &s_steer->promisc_qps[steer], list) { |
| 209 | /* don't add already existing qpn */ |
| 210 | if (pqp->qpn == qpn) |
| 211 | continue; |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 212 | if (members_count == dev->caps.num_qp_per_mgm) { |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 213 | /* out of space */ |
| 214 | err = -ENOMEM; |
| 215 | goto out_mailbox; |
| 216 | } |
| 217 | |
| 218 | /* add the qpn */ |
| 219 | mgm->qp[members_count++] = cpu_to_be32(pqp->qpn & MGM_QPN_MASK); |
| 220 | } |
| 221 | /* update the qps count and update the entry with all the promisc qps*/ |
| 222 | mgm->members_count = cpu_to_be32(members_count | (prot << 30)); |
| 223 | err = mlx4_WRITE_ENTRY(dev, index, mailbox); |
| 224 | |
| 225 | out_mailbox: |
| 226 | mlx4_free_cmd_mailbox(dev, mailbox); |
| 227 | if (!err) |
| 228 | return 0; |
| 229 | out_alloc: |
| 230 | if (dqp) { |
| 231 | list_del(&dqp->list); |
Mariusz Kozlowski | a14b289 | 2011-04-03 22:04:01 -0700 | [diff] [blame] | 232 | kfree(dqp); |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 233 | } |
| 234 | list_del(&new_entry->list); |
| 235 | kfree(new_entry); |
| 236 | return err; |
| 237 | } |
| 238 | |
| 239 | /* update the data structures with existing steering entry */ |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 240 | static int existing_steering_entry(struct mlx4_dev *dev, u8 port, |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 241 | enum mlx4_steer_type steer, |
| 242 | unsigned int index, u32 qpn) |
| 243 | { |
| 244 | struct mlx4_steer *s_steer; |
| 245 | struct mlx4_steer_index *tmp_entry, *entry = NULL; |
| 246 | struct mlx4_promisc_qp *pqp; |
| 247 | struct mlx4_promisc_qp *dqp; |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 248 | |
Matan Barak | 982290a | 2013-12-19 21:20:18 +0200 | [diff] [blame] | 249 | if (port < 1 || port > dev->caps.num_ports) |
| 250 | return -EINVAL; |
| 251 | |
Eugenia Emantayev | 4c41b36 | 2012-02-06 06:26:36 +0000 | [diff] [blame] | 252 | s_steer = &mlx4_priv(dev)->steer[port - 1]; |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 253 | |
Aviad Yehezkel | 60d31c1 | 2012-09-05 22:50:50 +0000 | [diff] [blame] | 254 | pqp = get_promisc_qp(dev, port, steer, qpn); |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 255 | if (!pqp) |
| 256 | return 0; /* nothing to do */ |
| 257 | |
| 258 | list_for_each_entry(tmp_entry, &s_steer->steer_entries[steer], list) { |
| 259 | if (tmp_entry->index == index) { |
| 260 | entry = tmp_entry; |
| 261 | break; |
| 262 | } |
| 263 | } |
| 264 | if (unlikely(!entry)) { |
| 265 | mlx4_warn(dev, "Steering entry at index %x is not registered\n", index); |
| 266 | return -EINVAL; |
| 267 | } |
| 268 | |
| 269 | /* the given qpn is listed as a promisc qpn |
| 270 | * we need to add it as a duplicate to this entry |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 271 | * for future references */ |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 272 | list_for_each_entry(dqp, &entry->duplicates, list) { |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 273 | if (qpn == pqp->qpn) |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 274 | return 0; /* qp is already duplicated */ |
| 275 | } |
| 276 | |
| 277 | /* add the qp as a duplicate on this index */ |
| 278 | dqp = kmalloc(sizeof *dqp, GFP_KERNEL); |
| 279 | if (!dqp) |
| 280 | return -ENOMEM; |
| 281 | dqp->qpn = qpn; |
| 282 | list_add_tail(&dqp->list, &entry->duplicates); |
| 283 | |
| 284 | return 0; |
| 285 | } |
| 286 | |
| 287 | /* Check whether a qpn is a duplicate on steering entry |
| 288 | * If so, it should not be removed from mgm */ |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 289 | static bool check_duplicate_entry(struct mlx4_dev *dev, u8 port, |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 290 | enum mlx4_steer_type steer, |
| 291 | unsigned int index, u32 qpn) |
| 292 | { |
| 293 | struct mlx4_steer *s_steer; |
| 294 | struct mlx4_steer_index *tmp_entry, *entry = NULL; |
| 295 | struct mlx4_promisc_qp *dqp, *tmp_dqp; |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 296 | |
Matan Barak | 982290a | 2013-12-19 21:20:18 +0200 | [diff] [blame] | 297 | if (port < 1 || port > dev->caps.num_ports) |
| 298 | return NULL; |
| 299 | |
Eugenia Emantayev | 4c41b36 | 2012-02-06 06:26:36 +0000 | [diff] [blame] | 300 | s_steer = &mlx4_priv(dev)->steer[port - 1]; |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 301 | |
| 302 | /* if qp is not promisc, it cannot be duplicated */ |
Aviad Yehezkel | 60d31c1 | 2012-09-05 22:50:50 +0000 | [diff] [blame] | 303 | if (!get_promisc_qp(dev, port, steer, qpn)) |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 304 | return false; |
| 305 | |
| 306 | /* The qp is promisc qp so it is a duplicate on this index |
| 307 | * Find the index entry, and remove the duplicate */ |
| 308 | list_for_each_entry(tmp_entry, &s_steer->steer_entries[steer], list) { |
| 309 | if (tmp_entry->index == index) { |
| 310 | entry = tmp_entry; |
| 311 | break; |
| 312 | } |
| 313 | } |
| 314 | if (unlikely(!entry)) { |
| 315 | mlx4_warn(dev, "Steering entry for index %x is not registered\n", index); |
| 316 | return false; |
| 317 | } |
| 318 | list_for_each_entry_safe(dqp, tmp_dqp, &entry->duplicates, list) { |
| 319 | if (dqp->qpn == qpn) { |
| 320 | list_del(&dqp->list); |
| 321 | kfree(dqp); |
| 322 | } |
| 323 | } |
| 324 | return true; |
| 325 | } |
| 326 | |
| 327 | /* I a steering entry contains only promisc QPs, it can be removed. */ |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 328 | static bool can_remove_steering_entry(struct mlx4_dev *dev, u8 port, |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 329 | enum mlx4_steer_type steer, |
| 330 | unsigned int index, u32 tqpn) |
| 331 | { |
| 332 | struct mlx4_steer *s_steer; |
| 333 | struct mlx4_cmd_mailbox *mailbox; |
| 334 | struct mlx4_mgm *mgm; |
| 335 | struct mlx4_steer_index *entry = NULL, *tmp_entry; |
| 336 | u32 qpn; |
| 337 | u32 members_count; |
| 338 | bool ret = false; |
| 339 | int i; |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 340 | |
Matan Barak | 982290a | 2013-12-19 21:20:18 +0200 | [diff] [blame] | 341 | if (port < 1 || port > dev->caps.num_ports) |
| 342 | return NULL; |
| 343 | |
Eugenia Emantayev | 4c41b36 | 2012-02-06 06:26:36 +0000 | [diff] [blame] | 344 | s_steer = &mlx4_priv(dev)->steer[port - 1]; |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 345 | |
| 346 | mailbox = mlx4_alloc_cmd_mailbox(dev); |
| 347 | if (IS_ERR(mailbox)) |
| 348 | return false; |
| 349 | mgm = mailbox->buf; |
| 350 | |
| 351 | if (mlx4_READ_ENTRY(dev, index, mailbox)) |
| 352 | goto out; |
| 353 | members_count = be32_to_cpu(mgm->members_count) & 0xffffff; |
| 354 | for (i = 0; i < members_count; i++) { |
| 355 | qpn = be32_to_cpu(mgm->qp[i]) & MGM_QPN_MASK; |
Aviad Yehezkel | 60d31c1 | 2012-09-05 22:50:50 +0000 | [diff] [blame] | 356 | if (!get_promisc_qp(dev, port, steer, qpn) && qpn != tqpn) { |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 357 | /* the qp is not promisc, the entry can't be removed */ |
| 358 | goto out; |
| 359 | } |
| 360 | } |
| 361 | /* All the qps currently registered for this entry are promiscuous, |
| 362 | * Checking for duplicates */ |
| 363 | ret = true; |
| 364 | list_for_each_entry_safe(entry, tmp_entry, &s_steer->steer_entries[steer], list) { |
| 365 | if (entry->index == index) { |
Yevgeny Petrilin | 0d7869a | 2014-07-16 11:57:47 +0300 | [diff] [blame] | 366 | if (list_empty(&entry->duplicates) || |
| 367 | members_count == 1) { |
| 368 | struct mlx4_promisc_qp *pqp, *tmp_pqp; |
| 369 | /* If there is only 1 entry in duplicates then |
| 370 | * this is the QP we want to delete, going over |
| 371 | * the list and deleting the entry. |
| 372 | */ |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 373 | list_del(&entry->list); |
Yevgeny Petrilin | 0d7869a | 2014-07-16 11:57:47 +0300 | [diff] [blame] | 374 | list_for_each_entry_safe(pqp, tmp_pqp, |
| 375 | &entry->duplicates, |
| 376 | list) { |
| 377 | list_del(&pqp->list); |
| 378 | kfree(pqp); |
| 379 | } |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 380 | kfree(entry); |
| 381 | } else { |
| 382 | /* This entry contains duplicates so it shouldn't be removed */ |
| 383 | ret = false; |
| 384 | goto out; |
| 385 | } |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | out: |
| 390 | mlx4_free_cmd_mailbox(dev, mailbox); |
| 391 | return ret; |
| 392 | } |
| 393 | |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 394 | static int add_promisc_qp(struct mlx4_dev *dev, u8 port, |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 395 | enum mlx4_steer_type steer, u32 qpn) |
| 396 | { |
| 397 | struct mlx4_steer *s_steer; |
| 398 | struct mlx4_cmd_mailbox *mailbox; |
| 399 | struct mlx4_mgm *mgm; |
| 400 | struct mlx4_steer_index *entry; |
| 401 | struct mlx4_promisc_qp *pqp; |
| 402 | struct mlx4_promisc_qp *dqp; |
| 403 | u32 members_count; |
| 404 | u32 prot; |
| 405 | int i; |
| 406 | bool found; |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 407 | int err; |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 408 | struct mlx4_priv *priv = mlx4_priv(dev); |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 409 | |
Matan Barak | 982290a | 2013-12-19 21:20:18 +0200 | [diff] [blame] | 410 | if (port < 1 || port > dev->caps.num_ports) |
| 411 | return -EINVAL; |
| 412 | |
Eugenia Emantayev | 4c41b36 | 2012-02-06 06:26:36 +0000 | [diff] [blame] | 413 | s_steer = &mlx4_priv(dev)->steer[port - 1]; |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 414 | |
| 415 | mutex_lock(&priv->mcg_table.mutex); |
| 416 | |
Aviad Yehezkel | 60d31c1 | 2012-09-05 22:50:50 +0000 | [diff] [blame] | 417 | if (get_promisc_qp(dev, port, steer, qpn)) { |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 418 | err = 0; /* Noting to do, already exists */ |
| 419 | goto out_mutex; |
| 420 | } |
| 421 | |
| 422 | pqp = kmalloc(sizeof *pqp, GFP_KERNEL); |
| 423 | if (!pqp) { |
| 424 | err = -ENOMEM; |
| 425 | goto out_mutex; |
| 426 | } |
| 427 | pqp->qpn = qpn; |
| 428 | |
| 429 | mailbox = mlx4_alloc_cmd_mailbox(dev); |
| 430 | if (IS_ERR(mailbox)) { |
| 431 | err = -ENOMEM; |
| 432 | goto out_alloc; |
| 433 | } |
| 434 | mgm = mailbox->buf; |
| 435 | |
Eugenia Emantayev | 816e598 | 2014-07-16 11:57:50 +0300 | [diff] [blame^] | 436 | if (!(mlx4_is_mfunc(dev) && steer == MLX4_UC_STEER)) { |
| 437 | /* The promisc QP needs to be added for each one of the steering |
| 438 | * entries. If it already exists, needs to be added as |
| 439 | * a duplicate for this entry. |
| 440 | */ |
| 441 | list_for_each_entry(entry, |
| 442 | &s_steer->steer_entries[steer], |
| 443 | list) { |
| 444 | err = mlx4_READ_ENTRY(dev, entry->index, mailbox); |
| 445 | if (err) |
| 446 | goto out_mailbox; |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 447 | |
Eugenia Emantayev | 816e598 | 2014-07-16 11:57:50 +0300 | [diff] [blame^] | 448 | members_count = be32_to_cpu(mgm->members_count) & |
| 449 | 0xffffff; |
| 450 | prot = be32_to_cpu(mgm->members_count) >> 30; |
| 451 | found = false; |
| 452 | for (i = 0; i < members_count; i++) { |
| 453 | if ((be32_to_cpu(mgm->qp[i]) & |
| 454 | MGM_QPN_MASK) == qpn) { |
| 455 | /* Entry already exists. |
| 456 | * Add to duplicates. |
| 457 | */ |
| 458 | dqp = kmalloc(sizeof(*dqp), GFP_KERNEL); |
| 459 | if (!dqp) { |
| 460 | err = -ENOMEM; |
| 461 | goto out_mailbox; |
| 462 | } |
| 463 | dqp->qpn = qpn; |
| 464 | list_add_tail(&dqp->list, |
| 465 | &entry->duplicates); |
| 466 | found = true; |
| 467 | } |
| 468 | } |
| 469 | if (!found) { |
| 470 | /* Need to add the qpn to mgm */ |
| 471 | if (members_count == |
| 472 | dev->caps.num_qp_per_mgm) { |
| 473 | /* entry is full */ |
Julia Lawall | 499b95f | 2012-08-14 02:58:34 +0000 | [diff] [blame] | 474 | err = -ENOMEM; |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 475 | goto out_mailbox; |
Julia Lawall | 499b95f | 2012-08-14 02:58:34 +0000 | [diff] [blame] | 476 | } |
Eugenia Emantayev | 816e598 | 2014-07-16 11:57:50 +0300 | [diff] [blame^] | 477 | mgm->qp[members_count++] = |
| 478 | cpu_to_be32(qpn & MGM_QPN_MASK); |
| 479 | mgm->members_count = |
| 480 | cpu_to_be32(members_count | |
| 481 | (prot << 30)); |
| 482 | err = mlx4_WRITE_ENTRY(dev, entry->index, |
| 483 | mailbox); |
| 484 | if (err) |
| 485 | goto out_mailbox; |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 486 | } |
| 487 | } |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | /* add the new qpn to list of promisc qps */ |
| 491 | list_add_tail(&pqp->list, &s_steer->promisc_qps[steer]); |
| 492 | /* now need to add all the promisc qps to default entry */ |
| 493 | memset(mgm, 0, sizeof *mgm); |
| 494 | members_count = 0; |
Alexander Guller | 7590837 | 2014-07-16 11:57:49 +0300 | [diff] [blame] | 495 | list_for_each_entry(dqp, &s_steer->promisc_qps[steer], list) { |
| 496 | if (members_count == dev->caps.num_qp_per_mgm) { |
| 497 | /* entry is full */ |
| 498 | err = -ENOMEM; |
| 499 | goto out_list; |
| 500 | } |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 501 | mgm->qp[members_count++] = cpu_to_be32(dqp->qpn & MGM_QPN_MASK); |
Alexander Guller | 7590837 | 2014-07-16 11:57:49 +0300 | [diff] [blame] | 502 | } |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 503 | mgm->members_count = cpu_to_be32(members_count | MLX4_PROT_ETH << 30); |
| 504 | |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 505 | err = mlx4_WRITE_PROMISC(dev, port, steer, mailbox); |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 506 | if (err) |
| 507 | goto out_list; |
| 508 | |
| 509 | mlx4_free_cmd_mailbox(dev, mailbox); |
| 510 | mutex_unlock(&priv->mcg_table.mutex); |
| 511 | return 0; |
| 512 | |
| 513 | out_list: |
| 514 | list_del(&pqp->list); |
| 515 | out_mailbox: |
| 516 | mlx4_free_cmd_mailbox(dev, mailbox); |
| 517 | out_alloc: |
| 518 | kfree(pqp); |
| 519 | out_mutex: |
| 520 | mutex_unlock(&priv->mcg_table.mutex); |
| 521 | return err; |
| 522 | } |
| 523 | |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 524 | static int remove_promisc_qp(struct mlx4_dev *dev, u8 port, |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 525 | enum mlx4_steer_type steer, u32 qpn) |
| 526 | { |
| 527 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 528 | struct mlx4_steer *s_steer; |
| 529 | struct mlx4_cmd_mailbox *mailbox; |
| 530 | struct mlx4_mgm *mgm; |
| 531 | struct mlx4_steer_index *entry; |
| 532 | struct mlx4_promisc_qp *pqp; |
| 533 | struct mlx4_promisc_qp *dqp; |
| 534 | u32 members_count; |
| 535 | bool found; |
| 536 | bool back_to_list = false; |
Dotan Barak | aab2bb0 | 2014-07-16 11:57:48 +0300 | [diff] [blame] | 537 | int i; |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 538 | int err; |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 539 | |
Matan Barak | 982290a | 2013-12-19 21:20:18 +0200 | [diff] [blame] | 540 | if (port < 1 || port > dev->caps.num_ports) |
| 541 | return -EINVAL; |
| 542 | |
Eugenia Emantayev | 4c41b36 | 2012-02-06 06:26:36 +0000 | [diff] [blame] | 543 | s_steer = &mlx4_priv(dev)->steer[port - 1]; |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 544 | mutex_lock(&priv->mcg_table.mutex); |
| 545 | |
Aviad Yehezkel | 60d31c1 | 2012-09-05 22:50:50 +0000 | [diff] [blame] | 546 | pqp = get_promisc_qp(dev, port, steer, qpn); |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 547 | if (unlikely(!pqp)) { |
| 548 | mlx4_warn(dev, "QP %x is not promiscuous QP\n", qpn); |
| 549 | /* nothing to do */ |
| 550 | err = 0; |
| 551 | goto out_mutex; |
| 552 | } |
| 553 | |
| 554 | /*remove from list of promisc qps */ |
| 555 | list_del(&pqp->list); |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 556 | |
| 557 | /* set the default entry not to include the removed one */ |
| 558 | mailbox = mlx4_alloc_cmd_mailbox(dev); |
| 559 | if (IS_ERR(mailbox)) { |
| 560 | err = -ENOMEM; |
| 561 | back_to_list = true; |
| 562 | goto out_list; |
| 563 | } |
| 564 | mgm = mailbox->buf; |
| 565 | members_count = 0; |
| 566 | list_for_each_entry(dqp, &s_steer->promisc_qps[steer], list) |
| 567 | mgm->qp[members_count++] = cpu_to_be32(dqp->qpn & MGM_QPN_MASK); |
| 568 | mgm->members_count = cpu_to_be32(members_count | MLX4_PROT_ETH << 30); |
| 569 | |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 570 | err = mlx4_WRITE_PROMISC(dev, port, steer, mailbox); |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 571 | if (err) |
| 572 | goto out_mailbox; |
| 573 | |
Eugenia Emantayev | 816e598 | 2014-07-16 11:57:50 +0300 | [diff] [blame^] | 574 | if (!(mlx4_is_mfunc(dev) && steer == MLX4_UC_STEER)) { |
| 575 | /* remove the qp from all the steering entries*/ |
| 576 | list_for_each_entry(entry, |
| 577 | &s_steer->steer_entries[steer], |
| 578 | list) { |
| 579 | found = false; |
| 580 | list_for_each_entry(dqp, &entry->duplicates, list) { |
| 581 | if (dqp->qpn == qpn) { |
| 582 | found = true; |
Dotan Barak | aab2bb0 | 2014-07-16 11:57:48 +0300 | [diff] [blame] | 583 | break; |
| 584 | } |
Dotan Barak | aab2bb0 | 2014-07-16 11:57:48 +0300 | [diff] [blame] | 585 | } |
Eugenia Emantayev | 816e598 | 2014-07-16 11:57:50 +0300 | [diff] [blame^] | 586 | if (found) { |
| 587 | /* A duplicate, no need to change the MGM, |
| 588 | * only update the duplicates list |
| 589 | */ |
| 590 | list_del(&dqp->list); |
| 591 | kfree(dqp); |
| 592 | } else { |
| 593 | int loc = -1; |
Dotan Barak | aab2bb0 | 2014-07-16 11:57:48 +0300 | [diff] [blame] | 594 | |
Eugenia Emantayev | 816e598 | 2014-07-16 11:57:50 +0300 | [diff] [blame^] | 595 | err = mlx4_READ_ENTRY(dev, |
| 596 | entry->index, |
| 597 | mailbox); |
| 598 | if (err) |
| 599 | goto out_mailbox; |
| 600 | members_count = |
| 601 | be32_to_cpu(mgm->members_count) & |
| 602 | 0xffffff; |
| 603 | for (i = 0; i < members_count; ++i) |
| 604 | if ((be32_to_cpu(mgm->qp[i]) & |
| 605 | MGM_QPN_MASK) == qpn) { |
| 606 | loc = i; |
| 607 | break; |
| 608 | } |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 609 | |
Eugenia Emantayev | 816e598 | 2014-07-16 11:57:50 +0300 | [diff] [blame^] | 610 | if (loc < 0) { |
| 611 | mlx4_err(dev, "QP %06x wasn't found in entry %d\n", |
| 612 | qpn, entry->index); |
| 613 | err = -EINVAL; |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 614 | goto out_mailbox; |
Eugenia Emantayev | 816e598 | 2014-07-16 11:57:50 +0300 | [diff] [blame^] | 615 | } |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 616 | |
Eugenia Emantayev | 816e598 | 2014-07-16 11:57:50 +0300 | [diff] [blame^] | 617 | /* copy the last QP in this MGM |
| 618 | * over removed QP |
| 619 | */ |
| 620 | mgm->qp[loc] = mgm->qp[members_count - 1]; |
| 621 | mgm->qp[members_count - 1] = 0; |
| 622 | mgm->members_count = |
| 623 | cpu_to_be32(--members_count | |
| 624 | (MLX4_PROT_ETH << 30)); |
| 625 | |
| 626 | err = mlx4_WRITE_ENTRY(dev, |
| 627 | entry->index, |
| 628 | mailbox); |
| 629 | if (err) |
| 630 | goto out_mailbox; |
| 631 | } |
| 632 | } |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | out_mailbox: |
| 636 | mlx4_free_cmd_mailbox(dev, mailbox); |
| 637 | out_list: |
| 638 | if (back_to_list) |
| 639 | list_add_tail(&pqp->list, &s_steer->promisc_qps[steer]); |
Yevgeny Petrilin | 5302009 | 2011-03-30 23:28:52 +0000 | [diff] [blame] | 640 | else |
| 641 | kfree(pqp); |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 642 | out_mutex: |
| 643 | mutex_unlock(&priv->mcg_table.mutex); |
| 644 | return err; |
| 645 | } |
| 646 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 647 | /* |
| 648 | * Caller must hold MCG table semaphore. gid and mgm parameters must |
| 649 | * be properly aligned for command interface. |
| 650 | * |
| 651 | * Returns 0 unless a firmware command error occurs. |
| 652 | * |
| 653 | * If GID is found in MGM or MGM is empty, *index = *hash, *prev = -1 |
| 654 | * and *mgm holds MGM entry. |
| 655 | * |
| 656 | * if GID is found in AMGM, *index = index in AMGM, *prev = index of |
| 657 | * previous entry in hash chain and *mgm holds AMGM entry. |
| 658 | * |
| 659 | * If no AMGM exists for given gid, *index = -1, *prev = index of last |
| 660 | * entry in hash chain and *mgm holds end of hash chain. |
| 661 | */ |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 662 | static int find_entry(struct mlx4_dev *dev, u8 port, |
| 663 | u8 *gid, enum mlx4_protocol prot, |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 664 | struct mlx4_cmd_mailbox *mgm_mailbox, |
Eugenia Emantayev | deb8b3e | 2012-02-14 06:37:46 +0000 | [diff] [blame] | 665 | int *prev, int *index) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 666 | { |
| 667 | struct mlx4_cmd_mailbox *mailbox; |
| 668 | struct mlx4_mgm *mgm = mgm_mailbox->buf; |
| 669 | u8 *mgid; |
| 670 | int err; |
Eugenia Emantayev | deb8b3e | 2012-02-14 06:37:46 +0000 | [diff] [blame] | 671 | u16 hash; |
Or Gerlitz | ccf8632 | 2011-07-07 19:19:29 +0000 | [diff] [blame] | 672 | u8 op_mod = (prot == MLX4_PROT_ETH) ? |
| 673 | !!(dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_MC_STEER) : 0; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 674 | |
| 675 | mailbox = mlx4_alloc_cmd_mailbox(dev); |
| 676 | if (IS_ERR(mailbox)) |
| 677 | return -ENOMEM; |
| 678 | mgid = mailbox->buf; |
| 679 | |
| 680 | memcpy(mgid, gid, 16); |
| 681 | |
Eugenia Emantayev | deb8b3e | 2012-02-14 06:37:46 +0000 | [diff] [blame] | 682 | err = mlx4_GID_HASH(dev, mailbox, &hash, op_mod); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 683 | mlx4_free_cmd_mailbox(dev, mailbox); |
| 684 | if (err) |
| 685 | return err; |
| 686 | |
| 687 | if (0) |
Eugenia Emantayev | deb8b3e | 2012-02-14 06:37:46 +0000 | [diff] [blame] | 688 | mlx4_dbg(dev, "Hash for %pI6 is %04x\n", gid, hash); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 689 | |
Eugenia Emantayev | deb8b3e | 2012-02-14 06:37:46 +0000 | [diff] [blame] | 690 | *index = hash; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 691 | *prev = -1; |
| 692 | |
| 693 | do { |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 694 | err = mlx4_READ_ENTRY(dev, *index, mgm_mailbox); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 695 | if (err) |
| 696 | return err; |
| 697 | |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 698 | if (!(be32_to_cpu(mgm->members_count) & 0xffffff)) { |
Eugenia Emantayev | deb8b3e | 2012-02-14 06:37:46 +0000 | [diff] [blame] | 699 | if (*index != hash) { |
Joe Perches | 1a91de2 | 2014-05-07 12:52:57 -0700 | [diff] [blame] | 700 | mlx4_err(dev, "Found zero MGID in AMGM\n"); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 701 | err = -EINVAL; |
| 702 | } |
| 703 | return err; |
| 704 | } |
| 705 | |
Aleksey Senin | da995a8 | 2010-12-02 11:44:49 +0000 | [diff] [blame] | 706 | if (!memcmp(mgm->gid, gid, 16) && |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 707 | be32_to_cpu(mgm->members_count) >> 30 == prot) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 708 | return err; |
| 709 | |
| 710 | *prev = *index; |
| 711 | *index = be32_to_cpu(mgm->next_gid_index) >> 6; |
| 712 | } while (*index); |
| 713 | |
| 714 | *index = -1; |
| 715 | return err; |
| 716 | } |
| 717 | |
Hadar Hen Zion | c2c19dc | 2013-04-24 13:58:48 +0000 | [diff] [blame] | 718 | static const u8 __promisc_mode[] = { |
| 719 | [MLX4_FS_REGULAR] = 0x0, |
| 720 | [MLX4_FS_ALL_DEFAULT] = 0x1, |
| 721 | [MLX4_FS_MC_DEFAULT] = 0x3, |
| 722 | [MLX4_FS_UC_SNIFFER] = 0x4, |
| 723 | [MLX4_FS_MC_SNIFFER] = 0x5, |
| 724 | }; |
| 725 | |
| 726 | int mlx4_map_sw_to_hw_steering_mode(struct mlx4_dev *dev, |
| 727 | enum mlx4_net_trans_promisc_mode flow_type) |
| 728 | { |
Or Gerlitz | fe66bb2 | 2013-10-15 16:55:21 +0200 | [diff] [blame] | 729 | if (flow_type >= MLX4_FS_MODE_NUM) { |
Hadar Hen Zion | c2c19dc | 2013-04-24 13:58:48 +0000 | [diff] [blame] | 730 | mlx4_err(dev, "Invalid flow type. type = %d\n", flow_type); |
| 731 | return -EINVAL; |
| 732 | } |
| 733 | return __promisc_mode[flow_type]; |
| 734 | } |
| 735 | EXPORT_SYMBOL_GPL(mlx4_map_sw_to_hw_steering_mode); |
| 736 | |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 737 | static void trans_rule_ctrl_to_hw(struct mlx4_net_trans_rule *ctrl, |
| 738 | struct mlx4_net_trans_rule_hw_ctrl *hw) |
| 739 | { |
Hadar Hen Zion | bcf3729 | 2013-04-24 13:58:47 +0000 | [diff] [blame] | 740 | u8 flags = 0; |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 741 | |
Hadar Hen Zion | bcf3729 | 2013-04-24 13:58:47 +0000 | [diff] [blame] | 742 | flags = ctrl->queue_mode == MLX4_NET_TRANS_Q_LIFO ? 1 : 0; |
| 743 | flags |= ctrl->exclusive ? (1 << 2) : 0; |
| 744 | flags |= ctrl->allow_loopback ? (1 << 3) : 0; |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 745 | |
Hadar Hen Zion | bcf3729 | 2013-04-24 13:58:47 +0000 | [diff] [blame] | 746 | hw->flags = flags; |
| 747 | hw->type = __promisc_mode[ctrl->promisc_mode]; |
| 748 | hw->prio = cpu_to_be16(ctrl->priority); |
Hadar Hen Zion | 015465f | 2013-01-30 23:07:02 +0000 | [diff] [blame] | 749 | hw->port = ctrl->port; |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 750 | hw->qpn = cpu_to_be32(ctrl->qpn); |
| 751 | } |
| 752 | |
Hadar Hen Zion | a8edc3b | 2012-09-05 22:50:48 +0000 | [diff] [blame] | 753 | const u16 __sw_id_hw[] = { |
| 754 | [MLX4_NET_TRANS_RULE_ID_ETH] = 0xE001, |
| 755 | [MLX4_NET_TRANS_RULE_ID_IB] = 0xE005, |
| 756 | [MLX4_NET_TRANS_RULE_ID_IPV6] = 0xE003, |
| 757 | [MLX4_NET_TRANS_RULE_ID_IPV4] = 0xE002, |
| 758 | [MLX4_NET_TRANS_RULE_ID_TCP] = 0xE004, |
Or Gerlitz | 7ffdf72 | 2013-12-23 16:09:43 +0200 | [diff] [blame] | 759 | [MLX4_NET_TRANS_RULE_ID_UDP] = 0xE006, |
| 760 | [MLX4_NET_TRANS_RULE_ID_VXLAN] = 0xE008 |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 761 | }; |
| 762 | |
Hadar Hen Zion | c2c19dc | 2013-04-24 13:58:48 +0000 | [diff] [blame] | 763 | int mlx4_map_sw_to_hw_steering_id(struct mlx4_dev *dev, |
| 764 | enum mlx4_net_trans_rule_id id) |
| 765 | { |
Or Gerlitz | fe66bb2 | 2013-10-15 16:55:21 +0200 | [diff] [blame] | 766 | if (id >= MLX4_NET_TRANS_RULE_NUM) { |
Hadar Hen Zion | c2c19dc | 2013-04-24 13:58:48 +0000 | [diff] [blame] | 767 | mlx4_err(dev, "Invalid network rule id. id = %d\n", id); |
| 768 | return -EINVAL; |
| 769 | } |
| 770 | return __sw_id_hw[id]; |
| 771 | } |
| 772 | EXPORT_SYMBOL_GPL(mlx4_map_sw_to_hw_steering_id); |
| 773 | |
| 774 | static const int __rule_hw_sz[] = { |
| 775 | [MLX4_NET_TRANS_RULE_ID_ETH] = |
| 776 | sizeof(struct mlx4_net_trans_rule_hw_eth), |
| 777 | [MLX4_NET_TRANS_RULE_ID_IB] = |
| 778 | sizeof(struct mlx4_net_trans_rule_hw_ib), |
| 779 | [MLX4_NET_TRANS_RULE_ID_IPV6] = 0, |
| 780 | [MLX4_NET_TRANS_RULE_ID_IPV4] = |
| 781 | sizeof(struct mlx4_net_trans_rule_hw_ipv4), |
| 782 | [MLX4_NET_TRANS_RULE_ID_TCP] = |
| 783 | sizeof(struct mlx4_net_trans_rule_hw_tcp_udp), |
| 784 | [MLX4_NET_TRANS_RULE_ID_UDP] = |
Or Gerlitz | 7ffdf72 | 2013-12-23 16:09:43 +0200 | [diff] [blame] | 785 | sizeof(struct mlx4_net_trans_rule_hw_tcp_udp), |
| 786 | [MLX4_NET_TRANS_RULE_ID_VXLAN] = |
| 787 | sizeof(struct mlx4_net_trans_rule_hw_vxlan) |
Hadar Hen Zion | c2c19dc | 2013-04-24 13:58:48 +0000 | [diff] [blame] | 788 | }; |
| 789 | |
| 790 | int mlx4_hw_rule_sz(struct mlx4_dev *dev, |
| 791 | enum mlx4_net_trans_rule_id id) |
| 792 | { |
Or Gerlitz | fe66bb2 | 2013-10-15 16:55:21 +0200 | [diff] [blame] | 793 | if (id >= MLX4_NET_TRANS_RULE_NUM) { |
Hadar Hen Zion | c2c19dc | 2013-04-24 13:58:48 +0000 | [diff] [blame] | 794 | mlx4_err(dev, "Invalid network rule id. id = %d\n", id); |
| 795 | return -EINVAL; |
| 796 | } |
| 797 | |
| 798 | return __rule_hw_sz[id]; |
| 799 | } |
| 800 | EXPORT_SYMBOL_GPL(mlx4_hw_rule_sz); |
| 801 | |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 802 | static int parse_trans_rule(struct mlx4_dev *dev, struct mlx4_spec_list *spec, |
| 803 | struct _rule_hw *rule_hw) |
| 804 | { |
Hadar Hen Zion | c2c19dc | 2013-04-24 13:58:48 +0000 | [diff] [blame] | 805 | if (mlx4_hw_rule_sz(dev, spec->id) < 0) |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 806 | return -EINVAL; |
Hadar Hen Zion | c2c19dc | 2013-04-24 13:58:48 +0000 | [diff] [blame] | 807 | memset(rule_hw, 0, mlx4_hw_rule_sz(dev, spec->id)); |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 808 | rule_hw->id = cpu_to_be16(__sw_id_hw[spec->id]); |
Hadar Hen Zion | c2c19dc | 2013-04-24 13:58:48 +0000 | [diff] [blame] | 809 | rule_hw->size = mlx4_hw_rule_sz(dev, spec->id) >> 2; |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 810 | |
| 811 | switch (spec->id) { |
| 812 | case MLX4_NET_TRANS_RULE_ID_ETH: |
| 813 | memcpy(rule_hw->eth.dst_mac, spec->eth.dst_mac, ETH_ALEN); |
| 814 | memcpy(rule_hw->eth.dst_mac_msk, spec->eth.dst_mac_msk, |
| 815 | ETH_ALEN); |
| 816 | memcpy(rule_hw->eth.src_mac, spec->eth.src_mac, ETH_ALEN); |
| 817 | memcpy(rule_hw->eth.src_mac_msk, spec->eth.src_mac_msk, |
| 818 | ETH_ALEN); |
| 819 | if (spec->eth.ether_type_enable) { |
| 820 | rule_hw->eth.ether_type_enable = 1; |
| 821 | rule_hw->eth.ether_type = spec->eth.ether_type; |
| 822 | } |
Hadar Hen Zion | ba60a35 | 2013-04-24 13:58:46 +0000 | [diff] [blame] | 823 | rule_hw->eth.vlan_tag = spec->eth.vlan_id; |
| 824 | rule_hw->eth.vlan_tag_msk = spec->eth.vlan_id_msk; |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 825 | break; |
| 826 | |
| 827 | case MLX4_NET_TRANS_RULE_ID_IB: |
Hadar Hen Zion | ba60a35 | 2013-04-24 13:58:46 +0000 | [diff] [blame] | 828 | rule_hw->ib.l3_qpn = spec->ib.l3_qpn; |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 829 | rule_hw->ib.qpn_mask = spec->ib.qpn_msk; |
| 830 | memcpy(&rule_hw->ib.dst_gid, &spec->ib.dst_gid, 16); |
| 831 | memcpy(&rule_hw->ib.dst_gid_msk, &spec->ib.dst_gid_msk, 16); |
| 832 | break; |
| 833 | |
| 834 | case MLX4_NET_TRANS_RULE_ID_IPV6: |
| 835 | return -EOPNOTSUPP; |
| 836 | |
| 837 | case MLX4_NET_TRANS_RULE_ID_IPV4: |
| 838 | rule_hw->ipv4.src_ip = spec->ipv4.src_ip; |
| 839 | rule_hw->ipv4.src_ip_msk = spec->ipv4.src_ip_msk; |
| 840 | rule_hw->ipv4.dst_ip = spec->ipv4.dst_ip; |
| 841 | rule_hw->ipv4.dst_ip_msk = spec->ipv4.dst_ip_msk; |
| 842 | break; |
| 843 | |
| 844 | case MLX4_NET_TRANS_RULE_ID_TCP: |
| 845 | case MLX4_NET_TRANS_RULE_ID_UDP: |
| 846 | rule_hw->tcp_udp.dst_port = spec->tcp_udp.dst_port; |
| 847 | rule_hw->tcp_udp.dst_port_msk = spec->tcp_udp.dst_port_msk; |
| 848 | rule_hw->tcp_udp.src_port = spec->tcp_udp.src_port; |
| 849 | rule_hw->tcp_udp.src_port_msk = spec->tcp_udp.src_port_msk; |
| 850 | break; |
| 851 | |
Or Gerlitz | 7ffdf72 | 2013-12-23 16:09:43 +0200 | [diff] [blame] | 852 | case MLX4_NET_TRANS_RULE_ID_VXLAN: |
| 853 | rule_hw->vxlan.vni = |
| 854 | cpu_to_be32(be32_to_cpu(spec->vxlan.vni) << 8); |
| 855 | rule_hw->vxlan.vni_mask = |
| 856 | cpu_to_be32(be32_to_cpu(spec->vxlan.vni_mask) << 8); |
| 857 | break; |
| 858 | |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 859 | default: |
| 860 | return -EINVAL; |
| 861 | } |
| 862 | |
| 863 | return __rule_hw_sz[spec->id]; |
| 864 | } |
| 865 | |
| 866 | static void mlx4_err_rule(struct mlx4_dev *dev, char *str, |
| 867 | struct mlx4_net_trans_rule *rule) |
| 868 | { |
| 869 | #define BUF_SIZE 256 |
| 870 | struct mlx4_spec_list *cur; |
| 871 | char buf[BUF_SIZE]; |
| 872 | int len = 0; |
| 873 | |
| 874 | mlx4_err(dev, "%s", str); |
| 875 | len += snprintf(buf + len, BUF_SIZE - len, |
| 876 | "port = %d prio = 0x%x qp = 0x%x ", |
| 877 | rule->port, rule->priority, rule->qpn); |
| 878 | |
| 879 | list_for_each_entry(cur, &rule->list, list) { |
| 880 | switch (cur->id) { |
| 881 | case MLX4_NET_TRANS_RULE_ID_ETH: |
| 882 | len += snprintf(buf + len, BUF_SIZE - len, |
| 883 | "dmac = %pM ", &cur->eth.dst_mac); |
| 884 | if (cur->eth.ether_type) |
| 885 | len += snprintf(buf + len, BUF_SIZE - len, |
| 886 | "ethertype = 0x%x ", |
| 887 | be16_to_cpu(cur->eth.ether_type)); |
| 888 | if (cur->eth.vlan_id) |
| 889 | len += snprintf(buf + len, BUF_SIZE - len, |
| 890 | "vlan-id = %d ", |
| 891 | be16_to_cpu(cur->eth.vlan_id)); |
| 892 | break; |
| 893 | |
| 894 | case MLX4_NET_TRANS_RULE_ID_IPV4: |
| 895 | if (cur->ipv4.src_ip) |
| 896 | len += snprintf(buf + len, BUF_SIZE - len, |
| 897 | "src-ip = %pI4 ", |
| 898 | &cur->ipv4.src_ip); |
| 899 | if (cur->ipv4.dst_ip) |
| 900 | len += snprintf(buf + len, BUF_SIZE - len, |
| 901 | "dst-ip = %pI4 ", |
| 902 | &cur->ipv4.dst_ip); |
| 903 | break; |
| 904 | |
| 905 | case MLX4_NET_TRANS_RULE_ID_TCP: |
| 906 | case MLX4_NET_TRANS_RULE_ID_UDP: |
| 907 | if (cur->tcp_udp.src_port) |
| 908 | len += snprintf(buf + len, BUF_SIZE - len, |
| 909 | "src-port = %d ", |
| 910 | be16_to_cpu(cur->tcp_udp.src_port)); |
| 911 | if (cur->tcp_udp.dst_port) |
| 912 | len += snprintf(buf + len, BUF_SIZE - len, |
| 913 | "dst-port = %d ", |
| 914 | be16_to_cpu(cur->tcp_udp.dst_port)); |
| 915 | break; |
| 916 | |
| 917 | case MLX4_NET_TRANS_RULE_ID_IB: |
| 918 | len += snprintf(buf + len, BUF_SIZE - len, |
| 919 | "dst-gid = %pI6\n", cur->ib.dst_gid); |
| 920 | len += snprintf(buf + len, BUF_SIZE - len, |
| 921 | "dst-gid-mask = %pI6\n", |
| 922 | cur->ib.dst_gid_msk); |
| 923 | break; |
| 924 | |
| 925 | case MLX4_NET_TRANS_RULE_ID_IPV6: |
| 926 | break; |
| 927 | |
| 928 | default: |
| 929 | break; |
| 930 | } |
| 931 | } |
| 932 | len += snprintf(buf + len, BUF_SIZE - len, "\n"); |
| 933 | mlx4_err(dev, "%s", buf); |
| 934 | |
| 935 | if (len >= BUF_SIZE) |
Joe Perches | 1a91de2 | 2014-05-07 12:52:57 -0700 | [diff] [blame] | 936 | mlx4_err(dev, "Network rule error message was truncated, print buffer is too small\n"); |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | int mlx4_flow_attach(struct mlx4_dev *dev, |
| 940 | struct mlx4_net_trans_rule *rule, u64 *reg_id) |
| 941 | { |
| 942 | struct mlx4_cmd_mailbox *mailbox; |
| 943 | struct mlx4_spec_list *cur; |
| 944 | u32 size = 0; |
| 945 | int ret; |
| 946 | |
| 947 | mailbox = mlx4_alloc_cmd_mailbox(dev); |
| 948 | if (IS_ERR(mailbox)) |
| 949 | return PTR_ERR(mailbox); |
| 950 | |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 951 | trans_rule_ctrl_to_hw(rule, mailbox->buf); |
| 952 | |
| 953 | size += sizeof(struct mlx4_net_trans_rule_hw_ctrl); |
| 954 | |
| 955 | list_for_each_entry(cur, &rule->list, list) { |
| 956 | ret = parse_trans_rule(dev, cur, mailbox->buf + size); |
| 957 | if (ret < 0) { |
| 958 | mlx4_free_cmd_mailbox(dev, mailbox); |
Eyal Perry | 7572038 | 2014-05-14 12:15:17 +0300 | [diff] [blame] | 959 | return ret; |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 960 | } |
| 961 | size += ret; |
| 962 | } |
| 963 | |
| 964 | ret = mlx4_QP_FLOW_STEERING_ATTACH(dev, mailbox, size >> 2, reg_id); |
| 965 | if (ret == -ENOMEM) |
| 966 | mlx4_err_rule(dev, |
Joe Perches | 1a91de2 | 2014-05-07 12:52:57 -0700 | [diff] [blame] | 967 | "mcg table is full. Fail to register network rule\n", |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 968 | rule); |
| 969 | else if (ret) |
Joe Perches | 1a91de2 | 2014-05-07 12:52:57 -0700 | [diff] [blame] | 970 | mlx4_err_rule(dev, "Fail to register network rule\n", rule); |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 971 | |
| 972 | mlx4_free_cmd_mailbox(dev, mailbox); |
| 973 | |
| 974 | return ret; |
| 975 | } |
| 976 | EXPORT_SYMBOL_GPL(mlx4_flow_attach); |
| 977 | |
| 978 | int mlx4_flow_detach(struct mlx4_dev *dev, u64 reg_id) |
| 979 | { |
| 980 | int err; |
| 981 | |
| 982 | err = mlx4_QP_FLOW_STEERING_DETACH(dev, reg_id); |
| 983 | if (err) |
| 984 | mlx4_err(dev, "Fail to detach network rule. registration id = 0x%llx\n", |
| 985 | reg_id); |
| 986 | return err; |
| 987 | } |
| 988 | EXPORT_SYMBOL_GPL(mlx4_flow_detach); |
| 989 | |
Matan Barak | 4de6580 | 2013-11-07 15:25:14 +0200 | [diff] [blame] | 990 | int mlx4_FLOW_STEERING_IB_UC_QP_RANGE(struct mlx4_dev *dev, u32 min_range_qpn, |
| 991 | u32 max_range_qpn) |
| 992 | { |
| 993 | int err; |
| 994 | u64 in_param; |
| 995 | |
| 996 | in_param = ((u64) min_range_qpn) << 32; |
| 997 | in_param |= ((u64) max_range_qpn) & 0xFFFFFFFF; |
| 998 | |
| 999 | err = mlx4_cmd(dev, in_param, 0, 0, |
| 1000 | MLX4_FLOW_STEERING_IB_UC_QP_RANGE, |
| 1001 | MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE); |
| 1002 | |
| 1003 | return err; |
| 1004 | } |
| 1005 | EXPORT_SYMBOL_GPL(mlx4_FLOW_STEERING_IB_UC_QP_RANGE); |
| 1006 | |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 1007 | int mlx4_qp_attach_common(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16], |
| 1008 | int block_mcast_loopback, enum mlx4_protocol prot, |
| 1009 | enum mlx4_steer_type steer) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1010 | { |
| 1011 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 1012 | struct mlx4_cmd_mailbox *mailbox; |
| 1013 | struct mlx4_mgm *mgm; |
| 1014 | u32 members_count; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1015 | int index, prev; |
| 1016 | int link = 0; |
| 1017 | int i; |
| 1018 | int err; |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 1019 | u8 port = gid[5]; |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 1020 | u8 new_entry = 0; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1021 | |
| 1022 | mailbox = mlx4_alloc_cmd_mailbox(dev); |
| 1023 | if (IS_ERR(mailbox)) |
| 1024 | return PTR_ERR(mailbox); |
| 1025 | mgm = mailbox->buf; |
| 1026 | |
| 1027 | mutex_lock(&priv->mcg_table.mutex); |
Eugenia Emantayev | deb8b3e | 2012-02-14 06:37:46 +0000 | [diff] [blame] | 1028 | err = find_entry(dev, port, gid, prot, |
| 1029 | mailbox, &prev, &index); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1030 | if (err) |
| 1031 | goto out; |
| 1032 | |
| 1033 | if (index != -1) { |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 1034 | if (!(be32_to_cpu(mgm->members_count) & 0xffffff)) { |
| 1035 | new_entry = 1; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1036 | memcpy(mgm->gid, gid, 16); |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 1037 | } |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1038 | } else { |
| 1039 | link = 1; |
| 1040 | |
| 1041 | index = mlx4_bitmap_alloc(&priv->mcg_table.bitmap); |
| 1042 | if (index == -1) { |
| 1043 | mlx4_err(dev, "No AMGM entries left\n"); |
| 1044 | err = -ENOMEM; |
| 1045 | goto out; |
| 1046 | } |
| 1047 | index += dev->caps.num_mgms; |
| 1048 | |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 1049 | new_entry = 1; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1050 | memset(mgm, 0, sizeof *mgm); |
| 1051 | memcpy(mgm->gid, gid, 16); |
| 1052 | } |
| 1053 | |
Aleksey Senin | da995a8 | 2010-12-02 11:44:49 +0000 | [diff] [blame] | 1054 | members_count = be32_to_cpu(mgm->members_count) & 0xffffff; |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 1055 | if (members_count == dev->caps.num_qp_per_mgm) { |
Joe Perches | 1a91de2 | 2014-05-07 12:52:57 -0700 | [diff] [blame] | 1056 | mlx4_err(dev, "MGM at index %x is full\n", index); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1057 | err = -ENOMEM; |
| 1058 | goto out; |
| 1059 | } |
| 1060 | |
| 1061 | for (i = 0; i < members_count; ++i) |
Ron Livne | 521e575 | 2008-07-14 23:48:48 -0700 | [diff] [blame] | 1062 | if ((be32_to_cpu(mgm->qp[i]) & MGM_QPN_MASK) == qp->qpn) { |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1063 | mlx4_dbg(dev, "QP %06x already a member of MGM\n", qp->qpn); |
| 1064 | err = 0; |
| 1065 | goto out; |
| 1066 | } |
| 1067 | |
Ron Livne | 521e575 | 2008-07-14 23:48:48 -0700 | [diff] [blame] | 1068 | if (block_mcast_loopback) |
| 1069 | mgm->qp[members_count++] = cpu_to_be32((qp->qpn & MGM_QPN_MASK) | |
Ingo Molnar | e6a1762 | 2008-11-25 16:57:59 -0800 | [diff] [blame] | 1070 | (1U << MGM_BLCK_LB_BIT)); |
Ron Livne | 521e575 | 2008-07-14 23:48:48 -0700 | [diff] [blame] | 1071 | else |
| 1072 | mgm->qp[members_count++] = cpu_to_be32(qp->qpn & MGM_QPN_MASK); |
| 1073 | |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 1074 | mgm->members_count = cpu_to_be32(members_count | (u32) prot << 30); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1075 | |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 1076 | err = mlx4_WRITE_ENTRY(dev, index, mailbox); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1077 | if (err) |
| 1078 | goto out; |
| 1079 | |
| 1080 | if (!link) |
| 1081 | goto out; |
| 1082 | |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 1083 | err = mlx4_READ_ENTRY(dev, prev, mailbox); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1084 | if (err) |
| 1085 | goto out; |
| 1086 | |
| 1087 | mgm->next_gid_index = cpu_to_be32(index << 6); |
| 1088 | |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 1089 | err = mlx4_WRITE_ENTRY(dev, prev, mailbox); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1090 | if (err) |
| 1091 | goto out; |
| 1092 | |
| 1093 | out: |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 1094 | if (prot == MLX4_PROT_ETH) { |
| 1095 | /* manage the steering entry for promisc mode */ |
| 1096 | if (new_entry) |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 1097 | new_steering_entry(dev, port, steer, index, qp->qpn); |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 1098 | else |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 1099 | existing_steering_entry(dev, port, steer, |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 1100 | index, qp->qpn); |
| 1101 | } |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1102 | if (err && link && index != -1) { |
| 1103 | if (index < dev->caps.num_mgms) |
Joe Perches | 1a91de2 | 2014-05-07 12:52:57 -0700 | [diff] [blame] | 1104 | mlx4_warn(dev, "Got AMGM index %d < %d\n", |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1105 | index, dev->caps.num_mgms); |
| 1106 | else |
| 1107 | mlx4_bitmap_free(&priv->mcg_table.bitmap, |
Jack Morgenstein | 7c6d74d | 2013-12-08 16:50:17 +0200 | [diff] [blame] | 1108 | index - dev->caps.num_mgms, MLX4_USE_RR); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1109 | } |
| 1110 | mutex_unlock(&priv->mcg_table.mutex); |
| 1111 | |
| 1112 | mlx4_free_cmd_mailbox(dev, mailbox); |
| 1113 | return err; |
| 1114 | } |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1115 | |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 1116 | int mlx4_qp_detach_common(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16], |
| 1117 | enum mlx4_protocol prot, enum mlx4_steer_type steer) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1118 | { |
| 1119 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 1120 | struct mlx4_cmd_mailbox *mailbox; |
| 1121 | struct mlx4_mgm *mgm; |
| 1122 | u32 members_count; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1123 | int prev, index; |
Dotan Barak | aab2bb0 | 2014-07-16 11:57:48 +0300 | [diff] [blame] | 1124 | int i, loc = -1; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1125 | int err; |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 1126 | u8 port = gid[5]; |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 1127 | bool removed_entry = false; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1128 | |
| 1129 | mailbox = mlx4_alloc_cmd_mailbox(dev); |
| 1130 | if (IS_ERR(mailbox)) |
| 1131 | return PTR_ERR(mailbox); |
| 1132 | mgm = mailbox->buf; |
| 1133 | |
| 1134 | mutex_lock(&priv->mcg_table.mutex); |
| 1135 | |
Eugenia Emantayev | deb8b3e | 2012-02-14 06:37:46 +0000 | [diff] [blame] | 1136 | err = find_entry(dev, port, gid, prot, |
| 1137 | mailbox, &prev, &index); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1138 | if (err) |
| 1139 | goto out; |
| 1140 | |
| 1141 | if (index == -1) { |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 1142 | mlx4_err(dev, "MGID %pI6 not found\n", gid); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1143 | err = -EINVAL; |
| 1144 | goto out; |
| 1145 | } |
| 1146 | |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 1147 | /* if this pq is also a promisc qp, it shouldn't be removed */ |
| 1148 | if (prot == MLX4_PROT_ETH && |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 1149 | check_duplicate_entry(dev, port, steer, index, qp->qpn)) |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 1150 | goto out; |
| 1151 | |
Aleksey Senin | da995a8 | 2010-12-02 11:44:49 +0000 | [diff] [blame] | 1152 | members_count = be32_to_cpu(mgm->members_count) & 0xffffff; |
Dotan Barak | aab2bb0 | 2014-07-16 11:57:48 +0300 | [diff] [blame] | 1153 | for (i = 0; i < members_count; ++i) |
| 1154 | if ((be32_to_cpu(mgm->qp[i]) & MGM_QPN_MASK) == qp->qpn) { |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1155 | loc = i; |
Dotan Barak | aab2bb0 | 2014-07-16 11:57:48 +0300 | [diff] [blame] | 1156 | break; |
| 1157 | } |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1158 | |
| 1159 | if (loc == -1) { |
| 1160 | mlx4_err(dev, "QP %06x not found in MGM\n", qp->qpn); |
| 1161 | err = -EINVAL; |
| 1162 | goto out; |
| 1163 | } |
| 1164 | |
Dotan Barak | aab2bb0 | 2014-07-16 11:57:48 +0300 | [diff] [blame] | 1165 | /* copy the last QP in this MGM over removed QP */ |
| 1166 | mgm->qp[loc] = mgm->qp[members_count - 1]; |
| 1167 | mgm->qp[members_count - 1] = 0; |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 1168 | mgm->members_count = cpu_to_be32(--members_count | (u32) prot << 30); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1169 | |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 1170 | if (prot == MLX4_PROT_ETH) |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 1171 | removed_entry = can_remove_steering_entry(dev, port, steer, |
| 1172 | index, qp->qpn); |
Dotan Barak | aab2bb0 | 2014-07-16 11:57:48 +0300 | [diff] [blame] | 1173 | if (members_count && (prot != MLX4_PROT_ETH || !removed_entry)) { |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 1174 | err = mlx4_WRITE_ENTRY(dev, index, mailbox); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1175 | goto out; |
Eli Cohen | 4dc51b3 | 2008-04-16 21:09:35 -0700 | [diff] [blame] | 1176 | } |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1177 | |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 1178 | /* We are going to delete the entry, members count should be 0 */ |
| 1179 | mgm->members_count = cpu_to_be32((u32) prot << 30); |
| 1180 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1181 | if (prev == -1) { |
| 1182 | /* Remove entry from MGM */ |
| 1183 | int amgm_index = be32_to_cpu(mgm->next_gid_index) >> 6; |
| 1184 | if (amgm_index) { |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 1185 | err = mlx4_READ_ENTRY(dev, amgm_index, mailbox); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1186 | if (err) |
| 1187 | goto out; |
| 1188 | } else |
| 1189 | memset(mgm->gid, 0, 16); |
| 1190 | |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 1191 | err = mlx4_WRITE_ENTRY(dev, index, mailbox); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1192 | if (err) |
| 1193 | goto out; |
| 1194 | |
| 1195 | if (amgm_index) { |
| 1196 | if (amgm_index < dev->caps.num_mgms) |
Joe Perches | 1a91de2 | 2014-05-07 12:52:57 -0700 | [diff] [blame] | 1197 | mlx4_warn(dev, "MGM entry %d had AMGM index %d < %d\n", |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1198 | index, amgm_index, dev->caps.num_mgms); |
| 1199 | else |
| 1200 | mlx4_bitmap_free(&priv->mcg_table.bitmap, |
Jack Morgenstein | 7c6d74d | 2013-12-08 16:50:17 +0200 | [diff] [blame] | 1201 | amgm_index - dev->caps.num_mgms, MLX4_USE_RR); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1202 | } |
| 1203 | } else { |
| 1204 | /* Remove entry from AMGM */ |
| 1205 | int cur_next_index = be32_to_cpu(mgm->next_gid_index) >> 6; |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 1206 | err = mlx4_READ_ENTRY(dev, prev, mailbox); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1207 | if (err) |
| 1208 | goto out; |
| 1209 | |
| 1210 | mgm->next_gid_index = cpu_to_be32(cur_next_index << 6); |
| 1211 | |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 1212 | err = mlx4_WRITE_ENTRY(dev, prev, mailbox); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1213 | if (err) |
| 1214 | goto out; |
| 1215 | |
| 1216 | if (index < dev->caps.num_mgms) |
Joe Perches | 1a91de2 | 2014-05-07 12:52:57 -0700 | [diff] [blame] | 1217 | mlx4_warn(dev, "entry %d had next AMGM index %d < %d\n", |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1218 | prev, index, dev->caps.num_mgms); |
| 1219 | else |
| 1220 | mlx4_bitmap_free(&priv->mcg_table.bitmap, |
Jack Morgenstein | 7c6d74d | 2013-12-08 16:50:17 +0200 | [diff] [blame] | 1221 | index - dev->caps.num_mgms, MLX4_USE_RR); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1222 | } |
| 1223 | |
| 1224 | out: |
| 1225 | mutex_unlock(&priv->mcg_table.mutex); |
| 1226 | |
| 1227 | mlx4_free_cmd_mailbox(dev, mailbox); |
| 1228 | return err; |
| 1229 | } |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 1230 | |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 1231 | static int mlx4_QP_ATTACH(struct mlx4_dev *dev, struct mlx4_qp *qp, |
| 1232 | u8 gid[16], u8 attach, u8 block_loopback, |
| 1233 | enum mlx4_protocol prot) |
| 1234 | { |
| 1235 | struct mlx4_cmd_mailbox *mailbox; |
| 1236 | int err = 0; |
| 1237 | int qpn; |
| 1238 | |
| 1239 | if (!mlx4_is_mfunc(dev)) |
| 1240 | return -EBADF; |
| 1241 | |
| 1242 | mailbox = mlx4_alloc_cmd_mailbox(dev); |
| 1243 | if (IS_ERR(mailbox)) |
| 1244 | return PTR_ERR(mailbox); |
| 1245 | |
| 1246 | memcpy(mailbox->buf, gid, 16); |
| 1247 | qpn = qp->qpn; |
| 1248 | qpn |= (prot << 28); |
| 1249 | if (attach && block_loopback) |
| 1250 | qpn |= (1 << 31); |
| 1251 | |
| 1252 | err = mlx4_cmd(dev, mailbox->dma, qpn, attach, |
| 1253 | MLX4_CMD_QP_ATTACH, MLX4_CMD_TIME_CLASS_A, |
| 1254 | MLX4_CMD_WRAPPED); |
| 1255 | |
| 1256 | mlx4_free_cmd_mailbox(dev, mailbox); |
| 1257 | return err; |
| 1258 | } |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 1259 | |
Hadar Hen Zion | fd91c49f | 2013-04-11 01:56:40 +0000 | [diff] [blame] | 1260 | int mlx4_trans_to_dmfs_attach(struct mlx4_dev *dev, struct mlx4_qp *qp, |
| 1261 | u8 gid[16], u8 port, |
| 1262 | int block_mcast_loopback, |
| 1263 | enum mlx4_protocol prot, u64 *reg_id) |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 1264 | { |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1265 | struct mlx4_spec_list spec = { {NULL} }; |
| 1266 | __be64 mac_mask = cpu_to_be64(MLX4_MAC_MASK << 16); |
| 1267 | |
| 1268 | struct mlx4_net_trans_rule rule = { |
| 1269 | .queue_mode = MLX4_NET_TRANS_Q_FIFO, |
| 1270 | .exclusive = 0, |
Hadar Hen Zion | f916253 | 2013-04-24 13:58:45 +0000 | [diff] [blame] | 1271 | .promisc_mode = MLX4_FS_REGULAR, |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1272 | .priority = MLX4_DOMAIN_NIC, |
| 1273 | }; |
| 1274 | |
Hadar Hen Zion | 248c62a | 2013-01-30 23:07:03 +0000 | [diff] [blame] | 1275 | rule.allow_loopback = !block_mcast_loopback; |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1276 | rule.port = port; |
| 1277 | rule.qpn = qp->qpn; |
| 1278 | INIT_LIST_HEAD(&rule.list); |
| 1279 | |
| 1280 | switch (prot) { |
| 1281 | case MLX4_PROT_ETH: |
| 1282 | spec.id = MLX4_NET_TRANS_RULE_ID_ETH; |
| 1283 | memcpy(spec.eth.dst_mac, &gid[10], ETH_ALEN); |
| 1284 | memcpy(spec.eth.dst_mac_msk, &mac_mask, ETH_ALEN); |
| 1285 | break; |
| 1286 | |
| 1287 | case MLX4_PROT_IB_IPV6: |
| 1288 | spec.id = MLX4_NET_TRANS_RULE_ID_IB; |
| 1289 | memcpy(spec.ib.dst_gid, gid, 16); |
| 1290 | memset(&spec.ib.dst_gid_msk, 0xff, 16); |
| 1291 | break; |
| 1292 | default: |
| 1293 | return -EINVAL; |
| 1294 | } |
| 1295 | list_add_tail(&spec.list, &rule.list); |
| 1296 | |
| 1297 | return mlx4_flow_attach(dev, &rule, reg_id); |
Hadar Hen Zion | fd91c49f | 2013-04-11 01:56:40 +0000 | [diff] [blame] | 1298 | } |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1299 | |
Hadar Hen Zion | fd91c49f | 2013-04-11 01:56:40 +0000 | [diff] [blame] | 1300 | int mlx4_multicast_attach(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16], |
| 1301 | u8 port, int block_mcast_loopback, |
| 1302 | enum mlx4_protocol prot, u64 *reg_id) |
| 1303 | { |
| 1304 | switch (dev->caps.steering_mode) { |
| 1305 | case MLX4_STEERING_MODE_A0: |
| 1306 | if (prot == MLX4_PROT_ETH) |
| 1307 | return 0; |
| 1308 | |
| 1309 | case MLX4_STEERING_MODE_B0: |
| 1310 | if (prot == MLX4_PROT_ETH) |
| 1311 | gid[7] |= (MLX4_MC_STEER << 1); |
| 1312 | |
| 1313 | if (mlx4_is_mfunc(dev)) |
| 1314 | return mlx4_QP_ATTACH(dev, qp, gid, 1, |
| 1315 | block_mcast_loopback, prot); |
| 1316 | return mlx4_qp_attach_common(dev, qp, gid, |
| 1317 | block_mcast_loopback, prot, |
| 1318 | MLX4_MC_STEER); |
| 1319 | |
| 1320 | case MLX4_STEERING_MODE_DEVICE_MANAGED: |
| 1321 | return mlx4_trans_to_dmfs_attach(dev, qp, gid, port, |
| 1322 | block_mcast_loopback, |
| 1323 | prot, reg_id); |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame] | 1324 | default: |
| 1325 | return -EINVAL; |
| 1326 | } |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 1327 | } |
| 1328 | EXPORT_SYMBOL_GPL(mlx4_multicast_attach); |
| 1329 | |
| 1330 | int mlx4_multicast_detach(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16], |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1331 | enum mlx4_protocol prot, u64 reg_id) |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 1332 | { |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame] | 1333 | switch (dev->caps.steering_mode) { |
| 1334 | case MLX4_STEERING_MODE_A0: |
| 1335 | if (prot == MLX4_PROT_ETH) |
| 1336 | return 0; |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 1337 | |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame] | 1338 | case MLX4_STEERING_MODE_B0: |
| 1339 | if (prot == MLX4_PROT_ETH) |
| 1340 | gid[7] |= (MLX4_MC_STEER << 1); |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 1341 | |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame] | 1342 | if (mlx4_is_mfunc(dev)) |
| 1343 | return mlx4_QP_ATTACH(dev, qp, gid, 0, 0, prot); |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 1344 | |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame] | 1345 | return mlx4_qp_detach_common(dev, qp, gid, prot, |
| 1346 | MLX4_MC_STEER); |
| 1347 | |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1348 | case MLX4_STEERING_MODE_DEVICE_MANAGED: |
| 1349 | return mlx4_flow_detach(dev, reg_id); |
| 1350 | |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame] | 1351 | default: |
| 1352 | return -EINVAL; |
| 1353 | } |
Yevgeny Petrilin | 0345584 | 2011-03-22 22:38:17 +0000 | [diff] [blame] | 1354 | } |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1355 | EXPORT_SYMBOL_GPL(mlx4_multicast_detach); |
| 1356 | |
Hadar Hen Zion | 592e49d | 2012-07-05 04:03:48 +0000 | [diff] [blame] | 1357 | int mlx4_flow_steer_promisc_add(struct mlx4_dev *dev, u8 port, |
| 1358 | u32 qpn, enum mlx4_net_trans_promisc_mode mode) |
| 1359 | { |
| 1360 | struct mlx4_net_trans_rule rule; |
| 1361 | u64 *regid_p; |
| 1362 | |
| 1363 | switch (mode) { |
Hadar Hen Zion | f916253 | 2013-04-24 13:58:45 +0000 | [diff] [blame] | 1364 | case MLX4_FS_ALL_DEFAULT: |
Hadar Hen Zion | 592e49d | 2012-07-05 04:03:48 +0000 | [diff] [blame] | 1365 | regid_p = &dev->regid_promisc_array[port]; |
| 1366 | break; |
Hadar Hen Zion | f916253 | 2013-04-24 13:58:45 +0000 | [diff] [blame] | 1367 | case MLX4_FS_MC_DEFAULT: |
Hadar Hen Zion | 592e49d | 2012-07-05 04:03:48 +0000 | [diff] [blame] | 1368 | regid_p = &dev->regid_allmulti_array[port]; |
| 1369 | break; |
| 1370 | default: |
| 1371 | return -1; |
| 1372 | } |
| 1373 | |
| 1374 | if (*regid_p != 0) |
| 1375 | return -1; |
| 1376 | |
| 1377 | rule.promisc_mode = mode; |
| 1378 | rule.port = port; |
| 1379 | rule.qpn = qpn; |
| 1380 | INIT_LIST_HEAD(&rule.list); |
| 1381 | mlx4_err(dev, "going promisc on %x\n", port); |
| 1382 | |
| 1383 | return mlx4_flow_attach(dev, &rule, regid_p); |
| 1384 | } |
| 1385 | EXPORT_SYMBOL_GPL(mlx4_flow_steer_promisc_add); |
| 1386 | |
| 1387 | int mlx4_flow_steer_promisc_remove(struct mlx4_dev *dev, u8 port, |
| 1388 | enum mlx4_net_trans_promisc_mode mode) |
| 1389 | { |
| 1390 | int ret; |
| 1391 | u64 *regid_p; |
| 1392 | |
| 1393 | switch (mode) { |
Hadar Hen Zion | f916253 | 2013-04-24 13:58:45 +0000 | [diff] [blame] | 1394 | case MLX4_FS_ALL_DEFAULT: |
Hadar Hen Zion | 592e49d | 2012-07-05 04:03:48 +0000 | [diff] [blame] | 1395 | regid_p = &dev->regid_promisc_array[port]; |
| 1396 | break; |
Hadar Hen Zion | f916253 | 2013-04-24 13:58:45 +0000 | [diff] [blame] | 1397 | case MLX4_FS_MC_DEFAULT: |
Hadar Hen Zion | 592e49d | 2012-07-05 04:03:48 +0000 | [diff] [blame] | 1398 | regid_p = &dev->regid_allmulti_array[port]; |
| 1399 | break; |
| 1400 | default: |
| 1401 | return -1; |
| 1402 | } |
| 1403 | |
| 1404 | if (*regid_p == 0) |
| 1405 | return -1; |
| 1406 | |
| 1407 | ret = mlx4_flow_detach(dev, *regid_p); |
| 1408 | if (ret == 0) |
| 1409 | *regid_p = 0; |
| 1410 | |
| 1411 | return ret; |
| 1412 | } |
| 1413 | EXPORT_SYMBOL_GPL(mlx4_flow_steer_promisc_remove); |
| 1414 | |
Eugenia Emantayev | ffe455a | 2011-12-13 04:16:21 +0000 | [diff] [blame] | 1415 | int mlx4_unicast_attach(struct mlx4_dev *dev, |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 1416 | struct mlx4_qp *qp, u8 gid[16], |
| 1417 | int block_mcast_loopback, enum mlx4_protocol prot) |
| 1418 | { |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 1419 | if (prot == MLX4_PROT_ETH) |
| 1420 | gid[7] |= (MLX4_UC_STEER << 1); |
| 1421 | |
| 1422 | if (mlx4_is_mfunc(dev)) |
| 1423 | return mlx4_QP_ATTACH(dev, qp, gid, 1, |
| 1424 | block_mcast_loopback, prot); |
| 1425 | |
| 1426 | return mlx4_qp_attach_common(dev, qp, gid, block_mcast_loopback, |
| 1427 | prot, MLX4_UC_STEER); |
| 1428 | } |
| 1429 | EXPORT_SYMBOL_GPL(mlx4_unicast_attach); |
| 1430 | |
Eugenia Emantayev | ffe455a | 2011-12-13 04:16:21 +0000 | [diff] [blame] | 1431 | int mlx4_unicast_detach(struct mlx4_dev *dev, struct mlx4_qp *qp, |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 1432 | u8 gid[16], enum mlx4_protocol prot) |
| 1433 | { |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 1434 | if (prot == MLX4_PROT_ETH) |
| 1435 | gid[7] |= (MLX4_UC_STEER << 1); |
| 1436 | |
| 1437 | if (mlx4_is_mfunc(dev)) |
| 1438 | return mlx4_QP_ATTACH(dev, qp, gid, 0, 0, prot); |
| 1439 | |
| 1440 | return mlx4_qp_detach_common(dev, qp, gid, prot, MLX4_UC_STEER); |
| 1441 | } |
| 1442 | EXPORT_SYMBOL_GPL(mlx4_unicast_detach); |
| 1443 | |
| 1444 | int mlx4_PROMISC_wrapper(struct mlx4_dev *dev, int slave, |
| 1445 | struct mlx4_vhcr *vhcr, |
| 1446 | struct mlx4_cmd_mailbox *inbox, |
| 1447 | struct mlx4_cmd_mailbox *outbox, |
| 1448 | struct mlx4_cmd_info *cmd) |
| 1449 | { |
| 1450 | u32 qpn = (u32) vhcr->in_param & 0xffffffff; |
Matan Barak | 449fc48 | 2014-03-19 18:11:52 +0200 | [diff] [blame] | 1451 | int port = mlx4_slave_convert_port(dev, slave, vhcr->in_param >> 62); |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 1452 | enum mlx4_steer_type steer = vhcr->in_modifier; |
| 1453 | |
Matan Barak | 449fc48 | 2014-03-19 18:11:52 +0200 | [diff] [blame] | 1454 | if (port < 0) |
| 1455 | return -EINVAL; |
| 1456 | |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 1457 | /* Promiscuous unicast is not allowed in mfunc */ |
| 1458 | if (mlx4_is_mfunc(dev) && steer == MLX4_UC_STEER) |
| 1459 | return 0; |
| 1460 | |
| 1461 | if (vhcr->op_modifier) |
| 1462 | return add_promisc_qp(dev, port, steer, qpn); |
| 1463 | else |
| 1464 | return remove_promisc_qp(dev, port, steer, qpn); |
| 1465 | } |
| 1466 | |
| 1467 | static int mlx4_PROMISC(struct mlx4_dev *dev, u32 qpn, |
| 1468 | enum mlx4_steer_type steer, u8 add, u8 port) |
| 1469 | { |
| 1470 | return mlx4_cmd(dev, (u64) qpn | (u64) port << 62, (u32) steer, add, |
| 1471 | MLX4_CMD_PROMISC, MLX4_CMD_TIME_CLASS_A, |
| 1472 | MLX4_CMD_WRAPPED); |
| 1473 | } |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 1474 | |
| 1475 | int mlx4_multicast_promisc_add(struct mlx4_dev *dev, u32 qpn, u8 port) |
| 1476 | { |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 1477 | if (mlx4_is_mfunc(dev)) |
| 1478 | return mlx4_PROMISC(dev, qpn, MLX4_MC_STEER, 1, port); |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 1479 | |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 1480 | return add_promisc_qp(dev, port, MLX4_MC_STEER, qpn); |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 1481 | } |
| 1482 | EXPORT_SYMBOL_GPL(mlx4_multicast_promisc_add); |
| 1483 | |
| 1484 | int mlx4_multicast_promisc_remove(struct mlx4_dev *dev, u32 qpn, u8 port) |
| 1485 | { |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 1486 | if (mlx4_is_mfunc(dev)) |
| 1487 | return mlx4_PROMISC(dev, qpn, MLX4_MC_STEER, 0, port); |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 1488 | |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 1489 | return remove_promisc_qp(dev, port, MLX4_MC_STEER, qpn); |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 1490 | } |
| 1491 | EXPORT_SYMBOL_GPL(mlx4_multicast_promisc_remove); |
| 1492 | |
| 1493 | int mlx4_unicast_promisc_add(struct mlx4_dev *dev, u32 qpn, u8 port) |
| 1494 | { |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 1495 | if (mlx4_is_mfunc(dev)) |
| 1496 | return mlx4_PROMISC(dev, qpn, MLX4_UC_STEER, 1, port); |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 1497 | |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 1498 | return add_promisc_qp(dev, port, MLX4_UC_STEER, qpn); |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 1499 | } |
| 1500 | EXPORT_SYMBOL_GPL(mlx4_unicast_promisc_add); |
| 1501 | |
| 1502 | int mlx4_unicast_promisc_remove(struct mlx4_dev *dev, u32 qpn, u8 port) |
| 1503 | { |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 1504 | if (mlx4_is_mfunc(dev)) |
| 1505 | return mlx4_PROMISC(dev, qpn, MLX4_UC_STEER, 0, port); |
| 1506 | |
| 1507 | return remove_promisc_qp(dev, port, MLX4_UC_STEER, qpn); |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 1508 | } |
| 1509 | EXPORT_SYMBOL_GPL(mlx4_unicast_promisc_remove); |
| 1510 | |
Roland Dreier | 3d73c28 | 2007-10-10 15:43:54 -0700 | [diff] [blame] | 1511 | int mlx4_init_mcg_table(struct mlx4_dev *dev) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1512 | { |
| 1513 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 1514 | int err; |
| 1515 | |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1516 | /* No need for mcg_table when fw managed the mcg table*/ |
| 1517 | if (dev->caps.steering_mode == |
| 1518 | MLX4_STEERING_MODE_DEVICE_MANAGED) |
| 1519 | return 0; |
Yevgeny Petrilin | 93fc9e1 | 2008-10-22 10:25:29 -0700 | [diff] [blame] | 1520 | err = mlx4_bitmap_init(&priv->mcg_table.bitmap, dev->caps.num_amgms, |
| 1521 | dev->caps.num_amgms - 1, 0, 0); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1522 | if (err) |
| 1523 | return err; |
| 1524 | |
| 1525 | mutex_init(&priv->mcg_table.mutex); |
| 1526 | |
| 1527 | return 0; |
| 1528 | } |
| 1529 | |
| 1530 | void mlx4_cleanup_mcg_table(struct mlx4_dev *dev) |
| 1531 | { |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1532 | if (dev->caps.steering_mode != |
| 1533 | MLX4_STEERING_MODE_DEVICE_MANAGED) |
| 1534 | mlx4_bitmap_cleanup(&mlx4_priv(dev)->mcg_table.bitmap); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1535 | } |