/*
*/
/*
* This file contains code imported from the OFED rds source file ib_cm.c
* Oracle elects to have and use the contents of ib_cm.c under and governed
* by the OpenIB.org BSD license (see below for full license text). However,
* the following notice accompanied the original version of this file:
*/
/*
* 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 int rdsv3_enable_snd_cq;
/*
* 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)
{
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",
return;
} else {
RDSV3_DPRINTF2("rdsv3_ib_cm_connect_complete",
}
if (rdsv3_enable_snd_cq) {
}
/* rdsv3_ib_refill_fn is expecting i_max_recv_alloc set */
if (rdsv3_enable_snd_cq) {
}
/*
* 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",
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
{
RDSV3_DPRINTF4("rdsv3_ib_snd_cq_comp_handler",
}
void
{
RDSV3_DPRINTF4("rdsv3_ib_snd_tasklet_fn",
/*
* Poll in a loop before and after enabling the next event
*/
IBT_SUCCESS) {
RDSV3_DPRINTF4("rdsv3_ib_snd_tasklet_fn",
"wc_id 0x%llx type %d status %u byte_len %u imm_data %u\n",
}
IBT_SUCCESS) {
RDSV3_DPRINTF4("rdsv3_ib_snd_tasklet_fn",
"wc_id 0x%llx type %d status %u byte_len %u imm_data %u\n",
}
}
static void
{
RDSV3_DPRINTF4("rdsv3_ib_cq_comp_handler",
}
void
{
(void) rdsv3_ib_recv_refill(conn, 0);
}
void
{
int i;
RDSV3_DPRINTF4("rdsv3_ib_tasklet_fn",
/*
* Poll in a loop before and after enabling the next event
*/
for (i = 0; i < polled; i++) {
RDSV3_DPRINTF4("rdsv3_ib_tasklet_fn",
"wc_id 0x%llx type %d status %u byte_len %u \
imm_data %u\n",
} else {
&ack_state);
}
}
}
for (i = 0; i < polled; i++) {
RDSV3_DPRINTF4("rdsv3_ib_tasklet_fn",
"wc_id 0x%llx type %d status %u byte_len %u \
imm_data %u\n",
} else {
&ack_state);
}
}
}
if (ack_state.ack_next_valid) {
}
}
if (rdsv3_conn_up(conn)) {
}
}
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
{
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.
*/
if (!rds_ibdev) {
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 failed: %d", ret);
goto out;
}
if (rdsv3_enable_snd_cq) {
RDSV3_DPRINTF2("rdsv3_ib_setup_qp",
"ib_create_cq send cq failed: %d", ret);
goto out;
}
}
/* + 1 to allow for the single ack message */
if (rdsv3_enable_snd_cq) {
} else {
}
/*
* 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;
}
}
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
{
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)
{
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
{
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(
/*
* Don't wait for the send ring to be empty -- there
* may be completed non-signaled entries sitting on
* there. We unmap these below.
*/
/*
* Note that Linux original code calls
* rdma_destroy_qp() after rdsv3_ib_recv_clear_ring(ic).
*/
}
if (rdsv3_enable_snd_cq) {
if (ic->i_snd_soft_cq) {
}
}
}
if (ic->i_refill_rq) {
}
/*
* 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)));
}
}
if (ic->i_recv_wrs) {
(sizeof (ibt_recv_wr_t)));
}
}
/* ARGSUSED */
int
{
/* XXX too lazy? */
if (!ic)
return (-ENOMEM);
/*
* 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
{
#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
{
}