blob: d275df04f03a746c5d2560b260447e86063948ce [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
Hannes Reinecke4d2095c2016-09-30 11:01:14 +020047/*
48 * RPORT REFERENCE COUNTING
49 *
50 * A rport reference should be taken when:
51 * - an rport is allocated
52 * - a workqueue item is scheduled
53 * - an ELS request is send
54 * The reference should be dropped when:
55 * - the workqueue function has finished
56 * - the ELS response is handled
57 * - an rport is removed
58 */
59
Robert Love42e9a922008-12-09 15:10:17 -080060#include <linux/kernel.h>
61#include <linux/spinlock.h>
62#include <linux/interrupt.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090063#include <linux/slab.h>
Robert Love42e9a922008-12-09 15:10:17 -080064#include <linux/rcupdate.h>
65#include <linux/timer.h>
66#include <linux/workqueue.h>
Paul Gortmaker09703662011-05-27 09:37:25 -040067#include <linux/export.h>
Robert Love42e9a922008-12-09 15:10:17 -080068#include <asm/unaligned.h>
69
70#include <scsi/libfc.h>
71#include <scsi/fc_encode.h>
72
Robert Love8866a5d2009-11-03 11:45:58 -080073#include "fc_libfc.h"
74
Randy Dunlap55204902011-01-28 16:03:57 -080075static struct workqueue_struct *rport_event_queue;
Robert Love42e9a922008-12-09 15:10:17 -080076
Joe Eykholta7b12a22010-07-20 15:20:08 -070077static void fc_rport_enter_flogi(struct fc_rport_priv *);
Joe Eykholt9fb9d322009-08-25 14:00:50 -070078static void fc_rport_enter_plogi(struct fc_rport_priv *);
79static void fc_rport_enter_prli(struct fc_rport_priv *);
80static void fc_rport_enter_rtv(struct fc_rport_priv *);
81static void fc_rport_enter_ready(struct fc_rport_priv *);
82static void fc_rport_enter_logo(struct fc_rport_priv *);
Joe Eykholt370c3bd2009-08-25 14:03:47 -070083static void fc_rport_enter_adisc(struct fc_rport_priv *);
Robert Love42e9a922008-12-09 15:10:17 -080084
Joe Eykholt922611562010-07-20 15:21:12 -070085static void fc_rport_recv_plogi_req(struct fc_lport *, struct fc_frame *);
86static void fc_rport_recv_prli_req(struct fc_rport_priv *, struct fc_frame *);
87static void fc_rport_recv_prlo_req(struct fc_rport_priv *, struct fc_frame *);
88static void fc_rport_recv_logo_req(struct fc_lport *, struct fc_frame *);
Robert Love42e9a922008-12-09 15:10:17 -080089static void fc_rport_timeout(struct work_struct *);
Hannes Reinecke9f9504a2016-10-13 15:10:44 +020090static void fc_rport_error(struct fc_rport_priv *, int);
91static void fc_rport_error_retry(struct fc_rport_priv *, int);
Robert Love42e9a922008-12-09 15:10:17 -080092static void fc_rport_work(struct work_struct *);
93
94static const char *fc_rport_state_names[] = {
Robert Love42e9a922008-12-09 15:10:17 -080095 [RPORT_ST_INIT] = "Init",
Joe Eykholta7b12a22010-07-20 15:20:08 -070096 [RPORT_ST_FLOGI] = "FLOGI",
97 [RPORT_ST_PLOGI_WAIT] = "PLOGI_WAIT",
Robert Love42e9a922008-12-09 15:10:17 -080098 [RPORT_ST_PLOGI] = "PLOGI",
99 [RPORT_ST_PRLI] = "PRLI",
100 [RPORT_ST_RTV] = "RTV",
101 [RPORT_ST_READY] = "Ready",
Joe Eykholt370c3bd2009-08-25 14:03:47 -0700102 [RPORT_ST_ADISC] = "ADISC",
Joe Eykholt14194052009-07-29 17:04:43 -0700103 [RPORT_ST_DELETE] = "Delete",
Robert Love42e9a922008-12-09 15:10:17 -0800104};
105
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700106/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800107 * fc_rport_lookup() - Lookup a remote port by port_id
108 * @lport: The local port to lookup the remote port on
109 * @port_id: The remote port ID to look up
Joe Eykholt42e90412010-07-20 15:19:37 -0700110 *
Hannes Reineckebaa67192016-05-24 08:11:58 +0200111 * The reference count of the fc_rport_priv structure is
112 * increased by one.
Joe Eykholt8025b5d2009-08-25 14:02:06 -0700113 */
114static struct fc_rport_priv *fc_rport_lookup(const struct fc_lport *lport,
115 u32 port_id)
116{
Hannes Reineckebaa67192016-05-24 08:11:58 +0200117 struct fc_rport_priv *rdata = NULL, *tmp_rdata;
Joe Eykholt8025b5d2009-08-25 14:02:06 -0700118
Hannes Reineckebaa67192016-05-24 08:11:58 +0200119 rcu_read_lock();
120 list_for_each_entry_rcu(tmp_rdata, &lport->disc.rports, peers)
121 if (tmp_rdata->ids.port_id == port_id &&
122 kref_get_unless_zero(&tmp_rdata->kref)) {
123 rdata = tmp_rdata;
124 break;
125 }
126 rcu_read_unlock();
127 return rdata;
Joe Eykholt8025b5d2009-08-25 14:02:06 -0700128}
129
130/**
Robert Love9737e6a2009-08-25 14:02:59 -0700131 * fc_rport_create() - Create a new remote port
Robert Love3a3b42b2009-11-03 11:47:39 -0800132 * @lport: The local port this remote port will be associated with
133 * @ids: The identifiers for the new remote port
134 *
135 * The remote port will start in the INIT state.
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700136 *
Joe Eykholt48f00902009-08-25 14:01:50 -0700137 * Locking note: must be called with the disc_mutex held.
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700138 */
139static struct fc_rport_priv *fc_rport_create(struct fc_lport *lport,
Robert Love9737e6a2009-08-25 14:02:59 -0700140 u32 port_id)
Robert Love42e9a922008-12-09 15:10:17 -0800141{
Joe Eykholtab28f1f2009-08-25 14:00:34 -0700142 struct fc_rport_priv *rdata;
Robert Love42e9a922008-12-09 15:10:17 -0800143
Robert Love9737e6a2009-08-25 14:02:59 -0700144 rdata = lport->tt.rport_lookup(lport, port_id);
Joe Eykholt19f97e32009-08-25 14:01:55 -0700145 if (rdata)
146 return rdata;
147
Joe Eykholtf90377a2010-07-20 15:19:42 -0700148 rdata = kzalloc(sizeof(*rdata) + lport->rport_priv_size, GFP_KERNEL);
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700149 if (!rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800150 return NULL;
151
Robert Love9737e6a2009-08-25 14:02:59 -0700152 rdata->ids.node_name = -1;
153 rdata->ids.port_name = -1;
154 rdata->ids.port_id = port_id;
155 rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
156
Joe Eykholtf211fa52009-08-25 14:01:01 -0700157 kref_init(&rdata->kref);
Robert Love42e9a922008-12-09 15:10:17 -0800158 mutex_init(&rdata->rp_mutex);
Joe Eykholt795d86f2009-08-25 14:00:39 -0700159 rdata->local_port = lport;
Robert Love42e9a922008-12-09 15:10:17 -0800160 rdata->rp_state = RPORT_ST_INIT;
161 rdata->event = RPORT_EV_NONE;
162 rdata->flags = FC_RP_FLAGS_REC_SUPPORTED;
Joe Eykholt795d86f2009-08-25 14:00:39 -0700163 rdata->e_d_tov = lport->e_d_tov;
164 rdata->r_a_tov = lport->r_a_tov;
Joe Eykholtf211fa52009-08-25 14:01:01 -0700165 rdata->maxframe_size = FC_MIN_MAX_PAYLOAD;
Robert Love42e9a922008-12-09 15:10:17 -0800166 INIT_DELAYED_WORK(&rdata->retry_work, fc_rport_timeout);
167 INIT_WORK(&rdata->event_work, fc_rport_work);
Bhanu Prakash Gollapudi75a27922011-01-28 16:05:27 -0800168 if (port_id != FC_FID_DIR_SERV) {
169 rdata->lld_event_callback = lport->tt.rport_event_callback;
Joe Eykholt42e90412010-07-20 15:19:37 -0700170 list_add_rcu(&rdata->peers, &lport->disc.rports);
Bhanu Prakash Gollapudi75a27922011-01-28 16:05:27 -0800171 }
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700172 return rdata;
Robert Love42e9a922008-12-09 15:10:17 -0800173}
174
175/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800176 * fc_rport_destroy() - Free a remote port after last reference is released
177 * @kref: The remote port's kref
Joe Eykholtf211fa52009-08-25 14:01:01 -0700178 */
179static void fc_rport_destroy(struct kref *kref)
180{
181 struct fc_rport_priv *rdata;
Joe Eykholtf211fa52009-08-25 14:01:01 -0700182
183 rdata = container_of(kref, struct fc_rport_priv, kref);
Lai Jiangshan8497a242011-03-18 11:41:14 +0800184 kfree_rcu(rdata, rcu);
Joe Eykholtf211fa52009-08-25 14:01:01 -0700185}
186
187/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800188 * fc_rport_state() - Return a string identifying the remote port's state
189 * @rdata: The remote port
Robert Love42e9a922008-12-09 15:10:17 -0800190 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700191static const char *fc_rport_state(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800192{
193 const char *cp;
Robert Love42e9a922008-12-09 15:10:17 -0800194
195 cp = fc_rport_state_names[rdata->rp_state];
196 if (!cp)
197 cp = "Unknown";
198 return cp;
199}
200
201/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800202 * fc_set_rport_loss_tmo() - Set the remote port loss timeout
203 * @rport: The remote port that gets a new timeout value
204 * @timeout: The new timeout value (in seconds)
Robert Love42e9a922008-12-09 15:10:17 -0800205 */
206void fc_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout)
207{
208 if (timeout)
Mike Christie73b43762010-10-08 17:12:10 -0700209 rport->dev_loss_tmo = timeout;
Robert Love42e9a922008-12-09 15:10:17 -0800210 else
Mike Christie73b43762010-10-08 17:12:10 -0700211 rport->dev_loss_tmo = 1;
Robert Love42e9a922008-12-09 15:10:17 -0800212}
213EXPORT_SYMBOL(fc_set_rport_loss_tmo);
214
215/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800216 * fc_plogi_get_maxframe() - Get the maximum payload from the common service
217 * parameters in a FLOGI frame
Joe Eykholta7b12a22010-07-20 15:20:08 -0700218 * @flp: The FLOGI or PLOGI payload
Robert Love3a3b42b2009-11-03 11:47:39 -0800219 * @maxval: The maximum frame size upper limit; this may be less than what
220 * is in the service parameters
Robert Love42e9a922008-12-09 15:10:17 -0800221 */
Robert Loveb2ab99c2009-02-27 10:55:50 -0800222static unsigned int fc_plogi_get_maxframe(struct fc_els_flogi *flp,
223 unsigned int maxval)
Robert Love42e9a922008-12-09 15:10:17 -0800224{
225 unsigned int mfs;
226
227 /*
228 * Get max payload from the common service parameters and the
229 * class 3 receive data field size.
230 */
231 mfs = ntohs(flp->fl_csp.sp_bb_data) & FC_SP_BB_DATA_MASK;
232 if (mfs >= FC_SP_MIN_MAX_PAYLOAD && mfs < maxval)
233 maxval = mfs;
234 mfs = ntohs(flp->fl_cssp[3 - 1].cp_rdfs);
235 if (mfs >= FC_SP_MIN_MAX_PAYLOAD && mfs < maxval)
236 maxval = mfs;
237 return maxval;
238}
239
240/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800241 * fc_rport_state_enter() - Change the state of a remote port
242 * @rdata: The remote port whose state should change
243 * @new: The new state
Robert Love42e9a922008-12-09 15:10:17 -0800244 *
245 * Locking Note: Called with the rport lock held
246 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700247static void fc_rport_state_enter(struct fc_rport_priv *rdata,
Robert Love42e9a922008-12-09 15:10:17 -0800248 enum fc_rport_state new)
249{
Robert Love42e9a922008-12-09 15:10:17 -0800250 if (rdata->rp_state != new)
251 rdata->retries = 0;
252 rdata->rp_state = new;
253}
254
Robert Love3a3b42b2009-11-03 11:47:39 -0800255/**
256 * fc_rport_work() - Handler for remote port events in the rport_event_queue
257 * @work: Handle to the remote port being dequeued
Hannes Reinecke4d2095c2016-09-30 11:01:14 +0200258 *
259 * Reference counting: drops kref on return
Robert Love3a3b42b2009-11-03 11:47:39 -0800260 */
Robert Love42e9a922008-12-09 15:10:17 -0800261static void fc_rport_work(struct work_struct *work)
262{
Abhijeet Joglekar571f8242009-02-27 10:54:41 -0800263 u32 port_id;
Joe Eykholtab28f1f2009-08-25 14:00:34 -0700264 struct fc_rport_priv *rdata =
265 container_of(work, struct fc_rport_priv, event_work);
Robert Love3a3b42b2009-11-03 11:47:39 -0800266 struct fc_rport_libfc_priv *rpriv;
Robert Love42e9a922008-12-09 15:10:17 -0800267 enum fc_rport_event event;
Robert Love42e9a922008-12-09 15:10:17 -0800268 struct fc_lport *lport = rdata->local_port;
269 struct fc_rport_operations *rport_ops;
Joe Eykholt629f4422009-08-25 14:01:06 -0700270 struct fc_rport_identifiers ids;
Joe Eykholtf211fa52009-08-25 14:01:01 -0700271 struct fc_rport *rport;
Joe Eykholt96ad8462011-01-28 16:04:02 -0800272 struct fc4_prov *prov;
273 u8 type;
Robert Love42e9a922008-12-09 15:10:17 -0800274
275 mutex_lock(&rdata->rp_mutex);
276 event = rdata->event;
277 rport_ops = rdata->ops;
Joe Eykholtf211fa52009-08-25 14:01:01 -0700278 rport = rdata->rport;
Robert Love42e9a922008-12-09 15:10:17 -0800279
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700280 FC_RPORT_DBG(rdata, "work event %u\n", event);
281
Joe Eykholt629f4422009-08-25 14:01:06 -0700282 switch (event) {
Joe Eykholt4c0f62b2009-08-25 14:01:12 -0700283 case RPORT_EV_READY:
Joe Eykholtf211fa52009-08-25 14:01:01 -0700284 ids = rdata->ids;
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700285 rdata->event = RPORT_EV_NONE;
Joe Eykholtf0342602010-06-11 16:44:57 -0700286 rdata->major_retries = 0;
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700287 kref_get(&rdata->kref);
Robert Love42e9a922008-12-09 15:10:17 -0800288 mutex_unlock(&rdata->rp_mutex);
289
Hannes Reinecke57d3ec7e2016-10-13 15:10:37 +0200290 if (!rport) {
291 FC_RPORT_DBG(rdata, "No rport!\n");
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700292 rport = fc_remote_port_add(lport->host, 0, &ids);
Hannes Reinecke57d3ec7e2016-10-13 15:10:37 +0200293 }
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700294 if (!rport) {
295 FC_RPORT_DBG(rdata, "Failed to add the rport\n");
296 lport->tt.rport_logoff(rdata);
297 kref_put(&rdata->kref, lport->tt.rport_destroy);
298 return;
Robert Love42e9a922008-12-09 15:10:17 -0800299 }
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700300 mutex_lock(&rdata->rp_mutex);
301 if (rdata->rport)
302 FC_RPORT_DBG(rdata, "rport already allocated\n");
303 rdata->rport = rport;
304 rport->maxframe_size = rdata->maxframe_size;
305 rport->supported_classes = rdata->supported_classes;
306
Robert Love3a3b42b2009-11-03 11:47:39 -0800307 rpriv = rport->dd_data;
308 rpriv->local_port = lport;
309 rpriv->rp_state = rdata->rp_state;
310 rpriv->flags = rdata->flags;
311 rpriv->e_d_tov = rdata->e_d_tov;
312 rpriv->r_a_tov = rdata->r_a_tov;
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700313 mutex_unlock(&rdata->rp_mutex);
314
Joe Eykholt83455922009-08-25 14:02:01 -0700315 if (rport_ops && rport_ops->event_callback) {
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700316 FC_RPORT_DBG(rdata, "callback ev %d\n", event);
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700317 rport_ops->event_callback(lport, rdata, event);
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700318 }
Bhanu Prakash Gollapudi75a27922011-01-28 16:05:27 -0800319 if (rdata->lld_event_callback) {
320 FC_RPORT_DBG(rdata, "lld callback ev %d\n", event);
321 rdata->lld_event_callback(lport, rdata, event);
322 }
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700323 kref_put(&rdata->kref, lport->tt.rport_destroy);
Joe Eykholt629f4422009-08-25 14:01:06 -0700324 break;
325
326 case RPORT_EV_FAILED:
327 case RPORT_EV_LOGO:
328 case RPORT_EV_STOP:
Joe Eykholt96ad8462011-01-28 16:04:02 -0800329 if (rdata->prli_count) {
330 mutex_lock(&fc_prov_mutex);
331 for (type = 1; type < FC_FC4_PROV_SIZE; type++) {
332 prov = fc_passive_prov[type];
333 if (prov && prov->prlo)
334 prov->prlo(rdata);
335 }
336 mutex_unlock(&fc_prov_mutex);
337 }
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700338 port_id = rdata->ids.port_id;
Robert Love42e9a922008-12-09 15:10:17 -0800339 mutex_unlock(&rdata->rp_mutex);
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700340
Joe Eykholt83455922009-08-25 14:02:01 -0700341 if (rport_ops && rport_ops->event_callback) {
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700342 FC_RPORT_DBG(rdata, "callback ev %d\n", event);
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700343 rport_ops->event_callback(lport, rdata, event);
Abhijeet Joglekar571f8242009-02-27 10:54:41 -0800344 }
Bhanu Prakash Gollapudi75a27922011-01-28 16:05:27 -0800345 if (rdata->lld_event_callback) {
346 FC_RPORT_DBG(rdata, "lld callback ev %d\n", event);
347 rdata->lld_event_callback(lport, rdata, event);
348 }
Hannes Reinecke4d2095c2016-09-30 11:01:14 +0200349 if (cancel_delayed_work_sync(&rdata->retry_work))
350 kref_put(&rdata->kref, lport->tt.rport_destroy);
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700351
352 /*
353 * Reset any outstanding exchanges before freeing rport.
354 */
355 lport->tt.exch_mgr_reset(lport, 0, port_id);
356 lport->tt.exch_mgr_reset(lport, port_id, 0);
357
358 if (rport) {
Robert Love3a3b42b2009-11-03 11:47:39 -0800359 rpriv = rport->dd_data;
360 rpriv->rp_state = RPORT_ST_DELETE;
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700361 mutex_lock(&rdata->rp_mutex);
362 rdata->rport = NULL;
363 mutex_unlock(&rdata->rp_mutex);
364 fc_remote_port_delete(rport);
365 }
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700366
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700367 mutex_lock(&rdata->rp_mutex);
368 if (rdata->rp_state == RPORT_ST_DELETE) {
369 if (port_id == FC_FID_DIR_SERV) {
370 rdata->event = RPORT_EV_NONE;
371 mutex_unlock(&rdata->rp_mutex);
Parikh, Neeravfe5e3f12011-02-25 15:02:51 -0800372 kref_put(&rdata->kref, lport->tt.rport_destroy);
Joe Eykholtf0342602010-06-11 16:44:57 -0700373 } else if ((rdata->flags & FC_RP_STARTED) &&
374 rdata->major_retries <
375 lport->max_rport_retry_count) {
376 rdata->major_retries++;
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700377 rdata->event = RPORT_EV_NONE;
378 FC_RPORT_DBG(rdata, "work restart\n");
Joe Eykholta7b12a22010-07-20 15:20:08 -0700379 fc_rport_enter_flogi(rdata);
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700380 mutex_unlock(&rdata->rp_mutex);
381 } else {
382 FC_RPORT_DBG(rdata, "work delete\n");
Hannes Reineckea407c592016-09-30 11:01:15 +0200383 mutex_lock(&lport->disc.disc_mutex);
Joe Eykholt42e90412010-07-20 15:19:37 -0700384 list_del_rcu(&rdata->peers);
Hannes Reineckea407c592016-09-30 11:01:15 +0200385 mutex_unlock(&lport->disc.disc_mutex);
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700386 mutex_unlock(&rdata->rp_mutex);
387 kref_put(&rdata->kref, lport->tt.rport_destroy);
388 }
389 } else {
390 /*
391 * Re-open for events. Reissue READY event if ready.
392 */
393 rdata->event = RPORT_EV_NONE;
Hannes Reinecke57d3ec7e2016-10-13 15:10:37 +0200394 if (rdata->rp_state == RPORT_ST_READY) {
395 FC_RPORT_DBG(rdata, "work reopen\n");
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700396 fc_rport_enter_ready(rdata);
Hannes Reinecke57d3ec7e2016-10-13 15:10:37 +0200397 }
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -0700398 mutex_unlock(&rdata->rp_mutex);
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700399 }
Joe Eykholt629f4422009-08-25 14:01:06 -0700400 break;
401
402 default:
Robert Love42e9a922008-12-09 15:10:17 -0800403 mutex_unlock(&rdata->rp_mutex);
Joe Eykholt629f4422009-08-25 14:01:06 -0700404 break;
405 }
Hannes Reinecke4d2095c2016-09-30 11:01:14 +0200406 kref_put(&rdata->kref, lport->tt.rport_destroy);
Robert Love42e9a922008-12-09 15:10:17 -0800407}
408
409/**
Robert Love34f42a02009-02-27 10:55:45 -0800410 * fc_rport_login() - Start the remote port login state machine
Robert Love3a3b42b2009-11-03 11:47:39 -0800411 * @rdata: The remote port to be logged in to
Robert Love42e9a922008-12-09 15:10:17 -0800412 *
413 * Locking Note: Called without the rport lock held. This
414 * function will hold the rport lock, call an _enter_*
415 * function and then unlock the rport.
Joe Eykholt370c3bd2009-08-25 14:03:47 -0700416 *
417 * This indicates the intent to be logged into the remote port.
418 * If it appears we are already logged in, ADISC is used to verify
419 * the setup.
Robert Love42e9a922008-12-09 15:10:17 -0800420 */
Bart Van Asschec6b21c92012-01-13 17:26:20 -0800421static int fc_rport_login(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800422{
Robert Love42e9a922008-12-09 15:10:17 -0800423 mutex_lock(&rdata->rp_mutex);
424
Hannes Reinecke06ee2572016-09-30 11:01:18 +0200425 if (rdata->flags & FC_RP_STARTED) {
426 FC_RPORT_DBG(rdata, "port already started\n");
427 mutex_unlock(&rdata->rp_mutex);
428 return 0;
429 }
430
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700431 rdata->flags |= FC_RP_STARTED;
Joe Eykholt370c3bd2009-08-25 14:03:47 -0700432 switch (rdata->rp_state) {
433 case RPORT_ST_READY:
434 FC_RPORT_DBG(rdata, "ADISC port\n");
435 fc_rport_enter_adisc(rdata);
436 break;
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -0700437 case RPORT_ST_DELETE:
438 FC_RPORT_DBG(rdata, "Restart deleted port\n");
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -0700439 break;
Hannes Reineckee5a20002016-09-30 11:01:17 +0200440 case RPORT_ST_INIT:
Joe Eykholt370c3bd2009-08-25 14:03:47 -0700441 FC_RPORT_DBG(rdata, "Login to port\n");
Joe Eykholta7b12a22010-07-20 15:20:08 -0700442 fc_rport_enter_flogi(rdata);
Joe Eykholt370c3bd2009-08-25 14:03:47 -0700443 break;
Hannes Reineckee5a20002016-09-30 11:01:17 +0200444 default:
445 FC_RPORT_DBG(rdata, "Login in progress, state %s\n",
446 fc_rport_state(rdata));
447 break;
Joe Eykholt370c3bd2009-08-25 14:03:47 -0700448 }
Robert Love42e9a922008-12-09 15:10:17 -0800449 mutex_unlock(&rdata->rp_mutex);
450
451 return 0;
452}
453
454/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800455 * fc_rport_enter_delete() - Schedule a remote port to be deleted
456 * @rdata: The remote port to be deleted
457 * @event: The event to report as the reason for deletion
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700458 *
459 * Locking Note: Called with the rport lock held.
460 *
461 * Allow state change into DELETE only once.
462 *
463 * Call queue_work only if there's no event already pending.
464 * Set the new event so that the old pending event will not occur.
465 * Since we have the mutex, even if fc_rport_work() is already started,
466 * it'll see the new event.
Hannes Reinecke4d2095c2016-09-30 11:01:14 +0200467 *
468 * Reference counting: does not modify kref
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700469 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700470static void fc_rport_enter_delete(struct fc_rport_priv *rdata,
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700471 enum fc_rport_event event)
472{
Hannes Reinecke4d2095c2016-09-30 11:01:14 +0200473 struct fc_lport *lport = rdata->local_port;
474
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700475 if (rdata->rp_state == RPORT_ST_DELETE)
476 return;
477
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700478 FC_RPORT_DBG(rdata, "Delete port\n");
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700479
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700480 fc_rport_state_enter(rdata, RPORT_ST_DELETE);
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700481
Hannes Reinecke4d2095c2016-09-30 11:01:14 +0200482 kref_get(&rdata->kref);
483 if (rdata->event == RPORT_EV_NONE &&
484 !queue_work(rport_event_queue, &rdata->event_work))
485 kref_put(&rdata->kref, lport->tt.rport_destroy);
486
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700487 rdata->event = event;
488}
489
490/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800491 * fc_rport_logoff() - Logoff and remove a remote port
492 * @rdata: The remote port to be logged off of
Robert Love42e9a922008-12-09 15:10:17 -0800493 *
494 * Locking Note: Called without the rport lock held. This
495 * function will hold the rport lock, call an _enter_*
496 * function and then unlock the rport.
497 */
Bart Van Asschec6b21c92012-01-13 17:26:20 -0800498static int fc_rport_logoff(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800499{
Hannes Reinecke649eb862016-08-05 14:55:02 +0200500 struct fc_lport *lport = rdata->local_port;
501 u32 port_id = rdata->ids.port_id;
502
Robert Love42e9a922008-12-09 15:10:17 -0800503 mutex_lock(&rdata->rp_mutex);
504
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700505 FC_RPORT_DBG(rdata, "Remove port\n");
Robert Love42e9a922008-12-09 15:10:17 -0800506
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700507 rdata->flags &= ~FC_RP_STARTED;
Joe Eykholt14194052009-07-29 17:04:43 -0700508 if (rdata->rp_state == RPORT_ST_DELETE) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700509 FC_RPORT_DBG(rdata, "Port in Delete state, not removing\n");
Abhijeet Joglekarb4c6f542009-04-21 16:27:04 -0700510 goto out;
511 }
Hannes Reinecke649eb862016-08-05 14:55:02 +0200512 /*
513 * FC-LS states:
514 * To explicitly Logout, the initiating Nx_Port shall terminate
515 * other open Sequences that it initiated with the destination
516 * Nx_Port prior to performing Logout.
517 */
518 lport->tt.exch_mgr_reset(lport, 0, port_id);
519 lport->tt.exch_mgr_reset(lport, port_id, 0);
520
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700521 fc_rport_enter_logo(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800522
523 /*
Joe Eykholt14194052009-07-29 17:04:43 -0700524 * Change the state to Delete so that we discard
Robert Love42e9a922008-12-09 15:10:17 -0800525 * the response.
526 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700527 fc_rport_enter_delete(rdata, RPORT_EV_STOP);
Abhijeet Joglekarb4c6f542009-04-21 16:27:04 -0700528out:
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -0700529 mutex_unlock(&rdata->rp_mutex);
Robert Love42e9a922008-12-09 15:10:17 -0800530 return 0;
531}
532
533/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800534 * fc_rport_enter_ready() - Transition to the RPORT_ST_READY state
535 * @rdata: The remote port that is ready
Robert Love42e9a922008-12-09 15:10:17 -0800536 *
537 * Locking Note: The rport lock is expected to be held before calling
538 * this routine.
Hannes Reinecke4d2095c2016-09-30 11:01:14 +0200539 *
540 * Reference counting: schedules workqueue, does not modify kref
Robert Love42e9a922008-12-09 15:10:17 -0800541 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700542static void fc_rport_enter_ready(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800543{
Hannes Reinecke4d2095c2016-09-30 11:01:14 +0200544 struct fc_lport *lport = rdata->local_port;
545
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700546 fc_rport_state_enter(rdata, RPORT_ST_READY);
Robert Love42e9a922008-12-09 15:10:17 -0800547
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700548 FC_RPORT_DBG(rdata, "Port is Ready\n");
Robert Love42e9a922008-12-09 15:10:17 -0800549
Hannes Reinecke4d2095c2016-09-30 11:01:14 +0200550 kref_get(&rdata->kref);
551 if (rdata->event == RPORT_EV_NONE &&
552 !queue_work(rport_event_queue, &rdata->event_work))
553 kref_put(&rdata->kref, lport->tt.rport_destroy);
554
Joe Eykholt4c0f62b2009-08-25 14:01:12 -0700555 rdata->event = RPORT_EV_READY;
Robert Love42e9a922008-12-09 15:10:17 -0800556}
557
558/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800559 * fc_rport_timeout() - Handler for the retry_work timer
560 * @work: Handle to the remote port that has timed out
Robert Love42e9a922008-12-09 15:10:17 -0800561 *
562 * Locking Note: Called without the rport lock held. This
563 * function will hold the rport lock, call an _enter_*
564 * function and then unlock the rport.
Hannes Reinecke4d2095c2016-09-30 11:01:14 +0200565 *
566 * Reference counting: Drops kref on return.
Robert Love42e9a922008-12-09 15:10:17 -0800567 */
568static void fc_rport_timeout(struct work_struct *work)
569{
Joe Eykholtab28f1f2009-08-25 14:00:34 -0700570 struct fc_rport_priv *rdata =
571 container_of(work, struct fc_rport_priv, retry_work.work);
Hannes Reinecke4d2095c2016-09-30 11:01:14 +0200572 struct fc_lport *lport = rdata->local_port;
Robert Love42e9a922008-12-09 15:10:17 -0800573
574 mutex_lock(&rdata->rp_mutex);
Hannes Reinecke57d3ec7e2016-10-13 15:10:37 +0200575 FC_RPORT_DBG(rdata, "Port timeout, state %s\n", fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -0800576
577 switch (rdata->rp_state) {
Joe Eykholta7b12a22010-07-20 15:20:08 -0700578 case RPORT_ST_FLOGI:
579 fc_rport_enter_flogi(rdata);
580 break;
Robert Love42e9a922008-12-09 15:10:17 -0800581 case RPORT_ST_PLOGI:
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700582 fc_rport_enter_plogi(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800583 break;
584 case RPORT_ST_PRLI:
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700585 fc_rport_enter_prli(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800586 break;
587 case RPORT_ST_RTV:
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700588 fc_rport_enter_rtv(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800589 break;
Joe Eykholt370c3bd2009-08-25 14:03:47 -0700590 case RPORT_ST_ADISC:
591 fc_rport_enter_adisc(rdata);
592 break;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700593 case RPORT_ST_PLOGI_WAIT:
Robert Love42e9a922008-12-09 15:10:17 -0800594 case RPORT_ST_READY:
595 case RPORT_ST_INIT:
Joe Eykholt14194052009-07-29 17:04:43 -0700596 case RPORT_ST_DELETE:
Robert Love42e9a922008-12-09 15:10:17 -0800597 break;
598 }
599
600 mutex_unlock(&rdata->rp_mutex);
Hannes Reinecke4d2095c2016-09-30 11:01:14 +0200601 kref_put(&rdata->kref, lport->tt.rport_destroy);
Robert Love42e9a922008-12-09 15:10:17 -0800602}
603
604/**
Robert Love34f42a02009-02-27 10:55:45 -0800605 * fc_rport_error() - Error handler, called once retries have been exhausted
Robert Love3a3b42b2009-11-03 11:47:39 -0800606 * @rdata: The remote port the error is happened on
Hannes Reinecke9f9504a2016-10-13 15:10:44 +0200607 * @err: The error code
Robert Love42e9a922008-12-09 15:10:17 -0800608 *
Robert Love42e9a922008-12-09 15:10:17 -0800609 * Locking Note: The rport lock is expected to be held before
610 * calling this routine
Hannes Reinecke4d2095c2016-09-30 11:01:14 +0200611 *
612 * Reference counting: does not modify kref
Robert Love42e9a922008-12-09 15:10:17 -0800613 */
Hannes Reinecke9f9504a2016-10-13 15:10:44 +0200614static void fc_rport_error(struct fc_rport_priv *rdata, int err)
Robert Love42e9a922008-12-09 15:10:17 -0800615{
Hannes Reinecked3919662016-08-05 14:55:01 +0200616 struct fc_lport *lport = rdata->local_port;
617
Hannes Reinecke9f9504a2016-10-13 15:10:44 +0200618 FC_RPORT_DBG(rdata, "Error %d in state %s, retries %d\n",
619 -err, fc_rport_state(rdata), rdata->retries);
Robert Love42e9a922008-12-09 15:10:17 -0800620
Chris Leech6755db12009-02-27 10:55:02 -0800621 switch (rdata->rp_state) {
Joe Eykholta7b12a22010-07-20 15:20:08 -0700622 case RPORT_ST_FLOGI:
Joe Eykholt4b2164d2010-06-11 16:44:51 -0700623 rdata->flags &= ~FC_RP_STARTED;
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700624 fc_rport_enter_delete(rdata, RPORT_EV_FAILED);
Chris Leech6755db12009-02-27 10:55:02 -0800625 break;
Hannes Reinecked3919662016-08-05 14:55:01 +0200626 case RPORT_ST_PLOGI:
627 if (lport->point_to_multipoint) {
628 rdata->flags &= ~FC_RP_STARTED;
629 fc_rport_enter_delete(rdata, RPORT_EV_FAILED);
630 } else
631 fc_rport_enter_logo(rdata);
632 break;
Chris Leech6755db12009-02-27 10:55:02 -0800633 case RPORT_ST_RTV:
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700634 fc_rport_enter_ready(rdata);
Chris Leech6755db12009-02-27 10:55:02 -0800635 break;
Joe Eykholt370c3bd2009-08-25 14:03:47 -0700636 case RPORT_ST_PRLI:
637 case RPORT_ST_ADISC:
638 fc_rport_enter_logo(rdata);
639 break;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700640 case RPORT_ST_PLOGI_WAIT:
Joe Eykholt14194052009-07-29 17:04:43 -0700641 case RPORT_ST_DELETE:
Chris Leech6755db12009-02-27 10:55:02 -0800642 case RPORT_ST_READY:
643 case RPORT_ST_INIT:
644 break;
Robert Love42e9a922008-12-09 15:10:17 -0800645 }
646}
647
648/**
Robert Love3a3b42b2009-11-03 11:47:39 -0800649 * fc_rport_error_retry() - Handler for remote port state retries
650 * @rdata: The remote port whose state is to be retried
Hannes Reinecke9f9504a2016-10-13 15:10:44 +0200651 * @err: The error code
Chris Leech6755db12009-02-27 10:55:02 -0800652 *
653 * If the error was an exchange timeout retry immediately,
654 * otherwise wait for E_D_TOV.
655 *
656 * Locking Note: The rport lock is expected to be held before
657 * calling this routine
Hannes Reinecke4d2095c2016-09-30 11:01:14 +0200658 *
659 * Reference counting: increments kref when scheduling retry_work
Chris Leech6755db12009-02-27 10:55:02 -0800660 */
Hannes Reinecke9f9504a2016-10-13 15:10:44 +0200661static void fc_rport_error_retry(struct fc_rport_priv *rdata, int err)
Chris Leech6755db12009-02-27 10:55:02 -0800662{
Hannes Reineckea50cc9e2016-10-13 15:10:40 +0200663 unsigned long delay = msecs_to_jiffies(rdata->e_d_tov);
Hannes Reinecke4d2095c2016-09-30 11:01:14 +0200664 struct fc_lport *lport = rdata->local_port;
Chris Leech6755db12009-02-27 10:55:02 -0800665
666 /* make sure this isn't an FC_EX_CLOSED error, never retry those */
Hannes Reinecke9f9504a2016-10-13 15:10:44 +0200667 if (err == -FC_EX_CLOSED)
Hillf Danton28a4af12011-01-28 16:03:26 -0800668 goto out;
Chris Leech6755db12009-02-27 10:55:02 -0800669
Abhijeet Joglekara3666952009-05-01 10:01:26 -0700670 if (rdata->retries < rdata->local_port->max_rport_retry_count) {
Hannes Reinecke9f9504a2016-10-13 15:10:44 +0200671 FC_RPORT_DBG(rdata, "Error %d in state %s, retrying\n",
672 err, fc_rport_state(rdata));
Chris Leech6755db12009-02-27 10:55:02 -0800673 rdata->retries++;
674 /* no additional delay on exchange timeouts */
Hannes Reinecke9f9504a2016-10-13 15:10:44 +0200675 if (err == -FC_EX_TIMEOUT)
Chris Leech6755db12009-02-27 10:55:02 -0800676 delay = 0;
Hannes Reinecke4d2095c2016-09-30 11:01:14 +0200677 kref_get(&rdata->kref);
678 if (!schedule_delayed_work(&rdata->retry_work, delay))
679 kref_put(&rdata->kref, lport->tt.rport_destroy);
Chris Leech6755db12009-02-27 10:55:02 -0800680 return;
681 }
682
Hillf Danton28a4af12011-01-28 16:03:26 -0800683out:
Hannes Reinecke9f9504a2016-10-13 15:10:44 +0200684 fc_rport_error(rdata, err);
Chris Leech6755db12009-02-27 10:55:02 -0800685}
686
687/**
Joe Eykholta7b12a22010-07-20 15:20:08 -0700688 * fc_rport_login_complete() - Handle parameters and completion of p-mp login.
689 * @rdata: The remote port which we logged into or which logged into us.
690 * @fp: The FLOGI or PLOGI request or response frame
691 *
692 * Returns non-zero error if a problem is detected with the frame.
693 * Does not free the frame.
694 *
695 * This is only used in point-to-multipoint mode for FIP currently.
696 */
697static int fc_rport_login_complete(struct fc_rport_priv *rdata,
698 struct fc_frame *fp)
699{
700 struct fc_lport *lport = rdata->local_port;
701 struct fc_els_flogi *flogi;
702 unsigned int e_d_tov;
703 u16 csp_flags;
704
705 flogi = fc_frame_payload_get(fp, sizeof(*flogi));
706 if (!flogi)
707 return -EINVAL;
708
709 csp_flags = ntohs(flogi->fl_csp.sp_features);
710
711 if (fc_frame_payload_op(fp) == ELS_FLOGI) {
712 if (csp_flags & FC_SP_FT_FPORT) {
713 FC_RPORT_DBG(rdata, "Fabric bit set in FLOGI\n");
714 return -EINVAL;
715 }
716 } else {
717
718 /*
719 * E_D_TOV is not valid on an incoming FLOGI request.
720 */
721 e_d_tov = ntohl(flogi->fl_csp.sp_e_d_tov);
722 if (csp_flags & FC_SP_FT_EDTR)
723 e_d_tov /= 1000000;
724 if (e_d_tov > rdata->e_d_tov)
725 rdata->e_d_tov = e_d_tov;
726 }
727 rdata->maxframe_size = fc_plogi_get_maxframe(flogi, lport->mfs);
728 return 0;
729}
730
731/**
732 * fc_rport_flogi_resp() - Handle response to FLOGI request for p-mp mode
733 * @sp: The sequence that the FLOGI was on
734 * @fp: The FLOGI response frame
735 * @rp_arg: The remote port that received the FLOGI response
736 */
Bart Van Asschec6b21c92012-01-13 17:26:20 -0800737static void fc_rport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp,
738 void *rp_arg)
Joe Eykholta7b12a22010-07-20 15:20:08 -0700739{
740 struct fc_rport_priv *rdata = rp_arg;
741 struct fc_lport *lport = rdata->local_port;
742 struct fc_els_flogi *flogi;
743 unsigned int r_a_tov;
Hannes Reinecke9f9504a2016-10-13 15:10:44 +0200744 u8 opcode;
745 int err = 0;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700746
Hannes Reinecke9f9504a2016-10-13 15:10:44 +0200747 FC_RPORT_DBG(rdata, "Received a FLOGI %s\n",
748 IS_ERR(fp) ? "error" : fc_els_resp_type(fp));
Joe Eykholta7b12a22010-07-20 15:20:08 -0700749
750 if (fp == ERR_PTR(-FC_EX_CLOSED))
Hillf Danton0e9e3d32010-11-30 16:19:04 -0800751 goto put;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700752
753 mutex_lock(&rdata->rp_mutex);
754
755 if (rdata->rp_state != RPORT_ST_FLOGI) {
756 FC_RPORT_DBG(rdata, "Received a FLOGI response, but in state "
757 "%s\n", fc_rport_state(rdata));
758 if (IS_ERR(fp))
759 goto err;
760 goto out;
761 }
762
763 if (IS_ERR(fp)) {
Hannes Reinecke9f9504a2016-10-13 15:10:44 +0200764 fc_rport_error(rdata, PTR_ERR(fp));
Joe Eykholta7b12a22010-07-20 15:20:08 -0700765 goto err;
766 }
Hannes Reinecke9f9504a2016-10-13 15:10:44 +0200767 opcode = fc_frame_payload_op(fp);
768 if (opcode == ELS_LS_RJT) {
769 struct fc_els_ls_rjt *rjt;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700770
Hannes Reinecke9f9504a2016-10-13 15:10:44 +0200771 rjt = fc_frame_payload_get(fp, sizeof(*rjt));
772 FC_RPORT_DBG(rdata, "FLOGI ELS rejected, reason %x expl %x\n",
773 rjt->er_reason, rjt->er_explan);
774 err = -FC_EX_ELS_RJT;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700775 goto bad;
Hannes Reinecke9f9504a2016-10-13 15:10:44 +0200776 } else if (opcode != ELS_LS_ACC) {
777 FC_RPORT_DBG(rdata, "FLOGI ELS invalid opcode %x\n", opcode);
778 err = -FC_EX_ELS_RJT;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700779 goto bad;
Hannes Reinecke9f9504a2016-10-13 15:10:44 +0200780 }
781 if (fc_rport_login_complete(rdata, fp)) {
782 FC_RPORT_DBG(rdata, "FLOGI failed, no login\n");
783 err = -FC_EX_INV_LOGIN;
784 goto bad;
785 }
Joe Eykholta7b12a22010-07-20 15:20:08 -0700786
787 flogi = fc_frame_payload_get(fp, sizeof(*flogi));
Hannes Reineckef89b8d62016-09-30 11:01:19 +0200788 if (!flogi) {
Hannes Reinecke9f9504a2016-10-13 15:10:44 +0200789 err = -FC_EX_ALLOC_ERR;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700790 goto bad;
Hannes Reineckef89b8d62016-09-30 11:01:19 +0200791 }
Joe Eykholta7b12a22010-07-20 15:20:08 -0700792 r_a_tov = ntohl(flogi->fl_csp.sp_r_a_tov);
793 if (r_a_tov > rdata->r_a_tov)
794 rdata->r_a_tov = r_a_tov;
795
796 if (rdata->ids.port_name < lport->wwpn)
797 fc_rport_enter_plogi(rdata);
798 else
799 fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
800out:
801 fc_frame_free(fp);
802err:
803 mutex_unlock(&rdata->rp_mutex);
Hillf Danton0e9e3d32010-11-30 16:19:04 -0800804put:
Hannes Reineckebaa67192016-05-24 08:11:58 +0200805 kref_put(&rdata->kref, lport->tt.rport_destroy);
Joe Eykholta7b12a22010-07-20 15:20:08 -0700806 return;
807bad:
Hannes Reinecke9f9504a2016-10-13 15:10:44 +0200808 FC_RPORT_DBG(rdata, "Bad FLOGI response\n");
809 fc_rport_error_retry(rdata, err);
Joe Eykholta7b12a22010-07-20 15:20:08 -0700810 goto out;
811}
812
813/**
814 * fc_rport_enter_flogi() - Send a FLOGI request to the remote port for p-mp
815 * @rdata: The remote port to send a FLOGI to
816 *
817 * Locking Note: The rport lock is expected to be held before calling
818 * this routine.
Hannes Reinecke4d2095c2016-09-30 11:01:14 +0200819 *
820 * Reference counting: increments kref when sending ELS
Joe Eykholta7b12a22010-07-20 15:20:08 -0700821 */
822static void fc_rport_enter_flogi(struct fc_rport_priv *rdata)
823{
824 struct fc_lport *lport = rdata->local_port;
825 struct fc_frame *fp;
826
827 if (!lport->point_to_multipoint)
828 return fc_rport_enter_plogi(rdata);
829
830 FC_RPORT_DBG(rdata, "Entered FLOGI state from %s state\n",
831 fc_rport_state(rdata));
832
833 fc_rport_state_enter(rdata, RPORT_ST_FLOGI);
834
835 fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi));
836 if (!fp)
Hannes Reinecke9f9504a2016-10-13 15:10:44 +0200837 return fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
Joe Eykholta7b12a22010-07-20 15:20:08 -0700838
Hannes Reinecke4d2095c2016-09-30 11:01:14 +0200839 kref_get(&rdata->kref);
Joe Eykholta7b12a22010-07-20 15:20:08 -0700840 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_FLOGI,
841 fc_rport_flogi_resp, rdata,
Hannes Reinecke4d2095c2016-09-30 11:01:14 +0200842 2 * lport->r_a_tov)) {
Hannes Reinecke9f9504a2016-10-13 15:10:44 +0200843 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
Hannes Reinecke4d2095c2016-09-30 11:01:14 +0200844 kref_put(&rdata->kref, lport->tt.rport_destroy);
845 }
Joe Eykholta7b12a22010-07-20 15:20:08 -0700846}
847
848/**
849 * fc_rport_recv_flogi_req() - Handle Fabric Login (FLOGI) request in p-mp mode
850 * @lport: The local port that received the PLOGI request
Joe Eykholta7b12a22010-07-20 15:20:08 -0700851 * @rx_fp: The PLOGI request frame
Hannes Reinecke4d2095c2016-09-30 11:01:14 +0200852 *
853 * Reference counting: drops kref on return
Joe Eykholta7b12a22010-07-20 15:20:08 -0700854 */
855static void fc_rport_recv_flogi_req(struct fc_lport *lport,
Joe Eykholt922611562010-07-20 15:21:12 -0700856 struct fc_frame *rx_fp)
Joe Eykholta7b12a22010-07-20 15:20:08 -0700857{
858 struct fc_disc *disc;
859 struct fc_els_flogi *flp;
860 struct fc_rport_priv *rdata;
861 struct fc_frame *fp = rx_fp;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700862 struct fc_seq_els_data rjt_data;
Joe Eykholt24f089e2010-07-20 15:21:01 -0700863 u32 sid;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700864
Joe Eykholt251748a2010-07-20 15:20:56 -0700865 sid = fc_frame_sid(fp);
Joe Eykholta7b12a22010-07-20 15:20:08 -0700866
867 FC_RPORT_ID_DBG(lport, sid, "Received FLOGI request\n");
868
869 disc = &lport->disc;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700870 if (!lport->point_to_multipoint) {
871 rjt_data.reason = ELS_RJT_UNSUP;
872 rjt_data.explan = ELS_EXPL_NONE;
873 goto reject;
874 }
875
876 flp = fc_frame_payload_get(fp, sizeof(*flp));
877 if (!flp) {
878 rjt_data.reason = ELS_RJT_LOGIC;
879 rjt_data.explan = ELS_EXPL_INV_LEN;
880 goto reject;
881 }
882
883 rdata = lport->tt.rport_lookup(lport, sid);
884 if (!rdata) {
885 rjt_data.reason = ELS_RJT_FIP;
886 rjt_data.explan = ELS_EXPL_NOT_NEIGHBOR;
887 goto reject;
888 }
889 mutex_lock(&rdata->rp_mutex);
890
891 FC_RPORT_DBG(rdata, "Received FLOGI in %s state\n",
892 fc_rport_state(rdata));
893
894 switch (rdata->rp_state) {
895 case RPORT_ST_INIT:
Kiran Patil48058482011-06-20 16:58:59 -0700896 /*
897 * If received the FLOGI request on RPORT which is INIT state
898 * (means not transition to FLOGI either fc_rport timeout
899 * function didn;t trigger or this end hasn;t received
900 * beacon yet from other end. In that case only, allow RPORT
901 * state machine to continue, otherwise fall through which
902 * causes the code to send reject response.
903 * NOTE; Not checking for FIP->state such as VNMP_UP or
904 * VNMP_CLAIM because if FIP state is not one of those,
905 * RPORT wouldn;t have created and 'rport_lookup' would have
906 * failed anyway in that case.
907 */
Hannes Reinecke4d2095c2016-09-30 11:01:14 +0200908 break;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700909 case RPORT_ST_DELETE:
910 mutex_unlock(&rdata->rp_mutex);
911 rjt_data.reason = ELS_RJT_FIP;
912 rjt_data.explan = ELS_EXPL_NOT_NEIGHBOR;
Hannes Reineckebaa67192016-05-24 08:11:58 +0200913 goto reject_put;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700914 case RPORT_ST_FLOGI:
915 case RPORT_ST_PLOGI_WAIT:
916 case RPORT_ST_PLOGI:
917 break;
918 case RPORT_ST_PRLI:
919 case RPORT_ST_RTV:
920 case RPORT_ST_READY:
921 case RPORT_ST_ADISC:
922 /*
923 * Set the remote port to be deleted and to then restart.
924 * This queues work to be sure exchanges are reset.
925 */
926 fc_rport_enter_delete(rdata, RPORT_EV_LOGO);
927 mutex_unlock(&rdata->rp_mutex);
928 rjt_data.reason = ELS_RJT_BUSY;
929 rjt_data.explan = ELS_EXPL_NONE;
Hannes Reineckebaa67192016-05-24 08:11:58 +0200930 goto reject_put;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700931 }
932 if (fc_rport_login_complete(rdata, fp)) {
933 mutex_unlock(&rdata->rp_mutex);
934 rjt_data.reason = ELS_RJT_LOGIC;
935 rjt_data.explan = ELS_EXPL_NONE;
Hannes Reineckebaa67192016-05-24 08:11:58 +0200936 goto reject_put;
Joe Eykholta7b12a22010-07-20 15:20:08 -0700937 }
Joe Eykholta7b12a22010-07-20 15:20:08 -0700938
939 fp = fc_frame_alloc(lport, sizeof(*flp));
940 if (!fp)
941 goto out;
942
Joe Eykholta7b12a22010-07-20 15:20:08 -0700943 fc_flogi_fill(lport, fp);
944 flp = fc_frame_payload_get(fp, sizeof(*flp));
945 flp->fl_cmd = ELS_LS_ACC;
946
Joe Eykholt24f089e2010-07-20 15:21:01 -0700947 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
948 lport->tt.frame_send(lport, fp);
Joe Eykholta7b12a22010-07-20 15:20:08 -0700949
Hannes Reineckef89b8d62016-09-30 11:01:19 +0200950 /*
951 * Do not proceed with the state machine if our
952 * FLOGI has crossed with an FLOGI from the
953 * remote port; wait for the FLOGI response instead.
954 */
955 if (rdata->rp_state != RPORT_ST_FLOGI) {
956 if (rdata->ids.port_name < lport->wwpn)
957 fc_rport_enter_plogi(rdata);
958 else
959 fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
960 }
Joe Eykholta7b12a22010-07-20 15:20:08 -0700961out:
962 mutex_unlock(&rdata->rp_mutex);
Hannes Reineckebaa67192016-05-24 08:11:58 +0200963 kref_put(&rdata->kref, lport->tt.rport_destroy);
Joe Eykholt24f089e2010-07-20 15:21:01 -0700964 fc_frame_free(rx_fp);
Joe Eykholta7b12a22010-07-20 15:20:08 -0700965 return;
966
Hannes Reineckebaa67192016-05-24 08:11:58 +0200967reject_put:
968 kref_put(&rdata->kref, lport->tt.rport_destroy);
Joe Eykholta7b12a22010-07-20 15:20:08 -0700969reject:
Hannes Reinecke7ab24dd2016-10-18 10:01:35 +0200970 fc_seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
Joe Eykholt24f089e2010-07-20 15:21:01 -0700971 fc_frame_free(rx_fp);
Joe Eykholta7b12a22010-07-20 15:20:08 -0700972}
973
974/**
975 * fc_rport_plogi_resp() - Handler for ELS PLOGI responses
Robert Love3a3b42b2009-11-03 11:47:39 -0800976 * @sp: The sequence the PLOGI is on
977 * @fp: The PLOGI response frame
978 * @rdata_arg: The remote port that sent the PLOGI response
Robert Love42e9a922008-12-09 15:10:17 -0800979 *
980 * Locking Note: This function will be called without the rport lock
981 * held, but it will lock, call an _enter_* function or fc_rport_error
982 * and then unlock the rport.
983 */
984static void fc_rport_plogi_resp(struct fc_seq *sp, struct fc_frame *fp,
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700985 void *rdata_arg)
Robert Love42e9a922008-12-09 15:10:17 -0800986{
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700987 struct fc_rport_priv *rdata = rdata_arg;
Robert Love42e9a922008-12-09 15:10:17 -0800988 struct fc_lport *lport = rdata->local_port;
Robert Lovea29e7642009-04-21 16:27:41 -0700989 struct fc_els_flogi *plp = NULL;
Robert Love42e9a922008-12-09 15:10:17 -0800990 u16 csp_seq;
991 u16 cssp_seq;
992 u8 op;
993
Joe Eykholtf657d292009-08-25 14:03:21 -0700994 FC_RPORT_DBG(rdata, "Received a PLOGI %s\n", fc_els_resp_type(fp));
Robert Love42e9a922008-12-09 15:10:17 -0800995
Chad Dupuis785141c2016-09-30 11:01:16 +0200996 if (fp == ERR_PTR(-FC_EX_CLOSED))
997 goto put;
998
999 mutex_lock(&rdata->rp_mutex);
1000
Robert Love42e9a922008-12-09 15:10:17 -08001001 if (rdata->rp_state != RPORT_ST_PLOGI) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001002 FC_RPORT_DBG(rdata, "Received a PLOGI response, but in state "
1003 "%s\n", fc_rport_state(rdata));
Abhijeet Joglekar76f68042009-04-21 16:26:58 -07001004 if (IS_ERR(fp))
1005 goto err;
Robert Love42e9a922008-12-09 15:10:17 -08001006 goto out;
1007 }
1008
Abhijeet Joglekar76f68042009-04-21 16:26:58 -07001009 if (IS_ERR(fp)) {
Hannes Reinecke9f9504a2016-10-13 15:10:44 +02001010 fc_rport_error_retry(rdata, PTR_ERR(fp));
Abhijeet Joglekar76f68042009-04-21 16:26:58 -07001011 goto err;
1012 }
1013
Robert Love42e9a922008-12-09 15:10:17 -08001014 op = fc_frame_payload_op(fp);
1015 if (op == ELS_LS_ACC &&
1016 (plp = fc_frame_payload_get(fp, sizeof(*plp))) != NULL) {
Joe Eykholtf211fa52009-08-25 14:01:01 -07001017 rdata->ids.port_name = get_unaligned_be64(&plp->fl_wwpn);
1018 rdata->ids.node_name = get_unaligned_be64(&plp->fl_wwnn);
Robert Love42e9a922008-12-09 15:10:17 -08001019
Bhanu Prakash Gollapudi75a27922011-01-28 16:05:27 -08001020 /* save plogi response sp_features for further reference */
1021 rdata->sp_features = ntohs(plp->fl_csp.sp_features);
1022
Joe Eykholta7b12a22010-07-20 15:20:08 -07001023 if (lport->point_to_multipoint)
1024 fc_rport_login_complete(rdata, fp);
Robert Love42e9a922008-12-09 15:10:17 -08001025 csp_seq = ntohs(plp->fl_csp.sp_tot_seq);
1026 cssp_seq = ntohs(plp->fl_cssp[3 - 1].cp_con_seq);
1027 if (cssp_seq < csp_seq)
1028 csp_seq = cssp_seq;
1029 rdata->max_seq = csp_seq;
Joe Eykholtf211fa52009-08-25 14:01:01 -07001030 rdata->maxframe_size = fc_plogi_get_maxframe(plp, lport->mfs);
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001031 fc_rport_enter_prli(rdata);
Hannes Reinecke9f9504a2016-10-13 15:10:44 +02001032 } else {
1033 struct fc_els_ls_rjt *rjt;
Robert Love42e9a922008-12-09 15:10:17 -08001034
Hannes Reinecke9f9504a2016-10-13 15:10:44 +02001035 rjt = fc_frame_payload_get(fp, sizeof(*rjt));
1036 FC_RPORT_DBG(rdata, "PLOGI ELS rejected, reason %x expl %x\n",
1037 rjt->er_reason, rjt->er_explan);
1038 fc_rport_error_retry(rdata, -FC_EX_ELS_RJT);
1039 }
Robert Love42e9a922008-12-09 15:10:17 -08001040out:
1041 fc_frame_free(fp);
1042err:
1043 mutex_unlock(&rdata->rp_mutex);
Chad Dupuis785141c2016-09-30 11:01:16 +02001044put:
Hannes Reineckebaa67192016-05-24 08:11:58 +02001045 kref_put(&rdata->kref, lport->tt.rport_destroy);
Robert Love42e9a922008-12-09 15:10:17 -08001046}
1047
Mark Rustade0335f62013-05-18 04:01:36 +00001048static bool
1049fc_rport_compatible_roles(struct fc_lport *lport, struct fc_rport_priv *rdata)
1050{
1051 if (rdata->ids.roles == FC_PORT_ROLE_UNKNOWN)
1052 return true;
1053 if ((rdata->ids.roles & FC_PORT_ROLE_FCP_TARGET) &&
1054 (lport->service_params & FCP_SPPF_INIT_FCN))
1055 return true;
1056 if ((rdata->ids.roles & FC_PORT_ROLE_FCP_INITIATOR) &&
1057 (lport->service_params & FCP_SPPF_TARG_FCN))
1058 return true;
1059 return false;
1060}
1061
Robert Love42e9a922008-12-09 15:10:17 -08001062/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001063 * fc_rport_enter_plogi() - Send Port Login (PLOGI) request
1064 * @rdata: The remote port to send a PLOGI to
Robert Love42e9a922008-12-09 15:10:17 -08001065 *
1066 * Locking Note: The rport lock is expected to be held before calling
1067 * this routine.
Hannes Reinecke4d2095c2016-09-30 11:01:14 +02001068 *
1069 * Reference counting: increments kref when sending ELS
Robert Love42e9a922008-12-09 15:10:17 -08001070 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001071static void fc_rport_enter_plogi(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -08001072{
Robert Love42e9a922008-12-09 15:10:17 -08001073 struct fc_lport *lport = rdata->local_port;
1074 struct fc_frame *fp;
1075
Mark Rustade0335f62013-05-18 04:01:36 +00001076 if (!fc_rport_compatible_roles(lport, rdata)) {
1077 FC_RPORT_DBG(rdata, "PLOGI suppressed for incompatible role\n");
1078 fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
1079 return;
1080 }
1081
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001082 FC_RPORT_DBG(rdata, "Port entered PLOGI state from %s state\n",
1083 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -08001084
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001085 fc_rport_state_enter(rdata, RPORT_ST_PLOGI);
Robert Love42e9a922008-12-09 15:10:17 -08001086
Joe Eykholtf211fa52009-08-25 14:01:01 -07001087 rdata->maxframe_size = FC_MIN_MAX_PAYLOAD;
Robert Love42e9a922008-12-09 15:10:17 -08001088 fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi));
1089 if (!fp) {
Joe Eykholta7b12a22010-07-20 15:20:08 -07001090 FC_RPORT_DBG(rdata, "%s frame alloc failed\n", __func__);
Hannes Reinecke9f9504a2016-10-13 15:10:44 +02001091 fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
Robert Love42e9a922008-12-09 15:10:17 -08001092 return;
1093 }
1094 rdata->e_d_tov = lport->e_d_tov;
1095
Hannes Reinecke4d2095c2016-09-30 11:01:14 +02001096 kref_get(&rdata->kref);
Joe Eykholtf211fa52009-08-25 14:01:01 -07001097 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_PLOGI,
Joe Eykholtb94f8952009-11-03 11:50:21 -08001098 fc_rport_plogi_resp, rdata,
Hannes Reinecke4d2095c2016-09-30 11:01:14 +02001099 2 * lport->r_a_tov)) {
Hannes Reinecke9f9504a2016-10-13 15:10:44 +02001100 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
Hannes Reinecke4d2095c2016-09-30 11:01:14 +02001101 kref_put(&rdata->kref, lport->tt.rport_destroy);
1102 }
Robert Love42e9a922008-12-09 15:10:17 -08001103}
1104
1105/**
Robert Love34f42a02009-02-27 10:55:45 -08001106 * fc_rport_prli_resp() - Process Login (PRLI) response handler
Robert Love3a3b42b2009-11-03 11:47:39 -08001107 * @sp: The sequence the PRLI response was on
1108 * @fp: The PRLI response frame
1109 * @rdata_arg: The remote port that sent the PRLI response
Robert Love42e9a922008-12-09 15:10:17 -08001110 *
1111 * Locking Note: This function will be called without the rport lock
1112 * held, but it will lock, call an _enter_* function or fc_rport_error
1113 * and then unlock the rport.
1114 */
1115static void fc_rport_prli_resp(struct fc_seq *sp, struct fc_frame *fp,
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001116 void *rdata_arg)
Robert Love42e9a922008-12-09 15:10:17 -08001117{
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001118 struct fc_rport_priv *rdata = rdata_arg;
Robert Love42e9a922008-12-09 15:10:17 -08001119 struct {
1120 struct fc_els_prli prli;
1121 struct fc_els_spp spp;
1122 } *pp;
Joe Eykholt925ceda2011-01-28 16:04:23 -08001123 struct fc_els_spp temp_spp;
Hannes Reinecke57d3ec7e2016-10-13 15:10:37 +02001124 struct fc_els_ls_rjt *rjt;
Joe Eykholt925ceda2011-01-28 16:04:23 -08001125 struct fc4_prov *prov;
Robert Love42e9a922008-12-09 15:10:17 -08001126 u32 roles = FC_RPORT_ROLE_UNKNOWN;
1127 u32 fcp_parm = 0;
1128 u8 op;
Hannes Reinecke386b97b2016-10-13 15:10:46 +02001129 enum fc_els_spp_resp resp_code;
Robert Love42e9a922008-12-09 15:10:17 -08001130
Joe Eykholtf657d292009-08-25 14:03:21 -07001131 FC_RPORT_DBG(rdata, "Received a PRLI %s\n", fc_els_resp_type(fp));
Robert Love42e9a922008-12-09 15:10:17 -08001132
Chad Dupuis785141c2016-09-30 11:01:16 +02001133 if (fp == ERR_PTR(-FC_EX_CLOSED))
1134 goto put;
1135
1136 mutex_lock(&rdata->rp_mutex);
1137
Robert Love42e9a922008-12-09 15:10:17 -08001138 if (rdata->rp_state != RPORT_ST_PRLI) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001139 FC_RPORT_DBG(rdata, "Received a PRLI response, but in state "
1140 "%s\n", fc_rport_state(rdata));
Abhijeet Joglekar76f68042009-04-21 16:26:58 -07001141 if (IS_ERR(fp))
1142 goto err;
Robert Love42e9a922008-12-09 15:10:17 -08001143 goto out;
1144 }
1145
Abhijeet Joglekar76f68042009-04-21 16:26:58 -07001146 if (IS_ERR(fp)) {
Hannes Reinecke9f9504a2016-10-13 15:10:44 +02001147 fc_rport_error_retry(rdata, PTR_ERR(fp));
Abhijeet Joglekar76f68042009-04-21 16:26:58 -07001148 goto err;
1149 }
1150
Robert Love6bd054c2009-08-25 14:03:04 -07001151 /* reinitialize remote port roles */
1152 rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
1153
Robert Love42e9a922008-12-09 15:10:17 -08001154 op = fc_frame_payload_op(fp);
1155 if (op == ELS_LS_ACC) {
1156 pp = fc_frame_payload_get(fp, sizeof(*pp));
Bhanu Prakash Gollapudi618461c2010-06-11 16:43:54 -07001157 if (!pp)
1158 goto out;
1159
1160 resp_code = (pp->spp.spp_flags & FC_SPP_RESP_MASK);
Hannes Reinecke386b97b2016-10-13 15:10:46 +02001161 FC_RPORT_DBG(rdata, "PRLI spp_flags = 0x%x spp_type 0x%x\n",
1162 pp->spp.spp_flags, pp->spp.spp_type);
Bhanu Prakash Gollapudi75a27922011-01-28 16:05:27 -08001163 rdata->spp_type = pp->spp.spp_type;
Bhanu Prakash Gollapudi618461c2010-06-11 16:43:54 -07001164 if (resp_code != FC_SPP_RESP_ACK) {
1165 if (resp_code == FC_SPP_RESP_CONF)
Hannes Reinecke9f9504a2016-10-13 15:10:44 +02001166 fc_rport_error(rdata, -FC_EX_SEQ_ERR);
Bhanu Prakash Gollapudi618461c2010-06-11 16:43:54 -07001167 else
Hannes Reinecke9f9504a2016-10-13 15:10:44 +02001168 fc_rport_error_retry(rdata, -FC_EX_SEQ_ERR);
Bhanu Prakash Gollapudi618461c2010-06-11 16:43:54 -07001169 goto out;
Robert Love42e9a922008-12-09 15:10:17 -08001170 }
Bhanu Prakash Gollapudi618461c2010-06-11 16:43:54 -07001171 if (pp->prli.prli_spp_len < sizeof(pp->spp))
1172 goto out;
1173
1174 fcp_parm = ntohl(pp->spp.spp_params);
1175 if (fcp_parm & FCP_SPPF_RETRY)
1176 rdata->flags |= FC_RP_FLAGS_RETRY;
Bhanu Prakash Gollapudi75a27922011-01-28 16:05:27 -08001177 if (fcp_parm & FCP_SPPF_CONF_COMPL)
1178 rdata->flags |= FC_RP_FLAGS_CONF_REQ;
Robert Love42e9a922008-12-09 15:10:17 -08001179
Hannes Reinecke386b97b2016-10-13 15:10:46 +02001180 /*
1181 * Call prli provider if we should act as a target
1182 */
1183 prov = fc_passive_prov[rdata->spp_type];
Joe Eykholt925ceda2011-01-28 16:04:23 -08001184 if (prov) {
1185 memset(&temp_spp, 0, sizeof(temp_spp));
1186 prov->prli(rdata, pp->prli.prli_spp_len,
1187 &pp->spp, &temp_spp);
1188 }
Hannes Reinecke386b97b2016-10-13 15:10:46 +02001189 /*
1190 * Check if the image pair could be established
1191 */
1192 if (rdata->spp_type != FC_TYPE_FCP ||
1193 resp_code != FC_SPP_RESP_ACK ||
1194 !(pp->spp.spp_flags & FC_SPP_EST_IMG_PAIR)) {
1195 /*
1196 * Nope; we can't use this port as a target.
1197 */
1198 fcp_parm &= ~FCP_SPPF_TARG_FCN;
1199 }
Joe Eykholtf211fa52009-08-25 14:01:01 -07001200 rdata->supported_classes = FC_COS_CLASS3;
Robert Love42e9a922008-12-09 15:10:17 -08001201 if (fcp_parm & FCP_SPPF_INIT_FCN)
1202 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1203 if (fcp_parm & FCP_SPPF_TARG_FCN)
1204 roles |= FC_RPORT_ROLE_FCP_TARGET;
1205
Joe Eykholtf211fa52009-08-25 14:01:01 -07001206 rdata->ids.roles = roles;
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001207 fc_rport_enter_rtv(rdata);
Robert Love42e9a922008-12-09 15:10:17 -08001208
1209 } else {
Hannes Reinecke57d3ec7e2016-10-13 15:10:37 +02001210 rjt = fc_frame_payload_get(fp, sizeof(*rjt));
1211 FC_RPORT_DBG(rdata, "PRLI ELS rejected, reason %x expl %x\n",
1212 rjt->er_reason, rjt->er_explan);
Hannes Reinecke9f9504a2016-10-13 15:10:44 +02001213 fc_rport_error_retry(rdata, FC_EX_ELS_RJT);
Robert Love42e9a922008-12-09 15:10:17 -08001214 }
1215
1216out:
1217 fc_frame_free(fp);
1218err:
1219 mutex_unlock(&rdata->rp_mutex);
Chad Dupuis785141c2016-09-30 11:01:16 +02001220put:
Joe Eykholtf211fa52009-08-25 14:01:01 -07001221 kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
Robert Love42e9a922008-12-09 15:10:17 -08001222}
1223
1224/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001225 * fc_rport_enter_prli() - Send Process Login (PRLI) request
1226 * @rdata: The remote port to send the PRLI request to
Robert Love42e9a922008-12-09 15:10:17 -08001227 *
1228 * Locking Note: The rport lock is expected to be held before calling
1229 * this routine.
Hannes Reinecke4d2095c2016-09-30 11:01:14 +02001230 *
1231 * Reference counting: increments kref when sending ELS
Robert Love42e9a922008-12-09 15:10:17 -08001232 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001233static void fc_rport_enter_prli(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -08001234{
Robert Love42e9a922008-12-09 15:10:17 -08001235 struct fc_lport *lport = rdata->local_port;
1236 struct {
1237 struct fc_els_prli prli;
1238 struct fc_els_spp spp;
1239 } *pp;
1240 struct fc_frame *fp;
Joe Eykholt925ceda2011-01-28 16:04:23 -08001241 struct fc4_prov *prov;
Robert Love42e9a922008-12-09 15:10:17 -08001242
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001243 /*
1244 * If the rport is one of the well known addresses
1245 * we skip PRLI and RTV and go straight to READY.
1246 */
1247 if (rdata->ids.port_id >= FC_FID_DOM_MGR) {
1248 fc_rport_enter_ready(rdata);
1249 return;
1250 }
1251
Hannes Reinecke386b97b2016-10-13 15:10:46 +02001252 /*
1253 * And if the local port does not support the initiator function
1254 * there's no need to send a PRLI, either.
1255 */
1256 if (!(lport->service_params & FCP_SPPF_INIT_FCN)) {
1257 fc_rport_enter_ready(rdata);
1258 return;
1259 }
1260
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001261 FC_RPORT_DBG(rdata, "Port entered PRLI state from %s state\n",
1262 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -08001263
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001264 fc_rport_state_enter(rdata, RPORT_ST_PRLI);
Robert Love42e9a922008-12-09 15:10:17 -08001265
1266 fp = fc_frame_alloc(lport, sizeof(*pp));
1267 if (!fp) {
Hannes Reinecke9f9504a2016-10-13 15:10:44 +02001268 fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
Robert Love42e9a922008-12-09 15:10:17 -08001269 return;
1270 }
1271
Joe Eykholt925ceda2011-01-28 16:04:23 -08001272 fc_prli_fill(lport, fp);
1273
1274 prov = fc_passive_prov[FC_TYPE_FCP];
1275 if (prov) {
1276 pp = fc_frame_payload_get(fp, sizeof(*pp));
1277 prov->prli(rdata, sizeof(pp->spp), NULL, &pp->spp);
1278 }
1279
1280 fc_fill_fc_hdr(fp, FC_RCTL_ELS_REQ, rdata->ids.port_id,
1281 fc_host_port_id(lport->host), FC_TYPE_ELS,
1282 FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0);
1283
Hannes Reinecke4d2095c2016-09-30 11:01:14 +02001284 kref_get(&rdata->kref);
Hannes Reinecke3afd2d12016-10-18 10:01:38 +02001285 if (!fc_exch_seq_send(lport, fp, fc_rport_prli_resp,
1286 NULL, rdata, 2 * lport->r_a_tov)) {
Hannes Reinecke9f9504a2016-10-13 15:10:44 +02001287 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
Hannes Reinecke4d2095c2016-09-30 11:01:14 +02001288 kref_put(&rdata->kref, lport->tt.rport_destroy);
1289 }
Robert Love42e9a922008-12-09 15:10:17 -08001290}
1291
1292/**
Hannes Reinecke7c5a51b2016-10-13 15:10:45 +02001293 * fc_rport_rtv_resp() - Handler for Request Timeout Value (RTV) responses
Robert Love3a3b42b2009-11-03 11:47:39 -08001294 * @sp: The sequence the RTV was on
1295 * @fp: The RTV response frame
1296 * @rdata_arg: The remote port that sent the RTV response
Robert Love42e9a922008-12-09 15:10:17 -08001297 *
1298 * Many targets don't seem to support this.
1299 *
1300 * Locking Note: This function will be called without the rport lock
1301 * held, but it will lock, call an _enter_* function or fc_rport_error
1302 * and then unlock the rport.
1303 */
1304static void fc_rport_rtv_resp(struct fc_seq *sp, struct fc_frame *fp,
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001305 void *rdata_arg)
Robert Love42e9a922008-12-09 15:10:17 -08001306{
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001307 struct fc_rport_priv *rdata = rdata_arg;
Robert Love42e9a922008-12-09 15:10:17 -08001308 u8 op;
1309
Joe Eykholtf657d292009-08-25 14:03:21 -07001310 FC_RPORT_DBG(rdata, "Received a RTV %s\n", fc_els_resp_type(fp));
Robert Love42e9a922008-12-09 15:10:17 -08001311
Chad Dupuis785141c2016-09-30 11:01:16 +02001312 if (fp == ERR_PTR(-FC_EX_CLOSED))
1313 goto put;
1314
1315 mutex_lock(&rdata->rp_mutex);
1316
Robert Love42e9a922008-12-09 15:10:17 -08001317 if (rdata->rp_state != RPORT_ST_RTV) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001318 FC_RPORT_DBG(rdata, "Received a RTV response, but in state "
1319 "%s\n", fc_rport_state(rdata));
Abhijeet Joglekar76f68042009-04-21 16:26:58 -07001320 if (IS_ERR(fp))
1321 goto err;
Robert Love42e9a922008-12-09 15:10:17 -08001322 goto out;
1323 }
1324
Abhijeet Joglekar76f68042009-04-21 16:26:58 -07001325 if (IS_ERR(fp)) {
Hannes Reinecke9f9504a2016-10-13 15:10:44 +02001326 fc_rport_error(rdata, PTR_ERR(fp));
Abhijeet Joglekar76f68042009-04-21 16:26:58 -07001327 goto err;
1328 }
1329
Robert Love42e9a922008-12-09 15:10:17 -08001330 op = fc_frame_payload_op(fp);
1331 if (op == ELS_LS_ACC) {
1332 struct fc_els_rtv_acc *rtv;
1333 u32 toq;
1334 u32 tov;
1335
1336 rtv = fc_frame_payload_get(fp, sizeof(*rtv));
1337 if (rtv) {
1338 toq = ntohl(rtv->rtv_toq);
1339 tov = ntohl(rtv->rtv_r_a_tov);
1340 if (tov == 0)
1341 tov = 1;
Hannes Reinecke76e72ad2016-10-13 15:10:41 +02001342 if (tov > rdata->r_a_tov)
1343 rdata->r_a_tov = tov;
Robert Love42e9a922008-12-09 15:10:17 -08001344 tov = ntohl(rtv->rtv_e_d_tov);
1345 if (toq & FC_ELS_RTV_EDRES)
1346 tov /= 1000000;
1347 if (tov == 0)
1348 tov = 1;
Hannes Reinecke76e72ad2016-10-13 15:10:41 +02001349 if (tov > rdata->e_d_tov)
1350 rdata->e_d_tov = tov;
Robert Love42e9a922008-12-09 15:10:17 -08001351 }
1352 }
1353
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001354 fc_rport_enter_ready(rdata);
Robert Love42e9a922008-12-09 15:10:17 -08001355
1356out:
1357 fc_frame_free(fp);
1358err:
1359 mutex_unlock(&rdata->rp_mutex);
Chad Dupuis785141c2016-09-30 11:01:16 +02001360put:
Joe Eykholtf211fa52009-08-25 14:01:01 -07001361 kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
Robert Love42e9a922008-12-09 15:10:17 -08001362}
1363
1364/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001365 * fc_rport_enter_rtv() - Send Request Timeout Value (RTV) request
1366 * @rdata: The remote port to send the RTV request to
Robert Love42e9a922008-12-09 15:10:17 -08001367 *
1368 * Locking Note: The rport lock is expected to be held before calling
1369 * this routine.
Hannes Reinecke4d2095c2016-09-30 11:01:14 +02001370 *
1371 * Reference counting: increments kref when sending ELS
Robert Love42e9a922008-12-09 15:10:17 -08001372 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001373static void fc_rport_enter_rtv(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -08001374{
1375 struct fc_frame *fp;
Robert Love42e9a922008-12-09 15:10:17 -08001376 struct fc_lport *lport = rdata->local_port;
1377
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001378 FC_RPORT_DBG(rdata, "Port entered RTV state from %s state\n",
1379 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -08001380
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001381 fc_rport_state_enter(rdata, RPORT_ST_RTV);
Robert Love42e9a922008-12-09 15:10:17 -08001382
1383 fp = fc_frame_alloc(lport, sizeof(struct fc_els_rtv));
1384 if (!fp) {
Hannes Reinecke9f9504a2016-10-13 15:10:44 +02001385 fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
Robert Love42e9a922008-12-09 15:10:17 -08001386 return;
1387 }
1388
Hannes Reinecke4d2095c2016-09-30 11:01:14 +02001389 kref_get(&rdata->kref);
Joe Eykholtf211fa52009-08-25 14:01:01 -07001390 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_RTV,
Joe Eykholtb94f8952009-11-03 11:50:21 -08001391 fc_rport_rtv_resp, rdata,
Hannes Reinecke4d2095c2016-09-30 11:01:14 +02001392 2 * lport->r_a_tov)) {
Hannes Reinecke9f9504a2016-10-13 15:10:44 +02001393 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
Hannes Reinecke4d2095c2016-09-30 11:01:14 +02001394 kref_put(&rdata->kref, lport->tt.rport_destroy);
1395 }
Robert Love42e9a922008-12-09 15:10:17 -08001396}
1397
1398/**
Hannes Reinecke7c5a51b2016-10-13 15:10:45 +02001399 * fc_rport_recv_rtv_req() - Handler for Read Timeout Value (RTV) requests
1400 * @rdata: The remote port that sent the RTV request
1401 * @in_fp: The RTV request frame
1402 *
1403 * Locking Note: Called with the lport and rport locks held.
1404 */
1405static void fc_rport_recv_rtv_req(struct fc_rport_priv *rdata,
1406 struct fc_frame *in_fp)
1407{
1408 struct fc_lport *lport = rdata->local_port;
1409 struct fc_frame *fp;
1410 struct fc_els_rtv_acc *rtv;
1411 struct fc_seq_els_data rjt_data;
1412
1413 FC_RPORT_DBG(rdata, "Received RTV request\n");
1414
1415 fp = fc_frame_alloc(lport, sizeof(*rtv));
1416 if (!fp) {
1417 rjt_data.reason = ELS_RJT_UNAB;
1418 rjt_data.reason = ELS_EXPL_INSUF_RES;
Hannes Reinecke7ab24dd2016-10-18 10:01:35 +02001419 fc_seq_els_rsp_send(in_fp, ELS_LS_RJT, &rjt_data);
Hannes Reinecke7c5a51b2016-10-13 15:10:45 +02001420 goto drop;
1421 }
1422 rtv = fc_frame_payload_get(fp, sizeof(*rtv));
1423 rtv->rtv_cmd = ELS_LS_ACC;
1424 rtv->rtv_r_a_tov = htonl(lport->r_a_tov);
1425 rtv->rtv_e_d_tov = htonl(lport->e_d_tov);
1426 rtv->rtv_toq = 0;
1427 fc_fill_reply_hdr(fp, in_fp, FC_RCTL_ELS_REP, 0);
1428 lport->tt.frame_send(lport, fp);
1429drop:
1430 fc_frame_free(in_fp);
1431}
1432
1433/**
Joe Eykholt079ecd82010-07-20 15:20:51 -07001434 * fc_rport_logo_resp() - Handler for logout (LOGO) responses
1435 * @sp: The sequence the LOGO was on
1436 * @fp: The LOGO response frame
1437 * @lport_arg: The local port
1438 */
1439static void fc_rport_logo_resp(struct fc_seq *sp, struct fc_frame *fp,
Hannes Reinecke4d2095c2016-09-30 11:01:14 +02001440 void *rdata_arg)
Joe Eykholt079ecd82010-07-20 15:20:51 -07001441{
Hannes Reinecke4d2095c2016-09-30 11:01:14 +02001442 struct fc_rport_priv *rdata = rdata_arg;
1443 struct fc_lport *lport = rdata->local_port;
Joe Eykholt079ecd82010-07-20 15:20:51 -07001444
1445 FC_RPORT_ID_DBG(lport, fc_seq_exch(sp)->did,
1446 "Received a LOGO %s\n", fc_els_resp_type(fp));
Hannes Reinecke4d2095c2016-09-30 11:01:14 +02001447 if (!IS_ERR(fp))
1448 fc_frame_free(fp);
1449 kref_put(&rdata->kref, lport->tt.rport_destroy);
Joe Eykholt079ecd82010-07-20 15:20:51 -07001450}
1451
1452/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001453 * fc_rport_enter_logo() - Send a logout (LOGO) request
1454 * @rdata: The remote port to send the LOGO request to
Robert Love42e9a922008-12-09 15:10:17 -08001455 *
1456 * Locking Note: The rport lock is expected to be held before calling
1457 * this routine.
Hannes Reinecke4d2095c2016-09-30 11:01:14 +02001458 *
1459 * Reference counting: increments kref when sending ELS
Robert Love42e9a922008-12-09 15:10:17 -08001460 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001461static void fc_rport_enter_logo(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -08001462{
Robert Love42e9a922008-12-09 15:10:17 -08001463 struct fc_lport *lport = rdata->local_port;
1464 struct fc_frame *fp;
1465
Joe Eykholt079ecd82010-07-20 15:20:51 -07001466 FC_RPORT_DBG(rdata, "Port sending LOGO from %s state\n",
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001467 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -08001468
Robert Love42e9a922008-12-09 15:10:17 -08001469 fp = fc_frame_alloc(lport, sizeof(struct fc_els_logo));
Joe Eykholt079ecd82010-07-20 15:20:51 -07001470 if (!fp)
Robert Love42e9a922008-12-09 15:10:17 -08001471 return;
Hannes Reinecke4d2095c2016-09-30 11:01:14 +02001472 kref_get(&rdata->kref);
1473 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_LOGO,
1474 fc_rport_logo_resp, rdata, 0))
1475 kref_put(&rdata->kref, lport->tt.rport_destroy);
Robert Love42e9a922008-12-09 15:10:17 -08001476}
1477
Robert Love42e9a922008-12-09 15:10:17 -08001478/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001479 * fc_rport_els_adisc_resp() - Handler for Address Discovery (ADISC) responses
1480 * @sp: The sequence the ADISC response was on
1481 * @fp: The ADISC response frame
1482 * @rdata_arg: The remote port that sent the ADISC response
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001483 *
1484 * Locking Note: This function will be called without the rport lock
1485 * held, but it will lock, call an _enter_* function or fc_rport_error
1486 * and then unlock the rport.
1487 */
1488static void fc_rport_adisc_resp(struct fc_seq *sp, struct fc_frame *fp,
Robert Love3a3b42b2009-11-03 11:47:39 -08001489 void *rdata_arg)
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001490{
1491 struct fc_rport_priv *rdata = rdata_arg;
1492 struct fc_els_adisc *adisc;
1493 u8 op;
1494
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001495 FC_RPORT_DBG(rdata, "Received a ADISC response\n");
1496
Chad Dupuis785141c2016-09-30 11:01:16 +02001497 if (fp == ERR_PTR(-FC_EX_CLOSED))
1498 goto put;
1499
1500 mutex_lock(&rdata->rp_mutex);
1501
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001502 if (rdata->rp_state != RPORT_ST_ADISC) {
1503 FC_RPORT_DBG(rdata, "Received a ADISC resp but in state %s\n",
1504 fc_rport_state(rdata));
1505 if (IS_ERR(fp))
1506 goto err;
1507 goto out;
1508 }
1509
1510 if (IS_ERR(fp)) {
Hannes Reinecke9f9504a2016-10-13 15:10:44 +02001511 fc_rport_error(rdata, PTR_ERR(fp));
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001512 goto err;
1513 }
1514
1515 /*
1516 * If address verification failed. Consider us logged out of the rport.
1517 * Since the rport is still in discovery, we want to be
1518 * logged in, so go to PLOGI state. Otherwise, go back to READY.
1519 */
1520 op = fc_frame_payload_op(fp);
1521 adisc = fc_frame_payload_get(fp, sizeof(*adisc));
1522 if (op != ELS_LS_ACC || !adisc ||
1523 ntoh24(adisc->adisc_port_id) != rdata->ids.port_id ||
1524 get_unaligned_be64(&adisc->adisc_wwpn) != rdata->ids.port_name ||
1525 get_unaligned_be64(&adisc->adisc_wwnn) != rdata->ids.node_name) {
1526 FC_RPORT_DBG(rdata, "ADISC error or mismatch\n");
Joe Eykholta7b12a22010-07-20 15:20:08 -07001527 fc_rport_enter_flogi(rdata);
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001528 } else {
1529 FC_RPORT_DBG(rdata, "ADISC OK\n");
1530 fc_rport_enter_ready(rdata);
1531 }
1532out:
1533 fc_frame_free(fp);
1534err:
1535 mutex_unlock(&rdata->rp_mutex);
Chad Dupuis785141c2016-09-30 11:01:16 +02001536put:
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001537 kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
1538}
1539
1540/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001541 * fc_rport_enter_adisc() - Send Address Discover (ADISC) request
1542 * @rdata: The remote port to send the ADISC request to
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001543 *
1544 * Locking Note: The rport lock is expected to be held before calling
1545 * this routine.
Hannes Reinecke4d2095c2016-09-30 11:01:14 +02001546 *
1547 * Reference counting: increments kref when sending ELS
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001548 */
1549static void fc_rport_enter_adisc(struct fc_rport_priv *rdata)
1550{
1551 struct fc_lport *lport = rdata->local_port;
1552 struct fc_frame *fp;
1553
1554 FC_RPORT_DBG(rdata, "sending ADISC from %s state\n",
1555 fc_rport_state(rdata));
1556
1557 fc_rport_state_enter(rdata, RPORT_ST_ADISC);
1558
1559 fp = fc_frame_alloc(lport, sizeof(struct fc_els_adisc));
1560 if (!fp) {
Hannes Reinecke9f9504a2016-10-13 15:10:44 +02001561 fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001562 return;
1563 }
Hannes Reinecke4d2095c2016-09-30 11:01:14 +02001564 kref_get(&rdata->kref);
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001565 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_ADISC,
Joe Eykholtb94f8952009-11-03 11:50:21 -08001566 fc_rport_adisc_resp, rdata,
Hannes Reinecke4d2095c2016-09-30 11:01:14 +02001567 2 * lport->r_a_tov)) {
Hannes Reinecke9f9504a2016-10-13 15:10:44 +02001568 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
Hannes Reinecke4d2095c2016-09-30 11:01:14 +02001569 kref_put(&rdata->kref, lport->tt.rport_destroy);
1570 }
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001571}
1572
1573/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001574 * fc_rport_recv_adisc_req() - Handler for Address Discovery (ADISC) requests
1575 * @rdata: The remote port that sent the ADISC request
Robert Love3a3b42b2009-11-03 11:47:39 -08001576 * @in_fp: The ADISC request frame
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001577 *
1578 * Locking Note: Called with the lport and rport locks held.
1579 */
1580static void fc_rport_recv_adisc_req(struct fc_rport_priv *rdata,
Joe Eykholt922611562010-07-20 15:21:12 -07001581 struct fc_frame *in_fp)
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001582{
1583 struct fc_lport *lport = rdata->local_port;
1584 struct fc_frame *fp;
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001585 struct fc_els_adisc *adisc;
1586 struct fc_seq_els_data rjt_data;
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001587
1588 FC_RPORT_DBG(rdata, "Received ADISC request\n");
1589
1590 adisc = fc_frame_payload_get(in_fp, sizeof(*adisc));
1591 if (!adisc) {
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001592 rjt_data.reason = ELS_RJT_PROT;
1593 rjt_data.explan = ELS_EXPL_INV_LEN;
Hannes Reinecke7ab24dd2016-10-18 10:01:35 +02001594 fc_seq_els_rsp_send(in_fp, ELS_LS_RJT, &rjt_data);
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001595 goto drop;
1596 }
1597
1598 fp = fc_frame_alloc(lport, sizeof(*adisc));
1599 if (!fp)
1600 goto drop;
1601 fc_adisc_fill(lport, fp);
1602 adisc = fc_frame_payload_get(fp, sizeof(*adisc));
1603 adisc->adisc_cmd = ELS_LS_ACC;
Joe Eykholt24f089e2010-07-20 15:21:01 -07001604 fc_fill_reply_hdr(fp, in_fp, FC_RCTL_ELS_REP, 0);
1605 lport->tt.frame_send(lport, fp);
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001606drop:
1607 fc_frame_free(in_fp);
1608}
1609
1610/**
Yi Zou63e27fb2009-11-20 14:55:24 -08001611 * fc_rport_recv_rls_req() - Handle received Read Link Status request
1612 * @rdata: The remote port that sent the RLS request
Yi Zou63e27fb2009-11-20 14:55:24 -08001613 * @rx_fp: The PRLI request frame
1614 *
1615 * Locking Note: The rport lock is expected to be held before calling
1616 * this function.
1617 */
1618static void fc_rport_recv_rls_req(struct fc_rport_priv *rdata,
Joe Eykholt922611562010-07-20 15:21:12 -07001619 struct fc_frame *rx_fp)
Yi Zou63e27fb2009-11-20 14:55:24 -08001620
1621{
1622 struct fc_lport *lport = rdata->local_port;
1623 struct fc_frame *fp;
Yi Zou63e27fb2009-11-20 14:55:24 -08001624 struct fc_els_rls *rls;
1625 struct fc_els_rls_resp *rsp;
1626 struct fc_els_lesb *lesb;
1627 struct fc_seq_els_data rjt_data;
1628 struct fc_host_statistics *hst;
Yi Zou63e27fb2009-11-20 14:55:24 -08001629
1630 FC_RPORT_DBG(rdata, "Received RLS request while in state %s\n",
1631 fc_rport_state(rdata));
1632
1633 rls = fc_frame_payload_get(rx_fp, sizeof(*rls));
1634 if (!rls) {
1635 rjt_data.reason = ELS_RJT_PROT;
1636 rjt_data.explan = ELS_EXPL_INV_LEN;
1637 goto out_rjt;
1638 }
1639
1640 fp = fc_frame_alloc(lport, sizeof(*rsp));
1641 if (!fp) {
1642 rjt_data.reason = ELS_RJT_UNAB;
1643 rjt_data.explan = ELS_EXPL_INSUF_RES;
1644 goto out_rjt;
1645 }
1646
1647 rsp = fc_frame_payload_get(fp, sizeof(*rsp));
1648 memset(rsp, 0, sizeof(*rsp));
1649 rsp->rls_cmd = ELS_LS_ACC;
1650 lesb = &rsp->rls_lesb;
1651 if (lport->tt.get_lesb) {
1652 /* get LESB from LLD if it supports it */
1653 lport->tt.get_lesb(lport, lesb);
1654 } else {
1655 fc_get_host_stats(lport->host);
1656 hst = &lport->host_stats;
1657 lesb->lesb_link_fail = htonl(hst->link_failure_count);
1658 lesb->lesb_sync_loss = htonl(hst->loss_of_sync_count);
1659 lesb->lesb_sig_loss = htonl(hst->loss_of_signal_count);
1660 lesb->lesb_prim_err = htonl(hst->prim_seq_protocol_err_count);
1661 lesb->lesb_inv_word = htonl(hst->invalid_tx_word_count);
1662 lesb->lesb_inv_crc = htonl(hst->invalid_crc_count);
1663 }
1664
Joe Eykholt24f089e2010-07-20 15:21:01 -07001665 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
1666 lport->tt.frame_send(lport, fp);
Yi Zou63e27fb2009-11-20 14:55:24 -08001667 goto out;
1668
1669out_rjt:
Hannes Reinecke7ab24dd2016-10-18 10:01:35 +02001670 fc_seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
Yi Zou63e27fb2009-11-20 14:55:24 -08001671out:
1672 fc_frame_free(rx_fp);
1673}
1674
1675/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001676 * fc_rport_recv_els_req() - Handler for validated ELS requests
1677 * @lport: The local port that received the ELS request
Robert Love3a3b42b2009-11-03 11:47:39 -08001678 * @fp: The ELS request frame
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001679 *
1680 * Handle incoming ELS requests that require port login.
1681 * The ELS opcode has already been validated by the caller.
Robert Love42e9a922008-12-09 15:10:17 -08001682 *
Joe Eykholt131203a2009-08-25 14:03:10 -07001683 * Locking Note: Called with the lport lock held.
Hannes Reinecke4d2095c2016-09-30 11:01:14 +02001684 *
1685 * Reference counting: does not modify kref
Robert Love42e9a922008-12-09 15:10:17 -08001686 */
Joe Eykholt922611562010-07-20 15:21:12 -07001687static void fc_rport_recv_els_req(struct fc_lport *lport, struct fc_frame *fp)
Robert Love42e9a922008-12-09 15:10:17 -08001688{
Joe Eykholt131203a2009-08-25 14:03:10 -07001689 struct fc_rport_priv *rdata;
Robert Love42e9a922008-12-09 15:10:17 -08001690 struct fc_seq_els_data els_data;
Robert Love42e9a922008-12-09 15:10:17 -08001691
Joe Eykholt251748a2010-07-20 15:20:56 -07001692 rdata = lport->tt.rport_lookup(lport, fc_frame_sid(fp));
Hannes Reinecke57d3ec7e2016-10-13 15:10:37 +02001693 if (!rdata) {
1694 FC_RPORT_ID_DBG(lport, fc_frame_sid(fp),
1695 "Received ELS 0x%02x from non-logged-in port\n",
1696 fc_frame_payload_op(fp));
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001697 goto reject;
Hannes Reinecke57d3ec7e2016-10-13 15:10:37 +02001698 }
Hannes Reineckebaa67192016-05-24 08:11:58 +02001699
Joe Eykholt131203a2009-08-25 14:03:10 -07001700 mutex_lock(&rdata->rp_mutex);
1701
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001702 switch (rdata->rp_state) {
1703 case RPORT_ST_PRLI:
1704 case RPORT_ST_RTV:
1705 case RPORT_ST_READY:
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001706 case RPORT_ST_ADISC:
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001707 break;
Hannes Reinecke8acf1b52016-10-13 15:10:47 +02001708 case RPORT_ST_PLOGI:
1709 if (fc_frame_payload_op(fp) == ELS_PRLI) {
1710 FC_RPORT_DBG(rdata, "Reject ELS PRLI "
1711 "while in state %s\n",
1712 fc_rport_state(rdata));
1713 mutex_unlock(&rdata->rp_mutex);
1714 kref_put(&rdata->kref, lport->tt.rport_destroy);
1715 goto busy;
1716 }
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001717 default:
Hannes Reinecke57d3ec7e2016-10-13 15:10:37 +02001718 FC_RPORT_DBG(rdata,
1719 "Reject ELS 0x%02x while in state %s\n",
1720 fc_frame_payload_op(fp), fc_rport_state(rdata));
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001721 mutex_unlock(&rdata->rp_mutex);
Hannes Reineckebaa67192016-05-24 08:11:58 +02001722 kref_put(&rdata->kref, lport->tt.rport_destroy);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001723 goto reject;
1724 }
1725
1726 switch (fc_frame_payload_op(fp)) {
Joe Eykholt131203a2009-08-25 14:03:10 -07001727 case ELS_PRLI:
Joe Eykholt922611562010-07-20 15:21:12 -07001728 fc_rport_recv_prli_req(rdata, fp);
Joe Eykholt131203a2009-08-25 14:03:10 -07001729 break;
1730 case ELS_PRLO:
Joe Eykholt922611562010-07-20 15:21:12 -07001731 fc_rport_recv_prlo_req(rdata, fp);
Joe Eykholt131203a2009-08-25 14:03:10 -07001732 break;
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001733 case ELS_ADISC:
Joe Eykholt922611562010-07-20 15:21:12 -07001734 fc_rport_recv_adisc_req(rdata, fp);
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001735 break;
Joe Eykholt131203a2009-08-25 14:03:10 -07001736 case ELS_RRQ:
Hannes Reinecke7ab24dd2016-10-18 10:01:35 +02001737 fc_seq_els_rsp_send(fp, ELS_RRQ, NULL);
Joe Eykholt922611562010-07-20 15:21:12 -07001738 fc_frame_free(fp);
Joe Eykholt131203a2009-08-25 14:03:10 -07001739 break;
1740 case ELS_REC:
Hannes Reinecke7ab24dd2016-10-18 10:01:35 +02001741 fc_seq_els_rsp_send(fp, ELS_REC, NULL);
Joe Eykholt922611562010-07-20 15:21:12 -07001742 fc_frame_free(fp);
Joe Eykholt131203a2009-08-25 14:03:10 -07001743 break;
Yi Zou63e27fb2009-11-20 14:55:24 -08001744 case ELS_RLS:
Joe Eykholt922611562010-07-20 15:21:12 -07001745 fc_rport_recv_rls_req(rdata, fp);
Yi Zou63e27fb2009-11-20 14:55:24 -08001746 break;
Hannes Reinecke7c5a51b2016-10-13 15:10:45 +02001747 case ELS_RTV:
1748 fc_rport_recv_rtv_req(rdata, fp);
1749 break;
Joe Eykholt131203a2009-08-25 14:03:10 -07001750 default:
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001751 fc_frame_free(fp); /* can't happen */
Joe Eykholt131203a2009-08-25 14:03:10 -07001752 break;
Robert Love42e9a922008-12-09 15:10:17 -08001753 }
1754
1755 mutex_unlock(&rdata->rp_mutex);
Hannes Reineckebaa67192016-05-24 08:11:58 +02001756 kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001757 return;
1758
1759reject:
Joe Eykholt922611562010-07-20 15:21:12 -07001760 els_data.reason = ELS_RJT_UNAB;
1761 els_data.explan = ELS_EXPL_PLOGI_REQD;
Hannes Reinecke7ab24dd2016-10-18 10:01:35 +02001762 fc_seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001763 fc_frame_free(fp);
Hannes Reinecke8acf1b52016-10-13 15:10:47 +02001764 return;
1765
1766busy:
1767 els_data.reason = ELS_RJT_BUSY;
1768 els_data.explan = ELS_EXPL_NONE;
Hannes Reinecke7ab24dd2016-10-18 10:01:35 +02001769 fc_seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
Hannes Reinecke8acf1b52016-10-13 15:10:47 +02001770 fc_frame_free(fp);
1771 return;
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001772}
1773
1774/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001775 * fc_rport_recv_req() - Handler for requests
Robert Love3a3b42b2009-11-03 11:47:39 -08001776 * @lport: The local port that received the request
Joe Eykholt922611562010-07-20 15:21:12 -07001777 * @fp: The request frame
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001778 *
1779 * Locking Note: Called with the lport lock held.
Hannes Reinecke4d2095c2016-09-30 11:01:14 +02001780 *
1781 * Reference counting: does not modify kref
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001782 */
Bart Van Asschec6b21c92012-01-13 17:26:20 -08001783static void fc_rport_recv_req(struct fc_lport *lport, struct fc_frame *fp)
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001784{
1785 struct fc_seq_els_data els_data;
1786
1787 /*
Joe Eykholta7b12a22010-07-20 15:20:08 -07001788 * Handle FLOGI, PLOGI and LOGO requests separately, since they
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001789 * don't require prior login.
1790 * Check for unsupported opcodes first and reject them.
1791 * For some ops, it would be incorrect to reject with "PLOGI required".
1792 */
1793 switch (fc_frame_payload_op(fp)) {
Joe Eykholta7b12a22010-07-20 15:20:08 -07001794 case ELS_FLOGI:
Joe Eykholt922611562010-07-20 15:21:12 -07001795 fc_rport_recv_flogi_req(lport, fp);
Joe Eykholta7b12a22010-07-20 15:20:08 -07001796 break;
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001797 case ELS_PLOGI:
Joe Eykholt922611562010-07-20 15:21:12 -07001798 fc_rport_recv_plogi_req(lport, fp);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001799 break;
1800 case ELS_LOGO:
Joe Eykholt922611562010-07-20 15:21:12 -07001801 fc_rport_recv_logo_req(lport, fp);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001802 break;
1803 case ELS_PRLI:
1804 case ELS_PRLO:
Joe Eykholt8abbe3a2009-08-25 14:03:52 -07001805 case ELS_ADISC:
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001806 case ELS_RRQ:
1807 case ELS_REC:
Yi Zou63e27fb2009-11-20 14:55:24 -08001808 case ELS_RLS:
Hannes Reinecke7c5a51b2016-10-13 15:10:45 +02001809 case ELS_RTV:
Joe Eykholt922611562010-07-20 15:21:12 -07001810 fc_rport_recv_els_req(lport, fp);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001811 break;
1812 default:
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001813 els_data.reason = ELS_RJT_UNSUP;
1814 els_data.explan = ELS_EXPL_NONE;
Hannes Reinecke7ab24dd2016-10-18 10:01:35 +02001815 fc_seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
Joe Eykholt922611562010-07-20 15:21:12 -07001816 fc_frame_free(fp);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07001817 break;
1818 }
Robert Love42e9a922008-12-09 15:10:17 -08001819}
1820
1821/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001822 * fc_rport_recv_plogi_req() - Handler for Port Login (PLOGI) requests
1823 * @lport: The local port that received the PLOGI request
Robert Love3a3b42b2009-11-03 11:47:39 -08001824 * @rx_fp: The PLOGI request frame
Robert Love42e9a922008-12-09 15:10:17 -08001825 *
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001826 * Locking Note: The rport lock is held before calling this function.
Hannes Reinecke4d2095c2016-09-30 11:01:14 +02001827 *
1828 * Reference counting: increments kref on return
Robert Love42e9a922008-12-09 15:10:17 -08001829 */
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001830static void fc_rport_recv_plogi_req(struct fc_lport *lport,
Joe Eykholt922611562010-07-20 15:21:12 -07001831 struct fc_frame *rx_fp)
Robert Love42e9a922008-12-09 15:10:17 -08001832{
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001833 struct fc_disc *disc;
1834 struct fc_rport_priv *rdata;
Robert Love42e9a922008-12-09 15:10:17 -08001835 struct fc_frame *fp = rx_fp;
Robert Love42e9a922008-12-09 15:10:17 -08001836 struct fc_els_flogi *pl;
1837 struct fc_seq_els_data rjt_data;
Joe Eykholt24f089e2010-07-20 15:21:01 -07001838 u32 sid;
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001839
Joe Eykholt251748a2010-07-20 15:20:56 -07001840 sid = fc_frame_sid(fp);
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001841
1842 FC_RPORT_ID_DBG(lport, sid, "Received PLOGI request\n");
1843
Robert Love42e9a922008-12-09 15:10:17 -08001844 pl = fc_frame_payload_get(fp, sizeof(*pl));
1845 if (!pl) {
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001846 FC_RPORT_ID_DBG(lport, sid, "Received PLOGI too short\n");
1847 rjt_data.reason = ELS_RJT_PROT;
1848 rjt_data.explan = ELS_EXPL_INV_LEN;
1849 goto reject;
Robert Love42e9a922008-12-09 15:10:17 -08001850 }
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001851
1852 disc = &lport->disc;
1853 mutex_lock(&disc->disc_mutex);
1854 rdata = lport->tt.rport_create(lport, sid);
1855 if (!rdata) {
1856 mutex_unlock(&disc->disc_mutex);
1857 rjt_data.reason = ELS_RJT_UNAB;
1858 rjt_data.explan = ELS_EXPL_INSUF_RES;
1859 goto reject;
1860 }
1861
1862 mutex_lock(&rdata->rp_mutex);
1863 mutex_unlock(&disc->disc_mutex);
1864
1865 rdata->ids.port_name = get_unaligned_be64(&pl->fl_wwpn);
1866 rdata->ids.node_name = get_unaligned_be64(&pl->fl_wwnn);
Robert Love42e9a922008-12-09 15:10:17 -08001867
1868 /*
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001869 * If the rport was just created, possibly due to the incoming PLOGI,
Robert Love42e9a922008-12-09 15:10:17 -08001870 * set the state appropriately and accept the PLOGI.
1871 *
1872 * If we had also sent a PLOGI, and if the received PLOGI is from a
1873 * higher WWPN, we accept it, otherwise an LS_RJT is sent with reason
1874 * "command already in progress".
1875 *
1876 * XXX TBD: If the session was ready before, the PLOGI should result in
1877 * all outstanding exchanges being reset.
1878 */
1879 switch (rdata->rp_state) {
1880 case RPORT_ST_INIT:
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001881 FC_RPORT_DBG(rdata, "Received PLOGI in INIT state\n");
Robert Love42e9a922008-12-09 15:10:17 -08001882 break;
Joe Eykholta7b12a22010-07-20 15:20:08 -07001883 case RPORT_ST_PLOGI_WAIT:
1884 FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI_WAIT state\n");
1885 break;
Robert Love42e9a922008-12-09 15:10:17 -08001886 case RPORT_ST_PLOGI:
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001887 FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI state\n");
1888 if (rdata->ids.port_name < lport->wwpn) {
1889 mutex_unlock(&rdata->rp_mutex);
1890 rjt_data.reason = ELS_RJT_INPROG;
1891 rjt_data.explan = ELS_EXPL_NONE;
1892 goto reject;
1893 }
Robert Love42e9a922008-12-09 15:10:17 -08001894 break;
1895 case RPORT_ST_PRLI:
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -07001896 case RPORT_ST_RTV:
Robert Love42e9a922008-12-09 15:10:17 -08001897 case RPORT_ST_READY:
Joe Eykholt370c3bd2009-08-25 14:03:47 -07001898 case RPORT_ST_ADISC:
1899 FC_RPORT_DBG(rdata, "Received PLOGI in logged-in state %d "
1900 "- ignored for now\n", rdata->rp_state);
1901 /* XXX TBD - should reset */
Robert Love42e9a922008-12-09 15:10:17 -08001902 break;
Joe Eykholta7b12a22010-07-20 15:20:08 -07001903 case RPORT_ST_FLOGI:
Joe Eykholt14194052009-07-29 17:04:43 -07001904 case RPORT_ST_DELETE:
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -07001905 FC_RPORT_DBG(rdata, "Received PLOGI in state %s - send busy\n",
1906 fc_rport_state(rdata));
1907 mutex_unlock(&rdata->rp_mutex);
1908 rjt_data.reason = ELS_RJT_BUSY;
1909 rjt_data.explan = ELS_EXPL_NONE;
1910 goto reject;
Robert Love42e9a922008-12-09 15:10:17 -08001911 }
Mark Rustade0335f62013-05-18 04:01:36 +00001912 if (!fc_rport_compatible_roles(lport, rdata)) {
1913 FC_RPORT_DBG(rdata, "Received PLOGI for incompatible role\n");
1914 mutex_unlock(&rdata->rp_mutex);
1915 rjt_data.reason = ELS_RJT_LOGIC;
1916 rjt_data.explan = ELS_EXPL_NONE;
1917 goto reject;
1918 }
Robert Love42e9a922008-12-09 15:10:17 -08001919
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001920 /*
1921 * Get session payload size from incoming PLOGI.
1922 */
1923 rdata->maxframe_size = fc_plogi_get_maxframe(pl, lport->mfs);
Robert Love42e9a922008-12-09 15:10:17 -08001924
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001925 /*
1926 * Send LS_ACC. If this fails, the originator should retry.
1927 */
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001928 fp = fc_frame_alloc(lport, sizeof(*pl));
1929 if (!fp)
1930 goto out;
Robert Love42e9a922008-12-09 15:10:17 -08001931
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001932 fc_plogi_fill(lport, fp, ELS_LS_ACC);
Joe Eykholt24f089e2010-07-20 15:21:01 -07001933 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
1934 lport->tt.frame_send(lport, fp);
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001935 fc_rport_enter_prli(rdata);
1936out:
1937 mutex_unlock(&rdata->rp_mutex);
Joe Eykholt24f089e2010-07-20 15:21:01 -07001938 fc_frame_free(rx_fp);
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001939 return;
1940
1941reject:
Hannes Reinecke7ab24dd2016-10-18 10:01:35 +02001942 fc_seq_els_rsp_send(fp, ELS_LS_RJT, &rjt_data);
Joe Eykholt3ac6f982009-08-25 14:03:26 -07001943 fc_frame_free(fp);
Robert Love42e9a922008-12-09 15:10:17 -08001944}
1945
1946/**
Robert Love3a3b42b2009-11-03 11:47:39 -08001947 * fc_rport_recv_prli_req() - Handler for process login (PRLI) requests
1948 * @rdata: The remote port that sent the PRLI request
Robert Love3a3b42b2009-11-03 11:47:39 -08001949 * @rx_fp: The PRLI request frame
Robert Love42e9a922008-12-09 15:10:17 -08001950 *
Bart Van Asschec1d45422013-08-14 15:31:52 +00001951 * Locking Note: The rport lock is expected to be held before calling
Robert Love42e9a922008-12-09 15:10:17 -08001952 * this function.
1953 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001954static void fc_rport_recv_prli_req(struct fc_rport_priv *rdata,
Joe Eykholt922611562010-07-20 15:21:12 -07001955 struct fc_frame *rx_fp)
Robert Love42e9a922008-12-09 15:10:17 -08001956{
Robert Love42e9a922008-12-09 15:10:17 -08001957 struct fc_lport *lport = rdata->local_port;
Robert Love42e9a922008-12-09 15:10:17 -08001958 struct fc_frame *fp;
Robert Love42e9a922008-12-09 15:10:17 -08001959 struct {
1960 struct fc_els_prli prli;
1961 struct fc_els_spp spp;
1962 } *pp;
1963 struct fc_els_spp *rspp; /* request service param page */
1964 struct fc_els_spp *spp; /* response spp */
1965 unsigned int len;
1966 unsigned int plen;
Robert Love42e9a922008-12-09 15:10:17 -08001967 enum fc_els_spp_resp resp;
1968 struct fc_seq_els_data rjt_data;
Joe Eykholt96ad8462011-01-28 16:04:02 -08001969 struct fc4_prov *prov;
Robert Love42e9a922008-12-09 15:10:17 -08001970
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001971 FC_RPORT_DBG(rdata, "Received PRLI request while in state %s\n",
1972 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -08001973
Joe Eykholt251748a2010-07-20 15:20:56 -07001974 len = fr_len(rx_fp) - sizeof(struct fc_frame_header);
Robert Love42e9a922008-12-09 15:10:17 -08001975 pp = fc_frame_payload_get(rx_fp, sizeof(*pp));
Joe Eykholta2f6a022010-03-12 16:07:36 -08001976 if (!pp)
1977 goto reject_len;
1978 plen = ntohs(pp->prli.prli_len);
1979 if ((plen % 4) != 0 || plen > len || plen < 16)
1980 goto reject_len;
1981 if (plen < len)
1982 len = plen;
1983 plen = pp->prli.prli_spp_len;
1984 if ((plen % 4) != 0 || plen < sizeof(*spp) ||
1985 plen > len || len < sizeof(*pp) || plen < 12)
1986 goto reject_len;
1987 rspp = &pp->spp;
1988
1989 fp = fc_frame_alloc(lport, len);
1990 if (!fp) {
1991 rjt_data.reason = ELS_RJT_UNAB;
1992 rjt_data.explan = ELS_EXPL_INSUF_RES;
1993 goto reject;
Robert Love42e9a922008-12-09 15:10:17 -08001994 }
Joe Eykholta2f6a022010-03-12 16:07:36 -08001995 pp = fc_frame_payload_get(fp, len);
1996 WARN_ON(!pp);
1997 memset(pp, 0, len);
1998 pp->prli.prli_cmd = ELS_LS_ACC;
1999 pp->prli.prli_spp_len = plen;
2000 pp->prli.prli_len = htons(len);
2001 len -= sizeof(struct fc_els_prli);
Robert Love42e9a922008-12-09 15:10:17 -08002002
Joe Eykholta2f6a022010-03-12 16:07:36 -08002003 /*
2004 * Go through all the service parameter pages and build
2005 * response. If plen indicates longer SPP than standard,
2006 * use that. The entire response has been pre-cleared above.
2007 */
2008 spp = &pp->spp;
Joe Eykholt96ad8462011-01-28 16:04:02 -08002009 mutex_lock(&fc_prov_mutex);
Joe Eykholta2f6a022010-03-12 16:07:36 -08002010 while (len >= plen) {
Bhanu Prakash Gollapudi75a27922011-01-28 16:05:27 -08002011 rdata->spp_type = rspp->spp_type;
Joe Eykholta2f6a022010-03-12 16:07:36 -08002012 spp->spp_type = rspp->spp_type;
2013 spp->spp_type_ext = rspp->spp_type_ext;
Joe Eykholt96ad8462011-01-28 16:04:02 -08002014 resp = 0;
Robert Love42e9a922008-12-09 15:10:17 -08002015
Joe Eykholt96ad8462011-01-28 16:04:02 -08002016 if (rspp->spp_type < FC_FC4_PROV_SIZE) {
Hannes Reinecke386b97b2016-10-13 15:10:46 +02002017 enum fc_els_spp_resp active = 0, passive = 0;
2018
Joe Eykholt96ad8462011-01-28 16:04:02 -08002019 prov = fc_active_prov[rspp->spp_type];
2020 if (prov)
Hannes Reinecke386b97b2016-10-13 15:10:46 +02002021 active = prov->prli(rdata, plen, rspp, spp);
Joe Eykholt96ad8462011-01-28 16:04:02 -08002022 prov = fc_passive_prov[rspp->spp_type];
Hannes Reinecke386b97b2016-10-13 15:10:46 +02002023 if (prov)
Joe Eykholt96ad8462011-01-28 16:04:02 -08002024 passive = prov->prli(rdata, plen, rspp, spp);
Hannes Reinecke386b97b2016-10-13 15:10:46 +02002025 if (!active || passive == FC_SPP_RESP_ACK)
2026 resp = passive;
2027 else
2028 resp = active;
2029 FC_RPORT_DBG(rdata, "PRLI rspp type %x "
2030 "active %x passive %x\n",
2031 rspp->spp_type, active, passive);
Joe Eykholt96ad8462011-01-28 16:04:02 -08002032 }
2033 if (!resp) {
2034 if (spp->spp_flags & FC_SPP_EST_IMG_PAIR)
2035 resp |= FC_SPP_RESP_CONF;
2036 else
2037 resp |= FC_SPP_RESP_INVL;
Robert Love42e9a922008-12-09 15:10:17 -08002038 }
Joe Eykholta2f6a022010-03-12 16:07:36 -08002039 spp->spp_flags |= resp;
2040 len -= plen;
2041 rspp = (struct fc_els_spp *)((char *)rspp + plen);
2042 spp = (struct fc_els_spp *)((char *)spp + plen);
Robert Love42e9a922008-12-09 15:10:17 -08002043 }
Joe Eykholt96ad8462011-01-28 16:04:02 -08002044 mutex_unlock(&fc_prov_mutex);
Joe Eykholta2f6a022010-03-12 16:07:36 -08002045
2046 /*
2047 * Send LS_ACC. If this fails, the originator should retry.
2048 */
Joe Eykholt24f089e2010-07-20 15:21:01 -07002049 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
2050 lport->tt.frame_send(lport, fp);
Joe Eykholta2f6a022010-03-12 16:07:36 -08002051
Joe Eykholta2f6a022010-03-12 16:07:36 -08002052 goto drop;
2053
2054reject_len:
2055 rjt_data.reason = ELS_RJT_PROT;
2056 rjt_data.explan = ELS_EXPL_INV_LEN;
2057reject:
Hannes Reinecke7ab24dd2016-10-18 10:01:35 +02002058 fc_seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
Joe Eykholta2f6a022010-03-12 16:07:36 -08002059drop:
Robert Love42e9a922008-12-09 15:10:17 -08002060 fc_frame_free(rx_fp);
2061}
2062
2063/**
Robert Love3a3b42b2009-11-03 11:47:39 -08002064 * fc_rport_recv_prlo_req() - Handler for process logout (PRLO) requests
2065 * @rdata: The remote port that sent the PRLO request
Bhanu Prakash Gollapudif8fc6c22010-06-11 16:44:04 -07002066 * @rx_fp: The PRLO request frame
Robert Love42e9a922008-12-09 15:10:17 -08002067 *
Bart Van Asschec1d45422013-08-14 15:31:52 +00002068 * Locking Note: The rport lock is expected to be held before calling
Robert Love42e9a922008-12-09 15:10:17 -08002069 * this function.
2070 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -07002071static void fc_rport_recv_prlo_req(struct fc_rport_priv *rdata,
Bhanu Prakash Gollapudif8fc6c22010-06-11 16:44:04 -07002072 struct fc_frame *rx_fp)
Robert Love42e9a922008-12-09 15:10:17 -08002073{
Robert Love42e9a922008-12-09 15:10:17 -08002074 struct fc_lport *lport = rdata->local_port;
Bhanu Prakash Gollapudif8fc6c22010-06-11 16:44:04 -07002075 struct fc_frame *fp;
2076 struct {
2077 struct fc_els_prlo prlo;
2078 struct fc_els_spp spp;
2079 } *pp;
2080 struct fc_els_spp *rspp; /* request service param page */
2081 struct fc_els_spp *spp; /* response spp */
2082 unsigned int len;
2083 unsigned int plen;
Robert Love42e9a922008-12-09 15:10:17 -08002084 struct fc_seq_els_data rjt_data;
2085
Joe Eykholt9fb9d322009-08-25 14:00:50 -07002086 FC_RPORT_DBG(rdata, "Received PRLO request while in state %s\n",
2087 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -08002088
Joe Eykholt251748a2010-07-20 15:20:56 -07002089 len = fr_len(rx_fp) - sizeof(struct fc_frame_header);
Bhanu Prakash Gollapudif8fc6c22010-06-11 16:44:04 -07002090 pp = fc_frame_payload_get(rx_fp, sizeof(*pp));
2091 if (!pp)
2092 goto reject_len;
2093 plen = ntohs(pp->prlo.prlo_len);
2094 if (plen != 20)
2095 goto reject_len;
2096 if (plen < len)
2097 len = plen;
2098
2099 rspp = &pp->spp;
2100
2101 fp = fc_frame_alloc(lport, len);
2102 if (!fp) {
2103 rjt_data.reason = ELS_RJT_UNAB;
2104 rjt_data.explan = ELS_EXPL_INSUF_RES;
2105 goto reject;
2106 }
2107
Bhanu Prakash Gollapudif8fc6c22010-06-11 16:44:04 -07002108 pp = fc_frame_payload_get(fp, len);
2109 WARN_ON(!pp);
2110 memset(pp, 0, len);
2111 pp->prlo.prlo_cmd = ELS_LS_ACC;
2112 pp->prlo.prlo_obs = 0x10;
2113 pp->prlo.prlo_len = htons(len);
2114 spp = &pp->spp;
2115 spp->spp_type = rspp->spp_type;
2116 spp->spp_type_ext = rspp->spp_type_ext;
2117 spp->spp_flags = FC_SPP_RESP_ACK;
2118
Hannes Reinecke166f3102016-08-05 14:55:00 +02002119 fc_rport_enter_prli(rdata);
Bhanu Prakash Gollapudif8fc6c22010-06-11 16:44:04 -07002120
Joe Eykholt922611562010-07-20 15:21:12 -07002121 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
2122 lport->tt.frame_send(lport, fp);
Bhanu Prakash Gollapudif8fc6c22010-06-11 16:44:04 -07002123 goto drop;
2124
2125reject_len:
2126 rjt_data.reason = ELS_RJT_PROT;
2127 rjt_data.explan = ELS_EXPL_INV_LEN;
2128reject:
Hannes Reinecke7ab24dd2016-10-18 10:01:35 +02002129 fc_seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
Bhanu Prakash Gollapudif8fc6c22010-06-11 16:44:04 -07002130drop:
2131 fc_frame_free(rx_fp);
Robert Love42e9a922008-12-09 15:10:17 -08002132}
2133
2134/**
Robert Love3a3b42b2009-11-03 11:47:39 -08002135 * fc_rport_recv_logo_req() - Handler for logout (LOGO) requests
2136 * @lport: The local port that received the LOGO request
Robert Love3a3b42b2009-11-03 11:47:39 -08002137 * @fp: The LOGO request frame
Robert Love42e9a922008-12-09 15:10:17 -08002138 *
Bart Van Asschec1d45422013-08-14 15:31:52 +00002139 * Locking Note: The rport lock is expected to be held before calling
Robert Love42e9a922008-12-09 15:10:17 -08002140 * this function.
Hannes Reinecke4d2095c2016-09-30 11:01:14 +02002141 *
2142 * Reference counting: drops kref on return
Robert Love42e9a922008-12-09 15:10:17 -08002143 */
Joe Eykholt922611562010-07-20 15:21:12 -07002144static void fc_rport_recv_logo_req(struct fc_lport *lport, struct fc_frame *fp)
Robert Love42e9a922008-12-09 15:10:17 -08002145{
Joe Eykholt83fe6a92009-08-25 14:03:31 -07002146 struct fc_rport_priv *rdata;
2147 u32 sid;
Robert Love42e9a922008-12-09 15:10:17 -08002148
Hannes Reinecke7ab24dd2016-10-18 10:01:35 +02002149 fc_seq_els_rsp_send(fp, ELS_LS_ACC, NULL);
Joe Eykholtfeab4ae2009-08-25 14:03:36 -07002150
Joe Eykholt251748a2010-07-20 15:20:56 -07002151 sid = fc_frame_sid(fp);
Robert Love42e9a922008-12-09 15:10:17 -08002152
Joe Eykholt83fe6a92009-08-25 14:03:31 -07002153 rdata = lport->tt.rport_lookup(lport, sid);
2154 if (rdata) {
2155 mutex_lock(&rdata->rp_mutex);
2156 FC_RPORT_DBG(rdata, "Received LOGO request while in state %s\n",
2157 fc_rport_state(rdata));
Joe Eykholtfeab4ae2009-08-25 14:03:36 -07002158
Hannes Reinecke649eb862016-08-05 14:55:02 +02002159 fc_rport_enter_delete(rdata, RPORT_EV_STOP);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07002160 mutex_unlock(&rdata->rp_mutex);
Hannes Reineckebaa67192016-05-24 08:11:58 +02002161 kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
Joe Eykholt83fe6a92009-08-25 14:03:31 -07002162 } else
2163 FC_RPORT_ID_DBG(lport, sid,
2164 "Received LOGO from non-logged-in port\n");
Robert Love42e9a922008-12-09 15:10:17 -08002165 fc_frame_free(fp);
2166}
2167
Robert Love3a3b42b2009-11-03 11:47:39 -08002168/**
2169 * fc_rport_flush_queue() - Flush the rport_event_queue
2170 */
Robert Love42e9a922008-12-09 15:10:17 -08002171static void fc_rport_flush_queue(void)
2172{
2173 flush_workqueue(rport_event_queue);
2174}
2175
Robert Love3a3b42b2009-11-03 11:47:39 -08002176/**
2177 * fc_rport_init() - Initialize the remote port layer for a local port
2178 * @lport: The local port to initialize the remote port layer for
2179 */
Robert Love42e9a922008-12-09 15:10:17 -08002180int fc_rport_init(struct fc_lport *lport)
2181{
Joe Eykholt8025b5d2009-08-25 14:02:06 -07002182 if (!lport->tt.rport_lookup)
2183 lport->tt.rport_lookup = fc_rport_lookup;
2184
Robert Love5101ff92009-02-27 10:55:18 -08002185 if (!lport->tt.rport_create)
Joe Eykholt9e9d0452009-08-25 14:01:18 -07002186 lport->tt.rport_create = fc_rport_create;
Robert Love5101ff92009-02-27 10:55:18 -08002187
Robert Love42e9a922008-12-09 15:10:17 -08002188 if (!lport->tt.rport_login)
2189 lport->tt.rport_login = fc_rport_login;
2190
2191 if (!lport->tt.rport_logoff)
2192 lport->tt.rport_logoff = fc_rport_logoff;
2193
2194 if (!lport->tt.rport_recv_req)
2195 lport->tt.rport_recv_req = fc_rport_recv_req;
2196
2197 if (!lport->tt.rport_flush_queue)
2198 lport->tt.rport_flush_queue = fc_rport_flush_queue;
2199
Joe Eykholtf211fa52009-08-25 14:01:01 -07002200 if (!lport->tt.rport_destroy)
2201 lport->tt.rport_destroy = fc_rport_destroy;
2202
Robert Love42e9a922008-12-09 15:10:17 -08002203 return 0;
2204}
2205EXPORT_SYMBOL(fc_rport_init);
2206
Robert Love3a3b42b2009-11-03 11:47:39 -08002207/**
Joe Eykholt96ad8462011-01-28 16:04:02 -08002208 * fc_rport_fcp_prli() - Handle incoming PRLI for the FCP initiator.
2209 * @rdata: remote port private
2210 * @spp_len: service parameter page length
2211 * @rspp: received service parameter page
2212 * @spp: response service parameter page
2213 *
2214 * Returns the value for the response code to be placed in spp_flags;
2215 * Returns 0 if not an initiator.
2216 */
2217static int fc_rport_fcp_prli(struct fc_rport_priv *rdata, u32 spp_len,
2218 const struct fc_els_spp *rspp,
2219 struct fc_els_spp *spp)
2220{
2221 struct fc_lport *lport = rdata->local_port;
2222 u32 fcp_parm;
2223
2224 fcp_parm = ntohl(rspp->spp_params);
2225 rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
2226 if (fcp_parm & FCP_SPPF_INIT_FCN)
2227 rdata->ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2228 if (fcp_parm & FCP_SPPF_TARG_FCN)
2229 rdata->ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2230 if (fcp_parm & FCP_SPPF_RETRY)
2231 rdata->flags |= FC_RP_FLAGS_RETRY;
2232 rdata->supported_classes = FC_COS_CLASS3;
2233
Mark Rustad732bdb92013-03-20 07:17:55 +00002234 if (!(lport->service_params & FCP_SPPF_INIT_FCN))
Joe Eykholt96ad8462011-01-28 16:04:02 -08002235 return 0;
2236
2237 spp->spp_flags |= rspp->spp_flags & FC_SPP_EST_IMG_PAIR;
2238
2239 /*
2240 * OR in our service parameters with other providers (target), if any.
2241 */
2242 fcp_parm = ntohl(spp->spp_params);
2243 spp->spp_params = htonl(fcp_parm | lport->service_params);
2244 return FC_SPP_RESP_ACK;
2245}
2246
2247/*
2248 * FC-4 provider ops for FCP initiator.
2249 */
2250struct fc4_prov fc_rport_fcp_init = {
2251 .prli = fc_rport_fcp_prli,
2252};
2253
2254/**
2255 * fc_rport_t0_prli() - Handle incoming PRLI parameters for type 0
2256 * @rdata: remote port private
2257 * @spp_len: service parameter page length
2258 * @rspp: received service parameter page
2259 * @spp: response service parameter page
2260 */
2261static int fc_rport_t0_prli(struct fc_rport_priv *rdata, u32 spp_len,
2262 const struct fc_els_spp *rspp,
2263 struct fc_els_spp *spp)
2264{
2265 if (rspp->spp_flags & FC_SPP_EST_IMG_PAIR)
2266 return FC_SPP_RESP_INVL;
2267 return FC_SPP_RESP_ACK;
2268}
2269
2270/*
2271 * FC-4 provider ops for type 0 service parameters.
2272 *
2273 * This handles the special case of type 0 which is always successful
2274 * but doesn't do anything otherwise.
2275 */
2276struct fc4_prov fc_rport_t0_prov = {
2277 .prli = fc_rport_t0_prli,
2278};
2279
2280/**
Robert Love3a3b42b2009-11-03 11:47:39 -08002281 * fc_setup_rport() - Initialize the rport_event_queue
2282 */
Randy Dunlap55204902011-01-28 16:03:57 -08002283int fc_setup_rport(void)
Robert Love42e9a922008-12-09 15:10:17 -08002284{
2285 rport_event_queue = create_singlethread_workqueue("fc_rport_eq");
2286 if (!rport_event_queue)
2287 return -ENOMEM;
2288 return 0;
2289}
Robert Love42e9a922008-12-09 15:10:17 -08002290
Robert Love3a3b42b2009-11-03 11:47:39 -08002291/**
2292 * fc_destroy_rport() - Destroy the rport_event_queue
2293 */
Randy Dunlap55204902011-01-28 16:03:57 -08002294void fc_destroy_rport(void)
Robert Love42e9a922008-12-09 15:10:17 -08002295{
2296 destroy_workqueue(rport_event_queue);
2297}
Robert Love42e9a922008-12-09 15:10:17 -08002298
Robert Love3a3b42b2009-11-03 11:47:39 -08002299/**
2300 * fc_rport_terminate_io() - Stop all outstanding I/O on a remote port
2301 * @rport: The remote port whose I/O should be terminated
2302 */
Robert Love42e9a922008-12-09 15:10:17 -08002303void fc_rport_terminate_io(struct fc_rport *rport)
2304{
Robert Love3a3b42b2009-11-03 11:47:39 -08002305 struct fc_rport_libfc_priv *rpriv = rport->dd_data;
2306 struct fc_lport *lport = rpriv->local_port;
Robert Love42e9a922008-12-09 15:10:17 -08002307
Abhijeet Joglekar1f6ff362009-02-27 10:54:35 -08002308 lport->tt.exch_mgr_reset(lport, 0, rport->port_id);
2309 lport->tt.exch_mgr_reset(lport, rport->port_id, 0);
Robert Love42e9a922008-12-09 15:10:17 -08002310}
2311EXPORT_SYMBOL(fc_rport_terminate_io);