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 <asm/unaligned.h>
70 #include <scsi/libfc.h>
71 #include <scsi/fc_encode.h>
75 static struct workqueue_struct *rport_event_queue;
77 static void fc_rport_enter_flogi(struct fc_rport_priv *);
78 static void fc_rport_enter_plogi(struct fc_rport_priv *);
79 static void fc_rport_enter_prli(struct fc_rport_priv *);
80 static void fc_rport_enter_rtv(struct fc_rport_priv *);
81 static void fc_rport_enter_ready(struct fc_rport_priv *);
82 static void fc_rport_enter_logo(struct fc_rport_priv *);
83 static void fc_rport_enter_adisc(struct fc_rport_priv *);
85 static void fc_rport_recv_plogi_req(struct fc_lport *, struct fc_frame *);
86 static void fc_rport_recv_prli_req(struct fc_rport_priv *, struct fc_frame *);
87 static void fc_rport_recv_prlo_req(struct fc_rport_priv *, struct fc_frame *);
88 static void fc_rport_recv_logo_req(struct fc_lport *, struct fc_frame *);
89 static void fc_rport_timeout(struct work_struct *);
90 static void fc_rport_error(struct fc_rport_priv *, int);
91 static void fc_rport_error_retry(struct fc_rport_priv *, int);
92 static void fc_rport_work(struct work_struct *);
94 static const char *fc_rport_state_names[] = {
95 [RPORT_ST_INIT] = "Init",
96 [RPORT_ST_FLOGI] = "FLOGI",
97 [RPORT_ST_PLOGI_WAIT] = "PLOGI_WAIT",
98 [RPORT_ST_PLOGI] = "PLOGI",
99 [RPORT_ST_PRLI] = "PRLI",
100 [RPORT_ST_RTV] = "RTV",
101 [RPORT_ST_READY] = "Ready",
102 [RPORT_ST_ADISC] = "ADISC",
103 [RPORT_ST_DELETE] = "Delete",
107 * fc_rport_lookup() - Lookup a remote port by port_id
108 * @lport: The local port to lookup the remote port on
109 * @port_id: The remote port ID to look up
111 * The reference count of the fc_rport_priv structure is
114 struct fc_rport_priv *fc_rport_lookup(const struct fc_lport *lport,
117 struct fc_rport_priv *rdata = NULL, *tmp_rdata;
120 list_for_each_entry_rcu(tmp_rdata, &lport->disc.rports, peers)
121 if (tmp_rdata->ids.port_id == port_id &&
122 kref_get_unless_zero(&tmp_rdata->kref)) {
129 EXPORT_SYMBOL(fc_rport_lookup);
132 * fc_rport_create() - Create a new remote port
133 * @lport: The local port this remote port will be associated with
134 * @ids: The identifiers for the new remote port
136 * The remote port will start in the INIT state.
138 * Locking note: must be called with the disc_mutex held.
140 struct fc_rport_priv *fc_rport_create(struct fc_lport *lport, u32 port_id)
142 struct fc_rport_priv *rdata;
144 rdata = fc_rport_lookup(lport, port_id);
148 rdata = kzalloc(sizeof(*rdata) + lport->rport_priv_size, GFP_KERNEL);
152 rdata->ids.node_name = -1;
153 rdata->ids.port_name = -1;
154 rdata->ids.port_id = port_id;
155 rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
157 kref_init(&rdata->kref);
158 mutex_init(&rdata->rp_mutex);
159 rdata->local_port = lport;
160 rdata->rp_state = RPORT_ST_INIT;
161 rdata->event = RPORT_EV_NONE;
162 rdata->flags = FC_RP_FLAGS_REC_SUPPORTED;
163 rdata->e_d_tov = lport->e_d_tov;
164 rdata->r_a_tov = lport->r_a_tov;
165 rdata->maxframe_size = FC_MIN_MAX_PAYLOAD;
166 INIT_DELAYED_WORK(&rdata->retry_work, fc_rport_timeout);
167 INIT_WORK(&rdata->event_work, fc_rport_work);
168 if (port_id != FC_FID_DIR_SERV) {
169 rdata->lld_event_callback = lport->tt.rport_event_callback;
170 list_add_rcu(&rdata->peers, &lport->disc.rports);
174 EXPORT_SYMBOL(fc_rport_create);
177 * fc_rport_destroy() - Free a remote port after last reference is released
178 * @kref: The remote port's kref
180 void fc_rport_destroy(struct kref *kref)
182 struct fc_rport_priv *rdata;
184 rdata = container_of(kref, struct fc_rport_priv, kref);
185 kfree_rcu(rdata, rcu);
187 EXPORT_SYMBOL(fc_rport_destroy);
190 * fc_rport_state() - Return a string identifying the remote port's state
191 * @rdata: The remote port
193 static const char *fc_rport_state(struct fc_rport_priv *rdata)
197 cp = fc_rport_state_names[rdata->rp_state];
204 * fc_set_rport_loss_tmo() - Set the remote port loss timeout
205 * @rport: The remote port that gets a new timeout value
206 * @timeout: The new timeout value (in seconds)
208 void fc_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout)
211 rport->dev_loss_tmo = timeout;
213 rport->dev_loss_tmo = 1;
215 EXPORT_SYMBOL(fc_set_rport_loss_tmo);
218 * fc_plogi_get_maxframe() - Get the maximum payload from the common service
219 * parameters in a FLOGI frame
220 * @flp: The FLOGI or PLOGI payload
221 * @maxval: The maximum frame size upper limit; this may be less than what
222 * is in the service parameters
224 static unsigned int fc_plogi_get_maxframe(struct fc_els_flogi *flp,
230 * Get max payload from the common service parameters and the
231 * class 3 receive data field size.
233 mfs = ntohs(flp->fl_csp.sp_bb_data) & FC_SP_BB_DATA_MASK;
234 if (mfs >= FC_SP_MIN_MAX_PAYLOAD && mfs < maxval)
236 mfs = ntohs(flp->fl_cssp[3 - 1].cp_rdfs);
237 if (mfs >= FC_SP_MIN_MAX_PAYLOAD && mfs < maxval)
243 * fc_rport_state_enter() - Change the state of a remote port
244 * @rdata: The remote port whose state should change
245 * @new: The new state
247 * Locking Note: Called with the rport lock held
249 static void fc_rport_state_enter(struct fc_rport_priv *rdata,
250 enum fc_rport_state new)
252 if (rdata->rp_state != new)
254 rdata->rp_state = new;
258 * fc_rport_work() - Handler for remote port events in the rport_event_queue
259 * @work: Handle to the remote port being dequeued
261 * Reference counting: drops kref on return
263 static void fc_rport_work(struct work_struct *work)
266 struct fc_rport_priv *rdata =
267 container_of(work, struct fc_rport_priv, event_work);
268 struct fc_rport_libfc_priv *rpriv;
269 enum fc_rport_event event;
270 struct fc_lport *lport = rdata->local_port;
271 struct fc_rport_operations *rport_ops;
272 struct fc_rport_identifiers ids;
273 struct fc_rport *rport;
274 struct fc4_prov *prov;
277 mutex_lock(&rdata->rp_mutex);
278 event = rdata->event;
279 rport_ops = rdata->ops;
280 rport = rdata->rport;
282 FC_RPORT_DBG(rdata, "work event %u\n", event);
287 rdata->event = RPORT_EV_NONE;
288 rdata->major_retries = 0;
289 kref_get(&rdata->kref);
290 mutex_unlock(&rdata->rp_mutex);
293 FC_RPORT_DBG(rdata, "No rport!\n");
294 rport = fc_remote_port_add(lport->host, 0, &ids);
297 FC_RPORT_DBG(rdata, "Failed to add the rport\n");
298 fc_rport_logoff(rdata);
299 kref_put(&rdata->kref, fc_rport_destroy);
302 mutex_lock(&rdata->rp_mutex);
304 FC_RPORT_DBG(rdata, "rport already allocated\n");
305 rdata->rport = rport;
306 rport->maxframe_size = rdata->maxframe_size;
307 rport->supported_classes = rdata->supported_classes;
309 rpriv = rport->dd_data;
310 rpriv->local_port = lport;
311 rpriv->rp_state = rdata->rp_state;
312 rpriv->flags = rdata->flags;
313 rpriv->e_d_tov = rdata->e_d_tov;
314 rpriv->r_a_tov = rdata->r_a_tov;
315 mutex_unlock(&rdata->rp_mutex);
317 if (rport_ops && rport_ops->event_callback) {
318 FC_RPORT_DBG(rdata, "callback ev %d\n", event);
319 rport_ops->event_callback(lport, rdata, event);
321 if (rdata->lld_event_callback) {
322 FC_RPORT_DBG(rdata, "lld callback ev %d\n", event);
323 rdata->lld_event_callback(lport, rdata, event);
325 kref_put(&rdata->kref, fc_rport_destroy);
328 case RPORT_EV_FAILED:
331 if (rdata->prli_count) {
332 mutex_lock(&fc_prov_mutex);
333 for (type = 1; type < FC_FC4_PROV_SIZE; type++) {
334 prov = fc_passive_prov[type];
335 if (prov && prov->prlo)
338 mutex_unlock(&fc_prov_mutex);
340 port_id = rdata->ids.port_id;
341 mutex_unlock(&rdata->rp_mutex);
343 if (rport_ops && rport_ops->event_callback) {
344 FC_RPORT_DBG(rdata, "callback ev %d\n", event);
345 rport_ops->event_callback(lport, rdata, event);
347 if (rdata->lld_event_callback) {
348 FC_RPORT_DBG(rdata, "lld callback ev %d\n", event);
349 rdata->lld_event_callback(lport, rdata, event);
351 if (cancel_delayed_work_sync(&rdata->retry_work))
352 kref_put(&rdata->kref, fc_rport_destroy);
355 * Reset any outstanding exchanges before freeing rport.
357 lport->tt.exch_mgr_reset(lport, 0, port_id);
358 lport->tt.exch_mgr_reset(lport, port_id, 0);
361 rpriv = rport->dd_data;
362 rpriv->rp_state = RPORT_ST_DELETE;
363 mutex_lock(&rdata->rp_mutex);
365 mutex_unlock(&rdata->rp_mutex);
366 fc_remote_port_delete(rport);
369 mutex_lock(&rdata->rp_mutex);
370 if (rdata->rp_state == RPORT_ST_DELETE) {
371 if (port_id == FC_FID_DIR_SERV) {
372 rdata->event = RPORT_EV_NONE;
373 mutex_unlock(&rdata->rp_mutex);
374 kref_put(&rdata->kref, fc_rport_destroy);
375 } else if ((rdata->flags & FC_RP_STARTED) &&
376 rdata->major_retries <
377 lport->max_rport_retry_count) {
378 rdata->major_retries++;
379 rdata->event = RPORT_EV_NONE;
380 FC_RPORT_DBG(rdata, "work restart\n");
381 fc_rport_enter_flogi(rdata);
382 mutex_unlock(&rdata->rp_mutex);
384 FC_RPORT_DBG(rdata, "work delete\n");
385 mutex_lock(&lport->disc.disc_mutex);
386 list_del_rcu(&rdata->peers);
387 mutex_unlock(&lport->disc.disc_mutex);
388 mutex_unlock(&rdata->rp_mutex);
389 kref_put(&rdata->kref, fc_rport_destroy);
393 * Re-open for events. Reissue READY event if ready.
395 rdata->event = RPORT_EV_NONE;
396 if (rdata->rp_state == RPORT_ST_READY) {
397 FC_RPORT_DBG(rdata, "work reopen\n");
398 fc_rport_enter_ready(rdata);
400 mutex_unlock(&rdata->rp_mutex);
405 mutex_unlock(&rdata->rp_mutex);
408 kref_put(&rdata->kref, fc_rport_destroy);
412 * fc_rport_login() - Start the remote port login state machine
413 * @rdata: The remote port to be logged in to
415 * Initiates the RP state machine. It is called from the LP module.
416 * This function will issue the following commands to the N_Port
417 * identified by the FC ID provided.
423 * Locking Note: Called without the rport lock held. This
424 * function will hold the rport lock, call an _enter_*
425 * function and then unlock the rport.
427 * This indicates the intent to be logged into the remote port.
428 * If it appears we are already logged in, ADISC is used to verify
431 int fc_rport_login(struct fc_rport_priv *rdata)
433 mutex_lock(&rdata->rp_mutex);
435 if (rdata->flags & FC_RP_STARTED) {
436 FC_RPORT_DBG(rdata, "port already started\n");
437 mutex_unlock(&rdata->rp_mutex);
441 rdata->flags |= FC_RP_STARTED;
442 switch (rdata->rp_state) {
444 FC_RPORT_DBG(rdata, "ADISC port\n");
445 fc_rport_enter_adisc(rdata);
447 case RPORT_ST_DELETE:
448 FC_RPORT_DBG(rdata, "Restart deleted port\n");
451 FC_RPORT_DBG(rdata, "Login to port\n");
452 fc_rport_enter_flogi(rdata);
455 FC_RPORT_DBG(rdata, "Login in progress, state %s\n",
456 fc_rport_state(rdata));
459 mutex_unlock(&rdata->rp_mutex);
463 EXPORT_SYMBOL(fc_rport_login);
466 * fc_rport_enter_delete() - Schedule a remote port to be deleted
467 * @rdata: The remote port to be deleted
468 * @event: The event to report as the reason for deletion
470 * Locking Note: Called with the rport lock held.
472 * Allow state change into DELETE only once.
474 * Call queue_work only if there's no event already pending.
475 * Set the new event so that the old pending event will not occur.
476 * Since we have the mutex, even if fc_rport_work() is already started,
477 * it'll see the new event.
479 * Reference counting: does not modify kref
481 static void fc_rport_enter_delete(struct fc_rport_priv *rdata,
482 enum fc_rport_event event)
484 if (rdata->rp_state == RPORT_ST_DELETE)
487 FC_RPORT_DBG(rdata, "Delete port\n");
489 fc_rport_state_enter(rdata, RPORT_ST_DELETE);
491 kref_get(&rdata->kref);
492 if (rdata->event == RPORT_EV_NONE &&
493 !queue_work(rport_event_queue, &rdata->event_work))
494 kref_put(&rdata->kref, fc_rport_destroy);
496 rdata->event = event;
500 * fc_rport_logoff() - Logoff and remove a remote port
501 * @rdata: The remote port to be logged off of
503 * Locking Note: Called without the rport lock held. This
504 * function will hold the rport lock, call an _enter_*
505 * function and then unlock the rport.
507 int fc_rport_logoff(struct fc_rport_priv *rdata)
509 struct fc_lport *lport = rdata->local_port;
510 u32 port_id = rdata->ids.port_id;
512 mutex_lock(&rdata->rp_mutex);
514 FC_RPORT_DBG(rdata, "Remove port\n");
516 rdata->flags &= ~FC_RP_STARTED;
517 if (rdata->rp_state == RPORT_ST_DELETE) {
518 FC_RPORT_DBG(rdata, "Port in Delete state, not removing\n");
523 * To explicitly Logout, the initiating Nx_Port shall terminate
524 * other open Sequences that it initiated with the destination
525 * Nx_Port prior to performing Logout.
527 lport->tt.exch_mgr_reset(lport, 0, port_id);
528 lport->tt.exch_mgr_reset(lport, port_id, 0);
530 fc_rport_enter_logo(rdata);
533 * Change the state to Delete so that we discard
536 fc_rport_enter_delete(rdata, RPORT_EV_STOP);
538 mutex_unlock(&rdata->rp_mutex);
541 EXPORT_SYMBOL(fc_rport_logoff);
544 * fc_rport_enter_ready() - Transition to the RPORT_ST_READY state
545 * @rdata: The remote port that is ready
547 * Locking Note: The rport lock is expected to be held before calling
550 * Reference counting: schedules workqueue, does not modify kref
552 static void fc_rport_enter_ready(struct fc_rport_priv *rdata)
554 fc_rport_state_enter(rdata, RPORT_ST_READY);
556 FC_RPORT_DBG(rdata, "Port is Ready\n");
558 kref_get(&rdata->kref);
559 if (rdata->event == RPORT_EV_NONE &&
560 !queue_work(rport_event_queue, &rdata->event_work))
561 kref_put(&rdata->kref, fc_rport_destroy);
563 rdata->event = RPORT_EV_READY;
567 * fc_rport_timeout() - Handler for the retry_work timer
568 * @work: Handle to the remote port that has timed out
570 * Locking Note: Called without the rport lock held. This
571 * function will hold the rport lock, call an _enter_*
572 * function and then unlock the rport.
574 * Reference counting: Drops kref on return.
576 static void fc_rport_timeout(struct work_struct *work)
578 struct fc_rport_priv *rdata =
579 container_of(work, struct fc_rport_priv, retry_work.work);
581 mutex_lock(&rdata->rp_mutex);
582 FC_RPORT_DBG(rdata, "Port timeout, state %s\n", fc_rport_state(rdata));
584 switch (rdata->rp_state) {
586 fc_rport_enter_flogi(rdata);
589 fc_rport_enter_plogi(rdata);
592 fc_rport_enter_prli(rdata);
595 fc_rport_enter_rtv(rdata);
598 fc_rport_enter_adisc(rdata);
600 case RPORT_ST_PLOGI_WAIT:
603 case RPORT_ST_DELETE:
607 mutex_unlock(&rdata->rp_mutex);
608 kref_put(&rdata->kref, fc_rport_destroy);
612 * fc_rport_error() - Error handler, called once retries have been exhausted
613 * @rdata: The remote port the error is happened on
614 * @err: The error code
616 * Locking Note: The rport lock is expected to be held before
617 * calling this routine
619 * Reference counting: does not modify kref
621 static void fc_rport_error(struct fc_rport_priv *rdata, int err)
623 struct fc_lport *lport = rdata->local_port;
625 FC_RPORT_DBG(rdata, "Error %d in state %s, retries %d\n",
626 -err, fc_rport_state(rdata), rdata->retries);
628 switch (rdata->rp_state) {
630 rdata->flags &= ~FC_RP_STARTED;
631 fc_rport_enter_delete(rdata, RPORT_EV_FAILED);
634 if (lport->point_to_multipoint) {
635 rdata->flags &= ~FC_RP_STARTED;
636 fc_rport_enter_delete(rdata, RPORT_EV_FAILED);
638 fc_rport_enter_logo(rdata);
641 fc_rport_enter_ready(rdata);
645 fc_rport_enter_logo(rdata);
647 case RPORT_ST_PLOGI_WAIT:
648 case RPORT_ST_DELETE:
656 * fc_rport_error_retry() - Handler for remote port state retries
657 * @rdata: The remote port whose state is to be retried
658 * @err: The error code
660 * If the error was an exchange timeout retry immediately,
661 * otherwise wait for E_D_TOV.
663 * Locking Note: The rport lock is expected to be held before
664 * calling this routine
666 * Reference counting: increments kref when scheduling retry_work
668 static void fc_rport_error_retry(struct fc_rport_priv *rdata, int err)
670 unsigned long delay = msecs_to_jiffies(rdata->e_d_tov);
672 /* make sure this isn't an FC_EX_CLOSED error, never retry those */
673 if (err == -FC_EX_CLOSED)
676 if (rdata->retries < rdata->local_port->max_rport_retry_count) {
677 FC_RPORT_DBG(rdata, "Error %d in state %s, retrying\n",
678 err, fc_rport_state(rdata));
680 /* no additional delay on exchange timeouts */
681 if (err == -FC_EX_TIMEOUT)
683 kref_get(&rdata->kref);
684 if (!schedule_delayed_work(&rdata->retry_work, delay))
685 kref_put(&rdata->kref, fc_rport_destroy);
690 fc_rport_error(rdata, err);
694 * fc_rport_login_complete() - Handle parameters and completion of p-mp login.
695 * @rdata: The remote port which we logged into or which logged into us.
696 * @fp: The FLOGI or PLOGI request or response frame
698 * Returns non-zero error if a problem is detected with the frame.
699 * Does not free the frame.
701 * This is only used in point-to-multipoint mode for FIP currently.
703 static int fc_rport_login_complete(struct fc_rport_priv *rdata,
706 struct fc_lport *lport = rdata->local_port;
707 struct fc_els_flogi *flogi;
708 unsigned int e_d_tov;
711 flogi = fc_frame_payload_get(fp, sizeof(*flogi));
715 csp_flags = ntohs(flogi->fl_csp.sp_features);
717 if (fc_frame_payload_op(fp) == ELS_FLOGI) {
718 if (csp_flags & FC_SP_FT_FPORT) {
719 FC_RPORT_DBG(rdata, "Fabric bit set in FLOGI\n");
725 * E_D_TOV is not valid on an incoming FLOGI request.
727 e_d_tov = ntohl(flogi->fl_csp.sp_e_d_tov);
728 if (csp_flags & FC_SP_FT_EDTR)
730 if (e_d_tov > rdata->e_d_tov)
731 rdata->e_d_tov = e_d_tov;
733 rdata->maxframe_size = fc_plogi_get_maxframe(flogi, lport->mfs);
738 * fc_rport_flogi_resp() - Handle response to FLOGI request for p-mp mode
739 * @sp: The sequence that the FLOGI was on
740 * @fp: The FLOGI response frame
741 * @rp_arg: The remote port that received the FLOGI response
743 static void fc_rport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp,
746 struct fc_rport_priv *rdata = rp_arg;
747 struct fc_lport *lport = rdata->local_port;
748 struct fc_els_flogi *flogi;
749 unsigned int r_a_tov;
753 FC_RPORT_DBG(rdata, "Received a FLOGI %s\n",
754 IS_ERR(fp) ? "error" : fc_els_resp_type(fp));
756 if (fp == ERR_PTR(-FC_EX_CLOSED))
759 mutex_lock(&rdata->rp_mutex);
761 if (rdata->rp_state != RPORT_ST_FLOGI) {
762 FC_RPORT_DBG(rdata, "Received a FLOGI response, but in state "
763 "%s\n", fc_rport_state(rdata));
770 fc_rport_error(rdata, PTR_ERR(fp));
773 opcode = fc_frame_payload_op(fp);
774 if (opcode == ELS_LS_RJT) {
775 struct fc_els_ls_rjt *rjt;
777 rjt = fc_frame_payload_get(fp, sizeof(*rjt));
778 FC_RPORT_DBG(rdata, "FLOGI ELS rejected, reason %x expl %x\n",
779 rjt->er_reason, rjt->er_explan);
780 err = -FC_EX_ELS_RJT;
782 } else if (opcode != ELS_LS_ACC) {
783 FC_RPORT_DBG(rdata, "FLOGI ELS invalid opcode %x\n", opcode);
784 err = -FC_EX_ELS_RJT;
787 if (fc_rport_login_complete(rdata, fp)) {
788 FC_RPORT_DBG(rdata, "FLOGI failed, no login\n");
789 err = -FC_EX_INV_LOGIN;
793 flogi = fc_frame_payload_get(fp, sizeof(*flogi));
795 err = -FC_EX_ALLOC_ERR;
798 r_a_tov = ntohl(flogi->fl_csp.sp_r_a_tov);
799 if (r_a_tov > rdata->r_a_tov)
800 rdata->r_a_tov = r_a_tov;
802 if (rdata->ids.port_name < lport->wwpn)
803 fc_rport_enter_plogi(rdata);
805 fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
809 mutex_unlock(&rdata->rp_mutex);
811 kref_put(&rdata->kref, fc_rport_destroy);
814 FC_RPORT_DBG(rdata, "Bad FLOGI response\n");
815 fc_rport_error_retry(rdata, err);
820 * fc_rport_enter_flogi() - Send a FLOGI request to the remote port for p-mp
821 * @rdata: The remote port to send a FLOGI to
823 * Locking Note: The rport lock is expected to be held before calling
826 * Reference counting: increments kref when sending ELS
828 static void fc_rport_enter_flogi(struct fc_rport_priv *rdata)
830 struct fc_lport *lport = rdata->local_port;
833 if (!lport->point_to_multipoint)
834 return fc_rport_enter_plogi(rdata);
836 FC_RPORT_DBG(rdata, "Entered FLOGI state from %s state\n",
837 fc_rport_state(rdata));
839 fc_rport_state_enter(rdata, RPORT_ST_FLOGI);
841 fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi));
843 return fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
845 kref_get(&rdata->kref);
846 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_FLOGI,
847 fc_rport_flogi_resp, rdata,
848 2 * lport->r_a_tov)) {
849 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
850 kref_put(&rdata->kref, fc_rport_destroy);
855 * fc_rport_recv_flogi_req() - Handle Fabric Login (FLOGI) request in p-mp mode
856 * @lport: The local port that received the PLOGI request
857 * @rx_fp: The PLOGI request frame
859 * Reference counting: drops kref on return
861 static void fc_rport_recv_flogi_req(struct fc_lport *lport,
862 struct fc_frame *rx_fp)
864 struct fc_disc *disc;
865 struct fc_els_flogi *flp;
866 struct fc_rport_priv *rdata;
867 struct fc_frame *fp = rx_fp;
868 struct fc_seq_els_data rjt_data;
871 sid = fc_frame_sid(fp);
873 FC_RPORT_ID_DBG(lport, sid, "Received FLOGI request\n");
876 if (!lport->point_to_multipoint) {
877 rjt_data.reason = ELS_RJT_UNSUP;
878 rjt_data.explan = ELS_EXPL_NONE;
882 flp = fc_frame_payload_get(fp, sizeof(*flp));
884 rjt_data.reason = ELS_RJT_LOGIC;
885 rjt_data.explan = ELS_EXPL_INV_LEN;
889 rdata = fc_rport_lookup(lport, sid);
891 rjt_data.reason = ELS_RJT_FIP;
892 rjt_data.explan = ELS_EXPL_NOT_NEIGHBOR;
895 mutex_lock(&rdata->rp_mutex);
897 FC_RPORT_DBG(rdata, "Received FLOGI in %s state\n",
898 fc_rport_state(rdata));
900 switch (rdata->rp_state) {
903 * If received the FLOGI request on RPORT which is INIT state
904 * (means not transition to FLOGI either fc_rport timeout
905 * function didn;t trigger or this end hasn;t received
906 * beacon yet from other end. In that case only, allow RPORT
907 * state machine to continue, otherwise fall through which
908 * causes the code to send reject response.
909 * NOTE; Not checking for FIP->state such as VNMP_UP or
910 * VNMP_CLAIM because if FIP state is not one of those,
911 * RPORT wouldn;t have created and 'rport_lookup' would have
912 * failed anyway in that case.
915 case RPORT_ST_DELETE:
916 mutex_unlock(&rdata->rp_mutex);
917 rjt_data.reason = ELS_RJT_FIP;
918 rjt_data.explan = ELS_EXPL_NOT_NEIGHBOR;
921 case RPORT_ST_PLOGI_WAIT:
929 * Set the remote port to be deleted and to then restart.
930 * This queues work to be sure exchanges are reset.
932 fc_rport_enter_delete(rdata, RPORT_EV_LOGO);
933 mutex_unlock(&rdata->rp_mutex);
934 rjt_data.reason = ELS_RJT_BUSY;
935 rjt_data.explan = ELS_EXPL_NONE;
938 if (fc_rport_login_complete(rdata, fp)) {
939 mutex_unlock(&rdata->rp_mutex);
940 rjt_data.reason = ELS_RJT_LOGIC;
941 rjt_data.explan = ELS_EXPL_NONE;
945 fp = fc_frame_alloc(lport, sizeof(*flp));
949 fc_flogi_fill(lport, fp);
950 flp = fc_frame_payload_get(fp, sizeof(*flp));
951 flp->fl_cmd = ELS_LS_ACC;
953 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
954 lport->tt.frame_send(lport, fp);
957 * Do not proceed with the state machine if our
958 * FLOGI has crossed with an FLOGI from the
959 * remote port; wait for the FLOGI response instead.
961 if (rdata->rp_state != RPORT_ST_FLOGI) {
962 if (rdata->ids.port_name < lport->wwpn)
963 fc_rport_enter_plogi(rdata);
965 fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
968 mutex_unlock(&rdata->rp_mutex);
969 kref_put(&rdata->kref, fc_rport_destroy);
970 fc_frame_free(rx_fp);
974 kref_put(&rdata->kref, fc_rport_destroy);
976 fc_seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
977 fc_frame_free(rx_fp);
981 * fc_rport_plogi_resp() - Handler for ELS PLOGI responses
982 * @sp: The sequence the PLOGI is on
983 * @fp: The PLOGI response frame
984 * @rdata_arg: The remote port that sent the PLOGI response
986 * Locking Note: This function will be called without the rport lock
987 * held, but it will lock, call an _enter_* function or fc_rport_error
988 * and then unlock the rport.
990 static void fc_rport_plogi_resp(struct fc_seq *sp, struct fc_frame *fp,
993 struct fc_rport_priv *rdata = rdata_arg;
994 struct fc_lport *lport = rdata->local_port;
995 struct fc_els_flogi *plp = NULL;
1000 FC_RPORT_DBG(rdata, "Received a PLOGI %s\n", fc_els_resp_type(fp));
1002 if (fp == ERR_PTR(-FC_EX_CLOSED))
1005 mutex_lock(&rdata->rp_mutex);
1007 if (rdata->rp_state != RPORT_ST_PLOGI) {
1008 FC_RPORT_DBG(rdata, "Received a PLOGI response, but in state "
1009 "%s\n", fc_rport_state(rdata));
1016 fc_rport_error_retry(rdata, PTR_ERR(fp));
1020 op = fc_frame_payload_op(fp);
1021 if (op == ELS_LS_ACC &&
1022 (plp = fc_frame_payload_get(fp, sizeof(*plp))) != NULL) {
1023 rdata->ids.port_name = get_unaligned_be64(&plp->fl_wwpn);
1024 rdata->ids.node_name = get_unaligned_be64(&plp->fl_wwnn);
1026 /* save plogi response sp_features for further reference */
1027 rdata->sp_features = ntohs(plp->fl_csp.sp_features);
1029 if (lport->point_to_multipoint)
1030 fc_rport_login_complete(rdata, fp);
1031 csp_seq = ntohs(plp->fl_csp.sp_tot_seq);
1032 cssp_seq = ntohs(plp->fl_cssp[3 - 1].cp_con_seq);
1033 if (cssp_seq < csp_seq)
1035 rdata->max_seq = csp_seq;
1036 rdata->maxframe_size = fc_plogi_get_maxframe(plp, lport->mfs);
1037 fc_rport_enter_prli(rdata);
1039 struct fc_els_ls_rjt *rjt;
1041 rjt = fc_frame_payload_get(fp, sizeof(*rjt));
1042 FC_RPORT_DBG(rdata, "PLOGI ELS rejected, reason %x expl %x\n",
1043 rjt->er_reason, rjt->er_explan);
1044 fc_rport_error_retry(rdata, -FC_EX_ELS_RJT);
1049 mutex_unlock(&rdata->rp_mutex);
1051 kref_put(&rdata->kref, fc_rport_destroy);
1055 fc_rport_compatible_roles(struct fc_lport *lport, struct fc_rport_priv *rdata)
1057 if (rdata->ids.roles == FC_PORT_ROLE_UNKNOWN)
1059 if ((rdata->ids.roles & FC_PORT_ROLE_FCP_TARGET) &&
1060 (lport->service_params & FCP_SPPF_INIT_FCN))
1062 if ((rdata->ids.roles & FC_PORT_ROLE_FCP_INITIATOR) &&
1063 (lport->service_params & FCP_SPPF_TARG_FCN))
1069 * fc_rport_enter_plogi() - Send Port Login (PLOGI) request
1070 * @rdata: The remote port to send a PLOGI to
1072 * Locking Note: The rport lock is expected to be held before calling
1075 * Reference counting: increments kref when sending ELS
1077 static void fc_rport_enter_plogi(struct fc_rport_priv *rdata)
1079 struct fc_lport *lport = rdata->local_port;
1080 struct fc_frame *fp;
1082 if (!fc_rport_compatible_roles(lport, rdata)) {
1083 FC_RPORT_DBG(rdata, "PLOGI suppressed for incompatible role\n");
1084 fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
1088 FC_RPORT_DBG(rdata, "Port entered PLOGI state from %s state\n",
1089 fc_rport_state(rdata));
1091 fc_rport_state_enter(rdata, RPORT_ST_PLOGI);
1093 rdata->maxframe_size = FC_MIN_MAX_PAYLOAD;
1094 fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi));
1096 FC_RPORT_DBG(rdata, "%s frame alloc failed\n", __func__);
1097 fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
1100 rdata->e_d_tov = lport->e_d_tov;
1102 kref_get(&rdata->kref);
1103 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_PLOGI,
1104 fc_rport_plogi_resp, rdata,
1105 2 * lport->r_a_tov)) {
1106 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
1107 kref_put(&rdata->kref, fc_rport_destroy);
1112 * fc_rport_prli_resp() - Process Login (PRLI) response handler
1113 * @sp: The sequence the PRLI response was on
1114 * @fp: The PRLI response frame
1115 * @rdata_arg: The remote port that sent the PRLI response
1117 * Locking Note: This function will be called without the rport lock
1118 * held, but it will lock, call an _enter_* function or fc_rport_error
1119 * and then unlock the rport.
1121 static void fc_rport_prli_resp(struct fc_seq *sp, struct fc_frame *fp,
1124 struct fc_rport_priv *rdata = rdata_arg;
1126 struct fc_els_prli prli;
1127 struct fc_els_spp spp;
1129 struct fc_els_spp temp_spp;
1130 struct fc_els_ls_rjt *rjt;
1131 struct fc4_prov *prov;
1132 u32 roles = FC_RPORT_ROLE_UNKNOWN;
1135 enum fc_els_spp_resp resp_code;
1137 FC_RPORT_DBG(rdata, "Received a PRLI %s\n", fc_els_resp_type(fp));
1139 if (fp == ERR_PTR(-FC_EX_CLOSED))
1142 mutex_lock(&rdata->rp_mutex);
1144 if (rdata->rp_state != RPORT_ST_PRLI) {
1145 FC_RPORT_DBG(rdata, "Received a PRLI response, but in state "
1146 "%s\n", fc_rport_state(rdata));
1153 fc_rport_error_retry(rdata, PTR_ERR(fp));
1157 /* reinitialize remote port roles */
1158 rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
1160 op = fc_frame_payload_op(fp);
1161 if (op == ELS_LS_ACC) {
1162 pp = fc_frame_payload_get(fp, sizeof(*pp));
1166 resp_code = (pp->spp.spp_flags & FC_SPP_RESP_MASK);
1167 FC_RPORT_DBG(rdata, "PRLI spp_flags = 0x%x spp_type 0x%x\n",
1168 pp->spp.spp_flags, pp->spp.spp_type);
1169 rdata->spp_type = pp->spp.spp_type;
1170 if (resp_code != FC_SPP_RESP_ACK) {
1171 if (resp_code == FC_SPP_RESP_CONF)
1172 fc_rport_error(rdata, -FC_EX_SEQ_ERR);
1174 fc_rport_error_retry(rdata, -FC_EX_SEQ_ERR);
1177 if (pp->prli.prli_spp_len < sizeof(pp->spp))
1180 fcp_parm = ntohl(pp->spp.spp_params);
1181 if (fcp_parm & FCP_SPPF_RETRY)
1182 rdata->flags |= FC_RP_FLAGS_RETRY;
1183 if (fcp_parm & FCP_SPPF_CONF_COMPL)
1184 rdata->flags |= FC_RP_FLAGS_CONF_REQ;
1187 * Call prli provider if we should act as a target
1189 prov = fc_passive_prov[rdata->spp_type];
1191 memset(&temp_spp, 0, sizeof(temp_spp));
1192 prov->prli(rdata, pp->prli.prli_spp_len,
1193 &pp->spp, &temp_spp);
1196 * Check if the image pair could be established
1198 if (rdata->spp_type != FC_TYPE_FCP ||
1199 !(pp->spp.spp_flags & FC_SPP_EST_IMG_PAIR)) {
1201 * Nope; we can't use this port as a target.
1203 fcp_parm &= ~FCP_SPPF_TARG_FCN;
1205 rdata->supported_classes = FC_COS_CLASS3;
1206 if (fcp_parm & FCP_SPPF_INIT_FCN)
1207 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1208 if (fcp_parm & FCP_SPPF_TARG_FCN)
1209 roles |= FC_RPORT_ROLE_FCP_TARGET;
1211 rdata->ids.roles = roles;
1212 fc_rport_enter_rtv(rdata);
1215 rjt = fc_frame_payload_get(fp, sizeof(*rjt));
1216 FC_RPORT_DBG(rdata, "PRLI ELS rejected, reason %x expl %x\n",
1217 rjt->er_reason, rjt->er_explan);
1218 fc_rport_error_retry(rdata, FC_EX_ELS_RJT);
1224 mutex_unlock(&rdata->rp_mutex);
1226 kref_put(&rdata->kref, fc_rport_destroy);
1230 * fc_rport_enter_prli() - Send Process Login (PRLI) request
1231 * @rdata: The remote port to send the PRLI request to
1233 * Locking Note: The rport lock is expected to be held before calling
1236 * Reference counting: increments kref when sending ELS
1238 static void fc_rport_enter_prli(struct fc_rport_priv *rdata)
1240 struct fc_lport *lport = rdata->local_port;
1242 struct fc_els_prli prli;
1243 struct fc_els_spp spp;
1245 struct fc_frame *fp;
1246 struct fc4_prov *prov;
1249 * If the rport is one of the well known addresses
1250 * we skip PRLI and RTV and go straight to READY.
1252 if (rdata->ids.port_id >= FC_FID_DOM_MGR) {
1253 fc_rport_enter_ready(rdata);
1258 * And if the local port does not support the initiator function
1259 * there's no need to send a PRLI, either.
1261 if (!(lport->service_params & FCP_SPPF_INIT_FCN)) {
1262 fc_rport_enter_ready(rdata);
1266 FC_RPORT_DBG(rdata, "Port entered PRLI state from %s state\n",
1267 fc_rport_state(rdata));
1269 fc_rport_state_enter(rdata, RPORT_ST_PRLI);
1271 fp = fc_frame_alloc(lport, sizeof(*pp));
1273 fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
1277 fc_prli_fill(lport, fp);
1279 prov = fc_passive_prov[FC_TYPE_FCP];
1281 pp = fc_frame_payload_get(fp, sizeof(*pp));
1282 prov->prli(rdata, sizeof(pp->spp), NULL, &pp->spp);
1285 fc_fill_fc_hdr(fp, FC_RCTL_ELS_REQ, rdata->ids.port_id,
1286 fc_host_port_id(lport->host), FC_TYPE_ELS,
1287 FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0);
1289 kref_get(&rdata->kref);
1290 if (!fc_exch_seq_send(lport, fp, fc_rport_prli_resp,
1291 NULL, rdata, 2 * lport->r_a_tov)) {
1292 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
1293 kref_put(&rdata->kref, fc_rport_destroy);
1298 * fc_rport_rtv_resp() - Handler for Request Timeout Value (RTV) responses
1299 * @sp: The sequence the RTV was on
1300 * @fp: The RTV response frame
1301 * @rdata_arg: The remote port that sent the RTV response
1303 * Many targets don't seem to support this.
1305 * Locking Note: This function will be called without the rport lock
1306 * held, but it will lock, call an _enter_* function or fc_rport_error
1307 * and then unlock the rport.
1309 static void fc_rport_rtv_resp(struct fc_seq *sp, struct fc_frame *fp,
1312 struct fc_rport_priv *rdata = rdata_arg;
1315 FC_RPORT_DBG(rdata, "Received a RTV %s\n", fc_els_resp_type(fp));
1317 if (fp == ERR_PTR(-FC_EX_CLOSED))
1320 mutex_lock(&rdata->rp_mutex);
1322 if (rdata->rp_state != RPORT_ST_RTV) {
1323 FC_RPORT_DBG(rdata, "Received a RTV response, but in state "
1324 "%s\n", fc_rport_state(rdata));
1331 fc_rport_error(rdata, PTR_ERR(fp));
1335 op = fc_frame_payload_op(fp);
1336 if (op == ELS_LS_ACC) {
1337 struct fc_els_rtv_acc *rtv;
1341 rtv = fc_frame_payload_get(fp, sizeof(*rtv));
1343 toq = ntohl(rtv->rtv_toq);
1344 tov = ntohl(rtv->rtv_r_a_tov);
1347 if (tov > rdata->r_a_tov)
1348 rdata->r_a_tov = tov;
1349 tov = ntohl(rtv->rtv_e_d_tov);
1350 if (toq & FC_ELS_RTV_EDRES)
1354 if (tov > rdata->e_d_tov)
1355 rdata->e_d_tov = tov;
1359 fc_rport_enter_ready(rdata);
1364 mutex_unlock(&rdata->rp_mutex);
1366 kref_put(&rdata->kref, fc_rport_destroy);
1370 * fc_rport_enter_rtv() - Send Request Timeout Value (RTV) request
1371 * @rdata: The remote port to send the RTV request to
1373 * Locking Note: The rport lock is expected to be held before calling
1376 * Reference counting: increments kref when sending ELS
1378 static void fc_rport_enter_rtv(struct fc_rport_priv *rdata)
1380 struct fc_frame *fp;
1381 struct fc_lport *lport = rdata->local_port;
1383 FC_RPORT_DBG(rdata, "Port entered RTV state from %s state\n",
1384 fc_rport_state(rdata));
1386 fc_rport_state_enter(rdata, RPORT_ST_RTV);
1388 fp = fc_frame_alloc(lport, sizeof(struct fc_els_rtv));
1390 fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
1394 kref_get(&rdata->kref);
1395 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_RTV,
1396 fc_rport_rtv_resp, rdata,
1397 2 * lport->r_a_tov)) {
1398 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
1399 kref_put(&rdata->kref, fc_rport_destroy);
1404 * fc_rport_recv_rtv_req() - Handler for Read Timeout Value (RTV) requests
1405 * @rdata: The remote port that sent the RTV request
1406 * @in_fp: The RTV request frame
1408 * Locking Note: Called with the lport and rport locks held.
1410 static void fc_rport_recv_rtv_req(struct fc_rport_priv *rdata,
1411 struct fc_frame *in_fp)
1413 struct fc_lport *lport = rdata->local_port;
1414 struct fc_frame *fp;
1415 struct fc_els_rtv_acc *rtv;
1416 struct fc_seq_els_data rjt_data;
1418 FC_RPORT_DBG(rdata, "Received RTV request\n");
1420 fp = fc_frame_alloc(lport, sizeof(*rtv));
1422 rjt_data.reason = ELS_RJT_UNAB;
1423 rjt_data.reason = ELS_EXPL_INSUF_RES;
1424 fc_seq_els_rsp_send(in_fp, ELS_LS_RJT, &rjt_data);
1427 rtv = fc_frame_payload_get(fp, sizeof(*rtv));
1428 rtv->rtv_cmd = ELS_LS_ACC;
1429 rtv->rtv_r_a_tov = htonl(lport->r_a_tov);
1430 rtv->rtv_e_d_tov = htonl(lport->e_d_tov);
1432 fc_fill_reply_hdr(fp, in_fp, FC_RCTL_ELS_REP, 0);
1433 lport->tt.frame_send(lport, fp);
1435 fc_frame_free(in_fp);
1439 * fc_rport_logo_resp() - Handler for logout (LOGO) responses
1440 * @sp: The sequence the LOGO was on
1441 * @fp: The LOGO response frame
1442 * @lport_arg: The local port
1444 static void fc_rport_logo_resp(struct fc_seq *sp, struct fc_frame *fp,
1447 struct fc_rport_priv *rdata = rdata_arg;
1448 struct fc_lport *lport = rdata->local_port;
1450 FC_RPORT_ID_DBG(lport, fc_seq_exch(sp)->did,
1451 "Received a LOGO %s\n", fc_els_resp_type(fp));
1454 kref_put(&rdata->kref, fc_rport_destroy);
1458 * fc_rport_enter_logo() - Send a logout (LOGO) request
1459 * @rdata: The remote port to send the LOGO request to
1461 * Locking Note: The rport lock is expected to be held before calling
1464 * Reference counting: increments kref when sending ELS
1466 static void fc_rport_enter_logo(struct fc_rport_priv *rdata)
1468 struct fc_lport *lport = rdata->local_port;
1469 struct fc_frame *fp;
1471 FC_RPORT_DBG(rdata, "Port sending LOGO from %s state\n",
1472 fc_rport_state(rdata));
1474 fp = fc_frame_alloc(lport, sizeof(struct fc_els_logo));
1477 kref_get(&rdata->kref);
1478 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_LOGO,
1479 fc_rport_logo_resp, rdata, 0))
1480 kref_put(&rdata->kref, fc_rport_destroy);
1484 * fc_rport_els_adisc_resp() - Handler for Address Discovery (ADISC) responses
1485 * @sp: The sequence the ADISC response was on
1486 * @fp: The ADISC response frame
1487 * @rdata_arg: The remote port that sent the ADISC response
1489 * Locking Note: This function will be called without the rport lock
1490 * held, but it will lock, call an _enter_* function or fc_rport_error
1491 * and then unlock the rport.
1493 static void fc_rport_adisc_resp(struct fc_seq *sp, struct fc_frame *fp,
1496 struct fc_rport_priv *rdata = rdata_arg;
1497 struct fc_els_adisc *adisc;
1500 FC_RPORT_DBG(rdata, "Received a ADISC response\n");
1502 if (fp == ERR_PTR(-FC_EX_CLOSED))
1505 mutex_lock(&rdata->rp_mutex);
1507 if (rdata->rp_state != RPORT_ST_ADISC) {
1508 FC_RPORT_DBG(rdata, "Received a ADISC resp but in state %s\n",
1509 fc_rport_state(rdata));
1516 fc_rport_error(rdata, PTR_ERR(fp));
1521 * If address verification failed. Consider us logged out of the rport.
1522 * Since the rport is still in discovery, we want to be
1523 * logged in, so go to PLOGI state. Otherwise, go back to READY.
1525 op = fc_frame_payload_op(fp);
1526 adisc = fc_frame_payload_get(fp, sizeof(*adisc));
1527 if (op != ELS_LS_ACC || !adisc ||
1528 ntoh24(adisc->adisc_port_id) != rdata->ids.port_id ||
1529 get_unaligned_be64(&adisc->adisc_wwpn) != rdata->ids.port_name ||
1530 get_unaligned_be64(&adisc->adisc_wwnn) != rdata->ids.node_name) {
1531 FC_RPORT_DBG(rdata, "ADISC error or mismatch\n");
1532 fc_rport_enter_flogi(rdata);
1534 FC_RPORT_DBG(rdata, "ADISC OK\n");
1535 fc_rport_enter_ready(rdata);
1540 mutex_unlock(&rdata->rp_mutex);
1542 kref_put(&rdata->kref, fc_rport_destroy);
1546 * fc_rport_enter_adisc() - Send Address Discover (ADISC) request
1547 * @rdata: The remote port to send the ADISC request to
1549 * Locking Note: The rport lock is expected to be held before calling
1552 * Reference counting: increments kref when sending ELS
1554 static void fc_rport_enter_adisc(struct fc_rport_priv *rdata)
1556 struct fc_lport *lport = rdata->local_port;
1557 struct fc_frame *fp;
1559 FC_RPORT_DBG(rdata, "sending ADISC from %s state\n",
1560 fc_rport_state(rdata));
1562 fc_rport_state_enter(rdata, RPORT_ST_ADISC);
1564 fp = fc_frame_alloc(lport, sizeof(struct fc_els_adisc));
1566 fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
1569 kref_get(&rdata->kref);
1570 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_ADISC,
1571 fc_rport_adisc_resp, rdata,
1572 2 * lport->r_a_tov)) {
1573 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
1574 kref_put(&rdata->kref, fc_rport_destroy);
1579 * fc_rport_recv_adisc_req() - Handler for Address Discovery (ADISC) requests
1580 * @rdata: The remote port that sent the ADISC request
1581 * @in_fp: The ADISC request frame
1583 * Locking Note: Called with the lport and rport locks held.
1585 static void fc_rport_recv_adisc_req(struct fc_rport_priv *rdata,
1586 struct fc_frame *in_fp)
1588 struct fc_lport *lport = rdata->local_port;
1589 struct fc_frame *fp;
1590 struct fc_els_adisc *adisc;
1591 struct fc_seq_els_data rjt_data;
1593 FC_RPORT_DBG(rdata, "Received ADISC request\n");
1595 adisc = fc_frame_payload_get(in_fp, sizeof(*adisc));
1597 rjt_data.reason = ELS_RJT_PROT;
1598 rjt_data.explan = ELS_EXPL_INV_LEN;
1599 fc_seq_els_rsp_send(in_fp, ELS_LS_RJT, &rjt_data);
1603 fp = fc_frame_alloc(lport, sizeof(*adisc));
1606 fc_adisc_fill(lport, fp);
1607 adisc = fc_frame_payload_get(fp, sizeof(*adisc));
1608 adisc->adisc_cmd = ELS_LS_ACC;
1609 fc_fill_reply_hdr(fp, in_fp, FC_RCTL_ELS_REP, 0);
1610 lport->tt.frame_send(lport, fp);
1612 fc_frame_free(in_fp);
1616 * fc_rport_recv_rls_req() - Handle received Read Link Status request
1617 * @rdata: The remote port that sent the RLS request
1618 * @rx_fp: The PRLI request frame
1620 * Locking Note: The rport lock is expected to be held before calling
1623 static void fc_rport_recv_rls_req(struct fc_rport_priv *rdata,
1624 struct fc_frame *rx_fp)
1627 struct fc_lport *lport = rdata->local_port;
1628 struct fc_frame *fp;
1629 struct fc_els_rls *rls;
1630 struct fc_els_rls_resp *rsp;
1631 struct fc_els_lesb *lesb;
1632 struct fc_seq_els_data rjt_data;
1633 struct fc_host_statistics *hst;
1635 FC_RPORT_DBG(rdata, "Received RLS request while in state %s\n",
1636 fc_rport_state(rdata));
1638 rls = fc_frame_payload_get(rx_fp, sizeof(*rls));
1640 rjt_data.reason = ELS_RJT_PROT;
1641 rjt_data.explan = ELS_EXPL_INV_LEN;
1645 fp = fc_frame_alloc(lport, sizeof(*rsp));
1647 rjt_data.reason = ELS_RJT_UNAB;
1648 rjt_data.explan = ELS_EXPL_INSUF_RES;
1652 rsp = fc_frame_payload_get(fp, sizeof(*rsp));
1653 memset(rsp, 0, sizeof(*rsp));
1654 rsp->rls_cmd = ELS_LS_ACC;
1655 lesb = &rsp->rls_lesb;
1656 if (lport->tt.get_lesb) {
1657 /* get LESB from LLD if it supports it */
1658 lport->tt.get_lesb(lport, lesb);
1660 fc_get_host_stats(lport->host);
1661 hst = &lport->host_stats;
1662 lesb->lesb_link_fail = htonl(hst->link_failure_count);
1663 lesb->lesb_sync_loss = htonl(hst->loss_of_sync_count);
1664 lesb->lesb_sig_loss = htonl(hst->loss_of_signal_count);
1665 lesb->lesb_prim_err = htonl(hst->prim_seq_protocol_err_count);
1666 lesb->lesb_inv_word = htonl(hst->invalid_tx_word_count);
1667 lesb->lesb_inv_crc = htonl(hst->invalid_crc_count);
1670 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
1671 lport->tt.frame_send(lport, fp);
1675 fc_seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
1677 fc_frame_free(rx_fp);
1681 * fc_rport_recv_els_req() - Handler for validated ELS requests
1682 * @lport: The local port that received the ELS request
1683 * @fp: The ELS request frame
1685 * Handle incoming ELS requests that require port login.
1686 * The ELS opcode has already been validated by the caller.
1688 * Locking Note: Called with the lport lock held.
1690 * Reference counting: does not modify kref
1692 static void fc_rport_recv_els_req(struct fc_lport *lport, struct fc_frame *fp)
1694 struct fc_rport_priv *rdata;
1695 struct fc_seq_els_data els_data;
1697 rdata = fc_rport_lookup(lport, fc_frame_sid(fp));
1699 FC_RPORT_ID_DBG(lport, fc_frame_sid(fp),
1700 "Received ELS 0x%02x from non-logged-in port\n",
1701 fc_frame_payload_op(fp));
1705 mutex_lock(&rdata->rp_mutex);
1707 switch (rdata->rp_state) {
1710 case RPORT_ST_READY:
1711 case RPORT_ST_ADISC:
1713 case RPORT_ST_PLOGI:
1714 if (fc_frame_payload_op(fp) == ELS_PRLI) {
1715 FC_RPORT_DBG(rdata, "Reject ELS PRLI "
1716 "while in state %s\n",
1717 fc_rport_state(rdata));
1718 mutex_unlock(&rdata->rp_mutex);
1719 kref_put(&rdata->kref, fc_rport_destroy);
1724 "Reject ELS 0x%02x while in state %s\n",
1725 fc_frame_payload_op(fp), fc_rport_state(rdata));
1726 mutex_unlock(&rdata->rp_mutex);
1727 kref_put(&rdata->kref, fc_rport_destroy);
1731 switch (fc_frame_payload_op(fp)) {
1733 fc_rport_recv_prli_req(rdata, fp);
1736 fc_rport_recv_prlo_req(rdata, fp);
1739 fc_rport_recv_adisc_req(rdata, fp);
1742 fc_seq_els_rsp_send(fp, ELS_RRQ, NULL);
1746 fc_seq_els_rsp_send(fp, ELS_REC, NULL);
1750 fc_rport_recv_rls_req(rdata, fp);
1753 fc_rport_recv_rtv_req(rdata, fp);
1756 fc_frame_free(fp); /* can't happen */
1760 mutex_unlock(&rdata->rp_mutex);
1761 kref_put(&rdata->kref, fc_rport_destroy);
1765 els_data.reason = ELS_RJT_UNAB;
1766 els_data.explan = ELS_EXPL_PLOGI_REQD;
1767 fc_seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
1772 els_data.reason = ELS_RJT_BUSY;
1773 els_data.explan = ELS_EXPL_NONE;
1774 fc_seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
1780 * fc_rport_recv_req() - Handler for requests
1781 * @lport: The local port that received the request
1782 * @fp: The request frame
1784 * Locking Note: Called with the lport lock held.
1786 * Reference counting: does not modify kref
1788 void fc_rport_recv_req(struct fc_lport *lport, struct fc_frame *fp)
1790 struct fc_seq_els_data els_data;
1793 * Handle FLOGI, PLOGI and LOGO requests separately, since they
1794 * don't require prior login.
1795 * Check for unsupported opcodes first and reject them.
1796 * For some ops, it would be incorrect to reject with "PLOGI required".
1798 switch (fc_frame_payload_op(fp)) {
1800 fc_rport_recv_flogi_req(lport, fp);
1803 fc_rport_recv_plogi_req(lport, fp);
1806 fc_rport_recv_logo_req(lport, fp);
1815 fc_rport_recv_els_req(lport, fp);
1818 els_data.reason = ELS_RJT_UNSUP;
1819 els_data.explan = ELS_EXPL_NONE;
1820 fc_seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
1825 EXPORT_SYMBOL(fc_rport_recv_req);
1828 * fc_rport_recv_plogi_req() - Handler for Port Login (PLOGI) requests
1829 * @lport: The local port that received the PLOGI request
1830 * @rx_fp: The PLOGI request frame
1832 * Locking Note: The rport lock is held before calling this function.
1834 * Reference counting: increments kref on return
1836 static void fc_rport_recv_plogi_req(struct fc_lport *lport,
1837 struct fc_frame *rx_fp)
1839 struct fc_disc *disc;
1840 struct fc_rport_priv *rdata;
1841 struct fc_frame *fp = rx_fp;
1842 struct fc_els_flogi *pl;
1843 struct fc_seq_els_data rjt_data;
1846 sid = fc_frame_sid(fp);
1848 FC_RPORT_ID_DBG(lport, sid, "Received PLOGI request\n");
1850 pl = fc_frame_payload_get(fp, sizeof(*pl));
1852 FC_RPORT_ID_DBG(lport, sid, "Received PLOGI too short\n");
1853 rjt_data.reason = ELS_RJT_PROT;
1854 rjt_data.explan = ELS_EXPL_INV_LEN;
1858 disc = &lport->disc;
1859 mutex_lock(&disc->disc_mutex);
1860 rdata = fc_rport_create(lport, sid);
1862 mutex_unlock(&disc->disc_mutex);
1863 rjt_data.reason = ELS_RJT_UNAB;
1864 rjt_data.explan = ELS_EXPL_INSUF_RES;
1868 mutex_lock(&rdata->rp_mutex);
1869 mutex_unlock(&disc->disc_mutex);
1871 rdata->ids.port_name = get_unaligned_be64(&pl->fl_wwpn);
1872 rdata->ids.node_name = get_unaligned_be64(&pl->fl_wwnn);
1875 * If the rport was just created, possibly due to the incoming PLOGI,
1876 * set the state appropriately and accept the PLOGI.
1878 * If we had also sent a PLOGI, and if the received PLOGI is from a
1879 * higher WWPN, we accept it, otherwise an LS_RJT is sent with reason
1880 * "command already in progress".
1882 * XXX TBD: If the session was ready before, the PLOGI should result in
1883 * all outstanding exchanges being reset.
1885 switch (rdata->rp_state) {
1887 FC_RPORT_DBG(rdata, "Received PLOGI in INIT state\n");
1889 case RPORT_ST_PLOGI_WAIT:
1890 FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI_WAIT state\n");
1892 case RPORT_ST_PLOGI:
1893 FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI state\n");
1894 if (rdata->ids.port_name < lport->wwpn) {
1895 mutex_unlock(&rdata->rp_mutex);
1896 rjt_data.reason = ELS_RJT_INPROG;
1897 rjt_data.explan = ELS_EXPL_NONE;
1903 case RPORT_ST_READY:
1904 case RPORT_ST_ADISC:
1905 FC_RPORT_DBG(rdata, "Received PLOGI in logged-in state %d "
1906 "- ignored for now\n", rdata->rp_state);
1907 /* XXX TBD - should reset */
1909 case RPORT_ST_FLOGI:
1910 case RPORT_ST_DELETE:
1911 FC_RPORT_DBG(rdata, "Received PLOGI in state %s - send busy\n",
1912 fc_rport_state(rdata));
1913 mutex_unlock(&rdata->rp_mutex);
1914 rjt_data.reason = ELS_RJT_BUSY;
1915 rjt_data.explan = ELS_EXPL_NONE;
1918 if (!fc_rport_compatible_roles(lport, rdata)) {
1919 FC_RPORT_DBG(rdata, "Received PLOGI for incompatible role\n");
1920 mutex_unlock(&rdata->rp_mutex);
1921 rjt_data.reason = ELS_RJT_LOGIC;
1922 rjt_data.explan = ELS_EXPL_NONE;
1927 * Get session payload size from incoming PLOGI.
1929 rdata->maxframe_size = fc_plogi_get_maxframe(pl, lport->mfs);
1932 * Send LS_ACC. If this fails, the originator should retry.
1934 fp = fc_frame_alloc(lport, sizeof(*pl));
1938 fc_plogi_fill(lport, fp, ELS_LS_ACC);
1939 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
1940 lport->tt.frame_send(lport, fp);
1941 fc_rport_enter_prli(rdata);
1943 mutex_unlock(&rdata->rp_mutex);
1944 fc_frame_free(rx_fp);
1948 fc_seq_els_rsp_send(fp, ELS_LS_RJT, &rjt_data);
1953 * fc_rport_recv_prli_req() - Handler for process login (PRLI) requests
1954 * @rdata: The remote port that sent the PRLI request
1955 * @rx_fp: The PRLI request frame
1957 * Locking Note: The rport lock is expected to be held before calling
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 FC_RPORT_DBG(rdata, "Received PRLI request while in state %s\n",
1978 fc_rport_state(rdata));
1980 len = fr_len(rx_fp) - sizeof(struct fc_frame_header);
1981 pp = fc_frame_payload_get(rx_fp, sizeof(*pp));
1984 plen = ntohs(pp->prli.prli_len);
1985 if ((plen % 4) != 0 || plen > len || plen < 16)
1989 plen = pp->prli.prli_spp_len;
1990 if ((plen % 4) != 0 || plen < sizeof(*spp) ||
1991 plen > len || len < sizeof(*pp) || plen < 12)
1995 fp = fc_frame_alloc(lport, len);
1997 rjt_data.reason = ELS_RJT_UNAB;
1998 rjt_data.explan = ELS_EXPL_INSUF_RES;
2001 pp = fc_frame_payload_get(fp, len);
2004 pp->prli.prli_cmd = ELS_LS_ACC;
2005 pp->prli.prli_spp_len = plen;
2006 pp->prli.prli_len = htons(len);
2007 len -= sizeof(struct fc_els_prli);
2010 * Go through all the service parameter pages and build
2011 * response. If plen indicates longer SPP than standard,
2012 * use that. The entire response has been pre-cleared above.
2015 mutex_lock(&fc_prov_mutex);
2016 while (len >= plen) {
2017 rdata->spp_type = rspp->spp_type;
2018 spp->spp_type = rspp->spp_type;
2019 spp->spp_type_ext = rspp->spp_type_ext;
2022 if (rspp->spp_type < FC_FC4_PROV_SIZE) {
2023 enum fc_els_spp_resp active = 0, passive = 0;
2025 prov = fc_active_prov[rspp->spp_type];
2027 active = prov->prli(rdata, plen, rspp, spp);
2028 prov = fc_passive_prov[rspp->spp_type];
2030 passive = prov->prli(rdata, plen, rspp, spp);
2031 if (!active || passive == FC_SPP_RESP_ACK)
2035 FC_RPORT_DBG(rdata, "PRLI rspp type %x "
2036 "active %x passive %x\n",
2037 rspp->spp_type, active, passive);
2040 if (spp->spp_flags & FC_SPP_EST_IMG_PAIR)
2041 resp |= FC_SPP_RESP_CONF;
2043 resp |= FC_SPP_RESP_INVL;
2045 spp->spp_flags |= resp;
2047 rspp = (struct fc_els_spp *)((char *)rspp + plen);
2048 spp = (struct fc_els_spp *)((char *)spp + plen);
2050 mutex_unlock(&fc_prov_mutex);
2053 * Send LS_ACC. If this fails, the originator should retry.
2055 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
2056 lport->tt.frame_send(lport, fp);
2061 rjt_data.reason = ELS_RJT_PROT;
2062 rjt_data.explan = ELS_EXPL_INV_LEN;
2064 fc_seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
2066 fc_frame_free(rx_fp);
2070 * fc_rport_recv_prlo_req() - Handler for process logout (PRLO) requests
2071 * @rdata: The remote port that sent the PRLO request
2072 * @rx_fp: The PRLO request frame
2074 * Locking Note: The rport lock is expected to be held before calling
2077 static void fc_rport_recv_prlo_req(struct fc_rport_priv *rdata,
2078 struct fc_frame *rx_fp)
2080 struct fc_lport *lport = rdata->local_port;
2081 struct fc_frame *fp;
2083 struct fc_els_prlo prlo;
2084 struct fc_els_spp spp;
2086 struct fc_els_spp *rspp; /* request service param page */
2087 struct fc_els_spp *spp; /* response spp */
2090 struct fc_seq_els_data rjt_data;
2092 FC_RPORT_DBG(rdata, "Received PRLO request while in state %s\n",
2093 fc_rport_state(rdata));
2095 len = fr_len(rx_fp) - sizeof(struct fc_frame_header);
2096 pp = fc_frame_payload_get(rx_fp, sizeof(*pp));
2099 plen = ntohs(pp->prlo.prlo_len);
2107 fp = fc_frame_alloc(lport, len);
2109 rjt_data.reason = ELS_RJT_UNAB;
2110 rjt_data.explan = ELS_EXPL_INSUF_RES;
2114 pp = fc_frame_payload_get(fp, len);
2117 pp->prlo.prlo_cmd = ELS_LS_ACC;
2118 pp->prlo.prlo_obs = 0x10;
2119 pp->prlo.prlo_len = htons(len);
2121 spp->spp_type = rspp->spp_type;
2122 spp->spp_type_ext = rspp->spp_type_ext;
2123 spp->spp_flags = FC_SPP_RESP_ACK;
2125 fc_rport_enter_prli(rdata);
2127 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
2128 lport->tt.frame_send(lport, fp);
2132 rjt_data.reason = ELS_RJT_PROT;
2133 rjt_data.explan = ELS_EXPL_INV_LEN;
2135 fc_seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
2137 fc_frame_free(rx_fp);
2141 * fc_rport_recv_logo_req() - Handler for logout (LOGO) requests
2142 * @lport: The local port that received the LOGO request
2143 * @fp: The LOGO request frame
2145 * Locking Note: The rport lock is expected to be held before calling
2148 * Reference counting: drops kref on return
2150 static void fc_rport_recv_logo_req(struct fc_lport *lport, struct fc_frame *fp)
2152 struct fc_rport_priv *rdata;
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);