Kalderon, Michal | 67b40dc | 2017-07-02 10:29:22 +0300 | [diff] [blame] | 1 | /* QLogic qed NIC Driver |
| 2 | * Copyright (c) 2015-2017 QLogic Corporation |
| 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 | */ |
Kalderon, Michal | b5c29ca | 2017-07-02 10:29:25 +0300 | [diff] [blame] | 32 | #include <linux/if_ether.h> |
| 33 | #include <linux/if_vlan.h> |
Kalderon, Michal | 65a91a6 | 2017-07-02 10:29:26 +0300 | [diff] [blame] | 34 | #include <linux/ip.h> |
| 35 | #include <linux/ipv6.h> |
| 36 | #include <linux/spinlock.h> |
| 37 | #include <linux/tcp.h> |
Kalderon, Michal | 67b40dc | 2017-07-02 10:29:22 +0300 | [diff] [blame] | 38 | #include "qed_cxt.h" |
| 39 | #include "qed_hw.h" |
Kalderon, Michal | b5c29ca | 2017-07-02 10:29:25 +0300 | [diff] [blame] | 40 | #include "qed_ll2.h" |
Kalderon, Michal | 67b40dc | 2017-07-02 10:29:22 +0300 | [diff] [blame] | 41 | #include "qed_rdma.h" |
| 42 | #include "qed_reg_addr.h" |
| 43 | #include "qed_sp.h" |
| 44 | |
| 45 | #define QED_IWARP_ORD_DEFAULT 32 |
| 46 | #define QED_IWARP_IRD_DEFAULT 32 |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 47 | #define QED_IWARP_MAX_FW_MSS 4120 |
| 48 | |
| 49 | #define QED_EP_SIG 0xecabcdef |
| 50 | |
| 51 | struct mpa_v2_hdr { |
| 52 | __be16 ird; |
| 53 | __be16 ord; |
| 54 | }; |
| 55 | |
| 56 | #define MPA_V2_PEER2PEER_MODEL 0x8000 |
| 57 | #define MPA_V2_SEND_RTR 0x4000 /* on ird */ |
| 58 | #define MPA_V2_READ_RTR 0x4000 /* on ord */ |
| 59 | #define MPA_V2_WRITE_RTR 0x8000 |
| 60 | #define MPA_V2_IRD_ORD_MASK 0x3FFF |
| 61 | |
| 62 | #define MPA_REV2(_mpa_rev) ((_mpa_rev) == MPA_NEGOTIATION_TYPE_ENHANCED) |
| 63 | |
| 64 | #define QED_IWARP_INVALID_TCP_CID 0xffffffff |
Kalderon, Michal | 67b40dc | 2017-07-02 10:29:22 +0300 | [diff] [blame] | 65 | #define QED_IWARP_RCV_WND_SIZE_DEF (256 * 1024) |
| 66 | #define QED_IWARP_RCV_WND_SIZE_MIN (64 * 1024) |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 67 | #define TIMESTAMP_HEADER_SIZE (12) |
| 68 | |
Kalderon, Michal | 67b40dc | 2017-07-02 10:29:22 +0300 | [diff] [blame] | 69 | #define QED_IWARP_TS_EN BIT(0) |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 70 | #define QED_IWARP_DA_EN BIT(1) |
Kalderon, Michal | 67b40dc | 2017-07-02 10:29:22 +0300 | [diff] [blame] | 71 | #define QED_IWARP_PARAM_CRC_NEEDED (1) |
| 72 | #define QED_IWARP_PARAM_P2P (1) |
| 73 | |
| 74 | static int qed_iwarp_async_event(struct qed_hwfn *p_hwfn, |
| 75 | u8 fw_event_code, u16 echo, |
| 76 | union event_ring_data *data, |
| 77 | u8 fw_return_code); |
| 78 | |
| 79 | /* Override devinfo with iWARP specific values */ |
| 80 | void qed_iwarp_init_devinfo(struct qed_hwfn *p_hwfn) |
| 81 | { |
| 82 | struct qed_rdma_device *dev = p_hwfn->p_rdma_info->dev; |
| 83 | |
| 84 | dev->max_inline = IWARP_REQ_MAX_INLINE_DATA_SIZE; |
| 85 | dev->max_qp = min_t(u32, |
| 86 | IWARP_MAX_QPS, |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 87 | p_hwfn->p_rdma_info->num_qps) - |
| 88 | QED_IWARP_PREALLOC_CNT; |
Kalderon, Michal | 67b40dc | 2017-07-02 10:29:22 +0300 | [diff] [blame] | 89 | |
| 90 | dev->max_cq = dev->max_qp; |
| 91 | |
| 92 | dev->max_qp_resp_rd_atomic_resc = QED_IWARP_IRD_DEFAULT; |
| 93 | dev->max_qp_req_rd_atomic_resc = QED_IWARP_ORD_DEFAULT; |
| 94 | } |
| 95 | |
| 96 | void qed_iwarp_init_hw(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
| 97 | { |
| 98 | p_hwfn->rdma_prs_search_reg = PRS_REG_SEARCH_TCP; |
| 99 | qed_wr(p_hwfn, p_ptt, p_hwfn->rdma_prs_search_reg, 1); |
| 100 | p_hwfn->b_rdma_enabled_in_prs = true; |
| 101 | } |
| 102 | |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 103 | /* We have two cid maps, one for tcp which should be used only from passive |
| 104 | * syn processing and replacing a pre-allocated ep in the list. The second |
| 105 | * for active tcp and for QPs. |
| 106 | */ |
Kalderon, Michal | 67b40dc | 2017-07-02 10:29:22 +0300 | [diff] [blame] | 107 | static void qed_iwarp_cid_cleaned(struct qed_hwfn *p_hwfn, u32 cid) |
| 108 | { |
| 109 | cid -= qed_cxt_get_proto_cid_start(p_hwfn, p_hwfn->p_rdma_info->proto); |
| 110 | |
| 111 | spin_lock_bh(&p_hwfn->p_rdma_info->lock); |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 112 | |
| 113 | if (cid < QED_IWARP_PREALLOC_CNT) |
| 114 | qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->tcp_cid_map, |
| 115 | cid); |
| 116 | else |
| 117 | qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->cid_map, cid); |
| 118 | |
Kalderon, Michal | 67b40dc | 2017-07-02 10:29:22 +0300 | [diff] [blame] | 119 | spin_unlock_bh(&p_hwfn->p_rdma_info->lock); |
| 120 | } |
| 121 | |
| 122 | static int qed_iwarp_alloc_cid(struct qed_hwfn *p_hwfn, u32 *cid) |
| 123 | { |
| 124 | int rc; |
| 125 | |
| 126 | spin_lock_bh(&p_hwfn->p_rdma_info->lock); |
| 127 | rc = qed_rdma_bmap_alloc_id(p_hwfn, &p_hwfn->p_rdma_info->cid_map, cid); |
| 128 | spin_unlock_bh(&p_hwfn->p_rdma_info->lock); |
| 129 | if (rc) { |
| 130 | DP_NOTICE(p_hwfn, "Failed in allocating iwarp cid\n"); |
| 131 | return rc; |
| 132 | } |
| 133 | *cid += qed_cxt_get_proto_cid_start(p_hwfn, p_hwfn->p_rdma_info->proto); |
| 134 | |
| 135 | rc = qed_cxt_dynamic_ilt_alloc(p_hwfn, QED_ELEM_CXT, *cid); |
| 136 | if (rc) |
| 137 | qed_iwarp_cid_cleaned(p_hwfn, *cid); |
| 138 | |
| 139 | return rc; |
| 140 | } |
| 141 | |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 142 | static void qed_iwarp_set_tcp_cid(struct qed_hwfn *p_hwfn, u32 cid) |
| 143 | { |
| 144 | cid -= qed_cxt_get_proto_cid_start(p_hwfn, p_hwfn->p_rdma_info->proto); |
| 145 | |
| 146 | spin_lock_bh(&p_hwfn->p_rdma_info->lock); |
| 147 | qed_bmap_set_id(p_hwfn, &p_hwfn->p_rdma_info->tcp_cid_map, cid); |
| 148 | spin_unlock_bh(&p_hwfn->p_rdma_info->lock); |
| 149 | } |
| 150 | |
| 151 | /* This function allocates a cid for passive tcp (called from syn receive) |
| 152 | * the reason it's separate from the regular cid allocation is because it |
| 153 | * is assured that these cids already have ilt allocated. They are preallocated |
| 154 | * to ensure that we won't need to allocate memory during syn processing |
| 155 | */ |
| 156 | static int qed_iwarp_alloc_tcp_cid(struct qed_hwfn *p_hwfn, u32 *cid) |
| 157 | { |
| 158 | int rc; |
| 159 | |
| 160 | spin_lock_bh(&p_hwfn->p_rdma_info->lock); |
| 161 | |
| 162 | rc = qed_rdma_bmap_alloc_id(p_hwfn, |
| 163 | &p_hwfn->p_rdma_info->tcp_cid_map, cid); |
| 164 | |
| 165 | spin_unlock_bh(&p_hwfn->p_rdma_info->lock); |
| 166 | |
| 167 | if (rc) { |
| 168 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 169 | "can't allocate iwarp tcp cid max-count=%d\n", |
| 170 | p_hwfn->p_rdma_info->tcp_cid_map.max_count); |
| 171 | |
| 172 | *cid = QED_IWARP_INVALID_TCP_CID; |
| 173 | return rc; |
| 174 | } |
| 175 | |
| 176 | *cid += qed_cxt_get_proto_cid_start(p_hwfn, |
| 177 | p_hwfn->p_rdma_info->proto); |
| 178 | return 0; |
| 179 | } |
| 180 | |
Kalderon, Michal | 67b40dc | 2017-07-02 10:29:22 +0300 | [diff] [blame] | 181 | int qed_iwarp_create_qp(struct qed_hwfn *p_hwfn, |
| 182 | struct qed_rdma_qp *qp, |
| 183 | struct qed_rdma_create_qp_out_params *out_params) |
| 184 | { |
| 185 | struct iwarp_create_qp_ramrod_data *p_ramrod; |
| 186 | struct qed_sp_init_data init_data; |
| 187 | struct qed_spq_entry *p_ent; |
| 188 | u16 physical_queue; |
| 189 | u32 cid; |
| 190 | int rc; |
| 191 | |
| 192 | qp->shared_queue = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev, |
| 193 | IWARP_SHARED_QUEUE_PAGE_SIZE, |
| 194 | &qp->shared_queue_phys_addr, |
| 195 | GFP_KERNEL); |
| 196 | if (!qp->shared_queue) |
| 197 | return -ENOMEM; |
| 198 | |
| 199 | out_params->sq_pbl_virt = (u8 *)qp->shared_queue + |
| 200 | IWARP_SHARED_QUEUE_PAGE_SQ_PBL_OFFSET; |
| 201 | out_params->sq_pbl_phys = qp->shared_queue_phys_addr + |
| 202 | IWARP_SHARED_QUEUE_PAGE_SQ_PBL_OFFSET; |
| 203 | out_params->rq_pbl_virt = (u8 *)qp->shared_queue + |
| 204 | IWARP_SHARED_QUEUE_PAGE_RQ_PBL_OFFSET; |
| 205 | out_params->rq_pbl_phys = qp->shared_queue_phys_addr + |
| 206 | IWARP_SHARED_QUEUE_PAGE_RQ_PBL_OFFSET; |
| 207 | |
| 208 | rc = qed_iwarp_alloc_cid(p_hwfn, &cid); |
| 209 | if (rc) |
| 210 | goto err1; |
| 211 | |
| 212 | qp->icid = (u16)cid; |
| 213 | |
| 214 | memset(&init_data, 0, sizeof(init_data)); |
| 215 | init_data.opaque_fid = p_hwfn->hw_info.opaque_fid; |
| 216 | init_data.cid = qp->icid; |
| 217 | init_data.comp_mode = QED_SPQ_MODE_EBLOCK; |
| 218 | |
| 219 | rc = qed_sp_init_request(p_hwfn, &p_ent, |
| 220 | IWARP_RAMROD_CMD_ID_CREATE_QP, |
| 221 | PROTOCOLID_IWARP, &init_data); |
| 222 | if (rc) |
| 223 | goto err2; |
| 224 | |
| 225 | p_ramrod = &p_ent->ramrod.iwarp_create_qp; |
| 226 | |
| 227 | SET_FIELD(p_ramrod->flags, |
| 228 | IWARP_CREATE_QP_RAMROD_DATA_FMR_AND_RESERVED_EN, |
| 229 | qp->fmr_and_reserved_lkey); |
| 230 | |
| 231 | SET_FIELD(p_ramrod->flags, |
| 232 | IWARP_CREATE_QP_RAMROD_DATA_SIGNALED_COMP, qp->signal_all); |
| 233 | |
| 234 | SET_FIELD(p_ramrod->flags, |
| 235 | IWARP_CREATE_QP_RAMROD_DATA_RDMA_RD_EN, |
| 236 | qp->incoming_rdma_read_en); |
| 237 | |
| 238 | SET_FIELD(p_ramrod->flags, |
| 239 | IWARP_CREATE_QP_RAMROD_DATA_RDMA_WR_EN, |
| 240 | qp->incoming_rdma_write_en); |
| 241 | |
| 242 | SET_FIELD(p_ramrod->flags, |
| 243 | IWARP_CREATE_QP_RAMROD_DATA_ATOMIC_EN, |
| 244 | qp->incoming_atomic_en); |
| 245 | |
| 246 | SET_FIELD(p_ramrod->flags, |
| 247 | IWARP_CREATE_QP_RAMROD_DATA_SRQ_FLG, qp->use_srq); |
| 248 | |
| 249 | p_ramrod->pd = qp->pd; |
| 250 | p_ramrod->sq_num_pages = qp->sq_num_pages; |
| 251 | p_ramrod->rq_num_pages = qp->rq_num_pages; |
| 252 | |
| 253 | p_ramrod->qp_handle_for_cqe.hi = cpu_to_le32(qp->qp_handle.hi); |
| 254 | p_ramrod->qp_handle_for_cqe.lo = cpu_to_le32(qp->qp_handle.lo); |
| 255 | |
| 256 | p_ramrod->cq_cid_for_sq = |
| 257 | cpu_to_le32((p_hwfn->hw_info.opaque_fid << 16) | qp->sq_cq_id); |
| 258 | p_ramrod->cq_cid_for_rq = |
| 259 | cpu_to_le32((p_hwfn->hw_info.opaque_fid << 16) | qp->rq_cq_id); |
| 260 | |
| 261 | p_ramrod->dpi = cpu_to_le16(qp->dpi); |
| 262 | |
| 263 | physical_queue = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_OFLD); |
| 264 | p_ramrod->physical_q0 = cpu_to_le16(physical_queue); |
| 265 | physical_queue = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_ACK); |
| 266 | p_ramrod->physical_q1 = cpu_to_le16(physical_queue); |
| 267 | |
| 268 | rc = qed_spq_post(p_hwfn, p_ent, NULL); |
| 269 | if (rc) |
| 270 | goto err2; |
| 271 | |
| 272 | return rc; |
| 273 | |
| 274 | err2: |
| 275 | qed_iwarp_cid_cleaned(p_hwfn, cid); |
| 276 | err1: |
| 277 | dma_free_coherent(&p_hwfn->cdev->pdev->dev, |
| 278 | IWARP_SHARED_QUEUE_PAGE_SIZE, |
| 279 | qp->shared_queue, qp->shared_queue_phys_addr); |
| 280 | |
| 281 | return rc; |
| 282 | } |
| 283 | |
| 284 | static int qed_iwarp_modify_fw(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp) |
| 285 | { |
| 286 | struct iwarp_modify_qp_ramrod_data *p_ramrod; |
| 287 | struct qed_sp_init_data init_data; |
| 288 | struct qed_spq_entry *p_ent; |
| 289 | int rc; |
| 290 | |
| 291 | /* Get SPQ entry */ |
| 292 | memset(&init_data, 0, sizeof(init_data)); |
| 293 | init_data.cid = qp->icid; |
| 294 | init_data.opaque_fid = p_hwfn->hw_info.opaque_fid; |
| 295 | init_data.comp_mode = QED_SPQ_MODE_EBLOCK; |
| 296 | |
| 297 | rc = qed_sp_init_request(p_hwfn, &p_ent, |
| 298 | IWARP_RAMROD_CMD_ID_MODIFY_QP, |
| 299 | p_hwfn->p_rdma_info->proto, &init_data); |
| 300 | if (rc) |
| 301 | return rc; |
| 302 | |
| 303 | p_ramrod = &p_ent->ramrod.iwarp_modify_qp; |
| 304 | SET_FIELD(p_ramrod->flags, IWARP_MODIFY_QP_RAMROD_DATA_STATE_TRANS_EN, |
| 305 | 0x1); |
| 306 | if (qp->iwarp_state == QED_IWARP_QP_STATE_CLOSING) |
| 307 | p_ramrod->transition_to_state = IWARP_MODIFY_QP_STATE_CLOSING; |
| 308 | else |
| 309 | p_ramrod->transition_to_state = IWARP_MODIFY_QP_STATE_ERROR; |
| 310 | |
| 311 | rc = qed_spq_post(p_hwfn, p_ent, NULL); |
| 312 | |
| 313 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP(0x%x)rc=%d\n", qp->icid, rc); |
| 314 | |
| 315 | return rc; |
| 316 | } |
| 317 | |
| 318 | enum qed_iwarp_qp_state qed_roce2iwarp_state(enum qed_roce_qp_state state) |
| 319 | { |
| 320 | switch (state) { |
| 321 | case QED_ROCE_QP_STATE_RESET: |
| 322 | case QED_ROCE_QP_STATE_INIT: |
| 323 | case QED_ROCE_QP_STATE_RTR: |
| 324 | return QED_IWARP_QP_STATE_IDLE; |
| 325 | case QED_ROCE_QP_STATE_RTS: |
| 326 | return QED_IWARP_QP_STATE_RTS; |
| 327 | case QED_ROCE_QP_STATE_SQD: |
| 328 | return QED_IWARP_QP_STATE_CLOSING; |
| 329 | case QED_ROCE_QP_STATE_ERR: |
| 330 | return QED_IWARP_QP_STATE_ERROR; |
| 331 | case QED_ROCE_QP_STATE_SQE: |
| 332 | return QED_IWARP_QP_STATE_TERMINATE; |
| 333 | default: |
| 334 | return QED_IWARP_QP_STATE_ERROR; |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | static enum qed_roce_qp_state |
| 339 | qed_iwarp2roce_state(enum qed_iwarp_qp_state state) |
| 340 | { |
| 341 | switch (state) { |
| 342 | case QED_IWARP_QP_STATE_IDLE: |
| 343 | return QED_ROCE_QP_STATE_INIT; |
| 344 | case QED_IWARP_QP_STATE_RTS: |
| 345 | return QED_ROCE_QP_STATE_RTS; |
| 346 | case QED_IWARP_QP_STATE_TERMINATE: |
| 347 | return QED_ROCE_QP_STATE_SQE; |
| 348 | case QED_IWARP_QP_STATE_CLOSING: |
| 349 | return QED_ROCE_QP_STATE_SQD; |
| 350 | case QED_IWARP_QP_STATE_ERROR: |
| 351 | return QED_ROCE_QP_STATE_ERR; |
| 352 | default: |
| 353 | return QED_ROCE_QP_STATE_ERR; |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | const char *iwarp_state_names[] = { |
| 358 | "IDLE", |
| 359 | "RTS", |
| 360 | "TERMINATE", |
| 361 | "CLOSING", |
| 362 | "ERROR", |
| 363 | }; |
| 364 | |
| 365 | int |
| 366 | qed_iwarp_modify_qp(struct qed_hwfn *p_hwfn, |
| 367 | struct qed_rdma_qp *qp, |
| 368 | enum qed_iwarp_qp_state new_state, bool internal) |
| 369 | { |
| 370 | enum qed_iwarp_qp_state prev_iw_state; |
| 371 | bool modify_fw = false; |
| 372 | int rc = 0; |
| 373 | |
| 374 | /* modify QP can be called from upper-layer or as a result of async |
| 375 | * RST/FIN... therefore need to protect |
| 376 | */ |
| 377 | spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.qp_lock); |
| 378 | prev_iw_state = qp->iwarp_state; |
| 379 | |
| 380 | if (prev_iw_state == new_state) { |
| 381 | spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.qp_lock); |
| 382 | return 0; |
| 383 | } |
| 384 | |
| 385 | switch (prev_iw_state) { |
| 386 | case QED_IWARP_QP_STATE_IDLE: |
| 387 | switch (new_state) { |
| 388 | case QED_IWARP_QP_STATE_RTS: |
| 389 | qp->iwarp_state = QED_IWARP_QP_STATE_RTS; |
| 390 | break; |
| 391 | case QED_IWARP_QP_STATE_ERROR: |
| 392 | qp->iwarp_state = QED_IWARP_QP_STATE_ERROR; |
| 393 | if (!internal) |
| 394 | modify_fw = true; |
| 395 | break; |
| 396 | default: |
| 397 | break; |
| 398 | } |
| 399 | break; |
| 400 | case QED_IWARP_QP_STATE_RTS: |
| 401 | switch (new_state) { |
| 402 | case QED_IWARP_QP_STATE_CLOSING: |
| 403 | if (!internal) |
| 404 | modify_fw = true; |
| 405 | |
| 406 | qp->iwarp_state = QED_IWARP_QP_STATE_CLOSING; |
| 407 | break; |
| 408 | case QED_IWARP_QP_STATE_ERROR: |
| 409 | if (!internal) |
| 410 | modify_fw = true; |
| 411 | qp->iwarp_state = QED_IWARP_QP_STATE_ERROR; |
| 412 | break; |
| 413 | default: |
| 414 | break; |
| 415 | } |
| 416 | break; |
| 417 | case QED_IWARP_QP_STATE_ERROR: |
| 418 | switch (new_state) { |
| 419 | case QED_IWARP_QP_STATE_IDLE: |
| 420 | |
| 421 | qp->iwarp_state = new_state; |
| 422 | break; |
| 423 | case QED_IWARP_QP_STATE_CLOSING: |
| 424 | /* could happen due to race... do nothing.... */ |
| 425 | break; |
| 426 | default: |
| 427 | rc = -EINVAL; |
| 428 | } |
| 429 | break; |
| 430 | case QED_IWARP_QP_STATE_TERMINATE: |
| 431 | case QED_IWARP_QP_STATE_CLOSING: |
| 432 | qp->iwarp_state = new_state; |
| 433 | break; |
| 434 | default: |
| 435 | break; |
| 436 | } |
| 437 | |
| 438 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP(0x%x) %s --> %s%s\n", |
| 439 | qp->icid, |
| 440 | iwarp_state_names[prev_iw_state], |
| 441 | iwarp_state_names[qp->iwarp_state], |
| 442 | internal ? "internal" : ""); |
| 443 | |
| 444 | spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.qp_lock); |
| 445 | |
| 446 | if (modify_fw) |
| 447 | rc = qed_iwarp_modify_fw(p_hwfn, qp); |
| 448 | |
| 449 | return rc; |
| 450 | } |
| 451 | |
| 452 | int qed_iwarp_fw_destroy(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp) |
| 453 | { |
| 454 | struct qed_sp_init_data init_data; |
| 455 | struct qed_spq_entry *p_ent; |
| 456 | int rc; |
| 457 | |
| 458 | /* Get SPQ entry */ |
| 459 | memset(&init_data, 0, sizeof(init_data)); |
| 460 | init_data.cid = qp->icid; |
| 461 | init_data.opaque_fid = p_hwfn->hw_info.opaque_fid; |
| 462 | init_data.comp_mode = QED_SPQ_MODE_EBLOCK; |
| 463 | |
| 464 | rc = qed_sp_init_request(p_hwfn, &p_ent, |
| 465 | IWARP_RAMROD_CMD_ID_DESTROY_QP, |
| 466 | p_hwfn->p_rdma_info->proto, &init_data); |
| 467 | if (rc) |
| 468 | return rc; |
| 469 | |
| 470 | rc = qed_spq_post(p_hwfn, p_ent, NULL); |
| 471 | |
| 472 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP(0x%x) rc = %d\n", qp->icid, rc); |
| 473 | |
| 474 | return rc; |
| 475 | } |
| 476 | |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 477 | static void qed_iwarp_destroy_ep(struct qed_hwfn *p_hwfn, |
| 478 | struct qed_iwarp_ep *ep, |
| 479 | bool remove_from_active_list) |
| 480 | { |
| 481 | dma_free_coherent(&p_hwfn->cdev->pdev->dev, |
| 482 | sizeof(*ep->ep_buffer_virt), |
| 483 | ep->ep_buffer_virt, ep->ep_buffer_phys); |
| 484 | |
| 485 | if (remove_from_active_list) { |
| 486 | spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock); |
| 487 | list_del(&ep->list_entry); |
| 488 | spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock); |
| 489 | } |
| 490 | |
| 491 | if (ep->qp) |
| 492 | ep->qp->ep = NULL; |
| 493 | |
| 494 | kfree(ep); |
| 495 | } |
| 496 | |
Kalderon, Michal | 67b40dc | 2017-07-02 10:29:22 +0300 | [diff] [blame] | 497 | int qed_iwarp_destroy_qp(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp) |
| 498 | { |
Kalderon, Michal | fc4c606 | 2017-07-02 10:29:29 +0300 | [diff] [blame^] | 499 | struct qed_iwarp_ep *ep = qp->ep; |
| 500 | int wait_count = 0; |
Kalderon, Michal | 67b40dc | 2017-07-02 10:29:22 +0300 | [diff] [blame] | 501 | int rc = 0; |
| 502 | |
| 503 | if (qp->iwarp_state != QED_IWARP_QP_STATE_ERROR) { |
| 504 | rc = qed_iwarp_modify_qp(p_hwfn, qp, |
| 505 | QED_IWARP_QP_STATE_ERROR, false); |
| 506 | if (rc) |
| 507 | return rc; |
| 508 | } |
| 509 | |
Kalderon, Michal | fc4c606 | 2017-07-02 10:29:29 +0300 | [diff] [blame^] | 510 | /* Make sure ep is closed before returning and freeing memory. */ |
| 511 | if (ep) { |
| 512 | while (ep->state != QED_IWARP_EP_CLOSED && wait_count++ < 200) |
| 513 | msleep(100); |
| 514 | |
| 515 | if (ep->state != QED_IWARP_EP_CLOSED) |
| 516 | DP_NOTICE(p_hwfn, "ep state close timeout state=%x\n", |
| 517 | ep->state); |
| 518 | |
| 519 | qed_iwarp_destroy_ep(p_hwfn, ep, false); |
| 520 | } |
| 521 | |
Kalderon, Michal | 67b40dc | 2017-07-02 10:29:22 +0300 | [diff] [blame] | 522 | rc = qed_iwarp_fw_destroy(p_hwfn, qp); |
| 523 | |
| 524 | if (qp->shared_queue) |
| 525 | dma_free_coherent(&p_hwfn->cdev->pdev->dev, |
| 526 | IWARP_SHARED_QUEUE_PAGE_SIZE, |
| 527 | qp->shared_queue, qp->shared_queue_phys_addr); |
| 528 | |
| 529 | return rc; |
| 530 | } |
| 531 | |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 532 | static int |
| 533 | qed_iwarp_create_ep(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep **ep_out) |
| 534 | { |
| 535 | struct qed_iwarp_ep *ep; |
| 536 | int rc; |
| 537 | |
| 538 | ep = kzalloc(sizeof(*ep), GFP_KERNEL); |
| 539 | if (!ep) |
| 540 | return -ENOMEM; |
| 541 | |
| 542 | ep->state = QED_IWARP_EP_INIT; |
| 543 | |
| 544 | ep->ep_buffer_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev, |
| 545 | sizeof(*ep->ep_buffer_virt), |
| 546 | &ep->ep_buffer_phys, |
| 547 | GFP_KERNEL); |
| 548 | if (!ep->ep_buffer_virt) { |
| 549 | rc = -ENOMEM; |
| 550 | goto err; |
| 551 | } |
| 552 | |
| 553 | ep->sig = QED_EP_SIG; |
| 554 | |
| 555 | *ep_out = ep; |
| 556 | |
| 557 | return 0; |
| 558 | |
| 559 | err: |
| 560 | kfree(ep); |
| 561 | return rc; |
| 562 | } |
| 563 | |
| 564 | static void |
| 565 | qed_iwarp_print_tcp_ramrod(struct qed_hwfn *p_hwfn, |
| 566 | struct iwarp_tcp_offload_ramrod_data *p_tcp_ramrod) |
| 567 | { |
| 568 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "local_mac=%x %x %x, remote_mac=%x %x %x\n", |
| 569 | p_tcp_ramrod->tcp.local_mac_addr_lo, |
| 570 | p_tcp_ramrod->tcp.local_mac_addr_mid, |
| 571 | p_tcp_ramrod->tcp.local_mac_addr_hi, |
| 572 | p_tcp_ramrod->tcp.remote_mac_addr_lo, |
| 573 | p_tcp_ramrod->tcp.remote_mac_addr_mid, |
| 574 | p_tcp_ramrod->tcp.remote_mac_addr_hi); |
| 575 | |
| 576 | if (p_tcp_ramrod->tcp.ip_version == TCP_IPV4) { |
| 577 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 578 | "local_ip=%pI4h:%x, remote_ip=%pI4h%x, vlan=%x\n", |
| 579 | p_tcp_ramrod->tcp.local_ip, |
| 580 | p_tcp_ramrod->tcp.local_port, |
| 581 | p_tcp_ramrod->tcp.remote_ip, |
| 582 | p_tcp_ramrod->tcp.remote_port, |
| 583 | p_tcp_ramrod->tcp.vlan_id); |
| 584 | } else { |
| 585 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 586 | "local_ip=%pI6h:%x, remote_ip=%pI6h:%x, vlan=%x\n", |
| 587 | p_tcp_ramrod->tcp.local_ip, |
| 588 | p_tcp_ramrod->tcp.local_port, |
| 589 | p_tcp_ramrod->tcp.remote_ip, |
| 590 | p_tcp_ramrod->tcp.remote_port, |
| 591 | p_tcp_ramrod->tcp.vlan_id); |
| 592 | } |
| 593 | |
| 594 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 595 | "flow_label=%x, ttl=%x, tos_or_tc=%x, mss=%x, rcv_wnd_scale=%x, connect_mode=%x, flags=%x\n", |
| 596 | p_tcp_ramrod->tcp.flow_label, |
| 597 | p_tcp_ramrod->tcp.ttl, |
| 598 | p_tcp_ramrod->tcp.tos_or_tc, |
| 599 | p_tcp_ramrod->tcp.mss, |
| 600 | p_tcp_ramrod->tcp.rcv_wnd_scale, |
| 601 | p_tcp_ramrod->tcp.connect_mode, |
| 602 | p_tcp_ramrod->tcp.flags); |
| 603 | |
| 604 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "syn_ip_payload_length=%x, lo=%x, hi=%x\n", |
| 605 | p_tcp_ramrod->tcp.syn_ip_payload_length, |
| 606 | p_tcp_ramrod->tcp.syn_phy_addr_lo, |
| 607 | p_tcp_ramrod->tcp.syn_phy_addr_hi); |
| 608 | } |
| 609 | |
| 610 | static int |
| 611 | qed_iwarp_tcp_offload(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep) |
| 612 | { |
| 613 | struct qed_iwarp_info *iwarp_info = &p_hwfn->p_rdma_info->iwarp; |
| 614 | struct iwarp_tcp_offload_ramrod_data *p_tcp_ramrod; |
| 615 | struct tcp_offload_params_opt2 *tcp; |
| 616 | struct qed_sp_init_data init_data; |
| 617 | struct qed_spq_entry *p_ent; |
| 618 | dma_addr_t async_output_phys; |
| 619 | dma_addr_t in_pdata_phys; |
| 620 | u16 physical_q; |
| 621 | u8 tcp_flags; |
| 622 | int rc; |
| 623 | int i; |
| 624 | |
| 625 | memset(&init_data, 0, sizeof(init_data)); |
| 626 | init_data.cid = ep->tcp_cid; |
| 627 | init_data.opaque_fid = p_hwfn->hw_info.opaque_fid; |
Kalderon, Michal | 4b0fdd7 | 2017-07-02 10:29:28 +0300 | [diff] [blame] | 628 | if (ep->connect_mode == TCP_CONNECT_PASSIVE) |
| 629 | init_data.comp_mode = QED_SPQ_MODE_CB; |
| 630 | else |
| 631 | init_data.comp_mode = QED_SPQ_MODE_EBLOCK; |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 632 | |
| 633 | rc = qed_sp_init_request(p_hwfn, &p_ent, |
| 634 | IWARP_RAMROD_CMD_ID_TCP_OFFLOAD, |
| 635 | PROTOCOLID_IWARP, &init_data); |
| 636 | if (rc) |
| 637 | return rc; |
| 638 | |
| 639 | p_tcp_ramrod = &p_ent->ramrod.iwarp_tcp_offload; |
| 640 | |
| 641 | in_pdata_phys = ep->ep_buffer_phys + |
| 642 | offsetof(struct qed_iwarp_ep_memory, in_pdata); |
| 643 | DMA_REGPAIR_LE(p_tcp_ramrod->iwarp.incoming_ulp_buffer.addr, |
| 644 | in_pdata_phys); |
| 645 | |
| 646 | p_tcp_ramrod->iwarp.incoming_ulp_buffer.len = |
| 647 | cpu_to_le16(sizeof(ep->ep_buffer_virt->in_pdata)); |
| 648 | |
| 649 | async_output_phys = ep->ep_buffer_phys + |
| 650 | offsetof(struct qed_iwarp_ep_memory, async_output); |
| 651 | DMA_REGPAIR_LE(p_tcp_ramrod->iwarp.async_eqe_output_buf, |
| 652 | async_output_phys); |
| 653 | |
| 654 | p_tcp_ramrod->iwarp.handle_for_async.hi = cpu_to_le32(PTR_HI(ep)); |
| 655 | p_tcp_ramrod->iwarp.handle_for_async.lo = cpu_to_le32(PTR_LO(ep)); |
| 656 | |
| 657 | physical_q = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_OFLD); |
| 658 | p_tcp_ramrod->iwarp.physical_q0 = cpu_to_le16(physical_q); |
| 659 | physical_q = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_ACK); |
| 660 | p_tcp_ramrod->iwarp.physical_q1 = cpu_to_le16(physical_q); |
| 661 | p_tcp_ramrod->iwarp.mpa_mode = iwarp_info->mpa_rev; |
| 662 | |
| 663 | tcp = &p_tcp_ramrod->tcp; |
| 664 | qed_set_fw_mac_addr(&tcp->remote_mac_addr_hi, |
| 665 | &tcp->remote_mac_addr_mid, |
| 666 | &tcp->remote_mac_addr_lo, ep->remote_mac_addr); |
| 667 | qed_set_fw_mac_addr(&tcp->local_mac_addr_hi, &tcp->local_mac_addr_mid, |
| 668 | &tcp->local_mac_addr_lo, ep->local_mac_addr); |
| 669 | |
| 670 | tcp->vlan_id = cpu_to_le16(ep->cm_info.vlan); |
| 671 | |
| 672 | tcp_flags = p_hwfn->p_rdma_info->iwarp.tcp_flags; |
| 673 | tcp->flags = 0; |
| 674 | SET_FIELD(tcp->flags, TCP_OFFLOAD_PARAMS_OPT2_TS_EN, |
| 675 | !!(tcp_flags & QED_IWARP_TS_EN)); |
| 676 | |
| 677 | SET_FIELD(tcp->flags, TCP_OFFLOAD_PARAMS_OPT2_DA_EN, |
| 678 | !!(tcp_flags & QED_IWARP_DA_EN)); |
| 679 | |
| 680 | tcp->ip_version = ep->cm_info.ip_version; |
| 681 | |
| 682 | for (i = 0; i < 4; i++) { |
| 683 | tcp->remote_ip[i] = cpu_to_le32(ep->cm_info.remote_ip[i]); |
| 684 | tcp->local_ip[i] = cpu_to_le32(ep->cm_info.local_ip[i]); |
| 685 | } |
| 686 | |
| 687 | tcp->remote_port = cpu_to_le16(ep->cm_info.remote_port); |
| 688 | tcp->local_port = cpu_to_le16(ep->cm_info.local_port); |
| 689 | tcp->mss = cpu_to_le16(ep->mss); |
| 690 | tcp->flow_label = 0; |
| 691 | tcp->ttl = 0x40; |
| 692 | tcp->tos_or_tc = 0; |
| 693 | |
| 694 | tcp->rcv_wnd_scale = (u8)p_hwfn->p_rdma_info->iwarp.rcv_wnd_scale; |
| 695 | tcp->connect_mode = ep->connect_mode; |
| 696 | |
| 697 | if (ep->connect_mode == TCP_CONNECT_PASSIVE) { |
| 698 | tcp->syn_ip_payload_length = |
| 699 | cpu_to_le16(ep->syn_ip_payload_length); |
| 700 | tcp->syn_phy_addr_hi = DMA_HI_LE(ep->syn_phy_addr); |
| 701 | tcp->syn_phy_addr_lo = DMA_LO_LE(ep->syn_phy_addr); |
| 702 | } |
| 703 | |
| 704 | qed_iwarp_print_tcp_ramrod(p_hwfn, p_tcp_ramrod); |
| 705 | |
| 706 | rc = qed_spq_post(p_hwfn, p_ent, NULL); |
| 707 | |
| 708 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 709 | "EP(0x%x) Offload completed rc=%d\n", ep->tcp_cid, rc); |
| 710 | |
| 711 | return rc; |
| 712 | } |
| 713 | |
| 714 | static void |
| 715 | qed_iwarp_mpa_received(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep) |
| 716 | { |
| 717 | struct qed_iwarp_info *iwarp_info = &p_hwfn->p_rdma_info->iwarp; |
| 718 | struct qed_iwarp_cm_event_params params; |
| 719 | struct mpa_v2_hdr *mpa_v2; |
| 720 | union async_output *async_data; |
| 721 | u16 mpa_ord, mpa_ird; |
| 722 | u8 mpa_hdr_size = 0; |
| 723 | u8 mpa_rev; |
| 724 | |
| 725 | async_data = &ep->ep_buffer_virt->async_output; |
| 726 | |
| 727 | mpa_rev = async_data->mpa_request.mpa_handshake_mode; |
| 728 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 729 | "private_data_len=%x handshake_mode=%x private_data=(%x)\n", |
| 730 | async_data->mpa_request.ulp_data_len, |
Kalderon, Michal | 4b0fdd7 | 2017-07-02 10:29:28 +0300 | [diff] [blame] | 731 | mpa_rev, *((u32 *)(ep->ep_buffer_virt->in_pdata))); |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 732 | |
| 733 | if (mpa_rev == MPA_NEGOTIATION_TYPE_ENHANCED) { |
| 734 | /* Read ord/ird values from private data buffer */ |
| 735 | mpa_v2 = (struct mpa_v2_hdr *)ep->ep_buffer_virt->in_pdata; |
| 736 | mpa_hdr_size = sizeof(*mpa_v2); |
| 737 | |
| 738 | mpa_ord = ntohs(mpa_v2->ord); |
| 739 | mpa_ird = ntohs(mpa_v2->ird); |
| 740 | |
| 741 | /* Temprary store in cm_info incoming ord/ird requested, later |
| 742 | * replace with negotiated value during accept |
| 743 | */ |
| 744 | ep->cm_info.ord = (u8)min_t(u16, |
| 745 | (mpa_ord & MPA_V2_IRD_ORD_MASK), |
| 746 | QED_IWARP_ORD_DEFAULT); |
| 747 | |
| 748 | ep->cm_info.ird = (u8)min_t(u16, |
| 749 | (mpa_ird & MPA_V2_IRD_ORD_MASK), |
| 750 | QED_IWARP_IRD_DEFAULT); |
| 751 | |
| 752 | /* Peer2Peer negotiation */ |
| 753 | ep->rtr_type = MPA_RTR_TYPE_NONE; |
| 754 | if (mpa_ird & MPA_V2_PEER2PEER_MODEL) { |
| 755 | if (mpa_ord & MPA_V2_WRITE_RTR) |
| 756 | ep->rtr_type |= MPA_RTR_TYPE_ZERO_WRITE; |
| 757 | |
| 758 | if (mpa_ord & MPA_V2_READ_RTR) |
| 759 | ep->rtr_type |= MPA_RTR_TYPE_ZERO_READ; |
| 760 | |
| 761 | if (mpa_ird & MPA_V2_SEND_RTR) |
| 762 | ep->rtr_type |= MPA_RTR_TYPE_ZERO_SEND; |
| 763 | |
| 764 | ep->rtr_type &= iwarp_info->rtr_type; |
| 765 | |
| 766 | /* if we're left with no match send our capabilities */ |
| 767 | if (ep->rtr_type == MPA_RTR_TYPE_NONE) |
| 768 | ep->rtr_type = iwarp_info->rtr_type; |
| 769 | } |
| 770 | |
| 771 | ep->mpa_rev = MPA_NEGOTIATION_TYPE_ENHANCED; |
| 772 | } else { |
| 773 | ep->cm_info.ord = QED_IWARP_ORD_DEFAULT; |
| 774 | ep->cm_info.ird = QED_IWARP_IRD_DEFAULT; |
| 775 | ep->mpa_rev = MPA_NEGOTIATION_TYPE_BASIC; |
| 776 | } |
| 777 | |
| 778 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 779 | "MPA_NEGOTIATE (v%d): ORD: 0x%x IRD: 0x%x rtr:0x%x ulp_data_len = %x mpa_hdr_size = %x\n", |
| 780 | mpa_rev, ep->cm_info.ord, ep->cm_info.ird, ep->rtr_type, |
| 781 | async_data->mpa_request.ulp_data_len, mpa_hdr_size); |
| 782 | |
| 783 | /* Strip mpa v2 hdr from private data before sending to upper layer */ |
| 784 | ep->cm_info.private_data = ep->ep_buffer_virt->in_pdata + mpa_hdr_size; |
| 785 | |
| 786 | ep->cm_info.private_data_len = async_data->mpa_request.ulp_data_len - |
| 787 | mpa_hdr_size; |
| 788 | |
| 789 | params.event = QED_IWARP_EVENT_MPA_REQUEST; |
| 790 | params.cm_info = &ep->cm_info; |
| 791 | params.ep_context = ep; |
| 792 | params.status = 0; |
| 793 | |
| 794 | ep->state = QED_IWARP_EP_MPA_REQ_RCVD; |
| 795 | ep->event_cb(ep->cb_context, ¶ms); |
| 796 | } |
| 797 | |
| 798 | static int |
| 799 | qed_iwarp_mpa_offload(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep) |
| 800 | { |
| 801 | struct iwarp_mpa_offload_ramrod_data *p_mpa_ramrod; |
| 802 | struct qed_sp_init_data init_data; |
| 803 | dma_addr_t async_output_phys; |
| 804 | struct qed_spq_entry *p_ent; |
| 805 | dma_addr_t out_pdata_phys; |
| 806 | dma_addr_t in_pdata_phys; |
| 807 | struct qed_rdma_qp *qp; |
| 808 | bool reject; |
| 809 | int rc; |
| 810 | |
| 811 | if (!ep) |
| 812 | return -EINVAL; |
| 813 | |
| 814 | qp = ep->qp; |
| 815 | reject = !qp; |
| 816 | |
| 817 | memset(&init_data, 0, sizeof(init_data)); |
| 818 | init_data.cid = reject ? ep->tcp_cid : qp->icid; |
| 819 | init_data.opaque_fid = p_hwfn->hw_info.opaque_fid; |
| 820 | |
Kalderon, Michal | 4b0fdd7 | 2017-07-02 10:29:28 +0300 | [diff] [blame] | 821 | if (ep->connect_mode == TCP_CONNECT_ACTIVE) |
| 822 | init_data.comp_mode = QED_SPQ_MODE_CB; |
| 823 | else |
| 824 | init_data.comp_mode = QED_SPQ_MODE_EBLOCK; |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 825 | |
| 826 | rc = qed_sp_init_request(p_hwfn, &p_ent, |
| 827 | IWARP_RAMROD_CMD_ID_MPA_OFFLOAD, |
| 828 | PROTOCOLID_IWARP, &init_data); |
| 829 | if (rc) |
| 830 | return rc; |
| 831 | |
| 832 | p_mpa_ramrod = &p_ent->ramrod.iwarp_mpa_offload; |
| 833 | out_pdata_phys = ep->ep_buffer_phys + |
| 834 | offsetof(struct qed_iwarp_ep_memory, out_pdata); |
| 835 | DMA_REGPAIR_LE(p_mpa_ramrod->common.outgoing_ulp_buffer.addr, |
| 836 | out_pdata_phys); |
| 837 | p_mpa_ramrod->common.outgoing_ulp_buffer.len = |
| 838 | ep->cm_info.private_data_len; |
| 839 | p_mpa_ramrod->common.crc_needed = p_hwfn->p_rdma_info->iwarp.crc_needed; |
| 840 | |
| 841 | p_mpa_ramrod->common.out_rq.ord = ep->cm_info.ord; |
| 842 | p_mpa_ramrod->common.out_rq.ird = ep->cm_info.ird; |
| 843 | |
| 844 | p_mpa_ramrod->tcp_cid = p_hwfn->hw_info.opaque_fid << 16 | ep->tcp_cid; |
| 845 | |
| 846 | in_pdata_phys = ep->ep_buffer_phys + |
| 847 | offsetof(struct qed_iwarp_ep_memory, in_pdata); |
| 848 | p_mpa_ramrod->tcp_connect_side = ep->connect_mode; |
| 849 | DMA_REGPAIR_LE(p_mpa_ramrod->incoming_ulp_buffer.addr, |
| 850 | in_pdata_phys); |
| 851 | p_mpa_ramrod->incoming_ulp_buffer.len = |
| 852 | cpu_to_le16(sizeof(ep->ep_buffer_virt->in_pdata)); |
| 853 | async_output_phys = ep->ep_buffer_phys + |
| 854 | offsetof(struct qed_iwarp_ep_memory, async_output); |
| 855 | DMA_REGPAIR_LE(p_mpa_ramrod->async_eqe_output_buf, |
| 856 | async_output_phys); |
| 857 | p_mpa_ramrod->handle_for_async.hi = cpu_to_le32(PTR_HI(ep)); |
| 858 | p_mpa_ramrod->handle_for_async.lo = cpu_to_le32(PTR_LO(ep)); |
| 859 | |
| 860 | if (!reject) { |
| 861 | DMA_REGPAIR_LE(p_mpa_ramrod->shared_queue_addr, |
| 862 | qp->shared_queue_phys_addr); |
| 863 | p_mpa_ramrod->stats_counter_id = |
| 864 | RESC_START(p_hwfn, QED_RDMA_STATS_QUEUE) + qp->stats_queue; |
| 865 | } else { |
| 866 | p_mpa_ramrod->common.reject = 1; |
| 867 | } |
| 868 | |
| 869 | p_mpa_ramrod->mode = ep->mpa_rev; |
| 870 | SET_FIELD(p_mpa_ramrod->rtr_pref, |
| 871 | IWARP_MPA_OFFLOAD_RAMROD_DATA_RTR_SUPPORTED, ep->rtr_type); |
| 872 | |
| 873 | ep->state = QED_IWARP_EP_MPA_OFFLOADED; |
| 874 | rc = qed_spq_post(p_hwfn, p_ent, NULL); |
| 875 | if (!reject) |
| 876 | ep->cid = qp->icid; /* Now they're migrated. */ |
| 877 | |
| 878 | DP_VERBOSE(p_hwfn, |
| 879 | QED_MSG_RDMA, |
| 880 | "QP(0x%x) EP(0x%x) MPA Offload rc = %d IRD=0x%x ORD=0x%x rtr_type=%d mpa_rev=%d reject=%d\n", |
| 881 | reject ? 0xffff : qp->icid, |
| 882 | ep->tcp_cid, |
| 883 | rc, |
| 884 | ep->cm_info.ird, |
| 885 | ep->cm_info.ord, ep->rtr_type, ep->mpa_rev, reject); |
| 886 | return rc; |
| 887 | } |
| 888 | |
| 889 | static void |
| 890 | qed_iwarp_return_ep(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep) |
| 891 | { |
| 892 | ep->state = QED_IWARP_EP_INIT; |
| 893 | if (ep->qp) |
| 894 | ep->qp->ep = NULL; |
| 895 | ep->qp = NULL; |
| 896 | memset(&ep->cm_info, 0, sizeof(ep->cm_info)); |
| 897 | |
| 898 | if (ep->tcp_cid == QED_IWARP_INVALID_TCP_CID) { |
| 899 | /* We don't care about the return code, it's ok if tcp_cid |
| 900 | * remains invalid...in this case we'll defer allocation |
| 901 | */ |
| 902 | qed_iwarp_alloc_tcp_cid(p_hwfn, &ep->tcp_cid); |
| 903 | } |
| 904 | spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock); |
| 905 | |
| 906 | list_del(&ep->list_entry); |
| 907 | list_add_tail(&ep->list_entry, |
| 908 | &p_hwfn->p_rdma_info->iwarp.ep_free_list); |
| 909 | |
| 910 | spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock); |
| 911 | } |
| 912 | |
Kalderon, Michal | 4b0fdd7 | 2017-07-02 10:29:28 +0300 | [diff] [blame] | 913 | void |
| 914 | qed_iwarp_parse_private_data(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep) |
| 915 | { |
| 916 | struct mpa_v2_hdr *mpa_v2_params; |
| 917 | union async_output *async_data; |
| 918 | u16 mpa_ird, mpa_ord; |
| 919 | u8 mpa_data_size = 0; |
| 920 | |
| 921 | if (MPA_REV2(p_hwfn->p_rdma_info->iwarp.mpa_rev)) { |
| 922 | mpa_v2_params = |
| 923 | (struct mpa_v2_hdr *)(ep->ep_buffer_virt->in_pdata); |
| 924 | mpa_data_size = sizeof(*mpa_v2_params); |
| 925 | mpa_ird = ntohs(mpa_v2_params->ird); |
| 926 | mpa_ord = ntohs(mpa_v2_params->ord); |
| 927 | |
| 928 | ep->cm_info.ird = (u8)(mpa_ord & MPA_V2_IRD_ORD_MASK); |
| 929 | ep->cm_info.ord = (u8)(mpa_ird & MPA_V2_IRD_ORD_MASK); |
| 930 | } |
| 931 | async_data = &ep->ep_buffer_virt->async_output; |
| 932 | |
| 933 | ep->cm_info.private_data = ep->ep_buffer_virt->in_pdata + mpa_data_size; |
| 934 | ep->cm_info.private_data_len = async_data->mpa_response.ulp_data_len - |
| 935 | mpa_data_size; |
| 936 | } |
| 937 | |
| 938 | void |
| 939 | qed_iwarp_mpa_reply_arrived(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep) |
| 940 | { |
| 941 | struct qed_iwarp_cm_event_params params; |
| 942 | |
| 943 | if (ep->connect_mode == TCP_CONNECT_PASSIVE) { |
| 944 | DP_NOTICE(p_hwfn, |
| 945 | "MPA reply event not expected on passive side!\n"); |
| 946 | return; |
| 947 | } |
| 948 | |
| 949 | params.event = QED_IWARP_EVENT_ACTIVE_MPA_REPLY; |
| 950 | |
| 951 | qed_iwarp_parse_private_data(p_hwfn, ep); |
| 952 | |
| 953 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 954 | "MPA_NEGOTIATE (v%d): ORD: 0x%x IRD: 0x%x\n", |
| 955 | ep->mpa_rev, ep->cm_info.ord, ep->cm_info.ird); |
| 956 | |
| 957 | params.cm_info = &ep->cm_info; |
| 958 | params.ep_context = ep; |
| 959 | params.status = 0; |
| 960 | |
| 961 | ep->mpa_reply_processed = true; |
| 962 | |
| 963 | ep->event_cb(ep->cb_context, ¶ms); |
| 964 | } |
| 965 | |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 966 | #define QED_IWARP_CONNECT_MODE_STRING(ep) \ |
| 967 | ((ep)->connect_mode == TCP_CONNECT_PASSIVE) ? "Passive" : "Active" |
| 968 | |
| 969 | /* Called as a result of the event: |
| 970 | * IWARP_EVENT_TYPE_ASYNC_MPA_HANDSHAKE_COMPLETE |
| 971 | */ |
| 972 | static void |
| 973 | qed_iwarp_mpa_complete(struct qed_hwfn *p_hwfn, |
| 974 | struct qed_iwarp_ep *ep, u8 fw_return_code) |
| 975 | { |
| 976 | struct qed_iwarp_cm_event_params params; |
| 977 | |
Kalderon, Michal | 4b0fdd7 | 2017-07-02 10:29:28 +0300 | [diff] [blame] | 978 | if (ep->connect_mode == TCP_CONNECT_ACTIVE) |
| 979 | params.event = QED_IWARP_EVENT_ACTIVE_COMPLETE; |
| 980 | else |
| 981 | params.event = QED_IWARP_EVENT_PASSIVE_COMPLETE; |
| 982 | |
| 983 | if (ep->connect_mode == TCP_CONNECT_ACTIVE && !ep->mpa_reply_processed) |
| 984 | qed_iwarp_parse_private_data(p_hwfn, ep); |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 985 | |
| 986 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 987 | "MPA_NEGOTIATE (v%d): ORD: 0x%x IRD: 0x%x\n", |
| 988 | ep->mpa_rev, ep->cm_info.ord, ep->cm_info.ird); |
| 989 | |
| 990 | params.cm_info = &ep->cm_info; |
| 991 | |
| 992 | params.ep_context = ep; |
| 993 | |
| 994 | ep->state = QED_IWARP_EP_CLOSED; |
| 995 | |
| 996 | switch (fw_return_code) { |
| 997 | case RDMA_RETURN_OK: |
| 998 | ep->qp->max_rd_atomic_req = ep->cm_info.ord; |
| 999 | ep->qp->max_rd_atomic_resp = ep->cm_info.ird; |
| 1000 | qed_iwarp_modify_qp(p_hwfn, ep->qp, QED_IWARP_QP_STATE_RTS, 1); |
| 1001 | ep->state = QED_IWARP_EP_ESTABLISHED; |
| 1002 | params.status = 0; |
| 1003 | break; |
| 1004 | default: |
| 1005 | params.status = -ECONNRESET; |
| 1006 | break; |
| 1007 | } |
| 1008 | |
| 1009 | ep->event_cb(ep->cb_context, ¶ms); |
| 1010 | } |
| 1011 | |
| 1012 | static void |
| 1013 | qed_iwarp_mpa_v2_set_private(struct qed_hwfn *p_hwfn, |
| 1014 | struct qed_iwarp_ep *ep, u8 *mpa_data_size) |
| 1015 | { |
| 1016 | struct mpa_v2_hdr *mpa_v2_params; |
| 1017 | u16 mpa_ird, mpa_ord; |
| 1018 | |
| 1019 | *mpa_data_size = 0; |
| 1020 | if (MPA_REV2(ep->mpa_rev)) { |
| 1021 | mpa_v2_params = |
| 1022 | (struct mpa_v2_hdr *)ep->ep_buffer_virt->out_pdata; |
| 1023 | *mpa_data_size = sizeof(*mpa_v2_params); |
| 1024 | |
| 1025 | mpa_ird = (u16)ep->cm_info.ird; |
| 1026 | mpa_ord = (u16)ep->cm_info.ord; |
| 1027 | |
| 1028 | if (ep->rtr_type != MPA_RTR_TYPE_NONE) { |
| 1029 | mpa_ird |= MPA_V2_PEER2PEER_MODEL; |
| 1030 | |
| 1031 | if (ep->rtr_type & MPA_RTR_TYPE_ZERO_SEND) |
| 1032 | mpa_ird |= MPA_V2_SEND_RTR; |
| 1033 | |
| 1034 | if (ep->rtr_type & MPA_RTR_TYPE_ZERO_WRITE) |
| 1035 | mpa_ord |= MPA_V2_WRITE_RTR; |
| 1036 | |
| 1037 | if (ep->rtr_type & MPA_RTR_TYPE_ZERO_READ) |
| 1038 | mpa_ord |= MPA_V2_READ_RTR; |
| 1039 | } |
| 1040 | |
| 1041 | mpa_v2_params->ird = htons(mpa_ird); |
| 1042 | mpa_v2_params->ord = htons(mpa_ord); |
| 1043 | |
| 1044 | DP_VERBOSE(p_hwfn, |
| 1045 | QED_MSG_RDMA, |
| 1046 | "MPA_NEGOTIATE Header: [%x ord:%x ird] %x ord:%x ird:%x peer2peer:%x rtr_send:%x rtr_write:%x rtr_read:%x\n", |
| 1047 | mpa_v2_params->ird, |
| 1048 | mpa_v2_params->ord, |
| 1049 | *((u32 *)mpa_v2_params), |
| 1050 | mpa_ord & MPA_V2_IRD_ORD_MASK, |
| 1051 | mpa_ird & MPA_V2_IRD_ORD_MASK, |
| 1052 | !!(mpa_ird & MPA_V2_PEER2PEER_MODEL), |
| 1053 | !!(mpa_ird & MPA_V2_SEND_RTR), |
| 1054 | !!(mpa_ord & MPA_V2_WRITE_RTR), |
| 1055 | !!(mpa_ord & MPA_V2_READ_RTR)); |
| 1056 | } |
| 1057 | } |
| 1058 | |
Kalderon, Michal | 4b0fdd7 | 2017-07-02 10:29:28 +0300 | [diff] [blame] | 1059 | int qed_iwarp_connect(void *rdma_cxt, |
| 1060 | struct qed_iwarp_connect_in *iparams, |
| 1061 | struct qed_iwarp_connect_out *oparams) |
| 1062 | { |
| 1063 | struct qed_hwfn *p_hwfn = rdma_cxt; |
| 1064 | struct qed_iwarp_info *iwarp_info; |
| 1065 | struct qed_iwarp_ep *ep; |
| 1066 | u8 mpa_data_size = 0; |
| 1067 | u8 ts_hdr_size = 0; |
| 1068 | u32 cid; |
| 1069 | int rc; |
| 1070 | |
| 1071 | if ((iparams->cm_info.ord > QED_IWARP_ORD_DEFAULT) || |
| 1072 | (iparams->cm_info.ird > QED_IWARP_IRD_DEFAULT)) { |
| 1073 | DP_NOTICE(p_hwfn, |
| 1074 | "QP(0x%x) ERROR: Invalid ord(0x%x)/ird(0x%x)\n", |
| 1075 | iparams->qp->icid, iparams->cm_info.ord, |
| 1076 | iparams->cm_info.ird); |
| 1077 | |
| 1078 | return -EINVAL; |
| 1079 | } |
| 1080 | |
| 1081 | iwarp_info = &p_hwfn->p_rdma_info->iwarp; |
| 1082 | |
| 1083 | /* Allocate ep object */ |
| 1084 | rc = qed_iwarp_alloc_cid(p_hwfn, &cid); |
| 1085 | if (rc) |
| 1086 | return rc; |
| 1087 | |
| 1088 | rc = qed_iwarp_create_ep(p_hwfn, &ep); |
| 1089 | if (rc) |
| 1090 | goto err; |
| 1091 | |
| 1092 | ep->tcp_cid = cid; |
| 1093 | |
| 1094 | spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock); |
| 1095 | list_add_tail(&ep->list_entry, &p_hwfn->p_rdma_info->iwarp.ep_list); |
| 1096 | spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock); |
| 1097 | |
| 1098 | ep->qp = iparams->qp; |
| 1099 | ep->qp->ep = ep; |
| 1100 | ether_addr_copy(ep->remote_mac_addr, iparams->remote_mac_addr); |
| 1101 | ether_addr_copy(ep->local_mac_addr, iparams->local_mac_addr); |
| 1102 | memcpy(&ep->cm_info, &iparams->cm_info, sizeof(ep->cm_info)); |
| 1103 | |
| 1104 | ep->cm_info.ord = iparams->cm_info.ord; |
| 1105 | ep->cm_info.ird = iparams->cm_info.ird; |
| 1106 | |
| 1107 | ep->rtr_type = iwarp_info->rtr_type; |
| 1108 | if (!iwarp_info->peer2peer) |
| 1109 | ep->rtr_type = MPA_RTR_TYPE_NONE; |
| 1110 | |
| 1111 | if ((ep->rtr_type & MPA_RTR_TYPE_ZERO_READ) && (ep->cm_info.ord == 0)) |
| 1112 | ep->cm_info.ord = 1; |
| 1113 | |
| 1114 | ep->mpa_rev = iwarp_info->mpa_rev; |
| 1115 | |
| 1116 | qed_iwarp_mpa_v2_set_private(p_hwfn, ep, &mpa_data_size); |
| 1117 | |
| 1118 | ep->cm_info.private_data = ep->ep_buffer_virt->out_pdata; |
| 1119 | ep->cm_info.private_data_len = iparams->cm_info.private_data_len + |
| 1120 | mpa_data_size; |
| 1121 | |
| 1122 | memcpy((u8 *)ep->ep_buffer_virt->out_pdata + mpa_data_size, |
| 1123 | iparams->cm_info.private_data, |
| 1124 | iparams->cm_info.private_data_len); |
| 1125 | |
| 1126 | if (p_hwfn->p_rdma_info->iwarp.tcp_flags & QED_IWARP_TS_EN) |
| 1127 | ts_hdr_size = TIMESTAMP_HEADER_SIZE; |
| 1128 | |
| 1129 | ep->mss = iparams->mss - ts_hdr_size; |
| 1130 | ep->mss = min_t(u16, QED_IWARP_MAX_FW_MSS, ep->mss); |
| 1131 | |
| 1132 | ep->event_cb = iparams->event_cb; |
| 1133 | ep->cb_context = iparams->cb_context; |
| 1134 | ep->connect_mode = TCP_CONNECT_ACTIVE; |
| 1135 | |
| 1136 | oparams->ep_context = ep; |
| 1137 | |
| 1138 | rc = qed_iwarp_tcp_offload(p_hwfn, ep); |
| 1139 | |
| 1140 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP(0x%x) EP(0x%x) rc = %d\n", |
| 1141 | iparams->qp->icid, ep->tcp_cid, rc); |
| 1142 | |
| 1143 | if (rc) { |
| 1144 | qed_iwarp_destroy_ep(p_hwfn, ep, true); |
| 1145 | goto err; |
| 1146 | } |
| 1147 | |
| 1148 | return rc; |
| 1149 | err: |
| 1150 | qed_iwarp_cid_cleaned(p_hwfn, cid); |
| 1151 | |
| 1152 | return rc; |
| 1153 | } |
| 1154 | |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 1155 | static struct qed_iwarp_ep *qed_iwarp_get_free_ep(struct qed_hwfn *p_hwfn) |
| 1156 | { |
| 1157 | struct qed_iwarp_ep *ep = NULL; |
| 1158 | int rc; |
| 1159 | |
| 1160 | spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock); |
| 1161 | |
| 1162 | if (list_empty(&p_hwfn->p_rdma_info->iwarp.ep_free_list)) { |
| 1163 | DP_ERR(p_hwfn, "Ep list is empty\n"); |
| 1164 | goto out; |
| 1165 | } |
| 1166 | |
| 1167 | ep = list_first_entry(&p_hwfn->p_rdma_info->iwarp.ep_free_list, |
| 1168 | struct qed_iwarp_ep, list_entry); |
| 1169 | |
| 1170 | /* in some cases we could have failed allocating a tcp cid when added |
| 1171 | * from accept / failure... retry now..this is not the common case. |
| 1172 | */ |
| 1173 | if (ep->tcp_cid == QED_IWARP_INVALID_TCP_CID) { |
| 1174 | rc = qed_iwarp_alloc_tcp_cid(p_hwfn, &ep->tcp_cid); |
| 1175 | |
| 1176 | /* if we fail we could look for another entry with a valid |
| 1177 | * tcp_cid, but since we don't expect to reach this anyway |
| 1178 | * it's not worth the handling |
| 1179 | */ |
| 1180 | if (rc) { |
| 1181 | ep->tcp_cid = QED_IWARP_INVALID_TCP_CID; |
| 1182 | ep = NULL; |
| 1183 | goto out; |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | list_del(&ep->list_entry); |
| 1188 | |
| 1189 | out: |
| 1190 | spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock); |
| 1191 | return ep; |
| 1192 | } |
| 1193 | |
Kalderon, Michal | 67b40dc | 2017-07-02 10:29:22 +0300 | [diff] [blame] | 1194 | #define QED_IWARP_MAX_CID_CLEAN_TIME 100 |
| 1195 | #define QED_IWARP_MAX_NO_PROGRESS_CNT 5 |
| 1196 | |
| 1197 | /* This function waits for all the bits of a bmap to be cleared, as long as |
| 1198 | * there is progress ( i.e. the number of bits left to be cleared decreases ) |
| 1199 | * the function continues. |
| 1200 | */ |
| 1201 | static int |
| 1202 | qed_iwarp_wait_cid_map_cleared(struct qed_hwfn *p_hwfn, struct qed_bmap *bmap) |
| 1203 | { |
| 1204 | int prev_weight = 0; |
| 1205 | int wait_count = 0; |
| 1206 | int weight = 0; |
| 1207 | |
| 1208 | weight = bitmap_weight(bmap->bitmap, bmap->max_count); |
| 1209 | prev_weight = weight; |
| 1210 | |
| 1211 | while (weight) { |
| 1212 | msleep(QED_IWARP_MAX_CID_CLEAN_TIME); |
| 1213 | |
| 1214 | weight = bitmap_weight(bmap->bitmap, bmap->max_count); |
| 1215 | |
| 1216 | if (prev_weight == weight) { |
| 1217 | wait_count++; |
| 1218 | } else { |
| 1219 | prev_weight = weight; |
| 1220 | wait_count = 0; |
| 1221 | } |
| 1222 | |
| 1223 | if (wait_count > QED_IWARP_MAX_NO_PROGRESS_CNT) { |
| 1224 | DP_NOTICE(p_hwfn, |
| 1225 | "%s bitmap wait timed out (%d cids pending)\n", |
| 1226 | bmap->name, weight); |
| 1227 | return -EBUSY; |
| 1228 | } |
| 1229 | } |
| 1230 | return 0; |
| 1231 | } |
| 1232 | |
| 1233 | static int qed_iwarp_wait_for_all_cids(struct qed_hwfn *p_hwfn) |
| 1234 | { |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 1235 | int rc; |
| 1236 | int i; |
| 1237 | |
| 1238 | rc = qed_iwarp_wait_cid_map_cleared(p_hwfn, |
| 1239 | &p_hwfn->p_rdma_info->tcp_cid_map); |
| 1240 | if (rc) |
| 1241 | return rc; |
| 1242 | |
| 1243 | /* Now free the tcp cids from the main cid map */ |
| 1244 | for (i = 0; i < QED_IWARP_PREALLOC_CNT; i++) |
| 1245 | qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->cid_map, i); |
| 1246 | |
Kalderon, Michal | 67b40dc | 2017-07-02 10:29:22 +0300 | [diff] [blame] | 1247 | /* Now wait for all cids to be completed */ |
| 1248 | return qed_iwarp_wait_cid_map_cleared(p_hwfn, |
| 1249 | &p_hwfn->p_rdma_info->cid_map); |
| 1250 | } |
| 1251 | |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 1252 | static void qed_iwarp_free_prealloc_ep(struct qed_hwfn *p_hwfn) |
| 1253 | { |
| 1254 | struct qed_iwarp_ep *ep; |
| 1255 | |
| 1256 | while (!list_empty(&p_hwfn->p_rdma_info->iwarp.ep_free_list)) { |
| 1257 | spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock); |
| 1258 | |
| 1259 | ep = list_first_entry(&p_hwfn->p_rdma_info->iwarp.ep_free_list, |
| 1260 | struct qed_iwarp_ep, list_entry); |
| 1261 | |
| 1262 | if (!ep) { |
| 1263 | spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock); |
| 1264 | break; |
| 1265 | } |
| 1266 | list_del(&ep->list_entry); |
| 1267 | |
| 1268 | spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock); |
| 1269 | |
| 1270 | if (ep->tcp_cid != QED_IWARP_INVALID_TCP_CID) |
| 1271 | qed_iwarp_cid_cleaned(p_hwfn, ep->tcp_cid); |
| 1272 | |
| 1273 | qed_iwarp_destroy_ep(p_hwfn, ep, false); |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | static int qed_iwarp_prealloc_ep(struct qed_hwfn *p_hwfn, bool init) |
| 1278 | { |
| 1279 | struct qed_iwarp_ep *ep; |
| 1280 | int rc = 0; |
| 1281 | int count; |
| 1282 | u32 cid; |
| 1283 | int i; |
| 1284 | |
| 1285 | count = init ? QED_IWARP_PREALLOC_CNT : 1; |
| 1286 | for (i = 0; i < count; i++) { |
| 1287 | rc = qed_iwarp_create_ep(p_hwfn, &ep); |
| 1288 | if (rc) |
| 1289 | return rc; |
| 1290 | |
| 1291 | /* During initialization we allocate from the main pool, |
| 1292 | * afterwards we allocate only from the tcp_cid. |
| 1293 | */ |
| 1294 | if (init) { |
| 1295 | rc = qed_iwarp_alloc_cid(p_hwfn, &cid); |
| 1296 | if (rc) |
| 1297 | goto err; |
| 1298 | qed_iwarp_set_tcp_cid(p_hwfn, cid); |
| 1299 | } else { |
| 1300 | /* We don't care about the return code, it's ok if |
| 1301 | * tcp_cid remains invalid...in this case we'll |
| 1302 | * defer allocation |
| 1303 | */ |
| 1304 | qed_iwarp_alloc_tcp_cid(p_hwfn, &cid); |
| 1305 | } |
| 1306 | |
| 1307 | ep->tcp_cid = cid; |
| 1308 | |
| 1309 | spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock); |
| 1310 | list_add_tail(&ep->list_entry, |
| 1311 | &p_hwfn->p_rdma_info->iwarp.ep_free_list); |
| 1312 | spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock); |
| 1313 | } |
| 1314 | |
| 1315 | return rc; |
| 1316 | |
| 1317 | err: |
| 1318 | qed_iwarp_destroy_ep(p_hwfn, ep, false); |
| 1319 | |
| 1320 | return rc; |
| 1321 | } |
| 1322 | |
Kalderon, Michal | 67b40dc | 2017-07-02 10:29:22 +0300 | [diff] [blame] | 1323 | int qed_iwarp_alloc(struct qed_hwfn *p_hwfn) |
| 1324 | { |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 1325 | int rc; |
| 1326 | |
| 1327 | /* Allocate bitmap for tcp cid. These are used by passive side |
| 1328 | * to ensure it can allocate a tcp cid during dpc that was |
| 1329 | * pre-acquired and doesn't require dynamic allocation of ilt |
| 1330 | */ |
| 1331 | rc = qed_rdma_bmap_alloc(p_hwfn, &p_hwfn->p_rdma_info->tcp_cid_map, |
| 1332 | QED_IWARP_PREALLOC_CNT, "TCP_CID"); |
| 1333 | if (rc) { |
| 1334 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 1335 | "Failed to allocate tcp cid, rc = %d\n", rc); |
| 1336 | return rc; |
| 1337 | } |
| 1338 | |
| 1339 | INIT_LIST_HEAD(&p_hwfn->p_rdma_info->iwarp.ep_free_list); |
Kalderon, Michal | 67b40dc | 2017-07-02 10:29:22 +0300 | [diff] [blame] | 1340 | spin_lock_init(&p_hwfn->p_rdma_info->iwarp.iw_lock); |
| 1341 | |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 1342 | return qed_iwarp_prealloc_ep(p_hwfn, true); |
Kalderon, Michal | 67b40dc | 2017-07-02 10:29:22 +0300 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | void qed_iwarp_resc_free(struct qed_hwfn *p_hwfn) |
| 1346 | { |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 1347 | qed_rdma_bmap_free(p_hwfn, &p_hwfn->p_rdma_info->tcp_cid_map, 1); |
| 1348 | } |
| 1349 | |
| 1350 | int qed_iwarp_accept(void *rdma_cxt, struct qed_iwarp_accept_in *iparams) |
| 1351 | { |
Kalderon, Michal | 4b0fdd7 | 2017-07-02 10:29:28 +0300 | [diff] [blame] | 1352 | struct qed_hwfn *p_hwfn = rdma_cxt; |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 1353 | struct qed_iwarp_ep *ep; |
| 1354 | u8 mpa_data_size = 0; |
| 1355 | int rc; |
| 1356 | |
Kalderon, Michal | 4b0fdd7 | 2017-07-02 10:29:28 +0300 | [diff] [blame] | 1357 | ep = iparams->ep_context; |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 1358 | if (!ep) { |
| 1359 | DP_ERR(p_hwfn, "Ep Context receive in accept is NULL\n"); |
| 1360 | return -EINVAL; |
| 1361 | } |
| 1362 | |
| 1363 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP(0x%x) EP(0x%x)\n", |
| 1364 | iparams->qp->icid, ep->tcp_cid); |
| 1365 | |
| 1366 | if ((iparams->ord > QED_IWARP_ORD_DEFAULT) || |
| 1367 | (iparams->ird > QED_IWARP_IRD_DEFAULT)) { |
| 1368 | DP_VERBOSE(p_hwfn, |
| 1369 | QED_MSG_RDMA, |
| 1370 | "QP(0x%x) EP(0x%x) ERROR: Invalid ord(0x%x)/ird(0x%x)\n", |
| 1371 | iparams->qp->icid, |
| 1372 | ep->tcp_cid, iparams->ord, iparams->ord); |
| 1373 | return -EINVAL; |
| 1374 | } |
| 1375 | |
| 1376 | qed_iwarp_prealloc_ep(p_hwfn, false); |
| 1377 | |
| 1378 | ep->cb_context = iparams->cb_context; |
| 1379 | ep->qp = iparams->qp; |
| 1380 | ep->qp->ep = ep; |
| 1381 | |
| 1382 | if (ep->mpa_rev == MPA_NEGOTIATION_TYPE_ENHANCED) { |
| 1383 | /* Negotiate ord/ird: if upperlayer requested ord larger than |
| 1384 | * ird advertised by remote, we need to decrease our ord |
| 1385 | */ |
| 1386 | if (iparams->ord > ep->cm_info.ird) |
| 1387 | iparams->ord = ep->cm_info.ird; |
| 1388 | |
| 1389 | if ((ep->rtr_type & MPA_RTR_TYPE_ZERO_READ) && |
| 1390 | (iparams->ird == 0)) |
| 1391 | iparams->ird = 1; |
| 1392 | } |
| 1393 | |
| 1394 | /* Update cm_info ord/ird to be negotiated values */ |
| 1395 | ep->cm_info.ord = iparams->ord; |
| 1396 | ep->cm_info.ird = iparams->ird; |
| 1397 | |
| 1398 | qed_iwarp_mpa_v2_set_private(p_hwfn, ep, &mpa_data_size); |
| 1399 | |
| 1400 | ep->cm_info.private_data = ep->ep_buffer_virt->out_pdata; |
| 1401 | ep->cm_info.private_data_len = iparams->private_data_len + |
| 1402 | mpa_data_size; |
| 1403 | |
| 1404 | memcpy((u8 *)ep->ep_buffer_virt->out_pdata + mpa_data_size, |
| 1405 | iparams->private_data, iparams->private_data_len); |
| 1406 | |
| 1407 | rc = qed_iwarp_mpa_offload(p_hwfn, ep); |
| 1408 | if (rc) |
| 1409 | qed_iwarp_modify_qp(p_hwfn, |
| 1410 | iparams->qp, QED_IWARP_QP_STATE_ERROR, 1); |
| 1411 | |
| 1412 | return rc; |
| 1413 | } |
| 1414 | |
| 1415 | int qed_iwarp_reject(void *rdma_cxt, struct qed_iwarp_reject_in *iparams) |
| 1416 | { |
| 1417 | struct qed_hwfn *p_hwfn = rdma_cxt; |
| 1418 | struct qed_iwarp_ep *ep; |
| 1419 | u8 mpa_data_size = 0; |
| 1420 | |
| 1421 | ep = iparams->ep_context; |
| 1422 | if (!ep) { |
| 1423 | DP_ERR(p_hwfn, "Ep Context receive in reject is NULL\n"); |
| 1424 | return -EINVAL; |
| 1425 | } |
| 1426 | |
| 1427 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "EP(0x%x)\n", ep->tcp_cid); |
| 1428 | |
| 1429 | ep->cb_context = iparams->cb_context; |
| 1430 | ep->qp = NULL; |
| 1431 | |
| 1432 | qed_iwarp_mpa_v2_set_private(p_hwfn, ep, &mpa_data_size); |
| 1433 | |
| 1434 | ep->cm_info.private_data = ep->ep_buffer_virt->out_pdata; |
| 1435 | ep->cm_info.private_data_len = iparams->private_data_len + |
| 1436 | mpa_data_size; |
| 1437 | |
| 1438 | memcpy((u8 *)ep->ep_buffer_virt->out_pdata + mpa_data_size, |
| 1439 | iparams->private_data, iparams->private_data_len); |
| 1440 | |
| 1441 | return qed_iwarp_mpa_offload(p_hwfn, ep); |
Kalderon, Michal | 67b40dc | 2017-07-02 10:29:22 +0300 | [diff] [blame] | 1442 | } |
| 1443 | |
Kalderon, Michal | 65a91a6 | 2017-07-02 10:29:26 +0300 | [diff] [blame] | 1444 | static void |
| 1445 | qed_iwarp_print_cm_info(struct qed_hwfn *p_hwfn, |
| 1446 | struct qed_iwarp_cm_info *cm_info) |
| 1447 | { |
| 1448 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "ip_version = %d\n", |
| 1449 | cm_info->ip_version); |
| 1450 | |
| 1451 | if (cm_info->ip_version == QED_TCP_IPV4) |
| 1452 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 1453 | "remote_ip %pI4h:%x, local_ip %pI4h:%x vlan=%x\n", |
| 1454 | cm_info->remote_ip, cm_info->remote_port, |
| 1455 | cm_info->local_ip, cm_info->local_port, |
| 1456 | cm_info->vlan); |
| 1457 | else |
| 1458 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 1459 | "remote_ip %pI6h:%x, local_ip %pI6h:%x vlan=%x\n", |
| 1460 | cm_info->remote_ip, cm_info->remote_port, |
| 1461 | cm_info->local_ip, cm_info->local_port, |
| 1462 | cm_info->vlan); |
| 1463 | |
| 1464 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 1465 | "private_data_len = %x ord = %d, ird = %d\n", |
| 1466 | cm_info->private_data_len, cm_info->ord, cm_info->ird); |
| 1467 | } |
| 1468 | |
Kalderon, Michal | b5c29ca | 2017-07-02 10:29:25 +0300 | [diff] [blame] | 1469 | static int |
| 1470 | qed_iwarp_ll2_post_rx(struct qed_hwfn *p_hwfn, |
| 1471 | struct qed_iwarp_ll2_buff *buf, u8 handle) |
| 1472 | { |
| 1473 | int rc; |
| 1474 | |
| 1475 | rc = qed_ll2_post_rx_buffer(p_hwfn, handle, buf->data_phys_addr, |
| 1476 | (u16)buf->buff_size, buf, 1); |
| 1477 | if (rc) { |
| 1478 | DP_NOTICE(p_hwfn, |
| 1479 | "Failed to repost rx buffer to ll2 rc = %d, handle=%d\n", |
| 1480 | rc, handle); |
| 1481 | dma_free_coherent(&p_hwfn->cdev->pdev->dev, buf->buff_size, |
| 1482 | buf->data, buf->data_phys_addr); |
| 1483 | kfree(buf); |
| 1484 | } |
| 1485 | |
| 1486 | return rc; |
| 1487 | } |
| 1488 | |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 1489 | static bool |
| 1490 | qed_iwarp_ep_exists(struct qed_hwfn *p_hwfn, struct qed_iwarp_cm_info *cm_info) |
| 1491 | { |
| 1492 | struct qed_iwarp_ep *ep = NULL; |
| 1493 | bool found = false; |
| 1494 | |
| 1495 | list_for_each_entry(ep, |
| 1496 | &p_hwfn->p_rdma_info->iwarp.ep_list, |
| 1497 | list_entry) { |
| 1498 | if ((ep->cm_info.local_port == cm_info->local_port) && |
| 1499 | (ep->cm_info.remote_port == cm_info->remote_port) && |
| 1500 | (ep->cm_info.vlan == cm_info->vlan) && |
| 1501 | !memcmp(&ep->cm_info.local_ip, cm_info->local_ip, |
| 1502 | sizeof(cm_info->local_ip)) && |
| 1503 | !memcmp(&ep->cm_info.remote_ip, cm_info->remote_ip, |
| 1504 | sizeof(cm_info->remote_ip))) { |
| 1505 | found = true; |
| 1506 | break; |
| 1507 | } |
| 1508 | } |
| 1509 | |
| 1510 | if (found) { |
| 1511 | DP_NOTICE(p_hwfn, |
| 1512 | "SYN received on active connection - dropping\n"); |
| 1513 | qed_iwarp_print_cm_info(p_hwfn, cm_info); |
| 1514 | |
| 1515 | return true; |
| 1516 | } |
| 1517 | |
| 1518 | return false; |
| 1519 | } |
| 1520 | |
Kalderon, Michal | 65a91a6 | 2017-07-02 10:29:26 +0300 | [diff] [blame] | 1521 | static struct qed_iwarp_listener * |
| 1522 | qed_iwarp_get_listener(struct qed_hwfn *p_hwfn, |
| 1523 | struct qed_iwarp_cm_info *cm_info) |
| 1524 | { |
| 1525 | struct qed_iwarp_listener *listener = NULL; |
| 1526 | static const u32 ip_zero[4] = { 0, 0, 0, 0 }; |
| 1527 | bool found = false; |
| 1528 | |
| 1529 | qed_iwarp_print_cm_info(p_hwfn, cm_info); |
| 1530 | |
| 1531 | list_for_each_entry(listener, |
| 1532 | &p_hwfn->p_rdma_info->iwarp.listen_list, |
| 1533 | list_entry) { |
| 1534 | if (listener->port == cm_info->local_port) { |
| 1535 | if (!memcmp(listener->ip_addr, |
| 1536 | ip_zero, sizeof(ip_zero))) { |
| 1537 | found = true; |
| 1538 | break; |
| 1539 | } |
| 1540 | |
| 1541 | if (!memcmp(listener->ip_addr, |
| 1542 | cm_info->local_ip, |
| 1543 | sizeof(cm_info->local_ip)) && |
| 1544 | (listener->vlan == cm_info->vlan)) { |
| 1545 | found = true; |
| 1546 | break; |
| 1547 | } |
| 1548 | } |
| 1549 | } |
| 1550 | |
| 1551 | if (found) { |
| 1552 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "listener found = %p\n", |
| 1553 | listener); |
| 1554 | return listener; |
| 1555 | } |
| 1556 | |
| 1557 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "listener not found\n"); |
| 1558 | return NULL; |
| 1559 | } |
| 1560 | |
| 1561 | static int |
| 1562 | qed_iwarp_parse_rx_pkt(struct qed_hwfn *p_hwfn, |
| 1563 | struct qed_iwarp_cm_info *cm_info, |
| 1564 | void *buf, |
| 1565 | u8 *remote_mac_addr, |
| 1566 | u8 *local_mac_addr, |
| 1567 | int *payload_len, int *tcp_start_offset) |
| 1568 | { |
| 1569 | struct vlan_ethhdr *vethh; |
| 1570 | bool vlan_valid = false; |
| 1571 | struct ipv6hdr *ip6h; |
| 1572 | struct ethhdr *ethh; |
| 1573 | struct tcphdr *tcph; |
| 1574 | struct iphdr *iph; |
| 1575 | int eth_hlen; |
| 1576 | int ip_hlen; |
| 1577 | int eth_type; |
| 1578 | int i; |
| 1579 | |
| 1580 | ethh = buf; |
| 1581 | eth_type = ntohs(ethh->h_proto); |
| 1582 | if (eth_type == ETH_P_8021Q) { |
| 1583 | vlan_valid = true; |
| 1584 | vethh = (struct vlan_ethhdr *)ethh; |
| 1585 | cm_info->vlan = ntohs(vethh->h_vlan_TCI) & VLAN_VID_MASK; |
| 1586 | eth_type = ntohs(vethh->h_vlan_encapsulated_proto); |
| 1587 | } |
| 1588 | |
| 1589 | eth_hlen = ETH_HLEN + (vlan_valid ? sizeof(u32) : 0); |
| 1590 | |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 1591 | ether_addr_copy(remote_mac_addr, ethh->h_source); |
| 1592 | ether_addr_copy(local_mac_addr, ethh->h_dest); |
Kalderon, Michal | 65a91a6 | 2017-07-02 10:29:26 +0300 | [diff] [blame] | 1593 | |
| 1594 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "eth_type =%d source mac: %pM\n", |
| 1595 | eth_type, ethh->h_source); |
| 1596 | |
| 1597 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "eth_hlen=%d destination mac: %pM\n", |
| 1598 | eth_hlen, ethh->h_dest); |
| 1599 | |
| 1600 | iph = (struct iphdr *)((u8 *)(ethh) + eth_hlen); |
| 1601 | |
| 1602 | if (eth_type == ETH_P_IP) { |
| 1603 | cm_info->local_ip[0] = ntohl(iph->daddr); |
| 1604 | cm_info->remote_ip[0] = ntohl(iph->saddr); |
| 1605 | cm_info->ip_version = TCP_IPV4; |
| 1606 | |
| 1607 | ip_hlen = (iph->ihl) * sizeof(u32); |
| 1608 | *payload_len = ntohs(iph->tot_len) - ip_hlen; |
| 1609 | } else if (eth_type == ETH_P_IPV6) { |
| 1610 | ip6h = (struct ipv6hdr *)iph; |
| 1611 | for (i = 0; i < 4; i++) { |
| 1612 | cm_info->local_ip[i] = |
| 1613 | ntohl(ip6h->daddr.in6_u.u6_addr32[i]); |
| 1614 | cm_info->remote_ip[i] = |
| 1615 | ntohl(ip6h->saddr.in6_u.u6_addr32[i]); |
| 1616 | } |
| 1617 | cm_info->ip_version = TCP_IPV6; |
| 1618 | |
| 1619 | ip_hlen = sizeof(*ip6h); |
| 1620 | *payload_len = ntohs(ip6h->payload_len); |
| 1621 | } else { |
| 1622 | DP_NOTICE(p_hwfn, "Unexpected ethertype on ll2 %x\n", eth_type); |
| 1623 | return -EINVAL; |
| 1624 | } |
| 1625 | |
| 1626 | tcph = (struct tcphdr *)((u8 *)iph + ip_hlen); |
| 1627 | |
| 1628 | if (!tcph->syn) { |
| 1629 | DP_NOTICE(p_hwfn, |
| 1630 | "Only SYN type packet expected on this ll2 conn, iph->ihl=%d source=%d dest=%d\n", |
| 1631 | iph->ihl, tcph->source, tcph->dest); |
| 1632 | return -EINVAL; |
| 1633 | } |
| 1634 | |
| 1635 | cm_info->local_port = ntohs(tcph->dest); |
| 1636 | cm_info->remote_port = ntohs(tcph->source); |
| 1637 | |
| 1638 | qed_iwarp_print_cm_info(p_hwfn, cm_info); |
| 1639 | |
| 1640 | *tcp_start_offset = eth_hlen + ip_hlen; |
| 1641 | |
| 1642 | return 0; |
| 1643 | } |
| 1644 | |
Kalderon, Michal | b5c29ca | 2017-07-02 10:29:25 +0300 | [diff] [blame] | 1645 | static void |
| 1646 | qed_iwarp_ll2_comp_syn_pkt(void *cxt, struct qed_ll2_comp_rx_data *data) |
| 1647 | { |
| 1648 | struct qed_iwarp_ll2_buff *buf = data->cookie; |
Kalderon, Michal | 65a91a6 | 2017-07-02 10:29:26 +0300 | [diff] [blame] | 1649 | struct qed_iwarp_listener *listener; |
| 1650 | struct qed_ll2_tx_pkt_info tx_pkt; |
| 1651 | struct qed_iwarp_cm_info cm_info; |
Kalderon, Michal | b5c29ca | 2017-07-02 10:29:25 +0300 | [diff] [blame] | 1652 | struct qed_hwfn *p_hwfn = cxt; |
Kalderon, Michal | 65a91a6 | 2017-07-02 10:29:26 +0300 | [diff] [blame] | 1653 | u8 remote_mac_addr[ETH_ALEN]; |
| 1654 | u8 local_mac_addr[ETH_ALEN]; |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 1655 | struct qed_iwarp_ep *ep; |
Kalderon, Michal | 65a91a6 | 2017-07-02 10:29:26 +0300 | [diff] [blame] | 1656 | int tcp_start_offset; |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 1657 | u8 ts_hdr_size = 0; |
Kalderon, Michal | 65a91a6 | 2017-07-02 10:29:26 +0300 | [diff] [blame] | 1658 | u8 ll2_syn_handle; |
| 1659 | int payload_len; |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 1660 | u32 hdr_size; |
Kalderon, Michal | 65a91a6 | 2017-07-02 10:29:26 +0300 | [diff] [blame] | 1661 | int rc; |
| 1662 | |
| 1663 | memset(&cm_info, 0, sizeof(cm_info)); |
Kalderon, Michal | b5c29ca | 2017-07-02 10:29:25 +0300 | [diff] [blame] | 1664 | |
| 1665 | if (GET_FIELD(data->parse_flags, |
| 1666 | PARSING_AND_ERR_FLAGS_L4CHKSMWASCALCULATED) && |
| 1667 | GET_FIELD(data->parse_flags, PARSING_AND_ERR_FLAGS_L4CHKSMERROR)) { |
| 1668 | DP_NOTICE(p_hwfn, "Syn packet received with checksum error\n"); |
| 1669 | goto err; |
| 1670 | } |
| 1671 | |
Kalderon, Michal | 65a91a6 | 2017-07-02 10:29:26 +0300 | [diff] [blame] | 1672 | rc = qed_iwarp_parse_rx_pkt(p_hwfn, &cm_info, (u8 *)(buf->data) + |
| 1673 | data->u.placement_offset, remote_mac_addr, |
| 1674 | local_mac_addr, &payload_len, |
| 1675 | &tcp_start_offset); |
| 1676 | if (rc) |
| 1677 | goto err; |
Kalderon, Michal | b5c29ca | 2017-07-02 10:29:25 +0300 | [diff] [blame] | 1678 | |
Kalderon, Michal | 65a91a6 | 2017-07-02 10:29:26 +0300 | [diff] [blame] | 1679 | /* Check if there is a listener for this 4-tuple+vlan */ |
| 1680 | ll2_syn_handle = p_hwfn->p_rdma_info->iwarp.ll2_syn_handle; |
| 1681 | listener = qed_iwarp_get_listener(p_hwfn, &cm_info); |
| 1682 | if (!listener) { |
| 1683 | DP_VERBOSE(p_hwfn, |
| 1684 | QED_MSG_RDMA, |
| 1685 | "SYN received on tuple not listened on parse_flags=%d packet len=%d\n", |
| 1686 | data->parse_flags, data->length.packet_length); |
| 1687 | |
| 1688 | memset(&tx_pkt, 0, sizeof(tx_pkt)); |
| 1689 | tx_pkt.num_of_bds = 1; |
| 1690 | tx_pkt.vlan = data->vlan; |
| 1691 | |
| 1692 | if (GET_FIELD(data->parse_flags, |
| 1693 | PARSING_AND_ERR_FLAGS_TAG8021QEXIST)) |
| 1694 | SET_FIELD(tx_pkt.bd_flags, |
| 1695 | CORE_TX_BD_DATA_VLAN_INSERTION, 1); |
| 1696 | |
| 1697 | tx_pkt.l4_hdr_offset_w = (data->length.packet_length) >> 2; |
| 1698 | tx_pkt.tx_dest = QED_LL2_TX_DEST_LB; |
| 1699 | tx_pkt.first_frag = buf->data_phys_addr + |
| 1700 | data->u.placement_offset; |
| 1701 | tx_pkt.first_frag_len = data->length.packet_length; |
| 1702 | tx_pkt.cookie = buf; |
| 1703 | |
| 1704 | rc = qed_ll2_prepare_tx_packet(p_hwfn, ll2_syn_handle, |
| 1705 | &tx_pkt, true); |
| 1706 | |
| 1707 | if (rc) { |
| 1708 | DP_NOTICE(p_hwfn, |
| 1709 | "Can't post SYN back to chip rc=%d\n", rc); |
| 1710 | goto err; |
| 1711 | } |
| 1712 | return; |
| 1713 | } |
| 1714 | |
| 1715 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Received syn on listening port\n"); |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 1716 | /* There may be an open ep on this connection if this is a syn |
| 1717 | * retrasnmit... need to make sure there isn't... |
| 1718 | */ |
| 1719 | if (qed_iwarp_ep_exists(p_hwfn, &cm_info)) |
| 1720 | goto err; |
| 1721 | |
| 1722 | ep = qed_iwarp_get_free_ep(p_hwfn); |
| 1723 | if (!ep) |
| 1724 | goto err; |
| 1725 | |
| 1726 | spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock); |
| 1727 | list_add_tail(&ep->list_entry, &p_hwfn->p_rdma_info->iwarp.ep_list); |
| 1728 | spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock); |
| 1729 | |
| 1730 | ether_addr_copy(ep->remote_mac_addr, remote_mac_addr); |
| 1731 | ether_addr_copy(ep->local_mac_addr, local_mac_addr); |
| 1732 | |
| 1733 | memcpy(&ep->cm_info, &cm_info, sizeof(ep->cm_info)); |
| 1734 | |
| 1735 | if (p_hwfn->p_rdma_info->iwarp.tcp_flags & QED_IWARP_TS_EN) |
| 1736 | ts_hdr_size = TIMESTAMP_HEADER_SIZE; |
| 1737 | |
| 1738 | hdr_size = ((cm_info.ip_version == QED_TCP_IPV4) ? 40 : 60) + |
| 1739 | ts_hdr_size; |
| 1740 | ep->mss = p_hwfn->p_rdma_info->iwarp.max_mtu - hdr_size; |
| 1741 | ep->mss = min_t(u16, QED_IWARP_MAX_FW_MSS, ep->mss); |
| 1742 | |
| 1743 | ep->event_cb = listener->event_cb; |
| 1744 | ep->cb_context = listener->cb_context; |
| 1745 | ep->connect_mode = TCP_CONNECT_PASSIVE; |
| 1746 | |
| 1747 | ep->syn = buf; |
| 1748 | ep->syn_ip_payload_length = (u16)payload_len; |
| 1749 | ep->syn_phy_addr = buf->data_phys_addr + data->u.placement_offset + |
| 1750 | tcp_start_offset; |
| 1751 | |
| 1752 | rc = qed_iwarp_tcp_offload(p_hwfn, ep); |
| 1753 | if (rc) { |
| 1754 | qed_iwarp_return_ep(p_hwfn, ep); |
| 1755 | goto err; |
| 1756 | } |
| 1757 | |
| 1758 | return; |
Kalderon, Michal | b5c29ca | 2017-07-02 10:29:25 +0300 | [diff] [blame] | 1759 | err: |
Kalderon, Michal | 65a91a6 | 2017-07-02 10:29:26 +0300 | [diff] [blame] | 1760 | qed_iwarp_ll2_post_rx(p_hwfn, buf, ll2_syn_handle); |
Kalderon, Michal | b5c29ca | 2017-07-02 10:29:25 +0300 | [diff] [blame] | 1761 | } |
| 1762 | |
| 1763 | static void qed_iwarp_ll2_rel_rx_pkt(void *cxt, u8 connection_handle, |
| 1764 | void *cookie, dma_addr_t rx_buf_addr, |
| 1765 | bool b_last_packet) |
| 1766 | { |
| 1767 | struct qed_iwarp_ll2_buff *buffer = cookie; |
| 1768 | struct qed_hwfn *p_hwfn = cxt; |
| 1769 | |
| 1770 | dma_free_coherent(&p_hwfn->cdev->pdev->dev, buffer->buff_size, |
| 1771 | buffer->data, buffer->data_phys_addr); |
| 1772 | kfree(buffer); |
| 1773 | } |
| 1774 | |
| 1775 | static void qed_iwarp_ll2_comp_tx_pkt(void *cxt, u8 connection_handle, |
| 1776 | void *cookie, dma_addr_t first_frag_addr, |
| 1777 | bool b_last_fragment, bool b_last_packet) |
| 1778 | { |
| 1779 | struct qed_iwarp_ll2_buff *buffer = cookie; |
| 1780 | struct qed_hwfn *p_hwfn = cxt; |
| 1781 | |
| 1782 | /* this was originally an rx packet, post it back */ |
| 1783 | qed_iwarp_ll2_post_rx(p_hwfn, buffer, connection_handle); |
| 1784 | } |
| 1785 | |
| 1786 | static void qed_iwarp_ll2_rel_tx_pkt(void *cxt, u8 connection_handle, |
| 1787 | void *cookie, dma_addr_t first_frag_addr, |
| 1788 | bool b_last_fragment, bool b_last_packet) |
| 1789 | { |
| 1790 | struct qed_iwarp_ll2_buff *buffer = cookie; |
| 1791 | struct qed_hwfn *p_hwfn = cxt; |
| 1792 | |
| 1793 | if (!buffer) |
| 1794 | return; |
| 1795 | |
| 1796 | dma_free_coherent(&p_hwfn->cdev->pdev->dev, buffer->buff_size, |
| 1797 | buffer->data, buffer->data_phys_addr); |
| 1798 | |
| 1799 | kfree(buffer); |
| 1800 | } |
| 1801 | |
| 1802 | static int qed_iwarp_ll2_stop(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
| 1803 | { |
| 1804 | struct qed_iwarp_info *iwarp_info = &p_hwfn->p_rdma_info->iwarp; |
| 1805 | int rc = 0; |
| 1806 | |
| 1807 | if (iwarp_info->ll2_syn_handle != QED_IWARP_HANDLE_INVAL) { |
| 1808 | rc = qed_ll2_terminate_connection(p_hwfn, |
| 1809 | iwarp_info->ll2_syn_handle); |
| 1810 | if (rc) |
| 1811 | DP_INFO(p_hwfn, "Failed to terminate syn connection\n"); |
| 1812 | |
| 1813 | qed_ll2_release_connection(p_hwfn, iwarp_info->ll2_syn_handle); |
| 1814 | iwarp_info->ll2_syn_handle = QED_IWARP_HANDLE_INVAL; |
| 1815 | } |
| 1816 | |
| 1817 | qed_llh_remove_mac_filter(p_hwfn, |
| 1818 | p_ptt, p_hwfn->p_rdma_info->iwarp.mac_addr); |
| 1819 | return rc; |
| 1820 | } |
| 1821 | |
| 1822 | static int |
| 1823 | qed_iwarp_ll2_alloc_buffers(struct qed_hwfn *p_hwfn, |
| 1824 | int num_rx_bufs, int buff_size, u8 ll2_handle) |
| 1825 | { |
| 1826 | struct qed_iwarp_ll2_buff *buffer; |
| 1827 | int rc = 0; |
| 1828 | int i; |
| 1829 | |
| 1830 | for (i = 0; i < num_rx_bufs; i++) { |
| 1831 | buffer = kzalloc(sizeof(*buffer), GFP_KERNEL); |
| 1832 | if (!buffer) { |
| 1833 | rc = -ENOMEM; |
| 1834 | break; |
| 1835 | } |
| 1836 | |
| 1837 | buffer->data = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev, |
| 1838 | buff_size, |
| 1839 | &buffer->data_phys_addr, |
| 1840 | GFP_KERNEL); |
| 1841 | if (!buffer->data) { |
| 1842 | kfree(buffer); |
| 1843 | rc = -ENOMEM; |
| 1844 | break; |
| 1845 | } |
| 1846 | |
| 1847 | buffer->buff_size = buff_size; |
| 1848 | rc = qed_iwarp_ll2_post_rx(p_hwfn, buffer, ll2_handle); |
| 1849 | if (rc) |
| 1850 | /* buffers will be deallocated by qed_ll2 */ |
| 1851 | break; |
| 1852 | } |
| 1853 | return rc; |
| 1854 | } |
| 1855 | |
| 1856 | #define QED_IWARP_MAX_BUF_SIZE(mtu) \ |
| 1857 | ALIGN((mtu) + ETH_HLEN + 2 * VLAN_HLEN + 2 + ETH_CACHE_LINE_SIZE, \ |
| 1858 | ETH_CACHE_LINE_SIZE) |
| 1859 | |
| 1860 | static int |
| 1861 | qed_iwarp_ll2_start(struct qed_hwfn *p_hwfn, |
| 1862 | struct qed_rdma_start_in_params *params, |
| 1863 | struct qed_ptt *p_ptt) |
| 1864 | { |
| 1865 | struct qed_iwarp_info *iwarp_info; |
| 1866 | struct qed_ll2_acquire_data data; |
| 1867 | struct qed_ll2_cbs cbs; |
| 1868 | int rc = 0; |
| 1869 | |
| 1870 | iwarp_info = &p_hwfn->p_rdma_info->iwarp; |
| 1871 | iwarp_info->ll2_syn_handle = QED_IWARP_HANDLE_INVAL; |
| 1872 | |
| 1873 | iwarp_info->max_mtu = params->max_mtu; |
| 1874 | |
| 1875 | ether_addr_copy(p_hwfn->p_rdma_info->iwarp.mac_addr, params->mac_addr); |
| 1876 | |
| 1877 | rc = qed_llh_add_mac_filter(p_hwfn, p_ptt, params->mac_addr); |
| 1878 | if (rc) |
| 1879 | return rc; |
| 1880 | |
| 1881 | /* Start SYN connection */ |
| 1882 | cbs.rx_comp_cb = qed_iwarp_ll2_comp_syn_pkt; |
| 1883 | cbs.rx_release_cb = qed_iwarp_ll2_rel_rx_pkt; |
| 1884 | cbs.tx_comp_cb = qed_iwarp_ll2_comp_tx_pkt; |
| 1885 | cbs.tx_release_cb = qed_iwarp_ll2_rel_tx_pkt; |
| 1886 | cbs.cookie = p_hwfn; |
| 1887 | |
| 1888 | memset(&data, 0, sizeof(data)); |
| 1889 | data.input.conn_type = QED_LL2_TYPE_IWARP; |
| 1890 | data.input.mtu = QED_IWARP_MAX_SYN_PKT_SIZE; |
| 1891 | data.input.rx_num_desc = QED_IWARP_LL2_SYN_RX_SIZE; |
| 1892 | data.input.tx_num_desc = QED_IWARP_LL2_SYN_TX_SIZE; |
| 1893 | data.input.tx_max_bds_per_packet = 1; /* will never be fragmented */ |
| 1894 | data.input.tx_tc = PKT_LB_TC; |
| 1895 | data.input.tx_dest = QED_LL2_TX_DEST_LB; |
| 1896 | data.p_connection_handle = &iwarp_info->ll2_syn_handle; |
| 1897 | data.cbs = &cbs; |
| 1898 | |
| 1899 | rc = qed_ll2_acquire_connection(p_hwfn, &data); |
| 1900 | if (rc) { |
| 1901 | DP_NOTICE(p_hwfn, "Failed to acquire LL2 connection\n"); |
| 1902 | qed_llh_remove_mac_filter(p_hwfn, p_ptt, params->mac_addr); |
| 1903 | return rc; |
| 1904 | } |
| 1905 | |
| 1906 | rc = qed_ll2_establish_connection(p_hwfn, iwarp_info->ll2_syn_handle); |
| 1907 | if (rc) { |
| 1908 | DP_NOTICE(p_hwfn, "Failed to establish LL2 connection\n"); |
| 1909 | goto err; |
| 1910 | } |
| 1911 | |
| 1912 | rc = qed_iwarp_ll2_alloc_buffers(p_hwfn, |
| 1913 | QED_IWARP_LL2_SYN_RX_SIZE, |
| 1914 | QED_IWARP_MAX_SYN_PKT_SIZE, |
| 1915 | iwarp_info->ll2_syn_handle); |
| 1916 | if (rc) |
| 1917 | goto err; |
| 1918 | |
| 1919 | return rc; |
| 1920 | err: |
| 1921 | qed_iwarp_ll2_stop(p_hwfn, p_ptt); |
| 1922 | |
| 1923 | return rc; |
| 1924 | } |
| 1925 | |
Kalderon, Michal | 67b40dc | 2017-07-02 10:29:22 +0300 | [diff] [blame] | 1926 | int qed_iwarp_setup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt, |
| 1927 | struct qed_rdma_start_in_params *params) |
| 1928 | { |
| 1929 | struct qed_iwarp_info *iwarp_info; |
| 1930 | u32 rcv_wnd_size; |
Kalderon, Michal | 67b40dc | 2017-07-02 10:29:22 +0300 | [diff] [blame] | 1931 | |
| 1932 | iwarp_info = &p_hwfn->p_rdma_info->iwarp; |
| 1933 | |
| 1934 | iwarp_info->tcp_flags = QED_IWARP_TS_EN; |
| 1935 | rcv_wnd_size = QED_IWARP_RCV_WND_SIZE_DEF; |
| 1936 | |
| 1937 | /* value 0 is used for ilog2(QED_IWARP_RCV_WND_SIZE_MIN) */ |
| 1938 | iwarp_info->rcv_wnd_scale = ilog2(rcv_wnd_size) - |
| 1939 | ilog2(QED_IWARP_RCV_WND_SIZE_MIN); |
| 1940 | iwarp_info->crc_needed = QED_IWARP_PARAM_CRC_NEEDED; |
| 1941 | iwarp_info->mpa_rev = MPA_NEGOTIATION_TYPE_ENHANCED; |
| 1942 | |
| 1943 | iwarp_info->peer2peer = QED_IWARP_PARAM_P2P; |
| 1944 | |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 1945 | iwarp_info->rtr_type = MPA_RTR_TYPE_ZERO_SEND | |
| 1946 | MPA_RTR_TYPE_ZERO_WRITE | |
| 1947 | MPA_RTR_TYPE_ZERO_READ; |
| 1948 | |
Kalderon, Michal | 67b40dc | 2017-07-02 10:29:22 +0300 | [diff] [blame] | 1949 | spin_lock_init(&p_hwfn->p_rdma_info->iwarp.qp_lock); |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 1950 | INIT_LIST_HEAD(&p_hwfn->p_rdma_info->iwarp.ep_list); |
Kalderon, Michal | 65a91a6 | 2017-07-02 10:29:26 +0300 | [diff] [blame] | 1951 | INIT_LIST_HEAD(&p_hwfn->p_rdma_info->iwarp.listen_list); |
Kalderon, Michal | 67b40dc | 2017-07-02 10:29:22 +0300 | [diff] [blame] | 1952 | |
| 1953 | qed_spq_register_async_cb(p_hwfn, PROTOCOLID_IWARP, |
| 1954 | qed_iwarp_async_event); |
| 1955 | |
Kalderon, Michal | b5c29ca | 2017-07-02 10:29:25 +0300 | [diff] [blame] | 1956 | return qed_iwarp_ll2_start(p_hwfn, params, p_ptt); |
Kalderon, Michal | 67b40dc | 2017-07-02 10:29:22 +0300 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | int qed_iwarp_stop(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
| 1960 | { |
| 1961 | int rc; |
| 1962 | |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 1963 | qed_iwarp_free_prealloc_ep(p_hwfn); |
Kalderon, Michal | 67b40dc | 2017-07-02 10:29:22 +0300 | [diff] [blame] | 1964 | rc = qed_iwarp_wait_for_all_cids(p_hwfn); |
| 1965 | if (rc) |
| 1966 | return rc; |
| 1967 | |
| 1968 | qed_spq_unregister_async_cb(p_hwfn, PROTOCOLID_IWARP); |
| 1969 | |
Kalderon, Michal | b5c29ca | 2017-07-02 10:29:25 +0300 | [diff] [blame] | 1970 | return qed_iwarp_ll2_stop(p_hwfn, p_ptt); |
Kalderon, Michal | 67b40dc | 2017-07-02 10:29:22 +0300 | [diff] [blame] | 1971 | } |
| 1972 | |
Kalderon, Michal | fc4c606 | 2017-07-02 10:29:29 +0300 | [diff] [blame^] | 1973 | void qed_iwarp_qp_in_error(struct qed_hwfn *p_hwfn, |
| 1974 | struct qed_iwarp_ep *ep, u8 fw_return_code) |
| 1975 | { |
| 1976 | struct qed_iwarp_cm_event_params params; |
| 1977 | |
| 1978 | qed_iwarp_modify_qp(p_hwfn, ep->qp, QED_IWARP_QP_STATE_ERROR, true); |
| 1979 | |
| 1980 | params.event = QED_IWARP_EVENT_CLOSE; |
| 1981 | params.ep_context = ep; |
| 1982 | params.cm_info = &ep->cm_info; |
| 1983 | params.status = (fw_return_code == IWARP_QP_IN_ERROR_GOOD_CLOSE) ? |
| 1984 | 0 : -ECONNRESET; |
| 1985 | |
| 1986 | ep->state = QED_IWARP_EP_CLOSED; |
| 1987 | spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock); |
| 1988 | list_del(&ep->list_entry); |
| 1989 | spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock); |
| 1990 | |
| 1991 | ep->event_cb(ep->cb_context, ¶ms); |
| 1992 | } |
| 1993 | |
| 1994 | void qed_iwarp_exception_received(struct qed_hwfn *p_hwfn, |
| 1995 | struct qed_iwarp_ep *ep, int fw_ret_code) |
| 1996 | { |
| 1997 | struct qed_iwarp_cm_event_params params; |
| 1998 | bool event_cb = false; |
| 1999 | |
| 2000 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "EP(0x%x) fw_ret_code=%d\n", |
| 2001 | ep->cid, fw_ret_code); |
| 2002 | |
| 2003 | switch (fw_ret_code) { |
| 2004 | case IWARP_EXCEPTION_DETECTED_LLP_CLOSED: |
| 2005 | params.status = 0; |
| 2006 | params.event = QED_IWARP_EVENT_DISCONNECT; |
| 2007 | event_cb = true; |
| 2008 | break; |
| 2009 | case IWARP_EXCEPTION_DETECTED_LLP_RESET: |
| 2010 | params.status = -ECONNRESET; |
| 2011 | params.event = QED_IWARP_EVENT_DISCONNECT; |
| 2012 | event_cb = true; |
| 2013 | break; |
| 2014 | default: |
| 2015 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 2016 | "Unhandled exception received...fw_ret_code=%d\n", |
| 2017 | fw_ret_code); |
| 2018 | break; |
| 2019 | } |
| 2020 | |
| 2021 | if (event_cb) { |
| 2022 | params.ep_context = ep; |
| 2023 | params.cm_info = &ep->cm_info; |
| 2024 | ep->event_cb(ep->cb_context, ¶ms); |
| 2025 | } |
| 2026 | } |
| 2027 | |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 2028 | void |
| 2029 | qed_iwarp_connect_complete(struct qed_hwfn *p_hwfn, |
| 2030 | struct qed_iwarp_ep *ep, u8 fw_return_code) |
| 2031 | { |
Kalderon, Michal | 4b0fdd7 | 2017-07-02 10:29:28 +0300 | [diff] [blame] | 2032 | u8 ll2_syn_handle = p_hwfn->p_rdma_info->iwarp.ll2_syn_handle; |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 2033 | |
Kalderon, Michal | 4b0fdd7 | 2017-07-02 10:29:28 +0300 | [diff] [blame] | 2034 | if (ep->connect_mode == TCP_CONNECT_PASSIVE) { |
| 2035 | /* Done with the SYN packet, post back to ll2 rx */ |
| 2036 | qed_iwarp_ll2_post_rx(p_hwfn, ep->syn, ll2_syn_handle); |
| 2037 | |
| 2038 | ep->syn = NULL; |
| 2039 | |
| 2040 | /* If connect failed - upper layer doesn't know about it */ |
| 2041 | qed_iwarp_mpa_received(p_hwfn, ep); |
| 2042 | } else { |
| 2043 | qed_iwarp_mpa_offload(p_hwfn, ep); |
| 2044 | } |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 2045 | } |
| 2046 | |
| 2047 | static inline bool |
| 2048 | qed_iwarp_check_ep_ok(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep) |
| 2049 | { |
| 2050 | if (!ep || (ep->sig != QED_EP_SIG)) { |
| 2051 | DP_ERR(p_hwfn, "ERROR ON ASYNC ep=%p\n", ep); |
| 2052 | return false; |
| 2053 | } |
| 2054 | |
| 2055 | return true; |
| 2056 | } |
| 2057 | |
Kalderon, Michal | 67b40dc | 2017-07-02 10:29:22 +0300 | [diff] [blame] | 2058 | static int qed_iwarp_async_event(struct qed_hwfn *p_hwfn, |
| 2059 | u8 fw_event_code, u16 echo, |
| 2060 | union event_ring_data *data, |
| 2061 | u8 fw_return_code) |
| 2062 | { |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 2063 | struct regpair *fw_handle = &data->rdma_data.async_handle; |
| 2064 | struct qed_iwarp_ep *ep = NULL; |
| 2065 | u16 cid; |
| 2066 | |
| 2067 | ep = (struct qed_iwarp_ep *)(uintptr_t)HILO_64(fw_handle->hi, |
| 2068 | fw_handle->lo); |
| 2069 | |
| 2070 | switch (fw_event_code) { |
| 2071 | case IWARP_EVENT_TYPE_ASYNC_CONNECT_COMPLETE: |
| 2072 | /* Async completion after TCP 3-way handshake */ |
| 2073 | if (!qed_iwarp_check_ep_ok(p_hwfn, ep)) |
| 2074 | return -EINVAL; |
| 2075 | DP_VERBOSE(p_hwfn, |
| 2076 | QED_MSG_RDMA, |
| 2077 | "EP(0x%x) IWARP_EVENT_TYPE_ASYNC_CONNECT_COMPLETE fw_ret_code=%d\n", |
| 2078 | ep->tcp_cid, fw_return_code); |
| 2079 | qed_iwarp_connect_complete(p_hwfn, ep, fw_return_code); |
| 2080 | break; |
Kalderon, Michal | fc4c606 | 2017-07-02 10:29:29 +0300 | [diff] [blame^] | 2081 | case IWARP_EVENT_TYPE_ASYNC_EXCEPTION_DETECTED: |
| 2082 | if (!qed_iwarp_check_ep_ok(p_hwfn, ep)) |
| 2083 | return -EINVAL; |
| 2084 | DP_VERBOSE(p_hwfn, |
| 2085 | QED_MSG_RDMA, |
| 2086 | "QP(0x%x) IWARP_EVENT_TYPE_ASYNC_EXCEPTION_DETECTED fw_ret_code=%d\n", |
| 2087 | ep->cid, fw_return_code); |
| 2088 | qed_iwarp_exception_received(p_hwfn, ep, fw_return_code); |
| 2089 | break; |
| 2090 | case IWARP_EVENT_TYPE_ASYNC_QP_IN_ERROR_STATE: |
| 2091 | /* Async completion for Close Connection ramrod */ |
| 2092 | if (!qed_iwarp_check_ep_ok(p_hwfn, ep)) |
| 2093 | return -EINVAL; |
| 2094 | DP_VERBOSE(p_hwfn, |
| 2095 | QED_MSG_RDMA, |
| 2096 | "QP(0x%x) IWARP_EVENT_TYPE_ASYNC_QP_IN_ERROR_STATE fw_ret_code=%d\n", |
| 2097 | ep->cid, fw_return_code); |
| 2098 | qed_iwarp_qp_in_error(p_hwfn, ep, fw_return_code); |
| 2099 | break; |
Kalderon, Michal | 4b0fdd7 | 2017-07-02 10:29:28 +0300 | [diff] [blame] | 2100 | case IWARP_EVENT_TYPE_ASYNC_ENHANCED_MPA_REPLY_ARRIVED: |
Kalderon, Michal | fc4c606 | 2017-07-02 10:29:29 +0300 | [diff] [blame^] | 2101 | /* Async event for active side only */ |
Kalderon, Michal | 4b0fdd7 | 2017-07-02 10:29:28 +0300 | [diff] [blame] | 2102 | if (!qed_iwarp_check_ep_ok(p_hwfn, ep)) |
| 2103 | return -EINVAL; |
| 2104 | DP_VERBOSE(p_hwfn, |
| 2105 | QED_MSG_RDMA, |
| 2106 | "QP(0x%x) IWARP_EVENT_TYPE_ASYNC_MPA_HANDSHAKE_MPA_REPLY_ARRIVED fw_ret_code=%d\n", |
| 2107 | ep->cid, fw_return_code); |
| 2108 | qed_iwarp_mpa_reply_arrived(p_hwfn, ep); |
| 2109 | break; |
Kalderon, Michal | 456a584 | 2017-07-02 10:29:27 +0300 | [diff] [blame] | 2110 | case IWARP_EVENT_TYPE_ASYNC_MPA_HANDSHAKE_COMPLETE: |
| 2111 | if (!qed_iwarp_check_ep_ok(p_hwfn, ep)) |
| 2112 | return -EINVAL; |
| 2113 | DP_VERBOSE(p_hwfn, |
| 2114 | QED_MSG_RDMA, |
| 2115 | "QP(0x%x) IWARP_EVENT_TYPE_ASYNC_MPA_HANDSHAKE_COMPLETE fw_ret_code=%d\n", |
| 2116 | ep->cid, fw_return_code); |
| 2117 | qed_iwarp_mpa_complete(p_hwfn, ep, fw_return_code); |
| 2118 | break; |
| 2119 | case IWARP_EVENT_TYPE_ASYNC_CID_CLEANED: |
| 2120 | cid = (u16)le32_to_cpu(fw_handle->lo); |
| 2121 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 2122 | "(0x%x)IWARP_EVENT_TYPE_ASYNC_CID_CLEANED\n", cid); |
| 2123 | qed_iwarp_cid_cleaned(p_hwfn, cid); |
| 2124 | |
| 2125 | break; |
| 2126 | } |
Kalderon, Michal | 67b40dc | 2017-07-02 10:29:22 +0300 | [diff] [blame] | 2127 | return 0; |
| 2128 | } |
| 2129 | |
Kalderon, Michal | 65a91a6 | 2017-07-02 10:29:26 +0300 | [diff] [blame] | 2130 | int |
| 2131 | qed_iwarp_create_listen(void *rdma_cxt, |
| 2132 | struct qed_iwarp_listen_in *iparams, |
| 2133 | struct qed_iwarp_listen_out *oparams) |
| 2134 | { |
| 2135 | struct qed_hwfn *p_hwfn = rdma_cxt; |
| 2136 | struct qed_iwarp_listener *listener; |
| 2137 | |
| 2138 | listener = kzalloc(sizeof(*listener), GFP_KERNEL); |
| 2139 | if (!listener) |
| 2140 | return -ENOMEM; |
| 2141 | |
| 2142 | listener->ip_version = iparams->ip_version; |
| 2143 | memcpy(listener->ip_addr, iparams->ip_addr, sizeof(listener->ip_addr)); |
| 2144 | listener->port = iparams->port; |
| 2145 | listener->vlan = iparams->vlan; |
| 2146 | |
| 2147 | listener->event_cb = iparams->event_cb; |
| 2148 | listener->cb_context = iparams->cb_context; |
| 2149 | listener->max_backlog = iparams->max_backlog; |
| 2150 | oparams->handle = listener; |
| 2151 | |
| 2152 | spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock); |
| 2153 | list_add_tail(&listener->list_entry, |
| 2154 | &p_hwfn->p_rdma_info->iwarp.listen_list); |
| 2155 | spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock); |
| 2156 | |
| 2157 | DP_VERBOSE(p_hwfn, |
| 2158 | QED_MSG_RDMA, |
| 2159 | "callback=%p handle=%p ip=%x:%x:%x:%x port=0x%x vlan=0x%x\n", |
| 2160 | listener->event_cb, |
| 2161 | listener, |
| 2162 | listener->ip_addr[0], |
| 2163 | listener->ip_addr[1], |
| 2164 | listener->ip_addr[2], |
| 2165 | listener->ip_addr[3], listener->port, listener->vlan); |
| 2166 | |
| 2167 | return 0; |
| 2168 | } |
| 2169 | |
| 2170 | int qed_iwarp_destroy_listen(void *rdma_cxt, void *handle) |
| 2171 | { |
| 2172 | struct qed_iwarp_listener *listener = handle; |
| 2173 | struct qed_hwfn *p_hwfn = rdma_cxt; |
| 2174 | |
| 2175 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "handle=%p\n", handle); |
| 2176 | |
| 2177 | spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock); |
| 2178 | list_del(&listener->list_entry); |
| 2179 | spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock); |
| 2180 | |
| 2181 | kfree(listener); |
| 2182 | |
| 2183 | return 0; |
| 2184 | } |
| 2185 | |
Kalderon, Michal | 4b0fdd7 | 2017-07-02 10:29:28 +0300 | [diff] [blame] | 2186 | int qed_iwarp_send_rtr(void *rdma_cxt, struct qed_iwarp_send_rtr_in *iparams) |
| 2187 | { |
| 2188 | struct qed_hwfn *p_hwfn = rdma_cxt; |
| 2189 | struct qed_sp_init_data init_data; |
| 2190 | struct qed_spq_entry *p_ent; |
| 2191 | struct qed_iwarp_ep *ep; |
| 2192 | struct qed_rdma_qp *qp; |
| 2193 | int rc; |
| 2194 | |
| 2195 | ep = iparams->ep_context; |
| 2196 | if (!ep) { |
| 2197 | DP_ERR(p_hwfn, "Ep Context receive in send_rtr is NULL\n"); |
| 2198 | return -EINVAL; |
| 2199 | } |
| 2200 | |
| 2201 | qp = ep->qp; |
| 2202 | |
| 2203 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP(0x%x) EP(0x%x)\n", |
| 2204 | qp->icid, ep->tcp_cid); |
| 2205 | |
| 2206 | memset(&init_data, 0, sizeof(init_data)); |
| 2207 | init_data.cid = qp->icid; |
| 2208 | init_data.opaque_fid = p_hwfn->hw_info.opaque_fid; |
| 2209 | init_data.comp_mode = QED_SPQ_MODE_CB; |
| 2210 | |
| 2211 | rc = qed_sp_init_request(p_hwfn, &p_ent, |
| 2212 | IWARP_RAMROD_CMD_ID_MPA_OFFLOAD_SEND_RTR, |
| 2213 | PROTOCOLID_IWARP, &init_data); |
| 2214 | |
| 2215 | if (rc) |
| 2216 | return rc; |
| 2217 | |
| 2218 | rc = qed_spq_post(p_hwfn, p_ent, NULL); |
| 2219 | |
| 2220 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "rc = 0x%x\n", rc); |
| 2221 | |
| 2222 | return rc; |
| 2223 | } |
| 2224 | |
Kalderon, Michal | 67b40dc | 2017-07-02 10:29:22 +0300 | [diff] [blame] | 2225 | void |
| 2226 | qed_iwarp_query_qp(struct qed_rdma_qp *qp, |
| 2227 | struct qed_rdma_query_qp_out_params *out_params) |
| 2228 | { |
| 2229 | out_params->state = qed_iwarp2roce_state(qp->iwarp_state); |
| 2230 | } |