1 /* 2 * This file is part of the Chelsio T6 Ethernet driver for Linux. 3 * 4 * Copyright (c) 2017-2018 Chelsio Communications, Inc. All rights reserved. 5 * 6 * This software is available to you under a choice of one of two 7 * licenses. You may choose to be licensed under the terms of the GNU 8 * General Public License (GPL) Version 2, available from the file 9 * COPYING in the main directory of this source tree, or the 10 * OpenIB.org BSD license below: 11 * 12 * Redistribution and use in source and binary forms, with or 13 * without modification, are permitted provided that the following 14 * conditions are met: 15 * 16 * - Redistributions of source code must retain the above 17 * copyright notice, this list of conditions and the following 18 * disclaimer. 19 * 20 * - Redistributions in binary form must reproduce the above 21 * copyright notice, this list of conditions and the following 22 * disclaimer in the documentation and/or other materials 23 * provided with the distribution. 24 * 25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32 * SOFTWARE. 33 */ 34 35 #include "cxgb4.h" 36 #include "t4_msg.h" 37 #include "srq.h" 38 39 struct srq_data *t4_init_srq(int srq_size) 40 { 41 struct srq_data *s; 42 43 s = kvzalloc(sizeof(*s), GFP_KERNEL); 44 if (!s) 45 return NULL; 46 47 s->srq_size = srq_size; 48 init_completion(&s->comp); 49 mutex_init(&s->lock); 50 51 return s; 52 } 53 54 /* cxgb4_get_srq_entry: read the SRQ table entry 55 * @dev: Pointer to the net_device 56 * @idx: Index to the srq 57 * @entryp: pointer to the srq entry 58 * 59 * Sends CPL_SRQ_TABLE_REQ message for the given index. 60 * Contents will be returned in CPL_SRQ_TABLE_RPL message. 61 * 62 * Returns zero if the read is successful, else a error 63 * number will be returned. Caller should not use the srq 64 * entry if the return value is non-zero. 65 * 66 * 67 */ 68 int cxgb4_get_srq_entry(struct net_device *dev, 69 int srq_idx, struct srq_entry *entryp) 70 { 71 struct cpl_srq_table_req *req; 72 struct adapter *adap; 73 struct sk_buff *skb; 74 struct srq_data *s; 75 int rc = -ENODEV; 76 77 adap = netdev2adap(dev); 78 s = adap->srq; 79 80 if (!(adap->flags & FULL_INIT_DONE) || !s) 81 goto out; 82 83 skb = alloc_skb(sizeof(*req), GFP_KERNEL); 84 if (!skb) 85 return -ENOMEM; 86 req = (struct cpl_srq_table_req *) 87 __skb_put(skb, sizeof(*req)); 88 memset(req, 0, sizeof(*req)); 89 INIT_TP_WR(req, 0); 90 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SRQ_TABLE_REQ, 91 TID_TID_V(srq_idx) | 92 TID_QID_V(adap->sge.fw_evtq.abs_id))); 93 req->idx = srq_idx; 94 95 mutex_lock(&s->lock); 96 97 s->entryp = entryp; 98 t4_mgmt_tx(adap, skb); 99 100 rc = wait_for_completion_timeout(&s->comp, SRQ_WAIT_TO); 101 if (rc) 102 rc = 0; 103 else /* !rc means we timed out */ 104 rc = -ETIMEDOUT; 105 106 WARN_ON_ONCE(entryp->idx != srq_idx); 107 mutex_unlock(&s->lock); 108 out: 109 return rc; 110 } 111 EXPORT_SYMBOL(cxgb4_get_srq_entry); 112 113 void do_srq_table_rpl(struct adapter *adap, 114 const struct cpl_srq_table_rpl *rpl) 115 { 116 unsigned int idx = TID_TID_G(GET_TID(rpl)); 117 struct srq_data *s = adap->srq; 118 struct srq_entry *e; 119 120 if (unlikely(rpl->status != CPL_CONTAINS_READ_RPL)) { 121 dev_err(adap->pdev_dev, 122 "Unexpected SRQ_TABLE_RPL status %u for entry %u\n", 123 rpl->status, idx); 124 goto out; 125 } 126 127 /* Store the read entry */ 128 e = s->entryp; 129 e->valid = 1; 130 e->idx = idx; 131 e->pdid = SRQT_PDID_G(be64_to_cpu(rpl->rsvd_pdid)); 132 e->qlen = SRQT_QLEN_G(be32_to_cpu(rpl->qlen_qbase)); 133 e->qbase = SRQT_QBASE_G(be32_to_cpu(rpl->qlen_qbase)); 134 e->cur_msn = be16_to_cpu(rpl->cur_msn); 135 e->max_msn = be16_to_cpu(rpl->max_msn); 136 out: 137 complete(&s->comp); 138 } 139