16e76cdd6e3cfaac7d91c3b0644ee1bc6cf52347agiri * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
16e76cdd6e3cfaac7d91c3b0644ee1bc6cf52347agiri * This file contains code imported from the OFED rds source file ib_cm.c
16e76cdd6e3cfaac7d91c3b0644ee1bc6cf52347agiri * Oracle elects to have and use the contents of ib_cm.c under and governed
16e76cdd6e3cfaac7d91c3b0644ee1bc6cf52347agiri * by the OpenIB.org BSD license (see below for full license text). However,
16e76cdd6e3cfaac7d91c3b0644ee1bc6cf52347agiri * the following notice accompanied the original version of this file:
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Copyright (c) 2006 Oracle. All rights reserved.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * This software is available to you under a choice of one of two
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * licenses. You may choose to be licensed under the terms of the GNU
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * General Public License (GPL) Version 2, available from the file
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * COPYING in the main directory of this source tree, or the
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * OpenIB.org BSD license below:
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Redistribution and use in source and binary forms, with or
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * without modification, are permitted provided that the following
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * conditions are met:
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * - Redistributions of source code must retain the above
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * copyright notice, this list of conditions and the following
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * disclaimer.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * - Redistributions in binary form must reproduce the above
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * copyright notice, this list of conditions and the following
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * disclaimer in the documentation and/or other materials
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * provided with the distribution.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * SOFTWARE.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Set the selected protocol version
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_set_protocol(struct rdsv3_connection *conn, unsigned int version)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_ib_set_protocol", "conn: %p version: %d",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Set up flow control
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_set_flow_control(struct rdsv3_connection *conn, uint32_t credits)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota struct rdsv3_ib_connection *ic = conn->c_transport_data;
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota if (rdsv3_ib_sysctl_flow_control && credits != 0) {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* We're doing flow control */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "Return: conn: %p credits: %d",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Tune RNR behavior. Without flow control, we use a rather
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * low timeout, but not the absolute minimum - this should
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * be tunable.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * We already set the RNR retry count to 7 (which is the
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * smallest infinite number :-) above.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * If flow control is off, we want to change this back to 0
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * so that we learn quickly when our credit accounting is
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Caller passes in a qp_attr pointer - don't waste stack spacv
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * by allocation this twice.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_tune_rnr(struct rdsv3_ib_connection *ic, struct ib_qp_attr *attr)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF2("rdsv3_ib_tune_rnr", "Enter ic: %p attr: %p",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota ret = ib_modify_qp(ic->i_cm_id->qp, attr, IB_QP_MIN_RNR_TIMER);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "ib_modify_qp(IB_QP_MIN_RNR_TIMER): err=%d", -ret);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Connection established.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * We get here for both outgoing and incoming connection.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_cm_connect_complete(struct rdsv3_connection *conn,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota struct rdsv3_ib_connection *ic = conn->c_transport_data;
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota ib_get_client_data(ic->i_cm_id->device, &rdsv3_ib_client);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota if (event->param.conn.private_data_len >= sizeof (*dp)) {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* make sure it isn't empty data */
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota "RDS/IB: Connection to %u.%u.%u.%u version %u.%u failed",
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota "RDS/IB: connected to %u.%u.%u.%u version %u.%u%s",
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota ic->i_soft_cq = rdsv3_af_intr_thr_create(rdsv3_ib_tasklet_fn,
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota (void *)ic, SCQ_INTR_BIND_CPU, rds_ibdev->aft_hcagp,
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota (void *)ic, SCQ_INTR_BIND_CPU, rds_ibdev->aft_hcagp,
5e12ddada2833f3aa285210603ce9aaeb8be35ccEiji Ota /* rdsv3_ib_refill_fn is expecting i_max_recv_alloc set */
5e12ddada2833f3aa285210603ce9aaeb8be35ccEiji Ota ic->i_max_recv_alloc = rdsv3_ib_sysctl_max_recv_allocation;
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota ic->i_refill_rq = rdsv3_af_thr_create(rdsv3_ib_refill_fn, (void *)conn,
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota (void) ib_req_notify_cq(ic->i_cq, IB_CQ_SOLICITED);
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota (void) ib_req_notify_cq(ic->i_snd_cq, IB_CQ_NEXT_COMP);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Init rings and fill recv. this needs to wait until protocol
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * negotiation
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * is complete, since ring layout is different from 3.0 to 3.1.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Post receive buffers - as a side effect, this will update
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * the posted credit count.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* Tune RNR behavior */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota err = ib_modify_qp(ic->i_cm_id->qp, &qp_attr, IB_QP_STATE);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* update ib_device with this local ipaddr & conn */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota err = rdsv3_ib_update_ipaddr(rds_ibdev, conn->c_laddr);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * If the peer gave us the last packet it saw, process this as if
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * we had received a regular ACK.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota rdsv3_send_drop_acked(conn, ntohll(dp->dp_ack_seq), NULL);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "Return conn: %p event: %p",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_cm_fill_conn_param(struct rdsv3_connection *conn,
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota struct rdsv3_ib_connection *ic = conn->c_transport_data;
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "Enter conn: %p conn_param: %p private: %p version: %d",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota (void) memset(conn_param, 0, sizeof (struct rdma_conn_param));
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota rds_ibdev = ib_get_client_data(ic->i_cm_id->device, &rdsv3_ib_client);
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota MIN(rds_ibdev->max_responder_resources, max_responder_resources);
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota MIN(rds_ibdev->max_initiator_depth, max_initiator_depth);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota conn_param->retry_count = min(rdsv3_ib_retry_count, 7);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota dp->dp_protocol_major = RDS_PROTOCOL_MAJOR(protocol_version);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota dp->dp_protocol_minor = RDS_PROTOCOL_MINOR(protocol_version);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* Advertise flow control */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "Return conn: %p conn_param: %p private: %p version: %d",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_cq_event_handler(struct ib_event *event, void *data)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF3("rdsv3_ib_cq_event_handler", "event %u data %p",
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Otardsv3_ib_snd_cq_comp_handler(struct ib_cq *cq, void *context)
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota struct rdsv3_ib_connection *ic = conn->c_transport_data;
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota struct rdsv3_ib_connection *ic = (struct rdsv3_ib_connection *)data;
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota * Poll in a loop before and after enabling the next event
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota while (ibt_poll_cq(RDSV3_CQ2CQHDL(ic->i_snd_cq), &wc, 1, &polled) ==
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota "wc_id 0x%llx type %d status %u byte_len %u imm_data %u\n",
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota (unsigned long long)wc.wc_id, wc.wc_type, wc.wc_status,
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota (void) ibt_enable_cq_notify(RDSV3_CQ2CQHDL(ic->i_snd_cq),
3f756f37bfdcab561a4d84fb80f41f1e1a15c135agiri while (ibt_poll_cq(RDSV3_CQ2CQHDL(ic->i_snd_cq), &wc, 1, &polled) ==
3f756f37bfdcab561a4d84fb80f41f1e1a15c135agiri "wc_id 0x%llx type %d status %u byte_len %u imm_data %u\n",
3f756f37bfdcab561a4d84fb80f41f1e1a15c135agiri (unsigned long long)wc.wc_id, wc.wc_type, wc.wc_status,
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Otardsv3_ib_cq_comp_handler(struct ib_cq *cq, void *context)
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota struct rdsv3_ib_connection *ic = conn->c_transport_data;
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota struct rdsv3_connection *conn = (struct rdsv3_connection *)data;
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota struct rdsv3_ib_connection *ic = (struct rdsv3_ib_connection *)data;
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota * Poll in a loop before and after enabling the next event
5e12ddada2833f3aa285210603ce9aaeb8be35ccEiji Ota while (ibt_poll_cq(RDSV3_CQ2CQHDL(ic->i_cq), &wc[0],
5e12ddada2833f3aa285210603ce9aaeb8be35ccEiji Ota for (i = 0; i < polled; i++) {
5e12ddada2833f3aa285210603ce9aaeb8be35ccEiji Ota "wc_id 0x%llx type %d status %u byte_len %u \
5e12ddada2833f3aa285210603ce9aaeb8be35ccEiji Ota imm_data %u\n",
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota (void) ibt_enable_cq_notify(RDSV3_CQ2CQHDL(ic->i_cq),
5e12ddada2833f3aa285210603ce9aaeb8be35ccEiji Ota while (ibt_poll_cq(RDSV3_CQ2CQHDL(ic->i_cq), &wc[0],
5e12ddada2833f3aa285210603ce9aaeb8be35ccEiji Ota for (i = 0; i < polled; i++) {
5e12ddada2833f3aa285210603ce9aaeb8be35ccEiji Ota "wc_id 0x%llx type %d status %u byte_len %u \
5e12ddada2833f3aa285210603ce9aaeb8be35ccEiji Ota imm_data %u\n",
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota if (ack_state.ack_recv_valid && ack_state.ack_recv > ic->i_ack_recv) {
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota rdsv3_send_drop_acked(conn, ack_state.ack_recv, NULL);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_qp_event_handler(struct ib_event *event, void *data)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota struct rdsv3_ib_connection *ic = conn->c_transport_data;
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF2("rdsv3_ib_qp_event_handler", "conn %p ic %p event %u",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota (void) rdma_notify(ic->i_cm_id, IB_EVENT_COMM_EST);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "RDS/IB: Fatal QP Event %u - "
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "connection %u.%u.%u.%u ->%u.%u.%u.%u "
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "...reconnecting",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "RDS/IB: Fatal QP Event %u - connection"
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF2("rdsv3_ib_qp_event_handler", "Return conn: %p event: %p",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * This needs to be very careful to not leave IS_ERR pointers around for
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * cleanup to trip over.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota struct rdsv3_ib_connection *ic = conn->c_transport_data;
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF2("rdsv3_ib_setup_qp", "Enter conn: %p", conn);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * rdsv3_ib_add_one creates a rdsv3_ib_device object per IB device,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * and allocates a protection domain, memory range and FMR pool
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * for each. If that fails for any reason, it will not register
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * the rds_ibdev at all.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota rds_ibdev = ib_get_client_data(dev, &rdsv3_ib_client);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "RDS/IB: No client_data for device %s", dev->name);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota rdsv3_ib_ring_resize(&ic->i_send_ring, rds_ibdev->max_wrs - 1);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota rdsv3_ib_ring_resize(&ic->i_recv_ring, rds_ibdev->max_wrs - 1);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* Protection domain and memory range */
cadbfdc3bdb156e92d7a88978bc98ea87f6e037fEiji Ota * IB_CQ_VECTOR_LEAST_ATTACHED and/or the corresponding feature is
cadbfdc3bdb156e92d7a88978bc98ea87f6e037fEiji Ota * not implmeneted in Hermon yet, but we can pass it to ib_create_cq()
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota ic->i_cq = ib_create_cq(dev, rdsv3_ib_cq_comp_handler,
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor rdsv3_af_grp_get_sched(ic->rds_ibdev->aft_hcagp));
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota ic->i_snd_cq = ib_create_cq(dev, rdsv3_ib_snd_cq_comp_handler,
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota rdsv3_ib_cq_event_handler, conn, ic->i_send_ring.w_nr + 1,
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor rdsv3_af_grp_get_sched(ic->rds_ibdev->aft_hcagp));
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* XXX negotiate max send/recv with remote? */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* + 1 to allow for the single ack message */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * XXX this can fail if max_*_wr is too large? Are we supposed
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * to back off until we get a value that the hardware can support?
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota ret = rdma_create_qp(ic->i_cm_id, ic->i_pd, &attr);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota if (ret != 0) {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota (void) memset(ic->i_sends, 0, ic->i_send_ring.w_nr *
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota sizeof (struct rdsv3_ib_send_work));
3f756f37bfdcab561a4d84fb80f41f1e1a15c135agiri kmem_alloc(ic->i_send_ring.w_nr * (sizeof (ibt_send_wr_t) +
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_IB_MAX_SGE * sizeof (ibt_wr_ds_t)), KM_NOSLEEP);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota (void) memset(ic->i_recvs, 0, ic->i_recv_ring.w_nr *
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota sizeof (struct rdsv3_ib_recv_work));
d2b539e744e90927cf7a57df3475145c279d68f9agiri kmem_alloc(ic->i_recv_ring.w_nr * sizeof (ibt_recv_wr_t),
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota RDSV3_DPRINTF2("rdsv3_ib_setup_qp", "conn %p pd %p mr %p cq %p",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_protocol_compatible(struct rdma_cm_event *event)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF2("rdsv3_ib_protocol_compatible", "Enter event: %p",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * rdma_cm private data is odd - when there is any private data in the
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * request, we will be given a pretty large buffer without telling us
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * original size. The only way to tell the difference is by looking at
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * the contents, which are initialized to zero.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * If the protocol version fields aren't set,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * this is a connection attempt
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * from an older version. This could could be 3.0 or 2.0 -
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * we can't tell.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * We really should have changed this for OFED 1.3 :-(
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* Be paranoid. RDS always has privdata */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "RDS incoming connection has no private data, rejecting");
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (0);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* Even if len is crap *now* I still want to check it. -ASG */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota if (event->param.conn.private_data_len < sizeof (*dp) ||
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "RDS: Connection from %u.%u.%u.%u using "
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "incompatible protocol version %u.%u\n",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF2("rdsv3_ib_protocol_compatible", "Return event: %p",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_cm_handle_connect(struct rdma_cm_id *cm_id,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota uint64_be_t lguid = cm_id->route.path_rec->sgid.global.interface_id;
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota uint64_be_t fguid = cm_id->route.path_rec->dgid.global.interface_id;
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* Check whether the remote protocol version matches ours. */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "version mismatch");
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "saddr %u.%u.%u.%u daddr %u.%u.%u.%u RDSv%d.%d lguid 0x%llx fguid "
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "0x%llx", NIPQUAD(dp->dp_saddr), NIPQUAD(dp->dp_daddr),
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDS_PROTOCOL_MAJOR(version), RDS_PROTOCOL_MINOR(version),
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota conn = rdsv3_conn_create(dp->dp_daddr, dp->dp_saddr,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * The connection request may occur while the
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * previous connection exist, e.g. in case of failover.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * But as connections may be initiated simultaneously
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * by both hosts, we have a random backoff mechanism -
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * see the comment above rdsv3_queue_reconnect()
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "incoming connect when connected: %p",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota } else if (rdsv3_conn_state(conn) == RDSV3_CONN_CONNECTING) {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* Wait and see - our connect may still be succeeding */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "peer-to-peer connection request: %p, "
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "lguid: 0x%llx fguid: 0x%llx",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota rdsv3_ib_set_flow_control(conn, ntohl(dp->dp_credit));
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * If the peer gave us the last packet it saw, process this as if
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * we had received a regular ACK.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota rdsv3_send_drop_acked(conn, ntohll(dp->dp_ack_seq), NULL);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * We got halfway through setting up the ib_connection, if we
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * fail now, we have to take the long route out of this mess.
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota rdsv3_ib_cm_fill_conn_param(conn, &conn_param, &dp_rep, version,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* rdma_accept() calls rdma_reject() internally if it fails */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (0);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_cm_initiate_connect(struct rdma_cm_id *cm_id)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota struct rdsv3_ib_connection *ic = conn->c_transport_data;
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF2("rdsv3_ib_cm_initiate_connect", "Enter: cm_id: %p",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * If the peer doesn't do protocol negotiation, we must
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * default to RDSv3.0
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota rdsv3_ib_sysctl_flow_control; /* advertise flow control */
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota rdsv3_ib_cm_fill_conn_param(conn, &conn_param, &dp,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Beware - returning non-zero tells the rdma_cm to destroy
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * the cm_id. We should certainly not do it as long as we still
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * "own" the cm_id.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_conn_connect(struct rdsv3_connection *conn)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota struct rdsv3_ib_connection *ic = conn->c_transport_data;
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF2("rdsv3_ib_conn_connect", "Enter: conn: %p", conn);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * XXX I wonder what affect the port space has
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* delegate cm event handler to rdma_transport */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota ic->i_cm_id = rdma_create_id(rdsv3_rdma_cm_event_handler, conn,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "created cm id %p for conn %p", ic->i_cm_id, conn);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* The ipaddr should be in the network order */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota if (ret == 0) {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF2(LABEL, "Path not found (0x%x 0x%x)",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota ret = rdma_resolve_addr(ic->i_cm_id, (struct sockaddr *)&src,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "addr resolve failed for cm id %p: %d", ic->i_cm_id, ret);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF2("rdsv3_ib_conn_connect", "Return: conn: %p", conn);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * This is so careful about only cleaning up resources that were built up
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * so that it can be called at any point during startup. In fact it
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * can be called multiple times for a given connection.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_conn_shutdown(struct rdsv3_connection *conn)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota struct rdsv3_ib_connection *ic = conn->c_transport_data;
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota ic->i_pd, ic->i_cq, ic->i_cm_id ? ic->i_cm_id->qp : NULL);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Actually this may happen quite frequently, when
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * an outgoing connect raced with an incoming connect.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "failed to disconnect, cm: %p err %d",
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota * Don't wait for the send ring to be empty -- there
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota * may be completed non-signaled entries sitting on
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota * there. We unmap these below.
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota * Note that Linux original code calls
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota * rdma_destroy_qp() after rdsv3_ib_recv_clear_ring(ic).
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Move connection back to the nodev list.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* Clear pending transmit */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* Clear the ACK state */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* Clear flow control state */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota rdsv3_ib_ring_init(&ic->i_send_ring, rdsv3_ib_sysctl_max_send_wr);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota rdsv3_ib_ring_init(&ic->i_recv_ring, rdsv3_ib_sysctl_max_recv_wr);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota ic->i_send_ring.w_nr * sizeof (struct rdsv3_ib_send_work));
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota ic->i_recv_ring.w_nr * sizeof (struct rdsv3_ib_recv_work));
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF2("rdsv3_ib_conn_shutdown", "Return conn: %p", conn);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota/* ARGSUSED */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_conn_alloc(struct rdsv3_connection *conn, int gfp)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF2("rdsv3_ib_conn_alloc", "conn: %p", conn);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* XXX too lazy? */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota ic = kmem_zalloc(sizeof (struct rdsv3_ib_connection), gfp);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota mutex_init(&ic->i_recv_mutex, NULL, MUTEX_DRIVER, NULL);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota mutex_init(&ic->i_ack_lock, NULL, MUTEX_DRIVER, NULL);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * rdsv3_ib_conn_shutdown() waits for these to be emptied so they
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * must be initialized before it can be called.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota rdsv3_ib_ring_init(&ic->i_send_ring, rdsv3_ib_sysctl_max_send_wr);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota rdsv3_ib_ring_init(&ic->i_recv_ring, rdsv3_ib_sysctl_max_recv_wr);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF2("rdsv3_ib_conn_alloc", "conn %p conn ic %p",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (0);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Free a connection. Connection must be shut down and not set for reconnect.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF2("rdsv3_ib_conn_free", "ic %p\n", ic);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Conn is either on a dev's list or on the nodev list.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * A race with shutdown() or connect() would cause problems
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * (since rds_ibdev would change) but that should never happen.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * An error occurred on the connection