1f931551bSRalph Campbell /* 25d18ee67SSebastian Sanchez * Copyright (c) 2012 - 2018 Intel Corporation. All rights reserved. 31fb9fed6SMike Marciniszyn * Copyright (c) 2006 - 2012 QLogic Corporation. All rights reserved. 4f931551bSRalph Campbell * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved. 5f931551bSRalph Campbell * 6f931551bSRalph Campbell * This software is available to you under a choice of one of two 7f931551bSRalph Campbell * licenses. You may choose to be licensed under the terms of the GNU 8f931551bSRalph Campbell * General Public License (GPL) Version 2, available from the file 9f931551bSRalph Campbell * COPYING in the main directory of this source tree, or the 10f931551bSRalph Campbell * OpenIB.org BSD license below: 11f931551bSRalph Campbell * 12f931551bSRalph Campbell * Redistribution and use in source and binary forms, with or 13f931551bSRalph Campbell * without modification, are permitted provided that the following 14f931551bSRalph Campbell * conditions are met: 15f931551bSRalph Campbell * 16f931551bSRalph Campbell * - Redistributions of source code must retain the above 17f931551bSRalph Campbell * copyright notice, this list of conditions and the following 18f931551bSRalph Campbell * disclaimer. 19f931551bSRalph Campbell * 20f931551bSRalph Campbell * - Redistributions in binary form must reproduce the above 21f931551bSRalph Campbell * copyright notice, this list of conditions and the following 22f931551bSRalph Campbell * disclaimer in the documentation and/or other materials 23f931551bSRalph Campbell * provided with the distribution. 24f931551bSRalph Campbell * 25f931551bSRalph Campbell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26f931551bSRalph Campbell * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27f931551bSRalph Campbell * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28f931551bSRalph Campbell * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 29f931551bSRalph Campbell * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 30f931551bSRalph Campbell * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 31f931551bSRalph Campbell * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32f931551bSRalph Campbell * SOFTWARE. 33f931551bSRalph Campbell */ 34f931551bSRalph Campbell 35f931551bSRalph Campbell #include <rdma/ib_mad.h> 36f931551bSRalph Campbell #include <rdma/ib_user_verbs.h> 37f931551bSRalph Campbell #include <linux/io.h> 38e4dd23d7SPaul Gortmaker #include <linux/module.h> 39f931551bSRalph Campbell #include <linux/utsname.h> 40f931551bSRalph Campbell #include <linux/rculist.h> 41f931551bSRalph Campbell #include <linux/mm.h> 42d6f1c17eSMike Marciniszyn #include <linux/vmalloc.h> 43eb636ac0SDennis Dalessandro #include <rdma/rdma_vt.h> 44f931551bSRalph Campbell 45f931551bSRalph Campbell #include "qib.h" 46f931551bSRalph Campbell #include "qib_common.h" 47f931551bSRalph Campbell 48af061a64SMike Marciniszyn static unsigned int ib_qib_qp_table_size = 256; 49f931551bSRalph Campbell module_param_named(qp_table_size, ib_qib_qp_table_size, uint, S_IRUGO); 50f931551bSRalph Campbell MODULE_PARM_DESC(qp_table_size, "QP table size"); 51f931551bSRalph Campbell 527c2e11feSDennis Dalessandro static unsigned int qib_lkey_table_size = 16; 537c2e11feSDennis Dalessandro module_param_named(lkey_table_size, qib_lkey_table_size, uint, 54f931551bSRalph Campbell S_IRUGO); 55f931551bSRalph Campbell MODULE_PARM_DESC(lkey_table_size, 56f931551bSRalph Campbell "LKEY table size in bits (2^n, 1 <= n <= 23)"); 57f931551bSRalph Campbell 58f931551bSRalph Campbell static unsigned int ib_qib_max_pds = 0xFFFF; 59f931551bSRalph Campbell module_param_named(max_pds, ib_qib_max_pds, uint, S_IRUGO); 60f931551bSRalph Campbell MODULE_PARM_DESC(max_pds, 61f931551bSRalph Campbell "Maximum number of protection domains to support"); 62f931551bSRalph Campbell 63f931551bSRalph Campbell static unsigned int ib_qib_max_ahs = 0xFFFF; 64f931551bSRalph Campbell module_param_named(max_ahs, ib_qib_max_ahs, uint, S_IRUGO); 65f931551bSRalph Campbell MODULE_PARM_DESC(max_ahs, "Maximum number of address handles to support"); 66f931551bSRalph Campbell 67f931551bSRalph Campbell unsigned int ib_qib_max_cqes = 0x2FFFF; 68f931551bSRalph Campbell module_param_named(max_cqes, ib_qib_max_cqes, uint, S_IRUGO); 69f931551bSRalph Campbell MODULE_PARM_DESC(max_cqes, 70f931551bSRalph Campbell "Maximum number of completion queue entries to support"); 71f931551bSRalph Campbell 72f931551bSRalph Campbell unsigned int ib_qib_max_cqs = 0x1FFFF; 73f931551bSRalph Campbell module_param_named(max_cqs, ib_qib_max_cqs, uint, S_IRUGO); 74f931551bSRalph Campbell MODULE_PARM_DESC(max_cqs, "Maximum number of completion queues to support"); 75f931551bSRalph Campbell 76f931551bSRalph Campbell unsigned int ib_qib_max_qp_wrs = 0x3FFF; 77f931551bSRalph Campbell module_param_named(max_qp_wrs, ib_qib_max_qp_wrs, uint, S_IRUGO); 78f931551bSRalph Campbell MODULE_PARM_DESC(max_qp_wrs, "Maximum number of QP WRs to support"); 79f931551bSRalph Campbell 80f931551bSRalph Campbell unsigned int ib_qib_max_qps = 16384; 81f931551bSRalph Campbell module_param_named(max_qps, ib_qib_max_qps, uint, S_IRUGO); 82f931551bSRalph Campbell MODULE_PARM_DESC(max_qps, "Maximum number of QPs to support"); 83f931551bSRalph Campbell 84f931551bSRalph Campbell unsigned int ib_qib_max_sges = 0x60; 85f931551bSRalph Campbell module_param_named(max_sges, ib_qib_max_sges, uint, S_IRUGO); 86f931551bSRalph Campbell MODULE_PARM_DESC(max_sges, "Maximum number of SGEs to support"); 87f931551bSRalph Campbell 88f931551bSRalph Campbell unsigned int ib_qib_max_mcast_grps = 16384; 89f931551bSRalph Campbell module_param_named(max_mcast_grps, ib_qib_max_mcast_grps, uint, S_IRUGO); 90f931551bSRalph Campbell MODULE_PARM_DESC(max_mcast_grps, 91f931551bSRalph Campbell "Maximum number of multicast groups to support"); 92f931551bSRalph Campbell 93f931551bSRalph Campbell unsigned int ib_qib_max_mcast_qp_attached = 16; 94f931551bSRalph Campbell module_param_named(max_mcast_qp_attached, ib_qib_max_mcast_qp_attached, 95f931551bSRalph Campbell uint, S_IRUGO); 96f931551bSRalph Campbell MODULE_PARM_DESC(max_mcast_qp_attached, 97f931551bSRalph Campbell "Maximum number of attached QPs to support"); 98f931551bSRalph Campbell 99f931551bSRalph Campbell unsigned int ib_qib_max_srqs = 1024; 100f931551bSRalph Campbell module_param_named(max_srqs, ib_qib_max_srqs, uint, S_IRUGO); 101f931551bSRalph Campbell MODULE_PARM_DESC(max_srqs, "Maximum number of SRQs to support"); 102f931551bSRalph Campbell 103f931551bSRalph Campbell unsigned int ib_qib_max_srq_sges = 128; 104f931551bSRalph Campbell module_param_named(max_srq_sges, ib_qib_max_srq_sges, uint, S_IRUGO); 105f931551bSRalph Campbell MODULE_PARM_DESC(max_srq_sges, "Maximum number of SRQ SGEs to support"); 106f931551bSRalph Campbell 107f931551bSRalph Campbell unsigned int ib_qib_max_srq_wrs = 0x1FFFF; 108f931551bSRalph Campbell module_param_named(max_srq_wrs, ib_qib_max_srq_wrs, uint, S_IRUGO); 109f931551bSRalph Campbell MODULE_PARM_DESC(max_srq_wrs, "Maximum number of SRQ WRs support"); 110f931551bSRalph Campbell 111f931551bSRalph Campbell static unsigned int ib_qib_disable_sma; 112f931551bSRalph Campbell module_param_named(disable_sma, ib_qib_disable_sma, uint, S_IWUSR | S_IRUGO); 113f931551bSRalph Campbell MODULE_PARM_DESC(disable_sma, "Disable the SMA"); 114f931551bSRalph Campbell 115f931551bSRalph Campbell /* 11643a474aaSMike Marciniszyn * Translate ib_wr_opcode into ib_wc_opcode. 11743a474aaSMike Marciniszyn */ 11843a474aaSMike Marciniszyn const enum ib_wc_opcode ib_qib_wc_opcode[] = { 11943a474aaSMike Marciniszyn [IB_WR_RDMA_WRITE] = IB_WC_RDMA_WRITE, 12043a474aaSMike Marciniszyn [IB_WR_RDMA_WRITE_WITH_IMM] = IB_WC_RDMA_WRITE, 12143a474aaSMike Marciniszyn [IB_WR_SEND] = IB_WC_SEND, 12243a474aaSMike Marciniszyn [IB_WR_SEND_WITH_IMM] = IB_WC_SEND, 12343a474aaSMike Marciniszyn [IB_WR_RDMA_READ] = IB_WC_RDMA_READ, 12443a474aaSMike Marciniszyn [IB_WR_ATOMIC_CMP_AND_SWP] = IB_WC_COMP_SWAP, 12543a474aaSMike Marciniszyn [IB_WR_ATOMIC_FETCH_AND_ADD] = IB_WC_FETCH_ADD 12643a474aaSMike Marciniszyn }; 12743a474aaSMike Marciniszyn 12843a474aaSMike Marciniszyn /* 129f931551bSRalph Campbell * System image GUID. 130f931551bSRalph Campbell */ 131f931551bSRalph Campbell __be64 ib_qib_sys_image_guid; 132f931551bSRalph Campbell 133f931551bSRalph Campbell /* 134f931551bSRalph Campbell * Count the number of DMA descriptors needed to send length bytes of data. 135f931551bSRalph Campbell * Don't modify the qib_sge_state to get the count. 136f931551bSRalph Campbell * Return zero if any of the segments is not aligned. 137f931551bSRalph Campbell */ 1387c2e11feSDennis Dalessandro static u32 qib_count_sge(struct rvt_sge_state *ss, u32 length) 139f931551bSRalph Campbell { 1407c2e11feSDennis Dalessandro struct rvt_sge *sg_list = ss->sg_list; 1417c2e11feSDennis Dalessandro struct rvt_sge sge = ss->sge; 142f931551bSRalph Campbell u8 num_sge = ss->num_sge; 143f931551bSRalph Campbell u32 ndesc = 1; /* count the header */ 144f931551bSRalph Campbell 145f931551bSRalph Campbell while (length) { 14687fc34b5SMichael J. Ruhl u32 len = rvt_get_sge_length(&sge, length); 147f931551bSRalph Campbell 148f931551bSRalph Campbell if (((long) sge.vaddr & (sizeof(u32) - 1)) || 149f931551bSRalph Campbell (len != length && (len & (sizeof(u32) - 1)))) { 150f931551bSRalph Campbell ndesc = 0; 151f931551bSRalph Campbell break; 152f931551bSRalph Campbell } 153f931551bSRalph Campbell ndesc++; 154f931551bSRalph Campbell sge.vaddr += len; 155f931551bSRalph Campbell sge.length -= len; 156f931551bSRalph Campbell sge.sge_length -= len; 157f931551bSRalph Campbell if (sge.sge_length == 0) { 158f931551bSRalph Campbell if (--num_sge) 159f931551bSRalph Campbell sge = *sg_list++; 160f931551bSRalph Campbell } else if (sge.length == 0 && sge.mr->lkey) { 1617c2e11feSDennis Dalessandro if (++sge.n >= RVT_SEGSZ) { 162f931551bSRalph Campbell if (++sge.m >= sge.mr->mapsz) 163f931551bSRalph Campbell break; 164f931551bSRalph Campbell sge.n = 0; 165f931551bSRalph Campbell } 166f931551bSRalph Campbell sge.vaddr = 167f931551bSRalph Campbell sge.mr->map[sge.m]->segs[sge.n].vaddr; 168f931551bSRalph Campbell sge.length = 169f931551bSRalph Campbell sge.mr->map[sge.m]->segs[sge.n].length; 170f931551bSRalph Campbell } 171f931551bSRalph Campbell length -= len; 172f931551bSRalph Campbell } 173f931551bSRalph Campbell return ndesc; 174f931551bSRalph Campbell } 175f931551bSRalph Campbell 176f931551bSRalph Campbell /* 177f931551bSRalph Campbell * Copy from the SGEs to the data buffer. 178f931551bSRalph Campbell */ 1797c2e11feSDennis Dalessandro static void qib_copy_from_sge(void *data, struct rvt_sge_state *ss, u32 length) 180f931551bSRalph Campbell { 1817c2e11feSDennis Dalessandro struct rvt_sge *sge = &ss->sge; 182f931551bSRalph Campbell 183f931551bSRalph Campbell while (length) { 18487fc34b5SMichael J. Ruhl u32 len = rvt_get_sge_length(sge, length); 185f931551bSRalph Campbell 186f931551bSRalph Campbell memcpy(data, sge->vaddr, len); 187f931551bSRalph Campbell sge->vaddr += len; 188f931551bSRalph Campbell sge->length -= len; 189f931551bSRalph Campbell sge->sge_length -= len; 190f931551bSRalph Campbell if (sge->sge_length == 0) { 191f931551bSRalph Campbell if (--ss->num_sge) 192f931551bSRalph Campbell *sge = *ss->sg_list++; 193f931551bSRalph Campbell } else if (sge->length == 0 && sge->mr->lkey) { 1947c2e11feSDennis Dalessandro if (++sge->n >= RVT_SEGSZ) { 195f931551bSRalph Campbell if (++sge->m >= sge->mr->mapsz) 196f931551bSRalph Campbell break; 197f931551bSRalph Campbell sge->n = 0; 198f931551bSRalph Campbell } 199f931551bSRalph Campbell sge->vaddr = 200f931551bSRalph Campbell sge->mr->map[sge->m]->segs[sge->n].vaddr; 201f931551bSRalph Campbell sge->length = 202f931551bSRalph Campbell sge->mr->map[sge->m]->segs[sge->n].length; 203f931551bSRalph Campbell } 204f931551bSRalph Campbell data += len; 205f931551bSRalph Campbell length -= len; 206f931551bSRalph Campbell } 207f931551bSRalph Campbell } 208f931551bSRalph Campbell 209f931551bSRalph Campbell /** 210f931551bSRalph Campbell * qib_qp_rcv - processing an incoming packet on a QP 211f931551bSRalph Campbell * @rcd: the context pointer 212f931551bSRalph Campbell * @hdr: the packet header 213f931551bSRalph Campbell * @has_grh: true if the packet has a GRH 214f931551bSRalph Campbell * @data: the packet data 215f931551bSRalph Campbell * @tlen: the packet length 216f931551bSRalph Campbell * @qp: the QP the packet came on 217f931551bSRalph Campbell * 218f931551bSRalph Campbell * This is called from qib_ib_rcv() to process an incoming packet 219f931551bSRalph Campbell * for the given QP. 220f931551bSRalph Campbell * Called at interrupt level. 221f931551bSRalph Campbell */ 222261a4351SMike Marciniszyn static void qib_qp_rcv(struct qib_ctxtdata *rcd, struct ib_header *hdr, 2237c2e11feSDennis Dalessandro int has_grh, void *data, u32 tlen, struct rvt_qp *qp) 224f931551bSRalph Campbell { 225f931551bSRalph Campbell struct qib_ibport *ibp = &rcd->ppd->ibport_data; 226f931551bSRalph Campbell 227a5210c12SRalph Campbell spin_lock(&qp->r_lock); 228a5210c12SRalph Campbell 229f931551bSRalph Campbell /* Check for valid receive state. */ 230db3ef0ebSHarish Chegondi if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK)) { 231f24a6d48SHarish Chegondi ibp->rvp.n_pkt_drops++; 232a5210c12SRalph Campbell goto unlock; 233f931551bSRalph Campbell } 234f931551bSRalph Campbell 235f931551bSRalph Campbell switch (qp->ibqp.qp_type) { 236f931551bSRalph Campbell case IB_QPT_SMI: 237f931551bSRalph Campbell case IB_QPT_GSI: 238f931551bSRalph Campbell if (ib_qib_disable_sma) 239f931551bSRalph Campbell break; 240df561f66SGustavo A. R. Silva fallthrough; 241f931551bSRalph Campbell case IB_QPT_UD: 242f931551bSRalph Campbell qib_ud_rcv(ibp, hdr, has_grh, data, tlen, qp); 243f931551bSRalph Campbell break; 244f931551bSRalph Campbell 245f931551bSRalph Campbell case IB_QPT_RC: 246f931551bSRalph Campbell qib_rc_rcv(rcd, hdr, has_grh, data, tlen, qp); 247f931551bSRalph Campbell break; 248f931551bSRalph Campbell 249f931551bSRalph Campbell case IB_QPT_UC: 250f931551bSRalph Campbell qib_uc_rcv(ibp, hdr, has_grh, data, tlen, qp); 251f931551bSRalph Campbell break; 252f931551bSRalph Campbell 253f931551bSRalph Campbell default: 254f931551bSRalph Campbell break; 255f931551bSRalph Campbell } 256a5210c12SRalph Campbell 257a5210c12SRalph Campbell unlock: 258a5210c12SRalph Campbell spin_unlock(&qp->r_lock); 259f931551bSRalph Campbell } 260f931551bSRalph Campbell 261f931551bSRalph Campbell /** 262f931551bSRalph Campbell * qib_ib_rcv - process an incoming packet 263f931551bSRalph Campbell * @rcd: the context pointer 264f931551bSRalph Campbell * @rhdr: the header of the packet 265f931551bSRalph Campbell * @data: the packet payload 266f931551bSRalph Campbell * @tlen: the packet length 267f931551bSRalph Campbell * 268f931551bSRalph Campbell * This is called from qib_kreceive() to process an incoming packet at 269f931551bSRalph Campbell * interrupt level. Tlen is the length of the header + data + CRC in bytes. 270f931551bSRalph Campbell */ 271f931551bSRalph Campbell void qib_ib_rcv(struct qib_ctxtdata *rcd, void *rhdr, void *data, u32 tlen) 272f931551bSRalph Campbell { 273f931551bSRalph Campbell struct qib_pportdata *ppd = rcd->ppd; 274f931551bSRalph Campbell struct qib_ibport *ibp = &ppd->ibport_data; 275261a4351SMike Marciniszyn struct ib_header *hdr = rhdr; 2761cefc2cdSHarish Chegondi struct qib_devdata *dd = ppd->dd; 2771cefc2cdSHarish Chegondi struct rvt_dev_info *rdi = &dd->verbs_dev.rdi; 278261a4351SMike Marciniszyn struct ib_other_headers *ohdr; 2797c2e11feSDennis Dalessandro struct rvt_qp *qp; 280f931551bSRalph Campbell u32 qp_num; 281f931551bSRalph Campbell int lnh; 282f931551bSRalph Campbell u8 opcode; 283f931551bSRalph Campbell u16 lid; 284f931551bSRalph Campbell 285f931551bSRalph Campbell /* 24 == LRH+BTH+CRC */ 286f931551bSRalph Campbell if (unlikely(tlen < 24)) 287f931551bSRalph Campbell goto drop; 288f931551bSRalph Campbell 289f931551bSRalph Campbell /* Check for a valid destination LID (see ch. 7.11.1). */ 290f931551bSRalph Campbell lid = be16_to_cpu(hdr->lrh[1]); 2919ff198f5SDennis Dalessandro if (lid < be16_to_cpu(IB_MULTICAST_LID_BASE)) { 292f931551bSRalph Campbell lid &= ~((1 << ppd->lmc) - 1); 293f931551bSRalph Campbell if (unlikely(lid != ppd->lid)) 294f931551bSRalph Campbell goto drop; 295f931551bSRalph Campbell } 296f931551bSRalph Campbell 297f931551bSRalph Campbell /* Check for GRH */ 298f931551bSRalph Campbell lnh = be16_to_cpu(hdr->lrh[0]) & 3; 299f931551bSRalph Campbell if (lnh == QIB_LRH_BTH) 300f931551bSRalph Campbell ohdr = &hdr->u.oth; 301f931551bSRalph Campbell else if (lnh == QIB_LRH_GRH) { 302f931551bSRalph Campbell u32 vtf; 303f931551bSRalph Campbell 304f931551bSRalph Campbell ohdr = &hdr->u.l.oth; 305f931551bSRalph Campbell if (hdr->u.l.grh.next_hdr != IB_GRH_NEXT_HDR) 306f931551bSRalph Campbell goto drop; 307f931551bSRalph Campbell vtf = be32_to_cpu(hdr->u.l.grh.version_tclass_flow); 308f931551bSRalph Campbell if ((vtf >> IB_GRH_VERSION_SHIFT) != IB_GRH_VERSION) 309f931551bSRalph Campbell goto drop; 310f931551bSRalph Campbell } else 311f931551bSRalph Campbell goto drop; 312f931551bSRalph Campbell 313ddb88765SMike Marciniszyn opcode = (be32_to_cpu(ohdr->bth[0]) >> 24) & 0x7f; 314ddb88765SMike Marciniszyn #ifdef CONFIG_DEBUG_FS 315ddb88765SMike Marciniszyn rcd->opstats->stats[opcode].n_bytes += tlen; 316ddb88765SMike Marciniszyn rcd->opstats->stats[opcode].n_packets++; 317ddb88765SMike Marciniszyn #endif 318f931551bSRalph Campbell 319f931551bSRalph Campbell /* Get the destination QP number. */ 32070696ea7SHarish Chegondi qp_num = be32_to_cpu(ohdr->bth[1]) & RVT_QPN_MASK; 321f931551bSRalph Campbell if (qp_num == QIB_MULTICAST_QPN) { 32218f6c582SHarish Chegondi struct rvt_mcast *mcast; 32318f6c582SHarish Chegondi struct rvt_mcast_qp *p; 324f931551bSRalph Campbell 325f931551bSRalph Campbell if (lnh != QIB_LRH_GRH) 326f931551bSRalph Campbell goto drop; 327aad9ff97SMichael J. Ruhl mcast = rvt_mcast_find(&ibp->rvp, &hdr->u.l.grh.dgid, lid); 328f931551bSRalph Campbell if (mcast == NULL) 329f931551bSRalph Campbell goto drop; 3307d7632adSMike Marciniszyn this_cpu_inc(ibp->pmastats->n_multicast_rcv); 331817a68a6SDennis Dalessandro rcu_read_lock(); 332f931551bSRalph Campbell list_for_each_entry_rcu(p, &mcast->qp_list, list) 333f931551bSRalph Campbell qib_qp_rcv(rcd, hdr, 1, data, tlen, p->qp); 334817a68a6SDennis Dalessandro rcu_read_unlock(); 335f931551bSRalph Campbell /* 33618f6c582SHarish Chegondi * Notify rvt_multicast_detach() if it is waiting for us 337f931551bSRalph Campbell * to finish. 338f931551bSRalph Campbell */ 339f931551bSRalph Campbell if (atomic_dec_return(&mcast->refcount) <= 1) 340f931551bSRalph Campbell wake_up(&mcast->wait); 341f931551bSRalph Campbell } else { 3421cefc2cdSHarish Chegondi rcu_read_lock(); 3431cefc2cdSHarish Chegondi qp = rvt_lookup_qpn(rdi, &ibp->rvp, qp_num); 3441cefc2cdSHarish Chegondi if (!qp) { 3451cefc2cdSHarish Chegondi rcu_read_unlock(); 346f931551bSRalph Campbell goto drop; 3471cefc2cdSHarish Chegondi } 3487d7632adSMike Marciniszyn this_cpu_inc(ibp->pmastats->n_unicast_rcv); 349f931551bSRalph Campbell qib_qp_rcv(rcd, hdr, lnh == QIB_LRH_GRH, data, tlen, qp); 3501cefc2cdSHarish Chegondi rcu_read_unlock(); 351f931551bSRalph Campbell } 352f931551bSRalph Campbell return; 353f931551bSRalph Campbell 354f931551bSRalph Campbell drop: 355f24a6d48SHarish Chegondi ibp->rvp.n_pkt_drops++; 356f931551bSRalph Campbell } 357f931551bSRalph Campbell 358f931551bSRalph Campbell /* 359f931551bSRalph Campbell * This is called from a timer to check for QPs 360f931551bSRalph Campbell * which need kernel memory in order to send a packet. 361f931551bSRalph Campbell */ 3624037c92fSKees Cook static void mem_timer(struct timer_list *t) 363f931551bSRalph Campbell { 3644037c92fSKees Cook struct qib_ibdev *dev = from_timer(dev, t, mem_timer); 365f931551bSRalph Campbell struct list_head *list = &dev->memwait; 3667c2e11feSDennis Dalessandro struct rvt_qp *qp = NULL; 367ffc26907SDennis Dalessandro struct qib_qp_priv *priv = NULL; 368f931551bSRalph Campbell unsigned long flags; 369f931551bSRalph Campbell 370cd18201fSHarish Chegondi spin_lock_irqsave(&dev->rdi.pending_lock, flags); 371f931551bSRalph Campbell if (!list_empty(list)) { 372ffc26907SDennis Dalessandro priv = list_entry(list->next, struct qib_qp_priv, iowait); 373ffc26907SDennis Dalessandro qp = priv->owner; 374ffc26907SDennis Dalessandro list_del_init(&priv->iowait); 375238b1862SSebastian Sanchez rvt_get_qp(qp); 376f931551bSRalph Campbell if (!list_empty(list)) 377f931551bSRalph Campbell mod_timer(&dev->mem_timer, jiffies + 1); 378f931551bSRalph Campbell } 379cd18201fSHarish Chegondi spin_unlock_irqrestore(&dev->rdi.pending_lock, flags); 380f931551bSRalph Campbell 381f931551bSRalph Campbell if (qp) { 382f931551bSRalph Campbell spin_lock_irqsave(&qp->s_lock, flags); 38301ba79d4SHarish Chegondi if (qp->s_flags & RVT_S_WAIT_KMEM) { 38401ba79d4SHarish Chegondi qp->s_flags &= ~RVT_S_WAIT_KMEM; 385f931551bSRalph Campbell qib_schedule_send(qp); 386f931551bSRalph Campbell } 387f931551bSRalph Campbell spin_unlock_irqrestore(&qp->s_lock, flags); 388238b1862SSebastian Sanchez rvt_put_qp(qp); 389f931551bSRalph Campbell } 390f931551bSRalph Campbell } 391f931551bSRalph Campbell 392f931551bSRalph Campbell #ifdef __LITTLE_ENDIAN 393f931551bSRalph Campbell static inline u32 get_upper_bits(u32 data, u32 shift) 394f931551bSRalph Campbell { 395f931551bSRalph Campbell return data >> shift; 396f931551bSRalph Campbell } 397f931551bSRalph Campbell 398f931551bSRalph Campbell static inline u32 set_upper_bits(u32 data, u32 shift) 399f931551bSRalph Campbell { 400f931551bSRalph Campbell return data << shift; 401f931551bSRalph Campbell } 402f931551bSRalph Campbell 403f931551bSRalph Campbell static inline u32 clear_upper_bytes(u32 data, u32 n, u32 off) 404f931551bSRalph Campbell { 405f931551bSRalph Campbell data <<= ((sizeof(u32) - n) * BITS_PER_BYTE); 406f931551bSRalph Campbell data >>= ((sizeof(u32) - n - off) * BITS_PER_BYTE); 407f931551bSRalph Campbell return data; 408f931551bSRalph Campbell } 409f931551bSRalph Campbell #else 410f931551bSRalph Campbell static inline u32 get_upper_bits(u32 data, u32 shift) 411f931551bSRalph Campbell { 412f931551bSRalph Campbell return data << shift; 413f931551bSRalph Campbell } 414f931551bSRalph Campbell 415f931551bSRalph Campbell static inline u32 set_upper_bits(u32 data, u32 shift) 416f931551bSRalph Campbell { 417f931551bSRalph Campbell return data >> shift; 418f931551bSRalph Campbell } 419f931551bSRalph Campbell 420f931551bSRalph Campbell static inline u32 clear_upper_bytes(u32 data, u32 n, u32 off) 421f931551bSRalph Campbell { 422f931551bSRalph Campbell data >>= ((sizeof(u32) - n) * BITS_PER_BYTE); 423f931551bSRalph Campbell data <<= ((sizeof(u32) - n - off) * BITS_PER_BYTE); 424f931551bSRalph Campbell return data; 425f931551bSRalph Campbell } 426f931551bSRalph Campbell #endif 427f931551bSRalph Campbell 4287c2e11feSDennis Dalessandro static void copy_io(u32 __iomem *piobuf, struct rvt_sge_state *ss, 429f931551bSRalph Campbell u32 length, unsigned flush_wc) 430f931551bSRalph Campbell { 431f931551bSRalph Campbell u32 extra = 0; 432f931551bSRalph Campbell u32 data = 0; 433f931551bSRalph Campbell u32 last; 434f931551bSRalph Campbell 435f931551bSRalph Campbell while (1) { 43687fc34b5SMichael J. Ruhl u32 len = rvt_get_sge_length(&ss->sge, length); 437f931551bSRalph Campbell u32 off; 438f931551bSRalph Campbell 439f931551bSRalph Campbell /* If the source address is not aligned, try to align it. */ 440f931551bSRalph Campbell off = (unsigned long)ss->sge.vaddr & (sizeof(u32) - 1); 441f931551bSRalph Campbell if (off) { 442f931551bSRalph Campbell u32 *addr = (u32 *)((unsigned long)ss->sge.vaddr & 443f931551bSRalph Campbell ~(sizeof(u32) - 1)); 444f931551bSRalph Campbell u32 v = get_upper_bits(*addr, off * BITS_PER_BYTE); 445f931551bSRalph Campbell u32 y; 446f931551bSRalph Campbell 447f931551bSRalph Campbell y = sizeof(u32) - off; 448f931551bSRalph Campbell if (len > y) 449f931551bSRalph Campbell len = y; 450f931551bSRalph Campbell if (len + extra >= sizeof(u32)) { 451f931551bSRalph Campbell data |= set_upper_bits(v, extra * 452f931551bSRalph Campbell BITS_PER_BYTE); 453f931551bSRalph Campbell len = sizeof(u32) - extra; 454f931551bSRalph Campbell if (len == length) { 455f931551bSRalph Campbell last = data; 456f931551bSRalph Campbell break; 457f931551bSRalph Campbell } 458f931551bSRalph Campbell __raw_writel(data, piobuf); 459f931551bSRalph Campbell piobuf++; 460f931551bSRalph Campbell extra = 0; 461f931551bSRalph Campbell data = 0; 462f931551bSRalph Campbell } else { 463f931551bSRalph Campbell /* Clear unused upper bytes */ 464f931551bSRalph Campbell data |= clear_upper_bytes(v, len, extra); 465f931551bSRalph Campbell if (len == length) { 466f931551bSRalph Campbell last = data; 467f931551bSRalph Campbell break; 468f931551bSRalph Campbell } 469f931551bSRalph Campbell extra += len; 470f931551bSRalph Campbell } 471f931551bSRalph Campbell } else if (extra) { 472f931551bSRalph Campbell /* Source address is aligned. */ 473f931551bSRalph Campbell u32 *addr = (u32 *) ss->sge.vaddr; 474f931551bSRalph Campbell int shift = extra * BITS_PER_BYTE; 475f931551bSRalph Campbell int ushift = 32 - shift; 476f931551bSRalph Campbell u32 l = len; 477f931551bSRalph Campbell 478f931551bSRalph Campbell while (l >= sizeof(u32)) { 479f931551bSRalph Campbell u32 v = *addr; 480f931551bSRalph Campbell 481f931551bSRalph Campbell data |= set_upper_bits(v, shift); 482f931551bSRalph Campbell __raw_writel(data, piobuf); 483f931551bSRalph Campbell data = get_upper_bits(v, ushift); 484f931551bSRalph Campbell piobuf++; 485f931551bSRalph Campbell addr++; 486f931551bSRalph Campbell l -= sizeof(u32); 487f931551bSRalph Campbell } 488f931551bSRalph Campbell /* 489f931551bSRalph Campbell * We still have 'extra' number of bytes leftover. 490f931551bSRalph Campbell */ 491f931551bSRalph Campbell if (l) { 492f931551bSRalph Campbell u32 v = *addr; 493f931551bSRalph Campbell 494f931551bSRalph Campbell if (l + extra >= sizeof(u32)) { 495f931551bSRalph Campbell data |= set_upper_bits(v, shift); 496f931551bSRalph Campbell len -= l + extra - sizeof(u32); 497f931551bSRalph Campbell if (len == length) { 498f931551bSRalph Campbell last = data; 499f931551bSRalph Campbell break; 500f931551bSRalph Campbell } 501f931551bSRalph Campbell __raw_writel(data, piobuf); 502f931551bSRalph Campbell piobuf++; 503f931551bSRalph Campbell extra = 0; 504f931551bSRalph Campbell data = 0; 505f931551bSRalph Campbell } else { 506f931551bSRalph Campbell /* Clear unused upper bytes */ 507f931551bSRalph Campbell data |= clear_upper_bytes(v, l, extra); 508f931551bSRalph Campbell if (len == length) { 509f931551bSRalph Campbell last = data; 510f931551bSRalph Campbell break; 511f931551bSRalph Campbell } 512f931551bSRalph Campbell extra += l; 513f931551bSRalph Campbell } 514f931551bSRalph Campbell } else if (len == length) { 515f931551bSRalph Campbell last = data; 516f931551bSRalph Campbell break; 517f931551bSRalph Campbell } 518f931551bSRalph Campbell } else if (len == length) { 519f931551bSRalph Campbell u32 w; 520f931551bSRalph Campbell 521f931551bSRalph Campbell /* 522f931551bSRalph Campbell * Need to round up for the last dword in the 523f931551bSRalph Campbell * packet. 524f931551bSRalph Campbell */ 525f931551bSRalph Campbell w = (len + 3) >> 2; 526f931551bSRalph Campbell qib_pio_copy(piobuf, ss->sge.vaddr, w - 1); 527f931551bSRalph Campbell piobuf += w - 1; 528f931551bSRalph Campbell last = ((u32 *) ss->sge.vaddr)[w - 1]; 529f931551bSRalph Campbell break; 530f931551bSRalph Campbell } else { 531f931551bSRalph Campbell u32 w = len >> 2; 532f931551bSRalph Campbell 533f931551bSRalph Campbell qib_pio_copy(piobuf, ss->sge.vaddr, w); 534f931551bSRalph Campbell piobuf += w; 535f931551bSRalph Campbell 536f931551bSRalph Campbell extra = len & (sizeof(u32) - 1); 537f931551bSRalph Campbell if (extra) { 538f931551bSRalph Campbell u32 v = ((u32 *) ss->sge.vaddr)[w]; 539f931551bSRalph Campbell 540f931551bSRalph Campbell /* Clear unused upper bytes */ 541f931551bSRalph Campbell data = clear_upper_bytes(v, extra, 0); 542f931551bSRalph Campbell } 543f931551bSRalph Campbell } 5443fc4a090SBrian Welty rvt_update_sge(ss, len, false); 545f931551bSRalph Campbell length -= len; 546f931551bSRalph Campbell } 547f931551bSRalph Campbell /* Update address before sending packet. */ 5483fc4a090SBrian Welty rvt_update_sge(ss, length, false); 549f931551bSRalph Campbell if (flush_wc) { 550f931551bSRalph Campbell /* must flush early everything before trigger word */ 551f931551bSRalph Campbell qib_flush_wc(); 552f931551bSRalph Campbell __raw_writel(last, piobuf); 553f931551bSRalph Campbell /* be sure trigger word is written */ 554f931551bSRalph Campbell qib_flush_wc(); 555f931551bSRalph Campbell } else 556f931551bSRalph Campbell __raw_writel(last, piobuf); 557f931551bSRalph Campbell } 558f931551bSRalph Campbell 55948947109SMike Marciniszyn static noinline struct qib_verbs_txreq *__get_txreq(struct qib_ibdev *dev, 5607c2e11feSDennis Dalessandro struct rvt_qp *qp) 561f931551bSRalph Campbell { 562ffc26907SDennis Dalessandro struct qib_qp_priv *priv = qp->priv; 563f931551bSRalph Campbell struct qib_verbs_txreq *tx; 564f931551bSRalph Campbell unsigned long flags; 565f931551bSRalph Campbell 566f931551bSRalph Campbell spin_lock_irqsave(&qp->s_lock, flags); 567cd18201fSHarish Chegondi spin_lock(&dev->rdi.pending_lock); 568f931551bSRalph Campbell 569f931551bSRalph Campbell if (!list_empty(&dev->txreq_free)) { 570f931551bSRalph Campbell struct list_head *l = dev->txreq_free.next; 571f931551bSRalph Campbell 572f931551bSRalph Campbell list_del(l); 573cd18201fSHarish Chegondi spin_unlock(&dev->rdi.pending_lock); 57448947109SMike Marciniszyn spin_unlock_irqrestore(&qp->s_lock, flags); 575f931551bSRalph Campbell tx = list_entry(l, struct qib_verbs_txreq, txreq.list); 576f931551bSRalph Campbell } else { 577db3ef0ebSHarish Chegondi if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK && 578ffc26907SDennis Dalessandro list_empty(&priv->iowait)) { 579f931551bSRalph Campbell dev->n_txwait++; 58001ba79d4SHarish Chegondi qp->s_flags |= RVT_S_WAIT_TX; 581ffc26907SDennis Dalessandro list_add_tail(&priv->iowait, &dev->txwait); 582f931551bSRalph Campbell } 58301ba79d4SHarish Chegondi qp->s_flags &= ~RVT_S_BUSY; 584cd18201fSHarish Chegondi spin_unlock(&dev->rdi.pending_lock); 585f931551bSRalph Campbell spin_unlock_irqrestore(&qp->s_lock, flags); 58648947109SMike Marciniszyn tx = ERR_PTR(-EBUSY); 58748947109SMike Marciniszyn } 58848947109SMike Marciniszyn return tx; 58948947109SMike Marciniszyn } 590f931551bSRalph Campbell 59148947109SMike Marciniszyn static inline struct qib_verbs_txreq *get_txreq(struct qib_ibdev *dev, 5927c2e11feSDennis Dalessandro struct rvt_qp *qp) 59348947109SMike Marciniszyn { 59448947109SMike Marciniszyn struct qib_verbs_txreq *tx; 59548947109SMike Marciniszyn unsigned long flags; 59648947109SMike Marciniszyn 597cd18201fSHarish Chegondi spin_lock_irqsave(&dev->rdi.pending_lock, flags); 59848947109SMike Marciniszyn /* assume the list non empty */ 59948947109SMike Marciniszyn if (likely(!list_empty(&dev->txreq_free))) { 60048947109SMike Marciniszyn struct list_head *l = dev->txreq_free.next; 60148947109SMike Marciniszyn 60248947109SMike Marciniszyn list_del(l); 603cd18201fSHarish Chegondi spin_unlock_irqrestore(&dev->rdi.pending_lock, flags); 60448947109SMike Marciniszyn tx = list_entry(l, struct qib_verbs_txreq, txreq.list); 60548947109SMike Marciniszyn } else { 60648947109SMike Marciniszyn /* call slow path to get the extra lock */ 607cd18201fSHarish Chegondi spin_unlock_irqrestore(&dev->rdi.pending_lock, flags); 60848947109SMike Marciniszyn tx = __get_txreq(dev, qp); 60948947109SMike Marciniszyn } 610f931551bSRalph Campbell return tx; 611f931551bSRalph Campbell } 612f931551bSRalph Campbell 613f931551bSRalph Campbell void qib_put_txreq(struct qib_verbs_txreq *tx) 614f931551bSRalph Campbell { 615f931551bSRalph Campbell struct qib_ibdev *dev; 6167c2e11feSDennis Dalessandro struct rvt_qp *qp; 617ffc26907SDennis Dalessandro struct qib_qp_priv *priv; 618f931551bSRalph Campbell unsigned long flags; 619f931551bSRalph Campbell 620f931551bSRalph Campbell qp = tx->qp; 621f931551bSRalph Campbell dev = to_idev(qp->ibqp.device); 622f931551bSRalph Campbell 623f931551bSRalph Campbell if (tx->mr) { 6247c2e11feSDennis Dalessandro rvt_put_mr(tx->mr); 625f931551bSRalph Campbell tx->mr = NULL; 626f931551bSRalph Campbell } 627f931551bSRalph Campbell if (tx->txreq.flags & QIB_SDMA_TXREQ_F_FREEBUF) { 628f931551bSRalph Campbell tx->txreq.flags &= ~QIB_SDMA_TXREQ_F_FREEBUF; 629f931551bSRalph Campbell dma_unmap_single(&dd_from_dev(dev)->pcidev->dev, 630f931551bSRalph Campbell tx->txreq.addr, tx->hdr_dwords << 2, 631f931551bSRalph Campbell DMA_TO_DEVICE); 632f931551bSRalph Campbell kfree(tx->align_buf); 633f931551bSRalph Campbell } 634f931551bSRalph Campbell 635cd18201fSHarish Chegondi spin_lock_irqsave(&dev->rdi.pending_lock, flags); 636f931551bSRalph Campbell 637f931551bSRalph Campbell /* Put struct back on free list */ 638f931551bSRalph Campbell list_add(&tx->txreq.list, &dev->txreq_free); 639f931551bSRalph Campbell 640f931551bSRalph Campbell if (!list_empty(&dev->txwait)) { 641f931551bSRalph Campbell /* Wake up first QP wanting a free struct */ 642ffc26907SDennis Dalessandro priv = list_entry(dev->txwait.next, struct qib_qp_priv, 643ffc26907SDennis Dalessandro iowait); 644ffc26907SDennis Dalessandro qp = priv->owner; 645ffc26907SDennis Dalessandro list_del_init(&priv->iowait); 646238b1862SSebastian Sanchez rvt_get_qp(qp); 647cd18201fSHarish Chegondi spin_unlock_irqrestore(&dev->rdi.pending_lock, flags); 648f931551bSRalph Campbell 649f931551bSRalph Campbell spin_lock_irqsave(&qp->s_lock, flags); 65001ba79d4SHarish Chegondi if (qp->s_flags & RVT_S_WAIT_TX) { 65101ba79d4SHarish Chegondi qp->s_flags &= ~RVT_S_WAIT_TX; 652f931551bSRalph Campbell qib_schedule_send(qp); 653f931551bSRalph Campbell } 654f931551bSRalph Campbell spin_unlock_irqrestore(&qp->s_lock, flags); 655f931551bSRalph Campbell 656238b1862SSebastian Sanchez rvt_put_qp(qp); 657f931551bSRalph Campbell } else 658cd18201fSHarish Chegondi spin_unlock_irqrestore(&dev->rdi.pending_lock, flags); 659f931551bSRalph Campbell } 660f931551bSRalph Campbell 661f931551bSRalph Campbell /* 662f931551bSRalph Campbell * This is called when there are send DMA descriptors that might be 663f931551bSRalph Campbell * available. 664f931551bSRalph Campbell * 665f931551bSRalph Campbell * This is called with ppd->sdma_lock held. 666f931551bSRalph Campbell */ 667f931551bSRalph Campbell void qib_verbs_sdma_desc_avail(struct qib_pportdata *ppd, unsigned avail) 668f931551bSRalph Campbell { 6692055d1f0SBart Van Assche struct rvt_qp *qp; 670ffc26907SDennis Dalessandro struct qib_qp_priv *qpp, *nqpp; 6717c2e11feSDennis Dalessandro struct rvt_qp *qps[20]; 672f931551bSRalph Campbell struct qib_ibdev *dev; 673f931551bSRalph Campbell unsigned i, n; 674f931551bSRalph Campbell 675f931551bSRalph Campbell n = 0; 676f931551bSRalph Campbell dev = &ppd->dd->verbs_dev; 677cd18201fSHarish Chegondi spin_lock(&dev->rdi.pending_lock); 678f931551bSRalph Campbell 679f931551bSRalph Campbell /* Search wait list for first QP wanting DMA descriptors. */ 680ffc26907SDennis Dalessandro list_for_each_entry_safe(qpp, nqpp, &dev->dmawait, iowait) { 681ffc26907SDennis Dalessandro qp = qpp->owner; 682f931551bSRalph Campbell if (qp->port_num != ppd->port) 683f931551bSRalph Campbell continue; 684f931551bSRalph Campbell if (n == ARRAY_SIZE(qps)) 685f931551bSRalph Campbell break; 686ffc26907SDennis Dalessandro if (qpp->s_tx->txreq.sg_count > avail) 687f931551bSRalph Campbell break; 688ffc26907SDennis Dalessandro avail -= qpp->s_tx->txreq.sg_count; 689ffc26907SDennis Dalessandro list_del_init(&qpp->iowait); 690238b1862SSebastian Sanchez rvt_get_qp(qp); 691f931551bSRalph Campbell qps[n++] = qp; 692f931551bSRalph Campbell } 693f931551bSRalph Campbell 694cd18201fSHarish Chegondi spin_unlock(&dev->rdi.pending_lock); 695f931551bSRalph Campbell 696f931551bSRalph Campbell for (i = 0; i < n; i++) { 697f931551bSRalph Campbell qp = qps[i]; 698f931551bSRalph Campbell spin_lock(&qp->s_lock); 69901ba79d4SHarish Chegondi if (qp->s_flags & RVT_S_WAIT_DMA_DESC) { 70001ba79d4SHarish Chegondi qp->s_flags &= ~RVT_S_WAIT_DMA_DESC; 701f931551bSRalph Campbell qib_schedule_send(qp); 702f931551bSRalph Campbell } 703f931551bSRalph Campbell spin_unlock(&qp->s_lock); 704238b1862SSebastian Sanchez rvt_put_qp(qp); 705f931551bSRalph Campbell } 706f931551bSRalph Campbell } 707f931551bSRalph Campbell 708f931551bSRalph Campbell /* 709f931551bSRalph Campbell * This is called with ppd->sdma_lock held. 710f931551bSRalph Campbell */ 711f931551bSRalph Campbell static void sdma_complete(struct qib_sdma_txreq *cookie, int status) 712f931551bSRalph Campbell { 713f931551bSRalph Campbell struct qib_verbs_txreq *tx = 714f931551bSRalph Campbell container_of(cookie, struct qib_verbs_txreq, txreq); 7157c2e11feSDennis Dalessandro struct rvt_qp *qp = tx->qp; 716ffc26907SDennis Dalessandro struct qib_qp_priv *priv = qp->priv; 717f931551bSRalph Campbell 718f931551bSRalph Campbell spin_lock(&qp->s_lock); 719f931551bSRalph Campbell if (tx->wqe) 720116aa033SVenkata Sandeep Dhanalakota rvt_send_complete(qp, tx->wqe, IB_WC_SUCCESS); 721f931551bSRalph Campbell else if (qp->ibqp.qp_type == IB_QPT_RC) { 722261a4351SMike Marciniszyn struct ib_header *hdr; 723f931551bSRalph Campbell 724f931551bSRalph Campbell if (tx->txreq.flags & QIB_SDMA_TXREQ_F_FREEBUF) 725f931551bSRalph Campbell hdr = &tx->align_buf->hdr; 726f931551bSRalph Campbell else { 727f931551bSRalph Campbell struct qib_ibdev *dev = to_idev(qp->ibqp.device); 728f931551bSRalph Campbell 729f931551bSRalph Campbell hdr = &dev->pio_hdrs[tx->hdr_inx].hdr; 730f931551bSRalph Campbell } 731f931551bSRalph Campbell qib_rc_send_complete(qp, hdr); 732f931551bSRalph Campbell } 733ffc26907SDennis Dalessandro if (atomic_dec_and_test(&priv->s_dma_busy)) { 734f931551bSRalph Campbell if (qp->state == IB_QPS_RESET) 735ffc26907SDennis Dalessandro wake_up(&priv->wait_dma); 73601ba79d4SHarish Chegondi else if (qp->s_flags & RVT_S_WAIT_DMA) { 73701ba79d4SHarish Chegondi qp->s_flags &= ~RVT_S_WAIT_DMA; 738f931551bSRalph Campbell qib_schedule_send(qp); 739f931551bSRalph Campbell } 740f931551bSRalph Campbell } 741f931551bSRalph Campbell spin_unlock(&qp->s_lock); 742f931551bSRalph Campbell 743f931551bSRalph Campbell qib_put_txreq(tx); 744f931551bSRalph Campbell } 745f931551bSRalph Campbell 7467c2e11feSDennis Dalessandro static int wait_kmem(struct qib_ibdev *dev, struct rvt_qp *qp) 747f931551bSRalph Campbell { 748ffc26907SDennis Dalessandro struct qib_qp_priv *priv = qp->priv; 749f931551bSRalph Campbell unsigned long flags; 750f931551bSRalph Campbell int ret = 0; 751f931551bSRalph Campbell 752f931551bSRalph Campbell spin_lock_irqsave(&qp->s_lock, flags); 753db3ef0ebSHarish Chegondi if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) { 754cd18201fSHarish Chegondi spin_lock(&dev->rdi.pending_lock); 755ffc26907SDennis Dalessandro if (list_empty(&priv->iowait)) { 756f931551bSRalph Campbell if (list_empty(&dev->memwait)) 757f931551bSRalph Campbell mod_timer(&dev->mem_timer, jiffies + 1); 75801ba79d4SHarish Chegondi qp->s_flags |= RVT_S_WAIT_KMEM; 759ffc26907SDennis Dalessandro list_add_tail(&priv->iowait, &dev->memwait); 760f931551bSRalph Campbell } 761cd18201fSHarish Chegondi spin_unlock(&dev->rdi.pending_lock); 76201ba79d4SHarish Chegondi qp->s_flags &= ~RVT_S_BUSY; 763f931551bSRalph Campbell ret = -EBUSY; 764f931551bSRalph Campbell } 765f931551bSRalph Campbell spin_unlock_irqrestore(&qp->s_lock, flags); 766f931551bSRalph Campbell 767f931551bSRalph Campbell return ret; 768f931551bSRalph Campbell } 769f931551bSRalph Campbell 770261a4351SMike Marciniszyn static int qib_verbs_send_dma(struct rvt_qp *qp, struct ib_header *hdr, 7717c2e11feSDennis Dalessandro u32 hdrwords, struct rvt_sge_state *ss, u32 len, 772f931551bSRalph Campbell u32 plen, u32 dwords) 773f931551bSRalph Campbell { 774ffc26907SDennis Dalessandro struct qib_qp_priv *priv = qp->priv; 775f931551bSRalph Campbell struct qib_ibdev *dev = to_idev(qp->ibqp.device); 776f931551bSRalph Campbell struct qib_devdata *dd = dd_from_dev(dev); 777f931551bSRalph Campbell struct qib_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num); 778f931551bSRalph Campbell struct qib_pportdata *ppd = ppd_from_ibp(ibp); 779f931551bSRalph Campbell struct qib_verbs_txreq *tx; 780f931551bSRalph Campbell struct qib_pio_header *phdr; 781f931551bSRalph Campbell u32 control; 782f931551bSRalph Campbell u32 ndesc; 783f931551bSRalph Campbell int ret; 784f931551bSRalph Campbell 785ffc26907SDennis Dalessandro tx = priv->s_tx; 786f931551bSRalph Campbell if (tx) { 787ffc26907SDennis Dalessandro priv->s_tx = NULL; 788f931551bSRalph Campbell /* resend previously constructed packet */ 789f931551bSRalph Campbell ret = qib_sdma_verbs_send(ppd, tx->ss, tx->dwords, tx); 790f931551bSRalph Campbell goto bail; 791f931551bSRalph Campbell } 792f931551bSRalph Campbell 79348947109SMike Marciniszyn tx = get_txreq(dev, qp); 79448947109SMike Marciniszyn if (IS_ERR(tx)) 79548947109SMike Marciniszyn goto bail_tx; 796f931551bSRalph Campbell 797f931551bSRalph Campbell control = dd->f_setpbc_control(ppd, plen, qp->s_srate, 798f931551bSRalph Campbell be16_to_cpu(hdr->lrh[0]) >> 12); 799f931551bSRalph Campbell tx->qp = qp; 800f931551bSRalph Campbell tx->wqe = qp->s_wqe; 801f931551bSRalph Campbell tx->mr = qp->s_rdma_mr; 802f931551bSRalph Campbell if (qp->s_rdma_mr) 803f931551bSRalph Campbell qp->s_rdma_mr = NULL; 804f931551bSRalph Campbell tx->txreq.callback = sdma_complete; 805f931551bSRalph Campbell if (dd->flags & QIB_HAS_SDMA_TIMEOUT) 806f931551bSRalph Campbell tx->txreq.flags = QIB_SDMA_TXREQ_F_HEADTOHOST; 807f931551bSRalph Campbell else 808f931551bSRalph Campbell tx->txreq.flags = QIB_SDMA_TXREQ_F_INTREQ; 809f931551bSRalph Campbell if (plen + 1 > dd->piosize2kmax_dwords) 810f931551bSRalph Campbell tx->txreq.flags |= QIB_SDMA_TXREQ_F_USELARGEBUF; 811f931551bSRalph Campbell 812f931551bSRalph Campbell if (len) { 813f931551bSRalph Campbell /* 814f931551bSRalph Campbell * Don't try to DMA if it takes more descriptors than 815f931551bSRalph Campbell * the queue holds. 816f931551bSRalph Campbell */ 817f931551bSRalph Campbell ndesc = qib_count_sge(ss, len); 818f931551bSRalph Campbell if (ndesc >= ppd->sdma_descq_cnt) 819f931551bSRalph Campbell ndesc = 0; 820f931551bSRalph Campbell } else 821f931551bSRalph Campbell ndesc = 1; 822f931551bSRalph Campbell if (ndesc) { 823f931551bSRalph Campbell phdr = &dev->pio_hdrs[tx->hdr_inx]; 824f931551bSRalph Campbell phdr->pbc[0] = cpu_to_le32(plen); 825f931551bSRalph Campbell phdr->pbc[1] = cpu_to_le32(control); 826f931551bSRalph Campbell memcpy(&phdr->hdr, hdr, hdrwords << 2); 827f931551bSRalph Campbell tx->txreq.flags |= QIB_SDMA_TXREQ_F_FREEDESC; 828f931551bSRalph Campbell tx->txreq.sg_count = ndesc; 829f931551bSRalph Campbell tx->txreq.addr = dev->pio_hdrs_phys + 830f931551bSRalph Campbell tx->hdr_inx * sizeof(struct qib_pio_header); 831f931551bSRalph Campbell tx->hdr_dwords = hdrwords + 2; /* add PBC length */ 832f931551bSRalph Campbell ret = qib_sdma_verbs_send(ppd, ss, dwords, tx); 833f931551bSRalph Campbell goto bail; 834f931551bSRalph Campbell } 835f931551bSRalph Campbell 836f931551bSRalph Campbell /* Allocate a buffer and copy the header and payload to it. */ 837f931551bSRalph Campbell tx->hdr_dwords = plen + 1; 838f931551bSRalph Campbell phdr = kmalloc(tx->hdr_dwords << 2, GFP_ATOMIC); 839f931551bSRalph Campbell if (!phdr) 840f931551bSRalph Campbell goto err_tx; 841f931551bSRalph Campbell phdr->pbc[0] = cpu_to_le32(plen); 842f931551bSRalph Campbell phdr->pbc[1] = cpu_to_le32(control); 843f931551bSRalph Campbell memcpy(&phdr->hdr, hdr, hdrwords << 2); 844f931551bSRalph Campbell qib_copy_from_sge((u32 *) &phdr->hdr + hdrwords, ss, len); 845f931551bSRalph Campbell 846f931551bSRalph Campbell tx->txreq.addr = dma_map_single(&dd->pcidev->dev, phdr, 847f931551bSRalph Campbell tx->hdr_dwords << 2, DMA_TO_DEVICE); 848f931551bSRalph Campbell if (dma_mapping_error(&dd->pcidev->dev, tx->txreq.addr)) 849f931551bSRalph Campbell goto map_err; 850f931551bSRalph Campbell tx->align_buf = phdr; 851f931551bSRalph Campbell tx->txreq.flags |= QIB_SDMA_TXREQ_F_FREEBUF; 852f931551bSRalph Campbell tx->txreq.sg_count = 1; 853f931551bSRalph Campbell ret = qib_sdma_verbs_send(ppd, NULL, 0, tx); 854f931551bSRalph Campbell goto unaligned; 855f931551bSRalph Campbell 856f931551bSRalph Campbell map_err: 857f931551bSRalph Campbell kfree(phdr); 858f931551bSRalph Campbell err_tx: 859f931551bSRalph Campbell qib_put_txreq(tx); 860f931551bSRalph Campbell ret = wait_kmem(dev, qp); 861f931551bSRalph Campbell unaligned: 862f24a6d48SHarish Chegondi ibp->rvp.n_unaligned++; 863f931551bSRalph Campbell bail: 864f931551bSRalph Campbell return ret; 86548947109SMike Marciniszyn bail_tx: 86648947109SMike Marciniszyn ret = PTR_ERR(tx); 86748947109SMike Marciniszyn goto bail; 868f931551bSRalph Campbell } 869f931551bSRalph Campbell 870f931551bSRalph Campbell /* 871f931551bSRalph Campbell * If we are now in the error state, return zero to flush the 872f931551bSRalph Campbell * send work request. 873f931551bSRalph Campbell */ 8747c2e11feSDennis Dalessandro static int no_bufs_available(struct rvt_qp *qp) 875f931551bSRalph Campbell { 876ffc26907SDennis Dalessandro struct qib_qp_priv *priv = qp->priv; 877f931551bSRalph Campbell struct qib_ibdev *dev = to_idev(qp->ibqp.device); 878f931551bSRalph Campbell struct qib_devdata *dd; 879f931551bSRalph Campbell unsigned long flags; 880f931551bSRalph Campbell int ret = 0; 881f931551bSRalph Campbell 882f931551bSRalph Campbell /* 883f931551bSRalph Campbell * Note that as soon as want_buffer() is called and 884f931551bSRalph Campbell * possibly before it returns, qib_ib_piobufavail() 885f931551bSRalph Campbell * could be called. Therefore, put QP on the I/O wait list before 886f931551bSRalph Campbell * enabling the PIO avail interrupt. 887f931551bSRalph Campbell */ 888f931551bSRalph Campbell spin_lock_irqsave(&qp->s_lock, flags); 889db3ef0ebSHarish Chegondi if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) { 890cd18201fSHarish Chegondi spin_lock(&dev->rdi.pending_lock); 891ffc26907SDennis Dalessandro if (list_empty(&priv->iowait)) { 892f931551bSRalph Campbell dev->n_piowait++; 89301ba79d4SHarish Chegondi qp->s_flags |= RVT_S_WAIT_PIO; 894ffc26907SDennis Dalessandro list_add_tail(&priv->iowait, &dev->piowait); 895f931551bSRalph Campbell dd = dd_from_dev(dev); 896f931551bSRalph Campbell dd->f_wantpiobuf_intr(dd, 1); 897f931551bSRalph Campbell } 898cd18201fSHarish Chegondi spin_unlock(&dev->rdi.pending_lock); 89901ba79d4SHarish Chegondi qp->s_flags &= ~RVT_S_BUSY; 900f931551bSRalph Campbell ret = -EBUSY; 901f931551bSRalph Campbell } 902f931551bSRalph Campbell spin_unlock_irqrestore(&qp->s_lock, flags); 903f931551bSRalph Campbell return ret; 904f931551bSRalph Campbell } 905f931551bSRalph Campbell 906261a4351SMike Marciniszyn static int qib_verbs_send_pio(struct rvt_qp *qp, struct ib_header *ibhdr, 9077c2e11feSDennis Dalessandro u32 hdrwords, struct rvt_sge_state *ss, u32 len, 908f931551bSRalph Campbell u32 plen, u32 dwords) 909f931551bSRalph Campbell { 910f931551bSRalph Campbell struct qib_devdata *dd = dd_from_ibdev(qp->ibqp.device); 911f931551bSRalph Campbell struct qib_pportdata *ppd = dd->pport + qp->port_num - 1; 912f931551bSRalph Campbell u32 *hdr = (u32 *) ibhdr; 913f931551bSRalph Campbell u32 __iomem *piobuf_orig; 914f931551bSRalph Campbell u32 __iomem *piobuf; 915f931551bSRalph Campbell u64 pbc; 916f931551bSRalph Campbell unsigned long flags; 917f931551bSRalph Campbell unsigned flush_wc; 918f931551bSRalph Campbell u32 control; 919f931551bSRalph Campbell u32 pbufn; 920f931551bSRalph Campbell 921f931551bSRalph Campbell control = dd->f_setpbc_control(ppd, plen, qp->s_srate, 922f931551bSRalph Campbell be16_to_cpu(ibhdr->lrh[0]) >> 12); 923f931551bSRalph Campbell pbc = ((u64) control << 32) | plen; 924f931551bSRalph Campbell piobuf = dd->f_getsendbuf(ppd, pbc, &pbufn); 925f931551bSRalph Campbell if (unlikely(piobuf == NULL)) 926f931551bSRalph Campbell return no_bufs_available(qp); 927f931551bSRalph Campbell 928f931551bSRalph Campbell /* 929f931551bSRalph Campbell * Write the pbc. 930f931551bSRalph Campbell * We have to flush after the PBC for correctness on some cpus 931f931551bSRalph Campbell * or WC buffer can be written out of order. 932f931551bSRalph Campbell */ 933f931551bSRalph Campbell writeq(pbc, piobuf); 934f931551bSRalph Campbell piobuf_orig = piobuf; 935f931551bSRalph Campbell piobuf += 2; 936f931551bSRalph Campbell 937f931551bSRalph Campbell flush_wc = dd->flags & QIB_PIO_FLUSH_WC; 938f931551bSRalph Campbell if (len == 0) { 939f931551bSRalph Campbell /* 940f931551bSRalph Campbell * If there is just the header portion, must flush before 941f931551bSRalph Campbell * writing last word of header for correctness, and after 942f931551bSRalph Campbell * the last header word (trigger word). 943f931551bSRalph Campbell */ 944f931551bSRalph Campbell if (flush_wc) { 945f931551bSRalph Campbell qib_flush_wc(); 946f931551bSRalph Campbell qib_pio_copy(piobuf, hdr, hdrwords - 1); 947f931551bSRalph Campbell qib_flush_wc(); 948f931551bSRalph Campbell __raw_writel(hdr[hdrwords - 1], piobuf + hdrwords - 1); 949f931551bSRalph Campbell qib_flush_wc(); 950f931551bSRalph Campbell } else 951f931551bSRalph Campbell qib_pio_copy(piobuf, hdr, hdrwords); 952f931551bSRalph Campbell goto done; 953f931551bSRalph Campbell } 954f931551bSRalph Campbell 955f931551bSRalph Campbell if (flush_wc) 956f931551bSRalph Campbell qib_flush_wc(); 957f931551bSRalph Campbell qib_pio_copy(piobuf, hdr, hdrwords); 958f931551bSRalph Campbell piobuf += hdrwords; 959f931551bSRalph Campbell 960f931551bSRalph Campbell /* The common case is aligned and contained in one segment. */ 961f931551bSRalph Campbell if (likely(ss->num_sge == 1 && len <= ss->sge.length && 962f931551bSRalph Campbell !((unsigned long)ss->sge.vaddr & (sizeof(u32) - 1)))) { 963f931551bSRalph Campbell u32 *addr = (u32 *) ss->sge.vaddr; 964f931551bSRalph Campbell 965f931551bSRalph Campbell /* Update address before sending packet. */ 9663fc4a090SBrian Welty rvt_update_sge(ss, len, false); 967f931551bSRalph Campbell if (flush_wc) { 968f931551bSRalph Campbell qib_pio_copy(piobuf, addr, dwords - 1); 969f931551bSRalph Campbell /* must flush early everything before trigger word */ 970f931551bSRalph Campbell qib_flush_wc(); 971f931551bSRalph Campbell __raw_writel(addr[dwords - 1], piobuf + dwords - 1); 972f931551bSRalph Campbell /* be sure trigger word is written */ 973f931551bSRalph Campbell qib_flush_wc(); 974f931551bSRalph Campbell } else 975f931551bSRalph Campbell qib_pio_copy(piobuf, addr, dwords); 976f931551bSRalph Campbell goto done; 977f931551bSRalph Campbell } 978f931551bSRalph Campbell copy_io(piobuf, ss, len, flush_wc); 979f931551bSRalph Campbell done: 980f931551bSRalph Campbell if (dd->flags & QIB_USE_SPCL_TRIG) { 981f931551bSRalph Campbell u32 spcl_off = (pbufn >= dd->piobcnt2k) ? 2047 : 1023; 982da12c1f6SMike Marciniszyn 983f931551bSRalph Campbell qib_flush_wc(); 984f931551bSRalph Campbell __raw_writel(0xaebecede, piobuf_orig + spcl_off); 985f931551bSRalph Campbell } 986f931551bSRalph Campbell qib_sendbuf_done(dd, pbufn); 987f931551bSRalph Campbell if (qp->s_rdma_mr) { 9887c2e11feSDennis Dalessandro rvt_put_mr(qp->s_rdma_mr); 989f931551bSRalph Campbell qp->s_rdma_mr = NULL; 990f931551bSRalph Campbell } 991f931551bSRalph Campbell if (qp->s_wqe) { 992f931551bSRalph Campbell spin_lock_irqsave(&qp->s_lock, flags); 993116aa033SVenkata Sandeep Dhanalakota rvt_send_complete(qp, qp->s_wqe, IB_WC_SUCCESS); 994f931551bSRalph Campbell spin_unlock_irqrestore(&qp->s_lock, flags); 995f931551bSRalph Campbell } else if (qp->ibqp.qp_type == IB_QPT_RC) { 996f931551bSRalph Campbell spin_lock_irqsave(&qp->s_lock, flags); 997f931551bSRalph Campbell qib_rc_send_complete(qp, ibhdr); 998f931551bSRalph Campbell spin_unlock_irqrestore(&qp->s_lock, flags); 999f931551bSRalph Campbell } 1000f931551bSRalph Campbell return 0; 1001f931551bSRalph Campbell } 1002f931551bSRalph Campbell 1003f931551bSRalph Campbell /** 1004f931551bSRalph Campbell * qib_verbs_send - send a packet 1005f931551bSRalph Campbell * @qp: the QP to send on 1006f931551bSRalph Campbell * @hdr: the packet header 1007f931551bSRalph Campbell * @hdrwords: the number of 32-bit words in the header 1008f931551bSRalph Campbell * @ss: the SGE to send 1009f931551bSRalph Campbell * @len: the length of the packet in bytes 1010f931551bSRalph Campbell * 1011f931551bSRalph Campbell * Return zero if packet is sent or queued OK. 101201ba79d4SHarish Chegondi * Return non-zero and clear qp->s_flags RVT_S_BUSY otherwise. 1013f931551bSRalph Campbell */ 1014261a4351SMike Marciniszyn int qib_verbs_send(struct rvt_qp *qp, struct ib_header *hdr, 10157c2e11feSDennis Dalessandro u32 hdrwords, struct rvt_sge_state *ss, u32 len) 1016f931551bSRalph Campbell { 1017f931551bSRalph Campbell struct qib_devdata *dd = dd_from_ibdev(qp->ibqp.device); 1018f931551bSRalph Campbell u32 plen; 1019f931551bSRalph Campbell int ret; 1020f931551bSRalph Campbell u32 dwords = (len + 3) >> 2; 1021f931551bSRalph Campbell 1022f931551bSRalph Campbell /* 1023f931551bSRalph Campbell * Calculate the send buffer trigger address. 1024f931551bSRalph Campbell * The +1 counts for the pbc control dword following the pbc length. 1025f931551bSRalph Campbell */ 1026f931551bSRalph Campbell plen = hdrwords + dwords + 1; 1027f931551bSRalph Campbell 1028f931551bSRalph Campbell /* 1029f931551bSRalph Campbell * VL15 packets (IB_QPT_SMI) will always use PIO, so we 1030f931551bSRalph Campbell * can defer SDMA restart until link goes ACTIVE without 1031f931551bSRalph Campbell * worrying about just how we got there. 1032f931551bSRalph Campbell */ 1033f931551bSRalph Campbell if (qp->ibqp.qp_type == IB_QPT_SMI || 1034f931551bSRalph Campbell !(dd->flags & QIB_HAS_SEND_DMA)) 1035f931551bSRalph Campbell ret = qib_verbs_send_pio(qp, hdr, hdrwords, ss, len, 1036f931551bSRalph Campbell plen, dwords); 1037f931551bSRalph Campbell else 1038f931551bSRalph Campbell ret = qib_verbs_send_dma(qp, hdr, hdrwords, ss, len, 1039f931551bSRalph Campbell plen, dwords); 1040f931551bSRalph Campbell 1041f931551bSRalph Campbell return ret; 1042f931551bSRalph Campbell } 1043f931551bSRalph Campbell 1044f931551bSRalph Campbell int qib_snapshot_counters(struct qib_pportdata *ppd, u64 *swords, 1045f931551bSRalph Campbell u64 *rwords, u64 *spkts, u64 *rpkts, 1046f931551bSRalph Campbell u64 *xmit_wait) 1047f931551bSRalph Campbell { 1048f931551bSRalph Campbell int ret; 1049f931551bSRalph Campbell struct qib_devdata *dd = ppd->dd; 1050f931551bSRalph Campbell 1051f931551bSRalph Campbell if (!(dd->flags & QIB_PRESENT)) { 1052f931551bSRalph Campbell /* no hardware, freeze, etc. */ 1053f931551bSRalph Campbell ret = -EINVAL; 1054f931551bSRalph Campbell goto bail; 1055f931551bSRalph Campbell } 1056f931551bSRalph Campbell *swords = dd->f_portcntr(ppd, QIBPORTCNTR_WORDSEND); 1057f931551bSRalph Campbell *rwords = dd->f_portcntr(ppd, QIBPORTCNTR_WORDRCV); 1058f931551bSRalph Campbell *spkts = dd->f_portcntr(ppd, QIBPORTCNTR_PKTSEND); 1059f931551bSRalph Campbell *rpkts = dd->f_portcntr(ppd, QIBPORTCNTR_PKTRCV); 1060f931551bSRalph Campbell *xmit_wait = dd->f_portcntr(ppd, QIBPORTCNTR_SENDSTALL); 1061f931551bSRalph Campbell 1062f931551bSRalph Campbell ret = 0; 1063f931551bSRalph Campbell 1064f931551bSRalph Campbell bail: 1065f931551bSRalph Campbell return ret; 1066f931551bSRalph Campbell } 1067f931551bSRalph Campbell 1068f931551bSRalph Campbell /** 1069f931551bSRalph Campbell * qib_get_counters - get various chip counters 10703c2504beSLee Jones * @ppd: the qlogic_ib device 1071f931551bSRalph Campbell * @cntrs: counters are placed here 1072f931551bSRalph Campbell * 1073f931551bSRalph Campbell * Return the counters needed by recv_pma_get_portcounters(). 1074f931551bSRalph Campbell */ 1075f931551bSRalph Campbell int qib_get_counters(struct qib_pportdata *ppd, 1076f931551bSRalph Campbell struct qib_verbs_counters *cntrs) 1077f931551bSRalph Campbell { 1078f931551bSRalph Campbell int ret; 1079f931551bSRalph Campbell 1080f931551bSRalph Campbell if (!(ppd->dd->flags & QIB_PRESENT)) { 1081f931551bSRalph Campbell /* no hardware, freeze, etc. */ 1082f931551bSRalph Campbell ret = -EINVAL; 1083f931551bSRalph Campbell goto bail; 1084f931551bSRalph Campbell } 1085f931551bSRalph Campbell cntrs->symbol_error_counter = 1086f931551bSRalph Campbell ppd->dd->f_portcntr(ppd, QIBPORTCNTR_IBSYMBOLERR); 1087f931551bSRalph Campbell cntrs->link_error_recovery_counter = 1088f931551bSRalph Campbell ppd->dd->f_portcntr(ppd, QIBPORTCNTR_IBLINKERRRECOV); 1089f931551bSRalph Campbell /* 1090f931551bSRalph Campbell * The link downed counter counts when the other side downs the 1091f931551bSRalph Campbell * connection. We add in the number of times we downed the link 1092f931551bSRalph Campbell * due to local link integrity errors to compensate. 1093f931551bSRalph Campbell */ 1094f931551bSRalph Campbell cntrs->link_downed_counter = 1095f931551bSRalph Campbell ppd->dd->f_portcntr(ppd, QIBPORTCNTR_IBLINKDOWN); 1096f931551bSRalph Campbell cntrs->port_rcv_errors = 1097f931551bSRalph Campbell ppd->dd->f_portcntr(ppd, QIBPORTCNTR_RXDROPPKT) + 1098f931551bSRalph Campbell ppd->dd->f_portcntr(ppd, QIBPORTCNTR_RCVOVFL) + 1099f931551bSRalph Campbell ppd->dd->f_portcntr(ppd, QIBPORTCNTR_ERR_RLEN) + 1100f931551bSRalph Campbell ppd->dd->f_portcntr(ppd, QIBPORTCNTR_INVALIDRLEN) + 1101f931551bSRalph Campbell ppd->dd->f_portcntr(ppd, QIBPORTCNTR_ERRLINK) + 1102f931551bSRalph Campbell ppd->dd->f_portcntr(ppd, QIBPORTCNTR_ERRICRC) + 1103f931551bSRalph Campbell ppd->dd->f_portcntr(ppd, QIBPORTCNTR_ERRVCRC) + 1104f931551bSRalph Campbell ppd->dd->f_portcntr(ppd, QIBPORTCNTR_ERRLPCRC) + 1105f931551bSRalph Campbell ppd->dd->f_portcntr(ppd, QIBPORTCNTR_BADFORMAT); 1106f931551bSRalph Campbell cntrs->port_rcv_errors += 1107f931551bSRalph Campbell ppd->dd->f_portcntr(ppd, QIBPORTCNTR_RXLOCALPHYERR); 1108f931551bSRalph Campbell cntrs->port_rcv_errors += 1109f931551bSRalph Campbell ppd->dd->f_portcntr(ppd, QIBPORTCNTR_RXVLERR); 1110f931551bSRalph Campbell cntrs->port_rcv_remphys_errors = 1111f931551bSRalph Campbell ppd->dd->f_portcntr(ppd, QIBPORTCNTR_RCVEBP); 1112f931551bSRalph Campbell cntrs->port_xmit_discards = 1113f931551bSRalph Campbell ppd->dd->f_portcntr(ppd, QIBPORTCNTR_UNSUPVL); 1114f931551bSRalph Campbell cntrs->port_xmit_data = ppd->dd->f_portcntr(ppd, 1115f931551bSRalph Campbell QIBPORTCNTR_WORDSEND); 1116f931551bSRalph Campbell cntrs->port_rcv_data = ppd->dd->f_portcntr(ppd, 1117f931551bSRalph Campbell QIBPORTCNTR_WORDRCV); 1118f931551bSRalph Campbell cntrs->port_xmit_packets = ppd->dd->f_portcntr(ppd, 1119f931551bSRalph Campbell QIBPORTCNTR_PKTSEND); 1120f931551bSRalph Campbell cntrs->port_rcv_packets = ppd->dd->f_portcntr(ppd, 1121f931551bSRalph Campbell QIBPORTCNTR_PKTRCV); 1122f931551bSRalph Campbell cntrs->local_link_integrity_errors = 1123f931551bSRalph Campbell ppd->dd->f_portcntr(ppd, QIBPORTCNTR_LLI); 1124f931551bSRalph Campbell cntrs->excessive_buffer_overrun_errors = 1125f931551bSRalph Campbell ppd->dd->f_portcntr(ppd, QIBPORTCNTR_EXCESSBUFOVFL); 1126f931551bSRalph Campbell cntrs->vl15_dropped = 1127f931551bSRalph Campbell ppd->dd->f_portcntr(ppd, QIBPORTCNTR_VL15PKTDROP); 1128f931551bSRalph Campbell 1129f931551bSRalph Campbell ret = 0; 1130f931551bSRalph Campbell 1131f931551bSRalph Campbell bail: 1132f931551bSRalph Campbell return ret; 1133f931551bSRalph Campbell } 1134f931551bSRalph Campbell 1135f931551bSRalph Campbell /** 1136f931551bSRalph Campbell * qib_ib_piobufavail - callback when a PIO buffer is available 1137f931551bSRalph Campbell * @dd: the device pointer 1138f931551bSRalph Campbell * 1139f931551bSRalph Campbell * This is called from qib_intr() at interrupt level when a PIO buffer is 1140f931551bSRalph Campbell * available after qib_verbs_send() returned an error that no buffers were 1141f931551bSRalph Campbell * available. Disable the interrupt if there are no more QPs waiting. 1142f931551bSRalph Campbell */ 1143f931551bSRalph Campbell void qib_ib_piobufavail(struct qib_devdata *dd) 1144f931551bSRalph Campbell { 1145f931551bSRalph Campbell struct qib_ibdev *dev = &dd->verbs_dev; 1146f931551bSRalph Campbell struct list_head *list; 11477c2e11feSDennis Dalessandro struct rvt_qp *qps[5]; 11487c2e11feSDennis Dalessandro struct rvt_qp *qp; 1149f931551bSRalph Campbell unsigned long flags; 1150f931551bSRalph Campbell unsigned i, n; 1151ffc26907SDennis Dalessandro struct qib_qp_priv *priv; 1152f931551bSRalph Campbell 1153f931551bSRalph Campbell list = &dev->piowait; 1154f931551bSRalph Campbell n = 0; 1155f931551bSRalph Campbell 1156f931551bSRalph Campbell /* 1157f931551bSRalph Campbell * Note: checking that the piowait list is empty and clearing 1158f931551bSRalph Campbell * the buffer available interrupt needs to be atomic or we 1159f931551bSRalph Campbell * could end up with QPs on the wait list with the interrupt 1160f931551bSRalph Campbell * disabled. 1161f931551bSRalph Campbell */ 1162cd18201fSHarish Chegondi spin_lock_irqsave(&dev->rdi.pending_lock, flags); 1163f931551bSRalph Campbell while (!list_empty(list)) { 1164f931551bSRalph Campbell if (n == ARRAY_SIZE(qps)) 1165f931551bSRalph Campbell goto full; 1166ffc26907SDennis Dalessandro priv = list_entry(list->next, struct qib_qp_priv, iowait); 1167ffc26907SDennis Dalessandro qp = priv->owner; 1168ffc26907SDennis Dalessandro list_del_init(&priv->iowait); 1169238b1862SSebastian Sanchez rvt_get_qp(qp); 1170f931551bSRalph Campbell qps[n++] = qp; 1171f931551bSRalph Campbell } 1172f931551bSRalph Campbell dd->f_wantpiobuf_intr(dd, 0); 1173f931551bSRalph Campbell full: 1174cd18201fSHarish Chegondi spin_unlock_irqrestore(&dev->rdi.pending_lock, flags); 1175f931551bSRalph Campbell 1176f931551bSRalph Campbell for (i = 0; i < n; i++) { 1177f931551bSRalph Campbell qp = qps[i]; 1178f931551bSRalph Campbell 1179f931551bSRalph Campbell spin_lock_irqsave(&qp->s_lock, flags); 118001ba79d4SHarish Chegondi if (qp->s_flags & RVT_S_WAIT_PIO) { 118101ba79d4SHarish Chegondi qp->s_flags &= ~RVT_S_WAIT_PIO; 1182f931551bSRalph Campbell qib_schedule_send(qp); 1183f931551bSRalph Campbell } 1184f931551bSRalph Campbell spin_unlock_irqrestore(&qp->s_lock, flags); 1185f931551bSRalph Campbell 1186f931551bSRalph Campbell /* Notify qib_destroy_qp() if it is waiting. */ 1187238b1862SSebastian Sanchez rvt_put_qp(qp); 1188f931551bSRalph Campbell } 1189f931551bSRalph Campbell } 1190f931551bSRalph Campbell 11911fb7f897SMark Bloch static int qib_query_port(struct rvt_dev_info *rdi, u32 port_num, 1192f931551bSRalph Campbell struct ib_port_attr *props) 1193f931551bSRalph Campbell { 1194530a5d8eSHarish Chegondi struct qib_ibdev *ibdev = container_of(rdi, struct qib_ibdev, rdi); 1195530a5d8eSHarish Chegondi struct qib_devdata *dd = dd_from_dev(ibdev); 1196530a5d8eSHarish Chegondi struct qib_pportdata *ppd = &dd->pport[port_num - 1]; 1197f931551bSRalph Campbell enum ib_mtu mtu; 1198f931551bSRalph Campbell u16 lid = ppd->lid; 1199f931551bSRalph Campbell 1200c4550c63SOr Gerlitz /* props being zeroed by the caller, avoid zeroing it here */ 1201f931551bSRalph Campbell props->lid = lid ? lid : be16_to_cpu(IB_LID_PERMISSIVE); 1202f931551bSRalph Campbell props->lmc = ppd->lmc; 1203f931551bSRalph Campbell props->state = dd->f_iblink_state(ppd->lastibcstat); 1204f931551bSRalph Campbell props->phys_state = dd->f_ibphys_portstate(ppd->lastibcstat); 1205f931551bSRalph Campbell props->gid_tbl_len = QIB_GUIDS_PER_PORT; 1206f931551bSRalph Campbell props->active_width = ppd->link_width_active; 1207f931551bSRalph Campbell /* See rate_show() */ 1208f931551bSRalph Campbell props->active_speed = ppd->link_speed_active; 1209f931551bSRalph Campbell props->max_vl_num = qib_num_vls(ppd->vls_supported); 1210f931551bSRalph Campbell 1211f931551bSRalph Campbell props->max_mtu = qib_ibmtu ? qib_ibmtu : IB_MTU_4096; 1212f931551bSRalph Campbell switch (ppd->ibmtu) { 1213f931551bSRalph Campbell case 4096: 1214f931551bSRalph Campbell mtu = IB_MTU_4096; 1215f931551bSRalph Campbell break; 1216f931551bSRalph Campbell case 2048: 1217f931551bSRalph Campbell mtu = IB_MTU_2048; 1218f931551bSRalph Campbell break; 1219f931551bSRalph Campbell case 1024: 1220f931551bSRalph Campbell mtu = IB_MTU_1024; 1221f931551bSRalph Campbell break; 1222f931551bSRalph Campbell case 512: 1223f931551bSRalph Campbell mtu = IB_MTU_512; 1224f931551bSRalph Campbell break; 1225f931551bSRalph Campbell case 256: 1226f931551bSRalph Campbell mtu = IB_MTU_256; 1227f931551bSRalph Campbell break; 1228f931551bSRalph Campbell default: 1229f931551bSRalph Campbell mtu = IB_MTU_2048; 1230f931551bSRalph Campbell } 1231f931551bSRalph Campbell props->active_mtu = mtu; 1232f931551bSRalph Campbell 1233f931551bSRalph Campbell return 0; 1234f931551bSRalph Campbell } 1235f931551bSRalph Campbell 1236f931551bSRalph Campbell static int qib_modify_device(struct ib_device *device, 1237f931551bSRalph Campbell int device_modify_mask, 1238f931551bSRalph Campbell struct ib_device_modify *device_modify) 1239f931551bSRalph Campbell { 1240f931551bSRalph Campbell struct qib_devdata *dd = dd_from_ibdev(device); 1241f931551bSRalph Campbell unsigned i; 1242f931551bSRalph Campbell int ret; 1243f931551bSRalph Campbell 1244f931551bSRalph Campbell if (device_modify_mask & ~(IB_DEVICE_MODIFY_SYS_IMAGE_GUID | 1245f931551bSRalph Campbell IB_DEVICE_MODIFY_NODE_DESC)) { 1246f931551bSRalph Campbell ret = -EOPNOTSUPP; 1247f931551bSRalph Campbell goto bail; 1248f931551bSRalph Campbell } 1249f931551bSRalph Campbell 1250f931551bSRalph Campbell if (device_modify_mask & IB_DEVICE_MODIFY_NODE_DESC) { 1251bd99fdeaSYuval Shaia memcpy(device->node_desc, device_modify->node_desc, 1252bd99fdeaSYuval Shaia IB_DEVICE_NODE_DESC_MAX); 1253f931551bSRalph Campbell for (i = 0; i < dd->num_pports; i++) { 1254f931551bSRalph Campbell struct qib_ibport *ibp = &dd->pport[i].ibport_data; 1255f931551bSRalph Campbell 1256f931551bSRalph Campbell qib_node_desc_chg(ibp); 1257f931551bSRalph Campbell } 1258f931551bSRalph Campbell } 1259f931551bSRalph Campbell 1260f931551bSRalph Campbell if (device_modify_mask & IB_DEVICE_MODIFY_SYS_IMAGE_GUID) { 1261f931551bSRalph Campbell ib_qib_sys_image_guid = 1262f931551bSRalph Campbell cpu_to_be64(device_modify->sys_image_guid); 1263f931551bSRalph Campbell for (i = 0; i < dd->num_pports; i++) { 1264f931551bSRalph Campbell struct qib_ibport *ibp = &dd->pport[i].ibport_data; 1265f931551bSRalph Campbell 1266f931551bSRalph Campbell qib_sys_guid_chg(ibp); 1267f931551bSRalph Campbell } 1268f931551bSRalph Campbell } 1269f931551bSRalph Campbell 1270f931551bSRalph Campbell ret = 0; 1271f931551bSRalph Campbell 1272f931551bSRalph Campbell bail: 1273f931551bSRalph Campbell return ret; 1274f931551bSRalph Campbell } 1275f931551bSRalph Campbell 12761fb7f897SMark Bloch static int qib_shut_down_port(struct rvt_dev_info *rdi, u32 port_num) 1277f931551bSRalph Campbell { 1278530a5d8eSHarish Chegondi struct qib_ibdev *ibdev = container_of(rdi, struct qib_ibdev, rdi); 1279530a5d8eSHarish Chegondi struct qib_devdata *dd = dd_from_dev(ibdev); 1280530a5d8eSHarish Chegondi struct qib_pportdata *ppd = &dd->pport[port_num - 1]; 1281f931551bSRalph Campbell 1282f931551bSRalph Campbell qib_set_linkstate(ppd, QIB_IB_LINKDOWN); 1283530a5d8eSHarish Chegondi 1284f931551bSRalph Campbell return 0; 1285f931551bSRalph Campbell } 1286f931551bSRalph Campbell 128723667546SDennis Dalessandro static int qib_get_guid_be(struct rvt_dev_info *rdi, struct rvt_ibport *rvp, 128823667546SDennis Dalessandro int guid_index, __be64 *guid) 1289f931551bSRalph Campbell { 129023667546SDennis Dalessandro struct qib_ibport *ibp = container_of(rvp, struct qib_ibport, rvp); 1291f931551bSRalph Campbell struct qib_pportdata *ppd = ppd_from_ibp(ibp); 1292f931551bSRalph Campbell 129323667546SDennis Dalessandro if (guid_index == 0) 129423667546SDennis Dalessandro *guid = ppd->guid; 129523667546SDennis Dalessandro else if (guid_index < QIB_GUIDS_PER_PORT) 129623667546SDennis Dalessandro *guid = ibp->guids[guid_index - 1]; 1297f931551bSRalph Campbell else 129823667546SDennis Dalessandro return -EINVAL; 1299f931551bSRalph Campbell 130023667546SDennis Dalessandro return 0; 1301f931551bSRalph Campbell } 1302f931551bSRalph Campbell 130390898850SDasaratharaman Chandramouli int qib_check_ah(struct ib_device *ibdev, struct rdma_ah_attr *ah_attr) 1304f931551bSRalph Campbell { 1305d8966fcdSDasaratharaman Chandramouli if (rdma_ah_get_sl(ah_attr) > 15) 1306f931551bSRalph Campbell return -EINVAL; 1307f931551bSRalph Campbell 130813c19222SDon Hiatt if (rdma_ah_get_dlid(ah_attr) == 0) 130913c19222SDon Hiatt return -EINVAL; 131013c19222SDon Hiatt if (rdma_ah_get_dlid(ah_attr) >= 131113c19222SDon Hiatt be16_to_cpu(IB_MULTICAST_LID_BASE) && 131213c19222SDon Hiatt rdma_ah_get_dlid(ah_attr) != 131313c19222SDon Hiatt be16_to_cpu(IB_LID_PERMISSIVE) && 131413c19222SDon Hiatt !(rdma_ah_get_ah_flags(ah_attr) & IB_AH_GRH)) 131513c19222SDon Hiatt return -EINVAL; 131613c19222SDon Hiatt 131796ab1ac1SDennis Dalessandro return 0; 1318f931551bSRalph Campbell } 1319f931551bSRalph Campbell 13205418a5abSHarish Chegondi static void qib_notify_new_ah(struct ib_device *ibdev, 132190898850SDasaratharaman Chandramouli struct rdma_ah_attr *ah_attr, 13225418a5abSHarish Chegondi struct rvt_ah *ah) 13235418a5abSHarish Chegondi { 13245418a5abSHarish Chegondi struct qib_ibport *ibp; 13255418a5abSHarish Chegondi struct qib_pportdata *ppd; 13265418a5abSHarish Chegondi 13275418a5abSHarish Chegondi /* 13285418a5abSHarish Chegondi * Do not trust reading anything from rvt_ah at this point as it is not 13295418a5abSHarish Chegondi * done being setup. We can however modify things which we need to set. 13305418a5abSHarish Chegondi */ 13315418a5abSHarish Chegondi 1332d8966fcdSDasaratharaman Chandramouli ibp = to_iport(ibdev, rdma_ah_get_port_num(ah_attr)); 13335418a5abSHarish Chegondi ppd = ppd_from_ibp(ibp); 1334d8966fcdSDasaratharaman Chandramouli ah->vl = ibp->sl_to_vl[rdma_ah_get_sl(&ah->attr)]; 13355418a5abSHarish Chegondi ah->log_pmtu = ilog2(ppd->ibmtu); 13365418a5abSHarish Chegondi } 13375418a5abSHarish Chegondi 13381fb9fed6SMike Marciniszyn struct ib_ah *qib_create_qp0_ah(struct qib_ibport *ibp, u16 dlid) 13391fb9fed6SMike Marciniszyn { 134090898850SDasaratharaman Chandramouli struct rdma_ah_attr attr; 13411fb9fed6SMike Marciniszyn struct ib_ah *ah = ERR_PTR(-EINVAL); 13427c2e11feSDennis Dalessandro struct rvt_qp *qp0; 1343d8966fcdSDasaratharaman Chandramouli struct qib_pportdata *ppd = ppd_from_ibp(ibp); 134444c58487SDasaratharaman Chandramouli struct qib_devdata *dd = dd_from_ppd(ppd); 13451fb7f897SMark Bloch u32 port_num = ppd->port; 13461fb9fed6SMike Marciniszyn 1347041af0bbSMike Marciniszyn memset(&attr, 0, sizeof(attr)); 134844c58487SDasaratharaman Chandramouli attr.type = rdma_ah_find_type(&dd->verbs_dev.rdi.ibdev, port_num); 1349d8966fcdSDasaratharaman Chandramouli rdma_ah_set_dlid(&attr, dlid); 1350d8966fcdSDasaratharaman Chandramouli rdma_ah_set_port_num(&attr, port_num); 13511fb9fed6SMike Marciniszyn rcu_read_lock(); 1352f24a6d48SHarish Chegondi qp0 = rcu_dereference(ibp->rvp.qp[0]); 13531fb9fed6SMike Marciniszyn if (qp0) 1354b090c4e3SGal Pressman ah = rdma_create_ah(qp0->ibqp.pd, &attr, 0); 13551fb9fed6SMike Marciniszyn rcu_read_unlock(); 13561fb9fed6SMike Marciniszyn return ah; 13571fb9fed6SMike Marciniszyn } 13581fb9fed6SMike Marciniszyn 1359f931551bSRalph Campbell /** 1360f931551bSRalph Campbell * qib_get_npkeys - return the size of the PKEY table for context 0 1361f931551bSRalph Campbell * @dd: the qlogic_ib device 1362f931551bSRalph Campbell */ 1363f931551bSRalph Campbell unsigned qib_get_npkeys(struct qib_devdata *dd) 1364f931551bSRalph Campbell { 1365f931551bSRalph Campbell return ARRAY_SIZE(dd->rcd[0]->pkeys); 1366f931551bSRalph Campbell } 1367f931551bSRalph Campbell 1368f931551bSRalph Campbell /* 1369f931551bSRalph Campbell * Return the indexed PKEY from the port PKEY table. 1370f931551bSRalph Campbell * No need to validate rcd[ctxt]; the port is setup if we are here. 1371f931551bSRalph Campbell */ 1372f931551bSRalph Campbell unsigned qib_get_pkey(struct qib_ibport *ibp, unsigned index) 1373f931551bSRalph Campbell { 1374f931551bSRalph Campbell struct qib_pportdata *ppd = ppd_from_ibp(ibp); 1375f931551bSRalph Campbell struct qib_devdata *dd = ppd->dd; 1376f931551bSRalph Campbell unsigned ctxt = ppd->hw_pidx; 1377f931551bSRalph Campbell unsigned ret; 1378f931551bSRalph Campbell 1379f931551bSRalph Campbell /* dd->rcd null if mini_init or some init failures */ 1380f931551bSRalph Campbell if (!dd->rcd || index >= ARRAY_SIZE(dd->rcd[ctxt]->pkeys)) 1381f931551bSRalph Campbell ret = 0; 1382f931551bSRalph Campbell else 1383f931551bSRalph Campbell ret = dd->rcd[ctxt]->pkeys[index]; 1384f931551bSRalph Campbell 1385f931551bSRalph Campbell return ret; 1386f931551bSRalph Campbell } 1387f931551bSRalph Campbell 1388f931551bSRalph Campbell static void init_ibport(struct qib_pportdata *ppd) 1389f931551bSRalph Campbell { 1390f931551bSRalph Campbell struct qib_verbs_counters cntrs; 1391f931551bSRalph Campbell struct qib_ibport *ibp = &ppd->ibport_data; 1392f931551bSRalph Campbell 1393f24a6d48SHarish Chegondi spin_lock_init(&ibp->rvp.lock); 1394f931551bSRalph Campbell /* Set the prefix to the default value (see ch. 4.1.1) */ 1395f24a6d48SHarish Chegondi ibp->rvp.gid_prefix = IB_DEFAULT_GID_PREFIX; 1396f24a6d48SHarish Chegondi ibp->rvp.sm_lid = be16_to_cpu(IB_LID_PERMISSIVE); 1397f24a6d48SHarish Chegondi ibp->rvp.port_cap_flags = IB_PORT_SYS_IMAGE_GUID_SUP | 1398f931551bSRalph Campbell IB_PORT_CLIENT_REG_SUP | IB_PORT_SL_MAP_SUP | 1399f931551bSRalph Campbell IB_PORT_TRAP_SUP | IB_PORT_AUTO_MIGR_SUP | 1400f931551bSRalph Campbell IB_PORT_DR_NOTICE_SUP | IB_PORT_CAP_MASK_NOTICE_SUP | 1401f931551bSRalph Campbell IB_PORT_OTHER_LOCAL_CHANGES_SUP; 1402f931551bSRalph Campbell if (ppd->dd->flags & QIB_HAS_LINK_LATENCY) 1403f24a6d48SHarish Chegondi ibp->rvp.port_cap_flags |= IB_PORT_LINK_LATENCY_SUP; 1404f24a6d48SHarish Chegondi ibp->rvp.pma_counter_select[0] = IB_PMA_PORT_XMIT_DATA; 1405f24a6d48SHarish Chegondi ibp->rvp.pma_counter_select[1] = IB_PMA_PORT_RCV_DATA; 1406f24a6d48SHarish Chegondi ibp->rvp.pma_counter_select[2] = IB_PMA_PORT_XMIT_PKTS; 1407f24a6d48SHarish Chegondi ibp->rvp.pma_counter_select[3] = IB_PMA_PORT_RCV_PKTS; 1408f24a6d48SHarish Chegondi ibp->rvp.pma_counter_select[4] = IB_PMA_PORT_XMIT_WAIT; 1409f931551bSRalph Campbell 1410f931551bSRalph Campbell /* Snapshot current HW counters to "clear" them. */ 1411f931551bSRalph Campbell qib_get_counters(ppd, &cntrs); 1412f931551bSRalph Campbell ibp->z_symbol_error_counter = cntrs.symbol_error_counter; 1413f931551bSRalph Campbell ibp->z_link_error_recovery_counter = 1414f931551bSRalph Campbell cntrs.link_error_recovery_counter; 1415f931551bSRalph Campbell ibp->z_link_downed_counter = cntrs.link_downed_counter; 1416f931551bSRalph Campbell ibp->z_port_rcv_errors = cntrs.port_rcv_errors; 1417f931551bSRalph Campbell ibp->z_port_rcv_remphys_errors = cntrs.port_rcv_remphys_errors; 1418f931551bSRalph Campbell ibp->z_port_xmit_discards = cntrs.port_xmit_discards; 1419f931551bSRalph Campbell ibp->z_port_xmit_data = cntrs.port_xmit_data; 1420f931551bSRalph Campbell ibp->z_port_rcv_data = cntrs.port_rcv_data; 1421f931551bSRalph Campbell ibp->z_port_xmit_packets = cntrs.port_xmit_packets; 1422f931551bSRalph Campbell ibp->z_port_rcv_packets = cntrs.port_rcv_packets; 1423f931551bSRalph Campbell ibp->z_local_link_integrity_errors = 1424f931551bSRalph Campbell cntrs.local_link_integrity_errors; 1425f931551bSRalph Campbell ibp->z_excessive_buffer_overrun_errors = 1426f931551bSRalph Campbell cntrs.excessive_buffer_overrun_errors; 1427f931551bSRalph Campbell ibp->z_vl15_dropped = cntrs.vl15_dropped; 1428f24a6d48SHarish Chegondi RCU_INIT_POINTER(ibp->rvp.qp[0], NULL); 1429f24a6d48SHarish Chegondi RCU_INIT_POINTER(ibp->rvp.qp[1], NULL); 1430f931551bSRalph Campbell } 1431f931551bSRalph Campbell 1432f931551bSRalph Campbell /** 14330aeddea2SHarish Chegondi * qib_fill_device_attr - Fill in rvt dev info device attributes. 14340aeddea2SHarish Chegondi * @dd: the device data structure 14350aeddea2SHarish Chegondi */ 14360aeddea2SHarish Chegondi static void qib_fill_device_attr(struct qib_devdata *dd) 14370aeddea2SHarish Chegondi { 14380aeddea2SHarish Chegondi struct rvt_dev_info *rdi = &dd->verbs_dev.rdi; 14390aeddea2SHarish Chegondi 14400aeddea2SHarish Chegondi memset(&rdi->dparms.props, 0, sizeof(rdi->dparms.props)); 14410aeddea2SHarish Chegondi 14420aeddea2SHarish Chegondi rdi->dparms.props.max_pd = ib_qib_max_pds; 14430aeddea2SHarish Chegondi rdi->dparms.props.max_ah = ib_qib_max_ahs; 14440aeddea2SHarish Chegondi rdi->dparms.props.device_cap_flags = IB_DEVICE_BAD_PKEY_CNTR | 14450aeddea2SHarish Chegondi IB_DEVICE_BAD_QKEY_CNTR | IB_DEVICE_SHUTDOWN_PORT | 14460aeddea2SHarish Chegondi IB_DEVICE_SYS_IMAGE_GUID | IB_DEVICE_RC_RNR_NAK_GEN | 14470aeddea2SHarish Chegondi IB_DEVICE_PORT_ACTIVE_EVENT | IB_DEVICE_SRQ_RESIZE; 14480aeddea2SHarish Chegondi rdi->dparms.props.page_size_cap = PAGE_SIZE; 14490aeddea2SHarish Chegondi rdi->dparms.props.vendor_id = 14500aeddea2SHarish Chegondi QIB_SRC_OUI_1 << 16 | QIB_SRC_OUI_2 << 8 | QIB_SRC_OUI_3; 14510aeddea2SHarish Chegondi rdi->dparms.props.vendor_part_id = dd->deviceid; 14520aeddea2SHarish Chegondi rdi->dparms.props.hw_ver = dd->minrev; 14530aeddea2SHarish Chegondi rdi->dparms.props.sys_image_guid = ib_qib_sys_image_guid; 14540aeddea2SHarish Chegondi rdi->dparms.props.max_mr_size = ~0ULL; 14550aeddea2SHarish Chegondi rdi->dparms.props.max_qp = ib_qib_max_qps; 14560aeddea2SHarish Chegondi rdi->dparms.props.max_qp_wr = ib_qib_max_qp_wrs; 145733023fb8SSteve Wise rdi->dparms.props.max_send_sge = ib_qib_max_sges; 145833023fb8SSteve Wise rdi->dparms.props.max_recv_sge = ib_qib_max_sges; 14590aeddea2SHarish Chegondi rdi->dparms.props.max_sge_rd = ib_qib_max_sges; 14600aeddea2SHarish Chegondi rdi->dparms.props.max_cq = ib_qib_max_cqs; 14610aeddea2SHarish Chegondi rdi->dparms.props.max_cqe = ib_qib_max_cqes; 14620aeddea2SHarish Chegondi rdi->dparms.props.max_ah = ib_qib_max_ahs; 14630aeddea2SHarish Chegondi rdi->dparms.props.max_qp_rd_atom = QIB_MAX_RDMA_ATOMIC; 14640aeddea2SHarish Chegondi rdi->dparms.props.max_qp_init_rd_atom = 255; 14650aeddea2SHarish Chegondi rdi->dparms.props.max_srq = ib_qib_max_srqs; 14660aeddea2SHarish Chegondi rdi->dparms.props.max_srq_wr = ib_qib_max_srq_wrs; 14670aeddea2SHarish Chegondi rdi->dparms.props.max_srq_sge = ib_qib_max_srq_sges; 14680aeddea2SHarish Chegondi rdi->dparms.props.atomic_cap = IB_ATOMIC_GLOB; 14690aeddea2SHarish Chegondi rdi->dparms.props.max_pkeys = qib_get_npkeys(dd); 14700aeddea2SHarish Chegondi rdi->dparms.props.max_mcast_grp = ib_qib_max_mcast_grps; 14710aeddea2SHarish Chegondi rdi->dparms.props.max_mcast_qp_attach = ib_qib_max_mcast_qp_attached; 14720aeddea2SHarish Chegondi rdi->dparms.props.max_total_mcast_qp_attach = 14730aeddea2SHarish Chegondi rdi->dparms.props.max_mcast_qp_attach * 14740aeddea2SHarish Chegondi rdi->dparms.props.max_mcast_grp; 14759ec4faa3SMike Marciniszyn /* post send table */ 14769ec4faa3SMike Marciniszyn dd->verbs_dev.rdi.post_parms = qib_post_parms; 1477116aa033SVenkata Sandeep Dhanalakota 1478116aa033SVenkata Sandeep Dhanalakota /* opcode translation table */ 1479116aa033SVenkata Sandeep Dhanalakota dd->verbs_dev.rdi.wc_opcode = ib_qib_wc_opcode; 14800aeddea2SHarish Chegondi } 14810aeddea2SHarish Chegondi 148216b0ba95SKamal Heib static const struct ib_device_ops qib_dev_ops = { 14837a154142SJason Gunthorpe .owner = THIS_MODULE, 1484b9560a41SJason Gunthorpe .driver_id = RDMA_DRIVER_QIB, 1485b9560a41SJason Gunthorpe 1486d7407d16SJason Gunthorpe .port_groups = qib_attr_port_groups, 1487*915e4af5SJason Gunthorpe .device_group = &qib_attr_group, 148816b0ba95SKamal Heib .modify_device = qib_modify_device, 148916b0ba95SKamal Heib .process_mad = qib_process_mad, 149016b0ba95SKamal Heib }; 149116b0ba95SKamal Heib 14920aeddea2SHarish Chegondi /** 1493f931551bSRalph Campbell * qib_register_ib_device - register our device with the infiniband core 1494f931551bSRalph Campbell * @dd: the device data structure 1495f931551bSRalph Campbell * Return the allocated qib_ibdev pointer or NULL on error. 1496f931551bSRalph Campbell */ 1497f931551bSRalph Campbell int qib_register_ib_device(struct qib_devdata *dd) 1498f931551bSRalph Campbell { 1499f931551bSRalph Campbell struct qib_ibdev *dev = &dd->verbs_dev; 15002dc05ab5SDennis Dalessandro struct ib_device *ibdev = &dev->rdi.ibdev; 1501f931551bSRalph Campbell struct qib_pportdata *ppd = dd->pport; 150276fec3e0SHarish Chegondi unsigned i, ctxt; 1503f931551bSRalph Campbell int ret; 1504f931551bSRalph Campbell 1505f931551bSRalph Campbell for (i = 0; i < dd->num_pports; i++) 1506f931551bSRalph Campbell init_ibport(ppd + i); 1507f931551bSRalph Campbell 1508f931551bSRalph Campbell /* Only need to initialize non-zero fields. */ 15094037c92fSKees Cook timer_setup(&dev->mem_timer, mem_timer, 0); 1510f931551bSRalph Campbell 1511f931551bSRalph Campbell INIT_LIST_HEAD(&dev->piowait); 1512f931551bSRalph Campbell INIT_LIST_HEAD(&dev->dmawait); 1513f931551bSRalph Campbell INIT_LIST_HEAD(&dev->txwait); 1514f931551bSRalph Campbell INIT_LIST_HEAD(&dev->memwait); 1515f931551bSRalph Campbell INIT_LIST_HEAD(&dev->txreq_free); 1516f931551bSRalph Campbell 1517f931551bSRalph Campbell if (ppd->sdma_descq_cnt) { 1518f931551bSRalph Campbell dev->pio_hdrs = dma_alloc_coherent(&dd->pcidev->dev, 1519f931551bSRalph Campbell ppd->sdma_descq_cnt * 1520f931551bSRalph Campbell sizeof(struct qib_pio_header), 1521f931551bSRalph Campbell &dev->pio_hdrs_phys, 1522f931551bSRalph Campbell GFP_KERNEL); 1523f931551bSRalph Campbell if (!dev->pio_hdrs) { 1524f931551bSRalph Campbell ret = -ENOMEM; 1525f931551bSRalph Campbell goto err_hdrs; 1526f931551bSRalph Campbell } 1527f931551bSRalph Campbell } 1528f931551bSRalph Campbell 1529f931551bSRalph Campbell for (i = 0; i < ppd->sdma_descq_cnt; i++) { 1530f931551bSRalph Campbell struct qib_verbs_txreq *tx; 1531f931551bSRalph Campbell 1532041af0bbSMike Marciniszyn tx = kzalloc(sizeof(*tx), GFP_KERNEL); 1533f931551bSRalph Campbell if (!tx) { 1534f931551bSRalph Campbell ret = -ENOMEM; 1535f931551bSRalph Campbell goto err_tx; 1536f931551bSRalph Campbell } 1537f931551bSRalph Campbell tx->hdr_inx = i; 1538f931551bSRalph Campbell list_add(&tx->txreq.list, &dev->txreq_free); 1539f931551bSRalph Campbell } 1540f931551bSRalph Campbell 1541f931551bSRalph Campbell /* 1542f931551bSRalph Campbell * The system image GUID is supposed to be the same for all 1543f931551bSRalph Campbell * IB HCAs in a single system but since there can be other 1544f931551bSRalph Campbell * device types in the system, we can't be sure this is unique. 1545f931551bSRalph Campbell */ 1546f931551bSRalph Campbell if (!ib_qib_sys_image_guid) 1547f931551bSRalph Campbell ib_qib_sys_image_guid = ppd->guid; 1548f931551bSRalph Campbell 1549f931551bSRalph Campbell ibdev->node_guid = ppd->guid; 1550f931551bSRalph Campbell ibdev->phys_port_cnt = dd->num_pports; 1551989ab358SBart Van Assche ibdev->dev.parent = &dd->pcidev->dev; 1552f931551bSRalph Campbell 1553f931551bSRalph Campbell snprintf(ibdev->node_desc, sizeof(ibdev->node_desc), 1554e2eed58bSVinit Agnihotri "Intel Infiniband HCA %s", init_utsname()->nodename); 1555f931551bSRalph Campbell 15562dc05ab5SDennis Dalessandro /* 15572dc05ab5SDennis Dalessandro * Fill in rvt info object. 15582dc05ab5SDennis Dalessandro */ 15596a9df403SDennis Dalessandro dd->verbs_dev.rdi.driver_f.get_pci_dev = qib_get_pci_dev; 156096ab1ac1SDennis Dalessandro dd->verbs_dev.rdi.driver_f.check_ah = qib_check_ah; 1561d205a06aSKaike Wan dd->verbs_dev.rdi.driver_f.setup_wqe = qib_check_send_wqe; 15625418a5abSHarish Chegondi dd->verbs_dev.rdi.driver_f.notify_new_ah = qib_notify_new_ah; 156320f333b6SHarish Chegondi dd->verbs_dev.rdi.driver_f.alloc_qpn = qib_alloc_qpn; 156420f333b6SHarish Chegondi dd->verbs_dev.rdi.driver_f.qp_priv_alloc = qib_qp_priv_alloc; 156520f333b6SHarish Chegondi dd->verbs_dev.rdi.driver_f.qp_priv_free = qib_qp_priv_free; 156647c7ea6dSHarish Chegondi dd->verbs_dev.rdi.driver_f.free_all_qps = qib_free_all_qps; 156720f333b6SHarish Chegondi dd->verbs_dev.rdi.driver_f.notify_qp_reset = qib_notify_qp_reset; 1568db3ef0ebSHarish Chegondi dd->verbs_dev.rdi.driver_f.do_send = qib_do_send; 1569db3ef0ebSHarish Chegondi dd->verbs_dev.rdi.driver_f.schedule_send = qib_schedule_send; 157020f333b6SHarish Chegondi dd->verbs_dev.rdi.driver_f.quiesce_qp = qib_quiesce_qp; 157120f333b6SHarish Chegondi dd->verbs_dev.rdi.driver_f.stop_send_queue = qib_stop_send_queue; 157220f333b6SHarish Chegondi dd->verbs_dev.rdi.driver_f.flush_qp_waiters = qib_flush_qp_waiters; 157320f333b6SHarish Chegondi dd->verbs_dev.rdi.driver_f.notify_error_qp = qib_notify_error_qp; 1574b4238e70SVenkata Sandeep Dhanalakota dd->verbs_dev.rdi.driver_f.notify_restart_rc = qib_restart_rc; 157520f333b6SHarish Chegondi dd->verbs_dev.rdi.driver_f.mtu_to_path_mtu = qib_mtu_to_path_mtu; 157620f333b6SHarish Chegondi dd->verbs_dev.rdi.driver_f.mtu_from_qp = qib_mtu_from_qp; 157720f333b6SHarish Chegondi dd->verbs_dev.rdi.driver_f.get_pmtu_from_attr = qib_get_pmtu_from_attr; 157846a80d62SMike Marciniszyn dd->verbs_dev.rdi.driver_f.schedule_send_no_lock = _qib_schedule_send; 1579530a5d8eSHarish Chegondi dd->verbs_dev.rdi.driver_f.query_port_state = qib_query_port; 158020f333b6SHarish Chegondi dd->verbs_dev.rdi.driver_f.shut_down_port = qib_shut_down_port; 1581530a5d8eSHarish Chegondi dd->verbs_dev.rdi.driver_f.cap_mask_chg = qib_cap_mask_chg; 1582611ac099SDennis Dalessandro dd->verbs_dev.rdi.driver_f.notify_create_mad_agent = 1583611ac099SDennis Dalessandro qib_notify_create_mad_agent; 1584611ac099SDennis Dalessandro dd->verbs_dev.rdi.driver_f.notify_free_mad_agent = 1585611ac099SDennis Dalessandro qib_notify_free_mad_agent; 158647c7ea6dSHarish Chegondi 158770696ea7SHarish Chegondi dd->verbs_dev.rdi.dparms.max_rdma_atomic = QIB_MAX_RDMA_ATOMIC; 158823667546SDennis Dalessandro dd->verbs_dev.rdi.driver_f.get_guid_be = qib_get_guid_be; 15897c2e11feSDennis Dalessandro dd->verbs_dev.rdi.dparms.lkey_table_size = qib_lkey_table_size; 159047c7ea6dSHarish Chegondi dd->verbs_dev.rdi.dparms.qp_table_size = ib_qib_qp_table_size; 159147c7ea6dSHarish Chegondi dd->verbs_dev.rdi.dparms.qpn_start = 1; 159247c7ea6dSHarish Chegondi dd->verbs_dev.rdi.dparms.qpn_res_start = QIB_KD_QP; 159347c7ea6dSHarish Chegondi dd->verbs_dev.rdi.dparms.qpn_res_end = QIB_KD_QP; /* Reserve one QP */ 159447c7ea6dSHarish Chegondi dd->verbs_dev.rdi.dparms.qpn_inc = 1; 159547c7ea6dSHarish Chegondi dd->verbs_dev.rdi.dparms.qos_shift = 1; 1596034a3e70SHarish Chegondi dd->verbs_dev.rdi.dparms.psn_mask = QIB_PSN_MASK; 159770696ea7SHarish Chegondi dd->verbs_dev.rdi.dparms.psn_shift = QIB_PSN_SHIFT; 159870696ea7SHarish Chegondi dd->verbs_dev.rdi.dparms.psn_modify_mask = QIB_PSN_MASK; 159976fec3e0SHarish Chegondi dd->verbs_dev.rdi.dparms.nports = dd->num_pports; 160076fec3e0SHarish Chegondi dd->verbs_dev.rdi.dparms.npkeys = qib_get_npkeys(dd); 16014bb88e5fSHarish Chegondi dd->verbs_dev.rdi.dparms.node = dd->assigned_node_id; 1602530a5d8eSHarish Chegondi dd->verbs_dev.rdi.dparms.core_cap_flags = RDMA_CORE_PORT_IBA_IB; 1603530a5d8eSHarish Chegondi dd->verbs_dev.rdi.dparms.max_mad_size = IB_MGMT_MAD_SIZE; 1604019f118bSBrian Welty dd->verbs_dev.rdi.dparms.sge_copy_mode = RVT_SGE_COPY_MEMCPY; 1605530a5d8eSHarish Chegondi 16060aeddea2SHarish Chegondi qib_fill_device_attr(dd); 16070aeddea2SHarish Chegondi 160876fec3e0SHarish Chegondi ppd = dd->pport; 160976fec3e0SHarish Chegondi for (i = 0; i < dd->num_pports; i++, ppd++) { 161076fec3e0SHarish Chegondi ctxt = ppd->hw_pidx; 161176fec3e0SHarish Chegondi rvt_init_port(&dd->verbs_dev.rdi, 161276fec3e0SHarish Chegondi &ppd->ibport_data.rvp, 161376fec3e0SHarish Chegondi i, 161476fec3e0SHarish Chegondi dd->rcd[ctxt]->pkeys); 161576fec3e0SHarish Chegondi } 16162dc05ab5SDennis Dalessandro 161716b0ba95SKamal Heib ib_set_device_ops(ibdev, &qib_dev_ops); 1618b9560a41SJason Gunthorpe ret = rvt_register_device(&dd->verbs_dev.rdi); 1619f931551bSRalph Campbell if (ret) 16205196aa96SDennis Dalessandro goto err_tx; 1621f931551bSRalph Campbell 16225196aa96SDennis Dalessandro return ret; 1623f931551bSRalph Campbell 1624f931551bSRalph Campbell err_tx: 1625f931551bSRalph Campbell while (!list_empty(&dev->txreq_free)) { 1626f931551bSRalph Campbell struct list_head *l = dev->txreq_free.next; 1627f931551bSRalph Campbell struct qib_verbs_txreq *tx; 1628f931551bSRalph Campbell 1629f931551bSRalph Campbell list_del(l); 1630f931551bSRalph Campbell tx = list_entry(l, struct qib_verbs_txreq, txreq.list); 1631f931551bSRalph Campbell kfree(tx); 1632f931551bSRalph Campbell } 1633f931551bSRalph Campbell if (ppd->sdma_descq_cnt) 1634f931551bSRalph Campbell dma_free_coherent(&dd->pcidev->dev, 1635f931551bSRalph Campbell ppd->sdma_descq_cnt * 1636f931551bSRalph Campbell sizeof(struct qib_pio_header), 1637f931551bSRalph Campbell dev->pio_hdrs, dev->pio_hdrs_phys); 1638f931551bSRalph Campbell err_hdrs: 1639f931551bSRalph Campbell qib_dev_err(dd, "cannot register verbs: %d!\n", -ret); 1640f931551bSRalph Campbell return ret; 1641f931551bSRalph Campbell } 1642f931551bSRalph Campbell 1643f931551bSRalph Campbell void qib_unregister_ib_device(struct qib_devdata *dd) 1644f931551bSRalph Campbell { 1645f931551bSRalph Campbell struct qib_ibdev *dev = &dd->verbs_dev; 1646f931551bSRalph Campbell 16472dc05ab5SDennis Dalessandro rvt_unregister_device(&dd->verbs_dev.rdi); 1648f931551bSRalph Campbell 1649f931551bSRalph Campbell if (!list_empty(&dev->piowait)) 1650f931551bSRalph Campbell qib_dev_err(dd, "piowait list not empty!\n"); 1651f931551bSRalph Campbell if (!list_empty(&dev->dmawait)) 1652f931551bSRalph Campbell qib_dev_err(dd, "dmawait list not empty!\n"); 1653f931551bSRalph Campbell if (!list_empty(&dev->txwait)) 1654f931551bSRalph Campbell qib_dev_err(dd, "txwait list not empty!\n"); 1655f931551bSRalph Campbell if (!list_empty(&dev->memwait)) 1656f931551bSRalph Campbell qib_dev_err(dd, "memwait list not empty!\n"); 1657f931551bSRalph Campbell 1658f931551bSRalph Campbell del_timer_sync(&dev->mem_timer); 1659f931551bSRalph Campbell while (!list_empty(&dev->txreq_free)) { 1660f931551bSRalph Campbell struct list_head *l = dev->txreq_free.next; 1661f931551bSRalph Campbell struct qib_verbs_txreq *tx; 1662f931551bSRalph Campbell 1663f931551bSRalph Campbell list_del(l); 1664f931551bSRalph Campbell tx = list_entry(l, struct qib_verbs_txreq, txreq.list); 1665f931551bSRalph Campbell kfree(tx); 1666f931551bSRalph Campbell } 1667f931551bSRalph Campbell if (dd->pport->sdma_descq_cnt) 1668f931551bSRalph Campbell dma_free_coherent(&dd->pcidev->dev, 1669f931551bSRalph Campbell dd->pport->sdma_descq_cnt * 1670f931551bSRalph Campbell sizeof(struct qib_pio_header), 1671f931551bSRalph Campbell dev->pio_hdrs, dev->pio_hdrs_phys); 1672f931551bSRalph Campbell } 1673551ace12SMike Marciniszyn 167446a80d62SMike Marciniszyn /** 167546a80d62SMike Marciniszyn * _qib_schedule_send - schedule progress 16763c2504beSLee Jones * @qp: the qp 167746a80d62SMike Marciniszyn * 167846a80d62SMike Marciniszyn * This schedules progress w/o regard to the s_flags. 167946a80d62SMike Marciniszyn * 168046a80d62SMike Marciniszyn * It is only used in post send, which doesn't hold 168146a80d62SMike Marciniszyn * the s_lock. 1682551ace12SMike Marciniszyn */ 16835da0fc9dSDennis Dalessandro bool _qib_schedule_send(struct rvt_qp *qp) 1684551ace12SMike Marciniszyn { 1685551ace12SMike Marciniszyn struct qib_ibport *ibp = 1686551ace12SMike Marciniszyn to_iport(qp->ibqp.device, qp->port_num); 1687551ace12SMike Marciniszyn struct qib_pportdata *ppd = ppd_from_ibp(ibp); 168846a80d62SMike Marciniszyn struct qib_qp_priv *priv = qp->priv; 1689551ace12SMike Marciniszyn 16905da0fc9dSDennis Dalessandro return queue_work(ppd->qib_wq, &priv->s_work); 1691551ace12SMike Marciniszyn } 169246a80d62SMike Marciniszyn 169346a80d62SMike Marciniszyn /** 169446a80d62SMike Marciniszyn * qib_schedule_send - schedule progress 16953c2504beSLee Jones * @qp: the qp 169646a80d62SMike Marciniszyn * 169746a80d62SMike Marciniszyn * This schedules qp progress. The s_lock 169846a80d62SMike Marciniszyn * should be held. 169946a80d62SMike Marciniszyn */ 17005da0fc9dSDennis Dalessandro bool qib_schedule_send(struct rvt_qp *qp) 170146a80d62SMike Marciniszyn { 170246a80d62SMike Marciniszyn if (qib_send_ok(qp)) 17035da0fc9dSDennis Dalessandro return _qib_schedule_send(qp); 17045da0fc9dSDennis Dalessandro return false; 1705551ace12SMike Marciniszyn } 1706