2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
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:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
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.
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
32 * $Id: mthca_cmd.c 1349 2004-12-16 21:09:43Z roland $
35 #include <linux/sched.h>
36 #include <linux/pci.h>
37 #include <linux/errno.h>
41 #include "mthca_dev.h"
42 #include "mthca_config_reg.h"
43 #include "mthca_cmd.h"
44 #include "mthca_memfree.h"
46 #define CMD_POLL_TOKEN 0xffff
49 HCR_IN_PARAM_OFFSET = 0x00,
50 HCR_IN_MODIFIER_OFFSET = 0x08,
51 HCR_OUT_PARAM_OFFSET = 0x0c,
52 HCR_TOKEN_OFFSET = 0x14,
53 HCR_STATUS_OFFSET = 0x18,
61 /* initialization and general commands */
67 CMD_MOD_STAT_CFG = 0x34,
68 CMD_QUERY_DEV_LIM = 0x3,
70 CMD_ENABLE_LAM = 0xff8,
71 CMD_DISABLE_LAM = 0xff7,
73 CMD_QUERY_ADAPTER = 0x6,
80 CMD_ACCESS_DDR = 0x2e,
82 CMD_UNMAP_ICM = 0xff9,
83 CMD_MAP_ICM_AUX = 0xffc,
84 CMD_UNMAP_ICM_AUX = 0xffb,
85 CMD_SET_ICM_SIZE = 0xffd,
105 CMD_RESIZE_CQ = 0x2c,
108 CMD_SW2HW_SRQ = 0x35,
109 CMD_HW2SW_SRQ = 0x36,
110 CMD_QUERY_SRQ = 0x37,
113 CMD_RST2INIT_QPEE = 0x19,
114 CMD_INIT2RTR_QPEE = 0x1a,
115 CMD_RTR2RTS_QPEE = 0x1b,
116 CMD_RTS2RTS_QPEE = 0x1c,
117 CMD_SQERR2RTS_QPEE = 0x1d,
118 CMD_2ERR_QPEE = 0x1e,
119 CMD_RTS2SQD_QPEE = 0x1f,
120 CMD_SQD2SQD_QPEE = 0x38,
121 CMD_SQD2RTS_QPEE = 0x20,
122 CMD_ERR2RST_QPEE = 0x21,
123 CMD_QUERY_QPEE = 0x22,
124 CMD_INIT2INIT_QPEE = 0x2d,
125 CMD_SUSPEND_QPEE = 0x32,
126 CMD_UNSUSPEND_QPEE = 0x33,
127 /* special QPs and management commands */
128 CMD_CONF_SPECIAL_QP = 0x23,
131 /* multicast commands */
133 CMD_WRITE_MGM = 0x26,
134 CMD_MGID_HASH = 0x27,
136 /* miscellaneous commands */
137 CMD_DIAG_RPRT = 0x30,
141 CMD_QUERY_DEBUG_MSG = 0x2a,
142 CMD_SET_DEBUG_MSG = 0x2b,
146 * According to Mellanox code, FW may be starved and never complete
147 * commands. So we can't use strict timeouts described in PRM -- we
148 * just arbitrarily select 60 seconds for now.
152 * Round up and add 1 to make sure we get the full wait time (since we
153 * will be starting in the middle of a jiffy)
156 CMD_TIME_CLASS_A = (HZ + 999) / 1000 + 1,
157 CMD_TIME_CLASS_B = (HZ + 99) / 100 + 1,
158 CMD_TIME_CLASS_C = (HZ + 9) / 10 + 1
162 CMD_TIME_CLASS_A = 60 * HZ,
163 CMD_TIME_CLASS_B = 60 * HZ,
164 CMD_TIME_CLASS_C = 60 * HZ
169 GO_BIT_TIMEOUT = HZ * 10
172 struct mthca_cmd_context {
173 struct completion done;
174 struct timer_list timer;
182 static inline int go_bit(struct mthca_dev *dev)
184 return readl(dev->hcr + HCR_STATUS_OFFSET) &
185 swab32(1 << HCR_GO_BIT);
188 static int mthca_cmd_post(struct mthca_dev *dev,
199 if (down_interruptible(&dev->cmd.hcr_sem))
203 unsigned long end = jiffies + GO_BIT_TIMEOUT;
205 while (go_bit(dev) && time_before(jiffies, end)) {
206 set_current_state(TASK_RUNNING);
217 * We use writel (instead of something like memcpy_toio)
218 * because writes of less than 32 bits to the HCR don't work
219 * (and some architectures such as ia64 implement memcpy_toio
220 * in terms of writeb).
222 __raw_writel(cpu_to_be32(in_param >> 32), dev->hcr + 0 * 4);
223 __raw_writel(cpu_to_be32(in_param & 0xfffffffful), dev->hcr + 1 * 4);
224 __raw_writel(cpu_to_be32(in_modifier), dev->hcr + 2 * 4);
225 __raw_writel(cpu_to_be32(out_param >> 32), dev->hcr + 3 * 4);
226 __raw_writel(cpu_to_be32(out_param & 0xfffffffful), dev->hcr + 4 * 4);
227 __raw_writel(cpu_to_be32(token << 16), dev->hcr + 5 * 4);
229 /* __raw_writel may not order writes. */
232 __raw_writel(cpu_to_be32((1 << HCR_GO_BIT) |
233 (event ? (1 << HCA_E_BIT) : 0) |
234 (op_modifier << HCR_OPMOD_SHIFT) |
235 op), dev->hcr + 6 * 4);
238 up(&dev->cmd.hcr_sem);
242 static int mthca_cmd_poll(struct mthca_dev *dev,
249 unsigned long timeout,
255 if (down_interruptible(&dev->cmd.poll_sem))
258 err = mthca_cmd_post(dev, in_param,
259 out_param ? *out_param : 0,
260 in_modifier, op_modifier,
261 op, CMD_POLL_TOKEN, 0);
265 end = timeout + jiffies;
266 while (go_bit(dev) && time_before(jiffies, end)) {
267 set_current_state(TASK_RUNNING);
277 memcpy_fromio(out_param, dev->hcr + HCR_OUT_PARAM_OFFSET, sizeof (u64));
278 be64_to_cpus(out_param);
281 *status = be32_to_cpu(__raw_readl(dev->hcr + HCR_STATUS_OFFSET)) >> 24;
284 up(&dev->cmd.poll_sem);
288 void mthca_cmd_event(struct mthca_dev *dev,
293 struct mthca_cmd_context *context =
294 &dev->cmd.context[token & dev->cmd.token_mask];
296 /* previously timed out command completing at long last */
297 if (token != context->token)
301 context->status = status;
302 context->out_param = out_param;
304 context->token += dev->cmd.token_mask + 1;
306 complete(&context->done);
309 static void event_timeout(unsigned long context_ptr)
311 struct mthca_cmd_context *context =
312 (struct mthca_cmd_context *) context_ptr;
314 context->result = -EBUSY;
315 complete(&context->done);
318 static int mthca_cmd_wait(struct mthca_dev *dev,
325 unsigned long timeout,
329 struct mthca_cmd_context *context;
331 if (down_interruptible(&dev->cmd.event_sem))
334 spin_lock(&dev->cmd.context_lock);
335 BUG_ON(dev->cmd.free_head < 0);
336 context = &dev->cmd.context[dev->cmd.free_head];
337 dev->cmd.free_head = context->next;
338 spin_unlock(&dev->cmd.context_lock);
340 init_completion(&context->done);
342 err = mthca_cmd_post(dev, in_param,
343 out_param ? *out_param : 0,
344 in_modifier, op_modifier,
345 op, context->token, 1);
349 context->timer.expires = jiffies + timeout;
350 add_timer(&context->timer);
352 wait_for_completion(&context->done);
353 del_timer_sync(&context->timer);
355 err = context->result;
359 *status = context->status;
361 mthca_dbg(dev, "Command %02x completed with status %02x\n",
365 *out_param = context->out_param;
368 spin_lock(&dev->cmd.context_lock);
369 context->next = dev->cmd.free_head;
370 dev->cmd.free_head = context - dev->cmd.context;
371 spin_unlock(&dev->cmd.context_lock);
373 up(&dev->cmd.event_sem);
377 /* Invoke a command with an output mailbox */
378 static int mthca_cmd_box(struct mthca_dev *dev,
384 unsigned long timeout,
387 if (dev->cmd.use_events)
388 return mthca_cmd_wait(dev, in_param, &out_param, 0,
389 in_modifier, op_modifier, op,
392 return mthca_cmd_poll(dev, in_param, &out_param, 0,
393 in_modifier, op_modifier, op,
397 /* Invoke a command with no output parameter */
398 static int mthca_cmd(struct mthca_dev *dev,
403 unsigned long timeout,
406 return mthca_cmd_box(dev, in_param, 0, in_modifier,
407 op_modifier, op, timeout, status);
411 * Invoke a command with an immediate output parameter (and copy the
412 * output into the caller's out_param pointer after the command
415 static int mthca_cmd_imm(struct mthca_dev *dev,
421 unsigned long timeout,
424 if (dev->cmd.use_events)
425 return mthca_cmd_wait(dev, in_param, out_param, 1,
426 in_modifier, op_modifier, op,
429 return mthca_cmd_poll(dev, in_param, out_param, 1,
430 in_modifier, op_modifier, op,
434 int mthca_cmd_init(struct mthca_dev *dev)
436 sema_init(&dev->cmd.hcr_sem, 1);
437 sema_init(&dev->cmd.poll_sem, 1);
438 dev->cmd.use_events = 0;
440 dev->hcr = ioremap(pci_resource_start(dev->pdev, 0) + MTHCA_HCR_BASE,
443 mthca_err(dev, "Couldn't map command register.");
447 dev->cmd.pool = pci_pool_create("mthca_cmd", dev->pdev,
449 MTHCA_MAILBOX_SIZE, 0);
450 if (!dev->cmd.pool) {
458 void mthca_cmd_cleanup(struct mthca_dev *dev)
460 pci_pool_destroy(dev->cmd.pool);
465 * Switch to using events to issue FW commands (should be called after
466 * event queue to command events has been initialized).
468 int mthca_cmd_use_events(struct mthca_dev *dev)
472 dev->cmd.context = kmalloc(dev->cmd.max_cmds *
473 sizeof (struct mthca_cmd_context),
475 if (!dev->cmd.context)
478 for (i = 0; i < dev->cmd.max_cmds; ++i) {
479 dev->cmd.context[i].token = i;
480 dev->cmd.context[i].next = i + 1;
481 init_timer(&dev->cmd.context[i].timer);
482 dev->cmd.context[i].timer.data =
483 (unsigned long) &dev->cmd.context[i];
484 dev->cmd.context[i].timer.function = event_timeout;
487 dev->cmd.context[dev->cmd.max_cmds - 1].next = -1;
488 dev->cmd.free_head = 0;
490 sema_init(&dev->cmd.event_sem, dev->cmd.max_cmds);
491 spin_lock_init(&dev->cmd.context_lock);
493 for (dev->cmd.token_mask = 1;
494 dev->cmd.token_mask < dev->cmd.max_cmds;
495 dev->cmd.token_mask <<= 1)
497 --dev->cmd.token_mask;
499 dev->cmd.use_events = 1;
500 down(&dev->cmd.poll_sem);
506 * Switch back to polling (used when shutting down the device)
508 void mthca_cmd_use_polling(struct mthca_dev *dev)
512 dev->cmd.use_events = 0;
514 for (i = 0; i < dev->cmd.max_cmds; ++i)
515 down(&dev->cmd.event_sem);
517 kfree(dev->cmd.context);
519 up(&dev->cmd.poll_sem);
522 struct mthca_mailbox *mthca_alloc_mailbox(struct mthca_dev *dev,
523 unsigned int gfp_mask)
525 struct mthca_mailbox *mailbox;
527 mailbox = kmalloc(sizeof *mailbox, gfp_mask);
529 return ERR_PTR(-ENOMEM);
531 mailbox->buf = pci_pool_alloc(dev->cmd.pool, gfp_mask, &mailbox->dma);
534 return ERR_PTR(-ENOMEM);
540 void mthca_free_mailbox(struct mthca_dev *dev, struct mthca_mailbox *mailbox)
545 pci_pool_free(dev->cmd.pool, mailbox->buf, mailbox->dma);
549 int mthca_SYS_EN(struct mthca_dev *dev, u8 *status)
554 ret = mthca_cmd_imm(dev, 0, &out, 0, 0, CMD_SYS_EN, HZ, status);
556 if (*status == MTHCA_CMD_STAT_DDR_MEM_ERR)
557 mthca_warn(dev, "SYS_EN DDR error: syn=%x, sock=%d, "
558 "sladdr=%d, SPD source=%s\n",
559 (int) (out >> 6) & 0xf, (int) (out >> 4) & 3,
560 (int) (out >> 1) & 7, (int) out & 1 ? "NVMEM" : "DIMM");
565 int mthca_SYS_DIS(struct mthca_dev *dev, u8 *status)
567 return mthca_cmd(dev, 0, 0, 0, CMD_SYS_DIS, HZ, status);
570 static int mthca_map_cmd(struct mthca_dev *dev, u16 op, struct mthca_icm *icm,
571 u64 virt, u8 *status)
573 struct mthca_mailbox *mailbox;
574 struct mthca_icm_iter iter;
582 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
584 return PTR_ERR(mailbox);
585 memset(mailbox->buf, 0, MTHCA_MAILBOX_SIZE);
586 pages = mailbox->buf;
588 for (mthca_icm_first(icm, &iter);
589 !mthca_icm_last(&iter);
590 mthca_icm_next(&iter)) {
592 * We have to pass pages that are aligned to their
593 * size, so find the least significant 1 in the
594 * address or size and use that as our log2 size.
596 lg = ffs(mthca_icm_addr(&iter) | mthca_icm_size(&iter)) - 1;
598 mthca_warn(dev, "Got FW area not aligned to 4K (%llx/%lx).\n",
599 (unsigned long long) mthca_icm_addr(&iter),
600 mthca_icm_size(&iter));
604 for (i = 0; i < mthca_icm_size(&iter) / (1 << lg); ++i, ++nent) {
606 pages[nent * 2] = cpu_to_be64(virt);
610 pages[nent * 2 + 1] = cpu_to_be64((mthca_icm_addr(&iter) +
611 (i << lg)) | (lg - 12));
612 ts += 1 << (lg - 10);
615 if (nent == MTHCA_MAILBOX_SIZE / 16) {
616 err = mthca_cmd(dev, mailbox->dma, nent, 0, op,
617 CMD_TIME_CLASS_B, status);
626 err = mthca_cmd(dev, mailbox->dma, nent, 0, op,
627 CMD_TIME_CLASS_B, status);
631 mthca_dbg(dev, "Mapped %d chunks/%d KB for FW.\n", tc, ts);
633 case CMD_MAP_ICM_AUX:
634 mthca_dbg(dev, "Mapped %d chunks/%d KB for ICM aux.\n", tc, ts);
637 mthca_dbg(dev, "Mapped %d chunks/%d KB at %llx for ICM.\n",
638 tc, ts, (unsigned long long) virt - (ts << 10));
643 mthca_free_mailbox(dev, mailbox);
647 int mthca_MAP_FA(struct mthca_dev *dev, struct mthca_icm *icm, u8 *status)
649 return mthca_map_cmd(dev, CMD_MAP_FA, icm, -1, status);
652 int mthca_UNMAP_FA(struct mthca_dev *dev, u8 *status)
654 return mthca_cmd(dev, 0, 0, 0, CMD_UNMAP_FA, CMD_TIME_CLASS_B, status);
657 int mthca_RUN_FW(struct mthca_dev *dev, u8 *status)
659 return mthca_cmd(dev, 0, 0, 0, CMD_RUN_FW, CMD_TIME_CLASS_A, status);
662 int mthca_QUERY_FW(struct mthca_dev *dev, u8 *status)
664 struct mthca_mailbox *mailbox;
669 #define QUERY_FW_OUT_SIZE 0x100
670 #define QUERY_FW_VER_OFFSET 0x00
671 #define QUERY_FW_MAX_CMD_OFFSET 0x0f
672 #define QUERY_FW_ERR_START_OFFSET 0x30
673 #define QUERY_FW_ERR_SIZE_OFFSET 0x38
675 #define QUERY_FW_START_OFFSET 0x20
676 #define QUERY_FW_END_OFFSET 0x28
678 #define QUERY_FW_SIZE_OFFSET 0x00
679 #define QUERY_FW_CLR_INT_BASE_OFFSET 0x20
680 #define QUERY_FW_EQ_ARM_BASE_OFFSET 0x40
681 #define QUERY_FW_EQ_SET_CI_BASE_OFFSET 0x48
683 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
685 return PTR_ERR(mailbox);
686 outbox = mailbox->buf;
688 err = mthca_cmd_box(dev, 0, mailbox->dma, 0, 0, CMD_QUERY_FW,
689 CMD_TIME_CLASS_A, status);
694 MTHCA_GET(dev->fw_ver, outbox, QUERY_FW_VER_OFFSET);
696 * FW subminor version is at more signifant bits than minor
697 * version, so swap here.
699 dev->fw_ver = (dev->fw_ver & 0xffff00000000ull) |
700 ((dev->fw_ver & 0xffff0000ull) >> 16) |
701 ((dev->fw_ver & 0x0000ffffull) << 16);
703 MTHCA_GET(lg, outbox, QUERY_FW_MAX_CMD_OFFSET);
704 dev->cmd.max_cmds = 1 << lg;
706 mthca_dbg(dev, "FW version %012llx, max commands %d\n",
707 (unsigned long long) dev->fw_ver, dev->cmd.max_cmds);
709 if (mthca_is_memfree(dev)) {
710 MTHCA_GET(dev->fw.arbel.fw_pages, outbox, QUERY_FW_SIZE_OFFSET);
711 MTHCA_GET(dev->fw.arbel.clr_int_base, outbox, QUERY_FW_CLR_INT_BASE_OFFSET);
712 MTHCA_GET(dev->fw.arbel.eq_arm_base, outbox, QUERY_FW_EQ_ARM_BASE_OFFSET);
713 MTHCA_GET(dev->fw.arbel.eq_set_ci_base, outbox, QUERY_FW_EQ_SET_CI_BASE_OFFSET);
714 mthca_dbg(dev, "FW size %d KB\n", dev->fw.arbel.fw_pages << 2);
717 * Arbel page size is always 4 KB; round up number of
718 * system pages needed.
720 dev->fw.arbel.fw_pages =
721 (dev->fw.arbel.fw_pages + (1 << (PAGE_SHIFT - 12)) - 1) >>
724 mthca_dbg(dev, "Clear int @ %llx, EQ arm @ %llx, EQ set CI @ %llx\n",
725 (unsigned long long) dev->fw.arbel.clr_int_base,
726 (unsigned long long) dev->fw.arbel.eq_arm_base,
727 (unsigned long long) dev->fw.arbel.eq_set_ci_base);
729 MTHCA_GET(dev->fw.tavor.fw_start, outbox, QUERY_FW_START_OFFSET);
730 MTHCA_GET(dev->fw.tavor.fw_end, outbox, QUERY_FW_END_OFFSET);
732 mthca_dbg(dev, "FW size %d KB (start %llx, end %llx)\n",
733 (int) ((dev->fw.tavor.fw_end - dev->fw.tavor.fw_start) >> 10),
734 (unsigned long long) dev->fw.tavor.fw_start,
735 (unsigned long long) dev->fw.tavor.fw_end);
739 mthca_free_mailbox(dev, mailbox);
743 int mthca_ENABLE_LAM(struct mthca_dev *dev, u8 *status)
745 struct mthca_mailbox *mailbox;
750 #define ENABLE_LAM_OUT_SIZE 0x100
751 #define ENABLE_LAM_START_OFFSET 0x00
752 #define ENABLE_LAM_END_OFFSET 0x08
753 #define ENABLE_LAM_INFO_OFFSET 0x13
755 #define ENABLE_LAM_INFO_HIDDEN_FLAG (1 << 4)
756 #define ENABLE_LAM_INFO_ECC_MASK 0x3
758 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
760 return PTR_ERR(mailbox);
761 outbox = mailbox->buf;
763 err = mthca_cmd_box(dev, 0, mailbox->dma, 0, 0, CMD_ENABLE_LAM,
764 CMD_TIME_CLASS_C, status);
769 if (*status == MTHCA_CMD_STAT_LAM_NOT_PRE)
772 MTHCA_GET(dev->ddr_start, outbox, ENABLE_LAM_START_OFFSET);
773 MTHCA_GET(dev->ddr_end, outbox, ENABLE_LAM_END_OFFSET);
774 MTHCA_GET(info, outbox, ENABLE_LAM_INFO_OFFSET);
776 if (!!(info & ENABLE_LAM_INFO_HIDDEN_FLAG) !=
777 !!(dev->mthca_flags & MTHCA_FLAG_DDR_HIDDEN)) {
778 mthca_info(dev, "FW reports that HCA-attached memory "
779 "is %s hidden; does not match PCI config\n",
780 (info & ENABLE_LAM_INFO_HIDDEN_FLAG) ?
783 if (info & ENABLE_LAM_INFO_HIDDEN_FLAG)
784 mthca_dbg(dev, "HCA-attached memory is hidden.\n");
786 mthca_dbg(dev, "HCA memory size %d KB (start %llx, end %llx)\n",
787 (int) ((dev->ddr_end - dev->ddr_start) >> 10),
788 (unsigned long long) dev->ddr_start,
789 (unsigned long long) dev->ddr_end);
792 mthca_free_mailbox(dev, mailbox);
796 int mthca_DISABLE_LAM(struct mthca_dev *dev, u8 *status)
798 return mthca_cmd(dev, 0, 0, 0, CMD_SYS_DIS, CMD_TIME_CLASS_C, status);
801 int mthca_QUERY_DDR(struct mthca_dev *dev, u8 *status)
803 struct mthca_mailbox *mailbox;
808 #define QUERY_DDR_OUT_SIZE 0x100
809 #define QUERY_DDR_START_OFFSET 0x00
810 #define QUERY_DDR_END_OFFSET 0x08
811 #define QUERY_DDR_INFO_OFFSET 0x13
813 #define QUERY_DDR_INFO_HIDDEN_FLAG (1 << 4)
814 #define QUERY_DDR_INFO_ECC_MASK 0x3
816 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
818 return PTR_ERR(mailbox);
819 outbox = mailbox->buf;
821 err = mthca_cmd_box(dev, 0, mailbox->dma, 0, 0, CMD_QUERY_DDR,
822 CMD_TIME_CLASS_A, status);
827 MTHCA_GET(dev->ddr_start, outbox, QUERY_DDR_START_OFFSET);
828 MTHCA_GET(dev->ddr_end, outbox, QUERY_DDR_END_OFFSET);
829 MTHCA_GET(info, outbox, QUERY_DDR_INFO_OFFSET);
831 if (!!(info & QUERY_DDR_INFO_HIDDEN_FLAG) !=
832 !!(dev->mthca_flags & MTHCA_FLAG_DDR_HIDDEN)) {
833 mthca_info(dev, "FW reports that HCA-attached memory "
834 "is %s hidden; does not match PCI config\n",
835 (info & QUERY_DDR_INFO_HIDDEN_FLAG) ?
838 if (info & QUERY_DDR_INFO_HIDDEN_FLAG)
839 mthca_dbg(dev, "HCA-attached memory is hidden.\n");
841 mthca_dbg(dev, "HCA memory size %d KB (start %llx, end %llx)\n",
842 (int) ((dev->ddr_end - dev->ddr_start) >> 10),
843 (unsigned long long) dev->ddr_start,
844 (unsigned long long) dev->ddr_end);
847 mthca_free_mailbox(dev, mailbox);
851 int mthca_QUERY_DEV_LIM(struct mthca_dev *dev,
852 struct mthca_dev_lim *dev_lim, u8 *status)
854 struct mthca_mailbox *mailbox;
860 #define QUERY_DEV_LIM_OUT_SIZE 0x100
861 #define QUERY_DEV_LIM_MAX_SRQ_SZ_OFFSET 0x10
862 #define QUERY_DEV_LIM_MAX_QP_SZ_OFFSET 0x11
863 #define QUERY_DEV_LIM_RSVD_QP_OFFSET 0x12
864 #define QUERY_DEV_LIM_MAX_QP_OFFSET 0x13
865 #define QUERY_DEV_LIM_RSVD_SRQ_OFFSET 0x14
866 #define QUERY_DEV_LIM_MAX_SRQ_OFFSET 0x15
867 #define QUERY_DEV_LIM_RSVD_EEC_OFFSET 0x16
868 #define QUERY_DEV_LIM_MAX_EEC_OFFSET 0x17
869 #define QUERY_DEV_LIM_MAX_CQ_SZ_OFFSET 0x19
870 #define QUERY_DEV_LIM_RSVD_CQ_OFFSET 0x1a
871 #define QUERY_DEV_LIM_MAX_CQ_OFFSET 0x1b
872 #define QUERY_DEV_LIM_MAX_MPT_OFFSET 0x1d
873 #define QUERY_DEV_LIM_RSVD_EQ_OFFSET 0x1e
874 #define QUERY_DEV_LIM_MAX_EQ_OFFSET 0x1f
875 #define QUERY_DEV_LIM_RSVD_MTT_OFFSET 0x20
876 #define QUERY_DEV_LIM_MAX_MRW_SZ_OFFSET 0x21
877 #define QUERY_DEV_LIM_RSVD_MRW_OFFSET 0x22
878 #define QUERY_DEV_LIM_MAX_MTT_SEG_OFFSET 0x23
879 #define QUERY_DEV_LIM_MAX_AV_OFFSET 0x27
880 #define QUERY_DEV_LIM_MAX_REQ_QP_OFFSET 0x29
881 #define QUERY_DEV_LIM_MAX_RES_QP_OFFSET 0x2b
882 #define QUERY_DEV_LIM_MAX_RDMA_OFFSET 0x2f
883 #define QUERY_DEV_LIM_RSZ_SRQ_OFFSET 0x33
884 #define QUERY_DEV_LIM_ACK_DELAY_OFFSET 0x35
885 #define QUERY_DEV_LIM_MTU_WIDTH_OFFSET 0x36
886 #define QUERY_DEV_LIM_VL_PORT_OFFSET 0x37
887 #define QUERY_DEV_LIM_MAX_GID_OFFSET 0x3b
888 #define QUERY_DEV_LIM_MAX_PKEY_OFFSET 0x3f
889 #define QUERY_DEV_LIM_FLAGS_OFFSET 0x44
890 #define QUERY_DEV_LIM_RSVD_UAR_OFFSET 0x48
891 #define QUERY_DEV_LIM_UAR_SZ_OFFSET 0x49
892 #define QUERY_DEV_LIM_PAGE_SZ_OFFSET 0x4b
893 #define QUERY_DEV_LIM_MAX_SG_OFFSET 0x51
894 #define QUERY_DEV_LIM_MAX_DESC_SZ_OFFSET 0x52
895 #define QUERY_DEV_LIM_MAX_SG_RQ_OFFSET 0x55
896 #define QUERY_DEV_LIM_MAX_DESC_SZ_RQ_OFFSET 0x56
897 #define QUERY_DEV_LIM_MAX_QP_MCG_OFFSET 0x61
898 #define QUERY_DEV_LIM_RSVD_MCG_OFFSET 0x62
899 #define QUERY_DEV_LIM_MAX_MCG_OFFSET 0x63
900 #define QUERY_DEV_LIM_RSVD_PD_OFFSET 0x64
901 #define QUERY_DEV_LIM_MAX_PD_OFFSET 0x65
902 #define QUERY_DEV_LIM_RSVD_RDD_OFFSET 0x66
903 #define QUERY_DEV_LIM_MAX_RDD_OFFSET 0x67
904 #define QUERY_DEV_LIM_EEC_ENTRY_SZ_OFFSET 0x80
905 #define QUERY_DEV_LIM_QPC_ENTRY_SZ_OFFSET 0x82
906 #define QUERY_DEV_LIM_EEEC_ENTRY_SZ_OFFSET 0x84
907 #define QUERY_DEV_LIM_EQPC_ENTRY_SZ_OFFSET 0x86
908 #define QUERY_DEV_LIM_EQC_ENTRY_SZ_OFFSET 0x88
909 #define QUERY_DEV_LIM_CQC_ENTRY_SZ_OFFSET 0x8a
910 #define QUERY_DEV_LIM_SRQ_ENTRY_SZ_OFFSET 0x8c
911 #define QUERY_DEV_LIM_UAR_ENTRY_SZ_OFFSET 0x8e
912 #define QUERY_DEV_LIM_MTT_ENTRY_SZ_OFFSET 0x90
913 #define QUERY_DEV_LIM_MPT_ENTRY_SZ_OFFSET 0x92
914 #define QUERY_DEV_LIM_PBL_SZ_OFFSET 0x96
915 #define QUERY_DEV_LIM_BMME_FLAGS_OFFSET 0x97
916 #define QUERY_DEV_LIM_RSVD_LKEY_OFFSET 0x98
917 #define QUERY_DEV_LIM_LAMR_OFFSET 0x9f
918 #define QUERY_DEV_LIM_MAX_ICM_SZ_OFFSET 0xa0
920 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
922 return PTR_ERR(mailbox);
923 outbox = mailbox->buf;
925 err = mthca_cmd_box(dev, 0, mailbox->dma, 0, 0, CMD_QUERY_DEV_LIM,
926 CMD_TIME_CLASS_A, status);
931 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_SRQ_SZ_OFFSET);
932 dev_lim->max_srq_sz = 1 << field;
933 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_QP_SZ_OFFSET);
934 dev_lim->max_qp_sz = 1 << field;
935 MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_QP_OFFSET);
936 dev_lim->reserved_qps = 1 << (field & 0xf);
937 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_QP_OFFSET);
938 dev_lim->max_qps = 1 << (field & 0x1f);
939 MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_SRQ_OFFSET);
940 dev_lim->reserved_srqs = 1 << (field >> 4);
941 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_SRQ_OFFSET);
942 dev_lim->max_srqs = 1 << (field & 0x1f);
943 MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_EEC_OFFSET);
944 dev_lim->reserved_eecs = 1 << (field & 0xf);
945 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_EEC_OFFSET);
946 dev_lim->max_eecs = 1 << (field & 0x1f);
947 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_CQ_SZ_OFFSET);
948 dev_lim->max_cq_sz = 1 << field;
949 MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_CQ_OFFSET);
950 dev_lim->reserved_cqs = 1 << (field & 0xf);
951 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_CQ_OFFSET);
952 dev_lim->max_cqs = 1 << (field & 0x1f);
953 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_MPT_OFFSET);
954 dev_lim->max_mpts = 1 << (field & 0x3f);
955 MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_EQ_OFFSET);
956 dev_lim->reserved_eqs = 1 << (field & 0xf);
957 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_EQ_OFFSET);
958 dev_lim->max_eqs = 1 << (field & 0x7);
959 MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_MTT_OFFSET);
960 dev_lim->reserved_mtts = 1 << (field >> 4);
961 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_MRW_SZ_OFFSET);
962 dev_lim->max_mrw_sz = 1 << field;
963 MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_MRW_OFFSET);
964 dev_lim->reserved_mrws = 1 << (field & 0xf);
965 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_MTT_SEG_OFFSET);
966 dev_lim->max_mtt_seg = 1 << (field & 0x3f);
967 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_REQ_QP_OFFSET);
968 dev_lim->max_requester_per_qp = 1 << (field & 0x3f);
969 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_RES_QP_OFFSET);
970 dev_lim->max_responder_per_qp = 1 << (field & 0x3f);
971 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_RDMA_OFFSET);
972 dev_lim->max_rdma_global = 1 << (field & 0x3f);
973 MTHCA_GET(field, outbox, QUERY_DEV_LIM_ACK_DELAY_OFFSET);
974 dev_lim->local_ca_ack_delay = field & 0x1f;
975 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MTU_WIDTH_OFFSET);
976 dev_lim->max_mtu = field >> 4;
977 dev_lim->max_port_width = field & 0xf;
978 MTHCA_GET(field, outbox, QUERY_DEV_LIM_VL_PORT_OFFSET);
979 dev_lim->max_vl = field >> 4;
980 dev_lim->num_ports = field & 0xf;
981 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_GID_OFFSET);
982 dev_lim->max_gids = 1 << (field & 0xf);
983 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_PKEY_OFFSET);
984 dev_lim->max_pkeys = 1 << (field & 0xf);
985 MTHCA_GET(dev_lim->flags, outbox, QUERY_DEV_LIM_FLAGS_OFFSET);
986 MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_UAR_OFFSET);
987 dev_lim->reserved_uars = field >> 4;
988 MTHCA_GET(field, outbox, QUERY_DEV_LIM_UAR_SZ_OFFSET);
989 dev_lim->uar_size = 1 << ((field & 0x3f) + 20);
990 MTHCA_GET(field, outbox, QUERY_DEV_LIM_PAGE_SZ_OFFSET);
991 dev_lim->min_page_sz = 1 << field;
992 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_SG_OFFSET);
993 dev_lim->max_sg = field;
995 MTHCA_GET(size, outbox, QUERY_DEV_LIM_MAX_DESC_SZ_OFFSET);
996 dev_lim->max_desc_sz = size;
998 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_QP_MCG_OFFSET);
999 dev_lim->max_qp_per_mcg = 1 << field;
1000 MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_MCG_OFFSET);
1001 dev_lim->reserved_mgms = field & 0xf;
1002 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_MCG_OFFSET);
1003 dev_lim->max_mcgs = 1 << field;
1004 MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_PD_OFFSET);
1005 dev_lim->reserved_pds = field >> 4;
1006 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_PD_OFFSET);
1007 dev_lim->max_pds = 1 << (field & 0x3f);
1008 MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_RDD_OFFSET);
1009 dev_lim->reserved_rdds = field >> 4;
1010 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_RDD_OFFSET);
1011 dev_lim->max_rdds = 1 << (field & 0x3f);
1013 MTHCA_GET(size, outbox, QUERY_DEV_LIM_EEC_ENTRY_SZ_OFFSET);
1014 dev_lim->eec_entry_sz = size;
1015 MTHCA_GET(size, outbox, QUERY_DEV_LIM_QPC_ENTRY_SZ_OFFSET);
1016 dev_lim->qpc_entry_sz = size;
1017 MTHCA_GET(size, outbox, QUERY_DEV_LIM_EEEC_ENTRY_SZ_OFFSET);
1018 dev_lim->eeec_entry_sz = size;
1019 MTHCA_GET(size, outbox, QUERY_DEV_LIM_EQPC_ENTRY_SZ_OFFSET);
1020 dev_lim->eqpc_entry_sz = size;
1021 MTHCA_GET(size, outbox, QUERY_DEV_LIM_EQC_ENTRY_SZ_OFFSET);
1022 dev_lim->eqc_entry_sz = size;
1023 MTHCA_GET(size, outbox, QUERY_DEV_LIM_CQC_ENTRY_SZ_OFFSET);
1024 dev_lim->cqc_entry_sz = size;
1025 MTHCA_GET(size, outbox, QUERY_DEV_LIM_SRQ_ENTRY_SZ_OFFSET);
1026 dev_lim->srq_entry_sz = size;
1027 MTHCA_GET(size, outbox, QUERY_DEV_LIM_UAR_ENTRY_SZ_OFFSET);
1028 dev_lim->uar_scratch_entry_sz = size;
1030 mthca_dbg(dev, "Max QPs: %d, reserved QPs: %d, entry size: %d\n",
1031 dev_lim->max_qps, dev_lim->reserved_qps, dev_lim->qpc_entry_sz);
1032 mthca_dbg(dev, "Max CQs: %d, reserved CQs: %d, entry size: %d\n",
1033 dev_lim->max_cqs, dev_lim->reserved_cqs, dev_lim->cqc_entry_sz);
1034 mthca_dbg(dev, "Max EQs: %d, reserved EQs: %d, entry size: %d\n",
1035 dev_lim->max_eqs, dev_lim->reserved_eqs, dev_lim->eqc_entry_sz);
1036 mthca_dbg(dev, "reserved MPTs: %d, reserved MTTs: %d\n",
1037 dev_lim->reserved_mrws, dev_lim->reserved_mtts);
1038 mthca_dbg(dev, "Max PDs: %d, reserved PDs: %d, reserved UARs: %d\n",
1039 dev_lim->max_pds, dev_lim->reserved_pds, dev_lim->reserved_uars);
1040 mthca_dbg(dev, "Max QP/MCG: %d, reserved MGMs: %d\n",
1041 dev_lim->max_pds, dev_lim->reserved_mgms);
1043 mthca_dbg(dev, "Flags: %08x\n", dev_lim->flags);
1045 if (mthca_is_memfree(dev)) {
1046 MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSZ_SRQ_OFFSET);
1047 dev_lim->hca.arbel.resize_srq = field & 1;
1048 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_SG_RQ_OFFSET);
1049 dev_lim->max_sg = min_t(int, field, dev_lim->max_sg);
1050 MTHCA_GET(size, outbox, QUERY_DEV_LIM_MPT_ENTRY_SZ_OFFSET);
1051 dev_lim->mpt_entry_sz = size;
1052 MTHCA_GET(field, outbox, QUERY_DEV_LIM_PBL_SZ_OFFSET);
1053 dev_lim->hca.arbel.max_pbl_sz = 1 << (field & 0x3f);
1054 MTHCA_GET(dev_lim->hca.arbel.bmme_flags, outbox,
1055 QUERY_DEV_LIM_BMME_FLAGS_OFFSET);
1056 MTHCA_GET(dev_lim->hca.arbel.reserved_lkey, outbox,
1057 QUERY_DEV_LIM_RSVD_LKEY_OFFSET);
1058 MTHCA_GET(field, outbox, QUERY_DEV_LIM_LAMR_OFFSET);
1059 dev_lim->hca.arbel.lam_required = field & 1;
1060 MTHCA_GET(dev_lim->hca.arbel.max_icm_sz, outbox,
1061 QUERY_DEV_LIM_MAX_ICM_SZ_OFFSET);
1063 if (dev_lim->hca.arbel.bmme_flags & 1)
1064 mthca_dbg(dev, "Base MM extensions: yes "
1065 "(flags %d, max PBL %d, rsvd L_Key %08x)\n",
1066 dev_lim->hca.arbel.bmme_flags,
1067 dev_lim->hca.arbel.max_pbl_sz,
1068 dev_lim->hca.arbel.reserved_lkey);
1070 mthca_dbg(dev, "Base MM extensions: no\n");
1072 mthca_dbg(dev, "Max ICM size %lld MB\n",
1073 (unsigned long long) dev_lim->hca.arbel.max_icm_sz >> 20);
1075 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_AV_OFFSET);
1076 dev_lim->hca.tavor.max_avs = 1 << (field & 0x3f);
1077 dev_lim->mpt_entry_sz = MTHCA_MPT_ENTRY_SIZE;
1081 mthca_free_mailbox(dev, mailbox);
1085 int mthca_QUERY_ADAPTER(struct mthca_dev *dev,
1086 struct mthca_adapter *adapter, u8 *status)
1088 struct mthca_mailbox *mailbox;
1092 #define QUERY_ADAPTER_OUT_SIZE 0x100
1093 #define QUERY_ADAPTER_VENDOR_ID_OFFSET 0x00
1094 #define QUERY_ADAPTER_DEVICE_ID_OFFSET 0x04
1095 #define QUERY_ADAPTER_REVISION_ID_OFFSET 0x08
1096 #define QUERY_ADAPTER_INTA_PIN_OFFSET 0x10
1098 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
1099 if (IS_ERR(mailbox))
1100 return PTR_ERR(mailbox);
1101 outbox = mailbox->buf;
1103 err = mthca_cmd_box(dev, 0, mailbox->dma, 0, 0, CMD_QUERY_ADAPTER,
1104 CMD_TIME_CLASS_A, status);
1109 MTHCA_GET(adapter->vendor_id, outbox, QUERY_ADAPTER_VENDOR_ID_OFFSET);
1110 MTHCA_GET(adapter->device_id, outbox, QUERY_ADAPTER_DEVICE_ID_OFFSET);
1111 MTHCA_GET(adapter->revision_id, outbox, QUERY_ADAPTER_REVISION_ID_OFFSET);
1112 MTHCA_GET(adapter->inta_pin, outbox, QUERY_ADAPTER_INTA_PIN_OFFSET);
1115 mthca_free_mailbox(dev, mailbox);
1119 int mthca_INIT_HCA(struct mthca_dev *dev,
1120 struct mthca_init_hca_param *param,
1123 struct mthca_mailbox *mailbox;
1127 #define INIT_HCA_IN_SIZE 0x200
1128 #define INIT_HCA_FLAGS_OFFSET 0x014
1129 #define INIT_HCA_QPC_OFFSET 0x020
1130 #define INIT_HCA_QPC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x10)
1131 #define INIT_HCA_LOG_QP_OFFSET (INIT_HCA_QPC_OFFSET + 0x17)
1132 #define INIT_HCA_EEC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x20)
1133 #define INIT_HCA_LOG_EEC_OFFSET (INIT_HCA_QPC_OFFSET + 0x27)
1134 #define INIT_HCA_SRQC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x28)
1135 #define INIT_HCA_LOG_SRQ_OFFSET (INIT_HCA_QPC_OFFSET + 0x2f)
1136 #define INIT_HCA_CQC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x30)
1137 #define INIT_HCA_LOG_CQ_OFFSET (INIT_HCA_QPC_OFFSET + 0x37)
1138 #define INIT_HCA_EQPC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x40)
1139 #define INIT_HCA_EEEC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x50)
1140 #define INIT_HCA_EQC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x60)
1141 #define INIT_HCA_LOG_EQ_OFFSET (INIT_HCA_QPC_OFFSET + 0x67)
1142 #define INIT_HCA_RDB_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x70)
1143 #define INIT_HCA_UDAV_OFFSET 0x0b0
1144 #define INIT_HCA_UDAV_LKEY_OFFSET (INIT_HCA_UDAV_OFFSET + 0x0)
1145 #define INIT_HCA_UDAV_PD_OFFSET (INIT_HCA_UDAV_OFFSET + 0x4)
1146 #define INIT_HCA_MCAST_OFFSET 0x0c0
1147 #define INIT_HCA_MC_BASE_OFFSET (INIT_HCA_MCAST_OFFSET + 0x00)
1148 #define INIT_HCA_LOG_MC_ENTRY_SZ_OFFSET (INIT_HCA_MCAST_OFFSET + 0x12)
1149 #define INIT_HCA_MC_HASH_SZ_OFFSET (INIT_HCA_MCAST_OFFSET + 0x16)
1150 #define INIT_HCA_LOG_MC_TABLE_SZ_OFFSET (INIT_HCA_MCAST_OFFSET + 0x1b)
1151 #define INIT_HCA_TPT_OFFSET 0x0f0
1152 #define INIT_HCA_MPT_BASE_OFFSET (INIT_HCA_TPT_OFFSET + 0x00)
1153 #define INIT_HCA_MTT_SEG_SZ_OFFSET (INIT_HCA_TPT_OFFSET + 0x09)
1154 #define INIT_HCA_LOG_MPT_SZ_OFFSET (INIT_HCA_TPT_OFFSET + 0x0b)
1155 #define INIT_HCA_MTT_BASE_OFFSET (INIT_HCA_TPT_OFFSET + 0x10)
1156 #define INIT_HCA_UAR_OFFSET 0x120
1157 #define INIT_HCA_UAR_BASE_OFFSET (INIT_HCA_UAR_OFFSET + 0x00)
1158 #define INIT_HCA_UARC_SZ_OFFSET (INIT_HCA_UAR_OFFSET + 0x09)
1159 #define INIT_HCA_LOG_UAR_SZ_OFFSET (INIT_HCA_UAR_OFFSET + 0x0a)
1160 #define INIT_HCA_UAR_PAGE_SZ_OFFSET (INIT_HCA_UAR_OFFSET + 0x0b)
1161 #define INIT_HCA_UAR_SCATCH_BASE_OFFSET (INIT_HCA_UAR_OFFSET + 0x10)
1162 #define INIT_HCA_UAR_CTX_BASE_OFFSET (INIT_HCA_UAR_OFFSET + 0x18)
1164 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
1165 if (IS_ERR(mailbox))
1166 return PTR_ERR(mailbox);
1167 inbox = mailbox->buf;
1169 memset(inbox, 0, INIT_HCA_IN_SIZE);
1171 #if defined(__LITTLE_ENDIAN)
1172 *(inbox + INIT_HCA_FLAGS_OFFSET / 4) &= ~cpu_to_be32(1 << 1);
1173 #elif defined(__BIG_ENDIAN)
1174 *(inbox + INIT_HCA_FLAGS_OFFSET / 4) |= cpu_to_be32(1 << 1);
1176 #error Host endianness not defined
1178 /* Check port for UD address vector: */
1179 *(inbox + INIT_HCA_FLAGS_OFFSET / 4) |= cpu_to_be32(1);
1181 /* We leave wqe_quota, responder_exu, etc as 0 (default) */
1183 /* QPC/EEC/CQC/EQC/RDB attributes */
1185 MTHCA_PUT(inbox, param->qpc_base, INIT_HCA_QPC_BASE_OFFSET);
1186 MTHCA_PUT(inbox, param->log_num_qps, INIT_HCA_LOG_QP_OFFSET);
1187 MTHCA_PUT(inbox, param->eec_base, INIT_HCA_EEC_BASE_OFFSET);
1188 MTHCA_PUT(inbox, param->log_num_eecs, INIT_HCA_LOG_EEC_OFFSET);
1189 MTHCA_PUT(inbox, param->srqc_base, INIT_HCA_SRQC_BASE_OFFSET);
1190 MTHCA_PUT(inbox, param->log_num_srqs, INIT_HCA_LOG_SRQ_OFFSET);
1191 MTHCA_PUT(inbox, param->cqc_base, INIT_HCA_CQC_BASE_OFFSET);
1192 MTHCA_PUT(inbox, param->log_num_cqs, INIT_HCA_LOG_CQ_OFFSET);
1193 MTHCA_PUT(inbox, param->eqpc_base, INIT_HCA_EQPC_BASE_OFFSET);
1194 MTHCA_PUT(inbox, param->eeec_base, INIT_HCA_EEEC_BASE_OFFSET);
1195 MTHCA_PUT(inbox, param->eqc_base, INIT_HCA_EQC_BASE_OFFSET);
1196 MTHCA_PUT(inbox, param->log_num_eqs, INIT_HCA_LOG_EQ_OFFSET);
1197 MTHCA_PUT(inbox, param->rdb_base, INIT_HCA_RDB_BASE_OFFSET);
1199 /* UD AV attributes */
1201 /* multicast attributes */
1203 MTHCA_PUT(inbox, param->mc_base, INIT_HCA_MC_BASE_OFFSET);
1204 MTHCA_PUT(inbox, param->log_mc_entry_sz, INIT_HCA_LOG_MC_ENTRY_SZ_OFFSET);
1205 MTHCA_PUT(inbox, param->mc_hash_sz, INIT_HCA_MC_HASH_SZ_OFFSET);
1206 MTHCA_PUT(inbox, param->log_mc_table_sz, INIT_HCA_LOG_MC_TABLE_SZ_OFFSET);
1208 /* TPT attributes */
1210 MTHCA_PUT(inbox, param->mpt_base, INIT_HCA_MPT_BASE_OFFSET);
1211 if (!mthca_is_memfree(dev))
1212 MTHCA_PUT(inbox, param->mtt_seg_sz, INIT_HCA_MTT_SEG_SZ_OFFSET);
1213 MTHCA_PUT(inbox, param->log_mpt_sz, INIT_HCA_LOG_MPT_SZ_OFFSET);
1214 MTHCA_PUT(inbox, param->mtt_base, INIT_HCA_MTT_BASE_OFFSET);
1216 /* UAR attributes */
1218 u8 uar_page_sz = PAGE_SHIFT - 12;
1219 MTHCA_PUT(inbox, uar_page_sz, INIT_HCA_UAR_PAGE_SZ_OFFSET);
1222 MTHCA_PUT(inbox, param->uar_scratch_base, INIT_HCA_UAR_SCATCH_BASE_OFFSET);
1224 if (mthca_is_memfree(dev)) {
1225 MTHCA_PUT(inbox, param->log_uarc_sz, INIT_HCA_UARC_SZ_OFFSET);
1226 MTHCA_PUT(inbox, param->log_uar_sz, INIT_HCA_LOG_UAR_SZ_OFFSET);
1227 MTHCA_PUT(inbox, param->uarc_base, INIT_HCA_UAR_CTX_BASE_OFFSET);
1230 err = mthca_cmd(dev, mailbox->dma, 0, 0, CMD_INIT_HCA, HZ, status);
1232 mthca_free_mailbox(dev, mailbox);
1236 int mthca_INIT_IB(struct mthca_dev *dev,
1237 struct mthca_init_ib_param *param,
1238 int port, u8 *status)
1240 struct mthca_mailbox *mailbox;
1245 #define INIT_IB_IN_SIZE 56
1246 #define INIT_IB_FLAGS_OFFSET 0x00
1247 #define INIT_IB_FLAG_SIG (1 << 18)
1248 #define INIT_IB_FLAG_NG (1 << 17)
1249 #define INIT_IB_FLAG_G0 (1 << 16)
1250 #define INIT_IB_FLAG_1X (1 << 8)
1251 #define INIT_IB_FLAG_4X (1 << 9)
1252 #define INIT_IB_FLAG_12X (1 << 11)
1253 #define INIT_IB_VL_SHIFT 4
1254 #define INIT_IB_MTU_SHIFT 12
1255 #define INIT_IB_MAX_GID_OFFSET 0x06
1256 #define INIT_IB_MAX_PKEY_OFFSET 0x0a
1257 #define INIT_IB_GUID0_OFFSET 0x10
1258 #define INIT_IB_NODE_GUID_OFFSET 0x18
1259 #define INIT_IB_SI_GUID_OFFSET 0x20
1261 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
1262 if (IS_ERR(mailbox))
1263 return PTR_ERR(mailbox);
1264 inbox = mailbox->buf;
1266 memset(inbox, 0, INIT_IB_IN_SIZE);
1269 flags |= param->enable_1x ? INIT_IB_FLAG_1X : 0;
1270 flags |= param->enable_4x ? INIT_IB_FLAG_4X : 0;
1271 flags |= param->set_guid0 ? INIT_IB_FLAG_G0 : 0;
1272 flags |= param->set_node_guid ? INIT_IB_FLAG_NG : 0;
1273 flags |= param->set_si_guid ? INIT_IB_FLAG_SIG : 0;
1274 flags |= param->vl_cap << INIT_IB_VL_SHIFT;
1275 flags |= param->mtu_cap << INIT_IB_MTU_SHIFT;
1276 MTHCA_PUT(inbox, flags, INIT_IB_FLAGS_OFFSET);
1278 MTHCA_PUT(inbox, param->gid_cap, INIT_IB_MAX_GID_OFFSET);
1279 MTHCA_PUT(inbox, param->pkey_cap, INIT_IB_MAX_PKEY_OFFSET);
1280 MTHCA_PUT(inbox, param->guid0, INIT_IB_GUID0_OFFSET);
1281 MTHCA_PUT(inbox, param->node_guid, INIT_IB_NODE_GUID_OFFSET);
1282 MTHCA_PUT(inbox, param->si_guid, INIT_IB_SI_GUID_OFFSET);
1284 err = mthca_cmd(dev, mailbox->dma, port, 0, CMD_INIT_IB,
1285 CMD_TIME_CLASS_A, status);
1287 mthca_free_mailbox(dev, mailbox);
1291 int mthca_CLOSE_IB(struct mthca_dev *dev, int port, u8 *status)
1293 return mthca_cmd(dev, 0, port, 0, CMD_CLOSE_IB, HZ, status);
1296 int mthca_CLOSE_HCA(struct mthca_dev *dev, int panic, u8 *status)
1298 return mthca_cmd(dev, 0, 0, panic, CMD_CLOSE_HCA, HZ, status);
1301 int mthca_SET_IB(struct mthca_dev *dev, struct mthca_set_ib_param *param,
1302 int port, u8 *status)
1304 struct mthca_mailbox *mailbox;
1309 #define SET_IB_IN_SIZE 0x40
1310 #define SET_IB_FLAGS_OFFSET 0x00
1311 #define SET_IB_FLAG_SIG (1 << 18)
1312 #define SET_IB_FLAG_RQK (1 << 0)
1313 #define SET_IB_CAP_MASK_OFFSET 0x04
1314 #define SET_IB_SI_GUID_OFFSET 0x08
1316 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
1317 if (IS_ERR(mailbox))
1318 return PTR_ERR(mailbox);
1319 inbox = mailbox->buf;
1321 memset(inbox, 0, SET_IB_IN_SIZE);
1323 flags |= param->set_si_guid ? SET_IB_FLAG_SIG : 0;
1324 flags |= param->reset_qkey_viol ? SET_IB_FLAG_RQK : 0;
1325 MTHCA_PUT(inbox, flags, SET_IB_FLAGS_OFFSET);
1327 MTHCA_PUT(inbox, param->cap_mask, SET_IB_CAP_MASK_OFFSET);
1328 MTHCA_PUT(inbox, param->si_guid, SET_IB_SI_GUID_OFFSET);
1330 err = mthca_cmd(dev, mailbox->dma, port, 0, CMD_SET_IB,
1331 CMD_TIME_CLASS_B, status);
1333 mthca_free_mailbox(dev, mailbox);
1337 int mthca_MAP_ICM(struct mthca_dev *dev, struct mthca_icm *icm, u64 virt, u8 *status)
1339 return mthca_map_cmd(dev, CMD_MAP_ICM, icm, virt, status);
1342 int mthca_MAP_ICM_page(struct mthca_dev *dev, u64 dma_addr, u64 virt, u8 *status)
1344 struct mthca_mailbox *mailbox;
1348 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
1349 if (IS_ERR(mailbox))
1350 return PTR_ERR(mailbox);
1351 inbox = mailbox->buf;
1353 inbox[0] = cpu_to_be64(virt);
1354 inbox[1] = cpu_to_be64(dma_addr);
1356 err = mthca_cmd(dev, mailbox->dma, 1, 0, CMD_MAP_ICM,
1357 CMD_TIME_CLASS_B, status);
1359 mthca_free_mailbox(dev, mailbox);
1362 mthca_dbg(dev, "Mapped page at %llx to %llx for ICM.\n",
1363 (unsigned long long) dma_addr, (unsigned long long) virt);
1368 int mthca_UNMAP_ICM(struct mthca_dev *dev, u64 virt, u32 page_count, u8 *status)
1370 mthca_dbg(dev, "Unmapping %d pages at %llx from ICM.\n",
1371 page_count, (unsigned long long) virt);
1373 return mthca_cmd(dev, virt, page_count, 0, CMD_UNMAP_ICM, CMD_TIME_CLASS_B, status);
1376 int mthca_MAP_ICM_AUX(struct mthca_dev *dev, struct mthca_icm *icm, u8 *status)
1378 return mthca_map_cmd(dev, CMD_MAP_ICM_AUX, icm, -1, status);
1381 int mthca_UNMAP_ICM_AUX(struct mthca_dev *dev, u8 *status)
1383 return mthca_cmd(dev, 0, 0, 0, CMD_UNMAP_ICM_AUX, CMD_TIME_CLASS_B, status);
1386 int mthca_SET_ICM_SIZE(struct mthca_dev *dev, u64 icm_size, u64 *aux_pages,
1389 int ret = mthca_cmd_imm(dev, icm_size, aux_pages, 0, 0, CMD_SET_ICM_SIZE,
1390 CMD_TIME_CLASS_A, status);
1396 * Arbel page size is always 4 KB; round up number of system
1399 *aux_pages = (*aux_pages + (1 << (PAGE_SHIFT - 12)) - 1) >> (PAGE_SHIFT - 12);
1404 int mthca_SW2HW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
1405 int mpt_index, u8 *status)
1407 return mthca_cmd(dev, mailbox->dma, mpt_index, 0, CMD_SW2HW_MPT,
1408 CMD_TIME_CLASS_B, status);
1411 int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
1412 int mpt_index, u8 *status)
1414 return mthca_cmd_box(dev, 0, mailbox ? mailbox->dma : 0, mpt_index,
1415 !mailbox, CMD_HW2SW_MPT,
1416 CMD_TIME_CLASS_B, status);
1419 int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
1420 int num_mtt, u8 *status)
1422 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
1423 CMD_TIME_CLASS_B, status);
1426 int mthca_SYNC_TPT(struct mthca_dev *dev, u8 *status)
1428 return mthca_cmd(dev, 0, 0, 0, CMD_SYNC_TPT, CMD_TIME_CLASS_B, status);
1431 int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
1432 int eq_num, u8 *status)
1434 mthca_dbg(dev, "%s mask %016llx for eqn %d\n",
1435 unmap ? "Clearing" : "Setting",
1436 (unsigned long long) event_mask, eq_num);
1437 return mthca_cmd(dev, event_mask, (unmap << 31) | eq_num,
1438 0, CMD_MAP_EQ, CMD_TIME_CLASS_B, status);
1441 int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
1442 int eq_num, u8 *status)
1444 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
1445 CMD_TIME_CLASS_A, status);
1448 int mthca_HW2SW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
1449 int eq_num, u8 *status)
1451 return mthca_cmd_box(dev, 0, mailbox->dma, eq_num, 0,
1453 CMD_TIME_CLASS_A, status);
1456 int mthca_SW2HW_CQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
1457 int cq_num, u8 *status)
1459 return mthca_cmd(dev, mailbox->dma, cq_num, 0, CMD_SW2HW_CQ,
1460 CMD_TIME_CLASS_A, status);
1463 int mthca_HW2SW_CQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
1464 int cq_num, u8 *status)
1466 return mthca_cmd_box(dev, 0, mailbox->dma, cq_num, 0,
1468 CMD_TIME_CLASS_A, status);
1471 int mthca_MODIFY_QP(struct mthca_dev *dev, int trans, u32 num,
1472 int is_ee, struct mthca_mailbox *mailbox, u32 optmask,
1475 static const u16 op[] = {
1476 [MTHCA_TRANS_RST2INIT] = CMD_RST2INIT_QPEE,
1477 [MTHCA_TRANS_INIT2INIT] = CMD_INIT2INIT_QPEE,
1478 [MTHCA_TRANS_INIT2RTR] = CMD_INIT2RTR_QPEE,
1479 [MTHCA_TRANS_RTR2RTS] = CMD_RTR2RTS_QPEE,
1480 [MTHCA_TRANS_RTS2RTS] = CMD_RTS2RTS_QPEE,
1481 [MTHCA_TRANS_SQERR2RTS] = CMD_SQERR2RTS_QPEE,
1482 [MTHCA_TRANS_ANY2ERR] = CMD_2ERR_QPEE,
1483 [MTHCA_TRANS_RTS2SQD] = CMD_RTS2SQD_QPEE,
1484 [MTHCA_TRANS_SQD2SQD] = CMD_SQD2SQD_QPEE,
1485 [MTHCA_TRANS_SQD2RTS] = CMD_SQD2RTS_QPEE,
1486 [MTHCA_TRANS_ANY2RST] = CMD_ERR2RST_QPEE
1492 if (trans < 0 || trans >= ARRAY_SIZE(op))
1495 if (trans == MTHCA_TRANS_ANY2RST) {
1496 op_mod = 3; /* don't write outbox, any->reset */
1500 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
1501 if (!IS_ERR(mailbox)) {
1503 op_mod = 2; /* write outbox, any->reset */
1510 mthca_dbg(dev, "Dumping QP context:\n");
1511 printk(" opt param mask: %08x\n", be32_to_cpup(mailbox->buf));
1512 for (i = 0; i < 0x100 / 4; ++i) {
1514 printk(" [%02x] ", i * 4);
1516 be32_to_cpu(((u32 *) mailbox->buf)[i + 2]));
1517 if ((i + 1) % 8 == 0)
1523 if (trans == MTHCA_TRANS_ANY2RST) {
1524 err = mthca_cmd_box(dev, 0, mailbox ? mailbox->dma : 0,
1525 (!!is_ee << 24) | num, op_mod,
1526 op[trans], CMD_TIME_CLASS_C, status);
1530 mthca_dbg(dev, "Dumping QP context:\n");
1531 printk(" %08x\n", be32_to_cpup(mailbox->buf));
1532 for (i = 0; i < 0x100 / 4; ++i) {
1534 printk("[%02x] ", i * 4);
1536 be32_to_cpu(((u32 *) mailbox->buf)[i + 2]));
1537 if ((i + 1) % 8 == 0)
1543 err = mthca_cmd(dev, mailbox->dma, (!!is_ee << 24) | num,
1544 op_mod, op[trans], CMD_TIME_CLASS_C, status);
1547 mthca_free_mailbox(dev, mailbox);
1552 int mthca_QUERY_QP(struct mthca_dev *dev, u32 num, int is_ee,
1553 struct mthca_mailbox *mailbox, u8 *status)
1555 return mthca_cmd_box(dev, 0, mailbox->dma, (!!is_ee << 24) | num, 0,
1556 CMD_QUERY_QPEE, CMD_TIME_CLASS_A, status);
1559 int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn,
1571 case IB_QPT_RAW_IPV6:
1574 case IB_QPT_RAW_ETY:
1581 return mthca_cmd(dev, 0, qpn, op_mod, CMD_CONF_SPECIAL_QP,
1582 CMD_TIME_CLASS_B, status);
1585 int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
1586 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
1587 void *in_mad, void *response_mad, u8 *status)
1589 struct mthca_mailbox *inmailbox, *outmailbox;
1592 u32 in_modifier = port;
1595 #define MAD_IFC_BOX_SIZE 0x400
1596 #define MAD_IFC_MY_QPN_OFFSET 0x100
1597 #define MAD_IFC_RQPN_OFFSET 0x104
1598 #define MAD_IFC_SL_OFFSET 0x108
1599 #define MAD_IFC_G_PATH_OFFSET 0x109
1600 #define MAD_IFC_RLID_OFFSET 0x10a
1601 #define MAD_IFC_PKEY_OFFSET 0x10e
1602 #define MAD_IFC_GRH_OFFSET 0x140
1604 inmailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
1605 if (IS_ERR(inmailbox))
1606 return PTR_ERR(inmailbox);
1607 inbox = inmailbox->buf;
1609 outmailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
1610 if (IS_ERR(outmailbox)) {
1611 mthca_free_mailbox(dev, inmailbox);
1612 return PTR_ERR(outmailbox);
1615 memcpy(inbox, in_mad, 256);
1618 * Key check traps can't be generated unless we have in_wc to
1619 * tell us where to send the trap.
1621 if (ignore_mkey || !in_wc)
1623 if (ignore_bkey || !in_wc)
1629 memset(inbox + 256, 0, 256);
1631 MTHCA_PUT(inbox, in_wc->qp_num, MAD_IFC_MY_QPN_OFFSET);
1632 MTHCA_PUT(inbox, in_wc->src_qp, MAD_IFC_RQPN_OFFSET);
1634 val = in_wc->sl << 4;
1635 MTHCA_PUT(inbox, val, MAD_IFC_SL_OFFSET);
1637 val = in_wc->dlid_path_bits |
1638 (in_wc->wc_flags & IB_WC_GRH ? 0x80 : 0);
1639 MTHCA_PUT(inbox, val, MAD_IFC_GRH_OFFSET);
1641 MTHCA_PUT(inbox, in_wc->slid, MAD_IFC_RLID_OFFSET);
1642 MTHCA_PUT(inbox, in_wc->pkey_index, MAD_IFC_PKEY_OFFSET);
1645 memcpy(inbox + MAD_IFC_GRH_OFFSET, in_grh, 40);
1647 op_modifier |= 0x10;
1649 in_modifier |= in_wc->slid << 16;
1652 err = mthca_cmd_box(dev, inmailbox->dma, outmailbox->dma,
1653 in_modifier, op_modifier,
1654 CMD_MAD_IFC, CMD_TIME_CLASS_C, status);
1656 if (!err && !*status)
1657 memcpy(response_mad, outmailbox->buf, 256);
1659 mthca_free_mailbox(dev, inmailbox);
1660 mthca_free_mailbox(dev, outmailbox);
1664 int mthca_READ_MGM(struct mthca_dev *dev, int index,
1665 struct mthca_mailbox *mailbox, u8 *status)
1667 return mthca_cmd_box(dev, 0, mailbox->dma, index, 0,
1668 CMD_READ_MGM, CMD_TIME_CLASS_A, status);
1671 int mthca_WRITE_MGM(struct mthca_dev *dev, int index,
1672 struct mthca_mailbox *mailbox, u8 *status)
1674 return mthca_cmd(dev, mailbox->dma, index, 0, CMD_WRITE_MGM,
1675 CMD_TIME_CLASS_A, status);
1678 int mthca_MGID_HASH(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
1679 u16 *hash, u8 *status)
1684 err = mthca_cmd_imm(dev, mailbox->dma, &imm, 0, 0, CMD_MGID_HASH,
1685 CMD_TIME_CLASS_A, status);
1691 int mthca_NOP(struct mthca_dev *dev, u8 *status)
1693 return mthca_cmd(dev, 0, 0x1f, 0, CMD_NOP, msecs_to_jiffies(100), status);