18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (c) 2018 Chelsio, Inc. All rights reserved. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * This software is available to you under a choice of one of two 58c2ecf20Sopenharmony_ci * licenses. You may choose to be licensed under the terms of the GNU 68c2ecf20Sopenharmony_ci * General Public License (GPL) Version 2, available from the file 78c2ecf20Sopenharmony_ci * COPYING in the main directory of this source tree, or the 88c2ecf20Sopenharmony_ci * OpenIB.org BSD license below: 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or 118c2ecf20Sopenharmony_ci * without modification, are permitted provided that the following 128c2ecf20Sopenharmony_ci * conditions are met: 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * - Redistributions of source code must retain the above 158c2ecf20Sopenharmony_ci * copyright notice, this list of conditions and the following 168c2ecf20Sopenharmony_ci * disclaimer. 178c2ecf20Sopenharmony_ci * 188c2ecf20Sopenharmony_ci * - Redistributions in binary form must reproduce the above 198c2ecf20Sopenharmony_ci * copyright notice, this list of conditions and the following 208c2ecf20Sopenharmony_ci * disclaimer in the documentation and/or other materials 218c2ecf20Sopenharmony_ci * provided with the distribution. 228c2ecf20Sopenharmony_ci * 238c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 248c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 258c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 268c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 278c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 288c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 298c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 308c2ecf20Sopenharmony_ci * SOFTWARE. 318c2ecf20Sopenharmony_ci */ 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#include <rdma/rdma_cm.h> 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#include "iw_cxgb4.h" 368c2ecf20Sopenharmony_ci#include <rdma/restrack.h> 378c2ecf20Sopenharmony_ci#include <uapi/rdma/rdma_netlink.h> 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_cistatic int fill_sq(struct sk_buff *msg, struct t4_wq *wq) 408c2ecf20Sopenharmony_ci{ 418c2ecf20Sopenharmony_ci /* WQ+SQ */ 428c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "sqid", wq->sq.qid)) 438c2ecf20Sopenharmony_ci goto err; 448c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "flushed", wq->flushed)) 458c2ecf20Sopenharmony_ci goto err; 468c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "memsize", wq->sq.memsize)) 478c2ecf20Sopenharmony_ci goto err; 488c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "cidx", wq->sq.cidx)) 498c2ecf20Sopenharmony_ci goto err; 508c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "pidx", wq->sq.pidx)) 518c2ecf20Sopenharmony_ci goto err; 528c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "wq_pidx", wq->sq.wq_pidx)) 538c2ecf20Sopenharmony_ci goto err; 548c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "flush_cidx", wq->sq.flush_cidx)) 558c2ecf20Sopenharmony_ci goto err; 568c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "in_use", wq->sq.in_use)) 578c2ecf20Sopenharmony_ci goto err; 588c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "size", wq->sq.size)) 598c2ecf20Sopenharmony_ci goto err; 608c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32_hex(msg, "flags", wq->sq.flags)) 618c2ecf20Sopenharmony_ci goto err; 628c2ecf20Sopenharmony_ci return 0; 638c2ecf20Sopenharmony_cierr: 648c2ecf20Sopenharmony_ci return -EMSGSIZE; 658c2ecf20Sopenharmony_ci} 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_cistatic int fill_rq(struct sk_buff *msg, struct t4_wq *wq) 688c2ecf20Sopenharmony_ci{ 698c2ecf20Sopenharmony_ci /* RQ */ 708c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "rqid", wq->rq.qid)) 718c2ecf20Sopenharmony_ci goto err; 728c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "memsize", wq->rq.memsize)) 738c2ecf20Sopenharmony_ci goto err; 748c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "cidx", wq->rq.cidx)) 758c2ecf20Sopenharmony_ci goto err; 768c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "pidx", wq->rq.pidx)) 778c2ecf20Sopenharmony_ci goto err; 788c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "wq_pidx", wq->rq.wq_pidx)) 798c2ecf20Sopenharmony_ci goto err; 808c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "msn", wq->rq.msn)) 818c2ecf20Sopenharmony_ci goto err; 828c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32_hex(msg, "rqt_hwaddr", wq->rq.rqt_hwaddr)) 838c2ecf20Sopenharmony_ci goto err; 848c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "rqt_size", wq->rq.rqt_size)) 858c2ecf20Sopenharmony_ci goto err; 868c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "in_use", wq->rq.in_use)) 878c2ecf20Sopenharmony_ci goto err; 888c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "size", wq->rq.size)) 898c2ecf20Sopenharmony_ci goto err; 908c2ecf20Sopenharmony_ci return 0; 918c2ecf20Sopenharmony_cierr: 928c2ecf20Sopenharmony_ci return -EMSGSIZE; 938c2ecf20Sopenharmony_ci} 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_cistatic int fill_swsqe(struct sk_buff *msg, struct t4_sq *sq, u16 idx, 968c2ecf20Sopenharmony_ci struct t4_swsqe *sqe) 978c2ecf20Sopenharmony_ci{ 988c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "idx", idx)) 998c2ecf20Sopenharmony_ci goto err; 1008c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "opcode", sqe->opcode)) 1018c2ecf20Sopenharmony_ci goto err; 1028c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "complete", sqe->complete)) 1038c2ecf20Sopenharmony_ci goto err; 1048c2ecf20Sopenharmony_ci if (sqe->complete && 1058c2ecf20Sopenharmony_ci rdma_nl_put_driver_u32(msg, "cqe_status", CQE_STATUS(&sqe->cqe))) 1068c2ecf20Sopenharmony_ci goto err; 1078c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "signaled", sqe->signaled)) 1088c2ecf20Sopenharmony_ci goto err; 1098c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "flushed", sqe->flushed)) 1108c2ecf20Sopenharmony_ci goto err; 1118c2ecf20Sopenharmony_ci return 0; 1128c2ecf20Sopenharmony_cierr: 1138c2ecf20Sopenharmony_ci return -EMSGSIZE; 1148c2ecf20Sopenharmony_ci} 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ci/* 1178c2ecf20Sopenharmony_ci * Dump the first and last pending sqes. 1188c2ecf20Sopenharmony_ci */ 1198c2ecf20Sopenharmony_cistatic int fill_swsqes(struct sk_buff *msg, struct t4_sq *sq, 1208c2ecf20Sopenharmony_ci u16 first_idx, struct t4_swsqe *first_sqe, 1218c2ecf20Sopenharmony_ci u16 last_idx, struct t4_swsqe *last_sqe) 1228c2ecf20Sopenharmony_ci{ 1238c2ecf20Sopenharmony_ci if (!first_sqe) 1248c2ecf20Sopenharmony_ci goto out; 1258c2ecf20Sopenharmony_ci if (fill_swsqe(msg, sq, first_idx, first_sqe)) 1268c2ecf20Sopenharmony_ci goto err; 1278c2ecf20Sopenharmony_ci if (!last_sqe) 1288c2ecf20Sopenharmony_ci goto out; 1298c2ecf20Sopenharmony_ci if (fill_swsqe(msg, sq, last_idx, last_sqe)) 1308c2ecf20Sopenharmony_ci goto err; 1318c2ecf20Sopenharmony_ciout: 1328c2ecf20Sopenharmony_ci return 0; 1338c2ecf20Sopenharmony_cierr: 1348c2ecf20Sopenharmony_ci return -EMSGSIZE; 1358c2ecf20Sopenharmony_ci} 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ciint c4iw_fill_res_qp_entry(struct sk_buff *msg, struct ib_qp *ibqp) 1388c2ecf20Sopenharmony_ci{ 1398c2ecf20Sopenharmony_ci struct t4_swsqe *fsp = NULL, *lsp = NULL; 1408c2ecf20Sopenharmony_ci struct c4iw_qp *qhp = to_c4iw_qp(ibqp); 1418c2ecf20Sopenharmony_ci u16 first_sq_idx = 0, last_sq_idx = 0; 1428c2ecf20Sopenharmony_ci struct t4_swsqe first_sqe, last_sqe; 1438c2ecf20Sopenharmony_ci struct nlattr *table_attr; 1448c2ecf20Sopenharmony_ci struct t4_wq wq; 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci /* User qp state is not available, so don't dump user qps */ 1478c2ecf20Sopenharmony_ci if (qhp->ucontext) 1488c2ecf20Sopenharmony_ci return 0; 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci table_attr = nla_nest_start_noflag(msg, RDMA_NLDEV_ATTR_DRIVER); 1518c2ecf20Sopenharmony_ci if (!table_attr) 1528c2ecf20Sopenharmony_ci goto err; 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci /* Get a consistent snapshot */ 1558c2ecf20Sopenharmony_ci spin_lock_irq(&qhp->lock); 1568c2ecf20Sopenharmony_ci wq = qhp->wq; 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci /* If there are any pending sqes, copy the first and last */ 1598c2ecf20Sopenharmony_ci if (wq.sq.cidx != wq.sq.pidx) { 1608c2ecf20Sopenharmony_ci first_sq_idx = wq.sq.cidx; 1618c2ecf20Sopenharmony_ci first_sqe = qhp->wq.sq.sw_sq[first_sq_idx]; 1628c2ecf20Sopenharmony_ci fsp = &first_sqe; 1638c2ecf20Sopenharmony_ci last_sq_idx = wq.sq.pidx; 1648c2ecf20Sopenharmony_ci if (last_sq_idx-- == 0) 1658c2ecf20Sopenharmony_ci last_sq_idx = wq.sq.size - 1; 1668c2ecf20Sopenharmony_ci if (last_sq_idx != first_sq_idx) { 1678c2ecf20Sopenharmony_ci last_sqe = qhp->wq.sq.sw_sq[last_sq_idx]; 1688c2ecf20Sopenharmony_ci lsp = &last_sqe; 1698c2ecf20Sopenharmony_ci } 1708c2ecf20Sopenharmony_ci } 1718c2ecf20Sopenharmony_ci spin_unlock_irq(&qhp->lock); 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci if (fill_sq(msg, &wq)) 1748c2ecf20Sopenharmony_ci goto err_cancel_table; 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci if (fill_swsqes(msg, &wq.sq, first_sq_idx, fsp, last_sq_idx, lsp)) 1778c2ecf20Sopenharmony_ci goto err_cancel_table; 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci if (fill_rq(msg, &wq)) 1808c2ecf20Sopenharmony_ci goto err_cancel_table; 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci nla_nest_end(msg, table_attr); 1838c2ecf20Sopenharmony_ci return 0; 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_cierr_cancel_table: 1868c2ecf20Sopenharmony_ci nla_nest_cancel(msg, table_attr); 1878c2ecf20Sopenharmony_cierr: 1888c2ecf20Sopenharmony_ci return -EMSGSIZE; 1898c2ecf20Sopenharmony_ci} 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ciunion union_ep { 1928c2ecf20Sopenharmony_ci struct c4iw_listen_ep lep; 1938c2ecf20Sopenharmony_ci struct c4iw_ep ep; 1948c2ecf20Sopenharmony_ci}; 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ciint c4iw_fill_res_cm_id_entry(struct sk_buff *msg, 1978c2ecf20Sopenharmony_ci struct rdma_cm_id *cm_id) 1988c2ecf20Sopenharmony_ci{ 1998c2ecf20Sopenharmony_ci struct nlattr *table_attr; 2008c2ecf20Sopenharmony_ci struct c4iw_ep_common *epcp; 2018c2ecf20Sopenharmony_ci struct c4iw_listen_ep *listen_ep = NULL; 2028c2ecf20Sopenharmony_ci struct c4iw_ep *ep = NULL; 2038c2ecf20Sopenharmony_ci struct iw_cm_id *iw_cm_id; 2048c2ecf20Sopenharmony_ci union union_ep *uep; 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci iw_cm_id = rdma_iw_cm_id(cm_id); 2078c2ecf20Sopenharmony_ci if (!iw_cm_id) 2088c2ecf20Sopenharmony_ci return 0; 2098c2ecf20Sopenharmony_ci epcp = (struct c4iw_ep_common *)iw_cm_id->provider_data; 2108c2ecf20Sopenharmony_ci if (!epcp) 2118c2ecf20Sopenharmony_ci return 0; 2128c2ecf20Sopenharmony_ci uep = kcalloc(1, sizeof(*uep), GFP_KERNEL); 2138c2ecf20Sopenharmony_ci if (!uep) 2148c2ecf20Sopenharmony_ci return 0; 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_ci table_attr = nla_nest_start_noflag(msg, RDMA_NLDEV_ATTR_DRIVER); 2178c2ecf20Sopenharmony_ci if (!table_attr) 2188c2ecf20Sopenharmony_ci goto err_free_uep; 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci /* Get a consistent snapshot */ 2218c2ecf20Sopenharmony_ci mutex_lock(&epcp->mutex); 2228c2ecf20Sopenharmony_ci if (epcp->state == LISTEN) { 2238c2ecf20Sopenharmony_ci uep->lep = *(struct c4iw_listen_ep *)epcp; 2248c2ecf20Sopenharmony_ci mutex_unlock(&epcp->mutex); 2258c2ecf20Sopenharmony_ci listen_ep = &uep->lep; 2268c2ecf20Sopenharmony_ci epcp = &listen_ep->com; 2278c2ecf20Sopenharmony_ci } else { 2288c2ecf20Sopenharmony_ci uep->ep = *(struct c4iw_ep *)epcp; 2298c2ecf20Sopenharmony_ci mutex_unlock(&epcp->mutex); 2308c2ecf20Sopenharmony_ci ep = &uep->ep; 2318c2ecf20Sopenharmony_ci epcp = &ep->com; 2328c2ecf20Sopenharmony_ci } 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "state", epcp->state)) 2358c2ecf20Sopenharmony_ci goto err_cancel_table; 2368c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u64_hex(msg, "flags", epcp->flags)) 2378c2ecf20Sopenharmony_ci goto err_cancel_table; 2388c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u64_hex(msg, "history", epcp->history)) 2398c2ecf20Sopenharmony_ci goto err_cancel_table; 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ci if (epcp->state == LISTEN) { 2428c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "stid", listen_ep->stid)) 2438c2ecf20Sopenharmony_ci goto err_cancel_table; 2448c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "backlog", listen_ep->backlog)) 2458c2ecf20Sopenharmony_ci goto err_cancel_table; 2468c2ecf20Sopenharmony_ci } else { 2478c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "hwtid", ep->hwtid)) 2488c2ecf20Sopenharmony_ci goto err_cancel_table; 2498c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "ord", ep->ord)) 2508c2ecf20Sopenharmony_ci goto err_cancel_table; 2518c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "ird", ep->ird)) 2528c2ecf20Sopenharmony_ci goto err_cancel_table; 2538c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "emss", ep->emss)) 2548c2ecf20Sopenharmony_ci goto err_cancel_table; 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci if (!ep->parent_ep && rdma_nl_put_driver_u32(msg, "atid", 2578c2ecf20Sopenharmony_ci ep->atid)) 2588c2ecf20Sopenharmony_ci goto err_cancel_table; 2598c2ecf20Sopenharmony_ci } 2608c2ecf20Sopenharmony_ci nla_nest_end(msg, table_attr); 2618c2ecf20Sopenharmony_ci kfree(uep); 2628c2ecf20Sopenharmony_ci return 0; 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_cierr_cancel_table: 2658c2ecf20Sopenharmony_ci nla_nest_cancel(msg, table_attr); 2668c2ecf20Sopenharmony_cierr_free_uep: 2678c2ecf20Sopenharmony_ci kfree(uep); 2688c2ecf20Sopenharmony_ci return -EMSGSIZE; 2698c2ecf20Sopenharmony_ci} 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_cistatic int fill_cq(struct sk_buff *msg, struct t4_cq *cq) 2728c2ecf20Sopenharmony_ci{ 2738c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "cqid", cq->cqid)) 2748c2ecf20Sopenharmony_ci goto err; 2758c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "memsize", cq->memsize)) 2768c2ecf20Sopenharmony_ci goto err; 2778c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "size", cq->size)) 2788c2ecf20Sopenharmony_ci goto err; 2798c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "cidx", cq->cidx)) 2808c2ecf20Sopenharmony_ci goto err; 2818c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "cidx_inc", cq->cidx_inc)) 2828c2ecf20Sopenharmony_ci goto err; 2838c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "sw_cidx", cq->sw_cidx)) 2848c2ecf20Sopenharmony_ci goto err; 2858c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "sw_pidx", cq->sw_pidx)) 2868c2ecf20Sopenharmony_ci goto err; 2878c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "sw_in_use", cq->sw_in_use)) 2888c2ecf20Sopenharmony_ci goto err; 2898c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "vector", cq->vector)) 2908c2ecf20Sopenharmony_ci goto err; 2918c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "gen", cq->gen)) 2928c2ecf20Sopenharmony_ci goto err; 2938c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "error", cq->error)) 2948c2ecf20Sopenharmony_ci goto err; 2958c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u64_hex(msg, "bits_type_ts", 2968c2ecf20Sopenharmony_ci be64_to_cpu(cq->bits_type_ts))) 2978c2ecf20Sopenharmony_ci goto err; 2988c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u64_hex(msg, "flags", cq->flags)) 2998c2ecf20Sopenharmony_ci goto err; 3008c2ecf20Sopenharmony_ci 3018c2ecf20Sopenharmony_ci return 0; 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_cierr: 3048c2ecf20Sopenharmony_ci return -EMSGSIZE; 3058c2ecf20Sopenharmony_ci} 3068c2ecf20Sopenharmony_ci 3078c2ecf20Sopenharmony_cistatic int fill_cqe(struct sk_buff *msg, struct t4_cqe *cqe, u16 idx, 3088c2ecf20Sopenharmony_ci const char *qstr) 3098c2ecf20Sopenharmony_ci{ 3108c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, qstr, idx)) 3118c2ecf20Sopenharmony_ci goto err; 3128c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32_hex(msg, "header", 3138c2ecf20Sopenharmony_ci be32_to_cpu(cqe->header))) 3148c2ecf20Sopenharmony_ci goto err; 3158c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "len", be32_to_cpu(cqe->len))) 3168c2ecf20Sopenharmony_ci goto err; 3178c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32_hex(msg, "wrid_hi", 3188c2ecf20Sopenharmony_ci be32_to_cpu(cqe->u.gen.wrid_hi))) 3198c2ecf20Sopenharmony_ci goto err; 3208c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32_hex(msg, "wrid_low", 3218c2ecf20Sopenharmony_ci be32_to_cpu(cqe->u.gen.wrid_low))) 3228c2ecf20Sopenharmony_ci goto err; 3238c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u64_hex(msg, "bits_type_ts", 3248c2ecf20Sopenharmony_ci be64_to_cpu(cqe->bits_type_ts))) 3258c2ecf20Sopenharmony_ci goto err; 3268c2ecf20Sopenharmony_ci 3278c2ecf20Sopenharmony_ci return 0; 3288c2ecf20Sopenharmony_ci 3298c2ecf20Sopenharmony_cierr: 3308c2ecf20Sopenharmony_ci return -EMSGSIZE; 3318c2ecf20Sopenharmony_ci} 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_cistatic int fill_hwcqes(struct sk_buff *msg, struct t4_cq *cq, 3348c2ecf20Sopenharmony_ci struct t4_cqe *cqes) 3358c2ecf20Sopenharmony_ci{ 3368c2ecf20Sopenharmony_ci u16 idx; 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci idx = (cq->cidx > 0) ? cq->cidx - 1 : cq->size - 1; 3398c2ecf20Sopenharmony_ci if (fill_cqe(msg, cqes, idx, "hwcq_idx")) 3408c2ecf20Sopenharmony_ci goto err; 3418c2ecf20Sopenharmony_ci idx = cq->cidx; 3428c2ecf20Sopenharmony_ci if (fill_cqe(msg, cqes + 1, idx, "hwcq_idx")) 3438c2ecf20Sopenharmony_ci goto err; 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_ci return 0; 3468c2ecf20Sopenharmony_cierr: 3478c2ecf20Sopenharmony_ci return -EMSGSIZE; 3488c2ecf20Sopenharmony_ci} 3498c2ecf20Sopenharmony_ci 3508c2ecf20Sopenharmony_cistatic int fill_swcqes(struct sk_buff *msg, struct t4_cq *cq, 3518c2ecf20Sopenharmony_ci struct t4_cqe *cqes) 3528c2ecf20Sopenharmony_ci{ 3538c2ecf20Sopenharmony_ci u16 idx; 3548c2ecf20Sopenharmony_ci 3558c2ecf20Sopenharmony_ci if (!cq->sw_in_use) 3568c2ecf20Sopenharmony_ci return 0; 3578c2ecf20Sopenharmony_ci 3588c2ecf20Sopenharmony_ci idx = cq->sw_cidx; 3598c2ecf20Sopenharmony_ci if (fill_cqe(msg, cqes, idx, "swcq_idx")) 3608c2ecf20Sopenharmony_ci goto err; 3618c2ecf20Sopenharmony_ci if (cq->sw_in_use == 1) 3628c2ecf20Sopenharmony_ci goto out; 3638c2ecf20Sopenharmony_ci idx = (cq->sw_pidx > 0) ? cq->sw_pidx - 1 : cq->size - 1; 3648c2ecf20Sopenharmony_ci if (fill_cqe(msg, cqes + 1, idx, "swcq_idx")) 3658c2ecf20Sopenharmony_ci goto err; 3668c2ecf20Sopenharmony_ciout: 3678c2ecf20Sopenharmony_ci return 0; 3688c2ecf20Sopenharmony_cierr: 3698c2ecf20Sopenharmony_ci return -EMSGSIZE; 3708c2ecf20Sopenharmony_ci} 3718c2ecf20Sopenharmony_ci 3728c2ecf20Sopenharmony_ciint c4iw_fill_res_cq_entry(struct sk_buff *msg, struct ib_cq *ibcq) 3738c2ecf20Sopenharmony_ci{ 3748c2ecf20Sopenharmony_ci struct c4iw_cq *chp = to_c4iw_cq(ibcq); 3758c2ecf20Sopenharmony_ci struct nlattr *table_attr; 3768c2ecf20Sopenharmony_ci struct t4_cqe hwcqes[2]; 3778c2ecf20Sopenharmony_ci struct t4_cqe swcqes[2]; 3788c2ecf20Sopenharmony_ci struct t4_cq cq; 3798c2ecf20Sopenharmony_ci u16 idx; 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_ci /* User cq state is not available, so don't dump user cqs */ 3828c2ecf20Sopenharmony_ci if (ibcq->uobject) 3838c2ecf20Sopenharmony_ci return 0; 3848c2ecf20Sopenharmony_ci 3858c2ecf20Sopenharmony_ci table_attr = nla_nest_start_noflag(msg, RDMA_NLDEV_ATTR_DRIVER); 3868c2ecf20Sopenharmony_ci if (!table_attr) 3878c2ecf20Sopenharmony_ci goto err; 3888c2ecf20Sopenharmony_ci 3898c2ecf20Sopenharmony_ci /* Get a consistent snapshot */ 3908c2ecf20Sopenharmony_ci spin_lock_irq(&chp->lock); 3918c2ecf20Sopenharmony_ci 3928c2ecf20Sopenharmony_ci /* t4_cq struct */ 3938c2ecf20Sopenharmony_ci cq = chp->cq; 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_ci /* get 2 hw cqes: cidx-1, and cidx */ 3968c2ecf20Sopenharmony_ci idx = (cq.cidx > 0) ? cq.cidx - 1 : cq.size - 1; 3978c2ecf20Sopenharmony_ci hwcqes[0] = chp->cq.queue[idx]; 3988c2ecf20Sopenharmony_ci 3998c2ecf20Sopenharmony_ci idx = cq.cidx; 4008c2ecf20Sopenharmony_ci hwcqes[1] = chp->cq.queue[idx]; 4018c2ecf20Sopenharmony_ci 4028c2ecf20Sopenharmony_ci /* get first and last sw cqes */ 4038c2ecf20Sopenharmony_ci if (cq.sw_in_use) { 4048c2ecf20Sopenharmony_ci swcqes[0] = chp->cq.sw_queue[cq.sw_cidx]; 4058c2ecf20Sopenharmony_ci if (cq.sw_in_use > 1) { 4068c2ecf20Sopenharmony_ci idx = (cq.sw_pidx > 0) ? cq.sw_pidx - 1 : cq.size - 1; 4078c2ecf20Sopenharmony_ci swcqes[1] = chp->cq.sw_queue[idx]; 4088c2ecf20Sopenharmony_ci } 4098c2ecf20Sopenharmony_ci } 4108c2ecf20Sopenharmony_ci 4118c2ecf20Sopenharmony_ci spin_unlock_irq(&chp->lock); 4128c2ecf20Sopenharmony_ci 4138c2ecf20Sopenharmony_ci if (fill_cq(msg, &cq)) 4148c2ecf20Sopenharmony_ci goto err_cancel_table; 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_ci if (fill_swcqes(msg, &cq, swcqes)) 4178c2ecf20Sopenharmony_ci goto err_cancel_table; 4188c2ecf20Sopenharmony_ci 4198c2ecf20Sopenharmony_ci if (fill_hwcqes(msg, &cq, hwcqes)) 4208c2ecf20Sopenharmony_ci goto err_cancel_table; 4218c2ecf20Sopenharmony_ci 4228c2ecf20Sopenharmony_ci nla_nest_end(msg, table_attr); 4238c2ecf20Sopenharmony_ci return 0; 4248c2ecf20Sopenharmony_ci 4258c2ecf20Sopenharmony_cierr_cancel_table: 4268c2ecf20Sopenharmony_ci nla_nest_cancel(msg, table_attr); 4278c2ecf20Sopenharmony_cierr: 4288c2ecf20Sopenharmony_ci return -EMSGSIZE; 4298c2ecf20Sopenharmony_ci} 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_ciint c4iw_fill_res_mr_entry(struct sk_buff *msg, struct ib_mr *ibmr) 4328c2ecf20Sopenharmony_ci{ 4338c2ecf20Sopenharmony_ci struct c4iw_mr *mhp = to_c4iw_mr(ibmr); 4348c2ecf20Sopenharmony_ci struct c4iw_dev *dev = mhp->rhp; 4358c2ecf20Sopenharmony_ci u32 stag = mhp->attr.stag; 4368c2ecf20Sopenharmony_ci struct nlattr *table_attr; 4378c2ecf20Sopenharmony_ci struct fw_ri_tpte tpte; 4388c2ecf20Sopenharmony_ci int ret; 4398c2ecf20Sopenharmony_ci 4408c2ecf20Sopenharmony_ci if (!stag) 4418c2ecf20Sopenharmony_ci return 0; 4428c2ecf20Sopenharmony_ci 4438c2ecf20Sopenharmony_ci table_attr = nla_nest_start_noflag(msg, RDMA_NLDEV_ATTR_DRIVER); 4448c2ecf20Sopenharmony_ci if (!table_attr) 4458c2ecf20Sopenharmony_ci goto err; 4468c2ecf20Sopenharmony_ci 4478c2ecf20Sopenharmony_ci ret = cxgb4_read_tpte(dev->rdev.lldi.ports[0], stag, (__be32 *)&tpte); 4488c2ecf20Sopenharmony_ci if (ret) { 4498c2ecf20Sopenharmony_ci dev_err(&dev->rdev.lldi.pdev->dev, 4508c2ecf20Sopenharmony_ci "%s cxgb4_read_tpte err %d\n", __func__, ret); 4518c2ecf20Sopenharmony_ci return 0; 4528c2ecf20Sopenharmony_ci } 4538c2ecf20Sopenharmony_ci 4548c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32_hex(msg, "idx", stag >> 8)) 4558c2ecf20Sopenharmony_ci goto err_cancel_table; 4568c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "valid", 4578c2ecf20Sopenharmony_ci FW_RI_TPTE_VALID_G(ntohl(tpte.valid_to_pdid)))) 4588c2ecf20Sopenharmony_ci goto err_cancel_table; 4598c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32_hex(msg, "key", stag & 0xff)) 4608c2ecf20Sopenharmony_ci goto err_cancel_table; 4618c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "state", 4628c2ecf20Sopenharmony_ci FW_RI_TPTE_STAGSTATE_G(ntohl(tpte.valid_to_pdid)))) 4638c2ecf20Sopenharmony_ci goto err_cancel_table; 4648c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "pdid", 4658c2ecf20Sopenharmony_ci FW_RI_TPTE_PDID_G(ntohl(tpte.valid_to_pdid)))) 4668c2ecf20Sopenharmony_ci goto err_cancel_table; 4678c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32_hex(msg, "perm", 4688c2ecf20Sopenharmony_ci FW_RI_TPTE_PERM_G(ntohl(tpte.locread_to_qpid)))) 4698c2ecf20Sopenharmony_ci goto err_cancel_table; 4708c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32(msg, "ps", 4718c2ecf20Sopenharmony_ci FW_RI_TPTE_PS_G(ntohl(tpte.locread_to_qpid)))) 4728c2ecf20Sopenharmony_ci goto err_cancel_table; 4738c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u64(msg, "len", 4748c2ecf20Sopenharmony_ci ((u64)ntohl(tpte.len_hi) << 32) | ntohl(tpte.len_lo))) 4758c2ecf20Sopenharmony_ci goto err_cancel_table; 4768c2ecf20Sopenharmony_ci if (rdma_nl_put_driver_u32_hex(msg, "pbl_addr", 4778c2ecf20Sopenharmony_ci FW_RI_TPTE_PBLADDR_G(ntohl(tpte.nosnoop_pbladdr)))) 4788c2ecf20Sopenharmony_ci goto err_cancel_table; 4798c2ecf20Sopenharmony_ci 4808c2ecf20Sopenharmony_ci nla_nest_end(msg, table_attr); 4818c2ecf20Sopenharmony_ci return 0; 4828c2ecf20Sopenharmony_ci 4838c2ecf20Sopenharmony_cierr_cancel_table: 4848c2ecf20Sopenharmony_ci nla_nest_cancel(msg, table_attr); 4858c2ecf20Sopenharmony_cierr: 4868c2ecf20Sopenharmony_ci return -EMSGSIZE; 4878c2ecf20Sopenharmony_ci} 488