2 * Copyright(c) 2007 - 2008 Intel Corporation. All rights reserved.
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.
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
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.
17 * Maintained at www.Open-FCoE.org
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.
28 * fc_rport's represent N_Port's within the fabric.
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
37 * more comments on the hierarchy.
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.
48 * RPORT REFERENCE COUNTING
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
60 #include <linux/kernel.h>
61 #include <linux/spinlock.h>
62 #include <linux/interrupt.h>
63 #include <linux/slab.h>
64 #include <linux/rcupdate.h>
65 #include <linux/timer.h>
66 #include <linux/workqueue.h>
67 #include <linux/export.h>
68 #include <linux/rculist.h>
70 #include <asm/unaligned.h>
72 #include <scsi/libfc.h>
73 #include <scsi/fc_encode.h>
77 static struct workqueue_struct *rport_event_queue;
79 static void fc_rport_enter_flogi(struct fc_rport_priv *);
80 static void fc_rport_enter_plogi(struct fc_rport_priv *);
81 static void fc_rport_enter_prli(struct fc_rport_priv *);
82 static void fc_rport_enter_rtv(struct fc_rport_priv *);
83 static void fc_rport_enter_ready(struct fc_rport_priv *);
84 static void fc_rport_enter_logo(struct fc_rport_priv *);
85 static void fc_rport_enter_adisc(struct fc_rport_priv *);
87 static void fc_rport_recv_plogi_req(struct fc_lport *, struct fc_frame *);
88 static void fc_rport_recv_prli_req(struct fc_rport_priv *, struct fc_frame *);
89 static void fc_rport_recv_prlo_req(struct fc_rport_priv *, struct fc_frame *);
90 static void fc_rport_recv_logo_req(struct fc_lport *, struct fc_frame *);
91 static void fc_rport_timeout(struct work_struct *);
92 static void fc_rport_error(struct fc_rport_priv *, int);
93 static void fc_rport_error_retry(struct fc_rport_priv *, int);
94 static void fc_rport_work(struct work_struct *);
96 static const char *fc_rport_state_names[] = {
97 [RPORT_ST_INIT] = "Init",
98 [RPORT_ST_FLOGI] = "FLOGI",
99 [RPORT_ST_PLOGI_WAIT] = "PLOGI_WAIT",
100 [RPORT_ST_PLOGI] = "PLOGI",
101 [RPORT_ST_PRLI] = "PRLI",
102 [RPORT_ST_RTV] = "RTV",
103 [RPORT_ST_READY] = "Ready",
104 [RPORT_ST_ADISC] = "ADISC",
105 [RPORT_ST_DELETE] = "Delete",
109 * fc_rport_lookup() - Lookup a remote port by port_id
110 * @lport: The local port to lookup the remote port on
111 * @port_id: The remote port ID to look up
113 * The reference count of the fc_rport_priv structure is
116 struct fc_rport_priv *fc_rport_lookup(const struct fc_lport *lport,
119 struct fc_rport_priv *rdata = NULL, *tmp_rdata;
122 list_for_each_entry_rcu(tmp_rdata, &lport->disc.rports, peers)
123 if (tmp_rdata->ids.port_id == port_id &&
124 kref_get_unless_zero(&tmp_rdata->kref)) {
131 EXPORT_SYMBOL(fc_rport_lookup);
134 * fc_rport_create() - Create a new remote port
135 * @lport: The local port this remote port will be associated with
136 * @ids: The identifiers for the new remote port
138 * The remote port will start in the INIT state.
140 struct fc_rport_priv *fc_rport_create(struct fc_lport *lport, u32 port_id)
142 struct fc_rport_priv *rdata;
143 size_t rport_priv_size = sizeof(*rdata);
145 lockdep_assert_held(&lport->disc.disc_mutex);
147 rdata = fc_rport_lookup(lport, port_id);
151 if (lport->rport_priv_size > 0)
152 rport_priv_size = lport->rport_priv_size;
153 rdata = kzalloc(rport_priv_size, GFP_KERNEL);
157 rdata->ids.node_name = -1;
158 rdata->ids.port_name = -1;
159 rdata->ids.port_id = port_id;
160 rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
162 kref_init(&rdata->kref);
163 mutex_init(&rdata->rp_mutex);
164 rdata->local_port = lport;
165 rdata->rp_state = RPORT_ST_INIT;
166 rdata->event = RPORT_EV_NONE;
167 rdata->flags = FC_RP_FLAGS_REC_SUPPORTED;
168 rdata->e_d_tov = lport->e_d_tov;
169 rdata->r_a_tov = lport->r_a_tov;
170 rdata->maxframe_size = FC_MIN_MAX_PAYLOAD;
171 INIT_DELAYED_WORK(&rdata->retry_work, fc_rport_timeout);
172 INIT_WORK(&rdata->event_work, fc_rport_work);
173 if (port_id != FC_FID_DIR_SERV) {
174 rdata->lld_event_callback = lport->tt.rport_event_callback;
175 list_add_rcu(&rdata->peers, &lport->disc.rports);
179 EXPORT_SYMBOL(fc_rport_create);
182 * fc_rport_destroy() - Free a remote port after last reference is released
183 * @kref: The remote port's kref
185 void fc_rport_destroy(struct kref *kref)
187 struct fc_rport_priv *rdata;
189 rdata = container_of(kref, struct fc_rport_priv, kref);
190 kfree_rcu(rdata, rcu);
192 EXPORT_SYMBOL(fc_rport_destroy);
195 * fc_rport_state() - Return a string identifying the remote port's state
196 * @rdata: The remote port
198 static const char *fc_rport_state(struct fc_rport_priv *rdata)
202 cp = fc_rport_state_names[rdata->rp_state];
209 * fc_set_rport_loss_tmo() - Set the remote port loss timeout
210 * @rport: The remote port that gets a new timeout value
211 * @timeout: The new timeout value (in seconds)
213 void fc_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout)
216 rport->dev_loss_tmo = timeout;
218 rport->dev_loss_tmo = 1;
220 EXPORT_SYMBOL(fc_set_rport_loss_tmo);
223 * fc_plogi_get_maxframe() - Get the maximum payload from the common service
224 * parameters in a FLOGI frame
225 * @flp: The FLOGI or PLOGI payload
226 * @maxval: The maximum frame size upper limit; this may be less than what
227 * is in the service parameters
229 static unsigned int fc_plogi_get_maxframe(struct fc_els_flogi *flp,
235 * Get max payload from the common service parameters and the
236 * class 3 receive data field size.
238 mfs = ntohs(flp->fl_csp.sp_bb_data) & FC_SP_BB_DATA_MASK;
239 if (mfs >= FC_SP_MIN_MAX_PAYLOAD && mfs < maxval)
241 mfs = ntohs(flp->fl_cssp[3 - 1].cp_rdfs);
242 if (mfs >= FC_SP_MIN_MAX_PAYLOAD && mfs < maxval)
248 * fc_rport_state_enter() - Change the state of a remote port
249 * @rdata: The remote port whose state should change
250 * @new: The new state
252 static void fc_rport_state_enter(struct fc_rport_priv *rdata,
253 enum fc_rport_state new)
255 lockdep_assert_held(&rdata->rp_mutex);
257 if (rdata->rp_state != new)
259 rdata->rp_state = new;
263 * fc_rport_work() - Handler for remote port events in the rport_event_queue
264 * @work: Handle to the remote port being dequeued
266 * Reference counting: drops kref on return
268 static void fc_rport_work(struct work_struct *work)
271 struct fc_rport_priv *rdata =
272 container_of(work, struct fc_rport_priv, event_work);
273 struct fc_rport_libfc_priv *rpriv;
274 enum fc_rport_event event;
275 struct fc_lport *lport = rdata->local_port;
276 struct fc_rport_operations *rport_ops;
277 struct fc_rport_identifiers ids;
278 struct fc_rport *rport;
279 struct fc4_prov *prov;
282 mutex_lock(&rdata->rp_mutex);
283 event = rdata->event;
284 rport_ops = rdata->ops;
285 rport = rdata->rport;
287 FC_RPORT_DBG(rdata, "work event %u\n", event);
292 rdata->event = RPORT_EV_NONE;
293 rdata->major_retries = 0;
294 kref_get(&rdata->kref);
295 mutex_unlock(&rdata->rp_mutex);
298 FC_RPORT_DBG(rdata, "No rport!\n");
299 rport = fc_remote_port_add(lport->host, 0, &ids);
302 FC_RPORT_DBG(rdata, "Failed to add the rport\n");
303 fc_rport_logoff(rdata);
304 kref_put(&rdata->kref, fc_rport_destroy);
307 mutex_lock(&rdata->rp_mutex);
309 FC_RPORT_DBG(rdata, "rport already allocated\n");
310 rdata->rport = rport;
311 rport->maxframe_size = rdata->maxframe_size;
312 rport->supported_classes = rdata->supported_classes;
314 rpriv = rport->dd_data;
315 rpriv->local_port = lport;
316 rpriv->rp_state = rdata->rp_state;
317 rpriv->flags = rdata->flags;
318 rpriv->e_d_tov = rdata->e_d_tov;
319 rpriv->r_a_tov = rdata->r_a_tov;
320 mutex_unlock(&rdata->rp_mutex);
322 if (rport_ops && rport_ops->event_callback) {
323 FC_RPORT_DBG(rdata, "callback ev %d\n", event);
324 rport_ops->event_callback(lport, rdata, event);
326 if (rdata->lld_event_callback) {
327 FC_RPORT_DBG(rdata, "lld callback ev %d\n", event);
328 rdata->lld_event_callback(lport, rdata, event);
330 kref_put(&rdata->kref, fc_rport_destroy);
333 case RPORT_EV_FAILED:
336 if (rdata->prli_count) {
337 mutex_lock(&fc_prov_mutex);
338 for (type = 1; type < FC_FC4_PROV_SIZE; type++) {
339 prov = fc_passive_prov[type];
340 if (prov && prov->prlo)
343 mutex_unlock(&fc_prov_mutex);
345 port_id = rdata->ids.port_id;
346 mutex_unlock(&rdata->rp_mutex);
348 if (rport_ops && rport_ops->event_callback) {
349 FC_RPORT_DBG(rdata, "callback ev %d\n", event);
350 rport_ops->event_callback(lport, rdata, event);
352 if (rdata->lld_event_callback) {
353 FC_RPORT_DBG(rdata, "lld callback ev %d\n", event);
354 rdata->lld_event_callback(lport, rdata, event);
356 if (cancel_delayed_work_sync(&rdata->retry_work))
357 kref_put(&rdata->kref, fc_rport_destroy);
360 * Reset any outstanding exchanges before freeing rport.
362 lport->tt.exch_mgr_reset(lport, 0, port_id);
363 lport->tt.exch_mgr_reset(lport, port_id, 0);
366 rpriv = rport->dd_data;
367 rpriv->rp_state = RPORT_ST_DELETE;
368 mutex_lock(&rdata->rp_mutex);
370 mutex_unlock(&rdata->rp_mutex);
371 fc_remote_port_delete(rport);
374 mutex_lock(&rdata->rp_mutex);
375 if (rdata->rp_state == RPORT_ST_DELETE) {
376 if (port_id == FC_FID_DIR_SERV) {
377 rdata->event = RPORT_EV_NONE;
378 mutex_unlock(&rdata->rp_mutex);
379 kref_put(&rdata->kref, fc_rport_destroy);
380 } else if ((rdata->flags & FC_RP_STARTED) &&
381 rdata->major_retries <
382 lport->max_rport_retry_count) {
383 rdata->major_retries++;
384 rdata->event = RPORT_EV_NONE;
385 FC_RPORT_DBG(rdata, "work restart\n");
386 fc_rport_enter_flogi(rdata);
387 mutex_unlock(&rdata->rp_mutex);
389 mutex_unlock(&rdata->rp_mutex);
390 FC_RPORT_DBG(rdata, "work delete\n");
391 mutex_lock(&lport->disc.disc_mutex);
392 list_del_rcu(&rdata->peers);
393 mutex_unlock(&lport->disc.disc_mutex);
394 kref_put(&rdata->kref, fc_rport_destroy);
398 * Re-open for events. Reissue READY event if ready.
400 rdata->event = RPORT_EV_NONE;
401 if (rdata->rp_state == RPORT_ST_READY) {
402 FC_RPORT_DBG(rdata, "work reopen\n");
403 fc_rport_enter_ready(rdata);
405 mutex_unlock(&rdata->rp_mutex);
410 mutex_unlock(&rdata->rp_mutex);
413 kref_put(&rdata->kref, fc_rport_destroy);
417 * fc_rport_login() - Start the remote port login state machine
418 * @rdata: The remote port to be logged in to
420 * Initiates the RP state machine. It is called from the LP module.
421 * This function will issue the following commands to the N_Port
422 * identified by the FC ID provided.
428 * Locking Note: Called without the rport lock held. This
429 * function will hold the rport lock, call an _enter_*
430 * function and then unlock the rport.
432 * This indicates the intent to be logged into the remote port.
433 * If it appears we are already logged in, ADISC is used to verify
436 int fc_rport_login(struct fc_rport_priv *rdata)
438 mutex_lock(&rdata->rp_mutex);
440 if (rdata->flags & FC_RP_STARTED) {
441 FC_RPORT_DBG(rdata, "port already started\n");
442 mutex_unlock(&rdata->rp_mutex);
446 rdata->flags |= FC_RP_STARTED;
447 switch (rdata->rp_state) {
449 FC_RPORT_DBG(rdata, "ADISC port\n");
450 fc_rport_enter_adisc(rdata);
452 case RPORT_ST_DELETE:
453 FC_RPORT_DBG(rdata, "Restart deleted port\n");
456 FC_RPORT_DBG(rdata, "Login to port\n");
457 fc_rport_enter_flogi(rdata);
460 FC_RPORT_DBG(rdata, "Login in progress, state %s\n",
461 fc_rport_state(rdata));
464 mutex_unlock(&rdata->rp_mutex);
468 EXPORT_SYMBOL(fc_rport_login);
471 * fc_rport_enter_delete() - Schedule a remote port to be deleted
472 * @rdata: The remote port to be deleted
473 * @event: The event to report as the reason for deletion
475 * Allow state change into DELETE only once.
477 * Call queue_work only if there's no event already pending.
478 * Set the new event so that the old pending event will not occur.
479 * Since we have the mutex, even if fc_rport_work() is already started,
480 * it'll see the new event.
482 * Reference counting: does not modify kref
484 static void fc_rport_enter_delete(struct fc_rport_priv *rdata,
485 enum fc_rport_event event)
487 lockdep_assert_held(&rdata->rp_mutex);
489 if (rdata->rp_state == RPORT_ST_DELETE)
492 FC_RPORT_DBG(rdata, "Delete port\n");
494 fc_rport_state_enter(rdata, RPORT_ST_DELETE);
496 kref_get(&rdata->kref);
497 if (rdata->event == RPORT_EV_NONE &&
498 !queue_work(rport_event_queue, &rdata->event_work))
499 kref_put(&rdata->kref, fc_rport_destroy);
501 rdata->event = event;
505 * fc_rport_logoff() - Logoff and remove a remote port
506 * @rdata: The remote port to be logged off of
508 * Locking Note: Called without the rport lock held. This
509 * function will hold the rport lock, call an _enter_*
510 * function and then unlock the rport.
512 int fc_rport_logoff(struct fc_rport_priv *rdata)
514 struct fc_lport *lport = rdata->local_port;
515 u32 port_id = rdata->ids.port_id;
517 mutex_lock(&rdata->rp_mutex);
519 FC_RPORT_DBG(rdata, "Remove port\n");
521 rdata->flags &= ~FC_RP_STARTED;
522 if (rdata->rp_state == RPORT_ST_DELETE) {
523 FC_RPORT_DBG(rdata, "Port in Delete state, not removing\n");
528 * To explicitly Logout, the initiating Nx_Port shall terminate
529 * other open Sequences that it initiated with the destination
530 * Nx_Port prior to performing Logout.
532 lport->tt.exch_mgr_reset(lport, 0, port_id);
533 lport->tt.exch_mgr_reset(lport, port_id, 0);
535 fc_rport_enter_logo(rdata);
538 * Change the state to Delete so that we discard
541 fc_rport_enter_delete(rdata, RPORT_EV_STOP);
543 mutex_unlock(&rdata->rp_mutex);
546 EXPORT_SYMBOL(fc_rport_logoff);
549 * fc_rport_enter_ready() - Transition to the RPORT_ST_READY state
550 * @rdata: The remote port that is ready
552 * Reference counting: schedules workqueue, does not modify kref
554 static void fc_rport_enter_ready(struct fc_rport_priv *rdata)
556 lockdep_assert_held(&rdata->rp_mutex);
558 fc_rport_state_enter(rdata, RPORT_ST_READY);
560 FC_RPORT_DBG(rdata, "Port is Ready\n");
562 kref_get(&rdata->kref);
563 if (rdata->event == RPORT_EV_NONE &&
564 !queue_work(rport_event_queue, &rdata->event_work))
565 kref_put(&rdata->kref, fc_rport_destroy);
567 rdata->event = RPORT_EV_READY;
571 * fc_rport_timeout() - Handler for the retry_work timer
572 * @work: Handle to the remote port that has timed out
574 * Locking Note: Called without the rport lock held. This
575 * function will hold the rport lock, call an _enter_*
576 * function and then unlock the rport.
578 * Reference counting: Drops kref on return.
580 static void fc_rport_timeout(struct work_struct *work)
582 struct fc_rport_priv *rdata =
583 container_of(work, struct fc_rport_priv, retry_work.work);
585 mutex_lock(&rdata->rp_mutex);
586 FC_RPORT_DBG(rdata, "Port timeout, state %s\n", fc_rport_state(rdata));
588 switch (rdata->rp_state) {
590 fc_rport_enter_flogi(rdata);
593 fc_rport_enter_plogi(rdata);
596 fc_rport_enter_prli(rdata);
599 fc_rport_enter_rtv(rdata);
602 fc_rport_enter_adisc(rdata);
604 case RPORT_ST_PLOGI_WAIT:
607 case RPORT_ST_DELETE:
611 mutex_unlock(&rdata->rp_mutex);
612 kref_put(&rdata->kref, fc_rport_destroy);
616 * fc_rport_error() - Error handler, called once retries have been exhausted
617 * @rdata: The remote port the error is happened on
618 * @err: The error code
620 * Reference counting: does not modify kref
622 static void fc_rport_error(struct fc_rport_priv *rdata, int err)
624 struct fc_lport *lport = rdata->local_port;
626 lockdep_assert_held(&rdata->rp_mutex);
628 FC_RPORT_DBG(rdata, "Error %d in state %s, retries %d\n",
629 -err, fc_rport_state(rdata), rdata->retries);
631 switch (rdata->rp_state) {
633 rdata->flags &= ~FC_RP_STARTED;
634 fc_rport_enter_delete(rdata, RPORT_EV_FAILED);
637 if (lport->point_to_multipoint) {
638 rdata->flags &= ~FC_RP_STARTED;
639 fc_rport_enter_delete(rdata, RPORT_EV_FAILED);
641 fc_rport_enter_logo(rdata);
644 fc_rport_enter_ready(rdata);
648 fc_rport_enter_logo(rdata);
650 case RPORT_ST_PLOGI_WAIT:
651 case RPORT_ST_DELETE:
659 * fc_rport_error_retry() - Handler for remote port state retries
660 * @rdata: The remote port whose state is to be retried
661 * @err: The error code
663 * If the error was an exchange timeout retry immediately,
664 * otherwise wait for E_D_TOV.
666 * Reference counting: increments kref when scheduling retry_work
668 static void fc_rport_error_retry(struct fc_rport_priv *rdata, int err)
670 unsigned long delay = msecs_to_jiffies(rdata->e_d_tov);
672 lockdep_assert_held(&rdata->rp_mutex);
674 /* make sure this isn't an FC_EX_CLOSED error, never retry those */
675 if (err == -FC_EX_CLOSED)
678 if (rdata->retries < rdata->local_port->max_rport_retry_count) {
679 FC_RPORT_DBG(rdata, "Error %d in state %s, retrying\n",
680 err, fc_rport_state(rdata));
682 /* no additional delay on exchange timeouts */
683 if (err == -FC_EX_TIMEOUT)
685 kref_get(&rdata->kref);
686 if (!schedule_delayed_work(&rdata->retry_work, delay))
687 kref_put(&rdata->kref, fc_rport_destroy);
692 fc_rport_error(rdata, err);
696 * fc_rport_login_complete() - Handle parameters and completion of p-mp login.
697 * @rdata: The remote port which we logged into or which logged into us.
698 * @fp: The FLOGI or PLOGI request or response frame
700 * Returns non-zero error if a problem is detected with the frame.
701 * Does not free the frame.
703 * This is only used in point-to-multipoint mode for FIP currently.
705 static int fc_rport_login_complete(struct fc_rport_priv *rdata,
708 struct fc_lport *lport = rdata->local_port;
709 struct fc_els_flogi *flogi;
710 unsigned int e_d_tov;
713 flogi = fc_frame_payload_get(fp, sizeof(*flogi));
717 csp_flags = ntohs(flogi->fl_csp.sp_features);
719 if (fc_frame_payload_op(fp) == ELS_FLOGI) {
720 if (csp_flags & FC_SP_FT_FPORT) {
721 FC_RPORT_DBG(rdata, "Fabric bit set in FLOGI\n");
727 * E_D_TOV is not valid on an incoming FLOGI request.
729 e_d_tov = ntohl(flogi->fl_csp.sp_e_d_tov);
730 if (csp_flags & FC_SP_FT_EDTR)
732 if (e_d_tov > rdata->e_d_tov)
733 rdata->e_d_tov = e_d_tov;
735 rdata->maxframe_size = fc_plogi_get_maxframe(flogi, lport->mfs);
740 * fc_rport_flogi_resp() - Handle response to FLOGI request for p-mp mode
741 * @sp: The sequence that the FLOGI was on
742 * @fp: The FLOGI response frame
743 * @rp_arg: The remote port that received the FLOGI response
745 static void fc_rport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp,
748 struct fc_rport_priv *rdata = rp_arg;
749 struct fc_lport *lport = rdata->local_port;
750 struct fc_els_flogi *flogi;
751 unsigned int r_a_tov;
755 FC_RPORT_DBG(rdata, "Received a FLOGI %s\n",
756 IS_ERR(fp) ? "error" : fc_els_resp_type(fp));
758 if (fp == ERR_PTR(-FC_EX_CLOSED))
761 mutex_lock(&rdata->rp_mutex);
763 if (rdata->rp_state != RPORT_ST_FLOGI) {
764 FC_RPORT_DBG(rdata, "Received a FLOGI response, but in state "
765 "%s\n", fc_rport_state(rdata));
772 fc_rport_error(rdata, PTR_ERR(fp));
775 opcode = fc_frame_payload_op(fp);
776 if (opcode == ELS_LS_RJT) {
777 struct fc_els_ls_rjt *rjt;
779 rjt = fc_frame_payload_get(fp, sizeof(*rjt));
780 FC_RPORT_DBG(rdata, "FLOGI ELS rejected, reason %x expl %x\n",
781 rjt->er_reason, rjt->er_explan);
782 err = -FC_EX_ELS_RJT;
784 } else if (opcode != ELS_LS_ACC) {
785 FC_RPORT_DBG(rdata, "FLOGI ELS invalid opcode %x\n", opcode);
786 err = -FC_EX_ELS_RJT;
789 if (fc_rport_login_complete(rdata, fp)) {
790 FC_RPORT_DBG(rdata, "FLOGI failed, no login\n");
791 err = -FC_EX_INV_LOGIN;
795 flogi = fc_frame_payload_get(fp, sizeof(*flogi));
797 err = -FC_EX_ALLOC_ERR;
800 r_a_tov = ntohl(flogi->fl_csp.sp_r_a_tov);
801 if (r_a_tov > rdata->r_a_tov)
802 rdata->r_a_tov = r_a_tov;
804 if (rdata->ids.port_name < lport->wwpn)
805 fc_rport_enter_plogi(rdata);
807 fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
811 mutex_unlock(&rdata->rp_mutex);
813 kref_put(&rdata->kref, fc_rport_destroy);
816 FC_RPORT_DBG(rdata, "Bad FLOGI response\n");
817 fc_rport_error_retry(rdata, err);
822 * fc_rport_enter_flogi() - Send a FLOGI request to the remote port for p-mp
823 * @rdata: The remote port to send a FLOGI to
825 * Reference counting: increments kref when sending ELS
827 static void fc_rport_enter_flogi(struct fc_rport_priv *rdata)
829 struct fc_lport *lport = rdata->local_port;
832 lockdep_assert_held(&rdata->rp_mutex);
834 if (!lport->point_to_multipoint)
835 return fc_rport_enter_plogi(rdata);
837 FC_RPORT_DBG(rdata, "Entered FLOGI state from %s state\n",
838 fc_rport_state(rdata));
840 fc_rport_state_enter(rdata, RPORT_ST_FLOGI);
842 fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi));
844 return fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
846 kref_get(&rdata->kref);
847 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_FLOGI,
848 fc_rport_flogi_resp, rdata,
849 2 * lport->r_a_tov)) {
850 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
851 kref_put(&rdata->kref, fc_rport_destroy);
856 * fc_rport_recv_flogi_req() - Handle Fabric Login (FLOGI) request in p-mp mode
857 * @lport: The local port that received the PLOGI request
858 * @rx_fp: The PLOGI request frame
860 * Reference counting: drops kref on return
862 static void fc_rport_recv_flogi_req(struct fc_lport *lport,
863 struct fc_frame *rx_fp)
865 struct fc_disc *disc;
866 struct fc_els_flogi *flp;
867 struct fc_rport_priv *rdata;
868 struct fc_frame *fp = rx_fp;
869 struct fc_seq_els_data rjt_data;
872 sid = fc_frame_sid(fp);
874 FC_RPORT_ID_DBG(lport, sid, "Received FLOGI request\n");
877 if (!lport->point_to_multipoint) {
878 rjt_data.reason = ELS_RJT_UNSUP;
879 rjt_data.explan = ELS_EXPL_NONE;
883 flp = fc_frame_payload_get(fp, sizeof(*flp));
885 rjt_data.reason = ELS_RJT_LOGIC;
886 rjt_data.explan = ELS_EXPL_INV_LEN;
890 rdata = fc_rport_lookup(lport, sid);
892 rjt_data.reason = ELS_RJT_FIP;
893 rjt_data.explan = ELS_EXPL_NOT_NEIGHBOR;
896 mutex_lock(&rdata->rp_mutex);
898 FC_RPORT_DBG(rdata, "Received FLOGI in %s state\n",
899 fc_rport_state(rdata));
901 switch (rdata->rp_state) {
904 * If received the FLOGI request on RPORT which is INIT state
905 * (means not transition to FLOGI either fc_rport timeout
906 * function didn;t trigger or this end hasn;t received
907 * beacon yet from other end. In that case only, allow RPORT
908 * state machine to continue, otherwise fall through which
909 * causes the code to send reject response.
910 * NOTE; Not checking for FIP->state such as VNMP_UP or
911 * VNMP_CLAIM because if FIP state is not one of those,
912 * RPORT wouldn;t have created and 'rport_lookup' would have
913 * failed anyway in that case.
916 case RPORT_ST_DELETE:
917 mutex_unlock(&rdata->rp_mutex);
918 rjt_data.reason = ELS_RJT_FIP;
919 rjt_data.explan = ELS_EXPL_NOT_NEIGHBOR;
922 case RPORT_ST_PLOGI_WAIT:
930 * Set the remote port to be deleted and to then restart.
931 * This queues work to be sure exchanges are reset.
933 fc_rport_enter_delete(rdata, RPORT_EV_LOGO);
934 mutex_unlock(&rdata->rp_mutex);
935 rjt_data.reason = ELS_RJT_BUSY;
936 rjt_data.explan = ELS_EXPL_NONE;
939 if (fc_rport_login_complete(rdata, fp)) {
940 mutex_unlock(&rdata->rp_mutex);
941 rjt_data.reason = ELS_RJT_LOGIC;
942 rjt_data.explan = ELS_EXPL_NONE;
946 fp = fc_frame_alloc(lport, sizeof(*flp));
950 fc_flogi_fill(lport, fp);
951 flp = fc_frame_payload_get(fp, sizeof(*flp));
952 flp->fl_cmd = ELS_LS_ACC;
954 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
955 lport->tt.frame_send(lport, fp);
958 * Do not proceed with the state machine if our
959 * FLOGI has crossed with an FLOGI from the
960 * remote port; wait for the FLOGI response instead.
962 if (rdata->rp_state != RPORT_ST_FLOGI) {
963 if (rdata->ids.port_name < lport->wwpn)
964 fc_rport_enter_plogi(rdata);
966 fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
969 mutex_unlock(&rdata->rp_mutex);
970 kref_put(&rdata->kref, fc_rport_destroy);
971 fc_frame_free(rx_fp);
975 kref_put(&rdata->kref, fc_rport_destroy);
977 fc_seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
978 fc_frame_free(rx_fp);
982 * fc_rport_plogi_resp() - Handler for ELS PLOGI responses
983 * @sp: The sequence the PLOGI is on
984 * @fp: The PLOGI response frame
985 * @rdata_arg: The remote port that sent the PLOGI response
987 * Locking Note: This function will be called without the rport lock
988 * held, but it will lock, call an _enter_* function or fc_rport_error
989 * and then unlock the rport.
991 static void fc_rport_plogi_resp(struct fc_seq *sp, struct fc_frame *fp,
994 struct fc_rport_priv *rdata = rdata_arg;
995 struct fc_lport *lport = rdata->local_port;
996 struct fc_els_flogi *plp = NULL;
1001 FC_RPORT_DBG(rdata, "Received a PLOGI %s\n", fc_els_resp_type(fp));
1003 if (fp == ERR_PTR(-FC_EX_CLOSED))
1006 mutex_lock(&rdata->rp_mutex);
1008 if (rdata->rp_state != RPORT_ST_PLOGI) {
1009 FC_RPORT_DBG(rdata, "Received a PLOGI response, but in state "
1010 "%s\n", fc_rport_state(rdata));
1017 fc_rport_error_retry(rdata, PTR_ERR(fp));
1021 op = fc_frame_payload_op(fp);
1022 if (op == ELS_LS_ACC &&
1023 (plp = fc_frame_payload_get(fp, sizeof(*plp))) != NULL) {
1024 rdata->ids.port_name = get_unaligned_be64(&plp->fl_wwpn);
1025 rdata->ids.node_name = get_unaligned_be64(&plp->fl_wwnn);
1027 /* save plogi response sp_features for further reference */
1028 rdata->sp_features = ntohs(plp->fl_csp.sp_features);
1030 if (lport->point_to_multipoint)
1031 fc_rport_login_complete(rdata, fp);
1032 csp_seq = ntohs(plp->fl_csp.sp_tot_seq);
1033 cssp_seq = ntohs(plp->fl_cssp[3 - 1].cp_con_seq);
1034 if (cssp_seq < csp_seq)
1036 rdata->max_seq = csp_seq;
1037 rdata->maxframe_size = fc_plogi_get_maxframe(plp, lport->mfs);
1038 fc_rport_enter_prli(rdata);
1040 struct fc_els_ls_rjt *rjt;
1042 rjt = fc_frame_payload_get(fp, sizeof(*rjt));
1043 FC_RPORT_DBG(rdata, "PLOGI ELS rejected, reason %x expl %x\n",
1044 rjt->er_reason, rjt->er_explan);
1045 fc_rport_error_retry(rdata, -FC_EX_ELS_RJT);
1050 mutex_unlock(&rdata->rp_mutex);
1052 kref_put(&rdata->kref, fc_rport_destroy);
1056 fc_rport_compatible_roles(struct fc_lport *lport, struct fc_rport_priv *rdata)
1058 if (rdata->ids.roles == FC_PORT_ROLE_UNKNOWN)
1060 if ((rdata->ids.roles & FC_PORT_ROLE_FCP_TARGET) &&
1061 (lport->service_params & FCP_SPPF_INIT_FCN))
1063 if ((rdata->ids.roles & FC_PORT_ROLE_FCP_INITIATOR) &&
1064 (lport->service_params & FCP_SPPF_TARG_FCN))
1070 * fc_rport_enter_plogi() - Send Port Login (PLOGI) request
1071 * @rdata: The remote port to send a PLOGI to
1073 * Reference counting: increments kref when sending ELS
1075 static void fc_rport_enter_plogi(struct fc_rport_priv *rdata)
1077 struct fc_lport *lport = rdata->local_port;
1078 struct fc_frame *fp;
1080 lockdep_assert_held(&rdata->rp_mutex);
1082 if (!fc_rport_compatible_roles(lport, rdata)) {
1083 FC_RPORT_DBG(rdata, "PLOGI suppressed for incompatible role\n");
1084 fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
1088 FC_RPORT_DBG(rdata, "Port entered PLOGI state from %s state\n",
1089 fc_rport_state(rdata));
1091 fc_rport_state_enter(rdata, RPORT_ST_PLOGI);
1093 rdata->maxframe_size = FC_MIN_MAX_PAYLOAD;
1094 fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi));
1096 FC_RPORT_DBG(rdata, "%s frame alloc failed\n", __func__);
1097 fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
1100 rdata->e_d_tov = lport->e_d_tov;
1102 kref_get(&rdata->kref);
1103 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_PLOGI,
1104 fc_rport_plogi_resp, rdata,
1105 2 * lport->r_a_tov)) {
1106 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
1107 kref_put(&rdata->kref, fc_rport_destroy);
1112 * fc_rport_prli_resp() - Process Login (PRLI) response handler
1113 * @sp: The sequence the PRLI response was on
1114 * @fp: The PRLI response frame
1115 * @rdata_arg: The remote port that sent the PRLI response
1117 * Locking Note: This function will be called without the rport lock
1118 * held, but it will lock, call an _enter_* function or fc_rport_error
1119 * and then unlock the rport.
1121 static void fc_rport_prli_resp(struct fc_seq *sp, struct fc_frame *fp,
1124 struct fc_rport_priv *rdata = rdata_arg;
1126 struct fc_els_prli prli;
1127 struct fc_els_spp spp;
1129 struct fc_els_spp temp_spp;
1130 struct fc_els_ls_rjt *rjt;
1131 struct fc4_prov *prov;
1132 u32 roles = FC_RPORT_ROLE_UNKNOWN;
1135 enum fc_els_spp_resp resp_code;
1137 FC_RPORT_DBG(rdata, "Received a PRLI %s\n", fc_els_resp_type(fp));
1139 if (fp == ERR_PTR(-FC_EX_CLOSED))
1142 mutex_lock(&rdata->rp_mutex);
1144 if (rdata->rp_state != RPORT_ST_PRLI) {
1145 FC_RPORT_DBG(rdata, "Received a PRLI response, but in state "
1146 "%s\n", fc_rport_state(rdata));
1153 fc_rport_error_retry(rdata, PTR_ERR(fp));
1157 /* reinitialize remote port roles */
1158 rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
1160 op = fc_frame_payload_op(fp);
1161 if (op == ELS_LS_ACC) {
1162 pp = fc_frame_payload_get(fp, sizeof(*pp));
1166 resp_code = (pp->spp.spp_flags & FC_SPP_RESP_MASK);
1167 FC_RPORT_DBG(rdata, "PRLI spp_flags = 0x%x spp_type 0x%x\n",
1168 pp->spp.spp_flags, pp->spp.spp_type);
1169 rdata->spp_type = pp->spp.spp_type;
1170 if (resp_code != FC_SPP_RESP_ACK) {
1171 if (resp_code == FC_SPP_RESP_CONF)
1172 fc_rport_error(rdata, -FC_EX_SEQ_ERR);
1174 fc_rport_error_retry(rdata, -FC_EX_SEQ_ERR);
1177 if (pp->prli.prli_spp_len < sizeof(pp->spp))
1180 fcp_parm = ntohl(pp->spp.spp_params);
1181 if (fcp_parm & FCP_SPPF_RETRY)
1182 rdata->flags |= FC_RP_FLAGS_RETRY;
1183 if (fcp_parm & FCP_SPPF_CONF_COMPL)
1184 rdata->flags |= FC_RP_FLAGS_CONF_REQ;
1187 * Call prli provider if we should act as a target
1189 prov = fc_passive_prov[rdata->spp_type];
1191 memset(&temp_spp, 0, sizeof(temp_spp));
1192 prov->prli(rdata, pp->prli.prli_spp_len,
1193 &pp->spp, &temp_spp);
1196 * Check if the image pair could be established
1198 if (rdata->spp_type != FC_TYPE_FCP ||
1199 !(pp->spp.spp_flags & FC_SPP_EST_IMG_PAIR)) {
1201 * Nope; we can't use this port as a target.
1203 fcp_parm &= ~FCP_SPPF_TARG_FCN;
1205 rdata->supported_classes = FC_COS_CLASS3;
1206 if (fcp_parm & FCP_SPPF_INIT_FCN)
1207 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1208 if (fcp_parm & FCP_SPPF_TARG_FCN)
1209 roles |= FC_RPORT_ROLE_FCP_TARGET;
1211 rdata->ids.roles = roles;
1212 fc_rport_enter_rtv(rdata);
1215 rjt = fc_frame_payload_get(fp, sizeof(*rjt));
1216 FC_RPORT_DBG(rdata, "PRLI ELS rejected, reason %x expl %x\n",
1217 rjt->er_reason, rjt->er_explan);
1218 fc_rport_error_retry(rdata, FC_EX_ELS_RJT);
1224 mutex_unlock(&rdata->rp_mutex);
1226 kref_put(&rdata->kref, fc_rport_destroy);
1230 * fc_rport_enter_prli() - Send Process Login (PRLI) request
1231 * @rdata: The remote port to send the PRLI request to
1233 * Reference counting: increments kref when sending ELS
1235 static void fc_rport_enter_prli(struct fc_rport_priv *rdata)
1237 struct fc_lport *lport = rdata->local_port;
1239 struct fc_els_prli prli;
1240 struct fc_els_spp spp;
1242 struct fc_frame *fp;
1243 struct fc4_prov *prov;
1245 lockdep_assert_held(&rdata->rp_mutex);
1248 * If the rport is one of the well known addresses
1249 * we skip PRLI and RTV and go straight to READY.
1251 if (rdata->ids.port_id >= FC_FID_DOM_MGR) {
1252 fc_rport_enter_ready(rdata);
1257 * And if the local port does not support the initiator function
1258 * there's no need to send a PRLI, either.
1260 if (!(lport->service_params & FCP_SPPF_INIT_FCN)) {
1261 fc_rport_enter_ready(rdata);
1265 FC_RPORT_DBG(rdata, "Port entered PRLI state from %s state\n",
1266 fc_rport_state(rdata));
1268 fc_rport_state_enter(rdata, RPORT_ST_PRLI);
1270 fp = fc_frame_alloc(lport, sizeof(*pp));
1272 fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
1276 fc_prli_fill(lport, fp);
1278 prov = fc_passive_prov[FC_TYPE_FCP];
1280 pp = fc_frame_payload_get(fp, sizeof(*pp));
1281 prov->prli(rdata, sizeof(pp->spp), NULL, &pp->spp);
1284 fc_fill_fc_hdr(fp, FC_RCTL_ELS_REQ, rdata->ids.port_id,
1285 fc_host_port_id(lport->host), FC_TYPE_ELS,
1286 FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0);
1288 kref_get(&rdata->kref);
1289 if (!fc_exch_seq_send(lport, fp, fc_rport_prli_resp,
1290 NULL, rdata, 2 * lport->r_a_tov)) {
1291 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
1292 kref_put(&rdata->kref, fc_rport_destroy);
1297 * fc_rport_rtv_resp() - Handler for Request Timeout Value (RTV) responses
1298 * @sp: The sequence the RTV was on
1299 * @fp: The RTV response frame
1300 * @rdata_arg: The remote port that sent the RTV response
1302 * Many targets don't seem to support this.
1304 * Locking Note: This function will be called without the rport lock
1305 * held, but it will lock, call an _enter_* function or fc_rport_error
1306 * and then unlock the rport.
1308 static void fc_rport_rtv_resp(struct fc_seq *sp, struct fc_frame *fp,
1311 struct fc_rport_priv *rdata = rdata_arg;
1314 FC_RPORT_DBG(rdata, "Received a RTV %s\n", fc_els_resp_type(fp));
1316 if (fp == ERR_PTR(-FC_EX_CLOSED))
1319 mutex_lock(&rdata->rp_mutex);
1321 if (rdata->rp_state != RPORT_ST_RTV) {
1322 FC_RPORT_DBG(rdata, "Received a RTV response, but in state "
1323 "%s\n", fc_rport_state(rdata));
1330 fc_rport_error(rdata, PTR_ERR(fp));
1334 op = fc_frame_payload_op(fp);
1335 if (op == ELS_LS_ACC) {
1336 struct fc_els_rtv_acc *rtv;
1340 rtv = fc_frame_payload_get(fp, sizeof(*rtv));
1342 toq = ntohl(rtv->rtv_toq);
1343 tov = ntohl(rtv->rtv_r_a_tov);
1346 if (tov > rdata->r_a_tov)
1347 rdata->r_a_tov = tov;
1348 tov = ntohl(rtv->rtv_e_d_tov);
1349 if (toq & FC_ELS_RTV_EDRES)
1353 if (tov > rdata->e_d_tov)
1354 rdata->e_d_tov = tov;
1358 fc_rport_enter_ready(rdata);
1363 mutex_unlock(&rdata->rp_mutex);
1365 kref_put(&rdata->kref, fc_rport_destroy);
1369 * fc_rport_enter_rtv() - Send Request Timeout Value (RTV) request
1370 * @rdata: The remote port to send the RTV request to
1372 * Reference counting: increments kref when sending ELS
1374 static void fc_rport_enter_rtv(struct fc_rport_priv *rdata)
1376 struct fc_frame *fp;
1377 struct fc_lport *lport = rdata->local_port;
1379 lockdep_assert_held(&rdata->rp_mutex);
1381 FC_RPORT_DBG(rdata, "Port entered RTV state from %s state\n",
1382 fc_rport_state(rdata));
1384 fc_rport_state_enter(rdata, RPORT_ST_RTV);
1386 fp = fc_frame_alloc(lport, sizeof(struct fc_els_rtv));
1388 fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
1392 kref_get(&rdata->kref);
1393 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_RTV,
1394 fc_rport_rtv_resp, rdata,
1395 2 * lport->r_a_tov)) {
1396 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
1397 kref_put(&rdata->kref, fc_rport_destroy);
1402 * fc_rport_recv_rtv_req() - Handler for Read Timeout Value (RTV) requests
1403 * @rdata: The remote port that sent the RTV request
1404 * @in_fp: The RTV request frame
1406 static void fc_rport_recv_rtv_req(struct fc_rport_priv *rdata,
1407 struct fc_frame *in_fp)
1409 struct fc_lport *lport = rdata->local_port;
1410 struct fc_frame *fp;
1411 struct fc_els_rtv_acc *rtv;
1412 struct fc_seq_els_data rjt_data;
1414 lockdep_assert_held(&rdata->rp_mutex);
1415 lockdep_assert_held(&lport->lp_mutex);
1417 FC_RPORT_DBG(rdata, "Received RTV request\n");
1419 fp = fc_frame_alloc(lport, sizeof(*rtv));
1421 rjt_data.reason = ELS_RJT_UNAB;
1422 rjt_data.explan = ELS_EXPL_INSUF_RES;
1423 fc_seq_els_rsp_send(in_fp, ELS_LS_RJT, &rjt_data);
1426 rtv = fc_frame_payload_get(fp, sizeof(*rtv));
1427 rtv->rtv_cmd = ELS_LS_ACC;
1428 rtv->rtv_r_a_tov = htonl(lport->r_a_tov);
1429 rtv->rtv_e_d_tov = htonl(lport->e_d_tov);
1431 fc_fill_reply_hdr(fp, in_fp, FC_RCTL_ELS_REP, 0);
1432 lport->tt.frame_send(lport, fp);
1434 fc_frame_free(in_fp);
1438 * fc_rport_logo_resp() - Handler for logout (LOGO) responses
1439 * @sp: The sequence the LOGO was on
1440 * @fp: The LOGO response frame
1441 * @lport_arg: The local port
1443 static void fc_rport_logo_resp(struct fc_seq *sp, struct fc_frame *fp,
1446 struct fc_rport_priv *rdata = rdata_arg;
1447 struct fc_lport *lport = rdata->local_port;
1449 FC_RPORT_ID_DBG(lport, fc_seq_exch(sp)->did,
1450 "Received a LOGO %s\n", fc_els_resp_type(fp));
1453 kref_put(&rdata->kref, fc_rport_destroy);
1457 * fc_rport_enter_logo() - Send a logout (LOGO) request
1458 * @rdata: The remote port to send the LOGO request to
1460 * Reference counting: increments kref when sending ELS
1462 static void fc_rport_enter_logo(struct fc_rport_priv *rdata)
1464 struct fc_lport *lport = rdata->local_port;
1465 struct fc_frame *fp;
1467 lockdep_assert_held(&rdata->rp_mutex);
1469 FC_RPORT_DBG(rdata, "Port sending LOGO from %s state\n",
1470 fc_rport_state(rdata));
1472 fp = fc_frame_alloc(lport, sizeof(struct fc_els_logo));
1475 kref_get(&rdata->kref);
1476 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_LOGO,
1477 fc_rport_logo_resp, rdata, 0))
1478 kref_put(&rdata->kref, fc_rport_destroy);
1482 * fc_rport_els_adisc_resp() - Handler for Address Discovery (ADISC) responses
1483 * @sp: The sequence the ADISC response was on
1484 * @fp: The ADISC response frame
1485 * @rdata_arg: The remote port that sent the ADISC response
1487 * Locking Note: This function will be called without the rport lock
1488 * held, but it will lock, call an _enter_* function or fc_rport_error
1489 * and then unlock the rport.
1491 static void fc_rport_adisc_resp(struct fc_seq *sp, struct fc_frame *fp,
1494 struct fc_rport_priv *rdata = rdata_arg;
1495 struct fc_els_adisc *adisc;
1498 FC_RPORT_DBG(rdata, "Received a ADISC response\n");
1500 if (fp == ERR_PTR(-FC_EX_CLOSED))
1503 mutex_lock(&rdata->rp_mutex);
1505 if (rdata->rp_state != RPORT_ST_ADISC) {
1506 FC_RPORT_DBG(rdata, "Received a ADISC resp but in state %s\n",
1507 fc_rport_state(rdata));
1514 fc_rport_error(rdata, PTR_ERR(fp));
1519 * If address verification failed. Consider us logged out of the rport.
1520 * Since the rport is still in discovery, we want to be
1521 * logged in, so go to PLOGI state. Otherwise, go back to READY.
1523 op = fc_frame_payload_op(fp);
1524 adisc = fc_frame_payload_get(fp, sizeof(*adisc));
1525 if (op != ELS_LS_ACC || !adisc ||
1526 ntoh24(adisc->adisc_port_id) != rdata->ids.port_id ||
1527 get_unaligned_be64(&adisc->adisc_wwpn) != rdata->ids.port_name ||
1528 get_unaligned_be64(&adisc->adisc_wwnn) != rdata->ids.node_name) {
1529 FC_RPORT_DBG(rdata, "ADISC error or mismatch\n");
1530 fc_rport_enter_flogi(rdata);
1532 FC_RPORT_DBG(rdata, "ADISC OK\n");
1533 fc_rport_enter_ready(rdata);
1538 mutex_unlock(&rdata->rp_mutex);
1540 kref_put(&rdata->kref, fc_rport_destroy);
1544 * fc_rport_enter_adisc() - Send Address Discover (ADISC) request
1545 * @rdata: The remote port to send the ADISC request to
1547 * Reference counting: increments kref when sending ELS
1549 static void fc_rport_enter_adisc(struct fc_rport_priv *rdata)
1551 struct fc_lport *lport = rdata->local_port;
1552 struct fc_frame *fp;
1554 lockdep_assert_held(&rdata->rp_mutex);
1556 FC_RPORT_DBG(rdata, "sending ADISC from %s state\n",
1557 fc_rport_state(rdata));
1559 fc_rport_state_enter(rdata, RPORT_ST_ADISC);
1561 fp = fc_frame_alloc(lport, sizeof(struct fc_els_adisc));
1563 fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
1566 kref_get(&rdata->kref);
1567 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_ADISC,
1568 fc_rport_adisc_resp, rdata,
1569 2 * lport->r_a_tov)) {
1570 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
1571 kref_put(&rdata->kref, fc_rport_destroy);
1576 * fc_rport_recv_adisc_req() - Handler for Address Discovery (ADISC) requests
1577 * @rdata: The remote port that sent the ADISC request
1578 * @in_fp: The ADISC request frame
1580 static void fc_rport_recv_adisc_req(struct fc_rport_priv *rdata,
1581 struct fc_frame *in_fp)
1583 struct fc_lport *lport = rdata->local_port;
1584 struct fc_frame *fp;
1585 struct fc_els_adisc *adisc;
1586 struct fc_seq_els_data rjt_data;
1588 lockdep_assert_held(&rdata->rp_mutex);
1589 lockdep_assert_held(&lport->lp_mutex);
1591 FC_RPORT_DBG(rdata, "Received ADISC request\n");
1593 adisc = fc_frame_payload_get(in_fp, sizeof(*adisc));
1595 rjt_data.reason = ELS_RJT_PROT;
1596 rjt_data.explan = ELS_EXPL_INV_LEN;
1597 fc_seq_els_rsp_send(in_fp, ELS_LS_RJT, &rjt_data);
1601 fp = fc_frame_alloc(lport, sizeof(*adisc));
1604 fc_adisc_fill(lport, fp);
1605 adisc = fc_frame_payload_get(fp, sizeof(*adisc));
1606 adisc->adisc_cmd = ELS_LS_ACC;
1607 fc_fill_reply_hdr(fp, in_fp, FC_RCTL_ELS_REP, 0);
1608 lport->tt.frame_send(lport, fp);
1610 fc_frame_free(in_fp);
1614 * fc_rport_recv_rls_req() - Handle received Read Link Status request
1615 * @rdata: The remote port that sent the RLS request
1616 * @rx_fp: The PRLI request frame
1618 static void fc_rport_recv_rls_req(struct fc_rport_priv *rdata,
1619 struct fc_frame *rx_fp)
1622 struct fc_lport *lport = rdata->local_port;
1623 struct fc_frame *fp;
1624 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;
1630 lockdep_assert_held(&rdata->rp_mutex);
1632 FC_RPORT_DBG(rdata, "Received RLS request while in state %s\n",
1633 fc_rport_state(rdata));
1635 rls = fc_frame_payload_get(rx_fp, sizeof(*rls));
1637 rjt_data.reason = ELS_RJT_PROT;
1638 rjt_data.explan = ELS_EXPL_INV_LEN;
1642 fp = fc_frame_alloc(lport, sizeof(*rsp));
1644 rjt_data.reason = ELS_RJT_UNAB;
1645 rjt_data.explan = ELS_EXPL_INSUF_RES;
1649 rsp = fc_frame_payload_get(fp, sizeof(*rsp));
1650 memset(rsp, 0, sizeof(*rsp));
1651 rsp->rls_cmd = ELS_LS_ACC;
1652 lesb = &rsp->rls_lesb;
1653 if (lport->tt.get_lesb) {
1654 /* get LESB from LLD if it supports it */
1655 lport->tt.get_lesb(lport, lesb);
1657 fc_get_host_stats(lport->host);
1658 hst = &lport->host_stats;
1659 lesb->lesb_link_fail = htonl(hst->link_failure_count);
1660 lesb->lesb_sync_loss = htonl(hst->loss_of_sync_count);
1661 lesb->lesb_sig_loss = htonl(hst->loss_of_signal_count);
1662 lesb->lesb_prim_err = htonl(hst->prim_seq_protocol_err_count);
1663 lesb->lesb_inv_word = htonl(hst->invalid_tx_word_count);
1664 lesb->lesb_inv_crc = htonl(hst->invalid_crc_count);
1667 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
1668 lport->tt.frame_send(lport, fp);
1672 fc_seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
1674 fc_frame_free(rx_fp);
1678 * fc_rport_recv_els_req() - Handler for validated ELS requests
1679 * @lport: The local port that received the ELS request
1680 * @fp: The ELS request frame
1682 * Handle incoming ELS requests that require port login.
1683 * The ELS opcode has already been validated by the caller.
1685 * Reference counting: does not modify kref
1687 static void fc_rport_recv_els_req(struct fc_lport *lport, struct fc_frame *fp)
1689 struct fc_rport_priv *rdata;
1690 struct fc_seq_els_data els_data;
1692 lockdep_assert_held(&lport->lp_mutex);
1694 rdata = fc_rport_lookup(lport, fc_frame_sid(fp));
1696 FC_RPORT_ID_DBG(lport, fc_frame_sid(fp),
1697 "Received ELS 0x%02x from non-logged-in port\n",
1698 fc_frame_payload_op(fp));
1702 mutex_lock(&rdata->rp_mutex);
1704 switch (rdata->rp_state) {
1707 case RPORT_ST_READY:
1708 case RPORT_ST_ADISC:
1710 case RPORT_ST_PLOGI:
1711 if (fc_frame_payload_op(fp) == ELS_PRLI) {
1712 FC_RPORT_DBG(rdata, "Reject ELS PRLI "
1713 "while in state %s\n",
1714 fc_rport_state(rdata));
1715 mutex_unlock(&rdata->rp_mutex);
1716 kref_put(&rdata->kref, fc_rport_destroy);
1721 "Reject ELS 0x%02x while in state %s\n",
1722 fc_frame_payload_op(fp), fc_rport_state(rdata));
1723 mutex_unlock(&rdata->rp_mutex);
1724 kref_put(&rdata->kref, fc_rport_destroy);
1728 switch (fc_frame_payload_op(fp)) {
1730 fc_rport_recv_prli_req(rdata, fp);
1733 fc_rport_recv_prlo_req(rdata, fp);
1736 fc_rport_recv_adisc_req(rdata, fp);
1739 fc_seq_els_rsp_send(fp, ELS_RRQ, NULL);
1743 fc_seq_els_rsp_send(fp, ELS_REC, NULL);
1747 fc_rport_recv_rls_req(rdata, fp);
1750 fc_rport_recv_rtv_req(rdata, fp);
1753 fc_frame_free(fp); /* can't happen */
1757 mutex_unlock(&rdata->rp_mutex);
1758 kref_put(&rdata->kref, fc_rport_destroy);
1762 els_data.reason = ELS_RJT_UNAB;
1763 els_data.explan = ELS_EXPL_PLOGI_REQD;
1764 fc_seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
1769 els_data.reason = ELS_RJT_BUSY;
1770 els_data.explan = ELS_EXPL_NONE;
1771 fc_seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
1777 * fc_rport_recv_req() - Handler for requests
1778 * @lport: The local port that received the request
1779 * @fp: The request frame
1781 * Reference counting: does not modify kref
1783 void fc_rport_recv_req(struct fc_lport *lport, struct fc_frame *fp)
1785 struct fc_seq_els_data els_data;
1787 lockdep_assert_held(&lport->lp_mutex);
1790 * Handle FLOGI, PLOGI and LOGO requests separately, since they
1791 * don't require prior login.
1792 * Check for unsupported opcodes first and reject them.
1793 * For some ops, it would be incorrect to reject with "PLOGI required".
1795 switch (fc_frame_payload_op(fp)) {
1797 fc_rport_recv_flogi_req(lport, fp);
1800 fc_rport_recv_plogi_req(lport, fp);
1803 fc_rport_recv_logo_req(lport, fp);
1812 fc_rport_recv_els_req(lport, fp);
1815 els_data.reason = ELS_RJT_UNSUP;
1816 els_data.explan = ELS_EXPL_NONE;
1817 fc_seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
1822 EXPORT_SYMBOL(fc_rport_recv_req);
1825 * fc_rport_recv_plogi_req() - Handler for Port Login (PLOGI) requests
1826 * @lport: The local port that received the PLOGI request
1827 * @rx_fp: The PLOGI request frame
1829 * Reference counting: increments kref on return
1831 static void fc_rport_recv_plogi_req(struct fc_lport *lport,
1832 struct fc_frame *rx_fp)
1834 struct fc_disc *disc;
1835 struct fc_rport_priv *rdata;
1836 struct fc_frame *fp = rx_fp;
1837 struct fc_els_flogi *pl;
1838 struct fc_seq_els_data rjt_data;
1841 lockdep_assert_held(&lport->lp_mutex);
1843 sid = fc_frame_sid(fp);
1845 FC_RPORT_ID_DBG(lport, sid, "Received PLOGI request\n");
1847 pl = fc_frame_payload_get(fp, sizeof(*pl));
1849 FC_RPORT_ID_DBG(lport, sid, "Received PLOGI too short\n");
1850 rjt_data.reason = ELS_RJT_PROT;
1851 rjt_data.explan = ELS_EXPL_INV_LEN;
1855 disc = &lport->disc;
1856 mutex_lock(&disc->disc_mutex);
1857 rdata = fc_rport_create(lport, sid);
1859 mutex_unlock(&disc->disc_mutex);
1860 rjt_data.reason = ELS_RJT_UNAB;
1861 rjt_data.explan = ELS_EXPL_INSUF_RES;
1865 mutex_lock(&rdata->rp_mutex);
1866 mutex_unlock(&disc->disc_mutex);
1868 rdata->ids.port_name = get_unaligned_be64(&pl->fl_wwpn);
1869 rdata->ids.node_name = get_unaligned_be64(&pl->fl_wwnn);
1872 * If the rport was just created, possibly due to the incoming PLOGI,
1873 * set the state appropriately and accept the PLOGI.
1875 * If we had also sent a PLOGI, and if the received PLOGI is from a
1876 * higher WWPN, we accept it, otherwise an LS_RJT is sent with reason
1877 * "command already in progress".
1879 * XXX TBD: If the session was ready before, the PLOGI should result in
1880 * all outstanding exchanges being reset.
1882 switch (rdata->rp_state) {
1884 FC_RPORT_DBG(rdata, "Received PLOGI in INIT state\n");
1886 case RPORT_ST_PLOGI_WAIT:
1887 FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI_WAIT state\n");
1889 case RPORT_ST_PLOGI:
1890 FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI state\n");
1891 if (rdata->ids.port_name < lport->wwpn) {
1892 mutex_unlock(&rdata->rp_mutex);
1893 rjt_data.reason = ELS_RJT_INPROG;
1894 rjt_data.explan = ELS_EXPL_NONE;
1900 case RPORT_ST_READY:
1901 case RPORT_ST_ADISC:
1902 FC_RPORT_DBG(rdata, "Received PLOGI in logged-in state %d "
1903 "- ignored for now\n", rdata->rp_state);
1904 /* XXX TBD - should reset */
1906 case RPORT_ST_FLOGI:
1907 case RPORT_ST_DELETE:
1908 FC_RPORT_DBG(rdata, "Received PLOGI in state %s - send busy\n",
1909 fc_rport_state(rdata));
1910 mutex_unlock(&rdata->rp_mutex);
1911 rjt_data.reason = ELS_RJT_BUSY;
1912 rjt_data.explan = ELS_EXPL_NONE;
1915 if (!fc_rport_compatible_roles(lport, rdata)) {
1916 FC_RPORT_DBG(rdata, "Received PLOGI for incompatible role\n");
1917 mutex_unlock(&rdata->rp_mutex);
1918 rjt_data.reason = ELS_RJT_LOGIC;
1919 rjt_data.explan = ELS_EXPL_NONE;
1924 * Get session payload size from incoming PLOGI.
1926 rdata->maxframe_size = fc_plogi_get_maxframe(pl, lport->mfs);
1929 * Send LS_ACC. If this fails, the originator should retry.
1931 fp = fc_frame_alloc(lport, sizeof(*pl));
1935 fc_plogi_fill(lport, fp, ELS_LS_ACC);
1936 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
1937 lport->tt.frame_send(lport, fp);
1938 fc_rport_enter_prli(rdata);
1940 mutex_unlock(&rdata->rp_mutex);
1941 fc_frame_free(rx_fp);
1945 fc_seq_els_rsp_send(fp, ELS_LS_RJT, &rjt_data);
1950 * fc_rport_recv_prli_req() - Handler for process login (PRLI) requests
1951 * @rdata: The remote port that sent the PRLI request
1952 * @rx_fp: The PRLI request frame
1954 static void fc_rport_recv_prli_req(struct fc_rport_priv *rdata,
1955 struct fc_frame *rx_fp)
1957 struct fc_lport *lport = rdata->local_port;
1958 struct fc_frame *fp;
1960 struct fc_els_prli prli;
1961 struct fc_els_spp spp;
1963 struct fc_els_spp *rspp; /* request service param page */
1964 struct fc_els_spp *spp; /* response spp */
1967 enum fc_els_spp_resp resp;
1968 struct fc_seq_els_data rjt_data;
1969 struct fc4_prov *prov;
1971 lockdep_assert_held(&rdata->rp_mutex);
1973 FC_RPORT_DBG(rdata, "Received PRLI request while in state %s\n",
1974 fc_rport_state(rdata));
1976 len = fr_len(rx_fp) - sizeof(struct fc_frame_header);
1977 pp = fc_frame_payload_get(rx_fp, sizeof(*pp));
1980 plen = ntohs(pp->prli.prli_len);
1981 if ((plen % 4) != 0 || plen > len || plen < 16)
1985 plen = pp->prli.prli_spp_len;
1986 if ((plen % 4) != 0 || plen < sizeof(*spp) ||
1987 plen > len || len < sizeof(*pp) || plen < 12)
1991 fp = fc_frame_alloc(lport, len);
1993 rjt_data.reason = ELS_RJT_UNAB;
1994 rjt_data.explan = ELS_EXPL_INSUF_RES;
1997 pp = fc_frame_payload_get(fp, len);
2000 pp->prli.prli_cmd = ELS_LS_ACC;
2001 pp->prli.prli_spp_len = plen;
2002 pp->prli.prli_len = htons(len);
2003 len -= sizeof(struct fc_els_prli);
2006 * Go through all the service parameter pages and build
2007 * response. If plen indicates longer SPP than standard,
2008 * use that. The entire response has been pre-cleared above.
2011 mutex_lock(&fc_prov_mutex);
2012 while (len >= plen) {
2013 rdata->spp_type = rspp->spp_type;
2014 spp->spp_type = rspp->spp_type;
2015 spp->spp_type_ext = rspp->spp_type_ext;
2018 if (rspp->spp_type < FC_FC4_PROV_SIZE) {
2019 enum fc_els_spp_resp active = 0, passive = 0;
2021 prov = fc_active_prov[rspp->spp_type];
2023 active = prov->prli(rdata, plen, rspp, spp);
2024 prov = fc_passive_prov[rspp->spp_type];
2026 passive = prov->prli(rdata, plen, rspp, spp);
2027 if (!active || passive == FC_SPP_RESP_ACK)
2031 FC_RPORT_DBG(rdata, "PRLI rspp type %x "
2032 "active %x passive %x\n",
2033 rspp->spp_type, active, passive);
2036 if (spp->spp_flags & FC_SPP_EST_IMG_PAIR)
2037 resp |= FC_SPP_RESP_CONF;
2039 resp |= FC_SPP_RESP_INVL;
2041 spp->spp_flags |= resp;
2043 rspp = (struct fc_els_spp *)((char *)rspp + plen);
2044 spp = (struct fc_els_spp *)((char *)spp + plen);
2046 mutex_unlock(&fc_prov_mutex);
2049 * Send LS_ACC. If this fails, the originator should retry.
2051 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
2052 lport->tt.frame_send(lport, fp);
2057 rjt_data.reason = ELS_RJT_PROT;
2058 rjt_data.explan = ELS_EXPL_INV_LEN;
2060 fc_seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
2062 fc_frame_free(rx_fp);
2066 * fc_rport_recv_prlo_req() - Handler for process logout (PRLO) requests
2067 * @rdata: The remote port that sent the PRLO request
2068 * @rx_fp: The PRLO request frame
2070 static void fc_rport_recv_prlo_req(struct fc_rport_priv *rdata,
2071 struct fc_frame *rx_fp)
2073 struct fc_lport *lport = rdata->local_port;
2074 struct fc_frame *fp;
2076 struct fc_els_prlo prlo;
2077 struct fc_els_spp spp;
2079 struct fc_els_spp *rspp; /* request service param page */
2080 struct fc_els_spp *spp; /* response spp */
2083 struct fc_seq_els_data rjt_data;
2085 lockdep_assert_held(&rdata->rp_mutex);
2087 FC_RPORT_DBG(rdata, "Received PRLO request while in state %s\n",
2088 fc_rport_state(rdata));
2090 len = fr_len(rx_fp) - sizeof(struct fc_frame_header);
2091 pp = fc_frame_payload_get(rx_fp, sizeof(*pp));
2094 plen = ntohs(pp->prlo.prlo_len);
2102 fp = fc_frame_alloc(lport, len);
2104 rjt_data.reason = ELS_RJT_UNAB;
2105 rjt_data.explan = ELS_EXPL_INSUF_RES;
2109 pp = fc_frame_payload_get(fp, len);
2112 pp->prlo.prlo_cmd = ELS_LS_ACC;
2113 pp->prlo.prlo_obs = 0x10;
2114 pp->prlo.prlo_len = htons(len);
2116 spp->spp_type = rspp->spp_type;
2117 spp->spp_type_ext = rspp->spp_type_ext;
2118 spp->spp_flags = FC_SPP_RESP_ACK;
2120 fc_rport_enter_prli(rdata);
2122 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
2123 lport->tt.frame_send(lport, fp);
2127 rjt_data.reason = ELS_RJT_PROT;
2128 rjt_data.explan = ELS_EXPL_INV_LEN;
2130 fc_seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
2132 fc_frame_free(rx_fp);
2136 * fc_rport_recv_logo_req() - Handler for logout (LOGO) requests
2137 * @lport: The local port that received the LOGO request
2138 * @fp: The LOGO request frame
2140 * Reference counting: drops kref on return
2142 static void fc_rport_recv_logo_req(struct fc_lport *lport, struct fc_frame *fp)
2144 struct fc_rport_priv *rdata;
2147 lockdep_assert_held(&lport->lp_mutex);
2149 fc_seq_els_rsp_send(fp, ELS_LS_ACC, NULL);
2151 sid = fc_frame_sid(fp);
2153 rdata = fc_rport_lookup(lport, sid);
2155 mutex_lock(&rdata->rp_mutex);
2156 FC_RPORT_DBG(rdata, "Received LOGO request while in state %s\n",
2157 fc_rport_state(rdata));
2159 fc_rport_enter_delete(rdata, RPORT_EV_STOP);
2160 mutex_unlock(&rdata->rp_mutex);
2161 kref_put(&rdata->kref, fc_rport_destroy);
2163 FC_RPORT_ID_DBG(lport, sid,
2164 "Received LOGO from non-logged-in port\n");
2169 * fc_rport_flush_queue() - Flush the rport_event_queue
2171 void fc_rport_flush_queue(void)
2173 flush_workqueue(rport_event_queue);
2175 EXPORT_SYMBOL(fc_rport_flush_queue);
2178 * fc_rport_fcp_prli() - Handle incoming PRLI for the FCP initiator.
2179 * @rdata: remote port private
2180 * @spp_len: service parameter page length
2181 * @rspp: received service parameter page
2182 * @spp: response service parameter page
2184 * Returns the value for the response code to be placed in spp_flags;
2185 * Returns 0 if not an initiator.
2187 static int fc_rport_fcp_prli(struct fc_rport_priv *rdata, u32 spp_len,
2188 const struct fc_els_spp *rspp,
2189 struct fc_els_spp *spp)
2191 struct fc_lport *lport = rdata->local_port;
2194 fcp_parm = ntohl(rspp->spp_params);
2195 rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
2196 if (fcp_parm & FCP_SPPF_INIT_FCN)
2197 rdata->ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2198 if (fcp_parm & FCP_SPPF_TARG_FCN)
2199 rdata->ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2200 if (fcp_parm & FCP_SPPF_RETRY)
2201 rdata->flags |= FC_RP_FLAGS_RETRY;
2202 rdata->supported_classes = FC_COS_CLASS3;
2204 if (!(lport->service_params & FCP_SPPF_INIT_FCN))
2207 spp->spp_flags |= rspp->spp_flags & FC_SPP_EST_IMG_PAIR;
2210 * OR in our service parameters with other providers (target), if any.
2212 fcp_parm = ntohl(spp->spp_params);
2213 spp->spp_params = htonl(fcp_parm | lport->service_params);
2214 return FC_SPP_RESP_ACK;
2218 * FC-4 provider ops for FCP initiator.
2220 struct fc4_prov fc_rport_fcp_init = {
2221 .prli = fc_rport_fcp_prli,
2225 * fc_rport_t0_prli() - Handle incoming PRLI parameters for type 0
2226 * @rdata: remote port private
2227 * @spp_len: service parameter page length
2228 * @rspp: received service parameter page
2229 * @spp: response service parameter page
2231 static int fc_rport_t0_prli(struct fc_rport_priv *rdata, u32 spp_len,
2232 const struct fc_els_spp *rspp,
2233 struct fc_els_spp *spp)
2235 if (rspp->spp_flags & FC_SPP_EST_IMG_PAIR)
2236 return FC_SPP_RESP_INVL;
2237 return FC_SPP_RESP_ACK;
2241 * FC-4 provider ops for type 0 service parameters.
2243 * This handles the special case of type 0 which is always successful
2244 * but doesn't do anything otherwise.
2246 struct fc4_prov fc_rport_t0_prov = {
2247 .prli = fc_rport_t0_prli,
2251 * fc_setup_rport() - Initialize the rport_event_queue
2253 int fc_setup_rport(void)
2255 rport_event_queue = create_singlethread_workqueue("fc_rport_eq");
2256 if (!rport_event_queue)
2262 * fc_destroy_rport() - Destroy the rport_event_queue
2264 void fc_destroy_rport(void)
2266 destroy_workqueue(rport_event_queue);
2270 * fc_rport_terminate_io() - Stop all outstanding I/O on a remote port
2271 * @rport: The remote port whose I/O should be terminated
2273 void fc_rport_terminate_io(struct fc_rport *rport)
2275 struct fc_rport_libfc_priv *rpriv = rport->dd_data;
2276 struct fc_lport *lport = rpriv->local_port;
2278 lport->tt.exch_mgr_reset(lport, 0, rport->port_id);
2279 lport->tt.exch_mgr_reset(lport, rport->port_id, 0);
2281 EXPORT_SYMBOL(fc_rport_terminate_io);