ib_cm.c revision d2b539e744e90927cf7a57df3475145c279d68f9
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/*
* Copyright (c) 2006 Oracle. All rights reserved.
*
* This software is available to you under a choice of one of two
* licenses. You may choose to be licensed under the terms of the GNU
* General Public License (GPL) Version 2, available from the file
* COPYING in the main directory of this source tree, or the
* OpenIB.org BSD license below:
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* provided with the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
extern ddi_taskq_t *rdsv3_taskq;
/*
* Set the selected protocol version
*/
static void
{
}
/*
* Set up flow control
*/
static void
{
RDSV3_DPRINTF2("rdsv3_ib_set_flow_control",
if (rdsv3_ib_sysctl_flow_control && credits != 0) {
/* We're doing flow control */
} else {
}
RDSV3_DPRINTF2("rdsv3_ib_set_flow_control",
"Return: conn: %p credits: %d",
}
/*
* Tune RNR behavior. Without flow control, we use a rather
* low timeout, but not the absolute minimum - this should
* be tunable.
*
* We already set the RNR retry count to 7 (which is the
* smallest infinite number :-) above.
* If flow control is off, we want to change this back to 0
* so that we learn quickly when our credit accounting is
* buggy.
*
* Caller passes in a qp_attr pointer - don't waste stack spacv
* by allocation this twice.
*/
static void
{
int ret;
if (ret)
RDSV3_DPRINTF2("rdsv3_ib_tune_rnr",
"ib_modify_qp(IB_QP_MIN_RNR_TIMER): err=%d", -ret);
}
/*
* Connection established.
* We get here for both outgoing and incoming connection.
*/
void
struct rdma_cm_event *event)
{
struct rdsv3_ib_device *rds_ibdev;
struct ib_qp_attr qp_attr;
int err;
RDSV3_DPRINTF2("rdsv3_ib_cm_connect_complete",
/* make sure it isn't empty data */
if (dp->dp_protocol_major) {
dp->dp_protocol_minor));
}
}
RDSV3_DPRINTF2("rdsv3_ib_cm_connect_complete",
/*
* Init rings and fill recv. this needs to wait until protocol
* negotiation
* is complete, since ring layout is different from 3.0 to 3.1.
*/
/*
* Post receive buffers - as a side effect, this will update
* the posted credit count.
*/
/* Tune RNR behavior */
if (err)
RDSV3_DPRINTF2("rdsv3_ib_cm_connect_complete",
"ib_modify_qp(IB_QP_STATE, RTS): err=%d", err);
/* update ib_device with this local ipaddr & conn */
if (err)
RDSV3_DPRINTF2("rdsv3_ib_cm_connect_complete",
"rdsv3_ib_update_ipaddr failed (%d)", err);
/*
* If the peer gave us the last packet it saw, process this as if
* we had received a regular ACK.
*/
RDSV3_DPRINTF2("rdsv3_ib_cm_connect_complete",
"Return conn: %p event: %p",
}
static void
struct rdma_conn_param *conn_param,
struct rdsv3_ib_connect_private *dp,
{
RDSV3_DPRINTF2("rdsv3_ib_cm_fill_conn_param",
"Enter conn: %p conn_param: %p private: %p version: %d",
/* XXX tune these? */
if (dp) {
/* Advertise flow control */
unsigned int credits;
}
}
RDSV3_DPRINTF2("rdsv3_ib_cm_fill_conn_param",
"Return conn: %p conn_param: %p private: %p version: %d",
}
static void
{
}
static void
{
case IB_EVENT_COMM_EST:
break;
default:
if (conn) {
RDSV3_DPRINTF2("rdsv3_ib_qp_event_handler",
"connection %u.%u.%u.%u ->%u.%u.%u.%u "
"...reconnecting",
} else {
RDSV3_DPRINTF2("rdsv3_ib_qp_event_handler",
}
break;
}
}
struct rdsv3_ib_connection *ic);
struct rdsv3_ib_connection *ic);
/*
* This needs to be very careful to not leave IS_ERR pointers around for
* cleanup to trip over.
*/
static int
{
struct ib_qp_init_attr attr;
struct rdsv3_ib_device *rds_ibdev;
int ret, i;
/*
* rdsv3_ib_add_one creates a rdsv3_ib_device object per IB device,
* and allocates a protection domain, memory range and FMR pool
* for each. If that fails for any reason, it will not register
* the rds_ibdev at all.
*/
RDSV3_DPRINTF2("rdsv3_ib_setup_qp",
return (-EOPNOTSUPP);
}
/* Protection domain and memory range */
/*
* not implmeneted in Hermon yet, but we can pass it to ib_create_cq()
* anyway.
*/
RDSV3_DPRINTF2("rdsv3_ib_setup_qp",
"ib_create_cq send failed: %d", ret);
goto out;
}
/*
* not implmeneted in Hermon yet, but we can pass it to ib_create_cq()
* anyway.
*/
RDSV3_DPRINTF2("rdsv3_ib_setup_qp",
"ib_create_cq recv failed: %d", ret);
goto out;
}
if (ret) {
RDSV3_DPRINTF2("rdsv3_ib_setup_qp",
"ib_req_notify_cq send failed: %d", ret);
goto out;
}
if (ret) {
RDSV3_DPRINTF2("rdsv3_ib_setup_qp",
"ib_req_notify_cq recv failed: %d", ret);
goto out;
}
/* + 1 to allow for the single ack message */
/*
* XXX this can fail if max_*_wr is too large? Are we supposed
* to back off until we get a value that the hardware can support?
*/
if (ret) {
RDSV3_DPRINTF2("rdsv3_ib_setup_qp",
"rdma_create_qp failed: %d", ret);
goto out;
}
if (ret != 0) {
RDSV3_DPRINTF2("rdsv3_ib_setup_qp",
"rdsv3_ib_alloc_hdrs failed: %d", ret);
goto out;
}
sizeof (struct rdsv3_ib_send_work), KM_NOSLEEP);
RDSV3_DPRINTF2("rdsv3_ib_setup_qp",
"send allocation failed: %d", ret);
goto out;
}
sizeof (struct rdsv3_ib_send_work));
ic->i_send_wrs =
RDSV3_DPRINTF2("rdsv3_ib_setup_qp",
"Send WR allocation failed: %d", ret);
goto out;
}
(RDSV3_IB_SEND_WRS * sizeof (ibt_send_wr_t)));
for (i = 0; i < RDSV3_IB_SEND_WRS; i++) {
}
sizeof (struct rdsv3_ib_recv_work), KM_NOSLEEP);
RDSV3_DPRINTF2("rdsv3_ib_setup_qp",
"recv allocation failed: %d", ret);
goto out;
}
sizeof (struct rdsv3_ib_recv_work));
ic->i_recv_wrs =
RDSV3_DPRINTF2("rdsv3_ib_setup_qp",
"Recv WR allocation failed: %d", ret);
goto out;
}
out:
return (ret);
}
static uint32_t
{
const struct rdsv3_ib_connect_private *dp =
event);
/*
* rdma_cm private data is odd - when there is any private data in the
* request, we will be given a pretty large buffer without telling us
* the
* original size. The only way to tell the difference is by looking at
* the contents, which are initialized to zero.
* If the protocol version fields aren't set,
* this is a connection attempt
* from an older version. This could could be 3.0 or 2.0 -
* we can't tell.
* We really should have changed this for OFED 1.3 :-(
*/
/* Be paranoid. RDS always has privdata */
RDSV3_DPRINTF2("rdsv3_ib_protocol_compatible",
"RDS incoming connection has no private data, rejecting");
return (0);
}
/* Even if len is crap *now* I still want to check it. -ASG */
dp->dp_protocol_major == 0)
return (RDS_PROTOCOL_3_0);
while ((common >>= 1) != 0)
version++;
} else {
RDSV3_DPRINTF2("rdsv3_ib_protocol_compatible",
"RDS: Connection from %u.%u.%u.%u using "
"incompatible protocol version %u.%u\n",
}
event);
return (version);
}
int
struct rdma_cm_event *event)
{
const struct rdsv3_ib_connect_private *dp =
struct rdsv3_ib_connect_private dp_rep;
struct rdma_conn_param conn_param;
RDSV3_DPRINTF2("rdsv3_ib_cm_handle_connect",
/* Check whether the remote protocol version matches ours. */
if (!version) {
RDSV3_DPRINTF2("rdsv3_ib_cm_handle_connect",
"version mismatch");
goto out;
}
RDSV3_DPRINTF2("rdsv3_ib_cm_handle_connect",
"saddr %u.%u.%u.%u daddr %u.%u.%u.%u RDSv%d.%d lguid 0x%llx fguid "
RDSV3_DPRINTF2("rdsv3_ib_cm_handle_connect",
goto out;
}
/*
* The connection request may occur while the
* previous connection exist, e.g. in case of failover.
* But as connections may be initiated simultaneously
* by both hosts, we have a random backoff mechanism -
* see the comment above rdsv3_queue_reconnect()
*/
RDSV3_DPRINTF2("rdsv3_ib_cm_handle_connect",
"incoming connect when connected: %p",
conn);
goto out;
/* Wait and see - our connect may still be succeeding */
RDSV3_DPRINTF2("rdsv3_ib_cm_handle_connect",
"peer-to-peer connection request: %p, "
"lguid: 0x%llx fguid: 0x%llx",
}
goto out;
}
/*
* If the peer gave us the last packet it saw, process this as if
* we had received a regular ACK.
*/
if (dp->dp_ack_seq)
RDSV3_PANIC();
/*
* We got halfway through setting up the ib_connection, if we
* fail now, we have to take the long route out of this mess.
*/
destroy = 0;
if (err) {
RDSV3_DPRINTF2("rdsv3_ib_cm_handle_connect",
"rdsv3_ib_setup_qp failed (%d)", err);
goto out;
}
/* rdma_accept() calls rdma_reject() internally if it fails */
if (err) {
RDSV3_DPRINTF2("rdsv3_ib_cm_handle_connect",
"rdma_accept failed (%d)", err);
goto out;
}
RDSV3_DPRINTF2("rdsv3_ib_cm_handle_connect",
return (0);
out:
return (destroy);
}
int
{
struct rdma_conn_param conn_param;
struct rdsv3_ib_connect_private dp;
int ret;
cm_id);
/*
* If the peer doesn't do protocol negotiation, we must
* default to RDSv3.0
*/
rdsv3_ib_sysctl_flow_control; /* advertise flow control */
if (ret) {
RDSV3_DPRINTF2("rdsv3_ib_cm_initiate_connect",
"rdsv3_ib_setup_qp failed (%d)", ret);
goto out;
}
if (ret) {
RDSV3_DPRINTF2("rdsv3_ib_cm_initiate_connect",
"rdma_connect failed (%d)", ret);
}
RDSV3_DPRINTF2("rdsv3_ib_cm_initiate_connect",
"Return: cm_id: %p", cm_id);
out:
/*
* Beware - returning non-zero tells the rdma_cm to destroy
* the cm_id. We should certainly not do it as long as we still
* "own" the cm_id.
*/
if (ret) {
ret = 0;
}
return (ret);
}
int
{
int ret;
/*
* XXX I wonder what affect the port space has
*/
/* delegate cm event handler to rdma_transport */
RDSV3_DPRINTF2("rdsv3_ib_conn_connect",
"rdma_create_id() failed: %d", ret);
goto out;
}
RDSV3_DPRINTF3("rdsv3_ib_conn_connect",
/* The ipaddr should be in the network order */
if (ret == 0) {
}
if (ret) {
RDSV3_DPRINTF2("rdsv3_ib_conn_connect",
}
out:
return (ret);
}
/*
* This is so careful about only cleaning up resources that were built up
* so that it can be called at any point during startup. In fact it
* can be called multiple times for a given connection.
*/
void
{
int err = 0;
RDSV3_DPRINTF2("rdsv3_ib_conn_shutdown",
RDSV3_DPRINTF2("rdsv3_ib_conn_shutdown",
if (err) {
/*
* Actually this may happen quite frequently, when
* an outgoing connect raced with an incoming connect.
*/
RDSV3_DPRINTF2("rdsv3_ib_conn_shutdown",
"failed to disconnect, cm: %p err %d",
}
(void) ibt_flush_qp(
/* wait until all WRs are flushed */
}
/*
* Move connection back to the nodev list.
*/
if (ic->i_on_dev_list)
}
/* Clear pending transmit */
}
/* Clear the ACK state */
ic->i_ack_next = 0;
ic->i_ack_recv = 0;
/* Clear flow control state */
}
}
if (ic->i_send_wrs) {
(sizeof (ibt_send_wr_t) +
RDSV3_IB_MAX_SGE * sizeof (ibt_wr_ds_t)));
}
}
}
/*
* the connection can be allocated from either rdsv3_conn_create_outgoing()
* or rdsv3_conn_create(), so ddi_taskq_create() can be called with the
* same string. This can print the kstat warning on the console. To prevent
* it, this counter value is used.
* Note that requests from rdsv3_conn_create_outgoing() refers to the cached
* value with the mutex lock before it allocates the connection, so that
* the warning cannot be produced in the case. (only between
* rdsv3_conn_create() and rdsv3_conn_create_outgoing().
*/
static int conn_cnt;
/* ARGSUSED */
int
{
struct rdsv3_ib_connection *ic;
char tq_name[TASKQ_NAMELEN];
/* XXX too lazy? */
return (-ENOMEM);
ic->i_recv_tasklet =
/*
* rdsv3_ib_conn_shutdown() waits for these to be emptied so they
* must be initialized before it can be called.
*/
return (0);
}
/*
* Free a connection. Connection must be shut down and not set for reconnect.
*/
void
rdsv3_ib_conn_free(void *arg)
{
#ifndef __lock_lint
/*
* Conn is either on a dev's list or on the nodev list.
* A race with shutdown() or connect() would cause problems
* (since rds_ibdev would change) but that should never happen.
*/
#endif
}
/*
* An error occurred on the connection
*/
void
{
}