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 * Locking note: must be called with the disc_mutex held.
142 struct fc_rport_priv *fc_rport_create(struct fc_lport *lport, u32 port_id)
144 struct fc_rport_priv *rdata;
145 size_t rport_priv_size = sizeof(*rdata);
147 rdata = fc_rport_lookup(lport, port_id);
149 kref_put(&rdata->kref, fc_rport_destroy);
153 if (lport->rport_priv_size > 0)
154 rport_priv_size = lport->rport_priv_size;
155 rdata = kzalloc(rport_priv_size, GFP_KERNEL);
159 rdata->ids.node_name = -1;
160 rdata->ids.port_name = -1;
161 rdata->ids.port_id = port_id;
162 rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
164 kref_init(&rdata->kref);
165 mutex_init(&rdata->rp_mutex);
166 rdata->local_port = lport;
167 rdata->rp_state = RPORT_ST_INIT;
168 rdata->event = RPORT_EV_NONE;
169 rdata->flags = FC_RP_FLAGS_REC_SUPPORTED;
170 rdata->e_d_tov = lport->e_d_tov;
171 rdata->r_a_tov = lport->r_a_tov;
172 rdata->maxframe_size = FC_MIN_MAX_PAYLOAD;
173 INIT_DELAYED_WORK(&rdata->retry_work, fc_rport_timeout);
174 INIT_WORK(&rdata->event_work, fc_rport_work);
175 if (port_id != FC_FID_DIR_SERV) {
176 rdata->lld_event_callback = lport->tt.rport_event_callback;
177 list_add_rcu(&rdata->peers, &lport->disc.rports);
181 EXPORT_SYMBOL(fc_rport_create);
184 * fc_rport_destroy() - Free a remote port after last reference is released
185 * @kref: The remote port's kref
187 void fc_rport_destroy(struct kref *kref)
189 struct fc_rport_priv *rdata;
191 rdata = container_of(kref, struct fc_rport_priv, kref);
192 kfree_rcu(rdata, rcu);
194 EXPORT_SYMBOL(fc_rport_destroy);
197 * fc_rport_state() - Return a string identifying the remote port's state
198 * @rdata: The remote port
200 static const char *fc_rport_state(struct fc_rport_priv *rdata)
204 cp = fc_rport_state_names[rdata->rp_state];
211 * fc_set_rport_loss_tmo() - Set the remote port loss timeout
212 * @rport: The remote port that gets a new timeout value
213 * @timeout: The new timeout value (in seconds)
215 void fc_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout)
218 rport->dev_loss_tmo = timeout;
220 rport->dev_loss_tmo = 1;
222 EXPORT_SYMBOL(fc_set_rport_loss_tmo);
225 * fc_plogi_get_maxframe() - Get the maximum payload from the common service
226 * parameters in a FLOGI frame
227 * @flp: The FLOGI or PLOGI payload
228 * @maxval: The maximum frame size upper limit; this may be less than what
229 * is in the service parameters
231 static unsigned int fc_plogi_get_maxframe(struct fc_els_flogi *flp,
237 * Get max payload from the common service parameters and the
238 * class 3 receive data field size.
240 mfs = ntohs(flp->fl_csp.sp_bb_data) & FC_SP_BB_DATA_MASK;
241 if (mfs >= FC_SP_MIN_MAX_PAYLOAD && mfs < maxval)
243 mfs = ntohs(flp->fl_cssp[3 - 1].cp_rdfs);
244 if (mfs >= FC_SP_MIN_MAX_PAYLOAD && mfs < maxval)
250 * fc_rport_state_enter() - Change the state of a remote port
251 * @rdata: The remote port whose state should change
252 * @new: The new state
254 * Locking Note: Called with the rport lock held
256 static void fc_rport_state_enter(struct fc_rport_priv *rdata,
257 enum fc_rport_state new)
259 if (rdata->rp_state != new)
261 rdata->rp_state = new;
265 * fc_rport_work() - Handler for remote port events in the rport_event_queue
266 * @work: Handle to the remote port being dequeued
268 * Reference counting: drops kref on return
270 static void fc_rport_work(struct work_struct *work)
273 struct fc_rport_priv *rdata =
274 container_of(work, struct fc_rport_priv, event_work);
275 struct fc_rport_libfc_priv *rpriv;
276 enum fc_rport_event event;
277 struct fc_lport *lport = rdata->local_port;
278 struct fc_rport_operations *rport_ops;
279 struct fc_rport_identifiers ids;
280 struct fc_rport *rport;
281 struct fc4_prov *prov;
284 mutex_lock(&rdata->rp_mutex);
285 event = rdata->event;
286 rport_ops = rdata->ops;
287 rport = rdata->rport;
289 FC_RPORT_DBG(rdata, "work event %u\n", event);
294 rdata->event = RPORT_EV_NONE;
295 rdata->major_retries = 0;
296 kref_get(&rdata->kref);
297 mutex_unlock(&rdata->rp_mutex);
300 FC_RPORT_DBG(rdata, "No rport!\n");
301 rport = fc_remote_port_add(lport->host, 0, &ids);
304 FC_RPORT_DBG(rdata, "Failed to add the rport\n");
305 fc_rport_logoff(rdata);
306 kref_put(&rdata->kref, fc_rport_destroy);
309 mutex_lock(&rdata->rp_mutex);
311 FC_RPORT_DBG(rdata, "rport already allocated\n");
312 rdata->rport = rport;
313 rport->maxframe_size = rdata->maxframe_size;
314 rport->supported_classes = rdata->supported_classes;
316 rpriv = rport->dd_data;
317 rpriv->local_port = lport;
318 rpriv->rp_state = rdata->rp_state;
319 rpriv->flags = rdata->flags;
320 rpriv->e_d_tov = rdata->e_d_tov;
321 rpriv->r_a_tov = rdata->r_a_tov;
322 mutex_unlock(&rdata->rp_mutex);
324 if (rport_ops && rport_ops->event_callback) {
325 FC_RPORT_DBG(rdata, "callback ev %d\n", event);
326 rport_ops->event_callback(lport, rdata, event);
328 if (rdata->lld_event_callback) {
329 FC_RPORT_DBG(rdata, "lld callback ev %d\n", event);
330 rdata->lld_event_callback(lport, rdata, event);
332 kref_put(&rdata->kref, fc_rport_destroy);
335 case RPORT_EV_FAILED:
338 if (rdata->prli_count) {
339 mutex_lock(&fc_prov_mutex);
340 for (type = 1; type < FC_FC4_PROV_SIZE; type++) {
341 prov = fc_passive_prov[type];
342 if (prov && prov->prlo)
345 mutex_unlock(&fc_prov_mutex);
347 port_id = rdata->ids.port_id;
348 mutex_unlock(&rdata->rp_mutex);
350 if (rport_ops && rport_ops->event_callback) {
351 FC_RPORT_DBG(rdata, "callback ev %d\n", event);
352 rport_ops->event_callback(lport, rdata, event);
354 if (rdata->lld_event_callback) {
355 FC_RPORT_DBG(rdata, "lld callback ev %d\n", event);
356 rdata->lld_event_callback(lport, rdata, event);
358 if (cancel_delayed_work_sync(&rdata->retry_work))
359 kref_put(&rdata->kref, fc_rport_destroy);
362 * Reset any outstanding exchanges before freeing rport.
364 lport->tt.exch_mgr_reset(lport, 0, port_id);
365 lport->tt.exch_mgr_reset(lport, port_id, 0);
368 rpriv = rport->dd_data;
369 rpriv->rp_state = RPORT_ST_DELETE;
370 mutex_lock(&rdata->rp_mutex);
372 mutex_unlock(&rdata->rp_mutex);
373 fc_remote_port_delete(rport);
376 mutex_lock(&rdata->rp_mutex);
377 if (rdata->rp_state == RPORT_ST_DELETE) {
378 if (port_id == FC_FID_DIR_SERV) {
379 rdata->event = RPORT_EV_NONE;
380 mutex_unlock(&rdata->rp_mutex);
381 kref_put(&rdata->kref, fc_rport_destroy);
382 } else if ((rdata->flags & FC_RP_STARTED) &&
383 rdata->major_retries <
384 lport->max_rport_retry_count) {
385 rdata->major_retries++;
386 rdata->event = RPORT_EV_NONE;
387 FC_RPORT_DBG(rdata, "work restart\n");
388 fc_rport_enter_flogi(rdata);
389 mutex_unlock(&rdata->rp_mutex);
391 mutex_unlock(&rdata->rp_mutex);
392 FC_RPORT_DBG(rdata, "work delete\n");
393 mutex_lock(&lport->disc.disc_mutex);
394 list_del_rcu(&rdata->peers);
395 mutex_unlock(&lport->disc.disc_mutex);
396 kref_put(&rdata->kref, fc_rport_destroy);
400 * Re-open for events. Reissue READY event if ready.
402 rdata->event = RPORT_EV_NONE;
403 if (rdata->rp_state == RPORT_ST_READY) {
404 FC_RPORT_DBG(rdata, "work reopen\n");
405 fc_rport_enter_ready(rdata);
407 mutex_unlock(&rdata->rp_mutex);
412 mutex_unlock(&rdata->rp_mutex);
415 kref_put(&rdata->kref, fc_rport_destroy);
419 * fc_rport_login() - Start the remote port login state machine
420 * @rdata: The remote port to be logged in to
422 * Initiates the RP state machine. It is called from the LP module.
423 * This function will issue the following commands to the N_Port
424 * identified by the FC ID provided.
430 * Locking Note: Called without the rport lock held. This
431 * function will hold the rport lock, call an _enter_*
432 * function and then unlock the rport.
434 * This indicates the intent to be logged into the remote port.
435 * If it appears we are already logged in, ADISC is used to verify
438 int fc_rport_login(struct fc_rport_priv *rdata)
440 mutex_lock(&rdata->rp_mutex);
442 if (rdata->flags & FC_RP_STARTED) {
443 FC_RPORT_DBG(rdata, "port already started\n");
444 mutex_unlock(&rdata->rp_mutex);
448 rdata->flags |= FC_RP_STARTED;
449 switch (rdata->rp_state) {
451 FC_RPORT_DBG(rdata, "ADISC port\n");
452 fc_rport_enter_adisc(rdata);
454 case RPORT_ST_DELETE:
455 FC_RPORT_DBG(rdata, "Restart deleted port\n");
458 FC_RPORT_DBG(rdata, "Login to port\n");
459 fc_rport_enter_flogi(rdata);
462 FC_RPORT_DBG(rdata, "Login in progress, state %s\n",
463 fc_rport_state(rdata));
466 mutex_unlock(&rdata->rp_mutex);
470 EXPORT_SYMBOL(fc_rport_login);
473 * fc_rport_enter_delete() - Schedule a remote port to be deleted
474 * @rdata: The remote port to be deleted
475 * @event: The event to report as the reason for deletion
477 * Locking Note: Called with the rport lock held.
479 * Allow state change into DELETE only once.
481 * Call queue_work only if there's no event already pending.
482 * Set the new event so that the old pending event will not occur.
483 * Since we have the mutex, even if fc_rport_work() is already started,
484 * it'll see the new event.
486 * Reference counting: does not modify kref
488 static void fc_rport_enter_delete(struct fc_rport_priv *rdata,
489 enum fc_rport_event event)
491 if (rdata->rp_state == RPORT_ST_DELETE)
494 FC_RPORT_DBG(rdata, "Delete port\n");
496 fc_rport_state_enter(rdata, RPORT_ST_DELETE);
498 if (rdata->event == RPORT_EV_NONE) {
499 kref_get(&rdata->kref);
500 if (!queue_work(rport_event_queue, &rdata->event_work))
501 kref_put(&rdata->kref, fc_rport_destroy);
504 rdata->event = event;
508 * fc_rport_logoff() - Logoff and remove a remote port
509 * @rdata: The remote port to be logged off of
511 * Locking Note: Called without the rport lock held. This
512 * function will hold the rport lock, call an _enter_*
513 * function and then unlock the rport.
515 int fc_rport_logoff(struct fc_rport_priv *rdata)
517 struct fc_lport *lport = rdata->local_port;
518 u32 port_id = rdata->ids.port_id;
520 mutex_lock(&rdata->rp_mutex);
522 FC_RPORT_DBG(rdata, "Remove port\n");
524 rdata->flags &= ~FC_RP_STARTED;
525 if (rdata->rp_state == RPORT_ST_DELETE) {
526 FC_RPORT_DBG(rdata, "Port in Delete state, not removing\n");
531 * To explicitly Logout, the initiating Nx_Port shall terminate
532 * other open Sequences that it initiated with the destination
533 * Nx_Port prior to performing Logout.
535 lport->tt.exch_mgr_reset(lport, 0, port_id);
536 lport->tt.exch_mgr_reset(lport, port_id, 0);
538 fc_rport_enter_logo(rdata);
541 * Change the state to Delete so that we discard
544 fc_rport_enter_delete(rdata, RPORT_EV_STOP);
546 mutex_unlock(&rdata->rp_mutex);
549 EXPORT_SYMBOL(fc_rport_logoff);
552 * fc_rport_enter_ready() - Transition to the RPORT_ST_READY state
553 * @rdata: The remote port that is ready
555 * Locking Note: The rport lock is expected to be held before calling
558 * Reference counting: schedules workqueue, does not modify kref
560 static void fc_rport_enter_ready(struct fc_rport_priv *rdata)
562 fc_rport_state_enter(rdata, RPORT_ST_READY);
564 FC_RPORT_DBG(rdata, "Port is Ready\n");
566 kref_get(&rdata->kref);
567 if (rdata->event == RPORT_EV_NONE &&
568 !queue_work(rport_event_queue, &rdata->event_work))
569 kref_put(&rdata->kref, fc_rport_destroy);
571 rdata->event = RPORT_EV_READY;
575 * fc_rport_timeout() - Handler for the retry_work timer
576 * @work: Handle to the remote port that has timed out
578 * Locking Note: Called without the rport lock held. This
579 * function will hold the rport lock, call an _enter_*
580 * function and then unlock the rport.
582 * Reference counting: Drops kref on return.
584 static void fc_rport_timeout(struct work_struct *work)
586 struct fc_rport_priv *rdata =
587 container_of(work, struct fc_rport_priv, retry_work.work);
589 mutex_lock(&rdata->rp_mutex);
590 FC_RPORT_DBG(rdata, "Port timeout, state %s\n", fc_rport_state(rdata));
592 switch (rdata->rp_state) {
594 fc_rport_enter_flogi(rdata);
597 fc_rport_enter_plogi(rdata);
600 fc_rport_enter_prli(rdata);
603 fc_rport_enter_rtv(rdata);
606 fc_rport_enter_adisc(rdata);
608 case RPORT_ST_PLOGI_WAIT:
611 case RPORT_ST_DELETE:
615 mutex_unlock(&rdata->rp_mutex);
616 kref_put(&rdata->kref, fc_rport_destroy);
620 * fc_rport_error() - Error handler, called once retries have been exhausted
621 * @rdata: The remote port the error is happened on
622 * @err: The error code
624 * Locking Note: The rport lock is expected to be held before
625 * calling this routine
627 * Reference counting: does not modify kref
629 static void fc_rport_error(struct fc_rport_priv *rdata, int err)
631 struct fc_lport *lport = rdata->local_port;
633 FC_RPORT_DBG(rdata, "Error %d in state %s, retries %d\n",
634 -err, fc_rport_state(rdata), rdata->retries);
636 switch (rdata->rp_state) {
638 rdata->flags &= ~FC_RP_STARTED;
639 fc_rport_enter_delete(rdata, RPORT_EV_FAILED);
642 if (lport->point_to_multipoint) {
643 rdata->flags &= ~FC_RP_STARTED;
644 fc_rport_enter_delete(rdata, RPORT_EV_FAILED);
646 fc_rport_enter_logo(rdata);
649 fc_rport_enter_ready(rdata);
653 fc_rport_enter_logo(rdata);
655 case RPORT_ST_PLOGI_WAIT:
656 case RPORT_ST_DELETE:
664 * fc_rport_error_retry() - Handler for remote port state retries
665 * @rdata: The remote port whose state is to be retried
666 * @err: The error code
668 * If the error was an exchange timeout retry immediately,
669 * otherwise wait for E_D_TOV.
671 * Locking Note: The rport lock is expected to be held before
672 * calling this routine
674 * Reference counting: increments kref when scheduling retry_work
676 static void fc_rport_error_retry(struct fc_rport_priv *rdata, int err)
678 unsigned long delay = msecs_to_jiffies(rdata->e_d_tov);
680 /* make sure this isn't an FC_EX_CLOSED error, never retry those */
681 if (err == -FC_EX_CLOSED)
684 if (rdata->retries < rdata->local_port->max_rport_retry_count) {
685 FC_RPORT_DBG(rdata, "Error %d in state %s, retrying\n",
686 err, fc_rport_state(rdata));
688 /* no additional delay on exchange timeouts */
689 if (err == -FC_EX_TIMEOUT)
691 kref_get(&rdata->kref);
692 if (!schedule_delayed_work(&rdata->retry_work, delay))
693 kref_put(&rdata->kref, fc_rport_destroy);
698 fc_rport_error(rdata, err);
702 * fc_rport_login_complete() - Handle parameters and completion of p-mp login.
703 * @rdata: The remote port which we logged into or which logged into us.
704 * @fp: The FLOGI or PLOGI request or response frame
706 * Returns non-zero error if a problem is detected with the frame.
707 * Does not free the frame.
709 * This is only used in point-to-multipoint mode for FIP currently.
711 static int fc_rport_login_complete(struct fc_rport_priv *rdata,
714 struct fc_lport *lport = rdata->local_port;
715 struct fc_els_flogi *flogi;
716 unsigned int e_d_tov;
719 flogi = fc_frame_payload_get(fp, sizeof(*flogi));
723 csp_flags = ntohs(flogi->fl_csp.sp_features);
725 if (fc_frame_payload_op(fp) == ELS_FLOGI) {
726 if (csp_flags & FC_SP_FT_FPORT) {
727 FC_RPORT_DBG(rdata, "Fabric bit set in FLOGI\n");
733 * E_D_TOV is not valid on an incoming FLOGI request.
735 e_d_tov = ntohl(flogi->fl_csp.sp_e_d_tov);
736 if (csp_flags & FC_SP_FT_EDTR)
738 if (e_d_tov > rdata->e_d_tov)
739 rdata->e_d_tov = e_d_tov;
741 rdata->maxframe_size = fc_plogi_get_maxframe(flogi, lport->mfs);
746 * fc_rport_flogi_resp() - Handle response to FLOGI request for p-mp mode
747 * @sp: The sequence that the FLOGI was on
748 * @fp: The FLOGI response frame
749 * @rp_arg: The remote port that received the FLOGI response
751 static void fc_rport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp,
754 struct fc_rport_priv *rdata = rp_arg;
755 struct fc_lport *lport = rdata->local_port;
756 struct fc_els_flogi *flogi;
757 unsigned int r_a_tov;
761 FC_RPORT_DBG(rdata, "Received a FLOGI %s\n",
762 IS_ERR(fp) ? "error" : fc_els_resp_type(fp));
764 if (fp == ERR_PTR(-FC_EX_CLOSED))
767 mutex_lock(&rdata->rp_mutex);
769 if (rdata->rp_state != RPORT_ST_FLOGI) {
770 FC_RPORT_DBG(rdata, "Received a FLOGI response, but in state "
771 "%s\n", fc_rport_state(rdata));
778 fc_rport_error(rdata, PTR_ERR(fp));
781 opcode = fc_frame_payload_op(fp);
782 if (opcode == ELS_LS_RJT) {
783 struct fc_els_ls_rjt *rjt;
785 rjt = fc_frame_payload_get(fp, sizeof(*rjt));
786 FC_RPORT_DBG(rdata, "FLOGI ELS rejected, reason %x expl %x\n",
787 rjt->er_reason, rjt->er_explan);
788 err = -FC_EX_ELS_RJT;
790 } else if (opcode != ELS_LS_ACC) {
791 FC_RPORT_DBG(rdata, "FLOGI ELS invalid opcode %x\n", opcode);
792 err = -FC_EX_ELS_RJT;
795 if (fc_rport_login_complete(rdata, fp)) {
796 FC_RPORT_DBG(rdata, "FLOGI failed, no login\n");
797 err = -FC_EX_INV_LOGIN;
801 flogi = fc_frame_payload_get(fp, sizeof(*flogi));
803 err = -FC_EX_ALLOC_ERR;
806 r_a_tov = ntohl(flogi->fl_csp.sp_r_a_tov);
807 if (r_a_tov > rdata->r_a_tov)
808 rdata->r_a_tov = r_a_tov;
810 if (rdata->ids.port_name < lport->wwpn)
811 fc_rport_enter_plogi(rdata);
813 fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
817 mutex_unlock(&rdata->rp_mutex);
819 kref_put(&rdata->kref, fc_rport_destroy);
822 FC_RPORT_DBG(rdata, "Bad FLOGI response\n");
823 fc_rport_error_retry(rdata, err);
828 * fc_rport_enter_flogi() - Send a FLOGI request to the remote port for p-mp
829 * @rdata: The remote port to send a FLOGI to
831 * Locking Note: The rport lock is expected to be held before calling
834 * Reference counting: increments kref when sending ELS
836 static void fc_rport_enter_flogi(struct fc_rport_priv *rdata)
838 struct fc_lport *lport = rdata->local_port;
841 if (!lport->point_to_multipoint)
842 return fc_rport_enter_plogi(rdata);
844 FC_RPORT_DBG(rdata, "Entered FLOGI state from %s state\n",
845 fc_rport_state(rdata));
847 fc_rport_state_enter(rdata, RPORT_ST_FLOGI);
849 fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi));
851 return fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
853 kref_get(&rdata->kref);
854 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_FLOGI,
855 fc_rport_flogi_resp, rdata,
856 2 * lport->r_a_tov)) {
857 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
858 kref_put(&rdata->kref, fc_rport_destroy);
863 * fc_rport_recv_flogi_req() - Handle Fabric Login (FLOGI) request in p-mp mode
864 * @lport: The local port that received the PLOGI request
865 * @rx_fp: The PLOGI request frame
867 * Reference counting: drops kref on return
869 static void fc_rport_recv_flogi_req(struct fc_lport *lport,
870 struct fc_frame *rx_fp)
872 struct fc_disc *disc;
873 struct fc_els_flogi *flp;
874 struct fc_rport_priv *rdata;
875 struct fc_frame *fp = rx_fp;
876 struct fc_seq_els_data rjt_data;
879 sid = fc_frame_sid(fp);
881 FC_RPORT_ID_DBG(lport, sid, "Received FLOGI request\n");
884 if (!lport->point_to_multipoint) {
885 rjt_data.reason = ELS_RJT_UNSUP;
886 rjt_data.explan = ELS_EXPL_NONE;
890 flp = fc_frame_payload_get(fp, sizeof(*flp));
892 rjt_data.reason = ELS_RJT_LOGIC;
893 rjt_data.explan = ELS_EXPL_INV_LEN;
897 rdata = fc_rport_lookup(lport, sid);
899 rjt_data.reason = ELS_RJT_FIP;
900 rjt_data.explan = ELS_EXPL_NOT_NEIGHBOR;
903 mutex_lock(&rdata->rp_mutex);
905 FC_RPORT_DBG(rdata, "Received FLOGI in %s state\n",
906 fc_rport_state(rdata));
908 switch (rdata->rp_state) {
911 * If received the FLOGI request on RPORT which is INIT state
912 * (means not transition to FLOGI either fc_rport timeout
913 * function didn;t trigger or this end hasn;t received
914 * beacon yet from other end. In that case only, allow RPORT
915 * state machine to continue, otherwise fall through which
916 * causes the code to send reject response.
917 * NOTE; Not checking for FIP->state such as VNMP_UP or
918 * VNMP_CLAIM because if FIP state is not one of those,
919 * RPORT wouldn;t have created and 'rport_lookup' would have
920 * failed anyway in that case.
923 case RPORT_ST_DELETE:
924 mutex_unlock(&rdata->rp_mutex);
925 rjt_data.reason = ELS_RJT_FIP;
926 rjt_data.explan = ELS_EXPL_NOT_NEIGHBOR;
929 case RPORT_ST_PLOGI_WAIT:
937 * Set the remote port to be deleted and to then restart.
938 * This queues work to be sure exchanges are reset.
940 fc_rport_enter_delete(rdata, RPORT_EV_LOGO);
941 mutex_unlock(&rdata->rp_mutex);
942 rjt_data.reason = ELS_RJT_BUSY;
943 rjt_data.explan = ELS_EXPL_NONE;
946 if (fc_rport_login_complete(rdata, fp)) {
947 mutex_unlock(&rdata->rp_mutex);
948 rjt_data.reason = ELS_RJT_LOGIC;
949 rjt_data.explan = ELS_EXPL_NONE;
953 fp = fc_frame_alloc(lport, sizeof(*flp));
957 fc_flogi_fill(lport, fp);
958 flp = fc_frame_payload_get(fp, sizeof(*flp));
959 flp->fl_cmd = ELS_LS_ACC;
961 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
962 lport->tt.frame_send(lport, fp);
965 * Do not proceed with the state machine if our
966 * FLOGI has crossed with an FLOGI from the
967 * remote port; wait for the FLOGI response instead.
969 if (rdata->rp_state != RPORT_ST_FLOGI) {
970 if (rdata->ids.port_name < lport->wwpn)
971 fc_rport_enter_plogi(rdata);
973 fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
976 mutex_unlock(&rdata->rp_mutex);
977 kref_put(&rdata->kref, fc_rport_destroy);
978 fc_frame_free(rx_fp);
982 kref_put(&rdata->kref, fc_rport_destroy);
984 fc_seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
985 fc_frame_free(rx_fp);
989 * fc_rport_plogi_resp() - Handler for ELS PLOGI responses
990 * @sp: The sequence the PLOGI is on
991 * @fp: The PLOGI response frame
992 * @rdata_arg: The remote port that sent the PLOGI response
994 * Locking Note: This function will be called without the rport lock
995 * held, but it will lock, call an _enter_* function or fc_rport_error
996 * and then unlock the rport.
998 static void fc_rport_plogi_resp(struct fc_seq *sp, struct fc_frame *fp,
1001 struct fc_rport_priv *rdata = rdata_arg;
1002 struct fc_lport *lport = rdata->local_port;
1003 struct fc_els_flogi *plp = NULL;
1008 FC_RPORT_DBG(rdata, "Received a PLOGI %s\n", fc_els_resp_type(fp));
1010 if (fp == ERR_PTR(-FC_EX_CLOSED))
1013 mutex_lock(&rdata->rp_mutex);
1015 if (rdata->rp_state != RPORT_ST_PLOGI) {
1016 FC_RPORT_DBG(rdata, "Received a PLOGI response, but in state "
1017 "%s\n", fc_rport_state(rdata));
1024 fc_rport_error_retry(rdata, PTR_ERR(fp));
1028 op = fc_frame_payload_op(fp);
1029 if (op == ELS_LS_ACC &&
1030 (plp = fc_frame_payload_get(fp, sizeof(*plp))) != NULL) {
1031 rdata->ids.port_name = get_unaligned_be64(&plp->fl_wwpn);
1032 rdata->ids.node_name = get_unaligned_be64(&plp->fl_wwnn);
1034 /* save plogi response sp_features for further reference */
1035 rdata->sp_features = ntohs(plp->fl_csp.sp_features);
1037 if (lport->point_to_multipoint)
1038 fc_rport_login_complete(rdata, fp);
1039 csp_seq = ntohs(plp->fl_csp.sp_tot_seq);
1040 cssp_seq = ntohs(plp->fl_cssp[3 - 1].cp_con_seq);
1041 if (cssp_seq < csp_seq)
1043 rdata->max_seq = csp_seq;
1044 rdata->maxframe_size = fc_plogi_get_maxframe(plp, lport->mfs);
1045 fc_rport_enter_prli(rdata);
1047 struct fc_els_ls_rjt *rjt;
1049 rjt = fc_frame_payload_get(fp, sizeof(*rjt));
1050 FC_RPORT_DBG(rdata, "PLOGI ELS rejected, reason %x expl %x\n",
1051 rjt->er_reason, rjt->er_explan);
1052 fc_rport_error_retry(rdata, -FC_EX_ELS_RJT);
1057 mutex_unlock(&rdata->rp_mutex);
1059 kref_put(&rdata->kref, fc_rport_destroy);
1063 fc_rport_compatible_roles(struct fc_lport *lport, struct fc_rport_priv *rdata)
1065 if (rdata->ids.roles == FC_PORT_ROLE_UNKNOWN)
1067 if ((rdata->ids.roles & FC_PORT_ROLE_FCP_TARGET) &&
1068 (lport->service_params & FCP_SPPF_INIT_FCN))
1070 if ((rdata->ids.roles & FC_PORT_ROLE_FCP_INITIATOR) &&
1071 (lport->service_params & FCP_SPPF_TARG_FCN))
1077 * fc_rport_enter_plogi() - Send Port Login (PLOGI) request
1078 * @rdata: The remote port to send a PLOGI to
1080 * Locking Note: The rport lock is expected to be held before calling
1083 * Reference counting: increments kref when sending ELS
1085 static void fc_rport_enter_plogi(struct fc_rport_priv *rdata)
1087 struct fc_lport *lport = rdata->local_port;
1088 struct fc_frame *fp;
1090 if (!fc_rport_compatible_roles(lport, rdata)) {
1091 FC_RPORT_DBG(rdata, "PLOGI suppressed for incompatible role\n");
1092 fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
1096 FC_RPORT_DBG(rdata, "Port entered PLOGI state from %s state\n",
1097 fc_rport_state(rdata));
1099 fc_rport_state_enter(rdata, RPORT_ST_PLOGI);
1101 rdata->maxframe_size = FC_MIN_MAX_PAYLOAD;
1102 fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi));
1104 FC_RPORT_DBG(rdata, "%s frame alloc failed\n", __func__);
1105 fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
1108 rdata->e_d_tov = lport->e_d_tov;
1110 kref_get(&rdata->kref);
1111 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_PLOGI,
1112 fc_rport_plogi_resp, rdata,
1113 2 * lport->r_a_tov)) {
1114 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
1115 kref_put(&rdata->kref, fc_rport_destroy);
1120 * fc_rport_prli_resp() - Process Login (PRLI) response handler
1121 * @sp: The sequence the PRLI response was on
1122 * @fp: The PRLI response frame
1123 * @rdata_arg: The remote port that sent the PRLI response
1125 * Locking Note: This function will be called without the rport lock
1126 * held, but it will lock, call an _enter_* function or fc_rport_error
1127 * and then unlock the rport.
1129 static void fc_rport_prli_resp(struct fc_seq *sp, struct fc_frame *fp,
1132 struct fc_rport_priv *rdata = rdata_arg;
1134 struct fc_els_prli prli;
1135 struct fc_els_spp spp;
1137 struct fc_els_spp temp_spp;
1138 struct fc_els_ls_rjt *rjt;
1139 struct fc4_prov *prov;
1140 u32 roles = FC_RPORT_ROLE_UNKNOWN;
1143 enum fc_els_spp_resp resp_code;
1145 FC_RPORT_DBG(rdata, "Received a PRLI %s\n", fc_els_resp_type(fp));
1147 if (fp == ERR_PTR(-FC_EX_CLOSED))
1150 mutex_lock(&rdata->rp_mutex);
1152 if (rdata->rp_state != RPORT_ST_PRLI) {
1153 FC_RPORT_DBG(rdata, "Received a PRLI response, but in state "
1154 "%s\n", fc_rport_state(rdata));
1161 fc_rport_error_retry(rdata, PTR_ERR(fp));
1165 /* reinitialize remote port roles */
1166 rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
1168 op = fc_frame_payload_op(fp);
1169 if (op == ELS_LS_ACC) {
1170 pp = fc_frame_payload_get(fp, sizeof(*pp));
1174 resp_code = (pp->spp.spp_flags & FC_SPP_RESP_MASK);
1175 FC_RPORT_DBG(rdata, "PRLI spp_flags = 0x%x spp_type 0x%x\n",
1176 pp->spp.spp_flags, pp->spp.spp_type);
1178 rdata->spp_type = pp->spp.spp_type;
1179 if (resp_code != FC_SPP_RESP_ACK) {
1180 if (resp_code == FC_SPP_RESP_CONF)
1181 fc_rport_error(rdata, -FC_EX_SEQ_ERR);
1183 fc_rport_error_retry(rdata, -FC_EX_SEQ_ERR);
1186 if (pp->prli.prli_spp_len < sizeof(pp->spp))
1189 fcp_parm = ntohl(pp->spp.spp_params);
1190 if (fcp_parm & FCP_SPPF_RETRY)
1191 rdata->flags |= FC_RP_FLAGS_RETRY;
1192 if (fcp_parm & FCP_SPPF_CONF_COMPL)
1193 rdata->flags |= FC_RP_FLAGS_CONF_REQ;
1196 * Call prli provider if we should act as a target
1198 if (rdata->spp_type < FC_FC4_PROV_SIZE) {
1199 prov = fc_passive_prov[rdata->spp_type];
1201 memset(&temp_spp, 0, sizeof(temp_spp));
1202 prov->prli(rdata, pp->prli.prli_spp_len,
1203 &pp->spp, &temp_spp);
1207 * Check if the image pair could be established
1209 if (rdata->spp_type != FC_TYPE_FCP ||
1210 !(pp->spp.spp_flags & FC_SPP_EST_IMG_PAIR)) {
1212 * Nope; we can't use this port as a target.
1214 fcp_parm &= ~FCP_SPPF_TARG_FCN;
1216 rdata->supported_classes = FC_COS_CLASS3;
1217 if (fcp_parm & FCP_SPPF_INIT_FCN)
1218 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1219 if (fcp_parm & FCP_SPPF_TARG_FCN)
1220 roles |= FC_RPORT_ROLE_FCP_TARGET;
1222 rdata->ids.roles = roles;
1223 fc_rport_enter_rtv(rdata);
1226 rjt = fc_frame_payload_get(fp, sizeof(*rjt));
1227 FC_RPORT_DBG(rdata, "PRLI ELS rejected, reason %x expl %x\n",
1228 rjt->er_reason, rjt->er_explan);
1229 fc_rport_error_retry(rdata, FC_EX_ELS_RJT);
1235 mutex_unlock(&rdata->rp_mutex);
1237 kref_put(&rdata->kref, fc_rport_destroy);
1241 * fc_rport_enter_prli() - Send Process Login (PRLI) request
1242 * @rdata: The remote port to send the PRLI request to
1244 * Locking Note: The rport lock is expected to be held before calling
1247 * Reference counting: increments kref when sending ELS
1249 static void fc_rport_enter_prli(struct fc_rport_priv *rdata)
1251 struct fc_lport *lport = rdata->local_port;
1253 struct fc_els_prli prli;
1254 struct fc_els_spp spp;
1256 struct fc_frame *fp;
1257 struct fc4_prov *prov;
1260 * If the rport is one of the well known addresses
1261 * we skip PRLI and RTV and go straight to READY.
1263 if (rdata->ids.port_id >= FC_FID_DOM_MGR) {
1264 fc_rport_enter_ready(rdata);
1269 * And if the local port does not support the initiator function
1270 * there's no need to send a PRLI, either.
1272 if (!(lport->service_params & FCP_SPPF_INIT_FCN)) {
1273 fc_rport_enter_ready(rdata);
1277 FC_RPORT_DBG(rdata, "Port entered PRLI state from %s state\n",
1278 fc_rport_state(rdata));
1280 fc_rport_state_enter(rdata, RPORT_ST_PRLI);
1282 fp = fc_frame_alloc(lport, sizeof(*pp));
1284 fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
1288 fc_prli_fill(lport, fp);
1290 prov = fc_passive_prov[FC_TYPE_FCP];
1292 pp = fc_frame_payload_get(fp, sizeof(*pp));
1293 prov->prli(rdata, sizeof(pp->spp), NULL, &pp->spp);
1296 fc_fill_fc_hdr(fp, FC_RCTL_ELS_REQ, rdata->ids.port_id,
1297 fc_host_port_id(lport->host), FC_TYPE_ELS,
1298 FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0);
1300 kref_get(&rdata->kref);
1301 if (!fc_exch_seq_send(lport, fp, fc_rport_prli_resp,
1302 NULL, rdata, 2 * lport->r_a_tov)) {
1303 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
1304 kref_put(&rdata->kref, fc_rport_destroy);
1309 * fc_rport_rtv_resp() - Handler for Request Timeout Value (RTV) responses
1310 * @sp: The sequence the RTV was on
1311 * @fp: The RTV response frame
1312 * @rdata_arg: The remote port that sent the RTV response
1314 * Many targets don't seem to support this.
1316 * Locking Note: This function will be called without the rport lock
1317 * held, but it will lock, call an _enter_* function or fc_rport_error
1318 * and then unlock the rport.
1320 static void fc_rport_rtv_resp(struct fc_seq *sp, struct fc_frame *fp,
1323 struct fc_rport_priv *rdata = rdata_arg;
1326 FC_RPORT_DBG(rdata, "Received a RTV %s\n", fc_els_resp_type(fp));
1328 if (fp == ERR_PTR(-FC_EX_CLOSED))
1331 mutex_lock(&rdata->rp_mutex);
1333 if (rdata->rp_state != RPORT_ST_RTV) {
1334 FC_RPORT_DBG(rdata, "Received a RTV response, but in state "
1335 "%s\n", fc_rport_state(rdata));
1342 fc_rport_error(rdata, PTR_ERR(fp));
1346 op = fc_frame_payload_op(fp);
1347 if (op == ELS_LS_ACC) {
1348 struct fc_els_rtv_acc *rtv;
1352 rtv = fc_frame_payload_get(fp, sizeof(*rtv));
1354 toq = ntohl(rtv->rtv_toq);
1355 tov = ntohl(rtv->rtv_r_a_tov);
1358 if (tov > rdata->r_a_tov)
1359 rdata->r_a_tov = tov;
1360 tov = ntohl(rtv->rtv_e_d_tov);
1361 if (toq & FC_ELS_RTV_EDRES)
1365 if (tov > rdata->e_d_tov)
1366 rdata->e_d_tov = tov;
1370 fc_rport_enter_ready(rdata);
1375 mutex_unlock(&rdata->rp_mutex);
1377 kref_put(&rdata->kref, fc_rport_destroy);
1381 * fc_rport_enter_rtv() - Send Request Timeout Value (RTV) request
1382 * @rdata: The remote port to send the RTV request to
1384 * Locking Note: The rport lock is expected to be held before calling
1387 * Reference counting: increments kref when sending ELS
1389 static void fc_rport_enter_rtv(struct fc_rport_priv *rdata)
1391 struct fc_frame *fp;
1392 struct fc_lport *lport = rdata->local_port;
1394 FC_RPORT_DBG(rdata, "Port entered RTV state from %s state\n",
1395 fc_rport_state(rdata));
1397 fc_rport_state_enter(rdata, RPORT_ST_RTV);
1399 fp = fc_frame_alloc(lport, sizeof(struct fc_els_rtv));
1401 fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
1405 kref_get(&rdata->kref);
1406 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_RTV,
1407 fc_rport_rtv_resp, rdata,
1408 2 * lport->r_a_tov)) {
1409 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
1410 kref_put(&rdata->kref, fc_rport_destroy);
1415 * fc_rport_recv_rtv_req() - Handler for Read Timeout Value (RTV) requests
1416 * @rdata: The remote port that sent the RTV request
1417 * @in_fp: The RTV request frame
1419 * Locking Note: Called with the lport and rport locks held.
1421 static void fc_rport_recv_rtv_req(struct fc_rport_priv *rdata,
1422 struct fc_frame *in_fp)
1424 struct fc_lport *lport = rdata->local_port;
1425 struct fc_frame *fp;
1426 struct fc_els_rtv_acc *rtv;
1427 struct fc_seq_els_data rjt_data;
1429 FC_RPORT_DBG(rdata, "Received RTV request\n");
1431 fp = fc_frame_alloc(lport, sizeof(*rtv));
1433 rjt_data.reason = ELS_RJT_UNAB;
1434 rjt_data.explan = ELS_EXPL_INSUF_RES;
1435 fc_seq_els_rsp_send(in_fp, ELS_LS_RJT, &rjt_data);
1438 rtv = fc_frame_payload_get(fp, sizeof(*rtv));
1439 rtv->rtv_cmd = ELS_LS_ACC;
1440 rtv->rtv_r_a_tov = htonl(lport->r_a_tov);
1441 rtv->rtv_e_d_tov = htonl(lport->e_d_tov);
1443 fc_fill_reply_hdr(fp, in_fp, FC_RCTL_ELS_REP, 0);
1444 lport->tt.frame_send(lport, fp);
1446 fc_frame_free(in_fp);
1450 * fc_rport_logo_resp() - Handler for logout (LOGO) responses
1451 * @sp: The sequence the LOGO was on
1452 * @fp: The LOGO response frame
1453 * @lport_arg: The local port
1455 static void fc_rport_logo_resp(struct fc_seq *sp, struct fc_frame *fp,
1458 struct fc_rport_priv *rdata = rdata_arg;
1459 struct fc_lport *lport = rdata->local_port;
1461 FC_RPORT_ID_DBG(lport, fc_seq_exch(sp)->did,
1462 "Received a LOGO %s\n", fc_els_resp_type(fp));
1465 kref_put(&rdata->kref, fc_rport_destroy);
1469 * fc_rport_enter_logo() - Send a logout (LOGO) request
1470 * @rdata: The remote port to send the LOGO request to
1472 * Locking Note: The rport lock is expected to be held before calling
1475 * Reference counting: increments kref when sending ELS
1477 static void fc_rport_enter_logo(struct fc_rport_priv *rdata)
1479 struct fc_lport *lport = rdata->local_port;
1480 struct fc_frame *fp;
1482 FC_RPORT_DBG(rdata, "Port sending LOGO from %s state\n",
1483 fc_rport_state(rdata));
1485 fp = fc_frame_alloc(lport, sizeof(struct fc_els_logo));
1488 kref_get(&rdata->kref);
1489 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_LOGO,
1490 fc_rport_logo_resp, rdata, 0))
1491 kref_put(&rdata->kref, fc_rport_destroy);
1495 * fc_rport_els_adisc_resp() - Handler for Address Discovery (ADISC) responses
1496 * @sp: The sequence the ADISC response was on
1497 * @fp: The ADISC response frame
1498 * @rdata_arg: The remote port that sent the ADISC response
1500 * Locking Note: This function will be called without the rport lock
1501 * held, but it will lock, call an _enter_* function or fc_rport_error
1502 * and then unlock the rport.
1504 static void fc_rport_adisc_resp(struct fc_seq *sp, struct fc_frame *fp,
1507 struct fc_rport_priv *rdata = rdata_arg;
1508 struct fc_els_adisc *adisc;
1511 FC_RPORT_DBG(rdata, "Received a ADISC response\n");
1513 if (fp == ERR_PTR(-FC_EX_CLOSED))
1516 mutex_lock(&rdata->rp_mutex);
1518 if (rdata->rp_state != RPORT_ST_ADISC) {
1519 FC_RPORT_DBG(rdata, "Received a ADISC resp but in state %s\n",
1520 fc_rport_state(rdata));
1527 fc_rport_error(rdata, PTR_ERR(fp));
1532 * If address verification failed. Consider us logged out of the rport.
1533 * Since the rport is still in discovery, we want to be
1534 * logged in, so go to PLOGI state. Otherwise, go back to READY.
1536 op = fc_frame_payload_op(fp);
1537 adisc = fc_frame_payload_get(fp, sizeof(*adisc));
1538 if (op != ELS_LS_ACC || !adisc ||
1539 ntoh24(adisc->adisc_port_id) != rdata->ids.port_id ||
1540 get_unaligned_be64(&adisc->adisc_wwpn) != rdata->ids.port_name ||
1541 get_unaligned_be64(&adisc->adisc_wwnn) != rdata->ids.node_name) {
1542 FC_RPORT_DBG(rdata, "ADISC error or mismatch\n");
1543 fc_rport_enter_flogi(rdata);
1545 FC_RPORT_DBG(rdata, "ADISC OK\n");
1546 fc_rport_enter_ready(rdata);
1551 mutex_unlock(&rdata->rp_mutex);
1553 kref_put(&rdata->kref, fc_rport_destroy);
1557 * fc_rport_enter_adisc() - Send Address Discover (ADISC) request
1558 * @rdata: The remote port to send the ADISC request to
1560 * Locking Note: The rport lock is expected to be held before calling
1563 * Reference counting: increments kref when sending ELS
1565 static void fc_rport_enter_adisc(struct fc_rport_priv *rdata)
1567 struct fc_lport *lport = rdata->local_port;
1568 struct fc_frame *fp;
1570 FC_RPORT_DBG(rdata, "sending ADISC from %s state\n",
1571 fc_rport_state(rdata));
1573 fc_rport_state_enter(rdata, RPORT_ST_ADISC);
1575 fp = fc_frame_alloc(lport, sizeof(struct fc_els_adisc));
1577 fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
1580 kref_get(&rdata->kref);
1581 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_ADISC,
1582 fc_rport_adisc_resp, rdata,
1583 2 * lport->r_a_tov)) {
1584 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
1585 kref_put(&rdata->kref, fc_rport_destroy);
1590 * fc_rport_recv_adisc_req() - Handler for Address Discovery (ADISC) requests
1591 * @rdata: The remote port that sent the ADISC request
1592 * @in_fp: The ADISC request frame
1594 * Locking Note: Called with the lport and rport locks held.
1596 static void fc_rport_recv_adisc_req(struct fc_rport_priv *rdata,
1597 struct fc_frame *in_fp)
1599 struct fc_lport *lport = rdata->local_port;
1600 struct fc_frame *fp;
1601 struct fc_els_adisc *adisc;
1602 struct fc_seq_els_data rjt_data;
1604 FC_RPORT_DBG(rdata, "Received ADISC request\n");
1606 adisc = fc_frame_payload_get(in_fp, sizeof(*adisc));
1608 rjt_data.reason = ELS_RJT_PROT;
1609 rjt_data.explan = ELS_EXPL_INV_LEN;
1610 fc_seq_els_rsp_send(in_fp, ELS_LS_RJT, &rjt_data);
1614 fp = fc_frame_alloc(lport, sizeof(*adisc));
1617 fc_adisc_fill(lport, fp);
1618 adisc = fc_frame_payload_get(fp, sizeof(*adisc));
1619 adisc->adisc_cmd = ELS_LS_ACC;
1620 fc_fill_reply_hdr(fp, in_fp, FC_RCTL_ELS_REP, 0);
1621 lport->tt.frame_send(lport, fp);
1623 fc_frame_free(in_fp);
1627 * fc_rport_recv_rls_req() - Handle received Read Link Status request
1628 * @rdata: The remote port that sent the RLS request
1629 * @rx_fp: The PRLI request frame
1631 * Locking Note: The rport lock is expected to be held before calling
1634 static void fc_rport_recv_rls_req(struct fc_rport_priv *rdata,
1635 struct fc_frame *rx_fp)
1638 struct fc_lport *lport = rdata->local_port;
1639 struct fc_frame *fp;
1640 struct fc_els_rls *rls;
1641 struct fc_els_rls_resp *rsp;
1642 struct fc_els_lesb *lesb;
1643 struct fc_seq_els_data rjt_data;
1644 struct fc_host_statistics *hst;
1646 FC_RPORT_DBG(rdata, "Received RLS request while in state %s\n",
1647 fc_rport_state(rdata));
1649 rls = fc_frame_payload_get(rx_fp, sizeof(*rls));
1651 rjt_data.reason = ELS_RJT_PROT;
1652 rjt_data.explan = ELS_EXPL_INV_LEN;
1656 fp = fc_frame_alloc(lport, sizeof(*rsp));
1658 rjt_data.reason = ELS_RJT_UNAB;
1659 rjt_data.explan = ELS_EXPL_INSUF_RES;
1663 rsp = fc_frame_payload_get(fp, sizeof(*rsp));
1664 memset(rsp, 0, sizeof(*rsp));
1665 rsp->rls_cmd = ELS_LS_ACC;
1666 lesb = &rsp->rls_lesb;
1667 if (lport->tt.get_lesb) {
1668 /* get LESB from LLD if it supports it */
1669 lport->tt.get_lesb(lport, lesb);
1671 fc_get_host_stats(lport->host);
1672 hst = &lport->host_stats;
1673 lesb->lesb_link_fail = htonl(hst->link_failure_count);
1674 lesb->lesb_sync_loss = htonl(hst->loss_of_sync_count);
1675 lesb->lesb_sig_loss = htonl(hst->loss_of_signal_count);
1676 lesb->lesb_prim_err = htonl(hst->prim_seq_protocol_err_count);
1677 lesb->lesb_inv_word = htonl(hst->invalid_tx_word_count);
1678 lesb->lesb_inv_crc = htonl(hst->invalid_crc_count);
1681 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
1682 lport->tt.frame_send(lport, fp);
1686 fc_seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
1688 fc_frame_free(rx_fp);
1692 * fc_rport_recv_els_req() - Handler for validated ELS requests
1693 * @lport: The local port that received the ELS request
1694 * @fp: The ELS request frame
1696 * Handle incoming ELS requests that require port login.
1697 * The ELS opcode has already been validated by the caller.
1699 * Locking Note: Called with the lport lock held.
1701 * Reference counting: does not modify kref
1703 static void fc_rport_recv_els_req(struct fc_lport *lport, struct fc_frame *fp)
1705 struct fc_rport_priv *rdata;
1706 struct fc_seq_els_data els_data;
1708 rdata = fc_rport_lookup(lport, fc_frame_sid(fp));
1710 FC_RPORT_ID_DBG(lport, fc_frame_sid(fp),
1711 "Received ELS 0x%02x from non-logged-in port\n",
1712 fc_frame_payload_op(fp));
1716 mutex_lock(&rdata->rp_mutex);
1718 switch (rdata->rp_state) {
1721 case RPORT_ST_READY:
1722 case RPORT_ST_ADISC:
1724 case RPORT_ST_PLOGI:
1725 if (fc_frame_payload_op(fp) == ELS_PRLI) {
1726 FC_RPORT_DBG(rdata, "Reject ELS PRLI "
1727 "while in state %s\n",
1728 fc_rport_state(rdata));
1729 mutex_unlock(&rdata->rp_mutex);
1730 kref_put(&rdata->kref, fc_rport_destroy);
1735 "Reject ELS 0x%02x while in state %s\n",
1736 fc_frame_payload_op(fp), fc_rport_state(rdata));
1737 mutex_unlock(&rdata->rp_mutex);
1738 kref_put(&rdata->kref, fc_rport_destroy);
1742 switch (fc_frame_payload_op(fp)) {
1744 fc_rport_recv_prli_req(rdata, fp);
1747 fc_rport_recv_prlo_req(rdata, fp);
1750 fc_rport_recv_adisc_req(rdata, fp);
1753 fc_seq_els_rsp_send(fp, ELS_RRQ, NULL);
1757 fc_seq_els_rsp_send(fp, ELS_REC, NULL);
1761 fc_rport_recv_rls_req(rdata, fp);
1764 fc_rport_recv_rtv_req(rdata, fp);
1767 fc_frame_free(fp); /* can't happen */
1771 mutex_unlock(&rdata->rp_mutex);
1772 kref_put(&rdata->kref, fc_rport_destroy);
1776 els_data.reason = ELS_RJT_UNAB;
1777 els_data.explan = ELS_EXPL_PLOGI_REQD;
1778 fc_seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
1783 els_data.reason = ELS_RJT_BUSY;
1784 els_data.explan = ELS_EXPL_NONE;
1785 fc_seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
1791 * fc_rport_recv_req() - Handler for requests
1792 * @lport: The local port that received the request
1793 * @fp: The request frame
1795 * Locking Note: Called with the lport lock held.
1797 * Reference counting: does not modify kref
1799 void fc_rport_recv_req(struct fc_lport *lport, struct fc_frame *fp)
1801 struct fc_seq_els_data els_data;
1804 * Handle FLOGI, PLOGI and LOGO requests separately, since they
1805 * don't require prior login.
1806 * Check for unsupported opcodes first and reject them.
1807 * For some ops, it would be incorrect to reject with "PLOGI required".
1809 switch (fc_frame_payload_op(fp)) {
1811 fc_rport_recv_flogi_req(lport, fp);
1814 fc_rport_recv_plogi_req(lport, fp);
1817 fc_rport_recv_logo_req(lport, fp);
1826 fc_rport_recv_els_req(lport, fp);
1829 els_data.reason = ELS_RJT_UNSUP;
1830 els_data.explan = ELS_EXPL_NONE;
1831 fc_seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
1836 EXPORT_SYMBOL(fc_rport_recv_req);
1839 * fc_rport_recv_plogi_req() - Handler for Port Login (PLOGI) requests
1840 * @lport: The local port that received the PLOGI request
1841 * @rx_fp: The PLOGI request frame
1843 * Locking Note: The rport lock is held before calling this function.
1845 * Reference counting: increments kref on return
1847 static void fc_rport_recv_plogi_req(struct fc_lport *lport,
1848 struct fc_frame *rx_fp)
1850 struct fc_disc *disc;
1851 struct fc_rport_priv *rdata;
1852 struct fc_frame *fp = rx_fp;
1853 struct fc_els_flogi *pl;
1854 struct fc_seq_els_data rjt_data;
1857 sid = fc_frame_sid(fp);
1859 FC_RPORT_ID_DBG(lport, sid, "Received PLOGI request\n");
1861 pl = fc_frame_payload_get(fp, sizeof(*pl));
1863 FC_RPORT_ID_DBG(lport, sid, "Received PLOGI too short\n");
1864 rjt_data.reason = ELS_RJT_PROT;
1865 rjt_data.explan = ELS_EXPL_INV_LEN;
1869 disc = &lport->disc;
1870 mutex_lock(&disc->disc_mutex);
1871 rdata = fc_rport_create(lport, sid);
1873 mutex_unlock(&disc->disc_mutex);
1874 rjt_data.reason = ELS_RJT_UNAB;
1875 rjt_data.explan = ELS_EXPL_INSUF_RES;
1879 mutex_lock(&rdata->rp_mutex);
1880 mutex_unlock(&disc->disc_mutex);
1882 rdata->ids.port_name = get_unaligned_be64(&pl->fl_wwpn);
1883 rdata->ids.node_name = get_unaligned_be64(&pl->fl_wwnn);
1886 * If the rport was just created, possibly due to the incoming PLOGI,
1887 * set the state appropriately and accept the PLOGI.
1889 * If we had also sent a PLOGI, and if the received PLOGI is from a
1890 * higher WWPN, we accept it, otherwise an LS_RJT is sent with reason
1891 * "command already in progress".
1893 * XXX TBD: If the session was ready before, the PLOGI should result in
1894 * all outstanding exchanges being reset.
1896 switch (rdata->rp_state) {
1898 FC_RPORT_DBG(rdata, "Received PLOGI in INIT state\n");
1900 case RPORT_ST_PLOGI_WAIT:
1901 FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI_WAIT state\n");
1903 case RPORT_ST_PLOGI:
1904 FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI state\n");
1905 if (rdata->ids.port_name < lport->wwpn) {
1906 mutex_unlock(&rdata->rp_mutex);
1907 rjt_data.reason = ELS_RJT_INPROG;
1908 rjt_data.explan = ELS_EXPL_NONE;
1914 case RPORT_ST_READY:
1915 case RPORT_ST_ADISC:
1916 FC_RPORT_DBG(rdata, "Received PLOGI in logged-in state %d "
1917 "- ignored for now\n", rdata->rp_state);
1918 /* XXX TBD - should reset */
1920 case RPORT_ST_FLOGI:
1921 case RPORT_ST_DELETE:
1922 FC_RPORT_DBG(rdata, "Received PLOGI in state %s - send busy\n",
1923 fc_rport_state(rdata));
1924 mutex_unlock(&rdata->rp_mutex);
1925 rjt_data.reason = ELS_RJT_BUSY;
1926 rjt_data.explan = ELS_EXPL_NONE;
1929 if (!fc_rport_compatible_roles(lport, rdata)) {
1930 FC_RPORT_DBG(rdata, "Received PLOGI for incompatible role\n");
1931 mutex_unlock(&rdata->rp_mutex);
1932 rjt_data.reason = ELS_RJT_LOGIC;
1933 rjt_data.explan = ELS_EXPL_NONE;
1938 * Get session payload size from incoming PLOGI.
1940 rdata->maxframe_size = fc_plogi_get_maxframe(pl, lport->mfs);
1943 * Send LS_ACC. If this fails, the originator should retry.
1945 fp = fc_frame_alloc(lport, sizeof(*pl));
1949 fc_plogi_fill(lport, fp, ELS_LS_ACC);
1950 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
1951 lport->tt.frame_send(lport, fp);
1952 fc_rport_enter_prli(rdata);
1954 mutex_unlock(&rdata->rp_mutex);
1955 fc_frame_free(rx_fp);
1959 fc_seq_els_rsp_send(fp, ELS_LS_RJT, &rjt_data);
1964 * fc_rport_recv_prli_req() - Handler for process login (PRLI) requests
1965 * @rdata: The remote port that sent the PRLI request
1966 * @rx_fp: The PRLI request frame
1968 * Locking Note: The rport lock is expected to be held before calling
1971 static void fc_rport_recv_prli_req(struct fc_rport_priv *rdata,
1972 struct fc_frame *rx_fp)
1974 struct fc_lport *lport = rdata->local_port;
1975 struct fc_frame *fp;
1977 struct fc_els_prli prli;
1978 struct fc_els_spp spp;
1980 struct fc_els_spp *rspp; /* request service param page */
1981 struct fc_els_spp *spp; /* response spp */
1984 enum fc_els_spp_resp resp;
1985 struct fc_seq_els_data rjt_data;
1986 struct fc4_prov *prov;
1988 FC_RPORT_DBG(rdata, "Received PRLI request while in state %s\n",
1989 fc_rport_state(rdata));
1991 len = fr_len(rx_fp) - sizeof(struct fc_frame_header);
1992 pp = fc_frame_payload_get(rx_fp, sizeof(*pp));
1995 plen = ntohs(pp->prli.prli_len);
1996 if ((plen % 4) != 0 || plen > len || plen < 16)
2000 plen = pp->prli.prli_spp_len;
2001 if ((plen % 4) != 0 || plen < sizeof(*spp) ||
2002 plen > len || len < sizeof(*pp) || plen < 12)
2006 fp = fc_frame_alloc(lport, len);
2008 rjt_data.reason = ELS_RJT_UNAB;
2009 rjt_data.explan = ELS_EXPL_INSUF_RES;
2012 pp = fc_frame_payload_get(fp, len);
2015 pp->prli.prli_cmd = ELS_LS_ACC;
2016 pp->prli.prli_spp_len = plen;
2017 pp->prli.prli_len = htons(len);
2018 len -= sizeof(struct fc_els_prli);
2021 * Go through all the service parameter pages and build
2022 * response. If plen indicates longer SPP than standard,
2023 * use that. The entire response has been pre-cleared above.
2026 mutex_lock(&fc_prov_mutex);
2027 while (len >= plen) {
2028 rdata->spp_type = rspp->spp_type;
2029 spp->spp_type = rspp->spp_type;
2030 spp->spp_type_ext = rspp->spp_type_ext;
2033 if (rspp->spp_type < FC_FC4_PROV_SIZE) {
2034 enum fc_els_spp_resp active = 0, passive = 0;
2036 prov = fc_active_prov[rspp->spp_type];
2038 active = prov->prli(rdata, plen, rspp, spp);
2039 prov = fc_passive_prov[rspp->spp_type];
2041 passive = prov->prli(rdata, plen, rspp, spp);
2042 if (!active || passive == FC_SPP_RESP_ACK)
2046 FC_RPORT_DBG(rdata, "PRLI rspp type %x "
2047 "active %x passive %x\n",
2048 rspp->spp_type, active, passive);
2051 if (spp->spp_flags & FC_SPP_EST_IMG_PAIR)
2052 resp |= FC_SPP_RESP_CONF;
2054 resp |= FC_SPP_RESP_INVL;
2056 spp->spp_flags |= resp;
2058 rspp = (struct fc_els_spp *)((char *)rspp + plen);
2059 spp = (struct fc_els_spp *)((char *)spp + plen);
2061 mutex_unlock(&fc_prov_mutex);
2064 * Send LS_ACC. If this fails, the originator should retry.
2066 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
2067 lport->tt.frame_send(lport, fp);
2072 rjt_data.reason = ELS_RJT_PROT;
2073 rjt_data.explan = ELS_EXPL_INV_LEN;
2075 fc_seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
2077 fc_frame_free(rx_fp);
2081 * fc_rport_recv_prlo_req() - Handler for process logout (PRLO) requests
2082 * @rdata: The remote port that sent the PRLO request
2083 * @rx_fp: The PRLO request frame
2085 * Locking Note: The rport lock is expected to be held before calling
2088 static void fc_rport_recv_prlo_req(struct fc_rport_priv *rdata,
2089 struct fc_frame *rx_fp)
2091 struct fc_lport *lport = rdata->local_port;
2092 struct fc_frame *fp;
2094 struct fc_els_prlo prlo;
2095 struct fc_els_spp spp;
2097 struct fc_els_spp *rspp; /* request service param page */
2098 struct fc_els_spp *spp; /* response spp */
2101 struct fc_seq_els_data rjt_data;
2103 FC_RPORT_DBG(rdata, "Received PRLO request while in state %s\n",
2104 fc_rport_state(rdata));
2106 len = fr_len(rx_fp) - sizeof(struct fc_frame_header);
2107 pp = fc_frame_payload_get(rx_fp, sizeof(*pp));
2110 plen = ntohs(pp->prlo.prlo_len);
2118 fp = fc_frame_alloc(lport, len);
2120 rjt_data.reason = ELS_RJT_UNAB;
2121 rjt_data.explan = ELS_EXPL_INSUF_RES;
2125 pp = fc_frame_payload_get(fp, len);
2128 pp->prlo.prlo_cmd = ELS_LS_ACC;
2129 pp->prlo.prlo_obs = 0x10;
2130 pp->prlo.prlo_len = htons(len);
2132 spp->spp_type = rspp->spp_type;
2133 spp->spp_type_ext = rspp->spp_type_ext;
2134 spp->spp_flags = FC_SPP_RESP_ACK;
2136 fc_rport_enter_prli(rdata);
2138 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
2139 lport->tt.frame_send(lport, fp);
2143 rjt_data.reason = ELS_RJT_PROT;
2144 rjt_data.explan = ELS_EXPL_INV_LEN;
2146 fc_seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
2148 fc_frame_free(rx_fp);
2152 * fc_rport_recv_logo_req() - Handler for logout (LOGO) requests
2153 * @lport: The local port that received the LOGO request
2154 * @fp: The LOGO request frame
2156 * Locking Note: The rport lock is expected to be held before calling
2159 * Reference counting: drops kref on return
2161 static void fc_rport_recv_logo_req(struct fc_lport *lport, struct fc_frame *fp)
2163 struct fc_rport_priv *rdata;
2166 fc_seq_els_rsp_send(fp, ELS_LS_ACC, NULL);
2168 sid = fc_frame_sid(fp);
2170 rdata = fc_rport_lookup(lport, sid);
2172 mutex_lock(&rdata->rp_mutex);
2173 FC_RPORT_DBG(rdata, "Received LOGO request while in state %s\n",
2174 fc_rport_state(rdata));
2176 fc_rport_enter_delete(rdata, RPORT_EV_STOP);
2177 mutex_unlock(&rdata->rp_mutex);
2178 kref_put(&rdata->kref, fc_rport_destroy);
2180 FC_RPORT_ID_DBG(lport, sid,
2181 "Received LOGO from non-logged-in port\n");
2186 * fc_rport_flush_queue() - Flush the rport_event_queue
2188 void fc_rport_flush_queue(void)
2190 flush_workqueue(rport_event_queue);
2192 EXPORT_SYMBOL(fc_rport_flush_queue);
2195 * fc_rport_fcp_prli() - Handle incoming PRLI for the FCP initiator.
2196 * @rdata: remote port private
2197 * @spp_len: service parameter page length
2198 * @rspp: received service parameter page
2199 * @spp: response service parameter page
2201 * Returns the value for the response code to be placed in spp_flags;
2202 * Returns 0 if not an initiator.
2204 static int fc_rport_fcp_prli(struct fc_rport_priv *rdata, u32 spp_len,
2205 const struct fc_els_spp *rspp,
2206 struct fc_els_spp *spp)
2208 struct fc_lport *lport = rdata->local_port;
2211 fcp_parm = ntohl(rspp->spp_params);
2212 rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
2213 if (fcp_parm & FCP_SPPF_INIT_FCN)
2214 rdata->ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2215 if (fcp_parm & FCP_SPPF_TARG_FCN)
2216 rdata->ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2217 if (fcp_parm & FCP_SPPF_RETRY)
2218 rdata->flags |= FC_RP_FLAGS_RETRY;
2219 rdata->supported_classes = FC_COS_CLASS3;
2221 if (!(lport->service_params & FCP_SPPF_INIT_FCN))
2224 spp->spp_flags |= rspp->spp_flags & FC_SPP_EST_IMG_PAIR;
2227 * OR in our service parameters with other providers (target), if any.
2229 fcp_parm = ntohl(spp->spp_params);
2230 spp->spp_params = htonl(fcp_parm | lport->service_params);
2231 return FC_SPP_RESP_ACK;
2235 * FC-4 provider ops for FCP initiator.
2237 struct fc4_prov fc_rport_fcp_init = {
2238 .prli = fc_rport_fcp_prli,
2242 * fc_rport_t0_prli() - Handle incoming PRLI parameters for type 0
2243 * @rdata: remote port private
2244 * @spp_len: service parameter page length
2245 * @rspp: received service parameter page
2246 * @spp: response service parameter page
2248 static int fc_rport_t0_prli(struct fc_rport_priv *rdata, u32 spp_len,
2249 const struct fc_els_spp *rspp,
2250 struct fc_els_spp *spp)
2252 if (rspp->spp_flags & FC_SPP_EST_IMG_PAIR)
2253 return FC_SPP_RESP_INVL;
2254 return FC_SPP_RESP_ACK;
2258 * FC-4 provider ops for type 0 service parameters.
2260 * This handles the special case of type 0 which is always successful
2261 * but doesn't do anything otherwise.
2263 struct fc4_prov fc_rport_t0_prov = {
2264 .prli = fc_rport_t0_prli,
2268 * fc_setup_rport() - Initialize the rport_event_queue
2270 int fc_setup_rport(void)
2272 rport_event_queue = create_singlethread_workqueue("fc_rport_eq");
2273 if (!rport_event_queue)
2279 * fc_destroy_rport() - Destroy the rport_event_queue
2281 void fc_destroy_rport(void)
2283 destroy_workqueue(rport_event_queue);
2287 * fc_rport_terminate_io() - Stop all outstanding I/O on a remote port
2288 * @rport: The remote port whose I/O should be terminated
2290 void fc_rport_terminate_io(struct fc_rport *rport)
2292 struct fc_rport_libfc_priv *rpriv = rport->dd_data;
2293 struct fc_lport *lport = rpriv->local_port;
2295 lport->tt.exch_mgr_reset(lport, 0, rport->port_id);
2296 lport->tt.exch_mgr_reset(lport, rport->port_id, 0);
2298 EXPORT_SYMBOL(fc_rport_terminate_io);