Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1 | /* |
Mitko Haralanov | a74d530 | 2018-05-02 06:43:24 -0700 | [diff] [blame] | 2 | * Copyright(c) 2015 - 2018 Intel Corporation. |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 3 | * |
| 4 | * This file is provided under a dual BSD/GPLv2 license. When using or |
| 5 | * redistributing this file, you may do so under either license. |
| 6 | * |
| 7 | * GPL LICENSE SUMMARY |
| 8 | * |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of version 2 of the GNU General Public License as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | * BSD LICENSE |
| 19 | * |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 20 | * Redistribution and use in source and binary forms, with or without |
| 21 | * modification, are permitted provided that the following conditions |
| 22 | * are met: |
| 23 | * |
| 24 | * - Redistributions of source code must retain the above copyright |
| 25 | * notice, this list of conditions and the following disclaimer. |
| 26 | * - Redistributions in binary form must reproduce the above copyright |
| 27 | * notice, this list of conditions and the following disclaimer in |
| 28 | * the documentation and/or other materials provided with the |
| 29 | * distribution. |
| 30 | * - Neither the name of Intel Corporation nor the names of its |
| 31 | * contributors may be used to endorse or promote products derived |
| 32 | * from this software without specific prior written permission. |
| 33 | * |
| 34 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 35 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 36 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 37 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 38 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 39 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 40 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 41 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 42 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 43 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 44 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 45 | * |
| 46 | */ |
| 47 | |
| 48 | #include <rdma/ib_mad.h> |
| 49 | #include <rdma/ib_user_verbs.h> |
| 50 | #include <linux/io.h> |
| 51 | #include <linux/module.h> |
| 52 | #include <linux/utsname.h> |
| 53 | #include <linux/rculist.h> |
| 54 | #include <linux/mm.h> |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 55 | #include <linux/vmalloc.h> |
Don Hiatt | 13c1922 | 2017-08-04 13:53:51 -0700 | [diff] [blame] | 56 | #include <rdma/opa_addr.h> |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 57 | |
| 58 | #include "hfi.h" |
| 59 | #include "common.h" |
| 60 | #include "device.h" |
| 61 | #include "trace.h" |
| 62 | #include "qp.h" |
Mike Marciniszyn | 45842ab | 2016-02-14 12:44:34 -0800 | [diff] [blame] | 63 | #include "verbs_txreq.h" |
Don Hiatt | 0181ce3 | 2017-03-20 17:26:14 -0700 | [diff] [blame] | 64 | #include "debugfs.h" |
Vishwanathapura, Niranjana | 2280740 | 2017-04-12 20:29:29 -0700 | [diff] [blame] | 65 | #include "vnic.h" |
Mitko Haralanov | a74d530 | 2018-05-02 06:43:24 -0700 | [diff] [blame] | 66 | #include "fault.h" |
Sebastian Sanchez | 5d18ee6 | 2018-05-02 06:43:55 -0700 | [diff] [blame] | 67 | #include "affinity.h" |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 68 | |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 69 | static unsigned int hfi1_lkey_table_size = 16; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 70 | module_param_named(lkey_table_size, hfi1_lkey_table_size, uint, |
| 71 | S_IRUGO); |
| 72 | MODULE_PARM_DESC(lkey_table_size, |
| 73 | "LKEY table size in bits (2^n, 1 <= n <= 23)"); |
| 74 | |
| 75 | static unsigned int hfi1_max_pds = 0xFFFF; |
| 76 | module_param_named(max_pds, hfi1_max_pds, uint, S_IRUGO); |
| 77 | MODULE_PARM_DESC(max_pds, |
| 78 | "Maximum number of protection domains to support"); |
| 79 | |
| 80 | static unsigned int hfi1_max_ahs = 0xFFFF; |
| 81 | module_param_named(max_ahs, hfi1_max_ahs, uint, S_IRUGO); |
| 82 | MODULE_PARM_DESC(max_ahs, "Maximum number of address handles to support"); |
| 83 | |
Jianxin Xiong | f6aa7835 | 2016-09-25 07:41:18 -0700 | [diff] [blame] | 84 | unsigned int hfi1_max_cqes = 0x2FFFFF; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 85 | module_param_named(max_cqes, hfi1_max_cqes, uint, S_IRUGO); |
| 86 | MODULE_PARM_DESC(max_cqes, |
| 87 | "Maximum number of completion queue entries to support"); |
| 88 | |
| 89 | unsigned int hfi1_max_cqs = 0x1FFFF; |
| 90 | module_param_named(max_cqs, hfi1_max_cqs, uint, S_IRUGO); |
| 91 | MODULE_PARM_DESC(max_cqs, "Maximum number of completion queues to support"); |
| 92 | |
| 93 | unsigned int hfi1_max_qp_wrs = 0x3FFF; |
| 94 | module_param_named(max_qp_wrs, hfi1_max_qp_wrs, uint, S_IRUGO); |
| 95 | MODULE_PARM_DESC(max_qp_wrs, "Maximum number of QP WRs to support"); |
| 96 | |
Jianxin Xiong | f6aa7835 | 2016-09-25 07:41:18 -0700 | [diff] [blame] | 97 | unsigned int hfi1_max_qps = 32768; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 98 | module_param_named(max_qps, hfi1_max_qps, uint, S_IRUGO); |
| 99 | MODULE_PARM_DESC(max_qps, "Maximum number of QPs to support"); |
| 100 | |
| 101 | unsigned int hfi1_max_sges = 0x60; |
| 102 | module_param_named(max_sges, hfi1_max_sges, uint, S_IRUGO); |
| 103 | MODULE_PARM_DESC(max_sges, "Maximum number of SGEs to support"); |
| 104 | |
| 105 | unsigned int hfi1_max_mcast_grps = 16384; |
| 106 | module_param_named(max_mcast_grps, hfi1_max_mcast_grps, uint, S_IRUGO); |
| 107 | MODULE_PARM_DESC(max_mcast_grps, |
| 108 | "Maximum number of multicast groups to support"); |
| 109 | |
| 110 | unsigned int hfi1_max_mcast_qp_attached = 16; |
| 111 | module_param_named(max_mcast_qp_attached, hfi1_max_mcast_qp_attached, |
| 112 | uint, S_IRUGO); |
| 113 | MODULE_PARM_DESC(max_mcast_qp_attached, |
| 114 | "Maximum number of attached QPs to support"); |
| 115 | |
| 116 | unsigned int hfi1_max_srqs = 1024; |
| 117 | module_param_named(max_srqs, hfi1_max_srqs, uint, S_IRUGO); |
| 118 | MODULE_PARM_DESC(max_srqs, "Maximum number of SRQs to support"); |
| 119 | |
| 120 | unsigned int hfi1_max_srq_sges = 128; |
| 121 | module_param_named(max_srq_sges, hfi1_max_srq_sges, uint, S_IRUGO); |
| 122 | MODULE_PARM_DESC(max_srq_sges, "Maximum number of SRQ SGEs to support"); |
| 123 | |
| 124 | unsigned int hfi1_max_srq_wrs = 0x1FFFF; |
| 125 | module_param_named(max_srq_wrs, hfi1_max_srq_wrs, uint, S_IRUGO); |
| 126 | MODULE_PARM_DESC(max_srq_wrs, "Maximum number of SRQ WRs support"); |
| 127 | |
Mike Marciniszyn | d0e859c | 2016-03-07 11:35:46 -0800 | [diff] [blame] | 128 | unsigned short piothreshold = 256; |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 129 | module_param(piothreshold, ushort, S_IRUGO); |
| 130 | MODULE_PARM_DESC(piothreshold, "size used to determine sdma vs. pio"); |
| 131 | |
Dean Luick | 528ee9f | 2016-03-05 08:50:43 -0800 | [diff] [blame] | 132 | static unsigned int sge_copy_mode; |
| 133 | module_param(sge_copy_mode, uint, S_IRUGO); |
| 134 | MODULE_PARM_DESC(sge_copy_mode, |
| 135 | "Verbs copy mode: 0 use memcpy, 1 use cacheless copy, 2 adapt based on WSS"); |
| 136 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 137 | static void verbs_sdma_complete( |
| 138 | struct sdma_txreq *cookie, |
Mike Marciniszyn | a545f53 | 2016-02-14 12:45:53 -0800 | [diff] [blame] | 139 | int status); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 140 | |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 141 | static int pio_wait(struct rvt_qp *qp, |
| 142 | struct send_context *sc, |
| 143 | struct hfi1_pkt_state *ps, |
| 144 | u32 flag); |
| 145 | |
Jubin John | 64ffd86 | 2015-10-26 10:28:47 -0400 | [diff] [blame] | 146 | /* Length of buffer to create verbs txreq cache name */ |
| 147 | #define TXREQ_NAME_LEN 24 |
| 148 | |
Don Hiatt | f8195f3 | 2017-10-09 12:38:19 -0700 | [diff] [blame] | 149 | /* 16B trailing buffer */ |
| 150 | static const u8 trail_buf[MAX_16B_PADDING]; |
| 151 | |
Brian Welty | 019f118 | 2018-09-26 10:44:33 -0700 | [diff] [blame] | 152 | static uint wss_threshold = 80; |
Dean Luick | 528ee9f | 2016-03-05 08:50:43 -0800 | [diff] [blame] | 153 | module_param(wss_threshold, uint, S_IRUGO); |
| 154 | MODULE_PARM_DESC(wss_threshold, "Percentage (1-100) of LLC to use as a threshold for a cacheless copy"); |
| 155 | static uint wss_clean_period = 256; |
| 156 | module_param(wss_clean_period, uint, S_IRUGO); |
| 157 | MODULE_PARM_DESC(wss_clean_period, "Count of verbs copies before an entry in the page copy table is cleaned"); |
| 158 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 159 | /* |
Mike Marciniszyn | 43a474a | 2017-03-20 17:25:04 -0700 | [diff] [blame] | 160 | * Translate ib_wr_opcode into ib_wc_opcode. |
| 161 | */ |
| 162 | const enum ib_wc_opcode ib_hfi1_wc_opcode[] = { |
| 163 | [IB_WR_RDMA_WRITE] = IB_WC_RDMA_WRITE, |
| 164 | [IB_WR_RDMA_WRITE_WITH_IMM] = IB_WC_RDMA_WRITE, |
| 165 | [IB_WR_SEND] = IB_WC_SEND, |
| 166 | [IB_WR_SEND_WITH_IMM] = IB_WC_SEND, |
| 167 | [IB_WR_RDMA_READ] = IB_WC_RDMA_READ, |
| 168 | [IB_WR_ATOMIC_CMP_AND_SWP] = IB_WC_COMP_SWAP, |
| 169 | [IB_WR_ATOMIC_FETCH_AND_ADD] = IB_WC_FETCH_ADD, |
| 170 | [IB_WR_SEND_WITH_INV] = IB_WC_SEND, |
| 171 | [IB_WR_LOCAL_INV] = IB_WC_LOCAL_INV, |
| 172 | [IB_WR_REG_MR] = IB_WC_REG_MR |
| 173 | }; |
| 174 | |
| 175 | /* |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 176 | * Length of header by opcode, 0 --> not supported |
| 177 | */ |
| 178 | const u8 hdr_len_by_opcode[256] = { |
| 179 | /* RC */ |
| 180 | [IB_OPCODE_RC_SEND_FIRST] = 12 + 8, |
| 181 | [IB_OPCODE_RC_SEND_MIDDLE] = 12 + 8, |
| 182 | [IB_OPCODE_RC_SEND_LAST] = 12 + 8, |
| 183 | [IB_OPCODE_RC_SEND_LAST_WITH_IMMEDIATE] = 12 + 8 + 4, |
| 184 | [IB_OPCODE_RC_SEND_ONLY] = 12 + 8, |
| 185 | [IB_OPCODE_RC_SEND_ONLY_WITH_IMMEDIATE] = 12 + 8 + 4, |
| 186 | [IB_OPCODE_RC_RDMA_WRITE_FIRST] = 12 + 8 + 16, |
| 187 | [IB_OPCODE_RC_RDMA_WRITE_MIDDLE] = 12 + 8, |
| 188 | [IB_OPCODE_RC_RDMA_WRITE_LAST] = 12 + 8, |
| 189 | [IB_OPCODE_RC_RDMA_WRITE_LAST_WITH_IMMEDIATE] = 12 + 8 + 4, |
| 190 | [IB_OPCODE_RC_RDMA_WRITE_ONLY] = 12 + 8 + 16, |
| 191 | [IB_OPCODE_RC_RDMA_WRITE_ONLY_WITH_IMMEDIATE] = 12 + 8 + 20, |
| 192 | [IB_OPCODE_RC_RDMA_READ_REQUEST] = 12 + 8 + 16, |
| 193 | [IB_OPCODE_RC_RDMA_READ_RESPONSE_FIRST] = 12 + 8 + 4, |
| 194 | [IB_OPCODE_RC_RDMA_READ_RESPONSE_MIDDLE] = 12 + 8, |
| 195 | [IB_OPCODE_RC_RDMA_READ_RESPONSE_LAST] = 12 + 8 + 4, |
| 196 | [IB_OPCODE_RC_RDMA_READ_RESPONSE_ONLY] = 12 + 8 + 4, |
| 197 | [IB_OPCODE_RC_ACKNOWLEDGE] = 12 + 8 + 4, |
Mike Marciniszyn | 37aab62 | 2016-09-30 20:11:15 -0700 | [diff] [blame] | 198 | [IB_OPCODE_RC_ATOMIC_ACKNOWLEDGE] = 12 + 8 + 4 + 8, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 199 | [IB_OPCODE_RC_COMPARE_SWAP] = 12 + 8 + 28, |
| 200 | [IB_OPCODE_RC_FETCH_ADD] = 12 + 8 + 28, |
Jianxin Xiong | bdd8a98 | 2016-05-24 12:50:17 -0700 | [diff] [blame] | 201 | [IB_OPCODE_RC_SEND_LAST_WITH_INVALIDATE] = 12 + 8 + 4, |
| 202 | [IB_OPCODE_RC_SEND_ONLY_WITH_INVALIDATE] = 12 + 8 + 4, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 203 | /* UC */ |
| 204 | [IB_OPCODE_UC_SEND_FIRST] = 12 + 8, |
| 205 | [IB_OPCODE_UC_SEND_MIDDLE] = 12 + 8, |
| 206 | [IB_OPCODE_UC_SEND_LAST] = 12 + 8, |
| 207 | [IB_OPCODE_UC_SEND_LAST_WITH_IMMEDIATE] = 12 + 8 + 4, |
| 208 | [IB_OPCODE_UC_SEND_ONLY] = 12 + 8, |
| 209 | [IB_OPCODE_UC_SEND_ONLY_WITH_IMMEDIATE] = 12 + 8 + 4, |
| 210 | [IB_OPCODE_UC_RDMA_WRITE_FIRST] = 12 + 8 + 16, |
| 211 | [IB_OPCODE_UC_RDMA_WRITE_MIDDLE] = 12 + 8, |
| 212 | [IB_OPCODE_UC_RDMA_WRITE_LAST] = 12 + 8, |
| 213 | [IB_OPCODE_UC_RDMA_WRITE_LAST_WITH_IMMEDIATE] = 12 + 8 + 4, |
| 214 | [IB_OPCODE_UC_RDMA_WRITE_ONLY] = 12 + 8 + 16, |
| 215 | [IB_OPCODE_UC_RDMA_WRITE_ONLY_WITH_IMMEDIATE] = 12 + 8 + 20, |
| 216 | /* UD */ |
| 217 | [IB_OPCODE_UD_SEND_ONLY] = 12 + 8 + 8, |
| 218 | [IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE] = 12 + 8 + 12 |
| 219 | }; |
| 220 | |
| 221 | static const opcode_handler opcode_handler_tbl[256] = { |
| 222 | /* RC */ |
| 223 | [IB_OPCODE_RC_SEND_FIRST] = &hfi1_rc_rcv, |
| 224 | [IB_OPCODE_RC_SEND_MIDDLE] = &hfi1_rc_rcv, |
| 225 | [IB_OPCODE_RC_SEND_LAST] = &hfi1_rc_rcv, |
| 226 | [IB_OPCODE_RC_SEND_LAST_WITH_IMMEDIATE] = &hfi1_rc_rcv, |
| 227 | [IB_OPCODE_RC_SEND_ONLY] = &hfi1_rc_rcv, |
| 228 | [IB_OPCODE_RC_SEND_ONLY_WITH_IMMEDIATE] = &hfi1_rc_rcv, |
| 229 | [IB_OPCODE_RC_RDMA_WRITE_FIRST] = &hfi1_rc_rcv, |
| 230 | [IB_OPCODE_RC_RDMA_WRITE_MIDDLE] = &hfi1_rc_rcv, |
| 231 | [IB_OPCODE_RC_RDMA_WRITE_LAST] = &hfi1_rc_rcv, |
| 232 | [IB_OPCODE_RC_RDMA_WRITE_LAST_WITH_IMMEDIATE] = &hfi1_rc_rcv, |
| 233 | [IB_OPCODE_RC_RDMA_WRITE_ONLY] = &hfi1_rc_rcv, |
| 234 | [IB_OPCODE_RC_RDMA_WRITE_ONLY_WITH_IMMEDIATE] = &hfi1_rc_rcv, |
| 235 | [IB_OPCODE_RC_RDMA_READ_REQUEST] = &hfi1_rc_rcv, |
| 236 | [IB_OPCODE_RC_RDMA_READ_RESPONSE_FIRST] = &hfi1_rc_rcv, |
| 237 | [IB_OPCODE_RC_RDMA_READ_RESPONSE_MIDDLE] = &hfi1_rc_rcv, |
| 238 | [IB_OPCODE_RC_RDMA_READ_RESPONSE_LAST] = &hfi1_rc_rcv, |
| 239 | [IB_OPCODE_RC_RDMA_READ_RESPONSE_ONLY] = &hfi1_rc_rcv, |
| 240 | [IB_OPCODE_RC_ACKNOWLEDGE] = &hfi1_rc_rcv, |
| 241 | [IB_OPCODE_RC_ATOMIC_ACKNOWLEDGE] = &hfi1_rc_rcv, |
| 242 | [IB_OPCODE_RC_COMPARE_SWAP] = &hfi1_rc_rcv, |
| 243 | [IB_OPCODE_RC_FETCH_ADD] = &hfi1_rc_rcv, |
Jianxin Xiong | a2df0c8 | 2016-07-25 13:38:31 -0700 | [diff] [blame] | 244 | [IB_OPCODE_RC_SEND_LAST_WITH_INVALIDATE] = &hfi1_rc_rcv, |
| 245 | [IB_OPCODE_RC_SEND_ONLY_WITH_INVALIDATE] = &hfi1_rc_rcv, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 246 | /* UC */ |
| 247 | [IB_OPCODE_UC_SEND_FIRST] = &hfi1_uc_rcv, |
| 248 | [IB_OPCODE_UC_SEND_MIDDLE] = &hfi1_uc_rcv, |
| 249 | [IB_OPCODE_UC_SEND_LAST] = &hfi1_uc_rcv, |
| 250 | [IB_OPCODE_UC_SEND_LAST_WITH_IMMEDIATE] = &hfi1_uc_rcv, |
| 251 | [IB_OPCODE_UC_SEND_ONLY] = &hfi1_uc_rcv, |
| 252 | [IB_OPCODE_UC_SEND_ONLY_WITH_IMMEDIATE] = &hfi1_uc_rcv, |
| 253 | [IB_OPCODE_UC_RDMA_WRITE_FIRST] = &hfi1_uc_rcv, |
| 254 | [IB_OPCODE_UC_RDMA_WRITE_MIDDLE] = &hfi1_uc_rcv, |
| 255 | [IB_OPCODE_UC_RDMA_WRITE_LAST] = &hfi1_uc_rcv, |
| 256 | [IB_OPCODE_UC_RDMA_WRITE_LAST_WITH_IMMEDIATE] = &hfi1_uc_rcv, |
| 257 | [IB_OPCODE_UC_RDMA_WRITE_ONLY] = &hfi1_uc_rcv, |
| 258 | [IB_OPCODE_UC_RDMA_WRITE_ONLY_WITH_IMMEDIATE] = &hfi1_uc_rcv, |
| 259 | /* UD */ |
| 260 | [IB_OPCODE_UD_SEND_ONLY] = &hfi1_ud_rcv, |
| 261 | [IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE] = &hfi1_ud_rcv, |
| 262 | /* CNP */ |
| 263 | [IB_OPCODE_CNP] = &hfi1_cnp_rcv |
| 264 | }; |
| 265 | |
Mike Marciniszyn | b374e06 | 2016-09-25 07:40:58 -0700 | [diff] [blame] | 266 | #define OPMASK 0x1f |
| 267 | |
| 268 | static const u32 pio_opmask[BIT(3)] = { |
| 269 | /* RC */ |
| 270 | [IB_OPCODE_RC >> 5] = |
| 271 | BIT(RC_OP(SEND_ONLY) & OPMASK) | |
| 272 | BIT(RC_OP(SEND_ONLY_WITH_IMMEDIATE) & OPMASK) | |
| 273 | BIT(RC_OP(RDMA_WRITE_ONLY) & OPMASK) | |
| 274 | BIT(RC_OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE) & OPMASK) | |
| 275 | BIT(RC_OP(RDMA_READ_REQUEST) & OPMASK) | |
| 276 | BIT(RC_OP(ACKNOWLEDGE) & OPMASK) | |
| 277 | BIT(RC_OP(ATOMIC_ACKNOWLEDGE) & OPMASK) | |
| 278 | BIT(RC_OP(COMPARE_SWAP) & OPMASK) | |
| 279 | BIT(RC_OP(FETCH_ADD) & OPMASK), |
| 280 | /* UC */ |
| 281 | [IB_OPCODE_UC >> 5] = |
| 282 | BIT(UC_OP(SEND_ONLY) & OPMASK) | |
| 283 | BIT(UC_OP(SEND_ONLY_WITH_IMMEDIATE) & OPMASK) | |
| 284 | BIT(UC_OP(RDMA_WRITE_ONLY) & OPMASK) | |
| 285 | BIT(UC_OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE) & OPMASK), |
| 286 | }; |
| 287 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 288 | /* |
| 289 | * System image GUID. |
| 290 | */ |
| 291 | __be64 ib_hfi1_sys_image_guid; |
| 292 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 293 | /* |
| 294 | * Make sure the QP is ready and able to accept the given opcode. |
| 295 | */ |
Don Hiatt | 9039746 | 2017-05-12 09:20:20 -0700 | [diff] [blame] | 296 | static inline opcode_handler qp_ok(struct hfi1_packet *packet) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 297 | { |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 298 | if (!(ib_rvt_state_ops[packet->qp->state] & RVT_PROCESS_RECV_OK)) |
Jakub Pawlak | 71e68e3 | 2016-07-01 16:02:02 -0700 | [diff] [blame] | 299 | return NULL; |
Don Hiatt | 9039746 | 2017-05-12 09:20:20 -0700 | [diff] [blame] | 300 | if (((packet->opcode & RVT_OPCODE_QP_MASK) == |
| 301 | packet->qp->allowed_ops) || |
| 302 | (packet->opcode == IB_OPCODE_CNP)) |
| 303 | return opcode_handler_tbl[packet->opcode]; |
Jakub Pawlak | 71e68e3 | 2016-07-01 16:02:02 -0700 | [diff] [blame] | 304 | |
| 305 | return NULL; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 306 | } |
| 307 | |
Don Hiatt | 243d9f4 | 2017-03-20 17:26:20 -0700 | [diff] [blame] | 308 | static u64 hfi1_fault_tx(struct rvt_qp *qp, u8 opcode, u64 pbc) |
| 309 | { |
| 310 | #ifdef CONFIG_FAULT_INJECTION |
Kaike Wan | 6b6cf93 | 2019-01-23 19:30:51 -0800 | [diff] [blame^] | 311 | if ((opcode & IB_OPCODE_MSP) == IB_OPCODE_MSP) { |
Don Hiatt | 243d9f4 | 2017-03-20 17:26:20 -0700 | [diff] [blame] | 312 | /* |
| 313 | * In order to drop non-IB traffic we |
| 314 | * set PbcInsertHrc to NONE (0x2). |
| 315 | * The packet will still be delivered |
| 316 | * to the receiving node but a |
| 317 | * KHdrHCRCErr (KDETH packet with a bad |
| 318 | * HCRC) will be triggered and the |
| 319 | * packet will not be delivered to the |
| 320 | * correct context. |
| 321 | */ |
Kaike Wan | 6b6cf93 | 2019-01-23 19:30:51 -0800 | [diff] [blame^] | 322 | pbc &= ~PBC_INSERT_HCRC_SMASK; |
Don Hiatt | 243d9f4 | 2017-03-20 17:26:20 -0700 | [diff] [blame] | 323 | pbc |= (u64)PBC_IHCRC_NONE << PBC_INSERT_HCRC_SHIFT; |
Kaike Wan | 6b6cf93 | 2019-01-23 19:30:51 -0800 | [diff] [blame^] | 324 | } else { |
Don Hiatt | 243d9f4 | 2017-03-20 17:26:20 -0700 | [diff] [blame] | 325 | /* |
| 326 | * In order to drop regular verbs |
| 327 | * traffic we set the PbcTestEbp |
| 328 | * flag. The packet will still be |
| 329 | * delivered to the receiving node but |
| 330 | * a 'late ebp error' will be |
| 331 | * triggered and will be dropped. |
| 332 | */ |
| 333 | pbc |= PBC_TEST_EBP; |
Kaike Wan | 6b6cf93 | 2019-01-23 19:30:51 -0800 | [diff] [blame^] | 334 | } |
Don Hiatt | 243d9f4 | 2017-03-20 17:26:20 -0700 | [diff] [blame] | 335 | #endif |
| 336 | return pbc; |
| 337 | } |
| 338 | |
Don Hiatt | 5786adf3 | 2017-08-04 13:54:10 -0700 | [diff] [blame] | 339 | static int hfi1_do_pkey_check(struct hfi1_packet *packet) |
| 340 | { |
| 341 | struct hfi1_ctxtdata *rcd = packet->rcd; |
| 342 | struct hfi1_pportdata *ppd = rcd->ppd; |
| 343 | struct hfi1_16b_header *hdr = packet->hdr; |
| 344 | u16 pkey; |
| 345 | |
| 346 | /* Pkey check needed only for bypass packets */ |
| 347 | if (packet->etype != RHF_RCV_TYPE_BYPASS) |
| 348 | return 0; |
| 349 | |
| 350 | /* Perform pkey check */ |
| 351 | pkey = hfi1_16B_get_pkey(hdr); |
| 352 | return ingress_pkey_check(ppd, pkey, packet->sc, |
| 353 | packet->qp->s_pkey_index, |
| 354 | packet->slid, true); |
| 355 | } |
| 356 | |
Don Hiatt | 9039746 | 2017-05-12 09:20:20 -0700 | [diff] [blame] | 357 | static inline void hfi1_handle_packet(struct hfi1_packet *packet, |
| 358 | bool is_mcast) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 359 | { |
Don Hiatt | 9039746 | 2017-05-12 09:20:20 -0700 | [diff] [blame] | 360 | u32 qp_num; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 361 | struct hfi1_ctxtdata *rcd = packet->rcd; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 362 | struct hfi1_pportdata *ppd = rcd->ppd; |
Sebastian Sanchez | f3e862c | 2017-02-08 05:26:25 -0800 | [diff] [blame] | 363 | struct hfi1_ibport *ibp = rcd_to_iport(rcd); |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 364 | struct rvt_dev_info *rdi = &ppd->dd->verbs_dev.rdi; |
Jakub Pawlak | 71e68e3 | 2016-07-01 16:02:02 -0700 | [diff] [blame] | 365 | opcode_handler packet_handler; |
Dean Luick | b77d713 | 2015-10-26 10:28:43 -0400 | [diff] [blame] | 366 | unsigned long flags; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 367 | |
Don Hiatt | 9039746 | 2017-05-12 09:20:20 -0700 | [diff] [blame] | 368 | inc_opstats(packet->tlen, &rcd->opstats->stats[packet->opcode]); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 369 | |
Don Hiatt | 9039746 | 2017-05-12 09:20:20 -0700 | [diff] [blame] | 370 | if (unlikely(is_mcast)) { |
Dennis Dalessandro | 0facc5a | 2016-01-19 14:43:39 -0800 | [diff] [blame] | 371 | struct rvt_mcast *mcast; |
| 372 | struct rvt_mcast_qp *p; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 373 | |
Don Hiatt | 9039746 | 2017-05-12 09:20:20 -0700 | [diff] [blame] | 374 | if (!packet->grh) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 375 | goto drop; |
Don Hiatt | 9039746 | 2017-05-12 09:20:20 -0700 | [diff] [blame] | 376 | mcast = rvt_mcast_find(&ibp->rvp, |
| 377 | &packet->grh->dgid, |
Don Hiatt | 72c07e2 | 2017-08-04 13:53:58 -0700 | [diff] [blame] | 378 | opa_get_lid(packet->dlid, 9B)); |
Jubin John | d125a6c | 2016-02-14 20:19:49 -0800 | [diff] [blame] | 379 | if (!mcast) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 380 | goto drop; |
| 381 | list_for_each_entry_rcu(p, &mcast->qp_list, list) { |
| 382 | packet->qp = p->qp; |
Don Hiatt | 5786adf3 | 2017-08-04 13:54:10 -0700 | [diff] [blame] | 383 | if (hfi1_do_pkey_check(packet)) |
| 384 | goto drop; |
Dean Luick | b77d713 | 2015-10-26 10:28:43 -0400 | [diff] [blame] | 385 | spin_lock_irqsave(&packet->qp->r_lock, flags); |
Don Hiatt | 9039746 | 2017-05-12 09:20:20 -0700 | [diff] [blame] | 386 | packet_handler = qp_ok(packet); |
Jakub Pawlak | 71e68e3 | 2016-07-01 16:02:02 -0700 | [diff] [blame] | 387 | if (likely(packet_handler)) |
| 388 | packet_handler(packet); |
| 389 | else |
| 390 | ibp->rvp.n_pkt_drops++; |
Dean Luick | b77d713 | 2015-10-26 10:28:43 -0400 | [diff] [blame] | 391 | spin_unlock_irqrestore(&packet->qp->r_lock, flags); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 392 | } |
| 393 | /* |
Dennis Dalessandro | 0facc5a | 2016-01-19 14:43:39 -0800 | [diff] [blame] | 394 | * Notify rvt_multicast_detach() if it is waiting for us |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 395 | * to finish. |
| 396 | */ |
| 397 | if (atomic_dec_return(&mcast->refcount) <= 1) |
| 398 | wake_up(&mcast->wait); |
| 399 | } else { |
Don Hiatt | 9039746 | 2017-05-12 09:20:20 -0700 | [diff] [blame] | 400 | /* Get the destination QP number. */ |
Don Hiatt | 81cd389 | 2018-05-15 18:28:15 -0700 | [diff] [blame] | 401 | if (packet->etype == RHF_RCV_TYPE_BYPASS && |
| 402 | hfi1_16B_get_l4(packet->hdr) == OPA_16B_L4_FM) |
| 403 | qp_num = hfi1_16B_get_dest_qpn(packet->mgmt); |
| 404 | else |
| 405 | qp_num = ib_bth_get_qpn(packet->ohdr); |
| 406 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 407 | rcu_read_lock(); |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 408 | packet->qp = rvt_lookup_qpn(rdi, &ibp->rvp, qp_num); |
Don Hiatt | 5786adf3 | 2017-08-04 13:54:10 -0700 | [diff] [blame] | 409 | if (!packet->qp) |
| 410 | goto unlock_drop; |
| 411 | |
| 412 | if (hfi1_do_pkey_check(packet)) |
| 413 | goto unlock_drop; |
| 414 | |
Dean Luick | b77d713 | 2015-10-26 10:28:43 -0400 | [diff] [blame] | 415 | spin_lock_irqsave(&packet->qp->r_lock, flags); |
Don Hiatt | 9039746 | 2017-05-12 09:20:20 -0700 | [diff] [blame] | 416 | packet_handler = qp_ok(packet); |
Jakub Pawlak | 71e68e3 | 2016-07-01 16:02:02 -0700 | [diff] [blame] | 417 | if (likely(packet_handler)) |
| 418 | packet_handler(packet); |
| 419 | else |
| 420 | ibp->rvp.n_pkt_drops++; |
Dean Luick | b77d713 | 2015-10-26 10:28:43 -0400 | [diff] [blame] | 421 | spin_unlock_irqrestore(&packet->qp->r_lock, flags); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 422 | rcu_read_unlock(); |
| 423 | } |
| 424 | return; |
Don Hiatt | 5786adf3 | 2017-08-04 13:54:10 -0700 | [diff] [blame] | 425 | unlock_drop: |
| 426 | rcu_read_unlock(); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 427 | drop: |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 428 | ibp->rvp.n_pkt_drops++; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 429 | } |
| 430 | |
Don Hiatt | 9039746 | 2017-05-12 09:20:20 -0700 | [diff] [blame] | 431 | /** |
| 432 | * hfi1_ib_rcv - process an incoming packet |
| 433 | * @packet: data packet information |
| 434 | * |
| 435 | * This is called to process an incoming packet at interrupt level. |
| 436 | */ |
| 437 | void hfi1_ib_rcv(struct hfi1_packet *packet) |
| 438 | { |
| 439 | struct hfi1_ctxtdata *rcd = packet->rcd; |
Don Hiatt | 9039746 | 2017-05-12 09:20:20 -0700 | [diff] [blame] | 440 | |
Don Hiatt | 72c07e2 | 2017-08-04 13:53:58 -0700 | [diff] [blame] | 441 | trace_input_ibhdr(rcd->dd, packet, !!(rhf_dc_info(packet->rhf))); |
| 442 | hfi1_handle_packet(packet, hfi1_check_mcast(packet->dlid)); |
| 443 | } |
Don Hiatt | 9039746 | 2017-05-12 09:20:20 -0700 | [diff] [blame] | 444 | |
Don Hiatt | 72c07e2 | 2017-08-04 13:53:58 -0700 | [diff] [blame] | 445 | void hfi1_16B_rcv(struct hfi1_packet *packet) |
| 446 | { |
| 447 | struct hfi1_ctxtdata *rcd = packet->rcd; |
| 448 | |
| 449 | trace_input_ibhdr(rcd->dd, packet, false); |
| 450 | hfi1_handle_packet(packet, hfi1_check_mcast(packet->dlid)); |
Don Hiatt | 9039746 | 2017-05-12 09:20:20 -0700 | [diff] [blame] | 451 | } |
| 452 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 453 | /* |
| 454 | * This is called from a timer to check for QPs |
| 455 | * which need kernel memory in order to send a packet. |
| 456 | */ |
Kees Cook | 8064135 | 2017-10-16 15:51:54 -0700 | [diff] [blame] | 457 | static void mem_timer(struct timer_list *t) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 458 | { |
Kees Cook | 8064135 | 2017-10-16 15:51:54 -0700 | [diff] [blame] | 459 | struct hfi1_ibdev *dev = from_timer(dev, t, mem_timer); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 460 | struct list_head *list = &dev->memwait; |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 461 | struct rvt_qp *qp = NULL; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 462 | struct iowait *wait; |
| 463 | unsigned long flags; |
Dennis Dalessandro | 4c6829c | 2016-01-19 14:42:00 -0800 | [diff] [blame] | 464 | struct hfi1_qp_priv *priv; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 465 | |
| 466 | write_seqlock_irqsave(&dev->iowait_lock, flags); |
| 467 | if (!list_empty(list)) { |
| 468 | wait = list_first_entry(list, struct iowait, list); |
Dennis Dalessandro | 4c6829c | 2016-01-19 14:42:00 -0800 | [diff] [blame] | 469 | qp = iowait_to_qp(wait); |
| 470 | priv = qp->priv; |
| 471 | list_del_init(&priv->s_iowait.list); |
Mike Marciniszyn | 4e04557 | 2016-10-10 06:14:28 -0700 | [diff] [blame] | 472 | priv->s_iowait.lock = NULL; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 473 | /* refcount held until actual wake up */ |
| 474 | if (!list_empty(list)) |
| 475 | mod_timer(&dev->mem_timer, jiffies + 1); |
| 476 | } |
| 477 | write_sequnlock_irqrestore(&dev->iowait_lock, flags); |
| 478 | |
| 479 | if (qp) |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 480 | hfi1_qp_wakeup(qp, RVT_S_WAIT_KMEM); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 481 | } |
| 482 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 483 | /* |
| 484 | * This is called with progress side lock held. |
| 485 | */ |
| 486 | /* New API */ |
| 487 | static void verbs_sdma_complete( |
| 488 | struct sdma_txreq *cookie, |
Mike Marciniszyn | a545f53 | 2016-02-14 12:45:53 -0800 | [diff] [blame] | 489 | int status) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 490 | { |
| 491 | struct verbs_txreq *tx = |
| 492 | container_of(cookie, struct verbs_txreq, txreq); |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 493 | struct rvt_qp *qp = tx->qp; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 494 | |
| 495 | spin_lock(&qp->s_lock); |
Jubin John | e490974 | 2016-02-14 20:22:00 -0800 | [diff] [blame] | 496 | if (tx->wqe) { |
Venkata Sandeep Dhanalakota | 116aa03 | 2018-09-26 10:44:42 -0700 | [diff] [blame] | 497 | rvt_send_complete(qp, tx->wqe, IB_WC_SUCCESS); |
Jubin John | e490974 | 2016-02-14 20:22:00 -0800 | [diff] [blame] | 498 | } else if (qp->ibqp.qp_type == IB_QPT_RC) { |
Don Hiatt | 30e0741 | 2017-08-04 13:54:04 -0700 | [diff] [blame] | 499 | struct hfi1_opa_header *hdr; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 500 | |
| 501 | hdr = &tx->phdr.hdr; |
| 502 | hfi1_rc_send_complete(qp, hdr); |
| 503 | } |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 504 | spin_unlock(&qp->s_lock); |
| 505 | |
| 506 | hfi1_put_txreq(tx); |
| 507 | } |
| 508 | |
Kaike Wan | 838b6fd | 2019-01-23 19:30:07 -0800 | [diff] [blame] | 509 | void hfi1_wait_kmem(struct rvt_qp *qp) |
| 510 | { |
| 511 | struct hfi1_qp_priv *priv = qp->priv; |
| 512 | struct ib_qp *ibqp = &qp->ibqp; |
| 513 | struct ib_device *ibdev = ibqp->device; |
| 514 | struct hfi1_ibdev *dev = to_idev(ibdev); |
| 515 | |
| 516 | if (list_empty(&priv->s_iowait.list)) { |
| 517 | if (list_empty(&dev->memwait)) |
| 518 | mod_timer(&dev->mem_timer, jiffies + 1); |
| 519 | qp->s_flags |= RVT_S_WAIT_KMEM; |
| 520 | list_add_tail(&priv->s_iowait.list, &dev->memwait); |
| 521 | priv->s_iowait.lock = &dev->iowait_lock; |
| 522 | trace_hfi1_qpsleep(qp, RVT_S_WAIT_KMEM); |
| 523 | rvt_get_qp(qp); |
| 524 | } |
| 525 | } |
| 526 | |
Mike Marciniszyn | 711e104 | 2016-02-14 12:45:18 -0800 | [diff] [blame] | 527 | static int wait_kmem(struct hfi1_ibdev *dev, |
| 528 | struct rvt_qp *qp, |
| 529 | struct hfi1_pkt_state *ps) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 530 | { |
| 531 | unsigned long flags; |
| 532 | int ret = 0; |
| 533 | |
| 534 | spin_lock_irqsave(&qp->s_lock, flags); |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 535 | if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 536 | write_seqlock(&dev->iowait_lock); |
Mike Marciniszyn | 711e104 | 2016-02-14 12:45:18 -0800 | [diff] [blame] | 537 | list_add_tail(&ps->s_txreq->txreq.list, |
Dennis Dalessandro | 5da0fc9 | 2018-09-28 07:17:09 -0700 | [diff] [blame] | 538 | &ps->wait->tx_head); |
Kaike Wan | 838b6fd | 2019-01-23 19:30:07 -0800 | [diff] [blame] | 539 | hfi1_wait_kmem(qp); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 540 | write_sequnlock(&dev->iowait_lock); |
Dennis Dalessandro | 5da0fc9 | 2018-09-28 07:17:09 -0700 | [diff] [blame] | 541 | hfi1_qp_unbusy(qp, ps->wait); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 542 | ret = -EBUSY; |
| 543 | } |
| 544 | spin_unlock_irqrestore(&qp->s_lock, flags); |
| 545 | |
| 546 | return ret; |
| 547 | } |
| 548 | |
| 549 | /* |
| 550 | * This routine calls txadds for each sg entry. |
| 551 | * |
| 552 | * Add failures will revert the sge cursor |
| 553 | */ |
Mike Marciniszyn | 711e104 | 2016-02-14 12:45:18 -0800 | [diff] [blame] | 554 | static noinline int build_verbs_ulp_payload( |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 555 | struct sdma_engine *sde, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 556 | u32 length, |
| 557 | struct verbs_txreq *tx) |
| 558 | { |
Mitko Haralanov | b777f15 | 2016-12-07 19:33:27 -0800 | [diff] [blame] | 559 | struct rvt_sge_state *ss = tx->ss; |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 560 | struct rvt_sge *sg_list = ss->sg_list; |
| 561 | struct rvt_sge sge = ss->sge; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 562 | u8 num_sge = ss->num_sge; |
| 563 | u32 len; |
| 564 | int ret = 0; |
| 565 | |
| 566 | while (length) { |
Michael J. Ruhl | 87fc34b | 2019-01-23 19:08:19 -0800 | [diff] [blame] | 567 | len = rvt_get_sge_length(&ss->sge, length); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 568 | WARN_ON_ONCE(len == 0); |
| 569 | ret = sdma_txadd_kvaddr( |
| 570 | sde->dd, |
| 571 | &tx->txreq, |
| 572 | ss->sge.vaddr, |
| 573 | len); |
| 574 | if (ret) |
| 575 | goto bail_txadd; |
Brian Welty | 1198fce | 2017-02-08 05:27:37 -0800 | [diff] [blame] | 576 | rvt_update_sge(ss, len, false); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 577 | length -= len; |
| 578 | } |
| 579 | return ret; |
| 580 | bail_txadd: |
| 581 | /* unwind cursor */ |
| 582 | ss->sge = sge; |
| 583 | ss->num_sge = num_sge; |
| 584 | ss->sg_list = sg_list; |
| 585 | return ret; |
| 586 | } |
| 587 | |
Mike Marciniszyn | 1b311f8 | 2017-10-23 06:06:08 -0700 | [diff] [blame] | 588 | /** |
| 589 | * update_tx_opstats - record stats by opcode |
| 590 | * @qp; the qp |
| 591 | * @ps: transmit packet state |
| 592 | * @plen: the plen in dwords |
| 593 | * |
| 594 | * This is a routine to record the tx opstats after a |
| 595 | * packet has been presented to the egress mechanism. |
| 596 | */ |
| 597 | static void update_tx_opstats(struct rvt_qp *qp, struct hfi1_pkt_state *ps, |
| 598 | u32 plen) |
| 599 | { |
| 600 | #ifdef CONFIG_DEBUG_FS |
| 601 | struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device); |
| 602 | struct hfi1_opcode_stats_perctx *s = get_cpu_ptr(dd->tx_opstats); |
| 603 | |
| 604 | inc_opstats(plen * 4, &s->stats[ps->opcode]); |
| 605 | put_cpu_ptr(s); |
| 606 | #endif |
| 607 | } |
| 608 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 609 | /* |
| 610 | * Build the number of DMA descriptors needed to send length bytes of data. |
| 611 | * |
| 612 | * NOTE: DMA mapping is held in the tx until completed in the ring or |
| 613 | * the tx desc is freed without having been submitted to the ring |
| 614 | * |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 615 | * This routine ensures all the helper routine calls succeed. |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 616 | */ |
| 617 | /* New API */ |
| 618 | static int build_verbs_tx_desc( |
| 619 | struct sdma_engine *sde, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 620 | u32 length, |
| 621 | struct verbs_txreq *tx, |
Dasaratharaman Chandramouli | a9b6b3b | 2016-07-25 13:40:16 -0700 | [diff] [blame] | 622 | struct hfi1_ahg_info *ahg_info, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 623 | u64 pbc) |
| 624 | { |
| 625 | int ret = 0; |
Don Hiatt | d4d602e | 2016-07-25 13:40:22 -0700 | [diff] [blame] | 626 | struct hfi1_sdma_header *phdr = &tx->phdr; |
Mitko Haralanov | 9636258 | 2018-02-01 10:46:07 -0800 | [diff] [blame] | 627 | u16 hdrbytes = (tx->hdr_dwords + sizeof(pbc) / 4) << 2; |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 628 | u8 extra_bytes = 0; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 629 | |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 630 | if (tx->phdr.hdr.hdr_type) { |
| 631 | /* |
| 632 | * hdrbytes accounts for PBC. Need to subtract 8 bytes |
| 633 | * before calculating padding. |
| 634 | */ |
| 635 | extra_bytes = hfi1_get_16b_padding(hdrbytes - 8, length) + |
| 636 | (SIZE_OF_CRC << 2) + SIZE_OF_LT; |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 637 | } |
Dasaratharaman Chandramouli | a9b6b3b | 2016-07-25 13:40:16 -0700 | [diff] [blame] | 638 | if (!ahg_info->ahgcount) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 639 | ret = sdma_txinit_ahg( |
| 640 | &tx->txreq, |
Dasaratharaman Chandramouli | a9b6b3b | 2016-07-25 13:40:16 -0700 | [diff] [blame] | 641 | ahg_info->tx_flags, |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 642 | hdrbytes + length + |
| 643 | extra_bytes, |
Dasaratharaman Chandramouli | a9b6b3b | 2016-07-25 13:40:16 -0700 | [diff] [blame] | 644 | ahg_info->ahgidx, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 645 | 0, |
| 646 | NULL, |
| 647 | 0, |
| 648 | verbs_sdma_complete); |
| 649 | if (ret) |
| 650 | goto bail_txadd; |
| 651 | phdr->pbc = cpu_to_le64(pbc); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 652 | ret = sdma_txadd_kvaddr( |
| 653 | sde->dd, |
| 654 | &tx->txreq, |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 655 | phdr, |
| 656 | hdrbytes); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 657 | if (ret) |
| 658 | goto bail_txadd; |
| 659 | } else { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 660 | ret = sdma_txinit_ahg( |
| 661 | &tx->txreq, |
Dasaratharaman Chandramouli | a9b6b3b | 2016-07-25 13:40:16 -0700 | [diff] [blame] | 662 | ahg_info->tx_flags, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 663 | length, |
Dasaratharaman Chandramouli | a9b6b3b | 2016-07-25 13:40:16 -0700 | [diff] [blame] | 664 | ahg_info->ahgidx, |
| 665 | ahg_info->ahgcount, |
| 666 | ahg_info->ahgdesc, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 667 | hdrbytes, |
| 668 | verbs_sdma_complete); |
| 669 | if (ret) |
| 670 | goto bail_txadd; |
| 671 | } |
Mitko Haralanov | b777f15 | 2016-12-07 19:33:27 -0800 | [diff] [blame] | 672 | /* add the ulp payload - if any. tx->ss can be NULL for acks */ |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 673 | if (tx->ss) { |
Mitko Haralanov | b777f15 | 2016-12-07 19:33:27 -0800 | [diff] [blame] | 674 | ret = build_verbs_ulp_payload(sde, length, tx); |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 675 | if (ret) |
| 676 | goto bail_txadd; |
| 677 | } |
| 678 | |
| 679 | /* add icrc, lt byte, and padding to flit */ |
Don Hiatt | f8195f3 | 2017-10-09 12:38:19 -0700 | [diff] [blame] | 680 | if (extra_bytes) |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 681 | ret = sdma_txadd_kvaddr(sde->dd, &tx->txreq, |
Don Hiatt | f8195f3 | 2017-10-09 12:38:19 -0700 | [diff] [blame] | 682 | (void *)trail_buf, extra_bytes); |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 683 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 684 | bail_txadd: |
| 685 | return ret; |
| 686 | } |
| 687 | |
Kaike Wan | 6b6cf93 | 2019-01-23 19:30:51 -0800 | [diff] [blame^] | 688 | static u64 update_hcrc(u8 opcode, u64 pbc) |
| 689 | { |
| 690 | if ((opcode & IB_OPCODE_TID_RDMA) == IB_OPCODE_TID_RDMA) { |
| 691 | pbc &= ~PBC_INSERT_HCRC_SMASK; |
| 692 | pbc |= (u64)PBC_IHCRC_LKDETH << PBC_INSERT_HCRC_SHIFT; |
| 693 | } |
| 694 | return pbc; |
| 695 | } |
| 696 | |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 697 | int hfi1_verbs_send_dma(struct rvt_qp *qp, struct hfi1_pkt_state *ps, |
Dennis Dalessandro | d46e514 | 2015-11-11 00:34:37 -0500 | [diff] [blame] | 698 | u64 pbc) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 699 | { |
Dennis Dalessandro | 4c6829c | 2016-01-19 14:42:00 -0800 | [diff] [blame] | 700 | struct hfi1_qp_priv *priv = qp->priv; |
Dasaratharaman Chandramouli | a9b6b3b | 2016-07-25 13:40:16 -0700 | [diff] [blame] | 701 | struct hfi1_ahg_info *ahg_info = priv->s_ahg; |
Mitko Haralanov | 9636258 | 2018-02-01 10:46:07 -0800 | [diff] [blame] | 702 | u32 hdrwords = ps->s_txreq->hdr_dwords; |
Don Hiatt | e922ae0 | 2016-12-07 19:33:00 -0800 | [diff] [blame] | 703 | u32 len = ps->s_txreq->s_cur_size; |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 704 | u32 plen; |
Dennis Dalessandro | d46e514 | 2015-11-11 00:34:37 -0500 | [diff] [blame] | 705 | struct hfi1_ibdev *dev = ps->dev; |
| 706 | struct hfi1_pportdata *ppd = ps->ppd; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 707 | struct verbs_txreq *tx; |
Dennis Dalessandro | 4c6829c | 2016-01-19 14:42:00 -0800 | [diff] [blame] | 708 | u8 sc5 = priv->s_sc; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 709 | int ret; |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 710 | u32 dwords; |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 711 | |
| 712 | if (ps->s_txreq->phdr.hdr.hdr_type) { |
| 713 | u8 extra_bytes = hfi1_get_16b_padding((hdrwords << 2), len); |
| 714 | |
| 715 | dwords = (len + extra_bytes + (SIZE_OF_CRC << 2) + |
| 716 | SIZE_OF_LT) >> 2; |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 717 | } else { |
| 718 | dwords = (len + 3) >> 2; |
| 719 | } |
Mitko Haralanov | 9636258 | 2018-02-01 10:46:07 -0800 | [diff] [blame] | 720 | plen = hdrwords + dwords + sizeof(pbc) / 4; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 721 | |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 722 | tx = ps->s_txreq; |
Mike Marciniszyn | 711e104 | 2016-02-14 12:45:18 -0800 | [diff] [blame] | 723 | if (!sdma_txreq_built(&tx->txreq)) { |
| 724 | if (likely(pbc == 0)) { |
| 725 | u32 vl = sc_to_vlt(dd_from_ibdev(qp->ibqp.device), sc5); |
Don Hiatt | 243d9f4 | 2017-03-20 17:26:20 -0700 | [diff] [blame] | 726 | |
Mike Marciniszyn | 711e104 | 2016-02-14 12:45:18 -0800 | [diff] [blame] | 727 | /* No vl15 here */ |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 728 | /* set PBC_DC_INFO bit (aka SC[4]) in pbc */ |
| 729 | if (ps->s_txreq->phdr.hdr.hdr_type) |
| 730 | pbc |= PBC_PACKET_BYPASS | |
| 731 | PBC_INSERT_BYPASS_ICRC; |
| 732 | else |
| 733 | pbc |= (ib_is_sc5(sc5) << PBC_DC_INFO_SHIFT); |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 734 | |
Mitko Haralanov | a74d530 | 2018-05-02 06:43:24 -0700 | [diff] [blame] | 735 | if (unlikely(hfi1_dbg_should_fault_tx(qp, ps->opcode))) |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 736 | pbc = hfi1_fault_tx(qp, ps->opcode, pbc); |
Mike Marciniszyn | 711e104 | 2016-02-14 12:45:18 -0800 | [diff] [blame] | 737 | pbc = create_pbc(ppd, |
Don Hiatt | 243d9f4 | 2017-03-20 17:26:20 -0700 | [diff] [blame] | 738 | pbc, |
Mike Marciniszyn | 711e104 | 2016-02-14 12:45:18 -0800 | [diff] [blame] | 739 | qp->srate_mbps, |
| 740 | vl, |
| 741 | plen); |
Kaike Wan | 6b6cf93 | 2019-01-23 19:30:51 -0800 | [diff] [blame^] | 742 | |
| 743 | /* Update HCRC based on packet opcode */ |
| 744 | pbc = update_hcrc(ps->opcode, pbc); |
Mike Marciniszyn | 711e104 | 2016-02-14 12:45:18 -0800 | [diff] [blame] | 745 | } |
| 746 | tx->wqe = qp->s_wqe; |
Mitko Haralanov | b777f15 | 2016-12-07 19:33:27 -0800 | [diff] [blame] | 747 | ret = build_verbs_tx_desc(tx->sde, len, tx, ahg_info, pbc); |
Mike Marciniszyn | 711e104 | 2016-02-14 12:45:18 -0800 | [diff] [blame] | 748 | if (unlikely(ret)) |
| 749 | goto bail_build; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 750 | } |
Dennis Dalessandro | 5da0fc9 | 2018-09-28 07:17:09 -0700 | [diff] [blame] | 751 | ret = sdma_send_txreq(tx->sde, ps->wait, &tx->txreq, ps->pkts_sent); |
Mike Marciniszyn | 5326dfb | 2016-03-07 11:35:24 -0800 | [diff] [blame] | 752 | if (unlikely(ret < 0)) { |
| 753 | if (ret == -ECOMM) |
| 754 | goto bail_ecomm; |
| 755 | return ret; |
| 756 | } |
Mike Marciniszyn | 1b311f8 | 2017-10-23 06:06:08 -0700 | [diff] [blame] | 757 | |
| 758 | update_tx_opstats(qp, ps, plen); |
Mike Marciniszyn | 1db78ee | 2016-03-07 11:35:19 -0800 | [diff] [blame] | 759 | trace_sdma_output_ibhdr(dd_from_ibdev(qp->ibqp.device), |
Don Hiatt | 228d2af | 2017-05-12 09:20:08 -0700 | [diff] [blame] | 760 | &ps->s_txreq->phdr.hdr, ib_is_sc5(sc5)); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 761 | return ret; |
| 762 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 763 | bail_ecomm: |
| 764 | /* The current one got "sent" */ |
| 765 | return 0; |
| 766 | bail_build: |
Mike Marciniszyn | 711e104 | 2016-02-14 12:45:18 -0800 | [diff] [blame] | 767 | ret = wait_kmem(dev, qp, ps); |
| 768 | if (!ret) { |
| 769 | /* free txreq - bad state */ |
| 770 | hfi1_put_txreq(ps->s_txreq); |
| 771 | ps->s_txreq = NULL; |
| 772 | } |
| 773 | return ret; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | /* |
| 777 | * If we are now in the error state, return zero to flush the |
| 778 | * send work request. |
| 779 | */ |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 780 | static int pio_wait(struct rvt_qp *qp, |
| 781 | struct send_context *sc, |
| 782 | struct hfi1_pkt_state *ps, |
| 783 | u32 flag) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 784 | { |
Dennis Dalessandro | 4c6829c | 2016-01-19 14:42:00 -0800 | [diff] [blame] | 785 | struct hfi1_qp_priv *priv = qp->priv; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 786 | struct hfi1_devdata *dd = sc->dd; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 787 | unsigned long flags; |
| 788 | int ret = 0; |
| 789 | |
| 790 | /* |
| 791 | * Note that as soon as want_buffer() is called and |
| 792 | * possibly before it returns, sc_piobufavail() |
| 793 | * could be called. Therefore, put QP on the I/O wait list before |
| 794 | * enabling the PIO avail interrupt. |
| 795 | */ |
| 796 | spin_lock_irqsave(&qp->s_lock, flags); |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 797 | if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) { |
Mike Marciniszyn | 9aefcabe | 2018-11-28 10:33:00 -0800 | [diff] [blame] | 798 | write_seqlock(&sc->waitlock); |
Mike Marciniszyn | 711e104 | 2016-02-14 12:45:18 -0800 | [diff] [blame] | 799 | list_add_tail(&ps->s_txreq->txreq.list, |
Dennis Dalessandro | 5da0fc9 | 2018-09-28 07:17:09 -0700 | [diff] [blame] | 800 | &ps->wait->tx_head); |
Dennis Dalessandro | 4c6829c | 2016-01-19 14:42:00 -0800 | [diff] [blame] | 801 | if (list_empty(&priv->s_iowait.list)) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 802 | struct hfi1_ibdev *dev = &dd->verbs_dev; |
| 803 | int was_empty; |
| 804 | |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 805 | dev->n_piowait += !!(flag & RVT_S_WAIT_PIO); |
Mike Marciniszyn | 2e2ba09 | 2018-06-04 11:44:02 -0700 | [diff] [blame] | 806 | dev->n_piodrain += !!(flag & HFI1_S_WAIT_PIO_DRAIN); |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 807 | qp->s_flags |= flag; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 808 | was_empty = list_empty(&sc->piowait); |
Kaike Wan | bcad291 | 2017-07-24 07:45:37 -0700 | [diff] [blame] | 809 | iowait_queue(ps->pkts_sent, &priv->s_iowait, |
| 810 | &sc->piowait); |
Mike Marciniszyn | 9aefcabe | 2018-11-28 10:33:00 -0800 | [diff] [blame] | 811 | priv->s_iowait.lock = &sc->waitlock; |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 812 | trace_hfi1_qpsleep(qp, RVT_S_WAIT_PIO); |
Mike Marciniszyn | 4d6f85c | 2016-09-06 04:34:35 -0700 | [diff] [blame] | 813 | rvt_get_qp(qp); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 814 | /* counting: only call wantpiobuf_intr if first user */ |
| 815 | if (was_empty) |
| 816 | hfi1_sc_wantpiobuf_intr(sc, 1); |
| 817 | } |
Mike Marciniszyn | 9aefcabe | 2018-11-28 10:33:00 -0800 | [diff] [blame] | 818 | write_sequnlock(&sc->waitlock); |
Dennis Dalessandro | 5da0fc9 | 2018-09-28 07:17:09 -0700 | [diff] [blame] | 819 | hfi1_qp_unbusy(qp, ps->wait); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 820 | ret = -EBUSY; |
| 821 | } |
| 822 | spin_unlock_irqrestore(&qp->s_lock, flags); |
| 823 | return ret; |
| 824 | } |
| 825 | |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 826 | static void verbs_pio_complete(void *arg, int code) |
| 827 | { |
| 828 | struct rvt_qp *qp = (struct rvt_qp *)arg; |
| 829 | struct hfi1_qp_priv *priv = qp->priv; |
| 830 | |
| 831 | if (iowait_pio_dec(&priv->s_iowait)) |
| 832 | iowait_drain_wakeup(&priv->s_iowait); |
| 833 | } |
| 834 | |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 835 | int hfi1_verbs_send_pio(struct rvt_qp *qp, struct hfi1_pkt_state *ps, |
Dennis Dalessandro | d46e514 | 2015-11-11 00:34:37 -0500 | [diff] [blame] | 836 | u64 pbc) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 837 | { |
Dennis Dalessandro | 4c6829c | 2016-01-19 14:42:00 -0800 | [diff] [blame] | 838 | struct hfi1_qp_priv *priv = qp->priv; |
Mitko Haralanov | 9636258 | 2018-02-01 10:46:07 -0800 | [diff] [blame] | 839 | u32 hdrwords = ps->s_txreq->hdr_dwords; |
Mitko Haralanov | b777f15 | 2016-12-07 19:33:27 -0800 | [diff] [blame] | 840 | struct rvt_sge_state *ss = ps->s_txreq->ss; |
Don Hiatt | e922ae0 | 2016-12-07 19:33:00 -0800 | [diff] [blame] | 841 | u32 len = ps->s_txreq->s_cur_size; |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 842 | u32 dwords; |
| 843 | u32 plen; |
Dennis Dalessandro | d46e514 | 2015-11-11 00:34:37 -0500 | [diff] [blame] | 844 | struct hfi1_pportdata *ppd = ps->ppd; |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 845 | u32 *hdr; |
Mike Marciniszyn | 4f8cc5c | 2016-02-14 12:45:27 -0800 | [diff] [blame] | 846 | u8 sc5; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 847 | unsigned long flags = 0; |
| 848 | struct send_context *sc; |
| 849 | struct pio_buf *pbuf; |
| 850 | int wc_status = IB_WC_SUCCESS; |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 851 | int ret = 0; |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 852 | pio_release_cb cb = NULL; |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 853 | u8 extra_bytes = 0; |
| 854 | |
| 855 | if (ps->s_txreq->phdr.hdr.hdr_type) { |
| 856 | u8 pad_size = hfi1_get_16b_padding((hdrwords << 2), len); |
| 857 | |
| 858 | extra_bytes = pad_size + (SIZE_OF_CRC << 2) + SIZE_OF_LT; |
| 859 | dwords = (len + extra_bytes) >> 2; |
| 860 | hdr = (u32 *)&ps->s_txreq->phdr.hdr.opah; |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 861 | } else { |
| 862 | dwords = (len + 3) >> 2; |
| 863 | hdr = (u32 *)&ps->s_txreq->phdr.hdr.ibh; |
| 864 | } |
Mitko Haralanov | 9636258 | 2018-02-01 10:46:07 -0800 | [diff] [blame] | 865 | plen = hdrwords + dwords + sizeof(pbc) / 4; |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 866 | |
| 867 | /* only RC/UC use complete */ |
| 868 | switch (qp->ibqp.qp_type) { |
| 869 | case IB_QPT_RC: |
| 870 | case IB_QPT_UC: |
| 871 | cb = verbs_pio_complete; |
| 872 | break; |
| 873 | default: |
| 874 | break; |
| 875 | } |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 876 | |
| 877 | /* vl15 special case taken care of in ud.c */ |
Dennis Dalessandro | 4c6829c | 2016-01-19 14:42:00 -0800 | [diff] [blame] | 878 | sc5 = priv->s_sc; |
Mike Marciniszyn | cef504c | 2016-03-07 11:35:35 -0800 | [diff] [blame] | 879 | sc = ps->s_txreq->psc; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 880 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 881 | if (likely(pbc == 0)) { |
Mike Marciniszyn | 4f8cc5c | 2016-02-14 12:45:27 -0800 | [diff] [blame] | 882 | u8 vl = sc_to_vlt(dd_from_ibdev(qp->ibqp.device), sc5); |
Don Hiatt | 243d9f4 | 2017-03-20 17:26:20 -0700 | [diff] [blame] | 883 | |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 884 | /* set PBC_DC_INFO bit (aka SC[4]) in pbc */ |
| 885 | if (ps->s_txreq->phdr.hdr.hdr_type) |
| 886 | pbc |= PBC_PACKET_BYPASS | PBC_INSERT_BYPASS_ICRC; |
| 887 | else |
| 888 | pbc |= (ib_is_sc5(sc5) << PBC_DC_INFO_SHIFT); |
Mitko Haralanov | a74d530 | 2018-05-02 06:43:24 -0700 | [diff] [blame] | 889 | |
| 890 | if (unlikely(hfi1_dbg_should_fault_tx(qp, ps->opcode))) |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 891 | pbc = hfi1_fault_tx(qp, ps->opcode, pbc); |
Don Hiatt | 243d9f4 | 2017-03-20 17:26:20 -0700 | [diff] [blame] | 892 | pbc = create_pbc(ppd, pbc, qp->srate_mbps, vl, plen); |
Kaike Wan | 6b6cf93 | 2019-01-23 19:30:51 -0800 | [diff] [blame^] | 893 | |
| 894 | /* Update HCRC based on packet opcode */ |
| 895 | pbc = update_hcrc(ps->opcode, pbc); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 896 | } |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 897 | if (cb) |
| 898 | iowait_pio_inc(&priv->s_iowait); |
| 899 | pbuf = sc_buffer_alloc(sc, plen, cb, qp); |
Jubin John | d125a6c | 2016-02-14 20:19:49 -0800 | [diff] [blame] | 900 | if (unlikely(!pbuf)) { |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 901 | if (cb) |
| 902 | verbs_pio_complete(qp, 0); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 903 | if (ppd->host_link_state != HLS_UP_ACTIVE) { |
| 904 | /* |
| 905 | * If we have filled the PIO buffers to capacity and are |
| 906 | * not in an active state this request is not going to |
| 907 | * go out to so just complete it with an error or else a |
| 908 | * ULP or the core may be stuck waiting. |
| 909 | */ |
| 910 | hfi1_cdbg( |
| 911 | PIO, |
| 912 | "alloc failed. state not active, completing"); |
| 913 | wc_status = IB_WC_GENERAL_ERR; |
| 914 | goto pio_bail; |
| 915 | } else { |
| 916 | /* |
| 917 | * This is a normal occurrence. The PIO buffs are full |
| 918 | * up but we are still happily sending, well we could be |
| 919 | * so lets continue to queue the request. |
| 920 | */ |
| 921 | hfi1_cdbg(PIO, "alloc failed. state active, queuing"); |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 922 | ret = pio_wait(qp, sc, ps, RVT_S_WAIT_PIO); |
Mike Marciniszyn | 711e104 | 2016-02-14 12:45:18 -0800 | [diff] [blame] | 923 | if (!ret) |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 924 | /* txreq not queued - free */ |
Mike Marciniszyn | 711e104 | 2016-02-14 12:45:18 -0800 | [diff] [blame] | 925 | goto bail; |
| 926 | /* tx consumed in wait */ |
| 927 | return ret; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 928 | } |
| 929 | } |
| 930 | |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 931 | if (dwords == 0) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 932 | pio_copy(ppd->dd, pbuf, pbc, hdr, hdrwords); |
| 933 | } else { |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 934 | seg_pio_copy_start(pbuf, pbc, |
| 935 | hdr, hdrwords * 4); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 936 | if (ss) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 937 | while (len) { |
| 938 | void *addr = ss->sge.vaddr; |
Michael J. Ruhl | 87fc34b | 2019-01-23 19:08:19 -0800 | [diff] [blame] | 939 | u32 slen = rvt_get_sge_length(&ss->sge, len); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 940 | |
Brian Welty | 1198fce | 2017-02-08 05:27:37 -0800 | [diff] [blame] | 941 | rvt_update_sge(ss, slen, false); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 942 | seg_pio_copy_mid(pbuf, addr, slen); |
| 943 | len -= slen; |
| 944 | } |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 945 | } |
Don Hiatt | f8195f3 | 2017-10-09 12:38:19 -0700 | [diff] [blame] | 946 | /* add icrc, lt byte, and padding to flit */ |
| 947 | if (extra_bytes) |
| 948 | seg_pio_copy_mid(pbuf, trail_buf, extra_bytes); |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 949 | |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 950 | seg_pio_copy_end(pbuf); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 951 | } |
| 952 | |
Mike Marciniszyn | 1b311f8 | 2017-10-23 06:06:08 -0700 | [diff] [blame] | 953 | update_tx_opstats(qp, ps, plen); |
Mike Marciniszyn | 1db78ee | 2016-03-07 11:35:19 -0800 | [diff] [blame] | 954 | trace_pio_output_ibhdr(dd_from_ibdev(qp->ibqp.device), |
Don Hiatt | 228d2af | 2017-05-12 09:20:08 -0700 | [diff] [blame] | 955 | &ps->s_txreq->phdr.hdr, ib_is_sc5(sc5)); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 956 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 957 | pio_bail: |
| 958 | if (qp->s_wqe) { |
| 959 | spin_lock_irqsave(&qp->s_lock, flags); |
Venkata Sandeep Dhanalakota | 116aa03 | 2018-09-26 10:44:42 -0700 | [diff] [blame] | 960 | rvt_send_complete(qp, qp->s_wqe, wc_status); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 961 | spin_unlock_irqrestore(&qp->s_lock, flags); |
| 962 | } else if (qp->ibqp.qp_type == IB_QPT_RC) { |
| 963 | spin_lock_irqsave(&qp->s_lock, flags); |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 964 | hfi1_rc_send_complete(qp, &ps->s_txreq->phdr.hdr); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 965 | spin_unlock_irqrestore(&qp->s_lock, flags); |
| 966 | } |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 967 | |
| 968 | ret = 0; |
| 969 | |
| 970 | bail: |
| 971 | hfi1_put_txreq(ps->s_txreq); |
| 972 | return ret; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 973 | } |
Geliang Tang | b91cc57 | 2015-09-21 23:39:08 +0800 | [diff] [blame] | 974 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 975 | /* |
| 976 | * egress_pkey_matches_entry - return 1 if the pkey matches ent (ent |
Sebastian Sanchez | e38d1e4 | 2016-04-12 11:22:21 -0700 | [diff] [blame] | 977 | * being an entry from the partition key table), return 0 |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 978 | * otherwise. Use the matching criteria for egress partition keys |
| 979 | * specified in the OPAv1 spec., section 9.1l.7. |
| 980 | */ |
| 981 | static inline int egress_pkey_matches_entry(u16 pkey, u16 ent) |
| 982 | { |
| 983 | u16 mkey = pkey & PKEY_LOW_15_MASK; |
Sebastian Sanchez | e38d1e4 | 2016-04-12 11:22:21 -0700 | [diff] [blame] | 984 | u16 mentry = ent & PKEY_LOW_15_MASK; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 985 | |
Sebastian Sanchez | e38d1e4 | 2016-04-12 11:22:21 -0700 | [diff] [blame] | 986 | if (mkey == mentry) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 987 | /* |
| 988 | * If pkey[15] is set (full partition member), |
| 989 | * is bit 15 in the corresponding table element |
| 990 | * clear (limited member)? |
| 991 | */ |
| 992 | if (pkey & PKEY_MEMBER_MASK) |
| 993 | return !!(ent & PKEY_MEMBER_MASK); |
| 994 | return 1; |
| 995 | } |
| 996 | return 0; |
| 997 | } |
| 998 | |
Sebastian Sanchez | e38d1e4 | 2016-04-12 11:22:21 -0700 | [diff] [blame] | 999 | /** |
| 1000 | * egress_pkey_check - check P_KEY of a packet |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 1001 | * @ppd: Physical IB port data |
| 1002 | * @slid: SLID for packet |
| 1003 | * @bkey: PKEY for header |
| 1004 | * @sc5: SC for packet |
Sebastian Sanchez | e38d1e4 | 2016-04-12 11:22:21 -0700 | [diff] [blame] | 1005 | * @s_pkey_index: It will be used for look up optimization for kernel contexts |
| 1006 | * only. If it is negative value, then it means user contexts is calling this |
| 1007 | * function. |
| 1008 | * |
| 1009 | * It checks if hdr's pkey is valid. |
| 1010 | * |
| 1011 | * Return: 0 on success, otherwise, 1 |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1012 | */ |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 1013 | int egress_pkey_check(struct hfi1_pportdata *ppd, u32 slid, u16 pkey, |
Sebastian Sanchez | e38d1e4 | 2016-04-12 11:22:21 -0700 | [diff] [blame] | 1014 | u8 sc5, int8_t s_pkey_index) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1015 | { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1016 | struct hfi1_devdata *dd; |
Sebastian Sanchez | e38d1e4 | 2016-04-12 11:22:21 -0700 | [diff] [blame] | 1017 | int i; |
Sebastian Sanchez | e38d1e4 | 2016-04-12 11:22:21 -0700 | [diff] [blame] | 1018 | int is_user_ctxt_mechanism = (s_pkey_index < 0); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1019 | |
| 1020 | if (!(ppd->part_enforce & HFI1_PART_ENFORCE_OUT)) |
| 1021 | return 0; |
| 1022 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1023 | /* If SC15, pkey[0:14] must be 0x7fff */ |
| 1024 | if ((sc5 == 0xf) && ((pkey & PKEY_LOW_15_MASK) != PKEY_LOW_15_MASK)) |
| 1025 | goto bad; |
| 1026 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1027 | /* Is the pkey = 0x0, or 0x8000? */ |
| 1028 | if ((pkey & PKEY_LOW_15_MASK) == 0) |
| 1029 | goto bad; |
| 1030 | |
Sebastian Sanchez | e38d1e4 | 2016-04-12 11:22:21 -0700 | [diff] [blame] | 1031 | /* |
| 1032 | * For the kernel contexts only, if a qp is passed into the function, |
| 1033 | * the most likely matching pkey has index qp->s_pkey_index |
| 1034 | */ |
| 1035 | if (!is_user_ctxt_mechanism && |
| 1036 | egress_pkey_matches_entry(pkey, ppd->pkeys[s_pkey_index])) { |
| 1037 | return 0; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1038 | } |
| 1039 | |
Sebastian Sanchez | e38d1e4 | 2016-04-12 11:22:21 -0700 | [diff] [blame] | 1040 | for (i = 0; i < MAX_PKEY_VALUES; i++) { |
| 1041 | if (egress_pkey_matches_entry(pkey, ppd->pkeys[i])) |
| 1042 | return 0; |
| 1043 | } |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1044 | bad: |
Sebastian Sanchez | e38d1e4 | 2016-04-12 11:22:21 -0700 | [diff] [blame] | 1045 | /* |
| 1046 | * For the user-context mechanism, the P_KEY check would only happen |
| 1047 | * once per SDMA request, not once per packet. Therefore, there's no |
| 1048 | * need to increment the counter for the user-context mechanism. |
| 1049 | */ |
| 1050 | if (!is_user_ctxt_mechanism) { |
| 1051 | incr_cntr64(&ppd->port_xmit_constraint_errors); |
| 1052 | dd = ppd->dd; |
| 1053 | if (!(dd->err_info_xmit_constraint.status & |
| 1054 | OPA_EI_STATUS_SMASK)) { |
Sebastian Sanchez | e38d1e4 | 2016-04-12 11:22:21 -0700 | [diff] [blame] | 1055 | dd->err_info_xmit_constraint.status |= |
| 1056 | OPA_EI_STATUS_SMASK; |
| 1057 | dd->err_info_xmit_constraint.slid = slid; |
| 1058 | dd->err_info_xmit_constraint.pkey = pkey; |
| 1059 | } |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1060 | } |
| 1061 | return 1; |
| 1062 | } |
| 1063 | |
| 1064 | /** |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 1065 | * get_send_routine - choose an egress routine |
| 1066 | * |
| 1067 | * Choose an egress routine based on QP type |
| 1068 | * and size |
| 1069 | */ |
| 1070 | static inline send_routine get_send_routine(struct rvt_qp *qp, |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 1071 | struct hfi1_pkt_state *ps) |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 1072 | { |
| 1073 | struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device); |
| 1074 | struct hfi1_qp_priv *priv = qp->priv; |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 1075 | struct verbs_txreq *tx = ps->s_txreq; |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 1076 | |
| 1077 | if (unlikely(!(dd->flags & HFI1_HAS_SEND_DMA))) |
| 1078 | return dd->process_pio_send; |
| 1079 | switch (qp->ibqp.qp_type) { |
| 1080 | case IB_QPT_SMI: |
| 1081 | return dd->process_pio_send; |
| 1082 | case IB_QPT_GSI: |
| 1083 | case IB_QPT_UD: |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 1084 | break; |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 1085 | case IB_QPT_UC: |
Mike Marciniszyn | b374e06 | 2016-09-25 07:40:58 -0700 | [diff] [blame] | 1086 | case IB_QPT_RC: { |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 1087 | if (piothreshold && |
Don Hiatt | e922ae0 | 2016-12-07 19:33:00 -0800 | [diff] [blame] | 1088 | tx->s_cur_size <= min(piothreshold, qp->pmtu) && |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 1089 | (BIT(ps->opcode & OPMASK) & pio_opmask[ps->opcode >> 5]) && |
Mike Marciniszyn | 47177f1 | 2016-03-07 11:35:41 -0800 | [diff] [blame] | 1090 | iowait_sdma_pending(&priv->s_iowait) == 0 && |
| 1091 | !sdma_txreq_built(&tx->txreq)) |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 1092 | return dd->process_pio_send; |
| 1093 | break; |
Mike Marciniszyn | b374e06 | 2016-09-25 07:40:58 -0700 | [diff] [blame] | 1094 | } |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 1095 | default: |
| 1096 | break; |
| 1097 | } |
| 1098 | return dd->process_dma_send; |
| 1099 | } |
| 1100 | |
| 1101 | /** |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1102 | * hfi1_verbs_send - send a packet |
| 1103 | * @qp: the QP to send on |
Dennis Dalessandro | d46e514 | 2015-11-11 00:34:37 -0500 | [diff] [blame] | 1104 | * @ps: the state of the packet to send |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1105 | * |
| 1106 | * Return zero if packet is sent or queued OK. |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 1107 | * Return non-zero and clear qp->s_flags RVT_S_BUSY otherwise. |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1108 | */ |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 1109 | int hfi1_verbs_send(struct rvt_qp *qp, struct hfi1_pkt_state *ps) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1110 | { |
| 1111 | struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device); |
Mike Marciniszyn | 47177f1 | 2016-03-07 11:35:41 -0800 | [diff] [blame] | 1112 | struct hfi1_qp_priv *priv = qp->priv; |
Don Hiatt | 81cd389 | 2018-05-15 18:28:15 -0700 | [diff] [blame] | 1113 | struct ib_other_headers *ohdr = NULL; |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 1114 | send_routine sr; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1115 | int ret; |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 1116 | u16 pkey; |
| 1117 | u32 slid; |
Don Hiatt | 81cd389 | 2018-05-15 18:28:15 -0700 | [diff] [blame] | 1118 | u8 l4 = 0; |
Sebastian Sanchez | e38d1e4 | 2016-04-12 11:22:21 -0700 | [diff] [blame] | 1119 | |
Sebastian Sanchez | e38d1e4 | 2016-04-12 11:22:21 -0700 | [diff] [blame] | 1120 | /* locate the pkey within the headers */ |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 1121 | if (ps->s_txreq->phdr.hdr.hdr_type) { |
| 1122 | struct hfi1_16b_header *hdr = &ps->s_txreq->phdr.hdr.opah; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1123 | |
Don Hiatt | 81cd389 | 2018-05-15 18:28:15 -0700 | [diff] [blame] | 1124 | l4 = hfi1_16B_get_l4(hdr); |
| 1125 | if (l4 == OPA_16B_L4_IB_LOCAL) |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 1126 | ohdr = &hdr->u.oth; |
Don Hiatt | 81cd389 | 2018-05-15 18:28:15 -0700 | [diff] [blame] | 1127 | else if (l4 == OPA_16B_L4_IB_GLOBAL) |
| 1128 | ohdr = &hdr->u.l.oth; |
| 1129 | |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 1130 | slid = hfi1_16B_get_slid(hdr); |
| 1131 | pkey = hfi1_16B_get_pkey(hdr); |
| 1132 | } else { |
| 1133 | struct ib_header *hdr = &ps->s_txreq->phdr.hdr.ibh; |
| 1134 | u8 lnh = ib_get_lnh(hdr); |
| 1135 | |
| 1136 | if (lnh == HFI1_LRH_GRH) |
| 1137 | ohdr = &hdr->u.l.oth; |
| 1138 | else |
| 1139 | ohdr = &hdr->u.oth; |
| 1140 | slid = ib_get_slid(hdr); |
| 1141 | pkey = ib_bth_get_pkey(ohdr); |
| 1142 | } |
| 1143 | |
Don Hiatt | 81cd389 | 2018-05-15 18:28:15 -0700 | [diff] [blame] | 1144 | if (likely(l4 != OPA_16B_L4_FM)) |
| 1145 | ps->opcode = ib_bth_get_opcode(ohdr); |
| 1146 | else |
| 1147 | ps->opcode = IB_OPCODE_UD_SEND_ONLY; |
| 1148 | |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 1149 | sr = get_send_routine(qp, ps); |
| 1150 | ret = egress_pkey_check(dd->pport, slid, pkey, |
| 1151 | priv->s_sc, qp->s_pkey_index); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1152 | if (unlikely(ret)) { |
| 1153 | /* |
| 1154 | * The value we are returning here does not get propagated to |
| 1155 | * the verbs caller. Thus we need to complete the request with |
| 1156 | * error otherwise the caller could be sitting waiting on the |
| 1157 | * completion event. Only do this for PIO. SDMA has its own |
| 1158 | * mechanism for handling the errors. So for SDMA we can just |
| 1159 | * return. |
| 1160 | */ |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 1161 | if (sr == dd->process_pio_send) { |
| 1162 | unsigned long flags; |
| 1163 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1164 | hfi1_cdbg(PIO, "%s() Failed. Completing with err", |
| 1165 | __func__); |
| 1166 | spin_lock_irqsave(&qp->s_lock, flags); |
Venkata Sandeep Dhanalakota | 116aa03 | 2018-09-26 10:44:42 -0700 | [diff] [blame] | 1167 | rvt_send_complete(qp, qp->s_wqe, IB_WC_GENERAL_ERR); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1168 | spin_unlock_irqrestore(&qp->s_lock, flags); |
| 1169 | } |
| 1170 | return -EINVAL; |
| 1171 | } |
Mike Marciniszyn | 47177f1 | 2016-03-07 11:35:41 -0800 | [diff] [blame] | 1172 | if (sr == dd->process_dma_send && iowait_pio_pending(&priv->s_iowait)) |
| 1173 | return pio_wait(qp, |
| 1174 | ps->s_txreq->psc, |
| 1175 | ps, |
Mike Marciniszyn | 2e2ba09 | 2018-06-04 11:44:02 -0700 | [diff] [blame] | 1176 | HFI1_S_WAIT_PIO_DRAIN); |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 1177 | return sr(qp, ps, 0); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1178 | } |
| 1179 | |
Harish Chegondi | 94d5171 | 2016-01-19 14:43:17 -0800 | [diff] [blame] | 1180 | /** |
| 1181 | * hfi1_fill_device_attr - Fill in rvt dev info device attributes. |
| 1182 | * @dd: the device data structure |
| 1183 | */ |
| 1184 | static void hfi1_fill_device_attr(struct hfi1_devdata *dd) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1185 | { |
Harish Chegondi | 94d5171 | 2016-01-19 14:43:17 -0800 | [diff] [blame] | 1186 | struct rvt_dev_info *rdi = &dd->verbs_dev.rdi; |
Michael J. Ruhl | 5e6e9424 | 2017-03-20 17:25:48 -0700 | [diff] [blame] | 1187 | u32 ver = dd->dc8051_ver; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1188 | |
Harish Chegondi | 94d5171 | 2016-01-19 14:43:17 -0800 | [diff] [blame] | 1189 | memset(&rdi->dparms.props, 0, sizeof(rdi->dparms.props)); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1190 | |
Michael J. Ruhl | 5e6e9424 | 2017-03-20 17:25:48 -0700 | [diff] [blame] | 1191 | rdi->dparms.props.fw_ver = ((u64)(dc8051_ver_maj(ver)) << 32) | |
| 1192 | ((u64)(dc8051_ver_min(ver)) << 16) | |
| 1193 | (u64)dc8051_ver_patch(ver); |
| 1194 | |
Harish Chegondi | 94d5171 | 2016-01-19 14:43:17 -0800 | [diff] [blame] | 1195 | rdi->dparms.props.device_cap_flags = IB_DEVICE_BAD_PKEY_CNTR | |
| 1196 | IB_DEVICE_BAD_QKEY_CNTR | IB_DEVICE_SHUTDOWN_PORT | |
| 1197 | IB_DEVICE_SYS_IMAGE_GUID | IB_DEVICE_RC_RNR_NAK_GEN | |
Jianxin Xiong | c72cfe3 | 2016-07-25 13:38:43 -0700 | [diff] [blame] | 1198 | IB_DEVICE_PORT_ACTIVE_EVENT | IB_DEVICE_SRQ_RESIZE | |
Vishwanathapura, Niranjana | 2280740 | 2017-04-12 20:29:29 -0700 | [diff] [blame] | 1199 | IB_DEVICE_MEM_MGT_EXTENSIONS | |
| 1200 | IB_DEVICE_RDMA_NETDEV_OPA_VNIC; |
Harish Chegondi | 94d5171 | 2016-01-19 14:43:17 -0800 | [diff] [blame] | 1201 | rdi->dparms.props.page_size_cap = PAGE_SIZE; |
| 1202 | rdi->dparms.props.vendor_id = dd->oui1 << 16 | dd->oui2 << 8 | dd->oui3; |
| 1203 | rdi->dparms.props.vendor_part_id = dd->pcidev->device; |
| 1204 | rdi->dparms.props.hw_ver = dd->minrev; |
| 1205 | rdi->dparms.props.sys_image_guid = ib_hfi1_sys_image_guid; |
Jianxin Xiong | c72cfe3 | 2016-07-25 13:38:43 -0700 | [diff] [blame] | 1206 | rdi->dparms.props.max_mr_size = U64_MAX; |
| 1207 | rdi->dparms.props.max_fast_reg_page_list_len = UINT_MAX; |
Harish Chegondi | 94d5171 | 2016-01-19 14:43:17 -0800 | [diff] [blame] | 1208 | rdi->dparms.props.max_qp = hfi1_max_qps; |
| 1209 | rdi->dparms.props.max_qp_wr = hfi1_max_qp_wrs; |
Steve Wise | 33023fb | 2018-06-18 08:05:26 -0700 | [diff] [blame] | 1210 | rdi->dparms.props.max_send_sge = hfi1_max_sges; |
| 1211 | rdi->dparms.props.max_recv_sge = hfi1_max_sges; |
Harish Chegondi | 94d5171 | 2016-01-19 14:43:17 -0800 | [diff] [blame] | 1212 | rdi->dparms.props.max_sge_rd = hfi1_max_sges; |
| 1213 | rdi->dparms.props.max_cq = hfi1_max_cqs; |
| 1214 | rdi->dparms.props.max_ah = hfi1_max_ahs; |
| 1215 | rdi->dparms.props.max_cqe = hfi1_max_cqes; |
| 1216 | rdi->dparms.props.max_mr = rdi->lkey_table.max; |
| 1217 | rdi->dparms.props.max_fmr = rdi->lkey_table.max; |
| 1218 | rdi->dparms.props.max_map_per_fmr = 32767; |
| 1219 | rdi->dparms.props.max_pd = hfi1_max_pds; |
| 1220 | rdi->dparms.props.max_qp_rd_atom = HFI1_MAX_RDMA_ATOMIC; |
| 1221 | rdi->dparms.props.max_qp_init_rd_atom = 255; |
| 1222 | rdi->dparms.props.max_srq = hfi1_max_srqs; |
| 1223 | rdi->dparms.props.max_srq_wr = hfi1_max_srq_wrs; |
| 1224 | rdi->dparms.props.max_srq_sge = hfi1_max_srq_sges; |
| 1225 | rdi->dparms.props.atomic_cap = IB_ATOMIC_GLOB; |
| 1226 | rdi->dparms.props.max_pkeys = hfi1_get_npkeys(dd); |
| 1227 | rdi->dparms.props.max_mcast_grp = hfi1_max_mcast_grps; |
| 1228 | rdi->dparms.props.max_mcast_qp_attach = hfi1_max_mcast_qp_attached; |
| 1229 | rdi->dparms.props.max_total_mcast_qp_attach = |
| 1230 | rdi->dparms.props.max_mcast_qp_attach * |
| 1231 | rdi->dparms.props.max_mcast_grp; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | static inline u16 opa_speed_to_ib(u16 in) |
| 1235 | { |
| 1236 | u16 out = 0; |
| 1237 | |
| 1238 | if (in & OPA_LINK_SPEED_25G) |
| 1239 | out |= IB_SPEED_EDR; |
| 1240 | if (in & OPA_LINK_SPEED_12_5G) |
| 1241 | out |= IB_SPEED_FDR; |
| 1242 | |
| 1243 | return out; |
| 1244 | } |
| 1245 | |
| 1246 | /* |
| 1247 | * Convert a single OPA link width (no multiple flags) to an IB value. |
| 1248 | * A zero OPA link width means link down, which means the IB width value |
| 1249 | * is a don't care. |
| 1250 | */ |
| 1251 | static inline u16 opa_width_to_ib(u16 in) |
| 1252 | { |
| 1253 | switch (in) { |
| 1254 | case OPA_LINK_WIDTH_1X: |
| 1255 | /* map 2x and 3x to 1x as they don't exist in IB */ |
| 1256 | case OPA_LINK_WIDTH_2X: |
| 1257 | case OPA_LINK_WIDTH_3X: |
| 1258 | return IB_WIDTH_1X; |
| 1259 | default: /* link down or unknown, return our largest width */ |
| 1260 | case OPA_LINK_WIDTH_4X: |
| 1261 | return IB_WIDTH_4X; |
| 1262 | } |
| 1263 | } |
| 1264 | |
Harish Chegondi | 45b59ee | 2016-02-03 14:36:49 -0800 | [diff] [blame] | 1265 | static int query_port(struct rvt_dev_info *rdi, u8 port_num, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1266 | struct ib_port_attr *props) |
| 1267 | { |
Harish Chegondi | 45b59ee | 2016-02-03 14:36:49 -0800 | [diff] [blame] | 1268 | struct hfi1_ibdev *verbs_dev = dev_from_rdi(rdi); |
| 1269 | struct hfi1_devdata *dd = dd_from_dev(verbs_dev); |
| 1270 | struct hfi1_pportdata *ppd = &dd->pport[port_num - 1]; |
Dasaratharaman Chandramouli | 51e658f5 | 2017-08-04 13:54:35 -0700 | [diff] [blame] | 1271 | u32 lid = ppd->lid; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1272 | |
Or Gerlitz | c4550c6 | 2017-01-24 13:02:39 +0200 | [diff] [blame] | 1273 | /* props being zeroed by the caller, avoid zeroing it here */ |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1274 | props->lid = lid ? lid : 0; |
| 1275 | props->lmc = ppd->lmc; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1276 | /* OPA logical states match IB logical states */ |
| 1277 | props->state = driver_lstate(ppd); |
Byczkowski, Jakub | bec7c79 | 2017-05-29 17:21:32 -0700 | [diff] [blame] | 1278 | props->phys_state = driver_pstate(ppd); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1279 | props->gid_tbl_len = HFI1_GUIDS_PER_PORT; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1280 | props->active_width = (u8)opa_width_to_ib(ppd->link_width_active); |
| 1281 | /* see rate_show() in ib core/sysfs.c */ |
| 1282 | props->active_speed = (u8)opa_speed_to_ib(ppd->link_speed_active); |
| 1283 | props->max_vl_num = ppd->vls_supported; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1284 | |
| 1285 | /* Once we are a "first class" citizen and have added the OPA MTUs to |
| 1286 | * the core we can advertise the larger MTU enum to the ULPs, for now |
| 1287 | * advertise only 4K. |
| 1288 | * |
| 1289 | * Those applications which are either OPA aware or pass the MTU enum |
| 1290 | * from the Path Records to us will get the new 8k MTU. Those that |
| 1291 | * attempt to process the MTU enum may fail in various ways. |
| 1292 | */ |
| 1293 | props->max_mtu = mtu_to_enum((!valid_ib_mtu(hfi1_max_mtu) ? |
| 1294 | 4096 : hfi1_max_mtu), IB_MTU_4096); |
| 1295 | props->active_mtu = !valid_ib_mtu(ppd->ibmtu) ? props->max_mtu : |
Jan Sokolowski | 69a3ffa | 2017-11-14 04:34:45 -0800 | [diff] [blame] | 1296 | mtu_to_enum(ppd->ibmtu, IB_MTU_4096); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1297 | |
| 1298 | return 0; |
| 1299 | } |
| 1300 | |
| 1301 | static int modify_device(struct ib_device *device, |
| 1302 | int device_modify_mask, |
| 1303 | struct ib_device_modify *device_modify) |
| 1304 | { |
| 1305 | struct hfi1_devdata *dd = dd_from_ibdev(device); |
| 1306 | unsigned i; |
| 1307 | int ret; |
| 1308 | |
| 1309 | if (device_modify_mask & ~(IB_DEVICE_MODIFY_SYS_IMAGE_GUID | |
| 1310 | IB_DEVICE_MODIFY_NODE_DESC)) { |
| 1311 | ret = -EOPNOTSUPP; |
| 1312 | goto bail; |
| 1313 | } |
| 1314 | |
| 1315 | if (device_modify_mask & IB_DEVICE_MODIFY_NODE_DESC) { |
Yuval Shaia | bd99fde | 2016-08-25 10:57:07 -0700 | [diff] [blame] | 1316 | memcpy(device->node_desc, device_modify->node_desc, |
| 1317 | IB_DEVICE_NODE_DESC_MAX); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1318 | for (i = 0; i < dd->num_pports; i++) { |
| 1319 | struct hfi1_ibport *ibp = &dd->pport[i].ibport_data; |
| 1320 | |
| 1321 | hfi1_node_desc_chg(ibp); |
| 1322 | } |
| 1323 | } |
| 1324 | |
| 1325 | if (device_modify_mask & IB_DEVICE_MODIFY_SYS_IMAGE_GUID) { |
| 1326 | ib_hfi1_sys_image_guid = |
| 1327 | cpu_to_be64(device_modify->sys_image_guid); |
| 1328 | for (i = 0; i < dd->num_pports; i++) { |
| 1329 | struct hfi1_ibport *ibp = &dd->pport[i].ibport_data; |
| 1330 | |
| 1331 | hfi1_sys_guid_chg(ibp); |
| 1332 | } |
| 1333 | } |
| 1334 | |
| 1335 | ret = 0; |
| 1336 | |
| 1337 | bail: |
| 1338 | return ret; |
| 1339 | } |
| 1340 | |
Harish Chegondi | 45b59ee | 2016-02-03 14:36:49 -0800 | [diff] [blame] | 1341 | static int shut_down_port(struct rvt_dev_info *rdi, u8 port_num) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1342 | { |
Harish Chegondi | 45b59ee | 2016-02-03 14:36:49 -0800 | [diff] [blame] | 1343 | struct hfi1_ibdev *verbs_dev = dev_from_rdi(rdi); |
| 1344 | struct hfi1_devdata *dd = dd_from_dev(verbs_dev); |
| 1345 | struct hfi1_pportdata *ppd = &dd->pport[port_num - 1]; |
| 1346 | int ret; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1347 | |
Harish Chegondi | 45b59ee | 2016-02-03 14:36:49 -0800 | [diff] [blame] | 1348 | set_link_down_reason(ppd, OPA_LINKDOWN_REASON_UNKNOWN, 0, |
| 1349 | OPA_LINKDOWN_REASON_UNKNOWN); |
| 1350 | ret = set_link_state(ppd, HLS_DN_DOWNDEF); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1351 | return ret; |
| 1352 | } |
| 1353 | |
Dennis Dalessandro | 2513146 | 2016-02-03 14:36:40 -0800 | [diff] [blame] | 1354 | static int hfi1_get_guid_be(struct rvt_dev_info *rdi, struct rvt_ibport *rvp, |
| 1355 | int guid_index, __be64 *guid) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1356 | { |
Dennis Dalessandro | 2513146 | 2016-02-03 14:36:40 -0800 | [diff] [blame] | 1357 | struct hfi1_ibport *ibp = container_of(rvp, struct hfi1_ibport, rvp); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1358 | |
Jakub Pawlak | a6cd5f0 | 2016-10-17 04:19:30 -0700 | [diff] [blame] | 1359 | if (guid_index >= HFI1_GUIDS_PER_PORT) |
Dennis Dalessandro | 2513146 | 2016-02-03 14:36:40 -0800 | [diff] [blame] | 1360 | return -EINVAL; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1361 | |
Jakub Pawlak | a6cd5f0 | 2016-10-17 04:19:30 -0700 | [diff] [blame] | 1362 | *guid = get_sguid(ibp, guid_index); |
Dennis Dalessandro | 2513146 | 2016-02-03 14:36:40 -0800 | [diff] [blame] | 1363 | return 0; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1364 | } |
| 1365 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1366 | /* |
| 1367 | * convert ah port,sl to sc |
| 1368 | */ |
Dasaratharaman Chandramouli | 9089885 | 2017-04-29 14:41:18 -0400 | [diff] [blame] | 1369 | u8 ah_to_sc(struct ib_device *ibdev, struct rdma_ah_attr *ah) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1370 | { |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 1371 | struct hfi1_ibport *ibp = to_iport(ibdev, rdma_ah_get_port_num(ah)); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1372 | |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 1373 | return ibp->sl_to_sc[rdma_ah_get_sl(ah)]; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1374 | } |
| 1375 | |
Dasaratharaman Chandramouli | 9089885 | 2017-04-29 14:41:18 -0400 | [diff] [blame] | 1376 | static int hfi1_check_ah(struct ib_device *ibdev, struct rdma_ah_attr *ah_attr) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1377 | { |
| 1378 | struct hfi1_ibport *ibp; |
| 1379 | struct hfi1_pportdata *ppd; |
| 1380 | struct hfi1_devdata *dd; |
| 1381 | u8 sc5; |
Ira Weiny | 0dbfaa9 | 2018-09-20 12:58:46 -0700 | [diff] [blame] | 1382 | u8 sl; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1383 | |
Don Hiatt | 13c1922 | 2017-08-04 13:53:51 -0700 | [diff] [blame] | 1384 | if (hfi1_check_mcast(rdma_ah_get_dlid(ah_attr)) && |
| 1385 | !(rdma_ah_get_ah_flags(ah_attr) & IB_AH_GRH)) |
| 1386 | return -EINVAL; |
| 1387 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1388 | /* test the mapping for validity */ |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 1389 | ibp = to_iport(ibdev, rdma_ah_get_port_num(ah_attr)); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1390 | ppd = ppd_from_ibp(ibp); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1391 | dd = dd_from_ppd(ppd); |
Ira Weiny | 0dbfaa9 | 2018-09-20 12:58:46 -0700 | [diff] [blame] | 1392 | |
| 1393 | sl = rdma_ah_get_sl(ah_attr); |
| 1394 | if (sl >= ARRAY_SIZE(ibp->sl_to_sc)) |
| 1395 | return -EINVAL; |
| 1396 | |
| 1397 | sc5 = ibp->sl_to_sc[sl]; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1398 | if (sc_to_vlt(dd, sc5) > num_vls && sc_to_vlt(dd, sc5) != 0xf) |
Dennis Dalessandro | 15723f0 | 2016-01-19 14:42:17 -0800 | [diff] [blame] | 1399 | return -EINVAL; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1400 | return 0; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1401 | } |
| 1402 | |
Dennis Dalessandro | 8f1764fa | 2016-01-19 14:42:22 -0800 | [diff] [blame] | 1403 | static void hfi1_notify_new_ah(struct ib_device *ibdev, |
Dasaratharaman Chandramouli | 9089885 | 2017-04-29 14:41:18 -0400 | [diff] [blame] | 1404 | struct rdma_ah_attr *ah_attr, |
Dennis Dalessandro | 8f1764fa | 2016-01-19 14:42:22 -0800 | [diff] [blame] | 1405 | struct rvt_ah *ah) |
| 1406 | { |
| 1407 | struct hfi1_ibport *ibp; |
| 1408 | struct hfi1_pportdata *ppd; |
| 1409 | struct hfi1_devdata *dd; |
| 1410 | u8 sc5; |
Don Hiatt | d98bb7f | 2017-08-04 13:54:16 -0700 | [diff] [blame] | 1411 | struct rdma_ah_attr *attr = &ah->attr; |
Dennis Dalessandro | 8f1764fa | 2016-01-19 14:42:22 -0800 | [diff] [blame] | 1412 | |
| 1413 | /* |
| 1414 | * Do not trust reading anything from rvt_ah at this point as it is not |
| 1415 | * done being setup. We can however modify things which we need to set. |
| 1416 | */ |
| 1417 | |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 1418 | ibp = to_iport(ibdev, rdma_ah_get_port_num(ah_attr)); |
Dennis Dalessandro | 8f1764fa | 2016-01-19 14:42:22 -0800 | [diff] [blame] | 1419 | ppd = ppd_from_ibp(ibp); |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 1420 | sc5 = ibp->sl_to_sc[rdma_ah_get_sl(&ah->attr)]; |
Don Hiatt | d98bb7f | 2017-08-04 13:54:16 -0700 | [diff] [blame] | 1421 | hfi1_update_ah_attr(ibdev, attr); |
| 1422 | hfi1_make_opa_lid(attr); |
Dennis Dalessandro | 8f1764fa | 2016-01-19 14:42:22 -0800 | [diff] [blame] | 1423 | dd = dd_from_ppd(ppd); |
| 1424 | ah->vl = sc_to_vlt(dd, sc5); |
| 1425 | if (ah->vl < num_vls || ah->vl == 15) |
| 1426 | ah->log_pmtu = ilog2(dd->vld[ah->vl].mtu); |
| 1427 | } |
| 1428 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1429 | /** |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1430 | * hfi1_get_npkeys - return the size of the PKEY table for context 0 |
| 1431 | * @dd: the hfi1_ib device |
| 1432 | */ |
| 1433 | unsigned hfi1_get_npkeys(struct hfi1_devdata *dd) |
| 1434 | { |
| 1435 | return ARRAY_SIZE(dd->pport[0].pkeys); |
| 1436 | } |
| 1437 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1438 | static void init_ibport(struct hfi1_pportdata *ppd) |
| 1439 | { |
| 1440 | struct hfi1_ibport *ibp = &ppd->ibport_data; |
| 1441 | size_t sz = ARRAY_SIZE(ibp->sl_to_sc); |
| 1442 | int i; |
| 1443 | |
| 1444 | for (i = 0; i < sz; i++) { |
| 1445 | ibp->sl_to_sc[i] = i; |
| 1446 | ibp->sc_to_sl[i] = i; |
| 1447 | } |
| 1448 | |
Michael J. Ruhl | bf90aad | 2017-07-24 07:46:12 -0700 | [diff] [blame] | 1449 | for (i = 0; i < RVT_MAX_TRAP_LISTS ; i++) |
| 1450 | INIT_LIST_HEAD(&ibp->rvp.trap_lists[i].list); |
Kees Cook | 8064135 | 2017-10-16 15:51:54 -0700 | [diff] [blame] | 1451 | timer_setup(&ibp->rvp.trap_timer, hfi1_handle_trap_timer, 0); |
Michael J. Ruhl | bf90aad | 2017-07-24 07:46:12 -0700 | [diff] [blame] | 1452 | |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 1453 | spin_lock_init(&ibp->rvp.lock); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1454 | /* Set the prefix to the default value (see ch. 4.1.1) */ |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 1455 | ibp->rvp.gid_prefix = IB_DEFAULT_GID_PREFIX; |
| 1456 | ibp->rvp.sm_lid = 0; |
Vishwanathapura, Niranjana | cb49366 | 2017-06-01 17:04:02 -0700 | [diff] [blame] | 1457 | /* |
| 1458 | * Below should only set bits defined in OPA PortInfo.CapabilityMask |
| 1459 | * and PortInfo.CapabilityMask3 |
| 1460 | */ |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 1461 | ibp->rvp.port_cap_flags = IB_PORT_AUTO_MIGR_SUP | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1462 | IB_PORT_CAP_MASK_NOTICE_SUP; |
Vishwanathapura, Niranjana | cb49366 | 2017-06-01 17:04:02 -0700 | [diff] [blame] | 1463 | ibp->rvp.port_cap3_flags = OPA_CAP_MASK3_IsSharedSpaceSupported; |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 1464 | ibp->rvp.pma_counter_select[0] = IB_PMA_PORT_XMIT_DATA; |
| 1465 | ibp->rvp.pma_counter_select[1] = IB_PMA_PORT_RCV_DATA; |
| 1466 | ibp->rvp.pma_counter_select[2] = IB_PMA_PORT_XMIT_PKTS; |
| 1467 | ibp->rvp.pma_counter_select[3] = IB_PMA_PORT_RCV_PKTS; |
| 1468 | ibp->rvp.pma_counter_select[4] = IB_PMA_PORT_XMIT_WAIT; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1469 | |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 1470 | RCU_INIT_POINTER(ibp->rvp.qp[0], NULL); |
| 1471 | RCU_INIT_POINTER(ibp->rvp.qp[1], NULL); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1472 | } |
| 1473 | |
Leon Romanovsky | 9abb0d1 | 2017-06-27 16:49:53 +0300 | [diff] [blame] | 1474 | static void hfi1_get_dev_fw_str(struct ib_device *ibdev, char *str) |
Ira Weiny | 939b6ca | 2016-06-15 02:22:08 -0400 | [diff] [blame] | 1475 | { |
| 1476 | struct rvt_dev_info *rdi = ib_to_rvt(ibdev); |
| 1477 | struct hfi1_ibdev *dev = dev_from_rdi(rdi); |
Michael J. Ruhl | 5e6e9424 | 2017-03-20 17:25:48 -0700 | [diff] [blame] | 1478 | u32 ver = dd_from_dev(dev)->dc8051_ver; |
Ira Weiny | 939b6ca | 2016-06-15 02:22:08 -0400 | [diff] [blame] | 1479 | |
Leon Romanovsky | 9abb0d1 | 2017-06-27 16:49:53 +0300 | [diff] [blame] | 1480 | snprintf(str, IB_FW_VERSION_NAME_MAX, "%u.%u.%u", dc8051_ver_maj(ver), |
Michael J. Ruhl | 5e6e9424 | 2017-03-20 17:25:48 -0700 | [diff] [blame] | 1481 | dc8051_ver_min(ver), dc8051_ver_patch(ver)); |
Ira Weiny | 939b6ca | 2016-06-15 02:22:08 -0400 | [diff] [blame] | 1482 | } |
| 1483 | |
Jianxin Xiong | b748194 | 2016-12-07 19:32:53 -0800 | [diff] [blame] | 1484 | static const char * const driver_cntr_names[] = { |
| 1485 | /* must be element 0*/ |
| 1486 | "DRIVER_KernIntr", |
| 1487 | "DRIVER_ErrorIntr", |
| 1488 | "DRIVER_Tx_Errs", |
| 1489 | "DRIVER_Rcv_Errs", |
| 1490 | "DRIVER_HW_Errs", |
| 1491 | "DRIVER_NoPIOBufs", |
| 1492 | "DRIVER_CtxtsOpen", |
| 1493 | "DRIVER_RcvLen_Errs", |
| 1494 | "DRIVER_EgrBufFull", |
| 1495 | "DRIVER_EgrHdrFull" |
| 1496 | }; |
| 1497 | |
Tadeusz Struk | 62eed66 | 2017-03-20 17:25:35 -0700 | [diff] [blame] | 1498 | static DEFINE_MUTEX(cntr_names_lock); /* protects the *_cntr_names bufers */ |
Jianxin Xiong | b748194 | 2016-12-07 19:32:53 -0800 | [diff] [blame] | 1499 | static const char **dev_cntr_names; |
| 1500 | static const char **port_cntr_names; |
Piotr Stankiewicz | 36d8421 | 2018-11-28 06:44:46 -0800 | [diff] [blame] | 1501 | int num_driver_cntrs = ARRAY_SIZE(driver_cntr_names); |
Jianxin Xiong | b748194 | 2016-12-07 19:32:53 -0800 | [diff] [blame] | 1502 | static int num_dev_cntrs; |
| 1503 | static int num_port_cntrs; |
| 1504 | static int cntr_names_initialized; |
| 1505 | |
| 1506 | /* |
| 1507 | * Convert a list of names separated by '\n' into an array of NULL terminated |
| 1508 | * strings. Optionally some entries can be reserved in the array to hold extra |
| 1509 | * external strings. |
| 1510 | */ |
| 1511 | static int init_cntr_names(const char *names_in, |
Arnd Bergmann | 64b2ae7 | 2017-02-14 22:23:07 +0100 | [diff] [blame] | 1512 | const size_t names_len, |
Jianxin Xiong | b748194 | 2016-12-07 19:32:53 -0800 | [diff] [blame] | 1513 | int num_extra_names, |
| 1514 | int *num_cntrs, |
| 1515 | const char ***cntr_names) |
| 1516 | { |
| 1517 | char *names_out, *p, **q; |
| 1518 | int i, n; |
| 1519 | |
| 1520 | n = 0; |
| 1521 | for (i = 0; i < names_len; i++) |
| 1522 | if (names_in[i] == '\n') |
| 1523 | n++; |
| 1524 | |
| 1525 | names_out = kmalloc((n + num_extra_names) * sizeof(char *) + names_len, |
| 1526 | GFP_KERNEL); |
| 1527 | if (!names_out) { |
| 1528 | *num_cntrs = 0; |
| 1529 | *cntr_names = NULL; |
| 1530 | return -ENOMEM; |
| 1531 | } |
| 1532 | |
| 1533 | p = names_out + (n + num_extra_names) * sizeof(char *); |
| 1534 | memcpy(p, names_in, names_len); |
| 1535 | |
| 1536 | q = (char **)names_out; |
| 1537 | for (i = 0; i < n; i++) { |
| 1538 | q[i] = p; |
| 1539 | p = strchr(p, '\n'); |
| 1540 | *p++ = '\0'; |
| 1541 | } |
| 1542 | |
| 1543 | *num_cntrs = n; |
| 1544 | *cntr_names = (const char **)names_out; |
| 1545 | return 0; |
| 1546 | } |
| 1547 | |
| 1548 | static struct rdma_hw_stats *alloc_hw_stats(struct ib_device *ibdev, |
| 1549 | u8 port_num) |
| 1550 | { |
| 1551 | int i, err; |
| 1552 | |
Tadeusz Struk | 62eed66 | 2017-03-20 17:25:35 -0700 | [diff] [blame] | 1553 | mutex_lock(&cntr_names_lock); |
Jianxin Xiong | b748194 | 2016-12-07 19:32:53 -0800 | [diff] [blame] | 1554 | if (!cntr_names_initialized) { |
| 1555 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); |
| 1556 | |
| 1557 | err = init_cntr_names(dd->cntrnames, |
| 1558 | dd->cntrnameslen, |
| 1559 | num_driver_cntrs, |
| 1560 | &num_dev_cntrs, |
| 1561 | &dev_cntr_names); |
Tadeusz Struk | 62eed66 | 2017-03-20 17:25:35 -0700 | [diff] [blame] | 1562 | if (err) { |
| 1563 | mutex_unlock(&cntr_names_lock); |
Jianxin Xiong | b748194 | 2016-12-07 19:32:53 -0800 | [diff] [blame] | 1564 | return NULL; |
Tadeusz Struk | 62eed66 | 2017-03-20 17:25:35 -0700 | [diff] [blame] | 1565 | } |
Jianxin Xiong | b748194 | 2016-12-07 19:32:53 -0800 | [diff] [blame] | 1566 | |
| 1567 | for (i = 0; i < num_driver_cntrs; i++) |
| 1568 | dev_cntr_names[num_dev_cntrs + i] = |
| 1569 | driver_cntr_names[i]; |
| 1570 | |
| 1571 | err = init_cntr_names(dd->portcntrnames, |
| 1572 | dd->portcntrnameslen, |
| 1573 | 0, |
| 1574 | &num_port_cntrs, |
| 1575 | &port_cntr_names); |
| 1576 | if (err) { |
| 1577 | kfree(dev_cntr_names); |
| 1578 | dev_cntr_names = NULL; |
Tadeusz Struk | 62eed66 | 2017-03-20 17:25:35 -0700 | [diff] [blame] | 1579 | mutex_unlock(&cntr_names_lock); |
Jianxin Xiong | b748194 | 2016-12-07 19:32:53 -0800 | [diff] [blame] | 1580 | return NULL; |
| 1581 | } |
| 1582 | cntr_names_initialized = 1; |
| 1583 | } |
Tadeusz Struk | 62eed66 | 2017-03-20 17:25:35 -0700 | [diff] [blame] | 1584 | mutex_unlock(&cntr_names_lock); |
Jianxin Xiong | b748194 | 2016-12-07 19:32:53 -0800 | [diff] [blame] | 1585 | |
| 1586 | if (!port_num) |
| 1587 | return rdma_alloc_hw_stats_struct( |
| 1588 | dev_cntr_names, |
| 1589 | num_dev_cntrs + num_driver_cntrs, |
| 1590 | RDMA_HW_STATS_DEFAULT_LIFESPAN); |
| 1591 | else |
| 1592 | return rdma_alloc_hw_stats_struct( |
| 1593 | port_cntr_names, |
| 1594 | num_port_cntrs, |
| 1595 | RDMA_HW_STATS_DEFAULT_LIFESPAN); |
| 1596 | } |
| 1597 | |
| 1598 | static u64 hfi1_sps_ints(void) |
| 1599 | { |
| 1600 | unsigned long flags; |
| 1601 | struct hfi1_devdata *dd; |
| 1602 | u64 sps_ints = 0; |
| 1603 | |
| 1604 | spin_lock_irqsave(&hfi1_devs_lock, flags); |
| 1605 | list_for_each_entry(dd, &hfi1_dev_list, list) { |
| 1606 | sps_ints += get_all_cpu_total(dd->int_counter); |
| 1607 | } |
| 1608 | spin_unlock_irqrestore(&hfi1_devs_lock, flags); |
| 1609 | return sps_ints; |
| 1610 | } |
| 1611 | |
| 1612 | static int get_hw_stats(struct ib_device *ibdev, struct rdma_hw_stats *stats, |
| 1613 | u8 port, int index) |
| 1614 | { |
| 1615 | u64 *values; |
| 1616 | int count; |
| 1617 | |
| 1618 | if (!port) { |
| 1619 | u64 *stats = (u64 *)&hfi1_stats; |
| 1620 | int i; |
| 1621 | |
| 1622 | hfi1_read_cntrs(dd_from_ibdev(ibdev), NULL, &values); |
| 1623 | values[num_dev_cntrs] = hfi1_sps_ints(); |
| 1624 | for (i = 1; i < num_driver_cntrs; i++) |
| 1625 | values[num_dev_cntrs + i] = stats[i]; |
| 1626 | count = num_dev_cntrs + num_driver_cntrs; |
| 1627 | } else { |
| 1628 | struct hfi1_ibport *ibp = to_iport(ibdev, port); |
| 1629 | |
| 1630 | hfi1_read_portcntrs(ppd_from_ibp(ibp), NULL, &values); |
| 1631 | count = num_port_cntrs; |
| 1632 | } |
| 1633 | |
| 1634 | memcpy(stats->value, values, count * sizeof(u64)); |
| 1635 | return count; |
| 1636 | } |
| 1637 | |
Kamal Heib | e3c320c | 2018-12-10 21:09:34 +0200 | [diff] [blame] | 1638 | static const struct ib_device_ops hfi1_dev_ops = { |
| 1639 | .alloc_hw_stats = alloc_hw_stats, |
| 1640 | .alloc_rdma_netdev = hfi1_vnic_alloc_rn, |
| 1641 | .get_dev_fw_str = hfi1_get_dev_fw_str, |
| 1642 | .get_hw_stats = get_hw_stats, |
Parav Pandit | ea4baf7 | 2018-12-18 14:28:30 +0200 | [diff] [blame] | 1643 | .init_port = hfi1_create_port_files, |
Kamal Heib | e3c320c | 2018-12-10 21:09:34 +0200 | [diff] [blame] | 1644 | .modify_device = modify_device, |
| 1645 | /* keep process mad in the driver */ |
| 1646 | .process_mad = hfi1_process_mad, |
| 1647 | }; |
| 1648 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1649 | /** |
| 1650 | * hfi1_register_ib_device - register our device with the infiniband core |
| 1651 | * @dd: the device data structure |
| 1652 | * Return 0 if successful, errno if unsuccessful. |
| 1653 | */ |
| 1654 | int hfi1_register_ib_device(struct hfi1_devdata *dd) |
| 1655 | { |
| 1656 | struct hfi1_ibdev *dev = &dd->verbs_dev; |
Dennis Dalessandro | ec3f2c1 | 2016-01-19 14:41:33 -0800 | [diff] [blame] | 1657 | struct ib_device *ibdev = &dev->rdi.ibdev; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1658 | struct hfi1_pportdata *ppd = dd->pport; |
Jakub Pawlak | a6cd5f0 | 2016-10-17 04:19:30 -0700 | [diff] [blame] | 1659 | struct hfi1_ibport *ibp = &ppd->ibport_data; |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 1660 | unsigned i; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1661 | int ret; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1662 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1663 | for (i = 0; i < dd->num_pports; i++) |
| 1664 | init_ibport(ppd + i); |
| 1665 | |
| 1666 | /* Only need to initialize non-zero fields. */ |
Dennis Dalessandro | 4f87ccf | 2016-01-19 14:41:50 -0800 | [diff] [blame] | 1667 | |
Kees Cook | 8064135 | 2017-10-16 15:51:54 -0700 | [diff] [blame] | 1668 | timer_setup(&dev->mem_timer, mem_timer, 0); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1669 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1670 | seqlock_init(&dev->iowait_lock); |
Mike Marciniszyn | 4e04557 | 2016-10-10 06:14:28 -0700 | [diff] [blame] | 1671 | seqlock_init(&dev->txwait_lock); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1672 | INIT_LIST_HEAD(&dev->txwait); |
| 1673 | INIT_LIST_HEAD(&dev->memwait); |
| 1674 | |
Mike Marciniszyn | 45842ab | 2016-02-14 12:44:34 -0800 | [diff] [blame] | 1675 | ret = verbs_txreq_init(dev); |
| 1676 | if (ret) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1677 | goto err_verbs_txreq; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1678 | |
Jakub Pawlak | a6cd5f0 | 2016-10-17 04:19:30 -0700 | [diff] [blame] | 1679 | /* Use first-port GUID as node guid */ |
| 1680 | ibdev->node_guid = get_sguid(ibp, HFI1_PORT_GUID_INDEX); |
| 1681 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1682 | /* |
| 1683 | * The system image GUID is supposed to be the same for all |
| 1684 | * HFIs in a single system but since there can be other |
| 1685 | * device types in the system, we can't be sure this is unique. |
| 1686 | */ |
| 1687 | if (!ib_hfi1_sys_image_guid) |
Jakub Pawlak | a6cd5f0 | 2016-10-17 04:19:30 -0700 | [diff] [blame] | 1688 | ib_hfi1_sys_image_guid = ibdev->node_guid; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1689 | ibdev->owner = THIS_MODULE; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1690 | ibdev->phys_port_cnt = dd->num_pports; |
Bart Van Assche | 3067771 | 2017-01-20 13:04:17 -0800 | [diff] [blame] | 1691 | ibdev->dev.parent = &dd->pcidev->dev; |
Dennis Dalessandro | 4331629 | 2016-01-19 14:44:01 -0800 | [diff] [blame] | 1692 | |
Kamal Heib | e3c320c | 2018-12-10 21:09:34 +0200 | [diff] [blame] | 1693 | ib_set_device_ops(ibdev, &hfi1_dev_ops); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1694 | |
Bart Van Assche | 522628e | 2018-07-10 11:32:16 -0700 | [diff] [blame] | 1695 | strlcpy(ibdev->node_desc, init_utsname()->nodename, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1696 | sizeof(ibdev->node_desc)); |
| 1697 | |
Dennis Dalessandro | ec3f2c1 | 2016-01-19 14:41:33 -0800 | [diff] [blame] | 1698 | /* |
| 1699 | * Fill in rvt info object. |
| 1700 | */ |
Dennis Dalessandro | 49dbb6c | 2016-01-19 14:42:06 -0800 | [diff] [blame] | 1701 | dd->verbs_dev.rdi.driver_f.get_pci_dev = get_pci_dev; |
Dennis Dalessandro | 15723f0 | 2016-01-19 14:42:17 -0800 | [diff] [blame] | 1702 | dd->verbs_dev.rdi.driver_f.check_ah = hfi1_check_ah; |
Dennis Dalessandro | 8f1764fa | 2016-01-19 14:42:22 -0800 | [diff] [blame] | 1703 | dd->verbs_dev.rdi.driver_f.notify_new_ah = hfi1_notify_new_ah; |
Dennis Dalessandro | 2513146 | 2016-02-03 14:36:40 -0800 | [diff] [blame] | 1704 | dd->verbs_dev.rdi.driver_f.get_guid_be = hfi1_get_guid_be; |
Harish Chegondi | 45b59ee | 2016-02-03 14:36:49 -0800 | [diff] [blame] | 1705 | dd->verbs_dev.rdi.driver_f.query_port_state = query_port; |
| 1706 | dd->verbs_dev.rdi.driver_f.shut_down_port = shut_down_port; |
| 1707 | dd->verbs_dev.rdi.driver_f.cap_mask_chg = hfi1_cap_mask_chg; |
Harish Chegondi | 94d5171 | 2016-01-19 14:43:17 -0800 | [diff] [blame] | 1708 | /* |
| 1709 | * Fill in rvt info device attributes. |
| 1710 | */ |
| 1711 | hfi1_fill_device_attr(dd); |
Dennis Dalessandro | a2c2d60 | 2016-01-19 14:43:12 -0800 | [diff] [blame] | 1712 | |
| 1713 | /* queue pair */ |
Dennis Dalessandro | a2c2d60 | 2016-01-19 14:43:12 -0800 | [diff] [blame] | 1714 | dd->verbs_dev.rdi.dparms.qp_table_size = hfi1_qp_table_size; |
| 1715 | dd->verbs_dev.rdi.dparms.qpn_start = 0; |
| 1716 | dd->verbs_dev.rdi.dparms.qpn_inc = 1; |
| 1717 | dd->verbs_dev.rdi.dparms.qos_shift = dd->qos_shift; |
| 1718 | dd->verbs_dev.rdi.dparms.qpn_res_start = kdeth_qp << 16; |
| 1719 | dd->verbs_dev.rdi.dparms.qpn_res_end = |
Dennis Dalessandro | abd712d | 2016-01-19 14:43:22 -0800 | [diff] [blame] | 1720 | dd->verbs_dev.rdi.dparms.qpn_res_start + 65535; |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 1721 | dd->verbs_dev.rdi.dparms.max_rdma_atomic = HFI1_MAX_RDMA_ATOMIC; |
| 1722 | dd->verbs_dev.rdi.dparms.psn_mask = PSN_MASK; |
| 1723 | dd->verbs_dev.rdi.dparms.psn_shift = PSN_SHIFT; |
| 1724 | dd->verbs_dev.rdi.dparms.psn_modify_mask = PSN_MODIFY_MASK; |
Dasaratharaman Chandramouli | 7221403 | 2017-08-04 13:54:53 -0700 | [diff] [blame] | 1725 | dd->verbs_dev.rdi.dparms.core_cap_flags = RDMA_CORE_PORT_INTEL_OPA | |
| 1726 | RDMA_CORE_CAP_OPA_AH; |
Harish Chegondi | 45b59ee | 2016-02-03 14:36:49 -0800 | [diff] [blame] | 1727 | dd->verbs_dev.rdi.dparms.max_mad_size = OPA_MGMT_MAD_SIZE; |
| 1728 | |
Dennis Dalessandro | a2c2d60 | 2016-01-19 14:43:12 -0800 | [diff] [blame] | 1729 | dd->verbs_dev.rdi.driver_f.qp_priv_alloc = qp_priv_alloc; |
Mike Marciniszyn | 5190f05 | 2018-11-28 10:22:31 -0800 | [diff] [blame] | 1730 | dd->verbs_dev.rdi.driver_f.qp_priv_init = hfi1_qp_priv_init; |
Dennis Dalessandro | a2c2d60 | 2016-01-19 14:43:12 -0800 | [diff] [blame] | 1731 | dd->verbs_dev.rdi.driver_f.qp_priv_free = qp_priv_free; |
| 1732 | dd->verbs_dev.rdi.driver_f.free_all_qps = free_all_qps; |
| 1733 | dd->verbs_dev.rdi.driver_f.notify_qp_reset = notify_qp_reset; |
Mike Marciniszyn | b6eac93 | 2017-04-09 10:16:35 -0700 | [diff] [blame] | 1734 | dd->verbs_dev.rdi.driver_f.do_send = hfi1_do_send_from_rvt; |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 1735 | dd->verbs_dev.rdi.driver_f.schedule_send = hfi1_schedule_send; |
Mike Marciniszyn | 46a80d6 | 2016-02-14 12:10:04 -0800 | [diff] [blame] | 1736 | dd->verbs_dev.rdi.driver_f.schedule_send_no_lock = _hfi1_schedule_send; |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 1737 | dd->verbs_dev.rdi.driver_f.get_pmtu_from_attr = get_pmtu_from_attr; |
| 1738 | dd->verbs_dev.rdi.driver_f.notify_error_qp = notify_error_qp; |
| 1739 | dd->verbs_dev.rdi.driver_f.flush_qp_waiters = flush_qp_waiters; |
| 1740 | dd->verbs_dev.rdi.driver_f.stop_send_queue = stop_send_queue; |
| 1741 | dd->verbs_dev.rdi.driver_f.quiesce_qp = quiesce_qp; |
| 1742 | dd->verbs_dev.rdi.driver_f.notify_error_qp = notify_error_qp; |
| 1743 | dd->verbs_dev.rdi.driver_f.mtu_from_qp = mtu_from_qp; |
| 1744 | dd->verbs_dev.rdi.driver_f.mtu_to_path_mtu = mtu_to_path_mtu; |
| 1745 | dd->verbs_dev.rdi.driver_f.check_modify_qp = hfi1_check_modify_qp; |
| 1746 | dd->verbs_dev.rdi.driver_f.modify_qp = hfi1_modify_qp; |
Venkata Sandeep Dhanalakota | 56acbbf | 2017-02-08 05:27:19 -0800 | [diff] [blame] | 1747 | dd->verbs_dev.rdi.driver_f.notify_restart_rc = hfi1_restart_rc; |
Kaike Wan | d205a06a | 2018-09-26 10:26:44 -0700 | [diff] [blame] | 1748 | dd->verbs_dev.rdi.driver_f.setup_wqe = hfi1_setup_wqe; |
Sebastian Sanchez | 5d18ee6 | 2018-05-02 06:43:55 -0700 | [diff] [blame] | 1749 | dd->verbs_dev.rdi.driver_f.comp_vect_cpu_lookup = |
| 1750 | hfi1_comp_vect_mappings_lookup; |
Dennis Dalessandro | a2c2d60 | 2016-01-19 14:43:12 -0800 | [diff] [blame] | 1751 | |
Dennis Dalessandro | abd712d | 2016-01-19 14:43:22 -0800 | [diff] [blame] | 1752 | /* completeion queue */ |
Sebastian Sanchez | 5d18ee6 | 2018-05-02 06:43:55 -0700 | [diff] [blame] | 1753 | dd->verbs_dev.rdi.ibdev.num_comp_vectors = dd->comp_vect_possible_cpus; |
Mitko Haralanov | 2780739 | 2016-02-03 14:33:31 -0800 | [diff] [blame] | 1754 | dd->verbs_dev.rdi.dparms.node = dd->node; |
Dennis Dalessandro | abd712d | 2016-01-19 14:43:22 -0800 | [diff] [blame] | 1755 | |
Dennis Dalessandro | a2c2d60 | 2016-01-19 14:43:12 -0800 | [diff] [blame] | 1756 | /* misc settings */ |
Dennis Dalessandro | abd712d | 2016-01-19 14:43:22 -0800 | [diff] [blame] | 1757 | dd->verbs_dev.rdi.flags = 0; /* Let rdmavt handle it all */ |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 1758 | dd->verbs_dev.rdi.dparms.lkey_table_size = hfi1_lkey_table_size; |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 1759 | dd->verbs_dev.rdi.dparms.nports = dd->num_pports; |
| 1760 | dd->verbs_dev.rdi.dparms.npkeys = hfi1_get_npkeys(dd); |
Brian Welty | 019f118 | 2018-09-26 10:44:33 -0700 | [diff] [blame] | 1761 | dd->verbs_dev.rdi.dparms.sge_copy_mode = sge_copy_mode; |
| 1762 | dd->verbs_dev.rdi.dparms.wss_threshold = wss_threshold; |
| 1763 | dd->verbs_dev.rdi.dparms.wss_clean_period = wss_clean_period; |
Kaike Wan | 48a615d | 2019-01-23 19:21:11 -0800 | [diff] [blame] | 1764 | dd->verbs_dev.rdi.dparms.reserved_operations = 1; |
Kaike Wan | ddf922c | 2019-01-23 19:21:01 -0800 | [diff] [blame] | 1765 | dd->verbs_dev.rdi.dparms.extra_rdma_atomic = 1; |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 1766 | |
Mike Marciniszyn | 1ac57c5 | 2016-07-01 16:02:13 -0700 | [diff] [blame] | 1767 | /* post send table */ |
| 1768 | dd->verbs_dev.rdi.post_parms = hfi1_post_parms; |
| 1769 | |
Venkata Sandeep Dhanalakota | 116aa03 | 2018-09-26 10:44:42 -0700 | [diff] [blame] | 1770 | /* opcode translation table */ |
| 1771 | dd->verbs_dev.rdi.wc_opcode = ib_hfi1_wc_opcode; |
| 1772 | |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 1773 | ppd = dd->pport; |
| 1774 | for (i = 0; i < dd->num_pports; i++, ppd++) |
| 1775 | rvt_init_port(&dd->verbs_dev.rdi, |
| 1776 | &ppd->ibport_data.rvp, |
| 1777 | i, |
| 1778 | ppd->pkeys); |
Dennis Dalessandro | ec3f2c1 | 2016-01-19 14:41:33 -0800 | [diff] [blame] | 1779 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 1780 | rdma_set_device_sysfs_group(&dd->verbs_dev.rdi.ibdev, |
| 1781 | &ib_hfi1_attr_group); |
| 1782 | |
Matan Barak | 0ede73b | 2018-03-19 15:02:34 +0200 | [diff] [blame] | 1783 | ret = rvt_register_device(&dd->verbs_dev.rdi, RDMA_DRIVER_HFI1); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1784 | if (ret) |
Dennis Dalessandro | 9c4a311 | 2016-01-19 14:44:11 -0800 | [diff] [blame] | 1785 | goto err_verbs_txreq; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1786 | |
| 1787 | ret = hfi1_verbs_register_sysfs(dd); |
| 1788 | if (ret) |
| 1789 | goto err_class; |
| 1790 | |
Dennis Dalessandro | 9c4a311 | 2016-01-19 14:44:11 -0800 | [diff] [blame] | 1791 | return ret; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1792 | |
| 1793 | err_class: |
Dennis Dalessandro | ec3f2c1 | 2016-01-19 14:41:33 -0800 | [diff] [blame] | 1794 | rvt_unregister_device(&dd->verbs_dev.rdi); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1795 | err_verbs_txreq: |
Mike Marciniszyn | 45842ab | 2016-02-14 12:44:34 -0800 | [diff] [blame] | 1796 | verbs_txreq_exit(dev); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1797 | dd_dev_err(dd, "cannot register verbs: %d!\n", -ret); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1798 | return ret; |
| 1799 | } |
| 1800 | |
| 1801 | void hfi1_unregister_ib_device(struct hfi1_devdata *dd) |
| 1802 | { |
| 1803 | struct hfi1_ibdev *dev = &dd->verbs_dev; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1804 | |
| 1805 | hfi1_verbs_unregister_sysfs(dd); |
| 1806 | |
Dennis Dalessandro | ec3f2c1 | 2016-01-19 14:41:33 -0800 | [diff] [blame] | 1807 | rvt_unregister_device(&dd->verbs_dev.rdi); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1808 | |
| 1809 | if (!list_empty(&dev->txwait)) |
| 1810 | dd_dev_err(dd, "txwait list not empty!\n"); |
| 1811 | if (!list_empty(&dev->memwait)) |
| 1812 | dd_dev_err(dd, "memwait list not empty!\n"); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1813 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1814 | del_timer_sync(&dev->mem_timer); |
Mike Marciniszyn | 45842ab | 2016-02-14 12:44:34 -0800 | [diff] [blame] | 1815 | verbs_txreq_exit(dev); |
Jianxin Xiong | b748194 | 2016-12-07 19:32:53 -0800 | [diff] [blame] | 1816 | |
Tadeusz Struk | 62eed66 | 2017-03-20 17:25:35 -0700 | [diff] [blame] | 1817 | mutex_lock(&cntr_names_lock); |
Jianxin Xiong | b748194 | 2016-12-07 19:32:53 -0800 | [diff] [blame] | 1818 | kfree(dev_cntr_names); |
| 1819 | kfree(port_cntr_names); |
Tadeusz Struk | 62eed66 | 2017-03-20 17:25:35 -0700 | [diff] [blame] | 1820 | dev_cntr_names = NULL; |
| 1821 | port_cntr_names = NULL; |
Jianxin Xiong | b748194 | 2016-12-07 19:32:53 -0800 | [diff] [blame] | 1822 | cntr_names_initialized = 0; |
Tadeusz Struk | 62eed66 | 2017-03-20 17:25:35 -0700 | [diff] [blame] | 1823 | mutex_unlock(&cntr_names_lock); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1824 | } |
| 1825 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1826 | void hfi1_cnp_rcv(struct hfi1_packet *packet) |
| 1827 | { |
Sebastian Sanchez | f3e862c | 2017-02-08 05:26:25 -0800 | [diff] [blame] | 1828 | struct hfi1_ibport *ibp = rcd_to_iport(packet->rcd); |
Arthur Kepner | 977940b | 2015-11-04 21:10:10 -0500 | [diff] [blame] | 1829 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); |
Mike Marciniszyn | 261a435 | 2016-09-06 04:35:05 -0700 | [diff] [blame] | 1830 | struct ib_header *hdr = packet->hdr; |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 1831 | struct rvt_qp *qp = packet->qp; |
Arthur Kepner | 977940b | 2015-11-04 21:10:10 -0500 | [diff] [blame] | 1832 | u32 lqpn, rqpn = 0; |
| 1833 | u16 rlid = 0; |
Dasaratharaman Chandramouli | b736a46 | 2016-07-25 13:40:34 -0700 | [diff] [blame] | 1834 | u8 sl, sc5, svc_type; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1835 | |
Arthur Kepner | 977940b | 2015-11-04 21:10:10 -0500 | [diff] [blame] | 1836 | switch (packet->qp->ibqp.qp_type) { |
| 1837 | case IB_QPT_UC: |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 1838 | rlid = rdma_ah_get_dlid(&qp->remote_ah_attr); |
Arthur Kepner | 977940b | 2015-11-04 21:10:10 -0500 | [diff] [blame] | 1839 | rqpn = qp->remote_qpn; |
| 1840 | svc_type = IB_CC_SVCTYPE_UC; |
| 1841 | break; |
| 1842 | case IB_QPT_RC: |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 1843 | rlid = rdma_ah_get_dlid(&qp->remote_ah_attr); |
Arthur Kepner | 977940b | 2015-11-04 21:10:10 -0500 | [diff] [blame] | 1844 | rqpn = qp->remote_qpn; |
| 1845 | svc_type = IB_CC_SVCTYPE_RC; |
| 1846 | break; |
| 1847 | case IB_QPT_SMI: |
| 1848 | case IB_QPT_GSI: |
| 1849 | case IB_QPT_UD: |
| 1850 | svc_type = IB_CC_SVCTYPE_UD; |
| 1851 | break; |
| 1852 | default: |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 1853 | ibp->rvp.n_pkt_drops++; |
Arthur Kepner | 977940b | 2015-11-04 21:10:10 -0500 | [diff] [blame] | 1854 | return; |
| 1855 | } |
| 1856 | |
Dasaratharaman Chandramouli | aad559c | 2017-04-09 10:16:15 -0700 | [diff] [blame] | 1857 | sc5 = hfi1_9B_get_sc5(hdr, packet->rhf); |
Arthur Kepner | 977940b | 2015-11-04 21:10:10 -0500 | [diff] [blame] | 1858 | sl = ibp->sc_to_sl[sc5]; |
| 1859 | lqpn = qp->ibqp.qp_num; |
| 1860 | |
| 1861 | process_becn(ppd, sl, rlid, lqpn, rqpn, svc_type); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1862 | } |