blob: 59b16bbb66a3b1f87cf72f3b5eefee4796a022dd [file] [log] [blame]
Robert Love42e9a922008-12-09 15:10:17 -08001/*
2 * Copyright(c) 2007 - 2008 Intel Corporation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
16 *
17 * Maintained at www.Open-FCoE.org
18 */
19
20/*
21 * RPORT GENERAL INFO
22 *
23 * This file contains all processing regarding fc_rports. It contains the
24 * rport state machine and does all rport interaction with the transport class.
25 * There should be no other places in libfc that interact directly with the
26 * transport class in regards to adding and deleting rports.
27 *
28 * fc_rport's represent N_Port's within the fabric.
29 */
30
31/*
32 * RPORT LOCKING
33 *
34 * The rport should never hold the rport mutex and then attempt to acquire
35 * either the lport or disc mutexes. The rport's mutex is considered lesser
36 * than both the lport's mutex and the disc mutex. Refer to fc_lport.c for
Uwe Kleine-König732bee72010-06-11 12:16:59 +020037 * more comments on the hierarchy.
Robert Love42e9a922008-12-09 15:10:17 -080038 *
39 * The locking strategy is similar to the lport's strategy. The lock protects
40 * the rport's states and is held and released by the entry points to the rport
41 * block. All _enter_* functions correspond to rport states and expect the rport
42 * mutex to be locked before calling them. This means that rports only handle
43 * one request or response at a time, since they're not critical for the I/O
44 * path this potential over-use of the mutex is acceptable.
45 */
46
47#include <linux/kernel.h>
48#include <linux/spinlock.h>
49#include <linux/interrupt.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090050#include <linux/slab.h>
Robert Love42e9a922008-12-09 15:10:17 -080051#include <linux/rcupdate.h>
52#include <linux/timer.h>
53#include <linux/workqueue.h>
54#include <asm/unaligned.h>
55
56#include <scsi/libfc.h>
57#include <scsi/fc_encode.h>
58
Robert Love8866a5d2009-11-03 11:45:58 -080059#include "fc_libfc.h"
60
Randy Dunlap55204902011-01-28 16:03:57 -080061static struct workqueue_struct *rport_event_queue;
Robert Love42e9a922008-12-09 15:10:17 -080062
Joe Eykholta7b12a22010-07-20 15:20:08 -070063static void fc_rport_enter_flogi(struct fc_rport_priv *);
Joe Eykholt9fb9d322009-08-25 14:00:50 -070064static void fc_rport_enter_plogi(struct fc_rport_priv *);
65static void fc_rport_enter_prli(struct fc_rport_priv *);
66static void fc_rport_enter_rtv(struct fc_rport_priv *);
67static void fc_rport_enter_ready(struct fc_rport_priv *);
68static void fc_rport_enter_logo(struct fc_rport_priv *);
Joe Eykholt370c3bd2009-08-25 14:03:47 -070069static void fc_rport_enter_adisc(struct fc_rport_priv *);
Robert Love42e9a922008-12-09 15:10:17 -080070
Joe Eykholt92261152010-07-20 15:21:12 -070071static void fc_rport_recv_plogi_req(struct fc_lport *, struct fc_frame *);
72static void fc_rport_recv_prli_req(struct fc_rport_priv *, struct fc_frame *);
73static void fc_rport_recv_prlo_req(struct fc_rport_priv *, struct fc_frame *);
74static void fc_rport_recv_logo_req(struct fc_lport *, struct fc_frame *);
Robert Love42e9a922008-12-09 15:10:17 -080075static void fc_rport_timeout(struct work_struct *);
Joe Eykholt9fb9d322009-08-25 14:00:50 -070076static void fc_rport_error(struct fc_rport_priv *, struct fc_frame *);
77static void fc_rport_error_retry(struct fc_rport_priv *, struct fc_frame *);
Robert Love42e9a922008-12-09 15:10:17 -080078static void fc_rport_work(struct work_struct *);
79
80static const char *fc_rport_state_names[] = {
Robert Love42e9a922008-12-09 15:10:17 -080081 [RPORT_ST_INIT] = "Init",
Joe Eykholta7b12a22010-07-20 15:20:08 -070082 [RPORT_ST_FLOGI] = "FLOGI",
83 [RPORT_ST_PLOGI_WAIT] = "PLOGI_WAIT",
Robert Love42e9a922008-12-09 15:10:17 -080084 [RPORT_ST_PLOGI] = "PLOGI",
85 [RPORT_ST_PRLI] = "PRLI",
86 [RPORT_ST_RTV] = "RTV",
87 [RPORT_ST_READY] = "Ready",
Joe Eykholt370c3bd2009-08-25 14:03:47 -070088 [RPORT_ST_ADISC] = "ADISC",
Joe Eykholt14194052009-07-29 17:04:43 -070089 [RPORT_ST_DELETE] = "Delete",
Robert Love42e9a922008-12-09 15:10:17 -080090};
91
Joe Eykholt9e9d0452009-08-25 14:01:18 -070092/**
Robert Love3a3b42b2009-11-03 11:47:39 -080093 * fc_rport_lookup() - Lookup a remote port by port_id
94 * @lport: The local port to lookup the remote port on
95 * @port_id: The remote port ID to look up
Joe Eykholt42e90412010-07-20 15:19:37 -070096 *
97 * The caller must hold either disc_mutex or rcu_read_lock().
Joe Eykholt8025b5d2009-08-25 14:02:06 -070098 */
99static struct fc_rport_priv *fc_rport_lookup(const struct fc_lport *lport,
100 u32 port_id)
101{
102 struct fc_rport_priv *rdata;
103
Joe Eykholt42e90412010-07-20 15:19:37 -0700104 list_for_each_entry_rcu(rdata, &lport->disc.rports, peers)
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -0700105 if (rdata->ids.port_id == port_id)
Joe Eykholt8025b5d2009-08-25 14:02:06 -0700106 return rdata;
107 return NULL;
108}
109
110/**
Robert Love9737e6a2009-08-25 14:02:59 -0700111 * fc_rport_create() - Create a new remote port
Robert Love3a3b42b2009-11-03 11:47:39 -0800112 * @lport: The local port this remote port will be associated with
113 * @ids: The identifiers for the new remote port
114 *
115 * The remote port will start in the INIT state.
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700116 *
Joe Eykholt48f00902009-08-25 14:01:50 -0700117 * Locking note: must be called with the disc_mutex held.
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700118 */
119static struct fc_rport_priv *fc_rport_create(struct fc_lport *lport,
Robert Love9737e6a2009-08-25 14:02:59 -0700120 u32 port_id)
Robert Love42e9a922008-12-09 15:10:17 -0800121{
Joe Eykholtab28f1f2009-08-25 14:00:34 -0700122 struct fc_rport_priv *rdata;
Robert Love42e9a922008-12-09 15:10:17 -0800123
Robert Love9737e6a2009-08-25 14:02:59 -0700124 rdata = lport->tt.rport_lookup(lport, port_id);
Joe Eykholt19f97e32009-08-25 14:01:55 -0700125 if (rdata)
126 return rdata;
127
Joe Eykholtf90377a2010-07-20 15:19:42 -0700128 rdata = kzalloc(sizeof(*rdata) + lport->rport_priv_size, GFP_KERNEL);
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700129 if (!rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800130 return NULL;
131
Robert Love9737e6a2009-08-25 14:02:59 -0700132 rdata->ids.node_name = -1;
133 rdata->ids.port_name = -1;
134 rdata->ids.port_id = port_id;
135 rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
136
Joe Eykholtf211fa52009-08-25 14:01:01 -0700137 kref_init(&rdata->kref);
Robert Love42e9a922008-12-09 15:10:17 -0800138 mutex_init(&rdata->rp_mutex);
Joe Eykholt795d86f2009-08-25 14:00:39 -0700139 rdata->local_port = lport;
Robert Love42e9a922008-12-09 15:10:17 -0800140 rdata->rp_state = RPORT_ST_INIT;
141 rdata->event = RPORT_EV_NONE;
142 rdata->flags = FC_RP_FLAGS_REC_SUPPORTED;
Joe Eykholt795d86f2009-08-25 14:00:39 -0700143 rdata->e_d_tov = lport->e_d_tov;
144 rdata->r_a_tov = lport->r_a_tov;
Joe Eykholtf211fa52009-08-25 14:01:01 -0700145 rdata->maxframe_size = FC_MIN_MAX_PAYLOAD;
Robert Love42e9a922008-12-09 15:10:17 -0800146 INIT_DELAYED_WORK(&rdata->retry_work, fc_rport_timeout);
147 INIT_WORK(&rdata->event_work, fc_rport_work);
Bhanu Prakash Gollapudi75a27922011-01-28 16:05:27 -0800148 if (port_id != FC_FID_DIR_SERV) {
149 rdata->lld_event_callback = lport->tt.rport_event_callback;
Joe Eykholt42e90412010-07-20 15:19:37 -0700150 list_add_rcu(&rdata->peers, &lport->disc.rports);
Bhanu Prakash Gollapudi75a27922011-01-28 16:05:27 -0800151 }
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700152 return rdata;
Robert Love42e9a922008-12-09 15:10:17 -0800153}
154
155/**
Joe Eykholt42e90412010-07-20 15:19:37 -0700156 * fc_rport_free_rcu() - Free a remote port
157 * @rcu: The rcu_head structure inside the remote port
158 */
159static void fc_rport_free_rcu(struct rcu_head *rcu)
160{
161 struct fc_rport_priv *rdata;
162
163 rdata = container_of(rcu, struct fc_rport_priv, rcu);
164 kfree(rdata);
165}
166
167/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800168 * fc_rport_destroy() - Free a remote port after last reference is released
169 * @kref: The remote port's kref
Joe Eykholtf211fa52009-08-25 14:01:01 -0700170 */
171static void fc_rport_destroy(struct kref *kref)
172{
173 struct fc_rport_priv *rdata;
Joe Eykholtf211fa52009-08-25 14:01:01 -0700174
175 rdata = container_of(kref, struct fc_rport_priv, kref);
Joe Eykholt42e90412010-07-20 15:19:37 -0700176 call_rcu(&rdata->rcu, fc_rport_free_rcu);
Joe Eykholtf211fa52009-08-25 14:01:01 -0700177}
178
179/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800180 * fc_rport_state() - Return a string identifying the remote port's state
181 * @rdata: The remote port
Robert Love42e9a922008-12-09 15:10:17 -0800182 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700183static const char *fc_rport_state(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800184{
185 const char *cp;
Robert Love42e9a922008-12-09 15:10:17 -0800186
187 cp = fc_rport_state_names[rdata->rp_state];
188 if (!cp)
189 cp = "Unknown";
190 return cp;
191}
192
193/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800194 * fc_set_rport_loss_tmo() - Set the remote port loss timeout
195 * @rport: The remote port that gets a new timeout value
196 * @timeout: The new timeout value (in seconds)
Robert Love42e9a922008-12-09 15:10:17 -0800197 */
198void fc_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout)
199{
200 if (timeout)
Mike Christie73b43762010-10-08 17:12:10 -0700201 rport->dev_loss_tmo = timeout;
Robert Love42e9a922008-12-09 15:10:17 -0800202 else
Mike Christie73b43762010-10-08 17:12:10 -0700203 rport->dev_loss_tmo = 1;
Robert Love42e9a922008-12-09 15:10:17 -0800204}
205EXPORT_SYMBOL(fc_set_rport_loss_tmo);
206
207/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800208 * fc_plogi_get_maxframe() - Get the maximum payload from the common service
209 * parameters in a FLOGI frame
Joe Eykholta7b12a22010-07-20 15:20:08 -0700210 * @flp: The FLOGI or PLOGI payload
Robert Love3a3b42b2009-11-03 11:47:39 -0800211 * @maxval: The maximum frame size upper limit; this may be less than what
212 * is in the service parameters
Robert Love42e9a922008-12-09 15:10:17 -0800213 */
Robert Loveb2ab99c2009-02-27 10:55:50 -0800214static unsigned int fc_plogi_get_maxframe(struct fc_els_flogi *flp,
215 unsigned int maxval)
Robert Love42e9a922008-12-09 15:10:17 -0800216{
217 unsigned int mfs;
218
219 /*
220 * Get max payload from the common service parameters and the
221 * class 3 receive data field size.
222 */
223 mfs = ntohs(flp->fl_csp.sp_bb_data) & FC_SP_BB_DATA_MASK;
224 if (mfs >= FC_SP_MIN_MAX_PAYLOAD && mfs < maxval)
225 maxval = mfs;
226 mfs = ntohs(flp->fl_cssp[3 - 1].cp_rdfs);
227 if (mfs >= FC_SP_MIN_MAX_PAYLOAD && mfs < maxval)
228 maxval = mfs;
229 return maxval;
230}
231
232/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800233 * fc_rport_state_enter() - Change the state of a remote port
234 * @rdata: The remote port whose state should change
235 * @new: The new state
Robert Love42e9a922008-12-09 15:10:17 -0800236 *
237 * Locking Note: Called with the rport lock held
238 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700239static void fc_rport_state_enter(struct fc_rport_priv *rdata,
Robert Love42e9a922008-12-09 15:10:17 -0800240 enum fc_rport_state new)
241{
Robert Love42e9a922008-12-09 15:10:17 -0800242 if (rdata->rp_state != new)
243 rdata->retries = 0;
244 rdata->rp_state = new;
245}
246
Robert Love3a3b42b2009-11-03 11:47:39 -0800247/**
248 * fc_rport_work() - Handler for remote port events in the rport_event_queue
249 * @work: Handle to the remote port being dequeued
250 */
Robert Love42e9a922008-12-09 15:10:17 -0800251static void fc_rport_work(struct work_struct *work)
252{
Abhijeet Joglekar571f8242009-02-27 10:54:41 -0800253 u32 port_id;
Joe Eykholtab28f1f2009-08-25 14:00:34 -0700254 struct fc_rport_priv *rdata =
255 container_of(work, struct fc_rport_priv, event_work);
Robert Love3a3b42b2009-11-03 11:47:39 -0800256 struct fc_rport_libfc_priv *rpriv;
Robert Love42e9a922008-12-09 15:10:17 -0800257 enum fc_rport_event event;
Robert Love42e9a922008-12-09 15:10:17 -0800258 struct fc_lport *lport = rdata->local_port;
259 struct fc_rport_operations *rport_ops;
Joe Eykholt629f4422009-08-25 14:01:06 -0700260 struct fc_rport_identifiers ids;
Joe Eykholtf211fa52009-08-25 14:01:01 -0700261 struct fc_rport *rport;
Joe Eykholt96ad8462011-01-28 16:04:02 -0800262 struct fc4_prov *prov;
263 u8 type;
Robert Love42e9a922008-12-09 15:10:17 -0800264
265 mutex_lock(&rdata->rp_mutex);
266 event = rdata->event;
267 rport_ops = rdata->ops;
Joe Eykholtf211fa52009-08-25 14:01:01 -0700268 rport = rdata->rport;
Robert Love42e9a922008-12-09 15:10:17 -0800269
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700270 FC_RPORT_DBG(rdata, "work event %u\n", event);
271
Joe Eykholt629f4422009-08-25 14:01:06 -0700272 switch (event) {
Joe Eykholt4c0f62b2009-08-25 14:01:12 -0700273 case RPORT_EV_READY:
Joe Eykholtf211fa52009-08-25 14:01:01 -0700274 ids = rdata->ids;
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700275 rdata->event = RPORT_EV_NONE;
Joe Eykholtf0342602010-06-11 16:44:57 -0700276 rdata->major_retries = 0;
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700277 kref_get(&rdata->kref);
Robert Love42e9a922008-12-09 15:10:17 -0800278 mutex_unlock(&rdata->rp_mutex);
279
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700280 if (!rport)
281 rport = fc_remote_port_add(lport->host, 0, &ids);
282 if (!rport) {
283 FC_RPORT_DBG(rdata, "Failed to add the rport\n");
284 lport->tt.rport_logoff(rdata);
285 kref_put(&rdata->kref, lport->tt.rport_destroy);
286 return;
Robert Love42e9a922008-12-09 15:10:17 -0800287 }
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700288 mutex_lock(&rdata->rp_mutex);
289 if (rdata->rport)
290 FC_RPORT_DBG(rdata, "rport already allocated\n");
291 rdata->rport = rport;
292 rport->maxframe_size = rdata->maxframe_size;
293 rport->supported_classes = rdata->supported_classes;
294
Robert Love3a3b42b2009-11-03 11:47:39 -0800295 rpriv = rport->dd_data;
296 rpriv->local_port = lport;
297 rpriv->rp_state = rdata->rp_state;
298 rpriv->flags = rdata->flags;
299 rpriv->e_d_tov = rdata->e_d_tov;
300 rpriv->r_a_tov = rdata->r_a_tov;
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700301 mutex_unlock(&rdata->rp_mutex);
302
Joe Eykholt83455922009-08-25 14:02:01 -0700303 if (rport_ops && rport_ops->event_callback) {
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700304 FC_RPORT_DBG(rdata, "callback ev %d\n", event);
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700305 rport_ops->event_callback(lport, rdata, event);
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700306 }
Bhanu Prakash Gollapudi75a27922011-01-28 16:05:27 -0800307 if (rdata->lld_event_callback) {
308 FC_RPORT_DBG(rdata, "lld callback ev %d\n", event);
309 rdata->lld_event_callback(lport, rdata, event);
310 }
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700311 kref_put(&rdata->kref, lport->tt.rport_destroy);
Joe Eykholt629f4422009-08-25 14:01:06 -0700312 break;
313
314 case RPORT_EV_FAILED:
315 case RPORT_EV_LOGO:
316 case RPORT_EV_STOP:
Joe Eykholt96ad8462011-01-28 16:04:02 -0800317 if (rdata->prli_count) {
318 mutex_lock(&fc_prov_mutex);
319 for (type = 1; type < FC_FC4_PROV_SIZE; type++) {
320 prov = fc_passive_prov[type];
321 if (prov && prov->prlo)
322 prov->prlo(rdata);
323 }
324 mutex_unlock(&fc_prov_mutex);
325 }
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700326 port_id = rdata->ids.port_id;
Robert Love42e9a922008-12-09 15:10:17 -0800327 mutex_unlock(&rdata->rp_mutex);
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700328
Joe Eykholt83455922009-08-25 14:02:01 -0700329 if (rport_ops && rport_ops->event_callback) {
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700330 FC_RPORT_DBG(rdata, "callback ev %d\n", event);
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700331 rport_ops->event_callback(lport, rdata, event);
Abhijeet Joglekar571f8242009-02-27 10:54:41 -0800332 }
Bhanu Prakash Gollapudi75a27922011-01-28 16:05:27 -0800333 if (rdata->lld_event_callback) {
334 FC_RPORT_DBG(rdata, "lld callback ev %d\n", event);
335 rdata->lld_event_callback(lport, rdata, event);
336 }
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700337 cancel_delayed_work_sync(&rdata->retry_work);
338
339 /*
340 * Reset any outstanding exchanges before freeing rport.
341 */
342 lport->tt.exch_mgr_reset(lport, 0, port_id);
343 lport->tt.exch_mgr_reset(lport, port_id, 0);
344
345 if (rport) {
Robert Love3a3b42b2009-11-03 11:47:39 -0800346 rpriv = rport->dd_data;
347 rpriv->rp_state = RPORT_ST_DELETE;
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700348 mutex_lock(&rdata->rp_mutex);
349 rdata->rport = NULL;
350 mutex_unlock(&rdata->rp_mutex);
351 fc_remote_port_delete(rport);
352 }
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700353
354 mutex_lock(&lport->disc.disc_mutex);
355 mutex_lock(&rdata->rp_mutex);
356 if (rdata->rp_state == RPORT_ST_DELETE) {
357 if (port_id == FC_FID_DIR_SERV) {
358 rdata->event = RPORT_EV_NONE;
359 mutex_unlock(&rdata->rp_mutex);
Joe Eykholtf0342602010-06-11 16:44:57 -0700360 } else if ((rdata->flags & FC_RP_STARTED) &&
361 rdata->major_retries <
362 lport->max_rport_retry_count) {
363 rdata->major_retries++;
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700364 rdata->event = RPORT_EV_NONE;
365 FC_RPORT_DBG(rdata, "work restart\n");
Joe Eykholta7b12a22010-07-20 15:20:08 -0700366 fc_rport_enter_flogi(rdata);
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700367 mutex_unlock(&rdata->rp_mutex);
368 } else {
369 FC_RPORT_DBG(rdata, "work delete\n");
Joe Eykholt42e90412010-07-20 15:19:37 -0700370 list_del_rcu(&rdata->peers);
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700371 mutex_unlock(&rdata->rp_mutex);
372 kref_put(&rdata->kref, lport->tt.rport_destroy);
373 }
374 } else {
375 /*
376 * Re-open for events. Reissue READY event if ready.
377 */
378 rdata->event = RPORT_EV_NONE;
379 if (rdata->rp_state == RPORT_ST_READY)
380 fc_rport_enter_ready(rdata);
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -0700381 mutex_unlock(&rdata->rp_mutex);
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700382 }
383 mutex_unlock(&lport->disc.disc_mutex);
Joe Eykholt629f4422009-08-25 14:01:06 -0700384 break;
385
386 default:
Robert Love42e9a922008-12-09 15:10:17 -0800387 mutex_unlock(&rdata->rp_mutex);
Joe Eykholt629f4422009-08-25 14:01:06 -0700388 break;
389 }
Robert Love42e9a922008-12-09 15:10:17 -0800390}
391
392/**
Robert Love34f42a02009-02-27 10:55:45 -0800393 * fc_rport_login() - Start the remote port login state machine
Robert Love3a3b42b2009-11-03 11:47:39 -0800394 * @rdata: The remote port to be logged in to
Robert Love42e9a922008-12-09 15:10:17 -0800395 *
396 * Locking Note: Called without the rport lock held. This
397 * function will hold the rport lock, call an _enter_*
398 * function and then unlock the rport.
Joe Eykholt370c3bd2009-08-25 14:03:47 -0700399 *
400 * This indicates the intent to be logged into the remote port.
401 * If it appears we are already logged in, ADISC is used to verify
402 * the setup.
Robert Love42e9a922008-12-09 15:10:17 -0800403 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700404int fc_rport_login(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800405{
Robert Love42e9a922008-12-09 15:10:17 -0800406 mutex_lock(&rdata->rp_mutex);
407
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700408 rdata->flags |= FC_RP_STARTED;
Joe Eykholt370c3bd2009-08-25 14:03:47 -0700409 switch (rdata->rp_state) {
410 case RPORT_ST_READY:
411 FC_RPORT_DBG(rdata, "ADISC port\n");
412 fc_rport_enter_adisc(rdata);
413 break;
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -0700414 case RPORT_ST_DELETE:
415 FC_RPORT_DBG(rdata, "Restart deleted port\n");
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -0700416 break;
Joe Eykholt370c3bd2009-08-25 14:03:47 -0700417 default:
418 FC_RPORT_DBG(rdata, "Login to port\n");
Joe Eykholta7b12a22010-07-20 15:20:08 -0700419 fc_rport_enter_flogi(rdata);
Joe Eykholt370c3bd2009-08-25 14:03:47 -0700420 break;
421 }
Robert Love42e9a922008-12-09 15:10:17 -0800422 mutex_unlock(&rdata->rp_mutex);
423
424 return 0;
425}
426
427/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800428 * fc_rport_enter_delete() - Schedule a remote port to be deleted
429 * @rdata: The remote port to be deleted
430 * @event: The event to report as the reason for deletion
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700431 *
432 * Locking Note: Called with the rport lock held.
433 *
434 * Allow state change into DELETE only once.
435 *
436 * Call queue_work only if there's no event already pending.
437 * Set the new event so that the old pending event will not occur.
438 * Since we have the mutex, even if fc_rport_work() is already started,
439 * it'll see the new event.
440 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700441static void fc_rport_enter_delete(struct fc_rport_priv *rdata,
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700442 enum fc_rport_event event)
443{
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700444 if (rdata->rp_state == RPORT_ST_DELETE)
445 return;
446
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700447 FC_RPORT_DBG(rdata, "Delete port\n");
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700448
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700449 fc_rport_state_enter(rdata, RPORT_ST_DELETE);
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700450
451 if (rdata->event == RPORT_EV_NONE)
452 queue_work(rport_event_queue, &rdata->event_work);
453 rdata->event = event;
454}
455
456/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800457 * fc_rport_logoff() - Logoff and remove a remote port
458 * @rdata: The remote port to be logged off of
Robert Love42e9a922008-12-09 15:10:17 -0800459 *
460 * Locking Note: Called without the rport lock held. This
461 * function will hold the rport lock, call an _enter_*
462 * function and then unlock the rport.
463 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700464int fc_rport_logoff(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800465{
Robert Love42e9a922008-12-09 15:10:17 -0800466 mutex_lock(&rdata->rp_mutex);
467
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700468 FC_RPORT_DBG(rdata, "Remove port\n");
Robert Love42e9a922008-12-09 15:10:17 -0800469
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700470 rdata->flags &= ~FC_RP_STARTED;
Joe Eykholt14194052009-07-29 17:04:43 -0700471 if (rdata->rp_state == RPORT_ST_DELETE) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700472 FC_RPORT_DBG(rdata, "Port in Delete state, not removing\n");
Abhijeet Joglekarb4c6f542009-04-21 16:27:04 -0700473 goto out;
474 }
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700475 fc_rport_enter_logo(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800476
477 /*
Joe Eykholt14194052009-07-29 17:04:43 -0700478 * Change the state to Delete so that we discard
Robert Love42e9a922008-12-09 15:10:17 -0800479 * the response.
480 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700481 fc_rport_enter_delete(rdata, RPORT_EV_STOP);
Abhijeet Joglekarb4c6f542009-04-21 16:27:04 -0700482out:
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -0700483 mutex_unlock(&rdata->rp_mutex);
Robert Love42e9a922008-12-09 15:10:17 -0800484 return 0;
485}
486
487/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800488 * fc_rport_enter_ready() - Transition to the RPORT_ST_READY state
489 * @rdata: The remote port that is ready
Robert Love42e9a922008-12-09 15:10:17 -0800490 *
491 * Locking Note: The rport lock is expected to be held before calling
492 * this routine.
493 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700494static void fc_rport_enter_ready(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800495{
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700496 fc_rport_state_enter(rdata, RPORT_ST_READY);
Robert Love42e9a922008-12-09 15:10:17 -0800497
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700498 FC_RPORT_DBG(rdata, "Port is Ready\n");
Robert Love42e9a922008-12-09 15:10:17 -0800499
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700500 if (rdata->event == RPORT_EV_NONE)
501 queue_work(rport_event_queue, &rdata->event_work);
Joe Eykholt4c0f62b2009-08-25 14:01:12 -0700502 rdata->event = RPORT_EV_READY;
Robert Love42e9a922008-12-09 15:10:17 -0800503}
504
505/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800506 * fc_rport_timeout() - Handler for the retry_work timer
507 * @work: Handle to the remote port that has timed out
Robert Love42e9a922008-12-09 15:10:17 -0800508 *
509 * Locking Note: Called without the rport lock held. This
510 * function will hold the rport lock, call an _enter_*
511 * function and then unlock the rport.
512 */
513static void fc_rport_timeout(struct work_struct *work)
514{
Joe Eykholtab28f1f2009-08-25 14:00:34 -0700515 struct fc_rport_priv *rdata =
516 container_of(work, struct fc_rport_priv, retry_work.work);
Robert Love42e9a922008-12-09 15:10:17 -0800517
518 mutex_lock(&rdata->rp_mutex);
519
520 switch (rdata->rp_state) {
Joe Eykholta7b12a22010-07-20 15:20:08 -0700521 case RPORT_ST_FLOGI:
522 fc_rport_enter_flogi(rdata);
523 break;
Robert Love42e9a922008-12-09 15:10:17 -0800524 case RPORT_ST_PLOGI:
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700525 fc_rport_enter_plogi(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800526 break;
527 case RPORT_ST_PRLI:
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700528 fc_rport_enter_prli(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800529 break;
530 case RPORT_ST_RTV:
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700531 fc_rport_enter_rtv(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800532 break;
Joe Eykholt370c3bd2009-08-25 14:03:47 -0700533 case RPORT_ST_ADISC:
534 fc_rport_enter_adisc(rdata);
535 break;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700536 case RPORT_ST_PLOGI_WAIT:
Robert Love42e9a922008-12-09 15:10:17 -0800537 case RPORT_ST_READY:
538 case RPORT_ST_INIT:
Joe Eykholt14194052009-07-29 17:04:43 -0700539 case RPORT_ST_DELETE:
Robert Love42e9a922008-12-09 15:10:17 -0800540 break;
541 }
542
543 mutex_unlock(&rdata->rp_mutex);
Robert Love42e9a922008-12-09 15:10:17 -0800544}
545
546/**
Robert Love34f42a02009-02-27 10:55:45 -0800547 * fc_rport_error() - Error handler, called once retries have been exhausted
Robert Love3a3b42b2009-11-03 11:47:39 -0800548 * @rdata: The remote port the error is happened on
549 * @fp: The error code encapsulated in a frame pointer
Robert Love42e9a922008-12-09 15:10:17 -0800550 *
Robert Love42e9a922008-12-09 15:10:17 -0800551 * Locking Note: The rport lock is expected to be held before
552 * calling this routine
553 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700554static void fc_rport_error(struct fc_rport_priv *rdata, struct fc_frame *fp)
Robert Love42e9a922008-12-09 15:10:17 -0800555{
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700556 FC_RPORT_DBG(rdata, "Error %ld in state %s, retries %d\n",
Joe Eykholtcdbe6df2009-08-25 14:01:39 -0700557 IS_ERR(fp) ? -PTR_ERR(fp) : 0,
558 fc_rport_state(rdata), rdata->retries);
Robert Love42e9a922008-12-09 15:10:17 -0800559
Chris Leech6755db12009-02-27 10:55:02 -0800560 switch (rdata->rp_state) {
Joe Eykholta7b12a22010-07-20 15:20:08 -0700561 case RPORT_ST_FLOGI:
Chris Leech6755db12009-02-27 10:55:02 -0800562 case RPORT_ST_PLOGI:
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700563 rdata->flags &= ~FC_RP_STARTED;
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700564 fc_rport_enter_delete(rdata, RPORT_EV_FAILED);
Chris Leech6755db12009-02-27 10:55:02 -0800565 break;
566 case RPORT_ST_RTV:
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700567 fc_rport_enter_ready(rdata);
Chris Leech6755db12009-02-27 10:55:02 -0800568 break;
Joe Eykholt370c3bd2009-08-25 14:03:47 -0700569 case RPORT_ST_PRLI:
570 case RPORT_ST_ADISC:
571 fc_rport_enter_logo(rdata);
572 break;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700573 case RPORT_ST_PLOGI_WAIT:
Joe Eykholt14194052009-07-29 17:04:43 -0700574 case RPORT_ST_DELETE:
Chris Leech6755db12009-02-27 10:55:02 -0800575 case RPORT_ST_READY:
576 case RPORT_ST_INIT:
577 break;
Robert Love42e9a922008-12-09 15:10:17 -0800578 }
579}
580
581/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800582 * fc_rport_error_retry() - Handler for remote port state retries
583 * @rdata: The remote port whose state is to be retried
584 * @fp: The error code encapsulated in a frame pointer
Chris Leech6755db12009-02-27 10:55:02 -0800585 *
586 * If the error was an exchange timeout retry immediately,
587 * otherwise wait for E_D_TOV.
588 *
589 * Locking Note: The rport lock is expected to be held before
590 * calling this routine
591 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700592static void fc_rport_error_retry(struct fc_rport_priv *rdata,
593 struct fc_frame *fp)
Chris Leech6755db12009-02-27 10:55:02 -0800594{
Chris Leech6755db12009-02-27 10:55:02 -0800595 unsigned long delay = FC_DEF_E_D_TOV;
596
597 /* make sure this isn't an FC_EX_CLOSED error, never retry those */
598 if (PTR_ERR(fp) == -FC_EX_CLOSED)
Hillf Danton28a4af12011-01-28 16:03:26 -0800599 goto out;
Chris Leech6755db12009-02-27 10:55:02 -0800600
Abhijeet Joglekara3666952009-05-01 10:01:26 -0700601 if (rdata->retries < rdata->local_port->max_rport_retry_count) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700602 FC_RPORT_DBG(rdata, "Error %ld in state %s, retrying\n",
603 PTR_ERR(fp), fc_rport_state(rdata));
Chris Leech6755db12009-02-27 10:55:02 -0800604 rdata->retries++;
605 /* no additional delay on exchange timeouts */
606 if (PTR_ERR(fp) == -FC_EX_TIMEOUT)
607 delay = 0;
Chris Leech6755db12009-02-27 10:55:02 -0800608 schedule_delayed_work(&rdata->retry_work, delay);
609 return;
610 }
611
Hillf Danton28a4af12011-01-28 16:03:26 -0800612out:
613 fc_rport_error(rdata, fp);
Chris Leech6755db12009-02-27 10:55:02 -0800614}
615
616/**
Joe Eykholta7b12a22010-07-20 15:20:08 -0700617 * fc_rport_login_complete() - Handle parameters and completion of p-mp login.
618 * @rdata: The remote port which we logged into or which logged into us.
619 * @fp: The FLOGI or PLOGI request or response frame
620 *
621 * Returns non-zero error if a problem is detected with the frame.
622 * Does not free the frame.
623 *
624 * This is only used in point-to-multipoint mode for FIP currently.
625 */
626static int fc_rport_login_complete(struct fc_rport_priv *rdata,
627 struct fc_frame *fp)
628{
629 struct fc_lport *lport = rdata->local_port;
630 struct fc_els_flogi *flogi;
631 unsigned int e_d_tov;
632 u16 csp_flags;
633
634 flogi = fc_frame_payload_get(fp, sizeof(*flogi));
635 if (!flogi)
636 return -EINVAL;
637
638 csp_flags = ntohs(flogi->fl_csp.sp_features);
639
640 if (fc_frame_payload_op(fp) == ELS_FLOGI) {
641 if (csp_flags & FC_SP_FT_FPORT) {
642 FC_RPORT_DBG(rdata, "Fabric bit set in FLOGI\n");
643 return -EINVAL;
644 }
645 } else {
646
647 /*
648 * E_D_TOV is not valid on an incoming FLOGI request.
649 */
650 e_d_tov = ntohl(flogi->fl_csp.sp_e_d_tov);
651 if (csp_flags & FC_SP_FT_EDTR)
652 e_d_tov /= 1000000;
653 if (e_d_tov > rdata->e_d_tov)
654 rdata->e_d_tov = e_d_tov;
655 }
656 rdata->maxframe_size = fc_plogi_get_maxframe(flogi, lport->mfs);
657 return 0;
658}
659
660/**
661 * fc_rport_flogi_resp() - Handle response to FLOGI request for p-mp mode
662 * @sp: The sequence that the FLOGI was on
663 * @fp: The FLOGI response frame
664 * @rp_arg: The remote port that received the FLOGI response
665 */
666void fc_rport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp,
667 void *rp_arg)
668{
669 struct fc_rport_priv *rdata = rp_arg;
670 struct fc_lport *lport = rdata->local_port;
671 struct fc_els_flogi *flogi;
672 unsigned int r_a_tov;
673
674 FC_RPORT_DBG(rdata, "Received a FLOGI %s\n", fc_els_resp_type(fp));
675
676 if (fp == ERR_PTR(-FC_EX_CLOSED))
Hillf Danton0e9e3d32010-11-30 16:19:04 -0800677 goto put;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700678
679 mutex_lock(&rdata->rp_mutex);
680
681 if (rdata->rp_state != RPORT_ST_FLOGI) {
682 FC_RPORT_DBG(rdata, "Received a FLOGI response, but in state "
683 "%s\n", fc_rport_state(rdata));
684 if (IS_ERR(fp))
685 goto err;
686 goto out;
687 }
688
689 if (IS_ERR(fp)) {
690 fc_rport_error(rdata, fp);
691 goto err;
692 }
693
694 if (fc_frame_payload_op(fp) != ELS_LS_ACC)
695 goto bad;
696 if (fc_rport_login_complete(rdata, fp))
697 goto bad;
698
699 flogi = fc_frame_payload_get(fp, sizeof(*flogi));
700 if (!flogi)
701 goto bad;
702 r_a_tov = ntohl(flogi->fl_csp.sp_r_a_tov);
703 if (r_a_tov > rdata->r_a_tov)
704 rdata->r_a_tov = r_a_tov;
705
706 if (rdata->ids.port_name < lport->wwpn)
707 fc_rport_enter_plogi(rdata);
708 else
709 fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
710out:
711 fc_frame_free(fp);
712err:
713 mutex_unlock(&rdata->rp_mutex);
Hillf Danton0e9e3d32010-11-30 16:19:04 -0800714put:
Joe Eykholta7b12a22010-07-20 15:20:08 -0700715 kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
716 return;
717bad:
718 FC_RPORT_DBG(rdata, "Bad FLOGI response\n");
719 fc_rport_error_retry(rdata, fp);
720 goto out;
721}
722
723/**
724 * fc_rport_enter_flogi() - Send a FLOGI request to the remote port for p-mp
725 * @rdata: The remote port to send a FLOGI to
726 *
727 * Locking Note: The rport lock is expected to be held before calling
728 * this routine.
729 */
730static void fc_rport_enter_flogi(struct fc_rport_priv *rdata)
731{
732 struct fc_lport *lport = rdata->local_port;
733 struct fc_frame *fp;
734
735 if (!lport->point_to_multipoint)
736 return fc_rport_enter_plogi(rdata);
737
738 FC_RPORT_DBG(rdata, "Entered FLOGI state from %s state\n",
739 fc_rport_state(rdata));
740
741 fc_rport_state_enter(rdata, RPORT_ST_FLOGI);
742
743 fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi));
744 if (!fp)
745 return fc_rport_error_retry(rdata, fp);
746
747 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_FLOGI,
748 fc_rport_flogi_resp, rdata,
749 2 * lport->r_a_tov))
750 fc_rport_error_retry(rdata, NULL);
751 else
752 kref_get(&rdata->kref);
753}
754
755/**
756 * fc_rport_recv_flogi_req() - Handle Fabric Login (FLOGI) request in p-mp mode
757 * @lport: The local port that received the PLOGI request
Joe Eykholta7b12a22010-07-20 15:20:08 -0700758 * @rx_fp: The PLOGI request frame
759 */
760static void fc_rport_recv_flogi_req(struct fc_lport *lport,
Joe Eykholt92261152010-07-20 15:21:12 -0700761 struct fc_frame *rx_fp)
Joe Eykholta7b12a22010-07-20 15:20:08 -0700762{
763 struct fc_disc *disc;
764 struct fc_els_flogi *flp;
765 struct fc_rport_priv *rdata;
766 struct fc_frame *fp = rx_fp;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700767 struct fc_seq_els_data rjt_data;
Joe Eykholt24f089e2010-07-20 15:21:01 -0700768 u32 sid;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700769
Joe Eykholt251748a2010-07-20 15:20:56 -0700770 sid = fc_frame_sid(fp);
Joe Eykholta7b12a22010-07-20 15:20:08 -0700771
772 FC_RPORT_ID_DBG(lport, sid, "Received FLOGI request\n");
773
774 disc = &lport->disc;
775 mutex_lock(&disc->disc_mutex);
776
777 if (!lport->point_to_multipoint) {
778 rjt_data.reason = ELS_RJT_UNSUP;
779 rjt_data.explan = ELS_EXPL_NONE;
780 goto reject;
781 }
782
783 flp = fc_frame_payload_get(fp, sizeof(*flp));
784 if (!flp) {
785 rjt_data.reason = ELS_RJT_LOGIC;
786 rjt_data.explan = ELS_EXPL_INV_LEN;
787 goto reject;
788 }
789
790 rdata = lport->tt.rport_lookup(lport, sid);
791 if (!rdata) {
792 rjt_data.reason = ELS_RJT_FIP;
793 rjt_data.explan = ELS_EXPL_NOT_NEIGHBOR;
794 goto reject;
795 }
796 mutex_lock(&rdata->rp_mutex);
797
798 FC_RPORT_DBG(rdata, "Received FLOGI in %s state\n",
799 fc_rport_state(rdata));
800
801 switch (rdata->rp_state) {
802 case RPORT_ST_INIT:
Joe Eykholta7b12a22010-07-20 15:20:08 -0700803 case RPORT_ST_DELETE:
804 mutex_unlock(&rdata->rp_mutex);
805 rjt_data.reason = ELS_RJT_FIP;
806 rjt_data.explan = ELS_EXPL_NOT_NEIGHBOR;
807 goto reject;
808 case RPORT_ST_FLOGI:
809 case RPORT_ST_PLOGI_WAIT:
810 case RPORT_ST_PLOGI:
811 break;
812 case RPORT_ST_PRLI:
813 case RPORT_ST_RTV:
814 case RPORT_ST_READY:
815 case RPORT_ST_ADISC:
816 /*
817 * Set the remote port to be deleted and to then restart.
818 * This queues work to be sure exchanges are reset.
819 */
820 fc_rport_enter_delete(rdata, RPORT_EV_LOGO);
821 mutex_unlock(&rdata->rp_mutex);
822 rjt_data.reason = ELS_RJT_BUSY;
823 rjt_data.explan = ELS_EXPL_NONE;
824 goto reject;
825 }
826 if (fc_rport_login_complete(rdata, fp)) {
827 mutex_unlock(&rdata->rp_mutex);
828 rjt_data.reason = ELS_RJT_LOGIC;
829 rjt_data.explan = ELS_EXPL_NONE;
830 goto reject;
831 }
Joe Eykholta7b12a22010-07-20 15:20:08 -0700832
833 fp = fc_frame_alloc(lport, sizeof(*flp));
834 if (!fp)
835 goto out;
836
Joe Eykholta7b12a22010-07-20 15:20:08 -0700837 fc_flogi_fill(lport, fp);
838 flp = fc_frame_payload_get(fp, sizeof(*flp));
839 flp->fl_cmd = ELS_LS_ACC;
840
Joe Eykholt24f089e2010-07-20 15:21:01 -0700841 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
842 lport->tt.frame_send(lport, fp);
Joe Eykholta7b12a22010-07-20 15:20:08 -0700843
844 if (rdata->ids.port_name < lport->wwpn)
845 fc_rport_enter_plogi(rdata);
846 else
847 fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
848out:
849 mutex_unlock(&rdata->rp_mutex);
850 mutex_unlock(&disc->disc_mutex);
Joe Eykholt24f089e2010-07-20 15:21:01 -0700851 fc_frame_free(rx_fp);
Joe Eykholta7b12a22010-07-20 15:20:08 -0700852 return;
853
854reject:
855 mutex_unlock(&disc->disc_mutex);
Joe Eykholt92261152010-07-20 15:21:12 -0700856 lport->tt.seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
Joe Eykholt24f089e2010-07-20 15:21:01 -0700857 fc_frame_free(rx_fp);
Joe Eykholta7b12a22010-07-20 15:20:08 -0700858}
859
860/**
861 * fc_rport_plogi_resp() - Handler for ELS PLOGI responses
Robert Love3a3b42b2009-11-03 11:47:39 -0800862 * @sp: The sequence the PLOGI is on
863 * @fp: The PLOGI response frame
864 * @rdata_arg: The remote port that sent the PLOGI response
Robert Love42e9a922008-12-09 15:10:17 -0800865 *
866 * Locking Note: This function will be called without the rport lock
867 * held, but it will lock, call an _enter_* function or fc_rport_error
868 * and then unlock the rport.
869 */
870static void fc_rport_plogi_resp(struct fc_seq *sp, struct fc_frame *fp,
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700871 void *rdata_arg)
Robert Love42e9a922008-12-09 15:10:17 -0800872{
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700873 struct fc_rport_priv *rdata = rdata_arg;
Robert Love42e9a922008-12-09 15:10:17 -0800874 struct fc_lport *lport = rdata->local_port;
Robert Lovea29e7642009-04-21 16:27:41 -0700875 struct fc_els_flogi *plp = NULL;
Robert Love42e9a922008-12-09 15:10:17 -0800876 u16 csp_seq;
877 u16 cssp_seq;
878 u8 op;
879
880 mutex_lock(&rdata->rp_mutex);
881
Joe Eykholtf657d292009-08-25 14:03:21 -0700882 FC_RPORT_DBG(rdata, "Received a PLOGI %s\n", fc_els_resp_type(fp));
Robert Love42e9a922008-12-09 15:10:17 -0800883
884 if (rdata->rp_state != RPORT_ST_PLOGI) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700885 FC_RPORT_DBG(rdata, "Received a PLOGI response, but in state "
886 "%s\n", fc_rport_state(rdata));
Abhijeet Joglekar76f68042009-04-21 16:26:58 -0700887 if (IS_ERR(fp))
888 goto err;
Robert Love42e9a922008-12-09 15:10:17 -0800889 goto out;
890 }
891
Abhijeet Joglekar76f68042009-04-21 16:26:58 -0700892 if (IS_ERR(fp)) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700893 fc_rport_error_retry(rdata, fp);
Abhijeet Joglekar76f68042009-04-21 16:26:58 -0700894 goto err;
895 }
896
Robert Love42e9a922008-12-09 15:10:17 -0800897 op = fc_frame_payload_op(fp);
898 if (op == ELS_LS_ACC &&
899 (plp = fc_frame_payload_get(fp, sizeof(*plp))) != NULL) {
Joe Eykholtf211fa52009-08-25 14:01:01 -0700900 rdata->ids.port_name = get_unaligned_be64(&plp->fl_wwpn);
901 rdata->ids.node_name = get_unaligned_be64(&plp->fl_wwnn);
Robert Love42e9a922008-12-09 15:10:17 -0800902
Bhanu Prakash Gollapudi75a27922011-01-28 16:05:27 -0800903 /* save plogi response sp_features for further reference */
904 rdata->sp_features = ntohs(plp->fl_csp.sp_features);
905
Joe Eykholta7b12a22010-07-20 15:20:08 -0700906 if (lport->point_to_multipoint)
907 fc_rport_login_complete(rdata, fp);
Robert Love42e9a922008-12-09 15:10:17 -0800908 csp_seq = ntohs(plp->fl_csp.sp_tot_seq);
909 cssp_seq = ntohs(plp->fl_cssp[3 - 1].cp_con_seq);
910 if (cssp_seq < csp_seq)
911 csp_seq = cssp_seq;
912 rdata->max_seq = csp_seq;
Joe Eykholtf211fa52009-08-25 14:01:01 -0700913 rdata->maxframe_size = fc_plogi_get_maxframe(plp, lport->mfs);
Joe Eykholt3ac6f982009-08-25 14:03:26 -0700914 fc_rport_enter_prli(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800915 } else
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700916 fc_rport_error_retry(rdata, fp);
Robert Love42e9a922008-12-09 15:10:17 -0800917
918out:
919 fc_frame_free(fp);
920err:
921 mutex_unlock(&rdata->rp_mutex);
Joe Eykholtf211fa52009-08-25 14:01:01 -0700922 kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
Robert Love42e9a922008-12-09 15:10:17 -0800923}
924
925/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800926 * fc_rport_enter_plogi() - Send Port Login (PLOGI) request
927 * @rdata: The remote port to send a PLOGI to
Robert Love42e9a922008-12-09 15:10:17 -0800928 *
929 * Locking Note: The rport lock is expected to be held before calling
930 * this routine.
931 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700932static void fc_rport_enter_plogi(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800933{
Robert Love42e9a922008-12-09 15:10:17 -0800934 struct fc_lport *lport = rdata->local_port;
935 struct fc_frame *fp;
936
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700937 FC_RPORT_DBG(rdata, "Port entered PLOGI state from %s state\n",
938 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -0800939
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700940 fc_rport_state_enter(rdata, RPORT_ST_PLOGI);
Robert Love42e9a922008-12-09 15:10:17 -0800941
Joe Eykholtf211fa52009-08-25 14:01:01 -0700942 rdata->maxframe_size = FC_MIN_MAX_PAYLOAD;
Robert Love42e9a922008-12-09 15:10:17 -0800943 fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi));
944 if (!fp) {
Joe Eykholta7b12a22010-07-20 15:20:08 -0700945 FC_RPORT_DBG(rdata, "%s frame alloc failed\n", __func__);
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700946 fc_rport_error_retry(rdata, fp);
Robert Love42e9a922008-12-09 15:10:17 -0800947 return;
948 }
949 rdata->e_d_tov = lport->e_d_tov;
950
Joe Eykholtf211fa52009-08-25 14:01:01 -0700951 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_PLOGI,
Joe Eykholtb94f8952009-11-03 11:50:21 -0800952 fc_rport_plogi_resp, rdata,
953 2 * lport->r_a_tov))
Chris Leech8f550f92009-10-21 16:28:09 -0700954 fc_rport_error_retry(rdata, NULL);
Robert Love42e9a922008-12-09 15:10:17 -0800955 else
Joe Eykholtf211fa52009-08-25 14:01:01 -0700956 kref_get(&rdata->kref);
Robert Love42e9a922008-12-09 15:10:17 -0800957}
958
959/**
Robert Love34f42a02009-02-27 10:55:45 -0800960 * fc_rport_prli_resp() - Process Login (PRLI) response handler
Robert Love3a3b42b2009-11-03 11:47:39 -0800961 * @sp: The sequence the PRLI response was on
962 * @fp: The PRLI response frame
963 * @rdata_arg: The remote port that sent the PRLI response
Robert Love42e9a922008-12-09 15:10:17 -0800964 *
965 * Locking Note: This function will be called without the rport lock
966 * held, but it will lock, call an _enter_* function or fc_rport_error
967 * and then unlock the rport.
968 */
969static void fc_rport_prli_resp(struct fc_seq *sp, struct fc_frame *fp,
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700970 void *rdata_arg)
Robert Love42e9a922008-12-09 15:10:17 -0800971{
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700972 struct fc_rport_priv *rdata = rdata_arg;
Robert Love42e9a922008-12-09 15:10:17 -0800973 struct {
974 struct fc_els_prli prli;
975 struct fc_els_spp spp;
976 } *pp;
Joe Eykholt925ceda2011-01-28 16:04:23 -0800977 struct fc_els_spp temp_spp;
978 struct fc4_prov *prov;
Robert Love42e9a922008-12-09 15:10:17 -0800979 u32 roles = FC_RPORT_ROLE_UNKNOWN;
980 u32 fcp_parm = 0;
981 u8 op;
Bhanu Prakash Gollapudi618461c2010-06-11 16:43:54 -0700982 u8 resp_code = 0;
Robert Love42e9a922008-12-09 15:10:17 -0800983
984 mutex_lock(&rdata->rp_mutex);
985
Joe Eykholtf657d292009-08-25 14:03:21 -0700986 FC_RPORT_DBG(rdata, "Received a PRLI %s\n", fc_els_resp_type(fp));
Robert Love42e9a922008-12-09 15:10:17 -0800987
988 if (rdata->rp_state != RPORT_ST_PRLI) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700989 FC_RPORT_DBG(rdata, "Received a PRLI response, but in state "
990 "%s\n", fc_rport_state(rdata));
Abhijeet Joglekar76f68042009-04-21 16:26:58 -0700991 if (IS_ERR(fp))
992 goto err;
Robert Love42e9a922008-12-09 15:10:17 -0800993 goto out;
994 }
995
Abhijeet Joglekar76f68042009-04-21 16:26:58 -0700996 if (IS_ERR(fp)) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700997 fc_rport_error_retry(rdata, fp);
Abhijeet Joglekar76f68042009-04-21 16:26:58 -0700998 goto err;
999 }
1000
Robert Love6bd054c2009-08-25 14:03:04 -07001001 /* reinitialize remote port roles */
1002 rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
1003
Robert Love42e9a922008-12-09 15:10:17 -08001004 op = fc_frame_payload_op(fp);
1005 if (op == ELS_LS_ACC) {
1006 pp = fc_frame_payload_get(fp, sizeof(*pp));
Bhanu Prakash Gollapudi618461c2010-06-11 16:43:54 -07001007 if (!pp)
1008 goto out;
1009
1010 resp_code = (pp->spp.spp_flags & FC_SPP_RESP_MASK);
1011 FC_RPORT_DBG(rdata, "PRLI spp_flags = 0x%x\n",
1012 pp->spp.spp_flags);
Bhanu Prakash Gollapudi75a27922011-01-28 16:05:27 -08001013 rdata->spp_type = pp->spp.spp_type;
Bhanu Prakash Gollapudi618461c2010-06-11 16:43:54 -07001014 if (resp_code != FC_SPP_RESP_ACK) {
1015 if (resp_code == FC_SPP_RESP_CONF)
1016 fc_rport_error(rdata, fp);
1017 else
1018 fc_rport_error_retry(rdata, fp);
1019 goto out;
Robert Love42e9a922008-12-09 15:10:17 -08001020 }
Bhanu Prakash Gollapudi618461c2010-06-11 16:43:54 -07001021 if (pp->prli.prli_spp_len < sizeof(pp->spp))
1022 goto out;
1023
1024 fcp_parm = ntohl(pp->spp.spp_params);
1025 if (fcp_parm & FCP_SPPF_RETRY)
1026 rdata->flags |= FC_RP_FLAGS_RETRY;
Bhanu Prakash Gollapudi75a27922011-01-28 16:05:27 -08001027 if (fcp_parm & FCP_SPPF_CONF_COMPL)
1028 rdata->flags |= FC_RP_FLAGS_CONF_REQ;
Robert Love42e9a922008-12-09 15:10:17 -08001029
Joe Eykholt925ceda2011-01-28 16:04:23 -08001030 prov = fc_passive_prov[FC_TYPE_FCP];
1031 if (prov) {
1032 memset(&temp_spp, 0, sizeof(temp_spp));
1033 prov->prli(rdata, pp->prli.prli_spp_len,
1034 &pp->spp, &temp_spp);
1035 }
1036
Joe Eykholtf211fa52009-08-25 14:01:01 -07001037 rdata->supported_classes = FC_COS_CLASS3;
Robert Love42e9a922008-12-09 15:10:17 -08001038 if (fcp_parm & FCP_SPPF_INIT_FCN)
1039 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1040 if (fcp_parm & FCP_SPPF_TARG_FCN)
1041 roles |= FC_RPORT_ROLE_FCP_TARGET;
1042
Joe Eykholtf211fa52009-08-25 14:01:01 -07001043 rdata->ids.roles = roles;
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001044 fc_rport_enter_rtv(rdata);
Robert Love42e9a922008-12-09 15:10:17 -08001045
1046 } else {
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001047 FC_RPORT_DBG(rdata, "Bad ELS response for PRLI command\n");
Bhanu Prakash Gollapudi292e40b2010-06-11 16:43:49 -07001048 fc_rport_error_retry(rdata, fp);
Robert Love42e9a922008-12-09 15:10:17 -08001049 }
1050
1051out:
1052 fc_frame_free(fp);
1053err:
1054 mutex_unlock(&rdata->rp_mutex);
Joe Eykholtf211fa52009-08-25 14:01:01 -07001055 kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
Robert Love42e9a922008-12-09 15:10:17 -08001056}
1057
1058/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001059 * fc_rport_enter_prli() - Send Process Login (PRLI) request
1060 * @rdata: The remote port to send the PRLI request to
Robert Love42e9a922008-12-09 15:10:17 -08001061 *
1062 * Locking Note: The rport lock is expected to be held before calling
1063 * this routine.
1064 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001065static void fc_rport_enter_prli(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -08001066{
Robert Love42e9a922008-12-09 15:10:17 -08001067 struct fc_lport *lport = rdata->local_port;
1068 struct {
1069 struct fc_els_prli prli;
1070 struct fc_els_spp spp;
1071 } *pp;
1072 struct fc_frame *fp;
Joe Eykholt925ceda2011-01-28 16:04:23 -08001073 struct fc4_prov *prov;
Robert Love42e9a922008-12-09 15:10:17 -08001074
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001075 /*
1076 * If the rport is one of the well known addresses
1077 * we skip PRLI and RTV and go straight to READY.
1078 */
1079 if (rdata->ids.port_id >= FC_FID_DOM_MGR) {
1080 fc_rport_enter_ready(rdata);
1081 return;
1082 }
1083
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001084 FC_RPORT_DBG(rdata, "Port entered PRLI state from %s state\n",
1085 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -08001086
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001087 fc_rport_state_enter(rdata, RPORT_ST_PRLI);
Robert Love42e9a922008-12-09 15:10:17 -08001088
1089 fp = fc_frame_alloc(lport, sizeof(*pp));
1090 if (!fp) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001091 fc_rport_error_retry(rdata, fp);
Robert Love42e9a922008-12-09 15:10:17 -08001092 return;
1093 }
1094
Joe Eykholt925ceda2011-01-28 16:04:23 -08001095 fc_prli_fill(lport, fp);
1096
1097 prov = fc_passive_prov[FC_TYPE_FCP];
1098 if (prov) {
1099 pp = fc_frame_payload_get(fp, sizeof(*pp));
1100 prov->prli(rdata, sizeof(pp->spp), NULL, &pp->spp);
1101 }
1102
1103 fc_fill_fc_hdr(fp, FC_RCTL_ELS_REQ, rdata->ids.port_id,
1104 fc_host_port_id(lport->host), FC_TYPE_ELS,
1105 FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0);
1106
1107 if (!lport->tt.exch_seq_send(lport, fp, fc_rport_prli_resp,
1108 NULL, rdata, 2 * lport->r_a_tov))
Chris Leech8f550f92009-10-21 16:28:09 -07001109 fc_rport_error_retry(rdata, NULL);
Robert Love42e9a922008-12-09 15:10:17 -08001110 else
Joe Eykholtf211fa52009-08-25 14:01:01 -07001111 kref_get(&rdata->kref);
Robert Love42e9a922008-12-09 15:10:17 -08001112}
1113
1114/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001115 * fc_rport_els_rtv_resp() - Handler for Request Timeout Value (RTV) responses
1116 * @sp: The sequence the RTV was on
1117 * @fp: The RTV response frame
1118 * @rdata_arg: The remote port that sent the RTV response
Robert Love42e9a922008-12-09 15:10:17 -08001119 *
1120 * Many targets don't seem to support this.
1121 *
1122 * Locking Note: This function will be called without the rport lock
1123 * held, but it will lock, call an _enter_* function or fc_rport_error
1124 * and then unlock the rport.
1125 */
1126static void fc_rport_rtv_resp(struct fc_seq *sp, struct fc_frame *fp,
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001127 void *rdata_arg)
Robert Love42e9a922008-12-09 15:10:17 -08001128{
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001129 struct fc_rport_priv *rdata = rdata_arg;
Robert Love42e9a922008-12-09 15:10:17 -08001130 u8 op;
1131
1132 mutex_lock(&rdata->rp_mutex);
1133
Joe Eykholtf657d292009-08-25 14:03:21 -07001134 FC_RPORT_DBG(rdata, "Received a RTV %s\n", fc_els_resp_type(fp));
Robert Love42e9a922008-12-09 15:10:17 -08001135
1136 if (rdata->rp_state != RPORT_ST_RTV) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001137 FC_RPORT_DBG(rdata, "Received a RTV response, but in state "
1138 "%s\n", fc_rport_state(rdata));
Abhijeet Joglekar76f68042009-04-21 16:26:58 -07001139 if (IS_ERR(fp))
1140 goto err;
Robert Love42e9a922008-12-09 15:10:17 -08001141 goto out;
1142 }
1143
Abhijeet Joglekar76f68042009-04-21 16:26:58 -07001144 if (IS_ERR(fp)) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001145 fc_rport_error(rdata, fp);
Abhijeet Joglekar76f68042009-04-21 16:26:58 -07001146 goto err;
1147 }
1148
Robert Love42e9a922008-12-09 15:10:17 -08001149 op = fc_frame_payload_op(fp);
1150 if (op == ELS_LS_ACC) {
1151 struct fc_els_rtv_acc *rtv;
1152 u32 toq;
1153 u32 tov;
1154
1155 rtv = fc_frame_payload_get(fp, sizeof(*rtv));
1156 if (rtv) {
1157 toq = ntohl(rtv->rtv_toq);
1158 tov = ntohl(rtv->rtv_r_a_tov);
1159 if (tov == 0)
1160 tov = 1;
1161 rdata->r_a_tov = tov;
1162 tov = ntohl(rtv->rtv_e_d_tov);
1163 if (toq & FC_ELS_RTV_EDRES)
1164 tov /= 1000000;
1165 if (tov == 0)
1166 tov = 1;
1167 rdata->e_d_tov = tov;
1168 }
1169 }
1170
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001171 fc_rport_enter_ready(rdata);
Robert Love42e9a922008-12-09 15:10:17 -08001172
1173out:
1174 fc_frame_free(fp);
1175err:
1176 mutex_unlock(&rdata->rp_mutex);
Joe Eykholtf211fa52009-08-25 14:01:01 -07001177 kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
Robert Love42e9a922008-12-09 15:10:17 -08001178}
1179
1180/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001181 * fc_rport_enter_rtv() - Send Request Timeout Value (RTV) request
1182 * @rdata: The remote port to send the RTV request to
Robert Love42e9a922008-12-09 15:10:17 -08001183 *
1184 * Locking Note: The rport lock is expected to be held before calling
1185 * this routine.
1186 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001187static void fc_rport_enter_rtv(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -08001188{
1189 struct fc_frame *fp;
Robert Love42e9a922008-12-09 15:10:17 -08001190 struct fc_lport *lport = rdata->local_port;
1191
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001192 FC_RPORT_DBG(rdata, "Port entered RTV state from %s state\n",
1193 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -08001194
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001195 fc_rport_state_enter(rdata, RPORT_ST_RTV);
Robert Love42e9a922008-12-09 15:10:17 -08001196
1197 fp = fc_frame_alloc(lport, sizeof(struct fc_els_rtv));
1198 if (!fp) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001199 fc_rport_error_retry(rdata, fp);
Robert Love42e9a922008-12-09 15:10:17 -08001200 return;
1201 }
1202
Joe Eykholtf211fa52009-08-25 14:01:01 -07001203 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_RTV,
Joe Eykholtb94f8952009-11-03 11:50:21 -08001204 fc_rport_rtv_resp, rdata,
1205 2 * lport->r_a_tov))
Chris Leech8f550f92009-10-21 16:28:09 -07001206 fc_rport_error_retry(rdata, NULL);
Robert Love42e9a922008-12-09 15:10:17 -08001207 else
Joe Eykholtf211fa52009-08-25 14:01:01 -07001208 kref_get(&rdata->kref);
Robert Love42e9a922008-12-09 15:10:17 -08001209}
1210
1211/**
Joe Eykholt079ecd82010-07-20 15:20:51 -07001212 * fc_rport_logo_resp() - Handler for logout (LOGO) responses
1213 * @sp: The sequence the LOGO was on
1214 * @fp: The LOGO response frame
1215 * @lport_arg: The local port
1216 */
1217static void fc_rport_logo_resp(struct fc_seq *sp, struct fc_frame *fp,
1218 void *lport_arg)
1219{
1220 struct fc_lport *lport = lport_arg;
1221
1222 FC_RPORT_ID_DBG(lport, fc_seq_exch(sp)->did,
1223 "Received a LOGO %s\n", fc_els_resp_type(fp));
1224 if (IS_ERR(fp))
1225 return;
1226 fc_frame_free(fp);
1227}
1228
1229/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001230 * fc_rport_enter_logo() - Send a logout (LOGO) request
1231 * @rdata: The remote port to send the LOGO request to
Robert Love42e9a922008-12-09 15:10:17 -08001232 *
1233 * Locking Note: The rport lock is expected to be held before calling
1234 * this routine.
1235 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001236static void fc_rport_enter_logo(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -08001237{
Robert Love42e9a922008-12-09 15:10:17 -08001238 struct fc_lport *lport = rdata->local_port;
1239 struct fc_frame *fp;
1240
Joe Eykholt079ecd82010-07-20 15:20:51 -07001241 FC_RPORT_DBG(rdata, "Port sending LOGO from %s state\n",
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001242 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -08001243
Robert Love42e9a922008-12-09 15:10:17 -08001244 fp = fc_frame_alloc(lport, sizeof(struct fc_els_logo));
Joe Eykholt079ecd82010-07-20 15:20:51 -07001245 if (!fp)
Robert Love42e9a922008-12-09 15:10:17 -08001246 return;
Joe Eykholt079ecd82010-07-20 15:20:51 -07001247 (void)lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_LOGO,
1248 fc_rport_logo_resp, lport, 0);
Robert Love42e9a922008-12-09 15:10:17 -08001249}
1250
Robert Love42e9a922008-12-09 15:10:17 -08001251/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001252 * fc_rport_els_adisc_resp() - Handler for Address Discovery (ADISC) responses
1253 * @sp: The sequence the ADISC response was on
1254 * @fp: The ADISC response frame
1255 * @rdata_arg: The remote port that sent the ADISC response
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001256 *
1257 * Locking Note: This function will be called without the rport lock
1258 * held, but it will lock, call an _enter_* function or fc_rport_error
1259 * and then unlock the rport.
1260 */
1261static void fc_rport_adisc_resp(struct fc_seq *sp, struct fc_frame *fp,
Robert Love3a3b42b2009-11-03 11:47:39 -08001262 void *rdata_arg)
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001263{
1264 struct fc_rport_priv *rdata = rdata_arg;
1265 struct fc_els_adisc *adisc;
1266 u8 op;
1267
1268 mutex_lock(&rdata->rp_mutex);
1269
1270 FC_RPORT_DBG(rdata, "Received a ADISC response\n");
1271
1272 if (rdata->rp_state != RPORT_ST_ADISC) {
1273 FC_RPORT_DBG(rdata, "Received a ADISC resp but in state %s\n",
1274 fc_rport_state(rdata));
1275 if (IS_ERR(fp))
1276 goto err;
1277 goto out;
1278 }
1279
1280 if (IS_ERR(fp)) {
1281 fc_rport_error(rdata, fp);
1282 goto err;
1283 }
1284
1285 /*
1286 * If address verification failed. Consider us logged out of the rport.
1287 * Since the rport is still in discovery, we want to be
1288 * logged in, so go to PLOGI state. Otherwise, go back to READY.
1289 */
1290 op = fc_frame_payload_op(fp);
1291 adisc = fc_frame_payload_get(fp, sizeof(*adisc));
1292 if (op != ELS_LS_ACC || !adisc ||
1293 ntoh24(adisc->adisc_port_id) != rdata->ids.port_id ||
1294 get_unaligned_be64(&adisc->adisc_wwpn) != rdata->ids.port_name ||
1295 get_unaligned_be64(&adisc->adisc_wwnn) != rdata->ids.node_name) {
1296 FC_RPORT_DBG(rdata, "ADISC error or mismatch\n");
Joe Eykholta7b12a22010-07-20 15:20:08 -07001297 fc_rport_enter_flogi(rdata);
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001298 } else {
1299 FC_RPORT_DBG(rdata, "ADISC OK\n");
1300 fc_rport_enter_ready(rdata);
1301 }
1302out:
1303 fc_frame_free(fp);
1304err:
1305 mutex_unlock(&rdata->rp_mutex);
1306 kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
1307}
1308
1309/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001310 * fc_rport_enter_adisc() - Send Address Discover (ADISC) request
1311 * @rdata: The remote port to send the ADISC request to
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001312 *
1313 * Locking Note: The rport lock is expected to be held before calling
1314 * this routine.
1315 */
1316static void fc_rport_enter_adisc(struct fc_rport_priv *rdata)
1317{
1318 struct fc_lport *lport = rdata->local_port;
1319 struct fc_frame *fp;
1320
1321 FC_RPORT_DBG(rdata, "sending ADISC from %s state\n",
1322 fc_rport_state(rdata));
1323
1324 fc_rport_state_enter(rdata, RPORT_ST_ADISC);
1325
1326 fp = fc_frame_alloc(lport, sizeof(struct fc_els_adisc));
1327 if (!fp) {
1328 fc_rport_error_retry(rdata, fp);
1329 return;
1330 }
1331 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_ADISC,
Joe Eykholtb94f8952009-11-03 11:50:21 -08001332 fc_rport_adisc_resp, rdata,
1333 2 * lport->r_a_tov))
Chris Leech8f550f92009-10-21 16:28:09 -07001334 fc_rport_error_retry(rdata, NULL);
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001335 else
1336 kref_get(&rdata->kref);
1337}
1338
1339/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001340 * fc_rport_recv_adisc_req() - Handler for Address Discovery (ADISC) requests
1341 * @rdata: The remote port that sent the ADISC request
Robert Love3a3b42b2009-11-03 11:47:39 -08001342 * @in_fp: The ADISC request frame
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001343 *
1344 * Locking Note: Called with the lport and rport locks held.
1345 */
1346static void fc_rport_recv_adisc_req(struct fc_rport_priv *rdata,
Joe Eykholt92261152010-07-20 15:21:12 -07001347 struct fc_frame *in_fp)
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001348{
1349 struct fc_lport *lport = rdata->local_port;
1350 struct fc_frame *fp;
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001351 struct fc_els_adisc *adisc;
1352 struct fc_seq_els_data rjt_data;
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001353
1354 FC_RPORT_DBG(rdata, "Received ADISC request\n");
1355
1356 adisc = fc_frame_payload_get(in_fp, sizeof(*adisc));
1357 if (!adisc) {
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001358 rjt_data.reason = ELS_RJT_PROT;
1359 rjt_data.explan = ELS_EXPL_INV_LEN;
Joe Eykholt92261152010-07-20 15:21:12 -07001360 lport->tt.seq_els_rsp_send(in_fp, ELS_LS_RJT, &rjt_data);
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001361 goto drop;
1362 }
1363
1364 fp = fc_frame_alloc(lport, sizeof(*adisc));
1365 if (!fp)
1366 goto drop;
1367 fc_adisc_fill(lport, fp);
1368 adisc = fc_frame_payload_get(fp, sizeof(*adisc));
1369 adisc->adisc_cmd = ELS_LS_ACC;
Joe Eykholt24f089e2010-07-20 15:21:01 -07001370 fc_fill_reply_hdr(fp, in_fp, FC_RCTL_ELS_REP, 0);
1371 lport->tt.frame_send(lport, fp);
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001372drop:
1373 fc_frame_free(in_fp);
1374}
1375
1376/**
Yi Zou63e27fb2009-11-20 14:55:24 -08001377 * fc_rport_recv_rls_req() - Handle received Read Link Status request
1378 * @rdata: The remote port that sent the RLS request
Yi Zou63e27fb2009-11-20 14:55:24 -08001379 * @rx_fp: The PRLI request frame
1380 *
1381 * Locking Note: The rport lock is expected to be held before calling
1382 * this function.
1383 */
1384static void fc_rport_recv_rls_req(struct fc_rport_priv *rdata,
Joe Eykholt92261152010-07-20 15:21:12 -07001385 struct fc_frame *rx_fp)
Yi Zou63e27fb2009-11-20 14:55:24 -08001386
1387{
1388 struct fc_lport *lport = rdata->local_port;
1389 struct fc_frame *fp;
Yi Zou63e27fb2009-11-20 14:55:24 -08001390 struct fc_els_rls *rls;
1391 struct fc_els_rls_resp *rsp;
1392 struct fc_els_lesb *lesb;
1393 struct fc_seq_els_data rjt_data;
1394 struct fc_host_statistics *hst;
Yi Zou63e27fb2009-11-20 14:55:24 -08001395
1396 FC_RPORT_DBG(rdata, "Received RLS request while in state %s\n",
1397 fc_rport_state(rdata));
1398
1399 rls = fc_frame_payload_get(rx_fp, sizeof(*rls));
1400 if (!rls) {
1401 rjt_data.reason = ELS_RJT_PROT;
1402 rjt_data.explan = ELS_EXPL_INV_LEN;
1403 goto out_rjt;
1404 }
1405
1406 fp = fc_frame_alloc(lport, sizeof(*rsp));
1407 if (!fp) {
1408 rjt_data.reason = ELS_RJT_UNAB;
1409 rjt_data.explan = ELS_EXPL_INSUF_RES;
1410 goto out_rjt;
1411 }
1412
1413 rsp = fc_frame_payload_get(fp, sizeof(*rsp));
1414 memset(rsp, 0, sizeof(*rsp));
1415 rsp->rls_cmd = ELS_LS_ACC;
1416 lesb = &rsp->rls_lesb;
1417 if (lport->tt.get_lesb) {
1418 /* get LESB from LLD if it supports it */
1419 lport->tt.get_lesb(lport, lesb);
1420 } else {
1421 fc_get_host_stats(lport->host);
1422 hst = &lport->host_stats;
1423 lesb->lesb_link_fail = htonl(hst->link_failure_count);
1424 lesb->lesb_sync_loss = htonl(hst->loss_of_sync_count);
1425 lesb->lesb_sig_loss = htonl(hst->loss_of_signal_count);
1426 lesb->lesb_prim_err = htonl(hst->prim_seq_protocol_err_count);
1427 lesb->lesb_inv_word = htonl(hst->invalid_tx_word_count);
1428 lesb->lesb_inv_crc = htonl(hst->invalid_crc_count);
1429 }
1430
Joe Eykholt24f089e2010-07-20 15:21:01 -07001431 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
1432 lport->tt.frame_send(lport, fp);
Yi Zou63e27fb2009-11-20 14:55:24 -08001433 goto out;
1434
1435out_rjt:
Joe Eykholt92261152010-07-20 15:21:12 -07001436 lport->tt.seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
Yi Zou63e27fb2009-11-20 14:55:24 -08001437out:
1438 fc_frame_free(rx_fp);
1439}
1440
1441/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001442 * fc_rport_recv_els_req() - Handler for validated ELS requests
1443 * @lport: The local port that received the ELS request
Robert Love3a3b42b2009-11-03 11:47:39 -08001444 * @fp: The ELS request frame
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001445 *
1446 * Handle incoming ELS requests that require port login.
1447 * The ELS opcode has already been validated by the caller.
Robert Love42e9a922008-12-09 15:10:17 -08001448 *
Joe Eykholt131203a2009-08-25 14:03:10 -07001449 * Locking Note: Called with the lport lock held.
Robert Love42e9a922008-12-09 15:10:17 -08001450 */
Joe Eykholt92261152010-07-20 15:21:12 -07001451static void fc_rport_recv_els_req(struct fc_lport *lport, struct fc_frame *fp)
Robert Love42e9a922008-12-09 15:10:17 -08001452{
Joe Eykholt131203a2009-08-25 14:03:10 -07001453 struct fc_rport_priv *rdata;
Robert Love42e9a922008-12-09 15:10:17 -08001454 struct fc_seq_els_data els_data;
Robert Love42e9a922008-12-09 15:10:17 -08001455
Joe Eykholt25b37b92009-08-25 14:03:15 -07001456 mutex_lock(&lport->disc.disc_mutex);
Joe Eykholt251748a2010-07-20 15:20:56 -07001457 rdata = lport->tt.rport_lookup(lport, fc_frame_sid(fp));
Joe Eykholt131203a2009-08-25 14:03:10 -07001458 if (!rdata) {
Joe Eykholt25b37b92009-08-25 14:03:15 -07001459 mutex_unlock(&lport->disc.disc_mutex);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001460 goto reject;
Joe Eykholt131203a2009-08-25 14:03:10 -07001461 }
1462 mutex_lock(&rdata->rp_mutex);
Joe Eykholt25b37b92009-08-25 14:03:15 -07001463 mutex_unlock(&lport->disc.disc_mutex);
Joe Eykholt131203a2009-08-25 14:03:10 -07001464
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001465 switch (rdata->rp_state) {
1466 case RPORT_ST_PRLI:
1467 case RPORT_ST_RTV:
1468 case RPORT_ST_READY:
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001469 case RPORT_ST_ADISC:
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001470 break;
1471 default:
1472 mutex_unlock(&rdata->rp_mutex);
1473 goto reject;
1474 }
1475
1476 switch (fc_frame_payload_op(fp)) {
Joe Eykholt131203a2009-08-25 14:03:10 -07001477 case ELS_PRLI:
Joe Eykholt92261152010-07-20 15:21:12 -07001478 fc_rport_recv_prli_req(rdata, fp);
Joe Eykholt131203a2009-08-25 14:03:10 -07001479 break;
1480 case ELS_PRLO:
Joe Eykholt92261152010-07-20 15:21:12 -07001481 fc_rport_recv_prlo_req(rdata, fp);
Joe Eykholt131203a2009-08-25 14:03:10 -07001482 break;
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001483 case ELS_ADISC:
Joe Eykholt92261152010-07-20 15:21:12 -07001484 fc_rport_recv_adisc_req(rdata, fp);
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001485 break;
Joe Eykholt131203a2009-08-25 14:03:10 -07001486 case ELS_RRQ:
Joe Eykholt92261152010-07-20 15:21:12 -07001487 lport->tt.seq_els_rsp_send(fp, ELS_RRQ, NULL);
1488 fc_frame_free(fp);
Joe Eykholt131203a2009-08-25 14:03:10 -07001489 break;
1490 case ELS_REC:
Joe Eykholt92261152010-07-20 15:21:12 -07001491 lport->tt.seq_els_rsp_send(fp, ELS_REC, NULL);
1492 fc_frame_free(fp);
Joe Eykholt131203a2009-08-25 14:03:10 -07001493 break;
Yi Zou63e27fb2009-11-20 14:55:24 -08001494 case ELS_RLS:
Joe Eykholt92261152010-07-20 15:21:12 -07001495 fc_rport_recv_rls_req(rdata, fp);
Yi Zou63e27fb2009-11-20 14:55:24 -08001496 break;
Joe Eykholt131203a2009-08-25 14:03:10 -07001497 default:
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001498 fc_frame_free(fp); /* can't happen */
Joe Eykholt131203a2009-08-25 14:03:10 -07001499 break;
Robert Love42e9a922008-12-09 15:10:17 -08001500 }
1501
1502 mutex_unlock(&rdata->rp_mutex);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001503 return;
1504
1505reject:
Joe Eykholt92261152010-07-20 15:21:12 -07001506 els_data.reason = ELS_RJT_UNAB;
1507 els_data.explan = ELS_EXPL_PLOGI_REQD;
1508 lport->tt.seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001509 fc_frame_free(fp);
1510}
1511
1512/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001513 * fc_rport_recv_req() - Handler for requests
Robert Love3a3b42b2009-11-03 11:47:39 -08001514 * @lport: The local port that received the request
Joe Eykholt92261152010-07-20 15:21:12 -07001515 * @fp: The request frame
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001516 *
1517 * Locking Note: Called with the lport lock held.
1518 */
Joe Eykholt92261152010-07-20 15:21:12 -07001519void fc_rport_recv_req(struct fc_lport *lport, struct fc_frame *fp)
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001520{
1521 struct fc_seq_els_data els_data;
1522
1523 /*
Joe Eykholta7b12a22010-07-20 15:20:08 -07001524 * Handle FLOGI, PLOGI and LOGO requests separately, since they
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001525 * don't require prior login.
1526 * Check for unsupported opcodes first and reject them.
1527 * For some ops, it would be incorrect to reject with "PLOGI required".
1528 */
1529 switch (fc_frame_payload_op(fp)) {
Joe Eykholta7b12a22010-07-20 15:20:08 -07001530 case ELS_FLOGI:
Joe Eykholt92261152010-07-20 15:21:12 -07001531 fc_rport_recv_flogi_req(lport, fp);
Joe Eykholta7b12a22010-07-20 15:20:08 -07001532 break;
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001533 case ELS_PLOGI:
Joe Eykholt92261152010-07-20 15:21:12 -07001534 fc_rport_recv_plogi_req(lport, fp);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001535 break;
1536 case ELS_LOGO:
Joe Eykholt92261152010-07-20 15:21:12 -07001537 fc_rport_recv_logo_req(lport, fp);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001538 break;
1539 case ELS_PRLI:
1540 case ELS_PRLO:
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001541 case ELS_ADISC:
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001542 case ELS_RRQ:
1543 case ELS_REC:
Yi Zou63e27fb2009-11-20 14:55:24 -08001544 case ELS_RLS:
Joe Eykholt92261152010-07-20 15:21:12 -07001545 fc_rport_recv_els_req(lport, fp);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001546 break;
1547 default:
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001548 els_data.reason = ELS_RJT_UNSUP;
1549 els_data.explan = ELS_EXPL_NONE;
Joe Eykholt92261152010-07-20 15:21:12 -07001550 lport->tt.seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
1551 fc_frame_free(fp);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001552 break;
1553 }
Robert Love42e9a922008-12-09 15:10:17 -08001554}
1555
1556/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001557 * fc_rport_recv_plogi_req() - Handler for Port Login (PLOGI) requests
1558 * @lport: The local port that received the PLOGI request
Robert Love3a3b42b2009-11-03 11:47:39 -08001559 * @rx_fp: The PLOGI request frame
Robert Love42e9a922008-12-09 15:10:17 -08001560 *
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001561 * Locking Note: The rport lock is held before calling this function.
Robert Love42e9a922008-12-09 15:10:17 -08001562 */
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001563static void fc_rport_recv_plogi_req(struct fc_lport *lport,
Joe Eykholt92261152010-07-20 15:21:12 -07001564 struct fc_frame *rx_fp)
Robert Love42e9a922008-12-09 15:10:17 -08001565{
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001566 struct fc_disc *disc;
1567 struct fc_rport_priv *rdata;
Robert Love42e9a922008-12-09 15:10:17 -08001568 struct fc_frame *fp = rx_fp;
Robert Love42e9a922008-12-09 15:10:17 -08001569 struct fc_els_flogi *pl;
1570 struct fc_seq_els_data rjt_data;
Joe Eykholt24f089e2010-07-20 15:21:01 -07001571 u32 sid;
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001572
Joe Eykholt251748a2010-07-20 15:20:56 -07001573 sid = fc_frame_sid(fp);
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001574
1575 FC_RPORT_ID_DBG(lport, sid, "Received PLOGI request\n");
1576
Robert Love42e9a922008-12-09 15:10:17 -08001577 pl = fc_frame_payload_get(fp, sizeof(*pl));
1578 if (!pl) {
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001579 FC_RPORT_ID_DBG(lport, sid, "Received PLOGI too short\n");
1580 rjt_data.reason = ELS_RJT_PROT;
1581 rjt_data.explan = ELS_EXPL_INV_LEN;
1582 goto reject;
Robert Love42e9a922008-12-09 15:10:17 -08001583 }
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001584
1585 disc = &lport->disc;
1586 mutex_lock(&disc->disc_mutex);
1587 rdata = lport->tt.rport_create(lport, sid);
1588 if (!rdata) {
1589 mutex_unlock(&disc->disc_mutex);
1590 rjt_data.reason = ELS_RJT_UNAB;
1591 rjt_data.explan = ELS_EXPL_INSUF_RES;
1592 goto reject;
1593 }
1594
1595 mutex_lock(&rdata->rp_mutex);
1596 mutex_unlock(&disc->disc_mutex);
1597
1598 rdata->ids.port_name = get_unaligned_be64(&pl->fl_wwpn);
1599 rdata->ids.node_name = get_unaligned_be64(&pl->fl_wwnn);
Robert Love42e9a922008-12-09 15:10:17 -08001600
1601 /*
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001602 * If the rport was just created, possibly due to the incoming PLOGI,
Robert Love42e9a922008-12-09 15:10:17 -08001603 * set the state appropriately and accept the PLOGI.
1604 *
1605 * If we had also sent a PLOGI, and if the received PLOGI is from a
1606 * higher WWPN, we accept it, otherwise an LS_RJT is sent with reason
1607 * "command already in progress".
1608 *
1609 * XXX TBD: If the session was ready before, the PLOGI should result in
1610 * all outstanding exchanges being reset.
1611 */
1612 switch (rdata->rp_state) {
1613 case RPORT_ST_INIT:
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001614 FC_RPORT_DBG(rdata, "Received PLOGI in INIT state\n");
Robert Love42e9a922008-12-09 15:10:17 -08001615 break;
Joe Eykholta7b12a22010-07-20 15:20:08 -07001616 case RPORT_ST_PLOGI_WAIT:
1617 FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI_WAIT state\n");
1618 break;
Robert Love42e9a922008-12-09 15:10:17 -08001619 case RPORT_ST_PLOGI:
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001620 FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI state\n");
1621 if (rdata->ids.port_name < lport->wwpn) {
1622 mutex_unlock(&rdata->rp_mutex);
1623 rjt_data.reason = ELS_RJT_INPROG;
1624 rjt_data.explan = ELS_EXPL_NONE;
1625 goto reject;
1626 }
Robert Love42e9a922008-12-09 15:10:17 -08001627 break;
1628 case RPORT_ST_PRLI:
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -07001629 case RPORT_ST_RTV:
Robert Love42e9a922008-12-09 15:10:17 -08001630 case RPORT_ST_READY:
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001631 case RPORT_ST_ADISC:
1632 FC_RPORT_DBG(rdata, "Received PLOGI in logged-in state %d "
1633 "- ignored for now\n", rdata->rp_state);
1634 /* XXX TBD - should reset */
Robert Love42e9a922008-12-09 15:10:17 -08001635 break;
Joe Eykholta7b12a22010-07-20 15:20:08 -07001636 case RPORT_ST_FLOGI:
Joe Eykholt14194052009-07-29 17:04:43 -07001637 case RPORT_ST_DELETE:
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -07001638 FC_RPORT_DBG(rdata, "Received PLOGI in state %s - send busy\n",
1639 fc_rport_state(rdata));
1640 mutex_unlock(&rdata->rp_mutex);
1641 rjt_data.reason = ELS_RJT_BUSY;
1642 rjt_data.explan = ELS_EXPL_NONE;
1643 goto reject;
Robert Love42e9a922008-12-09 15:10:17 -08001644 }
1645
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001646 /*
1647 * Get session payload size from incoming PLOGI.
1648 */
1649 rdata->maxframe_size = fc_plogi_get_maxframe(pl, lport->mfs);
Robert Love42e9a922008-12-09 15:10:17 -08001650
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001651 /*
1652 * Send LS_ACC. If this fails, the originator should retry.
1653 */
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001654 fp = fc_frame_alloc(lport, sizeof(*pl));
1655 if (!fp)
1656 goto out;
Robert Love42e9a922008-12-09 15:10:17 -08001657
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001658 fc_plogi_fill(lport, fp, ELS_LS_ACC);
Joe Eykholt24f089e2010-07-20 15:21:01 -07001659 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
1660 lport->tt.frame_send(lport, fp);
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001661 fc_rport_enter_prli(rdata);
1662out:
1663 mutex_unlock(&rdata->rp_mutex);
Joe Eykholt24f089e2010-07-20 15:21:01 -07001664 fc_frame_free(rx_fp);
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001665 return;
1666
1667reject:
Joe Eykholt92261152010-07-20 15:21:12 -07001668 lport->tt.seq_els_rsp_send(fp, ELS_LS_RJT, &rjt_data);
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001669 fc_frame_free(fp);
Robert Love42e9a922008-12-09 15:10:17 -08001670}
1671
1672/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001673 * fc_rport_recv_prli_req() - Handler for process login (PRLI) requests
1674 * @rdata: The remote port that sent the PRLI request
Robert Love3a3b42b2009-11-03 11:47:39 -08001675 * @rx_fp: The PRLI request frame
Robert Love42e9a922008-12-09 15:10:17 -08001676 *
1677 * Locking Note: The rport lock is exected to be held before calling
1678 * this function.
1679 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001680static void fc_rport_recv_prli_req(struct fc_rport_priv *rdata,
Joe Eykholt92261152010-07-20 15:21:12 -07001681 struct fc_frame *rx_fp)
Robert Love42e9a922008-12-09 15:10:17 -08001682{
Robert Love42e9a922008-12-09 15:10:17 -08001683 struct fc_lport *lport = rdata->local_port;
Robert Love42e9a922008-12-09 15:10:17 -08001684 struct fc_frame *fp;
Robert Love42e9a922008-12-09 15:10:17 -08001685 struct {
1686 struct fc_els_prli prli;
1687 struct fc_els_spp spp;
1688 } *pp;
1689 struct fc_els_spp *rspp; /* request service param page */
1690 struct fc_els_spp *spp; /* response spp */
1691 unsigned int len;
1692 unsigned int plen;
Robert Love42e9a922008-12-09 15:10:17 -08001693 enum fc_els_spp_resp resp;
Joe Eykholt96ad8462011-01-28 16:04:02 -08001694 enum fc_els_spp_resp passive;
Robert Love42e9a922008-12-09 15:10:17 -08001695 struct fc_seq_els_data rjt_data;
Joe Eykholt96ad8462011-01-28 16:04:02 -08001696 struct fc4_prov *prov;
Robert Love42e9a922008-12-09 15:10:17 -08001697
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001698 FC_RPORT_DBG(rdata, "Received PRLI request while in state %s\n",
1699 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -08001700
Joe Eykholt251748a2010-07-20 15:20:56 -07001701 len = fr_len(rx_fp) - sizeof(struct fc_frame_header);
Robert Love42e9a922008-12-09 15:10:17 -08001702 pp = fc_frame_payload_get(rx_fp, sizeof(*pp));
Joe Eykholta2f6a022010-03-12 16:07:36 -08001703 if (!pp)
1704 goto reject_len;
1705 plen = ntohs(pp->prli.prli_len);
1706 if ((plen % 4) != 0 || plen > len || plen < 16)
1707 goto reject_len;
1708 if (plen < len)
1709 len = plen;
1710 plen = pp->prli.prli_spp_len;
1711 if ((plen % 4) != 0 || plen < sizeof(*spp) ||
1712 plen > len || len < sizeof(*pp) || plen < 12)
1713 goto reject_len;
1714 rspp = &pp->spp;
1715
1716 fp = fc_frame_alloc(lport, len);
1717 if (!fp) {
1718 rjt_data.reason = ELS_RJT_UNAB;
1719 rjt_data.explan = ELS_EXPL_INSUF_RES;
1720 goto reject;
Robert Love42e9a922008-12-09 15:10:17 -08001721 }
Joe Eykholta2f6a022010-03-12 16:07:36 -08001722 pp = fc_frame_payload_get(fp, len);
1723 WARN_ON(!pp);
1724 memset(pp, 0, len);
1725 pp->prli.prli_cmd = ELS_LS_ACC;
1726 pp->prli.prli_spp_len = plen;
1727 pp->prli.prli_len = htons(len);
1728 len -= sizeof(struct fc_els_prli);
Robert Love42e9a922008-12-09 15:10:17 -08001729
Joe Eykholta2f6a022010-03-12 16:07:36 -08001730 /*
1731 * Go through all the service parameter pages and build
1732 * response. If plen indicates longer SPP than standard,
1733 * use that. The entire response has been pre-cleared above.
1734 */
1735 spp = &pp->spp;
Joe Eykholt96ad8462011-01-28 16:04:02 -08001736 mutex_lock(&fc_prov_mutex);
Joe Eykholta2f6a022010-03-12 16:07:36 -08001737 while (len >= plen) {
Bhanu Prakash Gollapudi75a27922011-01-28 16:05:27 -08001738 rdata->spp_type = rspp->spp_type;
Joe Eykholta2f6a022010-03-12 16:07:36 -08001739 spp->spp_type = rspp->spp_type;
1740 spp->spp_type_ext = rspp->spp_type_ext;
Joe Eykholt96ad8462011-01-28 16:04:02 -08001741 resp = 0;
Robert Love42e9a922008-12-09 15:10:17 -08001742
Joe Eykholt96ad8462011-01-28 16:04:02 -08001743 if (rspp->spp_type < FC_FC4_PROV_SIZE) {
1744 prov = fc_active_prov[rspp->spp_type];
1745 if (prov)
1746 resp = prov->prli(rdata, plen, rspp, spp);
1747 prov = fc_passive_prov[rspp->spp_type];
1748 if (prov) {
1749 passive = prov->prli(rdata, plen, rspp, spp);
1750 if (!resp || passive == FC_SPP_RESP_ACK)
1751 resp = passive;
1752 }
1753 }
1754 if (!resp) {
1755 if (spp->spp_flags & FC_SPP_EST_IMG_PAIR)
1756 resp |= FC_SPP_RESP_CONF;
1757 else
1758 resp |= FC_SPP_RESP_INVL;
Robert Love42e9a922008-12-09 15:10:17 -08001759 }
Joe Eykholta2f6a022010-03-12 16:07:36 -08001760 spp->spp_flags |= resp;
1761 len -= plen;
1762 rspp = (struct fc_els_spp *)((char *)rspp + plen);
1763 spp = (struct fc_els_spp *)((char *)spp + plen);
Robert Love42e9a922008-12-09 15:10:17 -08001764 }
Joe Eykholt96ad8462011-01-28 16:04:02 -08001765 mutex_unlock(&fc_prov_mutex);
Joe Eykholta2f6a022010-03-12 16:07:36 -08001766
1767 /*
1768 * Send LS_ACC. If this fails, the originator should retry.
1769 */
Joe Eykholt24f089e2010-07-20 15:21:01 -07001770 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
1771 lport->tt.frame_send(lport, fp);
Joe Eykholta2f6a022010-03-12 16:07:36 -08001772
1773 switch (rdata->rp_state) {
1774 case RPORT_ST_PRLI:
1775 fc_rport_enter_ready(rdata);
1776 break;
1777 default:
1778 break;
1779 }
1780 goto drop;
1781
1782reject_len:
1783 rjt_data.reason = ELS_RJT_PROT;
1784 rjt_data.explan = ELS_EXPL_INV_LEN;
1785reject:
Joe Eykholt92261152010-07-20 15:21:12 -07001786 lport->tt.seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
Joe Eykholta2f6a022010-03-12 16:07:36 -08001787drop:
Robert Love42e9a922008-12-09 15:10:17 -08001788 fc_frame_free(rx_fp);
1789}
1790
1791/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001792 * fc_rport_recv_prlo_req() - Handler for process logout (PRLO) requests
1793 * @rdata: The remote port that sent the PRLO request
Bhanu Prakash Gollapudif8fc6c22010-06-11 16:44:04 -07001794 * @rx_fp: The PRLO request frame
Robert Love42e9a922008-12-09 15:10:17 -08001795 *
1796 * Locking Note: The rport lock is exected to be held before calling
1797 * this function.
1798 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001799static void fc_rport_recv_prlo_req(struct fc_rport_priv *rdata,
Bhanu Prakash Gollapudif8fc6c22010-06-11 16:44:04 -07001800 struct fc_frame *rx_fp)
Robert Love42e9a922008-12-09 15:10:17 -08001801{
Robert Love42e9a922008-12-09 15:10:17 -08001802 struct fc_lport *lport = rdata->local_port;
Bhanu Prakash Gollapudif8fc6c22010-06-11 16:44:04 -07001803 struct fc_frame *fp;
1804 struct {
1805 struct fc_els_prlo prlo;
1806 struct fc_els_spp spp;
1807 } *pp;
1808 struct fc_els_spp *rspp; /* request service param page */
1809 struct fc_els_spp *spp; /* response spp */
1810 unsigned int len;
1811 unsigned int plen;
Robert Love42e9a922008-12-09 15:10:17 -08001812 struct fc_seq_els_data rjt_data;
1813
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001814 FC_RPORT_DBG(rdata, "Received PRLO request while in state %s\n",
1815 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -08001816
Joe Eykholt251748a2010-07-20 15:20:56 -07001817 len = fr_len(rx_fp) - sizeof(struct fc_frame_header);
Bhanu Prakash Gollapudif8fc6c22010-06-11 16:44:04 -07001818 pp = fc_frame_payload_get(rx_fp, sizeof(*pp));
1819 if (!pp)
1820 goto reject_len;
1821 plen = ntohs(pp->prlo.prlo_len);
1822 if (plen != 20)
1823 goto reject_len;
1824 if (plen < len)
1825 len = plen;
1826
1827 rspp = &pp->spp;
1828
1829 fp = fc_frame_alloc(lport, len);
1830 if (!fp) {
1831 rjt_data.reason = ELS_RJT_UNAB;
1832 rjt_data.explan = ELS_EXPL_INSUF_RES;
1833 goto reject;
1834 }
1835
Bhanu Prakash Gollapudif8fc6c22010-06-11 16:44:04 -07001836 pp = fc_frame_payload_get(fp, len);
1837 WARN_ON(!pp);
1838 memset(pp, 0, len);
1839 pp->prlo.prlo_cmd = ELS_LS_ACC;
1840 pp->prlo.prlo_obs = 0x10;
1841 pp->prlo.prlo_len = htons(len);
1842 spp = &pp->spp;
1843 spp->spp_type = rspp->spp_type;
1844 spp->spp_type_ext = rspp->spp_type_ext;
1845 spp->spp_flags = FC_SPP_RESP_ACK;
1846
1847 fc_rport_enter_delete(rdata, RPORT_EV_LOGO);
1848
Joe Eykholt92261152010-07-20 15:21:12 -07001849 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
1850 lport->tt.frame_send(lport, fp);
Bhanu Prakash Gollapudif8fc6c22010-06-11 16:44:04 -07001851 goto drop;
1852
1853reject_len:
1854 rjt_data.reason = ELS_RJT_PROT;
1855 rjt_data.explan = ELS_EXPL_INV_LEN;
1856reject:
Joe Eykholt92261152010-07-20 15:21:12 -07001857 lport->tt.seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
Bhanu Prakash Gollapudif8fc6c22010-06-11 16:44:04 -07001858drop:
1859 fc_frame_free(rx_fp);
Robert Love42e9a922008-12-09 15:10:17 -08001860}
1861
1862/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001863 * fc_rport_recv_logo_req() - Handler for logout (LOGO) requests
1864 * @lport: The local port that received the LOGO request
Robert Love3a3b42b2009-11-03 11:47:39 -08001865 * @fp: The LOGO request frame
Robert Love42e9a922008-12-09 15:10:17 -08001866 *
1867 * Locking Note: The rport lock is exected to be held before calling
1868 * this function.
1869 */
Joe Eykholt92261152010-07-20 15:21:12 -07001870static void fc_rport_recv_logo_req(struct fc_lport *lport, struct fc_frame *fp)
Robert Love42e9a922008-12-09 15:10:17 -08001871{
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001872 struct fc_rport_priv *rdata;
1873 u32 sid;
Robert Love42e9a922008-12-09 15:10:17 -08001874
Joe Eykholt92261152010-07-20 15:21:12 -07001875 lport->tt.seq_els_rsp_send(fp, ELS_LS_ACC, NULL);
Joe Eykholtfeab4ae2009-08-25 14:03:36 -07001876
Joe Eykholt251748a2010-07-20 15:20:56 -07001877 sid = fc_frame_sid(fp);
Robert Love42e9a922008-12-09 15:10:17 -08001878
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001879 mutex_lock(&lport->disc.disc_mutex);
1880 rdata = lport->tt.rport_lookup(lport, sid);
1881 if (rdata) {
1882 mutex_lock(&rdata->rp_mutex);
1883 FC_RPORT_DBG(rdata, "Received LOGO request while in state %s\n",
1884 fc_rport_state(rdata));
Joe Eykholtfeab4ae2009-08-25 14:03:36 -07001885
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -07001886 fc_rport_enter_delete(rdata, RPORT_EV_LOGO);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001887 mutex_unlock(&rdata->rp_mutex);
1888 } else
1889 FC_RPORT_ID_DBG(lport, sid,
1890 "Received LOGO from non-logged-in port\n");
1891 mutex_unlock(&lport->disc.disc_mutex);
Robert Love42e9a922008-12-09 15:10:17 -08001892 fc_frame_free(fp);
1893}
1894
Robert Love3a3b42b2009-11-03 11:47:39 -08001895/**
1896 * fc_rport_flush_queue() - Flush the rport_event_queue
1897 */
Robert Love42e9a922008-12-09 15:10:17 -08001898static void fc_rport_flush_queue(void)
1899{
1900 flush_workqueue(rport_event_queue);
1901}
1902
Robert Love3a3b42b2009-11-03 11:47:39 -08001903/**
1904 * fc_rport_init() - Initialize the remote port layer for a local port
1905 * @lport: The local port to initialize the remote port layer for
1906 */
Robert Love42e9a922008-12-09 15:10:17 -08001907int fc_rport_init(struct fc_lport *lport)
1908{
Joe Eykholt8025b5d2009-08-25 14:02:06 -07001909 if (!lport->tt.rport_lookup)
1910 lport->tt.rport_lookup = fc_rport_lookup;
1911
Robert Love5101ff92009-02-27 10:55:18 -08001912 if (!lport->tt.rport_create)
Joe Eykholt9e9d0452009-08-25 14:01:18 -07001913 lport->tt.rport_create = fc_rport_create;
Robert Love5101ff92009-02-27 10:55:18 -08001914
Robert Love42e9a922008-12-09 15:10:17 -08001915 if (!lport->tt.rport_login)
1916 lport->tt.rport_login = fc_rport_login;
1917
1918 if (!lport->tt.rport_logoff)
1919 lport->tt.rport_logoff = fc_rport_logoff;
1920
1921 if (!lport->tt.rport_recv_req)
1922 lport->tt.rport_recv_req = fc_rport_recv_req;
1923
1924 if (!lport->tt.rport_flush_queue)
1925 lport->tt.rport_flush_queue = fc_rport_flush_queue;
1926
Joe Eykholtf211fa52009-08-25 14:01:01 -07001927 if (!lport->tt.rport_destroy)
1928 lport->tt.rport_destroy = fc_rport_destroy;
1929
Robert Love42e9a922008-12-09 15:10:17 -08001930 return 0;
1931}
1932EXPORT_SYMBOL(fc_rport_init);
1933
Robert Love3a3b42b2009-11-03 11:47:39 -08001934/**
Joe Eykholt96ad8462011-01-28 16:04:02 -08001935 * fc_rport_fcp_prli() - Handle incoming PRLI for the FCP initiator.
1936 * @rdata: remote port private
1937 * @spp_len: service parameter page length
1938 * @rspp: received service parameter page
1939 * @spp: response service parameter page
1940 *
1941 * Returns the value for the response code to be placed in spp_flags;
1942 * Returns 0 if not an initiator.
1943 */
1944static int fc_rport_fcp_prli(struct fc_rport_priv *rdata, u32 spp_len,
1945 const struct fc_els_spp *rspp,
1946 struct fc_els_spp *spp)
1947{
1948 struct fc_lport *lport = rdata->local_port;
1949 u32 fcp_parm;
1950
1951 fcp_parm = ntohl(rspp->spp_params);
1952 rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
1953 if (fcp_parm & FCP_SPPF_INIT_FCN)
1954 rdata->ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1955 if (fcp_parm & FCP_SPPF_TARG_FCN)
1956 rdata->ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1957 if (fcp_parm & FCP_SPPF_RETRY)
1958 rdata->flags |= FC_RP_FLAGS_RETRY;
1959 rdata->supported_classes = FC_COS_CLASS3;
1960
1961 if (!(lport->service_params & FC_RPORT_ROLE_FCP_INITIATOR))
1962 return 0;
1963
1964 spp->spp_flags |= rspp->spp_flags & FC_SPP_EST_IMG_PAIR;
1965
1966 /*
1967 * OR in our service parameters with other providers (target), if any.
1968 */
1969 fcp_parm = ntohl(spp->spp_params);
1970 spp->spp_params = htonl(fcp_parm | lport->service_params);
1971 return FC_SPP_RESP_ACK;
1972}
1973
1974/*
1975 * FC-4 provider ops for FCP initiator.
1976 */
1977struct fc4_prov fc_rport_fcp_init = {
1978 .prli = fc_rport_fcp_prli,
1979};
1980
1981/**
1982 * fc_rport_t0_prli() - Handle incoming PRLI parameters for type 0
1983 * @rdata: remote port private
1984 * @spp_len: service parameter page length
1985 * @rspp: received service parameter page
1986 * @spp: response service parameter page
1987 */
1988static int fc_rport_t0_prli(struct fc_rport_priv *rdata, u32 spp_len,
1989 const struct fc_els_spp *rspp,
1990 struct fc_els_spp *spp)
1991{
1992 if (rspp->spp_flags & FC_SPP_EST_IMG_PAIR)
1993 return FC_SPP_RESP_INVL;
1994 return FC_SPP_RESP_ACK;
1995}
1996
1997/*
1998 * FC-4 provider ops for type 0 service parameters.
1999 *
2000 * This handles the special case of type 0 which is always successful
2001 * but doesn't do anything otherwise.
2002 */
2003struct fc4_prov fc_rport_t0_prov = {
2004 .prli = fc_rport_t0_prli,
2005};
2006
2007/**
Robert Love3a3b42b2009-11-03 11:47:39 -08002008 * fc_setup_rport() - Initialize the rport_event_queue
2009 */
Randy Dunlap55204902011-01-28 16:03:57 -08002010int fc_setup_rport(void)
Robert Love42e9a922008-12-09 15:10:17 -08002011{
2012 rport_event_queue = create_singlethread_workqueue("fc_rport_eq");
2013 if (!rport_event_queue)
2014 return -ENOMEM;
2015 return 0;
2016}
Robert Love42e9a922008-12-09 15:10:17 -08002017
Robert Love3a3b42b2009-11-03 11:47:39 -08002018/**
2019 * fc_destroy_rport() - Destroy the rport_event_queue
2020 */
Randy Dunlap55204902011-01-28 16:03:57 -08002021void fc_destroy_rport(void)
Robert Love42e9a922008-12-09 15:10:17 -08002022{
2023 destroy_workqueue(rport_event_queue);
2024}
Robert Love42e9a922008-12-09 15:10:17 -08002025
Robert Love3a3b42b2009-11-03 11:47:39 -08002026/**
2027 * fc_rport_terminate_io() - Stop all outstanding I/O on a remote port
2028 * @rport: The remote port whose I/O should be terminated
2029 */
Robert Love42e9a922008-12-09 15:10:17 -08002030void fc_rport_terminate_io(struct fc_rport *rport)
2031{
Robert Love3a3b42b2009-11-03 11:47:39 -08002032 struct fc_rport_libfc_priv *rpriv = rport->dd_data;
2033 struct fc_lport *lport = rpriv->local_port;
Robert Love42e9a922008-12-09 15:10:17 -08002034
Abhijeet Joglekar1f6ff362009-02-27 10:54:35 -08002035 lport->tt.exch_mgr_reset(lport, 0, rport->port_id);
2036 lport->tt.exch_mgr_reset(lport, rport->port_id, 0);
Robert Love42e9a922008-12-09 15:10:17 -08002037}
2038EXPORT_SYMBOL(fc_rport_terminate_io);