blob: 589ff9aedd318088d5f0f61f143f780a223ed00d [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>
Paul Gortmaker09703662011-05-27 09:37:25 -040054#include <linux/export.h>
Robert Love42e9a922008-12-09 15:10:17 -080055#include <asm/unaligned.h>
56
57#include <scsi/libfc.h>
58#include <scsi/fc_encode.h>
59
Robert Love8866a5d2009-11-03 11:45:58 -080060#include "fc_libfc.h"
61
Randy Dunlap55204902011-01-28 16:03:57 -080062static struct workqueue_struct *rport_event_queue;
Robert Love42e9a922008-12-09 15:10:17 -080063
Joe Eykholta7b12a22010-07-20 15:20:08 -070064static void fc_rport_enter_flogi(struct fc_rport_priv *);
Joe Eykholt9fb9d322009-08-25 14:00:50 -070065static void fc_rport_enter_plogi(struct fc_rport_priv *);
66static void fc_rport_enter_prli(struct fc_rport_priv *);
67static void fc_rport_enter_rtv(struct fc_rport_priv *);
68static void fc_rport_enter_ready(struct fc_rport_priv *);
69static void fc_rport_enter_logo(struct fc_rport_priv *);
Joe Eykholt370c3bd2009-08-25 14:03:47 -070070static void fc_rport_enter_adisc(struct fc_rport_priv *);
Robert Love42e9a922008-12-09 15:10:17 -080071
Joe Eykholt922611562010-07-20 15:21:12 -070072static void fc_rport_recv_plogi_req(struct fc_lport *, struct fc_frame *);
73static void fc_rport_recv_prli_req(struct fc_rport_priv *, struct fc_frame *);
74static void fc_rport_recv_prlo_req(struct fc_rport_priv *, struct fc_frame *);
75static void fc_rport_recv_logo_req(struct fc_lport *, struct fc_frame *);
Robert Love42e9a922008-12-09 15:10:17 -080076static void fc_rport_timeout(struct work_struct *);
Joe Eykholt9fb9d322009-08-25 14:00:50 -070077static void fc_rport_error(struct fc_rport_priv *, struct fc_frame *);
78static void fc_rport_error_retry(struct fc_rport_priv *, struct fc_frame *);
Robert Love42e9a922008-12-09 15:10:17 -080079static void fc_rport_work(struct work_struct *);
80
81static const char *fc_rport_state_names[] = {
Robert Love42e9a922008-12-09 15:10:17 -080082 [RPORT_ST_INIT] = "Init",
Joe Eykholta7b12a22010-07-20 15:20:08 -070083 [RPORT_ST_FLOGI] = "FLOGI",
84 [RPORT_ST_PLOGI_WAIT] = "PLOGI_WAIT",
Robert Love42e9a922008-12-09 15:10:17 -080085 [RPORT_ST_PLOGI] = "PLOGI",
86 [RPORT_ST_PRLI] = "PRLI",
87 [RPORT_ST_RTV] = "RTV",
88 [RPORT_ST_READY] = "Ready",
Joe Eykholt370c3bd2009-08-25 14:03:47 -070089 [RPORT_ST_ADISC] = "ADISC",
Joe Eykholt14194052009-07-29 17:04:43 -070090 [RPORT_ST_DELETE] = "Delete",
Robert Love42e9a922008-12-09 15:10:17 -080091};
92
Joe Eykholt9e9d0452009-08-25 14:01:18 -070093/**
Robert Love3a3b42b2009-11-03 11:47:39 -080094 * fc_rport_lookup() - Lookup a remote port by port_id
95 * @lport: The local port to lookup the remote port on
96 * @port_id: The remote port ID to look up
Joe Eykholt42e90412010-07-20 15:19:37 -070097 *
98 * The caller must hold either disc_mutex or rcu_read_lock().
Joe Eykholt8025b5d2009-08-25 14:02:06 -070099 */
100static struct fc_rport_priv *fc_rport_lookup(const struct fc_lport *lport,
101 u32 port_id)
102{
103 struct fc_rport_priv *rdata;
104
Joe Eykholt42e90412010-07-20 15:19:37 -0700105 list_for_each_entry_rcu(rdata, &lport->disc.rports, peers)
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -0700106 if (rdata->ids.port_id == port_id)
Joe Eykholt8025b5d2009-08-25 14:02:06 -0700107 return rdata;
108 return NULL;
109}
110
111/**
Robert Love9737e6a2009-08-25 14:02:59 -0700112 * fc_rport_create() - Create a new remote port
Robert Love3a3b42b2009-11-03 11:47:39 -0800113 * @lport: The local port this remote port will be associated with
114 * @ids: The identifiers for the new remote port
115 *
116 * The remote port will start in the INIT state.
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700117 *
Joe Eykholt48f00902009-08-25 14:01:50 -0700118 * Locking note: must be called with the disc_mutex held.
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700119 */
120static struct fc_rport_priv *fc_rport_create(struct fc_lport *lport,
Robert Love9737e6a2009-08-25 14:02:59 -0700121 u32 port_id)
Robert Love42e9a922008-12-09 15:10:17 -0800122{
Joe Eykholtab28f1f2009-08-25 14:00:34 -0700123 struct fc_rport_priv *rdata;
Robert Love42e9a922008-12-09 15:10:17 -0800124
Robert Love9737e6a2009-08-25 14:02:59 -0700125 rdata = lport->tt.rport_lookup(lport, port_id);
Joe Eykholt19f97e32009-08-25 14:01:55 -0700126 if (rdata)
127 return rdata;
128
Joe Eykholtf90377a2010-07-20 15:19:42 -0700129 rdata = kzalloc(sizeof(*rdata) + lport->rport_priv_size, GFP_KERNEL);
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700130 if (!rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800131 return NULL;
132
Robert Love9737e6a2009-08-25 14:02:59 -0700133 rdata->ids.node_name = -1;
134 rdata->ids.port_name = -1;
135 rdata->ids.port_id = port_id;
136 rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
137
Joe Eykholtf211fa52009-08-25 14:01:01 -0700138 kref_init(&rdata->kref);
Robert Love42e9a922008-12-09 15:10:17 -0800139 mutex_init(&rdata->rp_mutex);
Joe Eykholt795d86f2009-08-25 14:00:39 -0700140 rdata->local_port = lport;
Robert Love42e9a922008-12-09 15:10:17 -0800141 rdata->rp_state = RPORT_ST_INIT;
142 rdata->event = RPORT_EV_NONE;
143 rdata->flags = FC_RP_FLAGS_REC_SUPPORTED;
Joe Eykholt795d86f2009-08-25 14:00:39 -0700144 rdata->e_d_tov = lport->e_d_tov;
145 rdata->r_a_tov = lport->r_a_tov;
Joe Eykholtf211fa52009-08-25 14:01:01 -0700146 rdata->maxframe_size = FC_MIN_MAX_PAYLOAD;
Robert Love42e9a922008-12-09 15:10:17 -0800147 INIT_DELAYED_WORK(&rdata->retry_work, fc_rport_timeout);
148 INIT_WORK(&rdata->event_work, fc_rport_work);
Bhanu Prakash Gollapudi75a27922011-01-28 16:05:27 -0800149 if (port_id != FC_FID_DIR_SERV) {
150 rdata->lld_event_callback = lport->tt.rport_event_callback;
Joe Eykholt42e90412010-07-20 15:19:37 -0700151 list_add_rcu(&rdata->peers, &lport->disc.rports);
Bhanu Prakash Gollapudi75a27922011-01-28 16:05:27 -0800152 }
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700153 return rdata;
Robert Love42e9a922008-12-09 15:10:17 -0800154}
155
156/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800157 * fc_rport_destroy() - Free a remote port after last reference is released
158 * @kref: The remote port's kref
Joe Eykholtf211fa52009-08-25 14:01:01 -0700159 */
160static void fc_rport_destroy(struct kref *kref)
161{
162 struct fc_rport_priv *rdata;
Joe Eykholtf211fa52009-08-25 14:01:01 -0700163
164 rdata = container_of(kref, struct fc_rport_priv, kref);
Lai Jiangshan8497a242011-03-18 11:41:14 +0800165 kfree_rcu(rdata, rcu);
Joe Eykholtf211fa52009-08-25 14:01:01 -0700166}
167
168/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800169 * fc_rport_state() - Return a string identifying the remote port's state
170 * @rdata: The remote port
Robert Love42e9a922008-12-09 15:10:17 -0800171 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700172static const char *fc_rport_state(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800173{
174 const char *cp;
Robert Love42e9a922008-12-09 15:10:17 -0800175
176 cp = fc_rport_state_names[rdata->rp_state];
177 if (!cp)
178 cp = "Unknown";
179 return cp;
180}
181
182/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800183 * fc_set_rport_loss_tmo() - Set the remote port loss timeout
184 * @rport: The remote port that gets a new timeout value
185 * @timeout: The new timeout value (in seconds)
Robert Love42e9a922008-12-09 15:10:17 -0800186 */
187void fc_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout)
188{
189 if (timeout)
Mike Christie73b43762010-10-08 17:12:10 -0700190 rport->dev_loss_tmo = timeout;
Robert Love42e9a922008-12-09 15:10:17 -0800191 else
Mike Christie73b43762010-10-08 17:12:10 -0700192 rport->dev_loss_tmo = 1;
Robert Love42e9a922008-12-09 15:10:17 -0800193}
194EXPORT_SYMBOL(fc_set_rport_loss_tmo);
195
196/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800197 * fc_plogi_get_maxframe() - Get the maximum payload from the common service
198 * parameters in a FLOGI frame
Joe Eykholta7b12a22010-07-20 15:20:08 -0700199 * @flp: The FLOGI or PLOGI payload
Robert Love3a3b42b2009-11-03 11:47:39 -0800200 * @maxval: The maximum frame size upper limit; this may be less than what
201 * is in the service parameters
Robert Love42e9a922008-12-09 15:10:17 -0800202 */
Robert Loveb2ab99c2009-02-27 10:55:50 -0800203static unsigned int fc_plogi_get_maxframe(struct fc_els_flogi *flp,
204 unsigned int maxval)
Robert Love42e9a922008-12-09 15:10:17 -0800205{
206 unsigned int mfs;
207
208 /*
209 * Get max payload from the common service parameters and the
210 * class 3 receive data field size.
211 */
212 mfs = ntohs(flp->fl_csp.sp_bb_data) & FC_SP_BB_DATA_MASK;
213 if (mfs >= FC_SP_MIN_MAX_PAYLOAD && mfs < maxval)
214 maxval = mfs;
215 mfs = ntohs(flp->fl_cssp[3 - 1].cp_rdfs);
216 if (mfs >= FC_SP_MIN_MAX_PAYLOAD && mfs < maxval)
217 maxval = mfs;
218 return maxval;
219}
220
221/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800222 * fc_rport_state_enter() - Change the state of a remote port
223 * @rdata: The remote port whose state should change
224 * @new: The new state
Robert Love42e9a922008-12-09 15:10:17 -0800225 *
226 * Locking Note: Called with the rport lock held
227 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700228static void fc_rport_state_enter(struct fc_rport_priv *rdata,
Robert Love42e9a922008-12-09 15:10:17 -0800229 enum fc_rport_state new)
230{
Robert Love42e9a922008-12-09 15:10:17 -0800231 if (rdata->rp_state != new)
232 rdata->retries = 0;
233 rdata->rp_state = new;
234}
235
Robert Love3a3b42b2009-11-03 11:47:39 -0800236/**
237 * fc_rport_work() - Handler for remote port events in the rport_event_queue
238 * @work: Handle to the remote port being dequeued
239 */
Robert Love42e9a922008-12-09 15:10:17 -0800240static void fc_rport_work(struct work_struct *work)
241{
Abhijeet Joglekar571f8242009-02-27 10:54:41 -0800242 u32 port_id;
Joe Eykholtab28f1f2009-08-25 14:00:34 -0700243 struct fc_rport_priv *rdata =
244 container_of(work, struct fc_rport_priv, event_work);
Robert Love3a3b42b2009-11-03 11:47:39 -0800245 struct fc_rport_libfc_priv *rpriv;
Robert Love42e9a922008-12-09 15:10:17 -0800246 enum fc_rport_event event;
Robert Love42e9a922008-12-09 15:10:17 -0800247 struct fc_lport *lport = rdata->local_port;
248 struct fc_rport_operations *rport_ops;
Joe Eykholt629f4422009-08-25 14:01:06 -0700249 struct fc_rport_identifiers ids;
Joe Eykholtf211fa52009-08-25 14:01:01 -0700250 struct fc_rport *rport;
Joe Eykholt96ad8462011-01-28 16:04:02 -0800251 struct fc4_prov *prov;
252 u8 type;
Robert Love42e9a922008-12-09 15:10:17 -0800253
254 mutex_lock(&rdata->rp_mutex);
255 event = rdata->event;
256 rport_ops = rdata->ops;
Joe Eykholtf211fa52009-08-25 14:01:01 -0700257 rport = rdata->rport;
Robert Love42e9a922008-12-09 15:10:17 -0800258
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700259 FC_RPORT_DBG(rdata, "work event %u\n", event);
260
Joe Eykholt629f4422009-08-25 14:01:06 -0700261 switch (event) {
Joe Eykholt4c0f62b2009-08-25 14:01:12 -0700262 case RPORT_EV_READY:
Joe Eykholtf211fa52009-08-25 14:01:01 -0700263 ids = rdata->ids;
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700264 rdata->event = RPORT_EV_NONE;
Joe Eykholtf0342602010-06-11 16:44:57 -0700265 rdata->major_retries = 0;
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700266 kref_get(&rdata->kref);
Robert Love42e9a922008-12-09 15:10:17 -0800267 mutex_unlock(&rdata->rp_mutex);
268
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700269 if (!rport)
270 rport = fc_remote_port_add(lport->host, 0, &ids);
271 if (!rport) {
272 FC_RPORT_DBG(rdata, "Failed to add the rport\n");
273 lport->tt.rport_logoff(rdata);
274 kref_put(&rdata->kref, lport->tt.rport_destroy);
275 return;
Robert Love42e9a922008-12-09 15:10:17 -0800276 }
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700277 mutex_lock(&rdata->rp_mutex);
278 if (rdata->rport)
279 FC_RPORT_DBG(rdata, "rport already allocated\n");
280 rdata->rport = rport;
281 rport->maxframe_size = rdata->maxframe_size;
282 rport->supported_classes = rdata->supported_classes;
283
Robert Love3a3b42b2009-11-03 11:47:39 -0800284 rpriv = rport->dd_data;
285 rpriv->local_port = lport;
286 rpriv->rp_state = rdata->rp_state;
287 rpriv->flags = rdata->flags;
288 rpriv->e_d_tov = rdata->e_d_tov;
289 rpriv->r_a_tov = rdata->r_a_tov;
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700290 mutex_unlock(&rdata->rp_mutex);
291
Joe Eykholt83455922009-08-25 14:02:01 -0700292 if (rport_ops && rport_ops->event_callback) {
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700293 FC_RPORT_DBG(rdata, "callback ev %d\n", event);
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700294 rport_ops->event_callback(lport, rdata, event);
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700295 }
Bhanu Prakash Gollapudi75a27922011-01-28 16:05:27 -0800296 if (rdata->lld_event_callback) {
297 FC_RPORT_DBG(rdata, "lld callback ev %d\n", event);
298 rdata->lld_event_callback(lport, rdata, event);
299 }
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700300 kref_put(&rdata->kref, lport->tt.rport_destroy);
Joe Eykholt629f4422009-08-25 14:01:06 -0700301 break;
302
303 case RPORT_EV_FAILED:
304 case RPORT_EV_LOGO:
305 case RPORT_EV_STOP:
Joe Eykholt96ad8462011-01-28 16:04:02 -0800306 if (rdata->prli_count) {
307 mutex_lock(&fc_prov_mutex);
308 for (type = 1; type < FC_FC4_PROV_SIZE; type++) {
309 prov = fc_passive_prov[type];
310 if (prov && prov->prlo)
311 prov->prlo(rdata);
312 }
313 mutex_unlock(&fc_prov_mutex);
314 }
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700315 port_id = rdata->ids.port_id;
Robert Love42e9a922008-12-09 15:10:17 -0800316 mutex_unlock(&rdata->rp_mutex);
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700317
Joe Eykholt83455922009-08-25 14:02:01 -0700318 if (rport_ops && rport_ops->event_callback) {
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700319 FC_RPORT_DBG(rdata, "callback ev %d\n", event);
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700320 rport_ops->event_callback(lport, rdata, event);
Abhijeet Joglekar571f8242009-02-27 10:54:41 -0800321 }
Bhanu Prakash Gollapudi75a27922011-01-28 16:05:27 -0800322 if (rdata->lld_event_callback) {
323 FC_RPORT_DBG(rdata, "lld callback ev %d\n", event);
324 rdata->lld_event_callback(lport, rdata, event);
325 }
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700326 cancel_delayed_work_sync(&rdata->retry_work);
327
328 /*
329 * Reset any outstanding exchanges before freeing rport.
330 */
331 lport->tt.exch_mgr_reset(lport, 0, port_id);
332 lport->tt.exch_mgr_reset(lport, port_id, 0);
333
334 if (rport) {
Robert Love3a3b42b2009-11-03 11:47:39 -0800335 rpriv = rport->dd_data;
336 rpriv->rp_state = RPORT_ST_DELETE;
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700337 mutex_lock(&rdata->rp_mutex);
338 rdata->rport = NULL;
339 mutex_unlock(&rdata->rp_mutex);
340 fc_remote_port_delete(rport);
341 }
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700342
343 mutex_lock(&lport->disc.disc_mutex);
344 mutex_lock(&rdata->rp_mutex);
345 if (rdata->rp_state == RPORT_ST_DELETE) {
346 if (port_id == FC_FID_DIR_SERV) {
347 rdata->event = RPORT_EV_NONE;
348 mutex_unlock(&rdata->rp_mutex);
Parikh, Neeravfe5e3f12011-02-25 15:02:51 -0800349 kref_put(&rdata->kref, lport->tt.rport_destroy);
Joe Eykholtf0342602010-06-11 16:44:57 -0700350 } else if ((rdata->flags & FC_RP_STARTED) &&
351 rdata->major_retries <
352 lport->max_rport_retry_count) {
353 rdata->major_retries++;
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700354 rdata->event = RPORT_EV_NONE;
355 FC_RPORT_DBG(rdata, "work restart\n");
Joe Eykholta7b12a22010-07-20 15:20:08 -0700356 fc_rport_enter_flogi(rdata);
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700357 mutex_unlock(&rdata->rp_mutex);
358 } else {
359 FC_RPORT_DBG(rdata, "work delete\n");
Joe Eykholt42e90412010-07-20 15:19:37 -0700360 list_del_rcu(&rdata->peers);
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700361 mutex_unlock(&rdata->rp_mutex);
362 kref_put(&rdata->kref, lport->tt.rport_destroy);
363 }
364 } else {
365 /*
366 * Re-open for events. Reissue READY event if ready.
367 */
368 rdata->event = RPORT_EV_NONE;
369 if (rdata->rp_state == RPORT_ST_READY)
370 fc_rport_enter_ready(rdata);
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -0700371 mutex_unlock(&rdata->rp_mutex);
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700372 }
373 mutex_unlock(&lport->disc.disc_mutex);
Joe Eykholt629f4422009-08-25 14:01:06 -0700374 break;
375
376 default:
Robert Love42e9a922008-12-09 15:10:17 -0800377 mutex_unlock(&rdata->rp_mutex);
Joe Eykholt629f4422009-08-25 14:01:06 -0700378 break;
379 }
Robert Love42e9a922008-12-09 15:10:17 -0800380}
381
382/**
Robert Love34f42a02009-02-27 10:55:45 -0800383 * fc_rport_login() - Start the remote port login state machine
Robert Love3a3b42b2009-11-03 11:47:39 -0800384 * @rdata: The remote port to be logged in to
Robert Love42e9a922008-12-09 15:10:17 -0800385 *
386 * Locking Note: Called without the rport lock held. This
387 * function will hold the rport lock, call an _enter_*
388 * function and then unlock the rport.
Joe Eykholt370c3bd2009-08-25 14:03:47 -0700389 *
390 * This indicates the intent to be logged into the remote port.
391 * If it appears we are already logged in, ADISC is used to verify
392 * the setup.
Robert Love42e9a922008-12-09 15:10:17 -0800393 */
Bart Van Asschec6b21c92012-01-13 17:26:20 -0800394static int fc_rport_login(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800395{
Robert Love42e9a922008-12-09 15:10:17 -0800396 mutex_lock(&rdata->rp_mutex);
397
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700398 rdata->flags |= FC_RP_STARTED;
Joe Eykholt370c3bd2009-08-25 14:03:47 -0700399 switch (rdata->rp_state) {
400 case RPORT_ST_READY:
401 FC_RPORT_DBG(rdata, "ADISC port\n");
402 fc_rport_enter_adisc(rdata);
403 break;
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -0700404 case RPORT_ST_DELETE:
405 FC_RPORT_DBG(rdata, "Restart deleted port\n");
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -0700406 break;
Joe Eykholt370c3bd2009-08-25 14:03:47 -0700407 default:
408 FC_RPORT_DBG(rdata, "Login to port\n");
Joe Eykholta7b12a22010-07-20 15:20:08 -0700409 fc_rport_enter_flogi(rdata);
Joe Eykholt370c3bd2009-08-25 14:03:47 -0700410 break;
411 }
Robert Love42e9a922008-12-09 15:10:17 -0800412 mutex_unlock(&rdata->rp_mutex);
413
414 return 0;
415}
416
417/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800418 * fc_rport_enter_delete() - Schedule a remote port to be deleted
419 * @rdata: The remote port to be deleted
420 * @event: The event to report as the reason for deletion
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700421 *
422 * Locking Note: Called with the rport lock held.
423 *
424 * Allow state change into DELETE only once.
425 *
426 * Call queue_work only if there's no event already pending.
427 * Set the new event so that the old pending event will not occur.
428 * Since we have the mutex, even if fc_rport_work() is already started,
429 * it'll see the new event.
430 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700431static void fc_rport_enter_delete(struct fc_rport_priv *rdata,
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700432 enum fc_rport_event event)
433{
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700434 if (rdata->rp_state == RPORT_ST_DELETE)
435 return;
436
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700437 FC_RPORT_DBG(rdata, "Delete port\n");
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700438
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700439 fc_rport_state_enter(rdata, RPORT_ST_DELETE);
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700440
441 if (rdata->event == RPORT_EV_NONE)
442 queue_work(rport_event_queue, &rdata->event_work);
443 rdata->event = event;
444}
445
446/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800447 * fc_rport_logoff() - Logoff and remove a remote port
448 * @rdata: The remote port to be logged off of
Robert Love42e9a922008-12-09 15:10:17 -0800449 *
450 * Locking Note: Called without the rport lock held. This
451 * function will hold the rport lock, call an _enter_*
452 * function and then unlock the rport.
453 */
Bart Van Asschec6b21c92012-01-13 17:26:20 -0800454static int fc_rport_logoff(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800455{
Robert Love42e9a922008-12-09 15:10:17 -0800456 mutex_lock(&rdata->rp_mutex);
457
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700458 FC_RPORT_DBG(rdata, "Remove port\n");
Robert Love42e9a922008-12-09 15:10:17 -0800459
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700460 rdata->flags &= ~FC_RP_STARTED;
Joe Eykholt14194052009-07-29 17:04:43 -0700461 if (rdata->rp_state == RPORT_ST_DELETE) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700462 FC_RPORT_DBG(rdata, "Port in Delete state, not removing\n");
Abhijeet Joglekarb4c6f542009-04-21 16:27:04 -0700463 goto out;
464 }
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700465 fc_rport_enter_logo(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800466
467 /*
Joe Eykholt14194052009-07-29 17:04:43 -0700468 * Change the state to Delete so that we discard
Robert Love42e9a922008-12-09 15:10:17 -0800469 * the response.
470 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700471 fc_rport_enter_delete(rdata, RPORT_EV_STOP);
Abhijeet Joglekarb4c6f542009-04-21 16:27:04 -0700472out:
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -0700473 mutex_unlock(&rdata->rp_mutex);
Robert Love42e9a922008-12-09 15:10:17 -0800474 return 0;
475}
476
477/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800478 * fc_rport_enter_ready() - Transition to the RPORT_ST_READY state
479 * @rdata: The remote port that is ready
Robert Love42e9a922008-12-09 15:10:17 -0800480 *
481 * Locking Note: The rport lock is expected to be held before calling
482 * this routine.
483 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700484static void fc_rport_enter_ready(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800485{
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700486 fc_rport_state_enter(rdata, RPORT_ST_READY);
Robert Love42e9a922008-12-09 15:10:17 -0800487
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700488 FC_RPORT_DBG(rdata, "Port is Ready\n");
Robert Love42e9a922008-12-09 15:10:17 -0800489
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700490 if (rdata->event == RPORT_EV_NONE)
491 queue_work(rport_event_queue, &rdata->event_work);
Joe Eykholt4c0f62b2009-08-25 14:01:12 -0700492 rdata->event = RPORT_EV_READY;
Robert Love42e9a922008-12-09 15:10:17 -0800493}
494
495/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800496 * fc_rport_timeout() - Handler for the retry_work timer
497 * @work: Handle to the remote port that has timed out
Robert Love42e9a922008-12-09 15:10:17 -0800498 *
499 * Locking Note: Called without the rport lock held. This
500 * function will hold the rport lock, call an _enter_*
501 * function and then unlock the rport.
502 */
503static void fc_rport_timeout(struct work_struct *work)
504{
Joe Eykholtab28f1f2009-08-25 14:00:34 -0700505 struct fc_rport_priv *rdata =
506 container_of(work, struct fc_rport_priv, retry_work.work);
Robert Love42e9a922008-12-09 15:10:17 -0800507
508 mutex_lock(&rdata->rp_mutex);
509
510 switch (rdata->rp_state) {
Joe Eykholta7b12a22010-07-20 15:20:08 -0700511 case RPORT_ST_FLOGI:
512 fc_rport_enter_flogi(rdata);
513 break;
Robert Love42e9a922008-12-09 15:10:17 -0800514 case RPORT_ST_PLOGI:
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700515 fc_rport_enter_plogi(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800516 break;
517 case RPORT_ST_PRLI:
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700518 fc_rport_enter_prli(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800519 break;
520 case RPORT_ST_RTV:
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700521 fc_rport_enter_rtv(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800522 break;
Joe Eykholt370c3bd2009-08-25 14:03:47 -0700523 case RPORT_ST_ADISC:
524 fc_rport_enter_adisc(rdata);
525 break;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700526 case RPORT_ST_PLOGI_WAIT:
Robert Love42e9a922008-12-09 15:10:17 -0800527 case RPORT_ST_READY:
528 case RPORT_ST_INIT:
Joe Eykholt14194052009-07-29 17:04:43 -0700529 case RPORT_ST_DELETE:
Robert Love42e9a922008-12-09 15:10:17 -0800530 break;
531 }
532
533 mutex_unlock(&rdata->rp_mutex);
Robert Love42e9a922008-12-09 15:10:17 -0800534}
535
536/**
Robert Love34f42a02009-02-27 10:55:45 -0800537 * fc_rport_error() - Error handler, called once retries have been exhausted
Robert Love3a3b42b2009-11-03 11:47:39 -0800538 * @rdata: The remote port the error is happened on
539 * @fp: The error code encapsulated in a frame pointer
Robert Love42e9a922008-12-09 15:10:17 -0800540 *
Robert Love42e9a922008-12-09 15:10:17 -0800541 * Locking Note: The rport lock is expected to be held before
542 * calling this routine
543 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700544static void fc_rport_error(struct fc_rport_priv *rdata, struct fc_frame *fp)
Robert Love42e9a922008-12-09 15:10:17 -0800545{
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700546 FC_RPORT_DBG(rdata, "Error %ld in state %s, retries %d\n",
Joe Eykholtcdbe6df2009-08-25 14:01:39 -0700547 IS_ERR(fp) ? -PTR_ERR(fp) : 0,
548 fc_rport_state(rdata), rdata->retries);
Robert Love42e9a922008-12-09 15:10:17 -0800549
Chris Leech6755db12009-02-27 10:55:02 -0800550 switch (rdata->rp_state) {
Joe Eykholta7b12a22010-07-20 15:20:08 -0700551 case RPORT_ST_FLOGI:
Chris Leech6755db12009-02-27 10:55:02 -0800552 case RPORT_ST_PLOGI:
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700553 rdata->flags &= ~FC_RP_STARTED;
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700554 fc_rport_enter_delete(rdata, RPORT_EV_FAILED);
Chris Leech6755db12009-02-27 10:55:02 -0800555 break;
556 case RPORT_ST_RTV:
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700557 fc_rport_enter_ready(rdata);
Chris Leech6755db12009-02-27 10:55:02 -0800558 break;
Joe Eykholt370c3bd2009-08-25 14:03:47 -0700559 case RPORT_ST_PRLI:
560 case RPORT_ST_ADISC:
561 fc_rport_enter_logo(rdata);
562 break;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700563 case RPORT_ST_PLOGI_WAIT:
Joe Eykholt14194052009-07-29 17:04:43 -0700564 case RPORT_ST_DELETE:
Chris Leech6755db12009-02-27 10:55:02 -0800565 case RPORT_ST_READY:
566 case RPORT_ST_INIT:
567 break;
Robert Love42e9a922008-12-09 15:10:17 -0800568 }
569}
570
571/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800572 * fc_rport_error_retry() - Handler for remote port state retries
573 * @rdata: The remote port whose state is to be retried
574 * @fp: The error code encapsulated in a frame pointer
Chris Leech6755db12009-02-27 10:55:02 -0800575 *
576 * If the error was an exchange timeout retry immediately,
577 * otherwise wait for E_D_TOV.
578 *
579 * Locking Note: The rport lock is expected to be held before
580 * calling this routine
581 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700582static void fc_rport_error_retry(struct fc_rport_priv *rdata,
583 struct fc_frame *fp)
Chris Leech6755db12009-02-27 10:55:02 -0800584{
Krishna Mohana5860692013-02-13 16:33:04 -0800585 unsigned long delay = msecs_to_jiffies(FC_DEF_E_D_TOV);
Chris Leech6755db12009-02-27 10:55:02 -0800586
587 /* make sure this isn't an FC_EX_CLOSED error, never retry those */
588 if (PTR_ERR(fp) == -FC_EX_CLOSED)
Hillf Danton28a4af12011-01-28 16:03:26 -0800589 goto out;
Chris Leech6755db12009-02-27 10:55:02 -0800590
Abhijeet Joglekara3666952009-05-01 10:01:26 -0700591 if (rdata->retries < rdata->local_port->max_rport_retry_count) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700592 FC_RPORT_DBG(rdata, "Error %ld in state %s, retrying\n",
593 PTR_ERR(fp), fc_rport_state(rdata));
Chris Leech6755db12009-02-27 10:55:02 -0800594 rdata->retries++;
595 /* no additional delay on exchange timeouts */
596 if (PTR_ERR(fp) == -FC_EX_TIMEOUT)
597 delay = 0;
Chris Leech6755db12009-02-27 10:55:02 -0800598 schedule_delayed_work(&rdata->retry_work, delay);
599 return;
600 }
601
Hillf Danton28a4af12011-01-28 16:03:26 -0800602out:
603 fc_rport_error(rdata, fp);
Chris Leech6755db12009-02-27 10:55:02 -0800604}
605
606/**
Joe Eykholta7b12a22010-07-20 15:20:08 -0700607 * fc_rport_login_complete() - Handle parameters and completion of p-mp login.
608 * @rdata: The remote port which we logged into or which logged into us.
609 * @fp: The FLOGI or PLOGI request or response frame
610 *
611 * Returns non-zero error if a problem is detected with the frame.
612 * Does not free the frame.
613 *
614 * This is only used in point-to-multipoint mode for FIP currently.
615 */
616static int fc_rport_login_complete(struct fc_rport_priv *rdata,
617 struct fc_frame *fp)
618{
619 struct fc_lport *lport = rdata->local_port;
620 struct fc_els_flogi *flogi;
621 unsigned int e_d_tov;
622 u16 csp_flags;
623
624 flogi = fc_frame_payload_get(fp, sizeof(*flogi));
625 if (!flogi)
626 return -EINVAL;
627
628 csp_flags = ntohs(flogi->fl_csp.sp_features);
629
630 if (fc_frame_payload_op(fp) == ELS_FLOGI) {
631 if (csp_flags & FC_SP_FT_FPORT) {
632 FC_RPORT_DBG(rdata, "Fabric bit set in FLOGI\n");
633 return -EINVAL;
634 }
635 } else {
636
637 /*
638 * E_D_TOV is not valid on an incoming FLOGI request.
639 */
640 e_d_tov = ntohl(flogi->fl_csp.sp_e_d_tov);
641 if (csp_flags & FC_SP_FT_EDTR)
642 e_d_tov /= 1000000;
643 if (e_d_tov > rdata->e_d_tov)
644 rdata->e_d_tov = e_d_tov;
645 }
646 rdata->maxframe_size = fc_plogi_get_maxframe(flogi, lport->mfs);
647 return 0;
648}
649
650/**
651 * fc_rport_flogi_resp() - Handle response to FLOGI request for p-mp mode
652 * @sp: The sequence that the FLOGI was on
653 * @fp: The FLOGI response frame
654 * @rp_arg: The remote port that received the FLOGI response
655 */
Bart Van Asschec6b21c92012-01-13 17:26:20 -0800656static void fc_rport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp,
657 void *rp_arg)
Joe Eykholta7b12a22010-07-20 15:20:08 -0700658{
659 struct fc_rport_priv *rdata = rp_arg;
660 struct fc_lport *lport = rdata->local_port;
661 struct fc_els_flogi *flogi;
662 unsigned int r_a_tov;
663
664 FC_RPORT_DBG(rdata, "Received a FLOGI %s\n", fc_els_resp_type(fp));
665
666 if (fp == ERR_PTR(-FC_EX_CLOSED))
Hillf Danton0e9e3d32010-11-30 16:19:04 -0800667 goto put;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700668
669 mutex_lock(&rdata->rp_mutex);
670
671 if (rdata->rp_state != RPORT_ST_FLOGI) {
672 FC_RPORT_DBG(rdata, "Received a FLOGI response, but in state "
673 "%s\n", fc_rport_state(rdata));
674 if (IS_ERR(fp))
675 goto err;
676 goto out;
677 }
678
679 if (IS_ERR(fp)) {
680 fc_rport_error(rdata, fp);
681 goto err;
682 }
683
684 if (fc_frame_payload_op(fp) != ELS_LS_ACC)
685 goto bad;
686 if (fc_rport_login_complete(rdata, fp))
687 goto bad;
688
689 flogi = fc_frame_payload_get(fp, sizeof(*flogi));
690 if (!flogi)
691 goto bad;
692 r_a_tov = ntohl(flogi->fl_csp.sp_r_a_tov);
693 if (r_a_tov > rdata->r_a_tov)
694 rdata->r_a_tov = r_a_tov;
695
696 if (rdata->ids.port_name < lport->wwpn)
697 fc_rport_enter_plogi(rdata);
698 else
699 fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
700out:
701 fc_frame_free(fp);
702err:
703 mutex_unlock(&rdata->rp_mutex);
Hillf Danton0e9e3d32010-11-30 16:19:04 -0800704put:
Joe Eykholta7b12a22010-07-20 15:20:08 -0700705 kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
706 return;
707bad:
708 FC_RPORT_DBG(rdata, "Bad FLOGI response\n");
709 fc_rport_error_retry(rdata, fp);
710 goto out;
711}
712
713/**
714 * fc_rport_enter_flogi() - Send a FLOGI request to the remote port for p-mp
715 * @rdata: The remote port to send a FLOGI to
716 *
717 * Locking Note: The rport lock is expected to be held before calling
718 * this routine.
719 */
720static void fc_rport_enter_flogi(struct fc_rport_priv *rdata)
721{
722 struct fc_lport *lport = rdata->local_port;
723 struct fc_frame *fp;
724
725 if (!lport->point_to_multipoint)
726 return fc_rport_enter_plogi(rdata);
727
728 FC_RPORT_DBG(rdata, "Entered FLOGI state from %s state\n",
729 fc_rport_state(rdata));
730
731 fc_rport_state_enter(rdata, RPORT_ST_FLOGI);
732
733 fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi));
734 if (!fp)
735 return fc_rport_error_retry(rdata, fp);
736
737 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_FLOGI,
738 fc_rport_flogi_resp, rdata,
739 2 * lport->r_a_tov))
740 fc_rport_error_retry(rdata, NULL);
741 else
742 kref_get(&rdata->kref);
743}
744
745/**
746 * fc_rport_recv_flogi_req() - Handle Fabric Login (FLOGI) request in p-mp mode
747 * @lport: The local port that received the PLOGI request
Joe Eykholta7b12a22010-07-20 15:20:08 -0700748 * @rx_fp: The PLOGI request frame
749 */
750static void fc_rport_recv_flogi_req(struct fc_lport *lport,
Joe Eykholt922611562010-07-20 15:21:12 -0700751 struct fc_frame *rx_fp)
Joe Eykholta7b12a22010-07-20 15:20:08 -0700752{
753 struct fc_disc *disc;
754 struct fc_els_flogi *flp;
755 struct fc_rport_priv *rdata;
756 struct fc_frame *fp = rx_fp;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700757 struct fc_seq_els_data rjt_data;
Joe Eykholt24f089e2010-07-20 15:21:01 -0700758 u32 sid;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700759
Joe Eykholt251748a2010-07-20 15:20:56 -0700760 sid = fc_frame_sid(fp);
Joe Eykholta7b12a22010-07-20 15:20:08 -0700761
762 FC_RPORT_ID_DBG(lport, sid, "Received FLOGI request\n");
763
764 disc = &lport->disc;
765 mutex_lock(&disc->disc_mutex);
766
767 if (!lport->point_to_multipoint) {
768 rjt_data.reason = ELS_RJT_UNSUP;
769 rjt_data.explan = ELS_EXPL_NONE;
770 goto reject;
771 }
772
773 flp = fc_frame_payload_get(fp, sizeof(*flp));
774 if (!flp) {
775 rjt_data.reason = ELS_RJT_LOGIC;
776 rjt_data.explan = ELS_EXPL_INV_LEN;
777 goto reject;
778 }
779
780 rdata = lport->tt.rport_lookup(lport, sid);
781 if (!rdata) {
782 rjt_data.reason = ELS_RJT_FIP;
783 rjt_data.explan = ELS_EXPL_NOT_NEIGHBOR;
784 goto reject;
785 }
786 mutex_lock(&rdata->rp_mutex);
787
788 FC_RPORT_DBG(rdata, "Received FLOGI in %s state\n",
789 fc_rport_state(rdata));
790
791 switch (rdata->rp_state) {
792 case RPORT_ST_INIT:
Kiran Patil48058482011-06-20 16:58:59 -0700793 /*
794 * If received the FLOGI request on RPORT which is INIT state
795 * (means not transition to FLOGI either fc_rport timeout
796 * function didn;t trigger or this end hasn;t received
797 * beacon yet from other end. In that case only, allow RPORT
798 * state machine to continue, otherwise fall through which
799 * causes the code to send reject response.
800 * NOTE; Not checking for FIP->state such as VNMP_UP or
801 * VNMP_CLAIM because if FIP state is not one of those,
802 * RPORT wouldn;t have created and 'rport_lookup' would have
803 * failed anyway in that case.
804 */
805 if (lport->point_to_multipoint)
806 break;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700807 case RPORT_ST_DELETE:
808 mutex_unlock(&rdata->rp_mutex);
809 rjt_data.reason = ELS_RJT_FIP;
810 rjt_data.explan = ELS_EXPL_NOT_NEIGHBOR;
811 goto reject;
812 case RPORT_ST_FLOGI:
813 case RPORT_ST_PLOGI_WAIT:
814 case RPORT_ST_PLOGI:
815 break;
816 case RPORT_ST_PRLI:
817 case RPORT_ST_RTV:
818 case RPORT_ST_READY:
819 case RPORT_ST_ADISC:
820 /*
821 * Set the remote port to be deleted and to then restart.
822 * This queues work to be sure exchanges are reset.
823 */
824 fc_rport_enter_delete(rdata, RPORT_EV_LOGO);
825 mutex_unlock(&rdata->rp_mutex);
826 rjt_data.reason = ELS_RJT_BUSY;
827 rjt_data.explan = ELS_EXPL_NONE;
828 goto reject;
829 }
830 if (fc_rport_login_complete(rdata, fp)) {
831 mutex_unlock(&rdata->rp_mutex);
832 rjt_data.reason = ELS_RJT_LOGIC;
833 rjt_data.explan = ELS_EXPL_NONE;
834 goto reject;
835 }
Joe Eykholta7b12a22010-07-20 15:20:08 -0700836
837 fp = fc_frame_alloc(lport, sizeof(*flp));
838 if (!fp)
839 goto out;
840
Joe Eykholta7b12a22010-07-20 15:20:08 -0700841 fc_flogi_fill(lport, fp);
842 flp = fc_frame_payload_get(fp, sizeof(*flp));
843 flp->fl_cmd = ELS_LS_ACC;
844
Joe Eykholt24f089e2010-07-20 15:21:01 -0700845 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
846 lport->tt.frame_send(lport, fp);
Joe Eykholta7b12a22010-07-20 15:20:08 -0700847
848 if (rdata->ids.port_name < lport->wwpn)
849 fc_rport_enter_plogi(rdata);
850 else
851 fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
852out:
853 mutex_unlock(&rdata->rp_mutex);
854 mutex_unlock(&disc->disc_mutex);
Joe Eykholt24f089e2010-07-20 15:21:01 -0700855 fc_frame_free(rx_fp);
Joe Eykholta7b12a22010-07-20 15:20:08 -0700856 return;
857
858reject:
859 mutex_unlock(&disc->disc_mutex);
Joe Eykholt922611562010-07-20 15:21:12 -0700860 lport->tt.seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
Joe Eykholt24f089e2010-07-20 15:21:01 -0700861 fc_frame_free(rx_fp);
Joe Eykholta7b12a22010-07-20 15:20:08 -0700862}
863
864/**
865 * fc_rport_plogi_resp() - Handler for ELS PLOGI responses
Robert Love3a3b42b2009-11-03 11:47:39 -0800866 * @sp: The sequence the PLOGI is on
867 * @fp: The PLOGI response frame
868 * @rdata_arg: The remote port that sent the PLOGI response
Robert Love42e9a922008-12-09 15:10:17 -0800869 *
870 * Locking Note: This function will be called without the rport lock
871 * held, but it will lock, call an _enter_* function or fc_rport_error
872 * and then unlock the rport.
873 */
874static void fc_rport_plogi_resp(struct fc_seq *sp, struct fc_frame *fp,
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700875 void *rdata_arg)
Robert Love42e9a922008-12-09 15:10:17 -0800876{
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700877 struct fc_rport_priv *rdata = rdata_arg;
Robert Love42e9a922008-12-09 15:10:17 -0800878 struct fc_lport *lport = rdata->local_port;
Robert Lovea29e7642009-04-21 16:27:41 -0700879 struct fc_els_flogi *plp = NULL;
Robert Love42e9a922008-12-09 15:10:17 -0800880 u16 csp_seq;
881 u16 cssp_seq;
882 u8 op;
883
884 mutex_lock(&rdata->rp_mutex);
885
Joe Eykholtf657d292009-08-25 14:03:21 -0700886 FC_RPORT_DBG(rdata, "Received a PLOGI %s\n", fc_els_resp_type(fp));
Robert Love42e9a922008-12-09 15:10:17 -0800887
888 if (rdata->rp_state != RPORT_ST_PLOGI) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700889 FC_RPORT_DBG(rdata, "Received a PLOGI response, but in state "
890 "%s\n", fc_rport_state(rdata));
Abhijeet Joglekar76f68042009-04-21 16:26:58 -0700891 if (IS_ERR(fp))
892 goto err;
Robert Love42e9a922008-12-09 15:10:17 -0800893 goto out;
894 }
895
Abhijeet Joglekar76f68042009-04-21 16:26:58 -0700896 if (IS_ERR(fp)) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700897 fc_rport_error_retry(rdata, fp);
Abhijeet Joglekar76f68042009-04-21 16:26:58 -0700898 goto err;
899 }
900
Robert Love42e9a922008-12-09 15:10:17 -0800901 op = fc_frame_payload_op(fp);
902 if (op == ELS_LS_ACC &&
903 (plp = fc_frame_payload_get(fp, sizeof(*plp))) != NULL) {
Joe Eykholtf211fa52009-08-25 14:01:01 -0700904 rdata->ids.port_name = get_unaligned_be64(&plp->fl_wwpn);
905 rdata->ids.node_name = get_unaligned_be64(&plp->fl_wwnn);
Robert Love42e9a922008-12-09 15:10:17 -0800906
Bhanu Prakash Gollapudi75a27922011-01-28 16:05:27 -0800907 /* save plogi response sp_features for further reference */
908 rdata->sp_features = ntohs(plp->fl_csp.sp_features);
909
Joe Eykholta7b12a22010-07-20 15:20:08 -0700910 if (lport->point_to_multipoint)
911 fc_rport_login_complete(rdata, fp);
Robert Love42e9a922008-12-09 15:10:17 -0800912 csp_seq = ntohs(plp->fl_csp.sp_tot_seq);
913 cssp_seq = ntohs(plp->fl_cssp[3 - 1].cp_con_seq);
914 if (cssp_seq < csp_seq)
915 csp_seq = cssp_seq;
916 rdata->max_seq = csp_seq;
Joe Eykholtf211fa52009-08-25 14:01:01 -0700917 rdata->maxframe_size = fc_plogi_get_maxframe(plp, lport->mfs);
Joe Eykholt3ac6f982009-08-25 14:03:26 -0700918 fc_rport_enter_prli(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800919 } else
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700920 fc_rport_error_retry(rdata, fp);
Robert Love42e9a922008-12-09 15:10:17 -0800921
922out:
923 fc_frame_free(fp);
924err:
925 mutex_unlock(&rdata->rp_mutex);
Joe Eykholtf211fa52009-08-25 14:01:01 -0700926 kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
Robert Love42e9a922008-12-09 15:10:17 -0800927}
928
Mark Rustade0335f62013-05-18 04:01:36 +0000929static bool
930fc_rport_compatible_roles(struct fc_lport *lport, struct fc_rport_priv *rdata)
931{
932 if (rdata->ids.roles == FC_PORT_ROLE_UNKNOWN)
933 return true;
934 if ((rdata->ids.roles & FC_PORT_ROLE_FCP_TARGET) &&
935 (lport->service_params & FCP_SPPF_INIT_FCN))
936 return true;
937 if ((rdata->ids.roles & FC_PORT_ROLE_FCP_INITIATOR) &&
938 (lport->service_params & FCP_SPPF_TARG_FCN))
939 return true;
940 return false;
941}
942
Robert Love42e9a922008-12-09 15:10:17 -0800943/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800944 * fc_rport_enter_plogi() - Send Port Login (PLOGI) request
945 * @rdata: The remote port to send a PLOGI to
Robert Love42e9a922008-12-09 15:10:17 -0800946 *
947 * Locking Note: The rport lock is expected to be held before calling
948 * this routine.
949 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700950static void fc_rport_enter_plogi(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800951{
Robert Love42e9a922008-12-09 15:10:17 -0800952 struct fc_lport *lport = rdata->local_port;
953 struct fc_frame *fp;
954
Mark Rustade0335f62013-05-18 04:01:36 +0000955 if (!fc_rport_compatible_roles(lport, rdata)) {
956 FC_RPORT_DBG(rdata, "PLOGI suppressed for incompatible role\n");
957 fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
958 return;
959 }
960
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700961 FC_RPORT_DBG(rdata, "Port entered PLOGI state from %s state\n",
962 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -0800963
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700964 fc_rport_state_enter(rdata, RPORT_ST_PLOGI);
Robert Love42e9a922008-12-09 15:10:17 -0800965
Joe Eykholtf211fa52009-08-25 14:01:01 -0700966 rdata->maxframe_size = FC_MIN_MAX_PAYLOAD;
Robert Love42e9a922008-12-09 15:10:17 -0800967 fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi));
968 if (!fp) {
Joe Eykholta7b12a22010-07-20 15:20:08 -0700969 FC_RPORT_DBG(rdata, "%s frame alloc failed\n", __func__);
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700970 fc_rport_error_retry(rdata, fp);
Robert Love42e9a922008-12-09 15:10:17 -0800971 return;
972 }
973 rdata->e_d_tov = lport->e_d_tov;
974
Joe Eykholtf211fa52009-08-25 14:01:01 -0700975 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_PLOGI,
Joe Eykholtb94f8952009-11-03 11:50:21 -0800976 fc_rport_plogi_resp, rdata,
977 2 * lport->r_a_tov))
Chris Leech8f550f92009-10-21 16:28:09 -0700978 fc_rport_error_retry(rdata, NULL);
Robert Love42e9a922008-12-09 15:10:17 -0800979 else
Joe Eykholtf211fa52009-08-25 14:01:01 -0700980 kref_get(&rdata->kref);
Robert Love42e9a922008-12-09 15:10:17 -0800981}
982
983/**
Robert Love34f42a02009-02-27 10:55:45 -0800984 * fc_rport_prli_resp() - Process Login (PRLI) response handler
Robert Love3a3b42b2009-11-03 11:47:39 -0800985 * @sp: The sequence the PRLI response was on
986 * @fp: The PRLI response frame
987 * @rdata_arg: The remote port that sent the PRLI response
Robert Love42e9a922008-12-09 15:10:17 -0800988 *
989 * Locking Note: This function will be called without the rport lock
990 * held, but it will lock, call an _enter_* function or fc_rport_error
991 * and then unlock the rport.
992 */
993static void fc_rport_prli_resp(struct fc_seq *sp, struct fc_frame *fp,
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700994 void *rdata_arg)
Robert Love42e9a922008-12-09 15:10:17 -0800995{
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700996 struct fc_rport_priv *rdata = rdata_arg;
Robert Love42e9a922008-12-09 15:10:17 -0800997 struct {
998 struct fc_els_prli prli;
999 struct fc_els_spp spp;
1000 } *pp;
Joe Eykholt925ceda2011-01-28 16:04:23 -08001001 struct fc_els_spp temp_spp;
1002 struct fc4_prov *prov;
Robert Love42e9a922008-12-09 15:10:17 -08001003 u32 roles = FC_RPORT_ROLE_UNKNOWN;
1004 u32 fcp_parm = 0;
1005 u8 op;
Bhanu Prakash Gollapudi618461c2010-06-11 16:43:54 -07001006 u8 resp_code = 0;
Robert Love42e9a922008-12-09 15:10:17 -08001007
1008 mutex_lock(&rdata->rp_mutex);
1009
Joe Eykholtf657d292009-08-25 14:03:21 -07001010 FC_RPORT_DBG(rdata, "Received a PRLI %s\n", fc_els_resp_type(fp));
Robert Love42e9a922008-12-09 15:10:17 -08001011
1012 if (rdata->rp_state != RPORT_ST_PRLI) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001013 FC_RPORT_DBG(rdata, "Received a PRLI response, but in state "
1014 "%s\n", fc_rport_state(rdata));
Abhijeet Joglekar76f68042009-04-21 16:26:58 -07001015 if (IS_ERR(fp))
1016 goto err;
Robert Love42e9a922008-12-09 15:10:17 -08001017 goto out;
1018 }
1019
Abhijeet Joglekar76f68042009-04-21 16:26:58 -07001020 if (IS_ERR(fp)) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001021 fc_rport_error_retry(rdata, fp);
Abhijeet Joglekar76f68042009-04-21 16:26:58 -07001022 goto err;
1023 }
1024
Robert Love6bd054c2009-08-25 14:03:04 -07001025 /* reinitialize remote port roles */
1026 rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
1027
Robert Love42e9a922008-12-09 15:10:17 -08001028 op = fc_frame_payload_op(fp);
1029 if (op == ELS_LS_ACC) {
1030 pp = fc_frame_payload_get(fp, sizeof(*pp));
Bhanu Prakash Gollapudi618461c2010-06-11 16:43:54 -07001031 if (!pp)
1032 goto out;
1033
1034 resp_code = (pp->spp.spp_flags & FC_SPP_RESP_MASK);
1035 FC_RPORT_DBG(rdata, "PRLI spp_flags = 0x%x\n",
1036 pp->spp.spp_flags);
Bhanu Prakash Gollapudi75a27922011-01-28 16:05:27 -08001037 rdata->spp_type = pp->spp.spp_type;
Bhanu Prakash Gollapudi618461c2010-06-11 16:43:54 -07001038 if (resp_code != FC_SPP_RESP_ACK) {
1039 if (resp_code == FC_SPP_RESP_CONF)
1040 fc_rport_error(rdata, fp);
1041 else
1042 fc_rport_error_retry(rdata, fp);
1043 goto out;
Robert Love42e9a922008-12-09 15:10:17 -08001044 }
Bhanu Prakash Gollapudi618461c2010-06-11 16:43:54 -07001045 if (pp->prli.prli_spp_len < sizeof(pp->spp))
1046 goto out;
1047
1048 fcp_parm = ntohl(pp->spp.spp_params);
1049 if (fcp_parm & FCP_SPPF_RETRY)
1050 rdata->flags |= FC_RP_FLAGS_RETRY;
Bhanu Prakash Gollapudi75a27922011-01-28 16:05:27 -08001051 if (fcp_parm & FCP_SPPF_CONF_COMPL)
1052 rdata->flags |= FC_RP_FLAGS_CONF_REQ;
Robert Love42e9a922008-12-09 15:10:17 -08001053
Joe Eykholt925ceda2011-01-28 16:04:23 -08001054 prov = fc_passive_prov[FC_TYPE_FCP];
1055 if (prov) {
1056 memset(&temp_spp, 0, sizeof(temp_spp));
1057 prov->prli(rdata, pp->prli.prli_spp_len,
1058 &pp->spp, &temp_spp);
1059 }
1060
Joe Eykholtf211fa52009-08-25 14:01:01 -07001061 rdata->supported_classes = FC_COS_CLASS3;
Robert Love42e9a922008-12-09 15:10:17 -08001062 if (fcp_parm & FCP_SPPF_INIT_FCN)
1063 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1064 if (fcp_parm & FCP_SPPF_TARG_FCN)
1065 roles |= FC_RPORT_ROLE_FCP_TARGET;
1066
Joe Eykholtf211fa52009-08-25 14:01:01 -07001067 rdata->ids.roles = roles;
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001068 fc_rport_enter_rtv(rdata);
Robert Love42e9a922008-12-09 15:10:17 -08001069
1070 } else {
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001071 FC_RPORT_DBG(rdata, "Bad ELS response for PRLI command\n");
Bhanu Prakash Gollapudi292e40b2010-06-11 16:43:49 -07001072 fc_rport_error_retry(rdata, fp);
Robert Love42e9a922008-12-09 15:10:17 -08001073 }
1074
1075out:
1076 fc_frame_free(fp);
1077err:
1078 mutex_unlock(&rdata->rp_mutex);
Joe Eykholtf211fa52009-08-25 14:01:01 -07001079 kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
Robert Love42e9a922008-12-09 15:10:17 -08001080}
1081
1082/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001083 * fc_rport_enter_prli() - Send Process Login (PRLI) request
1084 * @rdata: The remote port to send the PRLI request to
Robert Love42e9a922008-12-09 15:10:17 -08001085 *
1086 * Locking Note: The rport lock is expected to be held before calling
1087 * this routine.
1088 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001089static void fc_rport_enter_prli(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -08001090{
Robert Love42e9a922008-12-09 15:10:17 -08001091 struct fc_lport *lport = rdata->local_port;
1092 struct {
1093 struct fc_els_prli prli;
1094 struct fc_els_spp spp;
1095 } *pp;
1096 struct fc_frame *fp;
Joe Eykholt925ceda2011-01-28 16:04:23 -08001097 struct fc4_prov *prov;
Robert Love42e9a922008-12-09 15:10:17 -08001098
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001099 /*
1100 * If the rport is one of the well known addresses
1101 * we skip PRLI and RTV and go straight to READY.
1102 */
1103 if (rdata->ids.port_id >= FC_FID_DOM_MGR) {
1104 fc_rport_enter_ready(rdata);
1105 return;
1106 }
1107
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001108 FC_RPORT_DBG(rdata, "Port entered PRLI state from %s state\n",
1109 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -08001110
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001111 fc_rport_state_enter(rdata, RPORT_ST_PRLI);
Robert Love42e9a922008-12-09 15:10:17 -08001112
1113 fp = fc_frame_alloc(lport, sizeof(*pp));
1114 if (!fp) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001115 fc_rport_error_retry(rdata, fp);
Robert Love42e9a922008-12-09 15:10:17 -08001116 return;
1117 }
1118
Joe Eykholt925ceda2011-01-28 16:04:23 -08001119 fc_prli_fill(lport, fp);
1120
1121 prov = fc_passive_prov[FC_TYPE_FCP];
1122 if (prov) {
1123 pp = fc_frame_payload_get(fp, sizeof(*pp));
1124 prov->prli(rdata, sizeof(pp->spp), NULL, &pp->spp);
1125 }
1126
1127 fc_fill_fc_hdr(fp, FC_RCTL_ELS_REQ, rdata->ids.port_id,
1128 fc_host_port_id(lport->host), FC_TYPE_ELS,
1129 FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0);
1130
1131 if (!lport->tt.exch_seq_send(lport, fp, fc_rport_prli_resp,
1132 NULL, rdata, 2 * lport->r_a_tov))
Chris Leech8f550f92009-10-21 16:28:09 -07001133 fc_rport_error_retry(rdata, NULL);
Robert Love42e9a922008-12-09 15:10:17 -08001134 else
Joe Eykholtf211fa52009-08-25 14:01:01 -07001135 kref_get(&rdata->kref);
Robert Love42e9a922008-12-09 15:10:17 -08001136}
1137
1138/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001139 * fc_rport_els_rtv_resp() - Handler for Request Timeout Value (RTV) responses
1140 * @sp: The sequence the RTV was on
1141 * @fp: The RTV response frame
1142 * @rdata_arg: The remote port that sent the RTV response
Robert Love42e9a922008-12-09 15:10:17 -08001143 *
1144 * Many targets don't seem to support this.
1145 *
1146 * Locking Note: This function will be called without the rport lock
1147 * held, but it will lock, call an _enter_* function or fc_rport_error
1148 * and then unlock the rport.
1149 */
1150static void fc_rport_rtv_resp(struct fc_seq *sp, struct fc_frame *fp,
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001151 void *rdata_arg)
Robert Love42e9a922008-12-09 15:10:17 -08001152{
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001153 struct fc_rport_priv *rdata = rdata_arg;
Robert Love42e9a922008-12-09 15:10:17 -08001154 u8 op;
1155
1156 mutex_lock(&rdata->rp_mutex);
1157
Joe Eykholtf657d292009-08-25 14:03:21 -07001158 FC_RPORT_DBG(rdata, "Received a RTV %s\n", fc_els_resp_type(fp));
Robert Love42e9a922008-12-09 15:10:17 -08001159
1160 if (rdata->rp_state != RPORT_ST_RTV) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001161 FC_RPORT_DBG(rdata, "Received a RTV response, but in state "
1162 "%s\n", fc_rport_state(rdata));
Abhijeet Joglekar76f68042009-04-21 16:26:58 -07001163 if (IS_ERR(fp))
1164 goto err;
Robert Love42e9a922008-12-09 15:10:17 -08001165 goto out;
1166 }
1167
Abhijeet Joglekar76f68042009-04-21 16:26:58 -07001168 if (IS_ERR(fp)) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001169 fc_rport_error(rdata, fp);
Abhijeet Joglekar76f68042009-04-21 16:26:58 -07001170 goto err;
1171 }
1172
Robert Love42e9a922008-12-09 15:10:17 -08001173 op = fc_frame_payload_op(fp);
1174 if (op == ELS_LS_ACC) {
1175 struct fc_els_rtv_acc *rtv;
1176 u32 toq;
1177 u32 tov;
1178
1179 rtv = fc_frame_payload_get(fp, sizeof(*rtv));
1180 if (rtv) {
1181 toq = ntohl(rtv->rtv_toq);
1182 tov = ntohl(rtv->rtv_r_a_tov);
1183 if (tov == 0)
1184 tov = 1;
1185 rdata->r_a_tov = tov;
1186 tov = ntohl(rtv->rtv_e_d_tov);
1187 if (toq & FC_ELS_RTV_EDRES)
1188 tov /= 1000000;
1189 if (tov == 0)
1190 tov = 1;
1191 rdata->e_d_tov = tov;
1192 }
1193 }
1194
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001195 fc_rport_enter_ready(rdata);
Robert Love42e9a922008-12-09 15:10:17 -08001196
1197out:
1198 fc_frame_free(fp);
1199err:
1200 mutex_unlock(&rdata->rp_mutex);
Joe Eykholtf211fa52009-08-25 14:01:01 -07001201 kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
Robert Love42e9a922008-12-09 15:10:17 -08001202}
1203
1204/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001205 * fc_rport_enter_rtv() - Send Request Timeout Value (RTV) request
1206 * @rdata: The remote port to send the RTV request to
Robert Love42e9a922008-12-09 15:10:17 -08001207 *
1208 * Locking Note: The rport lock is expected to be held before calling
1209 * this routine.
1210 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001211static void fc_rport_enter_rtv(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -08001212{
1213 struct fc_frame *fp;
Robert Love42e9a922008-12-09 15:10:17 -08001214 struct fc_lport *lport = rdata->local_port;
1215
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001216 FC_RPORT_DBG(rdata, "Port entered RTV state from %s state\n",
1217 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -08001218
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001219 fc_rport_state_enter(rdata, RPORT_ST_RTV);
Robert Love42e9a922008-12-09 15:10:17 -08001220
1221 fp = fc_frame_alloc(lport, sizeof(struct fc_els_rtv));
1222 if (!fp) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001223 fc_rport_error_retry(rdata, fp);
Robert Love42e9a922008-12-09 15:10:17 -08001224 return;
1225 }
1226
Joe Eykholtf211fa52009-08-25 14:01:01 -07001227 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_RTV,
Joe Eykholtb94f8952009-11-03 11:50:21 -08001228 fc_rport_rtv_resp, rdata,
1229 2 * lport->r_a_tov))
Chris Leech8f550f92009-10-21 16:28:09 -07001230 fc_rport_error_retry(rdata, NULL);
Robert Love42e9a922008-12-09 15:10:17 -08001231 else
Joe Eykholtf211fa52009-08-25 14:01:01 -07001232 kref_get(&rdata->kref);
Robert Love42e9a922008-12-09 15:10:17 -08001233}
1234
1235/**
Joe Eykholt079ecd82010-07-20 15:20:51 -07001236 * fc_rport_logo_resp() - Handler for logout (LOGO) responses
1237 * @sp: The sequence the LOGO was on
1238 * @fp: The LOGO response frame
1239 * @lport_arg: The local port
1240 */
1241static void fc_rport_logo_resp(struct fc_seq *sp, struct fc_frame *fp,
1242 void *lport_arg)
1243{
1244 struct fc_lport *lport = lport_arg;
1245
1246 FC_RPORT_ID_DBG(lport, fc_seq_exch(sp)->did,
1247 "Received a LOGO %s\n", fc_els_resp_type(fp));
1248 if (IS_ERR(fp))
1249 return;
1250 fc_frame_free(fp);
1251}
1252
1253/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001254 * fc_rport_enter_logo() - Send a logout (LOGO) request
1255 * @rdata: The remote port to send the LOGO request to
Robert Love42e9a922008-12-09 15:10:17 -08001256 *
1257 * Locking Note: The rport lock is expected to be held before calling
1258 * this routine.
1259 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001260static void fc_rport_enter_logo(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -08001261{
Robert Love42e9a922008-12-09 15:10:17 -08001262 struct fc_lport *lport = rdata->local_port;
1263 struct fc_frame *fp;
1264
Joe Eykholt079ecd82010-07-20 15:20:51 -07001265 FC_RPORT_DBG(rdata, "Port sending LOGO from %s state\n",
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001266 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -08001267
Robert Love42e9a922008-12-09 15:10:17 -08001268 fp = fc_frame_alloc(lport, sizeof(struct fc_els_logo));
Joe Eykholt079ecd82010-07-20 15:20:51 -07001269 if (!fp)
Robert Love42e9a922008-12-09 15:10:17 -08001270 return;
Joe Eykholt079ecd82010-07-20 15:20:51 -07001271 (void)lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_LOGO,
1272 fc_rport_logo_resp, lport, 0);
Robert Love42e9a922008-12-09 15:10:17 -08001273}
1274
Robert Love42e9a922008-12-09 15:10:17 -08001275/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001276 * fc_rport_els_adisc_resp() - Handler for Address Discovery (ADISC) responses
1277 * @sp: The sequence the ADISC response was on
1278 * @fp: The ADISC response frame
1279 * @rdata_arg: The remote port that sent the ADISC response
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001280 *
1281 * Locking Note: This function will be called without the rport lock
1282 * held, but it will lock, call an _enter_* function or fc_rport_error
1283 * and then unlock the rport.
1284 */
1285static void fc_rport_adisc_resp(struct fc_seq *sp, struct fc_frame *fp,
Robert Love3a3b42b2009-11-03 11:47:39 -08001286 void *rdata_arg)
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001287{
1288 struct fc_rport_priv *rdata = rdata_arg;
1289 struct fc_els_adisc *adisc;
1290 u8 op;
1291
1292 mutex_lock(&rdata->rp_mutex);
1293
1294 FC_RPORT_DBG(rdata, "Received a ADISC response\n");
1295
1296 if (rdata->rp_state != RPORT_ST_ADISC) {
1297 FC_RPORT_DBG(rdata, "Received a ADISC resp but in state %s\n",
1298 fc_rport_state(rdata));
1299 if (IS_ERR(fp))
1300 goto err;
1301 goto out;
1302 }
1303
1304 if (IS_ERR(fp)) {
1305 fc_rport_error(rdata, fp);
1306 goto err;
1307 }
1308
1309 /*
1310 * If address verification failed. Consider us logged out of the rport.
1311 * Since the rport is still in discovery, we want to be
1312 * logged in, so go to PLOGI state. Otherwise, go back to READY.
1313 */
1314 op = fc_frame_payload_op(fp);
1315 adisc = fc_frame_payload_get(fp, sizeof(*adisc));
1316 if (op != ELS_LS_ACC || !adisc ||
1317 ntoh24(adisc->adisc_port_id) != rdata->ids.port_id ||
1318 get_unaligned_be64(&adisc->adisc_wwpn) != rdata->ids.port_name ||
1319 get_unaligned_be64(&adisc->adisc_wwnn) != rdata->ids.node_name) {
1320 FC_RPORT_DBG(rdata, "ADISC error or mismatch\n");
Joe Eykholta7b12a22010-07-20 15:20:08 -07001321 fc_rport_enter_flogi(rdata);
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001322 } else {
1323 FC_RPORT_DBG(rdata, "ADISC OK\n");
1324 fc_rport_enter_ready(rdata);
1325 }
1326out:
1327 fc_frame_free(fp);
1328err:
1329 mutex_unlock(&rdata->rp_mutex);
1330 kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
1331}
1332
1333/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001334 * fc_rport_enter_adisc() - Send Address Discover (ADISC) request
1335 * @rdata: The remote port to send the ADISC request to
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001336 *
1337 * Locking Note: The rport lock is expected to be held before calling
1338 * this routine.
1339 */
1340static void fc_rport_enter_adisc(struct fc_rport_priv *rdata)
1341{
1342 struct fc_lport *lport = rdata->local_port;
1343 struct fc_frame *fp;
1344
1345 FC_RPORT_DBG(rdata, "sending ADISC from %s state\n",
1346 fc_rport_state(rdata));
1347
1348 fc_rport_state_enter(rdata, RPORT_ST_ADISC);
1349
1350 fp = fc_frame_alloc(lport, sizeof(struct fc_els_adisc));
1351 if (!fp) {
1352 fc_rport_error_retry(rdata, fp);
1353 return;
1354 }
1355 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_ADISC,
Joe Eykholtb94f8952009-11-03 11:50:21 -08001356 fc_rport_adisc_resp, rdata,
1357 2 * lport->r_a_tov))
Chris Leech8f550f92009-10-21 16:28:09 -07001358 fc_rport_error_retry(rdata, NULL);
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001359 else
1360 kref_get(&rdata->kref);
1361}
1362
1363/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001364 * fc_rport_recv_adisc_req() - Handler for Address Discovery (ADISC) requests
1365 * @rdata: The remote port that sent the ADISC request
Robert Love3a3b42b2009-11-03 11:47:39 -08001366 * @in_fp: The ADISC request frame
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001367 *
1368 * Locking Note: Called with the lport and rport locks held.
1369 */
1370static void fc_rport_recv_adisc_req(struct fc_rport_priv *rdata,
Joe Eykholt922611562010-07-20 15:21:12 -07001371 struct fc_frame *in_fp)
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001372{
1373 struct fc_lport *lport = rdata->local_port;
1374 struct fc_frame *fp;
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001375 struct fc_els_adisc *adisc;
1376 struct fc_seq_els_data rjt_data;
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001377
1378 FC_RPORT_DBG(rdata, "Received ADISC request\n");
1379
1380 adisc = fc_frame_payload_get(in_fp, sizeof(*adisc));
1381 if (!adisc) {
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001382 rjt_data.reason = ELS_RJT_PROT;
1383 rjt_data.explan = ELS_EXPL_INV_LEN;
Joe Eykholt922611562010-07-20 15:21:12 -07001384 lport->tt.seq_els_rsp_send(in_fp, ELS_LS_RJT, &rjt_data);
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001385 goto drop;
1386 }
1387
1388 fp = fc_frame_alloc(lport, sizeof(*adisc));
1389 if (!fp)
1390 goto drop;
1391 fc_adisc_fill(lport, fp);
1392 adisc = fc_frame_payload_get(fp, sizeof(*adisc));
1393 adisc->adisc_cmd = ELS_LS_ACC;
Joe Eykholt24f089e2010-07-20 15:21:01 -07001394 fc_fill_reply_hdr(fp, in_fp, FC_RCTL_ELS_REP, 0);
1395 lport->tt.frame_send(lport, fp);
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001396drop:
1397 fc_frame_free(in_fp);
1398}
1399
1400/**
Yi Zou63e27fb2009-11-20 14:55:24 -08001401 * fc_rport_recv_rls_req() - Handle received Read Link Status request
1402 * @rdata: The remote port that sent the RLS request
Yi Zou63e27fb2009-11-20 14:55:24 -08001403 * @rx_fp: The PRLI request frame
1404 *
1405 * Locking Note: The rport lock is expected to be held before calling
1406 * this function.
1407 */
1408static void fc_rport_recv_rls_req(struct fc_rport_priv *rdata,
Joe Eykholt922611562010-07-20 15:21:12 -07001409 struct fc_frame *rx_fp)
Yi Zou63e27fb2009-11-20 14:55:24 -08001410
1411{
1412 struct fc_lport *lport = rdata->local_port;
1413 struct fc_frame *fp;
Yi Zou63e27fb2009-11-20 14:55:24 -08001414 struct fc_els_rls *rls;
1415 struct fc_els_rls_resp *rsp;
1416 struct fc_els_lesb *lesb;
1417 struct fc_seq_els_data rjt_data;
1418 struct fc_host_statistics *hst;
Yi Zou63e27fb2009-11-20 14:55:24 -08001419
1420 FC_RPORT_DBG(rdata, "Received RLS request while in state %s\n",
1421 fc_rport_state(rdata));
1422
1423 rls = fc_frame_payload_get(rx_fp, sizeof(*rls));
1424 if (!rls) {
1425 rjt_data.reason = ELS_RJT_PROT;
1426 rjt_data.explan = ELS_EXPL_INV_LEN;
1427 goto out_rjt;
1428 }
1429
1430 fp = fc_frame_alloc(lport, sizeof(*rsp));
1431 if (!fp) {
1432 rjt_data.reason = ELS_RJT_UNAB;
1433 rjt_data.explan = ELS_EXPL_INSUF_RES;
1434 goto out_rjt;
1435 }
1436
1437 rsp = fc_frame_payload_get(fp, sizeof(*rsp));
1438 memset(rsp, 0, sizeof(*rsp));
1439 rsp->rls_cmd = ELS_LS_ACC;
1440 lesb = &rsp->rls_lesb;
1441 if (lport->tt.get_lesb) {
1442 /* get LESB from LLD if it supports it */
1443 lport->tt.get_lesb(lport, lesb);
1444 } else {
1445 fc_get_host_stats(lport->host);
1446 hst = &lport->host_stats;
1447 lesb->lesb_link_fail = htonl(hst->link_failure_count);
1448 lesb->lesb_sync_loss = htonl(hst->loss_of_sync_count);
1449 lesb->lesb_sig_loss = htonl(hst->loss_of_signal_count);
1450 lesb->lesb_prim_err = htonl(hst->prim_seq_protocol_err_count);
1451 lesb->lesb_inv_word = htonl(hst->invalid_tx_word_count);
1452 lesb->lesb_inv_crc = htonl(hst->invalid_crc_count);
1453 }
1454
Joe Eykholt24f089e2010-07-20 15:21:01 -07001455 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
1456 lport->tt.frame_send(lport, fp);
Yi Zou63e27fb2009-11-20 14:55:24 -08001457 goto out;
1458
1459out_rjt:
Joe Eykholt922611562010-07-20 15:21:12 -07001460 lport->tt.seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
Yi Zou63e27fb2009-11-20 14:55:24 -08001461out:
1462 fc_frame_free(rx_fp);
1463}
1464
1465/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001466 * fc_rport_recv_els_req() - Handler for validated ELS requests
1467 * @lport: The local port that received the ELS request
Robert Love3a3b42b2009-11-03 11:47:39 -08001468 * @fp: The ELS request frame
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001469 *
1470 * Handle incoming ELS requests that require port login.
1471 * The ELS opcode has already been validated by the caller.
Robert Love42e9a922008-12-09 15:10:17 -08001472 *
Joe Eykholt131203a2009-08-25 14:03:10 -07001473 * Locking Note: Called with the lport lock held.
Robert Love42e9a922008-12-09 15:10:17 -08001474 */
Joe Eykholt922611562010-07-20 15:21:12 -07001475static void fc_rport_recv_els_req(struct fc_lport *lport, struct fc_frame *fp)
Robert Love42e9a922008-12-09 15:10:17 -08001476{
Joe Eykholt131203a2009-08-25 14:03:10 -07001477 struct fc_rport_priv *rdata;
Robert Love42e9a922008-12-09 15:10:17 -08001478 struct fc_seq_els_data els_data;
Robert Love42e9a922008-12-09 15:10:17 -08001479
Joe Eykholt25b37b92009-08-25 14:03:15 -07001480 mutex_lock(&lport->disc.disc_mutex);
Joe Eykholt251748a2010-07-20 15:20:56 -07001481 rdata = lport->tt.rport_lookup(lport, fc_frame_sid(fp));
Joe Eykholt131203a2009-08-25 14:03:10 -07001482 if (!rdata) {
Joe Eykholt25b37b92009-08-25 14:03:15 -07001483 mutex_unlock(&lport->disc.disc_mutex);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001484 goto reject;
Joe Eykholt131203a2009-08-25 14:03:10 -07001485 }
1486 mutex_lock(&rdata->rp_mutex);
Joe Eykholt25b37b92009-08-25 14:03:15 -07001487 mutex_unlock(&lport->disc.disc_mutex);
Joe Eykholt131203a2009-08-25 14:03:10 -07001488
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001489 switch (rdata->rp_state) {
1490 case RPORT_ST_PRLI:
1491 case RPORT_ST_RTV:
1492 case RPORT_ST_READY:
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001493 case RPORT_ST_ADISC:
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001494 break;
1495 default:
1496 mutex_unlock(&rdata->rp_mutex);
1497 goto reject;
1498 }
1499
1500 switch (fc_frame_payload_op(fp)) {
Joe Eykholt131203a2009-08-25 14:03:10 -07001501 case ELS_PRLI:
Joe Eykholt922611562010-07-20 15:21:12 -07001502 fc_rport_recv_prli_req(rdata, fp);
Joe Eykholt131203a2009-08-25 14:03:10 -07001503 break;
1504 case ELS_PRLO:
Joe Eykholt922611562010-07-20 15:21:12 -07001505 fc_rport_recv_prlo_req(rdata, fp);
Joe Eykholt131203a2009-08-25 14:03:10 -07001506 break;
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001507 case ELS_ADISC:
Joe Eykholt922611562010-07-20 15:21:12 -07001508 fc_rport_recv_adisc_req(rdata, fp);
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001509 break;
Joe Eykholt131203a2009-08-25 14:03:10 -07001510 case ELS_RRQ:
Joe Eykholt922611562010-07-20 15:21:12 -07001511 lport->tt.seq_els_rsp_send(fp, ELS_RRQ, NULL);
1512 fc_frame_free(fp);
Joe Eykholt131203a2009-08-25 14:03:10 -07001513 break;
1514 case ELS_REC:
Joe Eykholt922611562010-07-20 15:21:12 -07001515 lport->tt.seq_els_rsp_send(fp, ELS_REC, NULL);
1516 fc_frame_free(fp);
Joe Eykholt131203a2009-08-25 14:03:10 -07001517 break;
Yi Zou63e27fb2009-11-20 14:55:24 -08001518 case ELS_RLS:
Joe Eykholt922611562010-07-20 15:21:12 -07001519 fc_rport_recv_rls_req(rdata, fp);
Yi Zou63e27fb2009-11-20 14:55:24 -08001520 break;
Joe Eykholt131203a2009-08-25 14:03:10 -07001521 default:
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001522 fc_frame_free(fp); /* can't happen */
Joe Eykholt131203a2009-08-25 14:03:10 -07001523 break;
Robert Love42e9a922008-12-09 15:10:17 -08001524 }
1525
1526 mutex_unlock(&rdata->rp_mutex);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001527 return;
1528
1529reject:
Joe Eykholt922611562010-07-20 15:21:12 -07001530 els_data.reason = ELS_RJT_UNAB;
1531 els_data.explan = ELS_EXPL_PLOGI_REQD;
1532 lport->tt.seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001533 fc_frame_free(fp);
1534}
1535
1536/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001537 * fc_rport_recv_req() - Handler for requests
Robert Love3a3b42b2009-11-03 11:47:39 -08001538 * @lport: The local port that received the request
Joe Eykholt922611562010-07-20 15:21:12 -07001539 * @fp: The request frame
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001540 *
1541 * Locking Note: Called with the lport lock held.
1542 */
Bart Van Asschec6b21c92012-01-13 17:26:20 -08001543static void fc_rport_recv_req(struct fc_lport *lport, struct fc_frame *fp)
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001544{
1545 struct fc_seq_els_data els_data;
1546
1547 /*
Joe Eykholta7b12a22010-07-20 15:20:08 -07001548 * Handle FLOGI, PLOGI and LOGO requests separately, since they
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001549 * don't require prior login.
1550 * Check for unsupported opcodes first and reject them.
1551 * For some ops, it would be incorrect to reject with "PLOGI required".
1552 */
1553 switch (fc_frame_payload_op(fp)) {
Joe Eykholta7b12a22010-07-20 15:20:08 -07001554 case ELS_FLOGI:
Joe Eykholt922611562010-07-20 15:21:12 -07001555 fc_rport_recv_flogi_req(lport, fp);
Joe Eykholta7b12a22010-07-20 15:20:08 -07001556 break;
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001557 case ELS_PLOGI:
Joe Eykholt922611562010-07-20 15:21:12 -07001558 fc_rport_recv_plogi_req(lport, fp);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001559 break;
1560 case ELS_LOGO:
Joe Eykholt922611562010-07-20 15:21:12 -07001561 fc_rport_recv_logo_req(lport, fp);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001562 break;
1563 case ELS_PRLI:
1564 case ELS_PRLO:
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001565 case ELS_ADISC:
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001566 case ELS_RRQ:
1567 case ELS_REC:
Yi Zou63e27fb2009-11-20 14:55:24 -08001568 case ELS_RLS:
Joe Eykholt922611562010-07-20 15:21:12 -07001569 fc_rport_recv_els_req(lport, fp);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001570 break;
1571 default:
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001572 els_data.reason = ELS_RJT_UNSUP;
1573 els_data.explan = ELS_EXPL_NONE;
Joe Eykholt922611562010-07-20 15:21:12 -07001574 lport->tt.seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
1575 fc_frame_free(fp);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001576 break;
1577 }
Robert Love42e9a922008-12-09 15:10:17 -08001578}
1579
1580/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001581 * fc_rport_recv_plogi_req() - Handler for Port Login (PLOGI) requests
1582 * @lport: The local port that received the PLOGI request
Robert Love3a3b42b2009-11-03 11:47:39 -08001583 * @rx_fp: The PLOGI request frame
Robert Love42e9a922008-12-09 15:10:17 -08001584 *
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001585 * Locking Note: The rport lock is held before calling this function.
Robert Love42e9a922008-12-09 15:10:17 -08001586 */
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001587static void fc_rport_recv_plogi_req(struct fc_lport *lport,
Joe Eykholt922611562010-07-20 15:21:12 -07001588 struct fc_frame *rx_fp)
Robert Love42e9a922008-12-09 15:10:17 -08001589{
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001590 struct fc_disc *disc;
1591 struct fc_rport_priv *rdata;
Robert Love42e9a922008-12-09 15:10:17 -08001592 struct fc_frame *fp = rx_fp;
Robert Love42e9a922008-12-09 15:10:17 -08001593 struct fc_els_flogi *pl;
1594 struct fc_seq_els_data rjt_data;
Joe Eykholt24f089e2010-07-20 15:21:01 -07001595 u32 sid;
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001596
Joe Eykholt251748a2010-07-20 15:20:56 -07001597 sid = fc_frame_sid(fp);
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001598
1599 FC_RPORT_ID_DBG(lport, sid, "Received PLOGI request\n");
1600
Robert Love42e9a922008-12-09 15:10:17 -08001601 pl = fc_frame_payload_get(fp, sizeof(*pl));
1602 if (!pl) {
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001603 FC_RPORT_ID_DBG(lport, sid, "Received PLOGI too short\n");
1604 rjt_data.reason = ELS_RJT_PROT;
1605 rjt_data.explan = ELS_EXPL_INV_LEN;
1606 goto reject;
Robert Love42e9a922008-12-09 15:10:17 -08001607 }
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001608
1609 disc = &lport->disc;
1610 mutex_lock(&disc->disc_mutex);
1611 rdata = lport->tt.rport_create(lport, sid);
1612 if (!rdata) {
1613 mutex_unlock(&disc->disc_mutex);
1614 rjt_data.reason = ELS_RJT_UNAB;
1615 rjt_data.explan = ELS_EXPL_INSUF_RES;
1616 goto reject;
1617 }
1618
1619 mutex_lock(&rdata->rp_mutex);
1620 mutex_unlock(&disc->disc_mutex);
1621
1622 rdata->ids.port_name = get_unaligned_be64(&pl->fl_wwpn);
1623 rdata->ids.node_name = get_unaligned_be64(&pl->fl_wwnn);
Robert Love42e9a922008-12-09 15:10:17 -08001624
1625 /*
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001626 * If the rport was just created, possibly due to the incoming PLOGI,
Robert Love42e9a922008-12-09 15:10:17 -08001627 * set the state appropriately and accept the PLOGI.
1628 *
1629 * If we had also sent a PLOGI, and if the received PLOGI is from a
1630 * higher WWPN, we accept it, otherwise an LS_RJT is sent with reason
1631 * "command already in progress".
1632 *
1633 * XXX TBD: If the session was ready before, the PLOGI should result in
1634 * all outstanding exchanges being reset.
1635 */
1636 switch (rdata->rp_state) {
1637 case RPORT_ST_INIT:
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001638 FC_RPORT_DBG(rdata, "Received PLOGI in INIT state\n");
Robert Love42e9a922008-12-09 15:10:17 -08001639 break;
Joe Eykholta7b12a22010-07-20 15:20:08 -07001640 case RPORT_ST_PLOGI_WAIT:
1641 FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI_WAIT state\n");
1642 break;
Robert Love42e9a922008-12-09 15:10:17 -08001643 case RPORT_ST_PLOGI:
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001644 FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI state\n");
1645 if (rdata->ids.port_name < lport->wwpn) {
1646 mutex_unlock(&rdata->rp_mutex);
1647 rjt_data.reason = ELS_RJT_INPROG;
1648 rjt_data.explan = ELS_EXPL_NONE;
1649 goto reject;
1650 }
Robert Love42e9a922008-12-09 15:10:17 -08001651 break;
1652 case RPORT_ST_PRLI:
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -07001653 case RPORT_ST_RTV:
Robert Love42e9a922008-12-09 15:10:17 -08001654 case RPORT_ST_READY:
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001655 case RPORT_ST_ADISC:
1656 FC_RPORT_DBG(rdata, "Received PLOGI in logged-in state %d "
1657 "- ignored for now\n", rdata->rp_state);
1658 /* XXX TBD - should reset */
Robert Love42e9a922008-12-09 15:10:17 -08001659 break;
Joe Eykholta7b12a22010-07-20 15:20:08 -07001660 case RPORT_ST_FLOGI:
Joe Eykholt14194052009-07-29 17:04:43 -07001661 case RPORT_ST_DELETE:
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -07001662 FC_RPORT_DBG(rdata, "Received PLOGI in state %s - send busy\n",
1663 fc_rport_state(rdata));
1664 mutex_unlock(&rdata->rp_mutex);
1665 rjt_data.reason = ELS_RJT_BUSY;
1666 rjt_data.explan = ELS_EXPL_NONE;
1667 goto reject;
Robert Love42e9a922008-12-09 15:10:17 -08001668 }
Mark Rustade0335f62013-05-18 04:01:36 +00001669 if (!fc_rport_compatible_roles(lport, rdata)) {
1670 FC_RPORT_DBG(rdata, "Received PLOGI for incompatible role\n");
1671 mutex_unlock(&rdata->rp_mutex);
1672 rjt_data.reason = ELS_RJT_LOGIC;
1673 rjt_data.explan = ELS_EXPL_NONE;
1674 goto reject;
1675 }
Robert Love42e9a922008-12-09 15:10:17 -08001676
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001677 /*
1678 * Get session payload size from incoming PLOGI.
1679 */
1680 rdata->maxframe_size = fc_plogi_get_maxframe(pl, lport->mfs);
Robert Love42e9a922008-12-09 15:10:17 -08001681
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001682 /*
1683 * Send LS_ACC. If this fails, the originator should retry.
1684 */
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001685 fp = fc_frame_alloc(lport, sizeof(*pl));
1686 if (!fp)
1687 goto out;
Robert Love42e9a922008-12-09 15:10:17 -08001688
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001689 fc_plogi_fill(lport, fp, ELS_LS_ACC);
Joe Eykholt24f089e2010-07-20 15:21:01 -07001690 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
1691 lport->tt.frame_send(lport, fp);
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001692 fc_rport_enter_prli(rdata);
1693out:
1694 mutex_unlock(&rdata->rp_mutex);
Joe Eykholt24f089e2010-07-20 15:21:01 -07001695 fc_frame_free(rx_fp);
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001696 return;
1697
1698reject:
Joe Eykholt922611562010-07-20 15:21:12 -07001699 lport->tt.seq_els_rsp_send(fp, ELS_LS_RJT, &rjt_data);
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001700 fc_frame_free(fp);
Robert Love42e9a922008-12-09 15:10:17 -08001701}
1702
1703/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001704 * fc_rport_recv_prli_req() - Handler for process login (PRLI) requests
1705 * @rdata: The remote port that sent the PRLI request
Robert Love3a3b42b2009-11-03 11:47:39 -08001706 * @rx_fp: The PRLI request frame
Robert Love42e9a922008-12-09 15:10:17 -08001707 *
Bart Van Asschec1d45422013-08-14 15:31:52 +00001708 * Locking Note: The rport lock is expected to be held before calling
Robert Love42e9a922008-12-09 15:10:17 -08001709 * this function.
1710 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001711static void fc_rport_recv_prli_req(struct fc_rport_priv *rdata,
Joe Eykholt922611562010-07-20 15:21:12 -07001712 struct fc_frame *rx_fp)
Robert Love42e9a922008-12-09 15:10:17 -08001713{
Robert Love42e9a922008-12-09 15:10:17 -08001714 struct fc_lport *lport = rdata->local_port;
Robert Love42e9a922008-12-09 15:10:17 -08001715 struct fc_frame *fp;
Robert Love42e9a922008-12-09 15:10:17 -08001716 struct {
1717 struct fc_els_prli prli;
1718 struct fc_els_spp spp;
1719 } *pp;
1720 struct fc_els_spp *rspp; /* request service param page */
1721 struct fc_els_spp *spp; /* response spp */
1722 unsigned int len;
1723 unsigned int plen;
Robert Love42e9a922008-12-09 15:10:17 -08001724 enum fc_els_spp_resp resp;
Joe Eykholt96ad8462011-01-28 16:04:02 -08001725 enum fc_els_spp_resp passive;
Robert Love42e9a922008-12-09 15:10:17 -08001726 struct fc_seq_els_data rjt_data;
Joe Eykholt96ad8462011-01-28 16:04:02 -08001727 struct fc4_prov *prov;
Robert Love42e9a922008-12-09 15:10:17 -08001728
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001729 FC_RPORT_DBG(rdata, "Received PRLI request while in state %s\n",
1730 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -08001731
Joe Eykholt251748a2010-07-20 15:20:56 -07001732 len = fr_len(rx_fp) - sizeof(struct fc_frame_header);
Robert Love42e9a922008-12-09 15:10:17 -08001733 pp = fc_frame_payload_get(rx_fp, sizeof(*pp));
Joe Eykholta2f6a022010-03-12 16:07:36 -08001734 if (!pp)
1735 goto reject_len;
1736 plen = ntohs(pp->prli.prli_len);
1737 if ((plen % 4) != 0 || plen > len || plen < 16)
1738 goto reject_len;
1739 if (plen < len)
1740 len = plen;
1741 plen = pp->prli.prli_spp_len;
1742 if ((plen % 4) != 0 || plen < sizeof(*spp) ||
1743 plen > len || len < sizeof(*pp) || plen < 12)
1744 goto reject_len;
1745 rspp = &pp->spp;
1746
1747 fp = fc_frame_alloc(lport, len);
1748 if (!fp) {
1749 rjt_data.reason = ELS_RJT_UNAB;
1750 rjt_data.explan = ELS_EXPL_INSUF_RES;
1751 goto reject;
Robert Love42e9a922008-12-09 15:10:17 -08001752 }
Joe Eykholta2f6a022010-03-12 16:07:36 -08001753 pp = fc_frame_payload_get(fp, len);
1754 WARN_ON(!pp);
1755 memset(pp, 0, len);
1756 pp->prli.prli_cmd = ELS_LS_ACC;
1757 pp->prli.prli_spp_len = plen;
1758 pp->prli.prli_len = htons(len);
1759 len -= sizeof(struct fc_els_prli);
Robert Love42e9a922008-12-09 15:10:17 -08001760
Joe Eykholta2f6a022010-03-12 16:07:36 -08001761 /*
1762 * Go through all the service parameter pages and build
1763 * response. If plen indicates longer SPP than standard,
1764 * use that. The entire response has been pre-cleared above.
1765 */
1766 spp = &pp->spp;
Joe Eykholt96ad8462011-01-28 16:04:02 -08001767 mutex_lock(&fc_prov_mutex);
Joe Eykholta2f6a022010-03-12 16:07:36 -08001768 while (len >= plen) {
Bhanu Prakash Gollapudi75a27922011-01-28 16:05:27 -08001769 rdata->spp_type = rspp->spp_type;
Joe Eykholta2f6a022010-03-12 16:07:36 -08001770 spp->spp_type = rspp->spp_type;
1771 spp->spp_type_ext = rspp->spp_type_ext;
Joe Eykholt96ad8462011-01-28 16:04:02 -08001772 resp = 0;
Robert Love42e9a922008-12-09 15:10:17 -08001773
Joe Eykholt96ad8462011-01-28 16:04:02 -08001774 if (rspp->spp_type < FC_FC4_PROV_SIZE) {
1775 prov = fc_active_prov[rspp->spp_type];
1776 if (prov)
1777 resp = prov->prli(rdata, plen, rspp, spp);
1778 prov = fc_passive_prov[rspp->spp_type];
1779 if (prov) {
1780 passive = prov->prli(rdata, plen, rspp, spp);
1781 if (!resp || passive == FC_SPP_RESP_ACK)
1782 resp = passive;
1783 }
1784 }
1785 if (!resp) {
1786 if (spp->spp_flags & FC_SPP_EST_IMG_PAIR)
1787 resp |= FC_SPP_RESP_CONF;
1788 else
1789 resp |= FC_SPP_RESP_INVL;
Robert Love42e9a922008-12-09 15:10:17 -08001790 }
Joe Eykholta2f6a022010-03-12 16:07:36 -08001791 spp->spp_flags |= resp;
1792 len -= plen;
1793 rspp = (struct fc_els_spp *)((char *)rspp + plen);
1794 spp = (struct fc_els_spp *)((char *)spp + plen);
Robert Love42e9a922008-12-09 15:10:17 -08001795 }
Joe Eykholt96ad8462011-01-28 16:04:02 -08001796 mutex_unlock(&fc_prov_mutex);
Joe Eykholta2f6a022010-03-12 16:07:36 -08001797
1798 /*
1799 * Send LS_ACC. If this fails, the originator should retry.
1800 */
Joe Eykholt24f089e2010-07-20 15:21:01 -07001801 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
1802 lport->tt.frame_send(lport, fp);
Joe Eykholta2f6a022010-03-12 16:07:36 -08001803
1804 switch (rdata->rp_state) {
1805 case RPORT_ST_PRLI:
1806 fc_rport_enter_ready(rdata);
1807 break;
1808 default:
1809 break;
1810 }
1811 goto drop;
1812
1813reject_len:
1814 rjt_data.reason = ELS_RJT_PROT;
1815 rjt_data.explan = ELS_EXPL_INV_LEN;
1816reject:
Joe Eykholt922611562010-07-20 15:21:12 -07001817 lport->tt.seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
Joe Eykholta2f6a022010-03-12 16:07:36 -08001818drop:
Robert Love42e9a922008-12-09 15:10:17 -08001819 fc_frame_free(rx_fp);
1820}
1821
1822/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001823 * fc_rport_recv_prlo_req() - Handler for process logout (PRLO) requests
1824 * @rdata: The remote port that sent the PRLO request
Bhanu Prakash Gollapudif8fc6c22010-06-11 16:44:04 -07001825 * @rx_fp: The PRLO request frame
Robert Love42e9a922008-12-09 15:10:17 -08001826 *
Bart Van Asschec1d45422013-08-14 15:31:52 +00001827 * Locking Note: The rport lock is expected to be held before calling
Robert Love42e9a922008-12-09 15:10:17 -08001828 * this function.
1829 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001830static void fc_rport_recv_prlo_req(struct fc_rport_priv *rdata,
Bhanu Prakash Gollapudif8fc6c22010-06-11 16:44:04 -07001831 struct fc_frame *rx_fp)
Robert Love42e9a922008-12-09 15:10:17 -08001832{
Robert Love42e9a922008-12-09 15:10:17 -08001833 struct fc_lport *lport = rdata->local_port;
Bhanu Prakash Gollapudif8fc6c22010-06-11 16:44:04 -07001834 struct fc_frame *fp;
1835 struct {
1836 struct fc_els_prlo prlo;
1837 struct fc_els_spp spp;
1838 } *pp;
1839 struct fc_els_spp *rspp; /* request service param page */
1840 struct fc_els_spp *spp; /* response spp */
1841 unsigned int len;
1842 unsigned int plen;
Robert Love42e9a922008-12-09 15:10:17 -08001843 struct fc_seq_els_data rjt_data;
1844
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001845 FC_RPORT_DBG(rdata, "Received PRLO request while in state %s\n",
1846 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -08001847
Joe Eykholt251748a2010-07-20 15:20:56 -07001848 len = fr_len(rx_fp) - sizeof(struct fc_frame_header);
Bhanu Prakash Gollapudif8fc6c22010-06-11 16:44:04 -07001849 pp = fc_frame_payload_get(rx_fp, sizeof(*pp));
1850 if (!pp)
1851 goto reject_len;
1852 plen = ntohs(pp->prlo.prlo_len);
1853 if (plen != 20)
1854 goto reject_len;
1855 if (plen < len)
1856 len = plen;
1857
1858 rspp = &pp->spp;
1859
1860 fp = fc_frame_alloc(lport, len);
1861 if (!fp) {
1862 rjt_data.reason = ELS_RJT_UNAB;
1863 rjt_data.explan = ELS_EXPL_INSUF_RES;
1864 goto reject;
1865 }
1866
Bhanu Prakash Gollapudif8fc6c22010-06-11 16:44:04 -07001867 pp = fc_frame_payload_get(fp, len);
1868 WARN_ON(!pp);
1869 memset(pp, 0, len);
1870 pp->prlo.prlo_cmd = ELS_LS_ACC;
1871 pp->prlo.prlo_obs = 0x10;
1872 pp->prlo.prlo_len = htons(len);
1873 spp = &pp->spp;
1874 spp->spp_type = rspp->spp_type;
1875 spp->spp_type_ext = rspp->spp_type_ext;
1876 spp->spp_flags = FC_SPP_RESP_ACK;
1877
1878 fc_rport_enter_delete(rdata, RPORT_EV_LOGO);
1879
Joe Eykholt922611562010-07-20 15:21:12 -07001880 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
1881 lport->tt.frame_send(lport, fp);
Bhanu Prakash Gollapudif8fc6c22010-06-11 16:44:04 -07001882 goto drop;
1883
1884reject_len:
1885 rjt_data.reason = ELS_RJT_PROT;
1886 rjt_data.explan = ELS_EXPL_INV_LEN;
1887reject:
Joe Eykholt922611562010-07-20 15:21:12 -07001888 lport->tt.seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
Bhanu Prakash Gollapudif8fc6c22010-06-11 16:44:04 -07001889drop:
1890 fc_frame_free(rx_fp);
Robert Love42e9a922008-12-09 15:10:17 -08001891}
1892
1893/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001894 * fc_rport_recv_logo_req() - Handler for logout (LOGO) requests
1895 * @lport: The local port that received the LOGO request
Robert Love3a3b42b2009-11-03 11:47:39 -08001896 * @fp: The LOGO request frame
Robert Love42e9a922008-12-09 15:10:17 -08001897 *
Bart Van Asschec1d45422013-08-14 15:31:52 +00001898 * Locking Note: The rport lock is expected to be held before calling
Robert Love42e9a922008-12-09 15:10:17 -08001899 * this function.
1900 */
Joe Eykholt922611562010-07-20 15:21:12 -07001901static void fc_rport_recv_logo_req(struct fc_lport *lport, struct fc_frame *fp)
Robert Love42e9a922008-12-09 15:10:17 -08001902{
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001903 struct fc_rport_priv *rdata;
1904 u32 sid;
Robert Love42e9a922008-12-09 15:10:17 -08001905
Joe Eykholt922611562010-07-20 15:21:12 -07001906 lport->tt.seq_els_rsp_send(fp, ELS_LS_ACC, NULL);
Joe Eykholtfeab4ae2009-08-25 14:03:36 -07001907
Joe Eykholt251748a2010-07-20 15:20:56 -07001908 sid = fc_frame_sid(fp);
Robert Love42e9a922008-12-09 15:10:17 -08001909
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001910 mutex_lock(&lport->disc.disc_mutex);
1911 rdata = lport->tt.rport_lookup(lport, sid);
1912 if (rdata) {
1913 mutex_lock(&rdata->rp_mutex);
1914 FC_RPORT_DBG(rdata, "Received LOGO request while in state %s\n",
1915 fc_rport_state(rdata));
Joe Eykholtfeab4ae2009-08-25 14:03:36 -07001916
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -07001917 fc_rport_enter_delete(rdata, RPORT_EV_LOGO);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001918 mutex_unlock(&rdata->rp_mutex);
1919 } else
1920 FC_RPORT_ID_DBG(lport, sid,
1921 "Received LOGO from non-logged-in port\n");
1922 mutex_unlock(&lport->disc.disc_mutex);
Robert Love42e9a922008-12-09 15:10:17 -08001923 fc_frame_free(fp);
1924}
1925
Robert Love3a3b42b2009-11-03 11:47:39 -08001926/**
1927 * fc_rport_flush_queue() - Flush the rport_event_queue
1928 */
Robert Love42e9a922008-12-09 15:10:17 -08001929static void fc_rport_flush_queue(void)
1930{
1931 flush_workqueue(rport_event_queue);
1932}
1933
Robert Love3a3b42b2009-11-03 11:47:39 -08001934/**
1935 * fc_rport_init() - Initialize the remote port layer for a local port
1936 * @lport: The local port to initialize the remote port layer for
1937 */
Robert Love42e9a922008-12-09 15:10:17 -08001938int fc_rport_init(struct fc_lport *lport)
1939{
Joe Eykholt8025b5d2009-08-25 14:02:06 -07001940 if (!lport->tt.rport_lookup)
1941 lport->tt.rport_lookup = fc_rport_lookup;
1942
Robert Love5101ff92009-02-27 10:55:18 -08001943 if (!lport->tt.rport_create)
Joe Eykholt9e9d0452009-08-25 14:01:18 -07001944 lport->tt.rport_create = fc_rport_create;
Robert Love5101ff92009-02-27 10:55:18 -08001945
Robert Love42e9a922008-12-09 15:10:17 -08001946 if (!lport->tt.rport_login)
1947 lport->tt.rport_login = fc_rport_login;
1948
1949 if (!lport->tt.rport_logoff)
1950 lport->tt.rport_logoff = fc_rport_logoff;
1951
1952 if (!lport->tt.rport_recv_req)
1953 lport->tt.rport_recv_req = fc_rport_recv_req;
1954
1955 if (!lport->tt.rport_flush_queue)
1956 lport->tt.rport_flush_queue = fc_rport_flush_queue;
1957
Joe Eykholtf211fa52009-08-25 14:01:01 -07001958 if (!lport->tt.rport_destroy)
1959 lport->tt.rport_destroy = fc_rport_destroy;
1960
Robert Love42e9a922008-12-09 15:10:17 -08001961 return 0;
1962}
1963EXPORT_SYMBOL(fc_rport_init);
1964
Robert Love3a3b42b2009-11-03 11:47:39 -08001965/**
Joe Eykholt96ad8462011-01-28 16:04:02 -08001966 * fc_rport_fcp_prli() - Handle incoming PRLI for the FCP initiator.
1967 * @rdata: remote port private
1968 * @spp_len: service parameter page length
1969 * @rspp: received service parameter page
1970 * @spp: response service parameter page
1971 *
1972 * Returns the value for the response code to be placed in spp_flags;
1973 * Returns 0 if not an initiator.
1974 */
1975static int fc_rport_fcp_prli(struct fc_rport_priv *rdata, u32 spp_len,
1976 const struct fc_els_spp *rspp,
1977 struct fc_els_spp *spp)
1978{
1979 struct fc_lport *lport = rdata->local_port;
1980 u32 fcp_parm;
1981
1982 fcp_parm = ntohl(rspp->spp_params);
1983 rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
1984 if (fcp_parm & FCP_SPPF_INIT_FCN)
1985 rdata->ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1986 if (fcp_parm & FCP_SPPF_TARG_FCN)
1987 rdata->ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1988 if (fcp_parm & FCP_SPPF_RETRY)
1989 rdata->flags |= FC_RP_FLAGS_RETRY;
1990 rdata->supported_classes = FC_COS_CLASS3;
1991
Mark Rustad732bdb92013-03-20 07:17:55 +00001992 if (!(lport->service_params & FCP_SPPF_INIT_FCN))
Joe Eykholt96ad8462011-01-28 16:04:02 -08001993 return 0;
1994
1995 spp->spp_flags |= rspp->spp_flags & FC_SPP_EST_IMG_PAIR;
1996
1997 /*
1998 * OR in our service parameters with other providers (target), if any.
1999 */
2000 fcp_parm = ntohl(spp->spp_params);
2001 spp->spp_params = htonl(fcp_parm | lport->service_params);
2002 return FC_SPP_RESP_ACK;
2003}
2004
2005/*
2006 * FC-4 provider ops for FCP initiator.
2007 */
2008struct fc4_prov fc_rport_fcp_init = {
2009 .prli = fc_rport_fcp_prli,
2010};
2011
2012/**
2013 * fc_rport_t0_prli() - Handle incoming PRLI parameters for type 0
2014 * @rdata: remote port private
2015 * @spp_len: service parameter page length
2016 * @rspp: received service parameter page
2017 * @spp: response service parameter page
2018 */
2019static int fc_rport_t0_prli(struct fc_rport_priv *rdata, u32 spp_len,
2020 const struct fc_els_spp *rspp,
2021 struct fc_els_spp *spp)
2022{
2023 if (rspp->spp_flags & FC_SPP_EST_IMG_PAIR)
2024 return FC_SPP_RESP_INVL;
2025 return FC_SPP_RESP_ACK;
2026}
2027
2028/*
2029 * FC-4 provider ops for type 0 service parameters.
2030 *
2031 * This handles the special case of type 0 which is always successful
2032 * but doesn't do anything otherwise.
2033 */
2034struct fc4_prov fc_rport_t0_prov = {
2035 .prli = fc_rport_t0_prli,
2036};
2037
2038/**
Robert Love3a3b42b2009-11-03 11:47:39 -08002039 * fc_setup_rport() - Initialize the rport_event_queue
2040 */
Randy Dunlap55204902011-01-28 16:03:57 -08002041int fc_setup_rport(void)
Robert Love42e9a922008-12-09 15:10:17 -08002042{
2043 rport_event_queue = create_singlethread_workqueue("fc_rport_eq");
2044 if (!rport_event_queue)
2045 return -ENOMEM;
2046 return 0;
2047}
Robert Love42e9a922008-12-09 15:10:17 -08002048
Robert Love3a3b42b2009-11-03 11:47:39 -08002049/**
2050 * fc_destroy_rport() - Destroy the rport_event_queue
2051 */
Randy Dunlap55204902011-01-28 16:03:57 -08002052void fc_destroy_rport(void)
Robert Love42e9a922008-12-09 15:10:17 -08002053{
2054 destroy_workqueue(rport_event_queue);
2055}
Robert Love42e9a922008-12-09 15:10:17 -08002056
Robert Love3a3b42b2009-11-03 11:47:39 -08002057/**
2058 * fc_rport_terminate_io() - Stop all outstanding I/O on a remote port
2059 * @rport: The remote port whose I/O should be terminated
2060 */
Robert Love42e9a922008-12-09 15:10:17 -08002061void fc_rport_terminate_io(struct fc_rport *rport)
2062{
Robert Love3a3b42b2009-11-03 11:47:39 -08002063 struct fc_rport_libfc_priv *rpriv = rport->dd_data;
2064 struct fc_lport *lport = rpriv->local_port;
Robert Love42e9a922008-12-09 15:10:17 -08002065
Abhijeet Joglekar1f6ff362009-02-27 10:54:35 -08002066 lport->tt.exch_mgr_reset(lport, 0, rport->port_id);
2067 lport->tt.exch_mgr_reset(lport, rport->port_id, 0);
Robert Love42e9a922008-12-09 15:10:17 -08002068}
2069EXPORT_SYMBOL(fc_rport_terminate_io);