16e76cdd6e3cfaac7d91c3b0644ee1bc6cf52347agiri * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
16e76cdd6e3cfaac7d91c3b0644ee1bc6cf52347agiri * This file contains code imported from the OFED rds source file
16e76cdd6e3cfaac7d91c3b0644ee1bc6cf52347agiri * rdma_transport.c * Oracle elects to have and use the contents of
16e76cdd6e3cfaac7d91c3b0644ee1bc6cf52347agiri * rdma_transport.c under and governed by the OpenIB.org BSD license
16e76cdd6e3cfaac7d91c3b0644ee1bc6cf52347agiri * (see below for full license text). However, the following notice
16e76cdd6e3cfaac7d91c3b0644ee1bc6cf52347agiri * accompanied the original version of this file:
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Copyright (c) 2009 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 Otardsv3_rdma_cm_event_handler(struct rdma_cm_id *cm_id,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* this can be null in the listening path */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "conn %p id %p handling event %u", conn, cm_id, event->event);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Prevent shutdown from tearing down the connection
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * while we're executing.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * If the connection is being shut down, bail out
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * right away. We return 0 so cm_id doesn't get
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * destroyed prematurely
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota if (rdsv3_conn_state(conn) == RDSV3_CONN_DISCONNECTING) {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Reject incoming connections while we're tearing
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * down an existing one.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "conn %p id %p incoming event %u when "
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* XXX do we need to clean up if this fails? */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* XXX worry about racing with listen acceptance */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "RDS/RDMA: DISCONNECT event - dropping connection "
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "RDS/RDMA: DISCONNECT event - dropping connection "
cadbfdc3bdb156e92d7a88978bc98ea87f6e037fEiji Ota "%u.%u.%u.%u->%u.%u.%u.%u", NIPQUAD(conn->c_laddr),
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* things like device disconnect? */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "id %p event %u handling ret %d", cm_id, event->event, ret);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota cm_id = rdma_create_id(rdsv3_rdma_cm_event_handler, NULL, RDMA_PS_TCP);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "RDS/RDMA: failed to setup listener, "
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * XXX I bet this binds the cm_id to a device. If we want to support
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * fail-over we'll have to take this into consideration.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota ret = rdma_bind_addr(cm_id, (struct sockaddr *)&sin);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "RDS/RDMA: failed to setup listener, "
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "RDS/RDMA: failed to setup listener, "
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "Return: rdsv3_rdma_listen_id: %p", rdsv3_rdma_listen_id);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF2("rdsv3_rdma_listen_stop", "cm %p", rdsv3_rdma_listen_id);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF2("rdsv3_rdma_listen_stop", "Return");
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * This function can be called via two routes.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * 1. During attach on a worker thread.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * 2. From rdsv3_create() for 1st socket.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "rdsv3_rdma_listen_id is already initialized: %p",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota/*ARGSUSED*/
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* stop listening first to ensure no new connections are attempted */