|
| 1 | +/* |
| 2 | + * Copyright (c) 2018 Chelsio, Inc. All rights reserved. |
| 3 | + * |
| 4 | + * This software is available to you under a choice of one of two |
| 5 | + * licenses. You may choose to be licensed under the terms of the GNU |
| 6 | + * General Public License (GPL) Version 2, available from the file |
| 7 | + * COPYING in the main directory of this source tree, or the |
| 8 | + * OpenIB.org BSD license below: |
| 9 | + * |
| 10 | + * Redistribution and use in source and binary forms, with or |
| 11 | + * without modification, are permitted provided that the following |
| 12 | + * conditions are met: |
| 13 | + * |
| 14 | + * - Redistributions of source code must retain the above |
| 15 | + * copyright notice, this list of conditions and the following |
| 16 | + * disclaimer. |
| 17 | + * |
| 18 | + * - Redistributions in binary form must reproduce the above |
| 19 | + * copyright notice, this list of conditions and the following |
| 20 | + * disclaimer in the documentation and/or other materials |
| 21 | + * provided with the distribution. |
| 22 | + * |
| 23 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 24 | + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 25 | + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 26 | + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 27 | + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 28 | + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 29 | + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 30 | + * SOFTWARE. |
| 31 | + */ |
| 32 | + |
| 33 | +#include "iw_cxgb4.h" |
| 34 | +#include <rdma/restrack.h> |
| 35 | +#include <uapi/rdma/rdma_netlink.h> |
| 36 | + |
| 37 | +static int fill_sq(struct sk_buff *msg, struct t4_wq *wq) |
| 38 | +{ |
| 39 | + /* WQ+SQ */ |
| 40 | + if (rdma_nl_put_driver_u32(msg, "sqid", wq->sq.qid)) |
| 41 | + goto err; |
| 42 | + if (rdma_nl_put_driver_u32(msg, "flushed", wq->flushed)) |
| 43 | + goto err; |
| 44 | + if (rdma_nl_put_driver_u32(msg, "memsize", wq->sq.memsize)) |
| 45 | + goto err; |
| 46 | + if (rdma_nl_put_driver_u32(msg, "cidx", wq->sq.cidx)) |
| 47 | + goto err; |
| 48 | + if (rdma_nl_put_driver_u32(msg, "pidx", wq->sq.pidx)) |
| 49 | + goto err; |
| 50 | + if (rdma_nl_put_driver_u32(msg, "wq_pidx", wq->sq.wq_pidx)) |
| 51 | + goto err; |
| 52 | + if (rdma_nl_put_driver_u32(msg, "flush_cidx", wq->sq.flush_cidx)) |
| 53 | + goto err; |
| 54 | + if (rdma_nl_put_driver_u32(msg, "in_use", wq->sq.in_use)) |
| 55 | + goto err; |
| 56 | + if (rdma_nl_put_driver_u32(msg, "size", wq->sq.size)) |
| 57 | + goto err; |
| 58 | + if (rdma_nl_put_driver_u32_hex(msg, "flags", wq->sq.flags)) |
| 59 | + goto err; |
| 60 | + return 0; |
| 61 | +err: |
| 62 | + return -EMSGSIZE; |
| 63 | +} |
| 64 | + |
| 65 | +static int fill_rq(struct sk_buff *msg, struct t4_wq *wq) |
| 66 | +{ |
| 67 | + /* RQ */ |
| 68 | + if (rdma_nl_put_driver_u32(msg, "rqid", wq->rq.qid)) |
| 69 | + goto err; |
| 70 | + if (rdma_nl_put_driver_u32(msg, "memsize", wq->rq.memsize)) |
| 71 | + goto err; |
| 72 | + if (rdma_nl_put_driver_u32(msg, "cidx", wq->rq.cidx)) |
| 73 | + goto err; |
| 74 | + if (rdma_nl_put_driver_u32(msg, "pidx", wq->rq.pidx)) |
| 75 | + goto err; |
| 76 | + if (rdma_nl_put_driver_u32(msg, "wq_pidx", wq->rq.wq_pidx)) |
| 77 | + goto err; |
| 78 | + if (rdma_nl_put_driver_u32(msg, "msn", wq->rq.msn)) |
| 79 | + goto err; |
| 80 | + if (rdma_nl_put_driver_u32_hex(msg, "rqt_hwaddr", wq->rq.rqt_hwaddr)) |
| 81 | + goto err; |
| 82 | + if (rdma_nl_put_driver_u32(msg, "rqt_size", wq->rq.rqt_size)) |
| 83 | + goto err; |
| 84 | + if (rdma_nl_put_driver_u32(msg, "in_use", wq->rq.in_use)) |
| 85 | + goto err; |
| 86 | + if (rdma_nl_put_driver_u32(msg, "size", wq->rq.size)) |
| 87 | + goto err; |
| 88 | + return 0; |
| 89 | +err: |
| 90 | + return -EMSGSIZE; |
| 91 | +} |
| 92 | + |
| 93 | +static int fill_swsqe(struct sk_buff *msg, struct t4_sq *sq, u16 idx, |
| 94 | + struct t4_swsqe *sqe) |
| 95 | +{ |
| 96 | + if (rdma_nl_put_driver_u32(msg, "idx", idx)) |
| 97 | + goto err; |
| 98 | + if (rdma_nl_put_driver_u32(msg, "opcode", sqe->opcode)) |
| 99 | + goto err; |
| 100 | + if (rdma_nl_put_driver_u64_hex(msg, "wr_id", sqe->wr_id)) |
| 101 | + goto err; |
| 102 | + if (rdma_nl_put_driver_u32(msg, "complete", sqe->complete)) |
| 103 | + goto err; |
| 104 | + if (sqe->complete && |
| 105 | + rdma_nl_put_driver_u32(msg, "cqe_status", CQE_STATUS(&sqe->cqe))) |
| 106 | + goto err; |
| 107 | + if (rdma_nl_put_driver_u32(msg, "signaled", sqe->signaled)) |
| 108 | + goto err; |
| 109 | + if (rdma_nl_put_driver_u32(msg, "flushed", sqe->flushed)) |
| 110 | + goto err; |
| 111 | + return 0; |
| 112 | +err: |
| 113 | + return -EMSGSIZE; |
| 114 | +} |
| 115 | + |
| 116 | +/* |
| 117 | + * Dump the first and last pending sqes. |
| 118 | + */ |
| 119 | +static int fill_swsqes(struct sk_buff *msg, struct t4_sq *sq, |
| 120 | + u16 first_idx, struct t4_swsqe *first_sqe, |
| 121 | + u16 last_idx, struct t4_swsqe *last_sqe) |
| 122 | +{ |
| 123 | + if (!first_sqe) |
| 124 | + goto out; |
| 125 | + if (fill_swsqe(msg, sq, first_idx, first_sqe)) |
| 126 | + goto err; |
| 127 | + if (!last_sqe) |
| 128 | + goto out; |
| 129 | + if (fill_swsqe(msg, sq, last_idx, last_sqe)) |
| 130 | + goto err; |
| 131 | +out: |
| 132 | + return 0; |
| 133 | +err: |
| 134 | + return -EMSGSIZE; |
| 135 | +} |
| 136 | + |
| 137 | +static int fill_swrqe(struct sk_buff *msg, struct t4_rq *rq, u16 idx, |
| 138 | + struct t4_swrqe *rqe) |
| 139 | +{ |
| 140 | + if (rdma_nl_put_driver_u32(msg, "idx", idx)) |
| 141 | + goto err; |
| 142 | + if (rdma_nl_put_driver_u64_hex(msg, "wr_id", rqe->wr_id)) |
| 143 | + goto err; |
| 144 | + return 0; |
| 145 | +err: |
| 146 | + return -EMSGSIZE; |
| 147 | +} |
| 148 | + |
| 149 | +/* |
| 150 | + * Dump the first and last pending rqes. |
| 151 | + */ |
| 152 | +static int fill_swrqes(struct sk_buff *msg, struct t4_rq *rq, |
| 153 | + u16 first_idx, struct t4_swrqe *first_rqe, |
| 154 | + u16 last_idx, struct t4_swrqe *last_rqe) |
| 155 | +{ |
| 156 | + if (!first_rqe) |
| 157 | + goto out; |
| 158 | + if (fill_swrqe(msg, rq, first_idx, first_rqe)) |
| 159 | + goto err; |
| 160 | + if (!last_rqe) |
| 161 | + goto out; |
| 162 | + if (fill_swrqe(msg, rq, last_idx, last_rqe)) |
| 163 | + goto err; |
| 164 | +out: |
| 165 | + return 0; |
| 166 | +err: |
| 167 | + return -EMSGSIZE; |
| 168 | +} |
| 169 | + |
| 170 | +static int fill_res_qp_entry(struct sk_buff *msg, |
| 171 | + struct rdma_restrack_entry *res) |
| 172 | +{ |
| 173 | + struct ib_qp *ibqp = container_of(res, struct ib_qp, res); |
| 174 | + struct t4_swsqe *fsp = NULL, *lsp = NULL; |
| 175 | + struct t4_swrqe *frp = NULL, *lrp = NULL; |
| 176 | + struct c4iw_qp *qhp = to_c4iw_qp(ibqp); |
| 177 | + struct t4_swsqe first_sqe, last_sqe; |
| 178 | + struct t4_swrqe first_rqe, last_rqe; |
| 179 | + u16 first_sq_idx, last_sq_idx; |
| 180 | + u16 first_rq_idx, last_rq_idx; |
| 181 | + struct nlattr *table_attr; |
| 182 | + struct t4_wq wq; |
| 183 | + |
| 184 | + /* User qp state is not available, so don't dump user qps */ |
| 185 | + if (qhp->ucontext) |
| 186 | + return 0; |
| 187 | + |
| 188 | + table_attr = nla_nest_start(msg, RDMA_NLDEV_ATTR_DRIVER); |
| 189 | + if (!table_attr) |
| 190 | + goto err; |
| 191 | + |
| 192 | + /* Get a consistent snapshot */ |
| 193 | + spin_lock_irq(&qhp->lock); |
| 194 | + wq = qhp->wq; |
| 195 | + |
| 196 | + /* If there are any pending sqes, copy the first and last */ |
| 197 | + if (wq.sq.cidx != wq.sq.pidx) { |
| 198 | + first_sq_idx = wq.sq.cidx; |
| 199 | + first_sqe = qhp->wq.sq.sw_sq[first_sq_idx]; |
| 200 | + fsp = &first_sqe; |
| 201 | + last_sq_idx = wq.sq.pidx; |
| 202 | + if (last_sq_idx-- == 0) |
| 203 | + last_sq_idx = wq.sq.size - 1; |
| 204 | + if (last_sq_idx != first_sq_idx) { |
| 205 | + last_sqe = qhp->wq.sq.sw_sq[last_sq_idx]; |
| 206 | + lsp = &last_sqe; |
| 207 | + } |
| 208 | + } |
| 209 | + |
| 210 | + /* If there are any pending rqes, copy the first and last */ |
| 211 | + if (wq.rq.cidx != wq.rq.pidx) { |
| 212 | + first_rq_idx = wq.rq.cidx; |
| 213 | + first_rqe = qhp->wq.rq.sw_rq[first_rq_idx]; |
| 214 | + frp = &first_rqe; |
| 215 | + last_rq_idx = wq.rq.pidx; |
| 216 | + if (last_rq_idx-- == 0) |
| 217 | + last_rq_idx = wq.rq.size - 1; |
| 218 | + if (last_rq_idx != first_rq_idx) { |
| 219 | + last_rqe = qhp->wq.rq.sw_rq[last_rq_idx]; |
| 220 | + lrp = &last_rqe; |
| 221 | + } |
| 222 | + } |
| 223 | + spin_unlock_irq(&qhp->lock); |
| 224 | + |
| 225 | + if (fill_sq(msg, &wq)) |
| 226 | + goto err_cancel_table; |
| 227 | + |
| 228 | + if (fill_swsqes(msg, &wq.sq, first_sq_idx, fsp, last_sq_idx, lsp)) |
| 229 | + goto err_cancel_table; |
| 230 | + |
| 231 | + if (fill_rq(msg, &wq)) |
| 232 | + goto err_cancel_table; |
| 233 | + |
| 234 | + if (fill_swrqes(msg, &wq.rq, first_rq_idx, frp, last_rq_idx, lrp)) |
| 235 | + goto err_cancel_table; |
| 236 | + |
| 237 | + nla_nest_end(msg, table_attr); |
| 238 | + return 0; |
| 239 | + |
| 240 | +err_cancel_table: |
| 241 | + nla_nest_cancel(msg, table_attr); |
| 242 | +err: |
| 243 | + return -EMSGSIZE; |
| 244 | +} |
| 245 | + |
| 246 | +c4iw_restrack_func *c4iw_restrack_funcs[RDMA_RESTRACK_MAX] = { |
| 247 | + [RDMA_RESTRACK_QP] = fill_res_qp_entry, |
| 248 | +}; |
0 commit comments