blob: 3b669377406655b4b4758be67e091bfd82f4b12a [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);
Parikh, Neeravfe5e3f12011-02-25 15:02:51 -0800360 kref_put(&rdata->kref, lport->tt.rport_destroy);
Joe Eykholtf0342602010-06-11 16:44:57 -0700361 } else if ((rdata->flags & FC_RP_STARTED) &&
362 rdata->major_retries <
363 lport->max_rport_retry_count) {
364 rdata->major_retries++;
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700365 rdata->event = RPORT_EV_NONE;
366 FC_RPORT_DBG(rdata, "work restart\n");
Joe Eykholta7b12a22010-07-20 15:20:08 -0700367 fc_rport_enter_flogi(rdata);
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700368 mutex_unlock(&rdata->rp_mutex);
369 } else {
370 FC_RPORT_DBG(rdata, "work delete\n");
Joe Eykholt42e90412010-07-20 15:19:37 -0700371 list_del_rcu(&rdata->peers);
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700372 mutex_unlock(&rdata->rp_mutex);
373 kref_put(&rdata->kref, lport->tt.rport_destroy);
374 }
375 } else {
376 /*
377 * Re-open for events. Reissue READY event if ready.
378 */
379 rdata->event = RPORT_EV_NONE;
380 if (rdata->rp_state == RPORT_ST_READY)
381 fc_rport_enter_ready(rdata);
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -0700382 mutex_unlock(&rdata->rp_mutex);
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700383 }
384 mutex_unlock(&lport->disc.disc_mutex);
Joe Eykholt629f4422009-08-25 14:01:06 -0700385 break;
386
387 default:
Robert Love42e9a922008-12-09 15:10:17 -0800388 mutex_unlock(&rdata->rp_mutex);
Joe Eykholt629f4422009-08-25 14:01:06 -0700389 break;
390 }
Robert Love42e9a922008-12-09 15:10:17 -0800391}
392
393/**
Robert Love34f42a02009-02-27 10:55:45 -0800394 * fc_rport_login() - Start the remote port login state machine
Robert Love3a3b42b2009-11-03 11:47:39 -0800395 * @rdata: The remote port to be logged in to
Robert Love42e9a922008-12-09 15:10:17 -0800396 *
397 * Locking Note: Called without the rport lock held. This
398 * function will hold the rport lock, call an _enter_*
399 * function and then unlock the rport.
Joe Eykholt370c3bd2009-08-25 14:03:47 -0700400 *
401 * This indicates the intent to be logged into the remote port.
402 * If it appears we are already logged in, ADISC is used to verify
403 * the setup.
Robert Love42e9a922008-12-09 15:10:17 -0800404 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700405int fc_rport_login(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800406{
Robert Love42e9a922008-12-09 15:10:17 -0800407 mutex_lock(&rdata->rp_mutex);
408
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700409 rdata->flags |= FC_RP_STARTED;
Joe Eykholt370c3bd2009-08-25 14:03:47 -0700410 switch (rdata->rp_state) {
411 case RPORT_ST_READY:
412 FC_RPORT_DBG(rdata, "ADISC port\n");
413 fc_rport_enter_adisc(rdata);
414 break;
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -0700415 case RPORT_ST_DELETE:
416 FC_RPORT_DBG(rdata, "Restart deleted port\n");
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -0700417 break;
Joe Eykholt370c3bd2009-08-25 14:03:47 -0700418 default:
419 FC_RPORT_DBG(rdata, "Login to port\n");
Joe Eykholta7b12a22010-07-20 15:20:08 -0700420 fc_rport_enter_flogi(rdata);
Joe Eykholt370c3bd2009-08-25 14:03:47 -0700421 break;
422 }
Robert Love42e9a922008-12-09 15:10:17 -0800423 mutex_unlock(&rdata->rp_mutex);
424
425 return 0;
426}
427
428/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800429 * fc_rport_enter_delete() - Schedule a remote port to be deleted
430 * @rdata: The remote port to be deleted
431 * @event: The event to report as the reason for deletion
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700432 *
433 * Locking Note: Called with the rport lock held.
434 *
435 * Allow state change into DELETE only once.
436 *
437 * Call queue_work only if there's no event already pending.
438 * Set the new event so that the old pending event will not occur.
439 * Since we have the mutex, even if fc_rport_work() is already started,
440 * it'll see the new event.
441 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700442static void fc_rport_enter_delete(struct fc_rport_priv *rdata,
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700443 enum fc_rport_event event)
444{
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700445 if (rdata->rp_state == RPORT_ST_DELETE)
446 return;
447
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700448 FC_RPORT_DBG(rdata, "Delete port\n");
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700449
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700450 fc_rport_state_enter(rdata, RPORT_ST_DELETE);
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700451
452 if (rdata->event == RPORT_EV_NONE)
453 queue_work(rport_event_queue, &rdata->event_work);
454 rdata->event = event;
455}
456
457/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800458 * fc_rport_logoff() - Logoff and remove a remote port
459 * @rdata: The remote port to be logged off of
Robert Love42e9a922008-12-09 15:10:17 -0800460 *
461 * Locking Note: Called without the rport lock held. This
462 * function will hold the rport lock, call an _enter_*
463 * function and then unlock the rport.
464 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700465int fc_rport_logoff(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800466{
Robert Love42e9a922008-12-09 15:10:17 -0800467 mutex_lock(&rdata->rp_mutex);
468
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700469 FC_RPORT_DBG(rdata, "Remove port\n");
Robert Love42e9a922008-12-09 15:10:17 -0800470
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700471 rdata->flags &= ~FC_RP_STARTED;
Joe Eykholt14194052009-07-29 17:04:43 -0700472 if (rdata->rp_state == RPORT_ST_DELETE) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700473 FC_RPORT_DBG(rdata, "Port in Delete state, not removing\n");
Abhijeet Joglekarb4c6f542009-04-21 16:27:04 -0700474 goto out;
475 }
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700476 fc_rport_enter_logo(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800477
478 /*
Joe Eykholt14194052009-07-29 17:04:43 -0700479 * Change the state to Delete so that we discard
Robert Love42e9a922008-12-09 15:10:17 -0800480 * the response.
481 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700482 fc_rport_enter_delete(rdata, RPORT_EV_STOP);
Abhijeet Joglekarb4c6f542009-04-21 16:27:04 -0700483out:
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -0700484 mutex_unlock(&rdata->rp_mutex);
Robert Love42e9a922008-12-09 15:10:17 -0800485 return 0;
486}
487
488/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800489 * fc_rport_enter_ready() - Transition to the RPORT_ST_READY state
490 * @rdata: The remote port that is ready
Robert Love42e9a922008-12-09 15:10:17 -0800491 *
492 * Locking Note: The rport lock is expected to be held before calling
493 * this routine.
494 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700495static void fc_rport_enter_ready(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800496{
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700497 fc_rport_state_enter(rdata, RPORT_ST_READY);
Robert Love42e9a922008-12-09 15:10:17 -0800498
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700499 FC_RPORT_DBG(rdata, "Port is Ready\n");
Robert Love42e9a922008-12-09 15:10:17 -0800500
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700501 if (rdata->event == RPORT_EV_NONE)
502 queue_work(rport_event_queue, &rdata->event_work);
Joe Eykholt4c0f62b2009-08-25 14:01:12 -0700503 rdata->event = RPORT_EV_READY;
Robert Love42e9a922008-12-09 15:10:17 -0800504}
505
506/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800507 * fc_rport_timeout() - Handler for the retry_work timer
508 * @work: Handle to the remote port that has timed out
Robert Love42e9a922008-12-09 15:10:17 -0800509 *
510 * Locking Note: Called without the rport lock held. This
511 * function will hold the rport lock, call an _enter_*
512 * function and then unlock the rport.
513 */
514static void fc_rport_timeout(struct work_struct *work)
515{
Joe Eykholtab28f1f2009-08-25 14:00:34 -0700516 struct fc_rport_priv *rdata =
517 container_of(work, struct fc_rport_priv, retry_work.work);
Robert Love42e9a922008-12-09 15:10:17 -0800518
519 mutex_lock(&rdata->rp_mutex);
520
521 switch (rdata->rp_state) {
Joe Eykholta7b12a22010-07-20 15:20:08 -0700522 case RPORT_ST_FLOGI:
523 fc_rport_enter_flogi(rdata);
524 break;
Robert Love42e9a922008-12-09 15:10:17 -0800525 case RPORT_ST_PLOGI:
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700526 fc_rport_enter_plogi(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800527 break;
528 case RPORT_ST_PRLI:
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700529 fc_rport_enter_prli(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800530 break;
531 case RPORT_ST_RTV:
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700532 fc_rport_enter_rtv(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800533 break;
Joe Eykholt370c3bd2009-08-25 14:03:47 -0700534 case RPORT_ST_ADISC:
535 fc_rport_enter_adisc(rdata);
536 break;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700537 case RPORT_ST_PLOGI_WAIT:
Robert Love42e9a922008-12-09 15:10:17 -0800538 case RPORT_ST_READY:
539 case RPORT_ST_INIT:
Joe Eykholt14194052009-07-29 17:04:43 -0700540 case RPORT_ST_DELETE:
Robert Love42e9a922008-12-09 15:10:17 -0800541 break;
542 }
543
544 mutex_unlock(&rdata->rp_mutex);
Robert Love42e9a922008-12-09 15:10:17 -0800545}
546
547/**
Robert Love34f42a02009-02-27 10:55:45 -0800548 * fc_rport_error() - Error handler, called once retries have been exhausted
Robert Love3a3b42b2009-11-03 11:47:39 -0800549 * @rdata: The remote port the error is happened on
550 * @fp: The error code encapsulated in a frame pointer
Robert Love42e9a922008-12-09 15:10:17 -0800551 *
Robert Love42e9a922008-12-09 15:10:17 -0800552 * Locking Note: The rport lock is expected to be held before
553 * calling this routine
554 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700555static void fc_rport_error(struct fc_rport_priv *rdata, struct fc_frame *fp)
Robert Love42e9a922008-12-09 15:10:17 -0800556{
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700557 FC_RPORT_DBG(rdata, "Error %ld in state %s, retries %d\n",
Joe Eykholtcdbe6df2009-08-25 14:01:39 -0700558 IS_ERR(fp) ? -PTR_ERR(fp) : 0,
559 fc_rport_state(rdata), rdata->retries);
Robert Love42e9a922008-12-09 15:10:17 -0800560
Chris Leech6755db12009-02-27 10:55:02 -0800561 switch (rdata->rp_state) {
Joe Eykholta7b12a22010-07-20 15:20:08 -0700562 case RPORT_ST_FLOGI:
Chris Leech6755db12009-02-27 10:55:02 -0800563 case RPORT_ST_PLOGI:
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700564 rdata->flags &= ~FC_RP_STARTED;
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700565 fc_rport_enter_delete(rdata, RPORT_EV_FAILED);
Chris Leech6755db12009-02-27 10:55:02 -0800566 break;
567 case RPORT_ST_RTV:
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700568 fc_rport_enter_ready(rdata);
Chris Leech6755db12009-02-27 10:55:02 -0800569 break;
Joe Eykholt370c3bd2009-08-25 14:03:47 -0700570 case RPORT_ST_PRLI:
571 case RPORT_ST_ADISC:
572 fc_rport_enter_logo(rdata);
573 break;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700574 case RPORT_ST_PLOGI_WAIT:
Joe Eykholt14194052009-07-29 17:04:43 -0700575 case RPORT_ST_DELETE:
Chris Leech6755db12009-02-27 10:55:02 -0800576 case RPORT_ST_READY:
577 case RPORT_ST_INIT:
578 break;
Robert Love42e9a922008-12-09 15:10:17 -0800579 }
580}
581
582/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800583 * fc_rport_error_retry() - Handler for remote port state retries
584 * @rdata: The remote port whose state is to be retried
585 * @fp: The error code encapsulated in a frame pointer
Chris Leech6755db12009-02-27 10:55:02 -0800586 *
587 * If the error was an exchange timeout retry immediately,
588 * otherwise wait for E_D_TOV.
589 *
590 * Locking Note: The rport lock is expected to be held before
591 * calling this routine
592 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700593static void fc_rport_error_retry(struct fc_rport_priv *rdata,
594 struct fc_frame *fp)
Chris Leech6755db12009-02-27 10:55:02 -0800595{
Chris Leech6755db12009-02-27 10:55:02 -0800596 unsigned long delay = FC_DEF_E_D_TOV;
597
598 /* make sure this isn't an FC_EX_CLOSED error, never retry those */
599 if (PTR_ERR(fp) == -FC_EX_CLOSED)
Hillf Danton28a4af12011-01-28 16:03:26 -0800600 goto out;
Chris Leech6755db12009-02-27 10:55:02 -0800601
Abhijeet Joglekara3666952009-05-01 10:01:26 -0700602 if (rdata->retries < rdata->local_port->max_rport_retry_count) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700603 FC_RPORT_DBG(rdata, "Error %ld in state %s, retrying\n",
604 PTR_ERR(fp), fc_rport_state(rdata));
Chris Leech6755db12009-02-27 10:55:02 -0800605 rdata->retries++;
606 /* no additional delay on exchange timeouts */
607 if (PTR_ERR(fp) == -FC_EX_TIMEOUT)
608 delay = 0;
Chris Leech6755db12009-02-27 10:55:02 -0800609 schedule_delayed_work(&rdata->retry_work, delay);
610 return;
611 }
612
Hillf Danton28a4af12011-01-28 16:03:26 -0800613out:
614 fc_rport_error(rdata, fp);
Chris Leech6755db12009-02-27 10:55:02 -0800615}
616
617/**
Joe Eykholta7b12a22010-07-20 15:20:08 -0700618 * fc_rport_login_complete() - Handle parameters and completion of p-mp login.
619 * @rdata: The remote port which we logged into or which logged into us.
620 * @fp: The FLOGI or PLOGI request or response frame
621 *
622 * Returns non-zero error if a problem is detected with the frame.
623 * Does not free the frame.
624 *
625 * This is only used in point-to-multipoint mode for FIP currently.
626 */
627static int fc_rport_login_complete(struct fc_rport_priv *rdata,
628 struct fc_frame *fp)
629{
630 struct fc_lport *lport = rdata->local_port;
631 struct fc_els_flogi *flogi;
632 unsigned int e_d_tov;
633 u16 csp_flags;
634
635 flogi = fc_frame_payload_get(fp, sizeof(*flogi));
636 if (!flogi)
637 return -EINVAL;
638
639 csp_flags = ntohs(flogi->fl_csp.sp_features);
640
641 if (fc_frame_payload_op(fp) == ELS_FLOGI) {
642 if (csp_flags & FC_SP_FT_FPORT) {
643 FC_RPORT_DBG(rdata, "Fabric bit set in FLOGI\n");
644 return -EINVAL;
645 }
646 } else {
647
648 /*
649 * E_D_TOV is not valid on an incoming FLOGI request.
650 */
651 e_d_tov = ntohl(flogi->fl_csp.sp_e_d_tov);
652 if (csp_flags & FC_SP_FT_EDTR)
653 e_d_tov /= 1000000;
654 if (e_d_tov > rdata->e_d_tov)
655 rdata->e_d_tov = e_d_tov;
656 }
657 rdata->maxframe_size = fc_plogi_get_maxframe(flogi, lport->mfs);
658 return 0;
659}
660
661/**
662 * fc_rport_flogi_resp() - Handle response to FLOGI request for p-mp mode
663 * @sp: The sequence that the FLOGI was on
664 * @fp: The FLOGI response frame
665 * @rp_arg: The remote port that received the FLOGI response
666 */
667void fc_rport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp,
668 void *rp_arg)
669{
670 struct fc_rport_priv *rdata = rp_arg;
671 struct fc_lport *lport = rdata->local_port;
672 struct fc_els_flogi *flogi;
673 unsigned int r_a_tov;
674
675 FC_RPORT_DBG(rdata, "Received a FLOGI %s\n", fc_els_resp_type(fp));
676
677 if (fp == ERR_PTR(-FC_EX_CLOSED))
Hillf Danton0e9e3d32010-11-30 16:19:04 -0800678 goto put;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700679
680 mutex_lock(&rdata->rp_mutex);
681
682 if (rdata->rp_state != RPORT_ST_FLOGI) {
683 FC_RPORT_DBG(rdata, "Received a FLOGI response, but in state "
684 "%s\n", fc_rport_state(rdata));
685 if (IS_ERR(fp))
686 goto err;
687 goto out;
688 }
689
690 if (IS_ERR(fp)) {
691 fc_rport_error(rdata, fp);
692 goto err;
693 }
694
695 if (fc_frame_payload_op(fp) != ELS_LS_ACC)
696 goto bad;
697 if (fc_rport_login_complete(rdata, fp))
698 goto bad;
699
700 flogi = fc_frame_payload_get(fp, sizeof(*flogi));
701 if (!flogi)
702 goto bad;
703 r_a_tov = ntohl(flogi->fl_csp.sp_r_a_tov);
704 if (r_a_tov > rdata->r_a_tov)
705 rdata->r_a_tov = r_a_tov;
706
707 if (rdata->ids.port_name < lport->wwpn)
708 fc_rport_enter_plogi(rdata);
709 else
710 fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
711out:
712 fc_frame_free(fp);
713err:
714 mutex_unlock(&rdata->rp_mutex);
Hillf Danton0e9e3d32010-11-30 16:19:04 -0800715put:
Joe Eykholta7b12a22010-07-20 15:20:08 -0700716 kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
717 return;
718bad:
719 FC_RPORT_DBG(rdata, "Bad FLOGI response\n");
720 fc_rport_error_retry(rdata, fp);
721 goto out;
722}
723
724/**
725 * fc_rport_enter_flogi() - Send a FLOGI request to the remote port for p-mp
726 * @rdata: The remote port to send a FLOGI to
727 *
728 * Locking Note: The rport lock is expected to be held before calling
729 * this routine.
730 */
731static void fc_rport_enter_flogi(struct fc_rport_priv *rdata)
732{
733 struct fc_lport *lport = rdata->local_port;
734 struct fc_frame *fp;
735
736 if (!lport->point_to_multipoint)
737 return fc_rport_enter_plogi(rdata);
738
739 FC_RPORT_DBG(rdata, "Entered FLOGI state from %s state\n",
740 fc_rport_state(rdata));
741
742 fc_rport_state_enter(rdata, RPORT_ST_FLOGI);
743
744 fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi));
745 if (!fp)
746 return fc_rport_error_retry(rdata, fp);
747
748 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_FLOGI,
749 fc_rport_flogi_resp, rdata,
750 2 * lport->r_a_tov))
751 fc_rport_error_retry(rdata, NULL);
752 else
753 kref_get(&rdata->kref);
754}
755
756/**
757 * fc_rport_recv_flogi_req() - Handle Fabric Login (FLOGI) request in p-mp mode
758 * @lport: The local port that received the PLOGI request
Joe Eykholta7b12a22010-07-20 15:20:08 -0700759 * @rx_fp: The PLOGI request frame
760 */
761static void fc_rport_recv_flogi_req(struct fc_lport *lport,
Joe Eykholt92261152010-07-20 15:21:12 -0700762 struct fc_frame *rx_fp)
Joe Eykholta7b12a22010-07-20 15:20:08 -0700763{
764 struct fc_disc *disc;
765 struct fc_els_flogi *flp;
766 struct fc_rport_priv *rdata;
767 struct fc_frame *fp = rx_fp;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700768 struct fc_seq_els_data rjt_data;
Joe Eykholt24f089e2010-07-20 15:21:01 -0700769 u32 sid;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700770
Joe Eykholt251748a2010-07-20 15:20:56 -0700771 sid = fc_frame_sid(fp);
Joe Eykholta7b12a22010-07-20 15:20:08 -0700772
773 FC_RPORT_ID_DBG(lport, sid, "Received FLOGI request\n");
774
775 disc = &lport->disc;
776 mutex_lock(&disc->disc_mutex);
777
778 if (!lport->point_to_multipoint) {
779 rjt_data.reason = ELS_RJT_UNSUP;
780 rjt_data.explan = ELS_EXPL_NONE;
781 goto reject;
782 }
783
784 flp = fc_frame_payload_get(fp, sizeof(*flp));
785 if (!flp) {
786 rjt_data.reason = ELS_RJT_LOGIC;
787 rjt_data.explan = ELS_EXPL_INV_LEN;
788 goto reject;
789 }
790
791 rdata = lport->tt.rport_lookup(lport, sid);
792 if (!rdata) {
793 rjt_data.reason = ELS_RJT_FIP;
794 rjt_data.explan = ELS_EXPL_NOT_NEIGHBOR;
795 goto reject;
796 }
797 mutex_lock(&rdata->rp_mutex);
798
799 FC_RPORT_DBG(rdata, "Received FLOGI in %s state\n",
800 fc_rport_state(rdata));
801
802 switch (rdata->rp_state) {
803 case RPORT_ST_INIT:
Kiran Patil48058482011-06-20 16:58:59 -0700804 /*
805 * If received the FLOGI request on RPORT which is INIT state
806 * (means not transition to FLOGI either fc_rport timeout
807 * function didn;t trigger or this end hasn;t received
808 * beacon yet from other end. In that case only, allow RPORT
809 * state machine to continue, otherwise fall through which
810 * causes the code to send reject response.
811 * NOTE; Not checking for FIP->state such as VNMP_UP or
812 * VNMP_CLAIM because if FIP state is not one of those,
813 * RPORT wouldn;t have created and 'rport_lookup' would have
814 * failed anyway in that case.
815 */
816 if (lport->point_to_multipoint)
817 break;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700818 case RPORT_ST_DELETE:
819 mutex_unlock(&rdata->rp_mutex);
820 rjt_data.reason = ELS_RJT_FIP;
821 rjt_data.explan = ELS_EXPL_NOT_NEIGHBOR;
822 goto reject;
823 case RPORT_ST_FLOGI:
824 case RPORT_ST_PLOGI_WAIT:
825 case RPORT_ST_PLOGI:
826 break;
827 case RPORT_ST_PRLI:
828 case RPORT_ST_RTV:
829 case RPORT_ST_READY:
830 case RPORT_ST_ADISC:
831 /*
832 * Set the remote port to be deleted and to then restart.
833 * This queues work to be sure exchanges are reset.
834 */
835 fc_rport_enter_delete(rdata, RPORT_EV_LOGO);
836 mutex_unlock(&rdata->rp_mutex);
837 rjt_data.reason = ELS_RJT_BUSY;
838 rjt_data.explan = ELS_EXPL_NONE;
839 goto reject;
840 }
841 if (fc_rport_login_complete(rdata, fp)) {
842 mutex_unlock(&rdata->rp_mutex);
843 rjt_data.reason = ELS_RJT_LOGIC;
844 rjt_data.explan = ELS_EXPL_NONE;
845 goto reject;
846 }
Joe Eykholta7b12a22010-07-20 15:20:08 -0700847
848 fp = fc_frame_alloc(lport, sizeof(*flp));
849 if (!fp)
850 goto out;
851
Joe Eykholta7b12a22010-07-20 15:20:08 -0700852 fc_flogi_fill(lport, fp);
853 flp = fc_frame_payload_get(fp, sizeof(*flp));
854 flp->fl_cmd = ELS_LS_ACC;
855
Joe Eykholt24f089e2010-07-20 15:21:01 -0700856 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
857 lport->tt.frame_send(lport, fp);
Joe Eykholta7b12a22010-07-20 15:20:08 -0700858
859 if (rdata->ids.port_name < lport->wwpn)
860 fc_rport_enter_plogi(rdata);
861 else
862 fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
863out:
864 mutex_unlock(&rdata->rp_mutex);
865 mutex_unlock(&disc->disc_mutex);
Joe Eykholt24f089e2010-07-20 15:21:01 -0700866 fc_frame_free(rx_fp);
Joe Eykholta7b12a22010-07-20 15:20:08 -0700867 return;
868
869reject:
870 mutex_unlock(&disc->disc_mutex);
Joe Eykholt92261152010-07-20 15:21:12 -0700871 lport->tt.seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
Joe Eykholt24f089e2010-07-20 15:21:01 -0700872 fc_frame_free(rx_fp);
Joe Eykholta7b12a22010-07-20 15:20:08 -0700873}
874
875/**
876 * fc_rport_plogi_resp() - Handler for ELS PLOGI responses
Robert Love3a3b42b2009-11-03 11:47:39 -0800877 * @sp: The sequence the PLOGI is on
878 * @fp: The PLOGI response frame
879 * @rdata_arg: The remote port that sent the PLOGI response
Robert Love42e9a922008-12-09 15:10:17 -0800880 *
881 * Locking Note: This function will be called without the rport lock
882 * held, but it will lock, call an _enter_* function or fc_rport_error
883 * and then unlock the rport.
884 */
885static void fc_rport_plogi_resp(struct fc_seq *sp, struct fc_frame *fp,
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700886 void *rdata_arg)
Robert Love42e9a922008-12-09 15:10:17 -0800887{
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700888 struct fc_rport_priv *rdata = rdata_arg;
Robert Love42e9a922008-12-09 15:10:17 -0800889 struct fc_lport *lport = rdata->local_port;
Robert Lovea29e7642009-04-21 16:27:41 -0700890 struct fc_els_flogi *plp = NULL;
Robert Love42e9a922008-12-09 15:10:17 -0800891 u16 csp_seq;
892 u16 cssp_seq;
893 u8 op;
894
895 mutex_lock(&rdata->rp_mutex);
896
Joe Eykholtf657d292009-08-25 14:03:21 -0700897 FC_RPORT_DBG(rdata, "Received a PLOGI %s\n", fc_els_resp_type(fp));
Robert Love42e9a922008-12-09 15:10:17 -0800898
899 if (rdata->rp_state != RPORT_ST_PLOGI) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700900 FC_RPORT_DBG(rdata, "Received a PLOGI response, but in state "
901 "%s\n", fc_rport_state(rdata));
Abhijeet Joglekar76f68042009-04-21 16:26:58 -0700902 if (IS_ERR(fp))
903 goto err;
Robert Love42e9a922008-12-09 15:10:17 -0800904 goto out;
905 }
906
Abhijeet Joglekar76f68042009-04-21 16:26:58 -0700907 if (IS_ERR(fp)) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700908 fc_rport_error_retry(rdata, fp);
Abhijeet Joglekar76f68042009-04-21 16:26:58 -0700909 goto err;
910 }
911
Robert Love42e9a922008-12-09 15:10:17 -0800912 op = fc_frame_payload_op(fp);
913 if (op == ELS_LS_ACC &&
914 (plp = fc_frame_payload_get(fp, sizeof(*plp))) != NULL) {
Joe Eykholtf211fa52009-08-25 14:01:01 -0700915 rdata->ids.port_name = get_unaligned_be64(&plp->fl_wwpn);
916 rdata->ids.node_name = get_unaligned_be64(&plp->fl_wwnn);
Robert Love42e9a922008-12-09 15:10:17 -0800917
Bhanu Prakash Gollapudi75a27922011-01-28 16:05:27 -0800918 /* save plogi response sp_features for further reference */
919 rdata->sp_features = ntohs(plp->fl_csp.sp_features);
920
Joe Eykholta7b12a22010-07-20 15:20:08 -0700921 if (lport->point_to_multipoint)
922 fc_rport_login_complete(rdata, fp);
Robert Love42e9a922008-12-09 15:10:17 -0800923 csp_seq = ntohs(plp->fl_csp.sp_tot_seq);
924 cssp_seq = ntohs(plp->fl_cssp[3 - 1].cp_con_seq);
925 if (cssp_seq < csp_seq)
926 csp_seq = cssp_seq;
927 rdata->max_seq = csp_seq;
Joe Eykholtf211fa52009-08-25 14:01:01 -0700928 rdata->maxframe_size = fc_plogi_get_maxframe(plp, lport->mfs);
Joe Eykholt3ac6f982009-08-25 14:03:26 -0700929 fc_rport_enter_prli(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800930 } else
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700931 fc_rport_error_retry(rdata, fp);
Robert Love42e9a922008-12-09 15:10:17 -0800932
933out:
934 fc_frame_free(fp);
935err:
936 mutex_unlock(&rdata->rp_mutex);
Joe Eykholtf211fa52009-08-25 14:01:01 -0700937 kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
Robert Love42e9a922008-12-09 15:10:17 -0800938}
939
940/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800941 * fc_rport_enter_plogi() - Send Port Login (PLOGI) request
942 * @rdata: The remote port to send a PLOGI to
Robert Love42e9a922008-12-09 15:10:17 -0800943 *
944 * Locking Note: The rport lock is expected to be held before calling
945 * this routine.
946 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700947static void fc_rport_enter_plogi(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800948{
Robert Love42e9a922008-12-09 15:10:17 -0800949 struct fc_lport *lport = rdata->local_port;
950 struct fc_frame *fp;
951
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700952 FC_RPORT_DBG(rdata, "Port entered PLOGI state from %s state\n",
953 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -0800954
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700955 fc_rport_state_enter(rdata, RPORT_ST_PLOGI);
Robert Love42e9a922008-12-09 15:10:17 -0800956
Joe Eykholtf211fa52009-08-25 14:01:01 -0700957 rdata->maxframe_size = FC_MIN_MAX_PAYLOAD;
Robert Love42e9a922008-12-09 15:10:17 -0800958 fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi));
959 if (!fp) {
Joe Eykholta7b12a22010-07-20 15:20:08 -0700960 FC_RPORT_DBG(rdata, "%s frame alloc failed\n", __func__);
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700961 fc_rport_error_retry(rdata, fp);
Robert Love42e9a922008-12-09 15:10:17 -0800962 return;
963 }
964 rdata->e_d_tov = lport->e_d_tov;
965
Joe Eykholtf211fa52009-08-25 14:01:01 -0700966 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_PLOGI,
Joe Eykholtb94f8952009-11-03 11:50:21 -0800967 fc_rport_plogi_resp, rdata,
968 2 * lport->r_a_tov))
Chris Leech8f550f92009-10-21 16:28:09 -0700969 fc_rport_error_retry(rdata, NULL);
Robert Love42e9a922008-12-09 15:10:17 -0800970 else
Joe Eykholtf211fa52009-08-25 14:01:01 -0700971 kref_get(&rdata->kref);
Robert Love42e9a922008-12-09 15:10:17 -0800972}
973
974/**
Robert Love34f42a02009-02-27 10:55:45 -0800975 * fc_rport_prli_resp() - Process Login (PRLI) response handler
Robert Love3a3b42b2009-11-03 11:47:39 -0800976 * @sp: The sequence the PRLI response was on
977 * @fp: The PRLI response frame
978 * @rdata_arg: The remote port that sent the PRLI response
Robert Love42e9a922008-12-09 15:10:17 -0800979 *
980 * Locking Note: This function will be called without the rport lock
981 * held, but it will lock, call an _enter_* function or fc_rport_error
982 * and then unlock the rport.
983 */
984static void fc_rport_prli_resp(struct fc_seq *sp, struct fc_frame *fp,
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700985 void *rdata_arg)
Robert Love42e9a922008-12-09 15:10:17 -0800986{
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700987 struct fc_rport_priv *rdata = rdata_arg;
Robert Love42e9a922008-12-09 15:10:17 -0800988 struct {
989 struct fc_els_prli prli;
990 struct fc_els_spp spp;
991 } *pp;
Joe Eykholt925ceda2011-01-28 16:04:23 -0800992 struct fc_els_spp temp_spp;
993 struct fc4_prov *prov;
Robert Love42e9a922008-12-09 15:10:17 -0800994 u32 roles = FC_RPORT_ROLE_UNKNOWN;
995 u32 fcp_parm = 0;
996 u8 op;
Bhanu Prakash Gollapudi618461c2010-06-11 16:43:54 -0700997 u8 resp_code = 0;
Robert Love42e9a922008-12-09 15:10:17 -0800998
999 mutex_lock(&rdata->rp_mutex);
1000
Joe Eykholtf657d292009-08-25 14:03:21 -07001001 FC_RPORT_DBG(rdata, "Received a PRLI %s\n", fc_els_resp_type(fp));
Robert Love42e9a922008-12-09 15:10:17 -08001002
1003 if (rdata->rp_state != RPORT_ST_PRLI) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001004 FC_RPORT_DBG(rdata, "Received a PRLI response, but in state "
1005 "%s\n", fc_rport_state(rdata));
Abhijeet Joglekar76f68042009-04-21 16:26:58 -07001006 if (IS_ERR(fp))
1007 goto err;
Robert Love42e9a922008-12-09 15:10:17 -08001008 goto out;
1009 }
1010
Abhijeet Joglekar76f68042009-04-21 16:26:58 -07001011 if (IS_ERR(fp)) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001012 fc_rport_error_retry(rdata, fp);
Abhijeet Joglekar76f68042009-04-21 16:26:58 -07001013 goto err;
1014 }
1015
Robert Love6bd054c2009-08-25 14:03:04 -07001016 /* reinitialize remote port roles */
1017 rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
1018
Robert Love42e9a922008-12-09 15:10:17 -08001019 op = fc_frame_payload_op(fp);
1020 if (op == ELS_LS_ACC) {
1021 pp = fc_frame_payload_get(fp, sizeof(*pp));
Bhanu Prakash Gollapudi618461c2010-06-11 16:43:54 -07001022 if (!pp)
1023 goto out;
1024
1025 resp_code = (pp->spp.spp_flags & FC_SPP_RESP_MASK);
1026 FC_RPORT_DBG(rdata, "PRLI spp_flags = 0x%x\n",
1027 pp->spp.spp_flags);
Bhanu Prakash Gollapudi75a27922011-01-28 16:05:27 -08001028 rdata->spp_type = pp->spp.spp_type;
Bhanu Prakash Gollapudi618461c2010-06-11 16:43:54 -07001029 if (resp_code != FC_SPP_RESP_ACK) {
1030 if (resp_code == FC_SPP_RESP_CONF)
1031 fc_rport_error(rdata, fp);
1032 else
1033 fc_rport_error_retry(rdata, fp);
1034 goto out;
Robert Love42e9a922008-12-09 15:10:17 -08001035 }
Bhanu Prakash Gollapudi618461c2010-06-11 16:43:54 -07001036 if (pp->prli.prli_spp_len < sizeof(pp->spp))
1037 goto out;
1038
1039 fcp_parm = ntohl(pp->spp.spp_params);
1040 if (fcp_parm & FCP_SPPF_RETRY)
1041 rdata->flags |= FC_RP_FLAGS_RETRY;
Bhanu Prakash Gollapudi75a27922011-01-28 16:05:27 -08001042 if (fcp_parm & FCP_SPPF_CONF_COMPL)
1043 rdata->flags |= FC_RP_FLAGS_CONF_REQ;
Robert Love42e9a922008-12-09 15:10:17 -08001044
Joe Eykholt925ceda2011-01-28 16:04:23 -08001045 prov = fc_passive_prov[FC_TYPE_FCP];
1046 if (prov) {
1047 memset(&temp_spp, 0, sizeof(temp_spp));
1048 prov->prli(rdata, pp->prli.prli_spp_len,
1049 &pp->spp, &temp_spp);
1050 }
1051
Joe Eykholtf211fa52009-08-25 14:01:01 -07001052 rdata->supported_classes = FC_COS_CLASS3;
Robert Love42e9a922008-12-09 15:10:17 -08001053 if (fcp_parm & FCP_SPPF_INIT_FCN)
1054 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1055 if (fcp_parm & FCP_SPPF_TARG_FCN)
1056 roles |= FC_RPORT_ROLE_FCP_TARGET;
1057
Joe Eykholtf211fa52009-08-25 14:01:01 -07001058 rdata->ids.roles = roles;
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001059 fc_rport_enter_rtv(rdata);
Robert Love42e9a922008-12-09 15:10:17 -08001060
1061 } else {
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001062 FC_RPORT_DBG(rdata, "Bad ELS response for PRLI command\n");
Bhanu Prakash Gollapudi292e40b2010-06-11 16:43:49 -07001063 fc_rport_error_retry(rdata, fp);
Robert Love42e9a922008-12-09 15:10:17 -08001064 }
1065
1066out:
1067 fc_frame_free(fp);
1068err:
1069 mutex_unlock(&rdata->rp_mutex);
Joe Eykholtf211fa52009-08-25 14:01:01 -07001070 kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
Robert Love42e9a922008-12-09 15:10:17 -08001071}
1072
1073/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001074 * fc_rport_enter_prli() - Send Process Login (PRLI) request
1075 * @rdata: The remote port to send the PRLI request to
Robert Love42e9a922008-12-09 15:10:17 -08001076 *
1077 * Locking Note: The rport lock is expected to be held before calling
1078 * this routine.
1079 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001080static void fc_rport_enter_prli(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -08001081{
Robert Love42e9a922008-12-09 15:10:17 -08001082 struct fc_lport *lport = rdata->local_port;
1083 struct {
1084 struct fc_els_prli prli;
1085 struct fc_els_spp spp;
1086 } *pp;
1087 struct fc_frame *fp;
Joe Eykholt925ceda2011-01-28 16:04:23 -08001088 struct fc4_prov *prov;
Robert Love42e9a922008-12-09 15:10:17 -08001089
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001090 /*
1091 * If the rport is one of the well known addresses
1092 * we skip PRLI and RTV and go straight to READY.
1093 */
1094 if (rdata->ids.port_id >= FC_FID_DOM_MGR) {
1095 fc_rport_enter_ready(rdata);
1096 return;
1097 }
1098
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001099 FC_RPORT_DBG(rdata, "Port entered PRLI state from %s state\n",
1100 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -08001101
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001102 fc_rport_state_enter(rdata, RPORT_ST_PRLI);
Robert Love42e9a922008-12-09 15:10:17 -08001103
1104 fp = fc_frame_alloc(lport, sizeof(*pp));
1105 if (!fp) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001106 fc_rport_error_retry(rdata, fp);
Robert Love42e9a922008-12-09 15:10:17 -08001107 return;
1108 }
1109
Joe Eykholt925ceda2011-01-28 16:04:23 -08001110 fc_prli_fill(lport, fp);
1111
1112 prov = fc_passive_prov[FC_TYPE_FCP];
1113 if (prov) {
1114 pp = fc_frame_payload_get(fp, sizeof(*pp));
1115 prov->prli(rdata, sizeof(pp->spp), NULL, &pp->spp);
1116 }
1117
1118 fc_fill_fc_hdr(fp, FC_RCTL_ELS_REQ, rdata->ids.port_id,
1119 fc_host_port_id(lport->host), FC_TYPE_ELS,
1120 FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0);
1121
1122 if (!lport->tt.exch_seq_send(lport, fp, fc_rport_prli_resp,
1123 NULL, rdata, 2 * lport->r_a_tov))
Chris Leech8f550f92009-10-21 16:28:09 -07001124 fc_rport_error_retry(rdata, NULL);
Robert Love42e9a922008-12-09 15:10:17 -08001125 else
Joe Eykholtf211fa52009-08-25 14:01:01 -07001126 kref_get(&rdata->kref);
Robert Love42e9a922008-12-09 15:10:17 -08001127}
1128
1129/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001130 * fc_rport_els_rtv_resp() - Handler for Request Timeout Value (RTV) responses
1131 * @sp: The sequence the RTV was on
1132 * @fp: The RTV response frame
1133 * @rdata_arg: The remote port that sent the RTV response
Robert Love42e9a922008-12-09 15:10:17 -08001134 *
1135 * Many targets don't seem to support this.
1136 *
1137 * Locking Note: This function will be called without the rport lock
1138 * held, but it will lock, call an _enter_* function or fc_rport_error
1139 * and then unlock the rport.
1140 */
1141static void fc_rport_rtv_resp(struct fc_seq *sp, struct fc_frame *fp,
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001142 void *rdata_arg)
Robert Love42e9a922008-12-09 15:10:17 -08001143{
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001144 struct fc_rport_priv *rdata = rdata_arg;
Robert Love42e9a922008-12-09 15:10:17 -08001145 u8 op;
1146
1147 mutex_lock(&rdata->rp_mutex);
1148
Joe Eykholtf657d292009-08-25 14:03:21 -07001149 FC_RPORT_DBG(rdata, "Received a RTV %s\n", fc_els_resp_type(fp));
Robert Love42e9a922008-12-09 15:10:17 -08001150
1151 if (rdata->rp_state != RPORT_ST_RTV) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001152 FC_RPORT_DBG(rdata, "Received a RTV response, but in state "
1153 "%s\n", fc_rport_state(rdata));
Abhijeet Joglekar76f68042009-04-21 16:26:58 -07001154 if (IS_ERR(fp))
1155 goto err;
Robert Love42e9a922008-12-09 15:10:17 -08001156 goto out;
1157 }
1158
Abhijeet Joglekar76f68042009-04-21 16:26:58 -07001159 if (IS_ERR(fp)) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001160 fc_rport_error(rdata, fp);
Abhijeet Joglekar76f68042009-04-21 16:26:58 -07001161 goto err;
1162 }
1163
Robert Love42e9a922008-12-09 15:10:17 -08001164 op = fc_frame_payload_op(fp);
1165 if (op == ELS_LS_ACC) {
1166 struct fc_els_rtv_acc *rtv;
1167 u32 toq;
1168 u32 tov;
1169
1170 rtv = fc_frame_payload_get(fp, sizeof(*rtv));
1171 if (rtv) {
1172 toq = ntohl(rtv->rtv_toq);
1173 tov = ntohl(rtv->rtv_r_a_tov);
1174 if (tov == 0)
1175 tov = 1;
1176 rdata->r_a_tov = tov;
1177 tov = ntohl(rtv->rtv_e_d_tov);
1178 if (toq & FC_ELS_RTV_EDRES)
1179 tov /= 1000000;
1180 if (tov == 0)
1181 tov = 1;
1182 rdata->e_d_tov = tov;
1183 }
1184 }
1185
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001186 fc_rport_enter_ready(rdata);
Robert Love42e9a922008-12-09 15:10:17 -08001187
1188out:
1189 fc_frame_free(fp);
1190err:
1191 mutex_unlock(&rdata->rp_mutex);
Joe Eykholtf211fa52009-08-25 14:01:01 -07001192 kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
Robert Love42e9a922008-12-09 15:10:17 -08001193}
1194
1195/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001196 * fc_rport_enter_rtv() - Send Request Timeout Value (RTV) request
1197 * @rdata: The remote port to send the RTV request to
Robert Love42e9a922008-12-09 15:10:17 -08001198 *
1199 * Locking Note: The rport lock is expected to be held before calling
1200 * this routine.
1201 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001202static void fc_rport_enter_rtv(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -08001203{
1204 struct fc_frame *fp;
Robert Love42e9a922008-12-09 15:10:17 -08001205 struct fc_lport *lport = rdata->local_port;
1206
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001207 FC_RPORT_DBG(rdata, "Port entered RTV state from %s state\n",
1208 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -08001209
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001210 fc_rport_state_enter(rdata, RPORT_ST_RTV);
Robert Love42e9a922008-12-09 15:10:17 -08001211
1212 fp = fc_frame_alloc(lport, sizeof(struct fc_els_rtv));
1213 if (!fp) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001214 fc_rport_error_retry(rdata, fp);
Robert Love42e9a922008-12-09 15:10:17 -08001215 return;
1216 }
1217
Joe Eykholtf211fa52009-08-25 14:01:01 -07001218 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_RTV,
Joe Eykholtb94f8952009-11-03 11:50:21 -08001219 fc_rport_rtv_resp, rdata,
1220 2 * lport->r_a_tov))
Chris Leech8f550f92009-10-21 16:28:09 -07001221 fc_rport_error_retry(rdata, NULL);
Robert Love42e9a922008-12-09 15:10:17 -08001222 else
Joe Eykholtf211fa52009-08-25 14:01:01 -07001223 kref_get(&rdata->kref);
Robert Love42e9a922008-12-09 15:10:17 -08001224}
1225
1226/**
Joe Eykholt079ecd82010-07-20 15:20:51 -07001227 * fc_rport_logo_resp() - Handler for logout (LOGO) responses
1228 * @sp: The sequence the LOGO was on
1229 * @fp: The LOGO response frame
1230 * @lport_arg: The local port
1231 */
1232static void fc_rport_logo_resp(struct fc_seq *sp, struct fc_frame *fp,
1233 void *lport_arg)
1234{
1235 struct fc_lport *lport = lport_arg;
1236
1237 FC_RPORT_ID_DBG(lport, fc_seq_exch(sp)->did,
1238 "Received a LOGO %s\n", fc_els_resp_type(fp));
1239 if (IS_ERR(fp))
1240 return;
1241 fc_frame_free(fp);
1242}
1243
1244/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001245 * fc_rport_enter_logo() - Send a logout (LOGO) request
1246 * @rdata: The remote port to send the LOGO request to
Robert Love42e9a922008-12-09 15:10:17 -08001247 *
1248 * Locking Note: The rport lock is expected to be held before calling
1249 * this routine.
1250 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001251static void fc_rport_enter_logo(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -08001252{
Robert Love42e9a922008-12-09 15:10:17 -08001253 struct fc_lport *lport = rdata->local_port;
1254 struct fc_frame *fp;
1255
Joe Eykholt079ecd82010-07-20 15:20:51 -07001256 FC_RPORT_DBG(rdata, "Port sending LOGO from %s state\n",
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001257 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -08001258
Robert Love42e9a922008-12-09 15:10:17 -08001259 fp = fc_frame_alloc(lport, sizeof(struct fc_els_logo));
Joe Eykholt079ecd82010-07-20 15:20:51 -07001260 if (!fp)
Robert Love42e9a922008-12-09 15:10:17 -08001261 return;
Joe Eykholt079ecd82010-07-20 15:20:51 -07001262 (void)lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_LOGO,
1263 fc_rport_logo_resp, lport, 0);
Robert Love42e9a922008-12-09 15:10:17 -08001264}
1265
Robert Love42e9a922008-12-09 15:10:17 -08001266/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001267 * fc_rport_els_adisc_resp() - Handler for Address Discovery (ADISC) responses
1268 * @sp: The sequence the ADISC response was on
1269 * @fp: The ADISC response frame
1270 * @rdata_arg: The remote port that sent the ADISC response
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001271 *
1272 * Locking Note: This function will be called without the rport lock
1273 * held, but it will lock, call an _enter_* function or fc_rport_error
1274 * and then unlock the rport.
1275 */
1276static void fc_rport_adisc_resp(struct fc_seq *sp, struct fc_frame *fp,
Robert Love3a3b42b2009-11-03 11:47:39 -08001277 void *rdata_arg)
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001278{
1279 struct fc_rport_priv *rdata = rdata_arg;
1280 struct fc_els_adisc *adisc;
1281 u8 op;
1282
1283 mutex_lock(&rdata->rp_mutex);
1284
1285 FC_RPORT_DBG(rdata, "Received a ADISC response\n");
1286
1287 if (rdata->rp_state != RPORT_ST_ADISC) {
1288 FC_RPORT_DBG(rdata, "Received a ADISC resp but in state %s\n",
1289 fc_rport_state(rdata));
1290 if (IS_ERR(fp))
1291 goto err;
1292 goto out;
1293 }
1294
1295 if (IS_ERR(fp)) {
1296 fc_rport_error(rdata, fp);
1297 goto err;
1298 }
1299
1300 /*
1301 * If address verification failed. Consider us logged out of the rport.
1302 * Since the rport is still in discovery, we want to be
1303 * logged in, so go to PLOGI state. Otherwise, go back to READY.
1304 */
1305 op = fc_frame_payload_op(fp);
1306 adisc = fc_frame_payload_get(fp, sizeof(*adisc));
1307 if (op != ELS_LS_ACC || !adisc ||
1308 ntoh24(adisc->adisc_port_id) != rdata->ids.port_id ||
1309 get_unaligned_be64(&adisc->adisc_wwpn) != rdata->ids.port_name ||
1310 get_unaligned_be64(&adisc->adisc_wwnn) != rdata->ids.node_name) {
1311 FC_RPORT_DBG(rdata, "ADISC error or mismatch\n");
Joe Eykholta7b12a22010-07-20 15:20:08 -07001312 fc_rport_enter_flogi(rdata);
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001313 } else {
1314 FC_RPORT_DBG(rdata, "ADISC OK\n");
1315 fc_rport_enter_ready(rdata);
1316 }
1317out:
1318 fc_frame_free(fp);
1319err:
1320 mutex_unlock(&rdata->rp_mutex);
1321 kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
1322}
1323
1324/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001325 * fc_rport_enter_adisc() - Send Address Discover (ADISC) request
1326 * @rdata: The remote port to send the ADISC request to
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001327 *
1328 * Locking Note: The rport lock is expected to be held before calling
1329 * this routine.
1330 */
1331static void fc_rport_enter_adisc(struct fc_rport_priv *rdata)
1332{
1333 struct fc_lport *lport = rdata->local_port;
1334 struct fc_frame *fp;
1335
1336 FC_RPORT_DBG(rdata, "sending ADISC from %s state\n",
1337 fc_rport_state(rdata));
1338
1339 fc_rport_state_enter(rdata, RPORT_ST_ADISC);
1340
1341 fp = fc_frame_alloc(lport, sizeof(struct fc_els_adisc));
1342 if (!fp) {
1343 fc_rport_error_retry(rdata, fp);
1344 return;
1345 }
1346 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_ADISC,
Joe Eykholtb94f8952009-11-03 11:50:21 -08001347 fc_rport_adisc_resp, rdata,
1348 2 * lport->r_a_tov))
Chris Leech8f550f92009-10-21 16:28:09 -07001349 fc_rport_error_retry(rdata, NULL);
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001350 else
1351 kref_get(&rdata->kref);
1352}
1353
1354/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001355 * fc_rport_recv_adisc_req() - Handler for Address Discovery (ADISC) requests
1356 * @rdata: The remote port that sent the ADISC request
Robert Love3a3b42b2009-11-03 11:47:39 -08001357 * @in_fp: The ADISC request frame
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001358 *
1359 * Locking Note: Called with the lport and rport locks held.
1360 */
1361static void fc_rport_recv_adisc_req(struct fc_rport_priv *rdata,
Joe Eykholt92261152010-07-20 15:21:12 -07001362 struct fc_frame *in_fp)
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001363{
1364 struct fc_lport *lport = rdata->local_port;
1365 struct fc_frame *fp;
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001366 struct fc_els_adisc *adisc;
1367 struct fc_seq_els_data rjt_data;
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001368
1369 FC_RPORT_DBG(rdata, "Received ADISC request\n");
1370
1371 adisc = fc_frame_payload_get(in_fp, sizeof(*adisc));
1372 if (!adisc) {
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001373 rjt_data.reason = ELS_RJT_PROT;
1374 rjt_data.explan = ELS_EXPL_INV_LEN;
Joe Eykholt92261152010-07-20 15:21:12 -07001375 lport->tt.seq_els_rsp_send(in_fp, ELS_LS_RJT, &rjt_data);
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001376 goto drop;
1377 }
1378
1379 fp = fc_frame_alloc(lport, sizeof(*adisc));
1380 if (!fp)
1381 goto drop;
1382 fc_adisc_fill(lport, fp);
1383 adisc = fc_frame_payload_get(fp, sizeof(*adisc));
1384 adisc->adisc_cmd = ELS_LS_ACC;
Joe Eykholt24f089e2010-07-20 15:21:01 -07001385 fc_fill_reply_hdr(fp, in_fp, FC_RCTL_ELS_REP, 0);
1386 lport->tt.frame_send(lport, fp);
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001387drop:
1388 fc_frame_free(in_fp);
1389}
1390
1391/**
Yi Zou63e27fb2009-11-20 14:55:24 -08001392 * fc_rport_recv_rls_req() - Handle received Read Link Status request
1393 * @rdata: The remote port that sent the RLS request
Yi Zou63e27fb2009-11-20 14:55:24 -08001394 * @rx_fp: The PRLI request frame
1395 *
1396 * Locking Note: The rport lock is expected to be held before calling
1397 * this function.
1398 */
1399static void fc_rport_recv_rls_req(struct fc_rport_priv *rdata,
Joe Eykholt92261152010-07-20 15:21:12 -07001400 struct fc_frame *rx_fp)
Yi Zou63e27fb2009-11-20 14:55:24 -08001401
1402{
1403 struct fc_lport *lport = rdata->local_port;
1404 struct fc_frame *fp;
Yi Zou63e27fb2009-11-20 14:55:24 -08001405 struct fc_els_rls *rls;
1406 struct fc_els_rls_resp *rsp;
1407 struct fc_els_lesb *lesb;
1408 struct fc_seq_els_data rjt_data;
1409 struct fc_host_statistics *hst;
Yi Zou63e27fb2009-11-20 14:55:24 -08001410
1411 FC_RPORT_DBG(rdata, "Received RLS request while in state %s\n",
1412 fc_rport_state(rdata));
1413
1414 rls = fc_frame_payload_get(rx_fp, sizeof(*rls));
1415 if (!rls) {
1416 rjt_data.reason = ELS_RJT_PROT;
1417 rjt_data.explan = ELS_EXPL_INV_LEN;
1418 goto out_rjt;
1419 }
1420
1421 fp = fc_frame_alloc(lport, sizeof(*rsp));
1422 if (!fp) {
1423 rjt_data.reason = ELS_RJT_UNAB;
1424 rjt_data.explan = ELS_EXPL_INSUF_RES;
1425 goto out_rjt;
1426 }
1427
1428 rsp = fc_frame_payload_get(fp, sizeof(*rsp));
1429 memset(rsp, 0, sizeof(*rsp));
1430 rsp->rls_cmd = ELS_LS_ACC;
1431 lesb = &rsp->rls_lesb;
1432 if (lport->tt.get_lesb) {
1433 /* get LESB from LLD if it supports it */
1434 lport->tt.get_lesb(lport, lesb);
1435 } else {
1436 fc_get_host_stats(lport->host);
1437 hst = &lport->host_stats;
1438 lesb->lesb_link_fail = htonl(hst->link_failure_count);
1439 lesb->lesb_sync_loss = htonl(hst->loss_of_sync_count);
1440 lesb->lesb_sig_loss = htonl(hst->loss_of_signal_count);
1441 lesb->lesb_prim_err = htonl(hst->prim_seq_protocol_err_count);
1442 lesb->lesb_inv_word = htonl(hst->invalid_tx_word_count);
1443 lesb->lesb_inv_crc = htonl(hst->invalid_crc_count);
1444 }
1445
Joe Eykholt24f089e2010-07-20 15:21:01 -07001446 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
1447 lport->tt.frame_send(lport, fp);
Yi Zou63e27fb2009-11-20 14:55:24 -08001448 goto out;
1449
1450out_rjt:
Joe Eykholt92261152010-07-20 15:21:12 -07001451 lport->tt.seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
Yi Zou63e27fb2009-11-20 14:55:24 -08001452out:
1453 fc_frame_free(rx_fp);
1454}
1455
1456/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001457 * fc_rport_recv_els_req() - Handler for validated ELS requests
1458 * @lport: The local port that received the ELS request
Robert Love3a3b42b2009-11-03 11:47:39 -08001459 * @fp: The ELS request frame
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001460 *
1461 * Handle incoming ELS requests that require port login.
1462 * The ELS opcode has already been validated by the caller.
Robert Love42e9a922008-12-09 15:10:17 -08001463 *
Joe Eykholt131203a2009-08-25 14:03:10 -07001464 * Locking Note: Called with the lport lock held.
Robert Love42e9a922008-12-09 15:10:17 -08001465 */
Joe Eykholt92261152010-07-20 15:21:12 -07001466static void fc_rport_recv_els_req(struct fc_lport *lport, struct fc_frame *fp)
Robert Love42e9a922008-12-09 15:10:17 -08001467{
Joe Eykholt131203a2009-08-25 14:03:10 -07001468 struct fc_rport_priv *rdata;
Robert Love42e9a922008-12-09 15:10:17 -08001469 struct fc_seq_els_data els_data;
Robert Love42e9a922008-12-09 15:10:17 -08001470
Joe Eykholt25b37b92009-08-25 14:03:15 -07001471 mutex_lock(&lport->disc.disc_mutex);
Joe Eykholt251748a2010-07-20 15:20:56 -07001472 rdata = lport->tt.rport_lookup(lport, fc_frame_sid(fp));
Joe Eykholt131203a2009-08-25 14:03:10 -07001473 if (!rdata) {
Joe Eykholt25b37b92009-08-25 14:03:15 -07001474 mutex_unlock(&lport->disc.disc_mutex);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001475 goto reject;
Joe Eykholt131203a2009-08-25 14:03:10 -07001476 }
1477 mutex_lock(&rdata->rp_mutex);
Joe Eykholt25b37b92009-08-25 14:03:15 -07001478 mutex_unlock(&lport->disc.disc_mutex);
Joe Eykholt131203a2009-08-25 14:03:10 -07001479
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001480 switch (rdata->rp_state) {
1481 case RPORT_ST_PRLI:
1482 case RPORT_ST_RTV:
1483 case RPORT_ST_READY:
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001484 case RPORT_ST_ADISC:
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001485 break;
1486 default:
1487 mutex_unlock(&rdata->rp_mutex);
1488 goto reject;
1489 }
1490
1491 switch (fc_frame_payload_op(fp)) {
Joe Eykholt131203a2009-08-25 14:03:10 -07001492 case ELS_PRLI:
Joe Eykholt92261152010-07-20 15:21:12 -07001493 fc_rport_recv_prli_req(rdata, fp);
Joe Eykholt131203a2009-08-25 14:03:10 -07001494 break;
1495 case ELS_PRLO:
Joe Eykholt92261152010-07-20 15:21:12 -07001496 fc_rport_recv_prlo_req(rdata, fp);
Joe Eykholt131203a2009-08-25 14:03:10 -07001497 break;
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001498 case ELS_ADISC:
Joe Eykholt92261152010-07-20 15:21:12 -07001499 fc_rport_recv_adisc_req(rdata, fp);
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001500 break;
Joe Eykholt131203a2009-08-25 14:03:10 -07001501 case ELS_RRQ:
Joe Eykholt92261152010-07-20 15:21:12 -07001502 lport->tt.seq_els_rsp_send(fp, ELS_RRQ, NULL);
1503 fc_frame_free(fp);
Joe Eykholt131203a2009-08-25 14:03:10 -07001504 break;
1505 case ELS_REC:
Joe Eykholt92261152010-07-20 15:21:12 -07001506 lport->tt.seq_els_rsp_send(fp, ELS_REC, NULL);
1507 fc_frame_free(fp);
Joe Eykholt131203a2009-08-25 14:03:10 -07001508 break;
Yi Zou63e27fb2009-11-20 14:55:24 -08001509 case ELS_RLS:
Joe Eykholt92261152010-07-20 15:21:12 -07001510 fc_rport_recv_rls_req(rdata, fp);
Yi Zou63e27fb2009-11-20 14:55:24 -08001511 break;
Joe Eykholt131203a2009-08-25 14:03:10 -07001512 default:
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001513 fc_frame_free(fp); /* can't happen */
Joe Eykholt131203a2009-08-25 14:03:10 -07001514 break;
Robert Love42e9a922008-12-09 15:10:17 -08001515 }
1516
1517 mutex_unlock(&rdata->rp_mutex);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001518 return;
1519
1520reject:
Joe Eykholt92261152010-07-20 15:21:12 -07001521 els_data.reason = ELS_RJT_UNAB;
1522 els_data.explan = ELS_EXPL_PLOGI_REQD;
1523 lport->tt.seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001524 fc_frame_free(fp);
1525}
1526
1527/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001528 * fc_rport_recv_req() - Handler for requests
Robert Love3a3b42b2009-11-03 11:47:39 -08001529 * @lport: The local port that received the request
Joe Eykholt92261152010-07-20 15:21:12 -07001530 * @fp: The request frame
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001531 *
1532 * Locking Note: Called with the lport lock held.
1533 */
Joe Eykholt92261152010-07-20 15:21:12 -07001534void fc_rport_recv_req(struct fc_lport *lport, struct fc_frame *fp)
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001535{
1536 struct fc_seq_els_data els_data;
1537
1538 /*
Joe Eykholta7b12a22010-07-20 15:20:08 -07001539 * Handle FLOGI, PLOGI and LOGO requests separately, since they
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001540 * don't require prior login.
1541 * Check for unsupported opcodes first and reject them.
1542 * For some ops, it would be incorrect to reject with "PLOGI required".
1543 */
1544 switch (fc_frame_payload_op(fp)) {
Joe Eykholta7b12a22010-07-20 15:20:08 -07001545 case ELS_FLOGI:
Joe Eykholt92261152010-07-20 15:21:12 -07001546 fc_rport_recv_flogi_req(lport, fp);
Joe Eykholta7b12a22010-07-20 15:20:08 -07001547 break;
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001548 case ELS_PLOGI:
Joe Eykholt92261152010-07-20 15:21:12 -07001549 fc_rport_recv_plogi_req(lport, fp);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001550 break;
1551 case ELS_LOGO:
Joe Eykholt92261152010-07-20 15:21:12 -07001552 fc_rport_recv_logo_req(lport, fp);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001553 break;
1554 case ELS_PRLI:
1555 case ELS_PRLO:
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001556 case ELS_ADISC:
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001557 case ELS_RRQ:
1558 case ELS_REC:
Yi Zou63e27fb2009-11-20 14:55:24 -08001559 case ELS_RLS:
Joe Eykholt92261152010-07-20 15:21:12 -07001560 fc_rport_recv_els_req(lport, fp);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001561 break;
1562 default:
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001563 els_data.reason = ELS_RJT_UNSUP;
1564 els_data.explan = ELS_EXPL_NONE;
Joe Eykholt92261152010-07-20 15:21:12 -07001565 lport->tt.seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
1566 fc_frame_free(fp);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001567 break;
1568 }
Robert Love42e9a922008-12-09 15:10:17 -08001569}
1570
1571/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001572 * fc_rport_recv_plogi_req() - Handler for Port Login (PLOGI) requests
1573 * @lport: The local port that received the PLOGI request
Robert Love3a3b42b2009-11-03 11:47:39 -08001574 * @rx_fp: The PLOGI request frame
Robert Love42e9a922008-12-09 15:10:17 -08001575 *
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001576 * Locking Note: The rport lock is held before calling this function.
Robert Love42e9a922008-12-09 15:10:17 -08001577 */
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001578static void fc_rport_recv_plogi_req(struct fc_lport *lport,
Joe Eykholt92261152010-07-20 15:21:12 -07001579 struct fc_frame *rx_fp)
Robert Love42e9a922008-12-09 15:10:17 -08001580{
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001581 struct fc_disc *disc;
1582 struct fc_rport_priv *rdata;
Robert Love42e9a922008-12-09 15:10:17 -08001583 struct fc_frame *fp = rx_fp;
Robert Love42e9a922008-12-09 15:10:17 -08001584 struct fc_els_flogi *pl;
1585 struct fc_seq_els_data rjt_data;
Joe Eykholt24f089e2010-07-20 15:21:01 -07001586 u32 sid;
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001587
Joe Eykholt251748a2010-07-20 15:20:56 -07001588 sid = fc_frame_sid(fp);
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001589
1590 FC_RPORT_ID_DBG(lport, sid, "Received PLOGI request\n");
1591
Robert Love42e9a922008-12-09 15:10:17 -08001592 pl = fc_frame_payload_get(fp, sizeof(*pl));
1593 if (!pl) {
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001594 FC_RPORT_ID_DBG(lport, sid, "Received PLOGI too short\n");
1595 rjt_data.reason = ELS_RJT_PROT;
1596 rjt_data.explan = ELS_EXPL_INV_LEN;
1597 goto reject;
Robert Love42e9a922008-12-09 15:10:17 -08001598 }
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001599
1600 disc = &lport->disc;
1601 mutex_lock(&disc->disc_mutex);
1602 rdata = lport->tt.rport_create(lport, sid);
1603 if (!rdata) {
1604 mutex_unlock(&disc->disc_mutex);
1605 rjt_data.reason = ELS_RJT_UNAB;
1606 rjt_data.explan = ELS_EXPL_INSUF_RES;
1607 goto reject;
1608 }
1609
1610 mutex_lock(&rdata->rp_mutex);
1611 mutex_unlock(&disc->disc_mutex);
1612
1613 rdata->ids.port_name = get_unaligned_be64(&pl->fl_wwpn);
1614 rdata->ids.node_name = get_unaligned_be64(&pl->fl_wwnn);
Robert Love42e9a922008-12-09 15:10:17 -08001615
1616 /*
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001617 * If the rport was just created, possibly due to the incoming PLOGI,
Robert Love42e9a922008-12-09 15:10:17 -08001618 * set the state appropriately and accept the PLOGI.
1619 *
1620 * If we had also sent a PLOGI, and if the received PLOGI is from a
1621 * higher WWPN, we accept it, otherwise an LS_RJT is sent with reason
1622 * "command already in progress".
1623 *
1624 * XXX TBD: If the session was ready before, the PLOGI should result in
1625 * all outstanding exchanges being reset.
1626 */
1627 switch (rdata->rp_state) {
1628 case RPORT_ST_INIT:
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001629 FC_RPORT_DBG(rdata, "Received PLOGI in INIT state\n");
Robert Love42e9a922008-12-09 15:10:17 -08001630 break;
Joe Eykholta7b12a22010-07-20 15:20:08 -07001631 case RPORT_ST_PLOGI_WAIT:
1632 FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI_WAIT state\n");
1633 break;
Robert Love42e9a922008-12-09 15:10:17 -08001634 case RPORT_ST_PLOGI:
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001635 FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI state\n");
1636 if (rdata->ids.port_name < lport->wwpn) {
1637 mutex_unlock(&rdata->rp_mutex);
1638 rjt_data.reason = ELS_RJT_INPROG;
1639 rjt_data.explan = ELS_EXPL_NONE;
1640 goto reject;
1641 }
Robert Love42e9a922008-12-09 15:10:17 -08001642 break;
1643 case RPORT_ST_PRLI:
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -07001644 case RPORT_ST_RTV:
Robert Love42e9a922008-12-09 15:10:17 -08001645 case RPORT_ST_READY:
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001646 case RPORT_ST_ADISC:
1647 FC_RPORT_DBG(rdata, "Received PLOGI in logged-in state %d "
1648 "- ignored for now\n", rdata->rp_state);
1649 /* XXX TBD - should reset */
Robert Love42e9a922008-12-09 15:10:17 -08001650 break;
Joe Eykholta7b12a22010-07-20 15:20:08 -07001651 case RPORT_ST_FLOGI:
Joe Eykholt14194052009-07-29 17:04:43 -07001652 case RPORT_ST_DELETE:
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -07001653 FC_RPORT_DBG(rdata, "Received PLOGI in state %s - send busy\n",
1654 fc_rport_state(rdata));
1655 mutex_unlock(&rdata->rp_mutex);
1656 rjt_data.reason = ELS_RJT_BUSY;
1657 rjt_data.explan = ELS_EXPL_NONE;
1658 goto reject;
Robert Love42e9a922008-12-09 15:10:17 -08001659 }
1660
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001661 /*
1662 * Get session payload size from incoming PLOGI.
1663 */
1664 rdata->maxframe_size = fc_plogi_get_maxframe(pl, lport->mfs);
Robert Love42e9a922008-12-09 15:10:17 -08001665
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001666 /*
1667 * Send LS_ACC. If this fails, the originator should retry.
1668 */
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001669 fp = fc_frame_alloc(lport, sizeof(*pl));
1670 if (!fp)
1671 goto out;
Robert Love42e9a922008-12-09 15:10:17 -08001672
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001673 fc_plogi_fill(lport, fp, ELS_LS_ACC);
Joe Eykholt24f089e2010-07-20 15:21:01 -07001674 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
1675 lport->tt.frame_send(lport, fp);
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001676 fc_rport_enter_prli(rdata);
1677out:
1678 mutex_unlock(&rdata->rp_mutex);
Joe Eykholt24f089e2010-07-20 15:21:01 -07001679 fc_frame_free(rx_fp);
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001680 return;
1681
1682reject:
Joe Eykholt92261152010-07-20 15:21:12 -07001683 lport->tt.seq_els_rsp_send(fp, ELS_LS_RJT, &rjt_data);
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001684 fc_frame_free(fp);
Robert Love42e9a922008-12-09 15:10:17 -08001685}
1686
1687/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001688 * fc_rport_recv_prli_req() - Handler for process login (PRLI) requests
1689 * @rdata: The remote port that sent the PRLI request
Robert Love3a3b42b2009-11-03 11:47:39 -08001690 * @rx_fp: The PRLI request frame
Robert Love42e9a922008-12-09 15:10:17 -08001691 *
1692 * Locking Note: The rport lock is exected to be held before calling
1693 * this function.
1694 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001695static void fc_rport_recv_prli_req(struct fc_rport_priv *rdata,
Joe Eykholt92261152010-07-20 15:21:12 -07001696 struct fc_frame *rx_fp)
Robert Love42e9a922008-12-09 15:10:17 -08001697{
Robert Love42e9a922008-12-09 15:10:17 -08001698 struct fc_lport *lport = rdata->local_port;
Robert Love42e9a922008-12-09 15:10:17 -08001699 struct fc_frame *fp;
Robert Love42e9a922008-12-09 15:10:17 -08001700 struct {
1701 struct fc_els_prli prli;
1702 struct fc_els_spp spp;
1703 } *pp;
1704 struct fc_els_spp *rspp; /* request service param page */
1705 struct fc_els_spp *spp; /* response spp */
1706 unsigned int len;
1707 unsigned int plen;
Robert Love42e9a922008-12-09 15:10:17 -08001708 enum fc_els_spp_resp resp;
Joe Eykholt96ad8462011-01-28 16:04:02 -08001709 enum fc_els_spp_resp passive;
Robert Love42e9a922008-12-09 15:10:17 -08001710 struct fc_seq_els_data rjt_data;
Joe Eykholt96ad8462011-01-28 16:04:02 -08001711 struct fc4_prov *prov;
Robert Love42e9a922008-12-09 15:10:17 -08001712
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001713 FC_RPORT_DBG(rdata, "Received PRLI request while in state %s\n",
1714 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -08001715
Joe Eykholt251748a2010-07-20 15:20:56 -07001716 len = fr_len(rx_fp) - sizeof(struct fc_frame_header);
Robert Love42e9a922008-12-09 15:10:17 -08001717 pp = fc_frame_payload_get(rx_fp, sizeof(*pp));
Joe Eykholta2f6a022010-03-12 16:07:36 -08001718 if (!pp)
1719 goto reject_len;
1720 plen = ntohs(pp->prli.prli_len);
1721 if ((plen % 4) != 0 || plen > len || plen < 16)
1722 goto reject_len;
1723 if (plen < len)
1724 len = plen;
1725 plen = pp->prli.prli_spp_len;
1726 if ((plen % 4) != 0 || plen < sizeof(*spp) ||
1727 plen > len || len < sizeof(*pp) || plen < 12)
1728 goto reject_len;
1729 rspp = &pp->spp;
1730
1731 fp = fc_frame_alloc(lport, len);
1732 if (!fp) {
1733 rjt_data.reason = ELS_RJT_UNAB;
1734 rjt_data.explan = ELS_EXPL_INSUF_RES;
1735 goto reject;
Robert Love42e9a922008-12-09 15:10:17 -08001736 }
Joe Eykholta2f6a022010-03-12 16:07:36 -08001737 pp = fc_frame_payload_get(fp, len);
1738 WARN_ON(!pp);
1739 memset(pp, 0, len);
1740 pp->prli.prli_cmd = ELS_LS_ACC;
1741 pp->prli.prli_spp_len = plen;
1742 pp->prli.prli_len = htons(len);
1743 len -= sizeof(struct fc_els_prli);
Robert Love42e9a922008-12-09 15:10:17 -08001744
Joe Eykholta2f6a022010-03-12 16:07:36 -08001745 /*
1746 * Go through all the service parameter pages and build
1747 * response. If plen indicates longer SPP than standard,
1748 * use that. The entire response has been pre-cleared above.
1749 */
1750 spp = &pp->spp;
Joe Eykholt96ad8462011-01-28 16:04:02 -08001751 mutex_lock(&fc_prov_mutex);
Joe Eykholta2f6a022010-03-12 16:07:36 -08001752 while (len >= plen) {
Bhanu Prakash Gollapudi75a27922011-01-28 16:05:27 -08001753 rdata->spp_type = rspp->spp_type;
Joe Eykholta2f6a022010-03-12 16:07:36 -08001754 spp->spp_type = rspp->spp_type;
1755 spp->spp_type_ext = rspp->spp_type_ext;
Joe Eykholt96ad8462011-01-28 16:04:02 -08001756 resp = 0;
Robert Love42e9a922008-12-09 15:10:17 -08001757
Joe Eykholt96ad8462011-01-28 16:04:02 -08001758 if (rspp->spp_type < FC_FC4_PROV_SIZE) {
1759 prov = fc_active_prov[rspp->spp_type];
1760 if (prov)
1761 resp = prov->prli(rdata, plen, rspp, spp);
1762 prov = fc_passive_prov[rspp->spp_type];
1763 if (prov) {
1764 passive = prov->prli(rdata, plen, rspp, spp);
1765 if (!resp || passive == FC_SPP_RESP_ACK)
1766 resp = passive;
1767 }
1768 }
1769 if (!resp) {
1770 if (spp->spp_flags & FC_SPP_EST_IMG_PAIR)
1771 resp |= FC_SPP_RESP_CONF;
1772 else
1773 resp |= FC_SPP_RESP_INVL;
Robert Love42e9a922008-12-09 15:10:17 -08001774 }
Joe Eykholta2f6a022010-03-12 16:07:36 -08001775 spp->spp_flags |= resp;
1776 len -= plen;
1777 rspp = (struct fc_els_spp *)((char *)rspp + plen);
1778 spp = (struct fc_els_spp *)((char *)spp + plen);
Robert Love42e9a922008-12-09 15:10:17 -08001779 }
Joe Eykholt96ad8462011-01-28 16:04:02 -08001780 mutex_unlock(&fc_prov_mutex);
Joe Eykholta2f6a022010-03-12 16:07:36 -08001781
1782 /*
1783 * Send LS_ACC. If this fails, the originator should retry.
1784 */
Joe Eykholt24f089e2010-07-20 15:21:01 -07001785 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
1786 lport->tt.frame_send(lport, fp);
Joe Eykholta2f6a022010-03-12 16:07:36 -08001787
1788 switch (rdata->rp_state) {
1789 case RPORT_ST_PRLI:
1790 fc_rport_enter_ready(rdata);
1791 break;
1792 default:
1793 break;
1794 }
1795 goto drop;
1796
1797reject_len:
1798 rjt_data.reason = ELS_RJT_PROT;
1799 rjt_data.explan = ELS_EXPL_INV_LEN;
1800reject:
Joe Eykholt92261152010-07-20 15:21:12 -07001801 lport->tt.seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
Joe Eykholta2f6a022010-03-12 16:07:36 -08001802drop:
Robert Love42e9a922008-12-09 15:10:17 -08001803 fc_frame_free(rx_fp);
1804}
1805
1806/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001807 * fc_rport_recv_prlo_req() - Handler for process logout (PRLO) requests
1808 * @rdata: The remote port that sent the PRLO request
Bhanu Prakash Gollapudif8fc6c22010-06-11 16:44:04 -07001809 * @rx_fp: The PRLO request frame
Robert Love42e9a922008-12-09 15:10:17 -08001810 *
1811 * Locking Note: The rport lock is exected to be held before calling
1812 * this function.
1813 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001814static void fc_rport_recv_prlo_req(struct fc_rport_priv *rdata,
Bhanu Prakash Gollapudif8fc6c22010-06-11 16:44:04 -07001815 struct fc_frame *rx_fp)
Robert Love42e9a922008-12-09 15:10:17 -08001816{
Robert Love42e9a922008-12-09 15:10:17 -08001817 struct fc_lport *lport = rdata->local_port;
Bhanu Prakash Gollapudif8fc6c22010-06-11 16:44:04 -07001818 struct fc_frame *fp;
1819 struct {
1820 struct fc_els_prlo prlo;
1821 struct fc_els_spp spp;
1822 } *pp;
1823 struct fc_els_spp *rspp; /* request service param page */
1824 struct fc_els_spp *spp; /* response spp */
1825 unsigned int len;
1826 unsigned int plen;
Robert Love42e9a922008-12-09 15:10:17 -08001827 struct fc_seq_els_data rjt_data;
1828
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001829 FC_RPORT_DBG(rdata, "Received PRLO request while in state %s\n",
1830 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -08001831
Joe Eykholt251748a2010-07-20 15:20:56 -07001832 len = fr_len(rx_fp) - sizeof(struct fc_frame_header);
Bhanu Prakash Gollapudif8fc6c22010-06-11 16:44:04 -07001833 pp = fc_frame_payload_get(rx_fp, sizeof(*pp));
1834 if (!pp)
1835 goto reject_len;
1836 plen = ntohs(pp->prlo.prlo_len);
1837 if (plen != 20)
1838 goto reject_len;
1839 if (plen < len)
1840 len = plen;
1841
1842 rspp = &pp->spp;
1843
1844 fp = fc_frame_alloc(lport, len);
1845 if (!fp) {
1846 rjt_data.reason = ELS_RJT_UNAB;
1847 rjt_data.explan = ELS_EXPL_INSUF_RES;
1848 goto reject;
1849 }
1850
Bhanu Prakash Gollapudif8fc6c22010-06-11 16:44:04 -07001851 pp = fc_frame_payload_get(fp, len);
1852 WARN_ON(!pp);
1853 memset(pp, 0, len);
1854 pp->prlo.prlo_cmd = ELS_LS_ACC;
1855 pp->prlo.prlo_obs = 0x10;
1856 pp->prlo.prlo_len = htons(len);
1857 spp = &pp->spp;
1858 spp->spp_type = rspp->spp_type;
1859 spp->spp_type_ext = rspp->spp_type_ext;
1860 spp->spp_flags = FC_SPP_RESP_ACK;
1861
1862 fc_rport_enter_delete(rdata, RPORT_EV_LOGO);
1863
Joe Eykholt92261152010-07-20 15:21:12 -07001864 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
1865 lport->tt.frame_send(lport, fp);
Bhanu Prakash Gollapudif8fc6c22010-06-11 16:44:04 -07001866 goto drop;
1867
1868reject_len:
1869 rjt_data.reason = ELS_RJT_PROT;
1870 rjt_data.explan = ELS_EXPL_INV_LEN;
1871reject:
Joe Eykholt92261152010-07-20 15:21:12 -07001872 lport->tt.seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
Bhanu Prakash Gollapudif8fc6c22010-06-11 16:44:04 -07001873drop:
1874 fc_frame_free(rx_fp);
Robert Love42e9a922008-12-09 15:10:17 -08001875}
1876
1877/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001878 * fc_rport_recv_logo_req() - Handler for logout (LOGO) requests
1879 * @lport: The local port that received the LOGO request
Robert Love3a3b42b2009-11-03 11:47:39 -08001880 * @fp: The LOGO request frame
Robert Love42e9a922008-12-09 15:10:17 -08001881 *
1882 * Locking Note: The rport lock is exected to be held before calling
1883 * this function.
1884 */
Joe Eykholt92261152010-07-20 15:21:12 -07001885static void fc_rport_recv_logo_req(struct fc_lport *lport, struct fc_frame *fp)
Robert Love42e9a922008-12-09 15:10:17 -08001886{
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001887 struct fc_rport_priv *rdata;
1888 u32 sid;
Robert Love42e9a922008-12-09 15:10:17 -08001889
Joe Eykholt92261152010-07-20 15:21:12 -07001890 lport->tt.seq_els_rsp_send(fp, ELS_LS_ACC, NULL);
Joe Eykholtfeab4ae2009-08-25 14:03:36 -07001891
Joe Eykholt251748a2010-07-20 15:20:56 -07001892 sid = fc_frame_sid(fp);
Robert Love42e9a922008-12-09 15:10:17 -08001893
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001894 mutex_lock(&lport->disc.disc_mutex);
1895 rdata = lport->tt.rport_lookup(lport, sid);
1896 if (rdata) {
1897 mutex_lock(&rdata->rp_mutex);
1898 FC_RPORT_DBG(rdata, "Received LOGO request while in state %s\n",
1899 fc_rport_state(rdata));
Joe Eykholtfeab4ae2009-08-25 14:03:36 -07001900
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -07001901 fc_rport_enter_delete(rdata, RPORT_EV_LOGO);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001902 mutex_unlock(&rdata->rp_mutex);
1903 } else
1904 FC_RPORT_ID_DBG(lport, sid,
1905 "Received LOGO from non-logged-in port\n");
1906 mutex_unlock(&lport->disc.disc_mutex);
Robert Love42e9a922008-12-09 15:10:17 -08001907 fc_frame_free(fp);
1908}
1909
Robert Love3a3b42b2009-11-03 11:47:39 -08001910/**
1911 * fc_rport_flush_queue() - Flush the rport_event_queue
1912 */
Robert Love42e9a922008-12-09 15:10:17 -08001913static void fc_rport_flush_queue(void)
1914{
1915 flush_workqueue(rport_event_queue);
1916}
1917
Robert Love3a3b42b2009-11-03 11:47:39 -08001918/**
1919 * fc_rport_init() - Initialize the remote port layer for a local port
1920 * @lport: The local port to initialize the remote port layer for
1921 */
Robert Love42e9a922008-12-09 15:10:17 -08001922int fc_rport_init(struct fc_lport *lport)
1923{
Joe Eykholt8025b5d2009-08-25 14:02:06 -07001924 if (!lport->tt.rport_lookup)
1925 lport->tt.rport_lookup = fc_rport_lookup;
1926
Robert Love5101ff92009-02-27 10:55:18 -08001927 if (!lport->tt.rport_create)
Joe Eykholt9e9d0452009-08-25 14:01:18 -07001928 lport->tt.rport_create = fc_rport_create;
Robert Love5101ff92009-02-27 10:55:18 -08001929
Robert Love42e9a922008-12-09 15:10:17 -08001930 if (!lport->tt.rport_login)
1931 lport->tt.rport_login = fc_rport_login;
1932
1933 if (!lport->tt.rport_logoff)
1934 lport->tt.rport_logoff = fc_rport_logoff;
1935
1936 if (!lport->tt.rport_recv_req)
1937 lport->tt.rport_recv_req = fc_rport_recv_req;
1938
1939 if (!lport->tt.rport_flush_queue)
1940 lport->tt.rport_flush_queue = fc_rport_flush_queue;
1941
Joe Eykholtf211fa52009-08-25 14:01:01 -07001942 if (!lport->tt.rport_destroy)
1943 lport->tt.rport_destroy = fc_rport_destroy;
1944
Robert Love42e9a922008-12-09 15:10:17 -08001945 return 0;
1946}
1947EXPORT_SYMBOL(fc_rport_init);
1948
Robert Love3a3b42b2009-11-03 11:47:39 -08001949/**
Joe Eykholt96ad8462011-01-28 16:04:02 -08001950 * fc_rport_fcp_prli() - Handle incoming PRLI for the FCP initiator.
1951 * @rdata: remote port private
1952 * @spp_len: service parameter page length
1953 * @rspp: received service parameter page
1954 * @spp: response service parameter page
1955 *
1956 * Returns the value for the response code to be placed in spp_flags;
1957 * Returns 0 if not an initiator.
1958 */
1959static int fc_rport_fcp_prli(struct fc_rport_priv *rdata, u32 spp_len,
1960 const struct fc_els_spp *rspp,
1961 struct fc_els_spp *spp)
1962{
1963 struct fc_lport *lport = rdata->local_port;
1964 u32 fcp_parm;
1965
1966 fcp_parm = ntohl(rspp->spp_params);
1967 rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
1968 if (fcp_parm & FCP_SPPF_INIT_FCN)
1969 rdata->ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1970 if (fcp_parm & FCP_SPPF_TARG_FCN)
1971 rdata->ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1972 if (fcp_parm & FCP_SPPF_RETRY)
1973 rdata->flags |= FC_RP_FLAGS_RETRY;
1974 rdata->supported_classes = FC_COS_CLASS3;
1975
1976 if (!(lport->service_params & FC_RPORT_ROLE_FCP_INITIATOR))
1977 return 0;
1978
1979 spp->spp_flags |= rspp->spp_flags & FC_SPP_EST_IMG_PAIR;
1980
1981 /*
1982 * OR in our service parameters with other providers (target), if any.
1983 */
1984 fcp_parm = ntohl(spp->spp_params);
1985 spp->spp_params = htonl(fcp_parm | lport->service_params);
1986 return FC_SPP_RESP_ACK;
1987}
1988
1989/*
1990 * FC-4 provider ops for FCP initiator.
1991 */
1992struct fc4_prov fc_rport_fcp_init = {
1993 .prli = fc_rport_fcp_prli,
1994};
1995
1996/**
1997 * fc_rport_t0_prli() - Handle incoming PRLI parameters for type 0
1998 * @rdata: remote port private
1999 * @spp_len: service parameter page length
2000 * @rspp: received service parameter page
2001 * @spp: response service parameter page
2002 */
2003static int fc_rport_t0_prli(struct fc_rport_priv *rdata, u32 spp_len,
2004 const struct fc_els_spp *rspp,
2005 struct fc_els_spp *spp)
2006{
2007 if (rspp->spp_flags & FC_SPP_EST_IMG_PAIR)
2008 return FC_SPP_RESP_INVL;
2009 return FC_SPP_RESP_ACK;
2010}
2011
2012/*
2013 * FC-4 provider ops for type 0 service parameters.
2014 *
2015 * This handles the special case of type 0 which is always successful
2016 * but doesn't do anything otherwise.
2017 */
2018struct fc4_prov fc_rport_t0_prov = {
2019 .prli = fc_rport_t0_prli,
2020};
2021
2022/**
Robert Love3a3b42b2009-11-03 11:47:39 -08002023 * fc_setup_rport() - Initialize the rport_event_queue
2024 */
Randy Dunlap55204902011-01-28 16:03:57 -08002025int fc_setup_rport(void)
Robert Love42e9a922008-12-09 15:10:17 -08002026{
2027 rport_event_queue = create_singlethread_workqueue("fc_rport_eq");
2028 if (!rport_event_queue)
2029 return -ENOMEM;
2030 return 0;
2031}
Robert Love42e9a922008-12-09 15:10:17 -08002032
Robert Love3a3b42b2009-11-03 11:47:39 -08002033/**
2034 * fc_destroy_rport() - Destroy the rport_event_queue
2035 */
Randy Dunlap55204902011-01-28 16:03:57 -08002036void fc_destroy_rport(void)
Robert Love42e9a922008-12-09 15:10:17 -08002037{
2038 destroy_workqueue(rport_event_queue);
2039}
Robert Love42e9a922008-12-09 15:10:17 -08002040
Robert Love3a3b42b2009-11-03 11:47:39 -08002041/**
2042 * fc_rport_terminate_io() - Stop all outstanding I/O on a remote port
2043 * @rport: The remote port whose I/O should be terminated
2044 */
Robert Love42e9a922008-12-09 15:10:17 -08002045void fc_rport_terminate_io(struct fc_rport *rport)
2046{
Robert Love3a3b42b2009-11-03 11:47:39 -08002047 struct fc_rport_libfc_priv *rpriv = rport->dd_data;
2048 struct fc_lport *lport = rpriv->local_port;
Robert Love42e9a922008-12-09 15:10:17 -08002049
Abhijeet Joglekar1f6ff362009-02-27 10:54:35 -08002050 lport->tt.exch_mgr_reset(lport, 0, rport->port_id);
2051 lport->tt.exch_mgr_reset(lport, rport->port_id, 0);
Robert Love42e9a922008-12-09 15:10:17 -08002052}
2053EXPORT_SYMBOL(fc_rport_terminate_io);