15a2cc190SJeff Kirsher /* 25a2cc190SJeff Kirsher * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved. 35a2cc190SJeff Kirsher * Copyright (c) 2005, 2006, 2007, 2008 Mellanox Technologies. All rights reserved. 45a2cc190SJeff Kirsher * Copyright (c) 2005, 2006, 2007 Cisco Systems, Inc. All rights reserved. 55a2cc190SJeff Kirsher * 65a2cc190SJeff Kirsher * This software is available to you under a choice of one of two 75a2cc190SJeff Kirsher * licenses. You may choose to be licensed under the terms of the GNU 85a2cc190SJeff Kirsher * General Public License (GPL) Version 2, available from the file 95a2cc190SJeff Kirsher * COPYING in the main directory of this source tree, or the 105a2cc190SJeff Kirsher * OpenIB.org BSD license below: 115a2cc190SJeff Kirsher * 125a2cc190SJeff Kirsher * Redistribution and use in source and binary forms, with or 135a2cc190SJeff Kirsher * without modification, are permitted provided that the following 145a2cc190SJeff Kirsher * conditions are met: 155a2cc190SJeff Kirsher * 165a2cc190SJeff Kirsher * - Redistributions of source code must retain the above 175a2cc190SJeff Kirsher * copyright notice, this list of conditions and the following 185a2cc190SJeff Kirsher * disclaimer. 195a2cc190SJeff Kirsher * 205a2cc190SJeff Kirsher * - Redistributions in binary form must reproduce the above 215a2cc190SJeff Kirsher * copyright notice, this list of conditions and the following 225a2cc190SJeff Kirsher * disclaimer in the documentation and/or other materials 235a2cc190SJeff Kirsher * provided with the distribution. 245a2cc190SJeff Kirsher * 255a2cc190SJeff Kirsher * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 265a2cc190SJeff Kirsher * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 275a2cc190SJeff Kirsher * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 285a2cc190SJeff Kirsher * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 295a2cc190SJeff Kirsher * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 305a2cc190SJeff Kirsher * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 315a2cc190SJeff Kirsher * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 325a2cc190SJeff Kirsher * SOFTWARE. 335a2cc190SJeff Kirsher */ 345a2cc190SJeff Kirsher 355cc914f1SMarcel Apfelbaum #include <linux/etherdevice.h> 365a2cc190SJeff Kirsher #include <linux/mlx4/cmd.h> 379d9779e7SPaul Gortmaker #include <linux/module.h> 385a2cc190SJeff Kirsher #include <linux/cache.h> 395a2cc190SJeff Kirsher 405a2cc190SJeff Kirsher #include "fw.h" 415a2cc190SJeff Kirsher #include "icm.h" 425a2cc190SJeff Kirsher 435a2cc190SJeff Kirsher enum { 445a2cc190SJeff Kirsher MLX4_COMMAND_INTERFACE_MIN_REV = 2, 455a2cc190SJeff Kirsher MLX4_COMMAND_INTERFACE_MAX_REV = 3, 465a2cc190SJeff Kirsher MLX4_COMMAND_INTERFACE_NEW_PORT_CMDS = 3, 475a2cc190SJeff Kirsher }; 485a2cc190SJeff Kirsher 495a2cc190SJeff Kirsher extern void __buggy_use_of_MLX4_GET(void); 505a2cc190SJeff Kirsher extern void __buggy_use_of_MLX4_PUT(void); 515a2cc190SJeff Kirsher 5238438f7cSIdo Shamay static bool enable_qos = true; 535a2cc190SJeff Kirsher module_param(enable_qos, bool, 0444); 5438438f7cSIdo Shamay MODULE_PARM_DESC(enable_qos, "Enable Enhanced QoS support (default: on)"); 555a2cc190SJeff Kirsher 565a2cc190SJeff Kirsher #define MLX4_GET(dest, source, offset) \ 575a2cc190SJeff Kirsher do { \ 585a2cc190SJeff Kirsher void *__p = (char *) (source) + (offset); \ 5917d5ceb6SDavid Ahern u64 val; \ 605a2cc190SJeff Kirsher switch (sizeof (dest)) { \ 615a2cc190SJeff Kirsher case 1: (dest) = *(u8 *) __p; break; \ 625a2cc190SJeff Kirsher case 2: (dest) = be16_to_cpup(__p); break; \ 635a2cc190SJeff Kirsher case 4: (dest) = be32_to_cpup(__p); break; \ 6417d5ceb6SDavid Ahern case 8: val = get_unaligned((u64 *)__p); \ 6517d5ceb6SDavid Ahern (dest) = be64_to_cpu(val); break; \ 665a2cc190SJeff Kirsher default: __buggy_use_of_MLX4_GET(); \ 675a2cc190SJeff Kirsher } \ 685a2cc190SJeff Kirsher } while (0) 695a2cc190SJeff Kirsher 705a2cc190SJeff Kirsher #define MLX4_PUT(dest, source, offset) \ 715a2cc190SJeff Kirsher do { \ 725a2cc190SJeff Kirsher void *__d = ((char *) (dest) + (offset)); \ 735a2cc190SJeff Kirsher switch (sizeof(source)) { \ 745a2cc190SJeff Kirsher case 1: *(u8 *) __d = (source); break; \ 755a2cc190SJeff Kirsher case 2: *(__be16 *) __d = cpu_to_be16(source); break; \ 765a2cc190SJeff Kirsher case 4: *(__be32 *) __d = cpu_to_be32(source); break; \ 775a2cc190SJeff Kirsher case 8: *(__be64 *) __d = cpu_to_be64(source); break; \ 785a2cc190SJeff Kirsher default: __buggy_use_of_MLX4_PUT(); \ 795a2cc190SJeff Kirsher } \ 805a2cc190SJeff Kirsher } while (0) 815a2cc190SJeff Kirsher 825a2cc190SJeff Kirsher static void dump_dev_cap_flags(struct mlx4_dev *dev, u64 flags) 835a2cc190SJeff Kirsher { 845a2cc190SJeff Kirsher static const char *fname[] = { 855a2cc190SJeff Kirsher [ 0] = "RC transport", 865a2cc190SJeff Kirsher [ 1] = "UC transport", 875a2cc190SJeff Kirsher [ 2] = "UD transport", 885a2cc190SJeff Kirsher [ 3] = "XRC transport", 895a2cc190SJeff Kirsher [ 6] = "SRQ support", 905a2cc190SJeff Kirsher [ 7] = "IPoIB checksum offload", 915a2cc190SJeff Kirsher [ 8] = "P_Key violation counter", 925a2cc190SJeff Kirsher [ 9] = "Q_Key violation counter", 934d531aa8SOr Gerlitz [12] = "Dual Port Different Protocol (DPDP) support", 945a2cc190SJeff Kirsher [15] = "Big LSO headers", 955a2cc190SJeff Kirsher [16] = "MW support", 965a2cc190SJeff Kirsher [17] = "APM support", 975a2cc190SJeff Kirsher [18] = "Atomic ops support", 985a2cc190SJeff Kirsher [19] = "Raw multicast support", 995a2cc190SJeff Kirsher [20] = "Address vector port checking support", 1005a2cc190SJeff Kirsher [21] = "UD multicast support", 1015a2cc190SJeff Kirsher [30] = "IBoE support", 1025a2cc190SJeff Kirsher [32] = "Unicast loopback support", 103f3a9d1f2SYevgeny Petrilin [34] = "FCS header control", 104cb2147a9SOr Gerlitz [37] = "Wake On LAN (port1) support", 105cb2147a9SOr Gerlitz [38] = "Wake On LAN (port2) support", 1065a2cc190SJeff Kirsher [40] = "UDP RSS support", 1075a2cc190SJeff Kirsher [41] = "Unicast VEP steering support", 1085a2cc190SJeff Kirsher [42] = "Multicast VEP steering support", 1095a2cc190SJeff Kirsher [48] = "Counters support", 110802f42a8SIdo Shamay [52] = "RSS IP fragments support", 111540b3a39SOr Gerlitz [53] = "Port ETS Scheduler support", 1124d531aa8SOr Gerlitz [55] = "Port link type sensing support", 11300f5ce99SJack Morgenstein [59] = "Port management change event support", 11408ff3235SOr Gerlitz [61] = "64 byte EQE support", 11508ff3235SOr Gerlitz [62] = "64 byte CQE support", 1165a2cc190SJeff Kirsher }; 1175a2cc190SJeff Kirsher int i; 1185a2cc190SJeff Kirsher 1195a2cc190SJeff Kirsher mlx4_dbg(dev, "DEV_CAP flags:\n"); 1205a2cc190SJeff Kirsher for (i = 0; i < ARRAY_SIZE(fname); ++i) 1215a2cc190SJeff Kirsher if (fname[i] && (flags & (1LL << i))) 1225a2cc190SJeff Kirsher mlx4_dbg(dev, " %s\n", fname[i]); 1235a2cc190SJeff Kirsher } 1245a2cc190SJeff Kirsher 125b3416f44SShlomo Pongratz static void dump_dev_cap_flags2(struct mlx4_dev *dev, u64 flags) 126b3416f44SShlomo Pongratz { 127b3416f44SShlomo Pongratz static const char * const fname[] = { 128b3416f44SShlomo Pongratz [0] = "RSS support", 129b3416f44SShlomo Pongratz [1] = "RSS Toeplitz Hash Function support", 1300ff1fb65SHadar Hen Zion [2] = "RSS XOR Hash Function support", 13156cb4567SOr Gerlitz [3] = "Device managed flow steering support", 132d998735fSEugenia Emantayev [4] = "Automatic MAC reassignment support", 1334e8cf5b8SOr Gerlitz [5] = "Time stamping support", 1344e8cf5b8SOr Gerlitz [6] = "VST (control vlan insertion/stripping) support", 135b01978caSJack Morgenstein [7] = "FSM (MAC anti-spoofing) support", 1367ffdf726SOr Gerlitz [8] = "Dynamic QP updates support", 13756cb4567SOr Gerlitz [9] = "Device managed flow steering IPoIB support", 138114840c3SJack Morgenstein [10] = "TCP/IP offloads/flow-steering for VXLAN support", 13977507aa2SIdo Shamay [11] = "MAD DEMUX (Secure-Host) support", 14077507aa2SIdo Shamay [12] = "Large cache line (>64B) CQE stride support", 141adbc7ac5SSaeed Mahameed [13] = "Large cache line (>64B) EQE stride support", 142a53e3e8cSSaeed Mahameed [14] = "Ethernet protocol control support", 143d475c95bSMatan Barak [15] = "Ethernet Backplane autoneg support", 1447ae0e400SMatan Barak [16] = "CONFIG DEV support", 145de966c59SMatan Barak [17] = "Asymmetric EQs support", 1467d077cd3SMatan Barak [18] = "More than 80 VFs support", 147be6a6b43SJack Morgenstein [19] = "Performance optimized for limited rule configuration flow steering support", 14859e14e32SMoni Shoua [20] = "Recoverable error events support", 149d237baa1SShani Michaeli [21] = "Port Remap support", 150fc31e256SOr Gerlitz [22] = "QCN support", 1510b131561SMatan Barak [23] = "QP rate limiting support", 152d019fcb2SIdo Shamay [24] = "Ethernet Flow control statistics support", 153d019fcb2SIdo Shamay [25] = "Granular QoS per VF support", 1543742cc65SIdo Shamay [26] = "Port ETS Scheduler support", 15551af33cfSIdo Shamay [27] = "Port beacon support", 15678500b8cSMuhammad Mahajna [28] = "RX-ALL support", 15777fc29c4SHadar Hen Zion [29] = "802.1ad offload support", 1589a892835SMaor Gottlieb [31] = "Modifying loopback source checks using UPDATE_QP support", 1599a892835SMaor Gottlieb [32] = "Loopback source checks support", 1600e451e88SMarina Varshaver [33] = "RoCEv2 support", 1610e451e88SMarina Varshaver [34] = "DMFS Sniffer support (UC & MC)" 162b3416f44SShlomo Pongratz }; 163b3416f44SShlomo Pongratz int i; 164b3416f44SShlomo Pongratz 165b3416f44SShlomo Pongratz for (i = 0; i < ARRAY_SIZE(fname); ++i) 166b3416f44SShlomo Pongratz if (fname[i] && (flags & (1LL << i))) 167b3416f44SShlomo Pongratz mlx4_dbg(dev, " %s\n", fname[i]); 168b3416f44SShlomo Pongratz } 169b3416f44SShlomo Pongratz 1705a2cc190SJeff Kirsher int mlx4_MOD_STAT_CFG(struct mlx4_dev *dev, struct mlx4_mod_stat_cfg *cfg) 1715a2cc190SJeff Kirsher { 1725a2cc190SJeff Kirsher struct mlx4_cmd_mailbox *mailbox; 1735a2cc190SJeff Kirsher u32 *inbox; 1745a2cc190SJeff Kirsher int err = 0; 1755a2cc190SJeff Kirsher 1765a2cc190SJeff Kirsher #define MOD_STAT_CFG_IN_SIZE 0x100 1775a2cc190SJeff Kirsher 1785a2cc190SJeff Kirsher #define MOD_STAT_CFG_PG_SZ_M_OFFSET 0x002 1795a2cc190SJeff Kirsher #define MOD_STAT_CFG_PG_SZ_OFFSET 0x003 1805a2cc190SJeff Kirsher 1815a2cc190SJeff Kirsher mailbox = mlx4_alloc_cmd_mailbox(dev); 1825a2cc190SJeff Kirsher if (IS_ERR(mailbox)) 1835a2cc190SJeff Kirsher return PTR_ERR(mailbox); 1845a2cc190SJeff Kirsher inbox = mailbox->buf; 1855a2cc190SJeff Kirsher 1865a2cc190SJeff Kirsher MLX4_PUT(inbox, cfg->log_pg_sz, MOD_STAT_CFG_PG_SZ_OFFSET); 1875a2cc190SJeff Kirsher MLX4_PUT(inbox, cfg->log_pg_sz_m, MOD_STAT_CFG_PG_SZ_M_OFFSET); 1885a2cc190SJeff Kirsher 1895a2cc190SJeff Kirsher err = mlx4_cmd(dev, mailbox->dma, 0, 0, MLX4_CMD_MOD_STAT_CFG, 190f9baff50SJack Morgenstein MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE); 1915a2cc190SJeff Kirsher 1925a2cc190SJeff Kirsher mlx4_free_cmd_mailbox(dev, mailbox); 1935a2cc190SJeff Kirsher return err; 1945a2cc190SJeff Kirsher } 1955a2cc190SJeff Kirsher 196e8c4265bSMatan Barak int mlx4_QUERY_FUNC(struct mlx4_dev *dev, struct mlx4_func *func, int slave) 197e8c4265bSMatan Barak { 198e8c4265bSMatan Barak struct mlx4_cmd_mailbox *mailbox; 199e8c4265bSMatan Barak u32 *outbox; 200e8c4265bSMatan Barak u8 in_modifier; 201e8c4265bSMatan Barak u8 field; 202e8c4265bSMatan Barak u16 field16; 203e8c4265bSMatan Barak int err; 204e8c4265bSMatan Barak 205e8c4265bSMatan Barak #define QUERY_FUNC_BUS_OFFSET 0x00 206e8c4265bSMatan Barak #define QUERY_FUNC_DEVICE_OFFSET 0x01 207e8c4265bSMatan Barak #define QUERY_FUNC_FUNCTION_OFFSET 0x01 208e8c4265bSMatan Barak #define QUERY_FUNC_PHYSICAL_FUNCTION_OFFSET 0x03 209e8c4265bSMatan Barak #define QUERY_FUNC_RSVD_EQS_OFFSET 0x04 210e8c4265bSMatan Barak #define QUERY_FUNC_MAX_EQ_OFFSET 0x06 211e8c4265bSMatan Barak #define QUERY_FUNC_RSVD_UARS_OFFSET 0x0b 212e8c4265bSMatan Barak 213e8c4265bSMatan Barak mailbox = mlx4_alloc_cmd_mailbox(dev); 214e8c4265bSMatan Barak if (IS_ERR(mailbox)) 215e8c4265bSMatan Barak return PTR_ERR(mailbox); 216e8c4265bSMatan Barak outbox = mailbox->buf; 217e8c4265bSMatan Barak 218e8c4265bSMatan Barak in_modifier = slave; 219e8c4265bSMatan Barak 220e8c4265bSMatan Barak err = mlx4_cmd_box(dev, 0, mailbox->dma, in_modifier, 0, 221e8c4265bSMatan Barak MLX4_CMD_QUERY_FUNC, 222e8c4265bSMatan Barak MLX4_CMD_TIME_CLASS_A, 223e8c4265bSMatan Barak MLX4_CMD_NATIVE); 224e8c4265bSMatan Barak if (err) 225e8c4265bSMatan Barak goto out; 226e8c4265bSMatan Barak 227e8c4265bSMatan Barak MLX4_GET(field, outbox, QUERY_FUNC_BUS_OFFSET); 228e8c4265bSMatan Barak func->bus = field & 0xf; 229e8c4265bSMatan Barak MLX4_GET(field, outbox, QUERY_FUNC_DEVICE_OFFSET); 230e8c4265bSMatan Barak func->device = field & 0xf1; 231e8c4265bSMatan Barak MLX4_GET(field, outbox, QUERY_FUNC_FUNCTION_OFFSET); 232e8c4265bSMatan Barak func->function = field & 0x7; 233e8c4265bSMatan Barak MLX4_GET(field, outbox, QUERY_FUNC_PHYSICAL_FUNCTION_OFFSET); 234e8c4265bSMatan Barak func->physical_function = field & 0xf; 235e8c4265bSMatan Barak MLX4_GET(field16, outbox, QUERY_FUNC_RSVD_EQS_OFFSET); 236e8c4265bSMatan Barak func->rsvd_eqs = field16 & 0xffff; 237e8c4265bSMatan Barak MLX4_GET(field16, outbox, QUERY_FUNC_MAX_EQ_OFFSET); 238e8c4265bSMatan Barak func->max_eq = field16 & 0xffff; 239e8c4265bSMatan Barak MLX4_GET(field, outbox, QUERY_FUNC_RSVD_UARS_OFFSET); 240e8c4265bSMatan Barak func->rsvd_uars = field & 0x0f; 241e8c4265bSMatan Barak 242e8c4265bSMatan Barak mlx4_dbg(dev, "Bus: %d, Device: %d, Function: %d, Physical function: %d, Max EQs: %d, Reserved EQs: %d, Reserved UARs: %d\n", 243e8c4265bSMatan Barak func->bus, func->device, func->function, func->physical_function, 244e8c4265bSMatan Barak func->max_eq, func->rsvd_eqs, func->rsvd_uars); 245e8c4265bSMatan Barak 246e8c4265bSMatan Barak out: 247e8c4265bSMatan Barak mlx4_free_cmd_mailbox(dev, mailbox); 248e8c4265bSMatan Barak return err; 249e8c4265bSMatan Barak } 250e8c4265bSMatan Barak 2515cc914f1SMarcel Apfelbaum int mlx4_QUERY_FUNC_CAP_wrapper(struct mlx4_dev *dev, int slave, 2525cc914f1SMarcel Apfelbaum struct mlx4_vhcr *vhcr, 2535cc914f1SMarcel Apfelbaum struct mlx4_cmd_mailbox *inbox, 2545cc914f1SMarcel Apfelbaum struct mlx4_cmd_mailbox *outbox, 2555cc914f1SMarcel Apfelbaum struct mlx4_cmd_info *cmd) 2565cc914f1SMarcel Apfelbaum { 2575a0d0a61SJack Morgenstein struct mlx4_priv *priv = mlx4_priv(dev); 25899ec41d0SJack Morgenstein u8 field, port; 25999ec41d0SJack Morgenstein u32 size, proxy_qp, qkey; 2605cc914f1SMarcel Apfelbaum int err = 0; 2617ae0e400SMatan Barak struct mlx4_func func; 2625cc914f1SMarcel Apfelbaum 2635cc914f1SMarcel Apfelbaum #define QUERY_FUNC_CAP_FLAGS_OFFSET 0x0 2645cc914f1SMarcel Apfelbaum #define QUERY_FUNC_CAP_NUM_PORTS_OFFSET 0x1 2655cc914f1SMarcel Apfelbaum #define QUERY_FUNC_CAP_PF_BHVR_OFFSET 0x4 266105c320fSJack Morgenstein #define QUERY_FUNC_CAP_FMR_OFFSET 0x8 267eb456a68SJack Morgenstein #define QUERY_FUNC_CAP_QP_QUOTA_OFFSET_DEP 0x10 268eb456a68SJack Morgenstein #define QUERY_FUNC_CAP_CQ_QUOTA_OFFSET_DEP 0x14 269eb456a68SJack Morgenstein #define QUERY_FUNC_CAP_SRQ_QUOTA_OFFSET_DEP 0x18 270eb456a68SJack Morgenstein #define QUERY_FUNC_CAP_MPT_QUOTA_OFFSET_DEP 0x20 271eb456a68SJack Morgenstein #define QUERY_FUNC_CAP_MTT_QUOTA_OFFSET_DEP 0x24 272eb456a68SJack Morgenstein #define QUERY_FUNC_CAP_MCG_QUOTA_OFFSET_DEP 0x28 2735cc914f1SMarcel Apfelbaum #define QUERY_FUNC_CAP_MAX_EQ_OFFSET 0x2c 27469612b9fSRoland Dreier #define QUERY_FUNC_CAP_RESERVED_EQ_OFFSET 0x30 275f0ce0615SJack Morgenstein #define QUERY_FUNC_CAP_QP_RESD_LKEY_OFFSET 0x48 2765cc914f1SMarcel Apfelbaum 277eb456a68SJack Morgenstein #define QUERY_FUNC_CAP_QP_QUOTA_OFFSET 0x50 278eb456a68SJack Morgenstein #define QUERY_FUNC_CAP_CQ_QUOTA_OFFSET 0x54 279eb456a68SJack Morgenstein #define QUERY_FUNC_CAP_SRQ_QUOTA_OFFSET 0x58 280eb456a68SJack Morgenstein #define QUERY_FUNC_CAP_MPT_QUOTA_OFFSET 0x60 281eb456a68SJack Morgenstein #define QUERY_FUNC_CAP_MTT_QUOTA_OFFSET 0x64 282eb456a68SJack Morgenstein #define QUERY_FUNC_CAP_MCG_QUOTA_OFFSET 0x68 283eb456a68SJack Morgenstein 284ddae0349SEugenia Emantayev #define QUERY_FUNC_CAP_EXTRA_FLAGS_OFFSET 0x6c 285ddae0349SEugenia Emantayev 286105c320fSJack Morgenstein #define QUERY_FUNC_CAP_FMR_FLAG 0x80 287105c320fSJack Morgenstein #define QUERY_FUNC_CAP_FLAG_RDMA 0x40 288105c320fSJack Morgenstein #define QUERY_FUNC_CAP_FLAG_ETH 0x80 289eb456a68SJack Morgenstein #define QUERY_FUNC_CAP_FLAG_QUOTAS 0x10 290f0ce0615SJack Morgenstein #define QUERY_FUNC_CAP_FLAG_RESD_LKEY 0x08 291ddae0349SEugenia Emantayev #define QUERY_FUNC_CAP_FLAG_VALID_MAILBOX 0x04 292ddae0349SEugenia Emantayev 293ddae0349SEugenia Emantayev #define QUERY_FUNC_CAP_EXTRA_FLAGS_BF_QP_ALLOC_FLAG (1UL << 31) 294d57febe1SMatan Barak #define QUERY_FUNC_CAP_EXTRA_FLAGS_A0_QP_ALLOC_FLAG (1UL << 30) 295105c320fSJack Morgenstein 296105c320fSJack Morgenstein /* when opcode modifier = 1 */ 2975cc914f1SMarcel Apfelbaum #define QUERY_FUNC_CAP_PHYS_PORT_OFFSET 0x3 29899ec41d0SJack Morgenstein #define QUERY_FUNC_CAP_PRIV_VF_QKEY_OFFSET 0x4 29973e74ab4SHadar Hen Zion #define QUERY_FUNC_CAP_FLAGS0_OFFSET 0x8 30073e74ab4SHadar Hen Zion #define QUERY_FUNC_CAP_FLAGS1_OFFSET 0xc 3015cc914f1SMarcel Apfelbaum 30247605df9SJack Morgenstein #define QUERY_FUNC_CAP_QP0_TUNNEL 0x10 30347605df9SJack Morgenstein #define QUERY_FUNC_CAP_QP0_PROXY 0x14 30447605df9SJack Morgenstein #define QUERY_FUNC_CAP_QP1_TUNNEL 0x18 30547605df9SJack Morgenstein #define QUERY_FUNC_CAP_QP1_PROXY 0x1c 3068e1a28e8SHadar Hen Zion #define QUERY_FUNC_CAP_PHYS_PORT_ID 0x28 30747605df9SJack Morgenstein 30873e74ab4SHadar Hen Zion #define QUERY_FUNC_CAP_FLAGS1_FORCE_MAC 0x40 30973e74ab4SHadar Hen Zion #define QUERY_FUNC_CAP_FLAGS1_FORCE_VLAN 0x80 310eb17711bSHadar Hen Zion #define QUERY_FUNC_CAP_FLAGS1_NIC_INFO 0x10 31199ec41d0SJack Morgenstein #define QUERY_FUNC_CAP_VF_ENABLE_QP0 0x08 312105c320fSJack Morgenstein 31373e74ab4SHadar Hen Zion #define QUERY_FUNC_CAP_FLAGS0_FORCE_PHY_WQE_GID 0x80 3147ae0e400SMatan Barak #define QUERY_FUNC_CAP_SUPPORTS_NON_POWER_OF_2_NUM_EQS (1 << 31) 31577fc29c4SHadar Hen Zion #define QUERY_FUNC_CAP_PHV_BIT 0x40 316105c320fSJack Morgenstein 3175cc914f1SMarcel Apfelbaum if (vhcr->op_modifier == 1) { 318449fc488SMatan Barak struct mlx4_active_ports actv_ports = 319449fc488SMatan Barak mlx4_get_active_ports(dev, slave); 320449fc488SMatan Barak int converted_port = mlx4_slave_convert_port( 321449fc488SMatan Barak dev, slave, vhcr->in_modifier); 322449fc488SMatan Barak 323449fc488SMatan Barak if (converted_port < 0) 324449fc488SMatan Barak return -EINVAL; 325449fc488SMatan Barak 326449fc488SMatan Barak vhcr->in_modifier = converted_port; 327449fc488SMatan Barak /* phys-port = logical-port */ 328449fc488SMatan Barak field = vhcr->in_modifier - 329449fc488SMatan Barak find_first_bit(actv_ports.ports, dev->caps.num_ports); 33047605df9SJack Morgenstein MLX4_PUT(outbox->buf, field, QUERY_FUNC_CAP_PHYS_PORT_OFFSET); 33147605df9SJack Morgenstein 33299ec41d0SJack Morgenstein port = vhcr->in_modifier; 33399ec41d0SJack Morgenstein proxy_qp = dev->phys_caps.base_proxy_sqpn + 8 * slave + port - 1; 33499ec41d0SJack Morgenstein 33599ec41d0SJack Morgenstein /* Set nic_info bit to mark new fields support */ 33699ec41d0SJack Morgenstein field = QUERY_FUNC_CAP_FLAGS1_NIC_INFO; 33799ec41d0SJack Morgenstein 33899ec41d0SJack Morgenstein if (mlx4_vf_smi_enabled(dev, slave, port) && 33999ec41d0SJack Morgenstein !mlx4_get_parav_qkey(dev, proxy_qp, &qkey)) { 34099ec41d0SJack Morgenstein field |= QUERY_FUNC_CAP_VF_ENABLE_QP0; 34199ec41d0SJack Morgenstein MLX4_PUT(outbox->buf, qkey, 34299ec41d0SJack Morgenstein QUERY_FUNC_CAP_PRIV_VF_QKEY_OFFSET); 34399ec41d0SJack Morgenstein } 34499ec41d0SJack Morgenstein MLX4_PUT(outbox->buf, field, QUERY_FUNC_CAP_FLAGS1_OFFSET); 34599ec41d0SJack Morgenstein 34647605df9SJack Morgenstein /* size is now the QP number */ 34799ec41d0SJack Morgenstein size = dev->phys_caps.base_tunnel_sqpn + 8 * slave + port - 1; 34847605df9SJack Morgenstein MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_QP0_TUNNEL); 34947605df9SJack Morgenstein 35047605df9SJack Morgenstein size += 2; 35147605df9SJack Morgenstein MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_QP1_TUNNEL); 35247605df9SJack Morgenstein 35399ec41d0SJack Morgenstein MLX4_PUT(outbox->buf, proxy_qp, QUERY_FUNC_CAP_QP0_PROXY); 35499ec41d0SJack Morgenstein proxy_qp += 2; 35599ec41d0SJack Morgenstein MLX4_PUT(outbox->buf, proxy_qp, QUERY_FUNC_CAP_QP1_PROXY); 35647605df9SJack Morgenstein 3578e1a28e8SHadar Hen Zion MLX4_PUT(outbox->buf, dev->caps.phys_port_id[vhcr->in_modifier], 3588e1a28e8SHadar Hen Zion QUERY_FUNC_CAP_PHYS_PORT_ID); 3598e1a28e8SHadar Hen Zion 36077fc29c4SHadar Hen Zion if (dev->caps.phv_bit[port]) { 36177fc29c4SHadar Hen Zion field = QUERY_FUNC_CAP_PHV_BIT; 36277fc29c4SHadar Hen Zion MLX4_PUT(outbox->buf, field, 36377fc29c4SHadar Hen Zion QUERY_FUNC_CAP_FLAGS0_OFFSET); 36477fc29c4SHadar Hen Zion } 36577fc29c4SHadar Hen Zion 3665cc914f1SMarcel Apfelbaum } else if (vhcr->op_modifier == 0) { 367449fc488SMatan Barak struct mlx4_active_ports actv_ports = 368449fc488SMatan Barak mlx4_get_active_ports(dev, slave); 369f0ce0615SJack Morgenstein /* enable rdma and ethernet interfaces, new quota locations, 370f0ce0615SJack Morgenstein * and reserved lkey 371f0ce0615SJack Morgenstein */ 372eb456a68SJack Morgenstein field = (QUERY_FUNC_CAP_FLAG_ETH | QUERY_FUNC_CAP_FLAG_RDMA | 373f0ce0615SJack Morgenstein QUERY_FUNC_CAP_FLAG_QUOTAS | QUERY_FUNC_CAP_FLAG_VALID_MAILBOX | 374f0ce0615SJack Morgenstein QUERY_FUNC_CAP_FLAG_RESD_LKEY); 3755cc914f1SMarcel Apfelbaum MLX4_PUT(outbox->buf, field, QUERY_FUNC_CAP_FLAGS_OFFSET); 3765cc914f1SMarcel Apfelbaum 377449fc488SMatan Barak field = min( 378449fc488SMatan Barak bitmap_weight(actv_ports.ports, dev->caps.num_ports), 379449fc488SMatan Barak dev->caps.num_ports); 3805cc914f1SMarcel Apfelbaum MLX4_PUT(outbox->buf, field, QUERY_FUNC_CAP_NUM_PORTS_OFFSET); 3815cc914f1SMarcel Apfelbaum 38208ff3235SOr Gerlitz size = dev->caps.function_caps; /* set PF behaviours */ 3835cc914f1SMarcel Apfelbaum MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_PF_BHVR_OFFSET); 3845cc914f1SMarcel Apfelbaum 385105c320fSJack Morgenstein field = 0; /* protected FMR support not available as yet */ 386105c320fSJack Morgenstein MLX4_PUT(outbox->buf, field, QUERY_FUNC_CAP_FMR_OFFSET); 387105c320fSJack Morgenstein 3885a0d0a61SJack Morgenstein size = priv->mfunc.master.res_tracker.res_alloc[RES_QP].quota[slave]; 3895cc914f1SMarcel Apfelbaum MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_QP_QUOTA_OFFSET); 390eb456a68SJack Morgenstein size = dev->caps.num_qps; 391eb456a68SJack Morgenstein MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_QP_QUOTA_OFFSET_DEP); 3925cc914f1SMarcel Apfelbaum 3935a0d0a61SJack Morgenstein size = priv->mfunc.master.res_tracker.res_alloc[RES_SRQ].quota[slave]; 3945cc914f1SMarcel Apfelbaum MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_SRQ_QUOTA_OFFSET); 395eb456a68SJack Morgenstein size = dev->caps.num_srqs; 396eb456a68SJack Morgenstein MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_SRQ_QUOTA_OFFSET_DEP); 3975cc914f1SMarcel Apfelbaum 3985a0d0a61SJack Morgenstein size = priv->mfunc.master.res_tracker.res_alloc[RES_CQ].quota[slave]; 3995cc914f1SMarcel Apfelbaum MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_CQ_QUOTA_OFFSET); 400eb456a68SJack Morgenstein size = dev->caps.num_cqs; 401eb456a68SJack Morgenstein MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_CQ_QUOTA_OFFSET_DEP); 4025cc914f1SMarcel Apfelbaum 4037ae0e400SMatan Barak if (!(dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_SYS_EQS) || 4047ae0e400SMatan Barak mlx4_QUERY_FUNC(dev, &func, slave)) { 4057ae0e400SMatan Barak size = vhcr->in_modifier & 4067ae0e400SMatan Barak QUERY_FUNC_CAP_SUPPORTS_NON_POWER_OF_2_NUM_EQS ? 4077ae0e400SMatan Barak dev->caps.num_eqs : 4087ae0e400SMatan Barak rounddown_pow_of_two(dev->caps.num_eqs); 4095cc914f1SMarcel Apfelbaum MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_MAX_EQ_OFFSET); 4105cc914f1SMarcel Apfelbaum size = dev->caps.reserved_eqs; 4115cc914f1SMarcel Apfelbaum MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_RESERVED_EQ_OFFSET); 4127ae0e400SMatan Barak } else { 4137ae0e400SMatan Barak size = vhcr->in_modifier & 4147ae0e400SMatan Barak QUERY_FUNC_CAP_SUPPORTS_NON_POWER_OF_2_NUM_EQS ? 4157ae0e400SMatan Barak func.max_eq : 4167ae0e400SMatan Barak rounddown_pow_of_two(func.max_eq); 4177ae0e400SMatan Barak MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_MAX_EQ_OFFSET); 4187ae0e400SMatan Barak size = func.rsvd_eqs; 4197ae0e400SMatan Barak MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_RESERVED_EQ_OFFSET); 4207ae0e400SMatan Barak } 4215cc914f1SMarcel Apfelbaum 4225a0d0a61SJack Morgenstein size = priv->mfunc.master.res_tracker.res_alloc[RES_MPT].quota[slave]; 4235cc914f1SMarcel Apfelbaum MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_MPT_QUOTA_OFFSET); 424eb456a68SJack Morgenstein size = dev->caps.num_mpts; 425eb456a68SJack Morgenstein MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_MPT_QUOTA_OFFSET_DEP); 4265cc914f1SMarcel Apfelbaum 4275a0d0a61SJack Morgenstein size = priv->mfunc.master.res_tracker.res_alloc[RES_MTT].quota[slave]; 4285cc914f1SMarcel Apfelbaum MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_MTT_QUOTA_OFFSET); 429eb456a68SJack Morgenstein size = dev->caps.num_mtts; 430eb456a68SJack Morgenstein MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_MTT_QUOTA_OFFSET_DEP); 4315cc914f1SMarcel Apfelbaum 4325cc914f1SMarcel Apfelbaum size = dev->caps.num_mgms + dev->caps.num_amgms; 4335cc914f1SMarcel Apfelbaum MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_MCG_QUOTA_OFFSET); 434eb456a68SJack Morgenstein MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_MCG_QUOTA_OFFSET_DEP); 4355cc914f1SMarcel Apfelbaum 436d57febe1SMatan Barak size = QUERY_FUNC_CAP_EXTRA_FLAGS_BF_QP_ALLOC_FLAG | 437d57febe1SMatan Barak QUERY_FUNC_CAP_EXTRA_FLAGS_A0_QP_ALLOC_FLAG; 438ddae0349SEugenia Emantayev MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_EXTRA_FLAGS_OFFSET); 439f0ce0615SJack Morgenstein 440f0ce0615SJack Morgenstein size = dev->caps.reserved_lkey + ((slave << 8) & 0xFF00); 441f0ce0615SJack Morgenstein MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_QP_RESD_LKEY_OFFSET); 4425cc914f1SMarcel Apfelbaum } else 4435cc914f1SMarcel Apfelbaum err = -EINVAL; 4445cc914f1SMarcel Apfelbaum 4455cc914f1SMarcel Apfelbaum return err; 4465cc914f1SMarcel Apfelbaum } 4475cc914f1SMarcel Apfelbaum 448225c6c8cSMatan Barak int mlx4_QUERY_FUNC_CAP(struct mlx4_dev *dev, u8 gen_or_port, 44947605df9SJack Morgenstein struct mlx4_func_cap *func_cap) 4505cc914f1SMarcel Apfelbaum { 4515cc914f1SMarcel Apfelbaum struct mlx4_cmd_mailbox *mailbox; 4525cc914f1SMarcel Apfelbaum u32 *outbox; 45347605df9SJack Morgenstein u8 field, op_modifier; 45499ec41d0SJack Morgenstein u32 size, qkey; 455eb456a68SJack Morgenstein int err = 0, quotas = 0; 4567ae0e400SMatan Barak u32 in_modifier; 4575cc914f1SMarcel Apfelbaum 45847605df9SJack Morgenstein op_modifier = !!gen_or_port; /* 0 = general, 1 = logical port */ 4597ae0e400SMatan Barak in_modifier = op_modifier ? gen_or_port : 4607ae0e400SMatan Barak QUERY_FUNC_CAP_SUPPORTS_NON_POWER_OF_2_NUM_EQS; 4615cc914f1SMarcel Apfelbaum 4625cc914f1SMarcel Apfelbaum mailbox = mlx4_alloc_cmd_mailbox(dev); 4635cc914f1SMarcel Apfelbaum if (IS_ERR(mailbox)) 4645cc914f1SMarcel Apfelbaum return PTR_ERR(mailbox); 4655cc914f1SMarcel Apfelbaum 4667ae0e400SMatan Barak err = mlx4_cmd_box(dev, 0, mailbox->dma, in_modifier, op_modifier, 46747605df9SJack Morgenstein MLX4_CMD_QUERY_FUNC_CAP, 4685cc914f1SMarcel Apfelbaum MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED); 4695cc914f1SMarcel Apfelbaum if (err) 4705cc914f1SMarcel Apfelbaum goto out; 4715cc914f1SMarcel Apfelbaum 4725cc914f1SMarcel Apfelbaum outbox = mailbox->buf; 4735cc914f1SMarcel Apfelbaum 47447605df9SJack Morgenstein if (!op_modifier) { 4755cc914f1SMarcel Apfelbaum MLX4_GET(field, outbox, QUERY_FUNC_CAP_FLAGS_OFFSET); 476105c320fSJack Morgenstein if (!(field & (QUERY_FUNC_CAP_FLAG_ETH | QUERY_FUNC_CAP_FLAG_RDMA))) { 477105c320fSJack Morgenstein mlx4_err(dev, "The host supports neither eth nor rdma interfaces\n"); 4785cc914f1SMarcel Apfelbaum err = -EPROTONOSUPPORT; 4795cc914f1SMarcel Apfelbaum goto out; 4805cc914f1SMarcel Apfelbaum } 481105c320fSJack Morgenstein func_cap->flags = field; 482eb456a68SJack Morgenstein quotas = !!(func_cap->flags & QUERY_FUNC_CAP_FLAG_QUOTAS); 4835cc914f1SMarcel Apfelbaum 4845cc914f1SMarcel Apfelbaum MLX4_GET(field, outbox, QUERY_FUNC_CAP_NUM_PORTS_OFFSET); 4855cc914f1SMarcel Apfelbaum func_cap->num_ports = field; 4865cc914f1SMarcel Apfelbaum 4875cc914f1SMarcel Apfelbaum MLX4_GET(size, outbox, QUERY_FUNC_CAP_PF_BHVR_OFFSET); 4885cc914f1SMarcel Apfelbaum func_cap->pf_context_behaviour = size; 4895cc914f1SMarcel Apfelbaum 490eb456a68SJack Morgenstein if (quotas) { 4915cc914f1SMarcel Apfelbaum MLX4_GET(size, outbox, QUERY_FUNC_CAP_QP_QUOTA_OFFSET); 4925cc914f1SMarcel Apfelbaum func_cap->qp_quota = size & 0xFFFFFF; 4935cc914f1SMarcel Apfelbaum 4945cc914f1SMarcel Apfelbaum MLX4_GET(size, outbox, QUERY_FUNC_CAP_SRQ_QUOTA_OFFSET); 4955cc914f1SMarcel Apfelbaum func_cap->srq_quota = size & 0xFFFFFF; 4965cc914f1SMarcel Apfelbaum 4975cc914f1SMarcel Apfelbaum MLX4_GET(size, outbox, QUERY_FUNC_CAP_CQ_QUOTA_OFFSET); 4985cc914f1SMarcel Apfelbaum func_cap->cq_quota = size & 0xFFFFFF; 4995cc914f1SMarcel Apfelbaum 5005cc914f1SMarcel Apfelbaum MLX4_GET(size, outbox, QUERY_FUNC_CAP_MPT_QUOTA_OFFSET); 5015cc914f1SMarcel Apfelbaum func_cap->mpt_quota = size & 0xFFFFFF; 5025cc914f1SMarcel Apfelbaum 5035cc914f1SMarcel Apfelbaum MLX4_GET(size, outbox, QUERY_FUNC_CAP_MTT_QUOTA_OFFSET); 5045cc914f1SMarcel Apfelbaum func_cap->mtt_quota = size & 0xFFFFFF; 5055cc914f1SMarcel Apfelbaum 5065cc914f1SMarcel Apfelbaum MLX4_GET(size, outbox, QUERY_FUNC_CAP_MCG_QUOTA_OFFSET); 5075cc914f1SMarcel Apfelbaum func_cap->mcg_quota = size & 0xFFFFFF; 508eb456a68SJack Morgenstein 509eb456a68SJack Morgenstein } else { 510eb456a68SJack Morgenstein MLX4_GET(size, outbox, QUERY_FUNC_CAP_QP_QUOTA_OFFSET_DEP); 511eb456a68SJack Morgenstein func_cap->qp_quota = size & 0xFFFFFF; 512eb456a68SJack Morgenstein 513eb456a68SJack Morgenstein MLX4_GET(size, outbox, QUERY_FUNC_CAP_SRQ_QUOTA_OFFSET_DEP); 514eb456a68SJack Morgenstein func_cap->srq_quota = size & 0xFFFFFF; 515eb456a68SJack Morgenstein 516eb456a68SJack Morgenstein MLX4_GET(size, outbox, QUERY_FUNC_CAP_CQ_QUOTA_OFFSET_DEP); 517eb456a68SJack Morgenstein func_cap->cq_quota = size & 0xFFFFFF; 518eb456a68SJack Morgenstein 519eb456a68SJack Morgenstein MLX4_GET(size, outbox, QUERY_FUNC_CAP_MPT_QUOTA_OFFSET_DEP); 520eb456a68SJack Morgenstein func_cap->mpt_quota = size & 0xFFFFFF; 521eb456a68SJack Morgenstein 522eb456a68SJack Morgenstein MLX4_GET(size, outbox, QUERY_FUNC_CAP_MTT_QUOTA_OFFSET_DEP); 523eb456a68SJack Morgenstein func_cap->mtt_quota = size & 0xFFFFFF; 524eb456a68SJack Morgenstein 525eb456a68SJack Morgenstein MLX4_GET(size, outbox, QUERY_FUNC_CAP_MCG_QUOTA_OFFSET_DEP); 526eb456a68SJack Morgenstein func_cap->mcg_quota = size & 0xFFFFFF; 527eb456a68SJack Morgenstein } 528eb456a68SJack Morgenstein MLX4_GET(size, outbox, QUERY_FUNC_CAP_MAX_EQ_OFFSET); 529eb456a68SJack Morgenstein func_cap->max_eq = size & 0xFFFFFF; 530eb456a68SJack Morgenstein 531eb456a68SJack Morgenstein MLX4_GET(size, outbox, QUERY_FUNC_CAP_RESERVED_EQ_OFFSET); 532eb456a68SJack Morgenstein func_cap->reserved_eq = size & 0xFFFFFF; 533eb456a68SJack Morgenstein 534f0ce0615SJack Morgenstein if (func_cap->flags & QUERY_FUNC_CAP_FLAG_RESD_LKEY) { 535f0ce0615SJack Morgenstein MLX4_GET(size, outbox, QUERY_FUNC_CAP_QP_RESD_LKEY_OFFSET); 536f0ce0615SJack Morgenstein func_cap->reserved_lkey = size; 537f0ce0615SJack Morgenstein } else { 538f0ce0615SJack Morgenstein func_cap->reserved_lkey = 0; 539f0ce0615SJack Morgenstein } 540f0ce0615SJack Morgenstein 541ddae0349SEugenia Emantayev func_cap->extra_flags = 0; 542ddae0349SEugenia Emantayev 543ddae0349SEugenia Emantayev /* Mailbox data from 0x6c and onward should only be treated if 544ddae0349SEugenia Emantayev * QUERY_FUNC_CAP_FLAG_VALID_MAILBOX is set in func_cap->flags 545ddae0349SEugenia Emantayev */ 546ddae0349SEugenia Emantayev if (func_cap->flags & QUERY_FUNC_CAP_FLAG_VALID_MAILBOX) { 547ddae0349SEugenia Emantayev MLX4_GET(size, outbox, QUERY_FUNC_CAP_EXTRA_FLAGS_OFFSET); 548ddae0349SEugenia Emantayev if (size & QUERY_FUNC_CAP_EXTRA_FLAGS_BF_QP_ALLOC_FLAG) 549ddae0349SEugenia Emantayev func_cap->extra_flags |= MLX4_QUERY_FUNC_FLAGS_BF_RES_QP; 550d57febe1SMatan Barak if (size & QUERY_FUNC_CAP_EXTRA_FLAGS_A0_QP_ALLOC_FLAG) 551d57febe1SMatan Barak func_cap->extra_flags |= MLX4_QUERY_FUNC_FLAGS_A0_RES_QP; 552ddae0349SEugenia Emantayev } 553ddae0349SEugenia Emantayev 5545cc914f1SMarcel Apfelbaum goto out; 55547605df9SJack Morgenstein } 5565cc914f1SMarcel Apfelbaum 55747605df9SJack Morgenstein /* logical port query */ 55847605df9SJack Morgenstein if (gen_or_port > dev->caps.num_ports) { 55947605df9SJack Morgenstein err = -EINVAL; 56047605df9SJack Morgenstein goto out; 56147605df9SJack Morgenstein } 56247605df9SJack Morgenstein 563eb17711bSHadar Hen Zion MLX4_GET(func_cap->flags1, outbox, QUERY_FUNC_CAP_FLAGS1_OFFSET); 56447605df9SJack Morgenstein if (dev->caps.port_type[gen_or_port] == MLX4_PORT_TYPE_ETH) { 565bc82878bSJack Morgenstein if (func_cap->flags1 & QUERY_FUNC_CAP_FLAGS1_FORCE_VLAN) { 5665cc914f1SMarcel Apfelbaum mlx4_err(dev, "VLAN is enforced on this port\n"); 5675cc914f1SMarcel Apfelbaum err = -EPROTONOSUPPORT; 5685cc914f1SMarcel Apfelbaum goto out; 5695cc914f1SMarcel Apfelbaum } 5705cc914f1SMarcel Apfelbaum 571eb17711bSHadar Hen Zion if (func_cap->flags1 & QUERY_FUNC_CAP_FLAGS1_FORCE_MAC) { 5725cc914f1SMarcel Apfelbaum mlx4_err(dev, "Force mac is enabled on this port\n"); 5735cc914f1SMarcel Apfelbaum err = -EPROTONOSUPPORT; 5745cc914f1SMarcel Apfelbaum goto out; 5755cc914f1SMarcel Apfelbaum } 57647605df9SJack Morgenstein } else if (dev->caps.port_type[gen_or_port] == MLX4_PORT_TYPE_IB) { 57773e74ab4SHadar Hen Zion MLX4_GET(field, outbox, QUERY_FUNC_CAP_FLAGS0_OFFSET); 57873e74ab4SHadar Hen Zion if (field & QUERY_FUNC_CAP_FLAGS0_FORCE_PHY_WQE_GID) { 5791a91de28SJoe Perches mlx4_err(dev, "phy_wqe_gid is enforced on this ib port\n"); 580105c320fSJack Morgenstein err = -EPROTONOSUPPORT; 581105c320fSJack Morgenstein goto out; 582105c320fSJack Morgenstein } 583105c320fSJack Morgenstein } 5845cc914f1SMarcel Apfelbaum 5855cc914f1SMarcel Apfelbaum MLX4_GET(field, outbox, QUERY_FUNC_CAP_PHYS_PORT_OFFSET); 58647605df9SJack Morgenstein func_cap->physical_port = field; 58747605df9SJack Morgenstein if (func_cap->physical_port != gen_or_port) { 58847605df9SJack Morgenstein err = -ENOSYS; 58947605df9SJack Morgenstein goto out; 5905cc914f1SMarcel Apfelbaum } 5915cc914f1SMarcel Apfelbaum 59299ec41d0SJack Morgenstein if (func_cap->flags1 & QUERY_FUNC_CAP_VF_ENABLE_QP0) { 59399ec41d0SJack Morgenstein MLX4_GET(qkey, outbox, QUERY_FUNC_CAP_PRIV_VF_QKEY_OFFSET); 59499ec41d0SJack Morgenstein func_cap->qp0_qkey = qkey; 59599ec41d0SJack Morgenstein } else { 59699ec41d0SJack Morgenstein func_cap->qp0_qkey = 0; 59799ec41d0SJack Morgenstein } 59899ec41d0SJack Morgenstein 59947605df9SJack Morgenstein MLX4_GET(size, outbox, QUERY_FUNC_CAP_QP0_TUNNEL); 60047605df9SJack Morgenstein func_cap->qp0_tunnel_qpn = size & 0xFFFFFF; 60147605df9SJack Morgenstein 60247605df9SJack Morgenstein MLX4_GET(size, outbox, QUERY_FUNC_CAP_QP0_PROXY); 60347605df9SJack Morgenstein func_cap->qp0_proxy_qpn = size & 0xFFFFFF; 60447605df9SJack Morgenstein 60547605df9SJack Morgenstein MLX4_GET(size, outbox, QUERY_FUNC_CAP_QP1_TUNNEL); 60647605df9SJack Morgenstein func_cap->qp1_tunnel_qpn = size & 0xFFFFFF; 60747605df9SJack Morgenstein 60847605df9SJack Morgenstein MLX4_GET(size, outbox, QUERY_FUNC_CAP_QP1_PROXY); 60947605df9SJack Morgenstein func_cap->qp1_proxy_qpn = size & 0xFFFFFF; 61047605df9SJack Morgenstein 6118e1a28e8SHadar Hen Zion if (func_cap->flags1 & QUERY_FUNC_CAP_FLAGS1_NIC_INFO) 6128e1a28e8SHadar Hen Zion MLX4_GET(func_cap->phys_port_id, outbox, 6138e1a28e8SHadar Hen Zion QUERY_FUNC_CAP_PHYS_PORT_ID); 6148e1a28e8SHadar Hen Zion 61577fc29c4SHadar Hen Zion MLX4_GET(field, outbox, QUERY_FUNC_CAP_FLAGS0_OFFSET); 61677fc29c4SHadar Hen Zion func_cap->flags |= (field & QUERY_FUNC_CAP_PHV_BIT); 61777fc29c4SHadar Hen Zion 6185cc914f1SMarcel Apfelbaum /* All other resources are allocated by the master, but we still report 6195cc914f1SMarcel Apfelbaum * 'num' and 'reserved' capabilities as follows: 6205cc914f1SMarcel Apfelbaum * - num remains the maximum resource index 6215cc914f1SMarcel Apfelbaum * - 'num - reserved' is the total available objects of a resource, but 6225cc914f1SMarcel Apfelbaum * resource indices may be less than 'reserved' 6235cc914f1SMarcel Apfelbaum * TODO: set per-resource quotas */ 6245cc914f1SMarcel Apfelbaum 6255cc914f1SMarcel Apfelbaum out: 6265cc914f1SMarcel Apfelbaum mlx4_free_cmd_mailbox(dev, mailbox); 6275cc914f1SMarcel Apfelbaum 6285cc914f1SMarcel Apfelbaum return err; 6295cc914f1SMarcel Apfelbaum } 6305cc914f1SMarcel Apfelbaum 631d8ae9141SMoni Shoua static void disable_unsupported_roce_caps(void *buf); 632d8ae9141SMoni Shoua 6335a2cc190SJeff Kirsher int mlx4_QUERY_DEV_CAP(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap) 6345a2cc190SJeff Kirsher { 6355a2cc190SJeff Kirsher struct mlx4_cmd_mailbox *mailbox; 6365a2cc190SJeff Kirsher u32 *outbox; 6375a2cc190SJeff Kirsher u8 field; 6385a2cc190SJeff Kirsher u32 field32, flags, ext_flags; 6395a2cc190SJeff Kirsher u16 size; 6405a2cc190SJeff Kirsher u16 stat_rate; 6415a2cc190SJeff Kirsher int err; 6425a2cc190SJeff Kirsher int i; 6435a2cc190SJeff Kirsher 6445a2cc190SJeff Kirsher #define QUERY_DEV_CAP_OUT_SIZE 0x100 6455a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MAX_SRQ_SZ_OFFSET 0x10 6465a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MAX_QP_SZ_OFFSET 0x11 6475a2cc190SJeff Kirsher #define QUERY_DEV_CAP_RSVD_QP_OFFSET 0x12 6485a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MAX_QP_OFFSET 0x13 6495a2cc190SJeff Kirsher #define QUERY_DEV_CAP_RSVD_SRQ_OFFSET 0x14 6505a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MAX_SRQ_OFFSET 0x15 6515a2cc190SJeff Kirsher #define QUERY_DEV_CAP_RSVD_EEC_OFFSET 0x16 6525a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MAX_EEC_OFFSET 0x17 6535a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MAX_CQ_SZ_OFFSET 0x19 6545a2cc190SJeff Kirsher #define QUERY_DEV_CAP_RSVD_CQ_OFFSET 0x1a 6555a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MAX_CQ_OFFSET 0x1b 6565a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MAX_MPT_OFFSET 0x1d 6575a2cc190SJeff Kirsher #define QUERY_DEV_CAP_RSVD_EQ_OFFSET 0x1e 6585a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MAX_EQ_OFFSET 0x1f 6595a2cc190SJeff Kirsher #define QUERY_DEV_CAP_RSVD_MTT_OFFSET 0x20 6605a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MAX_MRW_SZ_OFFSET 0x21 6615a2cc190SJeff Kirsher #define QUERY_DEV_CAP_RSVD_MRW_OFFSET 0x22 6625a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MAX_MTT_SEG_OFFSET 0x23 6637ae0e400SMatan Barak #define QUERY_DEV_CAP_NUM_SYS_EQ_OFFSET 0x26 6645a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MAX_AV_OFFSET 0x27 6655a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MAX_REQ_QP_OFFSET 0x29 6665a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MAX_RES_QP_OFFSET 0x2b 6675a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MAX_GSO_OFFSET 0x2d 668b3416f44SShlomo Pongratz #define QUERY_DEV_CAP_RSS_OFFSET 0x2e 6695a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MAX_RDMA_OFFSET 0x2f 6705a2cc190SJeff Kirsher #define QUERY_DEV_CAP_RSZ_SRQ_OFFSET 0x33 67151af33cfSIdo Shamay #define QUERY_DEV_CAP_PORT_BEACON_OFFSET 0x34 6725a2cc190SJeff Kirsher #define QUERY_DEV_CAP_ACK_DELAY_OFFSET 0x35 6735a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MTU_WIDTH_OFFSET 0x36 6745a2cc190SJeff Kirsher #define QUERY_DEV_CAP_VL_PORT_OFFSET 0x37 6755a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MAX_MSG_SZ_OFFSET 0x38 6765a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MAX_GID_OFFSET 0x3b 6775a2cc190SJeff Kirsher #define QUERY_DEV_CAP_RATE_SUPPORT_OFFSET 0x3c 678d998735fSEugenia Emantayev #define QUERY_DEV_CAP_CQ_TS_SUPPORT_OFFSET 0x3e 6795a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MAX_PKEY_OFFSET 0x3f 6805a2cc190SJeff Kirsher #define QUERY_DEV_CAP_EXT_FLAGS_OFFSET 0x40 6815a2cc190SJeff Kirsher #define QUERY_DEV_CAP_FLAGS_OFFSET 0x44 6825a2cc190SJeff Kirsher #define QUERY_DEV_CAP_RSVD_UAR_OFFSET 0x48 6835a2cc190SJeff Kirsher #define QUERY_DEV_CAP_UAR_SZ_OFFSET 0x49 6845a2cc190SJeff Kirsher #define QUERY_DEV_CAP_PAGE_SZ_OFFSET 0x4b 6855a2cc190SJeff Kirsher #define QUERY_DEV_CAP_BF_OFFSET 0x4c 6865a2cc190SJeff Kirsher #define QUERY_DEV_CAP_LOG_BF_REG_SZ_OFFSET 0x4d 6875a2cc190SJeff Kirsher #define QUERY_DEV_CAP_LOG_MAX_BF_REGS_PER_PAGE_OFFSET 0x4e 6885a2cc190SJeff Kirsher #define QUERY_DEV_CAP_LOG_MAX_BF_PAGES_OFFSET 0x4f 6895a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MAX_SG_SQ_OFFSET 0x51 6905a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MAX_DESC_SZ_SQ_OFFSET 0x52 6915a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MAX_SG_RQ_OFFSET 0x55 6925a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MAX_DESC_SZ_RQ_OFFSET 0x56 6935a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MAX_QP_MCG_OFFSET 0x61 6945a2cc190SJeff Kirsher #define QUERY_DEV_CAP_RSVD_MCG_OFFSET 0x62 6955a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MAX_MCG_OFFSET 0x63 6965a2cc190SJeff Kirsher #define QUERY_DEV_CAP_RSVD_PD_OFFSET 0x64 6975a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MAX_PD_OFFSET 0x65 698f470f8d4SLinus Torvalds #define QUERY_DEV_CAP_RSVD_XRC_OFFSET 0x66 699f470f8d4SLinus Torvalds #define QUERY_DEV_CAP_MAX_XRC_OFFSET 0x67 7005a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MAX_COUNTERS_OFFSET 0x68 7010b131561SMatan Barak #define QUERY_DEV_CAP_PORT_FLOWSTATS_COUNTERS_OFFSET 0x70 7023f7fb021SRony Efraim #define QUERY_DEV_CAP_EXT_2_FLAGS_OFFSET 0x70 7034de65803SMatan Barak #define QUERY_DEV_CAP_FLOW_STEERING_IPOIB_OFFSET 0x74 7040ff1fb65SHadar Hen Zion #define QUERY_DEV_CAP_FLOW_STEERING_RANGE_EN_OFFSET 0x76 7050ff1fb65SHadar Hen Zion #define QUERY_DEV_CAP_FLOW_STEERING_MAX_QP_OFFSET 0x77 70677507aa2SIdo Shamay #define QUERY_DEV_CAP_CQ_EQ_CACHE_LINE_STRIDE 0x7a 707d237baa1SShani Michaeli #define QUERY_DEV_CAP_ECN_QCN_VER_OFFSET 0x7b 7085a2cc190SJeff Kirsher #define QUERY_DEV_CAP_RDMARC_ENTRY_SZ_OFFSET 0x80 7095a2cc190SJeff Kirsher #define QUERY_DEV_CAP_QPC_ENTRY_SZ_OFFSET 0x82 7105a2cc190SJeff Kirsher #define QUERY_DEV_CAP_AUX_ENTRY_SZ_OFFSET 0x84 7115a2cc190SJeff Kirsher #define QUERY_DEV_CAP_ALTC_ENTRY_SZ_OFFSET 0x86 7125a2cc190SJeff Kirsher #define QUERY_DEV_CAP_EQC_ENTRY_SZ_OFFSET 0x88 7135a2cc190SJeff Kirsher #define QUERY_DEV_CAP_CQC_ENTRY_SZ_OFFSET 0x8a 7145a2cc190SJeff Kirsher #define QUERY_DEV_CAP_SRQ_ENTRY_SZ_OFFSET 0x8c 7155a2cc190SJeff Kirsher #define QUERY_DEV_CAP_C_MPT_ENTRY_SZ_OFFSET 0x8e 7165a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MTT_ENTRY_SZ_OFFSET 0x90 7175a2cc190SJeff Kirsher #define QUERY_DEV_CAP_D_MPT_ENTRY_SZ_OFFSET 0x92 7185a2cc190SJeff Kirsher #define QUERY_DEV_CAP_BMME_FLAGS_OFFSET 0x94 719d475c95bSMatan Barak #define QUERY_DEV_CAP_CONFIG_DEV_OFFSET 0x94 72077fc29c4SHadar Hen Zion #define QUERY_DEV_CAP_PHV_EN_OFFSET 0x96 7215a2cc190SJeff Kirsher #define QUERY_DEV_CAP_RSVD_LKEY_OFFSET 0x98 7225a2cc190SJeff Kirsher #define QUERY_DEV_CAP_MAX_ICM_SZ_OFFSET 0xa0 723a53e3e8cSSaeed Mahameed #define QUERY_DEV_CAP_ETH_BACKPL_OFFSET 0x9c 724*c7c122edSMark Bloch #define QUERY_DEV_CAP_DIAG_RPRT_PER_PORT 0x9c 725955154faSMatan Barak #define QUERY_DEV_CAP_FW_REASSIGN_MAC 0x9d 7267ffdf726SOr Gerlitz #define QUERY_DEV_CAP_VXLAN 0x9e 727114840c3SJack Morgenstein #define QUERY_DEV_CAP_MAD_DEMUX_OFFSET 0xb0 7287d077cd3SMatan Barak #define QUERY_DEV_CAP_DMFS_HIGH_RATE_QPN_BASE_OFFSET 0xa8 7297d077cd3SMatan Barak #define QUERY_DEV_CAP_DMFS_HIGH_RATE_QPN_RANGE_OFFSET 0xac 730fc31e256SOr Gerlitz #define QUERY_DEV_CAP_QP_RATE_LIMIT_NUM_OFFSET 0xcc 731fc31e256SOr Gerlitz #define QUERY_DEV_CAP_QP_RATE_LIMIT_MAX_OFFSET 0xd0 732fc31e256SOr Gerlitz #define QUERY_DEV_CAP_QP_RATE_LIMIT_MIN_OFFSET 0xd2 733fc31e256SOr Gerlitz 7345a2cc190SJeff Kirsher 735b3416f44SShlomo Pongratz dev_cap->flags2 = 0; 7365a2cc190SJeff Kirsher mailbox = mlx4_alloc_cmd_mailbox(dev); 7375a2cc190SJeff Kirsher if (IS_ERR(mailbox)) 7385a2cc190SJeff Kirsher return PTR_ERR(mailbox); 7395a2cc190SJeff Kirsher outbox = mailbox->buf; 7405a2cc190SJeff Kirsher 7415a2cc190SJeff Kirsher err = mlx4_cmd_box(dev, 0, mailbox->dma, 0, 0, MLX4_CMD_QUERY_DEV_CAP, 742401453a3SJack Morgenstein MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE); 7435a2cc190SJeff Kirsher if (err) 7445a2cc190SJeff Kirsher goto out; 7455a2cc190SJeff Kirsher 746d8ae9141SMoni Shoua if (mlx4_is_mfunc(dev)) 747d8ae9141SMoni Shoua disable_unsupported_roce_caps(outbox); 7485a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_QP_OFFSET); 7495a2cc190SJeff Kirsher dev_cap->reserved_qps = 1 << (field & 0xf); 7505a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_QP_OFFSET); 7515a2cc190SJeff Kirsher dev_cap->max_qps = 1 << (field & 0x1f); 7525a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_SRQ_OFFSET); 7535a2cc190SJeff Kirsher dev_cap->reserved_srqs = 1 << (field >> 4); 7545a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_SRQ_OFFSET); 7555a2cc190SJeff Kirsher dev_cap->max_srqs = 1 << (field & 0x1f); 7565a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_CQ_SZ_OFFSET); 7575a2cc190SJeff Kirsher dev_cap->max_cq_sz = 1 << field; 7585a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_CQ_OFFSET); 7595a2cc190SJeff Kirsher dev_cap->reserved_cqs = 1 << (field & 0xf); 7605a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_CQ_OFFSET); 7615a2cc190SJeff Kirsher dev_cap->max_cqs = 1 << (field & 0x1f); 7625a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_MPT_OFFSET); 7635a2cc190SJeff Kirsher dev_cap->max_mpts = 1 << (field & 0x3f); 7645a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_EQ_OFFSET); 7657c68dd43SMatan Barak dev_cap->reserved_eqs = 1 << (field & 0xf); 7665a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_EQ_OFFSET); 7675a2cc190SJeff Kirsher dev_cap->max_eqs = 1 << (field & 0xf); 7685a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_MTT_OFFSET); 7695a2cc190SJeff Kirsher dev_cap->reserved_mtts = 1 << (field >> 4); 7705a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_MRW_SZ_OFFSET); 7715a2cc190SJeff Kirsher dev_cap->max_mrw_sz = 1 << field; 7725a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_MRW_OFFSET); 7735a2cc190SJeff Kirsher dev_cap->reserved_mrws = 1 << (field & 0xf); 7745a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_MTT_SEG_OFFSET); 7755a2cc190SJeff Kirsher dev_cap->max_mtt_seg = 1 << (field & 0x3f); 7767ae0e400SMatan Barak MLX4_GET(size, outbox, QUERY_DEV_CAP_NUM_SYS_EQ_OFFSET); 7777ae0e400SMatan Barak dev_cap->num_sys_eqs = size & 0xfff; 7785a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_REQ_QP_OFFSET); 7795a2cc190SJeff Kirsher dev_cap->max_requester_per_qp = 1 << (field & 0x3f); 7805a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_RES_QP_OFFSET); 7815a2cc190SJeff Kirsher dev_cap->max_responder_per_qp = 1 << (field & 0x3f); 7825a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_GSO_OFFSET); 7835a2cc190SJeff Kirsher field &= 0x1f; 7845a2cc190SJeff Kirsher if (!field) 7855a2cc190SJeff Kirsher dev_cap->max_gso_sz = 0; 7865a2cc190SJeff Kirsher else 7875a2cc190SJeff Kirsher dev_cap->max_gso_sz = 1 << field; 7885a2cc190SJeff Kirsher 789b3416f44SShlomo Pongratz MLX4_GET(field, outbox, QUERY_DEV_CAP_RSS_OFFSET); 790b3416f44SShlomo Pongratz if (field & 0x20) 791b3416f44SShlomo Pongratz dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_RSS_XOR; 792b3416f44SShlomo Pongratz if (field & 0x10) 793b3416f44SShlomo Pongratz dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_RSS_TOP; 794b3416f44SShlomo Pongratz field &= 0xf; 795b3416f44SShlomo Pongratz if (field) { 796b3416f44SShlomo Pongratz dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_RSS; 797b3416f44SShlomo Pongratz dev_cap->max_rss_tbl_sz = 1 << field; 798b3416f44SShlomo Pongratz } else 799b3416f44SShlomo Pongratz dev_cap->max_rss_tbl_sz = 0; 8005a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_RDMA_OFFSET); 8015a2cc190SJeff Kirsher dev_cap->max_rdma_global = 1 << (field & 0x3f); 8025a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_ACK_DELAY_OFFSET); 8035a2cc190SJeff Kirsher dev_cap->local_ca_ack_delay = field & 0x1f; 8045a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_VL_PORT_OFFSET); 8055a2cc190SJeff Kirsher dev_cap->num_ports = field & 0xf; 8065a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_MSG_SZ_OFFSET); 807fab9adfbSEran Ben Elisha dev_cap->max_msg_sz = 1 << (field & 0x1f); 8080b131561SMatan Barak MLX4_GET(field, outbox, QUERY_DEV_CAP_PORT_FLOWSTATS_COUNTERS_OFFSET); 8090b131561SMatan Barak if (field & 0x10) 8100b131561SMatan Barak dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_FLOWSTATS_EN; 8110ff1fb65SHadar Hen Zion MLX4_GET(field, outbox, QUERY_DEV_CAP_FLOW_STEERING_RANGE_EN_OFFSET); 8120ff1fb65SHadar Hen Zion if (field & 0x80) 8130ff1fb65SHadar Hen Zion dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_FS_EN; 8140ff1fb65SHadar Hen Zion dev_cap->fs_log_max_ucast_qp_range_size = field & 0x1f; 8150e451e88SMarina Varshaver if (field & 0x20) 8160e451e88SMarina Varshaver dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_DMFS_UC_MC_SNIFFER; 81751af33cfSIdo Shamay MLX4_GET(field, outbox, QUERY_DEV_CAP_PORT_BEACON_OFFSET); 81851af33cfSIdo Shamay if (field & 0x80) 81951af33cfSIdo Shamay dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_PORT_BEACON; 8204de65803SMatan Barak MLX4_GET(field, outbox, QUERY_DEV_CAP_FLOW_STEERING_IPOIB_OFFSET); 8214de65803SMatan Barak if (field & 0x80) 8224de65803SMatan Barak dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_DMFS_IPOIB; 8230ff1fb65SHadar Hen Zion MLX4_GET(field, outbox, QUERY_DEV_CAP_FLOW_STEERING_MAX_QP_OFFSET); 8240ff1fb65SHadar Hen Zion dev_cap->fs_max_num_qp_per_entry = field; 825d237baa1SShani Michaeli MLX4_GET(field, outbox, QUERY_DEV_CAP_ECN_QCN_VER_OFFSET); 826d237baa1SShani Michaeli if (field & 0x1) 827d237baa1SShani Michaeli dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_QCN; 8285a2cc190SJeff Kirsher MLX4_GET(stat_rate, outbox, QUERY_DEV_CAP_RATE_SUPPORT_OFFSET); 8295a2cc190SJeff Kirsher dev_cap->stat_rate_support = stat_rate; 830d998735fSEugenia Emantayev MLX4_GET(field, outbox, QUERY_DEV_CAP_CQ_TS_SUPPORT_OFFSET); 831d998735fSEugenia Emantayev if (field & 0x80) 832d998735fSEugenia Emantayev dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_TS; 8335a2cc190SJeff Kirsher MLX4_GET(ext_flags, outbox, QUERY_DEV_CAP_EXT_FLAGS_OFFSET); 8345a2cc190SJeff Kirsher MLX4_GET(flags, outbox, QUERY_DEV_CAP_FLAGS_OFFSET); 8355a2cc190SJeff Kirsher dev_cap->flags = flags | (u64)ext_flags << 32; 8365a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_UAR_OFFSET); 8375a2cc190SJeff Kirsher dev_cap->reserved_uars = field >> 4; 8385a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_UAR_SZ_OFFSET); 8395a2cc190SJeff Kirsher dev_cap->uar_size = 1 << ((field & 0x3f) + 20); 8405a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_PAGE_SZ_OFFSET); 8415a2cc190SJeff Kirsher dev_cap->min_page_sz = 1 << field; 8425a2cc190SJeff Kirsher 8435a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_BF_OFFSET); 8445a2cc190SJeff Kirsher if (field & 0x80) { 8455a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_LOG_BF_REG_SZ_OFFSET); 8465a2cc190SJeff Kirsher dev_cap->bf_reg_size = 1 << (field & 0x1f); 8475a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_LOG_MAX_BF_REGS_PER_PAGE_OFFSET); 8485a2cc190SJeff Kirsher if ((1 << (field & 0x3f)) > (PAGE_SIZE / dev_cap->bf_reg_size)) 8495a2cc190SJeff Kirsher field = 3; 8505a2cc190SJeff Kirsher dev_cap->bf_regs_per_page = 1 << (field & 0x3f); 8515a2cc190SJeff Kirsher } else { 8525a2cc190SJeff Kirsher dev_cap->bf_reg_size = 0; 8535a2cc190SJeff Kirsher } 8545a2cc190SJeff Kirsher 8555a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_SG_SQ_OFFSET); 8565a2cc190SJeff Kirsher dev_cap->max_sq_sg = field; 8575a2cc190SJeff Kirsher MLX4_GET(size, outbox, QUERY_DEV_CAP_MAX_DESC_SZ_SQ_OFFSET); 8585a2cc190SJeff Kirsher dev_cap->max_sq_desc_sz = size; 8595a2cc190SJeff Kirsher 8605a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_QP_MCG_OFFSET); 8615a2cc190SJeff Kirsher dev_cap->max_qp_per_mcg = 1 << field; 8625a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_MCG_OFFSET); 8635a2cc190SJeff Kirsher dev_cap->reserved_mgms = field & 0xf; 8645a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_MCG_OFFSET); 8655a2cc190SJeff Kirsher dev_cap->max_mcgs = 1 << field; 8665a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_PD_OFFSET); 8675a2cc190SJeff Kirsher dev_cap->reserved_pds = field >> 4; 8685a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_PD_OFFSET); 8695a2cc190SJeff Kirsher dev_cap->max_pds = 1 << (field & 0x3f); 870f470f8d4SLinus Torvalds MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_XRC_OFFSET); 871f470f8d4SLinus Torvalds dev_cap->reserved_xrcds = field >> 4; 872426dd00dSDotan Barak MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_XRC_OFFSET); 873f470f8d4SLinus Torvalds dev_cap->max_xrcds = 1 << (field & 0x1f); 8745a2cc190SJeff Kirsher 8755a2cc190SJeff Kirsher MLX4_GET(size, outbox, QUERY_DEV_CAP_RDMARC_ENTRY_SZ_OFFSET); 8765a2cc190SJeff Kirsher dev_cap->rdmarc_entry_sz = size; 8775a2cc190SJeff Kirsher MLX4_GET(size, outbox, QUERY_DEV_CAP_QPC_ENTRY_SZ_OFFSET); 8785a2cc190SJeff Kirsher dev_cap->qpc_entry_sz = size; 8795a2cc190SJeff Kirsher MLX4_GET(size, outbox, QUERY_DEV_CAP_AUX_ENTRY_SZ_OFFSET); 8805a2cc190SJeff Kirsher dev_cap->aux_entry_sz = size; 8815a2cc190SJeff Kirsher MLX4_GET(size, outbox, QUERY_DEV_CAP_ALTC_ENTRY_SZ_OFFSET); 8825a2cc190SJeff Kirsher dev_cap->altc_entry_sz = size; 8835a2cc190SJeff Kirsher MLX4_GET(size, outbox, QUERY_DEV_CAP_EQC_ENTRY_SZ_OFFSET); 8845a2cc190SJeff Kirsher dev_cap->eqc_entry_sz = size; 8855a2cc190SJeff Kirsher MLX4_GET(size, outbox, QUERY_DEV_CAP_CQC_ENTRY_SZ_OFFSET); 8865a2cc190SJeff Kirsher dev_cap->cqc_entry_sz = size; 8875a2cc190SJeff Kirsher MLX4_GET(size, outbox, QUERY_DEV_CAP_SRQ_ENTRY_SZ_OFFSET); 8885a2cc190SJeff Kirsher dev_cap->srq_entry_sz = size; 8895a2cc190SJeff Kirsher MLX4_GET(size, outbox, QUERY_DEV_CAP_C_MPT_ENTRY_SZ_OFFSET); 8905a2cc190SJeff Kirsher dev_cap->cmpt_entry_sz = size; 8915a2cc190SJeff Kirsher MLX4_GET(size, outbox, QUERY_DEV_CAP_MTT_ENTRY_SZ_OFFSET); 8925a2cc190SJeff Kirsher dev_cap->mtt_entry_sz = size; 8935a2cc190SJeff Kirsher MLX4_GET(size, outbox, QUERY_DEV_CAP_D_MPT_ENTRY_SZ_OFFSET); 8945a2cc190SJeff Kirsher dev_cap->dmpt_entry_sz = size; 8955a2cc190SJeff Kirsher 8965a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_SRQ_SZ_OFFSET); 8975a2cc190SJeff Kirsher dev_cap->max_srq_sz = 1 << field; 8985a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_QP_SZ_OFFSET); 8995a2cc190SJeff Kirsher dev_cap->max_qp_sz = 1 << field; 9005a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_RSZ_SRQ_OFFSET); 9015a2cc190SJeff Kirsher dev_cap->resize_srq = field & 1; 9025a2cc190SJeff Kirsher MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_SG_RQ_OFFSET); 9035a2cc190SJeff Kirsher dev_cap->max_rq_sg = field; 9045a2cc190SJeff Kirsher MLX4_GET(size, outbox, QUERY_DEV_CAP_MAX_DESC_SZ_RQ_OFFSET); 9055a2cc190SJeff Kirsher dev_cap->max_rq_desc_sz = size; 90677507aa2SIdo Shamay MLX4_GET(field, outbox, QUERY_DEV_CAP_CQ_EQ_CACHE_LINE_STRIDE); 907d019fcb2SIdo Shamay if (field & (1 << 4)) 908d019fcb2SIdo Shamay dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_QOS_VPP; 909adbc7ac5SSaeed Mahameed if (field & (1 << 5)) 910adbc7ac5SSaeed Mahameed dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_ETH_PROT_CTRL; 91177507aa2SIdo Shamay if (field & (1 << 6)) 91277507aa2SIdo Shamay dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_CQE_STRIDE; 91377507aa2SIdo Shamay if (field & (1 << 7)) 91477507aa2SIdo Shamay dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_EQE_STRIDE; 9155a2cc190SJeff Kirsher MLX4_GET(dev_cap->bmme_flags, outbox, 9165a2cc190SJeff Kirsher QUERY_DEV_CAP_BMME_FLAGS_OFFSET); 917d8ae9141SMoni Shoua if (dev_cap->bmme_flags & MLX4_FLAG_ROCE_V1_V2) 918d8ae9141SMoni Shoua dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_ROCE_V1_V2; 91959e14e32SMoni Shoua if (dev_cap->bmme_flags & MLX4_FLAG_PORT_REMAP) 92059e14e32SMoni Shoua dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_PORT_REMAP; 921d475c95bSMatan Barak MLX4_GET(field, outbox, QUERY_DEV_CAP_CONFIG_DEV_OFFSET); 922d475c95bSMatan Barak if (field & 0x20) 923d475c95bSMatan Barak dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_CONFIG_DEV; 92478500b8cSMuhammad Mahajna if (field & (1 << 2)) 92578500b8cSMuhammad Mahajna dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_IGNORE_FCS; 92677fc29c4SHadar Hen Zion MLX4_GET(field, outbox, QUERY_DEV_CAP_PHV_EN_OFFSET); 92777fc29c4SHadar Hen Zion if (field & 0x80) 92877fc29c4SHadar Hen Zion dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_PHV_EN; 92977fc29c4SHadar Hen Zion if (field & 0x40) 93077fc29c4SHadar Hen Zion dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_SKIP_OUTER_VLAN; 93177fc29c4SHadar Hen Zion 9325a2cc190SJeff Kirsher MLX4_GET(dev_cap->reserved_lkey, outbox, 9335a2cc190SJeff Kirsher QUERY_DEV_CAP_RSVD_LKEY_OFFSET); 934a53e3e8cSSaeed Mahameed MLX4_GET(field32, outbox, QUERY_DEV_CAP_ETH_BACKPL_OFFSET); 935a53e3e8cSSaeed Mahameed if (field32 & (1 << 0)) 936a53e3e8cSSaeed Mahameed dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_ETH_BACKPL_AN_REP; 937be6a6b43SJack Morgenstein if (field32 & (1 << 7)) 938be6a6b43SJack Morgenstein dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_RECOVERABLE_ERROR_EVENT; 939*c7c122edSMark Bloch MLX4_GET(field32, outbox, QUERY_DEV_CAP_DIAG_RPRT_PER_PORT); 940*c7c122edSMark Bloch if (field32 & (1 << 17)) 941*c7c122edSMark Bloch dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_DIAG_PER_PORT; 942955154faSMatan Barak MLX4_GET(field, outbox, QUERY_DEV_CAP_FW_REASSIGN_MAC); 943955154faSMatan Barak if (field & 1<<6) 9445930e8d0SOr Gerlitz dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_REASSIGN_MAC_EN; 9457ffdf726SOr Gerlitz MLX4_GET(field, outbox, QUERY_DEV_CAP_VXLAN); 9467ffdf726SOr Gerlitz if (field & 1<<3) 9477ffdf726SOr Gerlitz dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_VXLAN_OFFLOADS; 9483742cc65SIdo Shamay if (field & (1 << 5)) 9493742cc65SIdo Shamay dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_ETS_CFG; 9505a2cc190SJeff Kirsher MLX4_GET(dev_cap->max_icm_sz, outbox, 9515a2cc190SJeff Kirsher QUERY_DEV_CAP_MAX_ICM_SZ_OFFSET); 9525a2cc190SJeff Kirsher if (dev_cap->flags & MLX4_DEV_CAP_FLAG_COUNTERS) 9535a2cc190SJeff Kirsher MLX4_GET(dev_cap->max_counters, outbox, 9545a2cc190SJeff Kirsher QUERY_DEV_CAP_MAX_COUNTERS_OFFSET); 9555a2cc190SJeff Kirsher 956114840c3SJack Morgenstein MLX4_GET(field32, outbox, 957114840c3SJack Morgenstein QUERY_DEV_CAP_MAD_DEMUX_OFFSET); 958114840c3SJack Morgenstein if (field32 & (1 << 0)) 959114840c3SJack Morgenstein dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_MAD_DEMUX; 960114840c3SJack Morgenstein 9617d077cd3SMatan Barak MLX4_GET(dev_cap->dmfs_high_rate_qpn_base, outbox, 9627d077cd3SMatan Barak QUERY_DEV_CAP_DMFS_HIGH_RATE_QPN_BASE_OFFSET); 9637d077cd3SMatan Barak dev_cap->dmfs_high_rate_qpn_base &= MGM_QPN_MASK; 9647d077cd3SMatan Barak MLX4_GET(dev_cap->dmfs_high_rate_qpn_range, outbox, 9657d077cd3SMatan Barak QUERY_DEV_CAP_DMFS_HIGH_RATE_QPN_RANGE_OFFSET); 9667d077cd3SMatan Barak dev_cap->dmfs_high_rate_qpn_range &= MGM_QPN_MASK; 9677d077cd3SMatan Barak 968fc31e256SOr Gerlitz MLX4_GET(size, outbox, QUERY_DEV_CAP_QP_RATE_LIMIT_NUM_OFFSET); 969fc31e256SOr Gerlitz dev_cap->rl_caps.num_rates = size; 970fc31e256SOr Gerlitz if (dev_cap->rl_caps.num_rates) { 971fc31e256SOr Gerlitz dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_QP_RATE_LIMIT; 972fc31e256SOr Gerlitz MLX4_GET(size, outbox, QUERY_DEV_CAP_QP_RATE_LIMIT_MAX_OFFSET); 973fc31e256SOr Gerlitz dev_cap->rl_caps.max_val = size & 0xfff; 974fc31e256SOr Gerlitz dev_cap->rl_caps.max_unit = size >> 14; 975fc31e256SOr Gerlitz MLX4_GET(size, outbox, QUERY_DEV_CAP_QP_RATE_LIMIT_MIN_OFFSET); 976fc31e256SOr Gerlitz dev_cap->rl_caps.min_val = size & 0xfff; 977fc31e256SOr Gerlitz dev_cap->rl_caps.min_unit = size >> 14; 978fc31e256SOr Gerlitz } 979fc31e256SOr Gerlitz 9803f7fb021SRony Efraim MLX4_GET(field32, outbox, QUERY_DEV_CAP_EXT_2_FLAGS_OFFSET); 981b01978caSJack Morgenstein if (field32 & (1 << 16)) 982b01978caSJack Morgenstein dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_UPDATE_QP; 9839a892835SMaor Gottlieb if (field32 & (1 << 18)) 9849a892835SMaor Gottlieb dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_UPDATE_QP_SRC_CHECK_LB; 9859a892835SMaor Gottlieb if (field32 & (1 << 19)) 9869a892835SMaor Gottlieb dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_LB_SRC_CHK; 9873f7fb021SRony Efraim if (field32 & (1 << 26)) 9883f7fb021SRony Efraim dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_VLAN_CONTROL; 989e6b6a231SRony Efraim if (field32 & (1 << 20)) 990e6b6a231SRony Efraim dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_FSM; 991de966c59SMatan Barak if (field32 & (1 << 21)) 992de966c59SMatan Barak dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_80_VFS; 9933f7fb021SRony Efraim 994431df8c7SMatan Barak for (i = 1; i <= dev_cap->num_ports; i++) { 995431df8c7SMatan Barak err = mlx4_QUERY_PORT(dev, i, dev_cap->port_cap + i); 9965a2cc190SJeff Kirsher if (err) 9975a2cc190SJeff Kirsher goto out; 9985a2cc190SJeff Kirsher } 9995a2cc190SJeff Kirsher 10005a2cc190SJeff Kirsher /* 10015a2cc190SJeff Kirsher * Each UAR has 4 EQ doorbells; so if a UAR is reserved, then 10025a2cc190SJeff Kirsher * we can't use any EQs whose doorbell falls on that page, 10035a2cc190SJeff Kirsher * even if the EQ itself isn't reserved. 10045a2cc190SJeff Kirsher */ 10057ae0e400SMatan Barak if (dev_cap->num_sys_eqs == 0) 10065a2cc190SJeff Kirsher dev_cap->reserved_eqs = max(dev_cap->reserved_uars * 4, 10075a2cc190SJeff Kirsher dev_cap->reserved_eqs); 10087ae0e400SMatan Barak else 10097ae0e400SMatan Barak dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_SYS_EQS; 10105a2cc190SJeff Kirsher 1011c78e25edSOr Gerlitz out: 1012c78e25edSOr Gerlitz mlx4_free_cmd_mailbox(dev, mailbox); 1013c78e25edSOr Gerlitz return err; 1014c78e25edSOr Gerlitz } 1015c78e25edSOr Gerlitz 1016c78e25edSOr Gerlitz void mlx4_dev_cap_dump(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap) 1017c78e25edSOr Gerlitz { 1018c78e25edSOr Gerlitz if (dev_cap->bf_reg_size > 0) 1019c78e25edSOr Gerlitz mlx4_dbg(dev, "BlueFlame available (reg size %d, regs/page %d)\n", 1020c78e25edSOr Gerlitz dev_cap->bf_reg_size, dev_cap->bf_regs_per_page); 1021c78e25edSOr Gerlitz else 1022c78e25edSOr Gerlitz mlx4_dbg(dev, "BlueFlame not available\n"); 1023c78e25edSOr Gerlitz 1024c78e25edSOr Gerlitz mlx4_dbg(dev, "Base MM extensions: flags %08x, rsvd L_Key %08x\n", 1025c78e25edSOr Gerlitz dev_cap->bmme_flags, dev_cap->reserved_lkey); 10265a2cc190SJeff Kirsher mlx4_dbg(dev, "Max ICM size %lld MB\n", 10275a2cc190SJeff Kirsher (unsigned long long) dev_cap->max_icm_sz >> 20); 10285a2cc190SJeff Kirsher mlx4_dbg(dev, "Max QPs: %d, reserved QPs: %d, entry size: %d\n", 10295a2cc190SJeff Kirsher dev_cap->max_qps, dev_cap->reserved_qps, dev_cap->qpc_entry_sz); 10305a2cc190SJeff Kirsher mlx4_dbg(dev, "Max SRQs: %d, reserved SRQs: %d, entry size: %d\n", 10315a2cc190SJeff Kirsher dev_cap->max_srqs, dev_cap->reserved_srqs, dev_cap->srq_entry_sz); 10325a2cc190SJeff Kirsher mlx4_dbg(dev, "Max CQs: %d, reserved CQs: %d, entry size: %d\n", 10335a2cc190SJeff Kirsher dev_cap->max_cqs, dev_cap->reserved_cqs, dev_cap->cqc_entry_sz); 10347ae0e400SMatan Barak mlx4_dbg(dev, "Num sys EQs: %d, max EQs: %d, reserved EQs: %d, entry size: %d\n", 10357ae0e400SMatan Barak dev_cap->num_sys_eqs, dev_cap->max_eqs, dev_cap->reserved_eqs, 10367ae0e400SMatan Barak dev_cap->eqc_entry_sz); 10375a2cc190SJeff Kirsher mlx4_dbg(dev, "reserved MPTs: %d, reserved MTTs: %d\n", 10385a2cc190SJeff Kirsher dev_cap->reserved_mrws, dev_cap->reserved_mtts); 10395a2cc190SJeff Kirsher mlx4_dbg(dev, "Max PDs: %d, reserved PDs: %d, reserved UARs: %d\n", 10405a2cc190SJeff Kirsher dev_cap->max_pds, dev_cap->reserved_pds, dev_cap->reserved_uars); 10415a2cc190SJeff Kirsher mlx4_dbg(dev, "Max QP/MCG: %d, reserved MGMs: %d\n", 10425a2cc190SJeff Kirsher dev_cap->max_pds, dev_cap->reserved_mgms); 10435a2cc190SJeff Kirsher mlx4_dbg(dev, "Max CQEs: %d, max WQEs: %d, max SRQ WQEs: %d\n", 10445a2cc190SJeff Kirsher dev_cap->max_cq_sz, dev_cap->max_qp_sz, dev_cap->max_srq_sz); 10455a2cc190SJeff Kirsher mlx4_dbg(dev, "Local CA ACK delay: %d, max MTU: %d, port width cap: %d\n", 1046431df8c7SMatan Barak dev_cap->local_ca_ack_delay, 128 << dev_cap->port_cap[1].ib_mtu, 1047431df8c7SMatan Barak dev_cap->port_cap[1].max_port_width); 10485a2cc190SJeff Kirsher mlx4_dbg(dev, "Max SQ desc size: %d, max SQ S/G: %d\n", 10495a2cc190SJeff Kirsher dev_cap->max_sq_desc_sz, dev_cap->max_sq_sg); 10505a2cc190SJeff Kirsher mlx4_dbg(dev, "Max RQ desc size: %d, max RQ S/G: %d\n", 10515a2cc190SJeff Kirsher dev_cap->max_rq_desc_sz, dev_cap->max_rq_sg); 10525a2cc190SJeff Kirsher mlx4_dbg(dev, "Max GSO size: %d\n", dev_cap->max_gso_sz); 10535a2cc190SJeff Kirsher mlx4_dbg(dev, "Max counters: %d\n", dev_cap->max_counters); 1054b3416f44SShlomo Pongratz mlx4_dbg(dev, "Max RSS Table size: %d\n", dev_cap->max_rss_tbl_sz); 10557d077cd3SMatan Barak mlx4_dbg(dev, "DMFS high rate steer QPn base: %d\n", 10567d077cd3SMatan Barak dev_cap->dmfs_high_rate_qpn_base); 10577d077cd3SMatan Barak mlx4_dbg(dev, "DMFS high rate steer QPn range: %d\n", 10587d077cd3SMatan Barak dev_cap->dmfs_high_rate_qpn_range); 1059fc31e256SOr Gerlitz 1060fc31e256SOr Gerlitz if (dev_cap->flags2 & MLX4_DEV_CAP_FLAG2_QP_RATE_LIMIT) { 1061fc31e256SOr Gerlitz struct mlx4_rate_limit_caps *rl_caps = &dev_cap->rl_caps; 1062fc31e256SOr Gerlitz 1063fc31e256SOr Gerlitz mlx4_dbg(dev, "QP Rate-Limit: #rates %d, unit/val max %d/%d, min %d/%d\n", 1064fc31e256SOr Gerlitz rl_caps->num_rates, rl_caps->max_unit, rl_caps->max_val, 1065fc31e256SOr Gerlitz rl_caps->min_unit, rl_caps->min_val); 1066fc31e256SOr Gerlitz } 1067fc31e256SOr Gerlitz 10685a2cc190SJeff Kirsher dump_dev_cap_flags(dev, dev_cap->flags); 1069b3416f44SShlomo Pongratz dump_dev_cap_flags2(dev, dev_cap->flags2); 10705a2cc190SJeff Kirsher } 10715a2cc190SJeff Kirsher 1072431df8c7SMatan Barak int mlx4_QUERY_PORT(struct mlx4_dev *dev, int port, struct mlx4_port_cap *port_cap) 1073431df8c7SMatan Barak { 1074431df8c7SMatan Barak struct mlx4_cmd_mailbox *mailbox; 1075431df8c7SMatan Barak u32 *outbox; 1076431df8c7SMatan Barak u8 field; 1077431df8c7SMatan Barak u32 field32; 1078431df8c7SMatan Barak int err; 1079431df8c7SMatan Barak 1080431df8c7SMatan Barak mailbox = mlx4_alloc_cmd_mailbox(dev); 1081431df8c7SMatan Barak if (IS_ERR(mailbox)) 1082431df8c7SMatan Barak return PTR_ERR(mailbox); 1083431df8c7SMatan Barak outbox = mailbox->buf; 1084431df8c7SMatan Barak 1085431df8c7SMatan Barak if (dev->flags & MLX4_FLAG_OLD_PORT_CMDS) { 1086431df8c7SMatan Barak err = mlx4_cmd_box(dev, 0, mailbox->dma, 0, 0, MLX4_CMD_QUERY_DEV_CAP, 1087431df8c7SMatan Barak MLX4_CMD_TIME_CLASS_A, 1088431df8c7SMatan Barak MLX4_CMD_NATIVE); 1089431df8c7SMatan Barak 1090431df8c7SMatan Barak if (err) 1091431df8c7SMatan Barak goto out; 1092431df8c7SMatan Barak 1093431df8c7SMatan Barak MLX4_GET(field, outbox, QUERY_DEV_CAP_VL_PORT_OFFSET); 1094431df8c7SMatan Barak port_cap->max_vl = field >> 4; 1095431df8c7SMatan Barak MLX4_GET(field, outbox, QUERY_DEV_CAP_MTU_WIDTH_OFFSET); 1096431df8c7SMatan Barak port_cap->ib_mtu = field >> 4; 1097431df8c7SMatan Barak port_cap->max_port_width = field & 0xf; 1098431df8c7SMatan Barak MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_GID_OFFSET); 1099431df8c7SMatan Barak port_cap->max_gids = 1 << (field & 0xf); 1100431df8c7SMatan Barak MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_PKEY_OFFSET); 1101431df8c7SMatan Barak port_cap->max_pkeys = 1 << (field & 0xf); 1102431df8c7SMatan Barak } else { 1103431df8c7SMatan Barak #define QUERY_PORT_SUPPORTED_TYPE_OFFSET 0x00 1104431df8c7SMatan Barak #define QUERY_PORT_MTU_OFFSET 0x01 1105431df8c7SMatan Barak #define QUERY_PORT_ETH_MTU_OFFSET 0x02 1106431df8c7SMatan Barak #define QUERY_PORT_WIDTH_OFFSET 0x06 1107431df8c7SMatan Barak #define QUERY_PORT_MAX_GID_PKEY_OFFSET 0x07 1108431df8c7SMatan Barak #define QUERY_PORT_MAX_MACVLAN_OFFSET 0x0a 1109431df8c7SMatan Barak #define QUERY_PORT_MAX_VL_OFFSET 0x0b 1110431df8c7SMatan Barak #define QUERY_PORT_MAC_OFFSET 0x10 1111431df8c7SMatan Barak #define QUERY_PORT_TRANS_VENDOR_OFFSET 0x18 1112431df8c7SMatan Barak #define QUERY_PORT_WAVELENGTH_OFFSET 0x1c 1113431df8c7SMatan Barak #define QUERY_PORT_TRANS_CODE_OFFSET 0x20 1114431df8c7SMatan Barak 1115431df8c7SMatan Barak err = mlx4_cmd_box(dev, 0, mailbox->dma, port, 0, MLX4_CMD_QUERY_PORT, 1116431df8c7SMatan Barak MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE); 1117431df8c7SMatan Barak if (err) 1118431df8c7SMatan Barak goto out; 1119431df8c7SMatan Barak 1120431df8c7SMatan Barak MLX4_GET(field, outbox, QUERY_PORT_SUPPORTED_TYPE_OFFSET); 1121e34305c8SOr Gerlitz port_cap->link_state = (field & 0x80) >> 7; 1122431df8c7SMatan Barak port_cap->supported_port_types = field & 3; 1123431df8c7SMatan Barak port_cap->suggested_type = (field >> 3) & 1; 1124431df8c7SMatan Barak port_cap->default_sense = (field >> 4) & 1; 11257d077cd3SMatan Barak port_cap->dmfs_optimized_state = (field >> 5) & 1; 1126431df8c7SMatan Barak MLX4_GET(field, outbox, QUERY_PORT_MTU_OFFSET); 1127431df8c7SMatan Barak port_cap->ib_mtu = field & 0xf; 1128431df8c7SMatan Barak MLX4_GET(field, outbox, QUERY_PORT_WIDTH_OFFSET); 1129431df8c7SMatan Barak port_cap->max_port_width = field & 0xf; 1130431df8c7SMatan Barak MLX4_GET(field, outbox, QUERY_PORT_MAX_GID_PKEY_OFFSET); 1131431df8c7SMatan Barak port_cap->max_gids = 1 << (field >> 4); 1132431df8c7SMatan Barak port_cap->max_pkeys = 1 << (field & 0xf); 1133431df8c7SMatan Barak MLX4_GET(field, outbox, QUERY_PORT_MAX_VL_OFFSET); 1134431df8c7SMatan Barak port_cap->max_vl = field & 0xf; 1135431df8c7SMatan Barak MLX4_GET(field, outbox, QUERY_PORT_MAX_MACVLAN_OFFSET); 1136431df8c7SMatan Barak port_cap->log_max_macs = field & 0xf; 1137431df8c7SMatan Barak port_cap->log_max_vlans = field >> 4; 1138431df8c7SMatan Barak MLX4_GET(port_cap->eth_mtu, outbox, QUERY_PORT_ETH_MTU_OFFSET); 1139431df8c7SMatan Barak MLX4_GET(port_cap->def_mac, outbox, QUERY_PORT_MAC_OFFSET); 1140431df8c7SMatan Barak MLX4_GET(field32, outbox, QUERY_PORT_TRANS_VENDOR_OFFSET); 1141431df8c7SMatan Barak port_cap->trans_type = field32 >> 24; 1142431df8c7SMatan Barak port_cap->vendor_oui = field32 & 0xffffff; 1143431df8c7SMatan Barak MLX4_GET(port_cap->wavelength, outbox, QUERY_PORT_WAVELENGTH_OFFSET); 1144431df8c7SMatan Barak MLX4_GET(port_cap->trans_code, outbox, QUERY_PORT_TRANS_CODE_OFFSET); 1145431df8c7SMatan Barak } 1146431df8c7SMatan Barak 1147431df8c7SMatan Barak out: 1148431df8c7SMatan Barak mlx4_free_cmd_mailbox(dev, mailbox); 1149431df8c7SMatan Barak return err; 1150431df8c7SMatan Barak } 1151431df8c7SMatan Barak 11520b131561SMatan Barak #define DEV_CAP_EXT_2_FLAG_PFC_COUNTERS (1 << 28) 1153383677daSOr Gerlitz #define DEV_CAP_EXT_2_FLAG_VLAN_CONTROL (1 << 26) 1154383677daSOr Gerlitz #define DEV_CAP_EXT_2_FLAG_80_VFS (1 << 21) 1155383677daSOr Gerlitz #define DEV_CAP_EXT_2_FLAG_FSM (1 << 20) 1156383677daSOr Gerlitz 1157b91cb3ebSJack Morgenstein int mlx4_QUERY_DEV_CAP_wrapper(struct mlx4_dev *dev, int slave, 1158b91cb3ebSJack Morgenstein struct mlx4_vhcr *vhcr, 1159b91cb3ebSJack Morgenstein struct mlx4_cmd_mailbox *inbox, 1160b91cb3ebSJack Morgenstein struct mlx4_cmd_mailbox *outbox, 1161b91cb3ebSJack Morgenstein struct mlx4_cmd_info *cmd) 1162b91cb3ebSJack Morgenstein { 11632a4fae14SJack Morgenstein u64 flags; 1164b91cb3ebSJack Morgenstein int err = 0; 1165b91cb3ebSJack Morgenstein u8 field; 1166fc31e256SOr Gerlitz u16 field16; 1167383677daSOr Gerlitz u32 bmme_flags, field32; 1168449fc488SMatan Barak int real_port; 1169449fc488SMatan Barak int slave_port; 1170449fc488SMatan Barak int first_port; 1171449fc488SMatan Barak struct mlx4_active_ports actv_ports; 1172b91cb3ebSJack Morgenstein 1173b91cb3ebSJack Morgenstein err = mlx4_cmd_box(dev, 0, outbox->dma, 0, 0, MLX4_CMD_QUERY_DEV_CAP, 1174b91cb3ebSJack Morgenstein MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE); 1175b91cb3ebSJack Morgenstein if (err) 1176b91cb3ebSJack Morgenstein return err; 1177b91cb3ebSJack Morgenstein 1178d8ae9141SMoni Shoua disable_unsupported_roce_caps(outbox->buf); 1179cc1ade94SShani Michaeli /* add port mng change event capability and disable mw type 1 1180cc1ade94SShani Michaeli * unconditionally to slaves 1181cc1ade94SShani Michaeli */ 11822a4fae14SJack Morgenstein MLX4_GET(flags, outbox->buf, QUERY_DEV_CAP_EXT_FLAGS_OFFSET); 11832a4fae14SJack Morgenstein flags |= MLX4_DEV_CAP_FLAG_PORT_MNG_CHG_EV; 1184cc1ade94SShani Michaeli flags &= ~MLX4_DEV_CAP_FLAG_MEM_WINDOW; 1185449fc488SMatan Barak actv_ports = mlx4_get_active_ports(dev, slave); 1186449fc488SMatan Barak first_port = find_first_bit(actv_ports.ports, dev->caps.num_ports); 1187449fc488SMatan Barak for (slave_port = 0, real_port = first_port; 1188449fc488SMatan Barak real_port < first_port + 1189449fc488SMatan Barak bitmap_weight(actv_ports.ports, dev->caps.num_ports); 1190449fc488SMatan Barak ++real_port, ++slave_port) { 1191449fc488SMatan Barak if (flags & (MLX4_DEV_CAP_FLAG_WOL_PORT1 << real_port)) 1192449fc488SMatan Barak flags |= MLX4_DEV_CAP_FLAG_WOL_PORT1 << slave_port; 1193449fc488SMatan Barak else 1194449fc488SMatan Barak flags &= ~(MLX4_DEV_CAP_FLAG_WOL_PORT1 << slave_port); 1195449fc488SMatan Barak } 1196449fc488SMatan Barak for (; slave_port < dev->caps.num_ports; ++slave_port) 1197449fc488SMatan Barak flags &= ~(MLX4_DEV_CAP_FLAG_WOL_PORT1 << slave_port); 1198802f42a8SIdo Shamay 1199802f42a8SIdo Shamay /* Not exposing RSS IP fragments to guests */ 1200802f42a8SIdo Shamay flags &= ~MLX4_DEV_CAP_FLAG_RSS_IP_FRAG; 12012a4fae14SJack Morgenstein MLX4_PUT(outbox->buf, flags, QUERY_DEV_CAP_EXT_FLAGS_OFFSET); 12022a4fae14SJack Morgenstein 1203449fc488SMatan Barak MLX4_GET(field, outbox->buf, QUERY_DEV_CAP_VL_PORT_OFFSET); 1204449fc488SMatan Barak field &= ~0x0F; 1205449fc488SMatan Barak field |= bitmap_weight(actv_ports.ports, dev->caps.num_ports) & 0x0F; 1206449fc488SMatan Barak MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_VL_PORT_OFFSET); 1207449fc488SMatan Barak 120830b40c31SAmir Vadai /* For guests, disable timestamp */ 120930b40c31SAmir Vadai MLX4_GET(field, outbox->buf, QUERY_DEV_CAP_CQ_TS_SUPPORT_OFFSET); 121030b40c31SAmir Vadai field &= 0x7f; 121130b40c31SAmir Vadai MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_CQ_TS_SUPPORT_OFFSET); 121230b40c31SAmir Vadai 12133742cc65SIdo Shamay /* For guests, disable vxlan tunneling and QoS support */ 121457352ef4SAmir Vadai MLX4_GET(field, outbox->buf, QUERY_DEV_CAP_VXLAN); 12153742cc65SIdo Shamay field &= 0xd7; 12167ffdf726SOr Gerlitz MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_VXLAN); 12177ffdf726SOr Gerlitz 121851af33cfSIdo Shamay /* For guests, disable port BEACON */ 121951af33cfSIdo Shamay MLX4_GET(field, outbox->buf, QUERY_DEV_CAP_PORT_BEACON_OFFSET); 122051af33cfSIdo Shamay field &= 0x7f; 122151af33cfSIdo Shamay MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_PORT_BEACON_OFFSET); 122251af33cfSIdo Shamay 1223b91cb3ebSJack Morgenstein /* For guests, report Blueflame disabled */ 1224b91cb3ebSJack Morgenstein MLX4_GET(field, outbox->buf, QUERY_DEV_CAP_BF_OFFSET); 1225b91cb3ebSJack Morgenstein field &= 0x7f; 1226b91cb3ebSJack Morgenstein MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_BF_OFFSET); 1227b91cb3ebSJack Morgenstein 122859e14e32SMoni Shoua /* For guests, disable mw type 2 and port remap*/ 122957352ef4SAmir Vadai MLX4_GET(bmme_flags, outbox->buf, QUERY_DEV_CAP_BMME_FLAGS_OFFSET); 1230cc1ade94SShani Michaeli bmme_flags &= ~MLX4_BMME_FLAG_TYPE_2_WIN; 123159e14e32SMoni Shoua bmme_flags &= ~MLX4_FLAG_PORT_REMAP; 1232cc1ade94SShani Michaeli MLX4_PUT(outbox->buf, bmme_flags, QUERY_DEV_CAP_BMME_FLAGS_OFFSET); 1233cc1ade94SShani Michaeli 12340081c8f3SJack Morgenstein /* turn off device-managed steering capability if not enabled */ 12350081c8f3SJack Morgenstein if (dev->caps.steering_mode != MLX4_STEERING_MODE_DEVICE_MANAGED) { 12360081c8f3SJack Morgenstein MLX4_GET(field, outbox->buf, 12370081c8f3SJack Morgenstein QUERY_DEV_CAP_FLOW_STEERING_RANGE_EN_OFFSET); 12380081c8f3SJack Morgenstein field &= 0x7f; 12390081c8f3SJack Morgenstein MLX4_PUT(outbox->buf, field, 12400081c8f3SJack Morgenstein QUERY_DEV_CAP_FLOW_STEERING_RANGE_EN_OFFSET); 12410081c8f3SJack Morgenstein } 12424de65803SMatan Barak 12434de65803SMatan Barak /* turn off ipoib managed steering for guests */ 124457352ef4SAmir Vadai MLX4_GET(field, outbox->buf, QUERY_DEV_CAP_FLOW_STEERING_IPOIB_OFFSET); 12454de65803SMatan Barak field &= ~0x80; 12464de65803SMatan Barak MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_FLOW_STEERING_IPOIB_OFFSET); 12474de65803SMatan Barak 1248383677daSOr Gerlitz /* turn off host side virt features (VST, FSM, etc) for guests */ 1249383677daSOr Gerlitz MLX4_GET(field32, outbox->buf, QUERY_DEV_CAP_EXT_2_FLAGS_OFFSET); 1250383677daSOr Gerlitz field32 &= ~(DEV_CAP_EXT_2_FLAG_VLAN_CONTROL | DEV_CAP_EXT_2_FLAG_80_VFS | 12510b131561SMatan Barak DEV_CAP_EXT_2_FLAG_FSM | DEV_CAP_EXT_2_FLAG_PFC_COUNTERS); 1252383677daSOr Gerlitz MLX4_PUT(outbox->buf, field32, QUERY_DEV_CAP_EXT_2_FLAGS_OFFSET); 1253383677daSOr Gerlitz 1254d237baa1SShani Michaeli /* turn off QCN for guests */ 1255d237baa1SShani Michaeli MLX4_GET(field, outbox->buf, QUERY_DEV_CAP_ECN_QCN_VER_OFFSET); 1256d237baa1SShani Michaeli field &= 0xfe; 1257d237baa1SShani Michaeli MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_ECN_QCN_VER_OFFSET); 1258d237baa1SShani Michaeli 1259fc31e256SOr Gerlitz /* turn off QP max-rate limiting for guests */ 1260fc31e256SOr Gerlitz field16 = 0; 1261fc31e256SOr Gerlitz MLX4_PUT(outbox->buf, field16, QUERY_DEV_CAP_QP_RATE_LIMIT_NUM_OFFSET); 1262fc31e256SOr Gerlitz 1263d019fcb2SIdo Shamay /* turn off QoS per VF support for guests */ 1264d019fcb2SIdo Shamay MLX4_GET(field, outbox->buf, QUERY_DEV_CAP_CQ_EQ_CACHE_LINE_STRIDE); 1265d019fcb2SIdo Shamay field &= 0xef; 1266d019fcb2SIdo Shamay MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_CQ_EQ_CACHE_LINE_STRIDE); 1267d019fcb2SIdo Shamay 126878500b8cSMuhammad Mahajna /* turn off ignore FCS feature for guests */ 126978500b8cSMuhammad Mahajna MLX4_GET(field, outbox->buf, QUERY_DEV_CAP_CONFIG_DEV_OFFSET); 127078500b8cSMuhammad Mahajna field &= 0xfb; 127178500b8cSMuhammad Mahajna MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_CONFIG_DEV_OFFSET); 127278500b8cSMuhammad Mahajna 1273b91cb3ebSJack Morgenstein return 0; 1274b91cb3ebSJack Morgenstein } 1275b91cb3ebSJack Morgenstein 1276d8ae9141SMoni Shoua static void disable_unsupported_roce_caps(void *buf) 1277d8ae9141SMoni Shoua { 1278d8ae9141SMoni Shoua u32 flags; 1279d8ae9141SMoni Shoua 1280d8ae9141SMoni Shoua MLX4_GET(flags, buf, QUERY_DEV_CAP_EXT_FLAGS_OFFSET); 1281d8ae9141SMoni Shoua flags &= ~(1UL << 31); 1282d8ae9141SMoni Shoua MLX4_PUT(buf, flags, QUERY_DEV_CAP_EXT_FLAGS_OFFSET); 1283d8ae9141SMoni Shoua MLX4_GET(flags, buf, QUERY_DEV_CAP_EXT_2_FLAGS_OFFSET); 1284d8ae9141SMoni Shoua flags &= ~(1UL << 24); 1285d8ae9141SMoni Shoua MLX4_PUT(buf, flags, QUERY_DEV_CAP_EXT_2_FLAGS_OFFSET); 1286d8ae9141SMoni Shoua MLX4_GET(flags, buf, QUERY_DEV_CAP_BMME_FLAGS_OFFSET); 1287d8ae9141SMoni Shoua flags &= ~(MLX4_FLAG_ROCE_V1_V2); 1288d8ae9141SMoni Shoua MLX4_PUT(buf, flags, QUERY_DEV_CAP_BMME_FLAGS_OFFSET); 1289d8ae9141SMoni Shoua } 1290d8ae9141SMoni Shoua 12915cc914f1SMarcel Apfelbaum int mlx4_QUERY_PORT_wrapper(struct mlx4_dev *dev, int slave, 12925cc914f1SMarcel Apfelbaum struct mlx4_vhcr *vhcr, 12935cc914f1SMarcel Apfelbaum struct mlx4_cmd_mailbox *inbox, 12945cc914f1SMarcel Apfelbaum struct mlx4_cmd_mailbox *outbox, 12955cc914f1SMarcel Apfelbaum struct mlx4_cmd_info *cmd) 12965cc914f1SMarcel Apfelbaum { 12970eb62b93SRony Efraim struct mlx4_priv *priv = mlx4_priv(dev); 12985cc914f1SMarcel Apfelbaum u64 def_mac; 12995cc914f1SMarcel Apfelbaum u8 port_type; 13006634961cSJack Morgenstein u16 short_field; 13015cc914f1SMarcel Apfelbaum int err; 1302948e306dSRony Efraim int admin_link_state; 1303449fc488SMatan Barak int port = mlx4_slave_convert_port(dev, slave, 1304449fc488SMatan Barak vhcr->in_modifier & 0xFF); 13055cc914f1SMarcel Apfelbaum 1306105c320fSJack Morgenstein #define MLX4_VF_PORT_NO_LINK_SENSE_MASK 0xE0 1307948e306dSRony Efraim #define MLX4_PORT_LINK_UP_MASK 0x80 13086634961cSJack Morgenstein #define QUERY_PORT_CUR_MAX_PKEY_OFFSET 0x0c 13096634961cSJack Morgenstein #define QUERY_PORT_CUR_MAX_GID_OFFSET 0x0e 131095f56e7aSYevgeny Petrilin 1311449fc488SMatan Barak if (port < 0) 1312449fc488SMatan Barak return -EINVAL; 1313449fc488SMatan Barak 1314a7401b9cSJack Morgenstein /* Protect against untrusted guests: enforce that this is the 1315a7401b9cSJack Morgenstein * QUERY_PORT general query. 1316a7401b9cSJack Morgenstein */ 1317a7401b9cSJack Morgenstein if (vhcr->op_modifier || vhcr->in_modifier & ~0xFF) 1318a7401b9cSJack Morgenstein return -EINVAL; 1319a7401b9cSJack Morgenstein 1320a7401b9cSJack Morgenstein vhcr->in_modifier = port; 1321449fc488SMatan Barak 13225cc914f1SMarcel Apfelbaum err = mlx4_cmd_box(dev, 0, outbox->dma, vhcr->in_modifier, 0, 13235cc914f1SMarcel Apfelbaum MLX4_CMD_QUERY_PORT, MLX4_CMD_TIME_CLASS_B, 13245cc914f1SMarcel Apfelbaum MLX4_CMD_NATIVE); 13255cc914f1SMarcel Apfelbaum 13265cc914f1SMarcel Apfelbaum if (!err && dev->caps.function != slave) { 13270eb62b93SRony Efraim def_mac = priv->mfunc.master.vf_oper[slave].vport[vhcr->in_modifier].state.mac; 13285cc914f1SMarcel Apfelbaum MLX4_PUT(outbox->buf, def_mac, QUERY_PORT_MAC_OFFSET); 13295cc914f1SMarcel Apfelbaum 13305cc914f1SMarcel Apfelbaum /* get port type - currently only eth is enabled */ 13315cc914f1SMarcel Apfelbaum MLX4_GET(port_type, outbox->buf, 13325cc914f1SMarcel Apfelbaum QUERY_PORT_SUPPORTED_TYPE_OFFSET); 13335cc914f1SMarcel Apfelbaum 1334105c320fSJack Morgenstein /* No link sensing allowed */ 1335105c320fSJack Morgenstein port_type &= MLX4_VF_PORT_NO_LINK_SENSE_MASK; 1336105c320fSJack Morgenstein /* set port type to currently operating port type */ 1337105c320fSJack Morgenstein port_type |= (dev->caps.port_type[vhcr->in_modifier] & 0x3); 13385cc914f1SMarcel Apfelbaum 1339948e306dSRony Efraim admin_link_state = priv->mfunc.master.vf_oper[slave].vport[vhcr->in_modifier].state.link_state; 1340948e306dSRony Efraim if (IFLA_VF_LINK_STATE_ENABLE == admin_link_state) 1341948e306dSRony Efraim port_type |= MLX4_PORT_LINK_UP_MASK; 1342948e306dSRony Efraim else if (IFLA_VF_LINK_STATE_DISABLE == admin_link_state) 1343948e306dSRony Efraim port_type &= ~MLX4_PORT_LINK_UP_MASK; 1344e34305c8SOr Gerlitz else if (IFLA_VF_LINK_STATE_AUTO == admin_link_state && mlx4_is_bonded(dev)) { 1345e34305c8SOr Gerlitz int other_port = (port == 1) ? 2 : 1; 1346e34305c8SOr Gerlitz struct mlx4_port_cap port_cap; 1347e34305c8SOr Gerlitz 1348e34305c8SOr Gerlitz err = mlx4_QUERY_PORT(dev, other_port, &port_cap); 1349e34305c8SOr Gerlitz if (err) 1350e34305c8SOr Gerlitz goto out; 1351e34305c8SOr Gerlitz port_type |= (port_cap.link_state << 7); 1352e34305c8SOr Gerlitz } 1353948e306dSRony Efraim 13545cc914f1SMarcel Apfelbaum MLX4_PUT(outbox->buf, port_type, 13555cc914f1SMarcel Apfelbaum QUERY_PORT_SUPPORTED_TYPE_OFFSET); 13566634961cSJack Morgenstein 1357b6ffaeffSJack Morgenstein if (dev->caps.port_type[vhcr->in_modifier] == MLX4_PORT_TYPE_ETH) 1358449fc488SMatan Barak short_field = mlx4_get_slave_num_gids(dev, slave, port); 1359b6ffaeffSJack Morgenstein else 13606634961cSJack Morgenstein short_field = 1; /* slave max gids */ 13616634961cSJack Morgenstein MLX4_PUT(outbox->buf, short_field, 13626634961cSJack Morgenstein QUERY_PORT_CUR_MAX_GID_OFFSET); 13636634961cSJack Morgenstein 13646634961cSJack Morgenstein short_field = dev->caps.pkey_table_len[vhcr->in_modifier]; 13656634961cSJack Morgenstein MLX4_PUT(outbox->buf, short_field, 13666634961cSJack Morgenstein QUERY_PORT_CUR_MAX_PKEY_OFFSET); 13675cc914f1SMarcel Apfelbaum } 1368e34305c8SOr Gerlitz out: 13695cc914f1SMarcel Apfelbaum return err; 13705cc914f1SMarcel Apfelbaum } 13715cc914f1SMarcel Apfelbaum 13726634961cSJack Morgenstein int mlx4_get_slave_pkey_gid_tbl_len(struct mlx4_dev *dev, u8 port, 13736634961cSJack Morgenstein int *gid_tbl_len, int *pkey_tbl_len) 13746634961cSJack Morgenstein { 13756634961cSJack Morgenstein struct mlx4_cmd_mailbox *mailbox; 13766634961cSJack Morgenstein u32 *outbox; 13776634961cSJack Morgenstein u16 field; 13786634961cSJack Morgenstein int err; 13796634961cSJack Morgenstein 13806634961cSJack Morgenstein mailbox = mlx4_alloc_cmd_mailbox(dev); 13816634961cSJack Morgenstein if (IS_ERR(mailbox)) 13826634961cSJack Morgenstein return PTR_ERR(mailbox); 13836634961cSJack Morgenstein 13846634961cSJack Morgenstein err = mlx4_cmd_box(dev, 0, mailbox->dma, port, 0, 13856634961cSJack Morgenstein MLX4_CMD_QUERY_PORT, MLX4_CMD_TIME_CLASS_B, 13866634961cSJack Morgenstein MLX4_CMD_WRAPPED); 13876634961cSJack Morgenstein if (err) 13886634961cSJack Morgenstein goto out; 13896634961cSJack Morgenstein 13906634961cSJack Morgenstein outbox = mailbox->buf; 13916634961cSJack Morgenstein 13926634961cSJack Morgenstein MLX4_GET(field, outbox, QUERY_PORT_CUR_MAX_GID_OFFSET); 13936634961cSJack Morgenstein *gid_tbl_len = field; 13946634961cSJack Morgenstein 13956634961cSJack Morgenstein MLX4_GET(field, outbox, QUERY_PORT_CUR_MAX_PKEY_OFFSET); 13966634961cSJack Morgenstein *pkey_tbl_len = field; 13976634961cSJack Morgenstein 13986634961cSJack Morgenstein out: 13996634961cSJack Morgenstein mlx4_free_cmd_mailbox(dev, mailbox); 14006634961cSJack Morgenstein return err; 14016634961cSJack Morgenstein } 14026634961cSJack Morgenstein EXPORT_SYMBOL(mlx4_get_slave_pkey_gid_tbl_len); 14036634961cSJack Morgenstein 14045a2cc190SJeff Kirsher int mlx4_map_cmd(struct mlx4_dev *dev, u16 op, struct mlx4_icm *icm, u64 virt) 14055a2cc190SJeff Kirsher { 14065a2cc190SJeff Kirsher struct mlx4_cmd_mailbox *mailbox; 14075a2cc190SJeff Kirsher struct mlx4_icm_iter iter; 14085a2cc190SJeff Kirsher __be64 *pages; 14095a2cc190SJeff Kirsher int lg; 14105a2cc190SJeff Kirsher int nent = 0; 14115a2cc190SJeff Kirsher int i; 14125a2cc190SJeff Kirsher int err = 0; 14135a2cc190SJeff Kirsher int ts = 0, tc = 0; 14145a2cc190SJeff Kirsher 14155a2cc190SJeff Kirsher mailbox = mlx4_alloc_cmd_mailbox(dev); 14165a2cc190SJeff Kirsher if (IS_ERR(mailbox)) 14175a2cc190SJeff Kirsher return PTR_ERR(mailbox); 14185a2cc190SJeff Kirsher pages = mailbox->buf; 14195a2cc190SJeff Kirsher 14205a2cc190SJeff Kirsher for (mlx4_icm_first(icm, &iter); 14215a2cc190SJeff Kirsher !mlx4_icm_last(&iter); 14225a2cc190SJeff Kirsher mlx4_icm_next(&iter)) { 14235a2cc190SJeff Kirsher /* 14245a2cc190SJeff Kirsher * We have to pass pages that are aligned to their 14255a2cc190SJeff Kirsher * size, so find the least significant 1 in the 14265a2cc190SJeff Kirsher * address or size and use that as our log2 size. 14275a2cc190SJeff Kirsher */ 14285a2cc190SJeff Kirsher lg = ffs(mlx4_icm_addr(&iter) | mlx4_icm_size(&iter)) - 1; 14295a2cc190SJeff Kirsher if (lg < MLX4_ICM_PAGE_SHIFT) { 14301a91de28SJoe Perches mlx4_warn(dev, "Got FW area not aligned to %d (%llx/%lx)\n", 14315a2cc190SJeff Kirsher MLX4_ICM_PAGE_SIZE, 14325a2cc190SJeff Kirsher (unsigned long long) mlx4_icm_addr(&iter), 14335a2cc190SJeff Kirsher mlx4_icm_size(&iter)); 14345a2cc190SJeff Kirsher err = -EINVAL; 14355a2cc190SJeff Kirsher goto out; 14365a2cc190SJeff Kirsher } 14375a2cc190SJeff Kirsher 14385a2cc190SJeff Kirsher for (i = 0; i < mlx4_icm_size(&iter) >> lg; ++i) { 14395a2cc190SJeff Kirsher if (virt != -1) { 14405a2cc190SJeff Kirsher pages[nent * 2] = cpu_to_be64(virt); 14415a2cc190SJeff Kirsher virt += 1 << lg; 14425a2cc190SJeff Kirsher } 14435a2cc190SJeff Kirsher 14445a2cc190SJeff Kirsher pages[nent * 2 + 1] = 14455a2cc190SJeff Kirsher cpu_to_be64((mlx4_icm_addr(&iter) + (i << lg)) | 14465a2cc190SJeff Kirsher (lg - MLX4_ICM_PAGE_SHIFT)); 14475a2cc190SJeff Kirsher ts += 1 << (lg - 10); 14485a2cc190SJeff Kirsher ++tc; 14495a2cc190SJeff Kirsher 14505a2cc190SJeff Kirsher if (++nent == MLX4_MAILBOX_SIZE / 16) { 14515a2cc190SJeff Kirsher err = mlx4_cmd(dev, mailbox->dma, nent, 0, op, 1452f9baff50SJack Morgenstein MLX4_CMD_TIME_CLASS_B, 1453f9baff50SJack Morgenstein MLX4_CMD_NATIVE); 14545a2cc190SJeff Kirsher if (err) 14555a2cc190SJeff Kirsher goto out; 14565a2cc190SJeff Kirsher nent = 0; 14575a2cc190SJeff Kirsher } 14585a2cc190SJeff Kirsher } 14595a2cc190SJeff Kirsher } 14605a2cc190SJeff Kirsher 14615a2cc190SJeff Kirsher if (nent) 1462f9baff50SJack Morgenstein err = mlx4_cmd(dev, mailbox->dma, nent, 0, op, 1463f9baff50SJack Morgenstein MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE); 14645a2cc190SJeff Kirsher if (err) 14655a2cc190SJeff Kirsher goto out; 14665a2cc190SJeff Kirsher 14675a2cc190SJeff Kirsher switch (op) { 14685a2cc190SJeff Kirsher case MLX4_CMD_MAP_FA: 14691a91de28SJoe Perches mlx4_dbg(dev, "Mapped %d chunks/%d KB for FW\n", tc, ts); 14705a2cc190SJeff Kirsher break; 14715a2cc190SJeff Kirsher case MLX4_CMD_MAP_ICM_AUX: 14721a91de28SJoe Perches mlx4_dbg(dev, "Mapped %d chunks/%d KB for ICM aux\n", tc, ts); 14735a2cc190SJeff Kirsher break; 14745a2cc190SJeff Kirsher case MLX4_CMD_MAP_ICM: 14751a91de28SJoe Perches mlx4_dbg(dev, "Mapped %d chunks/%d KB at %llx for ICM\n", 14765a2cc190SJeff Kirsher tc, ts, (unsigned long long) virt - (ts << 10)); 14775a2cc190SJeff Kirsher break; 14785a2cc190SJeff Kirsher } 14795a2cc190SJeff Kirsher 14805a2cc190SJeff Kirsher out: 14815a2cc190SJeff Kirsher mlx4_free_cmd_mailbox(dev, mailbox); 14825a2cc190SJeff Kirsher return err; 14835a2cc190SJeff Kirsher } 14845a2cc190SJeff Kirsher 14855a2cc190SJeff Kirsher int mlx4_MAP_FA(struct mlx4_dev *dev, struct mlx4_icm *icm) 14865a2cc190SJeff Kirsher { 14875a2cc190SJeff Kirsher return mlx4_map_cmd(dev, MLX4_CMD_MAP_FA, icm, -1); 14885a2cc190SJeff Kirsher } 14895a2cc190SJeff Kirsher 14905a2cc190SJeff Kirsher int mlx4_UNMAP_FA(struct mlx4_dev *dev) 14915a2cc190SJeff Kirsher { 1492f9baff50SJack Morgenstein return mlx4_cmd(dev, 0, 0, 0, MLX4_CMD_UNMAP_FA, 1493f9baff50SJack Morgenstein MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE); 14945a2cc190SJeff Kirsher } 14955a2cc190SJeff Kirsher 14965a2cc190SJeff Kirsher 14975a2cc190SJeff Kirsher int mlx4_RUN_FW(struct mlx4_dev *dev) 14985a2cc190SJeff Kirsher { 1499f9baff50SJack Morgenstein return mlx4_cmd(dev, 0, 0, 0, MLX4_CMD_RUN_FW, 1500f9baff50SJack Morgenstein MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE); 15015a2cc190SJeff Kirsher } 15025a2cc190SJeff Kirsher 15035a2cc190SJeff Kirsher int mlx4_QUERY_FW(struct mlx4_dev *dev) 15045a2cc190SJeff Kirsher { 15055a2cc190SJeff Kirsher struct mlx4_fw *fw = &mlx4_priv(dev)->fw; 15065a2cc190SJeff Kirsher struct mlx4_cmd *cmd = &mlx4_priv(dev)->cmd; 15075a2cc190SJeff Kirsher struct mlx4_cmd_mailbox *mailbox; 15085a2cc190SJeff Kirsher u32 *outbox; 15095a2cc190SJeff Kirsher int err = 0; 15105a2cc190SJeff Kirsher u64 fw_ver; 15115a2cc190SJeff Kirsher u16 cmd_if_rev; 15125a2cc190SJeff Kirsher u8 lg; 15135a2cc190SJeff Kirsher 15145a2cc190SJeff Kirsher #define QUERY_FW_OUT_SIZE 0x100 15155a2cc190SJeff Kirsher #define QUERY_FW_VER_OFFSET 0x00 15165cc914f1SMarcel Apfelbaum #define QUERY_FW_PPF_ID 0x09 15175a2cc190SJeff Kirsher #define QUERY_FW_CMD_IF_REV_OFFSET 0x0a 15185a2cc190SJeff Kirsher #define QUERY_FW_MAX_CMD_OFFSET 0x0f 15195a2cc190SJeff Kirsher #define QUERY_FW_ERR_START_OFFSET 0x30 15205a2cc190SJeff Kirsher #define QUERY_FW_ERR_SIZE_OFFSET 0x38 15215a2cc190SJeff Kirsher #define QUERY_FW_ERR_BAR_OFFSET 0x3c 15225a2cc190SJeff Kirsher 15235a2cc190SJeff Kirsher #define QUERY_FW_SIZE_OFFSET 0x00 15245a2cc190SJeff Kirsher #define QUERY_FW_CLR_INT_BASE_OFFSET 0x20 15255a2cc190SJeff Kirsher #define QUERY_FW_CLR_INT_BAR_OFFSET 0x28 15265a2cc190SJeff Kirsher 15275cc914f1SMarcel Apfelbaum #define QUERY_FW_COMM_BASE_OFFSET 0x40 15285cc914f1SMarcel Apfelbaum #define QUERY_FW_COMM_BAR_OFFSET 0x48 15295cc914f1SMarcel Apfelbaum 1530ddd8a6c1SEugenia Emantayev #define QUERY_FW_CLOCK_OFFSET 0x50 1531ddd8a6c1SEugenia Emantayev #define QUERY_FW_CLOCK_BAR 0x58 1532ddd8a6c1SEugenia Emantayev 15335a2cc190SJeff Kirsher mailbox = mlx4_alloc_cmd_mailbox(dev); 15345a2cc190SJeff Kirsher if (IS_ERR(mailbox)) 15355a2cc190SJeff Kirsher return PTR_ERR(mailbox); 15365a2cc190SJeff Kirsher outbox = mailbox->buf; 15375a2cc190SJeff Kirsher 15385a2cc190SJeff Kirsher err = mlx4_cmd_box(dev, 0, mailbox->dma, 0, 0, MLX4_CMD_QUERY_FW, 1539f9baff50SJack Morgenstein MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE); 15405a2cc190SJeff Kirsher if (err) 15415a2cc190SJeff Kirsher goto out; 15425a2cc190SJeff Kirsher 15435a2cc190SJeff Kirsher MLX4_GET(fw_ver, outbox, QUERY_FW_VER_OFFSET); 15445a2cc190SJeff Kirsher /* 15455a2cc190SJeff Kirsher * FW subminor version is at more significant bits than minor 15465a2cc190SJeff Kirsher * version, so swap here. 15475a2cc190SJeff Kirsher */ 15485a2cc190SJeff Kirsher dev->caps.fw_ver = (fw_ver & 0xffff00000000ull) | 15495a2cc190SJeff Kirsher ((fw_ver & 0xffff0000ull) >> 16) | 15505a2cc190SJeff Kirsher ((fw_ver & 0x0000ffffull) << 16); 15515a2cc190SJeff Kirsher 1552752a50caSJack Morgenstein MLX4_GET(lg, outbox, QUERY_FW_PPF_ID); 1553752a50caSJack Morgenstein dev->caps.function = lg; 1554752a50caSJack Morgenstein 1555b91cb3ebSJack Morgenstein if (mlx4_is_slave(dev)) 1556b91cb3ebSJack Morgenstein goto out; 1557b91cb3ebSJack Morgenstein 15585cc914f1SMarcel Apfelbaum 15595a2cc190SJeff Kirsher MLX4_GET(cmd_if_rev, outbox, QUERY_FW_CMD_IF_REV_OFFSET); 15605a2cc190SJeff Kirsher if (cmd_if_rev < MLX4_COMMAND_INTERFACE_MIN_REV || 15615a2cc190SJeff Kirsher cmd_if_rev > MLX4_COMMAND_INTERFACE_MAX_REV) { 15621a91de28SJoe Perches mlx4_err(dev, "Installed FW has unsupported command interface revision %d\n", 15635a2cc190SJeff Kirsher cmd_if_rev); 15645a2cc190SJeff Kirsher mlx4_err(dev, "(Installed FW version is %d.%d.%03d)\n", 15655a2cc190SJeff Kirsher (int) (dev->caps.fw_ver >> 32), 15665a2cc190SJeff Kirsher (int) (dev->caps.fw_ver >> 16) & 0xffff, 15675a2cc190SJeff Kirsher (int) dev->caps.fw_ver & 0xffff); 15681a91de28SJoe Perches mlx4_err(dev, "This driver version supports only revisions %d to %d\n", 15695a2cc190SJeff Kirsher MLX4_COMMAND_INTERFACE_MIN_REV, MLX4_COMMAND_INTERFACE_MAX_REV); 15705a2cc190SJeff Kirsher err = -ENODEV; 15715a2cc190SJeff Kirsher goto out; 15725a2cc190SJeff Kirsher } 15735a2cc190SJeff Kirsher 15745a2cc190SJeff Kirsher if (cmd_if_rev < MLX4_COMMAND_INTERFACE_NEW_PORT_CMDS) 15755a2cc190SJeff Kirsher dev->flags |= MLX4_FLAG_OLD_PORT_CMDS; 15765a2cc190SJeff Kirsher 15775a2cc190SJeff Kirsher MLX4_GET(lg, outbox, QUERY_FW_MAX_CMD_OFFSET); 15785a2cc190SJeff Kirsher cmd->max_cmds = 1 << lg; 15795a2cc190SJeff Kirsher 15805a2cc190SJeff Kirsher mlx4_dbg(dev, "FW version %d.%d.%03d (cmd intf rev %d), max commands %d\n", 15815a2cc190SJeff Kirsher (int) (dev->caps.fw_ver >> 32), 15825a2cc190SJeff Kirsher (int) (dev->caps.fw_ver >> 16) & 0xffff, 15835a2cc190SJeff Kirsher (int) dev->caps.fw_ver & 0xffff, 15845a2cc190SJeff Kirsher cmd_if_rev, cmd->max_cmds); 15855a2cc190SJeff Kirsher 15865a2cc190SJeff Kirsher MLX4_GET(fw->catas_offset, outbox, QUERY_FW_ERR_START_OFFSET); 15875a2cc190SJeff Kirsher MLX4_GET(fw->catas_size, outbox, QUERY_FW_ERR_SIZE_OFFSET); 15885a2cc190SJeff Kirsher MLX4_GET(fw->catas_bar, outbox, QUERY_FW_ERR_BAR_OFFSET); 15895a2cc190SJeff Kirsher fw->catas_bar = (fw->catas_bar >> 6) * 2; 15905a2cc190SJeff Kirsher 15915a2cc190SJeff Kirsher mlx4_dbg(dev, "Catastrophic error buffer at 0x%llx, size 0x%x, BAR %d\n", 15925a2cc190SJeff Kirsher (unsigned long long) fw->catas_offset, fw->catas_size, fw->catas_bar); 15935a2cc190SJeff Kirsher 15945a2cc190SJeff Kirsher MLX4_GET(fw->fw_pages, outbox, QUERY_FW_SIZE_OFFSET); 15955a2cc190SJeff Kirsher MLX4_GET(fw->clr_int_base, outbox, QUERY_FW_CLR_INT_BASE_OFFSET); 15965a2cc190SJeff Kirsher MLX4_GET(fw->clr_int_bar, outbox, QUERY_FW_CLR_INT_BAR_OFFSET); 15975a2cc190SJeff Kirsher fw->clr_int_bar = (fw->clr_int_bar >> 6) * 2; 15985a2cc190SJeff Kirsher 15995cc914f1SMarcel Apfelbaum MLX4_GET(fw->comm_base, outbox, QUERY_FW_COMM_BASE_OFFSET); 16005cc914f1SMarcel Apfelbaum MLX4_GET(fw->comm_bar, outbox, QUERY_FW_COMM_BAR_OFFSET); 16015cc914f1SMarcel Apfelbaum fw->comm_bar = (fw->comm_bar >> 6) * 2; 16025cc914f1SMarcel Apfelbaum mlx4_dbg(dev, "Communication vector bar:%d offset:0x%llx\n", 16035cc914f1SMarcel Apfelbaum fw->comm_bar, fw->comm_base); 16045a2cc190SJeff Kirsher mlx4_dbg(dev, "FW size %d KB\n", fw->fw_pages >> 2); 16055a2cc190SJeff Kirsher 1606ddd8a6c1SEugenia Emantayev MLX4_GET(fw->clock_offset, outbox, QUERY_FW_CLOCK_OFFSET); 1607ddd8a6c1SEugenia Emantayev MLX4_GET(fw->clock_bar, outbox, QUERY_FW_CLOCK_BAR); 1608ddd8a6c1SEugenia Emantayev fw->clock_bar = (fw->clock_bar >> 6) * 2; 1609ddd8a6c1SEugenia Emantayev mlx4_dbg(dev, "Internal clock bar:%d offset:0x%llx\n", 1610ddd8a6c1SEugenia Emantayev fw->clock_bar, fw->clock_offset); 1611ddd8a6c1SEugenia Emantayev 16125a2cc190SJeff Kirsher /* 16135a2cc190SJeff Kirsher * Round up number of system pages needed in case 16145a2cc190SJeff Kirsher * MLX4_ICM_PAGE_SIZE < PAGE_SIZE. 16155a2cc190SJeff Kirsher */ 16165a2cc190SJeff Kirsher fw->fw_pages = 16175a2cc190SJeff Kirsher ALIGN(fw->fw_pages, PAGE_SIZE / MLX4_ICM_PAGE_SIZE) >> 16185a2cc190SJeff Kirsher (PAGE_SHIFT - MLX4_ICM_PAGE_SHIFT); 16195a2cc190SJeff Kirsher 16205a2cc190SJeff Kirsher mlx4_dbg(dev, "Clear int @ %llx, BAR %d\n", 16215a2cc190SJeff Kirsher (unsigned long long) fw->clr_int_base, fw->clr_int_bar); 16225a2cc190SJeff Kirsher 16235a2cc190SJeff Kirsher out: 16245a2cc190SJeff Kirsher mlx4_free_cmd_mailbox(dev, mailbox); 16255a2cc190SJeff Kirsher return err; 16265a2cc190SJeff Kirsher } 16275a2cc190SJeff Kirsher 1628b91cb3ebSJack Morgenstein int mlx4_QUERY_FW_wrapper(struct mlx4_dev *dev, int slave, 1629b91cb3ebSJack Morgenstein struct mlx4_vhcr *vhcr, 1630b91cb3ebSJack Morgenstein struct mlx4_cmd_mailbox *inbox, 1631b91cb3ebSJack Morgenstein struct mlx4_cmd_mailbox *outbox, 1632b91cb3ebSJack Morgenstein struct mlx4_cmd_info *cmd) 1633b91cb3ebSJack Morgenstein { 1634b91cb3ebSJack Morgenstein u8 *outbuf; 1635b91cb3ebSJack Morgenstein int err; 1636b91cb3ebSJack Morgenstein 1637b91cb3ebSJack Morgenstein outbuf = outbox->buf; 1638b91cb3ebSJack Morgenstein err = mlx4_cmd_box(dev, 0, outbox->dma, 0, 0, MLX4_CMD_QUERY_FW, 1639b91cb3ebSJack Morgenstein MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE); 1640b91cb3ebSJack Morgenstein if (err) 1641b91cb3ebSJack Morgenstein return err; 1642b91cb3ebSJack Morgenstein 1643752a50caSJack Morgenstein /* for slaves, set pci PPF ID to invalid and zero out everything 1644752a50caSJack Morgenstein * else except FW version */ 1645b91cb3ebSJack Morgenstein outbuf[0] = outbuf[1] = 0; 1646b91cb3ebSJack Morgenstein memset(&outbuf[8], 0, QUERY_FW_OUT_SIZE - 8); 1647752a50caSJack Morgenstein outbuf[QUERY_FW_PPF_ID] = MLX4_INVALID_SLAVE_ID; 1648752a50caSJack Morgenstein 1649b91cb3ebSJack Morgenstein return 0; 1650b91cb3ebSJack Morgenstein } 1651b91cb3ebSJack Morgenstein 16525a2cc190SJeff Kirsher static void get_board_id(void *vsd, char *board_id) 16535a2cc190SJeff Kirsher { 16545a2cc190SJeff Kirsher int i; 16555a2cc190SJeff Kirsher 16565a2cc190SJeff Kirsher #define VSD_OFFSET_SIG1 0x00 16575a2cc190SJeff Kirsher #define VSD_OFFSET_SIG2 0xde 16585a2cc190SJeff Kirsher #define VSD_OFFSET_MLX_BOARD_ID 0xd0 16595a2cc190SJeff Kirsher #define VSD_OFFSET_TS_BOARD_ID 0x20 16605a2cc190SJeff Kirsher 16615a2cc190SJeff Kirsher #define VSD_SIGNATURE_TOPSPIN 0x5ad 16625a2cc190SJeff Kirsher 16635a2cc190SJeff Kirsher memset(board_id, 0, MLX4_BOARD_ID_LEN); 16645a2cc190SJeff Kirsher 16655a2cc190SJeff Kirsher if (be16_to_cpup(vsd + VSD_OFFSET_SIG1) == VSD_SIGNATURE_TOPSPIN && 16665a2cc190SJeff Kirsher be16_to_cpup(vsd + VSD_OFFSET_SIG2) == VSD_SIGNATURE_TOPSPIN) { 16675a2cc190SJeff Kirsher strlcpy(board_id, vsd + VSD_OFFSET_TS_BOARD_ID, MLX4_BOARD_ID_LEN); 16685a2cc190SJeff Kirsher } else { 16695a2cc190SJeff Kirsher /* 16705a2cc190SJeff Kirsher * The board ID is a string but the firmware byte 16715a2cc190SJeff Kirsher * swaps each 4-byte word before passing it back to 16725a2cc190SJeff Kirsher * us. Therefore we need to swab it before printing. 16735a2cc190SJeff Kirsher */ 167417d5ceb6SDavid Ahern u32 *bid_u32 = (u32 *)board_id; 167517d5ceb6SDavid Ahern 167617d5ceb6SDavid Ahern for (i = 0; i < 4; ++i) { 167717d5ceb6SDavid Ahern u32 *addr; 167817d5ceb6SDavid Ahern u32 val; 167917d5ceb6SDavid Ahern 168017d5ceb6SDavid Ahern addr = (u32 *) (vsd + VSD_OFFSET_MLX_BOARD_ID + i * 4); 168117d5ceb6SDavid Ahern val = get_unaligned(addr); 168217d5ceb6SDavid Ahern val = swab32(val); 168317d5ceb6SDavid Ahern put_unaligned(val, &bid_u32[i]); 168417d5ceb6SDavid Ahern } 16855a2cc190SJeff Kirsher } 16865a2cc190SJeff Kirsher } 16875a2cc190SJeff Kirsher 16885a2cc190SJeff Kirsher int mlx4_QUERY_ADAPTER(struct mlx4_dev *dev, struct mlx4_adapter *adapter) 16895a2cc190SJeff Kirsher { 16905a2cc190SJeff Kirsher struct mlx4_cmd_mailbox *mailbox; 16915a2cc190SJeff Kirsher u32 *outbox; 16925a2cc190SJeff Kirsher int err; 16935a2cc190SJeff Kirsher 16945a2cc190SJeff Kirsher #define QUERY_ADAPTER_OUT_SIZE 0x100 16955a2cc190SJeff Kirsher #define QUERY_ADAPTER_INTA_PIN_OFFSET 0x10 16965a2cc190SJeff Kirsher #define QUERY_ADAPTER_VSD_OFFSET 0x20 16975a2cc190SJeff Kirsher 16985a2cc190SJeff Kirsher mailbox = mlx4_alloc_cmd_mailbox(dev); 16995a2cc190SJeff Kirsher if (IS_ERR(mailbox)) 17005a2cc190SJeff Kirsher return PTR_ERR(mailbox); 17015a2cc190SJeff Kirsher outbox = mailbox->buf; 17025a2cc190SJeff Kirsher 17035a2cc190SJeff Kirsher err = mlx4_cmd_box(dev, 0, mailbox->dma, 0, 0, MLX4_CMD_QUERY_ADAPTER, 1704f9baff50SJack Morgenstein MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE); 17055a2cc190SJeff Kirsher if (err) 17065a2cc190SJeff Kirsher goto out; 17075a2cc190SJeff Kirsher 17085a2cc190SJeff Kirsher MLX4_GET(adapter->inta_pin, outbox, QUERY_ADAPTER_INTA_PIN_OFFSET); 17095a2cc190SJeff Kirsher 17105a2cc190SJeff Kirsher get_board_id(outbox + QUERY_ADAPTER_VSD_OFFSET / 4, 17115a2cc190SJeff Kirsher adapter->board_id); 17125a2cc190SJeff Kirsher 17135a2cc190SJeff Kirsher out: 17145a2cc190SJeff Kirsher mlx4_free_cmd_mailbox(dev, mailbox); 17155a2cc190SJeff Kirsher return err; 17165a2cc190SJeff Kirsher } 17175a2cc190SJeff Kirsher 17185a2cc190SJeff Kirsher int mlx4_INIT_HCA(struct mlx4_dev *dev, struct mlx4_init_hca_param *param) 17195a2cc190SJeff Kirsher { 17205a2cc190SJeff Kirsher struct mlx4_cmd_mailbox *mailbox; 17215a2cc190SJeff Kirsher __be32 *inbox; 17225a2cc190SJeff Kirsher int err; 17237d077cd3SMatan Barak static const u8 a0_dmfs_hw_steering[] = { 17247d077cd3SMatan Barak [MLX4_STEERING_DMFS_A0_DEFAULT] = 0, 17257d077cd3SMatan Barak [MLX4_STEERING_DMFS_A0_DYNAMIC] = 1, 17267d077cd3SMatan Barak [MLX4_STEERING_DMFS_A0_STATIC] = 2, 17277d077cd3SMatan Barak [MLX4_STEERING_DMFS_A0_DISABLE] = 3 17287d077cd3SMatan Barak }; 17295a2cc190SJeff Kirsher 17305a2cc190SJeff Kirsher #define INIT_HCA_IN_SIZE 0x200 17315a2cc190SJeff Kirsher #define INIT_HCA_VERSION_OFFSET 0x000 17325a2cc190SJeff Kirsher #define INIT_HCA_VERSION 2 17337ffdf726SOr Gerlitz #define INIT_HCA_VXLAN_OFFSET 0x0c 17345a2cc190SJeff Kirsher #define INIT_HCA_CACHELINE_SZ_OFFSET 0x0e 17355a2cc190SJeff Kirsher #define INIT_HCA_FLAGS_OFFSET 0x014 1736be6a6b43SJack Morgenstein #define INIT_HCA_RECOVERABLE_ERROR_EVENT_OFFSET 0x018 17375a2cc190SJeff Kirsher #define INIT_HCA_QPC_OFFSET 0x020 17385a2cc190SJeff Kirsher #define INIT_HCA_QPC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x10) 17395a2cc190SJeff Kirsher #define INIT_HCA_LOG_QP_OFFSET (INIT_HCA_QPC_OFFSET + 0x17) 17405a2cc190SJeff Kirsher #define INIT_HCA_SRQC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x28) 17415a2cc190SJeff Kirsher #define INIT_HCA_LOG_SRQ_OFFSET (INIT_HCA_QPC_OFFSET + 0x2f) 17425a2cc190SJeff Kirsher #define INIT_HCA_CQC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x30) 17435a2cc190SJeff Kirsher #define INIT_HCA_LOG_CQ_OFFSET (INIT_HCA_QPC_OFFSET + 0x37) 17445cc914f1SMarcel Apfelbaum #define INIT_HCA_EQE_CQE_OFFSETS (INIT_HCA_QPC_OFFSET + 0x38) 174577507aa2SIdo Shamay #define INIT_HCA_EQE_CQE_STRIDE_OFFSET (INIT_HCA_QPC_OFFSET + 0x3b) 17465a2cc190SJeff Kirsher #define INIT_HCA_ALTC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x40) 17475a2cc190SJeff Kirsher #define INIT_HCA_AUXC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x50) 17485a2cc190SJeff Kirsher #define INIT_HCA_EQC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x60) 17495a2cc190SJeff Kirsher #define INIT_HCA_LOG_EQ_OFFSET (INIT_HCA_QPC_OFFSET + 0x67) 17507ae0e400SMatan Barak #define INIT_HCA_NUM_SYS_EQS_OFFSET (INIT_HCA_QPC_OFFSET + 0x6a) 17515a2cc190SJeff Kirsher #define INIT_HCA_RDMARC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x70) 17525a2cc190SJeff Kirsher #define INIT_HCA_LOG_RD_OFFSET (INIT_HCA_QPC_OFFSET + 0x77) 17535a2cc190SJeff Kirsher #define INIT_HCA_MCAST_OFFSET 0x0c0 17545a2cc190SJeff Kirsher #define INIT_HCA_MC_BASE_OFFSET (INIT_HCA_MCAST_OFFSET + 0x00) 17555a2cc190SJeff Kirsher #define INIT_HCA_LOG_MC_ENTRY_SZ_OFFSET (INIT_HCA_MCAST_OFFSET + 0x12) 17565a2cc190SJeff Kirsher #define INIT_HCA_LOG_MC_HASH_SZ_OFFSET (INIT_HCA_MCAST_OFFSET + 0x16) 17575a2cc190SJeff Kirsher #define INIT_HCA_UC_STEERING_OFFSET (INIT_HCA_MCAST_OFFSET + 0x18) 17585a2cc190SJeff Kirsher #define INIT_HCA_LOG_MC_TABLE_SZ_OFFSET (INIT_HCA_MCAST_OFFSET + 0x1b) 17590ff1fb65SHadar Hen Zion #define INIT_HCA_DEVICE_MANAGED_FLOW_STEERING_EN 0x6 17600ff1fb65SHadar Hen Zion #define INIT_HCA_FS_PARAM_OFFSET 0x1d0 17610ff1fb65SHadar Hen Zion #define INIT_HCA_FS_BASE_OFFSET (INIT_HCA_FS_PARAM_OFFSET + 0x00) 17620ff1fb65SHadar Hen Zion #define INIT_HCA_FS_LOG_ENTRY_SZ_OFFSET (INIT_HCA_FS_PARAM_OFFSET + 0x12) 17637d077cd3SMatan Barak #define INIT_HCA_FS_A0_OFFSET (INIT_HCA_FS_PARAM_OFFSET + 0x18) 17640ff1fb65SHadar Hen Zion #define INIT_HCA_FS_LOG_TABLE_SZ_OFFSET (INIT_HCA_FS_PARAM_OFFSET + 0x1b) 17650ff1fb65SHadar Hen Zion #define INIT_HCA_FS_ETH_BITS_OFFSET (INIT_HCA_FS_PARAM_OFFSET + 0x21) 17660ff1fb65SHadar Hen Zion #define INIT_HCA_FS_ETH_NUM_ADDRS_OFFSET (INIT_HCA_FS_PARAM_OFFSET + 0x22) 17670ff1fb65SHadar Hen Zion #define INIT_HCA_FS_IB_BITS_OFFSET (INIT_HCA_FS_PARAM_OFFSET + 0x25) 17680ff1fb65SHadar Hen Zion #define INIT_HCA_FS_IB_NUM_ADDRS_OFFSET (INIT_HCA_FS_PARAM_OFFSET + 0x26) 17695a2cc190SJeff Kirsher #define INIT_HCA_TPT_OFFSET 0x0f0 17705a2cc190SJeff Kirsher #define INIT_HCA_DMPT_BASE_OFFSET (INIT_HCA_TPT_OFFSET + 0x00) 1771e448834eSShani Michaeli #define INIT_HCA_TPT_MW_OFFSET (INIT_HCA_TPT_OFFSET + 0x08) 17725a2cc190SJeff Kirsher #define INIT_HCA_LOG_MPT_SZ_OFFSET (INIT_HCA_TPT_OFFSET + 0x0b) 17735a2cc190SJeff Kirsher #define INIT_HCA_MTT_BASE_OFFSET (INIT_HCA_TPT_OFFSET + 0x10) 17745a2cc190SJeff Kirsher #define INIT_HCA_CMPT_BASE_OFFSET (INIT_HCA_TPT_OFFSET + 0x18) 17755a2cc190SJeff Kirsher #define INIT_HCA_UAR_OFFSET 0x120 17765a2cc190SJeff Kirsher #define INIT_HCA_LOG_UAR_SZ_OFFSET (INIT_HCA_UAR_OFFSET + 0x0a) 17775a2cc190SJeff Kirsher #define INIT_HCA_UAR_PAGE_SZ_OFFSET (INIT_HCA_UAR_OFFSET + 0x0b) 17785a2cc190SJeff Kirsher 17795a2cc190SJeff Kirsher mailbox = mlx4_alloc_cmd_mailbox(dev); 17805a2cc190SJeff Kirsher if (IS_ERR(mailbox)) 17815a2cc190SJeff Kirsher return PTR_ERR(mailbox); 17825a2cc190SJeff Kirsher inbox = mailbox->buf; 17835a2cc190SJeff Kirsher 17845a2cc190SJeff Kirsher *((u8 *) mailbox->buf + INIT_HCA_VERSION_OFFSET) = INIT_HCA_VERSION; 17855a2cc190SJeff Kirsher 17865a2cc190SJeff Kirsher *((u8 *) mailbox->buf + INIT_HCA_CACHELINE_SZ_OFFSET) = 17875a2cc190SJeff Kirsher (ilog2(cache_line_size()) - 4) << 5; 17885a2cc190SJeff Kirsher 17895a2cc190SJeff Kirsher #if defined(__LITTLE_ENDIAN) 17905a2cc190SJeff Kirsher *(inbox + INIT_HCA_FLAGS_OFFSET / 4) &= ~cpu_to_be32(1 << 1); 17915a2cc190SJeff Kirsher #elif defined(__BIG_ENDIAN) 17925a2cc190SJeff Kirsher *(inbox + INIT_HCA_FLAGS_OFFSET / 4) |= cpu_to_be32(1 << 1); 17935a2cc190SJeff Kirsher #else 17945a2cc190SJeff Kirsher #error Host endianness not defined 17955a2cc190SJeff Kirsher #endif 17965a2cc190SJeff Kirsher /* Check port for UD address vector: */ 17975a2cc190SJeff Kirsher *(inbox + INIT_HCA_FLAGS_OFFSET / 4) |= cpu_to_be32(1); 17985a2cc190SJeff Kirsher 17995a2cc190SJeff Kirsher /* Enable IPoIB checksumming if we can: */ 18005a2cc190SJeff Kirsher if (dev->caps.flags & MLX4_DEV_CAP_FLAG_IPOIB_CSUM) 18015a2cc190SJeff Kirsher *(inbox + INIT_HCA_FLAGS_OFFSET / 4) |= cpu_to_be32(1 << 3); 18025a2cc190SJeff Kirsher 18035a2cc190SJeff Kirsher /* Enable QoS support if module parameter set */ 180438438f7cSIdo Shamay if (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_ETS_CFG && enable_qos) 18055a2cc190SJeff Kirsher *(inbox + INIT_HCA_FLAGS_OFFSET / 4) |= cpu_to_be32(1 << 2); 18065a2cc190SJeff Kirsher 18075a2cc190SJeff Kirsher /* enable counters */ 18085a2cc190SJeff Kirsher if (dev->caps.flags & MLX4_DEV_CAP_FLAG_COUNTERS) 18095a2cc190SJeff Kirsher *(inbox + INIT_HCA_FLAGS_OFFSET / 4) |= cpu_to_be32(1 << 4); 18105a2cc190SJeff Kirsher 1811802f42a8SIdo Shamay /* Enable RSS spread to fragmented IP packets when supported */ 1812802f42a8SIdo Shamay if (dev->caps.flags & MLX4_DEV_CAP_FLAG_RSS_IP_FRAG) 1813802f42a8SIdo Shamay *(inbox + INIT_HCA_FLAGS_OFFSET / 4) |= cpu_to_be32(1 << 13); 1814802f42a8SIdo Shamay 181508ff3235SOr Gerlitz /* CX3 is capable of extending CQEs/EQEs from 32 to 64 bytes */ 181608ff3235SOr Gerlitz if (dev->caps.flags & MLX4_DEV_CAP_FLAG_64B_EQE) { 181708ff3235SOr Gerlitz *(inbox + INIT_HCA_EQE_CQE_OFFSETS / 4) |= cpu_to_be32(1 << 29); 181808ff3235SOr Gerlitz dev->caps.eqe_size = 64; 181908ff3235SOr Gerlitz dev->caps.eqe_factor = 1; 182008ff3235SOr Gerlitz } else { 182108ff3235SOr Gerlitz dev->caps.eqe_size = 32; 182208ff3235SOr Gerlitz dev->caps.eqe_factor = 0; 182308ff3235SOr Gerlitz } 182408ff3235SOr Gerlitz 182508ff3235SOr Gerlitz if (dev->caps.flags & MLX4_DEV_CAP_FLAG_64B_CQE) { 182608ff3235SOr Gerlitz *(inbox + INIT_HCA_EQE_CQE_OFFSETS / 4) |= cpu_to_be32(1 << 30); 182708ff3235SOr Gerlitz dev->caps.cqe_size = 64; 182877507aa2SIdo Shamay dev->caps.userspace_caps |= MLX4_USER_DEV_CAP_LARGE_CQE; 182908ff3235SOr Gerlitz } else { 183008ff3235SOr Gerlitz dev->caps.cqe_size = 32; 183108ff3235SOr Gerlitz } 183208ff3235SOr Gerlitz 183377507aa2SIdo Shamay /* CX3 is capable of extending CQEs\EQEs to strides larger than 64B */ 183477507aa2SIdo Shamay if ((dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_EQE_STRIDE) && 183577507aa2SIdo Shamay (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_CQE_STRIDE)) { 183677507aa2SIdo Shamay dev->caps.eqe_size = cache_line_size(); 183777507aa2SIdo Shamay dev->caps.cqe_size = cache_line_size(); 183877507aa2SIdo Shamay dev->caps.eqe_factor = 0; 183977507aa2SIdo Shamay MLX4_PUT(inbox, (u8)((ilog2(dev->caps.eqe_size) - 5) << 4 | 184077507aa2SIdo Shamay (ilog2(dev->caps.eqe_size) - 5)), 184177507aa2SIdo Shamay INIT_HCA_EQE_CQE_STRIDE_OFFSET); 184277507aa2SIdo Shamay 184377507aa2SIdo Shamay /* User still need to know to support CQE > 32B */ 184477507aa2SIdo Shamay dev->caps.userspace_caps |= MLX4_USER_DEV_CAP_LARGE_CQE; 184577507aa2SIdo Shamay } 184677507aa2SIdo Shamay 1847be6a6b43SJack Morgenstein if (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_RECOVERABLE_ERROR_EVENT) 1848be6a6b43SJack Morgenstein *(inbox + INIT_HCA_RECOVERABLE_ERROR_EVENT_OFFSET / 4) |= cpu_to_be32(1 << 31); 1849be6a6b43SJack Morgenstein 18505a2cc190SJeff Kirsher /* QPC/EEC/CQC/EQC/RDMARC attributes */ 18515a2cc190SJeff Kirsher 18525a2cc190SJeff Kirsher MLX4_PUT(inbox, param->qpc_base, INIT_HCA_QPC_BASE_OFFSET); 18535a2cc190SJeff Kirsher MLX4_PUT(inbox, param->log_num_qps, INIT_HCA_LOG_QP_OFFSET); 18545a2cc190SJeff Kirsher MLX4_PUT(inbox, param->srqc_base, INIT_HCA_SRQC_BASE_OFFSET); 18555a2cc190SJeff Kirsher MLX4_PUT(inbox, param->log_num_srqs, INIT_HCA_LOG_SRQ_OFFSET); 18565a2cc190SJeff Kirsher MLX4_PUT(inbox, param->cqc_base, INIT_HCA_CQC_BASE_OFFSET); 18575a2cc190SJeff Kirsher MLX4_PUT(inbox, param->log_num_cqs, INIT_HCA_LOG_CQ_OFFSET); 18585a2cc190SJeff Kirsher MLX4_PUT(inbox, param->altc_base, INIT_HCA_ALTC_BASE_OFFSET); 18595a2cc190SJeff Kirsher MLX4_PUT(inbox, param->auxc_base, INIT_HCA_AUXC_BASE_OFFSET); 18605a2cc190SJeff Kirsher MLX4_PUT(inbox, param->eqc_base, INIT_HCA_EQC_BASE_OFFSET); 18615a2cc190SJeff Kirsher MLX4_PUT(inbox, param->log_num_eqs, INIT_HCA_LOG_EQ_OFFSET); 18627ae0e400SMatan Barak MLX4_PUT(inbox, param->num_sys_eqs, INIT_HCA_NUM_SYS_EQS_OFFSET); 18635a2cc190SJeff Kirsher MLX4_PUT(inbox, param->rdmarc_base, INIT_HCA_RDMARC_BASE_OFFSET); 18645a2cc190SJeff Kirsher MLX4_PUT(inbox, param->log_rd_per_qp, INIT_HCA_LOG_RD_OFFSET); 18655a2cc190SJeff Kirsher 18660ff1fb65SHadar Hen Zion /* steering attributes */ 18670ff1fb65SHadar Hen Zion if (dev->caps.steering_mode == 18680ff1fb65SHadar Hen Zion MLX4_STEERING_MODE_DEVICE_MANAGED) { 18690ff1fb65SHadar Hen Zion *(inbox + INIT_HCA_FLAGS_OFFSET / 4) |= 18700ff1fb65SHadar Hen Zion cpu_to_be32(1 << 18710ff1fb65SHadar Hen Zion INIT_HCA_DEVICE_MANAGED_FLOW_STEERING_EN); 18725a2cc190SJeff Kirsher 18730ff1fb65SHadar Hen Zion MLX4_PUT(inbox, param->mc_base, INIT_HCA_FS_BASE_OFFSET); 18740ff1fb65SHadar Hen Zion MLX4_PUT(inbox, param->log_mc_entry_sz, 18750ff1fb65SHadar Hen Zion INIT_HCA_FS_LOG_ENTRY_SZ_OFFSET); 18760ff1fb65SHadar Hen Zion MLX4_PUT(inbox, param->log_mc_table_sz, 18770ff1fb65SHadar Hen Zion INIT_HCA_FS_LOG_TABLE_SZ_OFFSET); 18780ff1fb65SHadar Hen Zion /* Enable Ethernet flow steering 18790ff1fb65SHadar Hen Zion * with udp unicast and tcp unicast 18800ff1fb65SHadar Hen Zion */ 18817d077cd3SMatan Barak if (dev->caps.dmfs_high_steer_mode != 18827d077cd3SMatan Barak MLX4_STEERING_DMFS_A0_STATIC) 18837d077cd3SMatan Barak MLX4_PUT(inbox, 18847d077cd3SMatan Barak (u8)(MLX4_FS_UDP_UC_EN | MLX4_FS_TCP_UC_EN), 18850ff1fb65SHadar Hen Zion INIT_HCA_FS_ETH_BITS_OFFSET); 18860ff1fb65SHadar Hen Zion MLX4_PUT(inbox, (u16) MLX4_FS_NUM_OF_L2_ADDR, 18870ff1fb65SHadar Hen Zion INIT_HCA_FS_ETH_NUM_ADDRS_OFFSET); 18880ff1fb65SHadar Hen Zion /* Enable IPoIB flow steering 18890ff1fb65SHadar Hen Zion * with udp unicast and tcp unicast 18900ff1fb65SHadar Hen Zion */ 189123537b73SHadar Hen Zion MLX4_PUT(inbox, (u8) (MLX4_FS_UDP_UC_EN | MLX4_FS_TCP_UC_EN), 18920ff1fb65SHadar Hen Zion INIT_HCA_FS_IB_BITS_OFFSET); 18930ff1fb65SHadar Hen Zion MLX4_PUT(inbox, (u16) MLX4_FS_NUM_OF_L2_ADDR, 18940ff1fb65SHadar Hen Zion INIT_HCA_FS_IB_NUM_ADDRS_OFFSET); 18957d077cd3SMatan Barak 18967d077cd3SMatan Barak if (dev->caps.dmfs_high_steer_mode != 18977d077cd3SMatan Barak MLX4_STEERING_DMFS_A0_NOT_SUPPORTED) 18987d077cd3SMatan Barak MLX4_PUT(inbox, 18997d077cd3SMatan Barak ((u8)(a0_dmfs_hw_steering[dev->caps.dmfs_high_steer_mode] 19007d077cd3SMatan Barak << 6)), 19017d077cd3SMatan Barak INIT_HCA_FS_A0_OFFSET); 19020ff1fb65SHadar Hen Zion } else { 19035a2cc190SJeff Kirsher MLX4_PUT(inbox, param->mc_base, INIT_HCA_MC_BASE_OFFSET); 19040ff1fb65SHadar Hen Zion MLX4_PUT(inbox, param->log_mc_entry_sz, 19050ff1fb65SHadar Hen Zion INIT_HCA_LOG_MC_ENTRY_SZ_OFFSET); 19060ff1fb65SHadar Hen Zion MLX4_PUT(inbox, param->log_mc_hash_sz, 19070ff1fb65SHadar Hen Zion INIT_HCA_LOG_MC_HASH_SZ_OFFSET); 19080ff1fb65SHadar Hen Zion MLX4_PUT(inbox, param->log_mc_table_sz, 19090ff1fb65SHadar Hen Zion INIT_HCA_LOG_MC_TABLE_SZ_OFFSET); 1910c96d97f4SHadar Hen Zion if (dev->caps.steering_mode == MLX4_STEERING_MODE_B0) 19110ff1fb65SHadar Hen Zion MLX4_PUT(inbox, (u8) (1 << 3), 19120ff1fb65SHadar Hen Zion INIT_HCA_UC_STEERING_OFFSET); 19130ff1fb65SHadar Hen Zion } 19145a2cc190SJeff Kirsher 19155a2cc190SJeff Kirsher /* TPT attributes */ 19165a2cc190SJeff Kirsher 19175a2cc190SJeff Kirsher MLX4_PUT(inbox, param->dmpt_base, INIT_HCA_DMPT_BASE_OFFSET); 1918e448834eSShani Michaeli MLX4_PUT(inbox, param->mw_enabled, INIT_HCA_TPT_MW_OFFSET); 19195a2cc190SJeff Kirsher MLX4_PUT(inbox, param->log_mpt_sz, INIT_HCA_LOG_MPT_SZ_OFFSET); 19205a2cc190SJeff Kirsher MLX4_PUT(inbox, param->mtt_base, INIT_HCA_MTT_BASE_OFFSET); 19215a2cc190SJeff Kirsher MLX4_PUT(inbox, param->cmpt_base, INIT_HCA_CMPT_BASE_OFFSET); 19225a2cc190SJeff Kirsher 19235a2cc190SJeff Kirsher /* UAR attributes */ 19245a2cc190SJeff Kirsher 1925ab9c17a0SJack Morgenstein MLX4_PUT(inbox, param->uar_page_sz, INIT_HCA_UAR_PAGE_SZ_OFFSET); 19265a2cc190SJeff Kirsher MLX4_PUT(inbox, param->log_uar_sz, INIT_HCA_LOG_UAR_SZ_OFFSET); 19275a2cc190SJeff Kirsher 19287ffdf726SOr Gerlitz /* set parser VXLAN attributes */ 19297ffdf726SOr Gerlitz if (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_VXLAN_OFFLOADS) { 19307ffdf726SOr Gerlitz u8 parser_params = 0; 19317ffdf726SOr Gerlitz MLX4_PUT(inbox, parser_params, INIT_HCA_VXLAN_OFFSET); 19327ffdf726SOr Gerlitz } 19337ffdf726SOr Gerlitz 19345a031086SJack Morgenstein err = mlx4_cmd(dev, mailbox->dma, 0, 0, MLX4_CMD_INIT_HCA, 19355a031086SJack Morgenstein MLX4_CMD_TIME_CLASS_C, MLX4_CMD_NATIVE); 19365a2cc190SJeff Kirsher 19375a2cc190SJeff Kirsher if (err) 19385a2cc190SJeff Kirsher mlx4_err(dev, "INIT_HCA returns %d\n", err); 19395a2cc190SJeff Kirsher 19405a2cc190SJeff Kirsher mlx4_free_cmd_mailbox(dev, mailbox); 19415a2cc190SJeff Kirsher return err; 19425a2cc190SJeff Kirsher } 19435a2cc190SJeff Kirsher 1944ab9c17a0SJack Morgenstein int mlx4_QUERY_HCA(struct mlx4_dev *dev, 1945ab9c17a0SJack Morgenstein struct mlx4_init_hca_param *param) 1946ab9c17a0SJack Morgenstein { 1947ab9c17a0SJack Morgenstein struct mlx4_cmd_mailbox *mailbox; 1948ab9c17a0SJack Morgenstein __be32 *outbox; 19497b8157beSJack Morgenstein u32 dword_field; 1950ab9c17a0SJack Morgenstein int err; 195108ff3235SOr Gerlitz u8 byte_field; 19527d077cd3SMatan Barak static const u8 a0_dmfs_query_hw_steering[] = { 19537d077cd3SMatan Barak [0] = MLX4_STEERING_DMFS_A0_DEFAULT, 19547d077cd3SMatan Barak [1] = MLX4_STEERING_DMFS_A0_DYNAMIC, 19557d077cd3SMatan Barak [2] = MLX4_STEERING_DMFS_A0_STATIC, 19567d077cd3SMatan Barak [3] = MLX4_STEERING_DMFS_A0_DISABLE 19577d077cd3SMatan Barak }; 1958ab9c17a0SJack Morgenstein 1959ab9c17a0SJack Morgenstein #define QUERY_HCA_GLOBAL_CAPS_OFFSET 0x04 1960ddd8a6c1SEugenia Emantayev #define QUERY_HCA_CORE_CLOCK_OFFSET 0x0c 1961ab9c17a0SJack Morgenstein 1962ab9c17a0SJack Morgenstein mailbox = mlx4_alloc_cmd_mailbox(dev); 1963ab9c17a0SJack Morgenstein if (IS_ERR(mailbox)) 1964ab9c17a0SJack Morgenstein return PTR_ERR(mailbox); 1965ab9c17a0SJack Morgenstein outbox = mailbox->buf; 1966ab9c17a0SJack Morgenstein 1967ab9c17a0SJack Morgenstein err = mlx4_cmd_box(dev, 0, mailbox->dma, 0, 0, 1968ab9c17a0SJack Morgenstein MLX4_CMD_QUERY_HCA, 1969ab9c17a0SJack Morgenstein MLX4_CMD_TIME_CLASS_B, 1970ab9c17a0SJack Morgenstein !mlx4_is_slave(dev)); 1971ab9c17a0SJack Morgenstein if (err) 1972ab9c17a0SJack Morgenstein goto out; 1973ab9c17a0SJack Morgenstein 1974ab9c17a0SJack Morgenstein MLX4_GET(param->global_caps, outbox, QUERY_HCA_GLOBAL_CAPS_OFFSET); 1975ddd8a6c1SEugenia Emantayev MLX4_GET(param->hca_core_clock, outbox, QUERY_HCA_CORE_CLOCK_OFFSET); 1976ab9c17a0SJack Morgenstein 1977ab9c17a0SJack Morgenstein /* QPC/EEC/CQC/EQC/RDMARC attributes */ 1978ab9c17a0SJack Morgenstein 1979ab9c17a0SJack Morgenstein MLX4_GET(param->qpc_base, outbox, INIT_HCA_QPC_BASE_OFFSET); 1980ab9c17a0SJack Morgenstein MLX4_GET(param->log_num_qps, outbox, INIT_HCA_LOG_QP_OFFSET); 1981ab9c17a0SJack Morgenstein MLX4_GET(param->srqc_base, outbox, INIT_HCA_SRQC_BASE_OFFSET); 1982ab9c17a0SJack Morgenstein MLX4_GET(param->log_num_srqs, outbox, INIT_HCA_LOG_SRQ_OFFSET); 1983ab9c17a0SJack Morgenstein MLX4_GET(param->cqc_base, outbox, INIT_HCA_CQC_BASE_OFFSET); 1984ab9c17a0SJack Morgenstein MLX4_GET(param->log_num_cqs, outbox, INIT_HCA_LOG_CQ_OFFSET); 1985ab9c17a0SJack Morgenstein MLX4_GET(param->altc_base, outbox, INIT_HCA_ALTC_BASE_OFFSET); 1986ab9c17a0SJack Morgenstein MLX4_GET(param->auxc_base, outbox, INIT_HCA_AUXC_BASE_OFFSET); 1987ab9c17a0SJack Morgenstein MLX4_GET(param->eqc_base, outbox, INIT_HCA_EQC_BASE_OFFSET); 1988ab9c17a0SJack Morgenstein MLX4_GET(param->log_num_eqs, outbox, INIT_HCA_LOG_EQ_OFFSET); 19897ae0e400SMatan Barak MLX4_GET(param->num_sys_eqs, outbox, INIT_HCA_NUM_SYS_EQS_OFFSET); 1990ab9c17a0SJack Morgenstein MLX4_GET(param->rdmarc_base, outbox, INIT_HCA_RDMARC_BASE_OFFSET); 1991ab9c17a0SJack Morgenstein MLX4_GET(param->log_rd_per_qp, outbox, INIT_HCA_LOG_RD_OFFSET); 1992ab9c17a0SJack Morgenstein 19937b8157beSJack Morgenstein MLX4_GET(dword_field, outbox, INIT_HCA_FLAGS_OFFSET); 19947b8157beSJack Morgenstein if (dword_field & (1 << INIT_HCA_DEVICE_MANAGED_FLOW_STEERING_EN)) { 19957b8157beSJack Morgenstein param->steering_mode = MLX4_STEERING_MODE_DEVICE_MANAGED; 19967b8157beSJack Morgenstein } else { 19977b8157beSJack Morgenstein MLX4_GET(byte_field, outbox, INIT_HCA_UC_STEERING_OFFSET); 19987b8157beSJack Morgenstein if (byte_field & 0x8) 19997b8157beSJack Morgenstein param->steering_mode = MLX4_STEERING_MODE_B0; 20007b8157beSJack Morgenstein else 20017b8157beSJack Morgenstein param->steering_mode = MLX4_STEERING_MODE_A0; 20027b8157beSJack Morgenstein } 2003802f42a8SIdo Shamay 2004802f42a8SIdo Shamay if (dword_field & (1 << 13)) 2005802f42a8SIdo Shamay param->rss_ip_frags = 1; 2006802f42a8SIdo Shamay 20070ff1fb65SHadar Hen Zion /* steering attributes */ 20087b8157beSJack Morgenstein if (param->steering_mode == MLX4_STEERING_MODE_DEVICE_MANAGED) { 20090ff1fb65SHadar Hen Zion MLX4_GET(param->mc_base, outbox, INIT_HCA_FS_BASE_OFFSET); 20100ff1fb65SHadar Hen Zion MLX4_GET(param->log_mc_entry_sz, outbox, 20110ff1fb65SHadar Hen Zion INIT_HCA_FS_LOG_ENTRY_SZ_OFFSET); 20120ff1fb65SHadar Hen Zion MLX4_GET(param->log_mc_table_sz, outbox, 20130ff1fb65SHadar Hen Zion INIT_HCA_FS_LOG_TABLE_SZ_OFFSET); 20147d077cd3SMatan Barak MLX4_GET(byte_field, outbox, 20157d077cd3SMatan Barak INIT_HCA_FS_A0_OFFSET); 20167d077cd3SMatan Barak param->dmfs_high_steer_mode = 20177d077cd3SMatan Barak a0_dmfs_query_hw_steering[(byte_field >> 6) & 3]; 20180ff1fb65SHadar Hen Zion } else { 2019ab9c17a0SJack Morgenstein MLX4_GET(param->mc_base, outbox, INIT_HCA_MC_BASE_OFFSET); 2020ab9c17a0SJack Morgenstein MLX4_GET(param->log_mc_entry_sz, outbox, 2021ab9c17a0SJack Morgenstein INIT_HCA_LOG_MC_ENTRY_SZ_OFFSET); 2022ab9c17a0SJack Morgenstein MLX4_GET(param->log_mc_hash_sz, outbox, 2023ab9c17a0SJack Morgenstein INIT_HCA_LOG_MC_HASH_SZ_OFFSET); 2024ab9c17a0SJack Morgenstein MLX4_GET(param->log_mc_table_sz, outbox, 2025ab9c17a0SJack Morgenstein INIT_HCA_LOG_MC_TABLE_SZ_OFFSET); 20260ff1fb65SHadar Hen Zion } 2027ab9c17a0SJack Morgenstein 202808ff3235SOr Gerlitz /* CX3 is capable of extending CQEs/EQEs from 32 to 64 bytes */ 202908ff3235SOr Gerlitz MLX4_GET(byte_field, outbox, INIT_HCA_EQE_CQE_OFFSETS); 203008ff3235SOr Gerlitz if (byte_field & 0x20) /* 64-bytes eqe enabled */ 203108ff3235SOr Gerlitz param->dev_cap_enabled |= MLX4_DEV_CAP_64B_EQE_ENABLED; 203208ff3235SOr Gerlitz if (byte_field & 0x40) /* 64-bytes cqe enabled */ 203308ff3235SOr Gerlitz param->dev_cap_enabled |= MLX4_DEV_CAP_64B_CQE_ENABLED; 203408ff3235SOr Gerlitz 203577507aa2SIdo Shamay /* CX3 is capable of extending CQEs\EQEs to strides larger than 64B */ 203677507aa2SIdo Shamay MLX4_GET(byte_field, outbox, INIT_HCA_EQE_CQE_STRIDE_OFFSET); 203777507aa2SIdo Shamay if (byte_field) { 2038c3f2511fSIdo Shamay param->dev_cap_enabled |= MLX4_DEV_CAP_EQE_STRIDE_ENABLED; 2039c3f2511fSIdo Shamay param->dev_cap_enabled |= MLX4_DEV_CAP_CQE_STRIDE_ENABLED; 204077507aa2SIdo Shamay param->cqe_size = 1 << ((byte_field & 204177507aa2SIdo Shamay MLX4_CQE_SIZE_MASK_STRIDE) + 5); 204277507aa2SIdo Shamay param->eqe_size = 1 << (((byte_field & 204377507aa2SIdo Shamay MLX4_EQE_SIZE_MASK_STRIDE) >> 4) + 5); 204477507aa2SIdo Shamay } 204577507aa2SIdo Shamay 2046ab9c17a0SJack Morgenstein /* TPT attributes */ 2047ab9c17a0SJack Morgenstein 2048ab9c17a0SJack Morgenstein MLX4_GET(param->dmpt_base, outbox, INIT_HCA_DMPT_BASE_OFFSET); 2049e448834eSShani Michaeli MLX4_GET(param->mw_enabled, outbox, INIT_HCA_TPT_MW_OFFSET); 2050ab9c17a0SJack Morgenstein MLX4_GET(param->log_mpt_sz, outbox, INIT_HCA_LOG_MPT_SZ_OFFSET); 2051ab9c17a0SJack Morgenstein MLX4_GET(param->mtt_base, outbox, INIT_HCA_MTT_BASE_OFFSET); 2052ab9c17a0SJack Morgenstein MLX4_GET(param->cmpt_base, outbox, INIT_HCA_CMPT_BASE_OFFSET); 2053ab9c17a0SJack Morgenstein 2054ab9c17a0SJack Morgenstein /* UAR attributes */ 2055ab9c17a0SJack Morgenstein 2056ab9c17a0SJack Morgenstein MLX4_GET(param->uar_page_sz, outbox, INIT_HCA_UAR_PAGE_SZ_OFFSET); 2057ab9c17a0SJack Morgenstein MLX4_GET(param->log_uar_sz, outbox, INIT_HCA_LOG_UAR_SZ_OFFSET); 2058ab9c17a0SJack Morgenstein 205977fc29c4SHadar Hen Zion /* phv_check enable */ 206077fc29c4SHadar Hen Zion MLX4_GET(byte_field, outbox, INIT_HCA_CACHELINE_SZ_OFFSET); 206177fc29c4SHadar Hen Zion if (byte_field & 0x2) 206277fc29c4SHadar Hen Zion param->phv_check_en = 1; 2063ab9c17a0SJack Morgenstein out: 2064ab9c17a0SJack Morgenstein mlx4_free_cmd_mailbox(dev, mailbox); 2065ab9c17a0SJack Morgenstein 2066ab9c17a0SJack Morgenstein return err; 2067ab9c17a0SJack Morgenstein } 2068ab9c17a0SJack Morgenstein 20696d6e996cSMajd Dibbiny static int mlx4_hca_core_clock_update(struct mlx4_dev *dev) 20706d6e996cSMajd Dibbiny { 20716d6e996cSMajd Dibbiny struct mlx4_cmd_mailbox *mailbox; 20726d6e996cSMajd Dibbiny __be32 *outbox; 20736d6e996cSMajd Dibbiny int err; 20746d6e996cSMajd Dibbiny 20756d6e996cSMajd Dibbiny mailbox = mlx4_alloc_cmd_mailbox(dev); 20766d6e996cSMajd Dibbiny if (IS_ERR(mailbox)) { 20776d6e996cSMajd Dibbiny mlx4_warn(dev, "hca_core_clock mailbox allocation failed\n"); 20786d6e996cSMajd Dibbiny return PTR_ERR(mailbox); 20796d6e996cSMajd Dibbiny } 20806d6e996cSMajd Dibbiny outbox = mailbox->buf; 20816d6e996cSMajd Dibbiny 20826d6e996cSMajd Dibbiny err = mlx4_cmd_box(dev, 0, mailbox->dma, 0, 0, 20836d6e996cSMajd Dibbiny MLX4_CMD_QUERY_HCA, 20846d6e996cSMajd Dibbiny MLX4_CMD_TIME_CLASS_B, 20856d6e996cSMajd Dibbiny !mlx4_is_slave(dev)); 20866d6e996cSMajd Dibbiny if (err) { 20876d6e996cSMajd Dibbiny mlx4_warn(dev, "hca_core_clock update failed\n"); 20886d6e996cSMajd Dibbiny goto out; 20896d6e996cSMajd Dibbiny } 20906d6e996cSMajd Dibbiny 20916d6e996cSMajd Dibbiny MLX4_GET(dev->caps.hca_core_clock, outbox, QUERY_HCA_CORE_CLOCK_OFFSET); 20926d6e996cSMajd Dibbiny 20936d6e996cSMajd Dibbiny out: 20946d6e996cSMajd Dibbiny mlx4_free_cmd_mailbox(dev, mailbox); 20956d6e996cSMajd Dibbiny 20966d6e996cSMajd Dibbiny return err; 20976d6e996cSMajd Dibbiny } 20986d6e996cSMajd Dibbiny 2099980e9001SJack Morgenstein /* for IB-type ports only in SRIOV mode. Checks that both proxy QP0 2100980e9001SJack Morgenstein * and real QP0 are active, so that the paravirtualized QP0 is ready 2101980e9001SJack Morgenstein * to operate */ 2102980e9001SJack Morgenstein static int check_qp0_state(struct mlx4_dev *dev, int function, int port) 2103980e9001SJack Morgenstein { 2104980e9001SJack Morgenstein struct mlx4_priv *priv = mlx4_priv(dev); 2105980e9001SJack Morgenstein /* irrelevant if not infiniband */ 2106980e9001SJack Morgenstein if (priv->mfunc.master.qp0_state[port].proxy_qp0_active && 2107980e9001SJack Morgenstein priv->mfunc.master.qp0_state[port].qp0_active) 2108980e9001SJack Morgenstein return 1; 2109980e9001SJack Morgenstein return 0; 2110980e9001SJack Morgenstein } 2111980e9001SJack Morgenstein 21125cc914f1SMarcel Apfelbaum int mlx4_INIT_PORT_wrapper(struct mlx4_dev *dev, int slave, 21135cc914f1SMarcel Apfelbaum struct mlx4_vhcr *vhcr, 21145cc914f1SMarcel Apfelbaum struct mlx4_cmd_mailbox *inbox, 21155cc914f1SMarcel Apfelbaum struct mlx4_cmd_mailbox *outbox, 21165cc914f1SMarcel Apfelbaum struct mlx4_cmd_info *cmd) 21175cc914f1SMarcel Apfelbaum { 21185cc914f1SMarcel Apfelbaum struct mlx4_priv *priv = mlx4_priv(dev); 2119449fc488SMatan Barak int port = mlx4_slave_convert_port(dev, slave, vhcr->in_modifier); 21205cc914f1SMarcel Apfelbaum int err; 21215cc914f1SMarcel Apfelbaum 2122449fc488SMatan Barak if (port < 0) 2123449fc488SMatan Barak return -EINVAL; 2124449fc488SMatan Barak 21255cc914f1SMarcel Apfelbaum if (priv->mfunc.master.slave_state[slave].init_port_mask & (1 << port)) 21265cc914f1SMarcel Apfelbaum return 0; 21275cc914f1SMarcel Apfelbaum 2128980e9001SJack Morgenstein if (dev->caps.port_mask[port] != MLX4_PORT_TYPE_IB) { 21295cc914f1SMarcel Apfelbaum /* Enable port only if it was previously disabled */ 21305cc914f1SMarcel Apfelbaum if (!priv->mfunc.master.init_port_ref[port]) { 21315cc914f1SMarcel Apfelbaum err = mlx4_cmd(dev, 0, port, 0, MLX4_CMD_INIT_PORT, 21325cc914f1SMarcel Apfelbaum MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE); 21335cc914f1SMarcel Apfelbaum if (err) 21345cc914f1SMarcel Apfelbaum return err; 21355cc914f1SMarcel Apfelbaum } 21368bac9edeSJack Morgenstein priv->mfunc.master.slave_state[slave].init_port_mask |= (1 << port); 2137980e9001SJack Morgenstein } else { 2138980e9001SJack Morgenstein if (slave == mlx4_master_func_num(dev)) { 2139980e9001SJack Morgenstein if (check_qp0_state(dev, slave, port) && 2140980e9001SJack Morgenstein !priv->mfunc.master.qp0_state[port].port_active) { 2141980e9001SJack Morgenstein err = mlx4_cmd(dev, 0, port, 0, MLX4_CMD_INIT_PORT, 2142980e9001SJack Morgenstein MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE); 2143980e9001SJack Morgenstein if (err) 2144980e9001SJack Morgenstein return err; 2145980e9001SJack Morgenstein priv->mfunc.master.qp0_state[port].port_active = 1; 2146980e9001SJack Morgenstein priv->mfunc.master.slave_state[slave].init_port_mask |= (1 << port); 2147980e9001SJack Morgenstein } 2148980e9001SJack Morgenstein } else 2149980e9001SJack Morgenstein priv->mfunc.master.slave_state[slave].init_port_mask |= (1 << port); 2150980e9001SJack Morgenstein } 21515cc914f1SMarcel Apfelbaum ++priv->mfunc.master.init_port_ref[port]; 21525cc914f1SMarcel Apfelbaum return 0; 21535cc914f1SMarcel Apfelbaum } 21545cc914f1SMarcel Apfelbaum 21555a2cc190SJeff Kirsher int mlx4_INIT_PORT(struct mlx4_dev *dev, int port) 21565a2cc190SJeff Kirsher { 21575a2cc190SJeff Kirsher struct mlx4_cmd_mailbox *mailbox; 21585a2cc190SJeff Kirsher u32 *inbox; 21595a2cc190SJeff Kirsher int err; 21605a2cc190SJeff Kirsher u32 flags; 21615a2cc190SJeff Kirsher u16 field; 21625a2cc190SJeff Kirsher 21635a2cc190SJeff Kirsher if (dev->flags & MLX4_FLAG_OLD_PORT_CMDS) { 21645a2cc190SJeff Kirsher #define INIT_PORT_IN_SIZE 256 21655a2cc190SJeff Kirsher #define INIT_PORT_FLAGS_OFFSET 0x00 21665a2cc190SJeff Kirsher #define INIT_PORT_FLAG_SIG (1 << 18) 21675a2cc190SJeff Kirsher #define INIT_PORT_FLAG_NG (1 << 17) 21685a2cc190SJeff Kirsher #define INIT_PORT_FLAG_G0 (1 << 16) 21695a2cc190SJeff Kirsher #define INIT_PORT_VL_SHIFT 4 21705a2cc190SJeff Kirsher #define INIT_PORT_PORT_WIDTH_SHIFT 8 21715a2cc190SJeff Kirsher #define INIT_PORT_MTU_OFFSET 0x04 21725a2cc190SJeff Kirsher #define INIT_PORT_MAX_GID_OFFSET 0x06 21735a2cc190SJeff Kirsher #define INIT_PORT_MAX_PKEY_OFFSET 0x0a 21745a2cc190SJeff Kirsher #define INIT_PORT_GUID0_OFFSET 0x10 21755a2cc190SJeff Kirsher #define INIT_PORT_NODE_GUID_OFFSET 0x18 21765a2cc190SJeff Kirsher #define INIT_PORT_SI_GUID_OFFSET 0x20 21775a2cc190SJeff Kirsher 21785a2cc190SJeff Kirsher mailbox = mlx4_alloc_cmd_mailbox(dev); 21795a2cc190SJeff Kirsher if (IS_ERR(mailbox)) 21805a2cc190SJeff Kirsher return PTR_ERR(mailbox); 21815a2cc190SJeff Kirsher inbox = mailbox->buf; 21825a2cc190SJeff Kirsher 21835a2cc190SJeff Kirsher flags = 0; 21845a2cc190SJeff Kirsher flags |= (dev->caps.vl_cap[port] & 0xf) << INIT_PORT_VL_SHIFT; 21855a2cc190SJeff Kirsher flags |= (dev->caps.port_width_cap[port] & 0xf) << INIT_PORT_PORT_WIDTH_SHIFT; 21865a2cc190SJeff Kirsher MLX4_PUT(inbox, flags, INIT_PORT_FLAGS_OFFSET); 21875a2cc190SJeff Kirsher 21885a2cc190SJeff Kirsher field = 128 << dev->caps.ib_mtu_cap[port]; 21895a2cc190SJeff Kirsher MLX4_PUT(inbox, field, INIT_PORT_MTU_OFFSET); 21905a2cc190SJeff Kirsher field = dev->caps.gid_table_len[port]; 21915a2cc190SJeff Kirsher MLX4_PUT(inbox, field, INIT_PORT_MAX_GID_OFFSET); 21925a2cc190SJeff Kirsher field = dev->caps.pkey_table_len[port]; 21935a2cc190SJeff Kirsher MLX4_PUT(inbox, field, INIT_PORT_MAX_PKEY_OFFSET); 21945a2cc190SJeff Kirsher 21955a2cc190SJeff Kirsher err = mlx4_cmd(dev, mailbox->dma, port, 0, MLX4_CMD_INIT_PORT, 2196f9baff50SJack Morgenstein MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE); 21975a2cc190SJeff Kirsher 21985a2cc190SJeff Kirsher mlx4_free_cmd_mailbox(dev, mailbox); 21995a2cc190SJeff Kirsher } else 22005a2cc190SJeff Kirsher err = mlx4_cmd(dev, 0, port, 0, MLX4_CMD_INIT_PORT, 2201f9baff50SJack Morgenstein MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED); 22025a2cc190SJeff Kirsher 22036d6e996cSMajd Dibbiny if (!err) 22046d6e996cSMajd Dibbiny mlx4_hca_core_clock_update(dev); 22056d6e996cSMajd Dibbiny 22065a2cc190SJeff Kirsher return err; 22075a2cc190SJeff Kirsher } 22085a2cc190SJeff Kirsher EXPORT_SYMBOL_GPL(mlx4_INIT_PORT); 22095a2cc190SJeff Kirsher 22105cc914f1SMarcel Apfelbaum int mlx4_CLOSE_PORT_wrapper(struct mlx4_dev *dev, int slave, 22115cc914f1SMarcel Apfelbaum struct mlx4_vhcr *vhcr, 22125cc914f1SMarcel Apfelbaum struct mlx4_cmd_mailbox *inbox, 22135cc914f1SMarcel Apfelbaum struct mlx4_cmd_mailbox *outbox, 22145cc914f1SMarcel Apfelbaum struct mlx4_cmd_info *cmd) 22155cc914f1SMarcel Apfelbaum { 22165cc914f1SMarcel Apfelbaum struct mlx4_priv *priv = mlx4_priv(dev); 2217449fc488SMatan Barak int port = mlx4_slave_convert_port(dev, slave, vhcr->in_modifier); 22185cc914f1SMarcel Apfelbaum int err; 22195cc914f1SMarcel Apfelbaum 2220449fc488SMatan Barak if (port < 0) 2221449fc488SMatan Barak return -EINVAL; 2222449fc488SMatan Barak 22235cc914f1SMarcel Apfelbaum if (!(priv->mfunc.master.slave_state[slave].init_port_mask & 22245cc914f1SMarcel Apfelbaum (1 << port))) 22255cc914f1SMarcel Apfelbaum return 0; 22265cc914f1SMarcel Apfelbaum 2227980e9001SJack Morgenstein if (dev->caps.port_mask[port] != MLX4_PORT_TYPE_IB) { 22285cc914f1SMarcel Apfelbaum if (priv->mfunc.master.init_port_ref[port] == 1) { 2229980e9001SJack Morgenstein err = mlx4_cmd(dev, 0, port, 0, MLX4_CMD_CLOSE_PORT, 22305a031086SJack Morgenstein MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE); 22315cc914f1SMarcel Apfelbaum if (err) 22325cc914f1SMarcel Apfelbaum return err; 22335cc914f1SMarcel Apfelbaum } 22345cc914f1SMarcel Apfelbaum priv->mfunc.master.slave_state[slave].init_port_mask &= ~(1 << port); 2235980e9001SJack Morgenstein } else { 2236980e9001SJack Morgenstein /* infiniband port */ 2237980e9001SJack Morgenstein if (slave == mlx4_master_func_num(dev)) { 2238980e9001SJack Morgenstein if (!priv->mfunc.master.qp0_state[port].qp0_active && 2239980e9001SJack Morgenstein priv->mfunc.master.qp0_state[port].port_active) { 2240980e9001SJack Morgenstein err = mlx4_cmd(dev, 0, port, 0, MLX4_CMD_CLOSE_PORT, 22415a031086SJack Morgenstein MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE); 2242980e9001SJack Morgenstein if (err) 2243980e9001SJack Morgenstein return err; 2244980e9001SJack Morgenstein priv->mfunc.master.slave_state[slave].init_port_mask &= ~(1 << port); 2245980e9001SJack Morgenstein priv->mfunc.master.qp0_state[port].port_active = 0; 2246980e9001SJack Morgenstein } 2247980e9001SJack Morgenstein } else 2248980e9001SJack Morgenstein priv->mfunc.master.slave_state[slave].init_port_mask &= ~(1 << port); 2249980e9001SJack Morgenstein } 22505cc914f1SMarcel Apfelbaum --priv->mfunc.master.init_port_ref[port]; 22515cc914f1SMarcel Apfelbaum return 0; 22525cc914f1SMarcel Apfelbaum } 22535cc914f1SMarcel Apfelbaum 22545a2cc190SJeff Kirsher int mlx4_CLOSE_PORT(struct mlx4_dev *dev, int port) 22555a2cc190SJeff Kirsher { 22565a031086SJack Morgenstein return mlx4_cmd(dev, 0, port, 0, MLX4_CMD_CLOSE_PORT, 22575a031086SJack Morgenstein MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED); 22585a2cc190SJeff Kirsher } 22595a2cc190SJeff Kirsher EXPORT_SYMBOL_GPL(mlx4_CLOSE_PORT); 22605a2cc190SJeff Kirsher 22615a2cc190SJeff Kirsher int mlx4_CLOSE_HCA(struct mlx4_dev *dev, int panic) 22625a2cc190SJeff Kirsher { 22635a031086SJack Morgenstein return mlx4_cmd(dev, 0, 0, panic, MLX4_CMD_CLOSE_HCA, 22645a031086SJack Morgenstein MLX4_CMD_TIME_CLASS_C, MLX4_CMD_NATIVE); 22655a2cc190SJeff Kirsher } 22665a2cc190SJeff Kirsher 2267d18f141aSOr Gerlitz struct mlx4_config_dev { 2268d18f141aSOr Gerlitz __be32 update_flags; 2269d475c95bSMatan Barak __be32 rsvd1[3]; 2270d18f141aSOr Gerlitz __be16 vxlan_udp_dport; 2271d18f141aSOr Gerlitz __be16 rsvd2; 2272fca83006SMoni Shoua __be16 roce_v2_entropy; 2273fca83006SMoni Shoua __be16 roce_v2_udp_dport; 227459e14e32SMoni Shoua __be32 roce_flags; 227559e14e32SMoni Shoua __be32 rsvd4[25]; 227659e14e32SMoni Shoua __be16 rsvd5; 227759e14e32SMoni Shoua u8 rsvd6; 2278d475c95bSMatan Barak u8 rx_checksum_val; 2279d18f141aSOr Gerlitz }; 2280d18f141aSOr Gerlitz 2281d18f141aSOr Gerlitz #define MLX4_VXLAN_UDP_DPORT (1 << 0) 2282fca83006SMoni Shoua #define MLX4_ROCE_V2_UDP_DPORT BIT(3) 228359e14e32SMoni Shoua #define MLX4_DISABLE_RX_PORT BIT(18) 2284d18f141aSOr Gerlitz 2285d475c95bSMatan Barak static int mlx4_CONFIG_DEV_set(struct mlx4_dev *dev, struct mlx4_config_dev *config_dev) 2286d18f141aSOr Gerlitz { 2287d18f141aSOr Gerlitz int err; 2288d18f141aSOr Gerlitz struct mlx4_cmd_mailbox *mailbox; 2289d18f141aSOr Gerlitz 2290d18f141aSOr Gerlitz mailbox = mlx4_alloc_cmd_mailbox(dev); 2291d18f141aSOr Gerlitz if (IS_ERR(mailbox)) 2292d18f141aSOr Gerlitz return PTR_ERR(mailbox); 2293d18f141aSOr Gerlitz 2294d18f141aSOr Gerlitz memcpy(mailbox->buf, config_dev, sizeof(*config_dev)); 2295d18f141aSOr Gerlitz 2296d18f141aSOr Gerlitz err = mlx4_cmd(dev, mailbox->dma, 0, 0, MLX4_CMD_CONFIG_DEV, 2297d18f141aSOr Gerlitz MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE); 2298d18f141aSOr Gerlitz 2299d18f141aSOr Gerlitz mlx4_free_cmd_mailbox(dev, mailbox); 2300d18f141aSOr Gerlitz return err; 2301d18f141aSOr Gerlitz } 2302d18f141aSOr Gerlitz 2303d475c95bSMatan Barak static int mlx4_CONFIG_DEV_get(struct mlx4_dev *dev, struct mlx4_config_dev *config_dev) 2304d475c95bSMatan Barak { 2305d475c95bSMatan Barak int err; 2306d475c95bSMatan Barak struct mlx4_cmd_mailbox *mailbox; 2307d475c95bSMatan Barak 2308d475c95bSMatan Barak mailbox = mlx4_alloc_cmd_mailbox(dev); 2309d475c95bSMatan Barak if (IS_ERR(mailbox)) 2310d475c95bSMatan Barak return PTR_ERR(mailbox); 2311d475c95bSMatan Barak 2312d475c95bSMatan Barak err = mlx4_cmd_box(dev, 0, mailbox->dma, 0, 1, MLX4_CMD_CONFIG_DEV, 2313d475c95bSMatan Barak MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE); 2314d475c95bSMatan Barak 2315d475c95bSMatan Barak if (!err) 2316d475c95bSMatan Barak memcpy(config_dev, mailbox->buf, sizeof(*config_dev)); 2317d475c95bSMatan Barak 2318d475c95bSMatan Barak mlx4_free_cmd_mailbox(dev, mailbox); 2319d475c95bSMatan Barak return err; 2320d475c95bSMatan Barak } 2321d475c95bSMatan Barak 2322d475c95bSMatan Barak /* Conversion between the HW values and the actual functionality. 2323d475c95bSMatan Barak * The value represented by the array index, 2324d475c95bSMatan Barak * and the functionality determined by the flags. 2325d475c95bSMatan Barak */ 2326d475c95bSMatan Barak static const u8 config_dev_csum_flags[] = { 2327d475c95bSMatan Barak [0] = 0, 2328d475c95bSMatan Barak [1] = MLX4_RX_CSUM_MODE_VAL_NON_TCP_UDP, 2329d475c95bSMatan Barak [2] = MLX4_RX_CSUM_MODE_VAL_NON_TCP_UDP | 2330d475c95bSMatan Barak MLX4_RX_CSUM_MODE_L4, 2331d475c95bSMatan Barak [3] = MLX4_RX_CSUM_MODE_L4 | 2332d475c95bSMatan Barak MLX4_RX_CSUM_MODE_IP_OK_IP_NON_TCP_UDP | 2333d475c95bSMatan Barak MLX4_RX_CSUM_MODE_MULTI_VLAN 2334d475c95bSMatan Barak }; 2335d475c95bSMatan Barak 2336d475c95bSMatan Barak int mlx4_config_dev_retrieval(struct mlx4_dev *dev, 2337d475c95bSMatan Barak struct mlx4_config_dev_params *params) 2338d475c95bSMatan Barak { 23396af0a52fSMaor Gottlieb struct mlx4_config_dev config_dev = {0}; 2340d475c95bSMatan Barak int err; 2341d475c95bSMatan Barak u8 csum_mask; 2342d475c95bSMatan Barak 2343d475c95bSMatan Barak #define CONFIG_DEV_RX_CSUM_MODE_MASK 0x7 2344d475c95bSMatan Barak #define CONFIG_DEV_RX_CSUM_MODE_PORT1_BIT_OFFSET 0 2345d475c95bSMatan Barak #define CONFIG_DEV_RX_CSUM_MODE_PORT2_BIT_OFFSET 4 2346d475c95bSMatan Barak 2347d475c95bSMatan Barak if (!(dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_CONFIG_DEV)) 2348d475c95bSMatan Barak return -ENOTSUPP; 2349d475c95bSMatan Barak 2350d475c95bSMatan Barak err = mlx4_CONFIG_DEV_get(dev, &config_dev); 2351d475c95bSMatan Barak if (err) 2352d475c95bSMatan Barak return err; 2353d475c95bSMatan Barak 2354d475c95bSMatan Barak csum_mask = (config_dev.rx_checksum_val >> CONFIG_DEV_RX_CSUM_MODE_PORT1_BIT_OFFSET) & 2355d475c95bSMatan Barak CONFIG_DEV_RX_CSUM_MODE_MASK; 2356d475c95bSMatan Barak 2357d475c95bSMatan Barak if (csum_mask >= sizeof(config_dev_csum_flags)/sizeof(config_dev_csum_flags[0])) 2358d475c95bSMatan Barak return -EINVAL; 2359d475c95bSMatan Barak params->rx_csum_flags_port_1 = config_dev_csum_flags[csum_mask]; 2360d475c95bSMatan Barak 2361d475c95bSMatan Barak csum_mask = (config_dev.rx_checksum_val >> CONFIG_DEV_RX_CSUM_MODE_PORT2_BIT_OFFSET) & 2362d475c95bSMatan Barak CONFIG_DEV_RX_CSUM_MODE_MASK; 2363d475c95bSMatan Barak 2364d475c95bSMatan Barak if (csum_mask >= sizeof(config_dev_csum_flags)/sizeof(config_dev_csum_flags[0])) 2365d475c95bSMatan Barak return -EINVAL; 2366d475c95bSMatan Barak params->rx_csum_flags_port_2 = config_dev_csum_flags[csum_mask]; 2367d475c95bSMatan Barak 2368d475c95bSMatan Barak params->vxlan_udp_dport = be16_to_cpu(config_dev.vxlan_udp_dport); 2369d475c95bSMatan Barak 2370d475c95bSMatan Barak return 0; 2371d475c95bSMatan Barak } 2372d475c95bSMatan Barak EXPORT_SYMBOL_GPL(mlx4_config_dev_retrieval); 2373d475c95bSMatan Barak 2374d18f141aSOr Gerlitz int mlx4_config_vxlan_port(struct mlx4_dev *dev, __be16 udp_port) 2375d18f141aSOr Gerlitz { 2376d18f141aSOr Gerlitz struct mlx4_config_dev config_dev; 2377d18f141aSOr Gerlitz 2378d18f141aSOr Gerlitz memset(&config_dev, 0, sizeof(config_dev)); 2379d18f141aSOr Gerlitz config_dev.update_flags = cpu_to_be32(MLX4_VXLAN_UDP_DPORT); 2380d18f141aSOr Gerlitz config_dev.vxlan_udp_dport = udp_port; 2381d18f141aSOr Gerlitz 2382d475c95bSMatan Barak return mlx4_CONFIG_DEV_set(dev, &config_dev); 2383d18f141aSOr Gerlitz } 2384d18f141aSOr Gerlitz EXPORT_SYMBOL_GPL(mlx4_config_vxlan_port); 2385d18f141aSOr Gerlitz 238659e14e32SMoni Shoua #define CONFIG_DISABLE_RX_PORT BIT(15) 238759e14e32SMoni Shoua int mlx4_disable_rx_port_check(struct mlx4_dev *dev, bool dis) 238859e14e32SMoni Shoua { 238959e14e32SMoni Shoua struct mlx4_config_dev config_dev; 239059e14e32SMoni Shoua 239159e14e32SMoni Shoua memset(&config_dev, 0, sizeof(config_dev)); 239259e14e32SMoni Shoua config_dev.update_flags = cpu_to_be32(MLX4_DISABLE_RX_PORT); 239359e14e32SMoni Shoua if (dis) 239459e14e32SMoni Shoua config_dev.roce_flags = 239559e14e32SMoni Shoua cpu_to_be32(CONFIG_DISABLE_RX_PORT); 239659e14e32SMoni Shoua 239759e14e32SMoni Shoua return mlx4_CONFIG_DEV_set(dev, &config_dev); 239859e14e32SMoni Shoua } 239959e14e32SMoni Shoua 2400fca83006SMoni Shoua int mlx4_config_roce_v2_port(struct mlx4_dev *dev, u16 udp_port) 2401fca83006SMoni Shoua { 2402fca83006SMoni Shoua struct mlx4_config_dev config_dev; 2403fca83006SMoni Shoua 2404fca83006SMoni Shoua memset(&config_dev, 0, sizeof(config_dev)); 2405fca83006SMoni Shoua config_dev.update_flags = cpu_to_be32(MLX4_ROCE_V2_UDP_DPORT); 2406fca83006SMoni Shoua config_dev.roce_v2_udp_dport = cpu_to_be16(udp_port); 2407fca83006SMoni Shoua 2408fca83006SMoni Shoua return mlx4_CONFIG_DEV_set(dev, &config_dev); 2409fca83006SMoni Shoua } 2410fca83006SMoni Shoua EXPORT_SYMBOL_GPL(mlx4_config_roce_v2_port); 2411fca83006SMoni Shoua 241259e14e32SMoni Shoua int mlx4_virt2phy_port_map(struct mlx4_dev *dev, u32 port1, u32 port2) 241359e14e32SMoni Shoua { 241459e14e32SMoni Shoua struct mlx4_cmd_mailbox *mailbox; 241559e14e32SMoni Shoua struct { 241659e14e32SMoni Shoua __be32 v_port1; 241759e14e32SMoni Shoua __be32 v_port2; 241859e14e32SMoni Shoua } *v2p; 241959e14e32SMoni Shoua int err; 242059e14e32SMoni Shoua 242159e14e32SMoni Shoua mailbox = mlx4_alloc_cmd_mailbox(dev); 242259e14e32SMoni Shoua if (IS_ERR(mailbox)) 242359e14e32SMoni Shoua return -ENOMEM; 242459e14e32SMoni Shoua 242559e14e32SMoni Shoua v2p = mailbox->buf; 242659e14e32SMoni Shoua v2p->v_port1 = cpu_to_be32(port1); 242759e14e32SMoni Shoua v2p->v_port2 = cpu_to_be32(port2); 242859e14e32SMoni Shoua 242959e14e32SMoni Shoua err = mlx4_cmd(dev, mailbox->dma, 0, 243059e14e32SMoni Shoua MLX4_SET_PORT_VIRT2PHY, MLX4_CMD_VIRT_PORT_MAP, 243159e14e32SMoni Shoua MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE); 243259e14e32SMoni Shoua 243359e14e32SMoni Shoua mlx4_free_cmd_mailbox(dev, mailbox); 243459e14e32SMoni Shoua return err; 243559e14e32SMoni Shoua } 243659e14e32SMoni Shoua 2437d18f141aSOr Gerlitz 24385a2cc190SJeff Kirsher int mlx4_SET_ICM_SIZE(struct mlx4_dev *dev, u64 icm_size, u64 *aux_pages) 24395a2cc190SJeff Kirsher { 24405a2cc190SJeff Kirsher int ret = mlx4_cmd_imm(dev, icm_size, aux_pages, 0, 0, 24415a2cc190SJeff Kirsher MLX4_CMD_SET_ICM_SIZE, 2442f9baff50SJack Morgenstein MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE); 24435a2cc190SJeff Kirsher if (ret) 24445a2cc190SJeff Kirsher return ret; 24455a2cc190SJeff Kirsher 24465a2cc190SJeff Kirsher /* 24475a2cc190SJeff Kirsher * Round up number of system pages needed in case 24485a2cc190SJeff Kirsher * MLX4_ICM_PAGE_SIZE < PAGE_SIZE. 24495a2cc190SJeff Kirsher */ 24505a2cc190SJeff Kirsher *aux_pages = ALIGN(*aux_pages, PAGE_SIZE / MLX4_ICM_PAGE_SIZE) >> 24515a2cc190SJeff Kirsher (PAGE_SHIFT - MLX4_ICM_PAGE_SHIFT); 24525a2cc190SJeff Kirsher 24535a2cc190SJeff Kirsher return 0; 24545a2cc190SJeff Kirsher } 24555a2cc190SJeff Kirsher 24565a2cc190SJeff Kirsher int mlx4_NOP(struct mlx4_dev *dev) 24575a2cc190SJeff Kirsher { 24585a2cc190SJeff Kirsher /* Input modifier of 0x1f means "finish as soon as possible." */ 24595a031086SJack Morgenstein return mlx4_cmd(dev, 0, 0x1f, 0, MLX4_CMD_NOP, MLX4_CMD_TIME_CLASS_A, 24605a031086SJack Morgenstein MLX4_CMD_NATIVE); 24615a2cc190SJeff Kirsher } 24625a2cc190SJeff Kirsher 24638e1a28e8SHadar Hen Zion int mlx4_get_phys_port_id(struct mlx4_dev *dev) 24648e1a28e8SHadar Hen Zion { 24658e1a28e8SHadar Hen Zion u8 port; 24668e1a28e8SHadar Hen Zion u32 *outbox; 24678e1a28e8SHadar Hen Zion struct mlx4_cmd_mailbox *mailbox; 24688e1a28e8SHadar Hen Zion u32 in_mod; 24698e1a28e8SHadar Hen Zion u32 guid_hi, guid_lo; 24708e1a28e8SHadar Hen Zion int err, ret = 0; 24718e1a28e8SHadar Hen Zion #define MOD_STAT_CFG_PORT_OFFSET 8 24728e1a28e8SHadar Hen Zion #define MOD_STAT_CFG_GUID_H 0X14 24738e1a28e8SHadar Hen Zion #define MOD_STAT_CFG_GUID_L 0X1c 24748e1a28e8SHadar Hen Zion 24758e1a28e8SHadar Hen Zion mailbox = mlx4_alloc_cmd_mailbox(dev); 24768e1a28e8SHadar Hen Zion if (IS_ERR(mailbox)) 24778e1a28e8SHadar Hen Zion return PTR_ERR(mailbox); 24788e1a28e8SHadar Hen Zion outbox = mailbox->buf; 24798e1a28e8SHadar Hen Zion 24808e1a28e8SHadar Hen Zion for (port = 1; port <= dev->caps.num_ports; port++) { 24818e1a28e8SHadar Hen Zion in_mod = port << MOD_STAT_CFG_PORT_OFFSET; 24828e1a28e8SHadar Hen Zion err = mlx4_cmd_box(dev, 0, mailbox->dma, in_mod, 0x2, 24838e1a28e8SHadar Hen Zion MLX4_CMD_MOD_STAT_CFG, MLX4_CMD_TIME_CLASS_A, 24848e1a28e8SHadar Hen Zion MLX4_CMD_NATIVE); 24858e1a28e8SHadar Hen Zion if (err) { 24868e1a28e8SHadar Hen Zion mlx4_err(dev, "Fail to get port %d uplink guid\n", 24878e1a28e8SHadar Hen Zion port); 24888e1a28e8SHadar Hen Zion ret = err; 24898e1a28e8SHadar Hen Zion } else { 24908e1a28e8SHadar Hen Zion MLX4_GET(guid_hi, outbox, MOD_STAT_CFG_GUID_H); 24918e1a28e8SHadar Hen Zion MLX4_GET(guid_lo, outbox, MOD_STAT_CFG_GUID_L); 24928e1a28e8SHadar Hen Zion dev->caps.phys_port_id[port] = (u64)guid_lo | 24938e1a28e8SHadar Hen Zion (u64)guid_hi << 32; 24948e1a28e8SHadar Hen Zion } 24958e1a28e8SHadar Hen Zion } 24968e1a28e8SHadar Hen Zion mlx4_free_cmd_mailbox(dev, mailbox); 24978e1a28e8SHadar Hen Zion return ret; 24988e1a28e8SHadar Hen Zion } 24998e1a28e8SHadar Hen Zion 25005a2cc190SJeff Kirsher #define MLX4_WOL_SETUP_MODE (5 << 28) 25015a2cc190SJeff Kirsher int mlx4_wol_read(struct mlx4_dev *dev, u64 *config, int port) 25025a2cc190SJeff Kirsher { 25035a2cc190SJeff Kirsher u32 in_mod = MLX4_WOL_SETUP_MODE | port << 8; 25045a2cc190SJeff Kirsher 25055a2cc190SJeff Kirsher return mlx4_cmd_imm(dev, 0, config, in_mod, 0x3, 2506f9baff50SJack Morgenstein MLX4_CMD_MOD_STAT_CFG, MLX4_CMD_TIME_CLASS_A, 2507f9baff50SJack Morgenstein MLX4_CMD_NATIVE); 25085a2cc190SJeff Kirsher } 25095a2cc190SJeff Kirsher EXPORT_SYMBOL_GPL(mlx4_wol_read); 25105a2cc190SJeff Kirsher 25115a2cc190SJeff Kirsher int mlx4_wol_write(struct mlx4_dev *dev, u64 config, int port) 25125a2cc190SJeff Kirsher { 25135a2cc190SJeff Kirsher u32 in_mod = MLX4_WOL_SETUP_MODE | port << 8; 25145a2cc190SJeff Kirsher 25155a2cc190SJeff Kirsher return mlx4_cmd(dev, config, in_mod, 0x1, MLX4_CMD_MOD_STAT_CFG, 2516f9baff50SJack Morgenstein MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE); 25175a2cc190SJeff Kirsher } 25185a2cc190SJeff Kirsher EXPORT_SYMBOL_GPL(mlx4_wol_write); 2519fe6f700dSYevgeny Petrilin 2520fe6f700dSYevgeny Petrilin enum { 2521fe6f700dSYevgeny Petrilin ADD_TO_MCG = 0x26, 2522fe6f700dSYevgeny Petrilin }; 2523fe6f700dSYevgeny Petrilin 2524fe6f700dSYevgeny Petrilin 2525fe6f700dSYevgeny Petrilin void mlx4_opreq_action(struct work_struct *work) 2526fe6f700dSYevgeny Petrilin { 2527fe6f700dSYevgeny Petrilin struct mlx4_priv *priv = container_of(work, struct mlx4_priv, 2528fe6f700dSYevgeny Petrilin opreq_task); 2529fe6f700dSYevgeny Petrilin struct mlx4_dev *dev = &priv->dev; 2530fe6f700dSYevgeny Petrilin int num_tasks = atomic_read(&priv->opreq_count); 2531fe6f700dSYevgeny Petrilin struct mlx4_cmd_mailbox *mailbox; 2532fe6f700dSYevgeny Petrilin struct mlx4_mgm *mgm; 2533fe6f700dSYevgeny Petrilin u32 *outbox; 2534fe6f700dSYevgeny Petrilin u32 modifier; 2535fe6f700dSYevgeny Petrilin u16 token; 2536fe6f700dSYevgeny Petrilin u16 type; 2537fe6f700dSYevgeny Petrilin int err; 2538fe6f700dSYevgeny Petrilin u32 num_qps; 2539fe6f700dSYevgeny Petrilin struct mlx4_qp qp; 2540fe6f700dSYevgeny Petrilin int i; 2541fe6f700dSYevgeny Petrilin u8 rem_mcg; 2542fe6f700dSYevgeny Petrilin u8 prot; 2543fe6f700dSYevgeny Petrilin 2544fe6f700dSYevgeny Petrilin #define GET_OP_REQ_MODIFIER_OFFSET 0x08 2545fe6f700dSYevgeny Petrilin #define GET_OP_REQ_TOKEN_OFFSET 0x14 2546fe6f700dSYevgeny Petrilin #define GET_OP_REQ_TYPE_OFFSET 0x1a 2547fe6f700dSYevgeny Petrilin #define GET_OP_REQ_DATA_OFFSET 0x20 2548fe6f700dSYevgeny Petrilin 2549fe6f700dSYevgeny Petrilin mailbox = mlx4_alloc_cmd_mailbox(dev); 2550fe6f700dSYevgeny Petrilin if (IS_ERR(mailbox)) { 2551fe6f700dSYevgeny Petrilin mlx4_err(dev, "Failed to allocate mailbox for GET_OP_REQ\n"); 2552fe6f700dSYevgeny Petrilin return; 2553fe6f700dSYevgeny Petrilin } 2554fe6f700dSYevgeny Petrilin outbox = mailbox->buf; 2555fe6f700dSYevgeny Petrilin 2556fe6f700dSYevgeny Petrilin while (num_tasks) { 2557fe6f700dSYevgeny Petrilin err = mlx4_cmd_box(dev, 0, mailbox->dma, 0, 0, 2558fe6f700dSYevgeny Petrilin MLX4_CMD_GET_OP_REQ, MLX4_CMD_TIME_CLASS_A, 2559fe6f700dSYevgeny Petrilin MLX4_CMD_NATIVE); 2560fe6f700dSYevgeny Petrilin if (err) { 25616d3be300SMasanari Iida mlx4_err(dev, "Failed to retrieve required operation: %d\n", 2562fe6f700dSYevgeny Petrilin err); 2563fe6f700dSYevgeny Petrilin return; 2564fe6f700dSYevgeny Petrilin } 2565fe6f700dSYevgeny Petrilin MLX4_GET(modifier, outbox, GET_OP_REQ_MODIFIER_OFFSET); 2566fe6f700dSYevgeny Petrilin MLX4_GET(token, outbox, GET_OP_REQ_TOKEN_OFFSET); 2567fe6f700dSYevgeny Petrilin MLX4_GET(type, outbox, GET_OP_REQ_TYPE_OFFSET); 2568fe6f700dSYevgeny Petrilin type &= 0xfff; 2569fe6f700dSYevgeny Petrilin 2570fe6f700dSYevgeny Petrilin switch (type) { 2571fe6f700dSYevgeny Petrilin case ADD_TO_MCG: 2572fe6f700dSYevgeny Petrilin if (dev->caps.steering_mode == 2573fe6f700dSYevgeny Petrilin MLX4_STEERING_MODE_DEVICE_MANAGED) { 2574fe6f700dSYevgeny Petrilin mlx4_warn(dev, "ADD MCG operation is not supported in DEVICE_MANAGED steering mode\n"); 2575fe6f700dSYevgeny Petrilin err = EPERM; 2576fe6f700dSYevgeny Petrilin break; 2577fe6f700dSYevgeny Petrilin } 2578fe6f700dSYevgeny Petrilin mgm = (struct mlx4_mgm *)((u8 *)(outbox) + 2579fe6f700dSYevgeny Petrilin GET_OP_REQ_DATA_OFFSET); 2580fe6f700dSYevgeny Petrilin num_qps = be32_to_cpu(mgm->members_count) & 2581fe6f700dSYevgeny Petrilin MGM_QPN_MASK; 2582fe6f700dSYevgeny Petrilin rem_mcg = ((u8 *)(&mgm->members_count))[0] & 1; 2583fe6f700dSYevgeny Petrilin prot = ((u8 *)(&mgm->members_count))[0] >> 6; 2584fe6f700dSYevgeny Petrilin 2585fe6f700dSYevgeny Petrilin for (i = 0; i < num_qps; i++) { 2586fe6f700dSYevgeny Petrilin qp.qpn = be32_to_cpu(mgm->qp[i]); 2587fe6f700dSYevgeny Petrilin if (rem_mcg) 2588fe6f700dSYevgeny Petrilin err = mlx4_multicast_detach(dev, &qp, 2589fe6f700dSYevgeny Petrilin mgm->gid, 2590fe6f700dSYevgeny Petrilin prot, 0); 2591fe6f700dSYevgeny Petrilin else 2592fe6f700dSYevgeny Petrilin err = mlx4_multicast_attach(dev, &qp, 2593fe6f700dSYevgeny Petrilin mgm->gid, 2594fe6f700dSYevgeny Petrilin mgm->gid[5] 2595fe6f700dSYevgeny Petrilin , 0, prot, 2596fe6f700dSYevgeny Petrilin NULL); 2597fe6f700dSYevgeny Petrilin if (err) 2598fe6f700dSYevgeny Petrilin break; 2599fe6f700dSYevgeny Petrilin } 2600fe6f700dSYevgeny Petrilin break; 2601fe6f700dSYevgeny Petrilin default: 2602fe6f700dSYevgeny Petrilin mlx4_warn(dev, "Bad type for required operation\n"); 2603fe6f700dSYevgeny Petrilin err = EINVAL; 2604fe6f700dSYevgeny Petrilin break; 2605fe6f700dSYevgeny Petrilin } 260628d222bbSEyal Perry err = mlx4_cmd(dev, 0, ((u32) err | 260728d222bbSEyal Perry (__force u32)cpu_to_be32(token) << 16), 2608fe6f700dSYevgeny Petrilin 1, MLX4_CMD_GET_OP_REQ, MLX4_CMD_TIME_CLASS_A, 2609fe6f700dSYevgeny Petrilin MLX4_CMD_NATIVE); 2610fe6f700dSYevgeny Petrilin if (err) { 2611fe6f700dSYevgeny Petrilin mlx4_err(dev, "Failed to acknowledge required request: %d\n", 2612fe6f700dSYevgeny Petrilin err); 2613fe6f700dSYevgeny Petrilin goto out; 2614fe6f700dSYevgeny Petrilin } 2615fe6f700dSYevgeny Petrilin memset(outbox, 0, 0xffc); 2616fe6f700dSYevgeny Petrilin num_tasks = atomic_dec_return(&priv->opreq_count); 2617fe6f700dSYevgeny Petrilin } 2618fe6f700dSYevgeny Petrilin 2619fe6f700dSYevgeny Petrilin out: 2620fe6f700dSYevgeny Petrilin mlx4_free_cmd_mailbox(dev, mailbox); 2621fe6f700dSYevgeny Petrilin } 2622114840c3SJack Morgenstein 2623114840c3SJack Morgenstein static int mlx4_check_smp_firewall_active(struct mlx4_dev *dev, 2624114840c3SJack Morgenstein struct mlx4_cmd_mailbox *mailbox) 2625114840c3SJack Morgenstein { 2626114840c3SJack Morgenstein #define MLX4_CMD_MAD_DEMUX_SET_ATTR_OFFSET 0x10 2627114840c3SJack Morgenstein #define MLX4_CMD_MAD_DEMUX_GETRESP_ATTR_OFFSET 0x20 2628114840c3SJack Morgenstein #define MLX4_CMD_MAD_DEMUX_TRAP_ATTR_OFFSET 0x40 2629114840c3SJack Morgenstein #define MLX4_CMD_MAD_DEMUX_TRAP_REPRESS_ATTR_OFFSET 0x70 2630114840c3SJack Morgenstein 2631114840c3SJack Morgenstein u32 set_attr_mask, getresp_attr_mask; 2632114840c3SJack Morgenstein u32 trap_attr_mask, traprepress_attr_mask; 2633114840c3SJack Morgenstein 2634114840c3SJack Morgenstein MLX4_GET(set_attr_mask, mailbox->buf, 2635114840c3SJack Morgenstein MLX4_CMD_MAD_DEMUX_SET_ATTR_OFFSET); 2636114840c3SJack Morgenstein mlx4_dbg(dev, "SMP firewall set_attribute_mask = 0x%x\n", 2637114840c3SJack Morgenstein set_attr_mask); 2638114840c3SJack Morgenstein 2639114840c3SJack Morgenstein MLX4_GET(getresp_attr_mask, mailbox->buf, 2640114840c3SJack Morgenstein MLX4_CMD_MAD_DEMUX_GETRESP_ATTR_OFFSET); 2641114840c3SJack Morgenstein mlx4_dbg(dev, "SMP firewall getresp_attribute_mask = 0x%x\n", 2642114840c3SJack Morgenstein getresp_attr_mask); 2643114840c3SJack Morgenstein 2644114840c3SJack Morgenstein MLX4_GET(trap_attr_mask, mailbox->buf, 2645114840c3SJack Morgenstein MLX4_CMD_MAD_DEMUX_TRAP_ATTR_OFFSET); 2646114840c3SJack Morgenstein mlx4_dbg(dev, "SMP firewall trap_attribute_mask = 0x%x\n", 2647114840c3SJack Morgenstein trap_attr_mask); 2648114840c3SJack Morgenstein 2649114840c3SJack Morgenstein MLX4_GET(traprepress_attr_mask, mailbox->buf, 2650114840c3SJack Morgenstein MLX4_CMD_MAD_DEMUX_TRAP_REPRESS_ATTR_OFFSET); 2651114840c3SJack Morgenstein mlx4_dbg(dev, "SMP firewall traprepress_attribute_mask = 0x%x\n", 2652114840c3SJack Morgenstein traprepress_attr_mask); 2653114840c3SJack Morgenstein 2654114840c3SJack Morgenstein if (set_attr_mask && getresp_attr_mask && trap_attr_mask && 2655114840c3SJack Morgenstein traprepress_attr_mask) 2656114840c3SJack Morgenstein return 1; 2657114840c3SJack Morgenstein 2658114840c3SJack Morgenstein return 0; 2659114840c3SJack Morgenstein } 2660114840c3SJack Morgenstein 2661114840c3SJack Morgenstein int mlx4_config_mad_demux(struct mlx4_dev *dev) 2662114840c3SJack Morgenstein { 2663114840c3SJack Morgenstein struct mlx4_cmd_mailbox *mailbox; 2664114840c3SJack Morgenstein int secure_host_active; 2665114840c3SJack Morgenstein int err; 2666114840c3SJack Morgenstein 2667114840c3SJack Morgenstein /* Check if mad_demux is supported */ 2668114840c3SJack Morgenstein if (!(dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_MAD_DEMUX)) 2669114840c3SJack Morgenstein return 0; 2670114840c3SJack Morgenstein 2671114840c3SJack Morgenstein mailbox = mlx4_alloc_cmd_mailbox(dev); 2672114840c3SJack Morgenstein if (IS_ERR(mailbox)) { 2673114840c3SJack Morgenstein mlx4_warn(dev, "Failed to allocate mailbox for cmd MAD_DEMUX"); 2674114840c3SJack Morgenstein return -ENOMEM; 2675114840c3SJack Morgenstein } 2676114840c3SJack Morgenstein 2677114840c3SJack Morgenstein /* Query mad_demux to find out which MADs are handled by internal sma */ 2678114840c3SJack Morgenstein err = mlx4_cmd_box(dev, 0, mailbox->dma, 0x01 /* subn mgmt class */, 2679114840c3SJack Morgenstein MLX4_CMD_MAD_DEMUX_QUERY_RESTR, MLX4_CMD_MAD_DEMUX, 2680114840c3SJack Morgenstein MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE); 2681114840c3SJack Morgenstein if (err) { 2682114840c3SJack Morgenstein mlx4_warn(dev, "MLX4_CMD_MAD_DEMUX: query restrictions failed (%d)\n", 2683114840c3SJack Morgenstein err); 2684114840c3SJack Morgenstein goto out; 2685114840c3SJack Morgenstein } 2686114840c3SJack Morgenstein 2687114840c3SJack Morgenstein secure_host_active = mlx4_check_smp_firewall_active(dev, mailbox); 2688114840c3SJack Morgenstein 2689114840c3SJack Morgenstein /* Config mad_demux to handle all MADs returned by the query above */ 2690114840c3SJack Morgenstein err = mlx4_cmd(dev, mailbox->dma, 0x01 /* subn mgmt class */, 2691114840c3SJack Morgenstein MLX4_CMD_MAD_DEMUX_CONFIG, MLX4_CMD_MAD_DEMUX, 2692114840c3SJack Morgenstein MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE); 2693114840c3SJack Morgenstein if (err) { 2694114840c3SJack Morgenstein mlx4_warn(dev, "MLX4_CMD_MAD_DEMUX: configure failed (%d)\n", err); 2695114840c3SJack Morgenstein goto out; 2696114840c3SJack Morgenstein } 2697114840c3SJack Morgenstein 2698114840c3SJack Morgenstein if (secure_host_active) 2699114840c3SJack Morgenstein mlx4_warn(dev, "HCA operating in secure-host mode. SMP firewall activated.\n"); 2700114840c3SJack Morgenstein out: 2701114840c3SJack Morgenstein mlx4_free_cmd_mailbox(dev, mailbox); 2702114840c3SJack Morgenstein return err; 2703114840c3SJack Morgenstein } 2704adbc7ac5SSaeed Mahameed 2705adbc7ac5SSaeed Mahameed /* Access Reg commands */ 2706adbc7ac5SSaeed Mahameed enum mlx4_access_reg_masks { 2707adbc7ac5SSaeed Mahameed MLX4_ACCESS_REG_STATUS_MASK = 0x7f, 2708adbc7ac5SSaeed Mahameed MLX4_ACCESS_REG_METHOD_MASK = 0x7f, 2709adbc7ac5SSaeed Mahameed MLX4_ACCESS_REG_LEN_MASK = 0x7ff 2710adbc7ac5SSaeed Mahameed }; 2711adbc7ac5SSaeed Mahameed 2712adbc7ac5SSaeed Mahameed struct mlx4_access_reg { 2713adbc7ac5SSaeed Mahameed __be16 constant1; 2714adbc7ac5SSaeed Mahameed u8 status; 2715adbc7ac5SSaeed Mahameed u8 resrvd1; 2716adbc7ac5SSaeed Mahameed __be16 reg_id; 2717adbc7ac5SSaeed Mahameed u8 method; 2718adbc7ac5SSaeed Mahameed u8 constant2; 2719adbc7ac5SSaeed Mahameed __be32 resrvd2[2]; 2720adbc7ac5SSaeed Mahameed __be16 len_const; 2721adbc7ac5SSaeed Mahameed __be16 resrvd3; 2722adbc7ac5SSaeed Mahameed #define MLX4_ACCESS_REG_HEADER_SIZE (20) 2723adbc7ac5SSaeed Mahameed u8 reg_data[MLX4_MAILBOX_SIZE-MLX4_ACCESS_REG_HEADER_SIZE]; 2724adbc7ac5SSaeed Mahameed } __attribute__((__packed__)); 2725adbc7ac5SSaeed Mahameed 2726adbc7ac5SSaeed Mahameed /** 2727adbc7ac5SSaeed Mahameed * mlx4_ACCESS_REG - Generic access reg command. 2728adbc7ac5SSaeed Mahameed * @dev: mlx4_dev. 2729adbc7ac5SSaeed Mahameed * @reg_id: register ID to access. 2730adbc7ac5SSaeed Mahameed * @method: Access method Read/Write. 2731adbc7ac5SSaeed Mahameed * @reg_len: register length to Read/Write in bytes. 2732adbc7ac5SSaeed Mahameed * @reg_data: reg_data pointer to Read/Write From/To. 2733adbc7ac5SSaeed Mahameed * 2734adbc7ac5SSaeed Mahameed * Access ConnectX registers FW command. 2735adbc7ac5SSaeed Mahameed * Returns 0 on success and copies outbox mlx4_access_reg data 2736adbc7ac5SSaeed Mahameed * field into reg_data or a negative error code. 2737adbc7ac5SSaeed Mahameed */ 2738adbc7ac5SSaeed Mahameed static int mlx4_ACCESS_REG(struct mlx4_dev *dev, u16 reg_id, 2739adbc7ac5SSaeed Mahameed enum mlx4_access_reg_method method, 2740adbc7ac5SSaeed Mahameed u16 reg_len, void *reg_data) 2741adbc7ac5SSaeed Mahameed { 2742adbc7ac5SSaeed Mahameed struct mlx4_cmd_mailbox *inbox, *outbox; 2743adbc7ac5SSaeed Mahameed struct mlx4_access_reg *inbuf, *outbuf; 2744adbc7ac5SSaeed Mahameed int err; 2745adbc7ac5SSaeed Mahameed 2746adbc7ac5SSaeed Mahameed inbox = mlx4_alloc_cmd_mailbox(dev); 2747adbc7ac5SSaeed Mahameed if (IS_ERR(inbox)) 2748adbc7ac5SSaeed Mahameed return PTR_ERR(inbox); 2749adbc7ac5SSaeed Mahameed 2750adbc7ac5SSaeed Mahameed outbox = mlx4_alloc_cmd_mailbox(dev); 2751adbc7ac5SSaeed Mahameed if (IS_ERR(outbox)) { 2752adbc7ac5SSaeed Mahameed mlx4_free_cmd_mailbox(dev, inbox); 2753adbc7ac5SSaeed Mahameed return PTR_ERR(outbox); 2754adbc7ac5SSaeed Mahameed } 2755adbc7ac5SSaeed Mahameed 2756adbc7ac5SSaeed Mahameed inbuf = inbox->buf; 2757adbc7ac5SSaeed Mahameed outbuf = outbox->buf; 2758adbc7ac5SSaeed Mahameed 2759adbc7ac5SSaeed Mahameed inbuf->constant1 = cpu_to_be16(0x1<<11 | 0x4); 2760adbc7ac5SSaeed Mahameed inbuf->constant2 = 0x1; 2761adbc7ac5SSaeed Mahameed inbuf->reg_id = cpu_to_be16(reg_id); 2762adbc7ac5SSaeed Mahameed inbuf->method = method & MLX4_ACCESS_REG_METHOD_MASK; 2763adbc7ac5SSaeed Mahameed 2764adbc7ac5SSaeed Mahameed reg_len = min(reg_len, (u16)(sizeof(inbuf->reg_data))); 2765adbc7ac5SSaeed Mahameed inbuf->len_const = 2766adbc7ac5SSaeed Mahameed cpu_to_be16(((reg_len/4 + 1) & MLX4_ACCESS_REG_LEN_MASK) | 2767adbc7ac5SSaeed Mahameed ((0x3) << 12)); 2768adbc7ac5SSaeed Mahameed 2769adbc7ac5SSaeed Mahameed memcpy(inbuf->reg_data, reg_data, reg_len); 2770adbc7ac5SSaeed Mahameed err = mlx4_cmd_box(dev, inbox->dma, outbox->dma, 0, 0, 2771adbc7ac5SSaeed Mahameed MLX4_CMD_ACCESS_REG, MLX4_CMD_TIME_CLASS_C, 27726e806699SSaeed Mahameed MLX4_CMD_WRAPPED); 2773adbc7ac5SSaeed Mahameed if (err) 2774adbc7ac5SSaeed Mahameed goto out; 2775adbc7ac5SSaeed Mahameed 2776adbc7ac5SSaeed Mahameed if (outbuf->status & MLX4_ACCESS_REG_STATUS_MASK) { 2777adbc7ac5SSaeed Mahameed err = outbuf->status & MLX4_ACCESS_REG_STATUS_MASK; 2778adbc7ac5SSaeed Mahameed mlx4_err(dev, 2779adbc7ac5SSaeed Mahameed "MLX4_CMD_ACCESS_REG(%x) returned REG status (%x)\n", 2780adbc7ac5SSaeed Mahameed reg_id, err); 2781adbc7ac5SSaeed Mahameed goto out; 2782adbc7ac5SSaeed Mahameed } 2783adbc7ac5SSaeed Mahameed 2784adbc7ac5SSaeed Mahameed memcpy(reg_data, outbuf->reg_data, reg_len); 2785adbc7ac5SSaeed Mahameed out: 2786adbc7ac5SSaeed Mahameed mlx4_free_cmd_mailbox(dev, inbox); 2787adbc7ac5SSaeed Mahameed mlx4_free_cmd_mailbox(dev, outbox); 2788adbc7ac5SSaeed Mahameed return err; 2789adbc7ac5SSaeed Mahameed } 2790adbc7ac5SSaeed Mahameed 2791adbc7ac5SSaeed Mahameed /* ConnectX registers IDs */ 2792adbc7ac5SSaeed Mahameed enum mlx4_reg_id { 2793adbc7ac5SSaeed Mahameed MLX4_REG_ID_PTYS = 0x5004, 2794adbc7ac5SSaeed Mahameed }; 2795adbc7ac5SSaeed Mahameed 2796adbc7ac5SSaeed Mahameed /** 2797adbc7ac5SSaeed Mahameed * mlx4_ACCESS_PTYS_REG - Access PTYs (Port Type and Speed) 2798adbc7ac5SSaeed Mahameed * register 2799adbc7ac5SSaeed Mahameed * @dev: mlx4_dev. 2800adbc7ac5SSaeed Mahameed * @method: Access method Read/Write. 2801adbc7ac5SSaeed Mahameed * @ptys_reg: PTYS register data pointer. 2802adbc7ac5SSaeed Mahameed * 2803adbc7ac5SSaeed Mahameed * Access ConnectX PTYS register, to Read/Write Port Type/Speed 2804adbc7ac5SSaeed Mahameed * configuration 2805adbc7ac5SSaeed Mahameed * Returns 0 on success or a negative error code. 2806adbc7ac5SSaeed Mahameed */ 2807adbc7ac5SSaeed Mahameed int mlx4_ACCESS_PTYS_REG(struct mlx4_dev *dev, 2808adbc7ac5SSaeed Mahameed enum mlx4_access_reg_method method, 2809adbc7ac5SSaeed Mahameed struct mlx4_ptys_reg *ptys_reg) 2810adbc7ac5SSaeed Mahameed { 2811adbc7ac5SSaeed Mahameed return mlx4_ACCESS_REG(dev, MLX4_REG_ID_PTYS, 2812adbc7ac5SSaeed Mahameed method, sizeof(*ptys_reg), ptys_reg); 2813adbc7ac5SSaeed Mahameed } 2814adbc7ac5SSaeed Mahameed EXPORT_SYMBOL_GPL(mlx4_ACCESS_PTYS_REG); 28156e806699SSaeed Mahameed 28166e806699SSaeed Mahameed int mlx4_ACCESS_REG_wrapper(struct mlx4_dev *dev, int slave, 28176e806699SSaeed Mahameed struct mlx4_vhcr *vhcr, 28186e806699SSaeed Mahameed struct mlx4_cmd_mailbox *inbox, 28196e806699SSaeed Mahameed struct mlx4_cmd_mailbox *outbox, 28206e806699SSaeed Mahameed struct mlx4_cmd_info *cmd) 28216e806699SSaeed Mahameed { 28226e806699SSaeed Mahameed struct mlx4_access_reg *inbuf = inbox->buf; 28236e806699SSaeed Mahameed u8 method = inbuf->method & MLX4_ACCESS_REG_METHOD_MASK; 28246e806699SSaeed Mahameed u16 reg_id = be16_to_cpu(inbuf->reg_id); 28256e806699SSaeed Mahameed 28266e806699SSaeed Mahameed if (slave != mlx4_master_func_num(dev) && 28276e806699SSaeed Mahameed method == MLX4_ACCESS_REG_WRITE) 28286e806699SSaeed Mahameed return -EPERM; 28296e806699SSaeed Mahameed 28306e806699SSaeed Mahameed if (reg_id == MLX4_REG_ID_PTYS) { 28316e806699SSaeed Mahameed struct mlx4_ptys_reg *ptys_reg = 28326e806699SSaeed Mahameed (struct mlx4_ptys_reg *)inbuf->reg_data; 28336e806699SSaeed Mahameed 28346e806699SSaeed Mahameed ptys_reg->local_port = 28356e806699SSaeed Mahameed mlx4_slave_convert_port(dev, slave, 28366e806699SSaeed Mahameed ptys_reg->local_port); 28376e806699SSaeed Mahameed } 28386e806699SSaeed Mahameed 28396e806699SSaeed Mahameed return mlx4_cmd_box(dev, inbox->dma, outbox->dma, vhcr->in_modifier, 28406e806699SSaeed Mahameed 0, MLX4_CMD_ACCESS_REG, MLX4_CMD_TIME_CLASS_C, 28416e806699SSaeed Mahameed MLX4_CMD_NATIVE); 28426e806699SSaeed Mahameed } 284377fc29c4SHadar Hen Zion 284477fc29c4SHadar Hen Zion static int mlx4_SET_PORT_phv_bit(struct mlx4_dev *dev, u8 port, u8 phv_bit) 284577fc29c4SHadar Hen Zion { 284677fc29c4SHadar Hen Zion #define SET_PORT_GEN_PHV_VALID 0x10 284777fc29c4SHadar Hen Zion #define SET_PORT_GEN_PHV_EN 0x80 284877fc29c4SHadar Hen Zion 284977fc29c4SHadar Hen Zion struct mlx4_cmd_mailbox *mailbox; 285077fc29c4SHadar Hen Zion struct mlx4_set_port_general_context *context; 285177fc29c4SHadar Hen Zion u32 in_mod; 285277fc29c4SHadar Hen Zion int err; 285377fc29c4SHadar Hen Zion 285477fc29c4SHadar Hen Zion mailbox = mlx4_alloc_cmd_mailbox(dev); 285577fc29c4SHadar Hen Zion if (IS_ERR(mailbox)) 285677fc29c4SHadar Hen Zion return PTR_ERR(mailbox); 285777fc29c4SHadar Hen Zion context = mailbox->buf; 285877fc29c4SHadar Hen Zion 285977fc29c4SHadar Hen Zion context->v_ignore_fcs |= SET_PORT_GEN_PHV_VALID; 286077fc29c4SHadar Hen Zion if (phv_bit) 286177fc29c4SHadar Hen Zion context->phv_en |= SET_PORT_GEN_PHV_EN; 286277fc29c4SHadar Hen Zion 286377fc29c4SHadar Hen Zion in_mod = MLX4_SET_PORT_GENERAL << 8 | port; 286477fc29c4SHadar Hen Zion err = mlx4_cmd(dev, mailbox->dma, in_mod, MLX4_SET_PORT_ETH_OPCODE, 286577fc29c4SHadar Hen Zion MLX4_CMD_SET_PORT, MLX4_CMD_TIME_CLASS_B, 286677fc29c4SHadar Hen Zion MLX4_CMD_NATIVE); 286777fc29c4SHadar Hen Zion 286877fc29c4SHadar Hen Zion mlx4_free_cmd_mailbox(dev, mailbox); 286977fc29c4SHadar Hen Zion return err; 287077fc29c4SHadar Hen Zion } 287177fc29c4SHadar Hen Zion 287277fc29c4SHadar Hen Zion int get_phv_bit(struct mlx4_dev *dev, u8 port, int *phv) 287377fc29c4SHadar Hen Zion { 287477fc29c4SHadar Hen Zion int err; 287577fc29c4SHadar Hen Zion struct mlx4_func_cap func_cap; 287677fc29c4SHadar Hen Zion 287777fc29c4SHadar Hen Zion memset(&func_cap, 0, sizeof(func_cap)); 287835e455f4SAmir Vadai err = mlx4_QUERY_FUNC_CAP(dev, port, &func_cap); 287977fc29c4SHadar Hen Zion if (!err) 288077fc29c4SHadar Hen Zion *phv = func_cap.flags & QUERY_FUNC_CAP_PHV_BIT; 288177fc29c4SHadar Hen Zion return err; 288277fc29c4SHadar Hen Zion } 288377fc29c4SHadar Hen Zion EXPORT_SYMBOL(get_phv_bit); 288477fc29c4SHadar Hen Zion 288577fc29c4SHadar Hen Zion int set_phv_bit(struct mlx4_dev *dev, u8 port, int new_val) 288677fc29c4SHadar Hen Zion { 288777fc29c4SHadar Hen Zion int ret; 288877fc29c4SHadar Hen Zion 288977fc29c4SHadar Hen Zion if (mlx4_is_slave(dev)) 289077fc29c4SHadar Hen Zion return -EPERM; 289177fc29c4SHadar Hen Zion 289277fc29c4SHadar Hen Zion if (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_PHV_EN && 289377fc29c4SHadar Hen Zion !(dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_SKIP_OUTER_VLAN)) { 289477fc29c4SHadar Hen Zion ret = mlx4_SET_PORT_phv_bit(dev, port, new_val); 289577fc29c4SHadar Hen Zion if (!ret) 289677fc29c4SHadar Hen Zion dev->caps.phv_bit[port] = new_val; 289777fc29c4SHadar Hen Zion return ret; 289877fc29c4SHadar Hen Zion } 289977fc29c4SHadar Hen Zion 290077fc29c4SHadar Hen Zion return -EOPNOTSUPP; 290177fc29c4SHadar Hen Zion } 290277fc29c4SHadar Hen Zion EXPORT_SYMBOL(set_phv_bit); 29032b3ddf27SJack Morgenstein 29042b3ddf27SJack Morgenstein void mlx4_replace_zero_macs(struct mlx4_dev *dev) 29052b3ddf27SJack Morgenstein { 29062b3ddf27SJack Morgenstein int i; 29072b3ddf27SJack Morgenstein u8 mac_addr[ETH_ALEN]; 29082b3ddf27SJack Morgenstein 29092b3ddf27SJack Morgenstein dev->port_random_macs = 0; 29102b3ddf27SJack Morgenstein for (i = 1; i <= dev->caps.num_ports; ++i) 29112b3ddf27SJack Morgenstein if (!dev->caps.def_mac[i] && 29122b3ddf27SJack Morgenstein dev->caps.port_type[i] == MLX4_PORT_TYPE_ETH) { 29132b3ddf27SJack Morgenstein eth_random_addr(mac_addr); 29142b3ddf27SJack Morgenstein dev->port_random_macs |= 1 << i; 29152b3ddf27SJack Morgenstein dev->caps.def_mac[i] = mlx4_mac_to_u64(mac_addr); 29162b3ddf27SJack Morgenstein } 29172b3ddf27SJack Morgenstein } 29182b3ddf27SJack Morgenstein EXPORT_SYMBOL_GPL(mlx4_replace_zero_macs); 2919