18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright(c) 2015 - 2020 Intel Corporation. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * This file is provided under a dual BSD/GPLv2 license. When using or 58c2ecf20Sopenharmony_ci * redistributing this file, you may do so under either license. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * GPL LICENSE SUMMARY 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify 108c2ecf20Sopenharmony_ci * it under the terms of version 2 of the GNU General Public License as 118c2ecf20Sopenharmony_ci * published by the Free Software Foundation. 128c2ecf20Sopenharmony_ci * 138c2ecf20Sopenharmony_ci * This program is distributed in the hope that it will be useful, but 148c2ecf20Sopenharmony_ci * WITHOUT ANY WARRANTY; without even the implied warranty of 158c2ecf20Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 168c2ecf20Sopenharmony_ci * General Public License for more details. 178c2ecf20Sopenharmony_ci * 188c2ecf20Sopenharmony_ci * BSD LICENSE 198c2ecf20Sopenharmony_ci * 208c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 218c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions 228c2ecf20Sopenharmony_ci * are met: 238c2ecf20Sopenharmony_ci * 248c2ecf20Sopenharmony_ci * - Redistributions of source code must retain the above copyright 258c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer. 268c2ecf20Sopenharmony_ci * - Redistributions in binary form must reproduce the above copyright 278c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer in 288c2ecf20Sopenharmony_ci * the documentation and/or other materials provided with the 298c2ecf20Sopenharmony_ci * distribution. 308c2ecf20Sopenharmony_ci * - Neither the name of Intel Corporation nor the names of its 318c2ecf20Sopenharmony_ci * contributors may be used to endorse or promote products derived 328c2ecf20Sopenharmony_ci * from this software without specific prior written permission. 338c2ecf20Sopenharmony_ci * 348c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 358c2ecf20Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 368c2ecf20Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 378c2ecf20Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 388c2ecf20Sopenharmony_ci * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 398c2ecf20Sopenharmony_ci * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 408c2ecf20Sopenharmony_ci * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 418c2ecf20Sopenharmony_ci * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 428c2ecf20Sopenharmony_ci * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 438c2ecf20Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 448c2ecf20Sopenharmony_ci * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 458c2ecf20Sopenharmony_ci * 468c2ecf20Sopenharmony_ci */ 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci#include <rdma/ib_mad.h> 498c2ecf20Sopenharmony_ci#include <rdma/ib_user_verbs.h> 508c2ecf20Sopenharmony_ci#include <linux/io.h> 518c2ecf20Sopenharmony_ci#include <linux/module.h> 528c2ecf20Sopenharmony_ci#include <linux/utsname.h> 538c2ecf20Sopenharmony_ci#include <linux/rculist.h> 548c2ecf20Sopenharmony_ci#include <linux/mm.h> 558c2ecf20Sopenharmony_ci#include <linux/vmalloc.h> 568c2ecf20Sopenharmony_ci#include <rdma/opa_addr.h> 578c2ecf20Sopenharmony_ci#include <linux/nospec.h> 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci#include "hfi.h" 608c2ecf20Sopenharmony_ci#include "common.h" 618c2ecf20Sopenharmony_ci#include "device.h" 628c2ecf20Sopenharmony_ci#include "trace.h" 638c2ecf20Sopenharmony_ci#include "qp.h" 648c2ecf20Sopenharmony_ci#include "verbs_txreq.h" 658c2ecf20Sopenharmony_ci#include "debugfs.h" 668c2ecf20Sopenharmony_ci#include "vnic.h" 678c2ecf20Sopenharmony_ci#include "fault.h" 688c2ecf20Sopenharmony_ci#include "affinity.h" 698c2ecf20Sopenharmony_ci#include "ipoib.h" 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_cistatic unsigned int hfi1_lkey_table_size = 16; 728c2ecf20Sopenharmony_cimodule_param_named(lkey_table_size, hfi1_lkey_table_size, uint, 738c2ecf20Sopenharmony_ci S_IRUGO); 748c2ecf20Sopenharmony_ciMODULE_PARM_DESC(lkey_table_size, 758c2ecf20Sopenharmony_ci "LKEY table size in bits (2^n, 1 <= n <= 23)"); 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_cistatic unsigned int hfi1_max_pds = 0xFFFF; 788c2ecf20Sopenharmony_cimodule_param_named(max_pds, hfi1_max_pds, uint, S_IRUGO); 798c2ecf20Sopenharmony_ciMODULE_PARM_DESC(max_pds, 808c2ecf20Sopenharmony_ci "Maximum number of protection domains to support"); 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_cistatic unsigned int hfi1_max_ahs = 0xFFFF; 838c2ecf20Sopenharmony_cimodule_param_named(max_ahs, hfi1_max_ahs, uint, S_IRUGO); 848c2ecf20Sopenharmony_ciMODULE_PARM_DESC(max_ahs, "Maximum number of address handles to support"); 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ciunsigned int hfi1_max_cqes = 0x2FFFFF; 878c2ecf20Sopenharmony_cimodule_param_named(max_cqes, hfi1_max_cqes, uint, S_IRUGO); 888c2ecf20Sopenharmony_ciMODULE_PARM_DESC(max_cqes, 898c2ecf20Sopenharmony_ci "Maximum number of completion queue entries to support"); 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ciunsigned int hfi1_max_cqs = 0x1FFFF; 928c2ecf20Sopenharmony_cimodule_param_named(max_cqs, hfi1_max_cqs, uint, S_IRUGO); 938c2ecf20Sopenharmony_ciMODULE_PARM_DESC(max_cqs, "Maximum number of completion queues to support"); 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ciunsigned int hfi1_max_qp_wrs = 0x3FFF; 968c2ecf20Sopenharmony_cimodule_param_named(max_qp_wrs, hfi1_max_qp_wrs, uint, S_IRUGO); 978c2ecf20Sopenharmony_ciMODULE_PARM_DESC(max_qp_wrs, "Maximum number of QP WRs to support"); 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ciunsigned int hfi1_max_qps = 32768; 1008c2ecf20Sopenharmony_cimodule_param_named(max_qps, hfi1_max_qps, uint, S_IRUGO); 1018c2ecf20Sopenharmony_ciMODULE_PARM_DESC(max_qps, "Maximum number of QPs to support"); 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ciunsigned int hfi1_max_sges = 0x60; 1048c2ecf20Sopenharmony_cimodule_param_named(max_sges, hfi1_max_sges, uint, S_IRUGO); 1058c2ecf20Sopenharmony_ciMODULE_PARM_DESC(max_sges, "Maximum number of SGEs to support"); 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ciunsigned int hfi1_max_mcast_grps = 16384; 1088c2ecf20Sopenharmony_cimodule_param_named(max_mcast_grps, hfi1_max_mcast_grps, uint, S_IRUGO); 1098c2ecf20Sopenharmony_ciMODULE_PARM_DESC(max_mcast_grps, 1108c2ecf20Sopenharmony_ci "Maximum number of multicast groups to support"); 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ciunsigned int hfi1_max_mcast_qp_attached = 16; 1138c2ecf20Sopenharmony_cimodule_param_named(max_mcast_qp_attached, hfi1_max_mcast_qp_attached, 1148c2ecf20Sopenharmony_ci uint, S_IRUGO); 1158c2ecf20Sopenharmony_ciMODULE_PARM_DESC(max_mcast_qp_attached, 1168c2ecf20Sopenharmony_ci "Maximum number of attached QPs to support"); 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ciunsigned int hfi1_max_srqs = 1024; 1198c2ecf20Sopenharmony_cimodule_param_named(max_srqs, hfi1_max_srqs, uint, S_IRUGO); 1208c2ecf20Sopenharmony_ciMODULE_PARM_DESC(max_srqs, "Maximum number of SRQs to support"); 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ciunsigned int hfi1_max_srq_sges = 128; 1238c2ecf20Sopenharmony_cimodule_param_named(max_srq_sges, hfi1_max_srq_sges, uint, S_IRUGO); 1248c2ecf20Sopenharmony_ciMODULE_PARM_DESC(max_srq_sges, "Maximum number of SRQ SGEs to support"); 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ciunsigned int hfi1_max_srq_wrs = 0x1FFFF; 1278c2ecf20Sopenharmony_cimodule_param_named(max_srq_wrs, hfi1_max_srq_wrs, uint, S_IRUGO); 1288c2ecf20Sopenharmony_ciMODULE_PARM_DESC(max_srq_wrs, "Maximum number of SRQ WRs support"); 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ciunsigned short piothreshold = 256; 1318c2ecf20Sopenharmony_cimodule_param(piothreshold, ushort, S_IRUGO); 1328c2ecf20Sopenharmony_ciMODULE_PARM_DESC(piothreshold, "size used to determine sdma vs. pio"); 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_cistatic unsigned int sge_copy_mode; 1358c2ecf20Sopenharmony_cimodule_param(sge_copy_mode, uint, S_IRUGO); 1368c2ecf20Sopenharmony_ciMODULE_PARM_DESC(sge_copy_mode, 1378c2ecf20Sopenharmony_ci "Verbs copy mode: 0 use memcpy, 1 use cacheless copy, 2 adapt based on WSS"); 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_cistatic void verbs_sdma_complete( 1408c2ecf20Sopenharmony_ci struct sdma_txreq *cookie, 1418c2ecf20Sopenharmony_ci int status); 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_cistatic int pio_wait(struct rvt_qp *qp, 1448c2ecf20Sopenharmony_ci struct send_context *sc, 1458c2ecf20Sopenharmony_ci struct hfi1_pkt_state *ps, 1468c2ecf20Sopenharmony_ci u32 flag); 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci/* Length of buffer to create verbs txreq cache name */ 1498c2ecf20Sopenharmony_ci#define TXREQ_NAME_LEN 24 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_cistatic uint wss_threshold = 80; 1528c2ecf20Sopenharmony_cimodule_param(wss_threshold, uint, S_IRUGO); 1538c2ecf20Sopenharmony_ciMODULE_PARM_DESC(wss_threshold, "Percentage (1-100) of LLC to use as a threshold for a cacheless copy"); 1548c2ecf20Sopenharmony_cistatic uint wss_clean_period = 256; 1558c2ecf20Sopenharmony_cimodule_param(wss_clean_period, uint, S_IRUGO); 1568c2ecf20Sopenharmony_ciMODULE_PARM_DESC(wss_clean_period, "Count of verbs copies before an entry in the page copy table is cleaned"); 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci/* 1598c2ecf20Sopenharmony_ci * Translate ib_wr_opcode into ib_wc_opcode. 1608c2ecf20Sopenharmony_ci */ 1618c2ecf20Sopenharmony_ciconst enum ib_wc_opcode ib_hfi1_wc_opcode[] = { 1628c2ecf20Sopenharmony_ci [IB_WR_RDMA_WRITE] = IB_WC_RDMA_WRITE, 1638c2ecf20Sopenharmony_ci [IB_WR_TID_RDMA_WRITE] = IB_WC_RDMA_WRITE, 1648c2ecf20Sopenharmony_ci [IB_WR_RDMA_WRITE_WITH_IMM] = IB_WC_RDMA_WRITE, 1658c2ecf20Sopenharmony_ci [IB_WR_SEND] = IB_WC_SEND, 1668c2ecf20Sopenharmony_ci [IB_WR_SEND_WITH_IMM] = IB_WC_SEND, 1678c2ecf20Sopenharmony_ci [IB_WR_RDMA_READ] = IB_WC_RDMA_READ, 1688c2ecf20Sopenharmony_ci [IB_WR_TID_RDMA_READ] = IB_WC_RDMA_READ, 1698c2ecf20Sopenharmony_ci [IB_WR_ATOMIC_CMP_AND_SWP] = IB_WC_COMP_SWAP, 1708c2ecf20Sopenharmony_ci [IB_WR_ATOMIC_FETCH_AND_ADD] = IB_WC_FETCH_ADD, 1718c2ecf20Sopenharmony_ci [IB_WR_SEND_WITH_INV] = IB_WC_SEND, 1728c2ecf20Sopenharmony_ci [IB_WR_LOCAL_INV] = IB_WC_LOCAL_INV, 1738c2ecf20Sopenharmony_ci [IB_WR_REG_MR] = IB_WC_REG_MR 1748c2ecf20Sopenharmony_ci}; 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci/* 1778c2ecf20Sopenharmony_ci * Length of header by opcode, 0 --> not supported 1788c2ecf20Sopenharmony_ci */ 1798c2ecf20Sopenharmony_ciconst u8 hdr_len_by_opcode[256] = { 1808c2ecf20Sopenharmony_ci /* RC */ 1818c2ecf20Sopenharmony_ci [IB_OPCODE_RC_SEND_FIRST] = 12 + 8, 1828c2ecf20Sopenharmony_ci [IB_OPCODE_RC_SEND_MIDDLE] = 12 + 8, 1838c2ecf20Sopenharmony_ci [IB_OPCODE_RC_SEND_LAST] = 12 + 8, 1848c2ecf20Sopenharmony_ci [IB_OPCODE_RC_SEND_LAST_WITH_IMMEDIATE] = 12 + 8 + 4, 1858c2ecf20Sopenharmony_ci [IB_OPCODE_RC_SEND_ONLY] = 12 + 8, 1868c2ecf20Sopenharmony_ci [IB_OPCODE_RC_SEND_ONLY_WITH_IMMEDIATE] = 12 + 8 + 4, 1878c2ecf20Sopenharmony_ci [IB_OPCODE_RC_RDMA_WRITE_FIRST] = 12 + 8 + 16, 1888c2ecf20Sopenharmony_ci [IB_OPCODE_RC_RDMA_WRITE_MIDDLE] = 12 + 8, 1898c2ecf20Sopenharmony_ci [IB_OPCODE_RC_RDMA_WRITE_LAST] = 12 + 8, 1908c2ecf20Sopenharmony_ci [IB_OPCODE_RC_RDMA_WRITE_LAST_WITH_IMMEDIATE] = 12 + 8 + 4, 1918c2ecf20Sopenharmony_ci [IB_OPCODE_RC_RDMA_WRITE_ONLY] = 12 + 8 + 16, 1928c2ecf20Sopenharmony_ci [IB_OPCODE_RC_RDMA_WRITE_ONLY_WITH_IMMEDIATE] = 12 + 8 + 20, 1938c2ecf20Sopenharmony_ci [IB_OPCODE_RC_RDMA_READ_REQUEST] = 12 + 8 + 16, 1948c2ecf20Sopenharmony_ci [IB_OPCODE_RC_RDMA_READ_RESPONSE_FIRST] = 12 + 8 + 4, 1958c2ecf20Sopenharmony_ci [IB_OPCODE_RC_RDMA_READ_RESPONSE_MIDDLE] = 12 + 8, 1968c2ecf20Sopenharmony_ci [IB_OPCODE_RC_RDMA_READ_RESPONSE_LAST] = 12 + 8 + 4, 1978c2ecf20Sopenharmony_ci [IB_OPCODE_RC_RDMA_READ_RESPONSE_ONLY] = 12 + 8 + 4, 1988c2ecf20Sopenharmony_ci [IB_OPCODE_RC_ACKNOWLEDGE] = 12 + 8 + 4, 1998c2ecf20Sopenharmony_ci [IB_OPCODE_RC_ATOMIC_ACKNOWLEDGE] = 12 + 8 + 4 + 8, 2008c2ecf20Sopenharmony_ci [IB_OPCODE_RC_COMPARE_SWAP] = 12 + 8 + 28, 2018c2ecf20Sopenharmony_ci [IB_OPCODE_RC_FETCH_ADD] = 12 + 8 + 28, 2028c2ecf20Sopenharmony_ci [IB_OPCODE_RC_SEND_LAST_WITH_INVALIDATE] = 12 + 8 + 4, 2038c2ecf20Sopenharmony_ci [IB_OPCODE_RC_SEND_ONLY_WITH_INVALIDATE] = 12 + 8 + 4, 2048c2ecf20Sopenharmony_ci [IB_OPCODE_TID_RDMA_READ_REQ] = 12 + 8 + 36, 2058c2ecf20Sopenharmony_ci [IB_OPCODE_TID_RDMA_READ_RESP] = 12 + 8 + 36, 2068c2ecf20Sopenharmony_ci [IB_OPCODE_TID_RDMA_WRITE_REQ] = 12 + 8 + 36, 2078c2ecf20Sopenharmony_ci [IB_OPCODE_TID_RDMA_WRITE_RESP] = 12 + 8 + 36, 2088c2ecf20Sopenharmony_ci [IB_OPCODE_TID_RDMA_WRITE_DATA] = 12 + 8 + 36, 2098c2ecf20Sopenharmony_ci [IB_OPCODE_TID_RDMA_WRITE_DATA_LAST] = 12 + 8 + 36, 2108c2ecf20Sopenharmony_ci [IB_OPCODE_TID_RDMA_ACK] = 12 + 8 + 36, 2118c2ecf20Sopenharmony_ci [IB_OPCODE_TID_RDMA_RESYNC] = 12 + 8 + 36, 2128c2ecf20Sopenharmony_ci /* UC */ 2138c2ecf20Sopenharmony_ci [IB_OPCODE_UC_SEND_FIRST] = 12 + 8, 2148c2ecf20Sopenharmony_ci [IB_OPCODE_UC_SEND_MIDDLE] = 12 + 8, 2158c2ecf20Sopenharmony_ci [IB_OPCODE_UC_SEND_LAST] = 12 + 8, 2168c2ecf20Sopenharmony_ci [IB_OPCODE_UC_SEND_LAST_WITH_IMMEDIATE] = 12 + 8 + 4, 2178c2ecf20Sopenharmony_ci [IB_OPCODE_UC_SEND_ONLY] = 12 + 8, 2188c2ecf20Sopenharmony_ci [IB_OPCODE_UC_SEND_ONLY_WITH_IMMEDIATE] = 12 + 8 + 4, 2198c2ecf20Sopenharmony_ci [IB_OPCODE_UC_RDMA_WRITE_FIRST] = 12 + 8 + 16, 2208c2ecf20Sopenharmony_ci [IB_OPCODE_UC_RDMA_WRITE_MIDDLE] = 12 + 8, 2218c2ecf20Sopenharmony_ci [IB_OPCODE_UC_RDMA_WRITE_LAST] = 12 + 8, 2228c2ecf20Sopenharmony_ci [IB_OPCODE_UC_RDMA_WRITE_LAST_WITH_IMMEDIATE] = 12 + 8 + 4, 2238c2ecf20Sopenharmony_ci [IB_OPCODE_UC_RDMA_WRITE_ONLY] = 12 + 8 + 16, 2248c2ecf20Sopenharmony_ci [IB_OPCODE_UC_RDMA_WRITE_ONLY_WITH_IMMEDIATE] = 12 + 8 + 20, 2258c2ecf20Sopenharmony_ci /* UD */ 2268c2ecf20Sopenharmony_ci [IB_OPCODE_UD_SEND_ONLY] = 12 + 8 + 8, 2278c2ecf20Sopenharmony_ci [IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE] = 12 + 8 + 12 2288c2ecf20Sopenharmony_ci}; 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_cistatic const opcode_handler opcode_handler_tbl[256] = { 2318c2ecf20Sopenharmony_ci /* RC */ 2328c2ecf20Sopenharmony_ci [IB_OPCODE_RC_SEND_FIRST] = &hfi1_rc_rcv, 2338c2ecf20Sopenharmony_ci [IB_OPCODE_RC_SEND_MIDDLE] = &hfi1_rc_rcv, 2348c2ecf20Sopenharmony_ci [IB_OPCODE_RC_SEND_LAST] = &hfi1_rc_rcv, 2358c2ecf20Sopenharmony_ci [IB_OPCODE_RC_SEND_LAST_WITH_IMMEDIATE] = &hfi1_rc_rcv, 2368c2ecf20Sopenharmony_ci [IB_OPCODE_RC_SEND_ONLY] = &hfi1_rc_rcv, 2378c2ecf20Sopenharmony_ci [IB_OPCODE_RC_SEND_ONLY_WITH_IMMEDIATE] = &hfi1_rc_rcv, 2388c2ecf20Sopenharmony_ci [IB_OPCODE_RC_RDMA_WRITE_FIRST] = &hfi1_rc_rcv, 2398c2ecf20Sopenharmony_ci [IB_OPCODE_RC_RDMA_WRITE_MIDDLE] = &hfi1_rc_rcv, 2408c2ecf20Sopenharmony_ci [IB_OPCODE_RC_RDMA_WRITE_LAST] = &hfi1_rc_rcv, 2418c2ecf20Sopenharmony_ci [IB_OPCODE_RC_RDMA_WRITE_LAST_WITH_IMMEDIATE] = &hfi1_rc_rcv, 2428c2ecf20Sopenharmony_ci [IB_OPCODE_RC_RDMA_WRITE_ONLY] = &hfi1_rc_rcv, 2438c2ecf20Sopenharmony_ci [IB_OPCODE_RC_RDMA_WRITE_ONLY_WITH_IMMEDIATE] = &hfi1_rc_rcv, 2448c2ecf20Sopenharmony_ci [IB_OPCODE_RC_RDMA_READ_REQUEST] = &hfi1_rc_rcv, 2458c2ecf20Sopenharmony_ci [IB_OPCODE_RC_RDMA_READ_RESPONSE_FIRST] = &hfi1_rc_rcv, 2468c2ecf20Sopenharmony_ci [IB_OPCODE_RC_RDMA_READ_RESPONSE_MIDDLE] = &hfi1_rc_rcv, 2478c2ecf20Sopenharmony_ci [IB_OPCODE_RC_RDMA_READ_RESPONSE_LAST] = &hfi1_rc_rcv, 2488c2ecf20Sopenharmony_ci [IB_OPCODE_RC_RDMA_READ_RESPONSE_ONLY] = &hfi1_rc_rcv, 2498c2ecf20Sopenharmony_ci [IB_OPCODE_RC_ACKNOWLEDGE] = &hfi1_rc_rcv, 2508c2ecf20Sopenharmony_ci [IB_OPCODE_RC_ATOMIC_ACKNOWLEDGE] = &hfi1_rc_rcv, 2518c2ecf20Sopenharmony_ci [IB_OPCODE_RC_COMPARE_SWAP] = &hfi1_rc_rcv, 2528c2ecf20Sopenharmony_ci [IB_OPCODE_RC_FETCH_ADD] = &hfi1_rc_rcv, 2538c2ecf20Sopenharmony_ci [IB_OPCODE_RC_SEND_LAST_WITH_INVALIDATE] = &hfi1_rc_rcv, 2548c2ecf20Sopenharmony_ci [IB_OPCODE_RC_SEND_ONLY_WITH_INVALIDATE] = &hfi1_rc_rcv, 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci /* TID RDMA has separate handlers for different opcodes.*/ 2578c2ecf20Sopenharmony_ci [IB_OPCODE_TID_RDMA_WRITE_REQ] = &hfi1_rc_rcv_tid_rdma_write_req, 2588c2ecf20Sopenharmony_ci [IB_OPCODE_TID_RDMA_WRITE_RESP] = &hfi1_rc_rcv_tid_rdma_write_resp, 2598c2ecf20Sopenharmony_ci [IB_OPCODE_TID_RDMA_WRITE_DATA] = &hfi1_rc_rcv_tid_rdma_write_data, 2608c2ecf20Sopenharmony_ci [IB_OPCODE_TID_RDMA_WRITE_DATA_LAST] = &hfi1_rc_rcv_tid_rdma_write_data, 2618c2ecf20Sopenharmony_ci [IB_OPCODE_TID_RDMA_READ_REQ] = &hfi1_rc_rcv_tid_rdma_read_req, 2628c2ecf20Sopenharmony_ci [IB_OPCODE_TID_RDMA_READ_RESP] = &hfi1_rc_rcv_tid_rdma_read_resp, 2638c2ecf20Sopenharmony_ci [IB_OPCODE_TID_RDMA_RESYNC] = &hfi1_rc_rcv_tid_rdma_resync, 2648c2ecf20Sopenharmony_ci [IB_OPCODE_TID_RDMA_ACK] = &hfi1_rc_rcv_tid_rdma_ack, 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci /* UC */ 2678c2ecf20Sopenharmony_ci [IB_OPCODE_UC_SEND_FIRST] = &hfi1_uc_rcv, 2688c2ecf20Sopenharmony_ci [IB_OPCODE_UC_SEND_MIDDLE] = &hfi1_uc_rcv, 2698c2ecf20Sopenharmony_ci [IB_OPCODE_UC_SEND_LAST] = &hfi1_uc_rcv, 2708c2ecf20Sopenharmony_ci [IB_OPCODE_UC_SEND_LAST_WITH_IMMEDIATE] = &hfi1_uc_rcv, 2718c2ecf20Sopenharmony_ci [IB_OPCODE_UC_SEND_ONLY] = &hfi1_uc_rcv, 2728c2ecf20Sopenharmony_ci [IB_OPCODE_UC_SEND_ONLY_WITH_IMMEDIATE] = &hfi1_uc_rcv, 2738c2ecf20Sopenharmony_ci [IB_OPCODE_UC_RDMA_WRITE_FIRST] = &hfi1_uc_rcv, 2748c2ecf20Sopenharmony_ci [IB_OPCODE_UC_RDMA_WRITE_MIDDLE] = &hfi1_uc_rcv, 2758c2ecf20Sopenharmony_ci [IB_OPCODE_UC_RDMA_WRITE_LAST] = &hfi1_uc_rcv, 2768c2ecf20Sopenharmony_ci [IB_OPCODE_UC_RDMA_WRITE_LAST_WITH_IMMEDIATE] = &hfi1_uc_rcv, 2778c2ecf20Sopenharmony_ci [IB_OPCODE_UC_RDMA_WRITE_ONLY] = &hfi1_uc_rcv, 2788c2ecf20Sopenharmony_ci [IB_OPCODE_UC_RDMA_WRITE_ONLY_WITH_IMMEDIATE] = &hfi1_uc_rcv, 2798c2ecf20Sopenharmony_ci /* UD */ 2808c2ecf20Sopenharmony_ci [IB_OPCODE_UD_SEND_ONLY] = &hfi1_ud_rcv, 2818c2ecf20Sopenharmony_ci [IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE] = &hfi1_ud_rcv, 2828c2ecf20Sopenharmony_ci /* CNP */ 2838c2ecf20Sopenharmony_ci [IB_OPCODE_CNP] = &hfi1_cnp_rcv 2848c2ecf20Sopenharmony_ci}; 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ci#define OPMASK 0x1f 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_cistatic const u32 pio_opmask[BIT(3)] = { 2898c2ecf20Sopenharmony_ci /* RC */ 2908c2ecf20Sopenharmony_ci [IB_OPCODE_RC >> 5] = 2918c2ecf20Sopenharmony_ci BIT(RC_OP(SEND_ONLY) & OPMASK) | 2928c2ecf20Sopenharmony_ci BIT(RC_OP(SEND_ONLY_WITH_IMMEDIATE) & OPMASK) | 2938c2ecf20Sopenharmony_ci BIT(RC_OP(RDMA_WRITE_ONLY) & OPMASK) | 2948c2ecf20Sopenharmony_ci BIT(RC_OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE) & OPMASK) | 2958c2ecf20Sopenharmony_ci BIT(RC_OP(RDMA_READ_REQUEST) & OPMASK) | 2968c2ecf20Sopenharmony_ci BIT(RC_OP(ACKNOWLEDGE) & OPMASK) | 2978c2ecf20Sopenharmony_ci BIT(RC_OP(ATOMIC_ACKNOWLEDGE) & OPMASK) | 2988c2ecf20Sopenharmony_ci BIT(RC_OP(COMPARE_SWAP) & OPMASK) | 2998c2ecf20Sopenharmony_ci BIT(RC_OP(FETCH_ADD) & OPMASK), 3008c2ecf20Sopenharmony_ci /* UC */ 3018c2ecf20Sopenharmony_ci [IB_OPCODE_UC >> 5] = 3028c2ecf20Sopenharmony_ci BIT(UC_OP(SEND_ONLY) & OPMASK) | 3038c2ecf20Sopenharmony_ci BIT(UC_OP(SEND_ONLY_WITH_IMMEDIATE) & OPMASK) | 3048c2ecf20Sopenharmony_ci BIT(UC_OP(RDMA_WRITE_ONLY) & OPMASK) | 3058c2ecf20Sopenharmony_ci BIT(UC_OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE) & OPMASK), 3068c2ecf20Sopenharmony_ci}; 3078c2ecf20Sopenharmony_ci 3088c2ecf20Sopenharmony_ci/* 3098c2ecf20Sopenharmony_ci * System image GUID. 3108c2ecf20Sopenharmony_ci */ 3118c2ecf20Sopenharmony_ci__be64 ib_hfi1_sys_image_guid; 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci/* 3148c2ecf20Sopenharmony_ci * Make sure the QP is ready and able to accept the given opcode. 3158c2ecf20Sopenharmony_ci */ 3168c2ecf20Sopenharmony_cistatic inline opcode_handler qp_ok(struct hfi1_packet *packet) 3178c2ecf20Sopenharmony_ci{ 3188c2ecf20Sopenharmony_ci if (!(ib_rvt_state_ops[packet->qp->state] & RVT_PROCESS_RECV_OK)) 3198c2ecf20Sopenharmony_ci return NULL; 3208c2ecf20Sopenharmony_ci if (((packet->opcode & RVT_OPCODE_QP_MASK) == 3218c2ecf20Sopenharmony_ci packet->qp->allowed_ops) || 3228c2ecf20Sopenharmony_ci (packet->opcode == IB_OPCODE_CNP)) 3238c2ecf20Sopenharmony_ci return opcode_handler_tbl[packet->opcode]; 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_ci return NULL; 3268c2ecf20Sopenharmony_ci} 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_cistatic u64 hfi1_fault_tx(struct rvt_qp *qp, u8 opcode, u64 pbc) 3298c2ecf20Sopenharmony_ci{ 3308c2ecf20Sopenharmony_ci#ifdef CONFIG_FAULT_INJECTION 3318c2ecf20Sopenharmony_ci if ((opcode & IB_OPCODE_MSP) == IB_OPCODE_MSP) { 3328c2ecf20Sopenharmony_ci /* 3338c2ecf20Sopenharmony_ci * In order to drop non-IB traffic we 3348c2ecf20Sopenharmony_ci * set PbcInsertHrc to NONE (0x2). 3358c2ecf20Sopenharmony_ci * The packet will still be delivered 3368c2ecf20Sopenharmony_ci * to the receiving node but a 3378c2ecf20Sopenharmony_ci * KHdrHCRCErr (KDETH packet with a bad 3388c2ecf20Sopenharmony_ci * HCRC) will be triggered and the 3398c2ecf20Sopenharmony_ci * packet will not be delivered to the 3408c2ecf20Sopenharmony_ci * correct context. 3418c2ecf20Sopenharmony_ci */ 3428c2ecf20Sopenharmony_ci pbc &= ~PBC_INSERT_HCRC_SMASK; 3438c2ecf20Sopenharmony_ci pbc |= (u64)PBC_IHCRC_NONE << PBC_INSERT_HCRC_SHIFT; 3448c2ecf20Sopenharmony_ci } else { 3458c2ecf20Sopenharmony_ci /* 3468c2ecf20Sopenharmony_ci * In order to drop regular verbs 3478c2ecf20Sopenharmony_ci * traffic we set the PbcTestEbp 3488c2ecf20Sopenharmony_ci * flag. The packet will still be 3498c2ecf20Sopenharmony_ci * delivered to the receiving node but 3508c2ecf20Sopenharmony_ci * a 'late ebp error' will be 3518c2ecf20Sopenharmony_ci * triggered and will be dropped. 3528c2ecf20Sopenharmony_ci */ 3538c2ecf20Sopenharmony_ci pbc |= PBC_TEST_EBP; 3548c2ecf20Sopenharmony_ci } 3558c2ecf20Sopenharmony_ci#endif 3568c2ecf20Sopenharmony_ci return pbc; 3578c2ecf20Sopenharmony_ci} 3588c2ecf20Sopenharmony_ci 3598c2ecf20Sopenharmony_cistatic opcode_handler tid_qp_ok(int opcode, struct hfi1_packet *packet) 3608c2ecf20Sopenharmony_ci{ 3618c2ecf20Sopenharmony_ci if (packet->qp->ibqp.qp_type != IB_QPT_RC || 3628c2ecf20Sopenharmony_ci !(ib_rvt_state_ops[packet->qp->state] & RVT_PROCESS_RECV_OK)) 3638c2ecf20Sopenharmony_ci return NULL; 3648c2ecf20Sopenharmony_ci if ((opcode & RVT_OPCODE_QP_MASK) == IB_OPCODE_TID_RDMA) 3658c2ecf20Sopenharmony_ci return opcode_handler_tbl[opcode]; 3668c2ecf20Sopenharmony_ci return NULL; 3678c2ecf20Sopenharmony_ci} 3688c2ecf20Sopenharmony_ci 3698c2ecf20Sopenharmony_civoid hfi1_kdeth_eager_rcv(struct hfi1_packet *packet) 3708c2ecf20Sopenharmony_ci{ 3718c2ecf20Sopenharmony_ci struct hfi1_ctxtdata *rcd = packet->rcd; 3728c2ecf20Sopenharmony_ci struct ib_header *hdr = packet->hdr; 3738c2ecf20Sopenharmony_ci u32 tlen = packet->tlen; 3748c2ecf20Sopenharmony_ci struct hfi1_pportdata *ppd = rcd->ppd; 3758c2ecf20Sopenharmony_ci struct hfi1_ibport *ibp = &ppd->ibport_data; 3768c2ecf20Sopenharmony_ci struct rvt_dev_info *rdi = &ppd->dd->verbs_dev.rdi; 3778c2ecf20Sopenharmony_ci opcode_handler opcode_handler; 3788c2ecf20Sopenharmony_ci unsigned long flags; 3798c2ecf20Sopenharmony_ci u32 qp_num; 3808c2ecf20Sopenharmony_ci int lnh; 3818c2ecf20Sopenharmony_ci u8 opcode; 3828c2ecf20Sopenharmony_ci 3838c2ecf20Sopenharmony_ci /* DW == LRH (2) + BTH (3) + KDETH (9) + CRC (1) */ 3848c2ecf20Sopenharmony_ci if (unlikely(tlen < 15 * sizeof(u32))) 3858c2ecf20Sopenharmony_ci goto drop; 3868c2ecf20Sopenharmony_ci 3878c2ecf20Sopenharmony_ci lnh = be16_to_cpu(hdr->lrh[0]) & 3; 3888c2ecf20Sopenharmony_ci if (lnh != HFI1_LRH_BTH) 3898c2ecf20Sopenharmony_ci goto drop; 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci packet->ohdr = &hdr->u.oth; 3928c2ecf20Sopenharmony_ci trace_input_ibhdr(rcd->dd, packet, !!(rhf_dc_info(packet->rhf))); 3938c2ecf20Sopenharmony_ci 3948c2ecf20Sopenharmony_ci opcode = (be32_to_cpu(packet->ohdr->bth[0]) >> 24); 3958c2ecf20Sopenharmony_ci inc_opstats(tlen, &rcd->opstats->stats[opcode]); 3968c2ecf20Sopenharmony_ci 3978c2ecf20Sopenharmony_ci /* verbs_qp can be picked up from any tid_rdma header struct */ 3988c2ecf20Sopenharmony_ci qp_num = be32_to_cpu(packet->ohdr->u.tid_rdma.r_req.verbs_qp) & 3998c2ecf20Sopenharmony_ci RVT_QPN_MASK; 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ci rcu_read_lock(); 4028c2ecf20Sopenharmony_ci packet->qp = rvt_lookup_qpn(rdi, &ibp->rvp, qp_num); 4038c2ecf20Sopenharmony_ci if (!packet->qp) 4048c2ecf20Sopenharmony_ci goto drop_rcu; 4058c2ecf20Sopenharmony_ci spin_lock_irqsave(&packet->qp->r_lock, flags); 4068c2ecf20Sopenharmony_ci opcode_handler = tid_qp_ok(opcode, packet); 4078c2ecf20Sopenharmony_ci if (likely(opcode_handler)) 4088c2ecf20Sopenharmony_ci opcode_handler(packet); 4098c2ecf20Sopenharmony_ci else 4108c2ecf20Sopenharmony_ci goto drop_unlock; 4118c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&packet->qp->r_lock, flags); 4128c2ecf20Sopenharmony_ci rcu_read_unlock(); 4138c2ecf20Sopenharmony_ci 4148c2ecf20Sopenharmony_ci return; 4158c2ecf20Sopenharmony_cidrop_unlock: 4168c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&packet->qp->r_lock, flags); 4178c2ecf20Sopenharmony_cidrop_rcu: 4188c2ecf20Sopenharmony_ci rcu_read_unlock(); 4198c2ecf20Sopenharmony_cidrop: 4208c2ecf20Sopenharmony_ci ibp->rvp.n_pkt_drops++; 4218c2ecf20Sopenharmony_ci} 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_civoid hfi1_kdeth_expected_rcv(struct hfi1_packet *packet) 4248c2ecf20Sopenharmony_ci{ 4258c2ecf20Sopenharmony_ci struct hfi1_ctxtdata *rcd = packet->rcd; 4268c2ecf20Sopenharmony_ci struct ib_header *hdr = packet->hdr; 4278c2ecf20Sopenharmony_ci u32 tlen = packet->tlen; 4288c2ecf20Sopenharmony_ci struct hfi1_pportdata *ppd = rcd->ppd; 4298c2ecf20Sopenharmony_ci struct hfi1_ibport *ibp = &ppd->ibport_data; 4308c2ecf20Sopenharmony_ci struct rvt_dev_info *rdi = &ppd->dd->verbs_dev.rdi; 4318c2ecf20Sopenharmony_ci opcode_handler opcode_handler; 4328c2ecf20Sopenharmony_ci unsigned long flags; 4338c2ecf20Sopenharmony_ci u32 qp_num; 4348c2ecf20Sopenharmony_ci int lnh; 4358c2ecf20Sopenharmony_ci u8 opcode; 4368c2ecf20Sopenharmony_ci 4378c2ecf20Sopenharmony_ci /* DW == LRH (2) + BTH (3) + KDETH (9) + CRC (1) */ 4388c2ecf20Sopenharmony_ci if (unlikely(tlen < 15 * sizeof(u32))) 4398c2ecf20Sopenharmony_ci goto drop; 4408c2ecf20Sopenharmony_ci 4418c2ecf20Sopenharmony_ci lnh = be16_to_cpu(hdr->lrh[0]) & 3; 4428c2ecf20Sopenharmony_ci if (lnh != HFI1_LRH_BTH) 4438c2ecf20Sopenharmony_ci goto drop; 4448c2ecf20Sopenharmony_ci 4458c2ecf20Sopenharmony_ci packet->ohdr = &hdr->u.oth; 4468c2ecf20Sopenharmony_ci trace_input_ibhdr(rcd->dd, packet, !!(rhf_dc_info(packet->rhf))); 4478c2ecf20Sopenharmony_ci 4488c2ecf20Sopenharmony_ci opcode = (be32_to_cpu(packet->ohdr->bth[0]) >> 24); 4498c2ecf20Sopenharmony_ci inc_opstats(tlen, &rcd->opstats->stats[opcode]); 4508c2ecf20Sopenharmony_ci 4518c2ecf20Sopenharmony_ci /* verbs_qp can be picked up from any tid_rdma header struct */ 4528c2ecf20Sopenharmony_ci qp_num = be32_to_cpu(packet->ohdr->u.tid_rdma.r_rsp.verbs_qp) & 4538c2ecf20Sopenharmony_ci RVT_QPN_MASK; 4548c2ecf20Sopenharmony_ci 4558c2ecf20Sopenharmony_ci rcu_read_lock(); 4568c2ecf20Sopenharmony_ci packet->qp = rvt_lookup_qpn(rdi, &ibp->rvp, qp_num); 4578c2ecf20Sopenharmony_ci if (!packet->qp) 4588c2ecf20Sopenharmony_ci goto drop_rcu; 4598c2ecf20Sopenharmony_ci spin_lock_irqsave(&packet->qp->r_lock, flags); 4608c2ecf20Sopenharmony_ci opcode_handler = tid_qp_ok(opcode, packet); 4618c2ecf20Sopenharmony_ci if (likely(opcode_handler)) 4628c2ecf20Sopenharmony_ci opcode_handler(packet); 4638c2ecf20Sopenharmony_ci else 4648c2ecf20Sopenharmony_ci goto drop_unlock; 4658c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&packet->qp->r_lock, flags); 4668c2ecf20Sopenharmony_ci rcu_read_unlock(); 4678c2ecf20Sopenharmony_ci 4688c2ecf20Sopenharmony_ci return; 4698c2ecf20Sopenharmony_cidrop_unlock: 4708c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&packet->qp->r_lock, flags); 4718c2ecf20Sopenharmony_cidrop_rcu: 4728c2ecf20Sopenharmony_ci rcu_read_unlock(); 4738c2ecf20Sopenharmony_cidrop: 4748c2ecf20Sopenharmony_ci ibp->rvp.n_pkt_drops++; 4758c2ecf20Sopenharmony_ci} 4768c2ecf20Sopenharmony_ci 4778c2ecf20Sopenharmony_cistatic int hfi1_do_pkey_check(struct hfi1_packet *packet) 4788c2ecf20Sopenharmony_ci{ 4798c2ecf20Sopenharmony_ci struct hfi1_ctxtdata *rcd = packet->rcd; 4808c2ecf20Sopenharmony_ci struct hfi1_pportdata *ppd = rcd->ppd; 4818c2ecf20Sopenharmony_ci struct hfi1_16b_header *hdr = packet->hdr; 4828c2ecf20Sopenharmony_ci u16 pkey; 4838c2ecf20Sopenharmony_ci 4848c2ecf20Sopenharmony_ci /* Pkey check needed only for bypass packets */ 4858c2ecf20Sopenharmony_ci if (packet->etype != RHF_RCV_TYPE_BYPASS) 4868c2ecf20Sopenharmony_ci return 0; 4878c2ecf20Sopenharmony_ci 4888c2ecf20Sopenharmony_ci /* Perform pkey check */ 4898c2ecf20Sopenharmony_ci pkey = hfi1_16B_get_pkey(hdr); 4908c2ecf20Sopenharmony_ci return ingress_pkey_check(ppd, pkey, packet->sc, 4918c2ecf20Sopenharmony_ci packet->qp->s_pkey_index, 4928c2ecf20Sopenharmony_ci packet->slid, true); 4938c2ecf20Sopenharmony_ci} 4948c2ecf20Sopenharmony_ci 4958c2ecf20Sopenharmony_cistatic inline void hfi1_handle_packet(struct hfi1_packet *packet, 4968c2ecf20Sopenharmony_ci bool is_mcast) 4978c2ecf20Sopenharmony_ci{ 4988c2ecf20Sopenharmony_ci u32 qp_num; 4998c2ecf20Sopenharmony_ci struct hfi1_ctxtdata *rcd = packet->rcd; 5008c2ecf20Sopenharmony_ci struct hfi1_pportdata *ppd = rcd->ppd; 5018c2ecf20Sopenharmony_ci struct hfi1_ibport *ibp = rcd_to_iport(rcd); 5028c2ecf20Sopenharmony_ci struct rvt_dev_info *rdi = &ppd->dd->verbs_dev.rdi; 5038c2ecf20Sopenharmony_ci opcode_handler packet_handler; 5048c2ecf20Sopenharmony_ci unsigned long flags; 5058c2ecf20Sopenharmony_ci 5068c2ecf20Sopenharmony_ci inc_opstats(packet->tlen, &rcd->opstats->stats[packet->opcode]); 5078c2ecf20Sopenharmony_ci 5088c2ecf20Sopenharmony_ci if (unlikely(is_mcast)) { 5098c2ecf20Sopenharmony_ci struct rvt_mcast *mcast; 5108c2ecf20Sopenharmony_ci struct rvt_mcast_qp *p; 5118c2ecf20Sopenharmony_ci 5128c2ecf20Sopenharmony_ci if (!packet->grh) 5138c2ecf20Sopenharmony_ci goto drop; 5148c2ecf20Sopenharmony_ci mcast = rvt_mcast_find(&ibp->rvp, 5158c2ecf20Sopenharmony_ci &packet->grh->dgid, 5168c2ecf20Sopenharmony_ci opa_get_lid(packet->dlid, 9B)); 5178c2ecf20Sopenharmony_ci if (!mcast) 5188c2ecf20Sopenharmony_ci goto drop; 5198c2ecf20Sopenharmony_ci rcu_read_lock(); 5208c2ecf20Sopenharmony_ci list_for_each_entry_rcu(p, &mcast->qp_list, list) { 5218c2ecf20Sopenharmony_ci packet->qp = p->qp; 5228c2ecf20Sopenharmony_ci if (hfi1_do_pkey_check(packet)) 5238c2ecf20Sopenharmony_ci goto unlock_drop; 5248c2ecf20Sopenharmony_ci spin_lock_irqsave(&packet->qp->r_lock, flags); 5258c2ecf20Sopenharmony_ci packet_handler = qp_ok(packet); 5268c2ecf20Sopenharmony_ci if (likely(packet_handler)) 5278c2ecf20Sopenharmony_ci packet_handler(packet); 5288c2ecf20Sopenharmony_ci else 5298c2ecf20Sopenharmony_ci ibp->rvp.n_pkt_drops++; 5308c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&packet->qp->r_lock, flags); 5318c2ecf20Sopenharmony_ci } 5328c2ecf20Sopenharmony_ci rcu_read_unlock(); 5338c2ecf20Sopenharmony_ci /* 5348c2ecf20Sopenharmony_ci * Notify rvt_multicast_detach() if it is waiting for us 5358c2ecf20Sopenharmony_ci * to finish. 5368c2ecf20Sopenharmony_ci */ 5378c2ecf20Sopenharmony_ci if (atomic_dec_return(&mcast->refcount) <= 1) 5388c2ecf20Sopenharmony_ci wake_up(&mcast->wait); 5398c2ecf20Sopenharmony_ci } else { 5408c2ecf20Sopenharmony_ci /* Get the destination QP number. */ 5418c2ecf20Sopenharmony_ci if (packet->etype == RHF_RCV_TYPE_BYPASS && 5428c2ecf20Sopenharmony_ci hfi1_16B_get_l4(packet->hdr) == OPA_16B_L4_FM) 5438c2ecf20Sopenharmony_ci qp_num = hfi1_16B_get_dest_qpn(packet->mgmt); 5448c2ecf20Sopenharmony_ci else 5458c2ecf20Sopenharmony_ci qp_num = ib_bth_get_qpn(packet->ohdr); 5468c2ecf20Sopenharmony_ci 5478c2ecf20Sopenharmony_ci rcu_read_lock(); 5488c2ecf20Sopenharmony_ci packet->qp = rvt_lookup_qpn(rdi, &ibp->rvp, qp_num); 5498c2ecf20Sopenharmony_ci if (!packet->qp) 5508c2ecf20Sopenharmony_ci goto unlock_drop; 5518c2ecf20Sopenharmony_ci 5528c2ecf20Sopenharmony_ci if (hfi1_do_pkey_check(packet)) 5538c2ecf20Sopenharmony_ci goto unlock_drop; 5548c2ecf20Sopenharmony_ci 5558c2ecf20Sopenharmony_ci spin_lock_irqsave(&packet->qp->r_lock, flags); 5568c2ecf20Sopenharmony_ci packet_handler = qp_ok(packet); 5578c2ecf20Sopenharmony_ci if (likely(packet_handler)) 5588c2ecf20Sopenharmony_ci packet_handler(packet); 5598c2ecf20Sopenharmony_ci else 5608c2ecf20Sopenharmony_ci ibp->rvp.n_pkt_drops++; 5618c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&packet->qp->r_lock, flags); 5628c2ecf20Sopenharmony_ci rcu_read_unlock(); 5638c2ecf20Sopenharmony_ci } 5648c2ecf20Sopenharmony_ci return; 5658c2ecf20Sopenharmony_ciunlock_drop: 5668c2ecf20Sopenharmony_ci rcu_read_unlock(); 5678c2ecf20Sopenharmony_cidrop: 5688c2ecf20Sopenharmony_ci ibp->rvp.n_pkt_drops++; 5698c2ecf20Sopenharmony_ci} 5708c2ecf20Sopenharmony_ci 5718c2ecf20Sopenharmony_ci/** 5728c2ecf20Sopenharmony_ci * hfi1_ib_rcv - process an incoming packet 5738c2ecf20Sopenharmony_ci * @packet: data packet information 5748c2ecf20Sopenharmony_ci * 5758c2ecf20Sopenharmony_ci * This is called to process an incoming packet at interrupt level. 5768c2ecf20Sopenharmony_ci */ 5778c2ecf20Sopenharmony_civoid hfi1_ib_rcv(struct hfi1_packet *packet) 5788c2ecf20Sopenharmony_ci{ 5798c2ecf20Sopenharmony_ci struct hfi1_ctxtdata *rcd = packet->rcd; 5808c2ecf20Sopenharmony_ci 5818c2ecf20Sopenharmony_ci trace_input_ibhdr(rcd->dd, packet, !!(rhf_dc_info(packet->rhf))); 5828c2ecf20Sopenharmony_ci hfi1_handle_packet(packet, hfi1_check_mcast(packet->dlid)); 5838c2ecf20Sopenharmony_ci} 5848c2ecf20Sopenharmony_ci 5858c2ecf20Sopenharmony_civoid hfi1_16B_rcv(struct hfi1_packet *packet) 5868c2ecf20Sopenharmony_ci{ 5878c2ecf20Sopenharmony_ci struct hfi1_ctxtdata *rcd = packet->rcd; 5888c2ecf20Sopenharmony_ci 5898c2ecf20Sopenharmony_ci trace_input_ibhdr(rcd->dd, packet, false); 5908c2ecf20Sopenharmony_ci hfi1_handle_packet(packet, hfi1_check_mcast(packet->dlid)); 5918c2ecf20Sopenharmony_ci} 5928c2ecf20Sopenharmony_ci 5938c2ecf20Sopenharmony_ci/* 5948c2ecf20Sopenharmony_ci * This is called from a timer to check for QPs 5958c2ecf20Sopenharmony_ci * which need kernel memory in order to send a packet. 5968c2ecf20Sopenharmony_ci */ 5978c2ecf20Sopenharmony_cistatic void mem_timer(struct timer_list *t) 5988c2ecf20Sopenharmony_ci{ 5998c2ecf20Sopenharmony_ci struct hfi1_ibdev *dev = from_timer(dev, t, mem_timer); 6008c2ecf20Sopenharmony_ci struct list_head *list = &dev->memwait; 6018c2ecf20Sopenharmony_ci struct rvt_qp *qp = NULL; 6028c2ecf20Sopenharmony_ci struct iowait *wait; 6038c2ecf20Sopenharmony_ci unsigned long flags; 6048c2ecf20Sopenharmony_ci struct hfi1_qp_priv *priv; 6058c2ecf20Sopenharmony_ci 6068c2ecf20Sopenharmony_ci write_seqlock_irqsave(&dev->iowait_lock, flags); 6078c2ecf20Sopenharmony_ci if (!list_empty(list)) { 6088c2ecf20Sopenharmony_ci wait = list_first_entry(list, struct iowait, list); 6098c2ecf20Sopenharmony_ci qp = iowait_to_qp(wait); 6108c2ecf20Sopenharmony_ci priv = qp->priv; 6118c2ecf20Sopenharmony_ci list_del_init(&priv->s_iowait.list); 6128c2ecf20Sopenharmony_ci priv->s_iowait.lock = NULL; 6138c2ecf20Sopenharmony_ci /* refcount held until actual wake up */ 6148c2ecf20Sopenharmony_ci if (!list_empty(list)) 6158c2ecf20Sopenharmony_ci mod_timer(&dev->mem_timer, jiffies + 1); 6168c2ecf20Sopenharmony_ci } 6178c2ecf20Sopenharmony_ci write_sequnlock_irqrestore(&dev->iowait_lock, flags); 6188c2ecf20Sopenharmony_ci 6198c2ecf20Sopenharmony_ci if (qp) 6208c2ecf20Sopenharmony_ci hfi1_qp_wakeup(qp, RVT_S_WAIT_KMEM); 6218c2ecf20Sopenharmony_ci} 6228c2ecf20Sopenharmony_ci 6238c2ecf20Sopenharmony_ci/* 6248c2ecf20Sopenharmony_ci * This is called with progress side lock held. 6258c2ecf20Sopenharmony_ci */ 6268c2ecf20Sopenharmony_ci/* New API */ 6278c2ecf20Sopenharmony_cistatic void verbs_sdma_complete( 6288c2ecf20Sopenharmony_ci struct sdma_txreq *cookie, 6298c2ecf20Sopenharmony_ci int status) 6308c2ecf20Sopenharmony_ci{ 6318c2ecf20Sopenharmony_ci struct verbs_txreq *tx = 6328c2ecf20Sopenharmony_ci container_of(cookie, struct verbs_txreq, txreq); 6338c2ecf20Sopenharmony_ci struct rvt_qp *qp = tx->qp; 6348c2ecf20Sopenharmony_ci 6358c2ecf20Sopenharmony_ci spin_lock(&qp->s_lock); 6368c2ecf20Sopenharmony_ci if (tx->wqe) { 6378c2ecf20Sopenharmony_ci rvt_send_complete(qp, tx->wqe, IB_WC_SUCCESS); 6388c2ecf20Sopenharmony_ci } else if (qp->ibqp.qp_type == IB_QPT_RC) { 6398c2ecf20Sopenharmony_ci struct hfi1_opa_header *hdr; 6408c2ecf20Sopenharmony_ci 6418c2ecf20Sopenharmony_ci hdr = &tx->phdr.hdr; 6428c2ecf20Sopenharmony_ci if (unlikely(status == SDMA_TXREQ_S_ABORTED)) 6438c2ecf20Sopenharmony_ci hfi1_rc_verbs_aborted(qp, hdr); 6448c2ecf20Sopenharmony_ci hfi1_rc_send_complete(qp, hdr); 6458c2ecf20Sopenharmony_ci } 6468c2ecf20Sopenharmony_ci spin_unlock(&qp->s_lock); 6478c2ecf20Sopenharmony_ci 6488c2ecf20Sopenharmony_ci hfi1_put_txreq(tx); 6498c2ecf20Sopenharmony_ci} 6508c2ecf20Sopenharmony_ci 6518c2ecf20Sopenharmony_civoid hfi1_wait_kmem(struct rvt_qp *qp) 6528c2ecf20Sopenharmony_ci{ 6538c2ecf20Sopenharmony_ci struct hfi1_qp_priv *priv = qp->priv; 6548c2ecf20Sopenharmony_ci struct ib_qp *ibqp = &qp->ibqp; 6558c2ecf20Sopenharmony_ci struct ib_device *ibdev = ibqp->device; 6568c2ecf20Sopenharmony_ci struct hfi1_ibdev *dev = to_idev(ibdev); 6578c2ecf20Sopenharmony_ci 6588c2ecf20Sopenharmony_ci if (list_empty(&priv->s_iowait.list)) { 6598c2ecf20Sopenharmony_ci if (list_empty(&dev->memwait)) 6608c2ecf20Sopenharmony_ci mod_timer(&dev->mem_timer, jiffies + 1); 6618c2ecf20Sopenharmony_ci qp->s_flags |= RVT_S_WAIT_KMEM; 6628c2ecf20Sopenharmony_ci list_add_tail(&priv->s_iowait.list, &dev->memwait); 6638c2ecf20Sopenharmony_ci priv->s_iowait.lock = &dev->iowait_lock; 6648c2ecf20Sopenharmony_ci trace_hfi1_qpsleep(qp, RVT_S_WAIT_KMEM); 6658c2ecf20Sopenharmony_ci rvt_get_qp(qp); 6668c2ecf20Sopenharmony_ci } 6678c2ecf20Sopenharmony_ci} 6688c2ecf20Sopenharmony_ci 6698c2ecf20Sopenharmony_cistatic int wait_kmem(struct hfi1_ibdev *dev, 6708c2ecf20Sopenharmony_ci struct rvt_qp *qp, 6718c2ecf20Sopenharmony_ci struct hfi1_pkt_state *ps) 6728c2ecf20Sopenharmony_ci{ 6738c2ecf20Sopenharmony_ci unsigned long flags; 6748c2ecf20Sopenharmony_ci int ret = 0; 6758c2ecf20Sopenharmony_ci 6768c2ecf20Sopenharmony_ci spin_lock_irqsave(&qp->s_lock, flags); 6778c2ecf20Sopenharmony_ci if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) { 6788c2ecf20Sopenharmony_ci write_seqlock(&dev->iowait_lock); 6798c2ecf20Sopenharmony_ci list_add_tail(&ps->s_txreq->txreq.list, 6808c2ecf20Sopenharmony_ci &ps->wait->tx_head); 6818c2ecf20Sopenharmony_ci hfi1_wait_kmem(qp); 6828c2ecf20Sopenharmony_ci write_sequnlock(&dev->iowait_lock); 6838c2ecf20Sopenharmony_ci hfi1_qp_unbusy(qp, ps->wait); 6848c2ecf20Sopenharmony_ci ret = -EBUSY; 6858c2ecf20Sopenharmony_ci } 6868c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&qp->s_lock, flags); 6878c2ecf20Sopenharmony_ci 6888c2ecf20Sopenharmony_ci return ret; 6898c2ecf20Sopenharmony_ci} 6908c2ecf20Sopenharmony_ci 6918c2ecf20Sopenharmony_ci/* 6928c2ecf20Sopenharmony_ci * This routine calls txadds for each sg entry. 6938c2ecf20Sopenharmony_ci * 6948c2ecf20Sopenharmony_ci * Add failures will revert the sge cursor 6958c2ecf20Sopenharmony_ci */ 6968c2ecf20Sopenharmony_cistatic noinline int build_verbs_ulp_payload( 6978c2ecf20Sopenharmony_ci struct sdma_engine *sde, 6988c2ecf20Sopenharmony_ci u32 length, 6998c2ecf20Sopenharmony_ci struct verbs_txreq *tx) 7008c2ecf20Sopenharmony_ci{ 7018c2ecf20Sopenharmony_ci struct rvt_sge_state *ss = tx->ss; 7028c2ecf20Sopenharmony_ci struct rvt_sge *sg_list = ss->sg_list; 7038c2ecf20Sopenharmony_ci struct rvt_sge sge = ss->sge; 7048c2ecf20Sopenharmony_ci u8 num_sge = ss->num_sge; 7058c2ecf20Sopenharmony_ci u32 len; 7068c2ecf20Sopenharmony_ci int ret = 0; 7078c2ecf20Sopenharmony_ci 7088c2ecf20Sopenharmony_ci while (length) { 7098c2ecf20Sopenharmony_ci len = rvt_get_sge_length(&ss->sge, length); 7108c2ecf20Sopenharmony_ci WARN_ON_ONCE(len == 0); 7118c2ecf20Sopenharmony_ci ret = sdma_txadd_kvaddr( 7128c2ecf20Sopenharmony_ci sde->dd, 7138c2ecf20Sopenharmony_ci &tx->txreq, 7148c2ecf20Sopenharmony_ci ss->sge.vaddr, 7158c2ecf20Sopenharmony_ci len); 7168c2ecf20Sopenharmony_ci if (ret) 7178c2ecf20Sopenharmony_ci goto bail_txadd; 7188c2ecf20Sopenharmony_ci rvt_update_sge(ss, len, false); 7198c2ecf20Sopenharmony_ci length -= len; 7208c2ecf20Sopenharmony_ci } 7218c2ecf20Sopenharmony_ci return ret; 7228c2ecf20Sopenharmony_cibail_txadd: 7238c2ecf20Sopenharmony_ci /* unwind cursor */ 7248c2ecf20Sopenharmony_ci ss->sge = sge; 7258c2ecf20Sopenharmony_ci ss->num_sge = num_sge; 7268c2ecf20Sopenharmony_ci ss->sg_list = sg_list; 7278c2ecf20Sopenharmony_ci return ret; 7288c2ecf20Sopenharmony_ci} 7298c2ecf20Sopenharmony_ci 7308c2ecf20Sopenharmony_ci/** 7318c2ecf20Sopenharmony_ci * update_tx_opstats - record stats by opcode 7328c2ecf20Sopenharmony_ci * @qp; the qp 7338c2ecf20Sopenharmony_ci * @ps: transmit packet state 7348c2ecf20Sopenharmony_ci * @plen: the plen in dwords 7358c2ecf20Sopenharmony_ci * 7368c2ecf20Sopenharmony_ci * This is a routine to record the tx opstats after a 7378c2ecf20Sopenharmony_ci * packet has been presented to the egress mechanism. 7388c2ecf20Sopenharmony_ci */ 7398c2ecf20Sopenharmony_cistatic void update_tx_opstats(struct rvt_qp *qp, struct hfi1_pkt_state *ps, 7408c2ecf20Sopenharmony_ci u32 plen) 7418c2ecf20Sopenharmony_ci{ 7428c2ecf20Sopenharmony_ci#ifdef CONFIG_DEBUG_FS 7438c2ecf20Sopenharmony_ci struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device); 7448c2ecf20Sopenharmony_ci struct hfi1_opcode_stats_perctx *s = get_cpu_ptr(dd->tx_opstats); 7458c2ecf20Sopenharmony_ci 7468c2ecf20Sopenharmony_ci inc_opstats(plen * 4, &s->stats[ps->opcode]); 7478c2ecf20Sopenharmony_ci put_cpu_ptr(s); 7488c2ecf20Sopenharmony_ci#endif 7498c2ecf20Sopenharmony_ci} 7508c2ecf20Sopenharmony_ci 7518c2ecf20Sopenharmony_ci/* 7528c2ecf20Sopenharmony_ci * Build the number of DMA descriptors needed to send length bytes of data. 7538c2ecf20Sopenharmony_ci * 7548c2ecf20Sopenharmony_ci * NOTE: DMA mapping is held in the tx until completed in the ring or 7558c2ecf20Sopenharmony_ci * the tx desc is freed without having been submitted to the ring 7568c2ecf20Sopenharmony_ci * 7578c2ecf20Sopenharmony_ci * This routine ensures all the helper routine calls succeed. 7588c2ecf20Sopenharmony_ci */ 7598c2ecf20Sopenharmony_ci/* New API */ 7608c2ecf20Sopenharmony_cistatic int build_verbs_tx_desc( 7618c2ecf20Sopenharmony_ci struct sdma_engine *sde, 7628c2ecf20Sopenharmony_ci u32 length, 7638c2ecf20Sopenharmony_ci struct verbs_txreq *tx, 7648c2ecf20Sopenharmony_ci struct hfi1_ahg_info *ahg_info, 7658c2ecf20Sopenharmony_ci u64 pbc) 7668c2ecf20Sopenharmony_ci{ 7678c2ecf20Sopenharmony_ci int ret = 0; 7688c2ecf20Sopenharmony_ci struct hfi1_sdma_header *phdr = &tx->phdr; 7698c2ecf20Sopenharmony_ci u16 hdrbytes = (tx->hdr_dwords + sizeof(pbc) / 4) << 2; 7708c2ecf20Sopenharmony_ci u8 extra_bytes = 0; 7718c2ecf20Sopenharmony_ci 7728c2ecf20Sopenharmony_ci if (tx->phdr.hdr.hdr_type) { 7738c2ecf20Sopenharmony_ci /* 7748c2ecf20Sopenharmony_ci * hdrbytes accounts for PBC. Need to subtract 8 bytes 7758c2ecf20Sopenharmony_ci * before calculating padding. 7768c2ecf20Sopenharmony_ci */ 7778c2ecf20Sopenharmony_ci extra_bytes = hfi1_get_16b_padding(hdrbytes - 8, length) + 7788c2ecf20Sopenharmony_ci (SIZE_OF_CRC << 2) + SIZE_OF_LT; 7798c2ecf20Sopenharmony_ci } 7808c2ecf20Sopenharmony_ci if (!ahg_info->ahgcount) { 7818c2ecf20Sopenharmony_ci ret = sdma_txinit_ahg( 7828c2ecf20Sopenharmony_ci &tx->txreq, 7838c2ecf20Sopenharmony_ci ahg_info->tx_flags, 7848c2ecf20Sopenharmony_ci hdrbytes + length + 7858c2ecf20Sopenharmony_ci extra_bytes, 7868c2ecf20Sopenharmony_ci ahg_info->ahgidx, 7878c2ecf20Sopenharmony_ci 0, 7888c2ecf20Sopenharmony_ci NULL, 7898c2ecf20Sopenharmony_ci 0, 7908c2ecf20Sopenharmony_ci verbs_sdma_complete); 7918c2ecf20Sopenharmony_ci if (ret) 7928c2ecf20Sopenharmony_ci goto bail_txadd; 7938c2ecf20Sopenharmony_ci phdr->pbc = cpu_to_le64(pbc); 7948c2ecf20Sopenharmony_ci ret = sdma_txadd_kvaddr( 7958c2ecf20Sopenharmony_ci sde->dd, 7968c2ecf20Sopenharmony_ci &tx->txreq, 7978c2ecf20Sopenharmony_ci phdr, 7988c2ecf20Sopenharmony_ci hdrbytes); 7998c2ecf20Sopenharmony_ci if (ret) 8008c2ecf20Sopenharmony_ci goto bail_txadd; 8018c2ecf20Sopenharmony_ci } else { 8028c2ecf20Sopenharmony_ci ret = sdma_txinit_ahg( 8038c2ecf20Sopenharmony_ci &tx->txreq, 8048c2ecf20Sopenharmony_ci ahg_info->tx_flags, 8058c2ecf20Sopenharmony_ci length, 8068c2ecf20Sopenharmony_ci ahg_info->ahgidx, 8078c2ecf20Sopenharmony_ci ahg_info->ahgcount, 8088c2ecf20Sopenharmony_ci ahg_info->ahgdesc, 8098c2ecf20Sopenharmony_ci hdrbytes, 8108c2ecf20Sopenharmony_ci verbs_sdma_complete); 8118c2ecf20Sopenharmony_ci if (ret) 8128c2ecf20Sopenharmony_ci goto bail_txadd; 8138c2ecf20Sopenharmony_ci } 8148c2ecf20Sopenharmony_ci /* add the ulp payload - if any. tx->ss can be NULL for acks */ 8158c2ecf20Sopenharmony_ci if (tx->ss) { 8168c2ecf20Sopenharmony_ci ret = build_verbs_ulp_payload(sde, length, tx); 8178c2ecf20Sopenharmony_ci if (ret) 8188c2ecf20Sopenharmony_ci goto bail_txadd; 8198c2ecf20Sopenharmony_ci } 8208c2ecf20Sopenharmony_ci 8218c2ecf20Sopenharmony_ci /* add icrc, lt byte, and padding to flit */ 8228c2ecf20Sopenharmony_ci if (extra_bytes) 8238c2ecf20Sopenharmony_ci ret = sdma_txadd_daddr(sde->dd, &tx->txreq, sde->dd->sdma_pad_phys, 8248c2ecf20Sopenharmony_ci extra_bytes); 8258c2ecf20Sopenharmony_ci 8268c2ecf20Sopenharmony_cibail_txadd: 8278c2ecf20Sopenharmony_ci return ret; 8288c2ecf20Sopenharmony_ci} 8298c2ecf20Sopenharmony_ci 8308c2ecf20Sopenharmony_cistatic u64 update_hcrc(u8 opcode, u64 pbc) 8318c2ecf20Sopenharmony_ci{ 8328c2ecf20Sopenharmony_ci if ((opcode & IB_OPCODE_TID_RDMA) == IB_OPCODE_TID_RDMA) { 8338c2ecf20Sopenharmony_ci pbc &= ~PBC_INSERT_HCRC_SMASK; 8348c2ecf20Sopenharmony_ci pbc |= (u64)PBC_IHCRC_LKDETH << PBC_INSERT_HCRC_SHIFT; 8358c2ecf20Sopenharmony_ci } 8368c2ecf20Sopenharmony_ci return pbc; 8378c2ecf20Sopenharmony_ci} 8388c2ecf20Sopenharmony_ci 8398c2ecf20Sopenharmony_ciint hfi1_verbs_send_dma(struct rvt_qp *qp, struct hfi1_pkt_state *ps, 8408c2ecf20Sopenharmony_ci u64 pbc) 8418c2ecf20Sopenharmony_ci{ 8428c2ecf20Sopenharmony_ci struct hfi1_qp_priv *priv = qp->priv; 8438c2ecf20Sopenharmony_ci struct hfi1_ahg_info *ahg_info = priv->s_ahg; 8448c2ecf20Sopenharmony_ci u32 hdrwords = ps->s_txreq->hdr_dwords; 8458c2ecf20Sopenharmony_ci u32 len = ps->s_txreq->s_cur_size; 8468c2ecf20Sopenharmony_ci u32 plen; 8478c2ecf20Sopenharmony_ci struct hfi1_ibdev *dev = ps->dev; 8488c2ecf20Sopenharmony_ci struct hfi1_pportdata *ppd = ps->ppd; 8498c2ecf20Sopenharmony_ci struct verbs_txreq *tx; 8508c2ecf20Sopenharmony_ci u8 sc5 = priv->s_sc; 8518c2ecf20Sopenharmony_ci int ret; 8528c2ecf20Sopenharmony_ci u32 dwords; 8538c2ecf20Sopenharmony_ci 8548c2ecf20Sopenharmony_ci if (ps->s_txreq->phdr.hdr.hdr_type) { 8558c2ecf20Sopenharmony_ci u8 extra_bytes = hfi1_get_16b_padding((hdrwords << 2), len); 8568c2ecf20Sopenharmony_ci 8578c2ecf20Sopenharmony_ci dwords = (len + extra_bytes + (SIZE_OF_CRC << 2) + 8588c2ecf20Sopenharmony_ci SIZE_OF_LT) >> 2; 8598c2ecf20Sopenharmony_ci } else { 8608c2ecf20Sopenharmony_ci dwords = (len + 3) >> 2; 8618c2ecf20Sopenharmony_ci } 8628c2ecf20Sopenharmony_ci plen = hdrwords + dwords + sizeof(pbc) / 4; 8638c2ecf20Sopenharmony_ci 8648c2ecf20Sopenharmony_ci tx = ps->s_txreq; 8658c2ecf20Sopenharmony_ci if (!sdma_txreq_built(&tx->txreq)) { 8668c2ecf20Sopenharmony_ci if (likely(pbc == 0)) { 8678c2ecf20Sopenharmony_ci u32 vl = sc_to_vlt(dd_from_ibdev(qp->ibqp.device), sc5); 8688c2ecf20Sopenharmony_ci 8698c2ecf20Sopenharmony_ci /* No vl15 here */ 8708c2ecf20Sopenharmony_ci /* set PBC_DC_INFO bit (aka SC[4]) in pbc */ 8718c2ecf20Sopenharmony_ci if (ps->s_txreq->phdr.hdr.hdr_type) 8728c2ecf20Sopenharmony_ci pbc |= PBC_PACKET_BYPASS | 8738c2ecf20Sopenharmony_ci PBC_INSERT_BYPASS_ICRC; 8748c2ecf20Sopenharmony_ci else 8758c2ecf20Sopenharmony_ci pbc |= (ib_is_sc5(sc5) << PBC_DC_INFO_SHIFT); 8768c2ecf20Sopenharmony_ci 8778c2ecf20Sopenharmony_ci pbc = create_pbc(ppd, 8788c2ecf20Sopenharmony_ci pbc, 8798c2ecf20Sopenharmony_ci qp->srate_mbps, 8808c2ecf20Sopenharmony_ci vl, 8818c2ecf20Sopenharmony_ci plen); 8828c2ecf20Sopenharmony_ci 8838c2ecf20Sopenharmony_ci if (unlikely(hfi1_dbg_should_fault_tx(qp, ps->opcode))) 8848c2ecf20Sopenharmony_ci pbc = hfi1_fault_tx(qp, ps->opcode, pbc); 8858c2ecf20Sopenharmony_ci else 8868c2ecf20Sopenharmony_ci /* Update HCRC based on packet opcode */ 8878c2ecf20Sopenharmony_ci pbc = update_hcrc(ps->opcode, pbc); 8888c2ecf20Sopenharmony_ci } 8898c2ecf20Sopenharmony_ci tx->wqe = qp->s_wqe; 8908c2ecf20Sopenharmony_ci ret = build_verbs_tx_desc(tx->sde, len, tx, ahg_info, pbc); 8918c2ecf20Sopenharmony_ci if (unlikely(ret)) 8928c2ecf20Sopenharmony_ci goto bail_build; 8938c2ecf20Sopenharmony_ci } 8948c2ecf20Sopenharmony_ci ret = sdma_send_txreq(tx->sde, ps->wait, &tx->txreq, ps->pkts_sent); 8958c2ecf20Sopenharmony_ci if (unlikely(ret < 0)) { 8968c2ecf20Sopenharmony_ci if (ret == -ECOMM) 8978c2ecf20Sopenharmony_ci goto bail_ecomm; 8988c2ecf20Sopenharmony_ci return ret; 8998c2ecf20Sopenharmony_ci } 9008c2ecf20Sopenharmony_ci 9018c2ecf20Sopenharmony_ci update_tx_opstats(qp, ps, plen); 9028c2ecf20Sopenharmony_ci trace_sdma_output_ibhdr(dd_from_ibdev(qp->ibqp.device), 9038c2ecf20Sopenharmony_ci &ps->s_txreq->phdr.hdr, ib_is_sc5(sc5)); 9048c2ecf20Sopenharmony_ci return ret; 9058c2ecf20Sopenharmony_ci 9068c2ecf20Sopenharmony_cibail_ecomm: 9078c2ecf20Sopenharmony_ci /* The current one got "sent" */ 9088c2ecf20Sopenharmony_ci return 0; 9098c2ecf20Sopenharmony_cibail_build: 9108c2ecf20Sopenharmony_ci ret = wait_kmem(dev, qp, ps); 9118c2ecf20Sopenharmony_ci if (!ret) { 9128c2ecf20Sopenharmony_ci /* free txreq - bad state */ 9138c2ecf20Sopenharmony_ci hfi1_put_txreq(ps->s_txreq); 9148c2ecf20Sopenharmony_ci ps->s_txreq = NULL; 9158c2ecf20Sopenharmony_ci } 9168c2ecf20Sopenharmony_ci return ret; 9178c2ecf20Sopenharmony_ci} 9188c2ecf20Sopenharmony_ci 9198c2ecf20Sopenharmony_ci/* 9208c2ecf20Sopenharmony_ci * If we are now in the error state, return zero to flush the 9218c2ecf20Sopenharmony_ci * send work request. 9228c2ecf20Sopenharmony_ci */ 9238c2ecf20Sopenharmony_cistatic int pio_wait(struct rvt_qp *qp, 9248c2ecf20Sopenharmony_ci struct send_context *sc, 9258c2ecf20Sopenharmony_ci struct hfi1_pkt_state *ps, 9268c2ecf20Sopenharmony_ci u32 flag) 9278c2ecf20Sopenharmony_ci{ 9288c2ecf20Sopenharmony_ci struct hfi1_qp_priv *priv = qp->priv; 9298c2ecf20Sopenharmony_ci struct hfi1_devdata *dd = sc->dd; 9308c2ecf20Sopenharmony_ci unsigned long flags; 9318c2ecf20Sopenharmony_ci int ret = 0; 9328c2ecf20Sopenharmony_ci 9338c2ecf20Sopenharmony_ci /* 9348c2ecf20Sopenharmony_ci * Note that as soon as want_buffer() is called and 9358c2ecf20Sopenharmony_ci * possibly before it returns, sc_piobufavail() 9368c2ecf20Sopenharmony_ci * could be called. Therefore, put QP on the I/O wait list before 9378c2ecf20Sopenharmony_ci * enabling the PIO avail interrupt. 9388c2ecf20Sopenharmony_ci */ 9398c2ecf20Sopenharmony_ci spin_lock_irqsave(&qp->s_lock, flags); 9408c2ecf20Sopenharmony_ci if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) { 9418c2ecf20Sopenharmony_ci write_seqlock(&sc->waitlock); 9428c2ecf20Sopenharmony_ci list_add_tail(&ps->s_txreq->txreq.list, 9438c2ecf20Sopenharmony_ci &ps->wait->tx_head); 9448c2ecf20Sopenharmony_ci if (list_empty(&priv->s_iowait.list)) { 9458c2ecf20Sopenharmony_ci struct hfi1_ibdev *dev = &dd->verbs_dev; 9468c2ecf20Sopenharmony_ci int was_empty; 9478c2ecf20Sopenharmony_ci 9488c2ecf20Sopenharmony_ci dev->n_piowait += !!(flag & RVT_S_WAIT_PIO); 9498c2ecf20Sopenharmony_ci dev->n_piodrain += !!(flag & HFI1_S_WAIT_PIO_DRAIN); 9508c2ecf20Sopenharmony_ci qp->s_flags |= flag; 9518c2ecf20Sopenharmony_ci was_empty = list_empty(&sc->piowait); 9528c2ecf20Sopenharmony_ci iowait_get_priority(&priv->s_iowait); 9538c2ecf20Sopenharmony_ci iowait_queue(ps->pkts_sent, &priv->s_iowait, 9548c2ecf20Sopenharmony_ci &sc->piowait); 9558c2ecf20Sopenharmony_ci priv->s_iowait.lock = &sc->waitlock; 9568c2ecf20Sopenharmony_ci trace_hfi1_qpsleep(qp, RVT_S_WAIT_PIO); 9578c2ecf20Sopenharmony_ci rvt_get_qp(qp); 9588c2ecf20Sopenharmony_ci /* counting: only call wantpiobuf_intr if first user */ 9598c2ecf20Sopenharmony_ci if (was_empty) 9608c2ecf20Sopenharmony_ci hfi1_sc_wantpiobuf_intr(sc, 1); 9618c2ecf20Sopenharmony_ci } 9628c2ecf20Sopenharmony_ci write_sequnlock(&sc->waitlock); 9638c2ecf20Sopenharmony_ci hfi1_qp_unbusy(qp, ps->wait); 9648c2ecf20Sopenharmony_ci ret = -EBUSY; 9658c2ecf20Sopenharmony_ci } 9668c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&qp->s_lock, flags); 9678c2ecf20Sopenharmony_ci return ret; 9688c2ecf20Sopenharmony_ci} 9698c2ecf20Sopenharmony_ci 9708c2ecf20Sopenharmony_cistatic void verbs_pio_complete(void *arg, int code) 9718c2ecf20Sopenharmony_ci{ 9728c2ecf20Sopenharmony_ci struct rvt_qp *qp = (struct rvt_qp *)arg; 9738c2ecf20Sopenharmony_ci struct hfi1_qp_priv *priv = qp->priv; 9748c2ecf20Sopenharmony_ci 9758c2ecf20Sopenharmony_ci if (iowait_pio_dec(&priv->s_iowait)) 9768c2ecf20Sopenharmony_ci iowait_drain_wakeup(&priv->s_iowait); 9778c2ecf20Sopenharmony_ci} 9788c2ecf20Sopenharmony_ci 9798c2ecf20Sopenharmony_ciint hfi1_verbs_send_pio(struct rvt_qp *qp, struct hfi1_pkt_state *ps, 9808c2ecf20Sopenharmony_ci u64 pbc) 9818c2ecf20Sopenharmony_ci{ 9828c2ecf20Sopenharmony_ci struct hfi1_qp_priv *priv = qp->priv; 9838c2ecf20Sopenharmony_ci u32 hdrwords = ps->s_txreq->hdr_dwords; 9848c2ecf20Sopenharmony_ci struct rvt_sge_state *ss = ps->s_txreq->ss; 9858c2ecf20Sopenharmony_ci u32 len = ps->s_txreq->s_cur_size; 9868c2ecf20Sopenharmony_ci u32 dwords; 9878c2ecf20Sopenharmony_ci u32 plen; 9888c2ecf20Sopenharmony_ci struct hfi1_pportdata *ppd = ps->ppd; 9898c2ecf20Sopenharmony_ci u32 *hdr; 9908c2ecf20Sopenharmony_ci u8 sc5; 9918c2ecf20Sopenharmony_ci unsigned long flags = 0; 9928c2ecf20Sopenharmony_ci struct send_context *sc; 9938c2ecf20Sopenharmony_ci struct pio_buf *pbuf; 9948c2ecf20Sopenharmony_ci int wc_status = IB_WC_SUCCESS; 9958c2ecf20Sopenharmony_ci int ret = 0; 9968c2ecf20Sopenharmony_ci pio_release_cb cb = NULL; 9978c2ecf20Sopenharmony_ci u8 extra_bytes = 0; 9988c2ecf20Sopenharmony_ci 9998c2ecf20Sopenharmony_ci if (ps->s_txreq->phdr.hdr.hdr_type) { 10008c2ecf20Sopenharmony_ci u8 pad_size = hfi1_get_16b_padding((hdrwords << 2), len); 10018c2ecf20Sopenharmony_ci 10028c2ecf20Sopenharmony_ci extra_bytes = pad_size + (SIZE_OF_CRC << 2) + SIZE_OF_LT; 10038c2ecf20Sopenharmony_ci dwords = (len + extra_bytes) >> 2; 10048c2ecf20Sopenharmony_ci hdr = (u32 *)&ps->s_txreq->phdr.hdr.opah; 10058c2ecf20Sopenharmony_ci } else { 10068c2ecf20Sopenharmony_ci dwords = (len + 3) >> 2; 10078c2ecf20Sopenharmony_ci hdr = (u32 *)&ps->s_txreq->phdr.hdr.ibh; 10088c2ecf20Sopenharmony_ci } 10098c2ecf20Sopenharmony_ci plen = hdrwords + dwords + sizeof(pbc) / 4; 10108c2ecf20Sopenharmony_ci 10118c2ecf20Sopenharmony_ci /* only RC/UC use complete */ 10128c2ecf20Sopenharmony_ci switch (qp->ibqp.qp_type) { 10138c2ecf20Sopenharmony_ci case IB_QPT_RC: 10148c2ecf20Sopenharmony_ci case IB_QPT_UC: 10158c2ecf20Sopenharmony_ci cb = verbs_pio_complete; 10168c2ecf20Sopenharmony_ci break; 10178c2ecf20Sopenharmony_ci default: 10188c2ecf20Sopenharmony_ci break; 10198c2ecf20Sopenharmony_ci } 10208c2ecf20Sopenharmony_ci 10218c2ecf20Sopenharmony_ci /* vl15 special case taken care of in ud.c */ 10228c2ecf20Sopenharmony_ci sc5 = priv->s_sc; 10238c2ecf20Sopenharmony_ci sc = ps->s_txreq->psc; 10248c2ecf20Sopenharmony_ci 10258c2ecf20Sopenharmony_ci if (likely(pbc == 0)) { 10268c2ecf20Sopenharmony_ci u8 vl = sc_to_vlt(dd_from_ibdev(qp->ibqp.device), sc5); 10278c2ecf20Sopenharmony_ci 10288c2ecf20Sopenharmony_ci /* set PBC_DC_INFO bit (aka SC[4]) in pbc */ 10298c2ecf20Sopenharmony_ci if (ps->s_txreq->phdr.hdr.hdr_type) 10308c2ecf20Sopenharmony_ci pbc |= PBC_PACKET_BYPASS | PBC_INSERT_BYPASS_ICRC; 10318c2ecf20Sopenharmony_ci else 10328c2ecf20Sopenharmony_ci pbc |= (ib_is_sc5(sc5) << PBC_DC_INFO_SHIFT); 10338c2ecf20Sopenharmony_ci 10348c2ecf20Sopenharmony_ci pbc = create_pbc(ppd, pbc, qp->srate_mbps, vl, plen); 10358c2ecf20Sopenharmony_ci if (unlikely(hfi1_dbg_should_fault_tx(qp, ps->opcode))) 10368c2ecf20Sopenharmony_ci pbc = hfi1_fault_tx(qp, ps->opcode, pbc); 10378c2ecf20Sopenharmony_ci else 10388c2ecf20Sopenharmony_ci /* Update HCRC based on packet opcode */ 10398c2ecf20Sopenharmony_ci pbc = update_hcrc(ps->opcode, pbc); 10408c2ecf20Sopenharmony_ci } 10418c2ecf20Sopenharmony_ci if (cb) 10428c2ecf20Sopenharmony_ci iowait_pio_inc(&priv->s_iowait); 10438c2ecf20Sopenharmony_ci pbuf = sc_buffer_alloc(sc, plen, cb, qp); 10448c2ecf20Sopenharmony_ci if (IS_ERR_OR_NULL(pbuf)) { 10458c2ecf20Sopenharmony_ci if (cb) 10468c2ecf20Sopenharmony_ci verbs_pio_complete(qp, 0); 10478c2ecf20Sopenharmony_ci if (IS_ERR(pbuf)) { 10488c2ecf20Sopenharmony_ci /* 10498c2ecf20Sopenharmony_ci * If we have filled the PIO buffers to capacity and are 10508c2ecf20Sopenharmony_ci * not in an active state this request is not going to 10518c2ecf20Sopenharmony_ci * go out to so just complete it with an error or else a 10528c2ecf20Sopenharmony_ci * ULP or the core may be stuck waiting. 10538c2ecf20Sopenharmony_ci */ 10548c2ecf20Sopenharmony_ci hfi1_cdbg( 10558c2ecf20Sopenharmony_ci PIO, 10568c2ecf20Sopenharmony_ci "alloc failed. state not active, completing"); 10578c2ecf20Sopenharmony_ci wc_status = IB_WC_GENERAL_ERR; 10588c2ecf20Sopenharmony_ci goto pio_bail; 10598c2ecf20Sopenharmony_ci } else { 10608c2ecf20Sopenharmony_ci /* 10618c2ecf20Sopenharmony_ci * This is a normal occurrence. The PIO buffs are full 10628c2ecf20Sopenharmony_ci * up but we are still happily sending, well we could be 10638c2ecf20Sopenharmony_ci * so lets continue to queue the request. 10648c2ecf20Sopenharmony_ci */ 10658c2ecf20Sopenharmony_ci hfi1_cdbg(PIO, "alloc failed. state active, queuing"); 10668c2ecf20Sopenharmony_ci ret = pio_wait(qp, sc, ps, RVT_S_WAIT_PIO); 10678c2ecf20Sopenharmony_ci if (!ret) 10688c2ecf20Sopenharmony_ci /* txreq not queued - free */ 10698c2ecf20Sopenharmony_ci goto bail; 10708c2ecf20Sopenharmony_ci /* tx consumed in wait */ 10718c2ecf20Sopenharmony_ci return ret; 10728c2ecf20Sopenharmony_ci } 10738c2ecf20Sopenharmony_ci } 10748c2ecf20Sopenharmony_ci 10758c2ecf20Sopenharmony_ci if (dwords == 0) { 10768c2ecf20Sopenharmony_ci pio_copy(ppd->dd, pbuf, pbc, hdr, hdrwords); 10778c2ecf20Sopenharmony_ci } else { 10788c2ecf20Sopenharmony_ci seg_pio_copy_start(pbuf, pbc, 10798c2ecf20Sopenharmony_ci hdr, hdrwords * 4); 10808c2ecf20Sopenharmony_ci if (ss) { 10818c2ecf20Sopenharmony_ci while (len) { 10828c2ecf20Sopenharmony_ci void *addr = ss->sge.vaddr; 10838c2ecf20Sopenharmony_ci u32 slen = rvt_get_sge_length(&ss->sge, len); 10848c2ecf20Sopenharmony_ci 10858c2ecf20Sopenharmony_ci rvt_update_sge(ss, slen, false); 10868c2ecf20Sopenharmony_ci seg_pio_copy_mid(pbuf, addr, slen); 10878c2ecf20Sopenharmony_ci len -= slen; 10888c2ecf20Sopenharmony_ci } 10898c2ecf20Sopenharmony_ci } 10908c2ecf20Sopenharmony_ci /* add icrc, lt byte, and padding to flit */ 10918c2ecf20Sopenharmony_ci if (extra_bytes) 10928c2ecf20Sopenharmony_ci seg_pio_copy_mid(pbuf, ppd->dd->sdma_pad_dma, 10938c2ecf20Sopenharmony_ci extra_bytes); 10948c2ecf20Sopenharmony_ci 10958c2ecf20Sopenharmony_ci seg_pio_copy_end(pbuf); 10968c2ecf20Sopenharmony_ci } 10978c2ecf20Sopenharmony_ci 10988c2ecf20Sopenharmony_ci update_tx_opstats(qp, ps, plen); 10998c2ecf20Sopenharmony_ci trace_pio_output_ibhdr(dd_from_ibdev(qp->ibqp.device), 11008c2ecf20Sopenharmony_ci &ps->s_txreq->phdr.hdr, ib_is_sc5(sc5)); 11018c2ecf20Sopenharmony_ci 11028c2ecf20Sopenharmony_cipio_bail: 11038c2ecf20Sopenharmony_ci spin_lock_irqsave(&qp->s_lock, flags); 11048c2ecf20Sopenharmony_ci if (qp->s_wqe) { 11058c2ecf20Sopenharmony_ci rvt_send_complete(qp, qp->s_wqe, wc_status); 11068c2ecf20Sopenharmony_ci } else if (qp->ibqp.qp_type == IB_QPT_RC) { 11078c2ecf20Sopenharmony_ci if (unlikely(wc_status == IB_WC_GENERAL_ERR)) 11088c2ecf20Sopenharmony_ci hfi1_rc_verbs_aborted(qp, &ps->s_txreq->phdr.hdr); 11098c2ecf20Sopenharmony_ci hfi1_rc_send_complete(qp, &ps->s_txreq->phdr.hdr); 11108c2ecf20Sopenharmony_ci } 11118c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&qp->s_lock, flags); 11128c2ecf20Sopenharmony_ci 11138c2ecf20Sopenharmony_ci ret = 0; 11148c2ecf20Sopenharmony_ci 11158c2ecf20Sopenharmony_cibail: 11168c2ecf20Sopenharmony_ci hfi1_put_txreq(ps->s_txreq); 11178c2ecf20Sopenharmony_ci return ret; 11188c2ecf20Sopenharmony_ci} 11198c2ecf20Sopenharmony_ci 11208c2ecf20Sopenharmony_ci/* 11218c2ecf20Sopenharmony_ci * egress_pkey_matches_entry - return 1 if the pkey matches ent (ent 11228c2ecf20Sopenharmony_ci * being an entry from the partition key table), return 0 11238c2ecf20Sopenharmony_ci * otherwise. Use the matching criteria for egress partition keys 11248c2ecf20Sopenharmony_ci * specified in the OPAv1 spec., section 9.1l.7. 11258c2ecf20Sopenharmony_ci */ 11268c2ecf20Sopenharmony_cistatic inline int egress_pkey_matches_entry(u16 pkey, u16 ent) 11278c2ecf20Sopenharmony_ci{ 11288c2ecf20Sopenharmony_ci u16 mkey = pkey & PKEY_LOW_15_MASK; 11298c2ecf20Sopenharmony_ci u16 mentry = ent & PKEY_LOW_15_MASK; 11308c2ecf20Sopenharmony_ci 11318c2ecf20Sopenharmony_ci if (mkey == mentry) { 11328c2ecf20Sopenharmony_ci /* 11338c2ecf20Sopenharmony_ci * If pkey[15] is set (full partition member), 11348c2ecf20Sopenharmony_ci * is bit 15 in the corresponding table element 11358c2ecf20Sopenharmony_ci * clear (limited member)? 11368c2ecf20Sopenharmony_ci */ 11378c2ecf20Sopenharmony_ci if (pkey & PKEY_MEMBER_MASK) 11388c2ecf20Sopenharmony_ci return !!(ent & PKEY_MEMBER_MASK); 11398c2ecf20Sopenharmony_ci return 1; 11408c2ecf20Sopenharmony_ci } 11418c2ecf20Sopenharmony_ci return 0; 11428c2ecf20Sopenharmony_ci} 11438c2ecf20Sopenharmony_ci 11448c2ecf20Sopenharmony_ci/** 11458c2ecf20Sopenharmony_ci * egress_pkey_check - check P_KEY of a packet 11468c2ecf20Sopenharmony_ci * @ppd: Physical IB port data 11478c2ecf20Sopenharmony_ci * @slid: SLID for packet 11488c2ecf20Sopenharmony_ci * @bkey: PKEY for header 11498c2ecf20Sopenharmony_ci * @sc5: SC for packet 11508c2ecf20Sopenharmony_ci * @s_pkey_index: It will be used for look up optimization for kernel contexts 11518c2ecf20Sopenharmony_ci * only. If it is negative value, then it means user contexts is calling this 11528c2ecf20Sopenharmony_ci * function. 11538c2ecf20Sopenharmony_ci * 11548c2ecf20Sopenharmony_ci * It checks if hdr's pkey is valid. 11558c2ecf20Sopenharmony_ci * 11568c2ecf20Sopenharmony_ci * Return: 0 on success, otherwise, 1 11578c2ecf20Sopenharmony_ci */ 11588c2ecf20Sopenharmony_ciint egress_pkey_check(struct hfi1_pportdata *ppd, u32 slid, u16 pkey, 11598c2ecf20Sopenharmony_ci u8 sc5, int8_t s_pkey_index) 11608c2ecf20Sopenharmony_ci{ 11618c2ecf20Sopenharmony_ci struct hfi1_devdata *dd; 11628c2ecf20Sopenharmony_ci int i; 11638c2ecf20Sopenharmony_ci int is_user_ctxt_mechanism = (s_pkey_index < 0); 11648c2ecf20Sopenharmony_ci 11658c2ecf20Sopenharmony_ci if (!(ppd->part_enforce & HFI1_PART_ENFORCE_OUT)) 11668c2ecf20Sopenharmony_ci return 0; 11678c2ecf20Sopenharmony_ci 11688c2ecf20Sopenharmony_ci /* If SC15, pkey[0:14] must be 0x7fff */ 11698c2ecf20Sopenharmony_ci if ((sc5 == 0xf) && ((pkey & PKEY_LOW_15_MASK) != PKEY_LOW_15_MASK)) 11708c2ecf20Sopenharmony_ci goto bad; 11718c2ecf20Sopenharmony_ci 11728c2ecf20Sopenharmony_ci /* Is the pkey = 0x0, or 0x8000? */ 11738c2ecf20Sopenharmony_ci if ((pkey & PKEY_LOW_15_MASK) == 0) 11748c2ecf20Sopenharmony_ci goto bad; 11758c2ecf20Sopenharmony_ci 11768c2ecf20Sopenharmony_ci /* 11778c2ecf20Sopenharmony_ci * For the kernel contexts only, if a qp is passed into the function, 11788c2ecf20Sopenharmony_ci * the most likely matching pkey has index qp->s_pkey_index 11798c2ecf20Sopenharmony_ci */ 11808c2ecf20Sopenharmony_ci if (!is_user_ctxt_mechanism && 11818c2ecf20Sopenharmony_ci egress_pkey_matches_entry(pkey, ppd->pkeys[s_pkey_index])) { 11828c2ecf20Sopenharmony_ci return 0; 11838c2ecf20Sopenharmony_ci } 11848c2ecf20Sopenharmony_ci 11858c2ecf20Sopenharmony_ci for (i = 0; i < MAX_PKEY_VALUES; i++) { 11868c2ecf20Sopenharmony_ci if (egress_pkey_matches_entry(pkey, ppd->pkeys[i])) 11878c2ecf20Sopenharmony_ci return 0; 11888c2ecf20Sopenharmony_ci } 11898c2ecf20Sopenharmony_cibad: 11908c2ecf20Sopenharmony_ci /* 11918c2ecf20Sopenharmony_ci * For the user-context mechanism, the P_KEY check would only happen 11928c2ecf20Sopenharmony_ci * once per SDMA request, not once per packet. Therefore, there's no 11938c2ecf20Sopenharmony_ci * need to increment the counter for the user-context mechanism. 11948c2ecf20Sopenharmony_ci */ 11958c2ecf20Sopenharmony_ci if (!is_user_ctxt_mechanism) { 11968c2ecf20Sopenharmony_ci incr_cntr64(&ppd->port_xmit_constraint_errors); 11978c2ecf20Sopenharmony_ci dd = ppd->dd; 11988c2ecf20Sopenharmony_ci if (!(dd->err_info_xmit_constraint.status & 11998c2ecf20Sopenharmony_ci OPA_EI_STATUS_SMASK)) { 12008c2ecf20Sopenharmony_ci dd->err_info_xmit_constraint.status |= 12018c2ecf20Sopenharmony_ci OPA_EI_STATUS_SMASK; 12028c2ecf20Sopenharmony_ci dd->err_info_xmit_constraint.slid = slid; 12038c2ecf20Sopenharmony_ci dd->err_info_xmit_constraint.pkey = pkey; 12048c2ecf20Sopenharmony_ci } 12058c2ecf20Sopenharmony_ci } 12068c2ecf20Sopenharmony_ci return 1; 12078c2ecf20Sopenharmony_ci} 12088c2ecf20Sopenharmony_ci 12098c2ecf20Sopenharmony_ci/** 12108c2ecf20Sopenharmony_ci * get_send_routine - choose an egress routine 12118c2ecf20Sopenharmony_ci * 12128c2ecf20Sopenharmony_ci * Choose an egress routine based on QP type 12138c2ecf20Sopenharmony_ci * and size 12148c2ecf20Sopenharmony_ci */ 12158c2ecf20Sopenharmony_cistatic inline send_routine get_send_routine(struct rvt_qp *qp, 12168c2ecf20Sopenharmony_ci struct hfi1_pkt_state *ps) 12178c2ecf20Sopenharmony_ci{ 12188c2ecf20Sopenharmony_ci struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device); 12198c2ecf20Sopenharmony_ci struct hfi1_qp_priv *priv = qp->priv; 12208c2ecf20Sopenharmony_ci struct verbs_txreq *tx = ps->s_txreq; 12218c2ecf20Sopenharmony_ci 12228c2ecf20Sopenharmony_ci if (unlikely(!(dd->flags & HFI1_HAS_SEND_DMA))) 12238c2ecf20Sopenharmony_ci return dd->process_pio_send; 12248c2ecf20Sopenharmony_ci switch (qp->ibqp.qp_type) { 12258c2ecf20Sopenharmony_ci case IB_QPT_SMI: 12268c2ecf20Sopenharmony_ci return dd->process_pio_send; 12278c2ecf20Sopenharmony_ci case IB_QPT_GSI: 12288c2ecf20Sopenharmony_ci case IB_QPT_UD: 12298c2ecf20Sopenharmony_ci break; 12308c2ecf20Sopenharmony_ci case IB_QPT_UC: 12318c2ecf20Sopenharmony_ci case IB_QPT_RC: 12328c2ecf20Sopenharmony_ci priv->s_running_pkt_size = 12338c2ecf20Sopenharmony_ci (tx->s_cur_size + priv->s_running_pkt_size) / 2; 12348c2ecf20Sopenharmony_ci if (piothreshold && 12358c2ecf20Sopenharmony_ci priv->s_running_pkt_size <= min(piothreshold, qp->pmtu) && 12368c2ecf20Sopenharmony_ci (BIT(ps->opcode & OPMASK) & pio_opmask[ps->opcode >> 5]) && 12378c2ecf20Sopenharmony_ci iowait_sdma_pending(&priv->s_iowait) == 0 && 12388c2ecf20Sopenharmony_ci !sdma_txreq_built(&tx->txreq)) 12398c2ecf20Sopenharmony_ci return dd->process_pio_send; 12408c2ecf20Sopenharmony_ci break; 12418c2ecf20Sopenharmony_ci default: 12428c2ecf20Sopenharmony_ci break; 12438c2ecf20Sopenharmony_ci } 12448c2ecf20Sopenharmony_ci return dd->process_dma_send; 12458c2ecf20Sopenharmony_ci} 12468c2ecf20Sopenharmony_ci 12478c2ecf20Sopenharmony_ci/** 12488c2ecf20Sopenharmony_ci * hfi1_verbs_send - send a packet 12498c2ecf20Sopenharmony_ci * @qp: the QP to send on 12508c2ecf20Sopenharmony_ci * @ps: the state of the packet to send 12518c2ecf20Sopenharmony_ci * 12528c2ecf20Sopenharmony_ci * Return zero if packet is sent or queued OK. 12538c2ecf20Sopenharmony_ci * Return non-zero and clear qp->s_flags RVT_S_BUSY otherwise. 12548c2ecf20Sopenharmony_ci */ 12558c2ecf20Sopenharmony_ciint hfi1_verbs_send(struct rvt_qp *qp, struct hfi1_pkt_state *ps) 12568c2ecf20Sopenharmony_ci{ 12578c2ecf20Sopenharmony_ci struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device); 12588c2ecf20Sopenharmony_ci struct hfi1_qp_priv *priv = qp->priv; 12598c2ecf20Sopenharmony_ci struct ib_other_headers *ohdr = NULL; 12608c2ecf20Sopenharmony_ci send_routine sr; 12618c2ecf20Sopenharmony_ci int ret; 12628c2ecf20Sopenharmony_ci u16 pkey; 12638c2ecf20Sopenharmony_ci u32 slid; 12648c2ecf20Sopenharmony_ci u8 l4 = 0; 12658c2ecf20Sopenharmony_ci 12668c2ecf20Sopenharmony_ci /* locate the pkey within the headers */ 12678c2ecf20Sopenharmony_ci if (ps->s_txreq->phdr.hdr.hdr_type) { 12688c2ecf20Sopenharmony_ci struct hfi1_16b_header *hdr = &ps->s_txreq->phdr.hdr.opah; 12698c2ecf20Sopenharmony_ci 12708c2ecf20Sopenharmony_ci l4 = hfi1_16B_get_l4(hdr); 12718c2ecf20Sopenharmony_ci if (l4 == OPA_16B_L4_IB_LOCAL) 12728c2ecf20Sopenharmony_ci ohdr = &hdr->u.oth; 12738c2ecf20Sopenharmony_ci else if (l4 == OPA_16B_L4_IB_GLOBAL) 12748c2ecf20Sopenharmony_ci ohdr = &hdr->u.l.oth; 12758c2ecf20Sopenharmony_ci 12768c2ecf20Sopenharmony_ci slid = hfi1_16B_get_slid(hdr); 12778c2ecf20Sopenharmony_ci pkey = hfi1_16B_get_pkey(hdr); 12788c2ecf20Sopenharmony_ci } else { 12798c2ecf20Sopenharmony_ci struct ib_header *hdr = &ps->s_txreq->phdr.hdr.ibh; 12808c2ecf20Sopenharmony_ci u8 lnh = ib_get_lnh(hdr); 12818c2ecf20Sopenharmony_ci 12828c2ecf20Sopenharmony_ci if (lnh == HFI1_LRH_GRH) 12838c2ecf20Sopenharmony_ci ohdr = &hdr->u.l.oth; 12848c2ecf20Sopenharmony_ci else 12858c2ecf20Sopenharmony_ci ohdr = &hdr->u.oth; 12868c2ecf20Sopenharmony_ci slid = ib_get_slid(hdr); 12878c2ecf20Sopenharmony_ci pkey = ib_bth_get_pkey(ohdr); 12888c2ecf20Sopenharmony_ci } 12898c2ecf20Sopenharmony_ci 12908c2ecf20Sopenharmony_ci if (likely(l4 != OPA_16B_L4_FM)) 12918c2ecf20Sopenharmony_ci ps->opcode = ib_bth_get_opcode(ohdr); 12928c2ecf20Sopenharmony_ci else 12938c2ecf20Sopenharmony_ci ps->opcode = IB_OPCODE_UD_SEND_ONLY; 12948c2ecf20Sopenharmony_ci 12958c2ecf20Sopenharmony_ci sr = get_send_routine(qp, ps); 12968c2ecf20Sopenharmony_ci ret = egress_pkey_check(dd->pport, slid, pkey, 12978c2ecf20Sopenharmony_ci priv->s_sc, qp->s_pkey_index); 12988c2ecf20Sopenharmony_ci if (unlikely(ret)) { 12998c2ecf20Sopenharmony_ci /* 13008c2ecf20Sopenharmony_ci * The value we are returning here does not get propagated to 13018c2ecf20Sopenharmony_ci * the verbs caller. Thus we need to complete the request with 13028c2ecf20Sopenharmony_ci * error otherwise the caller could be sitting waiting on the 13038c2ecf20Sopenharmony_ci * completion event. Only do this for PIO. SDMA has its own 13048c2ecf20Sopenharmony_ci * mechanism for handling the errors. So for SDMA we can just 13058c2ecf20Sopenharmony_ci * return. 13068c2ecf20Sopenharmony_ci */ 13078c2ecf20Sopenharmony_ci if (sr == dd->process_pio_send) { 13088c2ecf20Sopenharmony_ci unsigned long flags; 13098c2ecf20Sopenharmony_ci 13108c2ecf20Sopenharmony_ci hfi1_cdbg(PIO, "%s() Failed. Completing with err", 13118c2ecf20Sopenharmony_ci __func__); 13128c2ecf20Sopenharmony_ci spin_lock_irqsave(&qp->s_lock, flags); 13138c2ecf20Sopenharmony_ci rvt_send_complete(qp, qp->s_wqe, IB_WC_GENERAL_ERR); 13148c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&qp->s_lock, flags); 13158c2ecf20Sopenharmony_ci } 13168c2ecf20Sopenharmony_ci return -EINVAL; 13178c2ecf20Sopenharmony_ci } 13188c2ecf20Sopenharmony_ci if (sr == dd->process_dma_send && iowait_pio_pending(&priv->s_iowait)) 13198c2ecf20Sopenharmony_ci return pio_wait(qp, 13208c2ecf20Sopenharmony_ci ps->s_txreq->psc, 13218c2ecf20Sopenharmony_ci ps, 13228c2ecf20Sopenharmony_ci HFI1_S_WAIT_PIO_DRAIN); 13238c2ecf20Sopenharmony_ci return sr(qp, ps, 0); 13248c2ecf20Sopenharmony_ci} 13258c2ecf20Sopenharmony_ci 13268c2ecf20Sopenharmony_ci/** 13278c2ecf20Sopenharmony_ci * hfi1_fill_device_attr - Fill in rvt dev info device attributes. 13288c2ecf20Sopenharmony_ci * @dd: the device data structure 13298c2ecf20Sopenharmony_ci */ 13308c2ecf20Sopenharmony_cistatic void hfi1_fill_device_attr(struct hfi1_devdata *dd) 13318c2ecf20Sopenharmony_ci{ 13328c2ecf20Sopenharmony_ci struct rvt_dev_info *rdi = &dd->verbs_dev.rdi; 13338c2ecf20Sopenharmony_ci u32 ver = dd->dc8051_ver; 13348c2ecf20Sopenharmony_ci 13358c2ecf20Sopenharmony_ci memset(&rdi->dparms.props, 0, sizeof(rdi->dparms.props)); 13368c2ecf20Sopenharmony_ci 13378c2ecf20Sopenharmony_ci rdi->dparms.props.fw_ver = ((u64)(dc8051_ver_maj(ver)) << 32) | 13388c2ecf20Sopenharmony_ci ((u64)(dc8051_ver_min(ver)) << 16) | 13398c2ecf20Sopenharmony_ci (u64)dc8051_ver_patch(ver); 13408c2ecf20Sopenharmony_ci 13418c2ecf20Sopenharmony_ci rdi->dparms.props.device_cap_flags = IB_DEVICE_BAD_PKEY_CNTR | 13428c2ecf20Sopenharmony_ci IB_DEVICE_BAD_QKEY_CNTR | IB_DEVICE_SHUTDOWN_PORT | 13438c2ecf20Sopenharmony_ci IB_DEVICE_SYS_IMAGE_GUID | IB_DEVICE_RC_RNR_NAK_GEN | 13448c2ecf20Sopenharmony_ci IB_DEVICE_PORT_ACTIVE_EVENT | IB_DEVICE_SRQ_RESIZE | 13458c2ecf20Sopenharmony_ci IB_DEVICE_MEM_MGT_EXTENSIONS | 13468c2ecf20Sopenharmony_ci IB_DEVICE_RDMA_NETDEV_OPA; 13478c2ecf20Sopenharmony_ci rdi->dparms.props.page_size_cap = PAGE_SIZE; 13488c2ecf20Sopenharmony_ci rdi->dparms.props.vendor_id = dd->oui1 << 16 | dd->oui2 << 8 | dd->oui3; 13498c2ecf20Sopenharmony_ci rdi->dparms.props.vendor_part_id = dd->pcidev->device; 13508c2ecf20Sopenharmony_ci rdi->dparms.props.hw_ver = dd->minrev; 13518c2ecf20Sopenharmony_ci rdi->dparms.props.sys_image_guid = ib_hfi1_sys_image_guid; 13528c2ecf20Sopenharmony_ci rdi->dparms.props.max_mr_size = U64_MAX; 13538c2ecf20Sopenharmony_ci rdi->dparms.props.max_fast_reg_page_list_len = UINT_MAX; 13548c2ecf20Sopenharmony_ci rdi->dparms.props.max_qp = hfi1_max_qps; 13558c2ecf20Sopenharmony_ci rdi->dparms.props.max_qp_wr = 13568c2ecf20Sopenharmony_ci (hfi1_max_qp_wrs >= HFI1_QP_WQE_INVALID ? 13578c2ecf20Sopenharmony_ci HFI1_QP_WQE_INVALID - 1 : hfi1_max_qp_wrs); 13588c2ecf20Sopenharmony_ci rdi->dparms.props.max_send_sge = hfi1_max_sges; 13598c2ecf20Sopenharmony_ci rdi->dparms.props.max_recv_sge = hfi1_max_sges; 13608c2ecf20Sopenharmony_ci rdi->dparms.props.max_sge_rd = hfi1_max_sges; 13618c2ecf20Sopenharmony_ci rdi->dparms.props.max_cq = hfi1_max_cqs; 13628c2ecf20Sopenharmony_ci rdi->dparms.props.max_ah = hfi1_max_ahs; 13638c2ecf20Sopenharmony_ci rdi->dparms.props.max_cqe = hfi1_max_cqes; 13648c2ecf20Sopenharmony_ci rdi->dparms.props.max_pd = hfi1_max_pds; 13658c2ecf20Sopenharmony_ci rdi->dparms.props.max_qp_rd_atom = HFI1_MAX_RDMA_ATOMIC; 13668c2ecf20Sopenharmony_ci rdi->dparms.props.max_qp_init_rd_atom = 255; 13678c2ecf20Sopenharmony_ci rdi->dparms.props.max_srq = hfi1_max_srqs; 13688c2ecf20Sopenharmony_ci rdi->dparms.props.max_srq_wr = hfi1_max_srq_wrs; 13698c2ecf20Sopenharmony_ci rdi->dparms.props.max_srq_sge = hfi1_max_srq_sges; 13708c2ecf20Sopenharmony_ci rdi->dparms.props.atomic_cap = IB_ATOMIC_GLOB; 13718c2ecf20Sopenharmony_ci rdi->dparms.props.max_pkeys = hfi1_get_npkeys(dd); 13728c2ecf20Sopenharmony_ci rdi->dparms.props.max_mcast_grp = hfi1_max_mcast_grps; 13738c2ecf20Sopenharmony_ci rdi->dparms.props.max_mcast_qp_attach = hfi1_max_mcast_qp_attached; 13748c2ecf20Sopenharmony_ci rdi->dparms.props.max_total_mcast_qp_attach = 13758c2ecf20Sopenharmony_ci rdi->dparms.props.max_mcast_qp_attach * 13768c2ecf20Sopenharmony_ci rdi->dparms.props.max_mcast_grp; 13778c2ecf20Sopenharmony_ci} 13788c2ecf20Sopenharmony_ci 13798c2ecf20Sopenharmony_cistatic inline u16 opa_speed_to_ib(u16 in) 13808c2ecf20Sopenharmony_ci{ 13818c2ecf20Sopenharmony_ci u16 out = 0; 13828c2ecf20Sopenharmony_ci 13838c2ecf20Sopenharmony_ci if (in & OPA_LINK_SPEED_25G) 13848c2ecf20Sopenharmony_ci out |= IB_SPEED_EDR; 13858c2ecf20Sopenharmony_ci if (in & OPA_LINK_SPEED_12_5G) 13868c2ecf20Sopenharmony_ci out |= IB_SPEED_FDR; 13878c2ecf20Sopenharmony_ci 13888c2ecf20Sopenharmony_ci return out; 13898c2ecf20Sopenharmony_ci} 13908c2ecf20Sopenharmony_ci 13918c2ecf20Sopenharmony_ci/* 13928c2ecf20Sopenharmony_ci * Convert a single OPA link width (no multiple flags) to an IB value. 13938c2ecf20Sopenharmony_ci * A zero OPA link width means link down, which means the IB width value 13948c2ecf20Sopenharmony_ci * is a don't care. 13958c2ecf20Sopenharmony_ci */ 13968c2ecf20Sopenharmony_cistatic inline u16 opa_width_to_ib(u16 in) 13978c2ecf20Sopenharmony_ci{ 13988c2ecf20Sopenharmony_ci switch (in) { 13998c2ecf20Sopenharmony_ci case OPA_LINK_WIDTH_1X: 14008c2ecf20Sopenharmony_ci /* map 2x and 3x to 1x as they don't exist in IB */ 14018c2ecf20Sopenharmony_ci case OPA_LINK_WIDTH_2X: 14028c2ecf20Sopenharmony_ci case OPA_LINK_WIDTH_3X: 14038c2ecf20Sopenharmony_ci return IB_WIDTH_1X; 14048c2ecf20Sopenharmony_ci default: /* link down or unknown, return our largest width */ 14058c2ecf20Sopenharmony_ci case OPA_LINK_WIDTH_4X: 14068c2ecf20Sopenharmony_ci return IB_WIDTH_4X; 14078c2ecf20Sopenharmony_ci } 14088c2ecf20Sopenharmony_ci} 14098c2ecf20Sopenharmony_ci 14108c2ecf20Sopenharmony_cistatic int query_port(struct rvt_dev_info *rdi, u8 port_num, 14118c2ecf20Sopenharmony_ci struct ib_port_attr *props) 14128c2ecf20Sopenharmony_ci{ 14138c2ecf20Sopenharmony_ci struct hfi1_ibdev *verbs_dev = dev_from_rdi(rdi); 14148c2ecf20Sopenharmony_ci struct hfi1_devdata *dd = dd_from_dev(verbs_dev); 14158c2ecf20Sopenharmony_ci struct hfi1_pportdata *ppd = &dd->pport[port_num - 1]; 14168c2ecf20Sopenharmony_ci u32 lid = ppd->lid; 14178c2ecf20Sopenharmony_ci 14188c2ecf20Sopenharmony_ci /* props being zeroed by the caller, avoid zeroing it here */ 14198c2ecf20Sopenharmony_ci props->lid = lid ? lid : 0; 14208c2ecf20Sopenharmony_ci props->lmc = ppd->lmc; 14218c2ecf20Sopenharmony_ci /* OPA logical states match IB logical states */ 14228c2ecf20Sopenharmony_ci props->state = driver_lstate(ppd); 14238c2ecf20Sopenharmony_ci props->phys_state = driver_pstate(ppd); 14248c2ecf20Sopenharmony_ci props->gid_tbl_len = HFI1_GUIDS_PER_PORT; 14258c2ecf20Sopenharmony_ci props->active_width = (u8)opa_width_to_ib(ppd->link_width_active); 14268c2ecf20Sopenharmony_ci /* see rate_show() in ib core/sysfs.c */ 14278c2ecf20Sopenharmony_ci props->active_speed = opa_speed_to_ib(ppd->link_speed_active); 14288c2ecf20Sopenharmony_ci props->max_vl_num = ppd->vls_supported; 14298c2ecf20Sopenharmony_ci 14308c2ecf20Sopenharmony_ci /* Once we are a "first class" citizen and have added the OPA MTUs to 14318c2ecf20Sopenharmony_ci * the core we can advertise the larger MTU enum to the ULPs, for now 14328c2ecf20Sopenharmony_ci * advertise only 4K. 14338c2ecf20Sopenharmony_ci * 14348c2ecf20Sopenharmony_ci * Those applications which are either OPA aware or pass the MTU enum 14358c2ecf20Sopenharmony_ci * from the Path Records to us will get the new 8k MTU. Those that 14368c2ecf20Sopenharmony_ci * attempt to process the MTU enum may fail in various ways. 14378c2ecf20Sopenharmony_ci */ 14388c2ecf20Sopenharmony_ci props->max_mtu = mtu_to_enum((!valid_ib_mtu(hfi1_max_mtu) ? 14398c2ecf20Sopenharmony_ci 4096 : hfi1_max_mtu), IB_MTU_4096); 14408c2ecf20Sopenharmony_ci props->active_mtu = !valid_ib_mtu(ppd->ibmtu) ? props->max_mtu : 14418c2ecf20Sopenharmony_ci mtu_to_enum(ppd->ibmtu, IB_MTU_4096); 14428c2ecf20Sopenharmony_ci props->phys_mtu = hfi1_max_mtu; 14438c2ecf20Sopenharmony_ci 14448c2ecf20Sopenharmony_ci return 0; 14458c2ecf20Sopenharmony_ci} 14468c2ecf20Sopenharmony_ci 14478c2ecf20Sopenharmony_cistatic int modify_device(struct ib_device *device, 14488c2ecf20Sopenharmony_ci int device_modify_mask, 14498c2ecf20Sopenharmony_ci struct ib_device_modify *device_modify) 14508c2ecf20Sopenharmony_ci{ 14518c2ecf20Sopenharmony_ci struct hfi1_devdata *dd = dd_from_ibdev(device); 14528c2ecf20Sopenharmony_ci unsigned i; 14538c2ecf20Sopenharmony_ci int ret; 14548c2ecf20Sopenharmony_ci 14558c2ecf20Sopenharmony_ci if (device_modify_mask & ~(IB_DEVICE_MODIFY_SYS_IMAGE_GUID | 14568c2ecf20Sopenharmony_ci IB_DEVICE_MODIFY_NODE_DESC)) { 14578c2ecf20Sopenharmony_ci ret = -EOPNOTSUPP; 14588c2ecf20Sopenharmony_ci goto bail; 14598c2ecf20Sopenharmony_ci } 14608c2ecf20Sopenharmony_ci 14618c2ecf20Sopenharmony_ci if (device_modify_mask & IB_DEVICE_MODIFY_NODE_DESC) { 14628c2ecf20Sopenharmony_ci memcpy(device->node_desc, device_modify->node_desc, 14638c2ecf20Sopenharmony_ci IB_DEVICE_NODE_DESC_MAX); 14648c2ecf20Sopenharmony_ci for (i = 0; i < dd->num_pports; i++) { 14658c2ecf20Sopenharmony_ci struct hfi1_ibport *ibp = &dd->pport[i].ibport_data; 14668c2ecf20Sopenharmony_ci 14678c2ecf20Sopenharmony_ci hfi1_node_desc_chg(ibp); 14688c2ecf20Sopenharmony_ci } 14698c2ecf20Sopenharmony_ci } 14708c2ecf20Sopenharmony_ci 14718c2ecf20Sopenharmony_ci if (device_modify_mask & IB_DEVICE_MODIFY_SYS_IMAGE_GUID) { 14728c2ecf20Sopenharmony_ci ib_hfi1_sys_image_guid = 14738c2ecf20Sopenharmony_ci cpu_to_be64(device_modify->sys_image_guid); 14748c2ecf20Sopenharmony_ci for (i = 0; i < dd->num_pports; i++) { 14758c2ecf20Sopenharmony_ci struct hfi1_ibport *ibp = &dd->pport[i].ibport_data; 14768c2ecf20Sopenharmony_ci 14778c2ecf20Sopenharmony_ci hfi1_sys_guid_chg(ibp); 14788c2ecf20Sopenharmony_ci } 14798c2ecf20Sopenharmony_ci } 14808c2ecf20Sopenharmony_ci 14818c2ecf20Sopenharmony_ci ret = 0; 14828c2ecf20Sopenharmony_ci 14838c2ecf20Sopenharmony_cibail: 14848c2ecf20Sopenharmony_ci return ret; 14858c2ecf20Sopenharmony_ci} 14868c2ecf20Sopenharmony_ci 14878c2ecf20Sopenharmony_cistatic int shut_down_port(struct rvt_dev_info *rdi, u8 port_num) 14888c2ecf20Sopenharmony_ci{ 14898c2ecf20Sopenharmony_ci struct hfi1_ibdev *verbs_dev = dev_from_rdi(rdi); 14908c2ecf20Sopenharmony_ci struct hfi1_devdata *dd = dd_from_dev(verbs_dev); 14918c2ecf20Sopenharmony_ci struct hfi1_pportdata *ppd = &dd->pport[port_num - 1]; 14928c2ecf20Sopenharmony_ci int ret; 14938c2ecf20Sopenharmony_ci 14948c2ecf20Sopenharmony_ci set_link_down_reason(ppd, OPA_LINKDOWN_REASON_UNKNOWN, 0, 14958c2ecf20Sopenharmony_ci OPA_LINKDOWN_REASON_UNKNOWN); 14968c2ecf20Sopenharmony_ci ret = set_link_state(ppd, HLS_DN_DOWNDEF); 14978c2ecf20Sopenharmony_ci return ret; 14988c2ecf20Sopenharmony_ci} 14998c2ecf20Sopenharmony_ci 15008c2ecf20Sopenharmony_cistatic int hfi1_get_guid_be(struct rvt_dev_info *rdi, struct rvt_ibport *rvp, 15018c2ecf20Sopenharmony_ci int guid_index, __be64 *guid) 15028c2ecf20Sopenharmony_ci{ 15038c2ecf20Sopenharmony_ci struct hfi1_ibport *ibp = container_of(rvp, struct hfi1_ibport, rvp); 15048c2ecf20Sopenharmony_ci 15058c2ecf20Sopenharmony_ci if (guid_index >= HFI1_GUIDS_PER_PORT) 15068c2ecf20Sopenharmony_ci return -EINVAL; 15078c2ecf20Sopenharmony_ci 15088c2ecf20Sopenharmony_ci *guid = get_sguid(ibp, guid_index); 15098c2ecf20Sopenharmony_ci return 0; 15108c2ecf20Sopenharmony_ci} 15118c2ecf20Sopenharmony_ci 15128c2ecf20Sopenharmony_ci/* 15138c2ecf20Sopenharmony_ci * convert ah port,sl to sc 15148c2ecf20Sopenharmony_ci */ 15158c2ecf20Sopenharmony_ciu8 ah_to_sc(struct ib_device *ibdev, struct rdma_ah_attr *ah) 15168c2ecf20Sopenharmony_ci{ 15178c2ecf20Sopenharmony_ci struct hfi1_ibport *ibp = to_iport(ibdev, rdma_ah_get_port_num(ah)); 15188c2ecf20Sopenharmony_ci 15198c2ecf20Sopenharmony_ci return ibp->sl_to_sc[rdma_ah_get_sl(ah)]; 15208c2ecf20Sopenharmony_ci} 15218c2ecf20Sopenharmony_ci 15228c2ecf20Sopenharmony_cistatic int hfi1_check_ah(struct ib_device *ibdev, struct rdma_ah_attr *ah_attr) 15238c2ecf20Sopenharmony_ci{ 15248c2ecf20Sopenharmony_ci struct hfi1_ibport *ibp; 15258c2ecf20Sopenharmony_ci struct hfi1_pportdata *ppd; 15268c2ecf20Sopenharmony_ci struct hfi1_devdata *dd; 15278c2ecf20Sopenharmony_ci u8 sc5; 15288c2ecf20Sopenharmony_ci u8 sl; 15298c2ecf20Sopenharmony_ci 15308c2ecf20Sopenharmony_ci if (hfi1_check_mcast(rdma_ah_get_dlid(ah_attr)) && 15318c2ecf20Sopenharmony_ci !(rdma_ah_get_ah_flags(ah_attr) & IB_AH_GRH)) 15328c2ecf20Sopenharmony_ci return -EINVAL; 15338c2ecf20Sopenharmony_ci 15348c2ecf20Sopenharmony_ci /* test the mapping for validity */ 15358c2ecf20Sopenharmony_ci ibp = to_iport(ibdev, rdma_ah_get_port_num(ah_attr)); 15368c2ecf20Sopenharmony_ci ppd = ppd_from_ibp(ibp); 15378c2ecf20Sopenharmony_ci dd = dd_from_ppd(ppd); 15388c2ecf20Sopenharmony_ci 15398c2ecf20Sopenharmony_ci sl = rdma_ah_get_sl(ah_attr); 15408c2ecf20Sopenharmony_ci if (sl >= ARRAY_SIZE(ibp->sl_to_sc)) 15418c2ecf20Sopenharmony_ci return -EINVAL; 15428c2ecf20Sopenharmony_ci sl = array_index_nospec(sl, ARRAY_SIZE(ibp->sl_to_sc)); 15438c2ecf20Sopenharmony_ci 15448c2ecf20Sopenharmony_ci sc5 = ibp->sl_to_sc[sl]; 15458c2ecf20Sopenharmony_ci if (sc_to_vlt(dd, sc5) > num_vls && sc_to_vlt(dd, sc5) != 0xf) 15468c2ecf20Sopenharmony_ci return -EINVAL; 15478c2ecf20Sopenharmony_ci return 0; 15488c2ecf20Sopenharmony_ci} 15498c2ecf20Sopenharmony_ci 15508c2ecf20Sopenharmony_cistatic void hfi1_notify_new_ah(struct ib_device *ibdev, 15518c2ecf20Sopenharmony_ci struct rdma_ah_attr *ah_attr, 15528c2ecf20Sopenharmony_ci struct rvt_ah *ah) 15538c2ecf20Sopenharmony_ci{ 15548c2ecf20Sopenharmony_ci struct hfi1_ibport *ibp; 15558c2ecf20Sopenharmony_ci struct hfi1_pportdata *ppd; 15568c2ecf20Sopenharmony_ci struct hfi1_devdata *dd; 15578c2ecf20Sopenharmony_ci u8 sc5; 15588c2ecf20Sopenharmony_ci struct rdma_ah_attr *attr = &ah->attr; 15598c2ecf20Sopenharmony_ci 15608c2ecf20Sopenharmony_ci /* 15618c2ecf20Sopenharmony_ci * Do not trust reading anything from rvt_ah at this point as it is not 15628c2ecf20Sopenharmony_ci * done being setup. We can however modify things which we need to set. 15638c2ecf20Sopenharmony_ci */ 15648c2ecf20Sopenharmony_ci 15658c2ecf20Sopenharmony_ci ibp = to_iport(ibdev, rdma_ah_get_port_num(ah_attr)); 15668c2ecf20Sopenharmony_ci ppd = ppd_from_ibp(ibp); 15678c2ecf20Sopenharmony_ci sc5 = ibp->sl_to_sc[rdma_ah_get_sl(&ah->attr)]; 15688c2ecf20Sopenharmony_ci hfi1_update_ah_attr(ibdev, attr); 15698c2ecf20Sopenharmony_ci hfi1_make_opa_lid(attr); 15708c2ecf20Sopenharmony_ci dd = dd_from_ppd(ppd); 15718c2ecf20Sopenharmony_ci ah->vl = sc_to_vlt(dd, sc5); 15728c2ecf20Sopenharmony_ci if (ah->vl < num_vls || ah->vl == 15) 15738c2ecf20Sopenharmony_ci ah->log_pmtu = ilog2(dd->vld[ah->vl].mtu); 15748c2ecf20Sopenharmony_ci} 15758c2ecf20Sopenharmony_ci 15768c2ecf20Sopenharmony_ci/** 15778c2ecf20Sopenharmony_ci * hfi1_get_npkeys - return the size of the PKEY table for context 0 15788c2ecf20Sopenharmony_ci * @dd: the hfi1_ib device 15798c2ecf20Sopenharmony_ci */ 15808c2ecf20Sopenharmony_ciunsigned hfi1_get_npkeys(struct hfi1_devdata *dd) 15818c2ecf20Sopenharmony_ci{ 15828c2ecf20Sopenharmony_ci return ARRAY_SIZE(dd->pport[0].pkeys); 15838c2ecf20Sopenharmony_ci} 15848c2ecf20Sopenharmony_ci 15858c2ecf20Sopenharmony_cistatic void init_ibport(struct hfi1_pportdata *ppd) 15868c2ecf20Sopenharmony_ci{ 15878c2ecf20Sopenharmony_ci struct hfi1_ibport *ibp = &ppd->ibport_data; 15888c2ecf20Sopenharmony_ci size_t sz = ARRAY_SIZE(ibp->sl_to_sc); 15898c2ecf20Sopenharmony_ci int i; 15908c2ecf20Sopenharmony_ci 15918c2ecf20Sopenharmony_ci for (i = 0; i < sz; i++) { 15928c2ecf20Sopenharmony_ci ibp->sl_to_sc[i] = i; 15938c2ecf20Sopenharmony_ci ibp->sc_to_sl[i] = i; 15948c2ecf20Sopenharmony_ci } 15958c2ecf20Sopenharmony_ci 15968c2ecf20Sopenharmony_ci for (i = 0; i < RVT_MAX_TRAP_LISTS ; i++) 15978c2ecf20Sopenharmony_ci INIT_LIST_HEAD(&ibp->rvp.trap_lists[i].list); 15988c2ecf20Sopenharmony_ci timer_setup(&ibp->rvp.trap_timer, hfi1_handle_trap_timer, 0); 15998c2ecf20Sopenharmony_ci 16008c2ecf20Sopenharmony_ci spin_lock_init(&ibp->rvp.lock); 16018c2ecf20Sopenharmony_ci /* Set the prefix to the default value (see ch. 4.1.1) */ 16028c2ecf20Sopenharmony_ci ibp->rvp.gid_prefix = IB_DEFAULT_GID_PREFIX; 16038c2ecf20Sopenharmony_ci ibp->rvp.sm_lid = 0; 16048c2ecf20Sopenharmony_ci /* 16058c2ecf20Sopenharmony_ci * Below should only set bits defined in OPA PortInfo.CapabilityMask 16068c2ecf20Sopenharmony_ci * and PortInfo.CapabilityMask3 16078c2ecf20Sopenharmony_ci */ 16088c2ecf20Sopenharmony_ci ibp->rvp.port_cap_flags = IB_PORT_AUTO_MIGR_SUP | 16098c2ecf20Sopenharmony_ci IB_PORT_CAP_MASK_NOTICE_SUP; 16108c2ecf20Sopenharmony_ci ibp->rvp.port_cap3_flags = OPA_CAP_MASK3_IsSharedSpaceSupported; 16118c2ecf20Sopenharmony_ci ibp->rvp.pma_counter_select[0] = IB_PMA_PORT_XMIT_DATA; 16128c2ecf20Sopenharmony_ci ibp->rvp.pma_counter_select[1] = IB_PMA_PORT_RCV_DATA; 16138c2ecf20Sopenharmony_ci ibp->rvp.pma_counter_select[2] = IB_PMA_PORT_XMIT_PKTS; 16148c2ecf20Sopenharmony_ci ibp->rvp.pma_counter_select[3] = IB_PMA_PORT_RCV_PKTS; 16158c2ecf20Sopenharmony_ci ibp->rvp.pma_counter_select[4] = IB_PMA_PORT_XMIT_WAIT; 16168c2ecf20Sopenharmony_ci 16178c2ecf20Sopenharmony_ci RCU_INIT_POINTER(ibp->rvp.qp[0], NULL); 16188c2ecf20Sopenharmony_ci RCU_INIT_POINTER(ibp->rvp.qp[1], NULL); 16198c2ecf20Sopenharmony_ci} 16208c2ecf20Sopenharmony_ci 16218c2ecf20Sopenharmony_cistatic void hfi1_get_dev_fw_str(struct ib_device *ibdev, char *str) 16228c2ecf20Sopenharmony_ci{ 16238c2ecf20Sopenharmony_ci struct rvt_dev_info *rdi = ib_to_rvt(ibdev); 16248c2ecf20Sopenharmony_ci struct hfi1_ibdev *dev = dev_from_rdi(rdi); 16258c2ecf20Sopenharmony_ci u32 ver = dd_from_dev(dev)->dc8051_ver; 16268c2ecf20Sopenharmony_ci 16278c2ecf20Sopenharmony_ci snprintf(str, IB_FW_VERSION_NAME_MAX, "%u.%u.%u", dc8051_ver_maj(ver), 16288c2ecf20Sopenharmony_ci dc8051_ver_min(ver), dc8051_ver_patch(ver)); 16298c2ecf20Sopenharmony_ci} 16308c2ecf20Sopenharmony_ci 16318c2ecf20Sopenharmony_cistatic const char * const driver_cntr_names[] = { 16328c2ecf20Sopenharmony_ci /* must be element 0*/ 16338c2ecf20Sopenharmony_ci "DRIVER_KernIntr", 16348c2ecf20Sopenharmony_ci "DRIVER_ErrorIntr", 16358c2ecf20Sopenharmony_ci "DRIVER_Tx_Errs", 16368c2ecf20Sopenharmony_ci "DRIVER_Rcv_Errs", 16378c2ecf20Sopenharmony_ci "DRIVER_HW_Errs", 16388c2ecf20Sopenharmony_ci "DRIVER_NoPIOBufs", 16398c2ecf20Sopenharmony_ci "DRIVER_CtxtsOpen", 16408c2ecf20Sopenharmony_ci "DRIVER_RcvLen_Errs", 16418c2ecf20Sopenharmony_ci "DRIVER_EgrBufFull", 16428c2ecf20Sopenharmony_ci "DRIVER_EgrHdrFull" 16438c2ecf20Sopenharmony_ci}; 16448c2ecf20Sopenharmony_ci 16458c2ecf20Sopenharmony_cistatic DEFINE_MUTEX(cntr_names_lock); /* protects the *_cntr_names bufers */ 16468c2ecf20Sopenharmony_cistatic const char **dev_cntr_names; 16478c2ecf20Sopenharmony_cistatic const char **port_cntr_names; 16488c2ecf20Sopenharmony_ciint num_driver_cntrs = ARRAY_SIZE(driver_cntr_names); 16498c2ecf20Sopenharmony_cistatic int num_dev_cntrs; 16508c2ecf20Sopenharmony_cistatic int num_port_cntrs; 16518c2ecf20Sopenharmony_cistatic int cntr_names_initialized; 16528c2ecf20Sopenharmony_ci 16538c2ecf20Sopenharmony_ci/* 16548c2ecf20Sopenharmony_ci * Convert a list of names separated by '\n' into an array of NULL terminated 16558c2ecf20Sopenharmony_ci * strings. Optionally some entries can be reserved in the array to hold extra 16568c2ecf20Sopenharmony_ci * external strings. 16578c2ecf20Sopenharmony_ci */ 16588c2ecf20Sopenharmony_cistatic int init_cntr_names(const char *names_in, 16598c2ecf20Sopenharmony_ci const size_t names_len, 16608c2ecf20Sopenharmony_ci int num_extra_names, 16618c2ecf20Sopenharmony_ci int *num_cntrs, 16628c2ecf20Sopenharmony_ci const char ***cntr_names) 16638c2ecf20Sopenharmony_ci{ 16648c2ecf20Sopenharmony_ci char *names_out, *p, **q; 16658c2ecf20Sopenharmony_ci int i, n; 16668c2ecf20Sopenharmony_ci 16678c2ecf20Sopenharmony_ci n = 0; 16688c2ecf20Sopenharmony_ci for (i = 0; i < names_len; i++) 16698c2ecf20Sopenharmony_ci if (names_in[i] == '\n') 16708c2ecf20Sopenharmony_ci n++; 16718c2ecf20Sopenharmony_ci 16728c2ecf20Sopenharmony_ci names_out = kmalloc((n + num_extra_names) * sizeof(char *) + names_len, 16738c2ecf20Sopenharmony_ci GFP_KERNEL); 16748c2ecf20Sopenharmony_ci if (!names_out) { 16758c2ecf20Sopenharmony_ci *num_cntrs = 0; 16768c2ecf20Sopenharmony_ci *cntr_names = NULL; 16778c2ecf20Sopenharmony_ci return -ENOMEM; 16788c2ecf20Sopenharmony_ci } 16798c2ecf20Sopenharmony_ci 16808c2ecf20Sopenharmony_ci p = names_out + (n + num_extra_names) * sizeof(char *); 16818c2ecf20Sopenharmony_ci memcpy(p, names_in, names_len); 16828c2ecf20Sopenharmony_ci 16838c2ecf20Sopenharmony_ci q = (char **)names_out; 16848c2ecf20Sopenharmony_ci for (i = 0; i < n; i++) { 16858c2ecf20Sopenharmony_ci q[i] = p; 16868c2ecf20Sopenharmony_ci p = strchr(p, '\n'); 16878c2ecf20Sopenharmony_ci *p++ = '\0'; 16888c2ecf20Sopenharmony_ci } 16898c2ecf20Sopenharmony_ci 16908c2ecf20Sopenharmony_ci *num_cntrs = n; 16918c2ecf20Sopenharmony_ci *cntr_names = (const char **)names_out; 16928c2ecf20Sopenharmony_ci return 0; 16938c2ecf20Sopenharmony_ci} 16948c2ecf20Sopenharmony_ci 16958c2ecf20Sopenharmony_cistatic struct rdma_hw_stats *alloc_hw_stats(struct ib_device *ibdev, 16968c2ecf20Sopenharmony_ci u8 port_num) 16978c2ecf20Sopenharmony_ci{ 16988c2ecf20Sopenharmony_ci int i, err; 16998c2ecf20Sopenharmony_ci 17008c2ecf20Sopenharmony_ci mutex_lock(&cntr_names_lock); 17018c2ecf20Sopenharmony_ci if (!cntr_names_initialized) { 17028c2ecf20Sopenharmony_ci struct hfi1_devdata *dd = dd_from_ibdev(ibdev); 17038c2ecf20Sopenharmony_ci 17048c2ecf20Sopenharmony_ci err = init_cntr_names(dd->cntrnames, 17058c2ecf20Sopenharmony_ci dd->cntrnameslen, 17068c2ecf20Sopenharmony_ci num_driver_cntrs, 17078c2ecf20Sopenharmony_ci &num_dev_cntrs, 17088c2ecf20Sopenharmony_ci &dev_cntr_names); 17098c2ecf20Sopenharmony_ci if (err) { 17108c2ecf20Sopenharmony_ci mutex_unlock(&cntr_names_lock); 17118c2ecf20Sopenharmony_ci return NULL; 17128c2ecf20Sopenharmony_ci } 17138c2ecf20Sopenharmony_ci 17148c2ecf20Sopenharmony_ci for (i = 0; i < num_driver_cntrs; i++) 17158c2ecf20Sopenharmony_ci dev_cntr_names[num_dev_cntrs + i] = 17168c2ecf20Sopenharmony_ci driver_cntr_names[i]; 17178c2ecf20Sopenharmony_ci 17188c2ecf20Sopenharmony_ci err = init_cntr_names(dd->portcntrnames, 17198c2ecf20Sopenharmony_ci dd->portcntrnameslen, 17208c2ecf20Sopenharmony_ci 0, 17218c2ecf20Sopenharmony_ci &num_port_cntrs, 17228c2ecf20Sopenharmony_ci &port_cntr_names); 17238c2ecf20Sopenharmony_ci if (err) { 17248c2ecf20Sopenharmony_ci kfree(dev_cntr_names); 17258c2ecf20Sopenharmony_ci dev_cntr_names = NULL; 17268c2ecf20Sopenharmony_ci mutex_unlock(&cntr_names_lock); 17278c2ecf20Sopenharmony_ci return NULL; 17288c2ecf20Sopenharmony_ci } 17298c2ecf20Sopenharmony_ci cntr_names_initialized = 1; 17308c2ecf20Sopenharmony_ci } 17318c2ecf20Sopenharmony_ci mutex_unlock(&cntr_names_lock); 17328c2ecf20Sopenharmony_ci 17338c2ecf20Sopenharmony_ci if (!port_num) 17348c2ecf20Sopenharmony_ci return rdma_alloc_hw_stats_struct( 17358c2ecf20Sopenharmony_ci dev_cntr_names, 17368c2ecf20Sopenharmony_ci num_dev_cntrs + num_driver_cntrs, 17378c2ecf20Sopenharmony_ci RDMA_HW_STATS_DEFAULT_LIFESPAN); 17388c2ecf20Sopenharmony_ci else 17398c2ecf20Sopenharmony_ci return rdma_alloc_hw_stats_struct( 17408c2ecf20Sopenharmony_ci port_cntr_names, 17418c2ecf20Sopenharmony_ci num_port_cntrs, 17428c2ecf20Sopenharmony_ci RDMA_HW_STATS_DEFAULT_LIFESPAN); 17438c2ecf20Sopenharmony_ci} 17448c2ecf20Sopenharmony_ci 17458c2ecf20Sopenharmony_cistatic u64 hfi1_sps_ints(void) 17468c2ecf20Sopenharmony_ci{ 17478c2ecf20Sopenharmony_ci unsigned long index, flags; 17488c2ecf20Sopenharmony_ci struct hfi1_devdata *dd; 17498c2ecf20Sopenharmony_ci u64 sps_ints = 0; 17508c2ecf20Sopenharmony_ci 17518c2ecf20Sopenharmony_ci xa_lock_irqsave(&hfi1_dev_table, flags); 17528c2ecf20Sopenharmony_ci xa_for_each(&hfi1_dev_table, index, dd) { 17538c2ecf20Sopenharmony_ci sps_ints += get_all_cpu_total(dd->int_counter); 17548c2ecf20Sopenharmony_ci } 17558c2ecf20Sopenharmony_ci xa_unlock_irqrestore(&hfi1_dev_table, flags); 17568c2ecf20Sopenharmony_ci return sps_ints; 17578c2ecf20Sopenharmony_ci} 17588c2ecf20Sopenharmony_ci 17598c2ecf20Sopenharmony_cistatic int get_hw_stats(struct ib_device *ibdev, struct rdma_hw_stats *stats, 17608c2ecf20Sopenharmony_ci u8 port, int index) 17618c2ecf20Sopenharmony_ci{ 17628c2ecf20Sopenharmony_ci u64 *values; 17638c2ecf20Sopenharmony_ci int count; 17648c2ecf20Sopenharmony_ci 17658c2ecf20Sopenharmony_ci if (!port) { 17668c2ecf20Sopenharmony_ci u64 *stats = (u64 *)&hfi1_stats; 17678c2ecf20Sopenharmony_ci int i; 17688c2ecf20Sopenharmony_ci 17698c2ecf20Sopenharmony_ci hfi1_read_cntrs(dd_from_ibdev(ibdev), NULL, &values); 17708c2ecf20Sopenharmony_ci values[num_dev_cntrs] = hfi1_sps_ints(); 17718c2ecf20Sopenharmony_ci for (i = 1; i < num_driver_cntrs; i++) 17728c2ecf20Sopenharmony_ci values[num_dev_cntrs + i] = stats[i]; 17738c2ecf20Sopenharmony_ci count = num_dev_cntrs + num_driver_cntrs; 17748c2ecf20Sopenharmony_ci } else { 17758c2ecf20Sopenharmony_ci struct hfi1_ibport *ibp = to_iport(ibdev, port); 17768c2ecf20Sopenharmony_ci 17778c2ecf20Sopenharmony_ci hfi1_read_portcntrs(ppd_from_ibp(ibp), NULL, &values); 17788c2ecf20Sopenharmony_ci count = num_port_cntrs; 17798c2ecf20Sopenharmony_ci } 17808c2ecf20Sopenharmony_ci 17818c2ecf20Sopenharmony_ci memcpy(stats->value, values, count * sizeof(u64)); 17828c2ecf20Sopenharmony_ci return count; 17838c2ecf20Sopenharmony_ci} 17848c2ecf20Sopenharmony_ci 17858c2ecf20Sopenharmony_cistatic const struct ib_device_ops hfi1_dev_ops = { 17868c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 17878c2ecf20Sopenharmony_ci .driver_id = RDMA_DRIVER_HFI1, 17888c2ecf20Sopenharmony_ci 17898c2ecf20Sopenharmony_ci .alloc_hw_stats = alloc_hw_stats, 17908c2ecf20Sopenharmony_ci .alloc_rdma_netdev = hfi1_vnic_alloc_rn, 17918c2ecf20Sopenharmony_ci .get_dev_fw_str = hfi1_get_dev_fw_str, 17928c2ecf20Sopenharmony_ci .get_hw_stats = get_hw_stats, 17938c2ecf20Sopenharmony_ci .init_port = hfi1_create_port_files, 17948c2ecf20Sopenharmony_ci .modify_device = modify_device, 17958c2ecf20Sopenharmony_ci /* keep process mad in the driver */ 17968c2ecf20Sopenharmony_ci .process_mad = hfi1_process_mad, 17978c2ecf20Sopenharmony_ci .rdma_netdev_get_params = hfi1_ipoib_rn_get_params, 17988c2ecf20Sopenharmony_ci}; 17998c2ecf20Sopenharmony_ci 18008c2ecf20Sopenharmony_ci/** 18018c2ecf20Sopenharmony_ci * hfi1_register_ib_device - register our device with the infiniband core 18028c2ecf20Sopenharmony_ci * @dd: the device data structure 18038c2ecf20Sopenharmony_ci * Return 0 if successful, errno if unsuccessful. 18048c2ecf20Sopenharmony_ci */ 18058c2ecf20Sopenharmony_ciint hfi1_register_ib_device(struct hfi1_devdata *dd) 18068c2ecf20Sopenharmony_ci{ 18078c2ecf20Sopenharmony_ci struct hfi1_ibdev *dev = &dd->verbs_dev; 18088c2ecf20Sopenharmony_ci struct ib_device *ibdev = &dev->rdi.ibdev; 18098c2ecf20Sopenharmony_ci struct hfi1_pportdata *ppd = dd->pport; 18108c2ecf20Sopenharmony_ci struct hfi1_ibport *ibp = &ppd->ibport_data; 18118c2ecf20Sopenharmony_ci unsigned i; 18128c2ecf20Sopenharmony_ci int ret; 18138c2ecf20Sopenharmony_ci 18148c2ecf20Sopenharmony_ci for (i = 0; i < dd->num_pports; i++) 18158c2ecf20Sopenharmony_ci init_ibport(ppd + i); 18168c2ecf20Sopenharmony_ci 18178c2ecf20Sopenharmony_ci /* Only need to initialize non-zero fields. */ 18188c2ecf20Sopenharmony_ci 18198c2ecf20Sopenharmony_ci timer_setup(&dev->mem_timer, mem_timer, 0); 18208c2ecf20Sopenharmony_ci 18218c2ecf20Sopenharmony_ci seqlock_init(&dev->iowait_lock); 18228c2ecf20Sopenharmony_ci seqlock_init(&dev->txwait_lock); 18238c2ecf20Sopenharmony_ci INIT_LIST_HEAD(&dev->txwait); 18248c2ecf20Sopenharmony_ci INIT_LIST_HEAD(&dev->memwait); 18258c2ecf20Sopenharmony_ci 18268c2ecf20Sopenharmony_ci ret = verbs_txreq_init(dev); 18278c2ecf20Sopenharmony_ci if (ret) 18288c2ecf20Sopenharmony_ci goto err_verbs_txreq; 18298c2ecf20Sopenharmony_ci 18308c2ecf20Sopenharmony_ci /* Use first-port GUID as node guid */ 18318c2ecf20Sopenharmony_ci ibdev->node_guid = get_sguid(ibp, HFI1_PORT_GUID_INDEX); 18328c2ecf20Sopenharmony_ci 18338c2ecf20Sopenharmony_ci /* 18348c2ecf20Sopenharmony_ci * The system image GUID is supposed to be the same for all 18358c2ecf20Sopenharmony_ci * HFIs in a single system but since there can be other 18368c2ecf20Sopenharmony_ci * device types in the system, we can't be sure this is unique. 18378c2ecf20Sopenharmony_ci */ 18388c2ecf20Sopenharmony_ci if (!ib_hfi1_sys_image_guid) 18398c2ecf20Sopenharmony_ci ib_hfi1_sys_image_guid = ibdev->node_guid; 18408c2ecf20Sopenharmony_ci ibdev->phys_port_cnt = dd->num_pports; 18418c2ecf20Sopenharmony_ci ibdev->dev.parent = &dd->pcidev->dev; 18428c2ecf20Sopenharmony_ci 18438c2ecf20Sopenharmony_ci ib_set_device_ops(ibdev, &hfi1_dev_ops); 18448c2ecf20Sopenharmony_ci 18458c2ecf20Sopenharmony_ci strlcpy(ibdev->node_desc, init_utsname()->nodename, 18468c2ecf20Sopenharmony_ci sizeof(ibdev->node_desc)); 18478c2ecf20Sopenharmony_ci 18488c2ecf20Sopenharmony_ci /* 18498c2ecf20Sopenharmony_ci * Fill in rvt info object. 18508c2ecf20Sopenharmony_ci */ 18518c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.driver_f.get_pci_dev = get_pci_dev; 18528c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.driver_f.check_ah = hfi1_check_ah; 18538c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.driver_f.notify_new_ah = hfi1_notify_new_ah; 18548c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.driver_f.get_guid_be = hfi1_get_guid_be; 18558c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.driver_f.query_port_state = query_port; 18568c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.driver_f.shut_down_port = shut_down_port; 18578c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.driver_f.cap_mask_chg = hfi1_cap_mask_chg; 18588c2ecf20Sopenharmony_ci /* 18598c2ecf20Sopenharmony_ci * Fill in rvt info device attributes. 18608c2ecf20Sopenharmony_ci */ 18618c2ecf20Sopenharmony_ci hfi1_fill_device_attr(dd); 18628c2ecf20Sopenharmony_ci 18638c2ecf20Sopenharmony_ci /* queue pair */ 18648c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.dparms.qp_table_size = hfi1_qp_table_size; 18658c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.dparms.qpn_start = 0; 18668c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.dparms.qpn_inc = 1; 18678c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.dparms.qos_shift = dd->qos_shift; 18688c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.dparms.qpn_res_start = RVT_KDETH_QP_BASE; 18698c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.dparms.qpn_res_end = RVT_AIP_QP_MAX; 18708c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.dparms.max_rdma_atomic = HFI1_MAX_RDMA_ATOMIC; 18718c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.dparms.psn_mask = PSN_MASK; 18728c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.dparms.psn_shift = PSN_SHIFT; 18738c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.dparms.psn_modify_mask = PSN_MODIFY_MASK; 18748c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.dparms.core_cap_flags = RDMA_CORE_PORT_INTEL_OPA | 18758c2ecf20Sopenharmony_ci RDMA_CORE_CAP_OPA_AH; 18768c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.dparms.max_mad_size = OPA_MGMT_MAD_SIZE; 18778c2ecf20Sopenharmony_ci 18788c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.driver_f.qp_priv_alloc = qp_priv_alloc; 18798c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.driver_f.qp_priv_init = hfi1_qp_priv_init; 18808c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.driver_f.qp_priv_free = qp_priv_free; 18818c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.driver_f.free_all_qps = free_all_qps; 18828c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.driver_f.notify_qp_reset = notify_qp_reset; 18838c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.driver_f.do_send = hfi1_do_send_from_rvt; 18848c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.driver_f.schedule_send = hfi1_schedule_send; 18858c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.driver_f.schedule_send_no_lock = _hfi1_schedule_send; 18868c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.driver_f.get_pmtu_from_attr = get_pmtu_from_attr; 18878c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.driver_f.notify_error_qp = notify_error_qp; 18888c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.driver_f.flush_qp_waiters = flush_qp_waiters; 18898c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.driver_f.stop_send_queue = stop_send_queue; 18908c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.driver_f.quiesce_qp = quiesce_qp; 18918c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.driver_f.notify_error_qp = notify_error_qp; 18928c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.driver_f.mtu_from_qp = mtu_from_qp; 18938c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.driver_f.mtu_to_path_mtu = mtu_to_path_mtu; 18948c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.driver_f.check_modify_qp = hfi1_check_modify_qp; 18958c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.driver_f.modify_qp = hfi1_modify_qp; 18968c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.driver_f.notify_restart_rc = hfi1_restart_rc; 18978c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.driver_f.setup_wqe = hfi1_setup_wqe; 18988c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.driver_f.comp_vect_cpu_lookup = 18998c2ecf20Sopenharmony_ci hfi1_comp_vect_mappings_lookup; 19008c2ecf20Sopenharmony_ci 19018c2ecf20Sopenharmony_ci /* completeion queue */ 19028c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.ibdev.num_comp_vectors = dd->comp_vect_possible_cpus; 19038c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.dparms.node = dd->node; 19048c2ecf20Sopenharmony_ci 19058c2ecf20Sopenharmony_ci /* misc settings */ 19068c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.flags = 0; /* Let rdmavt handle it all */ 19078c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.dparms.lkey_table_size = hfi1_lkey_table_size; 19088c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.dparms.nports = dd->num_pports; 19098c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.dparms.npkeys = hfi1_get_npkeys(dd); 19108c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.dparms.sge_copy_mode = sge_copy_mode; 19118c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.dparms.wss_threshold = wss_threshold; 19128c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.dparms.wss_clean_period = wss_clean_period; 19138c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.dparms.reserved_operations = 1; 19148c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.dparms.extra_rdma_atomic = HFI1_TID_RDMA_WRITE_CNT; 19158c2ecf20Sopenharmony_ci 19168c2ecf20Sopenharmony_ci /* post send table */ 19178c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.post_parms = hfi1_post_parms; 19188c2ecf20Sopenharmony_ci 19198c2ecf20Sopenharmony_ci /* opcode translation table */ 19208c2ecf20Sopenharmony_ci dd->verbs_dev.rdi.wc_opcode = ib_hfi1_wc_opcode; 19218c2ecf20Sopenharmony_ci 19228c2ecf20Sopenharmony_ci ppd = dd->pport; 19238c2ecf20Sopenharmony_ci for (i = 0; i < dd->num_pports; i++, ppd++) 19248c2ecf20Sopenharmony_ci rvt_init_port(&dd->verbs_dev.rdi, 19258c2ecf20Sopenharmony_ci &ppd->ibport_data.rvp, 19268c2ecf20Sopenharmony_ci i, 19278c2ecf20Sopenharmony_ci ppd->pkeys); 19288c2ecf20Sopenharmony_ci 19298c2ecf20Sopenharmony_ci rdma_set_device_sysfs_group(&dd->verbs_dev.rdi.ibdev, 19308c2ecf20Sopenharmony_ci &ib_hfi1_attr_group); 19318c2ecf20Sopenharmony_ci 19328c2ecf20Sopenharmony_ci ret = rvt_register_device(&dd->verbs_dev.rdi); 19338c2ecf20Sopenharmony_ci if (ret) 19348c2ecf20Sopenharmony_ci goto err_verbs_txreq; 19358c2ecf20Sopenharmony_ci 19368c2ecf20Sopenharmony_ci ret = hfi1_verbs_register_sysfs(dd); 19378c2ecf20Sopenharmony_ci if (ret) 19388c2ecf20Sopenharmony_ci goto err_class; 19398c2ecf20Sopenharmony_ci 19408c2ecf20Sopenharmony_ci return ret; 19418c2ecf20Sopenharmony_ci 19428c2ecf20Sopenharmony_cierr_class: 19438c2ecf20Sopenharmony_ci rvt_unregister_device(&dd->verbs_dev.rdi); 19448c2ecf20Sopenharmony_cierr_verbs_txreq: 19458c2ecf20Sopenharmony_ci verbs_txreq_exit(dev); 19468c2ecf20Sopenharmony_ci dd_dev_err(dd, "cannot register verbs: %d!\n", -ret); 19478c2ecf20Sopenharmony_ci return ret; 19488c2ecf20Sopenharmony_ci} 19498c2ecf20Sopenharmony_ci 19508c2ecf20Sopenharmony_civoid hfi1_unregister_ib_device(struct hfi1_devdata *dd) 19518c2ecf20Sopenharmony_ci{ 19528c2ecf20Sopenharmony_ci struct hfi1_ibdev *dev = &dd->verbs_dev; 19538c2ecf20Sopenharmony_ci 19548c2ecf20Sopenharmony_ci hfi1_verbs_unregister_sysfs(dd); 19558c2ecf20Sopenharmony_ci 19568c2ecf20Sopenharmony_ci rvt_unregister_device(&dd->verbs_dev.rdi); 19578c2ecf20Sopenharmony_ci 19588c2ecf20Sopenharmony_ci if (!list_empty(&dev->txwait)) 19598c2ecf20Sopenharmony_ci dd_dev_err(dd, "txwait list not empty!\n"); 19608c2ecf20Sopenharmony_ci if (!list_empty(&dev->memwait)) 19618c2ecf20Sopenharmony_ci dd_dev_err(dd, "memwait list not empty!\n"); 19628c2ecf20Sopenharmony_ci 19638c2ecf20Sopenharmony_ci del_timer_sync(&dev->mem_timer); 19648c2ecf20Sopenharmony_ci verbs_txreq_exit(dev); 19658c2ecf20Sopenharmony_ci 19668c2ecf20Sopenharmony_ci mutex_lock(&cntr_names_lock); 19678c2ecf20Sopenharmony_ci kfree(dev_cntr_names); 19688c2ecf20Sopenharmony_ci kfree(port_cntr_names); 19698c2ecf20Sopenharmony_ci dev_cntr_names = NULL; 19708c2ecf20Sopenharmony_ci port_cntr_names = NULL; 19718c2ecf20Sopenharmony_ci cntr_names_initialized = 0; 19728c2ecf20Sopenharmony_ci mutex_unlock(&cntr_names_lock); 19738c2ecf20Sopenharmony_ci} 19748c2ecf20Sopenharmony_ci 19758c2ecf20Sopenharmony_civoid hfi1_cnp_rcv(struct hfi1_packet *packet) 19768c2ecf20Sopenharmony_ci{ 19778c2ecf20Sopenharmony_ci struct hfi1_ibport *ibp = rcd_to_iport(packet->rcd); 19788c2ecf20Sopenharmony_ci struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); 19798c2ecf20Sopenharmony_ci struct ib_header *hdr = packet->hdr; 19808c2ecf20Sopenharmony_ci struct rvt_qp *qp = packet->qp; 19818c2ecf20Sopenharmony_ci u32 lqpn, rqpn = 0; 19828c2ecf20Sopenharmony_ci u16 rlid = 0; 19838c2ecf20Sopenharmony_ci u8 sl, sc5, svc_type; 19848c2ecf20Sopenharmony_ci 19858c2ecf20Sopenharmony_ci switch (packet->qp->ibqp.qp_type) { 19868c2ecf20Sopenharmony_ci case IB_QPT_UC: 19878c2ecf20Sopenharmony_ci rlid = rdma_ah_get_dlid(&qp->remote_ah_attr); 19888c2ecf20Sopenharmony_ci rqpn = qp->remote_qpn; 19898c2ecf20Sopenharmony_ci svc_type = IB_CC_SVCTYPE_UC; 19908c2ecf20Sopenharmony_ci break; 19918c2ecf20Sopenharmony_ci case IB_QPT_RC: 19928c2ecf20Sopenharmony_ci rlid = rdma_ah_get_dlid(&qp->remote_ah_attr); 19938c2ecf20Sopenharmony_ci rqpn = qp->remote_qpn; 19948c2ecf20Sopenharmony_ci svc_type = IB_CC_SVCTYPE_RC; 19958c2ecf20Sopenharmony_ci break; 19968c2ecf20Sopenharmony_ci case IB_QPT_SMI: 19978c2ecf20Sopenharmony_ci case IB_QPT_GSI: 19988c2ecf20Sopenharmony_ci case IB_QPT_UD: 19998c2ecf20Sopenharmony_ci svc_type = IB_CC_SVCTYPE_UD; 20008c2ecf20Sopenharmony_ci break; 20018c2ecf20Sopenharmony_ci default: 20028c2ecf20Sopenharmony_ci ibp->rvp.n_pkt_drops++; 20038c2ecf20Sopenharmony_ci return; 20048c2ecf20Sopenharmony_ci } 20058c2ecf20Sopenharmony_ci 20068c2ecf20Sopenharmony_ci sc5 = hfi1_9B_get_sc5(hdr, packet->rhf); 20078c2ecf20Sopenharmony_ci sl = ibp->sc_to_sl[sc5]; 20088c2ecf20Sopenharmony_ci lqpn = qp->ibqp.qp_num; 20098c2ecf20Sopenharmony_ci 20108c2ecf20Sopenharmony_ci process_becn(ppd, sl, rlid, lqpn, rqpn, svc_type); 20118c2ecf20Sopenharmony_ci} 2012