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);
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 static void fc_rport_state_enter(struct fc_rport_priv *rdata,
255 enum fc_rport_state new)
257 lockdep_assert_held(&rdata->rp_mutex);
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 * Allow state change into DELETE only once.
479 * Call queue_work only if there's no event already pending.
480 * Set the new event so that the old pending event will not occur.
481 * Since we have the mutex, even if fc_rport_work() is already started,
482 * it'll see the new event.
484 * Reference counting: does not modify kref
486 static void fc_rport_enter_delete(struct fc_rport_priv *rdata,
487 enum fc_rport_event event)
489 lockdep_assert_held(&rdata->rp_mutex);
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 * Reference counting: schedules workqueue, does not modify kref
557 static void fc_rport_enter_ready(struct fc_rport_priv *rdata)
559 lockdep_assert_held(&rdata->rp_mutex);
561 fc_rport_state_enter(rdata, RPORT_ST_READY);
563 FC_RPORT_DBG(rdata, "Port is Ready\n");
565 kref_get(&rdata->kref);
566 if (rdata->event == RPORT_EV_NONE &&
567 !queue_work(rport_event_queue, &rdata->event_work))
568 kref_put(&rdata->kref, fc_rport_destroy);
570 rdata->event = RPORT_EV_READY;
574 * fc_rport_timeout() - Handler for the retry_work timer
575 * @work: Handle to the remote port that has timed out
577 * Locking Note: Called without the rport lock held. This
578 * function will hold the rport lock, call an _enter_*
579 * function and then unlock the rport.
581 * Reference counting: Drops kref on return.
583 static void fc_rport_timeout(struct work_struct *work)
585 struct fc_rport_priv *rdata =
586 container_of(work, struct fc_rport_priv, retry_work.work);
588 mutex_lock(&rdata->rp_mutex);
589 FC_RPORT_DBG(rdata, "Port timeout, state %s\n", fc_rport_state(rdata));
591 switch (rdata->rp_state) {
593 fc_rport_enter_flogi(rdata);
596 fc_rport_enter_plogi(rdata);
599 fc_rport_enter_prli(rdata);
602 fc_rport_enter_rtv(rdata);
605 fc_rport_enter_adisc(rdata);
607 case RPORT_ST_PLOGI_WAIT:
610 case RPORT_ST_DELETE:
614 mutex_unlock(&rdata->rp_mutex);
615 kref_put(&rdata->kref, fc_rport_destroy);
619 * fc_rport_error() - Error handler, called once retries have been exhausted
620 * @rdata: The remote port the error is happened on
621 * @err: The error code
623 * Reference counting: does not modify kref
625 static void fc_rport_error(struct fc_rport_priv *rdata, int err)
627 struct fc_lport *lport = rdata->local_port;
629 lockdep_assert_held(&rdata->rp_mutex);
631 FC_RPORT_DBG(rdata, "Error %d in state %s, retries %d\n",
632 -err, fc_rport_state(rdata), rdata->retries);
634 switch (rdata->rp_state) {
636 rdata->flags &= ~FC_RP_STARTED;
637 fc_rport_enter_delete(rdata, RPORT_EV_FAILED);
640 if (lport->point_to_multipoint) {
641 rdata->flags &= ~FC_RP_STARTED;
642 fc_rport_enter_delete(rdata, RPORT_EV_FAILED);
644 fc_rport_enter_logo(rdata);
647 fc_rport_enter_ready(rdata);
651 fc_rport_enter_logo(rdata);
653 case RPORT_ST_PLOGI_WAIT:
654 case RPORT_ST_DELETE:
662 * fc_rport_error_retry() - Handler for remote port state retries
663 * @rdata: The remote port whose state is to be retried
664 * @err: The error code
666 * If the error was an exchange timeout retry immediately,
667 * otherwise wait for E_D_TOV.
669 * Reference counting: increments kref when scheduling retry_work
671 static void fc_rport_error_retry(struct fc_rport_priv *rdata, int err)
673 unsigned long delay = msecs_to_jiffies(rdata->e_d_tov);
675 lockdep_assert_held(&rdata->rp_mutex);
677 /* make sure this isn't an FC_EX_CLOSED error, never retry those */
678 if (err == -FC_EX_CLOSED)
681 if (rdata->retries < rdata->local_port->max_rport_retry_count) {
682 FC_RPORT_DBG(rdata, "Error %d in state %s, retrying\n",
683 err, fc_rport_state(rdata));
685 /* no additional delay on exchange timeouts */
686 if (err == -FC_EX_TIMEOUT)
688 kref_get(&rdata->kref);
689 if (!schedule_delayed_work(&rdata->retry_work, delay))
690 kref_put(&rdata->kref, fc_rport_destroy);
695 fc_rport_error(rdata, err);
699 * fc_rport_login_complete() - Handle parameters and completion of p-mp login.
700 * @rdata: The remote port which we logged into or which logged into us.
701 * @fp: The FLOGI or PLOGI request or response frame
703 * Returns non-zero error if a problem is detected with the frame.
704 * Does not free the frame.
706 * This is only used in point-to-multipoint mode for FIP currently.
708 static int fc_rport_login_complete(struct fc_rport_priv *rdata,
711 struct fc_lport *lport = rdata->local_port;
712 struct fc_els_flogi *flogi;
713 unsigned int e_d_tov;
716 flogi = fc_frame_payload_get(fp, sizeof(*flogi));
720 csp_flags = ntohs(flogi->fl_csp.sp_features);
722 if (fc_frame_payload_op(fp) == ELS_FLOGI) {
723 if (csp_flags & FC_SP_FT_FPORT) {
724 FC_RPORT_DBG(rdata, "Fabric bit set in FLOGI\n");
730 * E_D_TOV is not valid on an incoming FLOGI request.
732 e_d_tov = ntohl(flogi->fl_csp.sp_e_d_tov);
733 if (csp_flags & FC_SP_FT_EDTR)
735 if (e_d_tov > rdata->e_d_tov)
736 rdata->e_d_tov = e_d_tov;
738 rdata->maxframe_size = fc_plogi_get_maxframe(flogi, lport->mfs);
743 * fc_rport_flogi_resp() - Handle response to FLOGI request for p-mp mode
744 * @sp: The sequence that the FLOGI was on
745 * @fp: The FLOGI response frame
746 * @rp_arg: The remote port that received the FLOGI response
748 static void fc_rport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp,
751 struct fc_rport_priv *rdata = rp_arg;
752 struct fc_lport *lport = rdata->local_port;
753 struct fc_els_flogi *flogi;
754 unsigned int r_a_tov;
758 FC_RPORT_DBG(rdata, "Received a FLOGI %s\n",
759 IS_ERR(fp) ? "error" : fc_els_resp_type(fp));
761 if (fp == ERR_PTR(-FC_EX_CLOSED))
764 mutex_lock(&rdata->rp_mutex);
766 if (rdata->rp_state != RPORT_ST_FLOGI) {
767 FC_RPORT_DBG(rdata, "Received a FLOGI response, but in state "
768 "%s\n", fc_rport_state(rdata));
775 fc_rport_error(rdata, PTR_ERR(fp));
778 opcode = fc_frame_payload_op(fp);
779 if (opcode == ELS_LS_RJT) {
780 struct fc_els_ls_rjt *rjt;
782 rjt = fc_frame_payload_get(fp, sizeof(*rjt));
783 FC_RPORT_DBG(rdata, "FLOGI ELS rejected, reason %x expl %x\n",
784 rjt->er_reason, rjt->er_explan);
785 err = -FC_EX_ELS_RJT;
787 } else if (opcode != ELS_LS_ACC) {
788 FC_RPORT_DBG(rdata, "FLOGI ELS invalid opcode %x\n", opcode);
789 err = -FC_EX_ELS_RJT;
792 if (fc_rport_login_complete(rdata, fp)) {
793 FC_RPORT_DBG(rdata, "FLOGI failed, no login\n");
794 err = -FC_EX_INV_LOGIN;
798 flogi = fc_frame_payload_get(fp, sizeof(*flogi));
800 err = -FC_EX_ALLOC_ERR;
803 r_a_tov = ntohl(flogi->fl_csp.sp_r_a_tov);
804 if (r_a_tov > rdata->r_a_tov)
805 rdata->r_a_tov = r_a_tov;
807 if (rdata->ids.port_name < lport->wwpn)
808 fc_rport_enter_plogi(rdata);
810 fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
814 mutex_unlock(&rdata->rp_mutex);
816 kref_put(&rdata->kref, fc_rport_destroy);
819 FC_RPORT_DBG(rdata, "Bad FLOGI response\n");
820 fc_rport_error_retry(rdata, err);
825 * fc_rport_enter_flogi() - Send a FLOGI request to the remote port for p-mp
826 * @rdata: The remote port to send a FLOGI to
828 * Reference counting: increments kref when sending ELS
830 static void fc_rport_enter_flogi(struct fc_rport_priv *rdata)
832 struct fc_lport *lport = rdata->local_port;
835 lockdep_assert_held(&rdata->rp_mutex);
837 if (!lport->point_to_multipoint)
838 return fc_rport_enter_plogi(rdata);
840 FC_RPORT_DBG(rdata, "Entered FLOGI state from %s state\n",
841 fc_rport_state(rdata));
843 fc_rport_state_enter(rdata, RPORT_ST_FLOGI);
845 fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi));
847 return fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
849 kref_get(&rdata->kref);
850 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_FLOGI,
851 fc_rport_flogi_resp, rdata,
852 2 * lport->r_a_tov)) {
853 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
854 kref_put(&rdata->kref, fc_rport_destroy);
859 * fc_rport_recv_flogi_req() - Handle Fabric Login (FLOGI) request in p-mp mode
860 * @lport: The local port that received the PLOGI request
861 * @rx_fp: The PLOGI request frame
863 * Reference counting: drops kref on return
865 static void fc_rport_recv_flogi_req(struct fc_lport *lport,
866 struct fc_frame *rx_fp)
868 struct fc_disc *disc;
869 struct fc_els_flogi *flp;
870 struct fc_rport_priv *rdata;
871 struct fc_frame *fp = rx_fp;
872 struct fc_seq_els_data rjt_data;
875 sid = fc_frame_sid(fp);
877 FC_RPORT_ID_DBG(lport, sid, "Received FLOGI request\n");
880 if (!lport->point_to_multipoint) {
881 rjt_data.reason = ELS_RJT_UNSUP;
882 rjt_data.explan = ELS_EXPL_NONE;
886 flp = fc_frame_payload_get(fp, sizeof(*flp));
888 rjt_data.reason = ELS_RJT_LOGIC;
889 rjt_data.explan = ELS_EXPL_INV_LEN;
893 rdata = fc_rport_lookup(lport, sid);
895 rjt_data.reason = ELS_RJT_FIP;
896 rjt_data.explan = ELS_EXPL_NOT_NEIGHBOR;
899 mutex_lock(&rdata->rp_mutex);
901 FC_RPORT_DBG(rdata, "Received FLOGI in %s state\n",
902 fc_rport_state(rdata));
904 switch (rdata->rp_state) {
907 * If received the FLOGI request on RPORT which is INIT state
908 * (means not transition to FLOGI either fc_rport timeout
909 * function didn;t trigger or this end hasn;t received
910 * beacon yet from other end. In that case only, allow RPORT
911 * state machine to continue, otherwise fall through which
912 * causes the code to send reject response.
913 * NOTE; Not checking for FIP->state such as VNMP_UP or
914 * VNMP_CLAIM because if FIP state is not one of those,
915 * RPORT wouldn;t have created and 'rport_lookup' would have
916 * failed anyway in that case.
919 case RPORT_ST_DELETE:
920 mutex_unlock(&rdata->rp_mutex);
921 rjt_data.reason = ELS_RJT_FIP;
922 rjt_data.explan = ELS_EXPL_NOT_NEIGHBOR;
925 case RPORT_ST_PLOGI_WAIT:
933 * Set the remote port to be deleted and to then restart.
934 * This queues work to be sure exchanges are reset.
936 fc_rport_enter_delete(rdata, RPORT_EV_LOGO);
937 mutex_unlock(&rdata->rp_mutex);
938 rjt_data.reason = ELS_RJT_BUSY;
939 rjt_data.explan = ELS_EXPL_NONE;
942 if (fc_rport_login_complete(rdata, fp)) {
943 mutex_unlock(&rdata->rp_mutex);
944 rjt_data.reason = ELS_RJT_LOGIC;
945 rjt_data.explan = ELS_EXPL_NONE;
949 fp = fc_frame_alloc(lport, sizeof(*flp));
953 fc_flogi_fill(lport, fp);
954 flp = fc_frame_payload_get(fp, sizeof(*flp));
955 flp->fl_cmd = ELS_LS_ACC;
957 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
958 lport->tt.frame_send(lport, fp);
961 * Do not proceed with the state machine if our
962 * FLOGI has crossed with an FLOGI from the
963 * remote port; wait for the FLOGI response instead.
965 if (rdata->rp_state != RPORT_ST_FLOGI) {
966 if (rdata->ids.port_name < lport->wwpn)
967 fc_rport_enter_plogi(rdata);
969 fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
972 mutex_unlock(&rdata->rp_mutex);
973 kref_put(&rdata->kref, fc_rport_destroy);
974 fc_frame_free(rx_fp);
978 kref_put(&rdata->kref, fc_rport_destroy);
980 fc_seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
981 fc_frame_free(rx_fp);
985 * fc_rport_plogi_resp() - Handler for ELS PLOGI responses
986 * @sp: The sequence the PLOGI is on
987 * @fp: The PLOGI response frame
988 * @rdata_arg: The remote port that sent the PLOGI response
990 * Locking Note: This function will be called without the rport lock
991 * held, but it will lock, call an _enter_* function or fc_rport_error
992 * and then unlock the rport.
994 static void fc_rport_plogi_resp(struct fc_seq *sp, struct fc_frame *fp,
997 struct fc_rport_priv *rdata = rdata_arg;
998 struct fc_lport *lport = rdata->local_port;
999 struct fc_els_flogi *plp = NULL;
1004 FC_RPORT_DBG(rdata, "Received a PLOGI %s\n", fc_els_resp_type(fp));
1006 if (fp == ERR_PTR(-FC_EX_CLOSED))
1009 mutex_lock(&rdata->rp_mutex);
1011 if (rdata->rp_state != RPORT_ST_PLOGI) {
1012 FC_RPORT_DBG(rdata, "Received a PLOGI response, but in state "
1013 "%s\n", fc_rport_state(rdata));
1020 fc_rport_error_retry(rdata, PTR_ERR(fp));
1024 op = fc_frame_payload_op(fp);
1025 if (op == ELS_LS_ACC &&
1026 (plp = fc_frame_payload_get(fp, sizeof(*plp))) != NULL) {
1027 rdata->ids.port_name = get_unaligned_be64(&plp->fl_wwpn);
1028 rdata->ids.node_name = get_unaligned_be64(&plp->fl_wwnn);
1030 /* save plogi response sp_features for further reference */
1031 rdata->sp_features = ntohs(plp->fl_csp.sp_features);
1033 if (lport->point_to_multipoint)
1034 fc_rport_login_complete(rdata, fp);
1035 csp_seq = ntohs(plp->fl_csp.sp_tot_seq);
1036 cssp_seq = ntohs(plp->fl_cssp[3 - 1].cp_con_seq);
1037 if (cssp_seq < csp_seq)
1039 rdata->max_seq = csp_seq;
1040 rdata->maxframe_size = fc_plogi_get_maxframe(plp, lport->mfs);
1041 fc_rport_enter_prli(rdata);
1043 struct fc_els_ls_rjt *rjt;
1045 rjt = fc_frame_payload_get(fp, sizeof(*rjt));
1046 FC_RPORT_DBG(rdata, "PLOGI ELS rejected, reason %x expl %x\n",
1047 rjt->er_reason, rjt->er_explan);
1048 fc_rport_error_retry(rdata, -FC_EX_ELS_RJT);
1053 mutex_unlock(&rdata->rp_mutex);
1055 kref_put(&rdata->kref, fc_rport_destroy);
1059 fc_rport_compatible_roles(struct fc_lport *lport, struct fc_rport_priv *rdata)
1061 if (rdata->ids.roles == FC_PORT_ROLE_UNKNOWN)
1063 if ((rdata->ids.roles & FC_PORT_ROLE_FCP_TARGET) &&
1064 (lport->service_params & FCP_SPPF_INIT_FCN))
1066 if ((rdata->ids.roles & FC_PORT_ROLE_FCP_INITIATOR) &&
1067 (lport->service_params & FCP_SPPF_TARG_FCN))
1073 * fc_rport_enter_plogi() - Send Port Login (PLOGI) request
1074 * @rdata: The remote port to send a PLOGI to
1076 * Reference counting: increments kref when sending ELS
1078 static void fc_rport_enter_plogi(struct fc_rport_priv *rdata)
1080 struct fc_lport *lport = rdata->local_port;
1081 struct fc_frame *fp;
1083 lockdep_assert_held(&rdata->rp_mutex);
1085 if (!fc_rport_compatible_roles(lport, rdata)) {
1086 FC_RPORT_DBG(rdata, "PLOGI suppressed for incompatible role\n");
1087 fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
1091 FC_RPORT_DBG(rdata, "Port entered PLOGI state from %s state\n",
1092 fc_rport_state(rdata));
1094 fc_rport_state_enter(rdata, RPORT_ST_PLOGI);
1096 rdata->maxframe_size = FC_MIN_MAX_PAYLOAD;
1097 fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi));
1099 FC_RPORT_DBG(rdata, "%s frame alloc failed\n", __func__);
1100 fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
1103 rdata->e_d_tov = lport->e_d_tov;
1105 kref_get(&rdata->kref);
1106 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_PLOGI,
1107 fc_rport_plogi_resp, rdata,
1108 2 * lport->r_a_tov)) {
1109 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
1110 kref_put(&rdata->kref, fc_rport_destroy);
1115 * fc_rport_prli_resp() - Process Login (PRLI) response handler
1116 * @sp: The sequence the PRLI response was on
1117 * @fp: The PRLI response frame
1118 * @rdata_arg: The remote port that sent the PRLI response
1120 * Locking Note: This function will be called without the rport lock
1121 * held, but it will lock, call an _enter_* function or fc_rport_error
1122 * and then unlock the rport.
1124 static void fc_rport_prli_resp(struct fc_seq *sp, struct fc_frame *fp,
1127 struct fc_rport_priv *rdata = rdata_arg;
1129 struct fc_els_prli prli;
1130 struct fc_els_spp spp;
1132 struct fc_els_spp temp_spp;
1133 struct fc_els_ls_rjt *rjt;
1134 struct fc4_prov *prov;
1135 u32 roles = FC_RPORT_ROLE_UNKNOWN;
1138 enum fc_els_spp_resp resp_code;
1140 FC_RPORT_DBG(rdata, "Received a PRLI %s\n", fc_els_resp_type(fp));
1142 if (fp == ERR_PTR(-FC_EX_CLOSED))
1145 mutex_lock(&rdata->rp_mutex);
1147 if (rdata->rp_state != RPORT_ST_PRLI) {
1148 FC_RPORT_DBG(rdata, "Received a PRLI response, but in state "
1149 "%s\n", fc_rport_state(rdata));
1156 fc_rport_error_retry(rdata, PTR_ERR(fp));
1160 /* reinitialize remote port roles */
1161 rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
1163 op = fc_frame_payload_op(fp);
1164 if (op == ELS_LS_ACC) {
1165 pp = fc_frame_payload_get(fp, sizeof(*pp));
1169 resp_code = (pp->spp.spp_flags & FC_SPP_RESP_MASK);
1170 FC_RPORT_DBG(rdata, "PRLI spp_flags = 0x%x spp_type 0x%x\n",
1171 pp->spp.spp_flags, pp->spp.spp_type);
1173 rdata->spp_type = pp->spp.spp_type;
1174 if (resp_code != FC_SPP_RESP_ACK) {
1175 if (resp_code == FC_SPP_RESP_CONF)
1176 fc_rport_error(rdata, -FC_EX_SEQ_ERR);
1178 fc_rport_error_retry(rdata, -FC_EX_SEQ_ERR);
1181 if (pp->prli.prli_spp_len < sizeof(pp->spp))
1184 fcp_parm = ntohl(pp->spp.spp_params);
1185 if (fcp_parm & FCP_SPPF_RETRY)
1186 rdata->flags |= FC_RP_FLAGS_RETRY;
1187 if (fcp_parm & FCP_SPPF_CONF_COMPL)
1188 rdata->flags |= FC_RP_FLAGS_CONF_REQ;
1191 * Call prli provider if we should act as a target
1193 if (rdata->spp_type < FC_FC4_PROV_SIZE) {
1194 prov = fc_passive_prov[rdata->spp_type];
1196 memset(&temp_spp, 0, sizeof(temp_spp));
1197 prov->prli(rdata, pp->prli.prli_spp_len,
1198 &pp->spp, &temp_spp);
1202 * Check if the image pair could be established
1204 if (rdata->spp_type != FC_TYPE_FCP ||
1205 !(pp->spp.spp_flags & FC_SPP_EST_IMG_PAIR)) {
1207 * Nope; we can't use this port as a target.
1209 fcp_parm &= ~FCP_SPPF_TARG_FCN;
1211 rdata->supported_classes = FC_COS_CLASS3;
1212 if (fcp_parm & FCP_SPPF_INIT_FCN)
1213 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1214 if (fcp_parm & FCP_SPPF_TARG_FCN)
1215 roles |= FC_RPORT_ROLE_FCP_TARGET;
1217 rdata->ids.roles = roles;
1218 fc_rport_enter_rtv(rdata);
1221 rjt = fc_frame_payload_get(fp, sizeof(*rjt));
1222 FC_RPORT_DBG(rdata, "PRLI ELS rejected, reason %x expl %x\n",
1223 rjt->er_reason, rjt->er_explan);
1224 fc_rport_error_retry(rdata, FC_EX_ELS_RJT);
1230 mutex_unlock(&rdata->rp_mutex);
1232 kref_put(&rdata->kref, fc_rport_destroy);
1236 * fc_rport_enter_prli() - Send Process Login (PRLI) request
1237 * @rdata: The remote port to send the PRLI request to
1239 * Reference counting: increments kref when sending ELS
1241 static void fc_rport_enter_prli(struct fc_rport_priv *rdata)
1243 struct fc_lport *lport = rdata->local_port;
1245 struct fc_els_prli prli;
1246 struct fc_els_spp spp;
1248 struct fc_frame *fp;
1249 struct fc4_prov *prov;
1251 lockdep_assert_held(&rdata->rp_mutex);
1254 * If the rport is one of the well known addresses
1255 * we skip PRLI and RTV and go straight to READY.
1257 if (rdata->ids.port_id >= FC_FID_DOM_MGR) {
1258 fc_rport_enter_ready(rdata);
1263 * And if the local port does not support the initiator function
1264 * there's no need to send a PRLI, either.
1266 if (!(lport->service_params & FCP_SPPF_INIT_FCN)) {
1267 fc_rport_enter_ready(rdata);
1271 FC_RPORT_DBG(rdata, "Port entered PRLI state from %s state\n",
1272 fc_rport_state(rdata));
1274 fc_rport_state_enter(rdata, RPORT_ST_PRLI);
1276 fp = fc_frame_alloc(lport, sizeof(*pp));
1278 fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
1282 fc_prli_fill(lport, fp);
1284 prov = fc_passive_prov[FC_TYPE_FCP];
1286 pp = fc_frame_payload_get(fp, sizeof(*pp));
1287 prov->prli(rdata, sizeof(pp->spp), NULL, &pp->spp);
1290 fc_fill_fc_hdr(fp, FC_RCTL_ELS_REQ, rdata->ids.port_id,
1291 fc_host_port_id(lport->host), FC_TYPE_ELS,
1292 FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0);
1294 kref_get(&rdata->kref);
1295 if (!fc_exch_seq_send(lport, fp, fc_rport_prli_resp,
1296 NULL, rdata, 2 * lport->r_a_tov)) {
1297 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
1298 kref_put(&rdata->kref, fc_rport_destroy);
1303 * fc_rport_rtv_resp() - Handler for Request Timeout Value (RTV) responses
1304 * @sp: The sequence the RTV was on
1305 * @fp: The RTV response frame
1306 * @rdata_arg: The remote port that sent the RTV response
1308 * Many targets don't seem to support this.
1310 * Locking Note: This function will be called without the rport lock
1311 * held, but it will lock, call an _enter_* function or fc_rport_error
1312 * and then unlock the rport.
1314 static void fc_rport_rtv_resp(struct fc_seq *sp, struct fc_frame *fp,
1317 struct fc_rport_priv *rdata = rdata_arg;
1320 FC_RPORT_DBG(rdata, "Received a RTV %s\n", fc_els_resp_type(fp));
1322 if (fp == ERR_PTR(-FC_EX_CLOSED))
1325 mutex_lock(&rdata->rp_mutex);
1327 if (rdata->rp_state != RPORT_ST_RTV) {
1328 FC_RPORT_DBG(rdata, "Received a RTV response, but in state "
1329 "%s\n", fc_rport_state(rdata));
1336 fc_rport_error(rdata, PTR_ERR(fp));
1340 op = fc_frame_payload_op(fp);
1341 if (op == ELS_LS_ACC) {
1342 struct fc_els_rtv_acc *rtv;
1346 rtv = fc_frame_payload_get(fp, sizeof(*rtv));
1348 toq = ntohl(rtv->rtv_toq);
1349 tov = ntohl(rtv->rtv_r_a_tov);
1352 if (tov > rdata->r_a_tov)
1353 rdata->r_a_tov = tov;
1354 tov = ntohl(rtv->rtv_e_d_tov);
1355 if (toq & FC_ELS_RTV_EDRES)
1359 if (tov > rdata->e_d_tov)
1360 rdata->e_d_tov = tov;
1364 fc_rport_enter_ready(rdata);
1369 mutex_unlock(&rdata->rp_mutex);
1371 kref_put(&rdata->kref, fc_rport_destroy);
1375 * fc_rport_enter_rtv() - Send Request Timeout Value (RTV) request
1376 * @rdata: The remote port to send the RTV request to
1378 * Reference counting: increments kref when sending ELS
1380 static void fc_rport_enter_rtv(struct fc_rport_priv *rdata)
1382 struct fc_frame *fp;
1383 struct fc_lport *lport = rdata->local_port;
1385 lockdep_assert_held(&rdata->rp_mutex);
1387 FC_RPORT_DBG(rdata, "Port entered RTV state from %s state\n",
1388 fc_rport_state(rdata));
1390 fc_rport_state_enter(rdata, RPORT_ST_RTV);
1392 fp = fc_frame_alloc(lport, sizeof(struct fc_els_rtv));
1394 fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
1398 kref_get(&rdata->kref);
1399 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_RTV,
1400 fc_rport_rtv_resp, rdata,
1401 2 * lport->r_a_tov)) {
1402 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
1403 kref_put(&rdata->kref, fc_rport_destroy);
1408 * fc_rport_recv_rtv_req() - Handler for Read Timeout Value (RTV) requests
1409 * @rdata: The remote port that sent the RTV request
1410 * @in_fp: The RTV request frame
1412 static void fc_rport_recv_rtv_req(struct fc_rport_priv *rdata,
1413 struct fc_frame *in_fp)
1415 struct fc_lport *lport = rdata->local_port;
1416 struct fc_frame *fp;
1417 struct fc_els_rtv_acc *rtv;
1418 struct fc_seq_els_data rjt_data;
1420 lockdep_assert_held(&rdata->rp_mutex);
1421 lockdep_assert_held(&lport->lp_mutex);
1423 FC_RPORT_DBG(rdata, "Received RTV request\n");
1425 fp = fc_frame_alloc(lport, sizeof(*rtv));
1427 rjt_data.reason = ELS_RJT_UNAB;
1428 rjt_data.explan = ELS_EXPL_INSUF_RES;
1429 fc_seq_els_rsp_send(in_fp, ELS_LS_RJT, &rjt_data);
1432 rtv = fc_frame_payload_get(fp, sizeof(*rtv));
1433 rtv->rtv_cmd = ELS_LS_ACC;
1434 rtv->rtv_r_a_tov = htonl(lport->r_a_tov);
1435 rtv->rtv_e_d_tov = htonl(lport->e_d_tov);
1437 fc_fill_reply_hdr(fp, in_fp, FC_RCTL_ELS_REP, 0);
1438 lport->tt.frame_send(lport, fp);
1440 fc_frame_free(in_fp);
1444 * fc_rport_logo_resp() - Handler for logout (LOGO) responses
1445 * @sp: The sequence the LOGO was on
1446 * @fp: The LOGO response frame
1447 * @lport_arg: The local port
1449 static void fc_rport_logo_resp(struct fc_seq *sp, struct fc_frame *fp,
1452 struct fc_rport_priv *rdata = rdata_arg;
1453 struct fc_lport *lport = rdata->local_port;
1455 FC_RPORT_ID_DBG(lport, fc_seq_exch(sp)->did,
1456 "Received a LOGO %s\n", fc_els_resp_type(fp));
1459 kref_put(&rdata->kref, fc_rport_destroy);
1463 * fc_rport_enter_logo() - Send a logout (LOGO) request
1464 * @rdata: The remote port to send the LOGO request to
1466 * Reference counting: increments kref when sending ELS
1468 static void fc_rport_enter_logo(struct fc_rport_priv *rdata)
1470 struct fc_lport *lport = rdata->local_port;
1471 struct fc_frame *fp;
1473 lockdep_assert_held(&rdata->rp_mutex);
1475 FC_RPORT_DBG(rdata, "Port sending LOGO from %s state\n",
1476 fc_rport_state(rdata));
1478 fp = fc_frame_alloc(lport, sizeof(struct fc_els_logo));
1481 kref_get(&rdata->kref);
1482 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_LOGO,
1483 fc_rport_logo_resp, rdata, 0))
1484 kref_put(&rdata->kref, fc_rport_destroy);
1488 * fc_rport_els_adisc_resp() - Handler for Address Discovery (ADISC) responses
1489 * @sp: The sequence the ADISC response was on
1490 * @fp: The ADISC response frame
1491 * @rdata_arg: The remote port that sent the ADISC response
1493 * Locking Note: This function will be called without the rport lock
1494 * held, but it will lock, call an _enter_* function or fc_rport_error
1495 * and then unlock the rport.
1497 static void fc_rport_adisc_resp(struct fc_seq *sp, struct fc_frame *fp,
1500 struct fc_rport_priv *rdata = rdata_arg;
1501 struct fc_els_adisc *adisc;
1504 FC_RPORT_DBG(rdata, "Received a ADISC response\n");
1506 if (fp == ERR_PTR(-FC_EX_CLOSED))
1509 mutex_lock(&rdata->rp_mutex);
1511 if (rdata->rp_state != RPORT_ST_ADISC) {
1512 FC_RPORT_DBG(rdata, "Received a ADISC resp but in state %s\n",
1513 fc_rport_state(rdata));
1520 fc_rport_error(rdata, PTR_ERR(fp));
1525 * If address verification failed. Consider us logged out of the rport.
1526 * Since the rport is still in discovery, we want to be
1527 * logged in, so go to PLOGI state. Otherwise, go back to READY.
1529 op = fc_frame_payload_op(fp);
1530 adisc = fc_frame_payload_get(fp, sizeof(*adisc));
1531 if (op != ELS_LS_ACC || !adisc ||
1532 ntoh24(adisc->adisc_port_id) != rdata->ids.port_id ||
1533 get_unaligned_be64(&adisc->adisc_wwpn) != rdata->ids.port_name ||
1534 get_unaligned_be64(&adisc->adisc_wwnn) != rdata->ids.node_name) {
1535 FC_RPORT_DBG(rdata, "ADISC error or mismatch\n");
1536 fc_rport_enter_flogi(rdata);
1538 FC_RPORT_DBG(rdata, "ADISC OK\n");
1539 fc_rport_enter_ready(rdata);
1544 mutex_unlock(&rdata->rp_mutex);
1546 kref_put(&rdata->kref, fc_rport_destroy);
1550 * fc_rport_enter_adisc() - Send Address Discover (ADISC) request
1551 * @rdata: The remote port to send the ADISC request to
1553 * Reference counting: increments kref when sending ELS
1555 static void fc_rport_enter_adisc(struct fc_rport_priv *rdata)
1557 struct fc_lport *lport = rdata->local_port;
1558 struct fc_frame *fp;
1560 lockdep_assert_held(&rdata->rp_mutex);
1562 FC_RPORT_DBG(rdata, "sending ADISC from %s state\n",
1563 fc_rport_state(rdata));
1565 fc_rport_state_enter(rdata, RPORT_ST_ADISC);
1567 fp = fc_frame_alloc(lport, sizeof(struct fc_els_adisc));
1569 fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
1572 kref_get(&rdata->kref);
1573 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_ADISC,
1574 fc_rport_adisc_resp, rdata,
1575 2 * lport->r_a_tov)) {
1576 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
1577 kref_put(&rdata->kref, fc_rport_destroy);
1582 * fc_rport_recv_adisc_req() - Handler for Address Discovery (ADISC) requests
1583 * @rdata: The remote port that sent the ADISC request
1584 * @in_fp: The ADISC request frame
1586 static void fc_rport_recv_adisc_req(struct fc_rport_priv *rdata,
1587 struct fc_frame *in_fp)
1589 struct fc_lport *lport = rdata->local_port;
1590 struct fc_frame *fp;
1591 struct fc_els_adisc *adisc;
1592 struct fc_seq_els_data rjt_data;
1594 lockdep_assert_held(&rdata->rp_mutex);
1595 lockdep_assert_held(&lport->lp_mutex);
1597 FC_RPORT_DBG(rdata, "Received ADISC request\n");
1599 adisc = fc_frame_payload_get(in_fp, sizeof(*adisc));
1601 rjt_data.reason = ELS_RJT_PROT;
1602 rjt_data.explan = ELS_EXPL_INV_LEN;
1603 fc_seq_els_rsp_send(in_fp, ELS_LS_RJT, &rjt_data);
1607 fp = fc_frame_alloc(lport, sizeof(*adisc));
1610 fc_adisc_fill(lport, fp);
1611 adisc = fc_frame_payload_get(fp, sizeof(*adisc));
1612 adisc->adisc_cmd = ELS_LS_ACC;
1613 fc_fill_reply_hdr(fp, in_fp, FC_RCTL_ELS_REP, 0);
1614 lport->tt.frame_send(lport, fp);
1616 fc_frame_free(in_fp);
1620 * fc_rport_recv_rls_req() - Handle received Read Link Status request
1621 * @rdata: The remote port that sent the RLS request
1622 * @rx_fp: The PRLI request frame
1624 static void fc_rport_recv_rls_req(struct fc_rport_priv *rdata,
1625 struct fc_frame *rx_fp)
1628 struct fc_lport *lport = rdata->local_port;
1629 struct fc_frame *fp;
1630 struct fc_els_rls *rls;
1631 struct fc_els_rls_resp *rsp;
1632 struct fc_els_lesb *lesb;
1633 struct fc_seq_els_data rjt_data;
1634 struct fc_host_statistics *hst;
1636 lockdep_assert_held(&rdata->rp_mutex);
1638 FC_RPORT_DBG(rdata, "Received RLS request while in state %s\n",
1639 fc_rport_state(rdata));
1641 rls = fc_frame_payload_get(rx_fp, sizeof(*rls));
1643 rjt_data.reason = ELS_RJT_PROT;
1644 rjt_data.explan = ELS_EXPL_INV_LEN;
1648 fp = fc_frame_alloc(lport, sizeof(*rsp));
1650 rjt_data.reason = ELS_RJT_UNAB;
1651 rjt_data.explan = ELS_EXPL_INSUF_RES;
1655 rsp = fc_frame_payload_get(fp, sizeof(*rsp));
1656 memset(rsp, 0, sizeof(*rsp));
1657 rsp->rls_cmd = ELS_LS_ACC;
1658 lesb = &rsp->rls_lesb;
1659 if (lport->tt.get_lesb) {
1660 /* get LESB from LLD if it supports it */
1661 lport->tt.get_lesb(lport, lesb);
1663 fc_get_host_stats(lport->host);
1664 hst = &lport->host_stats;
1665 lesb->lesb_link_fail = htonl(hst->link_failure_count);
1666 lesb->lesb_sync_loss = htonl(hst->loss_of_sync_count);
1667 lesb->lesb_sig_loss = htonl(hst->loss_of_signal_count);
1668 lesb->lesb_prim_err = htonl(hst->prim_seq_protocol_err_count);
1669 lesb->lesb_inv_word = htonl(hst->invalid_tx_word_count);
1670 lesb->lesb_inv_crc = htonl(hst->invalid_crc_count);
1673 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
1674 lport->tt.frame_send(lport, fp);
1678 fc_seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
1680 fc_frame_free(rx_fp);
1684 * fc_rport_recv_els_req() - Handler for validated ELS requests
1685 * @lport: The local port that received the ELS request
1686 * @fp: The ELS request frame
1688 * Handle incoming ELS requests that require port login.
1689 * The ELS opcode has already been validated by the caller.
1691 * Reference counting: does not modify kref
1693 static void fc_rport_recv_els_req(struct fc_lport *lport, struct fc_frame *fp)
1695 struct fc_rport_priv *rdata;
1696 struct fc_seq_els_data els_data;
1698 lockdep_assert_held(&lport->lp_mutex);
1700 rdata = fc_rport_lookup(lport, fc_frame_sid(fp));
1702 FC_RPORT_ID_DBG(lport, fc_frame_sid(fp),
1703 "Received ELS 0x%02x from non-logged-in port\n",
1704 fc_frame_payload_op(fp));
1708 mutex_lock(&rdata->rp_mutex);
1710 switch (rdata->rp_state) {
1713 case RPORT_ST_READY:
1714 case RPORT_ST_ADISC:
1716 case RPORT_ST_PLOGI:
1717 if (fc_frame_payload_op(fp) == ELS_PRLI) {
1718 FC_RPORT_DBG(rdata, "Reject ELS PRLI "
1719 "while in state %s\n",
1720 fc_rport_state(rdata));
1721 mutex_unlock(&rdata->rp_mutex);
1722 kref_put(&rdata->kref, fc_rport_destroy);
1727 "Reject ELS 0x%02x while in state %s\n",
1728 fc_frame_payload_op(fp), fc_rport_state(rdata));
1729 mutex_unlock(&rdata->rp_mutex);
1730 kref_put(&rdata->kref, fc_rport_destroy);
1734 switch (fc_frame_payload_op(fp)) {
1736 fc_rport_recv_prli_req(rdata, fp);
1739 fc_rport_recv_prlo_req(rdata, fp);
1742 fc_rport_recv_adisc_req(rdata, fp);
1745 fc_seq_els_rsp_send(fp, ELS_RRQ, NULL);
1749 fc_seq_els_rsp_send(fp, ELS_REC, NULL);
1753 fc_rport_recv_rls_req(rdata, fp);
1756 fc_rport_recv_rtv_req(rdata, fp);
1759 fc_frame_free(fp); /* can't happen */
1763 mutex_unlock(&rdata->rp_mutex);
1764 kref_put(&rdata->kref, fc_rport_destroy);
1768 els_data.reason = ELS_RJT_UNAB;
1769 els_data.explan = ELS_EXPL_PLOGI_REQD;
1770 fc_seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
1775 els_data.reason = ELS_RJT_BUSY;
1776 els_data.explan = ELS_EXPL_NONE;
1777 fc_seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
1783 * fc_rport_recv_req() - Handler for requests
1784 * @lport: The local port that received the request
1785 * @fp: The request frame
1787 * Reference counting: does not modify kref
1789 void fc_rport_recv_req(struct fc_lport *lport, struct fc_frame *fp)
1791 struct fc_seq_els_data els_data;
1793 lockdep_assert_held(&lport->lp_mutex);
1796 * Handle FLOGI, PLOGI and LOGO requests separately, since they
1797 * don't require prior login.
1798 * Check for unsupported opcodes first and reject them.
1799 * For some ops, it would be incorrect to reject with "PLOGI required".
1801 switch (fc_frame_payload_op(fp)) {
1803 fc_rport_recv_flogi_req(lport, fp);
1806 fc_rport_recv_plogi_req(lport, fp);
1809 fc_rport_recv_logo_req(lport, fp);
1818 fc_rport_recv_els_req(lport, fp);
1821 els_data.reason = ELS_RJT_UNSUP;
1822 els_data.explan = ELS_EXPL_NONE;
1823 fc_seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
1828 EXPORT_SYMBOL(fc_rport_recv_req);
1831 * fc_rport_recv_plogi_req() - Handler for Port Login (PLOGI) requests
1832 * @lport: The local port that received the PLOGI request
1833 * @rx_fp: The PLOGI request frame
1835 * Reference counting: increments kref on return
1837 static void fc_rport_recv_plogi_req(struct fc_lport *lport,
1838 struct fc_frame *rx_fp)
1840 struct fc_disc *disc;
1841 struct fc_rport_priv *rdata;
1842 struct fc_frame *fp = rx_fp;
1843 struct fc_els_flogi *pl;
1844 struct fc_seq_els_data rjt_data;
1847 lockdep_assert_held(&lport->lp_mutex);
1849 sid = fc_frame_sid(fp);
1851 FC_RPORT_ID_DBG(lport, sid, "Received PLOGI request\n");
1853 pl = fc_frame_payload_get(fp, sizeof(*pl));
1855 FC_RPORT_ID_DBG(lport, sid, "Received PLOGI too short\n");
1856 rjt_data.reason = ELS_RJT_PROT;
1857 rjt_data.explan = ELS_EXPL_INV_LEN;
1861 disc = &lport->disc;
1862 mutex_lock(&disc->disc_mutex);
1863 rdata = fc_rport_create(lport, sid);
1865 mutex_unlock(&disc->disc_mutex);
1866 rjt_data.reason = ELS_RJT_UNAB;
1867 rjt_data.explan = ELS_EXPL_INSUF_RES;
1871 mutex_lock(&rdata->rp_mutex);
1872 mutex_unlock(&disc->disc_mutex);
1874 rdata->ids.port_name = get_unaligned_be64(&pl->fl_wwpn);
1875 rdata->ids.node_name = get_unaligned_be64(&pl->fl_wwnn);
1878 * If the rport was just created, possibly due to the incoming PLOGI,
1879 * set the state appropriately and accept the PLOGI.
1881 * If we had also sent a PLOGI, and if the received PLOGI is from a
1882 * higher WWPN, we accept it, otherwise an LS_RJT is sent with reason
1883 * "command already in progress".
1885 * XXX TBD: If the session was ready before, the PLOGI should result in
1886 * all outstanding exchanges being reset.
1888 switch (rdata->rp_state) {
1890 FC_RPORT_DBG(rdata, "Received PLOGI in INIT state\n");
1892 case RPORT_ST_PLOGI_WAIT:
1893 FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI_WAIT state\n");
1895 case RPORT_ST_PLOGI:
1896 FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI state\n");
1897 if (rdata->ids.port_name < lport->wwpn) {
1898 mutex_unlock(&rdata->rp_mutex);
1899 rjt_data.reason = ELS_RJT_INPROG;
1900 rjt_data.explan = ELS_EXPL_NONE;
1906 case RPORT_ST_READY:
1907 case RPORT_ST_ADISC:
1908 FC_RPORT_DBG(rdata, "Received PLOGI in logged-in state %d "
1909 "- ignored for now\n", rdata->rp_state);
1910 /* XXX TBD - should reset */
1912 case RPORT_ST_FLOGI:
1913 case RPORT_ST_DELETE:
1914 FC_RPORT_DBG(rdata, "Received PLOGI in state %s - send busy\n",
1915 fc_rport_state(rdata));
1916 mutex_unlock(&rdata->rp_mutex);
1917 rjt_data.reason = ELS_RJT_BUSY;
1918 rjt_data.explan = ELS_EXPL_NONE;
1921 if (!fc_rport_compatible_roles(lport, rdata)) {
1922 FC_RPORT_DBG(rdata, "Received PLOGI for incompatible role\n");
1923 mutex_unlock(&rdata->rp_mutex);
1924 rjt_data.reason = ELS_RJT_LOGIC;
1925 rjt_data.explan = ELS_EXPL_NONE;
1930 * Get session payload size from incoming PLOGI.
1932 rdata->maxframe_size = fc_plogi_get_maxframe(pl, lport->mfs);
1935 * Send LS_ACC. If this fails, the originator should retry.
1937 fp = fc_frame_alloc(lport, sizeof(*pl));
1941 fc_plogi_fill(lport, fp, ELS_LS_ACC);
1942 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
1943 lport->tt.frame_send(lport, fp);
1944 fc_rport_enter_prli(rdata);
1946 mutex_unlock(&rdata->rp_mutex);
1947 fc_frame_free(rx_fp);
1951 fc_seq_els_rsp_send(fp, ELS_LS_RJT, &rjt_data);
1956 * fc_rport_recv_prli_req() - Handler for process login (PRLI) requests
1957 * @rdata: The remote port that sent the PRLI request
1958 * @rx_fp: The PRLI request frame
1960 static void fc_rport_recv_prli_req(struct fc_rport_priv *rdata,
1961 struct fc_frame *rx_fp)
1963 struct fc_lport *lport = rdata->local_port;
1964 struct fc_frame *fp;
1966 struct fc_els_prli prli;
1967 struct fc_els_spp spp;
1969 struct fc_els_spp *rspp; /* request service param page */
1970 struct fc_els_spp *spp; /* response spp */
1973 enum fc_els_spp_resp resp;
1974 struct fc_seq_els_data rjt_data;
1975 struct fc4_prov *prov;
1977 lockdep_assert_held(&rdata->rp_mutex);
1979 FC_RPORT_DBG(rdata, "Received PRLI request while in state %s\n",
1980 fc_rport_state(rdata));
1982 len = fr_len(rx_fp) - sizeof(struct fc_frame_header);
1983 pp = fc_frame_payload_get(rx_fp, sizeof(*pp));
1986 plen = ntohs(pp->prli.prli_len);
1987 if ((plen % 4) != 0 || plen > len || plen < 16)
1991 plen = pp->prli.prli_spp_len;
1992 if ((plen % 4) != 0 || plen < sizeof(*spp) ||
1993 plen > len || len < sizeof(*pp) || plen < 12)
1997 fp = fc_frame_alloc(lport, len);
1999 rjt_data.reason = ELS_RJT_UNAB;
2000 rjt_data.explan = ELS_EXPL_INSUF_RES;
2003 pp = fc_frame_payload_get(fp, len);
2006 pp->prli.prli_cmd = ELS_LS_ACC;
2007 pp->prli.prli_spp_len = plen;
2008 pp->prli.prli_len = htons(len);
2009 len -= sizeof(struct fc_els_prli);
2012 * Go through all the service parameter pages and build
2013 * response. If plen indicates longer SPP than standard,
2014 * use that. The entire response has been pre-cleared above.
2017 mutex_lock(&fc_prov_mutex);
2018 while (len >= plen) {
2019 rdata->spp_type = rspp->spp_type;
2020 spp->spp_type = rspp->spp_type;
2021 spp->spp_type_ext = rspp->spp_type_ext;
2024 if (rspp->spp_type < FC_FC4_PROV_SIZE) {
2025 enum fc_els_spp_resp active = 0, passive = 0;
2027 prov = fc_active_prov[rspp->spp_type];
2029 active = prov->prli(rdata, plen, rspp, spp);
2030 prov = fc_passive_prov[rspp->spp_type];
2032 passive = prov->prli(rdata, plen, rspp, spp);
2033 if (!active || passive == FC_SPP_RESP_ACK)
2037 FC_RPORT_DBG(rdata, "PRLI rspp type %x "
2038 "active %x passive %x\n",
2039 rspp->spp_type, active, passive);
2042 if (spp->spp_flags & FC_SPP_EST_IMG_PAIR)
2043 resp |= FC_SPP_RESP_CONF;
2045 resp |= FC_SPP_RESP_INVL;
2047 spp->spp_flags |= resp;
2049 rspp = (struct fc_els_spp *)((char *)rspp + plen);
2050 spp = (struct fc_els_spp *)((char *)spp + plen);
2052 mutex_unlock(&fc_prov_mutex);
2055 * Send LS_ACC. If this fails, the originator should retry.
2057 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
2058 lport->tt.frame_send(lport, fp);
2063 rjt_data.reason = ELS_RJT_PROT;
2064 rjt_data.explan = ELS_EXPL_INV_LEN;
2066 fc_seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
2068 fc_frame_free(rx_fp);
2072 * fc_rport_recv_prlo_req() - Handler for process logout (PRLO) requests
2073 * @rdata: The remote port that sent the PRLO request
2074 * @rx_fp: The PRLO request frame
2076 static void fc_rport_recv_prlo_req(struct fc_rport_priv *rdata,
2077 struct fc_frame *rx_fp)
2079 struct fc_lport *lport = rdata->local_port;
2080 struct fc_frame *fp;
2082 struct fc_els_prlo prlo;
2083 struct fc_els_spp spp;
2085 struct fc_els_spp *rspp; /* request service param page */
2086 struct fc_els_spp *spp; /* response spp */
2089 struct fc_seq_els_data rjt_data;
2091 lockdep_assert_held(&rdata->rp_mutex);
2093 FC_RPORT_DBG(rdata, "Received PRLO request while in state %s\n",
2094 fc_rport_state(rdata));
2096 len = fr_len(rx_fp) - sizeof(struct fc_frame_header);
2097 pp = fc_frame_payload_get(rx_fp, sizeof(*pp));
2100 plen = ntohs(pp->prlo.prlo_len);
2108 fp = fc_frame_alloc(lport, len);
2110 rjt_data.reason = ELS_RJT_UNAB;
2111 rjt_data.explan = ELS_EXPL_INSUF_RES;
2115 pp = fc_frame_payload_get(fp, len);
2118 pp->prlo.prlo_cmd = ELS_LS_ACC;
2119 pp->prlo.prlo_obs = 0x10;
2120 pp->prlo.prlo_len = htons(len);
2122 spp->spp_type = rspp->spp_type;
2123 spp->spp_type_ext = rspp->spp_type_ext;
2124 spp->spp_flags = FC_SPP_RESP_ACK;
2126 fc_rport_enter_prli(rdata);
2128 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
2129 lport->tt.frame_send(lport, fp);
2133 rjt_data.reason = ELS_RJT_PROT;
2134 rjt_data.explan = ELS_EXPL_INV_LEN;
2136 fc_seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
2138 fc_frame_free(rx_fp);
2142 * fc_rport_recv_logo_req() - Handler for logout (LOGO) requests
2143 * @lport: The local port that received the LOGO request
2144 * @fp: The LOGO request frame
2146 * Reference counting: drops kref on return
2148 static void fc_rport_recv_logo_req(struct fc_lport *lport, struct fc_frame *fp)
2150 struct fc_rport_priv *rdata;
2153 lockdep_assert_held(&lport->lp_mutex);
2155 fc_seq_els_rsp_send(fp, ELS_LS_ACC, NULL);
2157 sid = fc_frame_sid(fp);
2159 rdata = fc_rport_lookup(lport, sid);
2161 mutex_lock(&rdata->rp_mutex);
2162 FC_RPORT_DBG(rdata, "Received LOGO request while in state %s\n",
2163 fc_rport_state(rdata));
2165 fc_rport_enter_delete(rdata, RPORT_EV_STOP);
2166 mutex_unlock(&rdata->rp_mutex);
2167 kref_put(&rdata->kref, fc_rport_destroy);
2169 FC_RPORT_ID_DBG(lport, sid,
2170 "Received LOGO from non-logged-in port\n");
2175 * fc_rport_flush_queue() - Flush the rport_event_queue
2177 void fc_rport_flush_queue(void)
2179 flush_workqueue(rport_event_queue);
2181 EXPORT_SYMBOL(fc_rport_flush_queue);
2184 * fc_rport_fcp_prli() - Handle incoming PRLI for the FCP initiator.
2185 * @rdata: remote port private
2186 * @spp_len: service parameter page length
2187 * @rspp: received service parameter page
2188 * @spp: response service parameter page
2190 * Returns the value for the response code to be placed in spp_flags;
2191 * Returns 0 if not an initiator.
2193 static int fc_rport_fcp_prli(struct fc_rport_priv *rdata, u32 spp_len,
2194 const struct fc_els_spp *rspp,
2195 struct fc_els_spp *spp)
2197 struct fc_lport *lport = rdata->local_port;
2200 fcp_parm = ntohl(rspp->spp_params);
2201 rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
2202 if (fcp_parm & FCP_SPPF_INIT_FCN)
2203 rdata->ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2204 if (fcp_parm & FCP_SPPF_TARG_FCN)
2205 rdata->ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2206 if (fcp_parm & FCP_SPPF_RETRY)
2207 rdata->flags |= FC_RP_FLAGS_RETRY;
2208 rdata->supported_classes = FC_COS_CLASS3;
2210 if (!(lport->service_params & FCP_SPPF_INIT_FCN))
2213 spp->spp_flags |= rspp->spp_flags & FC_SPP_EST_IMG_PAIR;
2216 * OR in our service parameters with other providers (target), if any.
2218 fcp_parm = ntohl(spp->spp_params);
2219 spp->spp_params = htonl(fcp_parm | lport->service_params);
2220 return FC_SPP_RESP_ACK;
2224 * FC-4 provider ops for FCP initiator.
2226 struct fc4_prov fc_rport_fcp_init = {
2227 .prli = fc_rport_fcp_prli,
2231 * fc_rport_t0_prli() - Handle incoming PRLI parameters for type 0
2232 * @rdata: remote port private
2233 * @spp_len: service parameter page length
2234 * @rspp: received service parameter page
2235 * @spp: response service parameter page
2237 static int fc_rport_t0_prli(struct fc_rport_priv *rdata, u32 spp_len,
2238 const struct fc_els_spp *rspp,
2239 struct fc_els_spp *spp)
2241 if (rspp->spp_flags & FC_SPP_EST_IMG_PAIR)
2242 return FC_SPP_RESP_INVL;
2243 return FC_SPP_RESP_ACK;
2247 * FC-4 provider ops for type 0 service parameters.
2249 * This handles the special case of type 0 which is always successful
2250 * but doesn't do anything otherwise.
2252 struct fc4_prov fc_rport_t0_prov = {
2253 .prli = fc_rport_t0_prli,
2257 * fc_setup_rport() - Initialize the rport_event_queue
2259 int fc_setup_rport(void)
2261 rport_event_queue = create_singlethread_workqueue("fc_rport_eq");
2262 if (!rport_event_queue)
2268 * fc_destroy_rport() - Destroy the rport_event_queue
2270 void fc_destroy_rport(void)
2272 destroy_workqueue(rport_event_queue);
2276 * fc_rport_terminate_io() - Stop all outstanding I/O on a remote port
2277 * @rport: The remote port whose I/O should be terminated
2279 void fc_rport_terminate_io(struct fc_rport *rport)
2281 struct fc_rport_libfc_priv *rpriv = rport->dd_data;
2282 struct fc_lport *lport = rpriv->local_port;
2284 lport->tt.exch_mgr_reset(lport, 0, rport->port_id);
2285 lport->tt.exch_mgr_reset(lport, rport->port_id, 0);
2287 EXPORT_SYMBOL(fc_rport_terminate_io);