Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2004 Topspin Communications. All rights reserved. |
| 3 | * |
| 4 | * This software is available to you under a choice of one of two |
| 5 | * licenses. You may choose to be licensed under the terms of the GNU |
| 6 | * General Public License (GPL) Version 2, available from the file |
| 7 | * COPYING in the main directory of this source tree, or the |
| 8 | * OpenIB.org BSD license below: |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or |
| 11 | * without modification, are permitted provided that the following |
| 12 | * conditions are met: |
| 13 | * |
| 14 | * - Redistributions of source code must retain the above |
| 15 | * copyright notice, this list of conditions and the following |
| 16 | * disclaimer. |
| 17 | * |
| 18 | * - Redistributions in binary form must reproduce the above |
| 19 | * copyright notice, this list of conditions and the following |
| 20 | * disclaimer in the documentation and/or other materials |
| 21 | * provided with the distribution. |
| 22 | * |
| 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 24 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 25 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 26 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 27 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 28 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 29 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 30 | * SOFTWARE. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | */ |
| 32 | |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 33 | #include <linux/string.h> |
| 34 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | #include "mthca_dev.h" |
| 37 | #include "mthca_cmd.h" |
| 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | struct mthca_mgm { |
Sean Hefty | 97f52eb | 2005-08-13 21:05:57 -0700 | [diff] [blame] | 40 | __be32 next_gid_index; |
| 41 | u32 reserved[3]; |
| 42 | u8 gid[16]; |
| 43 | __be32 qp[MTHCA_QP_PER_MGM]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | static const u8 zero_gid[16]; /* automatically initialized to 0 */ |
| 47 | |
| 48 | /* |
| 49 | * Caller must hold MCG table semaphore. gid and mgm parameters must |
| 50 | * be properly aligned for command interface. |
| 51 | * |
| 52 | * Returns 0 unless a firmware command error occurs. |
| 53 | * |
| 54 | * If GID is found in MGM or MGM is empty, *index = *hash, *prev = -1 |
| 55 | * and *mgm holds MGM entry. |
| 56 | * |
| 57 | * if GID is found in AMGM, *index = index in AMGM, *prev = index of |
| 58 | * previous entry in hash chain and *mgm holds AMGM entry. |
| 59 | * |
| 60 | * If no AMGM exists for given gid, *index = -1, *prev = index of last |
| 61 | * entry in hash chain and *mgm holds end of hash chain. |
| 62 | */ |
| 63 | static int find_mgm(struct mthca_dev *dev, |
Roland Dreier | ed87845 | 2005-06-27 14:36:45 -0700 | [diff] [blame] | 64 | u8 *gid, struct mthca_mailbox *mgm_mailbox, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | u16 *hash, int *prev, int *index) |
| 66 | { |
Roland Dreier | ed87845 | 2005-06-27 14:36:45 -0700 | [diff] [blame] | 67 | struct mthca_mailbox *mailbox; |
| 68 | struct mthca_mgm *mgm = mgm_mailbox->buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | u8 *mgid; |
| 70 | int err; |
| 71 | u8 status; |
| 72 | |
Roland Dreier | ed87845 | 2005-06-27 14:36:45 -0700 | [diff] [blame] | 73 | mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL); |
| 74 | if (IS_ERR(mailbox)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | return -ENOMEM; |
Roland Dreier | ed87845 | 2005-06-27 14:36:45 -0700 | [diff] [blame] | 76 | mgid = mailbox->buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
| 78 | memcpy(mgid, gid, 16); |
| 79 | |
Roland Dreier | ed87845 | 2005-06-27 14:36:45 -0700 | [diff] [blame] | 80 | err = mthca_MGID_HASH(dev, mailbox, hash, &status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | if (err) |
| 82 | goto out; |
| 83 | if (status) { |
| 84 | mthca_err(dev, "MGID_HASH returned status %02x\n", status); |
| 85 | err = -EINVAL; |
| 86 | goto out; |
| 87 | } |
| 88 | |
| 89 | if (0) |
| 90 | mthca_dbg(dev, "Hash for %04x:%04x:%04x:%04x:" |
| 91 | "%04x:%04x:%04x:%04x is %04x\n", |
Sean Hefty | 97f52eb | 2005-08-13 21:05:57 -0700 | [diff] [blame] | 92 | be16_to_cpu(((__be16 *) gid)[0]), |
| 93 | be16_to_cpu(((__be16 *) gid)[1]), |
| 94 | be16_to_cpu(((__be16 *) gid)[2]), |
| 95 | be16_to_cpu(((__be16 *) gid)[3]), |
| 96 | be16_to_cpu(((__be16 *) gid)[4]), |
| 97 | be16_to_cpu(((__be16 *) gid)[5]), |
| 98 | be16_to_cpu(((__be16 *) gid)[6]), |
| 99 | be16_to_cpu(((__be16 *) gid)[7]), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | *hash); |
| 101 | |
| 102 | *index = *hash; |
| 103 | *prev = -1; |
| 104 | |
| 105 | do { |
Roland Dreier | ed87845 | 2005-06-27 14:36:45 -0700 | [diff] [blame] | 106 | err = mthca_READ_MGM(dev, *index, mgm_mailbox, &status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | if (err) |
| 108 | goto out; |
| 109 | if (status) { |
| 110 | mthca_err(dev, "READ_MGM returned status %02x\n", status); |
Jack Morgenstein | 5ceb745 | 2006-01-06 13:11:07 -0800 | [diff] [blame] | 111 | err = -EINVAL; |
| 112 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | if (!memcmp(mgm->gid, zero_gid, 16)) { |
| 116 | if (*index != *hash) { |
| 117 | mthca_err(dev, "Found zero MGID in AMGM.\n"); |
| 118 | err = -EINVAL; |
| 119 | } |
| 120 | goto out; |
| 121 | } |
| 122 | |
| 123 | if (!memcmp(mgm->gid, gid, 16)) |
| 124 | goto out; |
| 125 | |
| 126 | *prev = *index; |
Jack Morgenstein | 5ceb745 | 2006-01-06 13:11:07 -0800 | [diff] [blame] | 127 | *index = be32_to_cpu(mgm->next_gid_index) >> 6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | } while (*index); |
| 129 | |
| 130 | *index = -1; |
| 131 | |
| 132 | out: |
Roland Dreier | ed87845 | 2005-06-27 14:36:45 -0700 | [diff] [blame] | 133 | mthca_free_mailbox(dev, mailbox); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | return err; |
| 135 | } |
| 136 | |
| 137 | int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
| 138 | { |
| 139 | struct mthca_dev *dev = to_mdev(ibqp->device); |
Roland Dreier | ed87845 | 2005-06-27 14:36:45 -0700 | [diff] [blame] | 140 | struct mthca_mailbox *mailbox; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | struct mthca_mgm *mgm; |
| 142 | u16 hash; |
| 143 | int index, prev; |
| 144 | int link = 0; |
| 145 | int i; |
| 146 | int err; |
| 147 | u8 status; |
| 148 | |
Roland Dreier | ed87845 | 2005-06-27 14:36:45 -0700 | [diff] [blame] | 149 | mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL); |
| 150 | if (IS_ERR(mailbox)) |
| 151 | return PTR_ERR(mailbox); |
| 152 | mgm = mailbox->buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
Roland Dreier | fd9cfdd | 2006-01-30 16:45:11 -0800 | [diff] [blame] | 154 | mutex_lock(&dev->mcg_table.mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
Roland Dreier | ed87845 | 2005-06-27 14:36:45 -0700 | [diff] [blame] | 156 | err = find_mgm(dev, gid->raw, mailbox, &hash, &prev, &index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | if (err) |
| 158 | goto out; |
| 159 | |
| 160 | if (index != -1) { |
| 161 | if (!memcmp(mgm->gid, zero_gid, 16)) |
| 162 | memcpy(mgm->gid, gid->raw, 16); |
| 163 | } else { |
| 164 | link = 1; |
| 165 | |
| 166 | index = mthca_alloc(&dev->mcg_table.alloc); |
| 167 | if (index == -1) { |
| 168 | mthca_err(dev, "No AMGM entries left\n"); |
| 169 | err = -ENOMEM; |
| 170 | goto out; |
| 171 | } |
| 172 | |
Roland Dreier | ed87845 | 2005-06-27 14:36:45 -0700 | [diff] [blame] | 173 | err = mthca_READ_MGM(dev, index, mailbox, &status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | if (err) |
| 175 | goto out; |
| 176 | if (status) { |
| 177 | mthca_err(dev, "READ_MGM returned status %02x\n", status); |
| 178 | err = -EINVAL; |
| 179 | goto out; |
| 180 | } |
Jack Morgenstein | 5ceb745 | 2006-01-06 13:11:07 -0800 | [diff] [blame] | 181 | memset(mgm, 0, sizeof *mgm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | memcpy(mgm->gid, gid->raw, 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | for (i = 0; i < MTHCA_QP_PER_MGM; ++i) |
Jack Morgenstein | 7150bf8 | 2005-10-18 14:46:38 -0700 | [diff] [blame] | 186 | if (mgm->qp[i] == cpu_to_be32(ibqp->qp_num | (1 << 31))) { |
Roland Dreier | 2fa5e2e | 2006-02-01 13:38:24 -0800 | [diff] [blame] | 187 | mthca_dbg(dev, "QP %06x already a member of MGM\n", |
Jack Morgenstein | 7150bf8 | 2005-10-18 14:46:38 -0700 | [diff] [blame] | 188 | ibqp->qp_num); |
| 189 | err = 0; |
| 190 | goto out; |
| 191 | } else if (!(mgm->qp[i] & cpu_to_be32(1 << 31))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | mgm->qp[i] = cpu_to_be32(ibqp->qp_num | (1 << 31)); |
| 193 | break; |
| 194 | } |
| 195 | |
| 196 | if (i == MTHCA_QP_PER_MGM) { |
| 197 | mthca_err(dev, "MGM at index %x is full.\n", index); |
| 198 | err = -ENOMEM; |
| 199 | goto out; |
| 200 | } |
| 201 | |
Roland Dreier | ed87845 | 2005-06-27 14:36:45 -0700 | [diff] [blame] | 202 | err = mthca_WRITE_MGM(dev, index, mailbox, &status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | if (err) |
| 204 | goto out; |
| 205 | if (status) { |
| 206 | mthca_err(dev, "WRITE_MGM returned status %02x\n", status); |
| 207 | err = -EINVAL; |
Jack Morgenstein | 5ceb745 | 2006-01-06 13:11:07 -0800 | [diff] [blame] | 208 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | if (!link) |
| 212 | goto out; |
| 213 | |
Roland Dreier | ed87845 | 2005-06-27 14:36:45 -0700 | [diff] [blame] | 214 | err = mthca_READ_MGM(dev, prev, mailbox, &status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | if (err) |
| 216 | goto out; |
| 217 | if (status) { |
| 218 | mthca_err(dev, "READ_MGM returned status %02x\n", status); |
| 219 | err = -EINVAL; |
| 220 | goto out; |
| 221 | } |
| 222 | |
Jack Morgenstein | 5ceb745 | 2006-01-06 13:11:07 -0800 | [diff] [blame] | 223 | mgm->next_gid_index = cpu_to_be32(index << 6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
Roland Dreier | ed87845 | 2005-06-27 14:36:45 -0700 | [diff] [blame] | 225 | err = mthca_WRITE_MGM(dev, prev, mailbox, &status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | if (err) |
| 227 | goto out; |
| 228 | if (status) { |
| 229 | mthca_err(dev, "WRITE_MGM returned status %02x\n", status); |
| 230 | err = -EINVAL; |
| 231 | } |
| 232 | |
| 233 | out: |
Jack Morgenstein | 5ceb745 | 2006-01-06 13:11:07 -0800 | [diff] [blame] | 234 | if (err && link && index != -1) { |
| 235 | BUG_ON(index < dev->limits.num_mgms); |
| 236 | mthca_free(&dev->mcg_table.alloc, index); |
| 237 | } |
Roland Dreier | fd9cfdd | 2006-01-30 16:45:11 -0800 | [diff] [blame] | 238 | mutex_unlock(&dev->mcg_table.mutex); |
Michael S. Tsirkin | e3aa31c | 2006-01-30 16:22:29 -0800 | [diff] [blame] | 239 | |
Roland Dreier | ed87845 | 2005-06-27 14:36:45 -0700 | [diff] [blame] | 240 | mthca_free_mailbox(dev, mailbox); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | return err; |
| 242 | } |
| 243 | |
| 244 | int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
| 245 | { |
| 246 | struct mthca_dev *dev = to_mdev(ibqp->device); |
Roland Dreier | ed87845 | 2005-06-27 14:36:45 -0700 | [diff] [blame] | 247 | struct mthca_mailbox *mailbox; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | struct mthca_mgm *mgm; |
| 249 | u16 hash; |
| 250 | int prev, index; |
| 251 | int i, loc; |
| 252 | int err; |
| 253 | u8 status; |
| 254 | |
Roland Dreier | ed87845 | 2005-06-27 14:36:45 -0700 | [diff] [blame] | 255 | mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL); |
| 256 | if (IS_ERR(mailbox)) |
| 257 | return PTR_ERR(mailbox); |
| 258 | mgm = mailbox->buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
Roland Dreier | fd9cfdd | 2006-01-30 16:45:11 -0800 | [diff] [blame] | 260 | mutex_lock(&dev->mcg_table.mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | |
Roland Dreier | ed87845 | 2005-06-27 14:36:45 -0700 | [diff] [blame] | 262 | err = find_mgm(dev, gid->raw, mailbox, &hash, &prev, &index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | if (err) |
| 264 | goto out; |
| 265 | |
| 266 | if (index == -1) { |
| 267 | mthca_err(dev, "MGID %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x " |
| 268 | "not found\n", |
Sean Hefty | 97f52eb | 2005-08-13 21:05:57 -0700 | [diff] [blame] | 269 | be16_to_cpu(((__be16 *) gid->raw)[0]), |
| 270 | be16_to_cpu(((__be16 *) gid->raw)[1]), |
| 271 | be16_to_cpu(((__be16 *) gid->raw)[2]), |
| 272 | be16_to_cpu(((__be16 *) gid->raw)[3]), |
| 273 | be16_to_cpu(((__be16 *) gid->raw)[4]), |
| 274 | be16_to_cpu(((__be16 *) gid->raw)[5]), |
| 275 | be16_to_cpu(((__be16 *) gid->raw)[6]), |
| 276 | be16_to_cpu(((__be16 *) gid->raw)[7])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | err = -EINVAL; |
| 278 | goto out; |
| 279 | } |
| 280 | |
| 281 | for (loc = -1, i = 0; i < MTHCA_QP_PER_MGM; ++i) { |
| 282 | if (mgm->qp[i] == cpu_to_be32(ibqp->qp_num | (1 << 31))) |
| 283 | loc = i; |
| 284 | if (!(mgm->qp[i] & cpu_to_be32(1 << 31))) |
| 285 | break; |
| 286 | } |
| 287 | |
| 288 | if (loc == -1) { |
| 289 | mthca_err(dev, "QP %06x not found in MGM\n", ibqp->qp_num); |
| 290 | err = -EINVAL; |
| 291 | goto out; |
| 292 | } |
| 293 | |
| 294 | mgm->qp[loc] = mgm->qp[i - 1]; |
| 295 | mgm->qp[i - 1] = 0; |
| 296 | |
Roland Dreier | ed87845 | 2005-06-27 14:36:45 -0700 | [diff] [blame] | 297 | err = mthca_WRITE_MGM(dev, index, mailbox, &status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | if (err) |
| 299 | goto out; |
| 300 | if (status) { |
| 301 | mthca_err(dev, "WRITE_MGM returned status %02x\n", status); |
| 302 | err = -EINVAL; |
| 303 | goto out; |
| 304 | } |
| 305 | |
| 306 | if (i != 1) |
| 307 | goto out; |
| 308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | if (prev == -1) { |
| 310 | /* Remove entry from MGM */ |
Jack Morgenstein | 5ceb745 | 2006-01-06 13:11:07 -0800 | [diff] [blame] | 311 | int amgm_index_to_free = be32_to_cpu(mgm->next_gid_index) >> 6; |
| 312 | if (amgm_index_to_free) { |
| 313 | err = mthca_READ_MGM(dev, amgm_index_to_free, |
Roland Dreier | ed87845 | 2005-06-27 14:36:45 -0700 | [diff] [blame] | 314 | mailbox, &status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | if (err) |
| 316 | goto out; |
| 317 | if (status) { |
| 318 | mthca_err(dev, "READ_MGM returned status %02x\n", |
| 319 | status); |
| 320 | err = -EINVAL; |
| 321 | goto out; |
| 322 | } |
| 323 | } else |
| 324 | memset(mgm->gid, 0, 16); |
| 325 | |
Roland Dreier | ed87845 | 2005-06-27 14:36:45 -0700 | [diff] [blame] | 326 | err = mthca_WRITE_MGM(dev, index, mailbox, &status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | if (err) |
| 328 | goto out; |
| 329 | if (status) { |
| 330 | mthca_err(dev, "WRITE_MGM returned status %02x\n", status); |
| 331 | err = -EINVAL; |
| 332 | goto out; |
| 333 | } |
Jack Morgenstein | 5ceb745 | 2006-01-06 13:11:07 -0800 | [diff] [blame] | 334 | if (amgm_index_to_free) { |
| 335 | BUG_ON(amgm_index_to_free < dev->limits.num_mgms); |
| 336 | mthca_free(&dev->mcg_table.alloc, amgm_index_to_free); |
| 337 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | } else { |
| 339 | /* Remove entry from AMGM */ |
Jack Morgenstein | 5ceb745 | 2006-01-06 13:11:07 -0800 | [diff] [blame] | 340 | int curr_next_index = be32_to_cpu(mgm->next_gid_index) >> 6; |
Roland Dreier | ed87845 | 2005-06-27 14:36:45 -0700 | [diff] [blame] | 341 | err = mthca_READ_MGM(dev, prev, mailbox, &status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | if (err) |
| 343 | goto out; |
| 344 | if (status) { |
| 345 | mthca_err(dev, "READ_MGM returned status %02x\n", status); |
| 346 | err = -EINVAL; |
| 347 | goto out; |
| 348 | } |
| 349 | |
Jack Morgenstein | 5ceb745 | 2006-01-06 13:11:07 -0800 | [diff] [blame] | 350 | mgm->next_gid_index = cpu_to_be32(curr_next_index << 6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | |
Roland Dreier | ed87845 | 2005-06-27 14:36:45 -0700 | [diff] [blame] | 352 | err = mthca_WRITE_MGM(dev, prev, mailbox, &status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | if (err) |
| 354 | goto out; |
| 355 | if (status) { |
| 356 | mthca_err(dev, "WRITE_MGM returned status %02x\n", status); |
| 357 | err = -EINVAL; |
| 358 | goto out; |
| 359 | } |
Jack Morgenstein | 5ceb745 | 2006-01-06 13:11:07 -0800 | [diff] [blame] | 360 | BUG_ON(index < dev->limits.num_mgms); |
| 361 | mthca_free(&dev->mcg_table.alloc, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | out: |
Roland Dreier | fd9cfdd | 2006-01-30 16:45:11 -0800 | [diff] [blame] | 365 | mutex_unlock(&dev->mcg_table.mutex); |
Michael S. Tsirkin | e3aa31c | 2006-01-30 16:22:29 -0800 | [diff] [blame] | 366 | |
Roland Dreier | ed87845 | 2005-06-27 14:36:45 -0700 | [diff] [blame] | 367 | mthca_free_mailbox(dev, mailbox); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | return err; |
| 369 | } |
| 370 | |
Roland Dreier | f4f3d0f | 2006-11-29 15:33:06 -0800 | [diff] [blame] | 371 | int mthca_init_mcg_table(struct mthca_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | { |
| 373 | int err; |
Jack Morgenstein | 5ceb745 | 2006-01-06 13:11:07 -0800 | [diff] [blame] | 374 | int table_size = dev->limits.num_mgms + dev->limits.num_amgms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | |
| 376 | err = mthca_alloc_init(&dev->mcg_table.alloc, |
Jack Morgenstein | 5ceb745 | 2006-01-06 13:11:07 -0800 | [diff] [blame] | 377 | table_size, |
| 378 | table_size - 1, |
| 379 | dev->limits.num_mgms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | if (err) |
| 381 | return err; |
| 382 | |
Roland Dreier | fd9cfdd | 2006-01-30 16:45:11 -0800 | [diff] [blame] | 383 | mutex_init(&dev->mcg_table.mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | |
| 385 | return 0; |
| 386 | } |
| 387 | |
Roland Dreier | e1f7868 | 2006-03-29 09:36:46 -0800 | [diff] [blame] | 388 | void mthca_cleanup_mcg_table(struct mthca_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | { |
| 390 | mthca_alloc_cleanup(&dev->mcg_table.alloc); |
| 391 | } |