11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved. 32a1d9b7fSRoland Dreier * Copyright (c) 2005 Mellanox Technologies. All rights reserved. 44885bf64SRoland Dreier * Copyright (c) 2005, 2006 Cisco Systems. All rights reserved. 51da177e4SLinus Torvalds * 61da177e4SLinus Torvalds * This software is available to you under a choice of one of two 71da177e4SLinus Torvalds * licenses. You may choose to be licensed under the terms of the GNU 81da177e4SLinus Torvalds * General Public License (GPL) Version 2, available from the file 91da177e4SLinus Torvalds * COPYING in the main directory of this source tree, or the 101da177e4SLinus Torvalds * OpenIB.org BSD license below: 111da177e4SLinus Torvalds * 121da177e4SLinus Torvalds * Redistribution and use in source and binary forms, with or 131da177e4SLinus Torvalds * without modification, are permitted provided that the following 141da177e4SLinus Torvalds * conditions are met: 151da177e4SLinus Torvalds * 161da177e4SLinus Torvalds * - Redistributions of source code must retain the above 171da177e4SLinus Torvalds * copyright notice, this list of conditions and the following 181da177e4SLinus Torvalds * disclaimer. 191da177e4SLinus Torvalds * 201da177e4SLinus Torvalds * - Redistributions in binary form must reproduce the above 211da177e4SLinus Torvalds * copyright notice, this list of conditions and the following 221da177e4SLinus Torvalds * disclaimer in the documentation and/or other materials 231da177e4SLinus Torvalds * provided with the distribution. 241da177e4SLinus Torvalds * 251da177e4SLinus Torvalds * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 261da177e4SLinus Torvalds * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 271da177e4SLinus Torvalds * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 281da177e4SLinus Torvalds * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 291da177e4SLinus Torvalds * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 301da177e4SLinus Torvalds * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 311da177e4SLinus Torvalds * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 321da177e4SLinus Torvalds * SOFTWARE. 331da177e4SLinus Torvalds */ 341da177e4SLinus Torvalds 352a214182SJames Lentini #include <linux/completion.h> 361da177e4SLinus Torvalds #include <linux/pci.h> 371da177e4SLinus Torvalds #include <linux/errno.h> 38e8edc6e0SAlexey Dobriyan #include <linux/sched.h> 395a0e3ad6STejun Heo #include <linux/slab.h> 401da177e4SLinus Torvalds #include <asm/io.h> 41a4d61e84SRoland Dreier #include <rdma/ib_mad.h> 421da177e4SLinus Torvalds 431da177e4SLinus Torvalds #include "mthca_dev.h" 441da177e4SLinus Torvalds #include "mthca_config_reg.h" 451da177e4SLinus Torvalds #include "mthca_cmd.h" 461da177e4SLinus Torvalds #include "mthca_memfree.h" 471da177e4SLinus Torvalds 481da177e4SLinus Torvalds #define CMD_POLL_TOKEN 0xffff 491da177e4SLinus Torvalds 501da177e4SLinus Torvalds enum { 511da177e4SLinus Torvalds HCR_IN_PARAM_OFFSET = 0x00, 521da177e4SLinus Torvalds HCR_IN_MODIFIER_OFFSET = 0x08, 531da177e4SLinus Torvalds HCR_OUT_PARAM_OFFSET = 0x0c, 541da177e4SLinus Torvalds HCR_TOKEN_OFFSET = 0x14, 551da177e4SLinus Torvalds HCR_STATUS_OFFSET = 0x18, 561da177e4SLinus Torvalds 571da177e4SLinus Torvalds HCR_OPMOD_SHIFT = 12, 581da177e4SLinus Torvalds HCA_E_BIT = 22, 591da177e4SLinus Torvalds HCR_GO_BIT = 23 601da177e4SLinus Torvalds }; 611da177e4SLinus Torvalds 621da177e4SLinus Torvalds enum { 631da177e4SLinus Torvalds /* initialization and general commands */ 641da177e4SLinus Torvalds CMD_SYS_EN = 0x1, 651da177e4SLinus Torvalds CMD_SYS_DIS = 0x2, 661da177e4SLinus Torvalds CMD_MAP_FA = 0xfff, 671da177e4SLinus Torvalds CMD_UNMAP_FA = 0xffe, 681da177e4SLinus Torvalds CMD_RUN_FW = 0xff6, 691da177e4SLinus Torvalds CMD_MOD_STAT_CFG = 0x34, 701da177e4SLinus Torvalds CMD_QUERY_DEV_LIM = 0x3, 711da177e4SLinus Torvalds CMD_QUERY_FW = 0x4, 721da177e4SLinus Torvalds CMD_ENABLE_LAM = 0xff8, 731da177e4SLinus Torvalds CMD_DISABLE_LAM = 0xff7, 741da177e4SLinus Torvalds CMD_QUERY_DDR = 0x5, 751da177e4SLinus Torvalds CMD_QUERY_ADAPTER = 0x6, 761da177e4SLinus Torvalds CMD_INIT_HCA = 0x7, 771da177e4SLinus Torvalds CMD_CLOSE_HCA = 0x8, 781da177e4SLinus Torvalds CMD_INIT_IB = 0x9, 791da177e4SLinus Torvalds CMD_CLOSE_IB = 0xa, 801da177e4SLinus Torvalds CMD_QUERY_HCA = 0xb, 811da177e4SLinus Torvalds CMD_SET_IB = 0xc, 821da177e4SLinus Torvalds CMD_ACCESS_DDR = 0x2e, 831da177e4SLinus Torvalds CMD_MAP_ICM = 0xffa, 841da177e4SLinus Torvalds CMD_UNMAP_ICM = 0xff9, 851da177e4SLinus Torvalds CMD_MAP_ICM_AUX = 0xffc, 861da177e4SLinus Torvalds CMD_UNMAP_ICM_AUX = 0xffb, 871da177e4SLinus Torvalds CMD_SET_ICM_SIZE = 0xffd, 881da177e4SLinus Torvalds 891da177e4SLinus Torvalds /* TPT commands */ 901da177e4SLinus Torvalds CMD_SW2HW_MPT = 0xd, 911da177e4SLinus Torvalds CMD_QUERY_MPT = 0xe, 921da177e4SLinus Torvalds CMD_HW2SW_MPT = 0xf, 931da177e4SLinus Torvalds CMD_READ_MTT = 0x10, 941da177e4SLinus Torvalds CMD_WRITE_MTT = 0x11, 951da177e4SLinus Torvalds CMD_SYNC_TPT = 0x2f, 961da177e4SLinus Torvalds 971da177e4SLinus Torvalds /* EQ commands */ 981da177e4SLinus Torvalds CMD_MAP_EQ = 0x12, 991da177e4SLinus Torvalds CMD_SW2HW_EQ = 0x13, 1001da177e4SLinus Torvalds CMD_HW2SW_EQ = 0x14, 1011da177e4SLinus Torvalds CMD_QUERY_EQ = 0x15, 1021da177e4SLinus Torvalds 1031da177e4SLinus Torvalds /* CQ commands */ 1041da177e4SLinus Torvalds CMD_SW2HW_CQ = 0x16, 1051da177e4SLinus Torvalds CMD_HW2SW_CQ = 0x17, 1061da177e4SLinus Torvalds CMD_QUERY_CQ = 0x18, 1071da177e4SLinus Torvalds CMD_RESIZE_CQ = 0x2c, 1081da177e4SLinus Torvalds 1091da177e4SLinus Torvalds /* SRQ commands */ 1101da177e4SLinus Torvalds CMD_SW2HW_SRQ = 0x35, 1111da177e4SLinus Torvalds CMD_HW2SW_SRQ = 0x36, 1121da177e4SLinus Torvalds CMD_QUERY_SRQ = 0x37, 113ec34a922SRoland Dreier CMD_ARM_SRQ = 0x40, 1141da177e4SLinus Torvalds 1151da177e4SLinus Torvalds /* QP/EE commands */ 1161da177e4SLinus Torvalds CMD_RST2INIT_QPEE = 0x19, 1171da177e4SLinus Torvalds CMD_INIT2RTR_QPEE = 0x1a, 1181da177e4SLinus Torvalds CMD_RTR2RTS_QPEE = 0x1b, 1191da177e4SLinus Torvalds CMD_RTS2RTS_QPEE = 0x1c, 1201da177e4SLinus Torvalds CMD_SQERR2RTS_QPEE = 0x1d, 1211da177e4SLinus Torvalds CMD_2ERR_QPEE = 0x1e, 1221da177e4SLinus Torvalds CMD_RTS2SQD_QPEE = 0x1f, 1231da177e4SLinus Torvalds CMD_SQD2SQD_QPEE = 0x38, 1241da177e4SLinus Torvalds CMD_SQD2RTS_QPEE = 0x20, 1251da177e4SLinus Torvalds CMD_ERR2RST_QPEE = 0x21, 1261da177e4SLinus Torvalds CMD_QUERY_QPEE = 0x22, 1271da177e4SLinus Torvalds CMD_INIT2INIT_QPEE = 0x2d, 1281da177e4SLinus Torvalds CMD_SUSPEND_QPEE = 0x32, 1291da177e4SLinus Torvalds CMD_UNSUSPEND_QPEE = 0x33, 1301da177e4SLinus Torvalds /* special QPs and management commands */ 1311da177e4SLinus Torvalds CMD_CONF_SPECIAL_QP = 0x23, 1321da177e4SLinus Torvalds CMD_MAD_IFC = 0x24, 1331da177e4SLinus Torvalds 1341da177e4SLinus Torvalds /* multicast commands */ 1351da177e4SLinus Torvalds CMD_READ_MGM = 0x25, 1361da177e4SLinus Torvalds CMD_WRITE_MGM = 0x26, 1371da177e4SLinus Torvalds CMD_MGID_HASH = 0x27, 1381da177e4SLinus Torvalds 1391da177e4SLinus Torvalds /* miscellaneous commands */ 1401da177e4SLinus Torvalds CMD_DIAG_RPRT = 0x30, 1411da177e4SLinus Torvalds CMD_NOP = 0x31, 1421da177e4SLinus Torvalds 1431da177e4SLinus Torvalds /* debug commands */ 1441da177e4SLinus Torvalds CMD_QUERY_DEBUG_MSG = 0x2a, 1451da177e4SLinus Torvalds CMD_SET_DEBUG_MSG = 0x2b, 1461da177e4SLinus Torvalds }; 1471da177e4SLinus Torvalds 1481da177e4SLinus Torvalds /* 1491da177e4SLinus Torvalds * According to Mellanox code, FW may be starved and never complete 1501da177e4SLinus Torvalds * commands. So we can't use strict timeouts described in PRM -- we 1511da177e4SLinus Torvalds * just arbitrarily select 60 seconds for now. 1521da177e4SLinus Torvalds */ 1531da177e4SLinus Torvalds #if 0 1541da177e4SLinus Torvalds /* 1551da177e4SLinus Torvalds * Round up and add 1 to make sure we get the full wait time (since we 1561da177e4SLinus Torvalds * will be starting in the middle of a jiffy) 1571da177e4SLinus Torvalds */ 1581da177e4SLinus Torvalds enum { 1591da177e4SLinus Torvalds CMD_TIME_CLASS_A = (HZ + 999) / 1000 + 1, 1601da177e4SLinus Torvalds CMD_TIME_CLASS_B = (HZ + 99) / 100 + 1, 1618531f1f1SJack Morgenstein CMD_TIME_CLASS_C = (HZ + 9) / 10 + 1, 1628531f1f1SJack Morgenstein CMD_TIME_CLASS_D = 60 * HZ 1631da177e4SLinus Torvalds }; 1641da177e4SLinus Torvalds #else 1651da177e4SLinus Torvalds enum { 1661da177e4SLinus Torvalds CMD_TIME_CLASS_A = 60 * HZ, 1671da177e4SLinus Torvalds CMD_TIME_CLASS_B = 60 * HZ, 1688531f1f1SJack Morgenstein CMD_TIME_CLASS_C = 60 * HZ, 1698531f1f1SJack Morgenstein CMD_TIME_CLASS_D = 60 * HZ 1701da177e4SLinus Torvalds }; 1711da177e4SLinus Torvalds #endif 1721da177e4SLinus Torvalds 1731da177e4SLinus Torvalds enum { 1741da177e4SLinus Torvalds GO_BIT_TIMEOUT = HZ * 10 1751da177e4SLinus Torvalds }; 1761da177e4SLinus Torvalds 1771da177e4SLinus Torvalds struct mthca_cmd_context { 1781da177e4SLinus Torvalds struct completion done; 1791da177e4SLinus Torvalds int result; 1801da177e4SLinus Torvalds int next; 1811da177e4SLinus Torvalds u64 out_param; 1821da177e4SLinus Torvalds u16 token; 1831da177e4SLinus Torvalds u8 status; 1841da177e4SLinus Torvalds }; 1851da177e4SLinus Torvalds 1861db76c14SRoland Dreier static int fw_cmd_doorbell = 0; 18714abdffcSEli Cohen module_param(fw_cmd_doorbell, int, 0644); 18814abdffcSEli Cohen MODULE_PARM_DESC(fw_cmd_doorbell, "post FW commands through doorbell page if nonzero " 18914abdffcSEli Cohen "(and supported by FW)"); 19014abdffcSEli Cohen 1911da177e4SLinus Torvalds static inline int go_bit(struct mthca_dev *dev) 1921da177e4SLinus Torvalds { 1931da177e4SLinus Torvalds return readl(dev->hcr + HCR_STATUS_OFFSET) & 1941da177e4SLinus Torvalds swab32(1 << HCR_GO_BIT); 1951da177e4SLinus Torvalds } 1961da177e4SLinus Torvalds 19714abdffcSEli Cohen static void mthca_cmd_post_dbell(struct mthca_dev *dev, 19814abdffcSEli Cohen u64 in_param, 19914abdffcSEli Cohen u64 out_param, 20014abdffcSEli Cohen u32 in_modifier, 20114abdffcSEli Cohen u8 op_modifier, 20214abdffcSEli Cohen u16 op, 20314abdffcSEli Cohen u16 token) 20414abdffcSEli Cohen { 20514abdffcSEli Cohen void __iomem *ptr = dev->cmd.dbell_map; 20614abdffcSEli Cohen u16 *offs = dev->cmd.dbell_offsets; 20714abdffcSEli Cohen 20814abdffcSEli Cohen __raw_writel((__force u32) cpu_to_be32(in_param >> 32), ptr + offs[0]); 20914abdffcSEli Cohen wmb(); 21014abdffcSEli Cohen __raw_writel((__force u32) cpu_to_be32(in_param & 0xfffffffful), ptr + offs[1]); 21114abdffcSEli Cohen wmb(); 21214abdffcSEli Cohen __raw_writel((__force u32) cpu_to_be32(in_modifier), ptr + offs[2]); 21314abdffcSEli Cohen wmb(); 21414abdffcSEli Cohen __raw_writel((__force u32) cpu_to_be32(out_param >> 32), ptr + offs[3]); 21514abdffcSEli Cohen wmb(); 21614abdffcSEli Cohen __raw_writel((__force u32) cpu_to_be32(out_param & 0xfffffffful), ptr + offs[4]); 21714abdffcSEli Cohen wmb(); 21814abdffcSEli Cohen __raw_writel((__force u32) cpu_to_be32(token << 16), ptr + offs[5]); 21914abdffcSEli Cohen wmb(); 22014abdffcSEli Cohen __raw_writel((__force u32) cpu_to_be32((1 << HCR_GO_BIT) | 22114abdffcSEli Cohen (1 << HCA_E_BIT) | 22214abdffcSEli Cohen (op_modifier << HCR_OPMOD_SHIFT) | 22314abdffcSEli Cohen op), ptr + offs[6]); 22414abdffcSEli Cohen wmb(); 22514abdffcSEli Cohen __raw_writel((__force u32) 0, ptr + offs[7]); 22614abdffcSEli Cohen wmb(); 22714abdffcSEli Cohen } 22814abdffcSEli Cohen 22914abdffcSEli Cohen static int mthca_cmd_post_hcr(struct mthca_dev *dev, 2301da177e4SLinus Torvalds u64 in_param, 2311da177e4SLinus Torvalds u64 out_param, 2321da177e4SLinus Torvalds u32 in_modifier, 2331da177e4SLinus Torvalds u8 op_modifier, 2341da177e4SLinus Torvalds u16 op, 2351da177e4SLinus Torvalds u16 token, 2361da177e4SLinus Torvalds int event) 2371da177e4SLinus Torvalds { 2381da177e4SLinus Torvalds if (event) { 2391da177e4SLinus Torvalds unsigned long end = jiffies + GO_BIT_TIMEOUT; 2401da177e4SLinus Torvalds 2411da177e4SLinus Torvalds while (go_bit(dev) && time_before(jiffies, end)) { 2421da177e4SLinus Torvalds set_current_state(TASK_RUNNING); 2431da177e4SLinus Torvalds schedule(); 2441da177e4SLinus Torvalds } 2451da177e4SLinus Torvalds } 2461da177e4SLinus Torvalds 24714abdffcSEli Cohen if (go_bit(dev)) 24814abdffcSEli Cohen return -EAGAIN; 2491da177e4SLinus Torvalds 2501da177e4SLinus Torvalds /* 2511da177e4SLinus Torvalds * We use writel (instead of something like memcpy_toio) 2521da177e4SLinus Torvalds * because writes of less than 32 bits to the HCR don't work 2531da177e4SLinus Torvalds * (and some architectures such as ia64 implement memcpy_toio 2541da177e4SLinus Torvalds * in terms of writeb). 2551da177e4SLinus Torvalds */ 25697f52eb4SSean Hefty __raw_writel((__force u32) cpu_to_be32(in_param >> 32), dev->hcr + 0 * 4); 25797f52eb4SSean Hefty __raw_writel((__force u32) cpu_to_be32(in_param & 0xfffffffful), dev->hcr + 1 * 4); 25897f52eb4SSean Hefty __raw_writel((__force u32) cpu_to_be32(in_modifier), dev->hcr + 2 * 4); 25997f52eb4SSean Hefty __raw_writel((__force u32) cpu_to_be32(out_param >> 32), dev->hcr + 3 * 4); 26097f52eb4SSean Hefty __raw_writel((__force u32) cpu_to_be32(out_param & 0xfffffffful), dev->hcr + 4 * 4); 26197f52eb4SSean Hefty __raw_writel((__force u32) cpu_to_be32(token << 16), dev->hcr + 5 * 4); 2621da177e4SLinus Torvalds 2631da177e4SLinus Torvalds /* __raw_writel may not order writes. */ 2641da177e4SLinus Torvalds wmb(); 2651da177e4SLinus Torvalds 26697f52eb4SSean Hefty __raw_writel((__force u32) cpu_to_be32((1 << HCR_GO_BIT) | 2671da177e4SLinus Torvalds (event ? (1 << HCA_E_BIT) : 0) | 2681da177e4SLinus Torvalds (op_modifier << HCR_OPMOD_SHIFT) | 2691da177e4SLinus Torvalds op), dev->hcr + 6 * 4); 2701da177e4SLinus Torvalds 27114abdffcSEli Cohen return 0; 27214abdffcSEli Cohen } 27314abdffcSEli Cohen 27414abdffcSEli Cohen static int mthca_cmd_post(struct mthca_dev *dev, 27514abdffcSEli Cohen u64 in_param, 27614abdffcSEli Cohen u64 out_param, 27714abdffcSEli Cohen u32 in_modifier, 27814abdffcSEli Cohen u8 op_modifier, 27914abdffcSEli Cohen u16 op, 28014abdffcSEli Cohen u16 token, 28114abdffcSEli Cohen int event) 28214abdffcSEli Cohen { 28314abdffcSEli Cohen int err = 0; 28414abdffcSEli Cohen 28514abdffcSEli Cohen mutex_lock(&dev->cmd.hcr_mutex); 28614abdffcSEli Cohen 28714abdffcSEli Cohen if (event && dev->cmd.flags & MTHCA_CMD_POST_DOORBELLS && fw_cmd_doorbell) 28814abdffcSEli Cohen mthca_cmd_post_dbell(dev, in_param, out_param, in_modifier, 28914abdffcSEli Cohen op_modifier, op, token); 29014abdffcSEli Cohen else 29114abdffcSEli Cohen err = mthca_cmd_post_hcr(dev, in_param, out_param, in_modifier, 29214abdffcSEli Cohen op_modifier, op, token, event); 29314abdffcSEli Cohen 29476d7cc03SRoland Dreier /* 29576d7cc03SRoland Dreier * Make sure that our HCR writes don't get mixed in with 29676d7cc03SRoland Dreier * writes from another CPU starting a FW command. 29776d7cc03SRoland Dreier */ 29876d7cc03SRoland Dreier mmiowb(); 29976d7cc03SRoland Dreier 300fd9cfdd1SRoland Dreier mutex_unlock(&dev->cmd.hcr_mutex); 3011da177e4SLinus Torvalds return err; 3021da177e4SLinus Torvalds } 3031da177e4SLinus Torvalds 3041da177e4SLinus Torvalds static int mthca_cmd_poll(struct mthca_dev *dev, 3051da177e4SLinus Torvalds u64 in_param, 3061da177e4SLinus Torvalds u64 *out_param, 3071da177e4SLinus Torvalds int out_is_imm, 3081da177e4SLinus Torvalds u32 in_modifier, 3091da177e4SLinus Torvalds u8 op_modifier, 3101da177e4SLinus Torvalds u16 op, 3111da177e4SLinus Torvalds unsigned long timeout, 3121da177e4SLinus Torvalds u8 *status) 3131da177e4SLinus Torvalds { 3141da177e4SLinus Torvalds int err = 0; 3151da177e4SLinus Torvalds unsigned long end; 3161da177e4SLinus Torvalds 317e3aa31c5SMichael S. Tsirkin down(&dev->cmd.poll_sem); 3181da177e4SLinus Torvalds 3191da177e4SLinus Torvalds err = mthca_cmd_post(dev, in_param, 3201da177e4SLinus Torvalds out_param ? *out_param : 0, 3211da177e4SLinus Torvalds in_modifier, op_modifier, 3221da177e4SLinus Torvalds op, CMD_POLL_TOKEN, 0); 3231da177e4SLinus Torvalds if (err) 3241da177e4SLinus Torvalds goto out; 3251da177e4SLinus Torvalds 3261da177e4SLinus Torvalds end = timeout + jiffies; 3271da177e4SLinus Torvalds while (go_bit(dev) && time_before(jiffies, end)) { 3281da177e4SLinus Torvalds set_current_state(TASK_RUNNING); 3291da177e4SLinus Torvalds schedule(); 3301da177e4SLinus Torvalds } 3311da177e4SLinus Torvalds 3321da177e4SLinus Torvalds if (go_bit(dev)) { 3331da177e4SLinus Torvalds err = -EBUSY; 3341da177e4SLinus Torvalds goto out; 3351da177e4SLinus Torvalds } 3361da177e4SLinus Torvalds 33797f52eb4SSean Hefty if (out_is_imm) 33897f52eb4SSean Hefty *out_param = 33997f52eb4SSean Hefty (u64) be32_to_cpu((__force __be32) 34097f52eb4SSean Hefty __raw_readl(dev->hcr + HCR_OUT_PARAM_OFFSET)) << 32 | 34197f52eb4SSean Hefty (u64) be32_to_cpu((__force __be32) 34297f52eb4SSean Hefty __raw_readl(dev->hcr + HCR_OUT_PARAM_OFFSET + 4)); 3431da177e4SLinus Torvalds 34497f52eb4SSean Hefty *status = be32_to_cpu((__force __be32) __raw_readl(dev->hcr + HCR_STATUS_OFFSET)) >> 24; 3451da177e4SLinus Torvalds 3461da177e4SLinus Torvalds out: 3471da177e4SLinus Torvalds up(&dev->cmd.poll_sem); 3481da177e4SLinus Torvalds return err; 3491da177e4SLinus Torvalds } 3501da177e4SLinus Torvalds 3511da177e4SLinus Torvalds void mthca_cmd_event(struct mthca_dev *dev, 3521da177e4SLinus Torvalds u16 token, 3531da177e4SLinus Torvalds u8 status, 3541da177e4SLinus Torvalds u64 out_param) 3551da177e4SLinus Torvalds { 3561da177e4SLinus Torvalds struct mthca_cmd_context *context = 3571da177e4SLinus Torvalds &dev->cmd.context[token & dev->cmd.token_mask]; 3581da177e4SLinus Torvalds 3591da177e4SLinus Torvalds /* previously timed out command completing at long last */ 3601da177e4SLinus Torvalds if (token != context->token) 3611da177e4SLinus Torvalds return; 3621da177e4SLinus Torvalds 3631da177e4SLinus Torvalds context->result = 0; 3641da177e4SLinus Torvalds context->status = status; 3651da177e4SLinus Torvalds context->out_param = out_param; 3661da177e4SLinus Torvalds 3671da177e4SLinus Torvalds complete(&context->done); 3681da177e4SLinus Torvalds } 3691da177e4SLinus Torvalds 3701da177e4SLinus Torvalds static int mthca_cmd_wait(struct mthca_dev *dev, 3711da177e4SLinus Torvalds u64 in_param, 3721da177e4SLinus Torvalds u64 *out_param, 3731da177e4SLinus Torvalds int out_is_imm, 3741da177e4SLinus Torvalds u32 in_modifier, 3751da177e4SLinus Torvalds u8 op_modifier, 3761da177e4SLinus Torvalds u16 op, 3771da177e4SLinus Torvalds unsigned long timeout, 3781da177e4SLinus Torvalds u8 *status) 3791da177e4SLinus Torvalds { 3801da177e4SLinus Torvalds int err = 0; 3811da177e4SLinus Torvalds struct mthca_cmd_context *context; 3821da177e4SLinus Torvalds 383e3aa31c5SMichael S. Tsirkin down(&dev->cmd.event_sem); 3841da177e4SLinus Torvalds 3851da177e4SLinus Torvalds spin_lock(&dev->cmd.context_lock); 3861da177e4SLinus Torvalds BUG_ON(dev->cmd.free_head < 0); 3871da177e4SLinus Torvalds context = &dev->cmd.context[dev->cmd.free_head]; 388c1f74958SMichael S. Tsirkin context->token += dev->cmd.token_mask + 1; 3891da177e4SLinus Torvalds dev->cmd.free_head = context->next; 3901da177e4SLinus Torvalds spin_unlock(&dev->cmd.context_lock); 3911da177e4SLinus Torvalds 3921da177e4SLinus Torvalds init_completion(&context->done); 3931da177e4SLinus Torvalds 3941da177e4SLinus Torvalds err = mthca_cmd_post(dev, in_param, 3951da177e4SLinus Torvalds out_param ? *out_param : 0, 3961da177e4SLinus Torvalds in_modifier, op_modifier, 3971da177e4SLinus Torvalds op, context->token, 1); 3981da177e4SLinus Torvalds if (err) 3991da177e4SLinus Torvalds goto out; 4001da177e4SLinus Torvalds 401e9cd5941SRoland Dreier if (!wait_for_completion_timeout(&context->done, timeout)) { 402e9cd5941SRoland Dreier err = -EBUSY; 403e9cd5941SRoland Dreier goto out; 404e9cd5941SRoland Dreier } 4051da177e4SLinus Torvalds 4061da177e4SLinus Torvalds err = context->result; 4071da177e4SLinus Torvalds if (err) 4081da177e4SLinus Torvalds goto out; 4091da177e4SLinus Torvalds 4101da177e4SLinus Torvalds *status = context->status; 4111da177e4SLinus Torvalds if (*status) 4121da177e4SLinus Torvalds mthca_dbg(dev, "Command %02x completed with status %02x\n", 4131da177e4SLinus Torvalds op, *status); 4141da177e4SLinus Torvalds 4151da177e4SLinus Torvalds if (out_is_imm) 4161da177e4SLinus Torvalds *out_param = context->out_param; 4171da177e4SLinus Torvalds 4181da177e4SLinus Torvalds out: 4191da177e4SLinus Torvalds spin_lock(&dev->cmd.context_lock); 4201da177e4SLinus Torvalds context->next = dev->cmd.free_head; 4211da177e4SLinus Torvalds dev->cmd.free_head = context - dev->cmd.context; 4221da177e4SLinus Torvalds spin_unlock(&dev->cmd.context_lock); 4231da177e4SLinus Torvalds 4241da177e4SLinus Torvalds up(&dev->cmd.event_sem); 4251da177e4SLinus Torvalds return err; 4261da177e4SLinus Torvalds } 4271da177e4SLinus Torvalds 4281da177e4SLinus Torvalds /* Invoke a command with an output mailbox */ 4291da177e4SLinus Torvalds static int mthca_cmd_box(struct mthca_dev *dev, 4301da177e4SLinus Torvalds u64 in_param, 4311da177e4SLinus Torvalds u64 out_param, 4321da177e4SLinus Torvalds u32 in_modifier, 4331da177e4SLinus Torvalds u8 op_modifier, 4341da177e4SLinus Torvalds u16 op, 4351da177e4SLinus Torvalds unsigned long timeout, 4361da177e4SLinus Torvalds u8 *status) 4371da177e4SLinus Torvalds { 43814abdffcSEli Cohen if (dev->cmd.flags & MTHCA_CMD_USE_EVENTS) 4391da177e4SLinus Torvalds return mthca_cmd_wait(dev, in_param, &out_param, 0, 4401da177e4SLinus Torvalds in_modifier, op_modifier, op, 4411da177e4SLinus Torvalds timeout, status); 4421da177e4SLinus Torvalds else 4431da177e4SLinus Torvalds return mthca_cmd_poll(dev, in_param, &out_param, 0, 4441da177e4SLinus Torvalds in_modifier, op_modifier, op, 4451da177e4SLinus Torvalds timeout, status); 4461da177e4SLinus Torvalds } 4471da177e4SLinus Torvalds 4481da177e4SLinus Torvalds /* Invoke a command with no output parameter */ 4491da177e4SLinus Torvalds static int mthca_cmd(struct mthca_dev *dev, 4501da177e4SLinus Torvalds u64 in_param, 4511da177e4SLinus Torvalds u32 in_modifier, 4521da177e4SLinus Torvalds u8 op_modifier, 4531da177e4SLinus Torvalds u16 op, 4541da177e4SLinus Torvalds unsigned long timeout, 4551da177e4SLinus Torvalds u8 *status) 4561da177e4SLinus Torvalds { 4571da177e4SLinus Torvalds return mthca_cmd_box(dev, in_param, 0, in_modifier, 4581da177e4SLinus Torvalds op_modifier, op, timeout, status); 4591da177e4SLinus Torvalds } 4601da177e4SLinus Torvalds 4611da177e4SLinus Torvalds /* 4621da177e4SLinus Torvalds * Invoke a command with an immediate output parameter (and copy the 4631da177e4SLinus Torvalds * output into the caller's out_param pointer after the command 4641da177e4SLinus Torvalds * executes). 4651da177e4SLinus Torvalds */ 4661da177e4SLinus Torvalds static int mthca_cmd_imm(struct mthca_dev *dev, 4671da177e4SLinus Torvalds u64 in_param, 4681da177e4SLinus Torvalds u64 *out_param, 4691da177e4SLinus Torvalds u32 in_modifier, 4701da177e4SLinus Torvalds u8 op_modifier, 4711da177e4SLinus Torvalds u16 op, 4721da177e4SLinus Torvalds unsigned long timeout, 4731da177e4SLinus Torvalds u8 *status) 4741da177e4SLinus Torvalds { 47514abdffcSEli Cohen if (dev->cmd.flags & MTHCA_CMD_USE_EVENTS) 4761da177e4SLinus Torvalds return mthca_cmd_wait(dev, in_param, out_param, 1, 4771da177e4SLinus Torvalds in_modifier, op_modifier, op, 4781da177e4SLinus Torvalds timeout, status); 4791da177e4SLinus Torvalds else 4801da177e4SLinus Torvalds return mthca_cmd_poll(dev, in_param, out_param, 1, 4811da177e4SLinus Torvalds in_modifier, op_modifier, op, 4821da177e4SLinus Torvalds timeout, status); 4831da177e4SLinus Torvalds } 4841da177e4SLinus Torvalds 48580fd8238SRoland Dreier int mthca_cmd_init(struct mthca_dev *dev) 48680fd8238SRoland Dreier { 487fd9cfdd1SRoland Dreier mutex_init(&dev->cmd.hcr_mutex); 48880fd8238SRoland Dreier sema_init(&dev->cmd.poll_sem, 1); 48914abdffcSEli Cohen dev->cmd.flags = 0; 49080fd8238SRoland Dreier 49180fd8238SRoland Dreier dev->hcr = ioremap(pci_resource_start(dev->pdev, 0) + MTHCA_HCR_BASE, 49280fd8238SRoland Dreier MTHCA_HCR_SIZE); 49380fd8238SRoland Dreier if (!dev->hcr) { 49480fd8238SRoland Dreier mthca_err(dev, "Couldn't map command register."); 49580fd8238SRoland Dreier return -ENOMEM; 49680fd8238SRoland Dreier } 49780fd8238SRoland Dreier 498ed878458SRoland Dreier dev->cmd.pool = pci_pool_create("mthca_cmd", dev->pdev, 499ed878458SRoland Dreier MTHCA_MAILBOX_SIZE, 500ed878458SRoland Dreier MTHCA_MAILBOX_SIZE, 0); 501ed878458SRoland Dreier if (!dev->cmd.pool) { 502ed878458SRoland Dreier iounmap(dev->hcr); 503ed878458SRoland Dreier return -ENOMEM; 504ed878458SRoland Dreier } 505ed878458SRoland Dreier 50680fd8238SRoland Dreier return 0; 50780fd8238SRoland Dreier } 50880fd8238SRoland Dreier 50980fd8238SRoland Dreier void mthca_cmd_cleanup(struct mthca_dev *dev) 51080fd8238SRoland Dreier { 511ed878458SRoland Dreier pci_pool_destroy(dev->cmd.pool); 51280fd8238SRoland Dreier iounmap(dev->hcr); 51314abdffcSEli Cohen if (dev->cmd.flags & MTHCA_CMD_POST_DOORBELLS) 51414abdffcSEli Cohen iounmap(dev->cmd.dbell_map); 51580fd8238SRoland Dreier } 51680fd8238SRoland Dreier 5171da177e4SLinus Torvalds /* 5181da177e4SLinus Torvalds * Switch to using events to issue FW commands (should be called after 5191da177e4SLinus Torvalds * event queue to command events has been initialized). 5201da177e4SLinus Torvalds */ 5211da177e4SLinus Torvalds int mthca_cmd_use_events(struct mthca_dev *dev) 5221da177e4SLinus Torvalds { 5231da177e4SLinus Torvalds int i; 5241da177e4SLinus Torvalds 5251da177e4SLinus Torvalds dev->cmd.context = kmalloc(dev->cmd.max_cmds * 5261da177e4SLinus Torvalds sizeof (struct mthca_cmd_context), 5271da177e4SLinus Torvalds GFP_KERNEL); 5281da177e4SLinus Torvalds if (!dev->cmd.context) 5291da177e4SLinus Torvalds return -ENOMEM; 5301da177e4SLinus Torvalds 5311da177e4SLinus Torvalds for (i = 0; i < dev->cmd.max_cmds; ++i) { 5321da177e4SLinus Torvalds dev->cmd.context[i].token = i; 5331da177e4SLinus Torvalds dev->cmd.context[i].next = i + 1; 5341da177e4SLinus Torvalds } 5351da177e4SLinus Torvalds 5361da177e4SLinus Torvalds dev->cmd.context[dev->cmd.max_cmds - 1].next = -1; 5371da177e4SLinus Torvalds dev->cmd.free_head = 0; 5381da177e4SLinus Torvalds 5391da177e4SLinus Torvalds sema_init(&dev->cmd.event_sem, dev->cmd.max_cmds); 5401da177e4SLinus Torvalds spin_lock_init(&dev->cmd.context_lock); 5411da177e4SLinus Torvalds 5421da177e4SLinus Torvalds for (dev->cmd.token_mask = 1; 5431da177e4SLinus Torvalds dev->cmd.token_mask < dev->cmd.max_cmds; 5441da177e4SLinus Torvalds dev->cmd.token_mask <<= 1) 5451da177e4SLinus Torvalds ; /* nothing */ 5461da177e4SLinus Torvalds --dev->cmd.token_mask; 5471da177e4SLinus Torvalds 54814abdffcSEli Cohen dev->cmd.flags |= MTHCA_CMD_USE_EVENTS; 54914abdffcSEli Cohen 5501da177e4SLinus Torvalds down(&dev->cmd.poll_sem); 5511da177e4SLinus Torvalds 5521da177e4SLinus Torvalds return 0; 5531da177e4SLinus Torvalds } 5541da177e4SLinus Torvalds 5551da177e4SLinus Torvalds /* 5561da177e4SLinus Torvalds * Switch back to polling (used when shutting down the device) 5571da177e4SLinus Torvalds */ 5581da177e4SLinus Torvalds void mthca_cmd_use_polling(struct mthca_dev *dev) 5591da177e4SLinus Torvalds { 5601da177e4SLinus Torvalds int i; 5611da177e4SLinus Torvalds 56214abdffcSEli Cohen dev->cmd.flags &= ~MTHCA_CMD_USE_EVENTS; 5631da177e4SLinus Torvalds 5641da177e4SLinus Torvalds for (i = 0; i < dev->cmd.max_cmds; ++i) 5651da177e4SLinus Torvalds down(&dev->cmd.event_sem); 5661da177e4SLinus Torvalds 5671da177e4SLinus Torvalds kfree(dev->cmd.context); 5681da177e4SLinus Torvalds 5691da177e4SLinus Torvalds up(&dev->cmd.poll_sem); 5701da177e4SLinus Torvalds } 5711da177e4SLinus Torvalds 572ed878458SRoland Dreier struct mthca_mailbox *mthca_alloc_mailbox(struct mthca_dev *dev, 57387b750dcSAl Viro gfp_t gfp_mask) 574ed878458SRoland Dreier { 575ed878458SRoland Dreier struct mthca_mailbox *mailbox; 576ed878458SRoland Dreier 577ed878458SRoland Dreier mailbox = kmalloc(sizeof *mailbox, gfp_mask); 578ed878458SRoland Dreier if (!mailbox) 579ed878458SRoland Dreier return ERR_PTR(-ENOMEM); 580ed878458SRoland Dreier 581ed878458SRoland Dreier mailbox->buf = pci_pool_alloc(dev->cmd.pool, gfp_mask, &mailbox->dma); 582ed878458SRoland Dreier if (!mailbox->buf) { 583ed878458SRoland Dreier kfree(mailbox); 584ed878458SRoland Dreier return ERR_PTR(-ENOMEM); 585ed878458SRoland Dreier } 586ed878458SRoland Dreier 587ed878458SRoland Dreier return mailbox; 588ed878458SRoland Dreier } 589ed878458SRoland Dreier 590ed878458SRoland Dreier void mthca_free_mailbox(struct mthca_dev *dev, struct mthca_mailbox *mailbox) 591ed878458SRoland Dreier { 592ed878458SRoland Dreier if (!mailbox) 593ed878458SRoland Dreier return; 594ed878458SRoland Dreier 595ed878458SRoland Dreier pci_pool_free(dev->cmd.pool, mailbox->buf, mailbox->dma); 596ed878458SRoland Dreier kfree(mailbox); 597ed878458SRoland Dreier } 598ed878458SRoland Dreier 5991da177e4SLinus Torvalds int mthca_SYS_EN(struct mthca_dev *dev, u8 *status) 6001da177e4SLinus Torvalds { 6011da177e4SLinus Torvalds u64 out; 6021da177e4SLinus Torvalds int ret; 6031da177e4SLinus Torvalds 6048531f1f1SJack Morgenstein ret = mthca_cmd_imm(dev, 0, &out, 0, 0, CMD_SYS_EN, CMD_TIME_CLASS_D, status); 6051da177e4SLinus Torvalds 6061da177e4SLinus Torvalds if (*status == MTHCA_CMD_STAT_DDR_MEM_ERR) 6071da177e4SLinus Torvalds mthca_warn(dev, "SYS_EN DDR error: syn=%x, sock=%d, " 6081da177e4SLinus Torvalds "sladdr=%d, SPD source=%s\n", 6091da177e4SLinus Torvalds (int) (out >> 6) & 0xf, (int) (out >> 4) & 3, 6101da177e4SLinus Torvalds (int) (out >> 1) & 7, (int) out & 1 ? "NVMEM" : "DIMM"); 6111da177e4SLinus Torvalds 6121da177e4SLinus Torvalds return ret; 6131da177e4SLinus Torvalds } 6141da177e4SLinus Torvalds 6151da177e4SLinus Torvalds int mthca_SYS_DIS(struct mthca_dev *dev, u8 *status) 6161da177e4SLinus Torvalds { 6178531f1f1SJack Morgenstein return mthca_cmd(dev, 0, 0, 0, CMD_SYS_DIS, CMD_TIME_CLASS_C, status); 6181da177e4SLinus Torvalds } 6191da177e4SLinus Torvalds 6201da177e4SLinus Torvalds static int mthca_map_cmd(struct mthca_dev *dev, u16 op, struct mthca_icm *icm, 6211da177e4SLinus Torvalds u64 virt, u8 *status) 6221da177e4SLinus Torvalds { 623ed878458SRoland Dreier struct mthca_mailbox *mailbox; 6241da177e4SLinus Torvalds struct mthca_icm_iter iter; 625ed878458SRoland Dreier __be64 *pages; 6261da177e4SLinus Torvalds int lg; 6271da177e4SLinus Torvalds int nent = 0; 6281da177e4SLinus Torvalds int i; 6291da177e4SLinus Torvalds int err = 0; 6301da177e4SLinus Torvalds int ts = 0, tc = 0; 6311da177e4SLinus Torvalds 632ed878458SRoland Dreier mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL); 633ed878458SRoland Dreier if (IS_ERR(mailbox)) 634ed878458SRoland Dreier return PTR_ERR(mailbox); 635ed878458SRoland Dreier memset(mailbox->buf, 0, MTHCA_MAILBOX_SIZE); 636ed878458SRoland Dreier pages = mailbox->buf; 6371da177e4SLinus Torvalds 6381da177e4SLinus Torvalds for (mthca_icm_first(icm, &iter); 6391da177e4SLinus Torvalds !mthca_icm_last(&iter); 6401da177e4SLinus Torvalds mthca_icm_next(&iter)) { 6411da177e4SLinus Torvalds /* 6421da177e4SLinus Torvalds * We have to pass pages that are aligned to their 6431da177e4SLinus Torvalds * size, so find the least significant 1 in the 6441da177e4SLinus Torvalds * address or size and use that as our log2 size. 6451da177e4SLinus Torvalds */ 6461da177e4SLinus Torvalds lg = ffs(mthca_icm_addr(&iter) | mthca_icm_size(&iter)) - 1; 6478d3ef29dSIshai Rabinovitz if (lg < MTHCA_ICM_PAGE_SHIFT) { 6488d3ef29dSIshai Rabinovitz mthca_warn(dev, "Got FW area not aligned to %d (%llx/%lx).\n", 6498d3ef29dSIshai Rabinovitz MTHCA_ICM_PAGE_SIZE, 6501da177e4SLinus Torvalds (unsigned long long) mthca_icm_addr(&iter), 6511da177e4SLinus Torvalds mthca_icm_size(&iter)); 6521da177e4SLinus Torvalds err = -EINVAL; 6531da177e4SLinus Torvalds goto out; 6541da177e4SLinus Torvalds } 65559f174faSIshai Rabinovitz for (i = 0; i < mthca_icm_size(&iter) >> lg; ++i) { 6561da177e4SLinus Torvalds if (virt != -1) { 657ed878458SRoland Dreier pages[nent * 2] = cpu_to_be64(virt); 6581da177e4SLinus Torvalds virt += 1 << lg; 6591da177e4SLinus Torvalds } 6601da177e4SLinus Torvalds 6618d3ef29dSIshai Rabinovitz pages[nent * 2 + 1] = 6628d3ef29dSIshai Rabinovitz cpu_to_be64((mthca_icm_addr(&iter) + (i << lg)) | 6638d3ef29dSIshai Rabinovitz (lg - MTHCA_ICM_PAGE_SHIFT)); 6641da177e4SLinus Torvalds ts += 1 << (lg - 10); 6651da177e4SLinus Torvalds ++tc; 6661da177e4SLinus Torvalds 66744dd823bSMichael S. Tsirkin if (++nent == MTHCA_MAILBOX_SIZE / 16) { 668ed878458SRoland Dreier err = mthca_cmd(dev, mailbox->dma, nent, 0, op, 6691da177e4SLinus Torvalds CMD_TIME_CLASS_B, status); 6701da177e4SLinus Torvalds if (err || *status) 6711da177e4SLinus Torvalds goto out; 6721da177e4SLinus Torvalds nent = 0; 6731da177e4SLinus Torvalds } 6741da177e4SLinus Torvalds } 6751da177e4SLinus Torvalds } 6761da177e4SLinus Torvalds 6771da177e4SLinus Torvalds if (nent) 678ed878458SRoland Dreier err = mthca_cmd(dev, mailbox->dma, nent, 0, op, 6791da177e4SLinus Torvalds CMD_TIME_CLASS_B, status); 6801da177e4SLinus Torvalds 6811da177e4SLinus Torvalds switch (op) { 6821da177e4SLinus Torvalds case CMD_MAP_FA: 6831da177e4SLinus Torvalds mthca_dbg(dev, "Mapped %d chunks/%d KB for FW.\n", tc, ts); 6841da177e4SLinus Torvalds break; 6851da177e4SLinus Torvalds case CMD_MAP_ICM_AUX: 6861da177e4SLinus Torvalds mthca_dbg(dev, "Mapped %d chunks/%d KB for ICM aux.\n", tc, ts); 6871da177e4SLinus Torvalds break; 6881da177e4SLinus Torvalds case CMD_MAP_ICM: 6891da177e4SLinus Torvalds mthca_dbg(dev, "Mapped %d chunks/%d KB at %llx for ICM.\n", 6901da177e4SLinus Torvalds tc, ts, (unsigned long long) virt - (ts << 10)); 6911da177e4SLinus Torvalds break; 6921da177e4SLinus Torvalds } 6931da177e4SLinus Torvalds 6941da177e4SLinus Torvalds out: 695ed878458SRoland Dreier mthca_free_mailbox(dev, mailbox); 6961da177e4SLinus Torvalds return err; 6971da177e4SLinus Torvalds } 6981da177e4SLinus Torvalds 6991da177e4SLinus Torvalds int mthca_MAP_FA(struct mthca_dev *dev, struct mthca_icm *icm, u8 *status) 7001da177e4SLinus Torvalds { 7011da177e4SLinus Torvalds return mthca_map_cmd(dev, CMD_MAP_FA, icm, -1, status); 7021da177e4SLinus Torvalds } 7031da177e4SLinus Torvalds 7041da177e4SLinus Torvalds int mthca_UNMAP_FA(struct mthca_dev *dev, u8 *status) 7051da177e4SLinus Torvalds { 7061da177e4SLinus Torvalds return mthca_cmd(dev, 0, 0, 0, CMD_UNMAP_FA, CMD_TIME_CLASS_B, status); 7071da177e4SLinus Torvalds } 7081da177e4SLinus Torvalds 7091da177e4SLinus Torvalds int mthca_RUN_FW(struct mthca_dev *dev, u8 *status) 7101da177e4SLinus Torvalds { 7111da177e4SLinus Torvalds return mthca_cmd(dev, 0, 0, 0, CMD_RUN_FW, CMD_TIME_CLASS_A, status); 7121da177e4SLinus Torvalds } 7131da177e4SLinus Torvalds 71414abdffcSEli Cohen static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base) 71514abdffcSEli Cohen { 71614abdffcSEli Cohen unsigned long addr; 71714abdffcSEli Cohen u16 max_off = 0; 71814abdffcSEli Cohen int i; 71914abdffcSEli Cohen 72014abdffcSEli Cohen for (i = 0; i < 8; ++i) 72114abdffcSEli Cohen max_off = max(max_off, dev->cmd.dbell_offsets[i]); 72214abdffcSEli Cohen 72314abdffcSEli Cohen if ((base & PAGE_MASK) != ((base + max_off) & PAGE_MASK)) { 72414abdffcSEli Cohen mthca_warn(dev, "Firmware doorbell region at 0x%016llx, " 72514abdffcSEli Cohen "length 0x%x crosses a page boundary\n", 72614abdffcSEli Cohen (unsigned long long) base, max_off); 72714abdffcSEli Cohen return; 72814abdffcSEli Cohen } 72914abdffcSEli Cohen 73014abdffcSEli Cohen addr = pci_resource_start(dev->pdev, 2) + 73114abdffcSEli Cohen ((pci_resource_len(dev->pdev, 2) - 1) & base); 73214abdffcSEli Cohen dev->cmd.dbell_map = ioremap(addr, max_off + sizeof(u32)); 73314abdffcSEli Cohen if (!dev->cmd.dbell_map) 73414abdffcSEli Cohen return; 73514abdffcSEli Cohen 73614abdffcSEli Cohen dev->cmd.flags |= MTHCA_CMD_POST_DOORBELLS; 73714abdffcSEli Cohen mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n"); 73814abdffcSEli Cohen } 73914abdffcSEli Cohen 7401da177e4SLinus Torvalds int mthca_QUERY_FW(struct mthca_dev *dev, u8 *status) 7411da177e4SLinus Torvalds { 742ed878458SRoland Dreier struct mthca_mailbox *mailbox; 7431da177e4SLinus Torvalds u32 *outbox; 74414abdffcSEli Cohen u64 base; 74514abdffcSEli Cohen u32 tmp; 7461da177e4SLinus Torvalds int err = 0; 7471da177e4SLinus Torvalds u8 lg; 74814abdffcSEli Cohen int i; 7491da177e4SLinus Torvalds 7501da177e4SLinus Torvalds #define QUERY_FW_OUT_SIZE 0x100 7511da177e4SLinus Torvalds #define QUERY_FW_VER_OFFSET 0x00 7521da177e4SLinus Torvalds #define QUERY_FW_MAX_CMD_OFFSET 0x0f 7531da177e4SLinus Torvalds #define QUERY_FW_ERR_START_OFFSET 0x30 7541da177e4SLinus Torvalds #define QUERY_FW_ERR_SIZE_OFFSET 0x38 7551da177e4SLinus Torvalds 75614abdffcSEli Cohen #define QUERY_FW_CMD_DB_EN_OFFSET 0x10 75714abdffcSEli Cohen #define QUERY_FW_CMD_DB_OFFSET 0x50 75814abdffcSEli Cohen #define QUERY_FW_CMD_DB_BASE 0x60 75914abdffcSEli Cohen 7601da177e4SLinus Torvalds #define QUERY_FW_START_OFFSET 0x20 7611da177e4SLinus Torvalds #define QUERY_FW_END_OFFSET 0x28 7621da177e4SLinus Torvalds 7631da177e4SLinus Torvalds #define QUERY_FW_SIZE_OFFSET 0x00 7641da177e4SLinus Torvalds #define QUERY_FW_CLR_INT_BASE_OFFSET 0x20 7651da177e4SLinus Torvalds #define QUERY_FW_EQ_ARM_BASE_OFFSET 0x40 7661da177e4SLinus Torvalds #define QUERY_FW_EQ_SET_CI_BASE_OFFSET 0x48 7671da177e4SLinus Torvalds 768ed878458SRoland Dreier mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL); 769ed878458SRoland Dreier if (IS_ERR(mailbox)) 770ed878458SRoland Dreier return PTR_ERR(mailbox); 771ed878458SRoland Dreier outbox = mailbox->buf; 7721da177e4SLinus Torvalds 773ed878458SRoland Dreier err = mthca_cmd_box(dev, 0, mailbox->dma, 0, 0, CMD_QUERY_FW, 7741da177e4SLinus Torvalds CMD_TIME_CLASS_A, status); 7751da177e4SLinus Torvalds 7761da177e4SLinus Torvalds if (err) 7771da177e4SLinus Torvalds goto out; 7781da177e4SLinus Torvalds 7791da177e4SLinus Torvalds MTHCA_GET(dev->fw_ver, outbox, QUERY_FW_VER_OFFSET); 7801da177e4SLinus Torvalds /* 7813e1db334SRoland Dreier * FW subminor version is at more significant bits than minor 7821da177e4SLinus Torvalds * version, so swap here. 7831da177e4SLinus Torvalds */ 7841da177e4SLinus Torvalds dev->fw_ver = (dev->fw_ver & 0xffff00000000ull) | 7851da177e4SLinus Torvalds ((dev->fw_ver & 0xffff0000ull) >> 16) | 7861da177e4SLinus Torvalds ((dev->fw_ver & 0x0000ffffull) << 16); 7871da177e4SLinus Torvalds 7888fdf679fSRoland Dreier MTHCA_GET(lg, outbox, QUERY_FW_MAX_CMD_OFFSET); 7898fdf679fSRoland Dreier dev->cmd.max_cmds = 1 << lg; 7908fdf679fSRoland Dreier 79114abdffcSEli Cohen mthca_dbg(dev, "FW version %012llx, max commands %d\n", 79214abdffcSEli Cohen (unsigned long long) dev->fw_ver, dev->cmd.max_cmds); 79314abdffcSEli Cohen 7943d155f8cSRoland Dreier MTHCA_GET(dev->catas_err.addr, outbox, QUERY_FW_ERR_START_OFFSET); 7953d155f8cSRoland Dreier MTHCA_GET(dev->catas_err.size, outbox, QUERY_FW_ERR_SIZE_OFFSET); 7961da177e4SLinus Torvalds 7973d155f8cSRoland Dreier mthca_dbg(dev, "Catastrophic error buffer at 0x%llx, size 0x%x\n", 7983d155f8cSRoland Dreier (unsigned long long) dev->catas_err.addr, dev->catas_err.size); 7991da177e4SLinus Torvalds 80014abdffcSEli Cohen MTHCA_GET(tmp, outbox, QUERY_FW_CMD_DB_EN_OFFSET); 80114abdffcSEli Cohen if (tmp & 0x1) { 80214abdffcSEli Cohen mthca_dbg(dev, "FW supports commands through doorbells\n"); 80314abdffcSEli Cohen 80414abdffcSEli Cohen MTHCA_GET(base, outbox, QUERY_FW_CMD_DB_BASE); 80514abdffcSEli Cohen for (i = 0; i < MTHCA_CMD_NUM_DBELL_DWORDS; ++i) 80614abdffcSEli Cohen MTHCA_GET(dev->cmd.dbell_offsets[i], outbox, 80714abdffcSEli Cohen QUERY_FW_CMD_DB_OFFSET + (i << 1)); 80814abdffcSEli Cohen 80914abdffcSEli Cohen mthca_setup_cmd_doorbells(dev, base); 81014abdffcSEli Cohen } 81114abdffcSEli Cohen 812d10ddbf6SRoland Dreier if (mthca_is_memfree(dev)) { 8131da177e4SLinus Torvalds MTHCA_GET(dev->fw.arbel.fw_pages, outbox, QUERY_FW_SIZE_OFFSET); 8141da177e4SLinus Torvalds MTHCA_GET(dev->fw.arbel.clr_int_base, outbox, QUERY_FW_CLR_INT_BASE_OFFSET); 8151da177e4SLinus Torvalds MTHCA_GET(dev->fw.arbel.eq_arm_base, outbox, QUERY_FW_EQ_ARM_BASE_OFFSET); 8161da177e4SLinus Torvalds MTHCA_GET(dev->fw.arbel.eq_set_ci_base, outbox, QUERY_FW_EQ_SET_CI_BASE_OFFSET); 8171da177e4SLinus Torvalds mthca_dbg(dev, "FW size %d KB\n", dev->fw.arbel.fw_pages << 2); 8181da177e4SLinus Torvalds 8191da177e4SLinus Torvalds /* 8208d3ef29dSIshai Rabinovitz * Round up number of system pages needed in case 8218d3ef29dSIshai Rabinovitz * MTHCA_ICM_PAGE_SIZE < PAGE_SIZE. 8221da177e4SLinus Torvalds */ 8231da177e4SLinus Torvalds dev->fw.arbel.fw_pages = 8248d3ef29dSIshai Rabinovitz ALIGN(dev->fw.arbel.fw_pages, PAGE_SIZE / MTHCA_ICM_PAGE_SIZE) >> 8258d3ef29dSIshai Rabinovitz (PAGE_SHIFT - MTHCA_ICM_PAGE_SHIFT); 8261da177e4SLinus Torvalds 8271da177e4SLinus Torvalds mthca_dbg(dev, "Clear int @ %llx, EQ arm @ %llx, EQ set CI @ %llx\n", 8281da177e4SLinus Torvalds (unsigned long long) dev->fw.arbel.clr_int_base, 8291da177e4SLinus Torvalds (unsigned long long) dev->fw.arbel.eq_arm_base, 8301da177e4SLinus Torvalds (unsigned long long) dev->fw.arbel.eq_set_ci_base); 8311da177e4SLinus Torvalds } else { 8321da177e4SLinus Torvalds MTHCA_GET(dev->fw.tavor.fw_start, outbox, QUERY_FW_START_OFFSET); 8331da177e4SLinus Torvalds MTHCA_GET(dev->fw.tavor.fw_end, outbox, QUERY_FW_END_OFFSET); 8341da177e4SLinus Torvalds 8351da177e4SLinus Torvalds mthca_dbg(dev, "FW size %d KB (start %llx, end %llx)\n", 8361da177e4SLinus Torvalds (int) ((dev->fw.tavor.fw_end - dev->fw.tavor.fw_start) >> 10), 8371da177e4SLinus Torvalds (unsigned long long) dev->fw.tavor.fw_start, 8381da177e4SLinus Torvalds (unsigned long long) dev->fw.tavor.fw_end); 8391da177e4SLinus Torvalds } 8401da177e4SLinus Torvalds 8411da177e4SLinus Torvalds out: 842ed878458SRoland Dreier mthca_free_mailbox(dev, mailbox); 8431da177e4SLinus Torvalds return err; 8441da177e4SLinus Torvalds } 8451da177e4SLinus Torvalds 8461da177e4SLinus Torvalds int mthca_ENABLE_LAM(struct mthca_dev *dev, u8 *status) 8471da177e4SLinus Torvalds { 848ed878458SRoland Dreier struct mthca_mailbox *mailbox; 8491da177e4SLinus Torvalds u8 info; 8501da177e4SLinus Torvalds u32 *outbox; 8511da177e4SLinus Torvalds int err = 0; 8521da177e4SLinus Torvalds 8531da177e4SLinus Torvalds #define ENABLE_LAM_OUT_SIZE 0x100 8541da177e4SLinus Torvalds #define ENABLE_LAM_START_OFFSET 0x00 8551da177e4SLinus Torvalds #define ENABLE_LAM_END_OFFSET 0x08 8561da177e4SLinus Torvalds #define ENABLE_LAM_INFO_OFFSET 0x13 8571da177e4SLinus Torvalds 8581da177e4SLinus Torvalds #define ENABLE_LAM_INFO_HIDDEN_FLAG (1 << 4) 8591da177e4SLinus Torvalds #define ENABLE_LAM_INFO_ECC_MASK 0x3 8601da177e4SLinus Torvalds 861ed878458SRoland Dreier mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL); 862ed878458SRoland Dreier if (IS_ERR(mailbox)) 863ed878458SRoland Dreier return PTR_ERR(mailbox); 864ed878458SRoland Dreier outbox = mailbox->buf; 8651da177e4SLinus Torvalds 866ed878458SRoland Dreier err = mthca_cmd_box(dev, 0, mailbox->dma, 0, 0, CMD_ENABLE_LAM, 8671da177e4SLinus Torvalds CMD_TIME_CLASS_C, status); 8681da177e4SLinus Torvalds 8691da177e4SLinus Torvalds if (err) 8701da177e4SLinus Torvalds goto out; 8711da177e4SLinus Torvalds 8721da177e4SLinus Torvalds if (*status == MTHCA_CMD_STAT_LAM_NOT_PRE) 8731da177e4SLinus Torvalds goto out; 8741da177e4SLinus Torvalds 8751da177e4SLinus Torvalds MTHCA_GET(dev->ddr_start, outbox, ENABLE_LAM_START_OFFSET); 8761da177e4SLinus Torvalds MTHCA_GET(dev->ddr_end, outbox, ENABLE_LAM_END_OFFSET); 8771da177e4SLinus Torvalds MTHCA_GET(info, outbox, ENABLE_LAM_INFO_OFFSET); 8781da177e4SLinus Torvalds 8791da177e4SLinus Torvalds if (!!(info & ENABLE_LAM_INFO_HIDDEN_FLAG) != 8801da177e4SLinus Torvalds !!(dev->mthca_flags & MTHCA_FLAG_DDR_HIDDEN)) { 8811da177e4SLinus Torvalds mthca_info(dev, "FW reports that HCA-attached memory " 8821da177e4SLinus Torvalds "is %s hidden; does not match PCI config\n", 8831da177e4SLinus Torvalds (info & ENABLE_LAM_INFO_HIDDEN_FLAG) ? 8841da177e4SLinus Torvalds "" : "not"); 8851da177e4SLinus Torvalds } 8861da177e4SLinus Torvalds if (info & ENABLE_LAM_INFO_HIDDEN_FLAG) 8871da177e4SLinus Torvalds mthca_dbg(dev, "HCA-attached memory is hidden.\n"); 8881da177e4SLinus Torvalds 8891da177e4SLinus Torvalds mthca_dbg(dev, "HCA memory size %d KB (start %llx, end %llx)\n", 8901da177e4SLinus Torvalds (int) ((dev->ddr_end - dev->ddr_start) >> 10), 8911da177e4SLinus Torvalds (unsigned long long) dev->ddr_start, 8921da177e4SLinus Torvalds (unsigned long long) dev->ddr_end); 8931da177e4SLinus Torvalds 8941da177e4SLinus Torvalds out: 895ed878458SRoland Dreier mthca_free_mailbox(dev, mailbox); 8961da177e4SLinus Torvalds return err; 8971da177e4SLinus Torvalds } 8981da177e4SLinus Torvalds 8991da177e4SLinus Torvalds int mthca_DISABLE_LAM(struct mthca_dev *dev, u8 *status) 9001da177e4SLinus Torvalds { 9011da177e4SLinus Torvalds return mthca_cmd(dev, 0, 0, 0, CMD_SYS_DIS, CMD_TIME_CLASS_C, status); 9021da177e4SLinus Torvalds } 9031da177e4SLinus Torvalds 9041da177e4SLinus Torvalds int mthca_QUERY_DDR(struct mthca_dev *dev, u8 *status) 9051da177e4SLinus Torvalds { 906ed878458SRoland Dreier struct mthca_mailbox *mailbox; 9071da177e4SLinus Torvalds u8 info; 9081da177e4SLinus Torvalds u32 *outbox; 9091da177e4SLinus Torvalds int err = 0; 9101da177e4SLinus Torvalds 9111da177e4SLinus Torvalds #define QUERY_DDR_OUT_SIZE 0x100 9121da177e4SLinus Torvalds #define QUERY_DDR_START_OFFSET 0x00 9131da177e4SLinus Torvalds #define QUERY_DDR_END_OFFSET 0x08 9141da177e4SLinus Torvalds #define QUERY_DDR_INFO_OFFSET 0x13 9151da177e4SLinus Torvalds 9161da177e4SLinus Torvalds #define QUERY_DDR_INFO_HIDDEN_FLAG (1 << 4) 9171da177e4SLinus Torvalds #define QUERY_DDR_INFO_ECC_MASK 0x3 9181da177e4SLinus Torvalds 919ed878458SRoland Dreier mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL); 920ed878458SRoland Dreier if (IS_ERR(mailbox)) 921ed878458SRoland Dreier return PTR_ERR(mailbox); 922ed878458SRoland Dreier outbox = mailbox->buf; 9231da177e4SLinus Torvalds 924ed878458SRoland Dreier err = mthca_cmd_box(dev, 0, mailbox->dma, 0, 0, CMD_QUERY_DDR, 9251da177e4SLinus Torvalds CMD_TIME_CLASS_A, status); 9261da177e4SLinus Torvalds 9271da177e4SLinus Torvalds if (err) 9281da177e4SLinus Torvalds goto out; 9291da177e4SLinus Torvalds 9301da177e4SLinus Torvalds MTHCA_GET(dev->ddr_start, outbox, QUERY_DDR_START_OFFSET); 9311da177e4SLinus Torvalds MTHCA_GET(dev->ddr_end, outbox, QUERY_DDR_END_OFFSET); 9321da177e4SLinus Torvalds MTHCA_GET(info, outbox, QUERY_DDR_INFO_OFFSET); 9331da177e4SLinus Torvalds 9341da177e4SLinus Torvalds if (!!(info & QUERY_DDR_INFO_HIDDEN_FLAG) != 9351da177e4SLinus Torvalds !!(dev->mthca_flags & MTHCA_FLAG_DDR_HIDDEN)) { 9361da177e4SLinus Torvalds mthca_info(dev, "FW reports that HCA-attached memory " 9371da177e4SLinus Torvalds "is %s hidden; does not match PCI config\n", 9381da177e4SLinus Torvalds (info & QUERY_DDR_INFO_HIDDEN_FLAG) ? 9391da177e4SLinus Torvalds "" : "not"); 9401da177e4SLinus Torvalds } 9411da177e4SLinus Torvalds if (info & QUERY_DDR_INFO_HIDDEN_FLAG) 9421da177e4SLinus Torvalds mthca_dbg(dev, "HCA-attached memory is hidden.\n"); 9431da177e4SLinus Torvalds 9441da177e4SLinus Torvalds mthca_dbg(dev, "HCA memory size %d KB (start %llx, end %llx)\n", 9451da177e4SLinus Torvalds (int) ((dev->ddr_end - dev->ddr_start) >> 10), 9461da177e4SLinus Torvalds (unsigned long long) dev->ddr_start, 9471da177e4SLinus Torvalds (unsigned long long) dev->ddr_end); 9481da177e4SLinus Torvalds 9491da177e4SLinus Torvalds out: 950ed878458SRoland Dreier mthca_free_mailbox(dev, mailbox); 9511da177e4SLinus Torvalds return err; 9521da177e4SLinus Torvalds } 9531da177e4SLinus Torvalds 9541da177e4SLinus Torvalds int mthca_QUERY_DEV_LIM(struct mthca_dev *dev, 9551da177e4SLinus Torvalds struct mthca_dev_lim *dev_lim, u8 *status) 9561da177e4SLinus Torvalds { 957ed878458SRoland Dreier struct mthca_mailbox *mailbox; 9581da177e4SLinus Torvalds u32 *outbox; 9591da177e4SLinus Torvalds u8 field; 9601da177e4SLinus Torvalds u16 size; 961bf6a9e31SJack Morgenstein u16 stat_rate; 9621da177e4SLinus Torvalds int err; 9631da177e4SLinus Torvalds 9641da177e4SLinus Torvalds #define QUERY_DEV_LIM_OUT_SIZE 0x100 9651da177e4SLinus Torvalds #define QUERY_DEV_LIM_MAX_SRQ_SZ_OFFSET 0x10 9661da177e4SLinus Torvalds #define QUERY_DEV_LIM_MAX_QP_SZ_OFFSET 0x11 9671da177e4SLinus Torvalds #define QUERY_DEV_LIM_RSVD_QP_OFFSET 0x12 9681da177e4SLinus Torvalds #define QUERY_DEV_LIM_MAX_QP_OFFSET 0x13 9691da177e4SLinus Torvalds #define QUERY_DEV_LIM_RSVD_SRQ_OFFSET 0x14 9701da177e4SLinus Torvalds #define QUERY_DEV_LIM_MAX_SRQ_OFFSET 0x15 9711da177e4SLinus Torvalds #define QUERY_DEV_LIM_RSVD_EEC_OFFSET 0x16 9721da177e4SLinus Torvalds #define QUERY_DEV_LIM_MAX_EEC_OFFSET 0x17 9731da177e4SLinus Torvalds #define QUERY_DEV_LIM_MAX_CQ_SZ_OFFSET 0x19 9741da177e4SLinus Torvalds #define QUERY_DEV_LIM_RSVD_CQ_OFFSET 0x1a 9751da177e4SLinus Torvalds #define QUERY_DEV_LIM_MAX_CQ_OFFSET 0x1b 9761da177e4SLinus Torvalds #define QUERY_DEV_LIM_MAX_MPT_OFFSET 0x1d 9771da177e4SLinus Torvalds #define QUERY_DEV_LIM_RSVD_EQ_OFFSET 0x1e 9781da177e4SLinus Torvalds #define QUERY_DEV_LIM_MAX_EQ_OFFSET 0x1f 9791da177e4SLinus Torvalds #define QUERY_DEV_LIM_RSVD_MTT_OFFSET 0x20 9801da177e4SLinus Torvalds #define QUERY_DEV_LIM_MAX_MRW_SZ_OFFSET 0x21 9811da177e4SLinus Torvalds #define QUERY_DEV_LIM_RSVD_MRW_OFFSET 0x22 9821da177e4SLinus Torvalds #define QUERY_DEV_LIM_MAX_MTT_SEG_OFFSET 0x23 9831da177e4SLinus Torvalds #define QUERY_DEV_LIM_MAX_AV_OFFSET 0x27 9841da177e4SLinus Torvalds #define QUERY_DEV_LIM_MAX_REQ_QP_OFFSET 0x29 9851da177e4SLinus Torvalds #define QUERY_DEV_LIM_MAX_RES_QP_OFFSET 0x2b 9861da177e4SLinus Torvalds #define QUERY_DEV_LIM_MAX_RDMA_OFFSET 0x2f 9871da177e4SLinus Torvalds #define QUERY_DEV_LIM_RSZ_SRQ_OFFSET 0x33 9881da177e4SLinus Torvalds #define QUERY_DEV_LIM_ACK_DELAY_OFFSET 0x35 9891da177e4SLinus Torvalds #define QUERY_DEV_LIM_MTU_WIDTH_OFFSET 0x36 9901da177e4SLinus Torvalds #define QUERY_DEV_LIM_VL_PORT_OFFSET 0x37 9911da177e4SLinus Torvalds #define QUERY_DEV_LIM_MAX_GID_OFFSET 0x3b 992bf6a9e31SJack Morgenstein #define QUERY_DEV_LIM_RATE_SUPPORT_OFFSET 0x3c 9931da177e4SLinus Torvalds #define QUERY_DEV_LIM_MAX_PKEY_OFFSET 0x3f 9941da177e4SLinus Torvalds #define QUERY_DEV_LIM_FLAGS_OFFSET 0x44 9951da177e4SLinus Torvalds #define QUERY_DEV_LIM_RSVD_UAR_OFFSET 0x48 9961da177e4SLinus Torvalds #define QUERY_DEV_LIM_UAR_SZ_OFFSET 0x49 9971da177e4SLinus Torvalds #define QUERY_DEV_LIM_PAGE_SZ_OFFSET 0x4b 9981da177e4SLinus Torvalds #define QUERY_DEV_LIM_MAX_SG_OFFSET 0x51 9991da177e4SLinus Torvalds #define QUERY_DEV_LIM_MAX_DESC_SZ_OFFSET 0x52 10001da177e4SLinus Torvalds #define QUERY_DEV_LIM_MAX_SG_RQ_OFFSET 0x55 10011da177e4SLinus Torvalds #define QUERY_DEV_LIM_MAX_DESC_SZ_RQ_OFFSET 0x56 10021da177e4SLinus Torvalds #define QUERY_DEV_LIM_MAX_QP_MCG_OFFSET 0x61 10031da177e4SLinus Torvalds #define QUERY_DEV_LIM_RSVD_MCG_OFFSET 0x62 10041da177e4SLinus Torvalds #define QUERY_DEV_LIM_MAX_MCG_OFFSET 0x63 10051da177e4SLinus Torvalds #define QUERY_DEV_LIM_RSVD_PD_OFFSET 0x64 10061da177e4SLinus Torvalds #define QUERY_DEV_LIM_MAX_PD_OFFSET 0x65 10071da177e4SLinus Torvalds #define QUERY_DEV_LIM_RSVD_RDD_OFFSET 0x66 10081da177e4SLinus Torvalds #define QUERY_DEV_LIM_MAX_RDD_OFFSET 0x67 10091da177e4SLinus Torvalds #define QUERY_DEV_LIM_EEC_ENTRY_SZ_OFFSET 0x80 10101da177e4SLinus Torvalds #define QUERY_DEV_LIM_QPC_ENTRY_SZ_OFFSET 0x82 10111da177e4SLinus Torvalds #define QUERY_DEV_LIM_EEEC_ENTRY_SZ_OFFSET 0x84 10121da177e4SLinus Torvalds #define QUERY_DEV_LIM_EQPC_ENTRY_SZ_OFFSET 0x86 10131da177e4SLinus Torvalds #define QUERY_DEV_LIM_EQC_ENTRY_SZ_OFFSET 0x88 10141da177e4SLinus Torvalds #define QUERY_DEV_LIM_CQC_ENTRY_SZ_OFFSET 0x8a 10151da177e4SLinus Torvalds #define QUERY_DEV_LIM_SRQ_ENTRY_SZ_OFFSET 0x8c 10161da177e4SLinus Torvalds #define QUERY_DEV_LIM_UAR_ENTRY_SZ_OFFSET 0x8e 10171da177e4SLinus Torvalds #define QUERY_DEV_LIM_MTT_ENTRY_SZ_OFFSET 0x90 10181da177e4SLinus Torvalds #define QUERY_DEV_LIM_MPT_ENTRY_SZ_OFFSET 0x92 10191da177e4SLinus Torvalds #define QUERY_DEV_LIM_PBL_SZ_OFFSET 0x96 10201da177e4SLinus Torvalds #define QUERY_DEV_LIM_BMME_FLAGS_OFFSET 0x97 10211da177e4SLinus Torvalds #define QUERY_DEV_LIM_RSVD_LKEY_OFFSET 0x98 10221da177e4SLinus Torvalds #define QUERY_DEV_LIM_LAMR_OFFSET 0x9f 10231da177e4SLinus Torvalds #define QUERY_DEV_LIM_MAX_ICM_SZ_OFFSET 0xa0 10241da177e4SLinus Torvalds 1025ed878458SRoland Dreier mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL); 1026ed878458SRoland Dreier if (IS_ERR(mailbox)) 1027ed878458SRoland Dreier return PTR_ERR(mailbox); 1028ed878458SRoland Dreier outbox = mailbox->buf; 10291da177e4SLinus Torvalds 1030ed878458SRoland Dreier err = mthca_cmd_box(dev, 0, mailbox->dma, 0, 0, CMD_QUERY_DEV_LIM, 10311da177e4SLinus Torvalds CMD_TIME_CLASS_A, status); 10321da177e4SLinus Torvalds 10331da177e4SLinus Torvalds if (err) 10341da177e4SLinus Torvalds goto out; 10351da177e4SLinus Torvalds 10361da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_QP_OFFSET); 10371da177e4SLinus Torvalds dev_lim->reserved_qps = 1 << (field & 0xf); 10381da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_QP_OFFSET); 10391da177e4SLinus Torvalds dev_lim->max_qps = 1 << (field & 0x1f); 10401da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_SRQ_OFFSET); 10411da177e4SLinus Torvalds dev_lim->reserved_srqs = 1 << (field >> 4); 10421da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_SRQ_OFFSET); 10431da177e4SLinus Torvalds dev_lim->max_srqs = 1 << (field & 0x1f); 10441da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_EEC_OFFSET); 10451da177e4SLinus Torvalds dev_lim->reserved_eecs = 1 << (field & 0xf); 10461da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_EEC_OFFSET); 10471da177e4SLinus Torvalds dev_lim->max_eecs = 1 << (field & 0x1f); 10481da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_CQ_SZ_OFFSET); 10491da177e4SLinus Torvalds dev_lim->max_cq_sz = 1 << field; 10501da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_CQ_OFFSET); 10511da177e4SLinus Torvalds dev_lim->reserved_cqs = 1 << (field & 0xf); 10521da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_CQ_OFFSET); 10531da177e4SLinus Torvalds dev_lim->max_cqs = 1 << (field & 0x1f); 10541da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_MPT_OFFSET); 10551da177e4SLinus Torvalds dev_lim->max_mpts = 1 << (field & 0x3f); 10561da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_EQ_OFFSET); 10571da177e4SLinus Torvalds dev_lim->reserved_eqs = 1 << (field & 0xf); 10581da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_EQ_OFFSET); 10591da177e4SLinus Torvalds dev_lim->max_eqs = 1 << (field & 0x7); 10601da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_MTT_OFFSET); 1061c7d204e8SMichael S. Tsirkin if (mthca_is_memfree(dev)) 1062c7d204e8SMichael S. Tsirkin dev_lim->reserved_mtts = ALIGN((1 << (field >> 4)) * sizeof(u64), 1063c1f67a88SEli Cohen dev->limits.mtt_seg_size) / dev->limits.mtt_seg_size; 1064c7d204e8SMichael S. Tsirkin else 10651da177e4SLinus Torvalds dev_lim->reserved_mtts = 1 << (field >> 4); 10661da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_MRW_SZ_OFFSET); 10671da177e4SLinus Torvalds dev_lim->max_mrw_sz = 1 << field; 10681da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_MRW_OFFSET); 10691da177e4SLinus Torvalds dev_lim->reserved_mrws = 1 << (field & 0xf); 10701da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_MTT_SEG_OFFSET); 10711da177e4SLinus Torvalds dev_lim->max_mtt_seg = 1 << (field & 0x3f); 10721da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_REQ_QP_OFFSET); 10731da177e4SLinus Torvalds dev_lim->max_requester_per_qp = 1 << (field & 0x3f); 10741da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_RES_QP_OFFSET); 10751da177e4SLinus Torvalds dev_lim->max_responder_per_qp = 1 << (field & 0x3f); 10761da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_RDMA_OFFSET); 10771da177e4SLinus Torvalds dev_lim->max_rdma_global = 1 << (field & 0x3f); 10781da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_ACK_DELAY_OFFSET); 10791da177e4SLinus Torvalds dev_lim->local_ca_ack_delay = field & 0x1f; 10801da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_MTU_WIDTH_OFFSET); 10811da177e4SLinus Torvalds dev_lim->max_mtu = field >> 4; 10821da177e4SLinus Torvalds dev_lim->max_port_width = field & 0xf; 10831da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_VL_PORT_OFFSET); 10841da177e4SLinus Torvalds dev_lim->max_vl = field >> 4; 10851da177e4SLinus Torvalds dev_lim->num_ports = field & 0xf; 10861da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_GID_OFFSET); 10871da177e4SLinus Torvalds dev_lim->max_gids = 1 << (field & 0xf); 1088bf6a9e31SJack Morgenstein MTHCA_GET(stat_rate, outbox, QUERY_DEV_LIM_RATE_SUPPORT_OFFSET); 1089bf6a9e31SJack Morgenstein dev_lim->stat_rate_support = stat_rate; 10901da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_PKEY_OFFSET); 10911da177e4SLinus Torvalds dev_lim->max_pkeys = 1 << (field & 0xf); 10921da177e4SLinus Torvalds MTHCA_GET(dev_lim->flags, outbox, QUERY_DEV_LIM_FLAGS_OFFSET); 10931da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_UAR_OFFSET); 10941da177e4SLinus Torvalds dev_lim->reserved_uars = field >> 4; 10951da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_UAR_SZ_OFFSET); 10961da177e4SLinus Torvalds dev_lim->uar_size = 1 << ((field & 0x3f) + 20); 10971da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_PAGE_SZ_OFFSET); 10981da177e4SLinus Torvalds dev_lim->min_page_sz = 1 << field; 10991da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_SG_OFFSET); 11001da177e4SLinus Torvalds dev_lim->max_sg = field; 11011da177e4SLinus Torvalds 11021da177e4SLinus Torvalds MTHCA_GET(size, outbox, QUERY_DEV_LIM_MAX_DESC_SZ_OFFSET); 11031da177e4SLinus Torvalds dev_lim->max_desc_sz = size; 11041da177e4SLinus Torvalds 11051da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_QP_MCG_OFFSET); 11061da177e4SLinus Torvalds dev_lim->max_qp_per_mcg = 1 << field; 11071da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_MCG_OFFSET); 11081da177e4SLinus Torvalds dev_lim->reserved_mgms = field & 0xf; 11091da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_MCG_OFFSET); 11101da177e4SLinus Torvalds dev_lim->max_mcgs = 1 << field; 11111da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_PD_OFFSET); 11121da177e4SLinus Torvalds dev_lim->reserved_pds = field >> 4; 11131da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_PD_OFFSET); 11141da177e4SLinus Torvalds dev_lim->max_pds = 1 << (field & 0x3f); 11151da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_RDD_OFFSET); 11161da177e4SLinus Torvalds dev_lim->reserved_rdds = field >> 4; 11171da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_RDD_OFFSET); 11181da177e4SLinus Torvalds dev_lim->max_rdds = 1 << (field & 0x3f); 11191da177e4SLinus Torvalds 11201da177e4SLinus Torvalds MTHCA_GET(size, outbox, QUERY_DEV_LIM_EEC_ENTRY_SZ_OFFSET); 11211da177e4SLinus Torvalds dev_lim->eec_entry_sz = size; 11221da177e4SLinus Torvalds MTHCA_GET(size, outbox, QUERY_DEV_LIM_QPC_ENTRY_SZ_OFFSET); 11231da177e4SLinus Torvalds dev_lim->qpc_entry_sz = size; 11241da177e4SLinus Torvalds MTHCA_GET(size, outbox, QUERY_DEV_LIM_EEEC_ENTRY_SZ_OFFSET); 11251da177e4SLinus Torvalds dev_lim->eeec_entry_sz = size; 11261da177e4SLinus Torvalds MTHCA_GET(size, outbox, QUERY_DEV_LIM_EQPC_ENTRY_SZ_OFFSET); 11271da177e4SLinus Torvalds dev_lim->eqpc_entry_sz = size; 11281da177e4SLinus Torvalds MTHCA_GET(size, outbox, QUERY_DEV_LIM_EQC_ENTRY_SZ_OFFSET); 11291da177e4SLinus Torvalds dev_lim->eqc_entry_sz = size; 11301da177e4SLinus Torvalds MTHCA_GET(size, outbox, QUERY_DEV_LIM_CQC_ENTRY_SZ_OFFSET); 11311da177e4SLinus Torvalds dev_lim->cqc_entry_sz = size; 11321da177e4SLinus Torvalds MTHCA_GET(size, outbox, QUERY_DEV_LIM_SRQ_ENTRY_SZ_OFFSET); 11331da177e4SLinus Torvalds dev_lim->srq_entry_sz = size; 11341da177e4SLinus Torvalds MTHCA_GET(size, outbox, QUERY_DEV_LIM_UAR_ENTRY_SZ_OFFSET); 11351da177e4SLinus Torvalds dev_lim->uar_scratch_entry_sz = size; 11361da177e4SLinus Torvalds 1137d10ddbf6SRoland Dreier if (mthca_is_memfree(dev)) { 1138a3c8ab4fSJack Morgenstein MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_SRQ_SZ_OFFSET); 1139a3c8ab4fSJack Morgenstein dev_lim->max_srq_sz = 1 << field; 1140a3c8ab4fSJack Morgenstein MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_QP_SZ_OFFSET); 1141a3c8ab4fSJack Morgenstein dev_lim->max_qp_sz = 1 << field; 11421da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSZ_SRQ_OFFSET); 11431da177e4SLinus Torvalds dev_lim->hca.arbel.resize_srq = field & 1; 11448cf2daf3SRoland Dreier MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_SG_RQ_OFFSET); 11458cf2daf3SRoland Dreier dev_lim->max_sg = min_t(int, field, dev_lim->max_sg); 114677369ed3SJack Morgenstein MTHCA_GET(size, outbox, QUERY_DEV_LIM_MAX_DESC_SZ_RQ_OFFSET); 114777369ed3SJack Morgenstein dev_lim->max_desc_sz = min_t(int, size, dev_lim->max_desc_sz); 11481da177e4SLinus Torvalds MTHCA_GET(size, outbox, QUERY_DEV_LIM_MPT_ENTRY_SZ_OFFSET); 11491da177e4SLinus Torvalds dev_lim->mpt_entry_sz = size; 11501da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_PBL_SZ_OFFSET); 11511da177e4SLinus Torvalds dev_lim->hca.arbel.max_pbl_sz = 1 << (field & 0x3f); 11521da177e4SLinus Torvalds MTHCA_GET(dev_lim->hca.arbel.bmme_flags, outbox, 11531da177e4SLinus Torvalds QUERY_DEV_LIM_BMME_FLAGS_OFFSET); 11541da177e4SLinus Torvalds MTHCA_GET(dev_lim->hca.arbel.reserved_lkey, outbox, 11551da177e4SLinus Torvalds QUERY_DEV_LIM_RSVD_LKEY_OFFSET); 11561da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_LAMR_OFFSET); 11571da177e4SLinus Torvalds dev_lim->hca.arbel.lam_required = field & 1; 11581da177e4SLinus Torvalds MTHCA_GET(dev_lim->hca.arbel.max_icm_sz, outbox, 11591da177e4SLinus Torvalds QUERY_DEV_LIM_MAX_ICM_SZ_OFFSET); 11601da177e4SLinus Torvalds 11611da177e4SLinus Torvalds if (dev_lim->hca.arbel.bmme_flags & 1) 11621da177e4SLinus Torvalds mthca_dbg(dev, "Base MM extensions: yes " 11631da177e4SLinus Torvalds "(flags %d, max PBL %d, rsvd L_Key %08x)\n", 11641da177e4SLinus Torvalds dev_lim->hca.arbel.bmme_flags, 11651da177e4SLinus Torvalds dev_lim->hca.arbel.max_pbl_sz, 11661da177e4SLinus Torvalds dev_lim->hca.arbel.reserved_lkey); 11671da177e4SLinus Torvalds else 11681da177e4SLinus Torvalds mthca_dbg(dev, "Base MM extensions: no\n"); 11691da177e4SLinus Torvalds 11701da177e4SLinus Torvalds mthca_dbg(dev, "Max ICM size %lld MB\n", 11711da177e4SLinus Torvalds (unsigned long long) dev_lim->hca.arbel.max_icm_sz >> 20); 11721da177e4SLinus Torvalds } else { 1173a3c8ab4fSJack Morgenstein MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_SRQ_SZ_OFFSET); 1174a3c8ab4fSJack Morgenstein dev_lim->max_srq_sz = (1 << field) - 1; 1175a3c8ab4fSJack Morgenstein MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_QP_SZ_OFFSET); 1176a3c8ab4fSJack Morgenstein dev_lim->max_qp_sz = (1 << field) - 1; 11771da177e4SLinus Torvalds MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_AV_OFFSET); 11781da177e4SLinus Torvalds dev_lim->hca.tavor.max_avs = 1 << (field & 0x3f); 11791da177e4SLinus Torvalds dev_lim->mpt_entry_sz = MTHCA_MPT_ENTRY_SIZE; 11801da177e4SLinus Torvalds } 11811da177e4SLinus Torvalds 1182f295c79bSRoland Dreier mthca_dbg(dev, "Max QPs: %d, reserved QPs: %d, entry size: %d\n", 1183f295c79bSRoland Dreier dev_lim->max_qps, dev_lim->reserved_qps, dev_lim->qpc_entry_sz); 1184f295c79bSRoland Dreier mthca_dbg(dev, "Max SRQs: %d, reserved SRQs: %d, entry size: %d\n", 1185f295c79bSRoland Dreier dev_lim->max_srqs, dev_lim->reserved_srqs, dev_lim->srq_entry_sz); 1186f295c79bSRoland Dreier mthca_dbg(dev, "Max CQs: %d, reserved CQs: %d, entry size: %d\n", 1187f295c79bSRoland Dreier dev_lim->max_cqs, dev_lim->reserved_cqs, dev_lim->cqc_entry_sz); 1188f295c79bSRoland Dreier mthca_dbg(dev, "Max EQs: %d, reserved EQs: %d, entry size: %d\n", 1189f295c79bSRoland Dreier dev_lim->max_eqs, dev_lim->reserved_eqs, dev_lim->eqc_entry_sz); 1190f295c79bSRoland Dreier mthca_dbg(dev, "reserved MPTs: %d, reserved MTTs: %d\n", 1191f295c79bSRoland Dreier dev_lim->reserved_mrws, dev_lim->reserved_mtts); 1192f295c79bSRoland Dreier mthca_dbg(dev, "Max PDs: %d, reserved PDs: %d, reserved UARs: %d\n", 1193f295c79bSRoland Dreier dev_lim->max_pds, dev_lim->reserved_pds, dev_lim->reserved_uars); 1194f295c79bSRoland Dreier mthca_dbg(dev, "Max QP/MCG: %d, reserved MGMs: %d\n", 1195f295c79bSRoland Dreier dev_lim->max_pds, dev_lim->reserved_mgms); 1196f295c79bSRoland Dreier mthca_dbg(dev, "Max CQEs: %d, max WQEs: %d, max SRQ WQEs: %d\n", 1197f295c79bSRoland Dreier dev_lim->max_cq_sz, dev_lim->max_qp_sz, dev_lim->max_srq_sz); 1198f295c79bSRoland Dreier 1199f295c79bSRoland Dreier mthca_dbg(dev, "Flags: %08x\n", dev_lim->flags); 1200f295c79bSRoland Dreier 12011da177e4SLinus Torvalds out: 1202ed878458SRoland Dreier mthca_free_mailbox(dev, mailbox); 12031da177e4SLinus Torvalds return err; 12041da177e4SLinus Torvalds } 12051da177e4SLinus Torvalds 12062e8b981cSMichael S. Tsirkin static void get_board_id(void *vsd, char *board_id) 12072e8b981cSMichael S. Tsirkin { 12082e8b981cSMichael S. Tsirkin int i; 12092e8b981cSMichael S. Tsirkin 12102e8b981cSMichael S. Tsirkin #define VSD_OFFSET_SIG1 0x00 12112e8b981cSMichael S. Tsirkin #define VSD_OFFSET_SIG2 0xde 12122e8b981cSMichael S. Tsirkin #define VSD_OFFSET_MLX_BOARD_ID 0xd0 12132e8b981cSMichael S. Tsirkin #define VSD_OFFSET_TS_BOARD_ID 0x20 12142e8b981cSMichael S. Tsirkin 12152e8b981cSMichael S. Tsirkin #define VSD_SIGNATURE_TOPSPIN 0x5ad 12162e8b981cSMichael S. Tsirkin 12172e8b981cSMichael S. Tsirkin memset(board_id, 0, MTHCA_BOARD_ID_LEN); 12182e8b981cSMichael S. Tsirkin 12192e8b981cSMichael S. Tsirkin if (be16_to_cpup(vsd + VSD_OFFSET_SIG1) == VSD_SIGNATURE_TOPSPIN && 12202e8b981cSMichael S. Tsirkin be16_to_cpup(vsd + VSD_OFFSET_SIG2) == VSD_SIGNATURE_TOPSPIN) { 12212e8b981cSMichael S. Tsirkin strlcpy(board_id, vsd + VSD_OFFSET_TS_BOARD_ID, MTHCA_BOARD_ID_LEN); 12222e8b981cSMichael S. Tsirkin } else { 12232e8b981cSMichael S. Tsirkin /* 12242e8b981cSMichael S. Tsirkin * The board ID is a string but the firmware byte 12252e8b981cSMichael S. Tsirkin * swaps each 4-byte word before passing it back to 12262e8b981cSMichael S. Tsirkin * us. Therefore we need to swab it before printing. 12272e8b981cSMichael S. Tsirkin */ 12282e8b981cSMichael S. Tsirkin for (i = 0; i < 4; ++i) 12292e8b981cSMichael S. Tsirkin ((u32 *) board_id)[i] = 12302e8b981cSMichael S. Tsirkin swab32(*(u32 *) (vsd + VSD_OFFSET_MLX_BOARD_ID + i * 4)); 12312e8b981cSMichael S. Tsirkin } 12322e8b981cSMichael S. Tsirkin } 12332e8b981cSMichael S. Tsirkin 12341da177e4SLinus Torvalds int mthca_QUERY_ADAPTER(struct mthca_dev *dev, 12351da177e4SLinus Torvalds struct mthca_adapter *adapter, u8 *status) 12361da177e4SLinus Torvalds { 1237ed878458SRoland Dreier struct mthca_mailbox *mailbox; 12381da177e4SLinus Torvalds u32 *outbox; 12391da177e4SLinus Torvalds int err; 12401da177e4SLinus Torvalds 12411da177e4SLinus Torvalds #define QUERY_ADAPTER_OUT_SIZE 0x100 12421da177e4SLinus Torvalds #define QUERY_ADAPTER_VENDOR_ID_OFFSET 0x00 12431da177e4SLinus Torvalds #define QUERY_ADAPTER_DEVICE_ID_OFFSET 0x04 12441da177e4SLinus Torvalds #define QUERY_ADAPTER_REVISION_ID_OFFSET 0x08 12451da177e4SLinus Torvalds #define QUERY_ADAPTER_INTA_PIN_OFFSET 0x10 12462e8b981cSMichael S. Tsirkin #define QUERY_ADAPTER_VSD_OFFSET 0x20 12471da177e4SLinus Torvalds 1248ed878458SRoland Dreier mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL); 1249ed878458SRoland Dreier if (IS_ERR(mailbox)) 1250ed878458SRoland Dreier return PTR_ERR(mailbox); 1251ed878458SRoland Dreier outbox = mailbox->buf; 12521da177e4SLinus Torvalds 1253ed878458SRoland Dreier err = mthca_cmd_box(dev, 0, mailbox->dma, 0, 0, CMD_QUERY_ADAPTER, 12541da177e4SLinus Torvalds CMD_TIME_CLASS_A, status); 12551da177e4SLinus Torvalds 12561da177e4SLinus Torvalds if (err) 12571da177e4SLinus Torvalds goto out; 12581da177e4SLinus Torvalds 12596ccef1deSJack Morgenstein if (!mthca_is_memfree(dev)) { 12606ccef1deSJack Morgenstein MTHCA_GET(adapter->vendor_id, outbox, 12616ccef1deSJack Morgenstein QUERY_ADAPTER_VENDOR_ID_OFFSET); 12626ccef1deSJack Morgenstein MTHCA_GET(adapter->device_id, outbox, 12636ccef1deSJack Morgenstein QUERY_ADAPTER_DEVICE_ID_OFFSET); 12646ccef1deSJack Morgenstein MTHCA_GET(adapter->revision_id, outbox, 12656ccef1deSJack Morgenstein QUERY_ADAPTER_REVISION_ID_OFFSET); 12666ccef1deSJack Morgenstein } 12671da177e4SLinus Torvalds MTHCA_GET(adapter->inta_pin, outbox, QUERY_ADAPTER_INTA_PIN_OFFSET); 12681da177e4SLinus Torvalds 12692e8b981cSMichael S. Tsirkin get_board_id(outbox + QUERY_ADAPTER_VSD_OFFSET / 4, 12702e8b981cSMichael S. Tsirkin adapter->board_id); 12712e8b981cSMichael S. Tsirkin 12721da177e4SLinus Torvalds out: 1273ed878458SRoland Dreier mthca_free_mailbox(dev, mailbox); 12741da177e4SLinus Torvalds return err; 12751da177e4SLinus Torvalds } 12761da177e4SLinus Torvalds 12771da177e4SLinus Torvalds int mthca_INIT_HCA(struct mthca_dev *dev, 12781da177e4SLinus Torvalds struct mthca_init_hca_param *param, 12791da177e4SLinus Torvalds u8 *status) 12801da177e4SLinus Torvalds { 1281ed878458SRoland Dreier struct mthca_mailbox *mailbox; 128297f52eb4SSean Hefty __be32 *inbox; 12831da177e4SLinus Torvalds int err; 12841da177e4SLinus Torvalds 12851da177e4SLinus Torvalds #define INIT_HCA_IN_SIZE 0x200 1286651eaac9SEli Cohen #define INIT_HCA_FLAGS1_OFFSET 0x00c 1287651eaac9SEli Cohen #define INIT_HCA_FLAGS2_OFFSET 0x014 12881da177e4SLinus Torvalds #define INIT_HCA_QPC_OFFSET 0x020 12891da177e4SLinus Torvalds #define INIT_HCA_QPC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x10) 12901da177e4SLinus Torvalds #define INIT_HCA_LOG_QP_OFFSET (INIT_HCA_QPC_OFFSET + 0x17) 12911da177e4SLinus Torvalds #define INIT_HCA_EEC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x20) 12921da177e4SLinus Torvalds #define INIT_HCA_LOG_EEC_OFFSET (INIT_HCA_QPC_OFFSET + 0x27) 12931da177e4SLinus Torvalds #define INIT_HCA_SRQC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x28) 12941da177e4SLinus Torvalds #define INIT_HCA_LOG_SRQ_OFFSET (INIT_HCA_QPC_OFFSET + 0x2f) 12951da177e4SLinus Torvalds #define INIT_HCA_CQC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x30) 12961da177e4SLinus Torvalds #define INIT_HCA_LOG_CQ_OFFSET (INIT_HCA_QPC_OFFSET + 0x37) 12971da177e4SLinus Torvalds #define INIT_HCA_EQPC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x40) 12981da177e4SLinus Torvalds #define INIT_HCA_EEEC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x50) 12991da177e4SLinus Torvalds #define INIT_HCA_EQC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x60) 13001da177e4SLinus Torvalds #define INIT_HCA_LOG_EQ_OFFSET (INIT_HCA_QPC_OFFSET + 0x67) 13011da177e4SLinus Torvalds #define INIT_HCA_RDB_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x70) 13021da177e4SLinus Torvalds #define INIT_HCA_UDAV_OFFSET 0x0b0 13031da177e4SLinus Torvalds #define INIT_HCA_UDAV_LKEY_OFFSET (INIT_HCA_UDAV_OFFSET + 0x0) 13041da177e4SLinus Torvalds #define INIT_HCA_UDAV_PD_OFFSET (INIT_HCA_UDAV_OFFSET + 0x4) 13051da177e4SLinus Torvalds #define INIT_HCA_MCAST_OFFSET 0x0c0 13061da177e4SLinus Torvalds #define INIT_HCA_MC_BASE_OFFSET (INIT_HCA_MCAST_OFFSET + 0x00) 13071da177e4SLinus Torvalds #define INIT_HCA_LOG_MC_ENTRY_SZ_OFFSET (INIT_HCA_MCAST_OFFSET + 0x12) 13081da177e4SLinus Torvalds #define INIT_HCA_MC_HASH_SZ_OFFSET (INIT_HCA_MCAST_OFFSET + 0x16) 13091da177e4SLinus Torvalds #define INIT_HCA_LOG_MC_TABLE_SZ_OFFSET (INIT_HCA_MCAST_OFFSET + 0x1b) 13101da177e4SLinus Torvalds #define INIT_HCA_TPT_OFFSET 0x0f0 13111da177e4SLinus Torvalds #define INIT_HCA_MPT_BASE_OFFSET (INIT_HCA_TPT_OFFSET + 0x00) 13121da177e4SLinus Torvalds #define INIT_HCA_MTT_SEG_SZ_OFFSET (INIT_HCA_TPT_OFFSET + 0x09) 13131da177e4SLinus Torvalds #define INIT_HCA_LOG_MPT_SZ_OFFSET (INIT_HCA_TPT_OFFSET + 0x0b) 13141da177e4SLinus Torvalds #define INIT_HCA_MTT_BASE_OFFSET (INIT_HCA_TPT_OFFSET + 0x10) 13151da177e4SLinus Torvalds #define INIT_HCA_UAR_OFFSET 0x120 13161da177e4SLinus Torvalds #define INIT_HCA_UAR_BASE_OFFSET (INIT_HCA_UAR_OFFSET + 0x00) 13171da177e4SLinus Torvalds #define INIT_HCA_UARC_SZ_OFFSET (INIT_HCA_UAR_OFFSET + 0x09) 13181da177e4SLinus Torvalds #define INIT_HCA_LOG_UAR_SZ_OFFSET (INIT_HCA_UAR_OFFSET + 0x0a) 13191da177e4SLinus Torvalds #define INIT_HCA_UAR_PAGE_SZ_OFFSET (INIT_HCA_UAR_OFFSET + 0x0b) 13201da177e4SLinus Torvalds #define INIT_HCA_UAR_SCATCH_BASE_OFFSET (INIT_HCA_UAR_OFFSET + 0x10) 13211da177e4SLinus Torvalds #define INIT_HCA_UAR_CTX_BASE_OFFSET (INIT_HCA_UAR_OFFSET + 0x18) 13221da177e4SLinus Torvalds 1323ed878458SRoland Dreier mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL); 1324ed878458SRoland Dreier if (IS_ERR(mailbox)) 1325ed878458SRoland Dreier return PTR_ERR(mailbox); 1326ed878458SRoland Dreier inbox = mailbox->buf; 13271da177e4SLinus Torvalds 13281da177e4SLinus Torvalds memset(inbox, 0, INIT_HCA_IN_SIZE); 13291da177e4SLinus Torvalds 1330651eaac9SEli Cohen if (dev->mthca_flags & MTHCA_FLAG_SINAI_OPT) 1331651eaac9SEli Cohen MTHCA_PUT(inbox, 0x1, INIT_HCA_FLAGS1_OFFSET); 1332651eaac9SEli Cohen 13331da177e4SLinus Torvalds #if defined(__LITTLE_ENDIAN) 1334651eaac9SEli Cohen *(inbox + INIT_HCA_FLAGS2_OFFSET / 4) &= ~cpu_to_be32(1 << 1); 13351da177e4SLinus Torvalds #elif defined(__BIG_ENDIAN) 1336651eaac9SEli Cohen *(inbox + INIT_HCA_FLAGS2_OFFSET / 4) |= cpu_to_be32(1 << 1); 13371da177e4SLinus Torvalds #else 13381da177e4SLinus Torvalds #error Host endianness not defined 13391da177e4SLinus Torvalds #endif 13401da177e4SLinus Torvalds /* Check port for UD address vector: */ 1341651eaac9SEli Cohen *(inbox + INIT_HCA_FLAGS2_OFFSET / 4) |= cpu_to_be32(1); 13421da177e4SLinus Torvalds 1343680b575fSEli Cohen /* Enable IPoIB checksumming if we can: */ 1344680b575fSEli Cohen if (dev->device_cap_flags & IB_DEVICE_UD_IP_CSUM) 1345680b575fSEli Cohen *(inbox + INIT_HCA_FLAGS2_OFFSET / 4) |= cpu_to_be32(7 << 3); 1346680b575fSEli Cohen 13471da177e4SLinus Torvalds /* We leave wqe_quota, responder_exu, etc as 0 (default) */ 13481da177e4SLinus Torvalds 13491da177e4SLinus Torvalds /* QPC/EEC/CQC/EQC/RDB attributes */ 13501da177e4SLinus Torvalds 13511da177e4SLinus Torvalds MTHCA_PUT(inbox, param->qpc_base, INIT_HCA_QPC_BASE_OFFSET); 13521da177e4SLinus Torvalds MTHCA_PUT(inbox, param->log_num_qps, INIT_HCA_LOG_QP_OFFSET); 13531da177e4SLinus Torvalds MTHCA_PUT(inbox, param->eec_base, INIT_HCA_EEC_BASE_OFFSET); 13541da177e4SLinus Torvalds MTHCA_PUT(inbox, param->log_num_eecs, INIT_HCA_LOG_EEC_OFFSET); 13551da177e4SLinus Torvalds MTHCA_PUT(inbox, param->srqc_base, INIT_HCA_SRQC_BASE_OFFSET); 13561da177e4SLinus Torvalds MTHCA_PUT(inbox, param->log_num_srqs, INIT_HCA_LOG_SRQ_OFFSET); 13571da177e4SLinus Torvalds MTHCA_PUT(inbox, param->cqc_base, INIT_HCA_CQC_BASE_OFFSET); 13581da177e4SLinus Torvalds MTHCA_PUT(inbox, param->log_num_cqs, INIT_HCA_LOG_CQ_OFFSET); 13591da177e4SLinus Torvalds MTHCA_PUT(inbox, param->eqpc_base, INIT_HCA_EQPC_BASE_OFFSET); 13601da177e4SLinus Torvalds MTHCA_PUT(inbox, param->eeec_base, INIT_HCA_EEEC_BASE_OFFSET); 13611da177e4SLinus Torvalds MTHCA_PUT(inbox, param->eqc_base, INIT_HCA_EQC_BASE_OFFSET); 13621da177e4SLinus Torvalds MTHCA_PUT(inbox, param->log_num_eqs, INIT_HCA_LOG_EQ_OFFSET); 13631da177e4SLinus Torvalds MTHCA_PUT(inbox, param->rdb_base, INIT_HCA_RDB_BASE_OFFSET); 13641da177e4SLinus Torvalds 13651da177e4SLinus Torvalds /* UD AV attributes */ 13661da177e4SLinus Torvalds 13671da177e4SLinus Torvalds /* multicast attributes */ 13681da177e4SLinus Torvalds 13691da177e4SLinus Torvalds MTHCA_PUT(inbox, param->mc_base, INIT_HCA_MC_BASE_OFFSET); 13701da177e4SLinus Torvalds MTHCA_PUT(inbox, param->log_mc_entry_sz, INIT_HCA_LOG_MC_ENTRY_SZ_OFFSET); 13711da177e4SLinus Torvalds MTHCA_PUT(inbox, param->mc_hash_sz, INIT_HCA_MC_HASH_SZ_OFFSET); 13721da177e4SLinus Torvalds MTHCA_PUT(inbox, param->log_mc_table_sz, INIT_HCA_LOG_MC_TABLE_SZ_OFFSET); 13731da177e4SLinus Torvalds 13741da177e4SLinus Torvalds /* TPT attributes */ 13751da177e4SLinus Torvalds 13761da177e4SLinus Torvalds MTHCA_PUT(inbox, param->mpt_base, INIT_HCA_MPT_BASE_OFFSET); 1377d10ddbf6SRoland Dreier if (!mthca_is_memfree(dev)) 13781da177e4SLinus Torvalds MTHCA_PUT(inbox, param->mtt_seg_sz, INIT_HCA_MTT_SEG_SZ_OFFSET); 13791da177e4SLinus Torvalds MTHCA_PUT(inbox, param->log_mpt_sz, INIT_HCA_LOG_MPT_SZ_OFFSET); 13801da177e4SLinus Torvalds MTHCA_PUT(inbox, param->mtt_base, INIT_HCA_MTT_BASE_OFFSET); 13811da177e4SLinus Torvalds 13821da177e4SLinus Torvalds /* UAR attributes */ 13831da177e4SLinus Torvalds { 13841da177e4SLinus Torvalds u8 uar_page_sz = PAGE_SHIFT - 12; 13851da177e4SLinus Torvalds MTHCA_PUT(inbox, uar_page_sz, INIT_HCA_UAR_PAGE_SZ_OFFSET); 13861da177e4SLinus Torvalds } 13871da177e4SLinus Torvalds 13881da177e4SLinus Torvalds MTHCA_PUT(inbox, param->uar_scratch_base, INIT_HCA_UAR_SCATCH_BASE_OFFSET); 13891da177e4SLinus Torvalds 1390d10ddbf6SRoland Dreier if (mthca_is_memfree(dev)) { 13911da177e4SLinus Torvalds MTHCA_PUT(inbox, param->log_uarc_sz, INIT_HCA_UARC_SZ_OFFSET); 13921da177e4SLinus Torvalds MTHCA_PUT(inbox, param->log_uar_sz, INIT_HCA_LOG_UAR_SZ_OFFSET); 13931da177e4SLinus Torvalds MTHCA_PUT(inbox, param->uarc_base, INIT_HCA_UAR_CTX_BASE_OFFSET); 13941da177e4SLinus Torvalds } 13951da177e4SLinus Torvalds 13968531f1f1SJack Morgenstein err = mthca_cmd(dev, mailbox->dma, 0, 0, CMD_INIT_HCA, CMD_TIME_CLASS_D, status); 13971da177e4SLinus Torvalds 1398ed878458SRoland Dreier mthca_free_mailbox(dev, mailbox); 13991da177e4SLinus Torvalds return err; 14001da177e4SLinus Torvalds } 14011da177e4SLinus Torvalds 14021da177e4SLinus Torvalds int mthca_INIT_IB(struct mthca_dev *dev, 14031da177e4SLinus Torvalds struct mthca_init_ib_param *param, 14041da177e4SLinus Torvalds int port, u8 *status) 14051da177e4SLinus Torvalds { 1406ed878458SRoland Dreier struct mthca_mailbox *mailbox; 14071da177e4SLinus Torvalds u32 *inbox; 14081da177e4SLinus Torvalds int err; 14091da177e4SLinus Torvalds u32 flags; 14101da177e4SLinus Torvalds 14111da177e4SLinus Torvalds #define INIT_IB_IN_SIZE 56 14121da177e4SLinus Torvalds #define INIT_IB_FLAGS_OFFSET 0x00 14131da177e4SLinus Torvalds #define INIT_IB_FLAG_SIG (1 << 18) 14141da177e4SLinus Torvalds #define INIT_IB_FLAG_NG (1 << 17) 14151da177e4SLinus Torvalds #define INIT_IB_FLAG_G0 (1 << 16) 14161da177e4SLinus Torvalds #define INIT_IB_VL_SHIFT 4 1417da6561c2SRoland Dreier #define INIT_IB_PORT_WIDTH_SHIFT 8 14181da177e4SLinus Torvalds #define INIT_IB_MTU_SHIFT 12 14191da177e4SLinus Torvalds #define INIT_IB_MAX_GID_OFFSET 0x06 14201da177e4SLinus Torvalds #define INIT_IB_MAX_PKEY_OFFSET 0x0a 14211da177e4SLinus Torvalds #define INIT_IB_GUID0_OFFSET 0x10 14221da177e4SLinus Torvalds #define INIT_IB_NODE_GUID_OFFSET 0x18 14231da177e4SLinus Torvalds #define INIT_IB_SI_GUID_OFFSET 0x20 14241da177e4SLinus Torvalds 1425ed878458SRoland Dreier mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL); 1426ed878458SRoland Dreier if (IS_ERR(mailbox)) 1427ed878458SRoland Dreier return PTR_ERR(mailbox); 1428ed878458SRoland Dreier inbox = mailbox->buf; 14291da177e4SLinus Torvalds 14301da177e4SLinus Torvalds memset(inbox, 0, INIT_IB_IN_SIZE); 14311da177e4SLinus Torvalds 14321da177e4SLinus Torvalds flags = 0; 14331da177e4SLinus Torvalds flags |= param->set_guid0 ? INIT_IB_FLAG_G0 : 0; 14341da177e4SLinus Torvalds flags |= param->set_node_guid ? INIT_IB_FLAG_NG : 0; 14351da177e4SLinus Torvalds flags |= param->set_si_guid ? INIT_IB_FLAG_SIG : 0; 14361da177e4SLinus Torvalds flags |= param->vl_cap << INIT_IB_VL_SHIFT; 1437da6561c2SRoland Dreier flags |= param->port_width << INIT_IB_PORT_WIDTH_SHIFT; 14381da177e4SLinus Torvalds flags |= param->mtu_cap << INIT_IB_MTU_SHIFT; 14391da177e4SLinus Torvalds MTHCA_PUT(inbox, flags, INIT_IB_FLAGS_OFFSET); 14401da177e4SLinus Torvalds 14411da177e4SLinus Torvalds MTHCA_PUT(inbox, param->gid_cap, INIT_IB_MAX_GID_OFFSET); 14421da177e4SLinus Torvalds MTHCA_PUT(inbox, param->pkey_cap, INIT_IB_MAX_PKEY_OFFSET); 14431da177e4SLinus Torvalds MTHCA_PUT(inbox, param->guid0, INIT_IB_GUID0_OFFSET); 14441da177e4SLinus Torvalds MTHCA_PUT(inbox, param->node_guid, INIT_IB_NODE_GUID_OFFSET); 14451da177e4SLinus Torvalds MTHCA_PUT(inbox, param->si_guid, INIT_IB_SI_GUID_OFFSET); 14461da177e4SLinus Torvalds 1447ed878458SRoland Dreier err = mthca_cmd(dev, mailbox->dma, port, 0, CMD_INIT_IB, 14481da177e4SLinus Torvalds CMD_TIME_CLASS_A, status); 14491da177e4SLinus Torvalds 1450ed878458SRoland Dreier mthca_free_mailbox(dev, mailbox); 14511da177e4SLinus Torvalds return err; 14521da177e4SLinus Torvalds } 14531da177e4SLinus Torvalds 14541da177e4SLinus Torvalds int mthca_CLOSE_IB(struct mthca_dev *dev, int port, u8 *status) 14551da177e4SLinus Torvalds { 14568531f1f1SJack Morgenstein return mthca_cmd(dev, 0, port, 0, CMD_CLOSE_IB, CMD_TIME_CLASS_A, status); 14571da177e4SLinus Torvalds } 14581da177e4SLinus Torvalds 14591da177e4SLinus Torvalds int mthca_CLOSE_HCA(struct mthca_dev *dev, int panic, u8 *status) 14601da177e4SLinus Torvalds { 14618531f1f1SJack Morgenstein return mthca_cmd(dev, 0, 0, panic, CMD_CLOSE_HCA, CMD_TIME_CLASS_C, status); 14621da177e4SLinus Torvalds } 14631da177e4SLinus Torvalds 14641da177e4SLinus Torvalds int mthca_SET_IB(struct mthca_dev *dev, struct mthca_set_ib_param *param, 14651da177e4SLinus Torvalds int port, u8 *status) 14661da177e4SLinus Torvalds { 1467ed878458SRoland Dreier struct mthca_mailbox *mailbox; 14681da177e4SLinus Torvalds u32 *inbox; 14691da177e4SLinus Torvalds int err; 14701da177e4SLinus Torvalds u32 flags = 0; 14711da177e4SLinus Torvalds 14721da177e4SLinus Torvalds #define SET_IB_IN_SIZE 0x40 14731da177e4SLinus Torvalds #define SET_IB_FLAGS_OFFSET 0x00 14741da177e4SLinus Torvalds #define SET_IB_FLAG_SIG (1 << 18) 14751da177e4SLinus Torvalds #define SET_IB_FLAG_RQK (1 << 0) 14761da177e4SLinus Torvalds #define SET_IB_CAP_MASK_OFFSET 0x04 14771da177e4SLinus Torvalds #define SET_IB_SI_GUID_OFFSET 0x08 14781da177e4SLinus Torvalds 1479ed878458SRoland Dreier mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL); 1480ed878458SRoland Dreier if (IS_ERR(mailbox)) 1481ed878458SRoland Dreier return PTR_ERR(mailbox); 1482ed878458SRoland Dreier inbox = mailbox->buf; 14831da177e4SLinus Torvalds 14841da177e4SLinus Torvalds memset(inbox, 0, SET_IB_IN_SIZE); 14851da177e4SLinus Torvalds 14861da177e4SLinus Torvalds flags |= param->set_si_guid ? SET_IB_FLAG_SIG : 0; 14871da177e4SLinus Torvalds flags |= param->reset_qkey_viol ? SET_IB_FLAG_RQK : 0; 14881da177e4SLinus Torvalds MTHCA_PUT(inbox, flags, SET_IB_FLAGS_OFFSET); 14891da177e4SLinus Torvalds 14901da177e4SLinus Torvalds MTHCA_PUT(inbox, param->cap_mask, SET_IB_CAP_MASK_OFFSET); 14911da177e4SLinus Torvalds MTHCA_PUT(inbox, param->si_guid, SET_IB_SI_GUID_OFFSET); 14921da177e4SLinus Torvalds 1493ed878458SRoland Dreier err = mthca_cmd(dev, mailbox->dma, port, 0, CMD_SET_IB, 14941da177e4SLinus Torvalds CMD_TIME_CLASS_B, status); 14951da177e4SLinus Torvalds 1496ed878458SRoland Dreier mthca_free_mailbox(dev, mailbox); 14971da177e4SLinus Torvalds return err; 14981da177e4SLinus Torvalds } 14991da177e4SLinus Torvalds 15001da177e4SLinus Torvalds int mthca_MAP_ICM(struct mthca_dev *dev, struct mthca_icm *icm, u64 virt, u8 *status) 15011da177e4SLinus Torvalds { 15021da177e4SLinus Torvalds return mthca_map_cmd(dev, CMD_MAP_ICM, icm, virt, status); 15031da177e4SLinus Torvalds } 15041da177e4SLinus Torvalds 15051da177e4SLinus Torvalds int mthca_MAP_ICM_page(struct mthca_dev *dev, u64 dma_addr, u64 virt, u8 *status) 15061da177e4SLinus Torvalds { 1507ed878458SRoland Dreier struct mthca_mailbox *mailbox; 150897f52eb4SSean Hefty __be64 *inbox; 15091da177e4SLinus Torvalds int err; 15101da177e4SLinus Torvalds 1511ed878458SRoland Dreier mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL); 1512ed878458SRoland Dreier if (IS_ERR(mailbox)) 1513ed878458SRoland Dreier return PTR_ERR(mailbox); 1514ed878458SRoland Dreier inbox = mailbox->buf; 15151da177e4SLinus Torvalds 15161da177e4SLinus Torvalds inbox[0] = cpu_to_be64(virt); 15171da177e4SLinus Torvalds inbox[1] = cpu_to_be64(dma_addr); 15181da177e4SLinus Torvalds 1519ed878458SRoland Dreier err = mthca_cmd(dev, mailbox->dma, 1, 0, CMD_MAP_ICM, 1520ed878458SRoland Dreier CMD_TIME_CLASS_B, status); 15211da177e4SLinus Torvalds 1522ed878458SRoland Dreier mthca_free_mailbox(dev, mailbox); 15231da177e4SLinus Torvalds 15241da177e4SLinus Torvalds if (!err) 15256bd6228eSRoland Dreier mthca_dbg(dev, "Mapped page at %llx to %llx for ICM.\n", 15266bd6228eSRoland Dreier (unsigned long long) dma_addr, (unsigned long long) virt); 15271da177e4SLinus Torvalds 15281da177e4SLinus Torvalds return err; 15291da177e4SLinus Torvalds } 15301da177e4SLinus Torvalds 15311da177e4SLinus Torvalds int mthca_UNMAP_ICM(struct mthca_dev *dev, u64 virt, u32 page_count, u8 *status) 15321da177e4SLinus Torvalds { 15331da177e4SLinus Torvalds mthca_dbg(dev, "Unmapping %d pages at %llx from ICM.\n", 15341da177e4SLinus Torvalds page_count, (unsigned long long) virt); 15351da177e4SLinus Torvalds 15361da177e4SLinus Torvalds return mthca_cmd(dev, virt, page_count, 0, CMD_UNMAP_ICM, CMD_TIME_CLASS_B, status); 15371da177e4SLinus Torvalds } 15381da177e4SLinus Torvalds 15391da177e4SLinus Torvalds int mthca_MAP_ICM_AUX(struct mthca_dev *dev, struct mthca_icm *icm, u8 *status) 15401da177e4SLinus Torvalds { 15411da177e4SLinus Torvalds return mthca_map_cmd(dev, CMD_MAP_ICM_AUX, icm, -1, status); 15421da177e4SLinus Torvalds } 15431da177e4SLinus Torvalds 15441da177e4SLinus Torvalds int mthca_UNMAP_ICM_AUX(struct mthca_dev *dev, u8 *status) 15451da177e4SLinus Torvalds { 15461da177e4SLinus Torvalds return mthca_cmd(dev, 0, 0, 0, CMD_UNMAP_ICM_AUX, CMD_TIME_CLASS_B, status); 15471da177e4SLinus Torvalds } 15481da177e4SLinus Torvalds 15491da177e4SLinus Torvalds int mthca_SET_ICM_SIZE(struct mthca_dev *dev, u64 icm_size, u64 *aux_pages, 15501da177e4SLinus Torvalds u8 *status) 15511da177e4SLinus Torvalds { 15521da177e4SLinus Torvalds int ret = mthca_cmd_imm(dev, icm_size, aux_pages, 0, 0, CMD_SET_ICM_SIZE, 15531da177e4SLinus Torvalds CMD_TIME_CLASS_A, status); 15541da177e4SLinus Torvalds 15551da177e4SLinus Torvalds if (ret || status) 15561da177e4SLinus Torvalds return ret; 15571da177e4SLinus Torvalds 15581da177e4SLinus Torvalds /* 15598d3ef29dSIshai Rabinovitz * Round up number of system pages needed in case 15608d3ef29dSIshai Rabinovitz * MTHCA_ICM_PAGE_SIZE < PAGE_SIZE. 15611da177e4SLinus Torvalds */ 15628d3ef29dSIshai Rabinovitz *aux_pages = ALIGN(*aux_pages, PAGE_SIZE / MTHCA_ICM_PAGE_SIZE) >> 15638d3ef29dSIshai Rabinovitz (PAGE_SHIFT - MTHCA_ICM_PAGE_SHIFT); 15641da177e4SLinus Torvalds 15651da177e4SLinus Torvalds return 0; 15661da177e4SLinus Torvalds } 15671da177e4SLinus Torvalds 1568ed878458SRoland Dreier int mthca_SW2HW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox, 15691da177e4SLinus Torvalds int mpt_index, u8 *status) 15701da177e4SLinus Torvalds { 1571ed878458SRoland Dreier return mthca_cmd(dev, mailbox->dma, mpt_index, 0, CMD_SW2HW_MPT, 15721da177e4SLinus Torvalds CMD_TIME_CLASS_B, status); 15731da177e4SLinus Torvalds } 15741da177e4SLinus Torvalds 1575ed878458SRoland Dreier int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox, 15761da177e4SLinus Torvalds int mpt_index, u8 *status) 15771da177e4SLinus Torvalds { 1578ed878458SRoland Dreier return mthca_cmd_box(dev, 0, mailbox ? mailbox->dma : 0, mpt_index, 1579ed878458SRoland Dreier !mailbox, CMD_HW2SW_MPT, 15801da177e4SLinus Torvalds CMD_TIME_CLASS_B, status); 15811da177e4SLinus Torvalds } 15821da177e4SLinus Torvalds 1583ed878458SRoland Dreier int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox, 15841da177e4SLinus Torvalds int num_mtt, u8 *status) 15851da177e4SLinus Torvalds { 1586ed878458SRoland Dreier return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT, 15871da177e4SLinus Torvalds CMD_TIME_CLASS_B, status); 15881da177e4SLinus Torvalds } 15891da177e4SLinus Torvalds 1590b8ca06f6SMichael S. Tsirkin int mthca_SYNC_TPT(struct mthca_dev *dev, u8 *status) 1591b8ca06f6SMichael S. Tsirkin { 1592b8ca06f6SMichael S. Tsirkin return mthca_cmd(dev, 0, 0, 0, CMD_SYNC_TPT, CMD_TIME_CLASS_B, status); 1593b8ca06f6SMichael S. Tsirkin } 1594b8ca06f6SMichael S. Tsirkin 15951da177e4SLinus Torvalds int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap, 15961da177e4SLinus Torvalds int eq_num, u8 *status) 15971da177e4SLinus Torvalds { 15981da177e4SLinus Torvalds mthca_dbg(dev, "%s mask %016llx for eqn %d\n", 15991da177e4SLinus Torvalds unmap ? "Clearing" : "Setting", 16001da177e4SLinus Torvalds (unsigned long long) event_mask, eq_num); 16011da177e4SLinus Torvalds return mthca_cmd(dev, event_mask, (unmap << 31) | eq_num, 16021da177e4SLinus Torvalds 0, CMD_MAP_EQ, CMD_TIME_CLASS_B, status); 16031da177e4SLinus Torvalds } 16041da177e4SLinus Torvalds 1605ed878458SRoland Dreier int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox, 16061da177e4SLinus Torvalds int eq_num, u8 *status) 16071da177e4SLinus Torvalds { 1608ed878458SRoland Dreier return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ, 16091da177e4SLinus Torvalds CMD_TIME_CLASS_A, status); 16101da177e4SLinus Torvalds } 16111da177e4SLinus Torvalds 1612ed878458SRoland Dreier int mthca_HW2SW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox, 16131da177e4SLinus Torvalds int eq_num, u8 *status) 16141da177e4SLinus Torvalds { 1615ed878458SRoland Dreier return mthca_cmd_box(dev, 0, mailbox->dma, eq_num, 0, 16161da177e4SLinus Torvalds CMD_HW2SW_EQ, 16171da177e4SLinus Torvalds CMD_TIME_CLASS_A, status); 16181da177e4SLinus Torvalds } 16191da177e4SLinus Torvalds 1620ed878458SRoland Dreier int mthca_SW2HW_CQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox, 16211da177e4SLinus Torvalds int cq_num, u8 *status) 16221da177e4SLinus Torvalds { 1623ed878458SRoland Dreier return mthca_cmd(dev, mailbox->dma, cq_num, 0, CMD_SW2HW_CQ, 16241da177e4SLinus Torvalds CMD_TIME_CLASS_A, status); 16251da177e4SLinus Torvalds } 16261da177e4SLinus Torvalds 1627ed878458SRoland Dreier int mthca_HW2SW_CQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox, 16281da177e4SLinus Torvalds int cq_num, u8 *status) 16291da177e4SLinus Torvalds { 1630ed878458SRoland Dreier return mthca_cmd_box(dev, 0, mailbox->dma, cq_num, 0, 16311da177e4SLinus Torvalds CMD_HW2SW_CQ, 16321da177e4SLinus Torvalds CMD_TIME_CLASS_A, status); 16331da177e4SLinus Torvalds } 16341da177e4SLinus Torvalds 16354885bf64SRoland Dreier int mthca_RESIZE_CQ(struct mthca_dev *dev, int cq_num, u32 lkey, u8 log_size, 16364885bf64SRoland Dreier u8 *status) 16374885bf64SRoland Dreier { 16384885bf64SRoland Dreier struct mthca_mailbox *mailbox; 16394885bf64SRoland Dreier __be32 *inbox; 16404885bf64SRoland Dreier int err; 16414885bf64SRoland Dreier 16424885bf64SRoland Dreier #define RESIZE_CQ_IN_SIZE 0x40 16434885bf64SRoland Dreier #define RESIZE_CQ_LOG_SIZE_OFFSET 0x0c 16444885bf64SRoland Dreier #define RESIZE_CQ_LKEY_OFFSET 0x1c 16454885bf64SRoland Dreier 16464885bf64SRoland Dreier mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL); 16474885bf64SRoland Dreier if (IS_ERR(mailbox)) 16484885bf64SRoland Dreier return PTR_ERR(mailbox); 16494885bf64SRoland Dreier inbox = mailbox->buf; 16504885bf64SRoland Dreier 16514885bf64SRoland Dreier memset(inbox, 0, RESIZE_CQ_IN_SIZE); 16524885bf64SRoland Dreier /* 16534885bf64SRoland Dreier * Leave start address fields zeroed out -- mthca assumes that 16544885bf64SRoland Dreier * MRs for CQs always start at virtual address 0. 16554885bf64SRoland Dreier */ 16564885bf64SRoland Dreier MTHCA_PUT(inbox, log_size, RESIZE_CQ_LOG_SIZE_OFFSET); 16574885bf64SRoland Dreier MTHCA_PUT(inbox, lkey, RESIZE_CQ_LKEY_OFFSET); 16584885bf64SRoland Dreier 16594885bf64SRoland Dreier err = mthca_cmd(dev, mailbox->dma, cq_num, 1, CMD_RESIZE_CQ, 16604885bf64SRoland Dreier CMD_TIME_CLASS_B, status); 16614885bf64SRoland Dreier 16624885bf64SRoland Dreier mthca_free_mailbox(dev, mailbox); 16634885bf64SRoland Dreier return err; 16644885bf64SRoland Dreier } 16654885bf64SRoland Dreier 1666ec34a922SRoland Dreier int mthca_SW2HW_SRQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox, 1667ec34a922SRoland Dreier int srq_num, u8 *status) 1668ec34a922SRoland Dreier { 1669ec34a922SRoland Dreier return mthca_cmd(dev, mailbox->dma, srq_num, 0, CMD_SW2HW_SRQ, 1670ec34a922SRoland Dreier CMD_TIME_CLASS_A, status); 1671ec34a922SRoland Dreier } 1672ec34a922SRoland Dreier 1673ec34a922SRoland Dreier int mthca_HW2SW_SRQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox, 1674ec34a922SRoland Dreier int srq_num, u8 *status) 1675ec34a922SRoland Dreier { 1676ec34a922SRoland Dreier return mthca_cmd_box(dev, 0, mailbox->dma, srq_num, 0, 1677ec34a922SRoland Dreier CMD_HW2SW_SRQ, 1678ec34a922SRoland Dreier CMD_TIME_CLASS_A, status); 1679ec34a922SRoland Dreier } 1680ec34a922SRoland Dreier 16818ebe5077SEli Cohen int mthca_QUERY_SRQ(struct mthca_dev *dev, u32 num, 16828ebe5077SEli Cohen struct mthca_mailbox *mailbox, u8 *status) 16838ebe5077SEli Cohen { 16848ebe5077SEli Cohen return mthca_cmd_box(dev, 0, mailbox->dma, num, 0, 16858ebe5077SEli Cohen CMD_QUERY_SRQ, CMD_TIME_CLASS_A, status); 16868ebe5077SEli Cohen } 16878ebe5077SEli Cohen 1688ec34a922SRoland Dreier int mthca_ARM_SRQ(struct mthca_dev *dev, int srq_num, int limit, u8 *status) 1689ec34a922SRoland Dreier { 1690ec34a922SRoland Dreier return mthca_cmd(dev, limit, srq_num, 0, CMD_ARM_SRQ, 1691ec34a922SRoland Dreier CMD_TIME_CLASS_B, status); 1692ec34a922SRoland Dreier } 1693ec34a922SRoland Dreier 1694d844183dSRoland Dreier int mthca_MODIFY_QP(struct mthca_dev *dev, enum ib_qp_state cur, 1695d844183dSRoland Dreier enum ib_qp_state next, u32 num, int is_ee, 1696d844183dSRoland Dreier struct mthca_mailbox *mailbox, u32 optmask, 16971da177e4SLinus Torvalds u8 *status) 16981da177e4SLinus Torvalds { 1699d844183dSRoland Dreier static const u16 op[IB_QPS_ERR + 1][IB_QPS_ERR + 1] = { 1700d844183dSRoland Dreier [IB_QPS_RESET] = { 1701d844183dSRoland Dreier [IB_QPS_RESET] = CMD_ERR2RST_QPEE, 1702d844183dSRoland Dreier [IB_QPS_ERR] = CMD_2ERR_QPEE, 1703d844183dSRoland Dreier [IB_QPS_INIT] = CMD_RST2INIT_QPEE, 1704d844183dSRoland Dreier }, 1705d844183dSRoland Dreier [IB_QPS_INIT] = { 1706d844183dSRoland Dreier [IB_QPS_RESET] = CMD_ERR2RST_QPEE, 1707d844183dSRoland Dreier [IB_QPS_ERR] = CMD_2ERR_QPEE, 1708d844183dSRoland Dreier [IB_QPS_INIT] = CMD_INIT2INIT_QPEE, 1709d844183dSRoland Dreier [IB_QPS_RTR] = CMD_INIT2RTR_QPEE, 1710d844183dSRoland Dreier }, 1711d844183dSRoland Dreier [IB_QPS_RTR] = { 1712d844183dSRoland Dreier [IB_QPS_RESET] = CMD_ERR2RST_QPEE, 1713d844183dSRoland Dreier [IB_QPS_ERR] = CMD_2ERR_QPEE, 1714d844183dSRoland Dreier [IB_QPS_RTS] = CMD_RTR2RTS_QPEE, 1715d844183dSRoland Dreier }, 1716d844183dSRoland Dreier [IB_QPS_RTS] = { 1717d844183dSRoland Dreier [IB_QPS_RESET] = CMD_ERR2RST_QPEE, 1718d844183dSRoland Dreier [IB_QPS_ERR] = CMD_2ERR_QPEE, 1719d844183dSRoland Dreier [IB_QPS_RTS] = CMD_RTS2RTS_QPEE, 1720d844183dSRoland Dreier [IB_QPS_SQD] = CMD_RTS2SQD_QPEE, 1721d844183dSRoland Dreier }, 1722d844183dSRoland Dreier [IB_QPS_SQD] = { 1723d844183dSRoland Dreier [IB_QPS_RESET] = CMD_ERR2RST_QPEE, 1724d844183dSRoland Dreier [IB_QPS_ERR] = CMD_2ERR_QPEE, 1725d844183dSRoland Dreier [IB_QPS_RTS] = CMD_SQD2RTS_QPEE, 1726d844183dSRoland Dreier [IB_QPS_SQD] = CMD_SQD2SQD_QPEE, 1727d844183dSRoland Dreier }, 1728d844183dSRoland Dreier [IB_QPS_SQE] = { 1729d844183dSRoland Dreier [IB_QPS_RESET] = CMD_ERR2RST_QPEE, 1730d844183dSRoland Dreier [IB_QPS_ERR] = CMD_2ERR_QPEE, 1731d844183dSRoland Dreier [IB_QPS_RTS] = CMD_SQERR2RTS_QPEE, 1732d844183dSRoland Dreier }, 1733d844183dSRoland Dreier [IB_QPS_ERR] = { 1734d844183dSRoland Dreier [IB_QPS_RESET] = CMD_ERR2RST_QPEE, 1735d844183dSRoland Dreier [IB_QPS_ERR] = CMD_2ERR_QPEE, 1736d844183dSRoland Dreier } 17371da177e4SLinus Torvalds }; 1738d844183dSRoland Dreier 17391da177e4SLinus Torvalds u8 op_mod = 0; 1740ed878458SRoland Dreier int my_mailbox = 0; 17411da177e4SLinus Torvalds int err; 17421da177e4SLinus Torvalds 1743d844183dSRoland Dreier if (op[cur][next] == CMD_ERR2RST_QPEE) { 17441da177e4SLinus Torvalds op_mod = 3; /* don't write outbox, any->reset */ 17451da177e4SLinus Torvalds 17461da177e4SLinus Torvalds /* For debugging */ 1747ed878458SRoland Dreier if (!mailbox) { 1748ed878458SRoland Dreier mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL); 1749ed878458SRoland Dreier if (!IS_ERR(mailbox)) { 1750ed878458SRoland Dreier my_mailbox = 1; 17511da177e4SLinus Torvalds op_mod = 2; /* write outbox, any->reset */ 1752ed878458SRoland Dreier } else 1753ed878458SRoland Dreier mailbox = NULL; 1754ed878458SRoland Dreier } 17551da177e4SLinus Torvalds 1756ed878458SRoland Dreier err = mthca_cmd_box(dev, 0, mailbox ? mailbox->dma : 0, 1757ed878458SRoland Dreier (!!is_ee << 24) | num, op_mod, 1758d844183dSRoland Dreier op[cur][next], CMD_TIME_CLASS_C, status); 17591da177e4SLinus Torvalds 1760ed878458SRoland Dreier if (0 && mailbox) { 17611da177e4SLinus Torvalds int i; 17621da177e4SLinus Torvalds mthca_dbg(dev, "Dumping QP context:\n"); 1763ed878458SRoland Dreier printk(" %08x\n", be32_to_cpup(mailbox->buf)); 17641da177e4SLinus Torvalds for (i = 0; i < 0x100 / 4; ++i) { 17651da177e4SLinus Torvalds if (i % 8 == 0) 17661da177e4SLinus Torvalds printk("[%02x] ", i * 4); 1767ed878458SRoland Dreier printk(" %08x", 176897f52eb4SSean Hefty be32_to_cpu(((__be32 *) mailbox->buf)[i + 2])); 17691da177e4SLinus Torvalds if ((i + 1) % 8 == 0) 17701da177e4SLinus Torvalds printk("\n"); 17711da177e4SLinus Torvalds } 17721da177e4SLinus Torvalds } 17731da177e4SLinus Torvalds 1774ed878458SRoland Dreier if (my_mailbox) 1775ed878458SRoland Dreier mthca_free_mailbox(dev, mailbox); 1776d844183dSRoland Dreier } else { 1777d844183dSRoland Dreier if (0) { 1778d844183dSRoland Dreier int i; 1779d844183dSRoland Dreier mthca_dbg(dev, "Dumping QP context:\n"); 1780d844183dSRoland Dreier printk(" opt param mask: %08x\n", be32_to_cpup(mailbox->buf)); 1781d844183dSRoland Dreier for (i = 0; i < 0x100 / 4; ++i) { 1782d844183dSRoland Dreier if (i % 8 == 0) 1783d844183dSRoland Dreier printk(" [%02x] ", i * 4); 1784d844183dSRoland Dreier printk(" %08x", 1785d844183dSRoland Dreier be32_to_cpu(((__be32 *) mailbox->buf)[i + 2])); 1786d844183dSRoland Dreier if ((i + 1) % 8 == 0) 1787d844183dSRoland Dreier printk("\n"); 1788d844183dSRoland Dreier } 1789d844183dSRoland Dreier } 1790d844183dSRoland Dreier 1791d844183dSRoland Dreier err = mthca_cmd(dev, mailbox->dma, optmask | (!!is_ee << 24) | num, 1792d844183dSRoland Dreier op_mod, op[cur][next], CMD_TIME_CLASS_C, status); 1793d844183dSRoland Dreier } 1794ed878458SRoland Dreier 17951da177e4SLinus Torvalds return err; 17961da177e4SLinus Torvalds } 17971da177e4SLinus Torvalds 17981da177e4SLinus Torvalds int mthca_QUERY_QP(struct mthca_dev *dev, u32 num, int is_ee, 1799ed878458SRoland Dreier struct mthca_mailbox *mailbox, u8 *status) 18001da177e4SLinus Torvalds { 1801ed878458SRoland Dreier return mthca_cmd_box(dev, 0, mailbox->dma, (!!is_ee << 24) | num, 0, 1802ed878458SRoland Dreier CMD_QUERY_QPEE, CMD_TIME_CLASS_A, status); 18031da177e4SLinus Torvalds } 18041da177e4SLinus Torvalds 18051da177e4SLinus Torvalds int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn, 18061da177e4SLinus Torvalds u8 *status) 18071da177e4SLinus Torvalds { 18081da177e4SLinus Torvalds u8 op_mod; 18091da177e4SLinus Torvalds 18101da177e4SLinus Torvalds switch (type) { 18111da177e4SLinus Torvalds case IB_QPT_SMI: 18121da177e4SLinus Torvalds op_mod = 0; 18131da177e4SLinus Torvalds break; 18141da177e4SLinus Torvalds case IB_QPT_GSI: 18151da177e4SLinus Torvalds op_mod = 1; 18161da177e4SLinus Torvalds break; 18171da177e4SLinus Torvalds case IB_QPT_RAW_IPV6: 18181da177e4SLinus Torvalds op_mod = 2; 18191da177e4SLinus Torvalds break; 1820*a2ebf07aSAleksey Senin case IB_QPT_RAW_ETHERTYPE: 18211da177e4SLinus Torvalds op_mod = 3; 18221da177e4SLinus Torvalds break; 18231da177e4SLinus Torvalds default: 18241da177e4SLinus Torvalds return -EINVAL; 18251da177e4SLinus Torvalds } 18261da177e4SLinus Torvalds 18271da177e4SLinus Torvalds return mthca_cmd(dev, 0, qpn, op_mod, CMD_CONF_SPECIAL_QP, 18281da177e4SLinus Torvalds CMD_TIME_CLASS_B, status); 18291da177e4SLinus Torvalds } 18301da177e4SLinus Torvalds 18311da177e4SLinus Torvalds int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey, 18321da177e4SLinus Torvalds int port, struct ib_wc *in_wc, struct ib_grh *in_grh, 18331da177e4SLinus Torvalds void *in_mad, void *response_mad, u8 *status) 18341da177e4SLinus Torvalds { 1835ed878458SRoland Dreier struct mthca_mailbox *inmailbox, *outmailbox; 1836ed878458SRoland Dreier void *inbox; 18371da177e4SLinus Torvalds int err; 18381da177e4SLinus Torvalds u32 in_modifier = port; 18391da177e4SLinus Torvalds u8 op_modifier = 0; 18401da177e4SLinus Torvalds 18411da177e4SLinus Torvalds #define MAD_IFC_BOX_SIZE 0x400 18421da177e4SLinus Torvalds #define MAD_IFC_MY_QPN_OFFSET 0x100 184368586b67SMichael S. Tsirkin #define MAD_IFC_RQPN_OFFSET 0x108 184468586b67SMichael S. Tsirkin #define MAD_IFC_SL_OFFSET 0x10c 184568586b67SMichael S. Tsirkin #define MAD_IFC_G_PATH_OFFSET 0x10d 184668586b67SMichael S. Tsirkin #define MAD_IFC_RLID_OFFSET 0x10e 184768586b67SMichael S. Tsirkin #define MAD_IFC_PKEY_OFFSET 0x112 18481da177e4SLinus Torvalds #define MAD_IFC_GRH_OFFSET 0x140 18491da177e4SLinus Torvalds 1850ed878458SRoland Dreier inmailbox = mthca_alloc_mailbox(dev, GFP_KERNEL); 1851ed878458SRoland Dreier if (IS_ERR(inmailbox)) 1852ed878458SRoland Dreier return PTR_ERR(inmailbox); 1853ed878458SRoland Dreier inbox = inmailbox->buf; 18541da177e4SLinus Torvalds 1855ed878458SRoland Dreier outmailbox = mthca_alloc_mailbox(dev, GFP_KERNEL); 1856ed878458SRoland Dreier if (IS_ERR(outmailbox)) { 1857ed878458SRoland Dreier mthca_free_mailbox(dev, inmailbox); 1858ed878458SRoland Dreier return PTR_ERR(outmailbox); 1859ed878458SRoland Dreier } 1860ed878458SRoland Dreier 1861ed878458SRoland Dreier memcpy(inbox, in_mad, 256); 18621da177e4SLinus Torvalds 18631da177e4SLinus Torvalds /* 18641da177e4SLinus Torvalds * Key check traps can't be generated unless we have in_wc to 18651da177e4SLinus Torvalds * tell us where to send the trap. 18661da177e4SLinus Torvalds */ 18671da177e4SLinus Torvalds if (ignore_mkey || !in_wc) 18681da177e4SLinus Torvalds op_modifier |= 0x1; 18691da177e4SLinus Torvalds if (ignore_bkey || !in_wc) 18701da177e4SLinus Torvalds op_modifier |= 0x2; 18711da177e4SLinus Torvalds 18721da177e4SLinus Torvalds if (in_wc) { 18731da177e4SLinus Torvalds u8 val; 18741da177e4SLinus Torvalds 1875ed878458SRoland Dreier memset(inbox + 256, 0, 256); 18761da177e4SLinus Torvalds 1877062dbb69SMichael S. Tsirkin MTHCA_PUT(inbox, in_wc->qp->qp_num, MAD_IFC_MY_QPN_OFFSET); 1878ed878458SRoland Dreier MTHCA_PUT(inbox, in_wc->src_qp, MAD_IFC_RQPN_OFFSET); 18791da177e4SLinus Torvalds 18801da177e4SLinus Torvalds val = in_wc->sl << 4; 1881ed878458SRoland Dreier MTHCA_PUT(inbox, val, MAD_IFC_SL_OFFSET); 18821da177e4SLinus Torvalds 18831da177e4SLinus Torvalds val = in_wc->dlid_path_bits | 18841da177e4SLinus Torvalds (in_wc->wc_flags & IB_WC_GRH ? 0x80 : 0); 188568586b67SMichael S. Tsirkin MTHCA_PUT(inbox, val, MAD_IFC_G_PATH_OFFSET); 18861da177e4SLinus Torvalds 1887ed878458SRoland Dreier MTHCA_PUT(inbox, in_wc->slid, MAD_IFC_RLID_OFFSET); 1888ed878458SRoland Dreier MTHCA_PUT(inbox, in_wc->pkey_index, MAD_IFC_PKEY_OFFSET); 18891da177e4SLinus Torvalds 18901da177e4SLinus Torvalds if (in_grh) 1891ed878458SRoland Dreier memcpy(inbox + MAD_IFC_GRH_OFFSET, in_grh, 40); 18921da177e4SLinus Torvalds 189368586b67SMichael S. Tsirkin op_modifier |= 0x4; 18941da177e4SLinus Torvalds 18951da177e4SLinus Torvalds in_modifier |= in_wc->slid << 16; 18961da177e4SLinus Torvalds } 18971da177e4SLinus Torvalds 1898ed878458SRoland Dreier err = mthca_cmd_box(dev, inmailbox->dma, outmailbox->dma, 1899ed878458SRoland Dreier in_modifier, op_modifier, 19001da177e4SLinus Torvalds CMD_MAD_IFC, CMD_TIME_CLASS_C, status); 19011da177e4SLinus Torvalds 19021da177e4SLinus Torvalds if (!err && !*status) 1903ed878458SRoland Dreier memcpy(response_mad, outmailbox->buf, 256); 19041da177e4SLinus Torvalds 1905ed878458SRoland Dreier mthca_free_mailbox(dev, inmailbox); 1906ed878458SRoland Dreier mthca_free_mailbox(dev, outmailbox); 19071da177e4SLinus Torvalds return err; 19081da177e4SLinus Torvalds } 19091da177e4SLinus Torvalds 1910ed878458SRoland Dreier int mthca_READ_MGM(struct mthca_dev *dev, int index, 1911ed878458SRoland Dreier struct mthca_mailbox *mailbox, u8 *status) 19121da177e4SLinus Torvalds { 1913ed878458SRoland Dreier return mthca_cmd_box(dev, 0, mailbox->dma, index, 0, 1914ed878458SRoland Dreier CMD_READ_MGM, CMD_TIME_CLASS_A, status); 1915ed878458SRoland Dreier } 19161da177e4SLinus Torvalds 1917ed878458SRoland Dreier int mthca_WRITE_MGM(struct mthca_dev *dev, int index, 1918ed878458SRoland Dreier struct mthca_mailbox *mailbox, u8 *status) 1919ed878458SRoland Dreier { 1920ed878458SRoland Dreier return mthca_cmd(dev, mailbox->dma, index, 0, CMD_WRITE_MGM, 19211da177e4SLinus Torvalds CMD_TIME_CLASS_A, status); 19221da177e4SLinus Torvalds } 19231da177e4SLinus Torvalds 1924ed878458SRoland Dreier int mthca_MGID_HASH(struct mthca_dev *dev, struct mthca_mailbox *mailbox, 1925ed878458SRoland Dreier u16 *hash, u8 *status) 19261da177e4SLinus Torvalds { 19271da177e4SLinus Torvalds u64 imm; 19281da177e4SLinus Torvalds int err; 19291da177e4SLinus Torvalds 1930ed878458SRoland Dreier err = mthca_cmd_imm(dev, mailbox->dma, &imm, 0, 0, CMD_MGID_HASH, 19311da177e4SLinus Torvalds CMD_TIME_CLASS_A, status); 19321da177e4SLinus Torvalds 1933ed878458SRoland Dreier *hash = imm; 19341da177e4SLinus Torvalds return err; 19351da177e4SLinus Torvalds } 19361da177e4SLinus Torvalds 19371da177e4SLinus Torvalds int mthca_NOP(struct mthca_dev *dev, u8 *status) 19381da177e4SLinus Torvalds { 19391da177e4SLinus Torvalds return mthca_cmd(dev, 0, 0x1f, 0, CMD_NOP, msecs_to_jiffies(100), status); 19401da177e4SLinus Torvalds } 1941