2008-12-10 07:10:17 +08:00
|
|
|
/*
|
|
|
|
* Copyright(c) 2007 - 2008 Intel Corporation. All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Maintained at www.Open-FCoE.org
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* RPORT GENERAL INFO
|
|
|
|
*
|
|
|
|
* This file contains all processing regarding fc_rports. It contains the
|
|
|
|
* rport state machine and does all rport interaction with the transport class.
|
|
|
|
* There should be no other places in libfc that interact directly with the
|
|
|
|
* transport class in regards to adding and deleting rports.
|
|
|
|
*
|
|
|
|
* fc_rport's represent N_Port's within the fabric.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* RPORT LOCKING
|
|
|
|
*
|
|
|
|
* The rport should never hold the rport mutex and then attempt to acquire
|
|
|
|
* either the lport or disc mutexes. The rport's mutex is considered lesser
|
|
|
|
* than both the lport's mutex and the disc mutex. Refer to fc_lport.c for
|
|
|
|
* more comments on the heirarchy.
|
|
|
|
*
|
|
|
|
* The locking strategy is similar to the lport's strategy. The lock protects
|
|
|
|
* the rport's states and is held and released by the entry points to the rport
|
|
|
|
* block. All _enter_* functions correspond to rport states and expect the rport
|
|
|
|
* mutex to be locked before calling them. This means that rports only handle
|
|
|
|
* one request or response at a time, since they're not critical for the I/O
|
|
|
|
* path this potential over-use of the mutex is acceptable.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/rcupdate.h>
|
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/workqueue.h>
|
|
|
|
#include <asm/unaligned.h>
|
|
|
|
|
|
|
|
#include <scsi/libfc.h>
|
|
|
|
#include <scsi/fc_encode.h>
|
|
|
|
|
|
|
|
struct workqueue_struct *rport_event_queue;
|
|
|
|
|
2009-08-26 05:00:50 +08:00
|
|
|
static void fc_rport_enter_plogi(struct fc_rport_priv *);
|
|
|
|
static void fc_rport_enter_prli(struct fc_rport_priv *);
|
|
|
|
static void fc_rport_enter_rtv(struct fc_rport_priv *);
|
|
|
|
static void fc_rport_enter_ready(struct fc_rport_priv *);
|
|
|
|
static void fc_rport_enter_logo(struct fc_rport_priv *);
|
2008-12-10 07:10:17 +08:00
|
|
|
|
2009-08-26 05:00:50 +08:00
|
|
|
static void fc_rport_recv_plogi_req(struct fc_rport_priv *,
|
2008-12-10 07:10:17 +08:00
|
|
|
struct fc_seq *, struct fc_frame *);
|
2009-08-26 05:00:50 +08:00
|
|
|
static void fc_rport_recv_prli_req(struct fc_rport_priv *,
|
2008-12-10 07:10:17 +08:00
|
|
|
struct fc_seq *, struct fc_frame *);
|
2009-08-26 05:00:50 +08:00
|
|
|
static void fc_rport_recv_prlo_req(struct fc_rport_priv *,
|
2008-12-10 07:10:17 +08:00
|
|
|
struct fc_seq *, struct fc_frame *);
|
2009-08-26 05:00:50 +08:00
|
|
|
static void fc_rport_recv_logo_req(struct fc_rport_priv *,
|
2008-12-10 07:10:17 +08:00
|
|
|
struct fc_seq *, struct fc_frame *);
|
|
|
|
static void fc_rport_timeout(struct work_struct *);
|
2009-08-26 05:00:50 +08:00
|
|
|
static void fc_rport_error(struct fc_rport_priv *, struct fc_frame *);
|
|
|
|
static void fc_rport_error_retry(struct fc_rport_priv *, struct fc_frame *);
|
2008-12-10 07:10:17 +08:00
|
|
|
static void fc_rport_work(struct work_struct *);
|
|
|
|
|
|
|
|
static const char *fc_rport_state_names[] = {
|
|
|
|
[RPORT_ST_INIT] = "Init",
|
|
|
|
[RPORT_ST_PLOGI] = "PLOGI",
|
|
|
|
[RPORT_ST_PRLI] = "PRLI",
|
|
|
|
[RPORT_ST_RTV] = "RTV",
|
|
|
|
[RPORT_ST_READY] = "Ready",
|
|
|
|
[RPORT_ST_LOGO] = "LOGO",
|
2009-07-30 08:04:43 +08:00
|
|
|
[RPORT_ST_DELETE] = "Delete",
|
2008-12-10 07:10:17 +08:00
|
|
|
};
|
|
|
|
|
2009-08-26 05:02:06 +08:00
|
|
|
/**
|
|
|
|
* fc_rport_lookup() - lookup a remote port by port_id
|
|
|
|
* @lport: Fibre Channel host port instance
|
|
|
|
* @port_id: remote port port_id to match
|
|
|
|
*/
|
|
|
|
static struct fc_rport_priv *fc_rport_lookup(const struct fc_lport *lport,
|
|
|
|
u32 port_id)
|
|
|
|
{
|
|
|
|
struct fc_rport_priv *rdata;
|
|
|
|
|
|
|
|
list_for_each_entry(rdata, &lport->disc.rports, peers)
|
|
|
|
if (rdata->ids.port_id == port_id &&
|
|
|
|
rdata->rp_state != RPORT_ST_DELETE)
|
|
|
|
return rdata;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-08-26 05:01:18 +08:00
|
|
|
/**
|
2009-08-26 05:02:59 +08:00
|
|
|
* fc_rport_create() - Create a new remote port
|
|
|
|
* @lport: The local port that the new remote port is for
|
|
|
|
* @port_id: The port ID for the new remote port
|
2009-08-26 05:01:18 +08:00
|
|
|
*
|
2009-08-26 05:01:50 +08:00
|
|
|
* Locking note: must be called with the disc_mutex held.
|
2009-08-26 05:01:18 +08:00
|
|
|
*/
|
|
|
|
static struct fc_rport_priv *fc_rport_create(struct fc_lport *lport,
|
2009-08-26 05:02:59 +08:00
|
|
|
u32 port_id)
|
2008-12-10 07:10:17 +08:00
|
|
|
{
|
2009-08-26 05:00:34 +08:00
|
|
|
struct fc_rport_priv *rdata;
|
2008-12-10 07:10:17 +08:00
|
|
|
|
2009-08-26 05:02:59 +08:00
|
|
|
rdata = lport->tt.rport_lookup(lport, port_id);
|
2009-08-26 05:01:55 +08:00
|
|
|
if (rdata)
|
|
|
|
return rdata;
|
|
|
|
|
2009-08-26 05:01:18 +08:00
|
|
|
rdata = kzalloc(sizeof(*rdata), GFP_KERNEL);
|
|
|
|
if (!rdata)
|
2008-12-10 07:10:17 +08:00
|
|
|
return NULL;
|
|
|
|
|
2009-08-26 05:02:59 +08:00
|
|
|
rdata->ids.node_name = -1;
|
|
|
|
rdata->ids.port_name = -1;
|
|
|
|
rdata->ids.port_id = port_id;
|
|
|
|
rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
|
|
|
|
|
2009-08-26 05:01:01 +08:00
|
|
|
kref_init(&rdata->kref);
|
2008-12-10 07:10:17 +08:00
|
|
|
mutex_init(&rdata->rp_mutex);
|
2009-08-26 05:00:39 +08:00
|
|
|
rdata->local_port = lport;
|
2008-12-10 07:10:17 +08:00
|
|
|
rdata->rp_state = RPORT_ST_INIT;
|
|
|
|
rdata->event = RPORT_EV_NONE;
|
|
|
|
rdata->flags = FC_RP_FLAGS_REC_SUPPORTED;
|
2009-08-26 05:00:39 +08:00
|
|
|
rdata->e_d_tov = lport->e_d_tov;
|
|
|
|
rdata->r_a_tov = lport->r_a_tov;
|
2009-08-26 05:01:01 +08:00
|
|
|
rdata->maxframe_size = FC_MIN_MAX_PAYLOAD;
|
2008-12-10 07:10:17 +08:00
|
|
|
INIT_DELAYED_WORK(&rdata->retry_work, fc_rport_timeout);
|
|
|
|
INIT_WORK(&rdata->event_work, fc_rport_work);
|
2009-08-26 05:02:59 +08:00
|
|
|
if (port_id != FC_FID_DIR_SERV)
|
2009-08-26 05:01:50 +08:00
|
|
|
list_add(&rdata->peers, &lport->disc.rports);
|
2009-08-26 05:00:50 +08:00
|
|
|
return rdata;
|
2008-12-10 07:10:17 +08:00
|
|
|
}
|
|
|
|
|
2009-08-26 05:01:01 +08:00
|
|
|
/**
|
|
|
|
* fc_rport_destroy() - free a remote port after last reference is released.
|
|
|
|
* @kref: pointer to kref inside struct fc_rport_priv
|
|
|
|
*/
|
|
|
|
static void fc_rport_destroy(struct kref *kref)
|
|
|
|
{
|
|
|
|
struct fc_rport_priv *rdata;
|
|
|
|
|
|
|
|
rdata = container_of(kref, struct fc_rport_priv, kref);
|
2009-08-26 05:01:18 +08:00
|
|
|
kfree(rdata);
|
2009-08-26 05:01:01 +08:00
|
|
|
}
|
|
|
|
|
2008-12-10 07:10:17 +08:00
|
|
|
/**
|
2009-02-28 02:55:45 +08:00
|
|
|
* fc_rport_state() - return a string for the state the rport is in
|
2009-08-26 05:00:50 +08:00
|
|
|
* @rdata: remote port private data
|
2008-12-10 07:10:17 +08:00
|
|
|
*/
|
2009-08-26 05:00:50 +08:00
|
|
|
static const char *fc_rport_state(struct fc_rport_priv *rdata)
|
2008-12-10 07:10:17 +08:00
|
|
|
{
|
|
|
|
const char *cp;
|
|
|
|
|
|
|
|
cp = fc_rport_state_names[rdata->rp_state];
|
|
|
|
if (!cp)
|
|
|
|
cp = "Unknown";
|
|
|
|
return cp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-02-28 02:55:45 +08:00
|
|
|
* fc_set_rport_loss_tmo() - Set the remote port loss timeout in seconds.
|
2008-12-10 07:10:17 +08:00
|
|
|
* @rport: Pointer to Fibre Channel remote port structure
|
|
|
|
* @timeout: timeout in seconds
|
|
|
|
*/
|
|
|
|
void fc_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout)
|
|
|
|
{
|
|
|
|
if (timeout)
|
|
|
|
rport->dev_loss_tmo = timeout + 5;
|
|
|
|
else
|
|
|
|
rport->dev_loss_tmo = 30;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(fc_set_rport_loss_tmo);
|
|
|
|
|
|
|
|
/**
|
2009-02-28 02:55:45 +08:00
|
|
|
* fc_plogi_get_maxframe() - Get max payload from the common service parameters
|
2008-12-10 07:10:17 +08:00
|
|
|
* @flp: FLOGI payload structure
|
|
|
|
* @maxval: upper limit, may be less than what is in the service parameters
|
|
|
|
*/
|
2009-02-28 02:55:50 +08:00
|
|
|
static unsigned int fc_plogi_get_maxframe(struct fc_els_flogi *flp,
|
|
|
|
unsigned int maxval)
|
2008-12-10 07:10:17 +08:00
|
|
|
{
|
|
|
|
unsigned int mfs;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get max payload from the common service parameters and the
|
|
|
|
* class 3 receive data field size.
|
|
|
|
*/
|
|
|
|
mfs = ntohs(flp->fl_csp.sp_bb_data) & FC_SP_BB_DATA_MASK;
|
|
|
|
if (mfs >= FC_SP_MIN_MAX_PAYLOAD && mfs < maxval)
|
|
|
|
maxval = mfs;
|
|
|
|
mfs = ntohs(flp->fl_cssp[3 - 1].cp_rdfs);
|
|
|
|
if (mfs >= FC_SP_MIN_MAX_PAYLOAD && mfs < maxval)
|
|
|
|
maxval = mfs;
|
|
|
|
return maxval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-02-28 02:55:45 +08:00
|
|
|
* fc_rport_state_enter() - Change the rport's state
|
2009-08-26 05:00:50 +08:00
|
|
|
* @rdata: The rport whose state should change
|
2008-12-10 07:10:17 +08:00
|
|
|
* @new: The new state of the rport
|
|
|
|
*
|
|
|
|
* Locking Note: Called with the rport lock held
|
|
|
|
*/
|
2009-08-26 05:00:50 +08:00
|
|
|
static void fc_rport_state_enter(struct fc_rport_priv *rdata,
|
2008-12-10 07:10:17 +08:00
|
|
|
enum fc_rport_state new)
|
|
|
|
{
|
|
|
|
if (rdata->rp_state != new)
|
|
|
|
rdata->retries = 0;
|
|
|
|
rdata->rp_state = new;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fc_rport_work(struct work_struct *work)
|
|
|
|
{
|
2009-02-28 02:54:41 +08:00
|
|
|
u32 port_id;
|
2009-08-26 05:00:34 +08:00
|
|
|
struct fc_rport_priv *rdata =
|
|
|
|
container_of(work, struct fc_rport_priv, event_work);
|
2009-08-26 05:01:18 +08:00
|
|
|
struct fc_rport_libfc_priv *rp;
|
2008-12-10 07:10:17 +08:00
|
|
|
enum fc_rport_event event;
|
|
|
|
struct fc_lport *lport = rdata->local_port;
|
|
|
|
struct fc_rport_operations *rport_ops;
|
2009-08-26 05:01:06 +08:00
|
|
|
struct fc_rport_identifiers ids;
|
2009-08-26 05:01:01 +08:00
|
|
|
struct fc_rport *rport;
|
2008-12-10 07:10:17 +08:00
|
|
|
|
|
|
|
mutex_lock(&rdata->rp_mutex);
|
|
|
|
event = rdata->event;
|
|
|
|
rport_ops = rdata->ops;
|
2009-08-26 05:01:01 +08:00
|
|
|
rport = rdata->rport;
|
2008-12-10 07:10:17 +08:00
|
|
|
|
2009-08-26 05:01:18 +08:00
|
|
|
FC_RPORT_DBG(rdata, "work event %u\n", event);
|
|
|
|
|
2009-08-26 05:01:06 +08:00
|
|
|
switch (event) {
|
2009-08-26 05:01:12 +08:00
|
|
|
case RPORT_EV_READY:
|
2009-08-26 05:01:01 +08:00
|
|
|
ids = rdata->ids;
|
2009-07-30 08:04:49 +08:00
|
|
|
rdata->event = RPORT_EV_NONE;
|
2009-08-26 05:01:18 +08:00
|
|
|
kref_get(&rdata->kref);
|
2008-12-10 07:10:17 +08:00
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
|
|
|
|
2009-08-26 05:01:18 +08:00
|
|
|
if (!rport)
|
|
|
|
rport = fc_remote_port_add(lport->host, 0, &ids);
|
|
|
|
if (!rport) {
|
|
|
|
FC_RPORT_DBG(rdata, "Failed to add the rport\n");
|
|
|
|
lport->tt.rport_logoff(rdata);
|
|
|
|
kref_put(&rdata->kref, lport->tt.rport_destroy);
|
|
|
|
return;
|
2008-12-10 07:10:17 +08:00
|
|
|
}
|
2009-08-26 05:01:18 +08:00
|
|
|
mutex_lock(&rdata->rp_mutex);
|
|
|
|
if (rdata->rport)
|
|
|
|
FC_RPORT_DBG(rdata, "rport already allocated\n");
|
|
|
|
rdata->rport = rport;
|
|
|
|
rport->maxframe_size = rdata->maxframe_size;
|
|
|
|
rport->supported_classes = rdata->supported_classes;
|
|
|
|
|
|
|
|
rp = rport->dd_data;
|
|
|
|
rp->local_port = lport;
|
|
|
|
rp->rp_state = rdata->rp_state;
|
|
|
|
rp->flags = rdata->flags;
|
|
|
|
rp->e_d_tov = rdata->e_d_tov;
|
|
|
|
rp->r_a_tov = rdata->r_a_tov;
|
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
|
|
|
|
2009-08-26 05:02:01 +08:00
|
|
|
if (rport_ops && rport_ops->event_callback) {
|
2009-08-26 05:01:18 +08:00
|
|
|
FC_RPORT_DBG(rdata, "callback ev %d\n", event);
|
2009-08-26 05:00:50 +08:00
|
|
|
rport_ops->event_callback(lport, rdata, event);
|
2009-08-26 05:01:18 +08:00
|
|
|
}
|
|
|
|
kref_put(&rdata->kref, lport->tt.rport_destroy);
|
2009-08-26 05:01:06 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RPORT_EV_FAILED:
|
|
|
|
case RPORT_EV_LOGO:
|
|
|
|
case RPORT_EV_STOP:
|
2009-08-26 05:01:18 +08:00
|
|
|
port_id = rdata->ids.port_id;
|
2008-12-10 07:10:17 +08:00
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
2009-08-26 05:01:18 +08:00
|
|
|
|
2009-08-26 05:01:50 +08:00
|
|
|
if (port_id != FC_FID_DIR_SERV) {
|
|
|
|
mutex_lock(&lport->disc.disc_mutex);
|
|
|
|
list_del(&rdata->peers);
|
|
|
|
mutex_unlock(&lport->disc.disc_mutex);
|
|
|
|
}
|
|
|
|
|
2009-08-26 05:02:01 +08:00
|
|
|
if (rport_ops && rport_ops->event_callback) {
|
2009-08-26 05:01:18 +08:00
|
|
|
FC_RPORT_DBG(rdata, "callback ev %d\n", event);
|
2009-08-26 05:00:50 +08:00
|
|
|
rport_ops->event_callback(lport, rdata, event);
|
2009-08-26 05:01:18 +08:00
|
|
|
}
|
2009-07-30 08:04:54 +08:00
|
|
|
cancel_delayed_work_sync(&rdata->retry_work);
|
2009-08-26 05:01:18 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset any outstanding exchanges before freeing rport.
|
|
|
|
*/
|
|
|
|
lport->tt.exch_mgr_reset(lport, 0, port_id);
|
|
|
|
lport->tt.exch_mgr_reset(lport, port_id, 0);
|
|
|
|
|
|
|
|
if (rport) {
|
|
|
|
rp = rport->dd_data;
|
|
|
|
rp->rp_state = RPORT_ST_DELETE;
|
|
|
|
mutex_lock(&rdata->rp_mutex);
|
|
|
|
rdata->rport = NULL;
|
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
2008-12-10 07:10:17 +08:00
|
|
|
fc_remote_port_delete(rport);
|
2009-02-28 02:54:41 +08:00
|
|
|
}
|
2009-08-26 05:01:18 +08:00
|
|
|
kref_put(&rdata->kref, lport->tt.rport_destroy);
|
2009-08-26 05:01:06 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2008-12-10 07:10:17 +08:00
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
2009-08-26 05:01:06 +08:00
|
|
|
break;
|
|
|
|
}
|
2008-12-10 07:10:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-02-28 02:55:45 +08:00
|
|
|
* fc_rport_login() - Start the remote port login state machine
|
2009-08-26 05:00:50 +08:00
|
|
|
* @rdata: private remote port
|
2008-12-10 07:10:17 +08:00
|
|
|
*
|
|
|
|
* Locking Note: Called without the rport lock held. This
|
|
|
|
* function will hold the rport lock, call an _enter_*
|
|
|
|
* function and then unlock the rport.
|
|
|
|
*/
|
2009-08-26 05:00:50 +08:00
|
|
|
int fc_rport_login(struct fc_rport_priv *rdata)
|
2008-12-10 07:10:17 +08:00
|
|
|
{
|
|
|
|
mutex_lock(&rdata->rp_mutex);
|
|
|
|
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Login to port\n");
|
2008-12-10 07:10:17 +08:00
|
|
|
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_enter_plogi(rdata);
|
2008-12-10 07:10:17 +08:00
|
|
|
|
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-30 08:04:49 +08:00
|
|
|
/**
|
|
|
|
* fc_rport_enter_delete() - schedule a remote port to be deleted.
|
2009-08-26 05:00:50 +08:00
|
|
|
* @rdata: private remote port
|
2009-07-30 08:04:49 +08:00
|
|
|
* @event: event to report as the reason for deletion
|
|
|
|
*
|
|
|
|
* Locking Note: Called with the rport lock held.
|
|
|
|
*
|
|
|
|
* Allow state change into DELETE only once.
|
|
|
|
*
|
|
|
|
* Call queue_work only if there's no event already pending.
|
|
|
|
* Set the new event so that the old pending event will not occur.
|
|
|
|
* Since we have the mutex, even if fc_rport_work() is already started,
|
|
|
|
* it'll see the new event.
|
|
|
|
*/
|
2009-08-26 05:00:50 +08:00
|
|
|
static void fc_rport_enter_delete(struct fc_rport_priv *rdata,
|
2009-07-30 08:04:49 +08:00
|
|
|
enum fc_rport_event event)
|
|
|
|
{
|
|
|
|
if (rdata->rp_state == RPORT_ST_DELETE)
|
|
|
|
return;
|
|
|
|
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Delete port\n");
|
2009-07-30 08:04:49 +08:00
|
|
|
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_state_enter(rdata, RPORT_ST_DELETE);
|
2009-07-30 08:04:49 +08:00
|
|
|
|
|
|
|
if (rdata->event == RPORT_EV_NONE)
|
|
|
|
queue_work(rport_event_queue, &rdata->event_work);
|
|
|
|
rdata->event = event;
|
|
|
|
}
|
|
|
|
|
2008-12-10 07:10:17 +08:00
|
|
|
/**
|
2009-02-28 02:55:45 +08:00
|
|
|
* fc_rport_logoff() - Logoff and remove an rport
|
2009-08-26 05:00:50 +08:00
|
|
|
* @rdata: private remote port
|
2008-12-10 07:10:17 +08:00
|
|
|
*
|
|
|
|
* Locking Note: Called without the rport lock held. This
|
|
|
|
* function will hold the rport lock, call an _enter_*
|
|
|
|
* function and then unlock the rport.
|
|
|
|
*/
|
2009-08-26 05:00:50 +08:00
|
|
|
int fc_rport_logoff(struct fc_rport_priv *rdata)
|
2008-12-10 07:10:17 +08:00
|
|
|
{
|
|
|
|
mutex_lock(&rdata->rp_mutex);
|
|
|
|
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Remove port\n");
|
2008-12-10 07:10:17 +08:00
|
|
|
|
2009-07-30 08:04:43 +08:00
|
|
|
if (rdata->rp_state == RPORT_ST_DELETE) {
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Port in Delete state, not removing\n");
|
[SCSI] libfc: Track rogue remote ports
Rogue ports are currently not tracked on any list. The only reference
to them is through any outstanding exchanges pending on the rogue ports.
If the module is removed while a retry is set on a rogue port
(say a Plogi retry for instance), this retry is not cancelled because there
is no reference to the rogue port in the discovery rports list. Thus the
local port can clean itself up, delete the exchange pool, and then the
rogue port timeout can fire and try to start up another exchange.
This patch tracks the rogue ports in a new list disc->rogue_rports. Creating
a new list instead of using the disc->rports list keeps remote port code
change to a minimum.
1) Whenever a rogue port is created, it is immediately added to the
disc->rogue_rports list.
2) When the rogues port goes to ready, it is removed from the rogue list
and the real remote port is added to the disc->rports list
3) The removal of the rogue from the disc->rogue_rports list is done in
the context of the fc_rport_work() workQ thread in discovery callback.
4) Real rports are removed from the disc->rports list like before. Lookup
is done only in the real rports list. This avoids making large changes
to the remote port code.
5) In fc_disc_stop_rports, the rogues list is traversed in addition to the
real list to stop the rogue ports and issue logoffs on them. This way, rogue
ports get cleaned up when the local port goes away.
6) rogue remote ports are not removed from the list right away, but
removed late in fc_rport_work() context, multiple threads can find the same
remote port in the list and call rport_logoff(). Rport_logoff() only
continues with the logoff if port is not in NONE state, thus preventing
multiple logoffs and multiple list deletions.
7) Since the rport is removed from the disc list at a later stage
(in the disc callback), incoming frames can find the rport even if
rport_logoff() has been called on the rport. When rport_logoff() is called,
the rport state is set to NONE, and we are trying to cancel all exchanges
and retries on that port. While in this state, if an incoming
Plogi/Prli/Logo or other frames match the rport, we should not reply
because the rport is in the NONE state. Just drop the frame, since the
rport will be deleted soon in the disc callback (fc_rport_work)
8) In fc_disc_single(), remove rport lookup and call to fc_disc_del_target.
fc_disc_single() is called from recv_rscn_req() where rport lookup
and rport_logoff is already done.
Signed-off-by: Abhijeet Joglekar <abjoglek@cisco.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2009-04-22 07:27:04 +08:00
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_enter_logo(rdata);
|
2008-12-10 07:10:17 +08:00
|
|
|
|
|
|
|
/*
|
2009-07-30 08:04:43 +08:00
|
|
|
* Change the state to Delete so that we discard
|
2008-12-10 07:10:17 +08:00
|
|
|
* the response.
|
|
|
|
*/
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_enter_delete(rdata, RPORT_EV_STOP);
|
2008-12-10 07:10:17 +08:00
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
|
|
|
|
[SCSI] libfc: Track rogue remote ports
Rogue ports are currently not tracked on any list. The only reference
to them is through any outstanding exchanges pending on the rogue ports.
If the module is removed while a retry is set on a rogue port
(say a Plogi retry for instance), this retry is not cancelled because there
is no reference to the rogue port in the discovery rports list. Thus the
local port can clean itself up, delete the exchange pool, and then the
rogue port timeout can fire and try to start up another exchange.
This patch tracks the rogue ports in a new list disc->rogue_rports. Creating
a new list instead of using the disc->rports list keeps remote port code
change to a minimum.
1) Whenever a rogue port is created, it is immediately added to the
disc->rogue_rports list.
2) When the rogues port goes to ready, it is removed from the rogue list
and the real remote port is added to the disc->rports list
3) The removal of the rogue from the disc->rogue_rports list is done in
the context of the fc_rport_work() workQ thread in discovery callback.
4) Real rports are removed from the disc->rports list like before. Lookup
is done only in the real rports list. This avoids making large changes
to the remote port code.
5) In fc_disc_stop_rports, the rogues list is traversed in addition to the
real list to stop the rogue ports and issue logoffs on them. This way, rogue
ports get cleaned up when the local port goes away.
6) rogue remote ports are not removed from the list right away, but
removed late in fc_rport_work() context, multiple threads can find the same
remote port in the list and call rport_logoff(). Rport_logoff() only
continues with the logoff if port is not in NONE state, thus preventing
multiple logoffs and multiple list deletions.
7) Since the rport is removed from the disc list at a later stage
(in the disc callback), incoming frames can find the rport even if
rport_logoff() has been called on the rport. When rport_logoff() is called,
the rport state is set to NONE, and we are trying to cancel all exchanges
and retries on that port. While in this state, if an incoming
Plogi/Prli/Logo or other frames match the rport, we should not reply
because the rport is in the NONE state. Just drop the frame, since the
rport will be deleted soon in the disc callback (fc_rport_work)
8) In fc_disc_single(), remove rport lookup and call to fc_disc_del_target.
fc_disc_single() is called from recv_rscn_req() where rport lookup
and rport_logoff is already done.
Signed-off-by: Abhijeet Joglekar <abjoglek@cisco.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2009-04-22 07:27:04 +08:00
|
|
|
out:
|
2008-12-10 07:10:17 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-02-28 02:55:45 +08:00
|
|
|
* fc_rport_enter_ready() - The rport is ready
|
2009-08-26 05:00:50 +08:00
|
|
|
* @rdata: private remote port
|
2008-12-10 07:10:17 +08:00
|
|
|
*
|
|
|
|
* Locking Note: The rport lock is expected to be held before calling
|
|
|
|
* this routine.
|
|
|
|
*/
|
2009-08-26 05:00:50 +08:00
|
|
|
static void fc_rport_enter_ready(struct fc_rport_priv *rdata)
|
2008-12-10 07:10:17 +08:00
|
|
|
{
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_state_enter(rdata, RPORT_ST_READY);
|
2008-12-10 07:10:17 +08:00
|
|
|
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Port is Ready\n");
|
2008-12-10 07:10:17 +08:00
|
|
|
|
2009-07-30 08:04:49 +08:00
|
|
|
if (rdata->event == RPORT_EV_NONE)
|
|
|
|
queue_work(rport_event_queue, &rdata->event_work);
|
2009-08-26 05:01:12 +08:00
|
|
|
rdata->event = RPORT_EV_READY;
|
2008-12-10 07:10:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-02-28 02:55:45 +08:00
|
|
|
* fc_rport_timeout() - Handler for the retry_work timer.
|
2009-08-26 05:00:34 +08:00
|
|
|
* @work: The work struct of the fc_rport_priv
|
2008-12-10 07:10:17 +08:00
|
|
|
*
|
|
|
|
* Locking Note: Called without the rport lock held. This
|
|
|
|
* function will hold the rport lock, call an _enter_*
|
|
|
|
* function and then unlock the rport.
|
|
|
|
*/
|
|
|
|
static void fc_rport_timeout(struct work_struct *work)
|
|
|
|
{
|
2009-08-26 05:00:34 +08:00
|
|
|
struct fc_rport_priv *rdata =
|
|
|
|
container_of(work, struct fc_rport_priv, retry_work.work);
|
2008-12-10 07:10:17 +08:00
|
|
|
|
|
|
|
mutex_lock(&rdata->rp_mutex);
|
|
|
|
|
|
|
|
switch (rdata->rp_state) {
|
|
|
|
case RPORT_ST_PLOGI:
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_enter_plogi(rdata);
|
2008-12-10 07:10:17 +08:00
|
|
|
break;
|
|
|
|
case RPORT_ST_PRLI:
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_enter_prli(rdata);
|
2008-12-10 07:10:17 +08:00
|
|
|
break;
|
|
|
|
case RPORT_ST_RTV:
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_enter_rtv(rdata);
|
2008-12-10 07:10:17 +08:00
|
|
|
break;
|
|
|
|
case RPORT_ST_LOGO:
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_enter_logo(rdata);
|
2008-12-10 07:10:17 +08:00
|
|
|
break;
|
|
|
|
case RPORT_ST_READY:
|
|
|
|
case RPORT_ST_INIT:
|
2009-07-30 08:04:43 +08:00
|
|
|
case RPORT_ST_DELETE:
|
2008-12-10 07:10:17 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-02-28 02:55:45 +08:00
|
|
|
* fc_rport_error() - Error handler, called once retries have been exhausted
|
2009-08-26 05:00:50 +08:00
|
|
|
* @rdata: private remote port
|
2008-12-10 07:10:17 +08:00
|
|
|
* @fp: The frame pointer
|
|
|
|
*
|
|
|
|
* Locking Note: The rport lock is expected to be held before
|
|
|
|
* calling this routine
|
|
|
|
*/
|
2009-08-26 05:00:50 +08:00
|
|
|
static void fc_rport_error(struct fc_rport_priv *rdata, struct fc_frame *fp)
|
2008-12-10 07:10:17 +08:00
|
|
|
{
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Error %ld in state %s, retries %d\n",
|
2009-08-26 05:01:39 +08:00
|
|
|
IS_ERR(fp) ? -PTR_ERR(fp) : 0,
|
|
|
|
fc_rport_state(rdata), rdata->retries);
|
2008-12-10 07:10:17 +08:00
|
|
|
|
2009-02-28 02:55:02 +08:00
|
|
|
switch (rdata->rp_state) {
|
|
|
|
case RPORT_ST_PLOGI:
|
|
|
|
case RPORT_ST_PRLI:
|
|
|
|
case RPORT_ST_LOGO:
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_enter_delete(rdata, RPORT_EV_FAILED);
|
2009-02-28 02:55:02 +08:00
|
|
|
break;
|
|
|
|
case RPORT_ST_RTV:
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_enter_ready(rdata);
|
2009-02-28 02:55:02 +08:00
|
|
|
break;
|
2009-07-30 08:04:43 +08:00
|
|
|
case RPORT_ST_DELETE:
|
2009-02-28 02:55:02 +08:00
|
|
|
case RPORT_ST_READY:
|
|
|
|
case RPORT_ST_INIT:
|
|
|
|
break;
|
2008-12-10 07:10:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-28 02:55:02 +08:00
|
|
|
/**
|
2009-02-28 02:55:45 +08:00
|
|
|
* fc_rport_error_retry() - Error handler when retries are desired
|
2009-08-26 05:00:50 +08:00
|
|
|
* @rdata: private remote port data
|
2009-02-28 02:55:02 +08:00
|
|
|
* @fp: The frame pointer
|
|
|
|
*
|
|
|
|
* If the error was an exchange timeout retry immediately,
|
|
|
|
* otherwise wait for E_D_TOV.
|
|
|
|
*
|
|
|
|
* Locking Note: The rport lock is expected to be held before
|
|
|
|
* calling this routine
|
|
|
|
*/
|
2009-08-26 05:00:50 +08:00
|
|
|
static void fc_rport_error_retry(struct fc_rport_priv *rdata,
|
|
|
|
struct fc_frame *fp)
|
2009-02-28 02:55:02 +08:00
|
|
|
{
|
|
|
|
unsigned long delay = FC_DEF_E_D_TOV;
|
|
|
|
|
|
|
|
/* make sure this isn't an FC_EX_CLOSED error, never retry those */
|
|
|
|
if (PTR_ERR(fp) == -FC_EX_CLOSED)
|
2009-08-26 05:00:50 +08:00
|
|
|
return fc_rport_error(rdata, fp);
|
2009-02-28 02:55:02 +08:00
|
|
|
|
2009-05-02 01:01:26 +08:00
|
|
|
if (rdata->retries < rdata->local_port->max_rport_retry_count) {
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Error %ld in state %s, retrying\n",
|
|
|
|
PTR_ERR(fp), fc_rport_state(rdata));
|
2009-02-28 02:55:02 +08:00
|
|
|
rdata->retries++;
|
|
|
|
/* no additional delay on exchange timeouts */
|
|
|
|
if (PTR_ERR(fp) == -FC_EX_TIMEOUT)
|
|
|
|
delay = 0;
|
|
|
|
schedule_delayed_work(&rdata->retry_work, delay);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-26 05:00:50 +08:00
|
|
|
return fc_rport_error(rdata, fp);
|
2009-02-28 02:55:02 +08:00
|
|
|
}
|
|
|
|
|
2008-12-10 07:10:17 +08:00
|
|
|
/**
|
2009-02-28 02:55:45 +08:00
|
|
|
* fc_rport_plogi_recv_resp() - Handle incoming ELS PLOGI response
|
2008-12-10 07:10:17 +08:00
|
|
|
* @sp: current sequence in the PLOGI exchange
|
|
|
|
* @fp: response frame
|
2009-08-26 05:00:50 +08:00
|
|
|
* @rdata_arg: private remote port data
|
2008-12-10 07:10:17 +08:00
|
|
|
*
|
|
|
|
* Locking Note: This function will be called without the rport lock
|
|
|
|
* held, but it will lock, call an _enter_* function or fc_rport_error
|
|
|
|
* and then unlock the rport.
|
|
|
|
*/
|
|
|
|
static void fc_rport_plogi_resp(struct fc_seq *sp, struct fc_frame *fp,
|
2009-08-26 05:00:50 +08:00
|
|
|
void *rdata_arg)
|
2008-12-10 07:10:17 +08:00
|
|
|
{
|
2009-08-26 05:00:50 +08:00
|
|
|
struct fc_rport_priv *rdata = rdata_arg;
|
2008-12-10 07:10:17 +08:00
|
|
|
struct fc_lport *lport = rdata->local_port;
|
2009-04-22 07:27:41 +08:00
|
|
|
struct fc_els_flogi *plp = NULL;
|
2008-12-10 07:10:17 +08:00
|
|
|
unsigned int tov;
|
|
|
|
u16 csp_seq;
|
|
|
|
u16 cssp_seq;
|
|
|
|
u8 op;
|
|
|
|
|
|
|
|
mutex_lock(&rdata->rp_mutex);
|
|
|
|
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Received a PLOGI response\n");
|
2008-12-10 07:10:17 +08:00
|
|
|
|
|
|
|
if (rdata->rp_state != RPORT_ST_PLOGI) {
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Received a PLOGI response, but in state "
|
|
|
|
"%s\n", fc_rport_state(rdata));
|
2009-04-22 07:26:58 +08:00
|
|
|
if (IS_ERR(fp))
|
|
|
|
goto err;
|
2008-12-10 07:10:17 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2009-04-22 07:26:58 +08:00
|
|
|
if (IS_ERR(fp)) {
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_error_retry(rdata, fp);
|
2009-04-22 07:26:58 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2008-12-10 07:10:17 +08:00
|
|
|
op = fc_frame_payload_op(fp);
|
|
|
|
if (op == ELS_LS_ACC &&
|
|
|
|
(plp = fc_frame_payload_get(fp, sizeof(*plp))) != NULL) {
|
2009-08-26 05:01:01 +08:00
|
|
|
rdata->ids.port_name = get_unaligned_be64(&plp->fl_wwpn);
|
|
|
|
rdata->ids.node_name = get_unaligned_be64(&plp->fl_wwnn);
|
2008-12-10 07:10:17 +08:00
|
|
|
|
|
|
|
tov = ntohl(plp->fl_csp.sp_e_d_tov);
|
|
|
|
if (ntohs(plp->fl_csp.sp_features) & FC_SP_FT_EDTR)
|
|
|
|
tov /= 1000;
|
|
|
|
if (tov > rdata->e_d_tov)
|
|
|
|
rdata->e_d_tov = tov;
|
|
|
|
csp_seq = ntohs(plp->fl_csp.sp_tot_seq);
|
|
|
|
cssp_seq = ntohs(plp->fl_cssp[3 - 1].cp_con_seq);
|
|
|
|
if (cssp_seq < csp_seq)
|
|
|
|
csp_seq = cssp_seq;
|
|
|
|
rdata->max_seq = csp_seq;
|
2009-08-26 05:01:01 +08:00
|
|
|
rdata->maxframe_size = fc_plogi_get_maxframe(plp, lport->mfs);
|
2008-12-10 07:10:17 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the rport is one of the well known addresses
|
|
|
|
* we skip PRLI and RTV and go straight to READY.
|
|
|
|
*/
|
2009-08-26 05:01:01 +08:00
|
|
|
if (rdata->ids.port_id >= FC_FID_DOM_MGR)
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_enter_ready(rdata);
|
2008-12-10 07:10:17 +08:00
|
|
|
else
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_enter_prli(rdata);
|
2008-12-10 07:10:17 +08:00
|
|
|
} else
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_error_retry(rdata, fp);
|
2008-12-10 07:10:17 +08:00
|
|
|
|
|
|
|
out:
|
|
|
|
fc_frame_free(fp);
|
|
|
|
err:
|
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
2009-08-26 05:01:01 +08:00
|
|
|
kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
|
2008-12-10 07:10:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-02-28 02:55:45 +08:00
|
|
|
* fc_rport_enter_plogi() - Send Port Login (PLOGI) request to peer
|
2009-08-26 05:00:50 +08:00
|
|
|
* @rdata: private remote port data
|
2008-12-10 07:10:17 +08:00
|
|
|
*
|
|
|
|
* Locking Note: The rport lock is expected to be held before calling
|
|
|
|
* this routine.
|
|
|
|
*/
|
2009-08-26 05:00:50 +08:00
|
|
|
static void fc_rport_enter_plogi(struct fc_rport_priv *rdata)
|
2008-12-10 07:10:17 +08:00
|
|
|
{
|
|
|
|
struct fc_lport *lport = rdata->local_port;
|
|
|
|
struct fc_frame *fp;
|
|
|
|
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Port entered PLOGI state from %s state\n",
|
|
|
|
fc_rport_state(rdata));
|
2008-12-10 07:10:17 +08:00
|
|
|
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_state_enter(rdata, RPORT_ST_PLOGI);
|
2008-12-10 07:10:17 +08:00
|
|
|
|
2009-08-26 05:01:01 +08:00
|
|
|
rdata->maxframe_size = FC_MIN_MAX_PAYLOAD;
|
2008-12-10 07:10:17 +08:00
|
|
|
fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi));
|
|
|
|
if (!fp) {
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_error_retry(rdata, fp);
|
2008-12-10 07:10:17 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
rdata->e_d_tov = lport->e_d_tov;
|
|
|
|
|
2009-08-26 05:01:01 +08:00
|
|
|
if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_PLOGI,
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_plogi_resp, rdata, lport->e_d_tov))
|
|
|
|
fc_rport_error_retry(rdata, fp);
|
2008-12-10 07:10:17 +08:00
|
|
|
else
|
2009-08-26 05:01:01 +08:00
|
|
|
kref_get(&rdata->kref);
|
2008-12-10 07:10:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-02-28 02:55:45 +08:00
|
|
|
* fc_rport_prli_resp() - Process Login (PRLI) response handler
|
2008-12-10 07:10:17 +08:00
|
|
|
* @sp: current sequence in the PRLI exchange
|
|
|
|
* @fp: response frame
|
2009-08-26 05:00:50 +08:00
|
|
|
* @rdata_arg: private remote port data
|
2008-12-10 07:10:17 +08:00
|
|
|
*
|
|
|
|
* Locking Note: This function will be called without the rport lock
|
|
|
|
* held, but it will lock, call an _enter_* function or fc_rport_error
|
|
|
|
* and then unlock the rport.
|
|
|
|
*/
|
|
|
|
static void fc_rport_prli_resp(struct fc_seq *sp, struct fc_frame *fp,
|
2009-08-26 05:00:50 +08:00
|
|
|
void *rdata_arg)
|
2008-12-10 07:10:17 +08:00
|
|
|
{
|
2009-08-26 05:00:50 +08:00
|
|
|
struct fc_rport_priv *rdata = rdata_arg;
|
2008-12-10 07:10:17 +08:00
|
|
|
struct {
|
|
|
|
struct fc_els_prli prli;
|
|
|
|
struct fc_els_spp spp;
|
|
|
|
} *pp;
|
|
|
|
u32 roles = FC_RPORT_ROLE_UNKNOWN;
|
|
|
|
u32 fcp_parm = 0;
|
|
|
|
u8 op;
|
|
|
|
|
|
|
|
mutex_lock(&rdata->rp_mutex);
|
|
|
|
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Received a PRLI response\n");
|
2008-12-10 07:10:17 +08:00
|
|
|
|
|
|
|
if (rdata->rp_state != RPORT_ST_PRLI) {
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Received a PRLI response, but in state "
|
|
|
|
"%s\n", fc_rport_state(rdata));
|
2009-04-22 07:26:58 +08:00
|
|
|
if (IS_ERR(fp))
|
|
|
|
goto err;
|
2008-12-10 07:10:17 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2009-04-22 07:26:58 +08:00
|
|
|
if (IS_ERR(fp)) {
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_error_retry(rdata, fp);
|
2009-04-22 07:26:58 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2008-12-10 07:10:17 +08:00
|
|
|
op = fc_frame_payload_op(fp);
|
|
|
|
if (op == ELS_LS_ACC) {
|
|
|
|
pp = fc_frame_payload_get(fp, sizeof(*pp));
|
|
|
|
if (pp && pp->prli.prli_spp_len >= sizeof(pp->spp)) {
|
|
|
|
fcp_parm = ntohl(pp->spp.spp_params);
|
|
|
|
if (fcp_parm & FCP_SPPF_RETRY)
|
|
|
|
rdata->flags |= FC_RP_FLAGS_RETRY;
|
|
|
|
}
|
|
|
|
|
2009-08-26 05:01:01 +08:00
|
|
|
rdata->supported_classes = FC_COS_CLASS3;
|
2008-12-10 07:10:17 +08:00
|
|
|
if (fcp_parm & FCP_SPPF_INIT_FCN)
|
|
|
|
roles |= FC_RPORT_ROLE_FCP_INITIATOR;
|
|
|
|
if (fcp_parm & FCP_SPPF_TARG_FCN)
|
|
|
|
roles |= FC_RPORT_ROLE_FCP_TARGET;
|
|
|
|
|
2009-08-26 05:01:01 +08:00
|
|
|
rdata->ids.roles = roles;
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_enter_rtv(rdata);
|
2008-12-10 07:10:17 +08:00
|
|
|
|
|
|
|
} else {
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Bad ELS response for PRLI command\n");
|
|
|
|
fc_rport_enter_delete(rdata, RPORT_EV_FAILED);
|
2008-12-10 07:10:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
fc_frame_free(fp);
|
|
|
|
err:
|
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
2009-08-26 05:01:01 +08:00
|
|
|
kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
|
2008-12-10 07:10:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-02-28 02:55:45 +08:00
|
|
|
* fc_rport_logo_resp() - Logout (LOGO) response handler
|
2008-12-10 07:10:17 +08:00
|
|
|
* @sp: current sequence in the LOGO exchange
|
|
|
|
* @fp: response frame
|
2009-08-26 05:00:50 +08:00
|
|
|
* @rdata_arg: private remote port data
|
2008-12-10 07:10:17 +08:00
|
|
|
*
|
|
|
|
* Locking Note: This function will be called without the rport lock
|
|
|
|
* held, but it will lock, call an _enter_* function or fc_rport_error
|
|
|
|
* and then unlock the rport.
|
|
|
|
*/
|
|
|
|
static void fc_rport_logo_resp(struct fc_seq *sp, struct fc_frame *fp,
|
2009-08-26 05:00:50 +08:00
|
|
|
void *rdata_arg)
|
2008-12-10 07:10:17 +08:00
|
|
|
{
|
2009-08-26 05:00:50 +08:00
|
|
|
struct fc_rport_priv *rdata = rdata_arg;
|
2008-12-10 07:10:17 +08:00
|
|
|
u8 op;
|
|
|
|
|
|
|
|
mutex_lock(&rdata->rp_mutex);
|
|
|
|
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Received a LOGO response\n");
|
2008-12-10 07:10:17 +08:00
|
|
|
|
|
|
|
if (rdata->rp_state != RPORT_ST_LOGO) {
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Received a LOGO response, but in state "
|
|
|
|
"%s\n", fc_rport_state(rdata));
|
2009-04-22 07:26:58 +08:00
|
|
|
if (IS_ERR(fp))
|
|
|
|
goto err;
|
2008-12-10 07:10:17 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2009-04-22 07:26:58 +08:00
|
|
|
if (IS_ERR(fp)) {
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_error_retry(rdata, fp);
|
2009-04-22 07:26:58 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2008-12-10 07:10:17 +08:00
|
|
|
op = fc_frame_payload_op(fp);
|
|
|
|
if (op == ELS_LS_ACC) {
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_enter_rtv(rdata);
|
2008-12-10 07:10:17 +08:00
|
|
|
} else {
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Bad ELS response for LOGO command\n");
|
|
|
|
fc_rport_enter_delete(rdata, RPORT_EV_LOGO);
|
2008-12-10 07:10:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
fc_frame_free(fp);
|
|
|
|
err:
|
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
2009-08-26 05:01:01 +08:00
|
|
|
kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
|
2008-12-10 07:10:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-02-28 02:55:45 +08:00
|
|
|
* fc_rport_enter_prli() - Send Process Login (PRLI) request to peer
|
2009-08-26 05:00:50 +08:00
|
|
|
* @rdata: private remote port data
|
2008-12-10 07:10:17 +08:00
|
|
|
*
|
|
|
|
* Locking Note: The rport lock is expected to be held before calling
|
|
|
|
* this routine.
|
|
|
|
*/
|
2009-08-26 05:00:50 +08:00
|
|
|
static void fc_rport_enter_prli(struct fc_rport_priv *rdata)
|
2008-12-10 07:10:17 +08:00
|
|
|
{
|
|
|
|
struct fc_lport *lport = rdata->local_port;
|
|
|
|
struct {
|
|
|
|
struct fc_els_prli prli;
|
|
|
|
struct fc_els_spp spp;
|
|
|
|
} *pp;
|
|
|
|
struct fc_frame *fp;
|
|
|
|
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Port entered PRLI state from %s state\n",
|
|
|
|
fc_rport_state(rdata));
|
2008-12-10 07:10:17 +08:00
|
|
|
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_state_enter(rdata, RPORT_ST_PRLI);
|
2008-12-10 07:10:17 +08:00
|
|
|
|
|
|
|
fp = fc_frame_alloc(lport, sizeof(*pp));
|
|
|
|
if (!fp) {
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_error_retry(rdata, fp);
|
2008-12-10 07:10:17 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-26 05:01:01 +08:00
|
|
|
if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_PRLI,
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_prli_resp, rdata, lport->e_d_tov))
|
|
|
|
fc_rport_error_retry(rdata, fp);
|
2008-12-10 07:10:17 +08:00
|
|
|
else
|
2009-08-26 05:01:01 +08:00
|
|
|
kref_get(&rdata->kref);
|
2008-12-10 07:10:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-02-28 02:55:45 +08:00
|
|
|
* fc_rport_els_rtv_resp() - Request Timeout Value response handler
|
2008-12-10 07:10:17 +08:00
|
|
|
* @sp: current sequence in the RTV exchange
|
|
|
|
* @fp: response frame
|
2009-08-26 05:00:50 +08:00
|
|
|
* @rdata_arg: private remote port data
|
2008-12-10 07:10:17 +08:00
|
|
|
*
|
|
|
|
* Many targets don't seem to support this.
|
|
|
|
*
|
|
|
|
* Locking Note: This function will be called without the rport lock
|
|
|
|
* held, but it will lock, call an _enter_* function or fc_rport_error
|
|
|
|
* and then unlock the rport.
|
|
|
|
*/
|
|
|
|
static void fc_rport_rtv_resp(struct fc_seq *sp, struct fc_frame *fp,
|
2009-08-26 05:00:50 +08:00
|
|
|
void *rdata_arg)
|
2008-12-10 07:10:17 +08:00
|
|
|
{
|
2009-08-26 05:00:50 +08:00
|
|
|
struct fc_rport_priv *rdata = rdata_arg;
|
2008-12-10 07:10:17 +08:00
|
|
|
u8 op;
|
|
|
|
|
|
|
|
mutex_lock(&rdata->rp_mutex);
|
|
|
|
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Received a RTV response\n");
|
2008-12-10 07:10:17 +08:00
|
|
|
|
|
|
|
if (rdata->rp_state != RPORT_ST_RTV) {
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Received a RTV response, but in state "
|
|
|
|
"%s\n", fc_rport_state(rdata));
|
2009-04-22 07:26:58 +08:00
|
|
|
if (IS_ERR(fp))
|
|
|
|
goto err;
|
2008-12-10 07:10:17 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2009-04-22 07:26:58 +08:00
|
|
|
if (IS_ERR(fp)) {
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_error(rdata, fp);
|
2009-04-22 07:26:58 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2008-12-10 07:10:17 +08:00
|
|
|
op = fc_frame_payload_op(fp);
|
|
|
|
if (op == ELS_LS_ACC) {
|
|
|
|
struct fc_els_rtv_acc *rtv;
|
|
|
|
u32 toq;
|
|
|
|
u32 tov;
|
|
|
|
|
|
|
|
rtv = fc_frame_payload_get(fp, sizeof(*rtv));
|
|
|
|
if (rtv) {
|
|
|
|
toq = ntohl(rtv->rtv_toq);
|
|
|
|
tov = ntohl(rtv->rtv_r_a_tov);
|
|
|
|
if (tov == 0)
|
|
|
|
tov = 1;
|
|
|
|
rdata->r_a_tov = tov;
|
|
|
|
tov = ntohl(rtv->rtv_e_d_tov);
|
|
|
|
if (toq & FC_ELS_RTV_EDRES)
|
|
|
|
tov /= 1000000;
|
|
|
|
if (tov == 0)
|
|
|
|
tov = 1;
|
|
|
|
rdata->e_d_tov = tov;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_enter_ready(rdata);
|
2008-12-10 07:10:17 +08:00
|
|
|
|
|
|
|
out:
|
|
|
|
fc_frame_free(fp);
|
|
|
|
err:
|
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
2009-08-26 05:01:01 +08:00
|
|
|
kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
|
2008-12-10 07:10:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-02-28 02:55:45 +08:00
|
|
|
* fc_rport_enter_rtv() - Send Request Timeout Value (RTV) request to peer
|
2009-08-26 05:00:50 +08:00
|
|
|
* @rdata: private remote port data
|
2008-12-10 07:10:17 +08:00
|
|
|
*
|
|
|
|
* Locking Note: The rport lock is expected to be held before calling
|
|
|
|
* this routine.
|
|
|
|
*/
|
2009-08-26 05:00:50 +08:00
|
|
|
static void fc_rport_enter_rtv(struct fc_rport_priv *rdata)
|
2008-12-10 07:10:17 +08:00
|
|
|
{
|
|
|
|
struct fc_frame *fp;
|
|
|
|
struct fc_lport *lport = rdata->local_port;
|
|
|
|
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Port entered RTV state from %s state\n",
|
|
|
|
fc_rport_state(rdata));
|
2008-12-10 07:10:17 +08:00
|
|
|
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_state_enter(rdata, RPORT_ST_RTV);
|
2008-12-10 07:10:17 +08:00
|
|
|
|
|
|
|
fp = fc_frame_alloc(lport, sizeof(struct fc_els_rtv));
|
|
|
|
if (!fp) {
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_error_retry(rdata, fp);
|
2008-12-10 07:10:17 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-26 05:01:01 +08:00
|
|
|
if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_RTV,
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_rtv_resp, rdata, lport->e_d_tov))
|
|
|
|
fc_rport_error_retry(rdata, fp);
|
2008-12-10 07:10:17 +08:00
|
|
|
else
|
2009-08-26 05:01:01 +08:00
|
|
|
kref_get(&rdata->kref);
|
2008-12-10 07:10:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-02-28 02:55:45 +08:00
|
|
|
* fc_rport_enter_logo() - Send Logout (LOGO) request to peer
|
2009-08-26 05:00:50 +08:00
|
|
|
* @rdata: private remote port data
|
2008-12-10 07:10:17 +08:00
|
|
|
*
|
|
|
|
* Locking Note: The rport lock is expected to be held before calling
|
|
|
|
* this routine.
|
|
|
|
*/
|
2009-08-26 05:00:50 +08:00
|
|
|
static void fc_rport_enter_logo(struct fc_rport_priv *rdata)
|
2008-12-10 07:10:17 +08:00
|
|
|
{
|
|
|
|
struct fc_lport *lport = rdata->local_port;
|
|
|
|
struct fc_frame *fp;
|
|
|
|
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Port entered LOGO state from %s state\n",
|
|
|
|
fc_rport_state(rdata));
|
2008-12-10 07:10:17 +08:00
|
|
|
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_state_enter(rdata, RPORT_ST_LOGO);
|
2008-12-10 07:10:17 +08:00
|
|
|
|
|
|
|
fp = fc_frame_alloc(lport, sizeof(struct fc_els_logo));
|
|
|
|
if (!fp) {
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_error_retry(rdata, fp);
|
2008-12-10 07:10:17 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-26 05:01:01 +08:00
|
|
|
if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_LOGO,
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_logo_resp, rdata, lport->e_d_tov))
|
|
|
|
fc_rport_error_retry(rdata, fp);
|
2008-12-10 07:10:17 +08:00
|
|
|
else
|
2009-08-26 05:01:01 +08:00
|
|
|
kref_get(&rdata->kref);
|
2008-12-10 07:10:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2009-02-28 02:55:45 +08:00
|
|
|
* fc_rport_recv_req() - Receive a request from a rport
|
2008-12-10 07:10:17 +08:00
|
|
|
* @sp: current sequence in the PLOGI exchange
|
|
|
|
* @fp: response frame
|
2009-08-26 05:00:50 +08:00
|
|
|
* @rdata_arg: private remote port data
|
2008-12-10 07:10:17 +08:00
|
|
|
*
|
|
|
|
* Locking Note: Called without the rport lock held. This
|
|
|
|
* function will hold the rport lock, call an _enter_*
|
|
|
|
* function and then unlock the rport.
|
|
|
|
*/
|
|
|
|
void fc_rport_recv_req(struct fc_seq *sp, struct fc_frame *fp,
|
2009-08-26 05:00:50 +08:00
|
|
|
struct fc_rport_priv *rdata)
|
2008-12-10 07:10:17 +08:00
|
|
|
{
|
|
|
|
struct fc_lport *lport = rdata->local_port;
|
|
|
|
|
|
|
|
struct fc_frame_header *fh;
|
|
|
|
struct fc_seq_els_data els_data;
|
|
|
|
u8 op;
|
|
|
|
|
|
|
|
mutex_lock(&rdata->rp_mutex);
|
|
|
|
|
|
|
|
els_data.fp = NULL;
|
|
|
|
els_data.explan = ELS_EXPL_NONE;
|
|
|
|
els_data.reason = ELS_RJT_NONE;
|
|
|
|
|
|
|
|
fh = fc_frame_header_get(fp);
|
|
|
|
|
|
|
|
if (fh->fh_r_ctl == FC_RCTL_ELS_REQ && fh->fh_type == FC_TYPE_ELS) {
|
|
|
|
op = fc_frame_payload_op(fp);
|
|
|
|
switch (op) {
|
|
|
|
case ELS_PLOGI:
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_recv_plogi_req(rdata, sp, fp);
|
2008-12-10 07:10:17 +08:00
|
|
|
break;
|
|
|
|
case ELS_PRLI:
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_recv_prli_req(rdata, sp, fp);
|
2008-12-10 07:10:17 +08:00
|
|
|
break;
|
|
|
|
case ELS_PRLO:
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_recv_prlo_req(rdata, sp, fp);
|
2008-12-10 07:10:17 +08:00
|
|
|
break;
|
|
|
|
case ELS_LOGO:
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_recv_logo_req(rdata, sp, fp);
|
2008-12-10 07:10:17 +08:00
|
|
|
break;
|
|
|
|
case ELS_RRQ:
|
|
|
|
els_data.fp = fp;
|
|
|
|
lport->tt.seq_els_rsp_send(sp, ELS_RRQ, &els_data);
|
|
|
|
break;
|
|
|
|
case ELS_REC:
|
|
|
|
els_data.fp = fp;
|
|
|
|
lport->tt.seq_els_rsp_send(sp, ELS_REC, &els_data);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
els_data.reason = ELS_RJT_UNSUP;
|
|
|
|
lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &els_data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-02-28 02:55:45 +08:00
|
|
|
* fc_rport_recv_plogi_req() - Handle incoming Port Login (PLOGI) request
|
2009-08-26 05:00:50 +08:00
|
|
|
* @rdata: private remote port data
|
2008-12-10 07:10:17 +08:00
|
|
|
* @sp: current sequence in the PLOGI exchange
|
|
|
|
* @fp: PLOGI request frame
|
|
|
|
*
|
|
|
|
* Locking Note: The rport lock is exected to be held before calling
|
|
|
|
* this function.
|
|
|
|
*/
|
2009-08-26 05:00:50 +08:00
|
|
|
static void fc_rport_recv_plogi_req(struct fc_rport_priv *rdata,
|
2008-12-10 07:10:17 +08:00
|
|
|
struct fc_seq *sp, struct fc_frame *rx_fp)
|
|
|
|
{
|
|
|
|
struct fc_lport *lport = rdata->local_port;
|
|
|
|
struct fc_frame *fp = rx_fp;
|
|
|
|
struct fc_exch *ep;
|
|
|
|
struct fc_frame_header *fh;
|
|
|
|
struct fc_els_flogi *pl;
|
|
|
|
struct fc_seq_els_data rjt_data;
|
|
|
|
u32 sid;
|
|
|
|
u64 wwpn;
|
|
|
|
u64 wwnn;
|
|
|
|
enum fc_els_rjt_reason reject = 0;
|
|
|
|
u32 f_ctl;
|
|
|
|
rjt_data.fp = NULL;
|
|
|
|
|
|
|
|
fh = fc_frame_header_get(fp);
|
|
|
|
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Received PLOGI request while in state %s\n",
|
|
|
|
fc_rport_state(rdata));
|
2008-12-10 07:10:17 +08:00
|
|
|
|
|
|
|
sid = ntoh24(fh->fh_s_id);
|
|
|
|
pl = fc_frame_payload_get(fp, sizeof(*pl));
|
|
|
|
if (!pl) {
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Received PLOGI too short\n");
|
2008-12-10 07:10:17 +08:00
|
|
|
WARN_ON(1);
|
|
|
|
/* XXX TBD: send reject? */
|
|
|
|
fc_frame_free(fp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wwpn = get_unaligned_be64(&pl->fl_wwpn);
|
|
|
|
wwnn = get_unaligned_be64(&pl->fl_wwnn);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the session was just created, possibly due to the incoming PLOGI,
|
|
|
|
* set the state appropriately and accept the PLOGI.
|
|
|
|
*
|
|
|
|
* If we had also sent a PLOGI, and if the received PLOGI is from a
|
|
|
|
* higher WWPN, we accept it, otherwise an LS_RJT is sent with reason
|
|
|
|
* "command already in progress".
|
|
|
|
*
|
|
|
|
* XXX TBD: If the session was ready before, the PLOGI should result in
|
|
|
|
* all outstanding exchanges being reset.
|
|
|
|
*/
|
|
|
|
switch (rdata->rp_state) {
|
|
|
|
case RPORT_ST_INIT:
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Received PLOGI, wwpn %llx state INIT "
|
2009-06-11 06:31:10 +08:00
|
|
|
"- reject\n", (unsigned long long)wwpn);
|
2008-12-10 07:10:17 +08:00
|
|
|
reject = ELS_RJT_UNSUP;
|
|
|
|
break;
|
|
|
|
case RPORT_ST_PLOGI:
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI state %d\n",
|
2009-06-11 06:31:10 +08:00
|
|
|
rdata->rp_state);
|
2008-12-10 07:10:17 +08:00
|
|
|
if (wwpn < lport->wwpn)
|
|
|
|
reject = ELS_RJT_INPROG;
|
|
|
|
break;
|
|
|
|
case RPORT_ST_PRLI:
|
|
|
|
case RPORT_ST_READY:
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Received PLOGI in logged-in state %d "
|
2009-06-11 06:31:10 +08:00
|
|
|
"- ignored for now\n", rdata->rp_state);
|
2008-12-10 07:10:17 +08:00
|
|
|
/* XXX TBD - should reset */
|
|
|
|
break;
|
2009-07-30 08:04:43 +08:00
|
|
|
case RPORT_ST_DELETE:
|
2008-12-10 07:10:17 +08:00
|
|
|
default:
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Received PLOGI in unexpected "
|
2009-06-11 06:31:10 +08:00
|
|
|
"state %d\n", rdata->rp_state);
|
[SCSI] libfc: Track rogue remote ports
Rogue ports are currently not tracked on any list. The only reference
to them is through any outstanding exchanges pending on the rogue ports.
If the module is removed while a retry is set on a rogue port
(say a Plogi retry for instance), this retry is not cancelled because there
is no reference to the rogue port in the discovery rports list. Thus the
local port can clean itself up, delete the exchange pool, and then the
rogue port timeout can fire and try to start up another exchange.
This patch tracks the rogue ports in a new list disc->rogue_rports. Creating
a new list instead of using the disc->rports list keeps remote port code
change to a minimum.
1) Whenever a rogue port is created, it is immediately added to the
disc->rogue_rports list.
2) When the rogues port goes to ready, it is removed from the rogue list
and the real remote port is added to the disc->rports list
3) The removal of the rogue from the disc->rogue_rports list is done in
the context of the fc_rport_work() workQ thread in discovery callback.
4) Real rports are removed from the disc->rports list like before. Lookup
is done only in the real rports list. This avoids making large changes
to the remote port code.
5) In fc_disc_stop_rports, the rogues list is traversed in addition to the
real list to stop the rogue ports and issue logoffs on them. This way, rogue
ports get cleaned up when the local port goes away.
6) rogue remote ports are not removed from the list right away, but
removed late in fc_rport_work() context, multiple threads can find the same
remote port in the list and call rport_logoff(). Rport_logoff() only
continues with the logoff if port is not in NONE state, thus preventing
multiple logoffs and multiple list deletions.
7) Since the rport is removed from the disc list at a later stage
(in the disc callback), incoming frames can find the rport even if
rport_logoff() has been called on the rport. When rport_logoff() is called,
the rport state is set to NONE, and we are trying to cancel all exchanges
and retries on that port. While in this state, if an incoming
Plogi/Prli/Logo or other frames match the rport, we should not reply
because the rport is in the NONE state. Just drop the frame, since the
rport will be deleted soon in the disc callback (fc_rport_work)
8) In fc_disc_single(), remove rport lookup and call to fc_disc_del_target.
fc_disc_single() is called from recv_rscn_req() where rport lookup
and rport_logoff is already done.
Signed-off-by: Abhijeet Joglekar <abjoglek@cisco.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2009-04-22 07:27:04 +08:00
|
|
|
fc_frame_free(fp);
|
|
|
|
return;
|
2008-12-10 07:10:17 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reject) {
|
|
|
|
rjt_data.reason = reject;
|
|
|
|
rjt_data.explan = ELS_EXPL_NONE;
|
|
|
|
lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data);
|
|
|
|
fc_frame_free(fp);
|
|
|
|
} else {
|
|
|
|
fp = fc_frame_alloc(lport, sizeof(*pl));
|
|
|
|
if (fp == NULL) {
|
|
|
|
fp = rx_fp;
|
|
|
|
rjt_data.reason = ELS_RJT_UNAB;
|
|
|
|
rjt_data.explan = ELS_EXPL_NONE;
|
|
|
|
lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data);
|
|
|
|
fc_frame_free(fp);
|
|
|
|
} else {
|
|
|
|
sp = lport->tt.seq_start_next(sp);
|
|
|
|
WARN_ON(!sp);
|
2009-08-26 05:01:01 +08:00
|
|
|
rdata->ids.port_name = wwpn;
|
|
|
|
rdata->ids.node_name = wwnn;
|
2008-12-10 07:10:17 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get session payload size from incoming PLOGI.
|
|
|
|
*/
|
2009-08-26 05:01:01 +08:00
|
|
|
rdata->maxframe_size =
|
2008-12-10 07:10:17 +08:00
|
|
|
fc_plogi_get_maxframe(pl, lport->mfs);
|
|
|
|
fc_frame_free(rx_fp);
|
|
|
|
fc_plogi_fill(lport, fp, ELS_LS_ACC);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send LS_ACC. If this fails,
|
|
|
|
* the originator should retry.
|
|
|
|
*/
|
|
|
|
f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ;
|
|
|
|
f_ctl |= FC_FC_END_SEQ | FC_FC_SEQ_INIT;
|
|
|
|
ep = fc_seq_exch(sp);
|
|
|
|
fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid,
|
|
|
|
FC_TYPE_ELS, f_ctl, 0);
|
|
|
|
lport->tt.seq_send(lport, sp, fp);
|
|
|
|
if (rdata->rp_state == RPORT_ST_PLOGI)
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_enter_prli(rdata);
|
2008-12-10 07:10:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-02-28 02:55:45 +08:00
|
|
|
* fc_rport_recv_prli_req() - Handle incoming Process Login (PRLI) request
|
2009-08-26 05:00:50 +08:00
|
|
|
* @rdata: private remote port data
|
2008-12-10 07:10:17 +08:00
|
|
|
* @sp: current sequence in the PRLI exchange
|
|
|
|
* @fp: PRLI request frame
|
|
|
|
*
|
|
|
|
* Locking Note: The rport lock is exected to be held before calling
|
|
|
|
* this function.
|
|
|
|
*/
|
2009-08-26 05:00:50 +08:00
|
|
|
static void fc_rport_recv_prli_req(struct fc_rport_priv *rdata,
|
2008-12-10 07:10:17 +08:00
|
|
|
struct fc_seq *sp, struct fc_frame *rx_fp)
|
|
|
|
{
|
|
|
|
struct fc_lport *lport = rdata->local_port;
|
|
|
|
struct fc_exch *ep;
|
|
|
|
struct fc_frame *fp;
|
|
|
|
struct fc_frame_header *fh;
|
|
|
|
struct {
|
|
|
|
struct fc_els_prli prli;
|
|
|
|
struct fc_els_spp spp;
|
|
|
|
} *pp;
|
|
|
|
struct fc_els_spp *rspp; /* request service param page */
|
|
|
|
struct fc_els_spp *spp; /* response spp */
|
|
|
|
unsigned int len;
|
|
|
|
unsigned int plen;
|
|
|
|
enum fc_els_rjt_reason reason = ELS_RJT_UNAB;
|
|
|
|
enum fc_els_rjt_explan explan = ELS_EXPL_NONE;
|
|
|
|
enum fc_els_spp_resp resp;
|
|
|
|
struct fc_seq_els_data rjt_data;
|
|
|
|
u32 f_ctl;
|
|
|
|
u32 fcp_parm;
|
|
|
|
u32 roles = FC_RPORT_ROLE_UNKNOWN;
|
|
|
|
rjt_data.fp = NULL;
|
|
|
|
|
|
|
|
fh = fc_frame_header_get(rx_fp);
|
|
|
|
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Received PRLI request while in state %s\n",
|
|
|
|
fc_rport_state(rdata));
|
2008-12-10 07:10:17 +08:00
|
|
|
|
|
|
|
switch (rdata->rp_state) {
|
|
|
|
case RPORT_ST_PRLI:
|
|
|
|
case RPORT_ST_READY:
|
|
|
|
reason = ELS_RJT_NONE;
|
|
|
|
break;
|
|
|
|
default:
|
[SCSI] libfc: Track rogue remote ports
Rogue ports are currently not tracked on any list. The only reference
to them is through any outstanding exchanges pending on the rogue ports.
If the module is removed while a retry is set on a rogue port
(say a Plogi retry for instance), this retry is not cancelled because there
is no reference to the rogue port in the discovery rports list. Thus the
local port can clean itself up, delete the exchange pool, and then the
rogue port timeout can fire and try to start up another exchange.
This patch tracks the rogue ports in a new list disc->rogue_rports. Creating
a new list instead of using the disc->rports list keeps remote port code
change to a minimum.
1) Whenever a rogue port is created, it is immediately added to the
disc->rogue_rports list.
2) When the rogues port goes to ready, it is removed from the rogue list
and the real remote port is added to the disc->rports list
3) The removal of the rogue from the disc->rogue_rports list is done in
the context of the fc_rport_work() workQ thread in discovery callback.
4) Real rports are removed from the disc->rports list like before. Lookup
is done only in the real rports list. This avoids making large changes
to the remote port code.
5) In fc_disc_stop_rports, the rogues list is traversed in addition to the
real list to stop the rogue ports and issue logoffs on them. This way, rogue
ports get cleaned up when the local port goes away.
6) rogue remote ports are not removed from the list right away, but
removed late in fc_rport_work() context, multiple threads can find the same
remote port in the list and call rport_logoff(). Rport_logoff() only
continues with the logoff if port is not in NONE state, thus preventing
multiple logoffs and multiple list deletions.
7) Since the rport is removed from the disc list at a later stage
(in the disc callback), incoming frames can find the rport even if
rport_logoff() has been called on the rport. When rport_logoff() is called,
the rport state is set to NONE, and we are trying to cancel all exchanges
and retries on that port. While in this state, if an incoming
Plogi/Prli/Logo or other frames match the rport, we should not reply
because the rport is in the NONE state. Just drop the frame, since the
rport will be deleted soon in the disc callback (fc_rport_work)
8) In fc_disc_single(), remove rport lookup and call to fc_disc_del_target.
fc_disc_single() is called from recv_rscn_req() where rport lookup
and rport_logoff is already done.
Signed-off-by: Abhijeet Joglekar <abjoglek@cisco.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2009-04-22 07:27:04 +08:00
|
|
|
fc_frame_free(rx_fp);
|
|
|
|
return;
|
2008-12-10 07:10:17 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
len = fr_len(rx_fp) - sizeof(*fh);
|
|
|
|
pp = fc_frame_payload_get(rx_fp, sizeof(*pp));
|
|
|
|
if (pp == NULL) {
|
|
|
|
reason = ELS_RJT_PROT;
|
|
|
|
explan = ELS_EXPL_INV_LEN;
|
|
|
|
} else {
|
|
|
|
plen = ntohs(pp->prli.prli_len);
|
|
|
|
if ((plen % 4) != 0 || plen > len) {
|
|
|
|
reason = ELS_RJT_PROT;
|
|
|
|
explan = ELS_EXPL_INV_LEN;
|
|
|
|
} else if (plen < len) {
|
|
|
|
len = plen;
|
|
|
|
}
|
|
|
|
plen = pp->prli.prli_spp_len;
|
|
|
|
if ((plen % 4) != 0 || plen < sizeof(*spp) ||
|
|
|
|
plen > len || len < sizeof(*pp)) {
|
|
|
|
reason = ELS_RJT_PROT;
|
|
|
|
explan = ELS_EXPL_INV_LEN;
|
|
|
|
}
|
|
|
|
rspp = &pp->spp;
|
|
|
|
}
|
|
|
|
if (reason != ELS_RJT_NONE ||
|
|
|
|
(fp = fc_frame_alloc(lport, len)) == NULL) {
|
|
|
|
rjt_data.reason = reason;
|
|
|
|
rjt_data.explan = explan;
|
|
|
|
lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data);
|
|
|
|
} else {
|
|
|
|
sp = lport->tt.seq_start_next(sp);
|
|
|
|
WARN_ON(!sp);
|
|
|
|
pp = fc_frame_payload_get(fp, len);
|
|
|
|
WARN_ON(!pp);
|
|
|
|
memset(pp, 0, len);
|
|
|
|
pp->prli.prli_cmd = ELS_LS_ACC;
|
|
|
|
pp->prli.prli_spp_len = plen;
|
|
|
|
pp->prli.prli_len = htons(len);
|
|
|
|
len -= sizeof(struct fc_els_prli);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Go through all the service parameter pages and build
|
|
|
|
* response. If plen indicates longer SPP than standard,
|
|
|
|
* use that. The entire response has been pre-cleared above.
|
|
|
|
*/
|
|
|
|
spp = &pp->spp;
|
|
|
|
while (len >= plen) {
|
|
|
|
spp->spp_type = rspp->spp_type;
|
|
|
|
spp->spp_type_ext = rspp->spp_type_ext;
|
|
|
|
spp->spp_flags = rspp->spp_flags & FC_SPP_EST_IMG_PAIR;
|
|
|
|
resp = FC_SPP_RESP_ACK;
|
|
|
|
if (rspp->spp_flags & FC_SPP_RPA_VAL)
|
|
|
|
resp = FC_SPP_RESP_NO_PA;
|
|
|
|
switch (rspp->spp_type) {
|
|
|
|
case 0: /* common to all FC-4 types */
|
|
|
|
break;
|
|
|
|
case FC_TYPE_FCP:
|
|
|
|
fcp_parm = ntohl(rspp->spp_params);
|
|
|
|
if (fcp_parm * FCP_SPPF_RETRY)
|
|
|
|
rdata->flags |= FC_RP_FLAGS_RETRY;
|
2009-08-26 05:01:01 +08:00
|
|
|
rdata->supported_classes = FC_COS_CLASS3;
|
2008-12-10 07:10:17 +08:00
|
|
|
if (fcp_parm & FCP_SPPF_INIT_FCN)
|
|
|
|
roles |= FC_RPORT_ROLE_FCP_INITIATOR;
|
|
|
|
if (fcp_parm & FCP_SPPF_TARG_FCN)
|
|
|
|
roles |= FC_RPORT_ROLE_FCP_TARGET;
|
2009-08-26 05:01:01 +08:00
|
|
|
rdata->ids.roles = roles;
|
2008-12-10 07:10:17 +08:00
|
|
|
|
|
|
|
spp->spp_params =
|
|
|
|
htonl(lport->service_params);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
resp = FC_SPP_RESP_INVL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
spp->spp_flags |= resp;
|
|
|
|
len -= plen;
|
|
|
|
rspp = (struct fc_els_spp *)((char *)rspp + plen);
|
|
|
|
spp = (struct fc_els_spp *)((char *)spp + plen);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send LS_ACC. If this fails, the originator should retry.
|
|
|
|
*/
|
|
|
|
f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ;
|
|
|
|
f_ctl |= FC_FC_END_SEQ | FC_FC_SEQ_INIT;
|
|
|
|
ep = fc_seq_exch(sp);
|
|
|
|
fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid,
|
|
|
|
FC_TYPE_ELS, f_ctl, 0);
|
|
|
|
lport->tt.seq_send(lport, sp, fp);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get lock and re-check state.
|
|
|
|
*/
|
|
|
|
switch (rdata->rp_state) {
|
|
|
|
case RPORT_ST_PRLI:
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_enter_ready(rdata);
|
2008-12-10 07:10:17 +08:00
|
|
|
break;
|
|
|
|
case RPORT_ST_READY:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fc_frame_free(rx_fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-02-28 02:55:45 +08:00
|
|
|
* fc_rport_recv_prlo_req() - Handle incoming Process Logout (PRLO) request
|
2009-08-26 05:00:50 +08:00
|
|
|
* @rdata: private remote port data
|
2008-12-10 07:10:17 +08:00
|
|
|
* @sp: current sequence in the PRLO exchange
|
|
|
|
* @fp: PRLO request frame
|
|
|
|
*
|
|
|
|
* Locking Note: The rport lock is exected to be held before calling
|
|
|
|
* this function.
|
|
|
|
*/
|
2009-08-26 05:00:50 +08:00
|
|
|
static void fc_rport_recv_prlo_req(struct fc_rport_priv *rdata,
|
|
|
|
struct fc_seq *sp,
|
2008-12-10 07:10:17 +08:00
|
|
|
struct fc_frame *fp)
|
|
|
|
{
|
|
|
|
struct fc_lport *lport = rdata->local_port;
|
|
|
|
|
|
|
|
struct fc_frame_header *fh;
|
|
|
|
struct fc_seq_els_data rjt_data;
|
|
|
|
|
|
|
|
fh = fc_frame_header_get(fp);
|
|
|
|
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Received PRLO request while in state %s\n",
|
|
|
|
fc_rport_state(rdata));
|
2008-12-10 07:10:17 +08:00
|
|
|
|
2009-07-30 08:04:43 +08:00
|
|
|
if (rdata->rp_state == RPORT_ST_DELETE) {
|
[SCSI] libfc: Track rogue remote ports
Rogue ports are currently not tracked on any list. The only reference
to them is through any outstanding exchanges pending on the rogue ports.
If the module is removed while a retry is set on a rogue port
(say a Plogi retry for instance), this retry is not cancelled because there
is no reference to the rogue port in the discovery rports list. Thus the
local port can clean itself up, delete the exchange pool, and then the
rogue port timeout can fire and try to start up another exchange.
This patch tracks the rogue ports in a new list disc->rogue_rports. Creating
a new list instead of using the disc->rports list keeps remote port code
change to a minimum.
1) Whenever a rogue port is created, it is immediately added to the
disc->rogue_rports list.
2) When the rogues port goes to ready, it is removed from the rogue list
and the real remote port is added to the disc->rports list
3) The removal of the rogue from the disc->rogue_rports list is done in
the context of the fc_rport_work() workQ thread in discovery callback.
4) Real rports are removed from the disc->rports list like before. Lookup
is done only in the real rports list. This avoids making large changes
to the remote port code.
5) In fc_disc_stop_rports, the rogues list is traversed in addition to the
real list to stop the rogue ports and issue logoffs on them. This way, rogue
ports get cleaned up when the local port goes away.
6) rogue remote ports are not removed from the list right away, but
removed late in fc_rport_work() context, multiple threads can find the same
remote port in the list and call rport_logoff(). Rport_logoff() only
continues with the logoff if port is not in NONE state, thus preventing
multiple logoffs and multiple list deletions.
7) Since the rport is removed from the disc list at a later stage
(in the disc callback), incoming frames can find the rport even if
rport_logoff() has been called on the rport. When rport_logoff() is called,
the rport state is set to NONE, and we are trying to cancel all exchanges
and retries on that port. While in this state, if an incoming
Plogi/Prli/Logo or other frames match the rport, we should not reply
because the rport is in the NONE state. Just drop the frame, since the
rport will be deleted soon in the disc callback (fc_rport_work)
8) In fc_disc_single(), remove rport lookup and call to fc_disc_del_target.
fc_disc_single() is called from recv_rscn_req() where rport lookup
and rport_logoff is already done.
Signed-off-by: Abhijeet Joglekar <abjoglek@cisco.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2009-04-22 07:27:04 +08:00
|
|
|
fc_frame_free(fp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-12-10 07:10:17 +08:00
|
|
|
rjt_data.fp = NULL;
|
|
|
|
rjt_data.reason = ELS_RJT_UNAB;
|
|
|
|
rjt_data.explan = ELS_EXPL_NONE;
|
|
|
|
lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data);
|
|
|
|
fc_frame_free(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-02-28 02:55:45 +08:00
|
|
|
* fc_rport_recv_logo_req() - Handle incoming Logout (LOGO) request
|
2009-08-26 05:00:50 +08:00
|
|
|
* @rdata: private remote port data
|
2008-12-10 07:10:17 +08:00
|
|
|
* @sp: current sequence in the LOGO exchange
|
|
|
|
* @fp: LOGO request frame
|
|
|
|
*
|
|
|
|
* Locking Note: The rport lock is exected to be held before calling
|
|
|
|
* this function.
|
|
|
|
*/
|
2009-08-26 05:00:50 +08:00
|
|
|
static void fc_rport_recv_logo_req(struct fc_rport_priv *rdata,
|
|
|
|
struct fc_seq *sp,
|
2008-12-10 07:10:17 +08:00
|
|
|
struct fc_frame *fp)
|
|
|
|
{
|
|
|
|
struct fc_frame_header *fh;
|
|
|
|
struct fc_lport *lport = rdata->local_port;
|
|
|
|
|
|
|
|
fh = fc_frame_header_get(fp);
|
|
|
|
|
2009-08-26 05:00:50 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Received LOGO request while in state %s\n",
|
|
|
|
fc_rport_state(rdata));
|
2008-12-10 07:10:17 +08:00
|
|
|
|
2009-07-30 08:04:43 +08:00
|
|
|
if (rdata->rp_state == RPORT_ST_DELETE) {
|
[SCSI] libfc: Track rogue remote ports
Rogue ports are currently not tracked on any list. The only reference
to them is through any outstanding exchanges pending on the rogue ports.
If the module is removed while a retry is set on a rogue port
(say a Plogi retry for instance), this retry is not cancelled because there
is no reference to the rogue port in the discovery rports list. Thus the
local port can clean itself up, delete the exchange pool, and then the
rogue port timeout can fire and try to start up another exchange.
This patch tracks the rogue ports in a new list disc->rogue_rports. Creating
a new list instead of using the disc->rports list keeps remote port code
change to a minimum.
1) Whenever a rogue port is created, it is immediately added to the
disc->rogue_rports list.
2) When the rogues port goes to ready, it is removed from the rogue list
and the real remote port is added to the disc->rports list
3) The removal of the rogue from the disc->rogue_rports list is done in
the context of the fc_rport_work() workQ thread in discovery callback.
4) Real rports are removed from the disc->rports list like before. Lookup
is done only in the real rports list. This avoids making large changes
to the remote port code.
5) In fc_disc_stop_rports, the rogues list is traversed in addition to the
real list to stop the rogue ports and issue logoffs on them. This way, rogue
ports get cleaned up when the local port goes away.
6) rogue remote ports are not removed from the list right away, but
removed late in fc_rport_work() context, multiple threads can find the same
remote port in the list and call rport_logoff(). Rport_logoff() only
continues with the logoff if port is not in NONE state, thus preventing
multiple logoffs and multiple list deletions.
7) Since the rport is removed from the disc list at a later stage
(in the disc callback), incoming frames can find the rport even if
rport_logoff() has been called on the rport. When rport_logoff() is called,
the rport state is set to NONE, and we are trying to cancel all exchanges
and retries on that port. While in this state, if an incoming
Plogi/Prli/Logo or other frames match the rport, we should not reply
because the rport is in the NONE state. Just drop the frame, since the
rport will be deleted soon in the disc callback (fc_rport_work)
8) In fc_disc_single(), remove rport lookup and call to fc_disc_del_target.
fc_disc_single() is called from recv_rscn_req() where rport lookup
and rport_logoff is already done.
Signed-off-by: Abhijeet Joglekar <abjoglek@cisco.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2009-04-22 07:27:04 +08:00
|
|
|
fc_frame_free(fp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-26 05:01:23 +08:00
|
|
|
fc_rport_enter_delete(rdata, RPORT_EV_LOGO);
|
2008-12-10 07:10:17 +08:00
|
|
|
|
|
|
|
lport->tt.seq_els_rsp_send(sp, ELS_LS_ACC, NULL);
|
|
|
|
fc_frame_free(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fc_rport_flush_queue(void)
|
|
|
|
{
|
|
|
|
flush_workqueue(rport_event_queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
int fc_rport_init(struct fc_lport *lport)
|
|
|
|
{
|
2009-08-26 05:02:06 +08:00
|
|
|
if (!lport->tt.rport_lookup)
|
|
|
|
lport->tt.rport_lookup = fc_rport_lookup;
|
|
|
|
|
2009-02-28 02:55:18 +08:00
|
|
|
if (!lport->tt.rport_create)
|
2009-08-26 05:01:18 +08:00
|
|
|
lport->tt.rport_create = fc_rport_create;
|
2009-02-28 02:55:18 +08:00
|
|
|
|
2008-12-10 07:10:17 +08:00
|
|
|
if (!lport->tt.rport_login)
|
|
|
|
lport->tt.rport_login = fc_rport_login;
|
|
|
|
|
|
|
|
if (!lport->tt.rport_logoff)
|
|
|
|
lport->tt.rport_logoff = fc_rport_logoff;
|
|
|
|
|
|
|
|
if (!lport->tt.rport_recv_req)
|
|
|
|
lport->tt.rport_recv_req = fc_rport_recv_req;
|
|
|
|
|
|
|
|
if (!lport->tt.rport_flush_queue)
|
|
|
|
lport->tt.rport_flush_queue = fc_rport_flush_queue;
|
|
|
|
|
2009-08-26 05:01:01 +08:00
|
|
|
if (!lport->tt.rport_destroy)
|
|
|
|
lport->tt.rport_destroy = fc_rport_destroy;
|
|
|
|
|
2008-12-10 07:10:17 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(fc_rport_init);
|
|
|
|
|
2009-04-28 12:49:31 +08:00
|
|
|
int fc_setup_rport(void)
|
2008-12-10 07:10:17 +08:00
|
|
|
{
|
|
|
|
rport_event_queue = create_singlethread_workqueue("fc_rport_eq");
|
|
|
|
if (!rport_event_queue)
|
|
|
|
return -ENOMEM;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(fc_setup_rport);
|
|
|
|
|
2009-04-28 12:49:31 +08:00
|
|
|
void fc_destroy_rport(void)
|
2008-12-10 07:10:17 +08:00
|
|
|
{
|
|
|
|
destroy_workqueue(rport_event_queue);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(fc_destroy_rport);
|
|
|
|
|
|
|
|
void fc_rport_terminate_io(struct fc_rport *rport)
|
|
|
|
{
|
2009-08-26 05:00:34 +08:00
|
|
|
struct fc_rport_libfc_priv *rp = rport->dd_data;
|
|
|
|
struct fc_lport *lport = rp->local_port;
|
2008-12-10 07:10:17 +08:00
|
|
|
|
2009-02-28 02:54:35 +08:00
|
|
|
lport->tt.exch_mgr_reset(lport, 0, rport->port_id);
|
|
|
|
lport->tt.exch_mgr_reset(lport, rport->port_id, 0);
|
2008-12-10 07:10:17 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(fc_rport_terminate_io);
|