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
|
2010-06-11 18:16:59 +08:00
|
|
|
* more comments on the hierarchy.
|
2008-12-10 07:10:17 +08:00
|
|
|
*
|
|
|
|
* 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 cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2008-12-10 07:10:17 +08:00
|
|
|
#include <linux/rcupdate.h>
|
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/workqueue.h>
|
2011-05-27 21:37:25 +08:00
|
|
|
#include <linux/export.h>
|
2008-12-10 07:10:17 +08:00
|
|
|
#include <asm/unaligned.h>
|
|
|
|
|
|
|
|
#include <scsi/libfc.h>
|
|
|
|
#include <scsi/fc_encode.h>
|
|
|
|
|
2009-11-04 03:45:58 +08:00
|
|
|
#include "fc_libfc.h"
|
|
|
|
|
2011-01-29 08:03:57 +08:00
|
|
|
static struct workqueue_struct *rport_event_queue;
|
2008-12-10 07:10:17 +08:00
|
|
|
|
2010-07-21 06:20:08 +08:00
|
|
|
static void fc_rport_enter_flogi(struct fc_rport_priv *);
|
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 *);
|
2009-08-26 05:03:47 +08:00
|
|
|
static void fc_rport_enter_adisc(struct fc_rport_priv *);
|
2008-12-10 07:10:17 +08:00
|
|
|
|
2010-07-21 06:21:12 +08:00
|
|
|
static void fc_rport_recv_plogi_req(struct fc_lport *, struct fc_frame *);
|
|
|
|
static void fc_rport_recv_prli_req(struct fc_rport_priv *, struct fc_frame *);
|
|
|
|
static void fc_rport_recv_prlo_req(struct fc_rport_priv *, struct fc_frame *);
|
|
|
|
static void fc_rport_recv_logo_req(struct fc_lport *, struct fc_frame *);
|
2008-12-10 07:10:17 +08:00
|
|
|
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",
|
2010-07-21 06:20:08 +08:00
|
|
|
[RPORT_ST_FLOGI] = "FLOGI",
|
|
|
|
[RPORT_ST_PLOGI_WAIT] = "PLOGI_WAIT",
|
2008-12-10 07:10:17 +08:00
|
|
|
[RPORT_ST_PLOGI] = "PLOGI",
|
|
|
|
[RPORT_ST_PRLI] = "PRLI",
|
|
|
|
[RPORT_ST_RTV] = "RTV",
|
|
|
|
[RPORT_ST_READY] = "Ready",
|
2009-08-26 05:03:47 +08:00
|
|
|
[RPORT_ST_ADISC] = "ADISC",
|
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
|
|
|
/**
|
2009-11-04 03:47:39 +08:00
|
|
|
* fc_rport_lookup() - Lookup a remote port by port_id
|
|
|
|
* @lport: The local port to lookup the remote port on
|
|
|
|
* @port_id: The remote port ID to look up
|
2010-07-21 06:19:37 +08:00
|
|
|
*
|
|
|
|
* The caller must hold either disc_mutex or rcu_read_lock().
|
2009-08-26 05:02:06 +08:00
|
|
|
*/
|
|
|
|
static struct fc_rport_priv *fc_rport_lookup(const struct fc_lport *lport,
|
|
|
|
u32 port_id)
|
|
|
|
{
|
|
|
|
struct fc_rport_priv *rdata;
|
|
|
|
|
2010-07-21 06:19:37 +08:00
|
|
|
list_for_each_entry_rcu(rdata, &lport->disc.rports, peers)
|
[SCSI] libfc: fix free of fc_rport_priv with timer pending
Timer crashes were caused by freeing a struct fc_rport_priv
with a timer pending, causing the timer facility list to be
corrupted. This was during FC uplink flap tests with a lot
of targets.
After discovery, we were doing an PLOGI on an rdata that was
in DELETE state but not yet removed from the lookup list.
This moved the rdata from DELETE state to PLOGI state.
If the PLOGI exchange allocation failed and needed to be
retried, the timer scheduling could race with the free
being done by fc_rport_work().
When fc_rport_login() is called on a rport in DELETE state,
move it to a new state RESTART. In fc_rport_work, when
handling a LOGO, STOPPED or FAILED event, look for restart
state. In the RESTART case, don't take the rdata off the
list and after the transport remote port is deleted and
exchanges are reset, re-login to the remote port.
Note that the new RESTART state also corrects a problem we
had when re-discovering a port that had moved to DELETE state.
In that case, a new rdata was created, but the old rdata
would do an exchange manager reset affecting the FC_ID
for both the new rdata and old rdata. With the new state,
the new port isn't logged into until after any old exchanges
are reset.
Signed-off-by: Joe Eykholt <jeykholt@cisco.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
2009-10-22 07:28:30 +08:00
|
|
|
if (rdata->ids.port_id == port_id)
|
2009-08-26 05:02:06 +08:00
|
|
|
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
|
2009-11-04 03:47:39 +08:00
|
|
|
* @lport: The local port this remote port will be associated with
|
|
|
|
* @ids: The identifiers for the new remote port
|
|
|
|
*
|
|
|
|
* The remote port will start in the INIT state.
|
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;
|
|
|
|
|
2010-07-21 06:19:42 +08:00
|
|
|
rdata = kzalloc(sizeof(*rdata) + lport->rport_priv_size, GFP_KERNEL);
|
2009-08-26 05:01:18 +08:00
|
|
|
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);
|
2011-01-29 08:05:27 +08:00
|
|
|
if (port_id != FC_FID_DIR_SERV) {
|
|
|
|
rdata->lld_event_callback = lport->tt.rport_event_callback;
|
2010-07-21 06:19:37 +08:00
|
|
|
list_add_rcu(&rdata->peers, &lport->disc.rports);
|
2011-01-29 08:05:27 +08:00
|
|
|
}
|
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
|
|
|
/**
|
2009-11-04 03:47:39 +08:00
|
|
|
* fc_rport_destroy() - Free a remote port after last reference is released
|
|
|
|
* @kref: The remote port's kref
|
2009-08-26 05:01:01 +08:00
|
|
|
*/
|
|
|
|
static void fc_rport_destroy(struct kref *kref)
|
|
|
|
{
|
|
|
|
struct fc_rport_priv *rdata;
|
|
|
|
|
|
|
|
rdata = container_of(kref, struct fc_rport_priv, kref);
|
2011-03-18 11:41:14 +08:00
|
|
|
kfree_rcu(rdata, rcu);
|
2009-08-26 05:01:01 +08:00
|
|
|
}
|
|
|
|
|
2008-12-10 07:10:17 +08:00
|
|
|
/**
|
2009-11-04 03:47:39 +08:00
|
|
|
* fc_rport_state() - Return a string identifying the remote port's state
|
|
|
|
* @rdata: The remote port
|
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-11-04 03:47:39 +08:00
|
|
|
* fc_set_rport_loss_tmo() - Set the remote port loss timeout
|
|
|
|
* @rport: The remote port that gets a new timeout value
|
|
|
|
* @timeout: The new timeout value (in seconds)
|
2008-12-10 07:10:17 +08:00
|
|
|
*/
|
|
|
|
void fc_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout)
|
|
|
|
{
|
|
|
|
if (timeout)
|
2010-10-09 08:12:10 +08:00
|
|
|
rport->dev_loss_tmo = timeout;
|
2008-12-10 07:10:17 +08:00
|
|
|
else
|
2010-10-09 08:12:10 +08:00
|
|
|
rport->dev_loss_tmo = 1;
|
2008-12-10 07:10:17 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(fc_set_rport_loss_tmo);
|
|
|
|
|
|
|
|
/**
|
2009-11-04 03:47:39 +08:00
|
|
|
* fc_plogi_get_maxframe() - Get the maximum payload from the common service
|
|
|
|
* parameters in a FLOGI frame
|
2010-07-21 06:20:08 +08:00
|
|
|
* @flp: The FLOGI or PLOGI payload
|
2009-11-04 03:47:39 +08:00
|
|
|
* @maxval: The maximum frame size upper limit; this may be less than what
|
|
|
|
* is in the service parameters
|
2008-12-10 07:10:17 +08:00
|
|
|
*/
|
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-11-04 03:47:39 +08:00
|
|
|
* fc_rport_state_enter() - Change the state of a remote port
|
|
|
|
* @rdata: The remote port whose state should change
|
|
|
|
* @new: The new state
|
2008-12-10 07:10:17 +08:00
|
|
|
*
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2009-11-04 03:47:39 +08:00
|
|
|
/**
|
|
|
|
* fc_rport_work() - Handler for remote port events in the rport_event_queue
|
|
|
|
* @work: Handle to the remote port being dequeued
|
|
|
|
*/
|
2008-12-10 07:10:17 +08:00
|
|
|
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-11-04 03:47:39 +08:00
|
|
|
struct fc_rport_libfc_priv *rpriv;
|
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;
|
2011-01-29 08:04:02 +08:00
|
|
|
struct fc4_prov *prov;
|
|
|
|
u8 type;
|
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;
|
2010-06-12 07:44:57 +08:00
|
|
|
rdata->major_retries = 0;
|
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;
|
|
|
|
|
2009-11-04 03:47:39 +08:00
|
|
|
rpriv = rport->dd_data;
|
|
|
|
rpriv->local_port = lport;
|
|
|
|
rpriv->rp_state = rdata->rp_state;
|
|
|
|
rpriv->flags = rdata->flags;
|
|
|
|
rpriv->e_d_tov = rdata->e_d_tov;
|
|
|
|
rpriv->r_a_tov = rdata->r_a_tov;
|
2009-08-26 05:01:18 +08:00
|
|
|
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
|
|
|
}
|
2011-01-29 08:05:27 +08:00
|
|
|
if (rdata->lld_event_callback) {
|
|
|
|
FC_RPORT_DBG(rdata, "lld callback ev %d\n", event);
|
|
|
|
rdata->lld_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:
|
2011-01-29 08:04:02 +08:00
|
|
|
if (rdata->prli_count) {
|
|
|
|
mutex_lock(&fc_prov_mutex);
|
|
|
|
for (type = 1; type < FC_FC4_PROV_SIZE; type++) {
|
|
|
|
prov = fc_passive_prov[type];
|
|
|
|
if (prov && prov->prlo)
|
|
|
|
prov->prlo(rdata);
|
|
|
|
}
|
|
|
|
mutex_unlock(&fc_prov_mutex);
|
|
|
|
}
|
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: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
|
|
|
}
|
2011-01-29 08:05:27 +08:00
|
|
|
if (rdata->lld_event_callback) {
|
|
|
|
FC_RPORT_DBG(rdata, "lld callback ev %d\n", event);
|
|
|
|
rdata->lld_event_callback(lport, rdata, event);
|
|
|
|
}
|
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) {
|
2009-11-04 03:47:39 +08:00
|
|
|
rpriv = rport->dd_data;
|
|
|
|
rpriv->rp_state = RPORT_ST_DELETE;
|
2009-08-26 05:01:18 +08:00
|
|
|
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
|
|
|
}
|
[SCSI] libfc: Fix remote port restart problem
This patch somewhat combines two fixes to remote port handing in libfc.
The first problem was that rport work could be queued on a deleted
and freed rport. This is handled by not resetting rdata->event
ton NONE if the rdata is about to be deleted.
However, that fix led to the second problem, described by
Bhanu Gollapudi, as follows:
> Here is the sequence of events. T1 is first LOGO receive thread, T2 is
> fc_rport_work() scheduled by T1 and T3 is second LOGO receive thread and
> T4 is fc_rport_work scheduled by T3.
>
> 1. (T1)Received 1st LOGO in state Ready
> 2. (T1)Delete port & enter to RESTART state.
> 3. (T1)schdule event_work, since event is RPORT_EV_NONE.
> 4. (T1)set event = RPORT_EV_LOGO
> 5. (T1)Enter RESTART state as disc_id is set.
> 6. (T2)remember to PLOGI, and set event = RPORT_EV_NONE
> 6. (T3)Received 2nd LOGO
> 7. (T3)Delete Port & enter to RESTART state.
> 8. (T3)schedule event_work, since event is RPORT_EV_NONE.
> 9. (T3)Enter RESTART state as disc_id is set.
> 9. (T3)set event = RPORT_EV_LOGO
> 10.(T2)work restart, enter PLOGI state and issues PLOGI
> 11.(T4)Since state is not RESTART anymore, restart is not set, and the
> event is not reset to RPORT_EV_NONE. (current event is RPORT_EV_LOGO).
> 12. Now, PLOGI succeeds and fc_rport_enter_ready() will not schedule
> event_work, and hence the rport will never be created, eventually losing
> the target after dev_loss_tmo.
So, the problem here is that we were tracking the desire for
the rport be restarted by state RESTART, which was otherwise
equivalent to DELETE. A contributing factor is that we dropped
the lock between steps 6 and 10 in thread T2, which allows the
state to change, and we didn't completely re-evaluate then.
This is hopefully corrected by the following minor redesign:
Simplify the rport restart logic by making the decision to
restart after deleting the transport rport. That decision
is based on a new STARTED flag that indicates fc_rport_login()
has been called and fc_rport_logoff() has not been called
since then. This replaces the need for the RESTART state.
Only restart if the rdata is still in DELETED state
and only if it still has the STARTED flag set.
Also now, since we clear the event code much later in the
work thread, allow for the possibility that the rport may
have become READY again via incoming PLOGI, and if so,
queue another event to handle that.
In the problem scenario, the second LOGO received will
cause the LOGO event to occur again.
Reported-by: Bhanu Gollapudi <bprakash@broadcom.com>
Signed-off-by: Joe Eykholt <jeykholt@cisco.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
2010-06-12 07:44:51 +08:00
|
|
|
|
|
|
|
mutex_lock(&lport->disc.disc_mutex);
|
|
|
|
mutex_lock(&rdata->rp_mutex);
|
|
|
|
if (rdata->rp_state == RPORT_ST_DELETE) {
|
|
|
|
if (port_id == FC_FID_DIR_SERV) {
|
|
|
|
rdata->event = RPORT_EV_NONE;
|
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
2011-02-26 07:02:51 +08:00
|
|
|
kref_put(&rdata->kref, lport->tt.rport_destroy);
|
2010-06-12 07:44:57 +08:00
|
|
|
} else if ((rdata->flags & FC_RP_STARTED) &&
|
|
|
|
rdata->major_retries <
|
|
|
|
lport->max_rport_retry_count) {
|
|
|
|
rdata->major_retries++;
|
[SCSI] libfc: Fix remote port restart problem
This patch somewhat combines two fixes to remote port handing in libfc.
The first problem was that rport work could be queued on a deleted
and freed rport. This is handled by not resetting rdata->event
ton NONE if the rdata is about to be deleted.
However, that fix led to the second problem, described by
Bhanu Gollapudi, as follows:
> Here is the sequence of events. T1 is first LOGO receive thread, T2 is
> fc_rport_work() scheduled by T1 and T3 is second LOGO receive thread and
> T4 is fc_rport_work scheduled by T3.
>
> 1. (T1)Received 1st LOGO in state Ready
> 2. (T1)Delete port & enter to RESTART state.
> 3. (T1)schdule event_work, since event is RPORT_EV_NONE.
> 4. (T1)set event = RPORT_EV_LOGO
> 5. (T1)Enter RESTART state as disc_id is set.
> 6. (T2)remember to PLOGI, and set event = RPORT_EV_NONE
> 6. (T3)Received 2nd LOGO
> 7. (T3)Delete Port & enter to RESTART state.
> 8. (T3)schedule event_work, since event is RPORT_EV_NONE.
> 9. (T3)Enter RESTART state as disc_id is set.
> 9. (T3)set event = RPORT_EV_LOGO
> 10.(T2)work restart, enter PLOGI state and issues PLOGI
> 11.(T4)Since state is not RESTART anymore, restart is not set, and the
> event is not reset to RPORT_EV_NONE. (current event is RPORT_EV_LOGO).
> 12. Now, PLOGI succeeds and fc_rport_enter_ready() will not schedule
> event_work, and hence the rport will never be created, eventually losing
> the target after dev_loss_tmo.
So, the problem here is that we were tracking the desire for
the rport be restarted by state RESTART, which was otherwise
equivalent to DELETE. A contributing factor is that we dropped
the lock between steps 6 and 10 in thread T2, which allows the
state to change, and we didn't completely re-evaluate then.
This is hopefully corrected by the following minor redesign:
Simplify the rport restart logic by making the decision to
restart after deleting the transport rport. That decision
is based on a new STARTED flag that indicates fc_rport_login()
has been called and fc_rport_logoff() has not been called
since then. This replaces the need for the RESTART state.
Only restart if the rdata is still in DELETED state
and only if it still has the STARTED flag set.
Also now, since we clear the event code much later in the
work thread, allow for the possibility that the rport may
have become READY again via incoming PLOGI, and if so,
queue another event to handle that.
In the problem scenario, the second LOGO received will
cause the LOGO event to occur again.
Reported-by: Bhanu Gollapudi <bprakash@broadcom.com>
Signed-off-by: Joe Eykholt <jeykholt@cisco.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
2010-06-12 07:44:51 +08:00
|
|
|
rdata->event = RPORT_EV_NONE;
|
|
|
|
FC_RPORT_DBG(rdata, "work restart\n");
|
2010-07-21 06:20:08 +08:00
|
|
|
fc_rport_enter_flogi(rdata);
|
[SCSI] libfc: Fix remote port restart problem
This patch somewhat combines two fixes to remote port handing in libfc.
The first problem was that rport work could be queued on a deleted
and freed rport. This is handled by not resetting rdata->event
ton NONE if the rdata is about to be deleted.
However, that fix led to the second problem, described by
Bhanu Gollapudi, as follows:
> Here is the sequence of events. T1 is first LOGO receive thread, T2 is
> fc_rport_work() scheduled by T1 and T3 is second LOGO receive thread and
> T4 is fc_rport_work scheduled by T3.
>
> 1. (T1)Received 1st LOGO in state Ready
> 2. (T1)Delete port & enter to RESTART state.
> 3. (T1)schdule event_work, since event is RPORT_EV_NONE.
> 4. (T1)set event = RPORT_EV_LOGO
> 5. (T1)Enter RESTART state as disc_id is set.
> 6. (T2)remember to PLOGI, and set event = RPORT_EV_NONE
> 6. (T3)Received 2nd LOGO
> 7. (T3)Delete Port & enter to RESTART state.
> 8. (T3)schedule event_work, since event is RPORT_EV_NONE.
> 9. (T3)Enter RESTART state as disc_id is set.
> 9. (T3)set event = RPORT_EV_LOGO
> 10.(T2)work restart, enter PLOGI state and issues PLOGI
> 11.(T4)Since state is not RESTART anymore, restart is not set, and the
> event is not reset to RPORT_EV_NONE. (current event is RPORT_EV_LOGO).
> 12. Now, PLOGI succeeds and fc_rport_enter_ready() will not schedule
> event_work, and hence the rport will never be created, eventually losing
> the target after dev_loss_tmo.
So, the problem here is that we were tracking the desire for
the rport be restarted by state RESTART, which was otherwise
equivalent to DELETE. A contributing factor is that we dropped
the lock between steps 6 and 10 in thread T2, which allows the
state to change, and we didn't completely re-evaluate then.
This is hopefully corrected by the following minor redesign:
Simplify the rport restart logic by making the decision to
restart after deleting the transport rport. That decision
is based on a new STARTED flag that indicates fc_rport_login()
has been called and fc_rport_logoff() has not been called
since then. This replaces the need for the RESTART state.
Only restart if the rdata is still in DELETED state
and only if it still has the STARTED flag set.
Also now, since we clear the event code much later in the
work thread, allow for the possibility that the rport may
have become READY again via incoming PLOGI, and if so,
queue another event to handle that.
In the problem scenario, the second LOGO received will
cause the LOGO event to occur again.
Reported-by: Bhanu Gollapudi <bprakash@broadcom.com>
Signed-off-by: Joe Eykholt <jeykholt@cisco.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
2010-06-12 07:44:51 +08:00
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
|
|
|
} else {
|
|
|
|
FC_RPORT_DBG(rdata, "work delete\n");
|
2010-07-21 06:19:37 +08:00
|
|
|
list_del_rcu(&rdata->peers);
|
[SCSI] libfc: Fix remote port restart problem
This patch somewhat combines two fixes to remote port handing in libfc.
The first problem was that rport work could be queued on a deleted
and freed rport. This is handled by not resetting rdata->event
ton NONE if the rdata is about to be deleted.
However, that fix led to the second problem, described by
Bhanu Gollapudi, as follows:
> Here is the sequence of events. T1 is first LOGO receive thread, T2 is
> fc_rport_work() scheduled by T1 and T3 is second LOGO receive thread and
> T4 is fc_rport_work scheduled by T3.
>
> 1. (T1)Received 1st LOGO in state Ready
> 2. (T1)Delete port & enter to RESTART state.
> 3. (T1)schdule event_work, since event is RPORT_EV_NONE.
> 4. (T1)set event = RPORT_EV_LOGO
> 5. (T1)Enter RESTART state as disc_id is set.
> 6. (T2)remember to PLOGI, and set event = RPORT_EV_NONE
> 6. (T3)Received 2nd LOGO
> 7. (T3)Delete Port & enter to RESTART state.
> 8. (T3)schedule event_work, since event is RPORT_EV_NONE.
> 9. (T3)Enter RESTART state as disc_id is set.
> 9. (T3)set event = RPORT_EV_LOGO
> 10.(T2)work restart, enter PLOGI state and issues PLOGI
> 11.(T4)Since state is not RESTART anymore, restart is not set, and the
> event is not reset to RPORT_EV_NONE. (current event is RPORT_EV_LOGO).
> 12. Now, PLOGI succeeds and fc_rport_enter_ready() will not schedule
> event_work, and hence the rport will never be created, eventually losing
> the target after dev_loss_tmo.
So, the problem here is that we were tracking the desire for
the rport be restarted by state RESTART, which was otherwise
equivalent to DELETE. A contributing factor is that we dropped
the lock between steps 6 and 10 in thread T2, which allows the
state to change, and we didn't completely re-evaluate then.
This is hopefully corrected by the following minor redesign:
Simplify the rport restart logic by making the decision to
restart after deleting the transport rport. That decision
is based on a new STARTED flag that indicates fc_rport_login()
has been called and fc_rport_logoff() has not been called
since then. This replaces the need for the RESTART state.
Only restart if the rdata is still in DELETED state
and only if it still has the STARTED flag set.
Also now, since we clear the event code much later in the
work thread, allow for the possibility that the rport may
have become READY again via incoming PLOGI, and if so,
queue another event to handle that.
In the problem scenario, the second LOGO received will
cause the LOGO event to occur again.
Reported-by: Bhanu Gollapudi <bprakash@broadcom.com>
Signed-off-by: Joe Eykholt <jeykholt@cisco.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
2010-06-12 07:44:51 +08:00
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
|
|
|
kref_put(&rdata->kref, lport->tt.rport_destroy);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Re-open for events. Reissue READY event if ready.
|
|
|
|
*/
|
|
|
|
rdata->event = RPORT_EV_NONE;
|
|
|
|
if (rdata->rp_state == RPORT_ST_READY)
|
|
|
|
fc_rport_enter_ready(rdata);
|
[SCSI] libfc: fix free of fc_rport_priv with timer pending
Timer crashes were caused by freeing a struct fc_rport_priv
with a timer pending, causing the timer facility list to be
corrupted. This was during FC uplink flap tests with a lot
of targets.
After discovery, we were doing an PLOGI on an rdata that was
in DELETE state but not yet removed from the lookup list.
This moved the rdata from DELETE state to PLOGI state.
If the PLOGI exchange allocation failed and needed to be
retried, the timer scheduling could race with the free
being done by fc_rport_work().
When fc_rport_login() is called on a rport in DELETE state,
move it to a new state RESTART. In fc_rport_work, when
handling a LOGO, STOPPED or FAILED event, look for restart
state. In the RESTART case, don't take the rdata off the
list and after the transport remote port is deleted and
exchanges are reset, re-login to the remote port.
Note that the new RESTART state also corrects a problem we
had when re-discovering a port that had moved to DELETE state.
In that case, a new rdata was created, but the old rdata
would do an exchange manager reset affecting the FC_ID
for both the new rdata and old rdata. With the new state,
the new port isn't logged into until after any old exchanges
are reset.
Signed-off-by: Joe Eykholt <jeykholt@cisco.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
2009-10-22 07:28:30 +08:00
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
[SCSI] libfc: Fix remote port restart problem
This patch somewhat combines two fixes to remote port handing in libfc.
The first problem was that rport work could be queued on a deleted
and freed rport. This is handled by not resetting rdata->event
ton NONE if the rdata is about to be deleted.
However, that fix led to the second problem, described by
Bhanu Gollapudi, as follows:
> Here is the sequence of events. T1 is first LOGO receive thread, T2 is
> fc_rport_work() scheduled by T1 and T3 is second LOGO receive thread and
> T4 is fc_rport_work scheduled by T3.
>
> 1. (T1)Received 1st LOGO in state Ready
> 2. (T1)Delete port & enter to RESTART state.
> 3. (T1)schdule event_work, since event is RPORT_EV_NONE.
> 4. (T1)set event = RPORT_EV_LOGO
> 5. (T1)Enter RESTART state as disc_id is set.
> 6. (T2)remember to PLOGI, and set event = RPORT_EV_NONE
> 6. (T3)Received 2nd LOGO
> 7. (T3)Delete Port & enter to RESTART state.
> 8. (T3)schedule event_work, since event is RPORT_EV_NONE.
> 9. (T3)Enter RESTART state as disc_id is set.
> 9. (T3)set event = RPORT_EV_LOGO
> 10.(T2)work restart, enter PLOGI state and issues PLOGI
> 11.(T4)Since state is not RESTART anymore, restart is not set, and the
> event is not reset to RPORT_EV_NONE. (current event is RPORT_EV_LOGO).
> 12. Now, PLOGI succeeds and fc_rport_enter_ready() will not schedule
> event_work, and hence the rport will never be created, eventually losing
> the target after dev_loss_tmo.
So, the problem here is that we were tracking the desire for
the rport be restarted by state RESTART, which was otherwise
equivalent to DELETE. A contributing factor is that we dropped
the lock between steps 6 and 10 in thread T2, which allows the
state to change, and we didn't completely re-evaluate then.
This is hopefully corrected by the following minor redesign:
Simplify the rport restart logic by making the decision to
restart after deleting the transport rport. That decision
is based on a new STARTED flag that indicates fc_rport_login()
has been called and fc_rport_logoff() has not been called
since then. This replaces the need for the RESTART state.
Only restart if the rdata is still in DELETED state
and only if it still has the STARTED flag set.
Also now, since we clear the event code much later in the
work thread, allow for the possibility that the rport may
have become READY again via incoming PLOGI, and if so,
queue another event to handle that.
In the problem scenario, the second LOGO received will
cause the LOGO event to occur again.
Reported-by: Bhanu Gollapudi <bprakash@broadcom.com>
Signed-off-by: Joe Eykholt <jeykholt@cisco.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
2010-06-12 07:44:51 +08:00
|
|
|
}
|
|
|
|
mutex_unlock(&lport->disc.disc_mutex);
|
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-11-04 03:47:39 +08:00
|
|
|
* @rdata: The remote port to be logged in to
|
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:03:47 +08:00
|
|
|
*
|
|
|
|
* This indicates the intent to be logged into the remote port.
|
|
|
|
* If it appears we are already logged in, ADISC is used to verify
|
|
|
|
* the setup.
|
2008-12-10 07:10:17 +08:00
|
|
|
*/
|
2012-01-14 09:26:20 +08:00
|
|
|
static int fc_rport_login(struct fc_rport_priv *rdata)
|
2008-12-10 07:10:17 +08:00
|
|
|
{
|
|
|
|
mutex_lock(&rdata->rp_mutex);
|
|
|
|
|
[SCSI] libfc: Fix remote port restart problem
This patch somewhat combines two fixes to remote port handing in libfc.
The first problem was that rport work could be queued on a deleted
and freed rport. This is handled by not resetting rdata->event
ton NONE if the rdata is about to be deleted.
However, that fix led to the second problem, described by
Bhanu Gollapudi, as follows:
> Here is the sequence of events. T1 is first LOGO receive thread, T2 is
> fc_rport_work() scheduled by T1 and T3 is second LOGO receive thread and
> T4 is fc_rport_work scheduled by T3.
>
> 1. (T1)Received 1st LOGO in state Ready
> 2. (T1)Delete port & enter to RESTART state.
> 3. (T1)schdule event_work, since event is RPORT_EV_NONE.
> 4. (T1)set event = RPORT_EV_LOGO
> 5. (T1)Enter RESTART state as disc_id is set.
> 6. (T2)remember to PLOGI, and set event = RPORT_EV_NONE
> 6. (T3)Received 2nd LOGO
> 7. (T3)Delete Port & enter to RESTART state.
> 8. (T3)schedule event_work, since event is RPORT_EV_NONE.
> 9. (T3)Enter RESTART state as disc_id is set.
> 9. (T3)set event = RPORT_EV_LOGO
> 10.(T2)work restart, enter PLOGI state and issues PLOGI
> 11.(T4)Since state is not RESTART anymore, restart is not set, and the
> event is not reset to RPORT_EV_NONE. (current event is RPORT_EV_LOGO).
> 12. Now, PLOGI succeeds and fc_rport_enter_ready() will not schedule
> event_work, and hence the rport will never be created, eventually losing
> the target after dev_loss_tmo.
So, the problem here is that we were tracking the desire for
the rport be restarted by state RESTART, which was otherwise
equivalent to DELETE. A contributing factor is that we dropped
the lock between steps 6 and 10 in thread T2, which allows the
state to change, and we didn't completely re-evaluate then.
This is hopefully corrected by the following minor redesign:
Simplify the rport restart logic by making the decision to
restart after deleting the transport rport. That decision
is based on a new STARTED flag that indicates fc_rport_login()
has been called and fc_rport_logoff() has not been called
since then. This replaces the need for the RESTART state.
Only restart if the rdata is still in DELETED state
and only if it still has the STARTED flag set.
Also now, since we clear the event code much later in the
work thread, allow for the possibility that the rport may
have become READY again via incoming PLOGI, and if so,
queue another event to handle that.
In the problem scenario, the second LOGO received will
cause the LOGO event to occur again.
Reported-by: Bhanu Gollapudi <bprakash@broadcom.com>
Signed-off-by: Joe Eykholt <jeykholt@cisco.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
2010-06-12 07:44:51 +08:00
|
|
|
rdata->flags |= FC_RP_STARTED;
|
2009-08-26 05:03:47 +08:00
|
|
|
switch (rdata->rp_state) {
|
|
|
|
case RPORT_ST_READY:
|
|
|
|
FC_RPORT_DBG(rdata, "ADISC port\n");
|
|
|
|
fc_rport_enter_adisc(rdata);
|
|
|
|
break;
|
[SCSI] libfc: fix free of fc_rport_priv with timer pending
Timer crashes were caused by freeing a struct fc_rport_priv
with a timer pending, causing the timer facility list to be
corrupted. This was during FC uplink flap tests with a lot
of targets.
After discovery, we were doing an PLOGI on an rdata that was
in DELETE state but not yet removed from the lookup list.
This moved the rdata from DELETE state to PLOGI state.
If the PLOGI exchange allocation failed and needed to be
retried, the timer scheduling could race with the free
being done by fc_rport_work().
When fc_rport_login() is called on a rport in DELETE state,
move it to a new state RESTART. In fc_rport_work, when
handling a LOGO, STOPPED or FAILED event, look for restart
state. In the RESTART case, don't take the rdata off the
list and after the transport remote port is deleted and
exchanges are reset, re-login to the remote port.
Note that the new RESTART state also corrects a problem we
had when re-discovering a port that had moved to DELETE state.
In that case, a new rdata was created, but the old rdata
would do an exchange manager reset affecting the FC_ID
for both the new rdata and old rdata. With the new state,
the new port isn't logged into until after any old exchanges
are reset.
Signed-off-by: Joe Eykholt <jeykholt@cisco.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
2009-10-22 07:28:30 +08:00
|
|
|
case RPORT_ST_DELETE:
|
|
|
|
FC_RPORT_DBG(rdata, "Restart deleted port\n");
|
|
|
|
break;
|
2009-08-26 05:03:47 +08:00
|
|
|
default:
|
|
|
|
FC_RPORT_DBG(rdata, "Login to port\n");
|
2010-07-21 06:20:08 +08:00
|
|
|
fc_rport_enter_flogi(rdata);
|
2009-08-26 05:03:47 +08:00
|
|
|
break;
|
|
|
|
}
|
2008-12-10 07:10:17 +08:00
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-30 08:04:49 +08:00
|
|
|
/**
|
2009-11-04 03:47:39 +08:00
|
|
|
* fc_rport_enter_delete() - Schedule a remote port to be deleted
|
|
|
|
* @rdata: The remote port to be deleted
|
|
|
|
* @event: The event to report as the reason for deletion
|
2009-07-30 08:04:49 +08:00
|
|
|
*
|
|
|
|
* 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-11-04 03:47:39 +08:00
|
|
|
* fc_rport_logoff() - Logoff and remove a remote port
|
|
|
|
* @rdata: The remote port to be logged off of
|
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.
|
|
|
|
*/
|
2012-01-14 09:26:20 +08:00
|
|
|
static 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
|
|
|
|
[SCSI] libfc: Fix remote port restart problem
This patch somewhat combines two fixes to remote port handing in libfc.
The first problem was that rport work could be queued on a deleted
and freed rport. This is handled by not resetting rdata->event
ton NONE if the rdata is about to be deleted.
However, that fix led to the second problem, described by
Bhanu Gollapudi, as follows:
> Here is the sequence of events. T1 is first LOGO receive thread, T2 is
> fc_rport_work() scheduled by T1 and T3 is second LOGO receive thread and
> T4 is fc_rport_work scheduled by T3.
>
> 1. (T1)Received 1st LOGO in state Ready
> 2. (T1)Delete port & enter to RESTART state.
> 3. (T1)schdule event_work, since event is RPORT_EV_NONE.
> 4. (T1)set event = RPORT_EV_LOGO
> 5. (T1)Enter RESTART state as disc_id is set.
> 6. (T2)remember to PLOGI, and set event = RPORT_EV_NONE
> 6. (T3)Received 2nd LOGO
> 7. (T3)Delete Port & enter to RESTART state.
> 8. (T3)schedule event_work, since event is RPORT_EV_NONE.
> 9. (T3)Enter RESTART state as disc_id is set.
> 9. (T3)set event = RPORT_EV_LOGO
> 10.(T2)work restart, enter PLOGI state and issues PLOGI
> 11.(T4)Since state is not RESTART anymore, restart is not set, and the
> event is not reset to RPORT_EV_NONE. (current event is RPORT_EV_LOGO).
> 12. Now, PLOGI succeeds and fc_rport_enter_ready() will not schedule
> event_work, and hence the rport will never be created, eventually losing
> the target after dev_loss_tmo.
So, the problem here is that we were tracking the desire for
the rport be restarted by state RESTART, which was otherwise
equivalent to DELETE. A contributing factor is that we dropped
the lock between steps 6 and 10 in thread T2, which allows the
state to change, and we didn't completely re-evaluate then.
This is hopefully corrected by the following minor redesign:
Simplify the rport restart logic by making the decision to
restart after deleting the transport rport. That decision
is based on a new STARTED flag that indicates fc_rport_login()
has been called and fc_rport_logoff() has not been called
since then. This replaces the need for the RESTART state.
Only restart if the rdata is still in DELETED state
and only if it still has the STARTED flag set.
Also now, since we clear the event code much later in the
work thread, allow for the possibility that the rport may
have become READY again via incoming PLOGI, and if so,
queue another event to handle that.
In the problem scenario, the second LOGO received will
cause the LOGO event to occur again.
Reported-by: Bhanu Gollapudi <bprakash@broadcom.com>
Signed-off-by: Joe Eykholt <jeykholt@cisco.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
2010-06-12 07:44:51 +08:00
|
|
|
rdata->flags &= ~FC_RP_STARTED;
|
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
|
|
|
goto out;
|
|
|
|
}
|
[SCSI] libfc: Fix remote port restart problem
This patch somewhat combines two fixes to remote port handing in libfc.
The first problem was that rport work could be queued on a deleted
and freed rport. This is handled by not resetting rdata->event
ton NONE if the rdata is about to be deleted.
However, that fix led to the second problem, described by
Bhanu Gollapudi, as follows:
> Here is the sequence of events. T1 is first LOGO receive thread, T2 is
> fc_rport_work() scheduled by T1 and T3 is second LOGO receive thread and
> T4 is fc_rport_work scheduled by T3.
>
> 1. (T1)Received 1st LOGO in state Ready
> 2. (T1)Delete port & enter to RESTART state.
> 3. (T1)schdule event_work, since event is RPORT_EV_NONE.
> 4. (T1)set event = RPORT_EV_LOGO
> 5. (T1)Enter RESTART state as disc_id is set.
> 6. (T2)remember to PLOGI, and set event = RPORT_EV_NONE
> 6. (T3)Received 2nd LOGO
> 7. (T3)Delete Port & enter to RESTART state.
> 8. (T3)schedule event_work, since event is RPORT_EV_NONE.
> 9. (T3)Enter RESTART state as disc_id is set.
> 9. (T3)set event = RPORT_EV_LOGO
> 10.(T2)work restart, enter PLOGI state and issues PLOGI
> 11.(T4)Since state is not RESTART anymore, restart is not set, and the
> event is not reset to RPORT_EV_NONE. (current event is RPORT_EV_LOGO).
> 12. Now, PLOGI succeeds and fc_rport_enter_ready() will not schedule
> event_work, and hence the rport will never be created, eventually losing
> the target after dev_loss_tmo.
So, the problem here is that we were tracking the desire for
the rport be restarted by state RESTART, which was otherwise
equivalent to DELETE. A contributing factor is that we dropped
the lock between steps 6 and 10 in thread T2, which allows the
state to change, and we didn't completely re-evaluate then.
This is hopefully corrected by the following minor redesign:
Simplify the rport restart logic by making the decision to
restart after deleting the transport rport. That decision
is based on a new STARTED flag that indicates fc_rport_login()
has been called and fc_rport_logoff() has not been called
since then. This replaces the need for the RESTART state.
Only restart if the rdata is still in DELETED state
and only if it still has the STARTED flag set.
Also now, since we clear the event code much later in the
work thread, allow for the possibility that the rport may
have become READY again via incoming PLOGI, and if so,
queue another event to handle that.
In the problem scenario, the second LOGO received will
cause the LOGO event to occur again.
Reported-by: Bhanu Gollapudi <bprakash@broadcom.com>
Signed-off-by: Joe Eykholt <jeykholt@cisco.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
2010-06-12 07:44:51 +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);
|
[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:
|
[SCSI] libfc: fix free of fc_rport_priv with timer pending
Timer crashes were caused by freeing a struct fc_rport_priv
with a timer pending, causing the timer facility list to be
corrupted. This was during FC uplink flap tests with a lot
of targets.
After discovery, we were doing an PLOGI on an rdata that was
in DELETE state but not yet removed from the lookup list.
This moved the rdata from DELETE state to PLOGI state.
If the PLOGI exchange allocation failed and needed to be
retried, the timer scheduling could race with the free
being done by fc_rport_work().
When fc_rport_login() is called on a rport in DELETE state,
move it to a new state RESTART. In fc_rport_work, when
handling a LOGO, STOPPED or FAILED event, look for restart
state. In the RESTART case, don't take the rdata off the
list and after the transport remote port is deleted and
exchanges are reset, re-login to the remote port.
Note that the new RESTART state also corrects a problem we
had when re-discovering a port that had moved to DELETE state.
In that case, a new rdata was created, but the old rdata
would do an exchange manager reset affecting the FC_ID
for both the new rdata and old rdata. With the new state,
the new port isn't logged into until after any old exchanges
are reset.
Signed-off-by: Joe Eykholt <jeykholt@cisco.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
2009-10-22 07:28:30 +08:00
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
2008-12-10 07:10:17 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-11-04 03:47:39 +08:00
|
|
|
* fc_rport_enter_ready() - Transition to the RPORT_ST_READY state
|
|
|
|
* @rdata: The remote port that is ready
|
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-11-04 03:47:39 +08:00
|
|
|
* fc_rport_timeout() - Handler for the retry_work timer
|
|
|
|
* @work: Handle to the remote port that has timed out
|
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) {
|
2010-07-21 06:20:08 +08:00
|
|
|
case RPORT_ST_FLOGI:
|
|
|
|
fc_rport_enter_flogi(rdata);
|
|
|
|
break;
|
2008-12-10 07:10:17 +08:00
|
|
|
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;
|
2009-08-26 05:03:47 +08:00
|
|
|
case RPORT_ST_ADISC:
|
|
|
|
fc_rport_enter_adisc(rdata);
|
|
|
|
break;
|
2010-07-21 06:20:08 +08:00
|
|
|
case RPORT_ST_PLOGI_WAIT:
|
2008-12-10 07:10:17 +08:00
|
|
|
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-11-04 03:47:39 +08:00
|
|
|
* @rdata: The remote port the error is happened on
|
|
|
|
* @fp: The error code encapsulated in a frame pointer
|
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_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) {
|
2010-07-21 06:20:08 +08:00
|
|
|
case RPORT_ST_FLOGI:
|
2009-02-28 02:55:02 +08:00
|
|
|
case RPORT_ST_PLOGI:
|
[SCSI] libfc: Fix remote port restart problem
This patch somewhat combines two fixes to remote port handing in libfc.
The first problem was that rport work could be queued on a deleted
and freed rport. This is handled by not resetting rdata->event
ton NONE if the rdata is about to be deleted.
However, that fix led to the second problem, described by
Bhanu Gollapudi, as follows:
> Here is the sequence of events. T1 is first LOGO receive thread, T2 is
> fc_rport_work() scheduled by T1 and T3 is second LOGO receive thread and
> T4 is fc_rport_work scheduled by T3.
>
> 1. (T1)Received 1st LOGO in state Ready
> 2. (T1)Delete port & enter to RESTART state.
> 3. (T1)schdule event_work, since event is RPORT_EV_NONE.
> 4. (T1)set event = RPORT_EV_LOGO
> 5. (T1)Enter RESTART state as disc_id is set.
> 6. (T2)remember to PLOGI, and set event = RPORT_EV_NONE
> 6. (T3)Received 2nd LOGO
> 7. (T3)Delete Port & enter to RESTART state.
> 8. (T3)schedule event_work, since event is RPORT_EV_NONE.
> 9. (T3)Enter RESTART state as disc_id is set.
> 9. (T3)set event = RPORT_EV_LOGO
> 10.(T2)work restart, enter PLOGI state and issues PLOGI
> 11.(T4)Since state is not RESTART anymore, restart is not set, and the
> event is not reset to RPORT_EV_NONE. (current event is RPORT_EV_LOGO).
> 12. Now, PLOGI succeeds and fc_rport_enter_ready() will not schedule
> event_work, and hence the rport will never be created, eventually losing
> the target after dev_loss_tmo.
So, the problem here is that we were tracking the desire for
the rport be restarted by state RESTART, which was otherwise
equivalent to DELETE. A contributing factor is that we dropped
the lock between steps 6 and 10 in thread T2, which allows the
state to change, and we didn't completely re-evaluate then.
This is hopefully corrected by the following minor redesign:
Simplify the rport restart logic by making the decision to
restart after deleting the transport rport. That decision
is based on a new STARTED flag that indicates fc_rport_login()
has been called and fc_rport_logoff() has not been called
since then. This replaces the need for the RESTART state.
Only restart if the rdata is still in DELETED state
and only if it still has the STARTED flag set.
Also now, since we clear the event code much later in the
work thread, allow for the possibility that the rport may
have become READY again via incoming PLOGI, and if so,
queue another event to handle that.
In the problem scenario, the second LOGO received will
cause the LOGO event to occur again.
Reported-by: Bhanu Gollapudi <bprakash@broadcom.com>
Signed-off-by: Joe Eykholt <jeykholt@cisco.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
2010-06-12 07:44:51 +08:00
|
|
|
rdata->flags &= ~FC_RP_STARTED;
|
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-08-26 05:03:47 +08:00
|
|
|
case RPORT_ST_PRLI:
|
|
|
|
case RPORT_ST_ADISC:
|
|
|
|
fc_rport_enter_logo(rdata);
|
|
|
|
break;
|
2010-07-21 06:20:08 +08:00
|
|
|
case RPORT_ST_PLOGI_WAIT:
|
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-11-04 03:47:39 +08:00
|
|
|
* fc_rport_error_retry() - Handler for remote port state retries
|
|
|
|
* @rdata: The remote port whose state is to be retried
|
|
|
|
* @fp: The error code encapsulated in a frame pointer
|
2009-02-28 02:55:02 +08:00
|
|
|
*
|
|
|
|
* 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
|
|
|
{
|
2013-02-14 08:33:04 +08:00
|
|
|
unsigned long delay = msecs_to_jiffies(FC_DEF_E_D_TOV);
|
2009-02-28 02:55:02 +08:00
|
|
|
|
|
|
|
/* make sure this isn't an FC_EX_CLOSED error, never retry those */
|
|
|
|
if (PTR_ERR(fp) == -FC_EX_CLOSED)
|
2011-01-29 08:03:26 +08:00
|
|
|
goto out;
|
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;
|
|
|
|
}
|
|
|
|
|
2011-01-29 08:03:26 +08:00
|
|
|
out:
|
|
|
|
fc_rport_error(rdata, fp);
|
2009-02-28 02:55:02 +08:00
|
|
|
}
|
|
|
|
|
2008-12-10 07:10:17 +08:00
|
|
|
/**
|
2010-07-21 06:20:08 +08:00
|
|
|
* fc_rport_login_complete() - Handle parameters and completion of p-mp login.
|
|
|
|
* @rdata: The remote port which we logged into or which logged into us.
|
|
|
|
* @fp: The FLOGI or PLOGI request or response frame
|
|
|
|
*
|
|
|
|
* Returns non-zero error if a problem is detected with the frame.
|
|
|
|
* Does not free the frame.
|
|
|
|
*
|
|
|
|
* This is only used in point-to-multipoint mode for FIP currently.
|
|
|
|
*/
|
|
|
|
static int fc_rport_login_complete(struct fc_rport_priv *rdata,
|
|
|
|
struct fc_frame *fp)
|
|
|
|
{
|
|
|
|
struct fc_lport *lport = rdata->local_port;
|
|
|
|
struct fc_els_flogi *flogi;
|
|
|
|
unsigned int e_d_tov;
|
|
|
|
u16 csp_flags;
|
|
|
|
|
|
|
|
flogi = fc_frame_payload_get(fp, sizeof(*flogi));
|
|
|
|
if (!flogi)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
csp_flags = ntohs(flogi->fl_csp.sp_features);
|
|
|
|
|
|
|
|
if (fc_frame_payload_op(fp) == ELS_FLOGI) {
|
|
|
|
if (csp_flags & FC_SP_FT_FPORT) {
|
|
|
|
FC_RPORT_DBG(rdata, "Fabric bit set in FLOGI\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* E_D_TOV is not valid on an incoming FLOGI request.
|
|
|
|
*/
|
|
|
|
e_d_tov = ntohl(flogi->fl_csp.sp_e_d_tov);
|
|
|
|
if (csp_flags & FC_SP_FT_EDTR)
|
|
|
|
e_d_tov /= 1000000;
|
|
|
|
if (e_d_tov > rdata->e_d_tov)
|
|
|
|
rdata->e_d_tov = e_d_tov;
|
|
|
|
}
|
|
|
|
rdata->maxframe_size = fc_plogi_get_maxframe(flogi, lport->mfs);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* fc_rport_flogi_resp() - Handle response to FLOGI request for p-mp mode
|
|
|
|
* @sp: The sequence that the FLOGI was on
|
|
|
|
* @fp: The FLOGI response frame
|
|
|
|
* @rp_arg: The remote port that received the FLOGI response
|
|
|
|
*/
|
2012-01-14 09:26:20 +08:00
|
|
|
static void fc_rport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp,
|
|
|
|
void *rp_arg)
|
2010-07-21 06:20:08 +08:00
|
|
|
{
|
|
|
|
struct fc_rport_priv *rdata = rp_arg;
|
|
|
|
struct fc_lport *lport = rdata->local_port;
|
|
|
|
struct fc_els_flogi *flogi;
|
|
|
|
unsigned int r_a_tov;
|
|
|
|
|
|
|
|
FC_RPORT_DBG(rdata, "Received a FLOGI %s\n", fc_els_resp_type(fp));
|
|
|
|
|
|
|
|
if (fp == ERR_PTR(-FC_EX_CLOSED))
|
2010-12-01 08:19:04 +08:00
|
|
|
goto put;
|
2010-07-21 06:20:08 +08:00
|
|
|
|
|
|
|
mutex_lock(&rdata->rp_mutex);
|
|
|
|
|
|
|
|
if (rdata->rp_state != RPORT_ST_FLOGI) {
|
|
|
|
FC_RPORT_DBG(rdata, "Received a FLOGI response, but in state "
|
|
|
|
"%s\n", fc_rport_state(rdata));
|
|
|
|
if (IS_ERR(fp))
|
|
|
|
goto err;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IS_ERR(fp)) {
|
|
|
|
fc_rport_error(rdata, fp);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fc_frame_payload_op(fp) != ELS_LS_ACC)
|
|
|
|
goto bad;
|
|
|
|
if (fc_rport_login_complete(rdata, fp))
|
|
|
|
goto bad;
|
|
|
|
|
|
|
|
flogi = fc_frame_payload_get(fp, sizeof(*flogi));
|
|
|
|
if (!flogi)
|
|
|
|
goto bad;
|
|
|
|
r_a_tov = ntohl(flogi->fl_csp.sp_r_a_tov);
|
|
|
|
if (r_a_tov > rdata->r_a_tov)
|
|
|
|
rdata->r_a_tov = r_a_tov;
|
|
|
|
|
|
|
|
if (rdata->ids.port_name < lport->wwpn)
|
|
|
|
fc_rport_enter_plogi(rdata);
|
|
|
|
else
|
|
|
|
fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
|
|
|
|
out:
|
|
|
|
fc_frame_free(fp);
|
|
|
|
err:
|
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
2010-12-01 08:19:04 +08:00
|
|
|
put:
|
2010-07-21 06:20:08 +08:00
|
|
|
kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
|
|
|
|
return;
|
|
|
|
bad:
|
|
|
|
FC_RPORT_DBG(rdata, "Bad FLOGI response\n");
|
|
|
|
fc_rport_error_retry(rdata, fp);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* fc_rport_enter_flogi() - Send a FLOGI request to the remote port for p-mp
|
|
|
|
* @rdata: The remote port to send a FLOGI to
|
|
|
|
*
|
|
|
|
* Locking Note: The rport lock is expected to be held before calling
|
|
|
|
* this routine.
|
|
|
|
*/
|
|
|
|
static void fc_rport_enter_flogi(struct fc_rport_priv *rdata)
|
|
|
|
{
|
|
|
|
struct fc_lport *lport = rdata->local_port;
|
|
|
|
struct fc_frame *fp;
|
|
|
|
|
|
|
|
if (!lport->point_to_multipoint)
|
|
|
|
return fc_rport_enter_plogi(rdata);
|
|
|
|
|
|
|
|
FC_RPORT_DBG(rdata, "Entered FLOGI state from %s state\n",
|
|
|
|
fc_rport_state(rdata));
|
|
|
|
|
|
|
|
fc_rport_state_enter(rdata, RPORT_ST_FLOGI);
|
|
|
|
|
|
|
|
fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi));
|
|
|
|
if (!fp)
|
|
|
|
return fc_rport_error_retry(rdata, fp);
|
|
|
|
|
|
|
|
if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_FLOGI,
|
|
|
|
fc_rport_flogi_resp, rdata,
|
|
|
|
2 * lport->r_a_tov))
|
|
|
|
fc_rport_error_retry(rdata, NULL);
|
|
|
|
else
|
|
|
|
kref_get(&rdata->kref);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* fc_rport_recv_flogi_req() - Handle Fabric Login (FLOGI) request in p-mp mode
|
|
|
|
* @lport: The local port that received the PLOGI request
|
|
|
|
* @rx_fp: The PLOGI request frame
|
|
|
|
*/
|
|
|
|
static void fc_rport_recv_flogi_req(struct fc_lport *lport,
|
2010-07-21 06:21:12 +08:00
|
|
|
struct fc_frame *rx_fp)
|
2010-07-21 06:20:08 +08:00
|
|
|
{
|
|
|
|
struct fc_disc *disc;
|
|
|
|
struct fc_els_flogi *flp;
|
|
|
|
struct fc_rport_priv *rdata;
|
|
|
|
struct fc_frame *fp = rx_fp;
|
|
|
|
struct fc_seq_els_data rjt_data;
|
2010-07-21 06:21:01 +08:00
|
|
|
u32 sid;
|
2010-07-21 06:20:08 +08:00
|
|
|
|
2010-07-21 06:20:56 +08:00
|
|
|
sid = fc_frame_sid(fp);
|
2010-07-21 06:20:08 +08:00
|
|
|
|
|
|
|
FC_RPORT_ID_DBG(lport, sid, "Received FLOGI request\n");
|
|
|
|
|
|
|
|
disc = &lport->disc;
|
|
|
|
mutex_lock(&disc->disc_mutex);
|
|
|
|
|
|
|
|
if (!lport->point_to_multipoint) {
|
|
|
|
rjt_data.reason = ELS_RJT_UNSUP;
|
|
|
|
rjt_data.explan = ELS_EXPL_NONE;
|
|
|
|
goto reject;
|
|
|
|
}
|
|
|
|
|
|
|
|
flp = fc_frame_payload_get(fp, sizeof(*flp));
|
|
|
|
if (!flp) {
|
|
|
|
rjt_data.reason = ELS_RJT_LOGIC;
|
|
|
|
rjt_data.explan = ELS_EXPL_INV_LEN;
|
|
|
|
goto reject;
|
|
|
|
}
|
|
|
|
|
|
|
|
rdata = lport->tt.rport_lookup(lport, sid);
|
|
|
|
if (!rdata) {
|
|
|
|
rjt_data.reason = ELS_RJT_FIP;
|
|
|
|
rjt_data.explan = ELS_EXPL_NOT_NEIGHBOR;
|
|
|
|
goto reject;
|
|
|
|
}
|
|
|
|
mutex_lock(&rdata->rp_mutex);
|
|
|
|
|
|
|
|
FC_RPORT_DBG(rdata, "Received FLOGI in %s state\n",
|
|
|
|
fc_rport_state(rdata));
|
|
|
|
|
|
|
|
switch (rdata->rp_state) {
|
|
|
|
case RPORT_ST_INIT:
|
[SCSI] libfc: Enhancement to RPORT state machine applicable only for VN2VN mode
Problem: Existing RPORT state machine continues witg FLOGI/PLOGI
process only after it receices beacon from other end. Once claiming
stage is over (either clain notify or clain repose), beacon is sent
and state machine enters into operational mode where it initiates the
rlogin process (FLOGI/PLOGI) to the peer but before this rlogin is
initiated, exitsing implementation checks if it received beacon from
other end, it beacon is not received yet, rlogin process is not
initiated. Other end initiates FLOGI but peer end keeps on rejecting
FLOGI, hence after 3 retries other end deletes associated rport, then
sends a beacon. Once the beacon is received, peer end now initiates
rlogin to the peer end but since associated rport is deleted FLOGI is
neither accepted nor the reject response send out because rport is
deleted. Hence unable to proceed withg FLOGI/PLOGI process and fails
to establish VN2VN connection.
Fix: VN2VN spec is not standard yet but based on exitsing collateral
on T11, it appears that, both end shall send beacon and enter into
'operational mode' without explictly waiting for beacon from other
end. Fix is to allow the RPORT login process as long as respective
RPORT is created (as part of claim notification / claim response) even
though state of RPORT is INIT. Means don't wait for beacon from peer
end, if peer end initiates FLOGI (means peer end exist and
responding).
Notes: This patch is preparing the FCoE stack for target wrt
offload. This is generic patch and harmless even if applied on storage
initiator because 'else if' condition of function 'fcoe_oem_found'
shall evaluate to TRUE only for targets.
Dependencies: None
Signed-off-by: Kiran Patil <kiran.patil@intel.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
2011-06-21 07:58:59 +08:00
|
|
|
/*
|
|
|
|
* If received the FLOGI request on RPORT which is INIT state
|
|
|
|
* (means not transition to FLOGI either fc_rport timeout
|
|
|
|
* function didn;t trigger or this end hasn;t received
|
|
|
|
* beacon yet from other end. In that case only, allow RPORT
|
|
|
|
* state machine to continue, otherwise fall through which
|
|
|
|
* causes the code to send reject response.
|
|
|
|
* NOTE; Not checking for FIP->state such as VNMP_UP or
|
|
|
|
* VNMP_CLAIM because if FIP state is not one of those,
|
|
|
|
* RPORT wouldn;t have created and 'rport_lookup' would have
|
|
|
|
* failed anyway in that case.
|
|
|
|
*/
|
|
|
|
if (lport->point_to_multipoint)
|
|
|
|
break;
|
2010-07-21 06:20:08 +08:00
|
|
|
case RPORT_ST_DELETE:
|
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
|
|
|
rjt_data.reason = ELS_RJT_FIP;
|
|
|
|
rjt_data.explan = ELS_EXPL_NOT_NEIGHBOR;
|
|
|
|
goto reject;
|
|
|
|
case RPORT_ST_FLOGI:
|
|
|
|
case RPORT_ST_PLOGI_WAIT:
|
|
|
|
case RPORT_ST_PLOGI:
|
|
|
|
break;
|
|
|
|
case RPORT_ST_PRLI:
|
|
|
|
case RPORT_ST_RTV:
|
|
|
|
case RPORT_ST_READY:
|
|
|
|
case RPORT_ST_ADISC:
|
|
|
|
/*
|
|
|
|
* Set the remote port to be deleted and to then restart.
|
|
|
|
* This queues work to be sure exchanges are reset.
|
|
|
|
*/
|
|
|
|
fc_rport_enter_delete(rdata, RPORT_EV_LOGO);
|
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
|
|
|
rjt_data.reason = ELS_RJT_BUSY;
|
|
|
|
rjt_data.explan = ELS_EXPL_NONE;
|
|
|
|
goto reject;
|
|
|
|
}
|
|
|
|
if (fc_rport_login_complete(rdata, fp)) {
|
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
|
|
|
rjt_data.reason = ELS_RJT_LOGIC;
|
|
|
|
rjt_data.explan = ELS_EXPL_NONE;
|
|
|
|
goto reject;
|
|
|
|
}
|
|
|
|
|
|
|
|
fp = fc_frame_alloc(lport, sizeof(*flp));
|
|
|
|
if (!fp)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
fc_flogi_fill(lport, fp);
|
|
|
|
flp = fc_frame_payload_get(fp, sizeof(*flp));
|
|
|
|
flp->fl_cmd = ELS_LS_ACC;
|
|
|
|
|
2010-07-21 06:21:01 +08:00
|
|
|
fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
|
|
|
|
lport->tt.frame_send(lport, fp);
|
2010-07-21 06:20:08 +08:00
|
|
|
|
|
|
|
if (rdata->ids.port_name < lport->wwpn)
|
|
|
|
fc_rport_enter_plogi(rdata);
|
|
|
|
else
|
|
|
|
fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
|
|
|
|
out:
|
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
|
|
|
mutex_unlock(&disc->disc_mutex);
|
2010-07-21 06:21:01 +08:00
|
|
|
fc_frame_free(rx_fp);
|
2010-07-21 06:20:08 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
reject:
|
|
|
|
mutex_unlock(&disc->disc_mutex);
|
2010-07-21 06:21:12 +08:00
|
|
|
lport->tt.seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
|
2010-07-21 06:21:01 +08:00
|
|
|
fc_frame_free(rx_fp);
|
2010-07-21 06:20:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* fc_rport_plogi_resp() - Handler for ELS PLOGI responses
|
2009-11-04 03:47:39 +08:00
|
|
|
* @sp: The sequence the PLOGI is on
|
|
|
|
* @fp: The PLOGI response frame
|
|
|
|
* @rdata_arg: The remote port that sent the PLOGI response
|
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
|
|
|
u16 csp_seq;
|
|
|
|
u16 cssp_seq;
|
|
|
|
u8 op;
|
|
|
|
|
|
|
|
mutex_lock(&rdata->rp_mutex);
|
|
|
|
|
2009-08-26 05:03:21 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Received a PLOGI %s\n", fc_els_resp_type(fp));
|
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
|
|
|
|
2011-01-29 08:05:27 +08:00
|
|
|
/* save plogi response sp_features for further reference */
|
|
|
|
rdata->sp_features = ntohs(plp->fl_csp.sp_features);
|
|
|
|
|
2010-07-21 06:20:08 +08:00
|
|
|
if (lport->point_to_multipoint)
|
|
|
|
fc_rport_login_complete(rdata, fp);
|
2008-12-10 07:10:17 +08:00
|
|
|
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);
|
2009-08-26 05:03:26 +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-11-04 03:47:39 +08:00
|
|
|
* fc_rport_enter_plogi() - Send Port Login (PLOGI) request
|
|
|
|
* @rdata: The remote port to send a PLOGI to
|
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) {
|
2010-07-21 06:20:08 +08:00
|
|
|
FC_RPORT_DBG(rdata, "%s frame alloc failed\n", __func__);
|
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-11-04 03:50:21 +08:00
|
|
|
fc_rport_plogi_resp, rdata,
|
|
|
|
2 * lport->r_a_tov))
|
2009-10-22 07:28:09 +08:00
|
|
|
fc_rport_error_retry(rdata, NULL);
|
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
|
2009-11-04 03:47:39 +08:00
|
|
|
* @sp: The sequence the PRLI response was on
|
|
|
|
* @fp: The PRLI response frame
|
|
|
|
* @rdata_arg: The remote port that sent the PRLI response
|
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;
|
2011-01-29 08:04:23 +08:00
|
|
|
struct fc_els_spp temp_spp;
|
|
|
|
struct fc4_prov *prov;
|
2008-12-10 07:10:17 +08:00
|
|
|
u32 roles = FC_RPORT_ROLE_UNKNOWN;
|
|
|
|
u32 fcp_parm = 0;
|
|
|
|
u8 op;
|
2010-06-12 07:43:54 +08:00
|
|
|
u8 resp_code = 0;
|
2008-12-10 07:10:17 +08:00
|
|
|
|
|
|
|
mutex_lock(&rdata->rp_mutex);
|
|
|
|
|
2009-08-26 05:03:21 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Received a PRLI %s\n", fc_els_resp_type(fp));
|
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;
|
|
|
|
}
|
|
|
|
|
2009-08-26 05:03:04 +08:00
|
|
|
/* reinitialize remote port roles */
|
|
|
|
rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
|
|
|
|
|
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));
|
2010-06-12 07:43:54 +08:00
|
|
|
if (!pp)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
resp_code = (pp->spp.spp_flags & FC_SPP_RESP_MASK);
|
|
|
|
FC_RPORT_DBG(rdata, "PRLI spp_flags = 0x%x\n",
|
|
|
|
pp->spp.spp_flags);
|
2011-01-29 08:05:27 +08:00
|
|
|
rdata->spp_type = pp->spp.spp_type;
|
2010-06-12 07:43:54 +08:00
|
|
|
if (resp_code != FC_SPP_RESP_ACK) {
|
|
|
|
if (resp_code == FC_SPP_RESP_CONF)
|
|
|
|
fc_rport_error(rdata, fp);
|
|
|
|
else
|
|
|
|
fc_rport_error_retry(rdata, fp);
|
|
|
|
goto out;
|
2008-12-10 07:10:17 +08:00
|
|
|
}
|
2010-06-12 07:43:54 +08:00
|
|
|
if (pp->prli.prli_spp_len < sizeof(pp->spp))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
fcp_parm = ntohl(pp->spp.spp_params);
|
|
|
|
if (fcp_parm & FCP_SPPF_RETRY)
|
|
|
|
rdata->flags |= FC_RP_FLAGS_RETRY;
|
2011-01-29 08:05:27 +08:00
|
|
|
if (fcp_parm & FCP_SPPF_CONF_COMPL)
|
|
|
|
rdata->flags |= FC_RP_FLAGS_CONF_REQ;
|
2008-12-10 07:10:17 +08:00
|
|
|
|
2011-01-29 08:04:23 +08:00
|
|
|
prov = fc_passive_prov[FC_TYPE_FCP];
|
|
|
|
if (prov) {
|
|
|
|
memset(&temp_spp, 0, sizeof(temp_spp));
|
|
|
|
prov->prli(rdata, pp->prli.prli_spp_len,
|
|
|
|
&pp->spp, &temp_spp);
|
|
|
|
}
|
|
|
|
|
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");
|
2010-06-12 07:43:49 +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-11-04 03:47:39 +08:00
|
|
|
* fc_rport_enter_prli() - Send Process Login (PRLI) request
|
|
|
|
* @rdata: The remote port to send the PRLI request to
|
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;
|
2011-01-29 08:04:23 +08:00
|
|
|
struct fc4_prov *prov;
|
2008-12-10 07:10:17 +08:00
|
|
|
|
2009-08-26 05:03:26 +08:00
|
|
|
/*
|
|
|
|
* If the rport is one of the well known addresses
|
|
|
|
* we skip PRLI and RTV and go straight to READY.
|
|
|
|
*/
|
|
|
|
if (rdata->ids.port_id >= FC_FID_DOM_MGR) {
|
|
|
|
fc_rport_enter_ready(rdata);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-01-29 08:04:23 +08:00
|
|
|
fc_prli_fill(lport, fp);
|
|
|
|
|
|
|
|
prov = fc_passive_prov[FC_TYPE_FCP];
|
|
|
|
if (prov) {
|
|
|
|
pp = fc_frame_payload_get(fp, sizeof(*pp));
|
|
|
|
prov->prli(rdata, sizeof(pp->spp), NULL, &pp->spp);
|
|
|
|
}
|
|
|
|
|
|
|
|
fc_fill_fc_hdr(fp, FC_RCTL_ELS_REQ, rdata->ids.port_id,
|
|
|
|
fc_host_port_id(lport->host), FC_TYPE_ELS,
|
|
|
|
FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0);
|
|
|
|
|
|
|
|
if (!lport->tt.exch_seq_send(lport, fp, fc_rport_prli_resp,
|
|
|
|
NULL, rdata, 2 * lport->r_a_tov))
|
2009-10-22 07:28:09 +08:00
|
|
|
fc_rport_error_retry(rdata, NULL);
|
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-11-04 03:47:39 +08:00
|
|
|
* fc_rport_els_rtv_resp() - Handler for Request Timeout Value (RTV) responses
|
|
|
|
* @sp: The sequence the RTV was on
|
|
|
|
* @fp: The RTV response frame
|
|
|
|
* @rdata_arg: The remote port that sent the RTV response
|
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:03:21 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Received a RTV %s\n", fc_els_resp_type(fp));
|
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-11-04 03:47:39 +08:00
|
|
|
* fc_rport_enter_rtv() - Send Request Timeout Value (RTV) request
|
|
|
|
* @rdata: The remote port to send the RTV request to
|
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-11-04 03:50:21 +08:00
|
|
|
fc_rport_rtv_resp, rdata,
|
|
|
|
2 * lport->r_a_tov))
|
2009-10-22 07:28:09 +08:00
|
|
|
fc_rport_error_retry(rdata, NULL);
|
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
|
|
|
}
|
|
|
|
|
2010-07-21 06:20:51 +08:00
|
|
|
/**
|
|
|
|
* fc_rport_logo_resp() - Handler for logout (LOGO) responses
|
|
|
|
* @sp: The sequence the LOGO was on
|
|
|
|
* @fp: The LOGO response frame
|
|
|
|
* @lport_arg: The local port
|
|
|
|
*/
|
|
|
|
static void fc_rport_logo_resp(struct fc_seq *sp, struct fc_frame *fp,
|
|
|
|
void *lport_arg)
|
|
|
|
{
|
|
|
|
struct fc_lport *lport = lport_arg;
|
|
|
|
|
|
|
|
FC_RPORT_ID_DBG(lport, fc_seq_exch(sp)->did,
|
|
|
|
"Received a LOGO %s\n", fc_els_resp_type(fp));
|
|
|
|
if (IS_ERR(fp))
|
|
|
|
return;
|
|
|
|
fc_frame_free(fp);
|
|
|
|
}
|
|
|
|
|
2008-12-10 07:10:17 +08:00
|
|
|
/**
|
2009-11-04 03:47:39 +08:00
|
|
|
* fc_rport_enter_logo() - Send a logout (LOGO) request
|
|
|
|
* @rdata: The remote port to send the LOGO request to
|
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;
|
|
|
|
|
2010-07-21 06:20:51 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Port sending LOGO from %s state\n",
|
2009-08-26 05:00:50 +08:00
|
|
|
fc_rport_state(rdata));
|
2008-12-10 07:10:17 +08:00
|
|
|
|
|
|
|
fp = fc_frame_alloc(lport, sizeof(struct fc_els_logo));
|
2010-07-21 06:20:51 +08:00
|
|
|
if (!fp)
|
2008-12-10 07:10:17 +08:00
|
|
|
return;
|
2010-07-21 06:20:51 +08:00
|
|
|
(void)lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_LOGO,
|
|
|
|
fc_rport_logo_resp, lport, 0);
|
2008-12-10 07:10:17 +08:00
|
|
|
}
|
|
|
|
|
2009-08-26 05:03:47 +08:00
|
|
|
/**
|
2009-11-04 03:47:39 +08:00
|
|
|
* fc_rport_els_adisc_resp() - Handler for Address Discovery (ADISC) responses
|
|
|
|
* @sp: The sequence the ADISC response was on
|
|
|
|
* @fp: The ADISC response frame
|
|
|
|
* @rdata_arg: The remote port that sent the ADISC response
|
2009-08-26 05:03:47 +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_adisc_resp(struct fc_seq *sp, struct fc_frame *fp,
|
2009-11-04 03:47:39 +08:00
|
|
|
void *rdata_arg)
|
2009-08-26 05:03:47 +08:00
|
|
|
{
|
|
|
|
struct fc_rport_priv *rdata = rdata_arg;
|
|
|
|
struct fc_els_adisc *adisc;
|
|
|
|
u8 op;
|
|
|
|
|
|
|
|
mutex_lock(&rdata->rp_mutex);
|
|
|
|
|
|
|
|
FC_RPORT_DBG(rdata, "Received a ADISC response\n");
|
|
|
|
|
|
|
|
if (rdata->rp_state != RPORT_ST_ADISC) {
|
|
|
|
FC_RPORT_DBG(rdata, "Received a ADISC resp but in state %s\n",
|
|
|
|
fc_rport_state(rdata));
|
|
|
|
if (IS_ERR(fp))
|
|
|
|
goto err;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IS_ERR(fp)) {
|
|
|
|
fc_rport_error(rdata, fp);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If address verification failed. Consider us logged out of the rport.
|
|
|
|
* Since the rport is still in discovery, we want to be
|
|
|
|
* logged in, so go to PLOGI state. Otherwise, go back to READY.
|
|
|
|
*/
|
|
|
|
op = fc_frame_payload_op(fp);
|
|
|
|
adisc = fc_frame_payload_get(fp, sizeof(*adisc));
|
|
|
|
if (op != ELS_LS_ACC || !adisc ||
|
|
|
|
ntoh24(adisc->adisc_port_id) != rdata->ids.port_id ||
|
|
|
|
get_unaligned_be64(&adisc->adisc_wwpn) != rdata->ids.port_name ||
|
|
|
|
get_unaligned_be64(&adisc->adisc_wwnn) != rdata->ids.node_name) {
|
|
|
|
FC_RPORT_DBG(rdata, "ADISC error or mismatch\n");
|
2010-07-21 06:20:08 +08:00
|
|
|
fc_rport_enter_flogi(rdata);
|
2009-08-26 05:03:47 +08:00
|
|
|
} else {
|
|
|
|
FC_RPORT_DBG(rdata, "ADISC OK\n");
|
|
|
|
fc_rport_enter_ready(rdata);
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
fc_frame_free(fp);
|
|
|
|
err:
|
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
|
|
|
kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-11-04 03:47:39 +08:00
|
|
|
* fc_rport_enter_adisc() - Send Address Discover (ADISC) request
|
|
|
|
* @rdata: The remote port to send the ADISC request to
|
2009-08-26 05:03:47 +08:00
|
|
|
*
|
|
|
|
* Locking Note: The rport lock is expected to be held before calling
|
|
|
|
* this routine.
|
|
|
|
*/
|
|
|
|
static void fc_rport_enter_adisc(struct fc_rport_priv *rdata)
|
|
|
|
{
|
|
|
|
struct fc_lport *lport = rdata->local_port;
|
|
|
|
struct fc_frame *fp;
|
|
|
|
|
|
|
|
FC_RPORT_DBG(rdata, "sending ADISC from %s state\n",
|
|
|
|
fc_rport_state(rdata));
|
|
|
|
|
|
|
|
fc_rport_state_enter(rdata, RPORT_ST_ADISC);
|
|
|
|
|
|
|
|
fp = fc_frame_alloc(lport, sizeof(struct fc_els_adisc));
|
|
|
|
if (!fp) {
|
|
|
|
fc_rport_error_retry(rdata, fp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_ADISC,
|
2009-11-04 03:50:21 +08:00
|
|
|
fc_rport_adisc_resp, rdata,
|
|
|
|
2 * lport->r_a_tov))
|
2009-10-22 07:28:09 +08:00
|
|
|
fc_rport_error_retry(rdata, NULL);
|
2009-08-26 05:03:47 +08:00
|
|
|
else
|
|
|
|
kref_get(&rdata->kref);
|
|
|
|
}
|
|
|
|
|
2009-08-26 05:03:52 +08:00
|
|
|
/**
|
2009-11-04 03:47:39 +08:00
|
|
|
* fc_rport_recv_adisc_req() - Handler for Address Discovery (ADISC) requests
|
|
|
|
* @rdata: The remote port that sent the ADISC request
|
|
|
|
* @in_fp: The ADISC request frame
|
2009-08-26 05:03:52 +08:00
|
|
|
*
|
|
|
|
* Locking Note: Called with the lport and rport locks held.
|
|
|
|
*/
|
|
|
|
static void fc_rport_recv_adisc_req(struct fc_rport_priv *rdata,
|
2010-07-21 06:21:12 +08:00
|
|
|
struct fc_frame *in_fp)
|
2009-08-26 05:03:52 +08:00
|
|
|
{
|
|
|
|
struct fc_lport *lport = rdata->local_port;
|
|
|
|
struct fc_frame *fp;
|
|
|
|
struct fc_els_adisc *adisc;
|
|
|
|
struct fc_seq_els_data rjt_data;
|
|
|
|
|
|
|
|
FC_RPORT_DBG(rdata, "Received ADISC request\n");
|
|
|
|
|
|
|
|
adisc = fc_frame_payload_get(in_fp, sizeof(*adisc));
|
|
|
|
if (!adisc) {
|
|
|
|
rjt_data.reason = ELS_RJT_PROT;
|
|
|
|
rjt_data.explan = ELS_EXPL_INV_LEN;
|
2010-07-21 06:21:12 +08:00
|
|
|
lport->tt.seq_els_rsp_send(in_fp, ELS_LS_RJT, &rjt_data);
|
2009-08-26 05:03:52 +08:00
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
|
|
|
|
fp = fc_frame_alloc(lport, sizeof(*adisc));
|
|
|
|
if (!fp)
|
|
|
|
goto drop;
|
|
|
|
fc_adisc_fill(lport, fp);
|
|
|
|
adisc = fc_frame_payload_get(fp, sizeof(*adisc));
|
|
|
|
adisc->adisc_cmd = ELS_LS_ACC;
|
2010-07-21 06:21:01 +08:00
|
|
|
fc_fill_reply_hdr(fp, in_fp, FC_RCTL_ELS_REP, 0);
|
|
|
|
lport->tt.frame_send(lport, fp);
|
2009-08-26 05:03:52 +08:00
|
|
|
drop:
|
|
|
|
fc_frame_free(in_fp);
|
|
|
|
}
|
|
|
|
|
2009-11-21 06:55:24 +08:00
|
|
|
/**
|
|
|
|
* fc_rport_recv_rls_req() - Handle received Read Link Status request
|
|
|
|
* @rdata: The remote port that sent the RLS request
|
|
|
|
* @rx_fp: The PRLI request frame
|
|
|
|
*
|
|
|
|
* Locking Note: The rport lock is expected to be held before calling
|
|
|
|
* this function.
|
|
|
|
*/
|
|
|
|
static void fc_rport_recv_rls_req(struct fc_rport_priv *rdata,
|
2010-07-21 06:21:12 +08:00
|
|
|
struct fc_frame *rx_fp)
|
2009-11-21 06:55:24 +08:00
|
|
|
|
|
|
|
{
|
|
|
|
struct fc_lport *lport = rdata->local_port;
|
|
|
|
struct fc_frame *fp;
|
|
|
|
struct fc_els_rls *rls;
|
|
|
|
struct fc_els_rls_resp *rsp;
|
|
|
|
struct fc_els_lesb *lesb;
|
|
|
|
struct fc_seq_els_data rjt_data;
|
|
|
|
struct fc_host_statistics *hst;
|
|
|
|
|
|
|
|
FC_RPORT_DBG(rdata, "Received RLS request while in state %s\n",
|
|
|
|
fc_rport_state(rdata));
|
|
|
|
|
|
|
|
rls = fc_frame_payload_get(rx_fp, sizeof(*rls));
|
|
|
|
if (!rls) {
|
|
|
|
rjt_data.reason = ELS_RJT_PROT;
|
|
|
|
rjt_data.explan = ELS_EXPL_INV_LEN;
|
|
|
|
goto out_rjt;
|
|
|
|
}
|
|
|
|
|
|
|
|
fp = fc_frame_alloc(lport, sizeof(*rsp));
|
|
|
|
if (!fp) {
|
|
|
|
rjt_data.reason = ELS_RJT_UNAB;
|
|
|
|
rjt_data.explan = ELS_EXPL_INSUF_RES;
|
|
|
|
goto out_rjt;
|
|
|
|
}
|
|
|
|
|
|
|
|
rsp = fc_frame_payload_get(fp, sizeof(*rsp));
|
|
|
|
memset(rsp, 0, sizeof(*rsp));
|
|
|
|
rsp->rls_cmd = ELS_LS_ACC;
|
|
|
|
lesb = &rsp->rls_lesb;
|
|
|
|
if (lport->tt.get_lesb) {
|
|
|
|
/* get LESB from LLD if it supports it */
|
|
|
|
lport->tt.get_lesb(lport, lesb);
|
|
|
|
} else {
|
|
|
|
fc_get_host_stats(lport->host);
|
|
|
|
hst = &lport->host_stats;
|
|
|
|
lesb->lesb_link_fail = htonl(hst->link_failure_count);
|
|
|
|
lesb->lesb_sync_loss = htonl(hst->loss_of_sync_count);
|
|
|
|
lesb->lesb_sig_loss = htonl(hst->loss_of_signal_count);
|
|
|
|
lesb->lesb_prim_err = htonl(hst->prim_seq_protocol_err_count);
|
|
|
|
lesb->lesb_inv_word = htonl(hst->invalid_tx_word_count);
|
|
|
|
lesb->lesb_inv_crc = htonl(hst->invalid_crc_count);
|
|
|
|
}
|
|
|
|
|
2010-07-21 06:21:01 +08:00
|
|
|
fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
|
|
|
|
lport->tt.frame_send(lport, fp);
|
2009-11-21 06:55:24 +08:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
out_rjt:
|
2010-07-21 06:21:12 +08:00
|
|
|
lport->tt.seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
|
2009-11-21 06:55:24 +08:00
|
|
|
out:
|
|
|
|
fc_frame_free(rx_fp);
|
|
|
|
}
|
|
|
|
|
2008-12-10 07:10:17 +08:00
|
|
|
/**
|
2009-11-04 03:47:39 +08:00
|
|
|
* fc_rport_recv_els_req() - Handler for validated ELS requests
|
|
|
|
* @lport: The local port that received the ELS request
|
|
|
|
* @fp: The ELS request frame
|
2009-08-26 05:03:31 +08:00
|
|
|
*
|
|
|
|
* Handle incoming ELS requests that require port login.
|
|
|
|
* The ELS opcode has already been validated by the caller.
|
2008-12-10 07:10:17 +08:00
|
|
|
*
|
2009-08-26 05:03:10 +08:00
|
|
|
* Locking Note: Called with the lport lock held.
|
2008-12-10 07:10:17 +08:00
|
|
|
*/
|
2010-07-21 06:21:12 +08:00
|
|
|
static void fc_rport_recv_els_req(struct fc_lport *lport, struct fc_frame *fp)
|
2008-12-10 07:10:17 +08:00
|
|
|
{
|
2009-08-26 05:03:10 +08:00
|
|
|
struct fc_rport_priv *rdata;
|
2008-12-10 07:10:17 +08:00
|
|
|
struct fc_seq_els_data els_data;
|
|
|
|
|
2009-08-26 05:03:15 +08:00
|
|
|
mutex_lock(&lport->disc.disc_mutex);
|
2010-07-21 06:20:56 +08:00
|
|
|
rdata = lport->tt.rport_lookup(lport, fc_frame_sid(fp));
|
2009-08-26 05:03:10 +08:00
|
|
|
if (!rdata) {
|
2009-08-26 05:03:15 +08:00
|
|
|
mutex_unlock(&lport->disc.disc_mutex);
|
2009-08-26 05:03:31 +08:00
|
|
|
goto reject;
|
2009-08-26 05:03:10 +08:00
|
|
|
}
|
|
|
|
mutex_lock(&rdata->rp_mutex);
|
2009-08-26 05:03:15 +08:00
|
|
|
mutex_unlock(&lport->disc.disc_mutex);
|
2009-08-26 05:03:10 +08:00
|
|
|
|
2009-08-26 05:03:31 +08:00
|
|
|
switch (rdata->rp_state) {
|
|
|
|
case RPORT_ST_PRLI:
|
|
|
|
case RPORT_ST_RTV:
|
|
|
|
case RPORT_ST_READY:
|
2009-08-26 05:03:47 +08:00
|
|
|
case RPORT_ST_ADISC:
|
2009-08-26 05:03:31 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
|
|
|
goto reject;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (fc_frame_payload_op(fp)) {
|
2009-08-26 05:03:10 +08:00
|
|
|
case ELS_PRLI:
|
2010-07-21 06:21:12 +08:00
|
|
|
fc_rport_recv_prli_req(rdata, fp);
|
2009-08-26 05:03:10 +08:00
|
|
|
break;
|
|
|
|
case ELS_PRLO:
|
2010-07-21 06:21:12 +08:00
|
|
|
fc_rport_recv_prlo_req(rdata, fp);
|
2009-08-26 05:03:10 +08:00
|
|
|
break;
|
2009-08-26 05:03:52 +08:00
|
|
|
case ELS_ADISC:
|
2010-07-21 06:21:12 +08:00
|
|
|
fc_rport_recv_adisc_req(rdata, fp);
|
2009-08-26 05:03:52 +08:00
|
|
|
break;
|
2009-08-26 05:03:10 +08:00
|
|
|
case ELS_RRQ:
|
2010-07-21 06:21:12 +08:00
|
|
|
lport->tt.seq_els_rsp_send(fp, ELS_RRQ, NULL);
|
|
|
|
fc_frame_free(fp);
|
2009-08-26 05:03:10 +08:00
|
|
|
break;
|
|
|
|
case ELS_REC:
|
2010-07-21 06:21:12 +08:00
|
|
|
lport->tt.seq_els_rsp_send(fp, ELS_REC, NULL);
|
|
|
|
fc_frame_free(fp);
|
2009-08-26 05:03:10 +08:00
|
|
|
break;
|
2009-11-21 06:55:24 +08:00
|
|
|
case ELS_RLS:
|
2010-07-21 06:21:12 +08:00
|
|
|
fc_rport_recv_rls_req(rdata, fp);
|
2009-11-21 06:55:24 +08:00
|
|
|
break;
|
2009-08-26 05:03:10 +08:00
|
|
|
default:
|
2009-08-26 05:03:31 +08:00
|
|
|
fc_frame_free(fp); /* can't happen */
|
2009-08-26 05:03:10 +08:00
|
|
|
break;
|
2008-12-10 07:10:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
2009-08-26 05:03:31 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
reject:
|
2010-07-21 06:21:12 +08:00
|
|
|
els_data.reason = ELS_RJT_UNAB;
|
|
|
|
els_data.explan = ELS_EXPL_PLOGI_REQD;
|
|
|
|
lport->tt.seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
|
2009-08-26 05:03:31 +08:00
|
|
|
fc_frame_free(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-11-04 03:47:39 +08:00
|
|
|
* fc_rport_recv_req() - Handler for requests
|
|
|
|
* @lport: The local port that received the request
|
2010-07-21 06:21:12 +08:00
|
|
|
* @fp: The request frame
|
2009-08-26 05:03:31 +08:00
|
|
|
*
|
|
|
|
* Locking Note: Called with the lport lock held.
|
|
|
|
*/
|
2012-01-14 09:26:20 +08:00
|
|
|
static void fc_rport_recv_req(struct fc_lport *lport, struct fc_frame *fp)
|
2009-08-26 05:03:31 +08:00
|
|
|
{
|
|
|
|
struct fc_seq_els_data els_data;
|
|
|
|
|
|
|
|
/*
|
2010-07-21 06:20:08 +08:00
|
|
|
* Handle FLOGI, PLOGI and LOGO requests separately, since they
|
2009-08-26 05:03:31 +08:00
|
|
|
* don't require prior login.
|
|
|
|
* Check for unsupported opcodes first and reject them.
|
|
|
|
* For some ops, it would be incorrect to reject with "PLOGI required".
|
|
|
|
*/
|
|
|
|
switch (fc_frame_payload_op(fp)) {
|
2010-07-21 06:20:08 +08:00
|
|
|
case ELS_FLOGI:
|
2010-07-21 06:21:12 +08:00
|
|
|
fc_rport_recv_flogi_req(lport, fp);
|
2010-07-21 06:20:08 +08:00
|
|
|
break;
|
2009-08-26 05:03:31 +08:00
|
|
|
case ELS_PLOGI:
|
2010-07-21 06:21:12 +08:00
|
|
|
fc_rport_recv_plogi_req(lport, fp);
|
2009-08-26 05:03:31 +08:00
|
|
|
break;
|
|
|
|
case ELS_LOGO:
|
2010-07-21 06:21:12 +08:00
|
|
|
fc_rport_recv_logo_req(lport, fp);
|
2009-08-26 05:03:31 +08:00
|
|
|
break;
|
|
|
|
case ELS_PRLI:
|
|
|
|
case ELS_PRLO:
|
2009-08-26 05:03:52 +08:00
|
|
|
case ELS_ADISC:
|
2009-08-26 05:03:31 +08:00
|
|
|
case ELS_RRQ:
|
|
|
|
case ELS_REC:
|
2009-11-21 06:55:24 +08:00
|
|
|
case ELS_RLS:
|
2010-07-21 06:21:12 +08:00
|
|
|
fc_rport_recv_els_req(lport, fp);
|
2009-08-26 05:03:31 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
els_data.reason = ELS_RJT_UNSUP;
|
|
|
|
els_data.explan = ELS_EXPL_NONE;
|
2010-07-21 06:21:12 +08:00
|
|
|
lport->tt.seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
|
|
|
|
fc_frame_free(fp);
|
2009-08-26 05:03:31 +08:00
|
|
|
break;
|
|
|
|
}
|
2008-12-10 07:10:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-11-04 03:47:39 +08:00
|
|
|
* fc_rport_recv_plogi_req() - Handler for Port Login (PLOGI) requests
|
|
|
|
* @lport: The local port that received the PLOGI request
|
|
|
|
* @rx_fp: The PLOGI request frame
|
2008-12-10 07:10:17 +08:00
|
|
|
*
|
2009-08-26 05:03:26 +08:00
|
|
|
* Locking Note: The rport lock is held before calling this function.
|
2008-12-10 07:10:17 +08:00
|
|
|
*/
|
2009-08-26 05:03:26 +08:00
|
|
|
static void fc_rport_recv_plogi_req(struct fc_lport *lport,
|
2010-07-21 06:21:12 +08:00
|
|
|
struct fc_frame *rx_fp)
|
2008-12-10 07:10:17 +08:00
|
|
|
{
|
2009-08-26 05:03:26 +08:00
|
|
|
struct fc_disc *disc;
|
|
|
|
struct fc_rport_priv *rdata;
|
2008-12-10 07:10:17 +08:00
|
|
|
struct fc_frame *fp = rx_fp;
|
|
|
|
struct fc_els_flogi *pl;
|
|
|
|
struct fc_seq_els_data rjt_data;
|
2010-07-21 06:21:01 +08:00
|
|
|
u32 sid;
|
2008-12-10 07:10:17 +08:00
|
|
|
|
2010-07-21 06:20:56 +08:00
|
|
|
sid = fc_frame_sid(fp);
|
2008-12-10 07:10:17 +08:00
|
|
|
|
2009-08-26 05:03:26 +08:00
|
|
|
FC_RPORT_ID_DBG(lport, sid, "Received PLOGI request\n");
|
2008-12-10 07:10:17 +08:00
|
|
|
|
|
|
|
pl = fc_frame_payload_get(fp, sizeof(*pl));
|
|
|
|
if (!pl) {
|
2009-08-26 05:03:26 +08:00
|
|
|
FC_RPORT_ID_DBG(lport, sid, "Received PLOGI too short\n");
|
|
|
|
rjt_data.reason = ELS_RJT_PROT;
|
|
|
|
rjt_data.explan = ELS_EXPL_INV_LEN;
|
|
|
|
goto reject;
|
2008-12-10 07:10:17 +08:00
|
|
|
}
|
2009-08-26 05:03:26 +08:00
|
|
|
|
|
|
|
disc = &lport->disc;
|
|
|
|
mutex_lock(&disc->disc_mutex);
|
|
|
|
rdata = lport->tt.rport_create(lport, sid);
|
|
|
|
if (!rdata) {
|
|
|
|
mutex_unlock(&disc->disc_mutex);
|
|
|
|
rjt_data.reason = ELS_RJT_UNAB;
|
|
|
|
rjt_data.explan = ELS_EXPL_INSUF_RES;
|
|
|
|
goto reject;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_lock(&rdata->rp_mutex);
|
|
|
|
mutex_unlock(&disc->disc_mutex);
|
|
|
|
|
|
|
|
rdata->ids.port_name = get_unaligned_be64(&pl->fl_wwpn);
|
|
|
|
rdata->ids.node_name = get_unaligned_be64(&pl->fl_wwnn);
|
2008-12-10 07:10:17 +08:00
|
|
|
|
|
|
|
/*
|
2009-08-26 05:03:26 +08:00
|
|
|
* If the rport was just created, possibly due to the incoming PLOGI,
|
2008-12-10 07:10:17 +08:00
|
|
|
* 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:03:26 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Received PLOGI in INIT state\n");
|
2008-12-10 07:10:17 +08:00
|
|
|
break;
|
2010-07-21 06:20:08 +08:00
|
|
|
case RPORT_ST_PLOGI_WAIT:
|
|
|
|
FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI_WAIT state\n");
|
|
|
|
break;
|
2008-12-10 07:10:17 +08:00
|
|
|
case RPORT_ST_PLOGI:
|
2009-08-26 05:03:26 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI state\n");
|
|
|
|
if (rdata->ids.port_name < lport->wwpn) {
|
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
|
|
|
rjt_data.reason = ELS_RJT_INPROG;
|
|
|
|
rjt_data.explan = ELS_EXPL_NONE;
|
|
|
|
goto reject;
|
|
|
|
}
|
2008-12-10 07:10:17 +08:00
|
|
|
break;
|
|
|
|
case RPORT_ST_PRLI:
|
[SCSI] libfc: fix free of fc_rport_priv with timer pending
Timer crashes were caused by freeing a struct fc_rport_priv
with a timer pending, causing the timer facility list to be
corrupted. This was during FC uplink flap tests with a lot
of targets.
After discovery, we were doing an PLOGI on an rdata that was
in DELETE state but not yet removed from the lookup list.
This moved the rdata from DELETE state to PLOGI state.
If the PLOGI exchange allocation failed and needed to be
retried, the timer scheduling could race with the free
being done by fc_rport_work().
When fc_rport_login() is called on a rport in DELETE state,
move it to a new state RESTART. In fc_rport_work, when
handling a LOGO, STOPPED or FAILED event, look for restart
state. In the RESTART case, don't take the rdata off the
list and after the transport remote port is deleted and
exchanges are reset, re-login to the remote port.
Note that the new RESTART state also corrects a problem we
had when re-discovering a port that had moved to DELETE state.
In that case, a new rdata was created, but the old rdata
would do an exchange manager reset affecting the FC_ID
for both the new rdata and old rdata. With the new state,
the new port isn't logged into until after any old exchanges
are reset.
Signed-off-by: Joe Eykholt <jeykholt@cisco.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
2009-10-22 07:28:30 +08:00
|
|
|
case RPORT_ST_RTV:
|
2008-12-10 07:10:17 +08:00
|
|
|
case RPORT_ST_READY:
|
2009-08-26 05:03:47 +08:00
|
|
|
case RPORT_ST_ADISC:
|
|
|
|
FC_RPORT_DBG(rdata, "Received PLOGI in logged-in state %d "
|
|
|
|
"- ignored for now\n", rdata->rp_state);
|
|
|
|
/* XXX TBD - should reset */
|
2008-12-10 07:10:17 +08:00
|
|
|
break;
|
2010-07-21 06:20:08 +08:00
|
|
|
case RPORT_ST_FLOGI:
|
2009-07-30 08:04:43 +08:00
|
|
|
case RPORT_ST_DELETE:
|
[SCSI] libfc: fix free of fc_rport_priv with timer pending
Timer crashes were caused by freeing a struct fc_rport_priv
with a timer pending, causing the timer facility list to be
corrupted. This was during FC uplink flap tests with a lot
of targets.
After discovery, we were doing an PLOGI on an rdata that was
in DELETE state but not yet removed from the lookup list.
This moved the rdata from DELETE state to PLOGI state.
If the PLOGI exchange allocation failed and needed to be
retried, the timer scheduling could race with the free
being done by fc_rport_work().
When fc_rport_login() is called on a rport in DELETE state,
move it to a new state RESTART. In fc_rport_work, when
handling a LOGO, STOPPED or FAILED event, look for restart
state. In the RESTART case, don't take the rdata off the
list and after the transport remote port is deleted and
exchanges are reset, re-login to the remote port.
Note that the new RESTART state also corrects a problem we
had when re-discovering a port that had moved to DELETE state.
In that case, a new rdata was created, but the old rdata
would do an exchange manager reset affecting the FC_ID
for both the new rdata and old rdata. With the new state,
the new port isn't logged into until after any old exchanges
are reset.
Signed-off-by: Joe Eykholt <jeykholt@cisco.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
2009-10-22 07:28:30 +08:00
|
|
|
FC_RPORT_DBG(rdata, "Received PLOGI in state %s - send busy\n",
|
|
|
|
fc_rport_state(rdata));
|
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
|
|
|
rjt_data.reason = ELS_RJT_BUSY;
|
|
|
|
rjt_data.explan = ELS_EXPL_NONE;
|
|
|
|
goto reject;
|
2008-12-10 07:10:17 +08:00
|
|
|
}
|
|
|
|
|
2009-08-26 05:03:26 +08:00
|
|
|
/*
|
|
|
|
* Get session payload size from incoming PLOGI.
|
|
|
|
*/
|
|
|
|
rdata->maxframe_size = fc_plogi_get_maxframe(pl, lport->mfs);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send LS_ACC. If this fails, the originator should retry.
|
|
|
|
*/
|
|
|
|
fp = fc_frame_alloc(lport, sizeof(*pl));
|
|
|
|
if (!fp)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
fc_plogi_fill(lport, fp, ELS_LS_ACC);
|
2010-07-21 06:21:01 +08:00
|
|
|
fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
|
|
|
|
lport->tt.frame_send(lport, fp);
|
2009-08-26 05:03:26 +08:00
|
|
|
fc_rport_enter_prli(rdata);
|
|
|
|
out:
|
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
2010-07-21 06:21:01 +08:00
|
|
|
fc_frame_free(rx_fp);
|
2009-08-26 05:03:26 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
reject:
|
2010-07-21 06:21:12 +08:00
|
|
|
lport->tt.seq_els_rsp_send(fp, ELS_LS_RJT, &rjt_data);
|
2009-08-26 05:03:26 +08:00
|
|
|
fc_frame_free(fp);
|
2008-12-10 07:10:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-11-04 03:47:39 +08:00
|
|
|
* fc_rport_recv_prli_req() - Handler for process login (PRLI) requests
|
|
|
|
* @rdata: The remote port that sent the PRLI request
|
|
|
|
* @rx_fp: The PRLI request frame
|
2008-12-10 07:10:17 +08:00
|
|
|
*
|
|
|
|
* 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,
|
2010-07-21 06:21:12 +08:00
|
|
|
struct fc_frame *rx_fp)
|
2008-12-10 07:10:17 +08:00
|
|
|
{
|
|
|
|
struct fc_lport *lport = rdata->local_port;
|
|
|
|
struct fc_frame *fp;
|
|
|
|
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_spp_resp resp;
|
2011-01-29 08:04:02 +08:00
|
|
|
enum fc_els_spp_resp passive;
|
2008-12-10 07:10:17 +08:00
|
|
|
struct fc_seq_els_data rjt_data;
|
2011-01-29 08:04:02 +08:00
|
|
|
struct fc4_prov *prov;
|
2008-12-10 07:10:17 +08:00
|
|
|
|
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
|
|
|
|
2010-07-21 06:20:56 +08:00
|
|
|
len = fr_len(rx_fp) - sizeof(struct fc_frame_header);
|
2008-12-10 07:10:17 +08:00
|
|
|
pp = fc_frame_payload_get(rx_fp, sizeof(*pp));
|
2010-03-13 08:07:36 +08:00
|
|
|
if (!pp)
|
|
|
|
goto reject_len;
|
|
|
|
plen = ntohs(pp->prli.prli_len);
|
|
|
|
if ((plen % 4) != 0 || plen > len || plen < 16)
|
|
|
|
goto reject_len;
|
|
|
|
if (plen < len)
|
|
|
|
len = plen;
|
|
|
|
plen = pp->prli.prli_spp_len;
|
|
|
|
if ((plen % 4) != 0 || plen < sizeof(*spp) ||
|
|
|
|
plen > len || len < sizeof(*pp) || plen < 12)
|
|
|
|
goto reject_len;
|
|
|
|
rspp = &pp->spp;
|
|
|
|
|
|
|
|
fp = fc_frame_alloc(lport, len);
|
|
|
|
if (!fp) {
|
|
|
|
rjt_data.reason = ELS_RJT_UNAB;
|
|
|
|
rjt_data.explan = ELS_EXPL_INSUF_RES;
|
|
|
|
goto reject;
|
2008-12-10 07:10:17 +08:00
|
|
|
}
|
2010-03-13 08:07:36 +08:00
|
|
|
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);
|
2008-12-10 07:10:17 +08:00
|
|
|
|
2010-03-13 08:07:36 +08:00
|
|
|
/*
|
|
|
|
* 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;
|
2011-01-29 08:04:02 +08:00
|
|
|
mutex_lock(&fc_prov_mutex);
|
2010-03-13 08:07:36 +08:00
|
|
|
while (len >= plen) {
|
2011-01-29 08:05:27 +08:00
|
|
|
rdata->spp_type = rspp->spp_type;
|
2010-03-13 08:07:36 +08:00
|
|
|
spp->spp_type = rspp->spp_type;
|
|
|
|
spp->spp_type_ext = rspp->spp_type_ext;
|
2011-01-29 08:04:02 +08:00
|
|
|
resp = 0;
|
|
|
|
|
|
|
|
if (rspp->spp_type < FC_FC4_PROV_SIZE) {
|
|
|
|
prov = fc_active_prov[rspp->spp_type];
|
|
|
|
if (prov)
|
|
|
|
resp = prov->prli(rdata, plen, rspp, spp);
|
|
|
|
prov = fc_passive_prov[rspp->spp_type];
|
|
|
|
if (prov) {
|
|
|
|
passive = prov->prli(rdata, plen, rspp, spp);
|
|
|
|
if (!resp || passive == FC_SPP_RESP_ACK)
|
|
|
|
resp = passive;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!resp) {
|
|
|
|
if (spp->spp_flags & FC_SPP_EST_IMG_PAIR)
|
|
|
|
resp |= FC_SPP_RESP_CONF;
|
|
|
|
else
|
|
|
|
resp |= FC_SPP_RESP_INVL;
|
2008-12-10 07:10:17 +08:00
|
|
|
}
|
2010-03-13 08:07:36 +08:00
|
|
|
spp->spp_flags |= resp;
|
|
|
|
len -= plen;
|
|
|
|
rspp = (struct fc_els_spp *)((char *)rspp + plen);
|
|
|
|
spp = (struct fc_els_spp *)((char *)spp + plen);
|
|
|
|
}
|
2011-01-29 08:04:02 +08:00
|
|
|
mutex_unlock(&fc_prov_mutex);
|
2010-03-13 08:07:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Send LS_ACC. If this fails, the originator should retry.
|
|
|
|
*/
|
2010-07-21 06:21:01 +08:00
|
|
|
fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
|
|
|
|
lport->tt.frame_send(lport, fp);
|
2010-03-13 08:07:36 +08:00
|
|
|
|
|
|
|
switch (rdata->rp_state) {
|
|
|
|
case RPORT_ST_PRLI:
|
|
|
|
fc_rport_enter_ready(rdata);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2008-12-10 07:10:17 +08:00
|
|
|
}
|
2010-03-13 08:07:36 +08:00
|
|
|
goto drop;
|
|
|
|
|
|
|
|
reject_len:
|
|
|
|
rjt_data.reason = ELS_RJT_PROT;
|
|
|
|
rjt_data.explan = ELS_EXPL_INV_LEN;
|
|
|
|
reject:
|
2010-07-21 06:21:12 +08:00
|
|
|
lport->tt.seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
|
2010-03-13 08:07:36 +08:00
|
|
|
drop:
|
2008-12-10 07:10:17 +08:00
|
|
|
fc_frame_free(rx_fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-11-04 03:47:39 +08:00
|
|
|
* fc_rport_recv_prlo_req() - Handler for process logout (PRLO) requests
|
|
|
|
* @rdata: The remote port that sent the PRLO request
|
2010-06-12 07:44:04 +08:00
|
|
|
* @rx_fp: The PRLO request frame
|
2008-12-10 07:10:17 +08:00
|
|
|
*
|
|
|
|
* 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,
|
2010-06-12 07:44:04 +08:00
|
|
|
struct fc_frame *rx_fp)
|
2008-12-10 07:10:17 +08:00
|
|
|
{
|
|
|
|
struct fc_lport *lport = rdata->local_port;
|
2010-06-12 07:44:04 +08:00
|
|
|
struct fc_frame *fp;
|
|
|
|
struct {
|
|
|
|
struct fc_els_prlo prlo;
|
|
|
|
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;
|
2008-12-10 07:10:17 +08:00
|
|
|
struct fc_seq_els_data rjt_data;
|
|
|
|
|
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
|
|
|
|
2010-07-21 06:20:56 +08:00
|
|
|
len = fr_len(rx_fp) - sizeof(struct fc_frame_header);
|
2010-06-12 07:44:04 +08:00
|
|
|
pp = fc_frame_payload_get(rx_fp, sizeof(*pp));
|
|
|
|
if (!pp)
|
|
|
|
goto reject_len;
|
|
|
|
plen = ntohs(pp->prlo.prlo_len);
|
|
|
|
if (plen != 20)
|
|
|
|
goto reject_len;
|
|
|
|
if (plen < len)
|
|
|
|
len = plen;
|
|
|
|
|
|
|
|
rspp = &pp->spp;
|
|
|
|
|
|
|
|
fp = fc_frame_alloc(lport, len);
|
|
|
|
if (!fp) {
|
|
|
|
rjt_data.reason = ELS_RJT_UNAB;
|
|
|
|
rjt_data.explan = ELS_EXPL_INSUF_RES;
|
|
|
|
goto reject;
|
|
|
|
}
|
|
|
|
|
|
|
|
pp = fc_frame_payload_get(fp, len);
|
|
|
|
WARN_ON(!pp);
|
|
|
|
memset(pp, 0, len);
|
|
|
|
pp->prlo.prlo_cmd = ELS_LS_ACC;
|
|
|
|
pp->prlo.prlo_obs = 0x10;
|
|
|
|
pp->prlo.prlo_len = htons(len);
|
|
|
|
spp = &pp->spp;
|
|
|
|
spp->spp_type = rspp->spp_type;
|
|
|
|
spp->spp_type_ext = rspp->spp_type_ext;
|
|
|
|
spp->spp_flags = FC_SPP_RESP_ACK;
|
|
|
|
|
|
|
|
fc_rport_enter_delete(rdata, RPORT_EV_LOGO);
|
|
|
|
|
2010-07-21 06:21:12 +08:00
|
|
|
fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
|
|
|
|
lport->tt.frame_send(lport, fp);
|
2010-06-12 07:44:04 +08:00
|
|
|
goto drop;
|
|
|
|
|
|
|
|
reject_len:
|
|
|
|
rjt_data.reason = ELS_RJT_PROT;
|
|
|
|
rjt_data.explan = ELS_EXPL_INV_LEN;
|
|
|
|
reject:
|
2010-07-21 06:21:12 +08:00
|
|
|
lport->tt.seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
|
2010-06-12 07:44:04 +08:00
|
|
|
drop:
|
|
|
|
fc_frame_free(rx_fp);
|
2008-12-10 07:10:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-11-04 03:47:39 +08:00
|
|
|
* fc_rport_recv_logo_req() - Handler for logout (LOGO) requests
|
|
|
|
* @lport: The local port that received the LOGO request
|
|
|
|
* @fp: The LOGO request frame
|
2008-12-10 07:10:17 +08:00
|
|
|
*
|
|
|
|
* Locking Note: The rport lock is exected to be held before calling
|
|
|
|
* this function.
|
|
|
|
*/
|
2010-07-21 06:21:12 +08:00
|
|
|
static void fc_rport_recv_logo_req(struct fc_lport *lport, struct fc_frame *fp)
|
2008-12-10 07:10:17 +08:00
|
|
|
{
|
2009-08-26 05:03:31 +08:00
|
|
|
struct fc_rport_priv *rdata;
|
|
|
|
u32 sid;
|
2008-12-10 07:10:17 +08:00
|
|
|
|
2010-07-21 06:21:12 +08:00
|
|
|
lport->tt.seq_els_rsp_send(fp, ELS_LS_ACC, NULL);
|
2009-08-26 05:03:36 +08:00
|
|
|
|
2010-07-21 06:20:56 +08:00
|
|
|
sid = fc_frame_sid(fp);
|
2008-12-10 07:10:17 +08:00
|
|
|
|
2009-08-26 05:03:31 +08:00
|
|
|
mutex_lock(&lport->disc.disc_mutex);
|
|
|
|
rdata = lport->tt.rport_lookup(lport, sid);
|
|
|
|
if (rdata) {
|
|
|
|
mutex_lock(&rdata->rp_mutex);
|
|
|
|
FC_RPORT_DBG(rdata, "Received LOGO request while in state %s\n",
|
|
|
|
fc_rport_state(rdata));
|
2009-08-26 05:03:36 +08:00
|
|
|
|
[SCSI] libfc: fix free of fc_rport_priv with timer pending
Timer crashes were caused by freeing a struct fc_rport_priv
with a timer pending, causing the timer facility list to be
corrupted. This was during FC uplink flap tests with a lot
of targets.
After discovery, we were doing an PLOGI on an rdata that was
in DELETE state but not yet removed from the lookup list.
This moved the rdata from DELETE state to PLOGI state.
If the PLOGI exchange allocation failed and needed to be
retried, the timer scheduling could race with the free
being done by fc_rport_work().
When fc_rport_login() is called on a rport in DELETE state,
move it to a new state RESTART. In fc_rport_work, when
handling a LOGO, STOPPED or FAILED event, look for restart
state. In the RESTART case, don't take the rdata off the
list and after the transport remote port is deleted and
exchanges are reset, re-login to the remote port.
Note that the new RESTART state also corrects a problem we
had when re-discovering a port that had moved to DELETE state.
In that case, a new rdata was created, but the old rdata
would do an exchange manager reset affecting the FC_ID
for both the new rdata and old rdata. With the new state,
the new port isn't logged into until after any old exchanges
are reset.
Signed-off-by: Joe Eykholt <jeykholt@cisco.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
2009-10-22 07:28:30 +08:00
|
|
|
fc_rport_enter_delete(rdata, RPORT_EV_LOGO);
|
2009-08-26 05:03:31 +08:00
|
|
|
mutex_unlock(&rdata->rp_mutex);
|
|
|
|
} else
|
|
|
|
FC_RPORT_ID_DBG(lport, sid,
|
|
|
|
"Received LOGO from non-logged-in port\n");
|
|
|
|
mutex_unlock(&lport->disc.disc_mutex);
|
2008-12-10 07:10:17 +08:00
|
|
|
fc_frame_free(fp);
|
|
|
|
}
|
|
|
|
|
2009-11-04 03:47:39 +08:00
|
|
|
/**
|
|
|
|
* fc_rport_flush_queue() - Flush the rport_event_queue
|
|
|
|
*/
|
2008-12-10 07:10:17 +08:00
|
|
|
static void fc_rport_flush_queue(void)
|
|
|
|
{
|
|
|
|
flush_workqueue(rport_event_queue);
|
|
|
|
}
|
|
|
|
|
2009-11-04 03:47:39 +08:00
|
|
|
/**
|
|
|
|
* fc_rport_init() - Initialize the remote port layer for a local port
|
|
|
|
* @lport: The local port to initialize the remote port layer for
|
|
|
|
*/
|
2008-12-10 07:10:17 +08:00
|
|
|
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);
|
|
|
|
|
2011-01-29 08:04:02 +08:00
|
|
|
/**
|
|
|
|
* fc_rport_fcp_prli() - Handle incoming PRLI for the FCP initiator.
|
|
|
|
* @rdata: remote port private
|
|
|
|
* @spp_len: service parameter page length
|
|
|
|
* @rspp: received service parameter page
|
|
|
|
* @spp: response service parameter page
|
|
|
|
*
|
|
|
|
* Returns the value for the response code to be placed in spp_flags;
|
|
|
|
* Returns 0 if not an initiator.
|
|
|
|
*/
|
|
|
|
static int fc_rport_fcp_prli(struct fc_rport_priv *rdata, u32 spp_len,
|
|
|
|
const struct fc_els_spp *rspp,
|
|
|
|
struct fc_els_spp *spp)
|
|
|
|
{
|
|
|
|
struct fc_lport *lport = rdata->local_port;
|
|
|
|
u32 fcp_parm;
|
|
|
|
|
|
|
|
fcp_parm = ntohl(rspp->spp_params);
|
|
|
|
rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
|
|
|
|
if (fcp_parm & FCP_SPPF_INIT_FCN)
|
|
|
|
rdata->ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
|
|
|
|
if (fcp_parm & FCP_SPPF_TARG_FCN)
|
|
|
|
rdata->ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
|
|
|
|
if (fcp_parm & FCP_SPPF_RETRY)
|
|
|
|
rdata->flags |= FC_RP_FLAGS_RETRY;
|
|
|
|
rdata->supported_classes = FC_COS_CLASS3;
|
|
|
|
|
2013-03-20 15:17:55 +08:00
|
|
|
if (!(lport->service_params & FCP_SPPF_INIT_FCN))
|
2011-01-29 08:04:02 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
spp->spp_flags |= rspp->spp_flags & FC_SPP_EST_IMG_PAIR;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* OR in our service parameters with other providers (target), if any.
|
|
|
|
*/
|
|
|
|
fcp_parm = ntohl(spp->spp_params);
|
|
|
|
spp->spp_params = htonl(fcp_parm | lport->service_params);
|
|
|
|
return FC_SPP_RESP_ACK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FC-4 provider ops for FCP initiator.
|
|
|
|
*/
|
|
|
|
struct fc4_prov fc_rport_fcp_init = {
|
|
|
|
.prli = fc_rport_fcp_prli,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* fc_rport_t0_prli() - Handle incoming PRLI parameters for type 0
|
|
|
|
* @rdata: remote port private
|
|
|
|
* @spp_len: service parameter page length
|
|
|
|
* @rspp: received service parameter page
|
|
|
|
* @spp: response service parameter page
|
|
|
|
*/
|
|
|
|
static int fc_rport_t0_prli(struct fc_rport_priv *rdata, u32 spp_len,
|
|
|
|
const struct fc_els_spp *rspp,
|
|
|
|
struct fc_els_spp *spp)
|
|
|
|
{
|
|
|
|
if (rspp->spp_flags & FC_SPP_EST_IMG_PAIR)
|
|
|
|
return FC_SPP_RESP_INVL;
|
|
|
|
return FC_SPP_RESP_ACK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FC-4 provider ops for type 0 service parameters.
|
|
|
|
*
|
|
|
|
* This handles the special case of type 0 which is always successful
|
|
|
|
* but doesn't do anything otherwise.
|
|
|
|
*/
|
|
|
|
struct fc4_prov fc_rport_t0_prov = {
|
|
|
|
.prli = fc_rport_t0_prli,
|
|
|
|
};
|
|
|
|
|
2009-11-04 03:47:39 +08:00
|
|
|
/**
|
|
|
|
* fc_setup_rport() - Initialize the rport_event_queue
|
|
|
|
*/
|
2011-01-29 08:03:57 +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;
|
|
|
|
}
|
|
|
|
|
2009-11-04 03:47:39 +08:00
|
|
|
/**
|
|
|
|
* fc_destroy_rport() - Destroy the rport_event_queue
|
|
|
|
*/
|
2011-01-29 08:03:57 +08:00
|
|
|
void fc_destroy_rport(void)
|
2008-12-10 07:10:17 +08:00
|
|
|
{
|
|
|
|
destroy_workqueue(rport_event_queue);
|
|
|
|
}
|
|
|
|
|
2009-11-04 03:47:39 +08:00
|
|
|
/**
|
|
|
|
* fc_rport_terminate_io() - Stop all outstanding I/O on a remote port
|
|
|
|
* @rport: The remote port whose I/O should be terminated
|
|
|
|
*/
|
2008-12-10 07:10:17 +08:00
|
|
|
void fc_rport_terminate_io(struct fc_rport *rport)
|
|
|
|
{
|
2009-11-04 03:47:39 +08:00
|
|
|
struct fc_rport_libfc_priv *rpriv = rport->dd_data;
|
|
|
|
struct fc_lport *lport = rpriv->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);
|