blob: ac3265d0bf79d8e00912fe853f0e208e0ef478b9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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.
31 *
32 * $Id: mthca_mr.c 1349 2004-12-16 21:09:43Z roland $
33 */
34
35#include <linux/slab.h>
36#include <linux/init.h>
37#include <linux/errno.h>
38
39#include "mthca_dev.h"
40#include "mthca_cmd.h"
Roland Dreier86562a12005-04-16 15:26:13 -070041#include "mthca_memfree.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43/*
44 * Must be packed because mtt_seg is 64 bits but only aligned to 32 bits.
45 */
46struct mthca_mpt_entry {
47 u32 flags;
48 u32 page_size;
49 u32 key;
50 u32 pd;
51 u64 start;
52 u64 length;
53 u32 lkey;
54 u32 window_count;
55 u32 window_count_limit;
56 u64 mtt_seg;
57 u32 mtt_sz; /* Arbel only */
58 u32 reserved[2];
59} __attribute__((packed));
60
61#define MTHCA_MPT_FLAG_SW_OWNS (0xfUL << 28)
62#define MTHCA_MPT_FLAG_MIO (1 << 17)
63#define MTHCA_MPT_FLAG_BIND_ENABLE (1 << 15)
64#define MTHCA_MPT_FLAG_PHYSICAL (1 << 9)
65#define MTHCA_MPT_FLAG_REGION (1 << 8)
66
67#define MTHCA_MTT_FLAG_PRESENT 1
68
69/*
70 * Buddy allocator for MTT segments (currently not very efficient
71 * since it doesn't keep a free list and just searches linearly
72 * through the bitmaps)
73 */
74
Michael S. Tsirkin9095e202005-04-16 15:26:26 -070075static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
77 int o;
78 int m;
79 u32 seg;
80
Michael S. Tsirkin9095e202005-04-16 15:26:26 -070081 spin_lock(&buddy->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Michael S. Tsirkin9095e202005-04-16 15:26:26 -070083 for (o = order; o <= buddy->max_order; ++o) {
84 m = 1 << (buddy->max_order - o);
85 seg = find_first_bit(buddy->bits[o], m);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 if (seg < m)
87 goto found;
88 }
89
Michael S. Tsirkin9095e202005-04-16 15:26:26 -070090 spin_unlock(&buddy->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 return -1;
92
93 found:
Michael S. Tsirkin9095e202005-04-16 15:26:26 -070094 clear_bit(seg, buddy->bits[o]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96 while (o > order) {
97 --o;
98 seg <<= 1;
Michael S. Tsirkin9095e202005-04-16 15:26:26 -070099 set_bit(seg ^ 1, buddy->bits[o]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 }
101
Michael S. Tsirkin9095e202005-04-16 15:26:26 -0700102 spin_unlock(&buddy->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
104 seg <<= order;
105
106 return seg;
107}
108
Michael S. Tsirkin9095e202005-04-16 15:26:26 -0700109static void mthca_buddy_free(struct mthca_buddy *buddy, u32 seg, int order)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110{
111 seg >>= order;
112
Michael S. Tsirkin9095e202005-04-16 15:26:26 -0700113 spin_lock(&buddy->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Michael S. Tsirkin9095e202005-04-16 15:26:26 -0700115 while (test_bit(seg ^ 1, buddy->bits[order])) {
116 clear_bit(seg ^ 1, buddy->bits[order]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 seg >>= 1;
118 ++order;
119 }
120
Michael S. Tsirkin9095e202005-04-16 15:26:26 -0700121 set_bit(seg, buddy->bits[order]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Michael S. Tsirkin9095e202005-04-16 15:26:26 -0700123 spin_unlock(&buddy->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124}
125
Michael S. Tsirkin9095e202005-04-16 15:26:26 -0700126static int __devinit mthca_buddy_init(struct mthca_buddy *buddy, int max_order)
Roland Dreier86562a12005-04-16 15:26:13 -0700127{
Michael S. Tsirkin9095e202005-04-16 15:26:26 -0700128 int i, s;
129
130 buddy->max_order = max_order;
131 spin_lock_init(&buddy->lock);
132
133 buddy->bits = kmalloc((buddy->max_order + 1) * sizeof (long *),
134 GFP_KERNEL);
135 if (!buddy->bits)
136 goto err_out;
137
138 memset(buddy->bits, 0, (buddy->max_order + 1) * sizeof (long *));
139
140 for (i = 0; i <= buddy->max_order; ++i) {
141 s = BITS_TO_LONGS(1 << (buddy->max_order - i));
142 buddy->bits[i] = kmalloc(s * sizeof (long), GFP_KERNEL);
143 if (!buddy->bits[i])
144 goto err_out_free;
145 bitmap_zero(buddy->bits[i],
146 1 << (buddy->max_order - i));
147 }
148
149 set_bit(0, buddy->bits[buddy->max_order]);
150
151 return 0;
152
153err_out_free:
154 for (i = 0; i <= buddy->max_order; ++i)
155 kfree(buddy->bits[i]);
156
157 kfree(buddy->bits);
158
159err_out:
160 return -ENOMEM;
161}
162
163static void __devexit mthca_buddy_cleanup(struct mthca_buddy *buddy)
164{
165 int i;
166
167 for (i = 0; i <= buddy->max_order; ++i)
168 kfree(buddy->bits[i]);
169
170 kfree(buddy->bits);
171}
172
173static u32 mthca_alloc_mtt(struct mthca_dev *dev, int order,
174 struct mthca_buddy *buddy)
175{
176 u32 seg = mthca_buddy_alloc(buddy, order);
Roland Dreier86562a12005-04-16 15:26:13 -0700177
178 if (seg == -1)
179 return -1;
180
181 if (dev->hca_type == ARBEL_NATIVE)
182 if (mthca_table_get_range(dev, dev->mr_table.mtt_table, seg,
183 seg + (1 << order) - 1)) {
Michael S. Tsirkin9095e202005-04-16 15:26:26 -0700184 mthca_buddy_free(buddy, seg, order);
Roland Dreier86562a12005-04-16 15:26:13 -0700185 seg = -1;
186 }
187
188 return seg;
189}
190
Michael S. Tsirkin9095e202005-04-16 15:26:26 -0700191static void mthca_free_mtt(struct mthca_dev *dev, u32 seg, int order,
192 struct mthca_buddy* buddy)
Roland Dreier86562a12005-04-16 15:26:13 -0700193{
Michael S. Tsirkin9095e202005-04-16 15:26:26 -0700194 mthca_buddy_free(buddy, seg, order);
Roland Dreier86562a12005-04-16 15:26:13 -0700195
196 if (dev->hca_type == ARBEL_NATIVE)
197 mthca_table_put_range(dev, dev->mr_table.mtt_table, seg,
198 seg + (1 << order) - 1);
199}
200
Michael S. Tsirkind0a9d252005-04-16 15:26:30 -0700201static inline u32 tavor_hw_index_to_key(u32 ind)
202{
203 return ind;
204}
205
206static inline u32 tavor_key_to_hw_index(u32 key)
207{
208 return key;
209}
210
211static inline u32 arbel_hw_index_to_key(u32 ind)
212{
213 return (ind >> 24) | (ind << 8);
214}
215
216static inline u32 arbel_key_to_hw_index(u32 key)
217{
218 return (key << 24) | (key >> 8);
219}
220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221static inline u32 hw_index_to_key(struct mthca_dev *dev, u32 ind)
222{
223 if (dev->hca_type == ARBEL_NATIVE)
Michael S. Tsirkind0a9d252005-04-16 15:26:30 -0700224 return arbel_hw_index_to_key(ind);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 else
Michael S. Tsirkind0a9d252005-04-16 15:26:30 -0700226 return tavor_hw_index_to_key(ind);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227}
228
229static inline u32 key_to_hw_index(struct mthca_dev *dev, u32 key)
230{
231 if (dev->hca_type == ARBEL_NATIVE)
Michael S. Tsirkind0a9d252005-04-16 15:26:30 -0700232 return arbel_key_to_hw_index(key);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 else
Michael S. Tsirkind0a9d252005-04-16 15:26:30 -0700234 return tavor_key_to_hw_index(key);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235}
236
237int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
238 u32 access, struct mthca_mr *mr)
239{
Roland Dreier86562a12005-04-16 15:26:13 -0700240 void *mailbox = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 struct mthca_mpt_entry *mpt_entry;
242 u32 key;
243 int err;
244 u8 status;
245
246 might_sleep();
247
248 mr->order = -1;
249 key = mthca_alloc(&dev->mr_table.mpt_alloc);
250 if (key == -1)
251 return -ENOMEM;
252 mr->ibmr.rkey = mr->ibmr.lkey = hw_index_to_key(dev, key);
253
Roland Dreier86562a12005-04-16 15:26:13 -0700254 if (dev->hca_type == ARBEL_NATIVE) {
255 err = mthca_table_get(dev, dev->mr_table.mpt_table, key);
256 if (err)
257 goto err_out_mpt_free;
258 }
259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 mailbox = kmalloc(sizeof *mpt_entry + MTHCA_CMD_MAILBOX_EXTRA,
261 GFP_KERNEL);
262 if (!mailbox) {
Roland Dreier86562a12005-04-16 15:26:13 -0700263 err = -ENOMEM;
264 goto err_out_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 }
266 mpt_entry = MAILBOX_ALIGN(mailbox);
267
268 mpt_entry->flags = cpu_to_be32(MTHCA_MPT_FLAG_SW_OWNS |
269 MTHCA_MPT_FLAG_MIO |
270 MTHCA_MPT_FLAG_PHYSICAL |
271 MTHCA_MPT_FLAG_REGION |
272 access);
273 mpt_entry->page_size = 0;
274 mpt_entry->key = cpu_to_be32(key);
275 mpt_entry->pd = cpu_to_be32(pd);
276 mpt_entry->start = 0;
277 mpt_entry->length = ~0ULL;
278
279 memset(&mpt_entry->lkey, 0,
280 sizeof *mpt_entry - offsetof(struct mthca_mpt_entry, lkey));
281
282 err = mthca_SW2HW_MPT(dev, mpt_entry,
283 key & (dev->limits.num_mpts - 1),
284 &status);
Roland Dreier86562a12005-04-16 15:26:13 -0700285 if (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 mthca_warn(dev, "SW2HW_MPT failed (%d)\n", err);
Roland Dreier86562a12005-04-16 15:26:13 -0700287 goto err_out_table;
288 } else if (status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 mthca_warn(dev, "SW2HW_MPT returned status 0x%02x\n",
290 status);
291 err = -EINVAL;
Roland Dreier86562a12005-04-16 15:26:13 -0700292 goto err_out_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 }
294
295 kfree(mailbox);
296 return err;
Roland Dreier86562a12005-04-16 15:26:13 -0700297
298err_out_table:
299 if (dev->hca_type == ARBEL_NATIVE)
300 mthca_table_put(dev, dev->mr_table.mpt_table, key);
301
302err_out_mpt_free:
Michael S. Tsirkin55645e92005-04-16 15:26:19 -0700303 mthca_free(&dev->mr_table.mpt_alloc, key);
Roland Dreier86562a12005-04-16 15:26:13 -0700304 kfree(mailbox);
305 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306}
307
308int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
309 u64 *buffer_list, int buffer_size_shift,
310 int list_len, u64 iova, u64 total_size,
311 u32 access, struct mthca_mr *mr)
312{
313 void *mailbox;
314 u64 *mtt_entry;
315 struct mthca_mpt_entry *mpt_entry;
316 u32 key;
317 int err = -ENOMEM;
318 u8 status;
319 int i;
320
321 might_sleep();
322 WARN_ON(buffer_size_shift >= 32);
323
324 key = mthca_alloc(&dev->mr_table.mpt_alloc);
325 if (key == -1)
326 return -ENOMEM;
327 mr->ibmr.rkey = mr->ibmr.lkey = hw_index_to_key(dev, key);
328
Roland Dreier86562a12005-04-16 15:26:13 -0700329 if (dev->hca_type == ARBEL_NATIVE) {
330 err = mthca_table_get(dev, dev->mr_table.mpt_table, key);
331 if (err)
332 goto err_out_mpt_free;
333 }
334
Roland Dreier44ea6682005-04-16 15:26:24 -0700335 for (i = MTHCA_MTT_SEG_SIZE / 8, mr->order = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 i < list_len;
337 i <<= 1, ++mr->order)
338 ; /* nothing */
339
Michael S. Tsirkin9095e202005-04-16 15:26:26 -0700340 mr->first_seg = mthca_alloc_mtt(dev, mr->order,
341 &dev->mr_table.mtt_buddy);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 if (mr->first_seg == -1)
Roland Dreier86562a12005-04-16 15:26:13 -0700343 goto err_out_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
345 /*
346 * If list_len is odd, we add one more dummy entry for
347 * firmware efficiency.
348 */
349 mailbox = kmalloc(max(sizeof *mpt_entry,
350 (size_t) 8 * (list_len + (list_len & 1) + 2)) +
351 MTHCA_CMD_MAILBOX_EXTRA,
352 GFP_KERNEL);
353 if (!mailbox)
354 goto err_out_free_mtt;
355
356 mtt_entry = MAILBOX_ALIGN(mailbox);
357
358 mtt_entry[0] = cpu_to_be64(dev->mr_table.mtt_base +
Roland Dreier44ea6682005-04-16 15:26:24 -0700359 mr->first_seg * MTHCA_MTT_SEG_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 mtt_entry[1] = 0;
361 for (i = 0; i < list_len; ++i)
362 mtt_entry[i + 2] = cpu_to_be64(buffer_list[i] |
363 MTHCA_MTT_FLAG_PRESENT);
364 if (list_len & 1) {
365 mtt_entry[i + 2] = 0;
366 ++list_len;
367 }
368
369 if (0) {
370 mthca_dbg(dev, "Dumping MPT entry\n");
371 for (i = 0; i < list_len + 2; ++i)
372 printk(KERN_ERR "[%2d] %016llx\n",
373 i, (unsigned long long) be64_to_cpu(mtt_entry[i]));
374 }
375
376 err = mthca_WRITE_MTT(dev, mtt_entry, list_len, &status);
377 if (err) {
378 mthca_warn(dev, "WRITE_MTT failed (%d)\n", err);
379 goto err_out_mailbox_free;
380 }
381 if (status) {
382 mthca_warn(dev, "WRITE_MTT returned status 0x%02x\n",
383 status);
384 err = -EINVAL;
385 goto err_out_mailbox_free;
386 }
387
388 mpt_entry = MAILBOX_ALIGN(mailbox);
389
390 mpt_entry->flags = cpu_to_be32(MTHCA_MPT_FLAG_SW_OWNS |
391 MTHCA_MPT_FLAG_MIO |
392 MTHCA_MPT_FLAG_REGION |
393 access);
394
395 mpt_entry->page_size = cpu_to_be32(buffer_size_shift - 12);
396 mpt_entry->key = cpu_to_be32(key);
397 mpt_entry->pd = cpu_to_be32(pd);
398 mpt_entry->start = cpu_to_be64(iova);
399 mpt_entry->length = cpu_to_be64(total_size);
400 memset(&mpt_entry->lkey, 0,
401 sizeof *mpt_entry - offsetof(struct mthca_mpt_entry, lkey));
402 mpt_entry->mtt_seg = cpu_to_be64(dev->mr_table.mtt_base +
Roland Dreier44ea6682005-04-16 15:26:24 -0700403 mr->first_seg * MTHCA_MTT_SEG_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
405 if (0) {
406 mthca_dbg(dev, "Dumping MPT entry %08x:\n", mr->ibmr.lkey);
407 for (i = 0; i < sizeof (struct mthca_mpt_entry) / 4; ++i) {
408 if (i % 4 == 0)
409 printk("[%02x] ", i * 4);
410 printk(" %08x", be32_to_cpu(((u32 *) mpt_entry)[i]));
411 if ((i + 1) % 4 == 0)
412 printk("\n");
413 }
414 }
415
416 err = mthca_SW2HW_MPT(dev, mpt_entry,
417 key & (dev->limits.num_mpts - 1),
418 &status);
419 if (err)
420 mthca_warn(dev, "SW2HW_MPT failed (%d)\n", err);
421 else if (status) {
422 mthca_warn(dev, "SW2HW_MPT returned status 0x%02x\n",
423 status);
424 err = -EINVAL;
425 }
426
427 kfree(mailbox);
428 return err;
429
Roland Dreier86562a12005-04-16 15:26:13 -0700430err_out_mailbox_free:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 kfree(mailbox);
432
Roland Dreier86562a12005-04-16 15:26:13 -0700433err_out_free_mtt:
Michael S. Tsirkin9095e202005-04-16 15:26:26 -0700434 mthca_free_mtt(dev, mr->first_seg, mr->order, &dev->mr_table.mtt_buddy);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
Roland Dreier86562a12005-04-16 15:26:13 -0700436err_out_table:
437 if (dev->hca_type == ARBEL_NATIVE)
438 mthca_table_put(dev, dev->mr_table.mpt_table, key);
439
440err_out_mpt_free:
Michael S. Tsirkin55645e92005-04-16 15:26:19 -0700441 mthca_free(&dev->mr_table.mpt_alloc, key);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 return err;
443}
444
445void mthca_free_mr(struct mthca_dev *dev, struct mthca_mr *mr)
446{
447 int err;
448 u8 status;
449
450 might_sleep();
451
452 err = mthca_HW2SW_MPT(dev, NULL,
453 key_to_hw_index(dev, mr->ibmr.lkey) &
454 (dev->limits.num_mpts - 1),
455 &status);
456 if (err)
457 mthca_warn(dev, "HW2SW_MPT failed (%d)\n", err);
458 else if (status)
459 mthca_warn(dev, "HW2SW_MPT returned status 0x%02x\n",
460 status);
461
462 if (mr->order >= 0)
Michael S. Tsirkin9095e202005-04-16 15:26:26 -0700463 mthca_free_mtt(dev, mr->first_seg, mr->order, &dev->mr_table.mtt_buddy);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
Roland Dreier86562a12005-04-16 15:26:13 -0700465 if (dev->hca_type == ARBEL_NATIVE)
466 mthca_table_put(dev, dev->mr_table.mpt_table,
467 key_to_hw_index(dev, mr->ibmr.lkey));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 mthca_free(&dev->mr_table.mpt_alloc, key_to_hw_index(dev, mr->ibmr.lkey));
469}
470
471int __devinit mthca_init_mr_table(struct mthca_dev *dev)
472{
473 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
475 err = mthca_alloc_init(&dev->mr_table.mpt_alloc,
476 dev->limits.num_mpts,
477 ~0, dev->limits.reserved_mrws);
478 if (err)
479 return err;
480
Michael S. Tsirkin9095e202005-04-16 15:26:26 -0700481 err = mthca_buddy_init(&dev->mr_table.mtt_buddy,
482 fls(dev->limits.num_mtt_segs - 1));
483 if (err)
484 goto err_mtt_buddy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
Michael S. Tsirkin9095e202005-04-16 15:26:26 -0700486 if (dev->limits.reserved_mtts) {
487 if (mthca_alloc_mtt(dev, fls(dev->limits.reserved_mtts - 1),
488 &dev->mr_table.mtt_buddy) == -1) {
489 mthca_warn(dev, "MTT table of order %d is too small.\n",
490 dev->mr_table.mtt_buddy.max_order);
491 err = -ENOMEM;
492 goto err_mtt_buddy;
493 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 }
495
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 return 0;
497
Michael S. Tsirkin9095e202005-04-16 15:26:26 -0700498err_mtt_buddy:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 mthca_alloc_cleanup(&dev->mr_table.mpt_alloc);
500
501 return err;
502}
503
504void __devexit mthca_cleanup_mr_table(struct mthca_dev *dev)
505{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 /* XXX check if any MRs are still allocated? */
Michael S. Tsirkin9095e202005-04-16 15:26:26 -0700507 mthca_buddy_cleanup(&dev->mr_table.mtt_buddy);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 mthca_alloc_cleanup(&dev->mr_table.mpt_alloc);
509}