1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright(c) 2007 - 2008 Intel Corporation. All rights reserved.
5 * Maintained at www.Open-FCoE.org
11 * This file contains all processing regarding fc_rports. It contains the
12 * rport state machine and does all rport interaction with the transport class.
13 * There should be no other places in libfc that interact directly with the
14 * transport class in regards to adding and deleting rports.
16 * fc_rport's represent N_Port's within the fabric.
22 * The rport should never hold the rport mutex and then attempt to acquire
23 * either the lport or disc mutexes. The rport's mutex is considered lesser
24 * than both the lport's mutex and the disc mutex. Refer to fc_lport.c for
25 * more comments on the hierarchy.
27 * The locking strategy is similar to the lport's strategy. The lock protects
28 * the rport's states and is held and released by the entry points to the rport
29 * block. All _enter_* functions correspond to rport states and expect the rport
30 * mutex to be locked before calling them. This means that rports only handle
31 * one request or response at a time, since they're not critical for the I/O
32 * path this potential over-use of the mutex is acceptable.
36 * RPORT REFERENCE COUNTING
38 * A rport reference should be taken when:
39 * - an rport is allocated
40 * - a workqueue item is scheduled
41 * - an ELS request is send
42 * The reference should be dropped when:
43 * - the workqueue function has finished
44 * - the ELS response is handled
45 * - an rport is removed
48 #include <linux/kernel.h>
49 #include <linux/spinlock.h>
50 #include <linux/interrupt.h>
51 #include <linux/slab.h>
52 #include <linux/rcupdate.h>
53 #include <linux/timer.h>
54 #include <linux/workqueue.h>
55 #include <linux/export.h>
56 #include <linux/rculist.h>
58 #include <asm/unaligned.h>
60 #include <scsi/libfc.h>
61 #include <scsi/fc_encode.h>
65 static struct workqueue_struct
*rport_event_queue
;
67 static void fc_rport_enter_flogi(struct fc_rport_priv
*);
68 static void fc_rport_enter_plogi(struct fc_rport_priv
*);
69 static void fc_rport_enter_prli(struct fc_rport_priv
*);
70 static void fc_rport_enter_rtv(struct fc_rport_priv
*);
71 static void fc_rport_enter_ready(struct fc_rport_priv
*);
72 static void fc_rport_enter_logo(struct fc_rport_priv
*);
73 static void fc_rport_enter_adisc(struct fc_rport_priv
*);
75 static void fc_rport_recv_plogi_req(struct fc_lport
*, struct fc_frame
*);
76 static void fc_rport_recv_prli_req(struct fc_rport_priv
*, struct fc_frame
*);
77 static void fc_rport_recv_prlo_req(struct fc_rport_priv
*, struct fc_frame
*);
78 static void fc_rport_recv_logo_req(struct fc_lport
*, struct fc_frame
*);
79 static void fc_rport_timeout(struct work_struct
*);
80 static void fc_rport_error(struct fc_rport_priv
*, int);
81 static void fc_rport_error_retry(struct fc_rport_priv
*, int);
82 static void fc_rport_work(struct work_struct
*);
84 static const char *fc_rport_state_names
[] = {
85 [RPORT_ST_INIT
] = "Init",
86 [RPORT_ST_FLOGI
] = "FLOGI",
87 [RPORT_ST_PLOGI_WAIT
] = "PLOGI_WAIT",
88 [RPORT_ST_PLOGI
] = "PLOGI",
89 [RPORT_ST_PRLI
] = "PRLI",
90 [RPORT_ST_RTV
] = "RTV",
91 [RPORT_ST_READY
] = "Ready",
92 [RPORT_ST_ADISC
] = "ADISC",
93 [RPORT_ST_DELETE
] = "Delete",
97 * fc_rport_lookup() - Lookup a remote port by port_id
98 * @lport: The local port to lookup the remote port on
99 * @port_id: The remote port ID to look up
101 * The reference count of the fc_rport_priv structure is
104 struct fc_rport_priv
*fc_rport_lookup(const struct fc_lport
*lport
,
107 struct fc_rport_priv
*rdata
= NULL
, *tmp_rdata
;
110 list_for_each_entry_rcu(tmp_rdata
, &lport
->disc
.rports
, peers
)
111 if (tmp_rdata
->ids
.port_id
== port_id
&&
112 kref_get_unless_zero(&tmp_rdata
->kref
)) {
119 EXPORT_SYMBOL(fc_rport_lookup
);
122 * fc_rport_create() - Create a new remote port
123 * @lport: The local port this remote port will be associated with
124 * @ids: The identifiers for the new remote port
126 * The remote port will start in the INIT state.
128 struct fc_rport_priv
*fc_rport_create(struct fc_lport
*lport
, u32 port_id
)
130 struct fc_rport_priv
*rdata
;
131 size_t rport_priv_size
= sizeof(*rdata
);
133 lockdep_assert_held(&lport
->disc
.disc_mutex
);
135 rdata
= fc_rport_lookup(lport
, port_id
);
139 if (lport
->rport_priv_size
> 0)
140 rport_priv_size
= lport
->rport_priv_size
;
141 rdata
= kzalloc(rport_priv_size
, GFP_KERNEL
);
145 rdata
->ids
.node_name
= -1;
146 rdata
->ids
.port_name
= -1;
147 rdata
->ids
.port_id
= port_id
;
148 rdata
->ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
150 kref_init(&rdata
->kref
);
151 mutex_init(&rdata
->rp_mutex
);
152 rdata
->local_port
= lport
;
153 rdata
->rp_state
= RPORT_ST_INIT
;
154 rdata
->event
= RPORT_EV_NONE
;
155 rdata
->flags
= FC_RP_FLAGS_REC_SUPPORTED
;
156 rdata
->e_d_tov
= lport
->e_d_tov
;
157 rdata
->r_a_tov
= lport
->r_a_tov
;
158 rdata
->maxframe_size
= FC_MIN_MAX_PAYLOAD
;
159 INIT_DELAYED_WORK(&rdata
->retry_work
, fc_rport_timeout
);
160 INIT_WORK(&rdata
->event_work
, fc_rport_work
);
161 if (port_id
!= FC_FID_DIR_SERV
) {
162 rdata
->lld_event_callback
= lport
->tt
.rport_event_callback
;
163 list_add_rcu(&rdata
->peers
, &lport
->disc
.rports
);
167 EXPORT_SYMBOL(fc_rport_create
);
170 * fc_rport_destroy() - Free a remote port after last reference is released
171 * @kref: The remote port's kref
173 void fc_rport_destroy(struct kref
*kref
)
175 struct fc_rport_priv
*rdata
;
177 rdata
= container_of(kref
, struct fc_rport_priv
, kref
);
178 kfree_rcu(rdata
, rcu
);
180 EXPORT_SYMBOL(fc_rport_destroy
);
183 * fc_rport_state() - Return a string identifying the remote port's state
184 * @rdata: The remote port
186 static const char *fc_rport_state(struct fc_rport_priv
*rdata
)
190 cp
= fc_rport_state_names
[rdata
->rp_state
];
197 * fc_set_rport_loss_tmo() - Set the remote port loss timeout
198 * @rport: The remote port that gets a new timeout value
199 * @timeout: The new timeout value (in seconds)
201 void fc_set_rport_loss_tmo(struct fc_rport
*rport
, u32 timeout
)
204 rport
->dev_loss_tmo
= timeout
;
206 rport
->dev_loss_tmo
= 1;
208 EXPORT_SYMBOL(fc_set_rport_loss_tmo
);
211 * fc_plogi_get_maxframe() - Get the maximum payload from the common service
212 * parameters in a FLOGI frame
213 * @flp: The FLOGI or PLOGI payload
214 * @maxval: The maximum frame size upper limit; this may be less than what
215 * is in the service parameters
217 static unsigned int fc_plogi_get_maxframe(struct fc_els_flogi
*flp
,
223 * Get max payload from the common service parameters and the
224 * class 3 receive data field size.
226 mfs
= ntohs(flp
->fl_csp
.sp_bb_data
) & FC_SP_BB_DATA_MASK
;
227 if (mfs
>= FC_SP_MIN_MAX_PAYLOAD
&& mfs
< maxval
)
229 mfs
= ntohs(flp
->fl_cssp
[3 - 1].cp_rdfs
);
230 if (mfs
>= FC_SP_MIN_MAX_PAYLOAD
&& mfs
< maxval
)
236 * fc_rport_state_enter() - Change the state of a remote port
237 * @rdata: The remote port whose state should change
238 * @new: The new state
240 static void fc_rport_state_enter(struct fc_rport_priv
*rdata
,
241 enum fc_rport_state
new)
243 lockdep_assert_held(&rdata
->rp_mutex
);
245 if (rdata
->rp_state
!= new)
247 rdata
->rp_state
= new;
251 * fc_rport_work() - Handler for remote port events in the rport_event_queue
252 * @work: Handle to the remote port being dequeued
254 * Reference counting: drops kref on return
256 static void fc_rport_work(struct work_struct
*work
)
259 struct fc_rport_priv
*rdata
=
260 container_of(work
, struct fc_rport_priv
, event_work
);
261 struct fc_rport_libfc_priv
*rpriv
;
262 enum fc_rport_event event
;
263 struct fc_lport
*lport
= rdata
->local_port
;
264 struct fc_rport_operations
*rport_ops
;
265 struct fc_rport_identifiers ids
;
266 struct fc_rport
*rport
;
267 struct fc4_prov
*prov
;
270 mutex_lock(&rdata
->rp_mutex
);
271 event
= rdata
->event
;
272 rport_ops
= rdata
->ops
;
273 rport
= rdata
->rport
;
275 FC_RPORT_DBG(rdata
, "work event %u\n", event
);
280 rdata
->event
= RPORT_EV_NONE
;
281 rdata
->major_retries
= 0;
282 kref_get(&rdata
->kref
);
283 mutex_unlock(&rdata
->rp_mutex
);
286 FC_RPORT_DBG(rdata
, "No rport!\n");
287 rport
= fc_remote_port_add(lport
->host
, 0, &ids
);
290 FC_RPORT_DBG(rdata
, "Failed to add the rport\n");
291 fc_rport_logoff(rdata
);
292 kref_put(&rdata
->kref
, fc_rport_destroy
);
295 mutex_lock(&rdata
->rp_mutex
);
297 FC_RPORT_DBG(rdata
, "rport already allocated\n");
298 rdata
->rport
= rport
;
299 rport
->maxframe_size
= rdata
->maxframe_size
;
300 rport
->supported_classes
= rdata
->supported_classes
;
302 rpriv
= rport
->dd_data
;
303 rpriv
->local_port
= lport
;
304 rpriv
->rp_state
= rdata
->rp_state
;
305 rpriv
->flags
= rdata
->flags
;
306 rpriv
->e_d_tov
= rdata
->e_d_tov
;
307 rpriv
->r_a_tov
= rdata
->r_a_tov
;
308 mutex_unlock(&rdata
->rp_mutex
);
310 if (rport_ops
&& rport_ops
->event_callback
) {
311 FC_RPORT_DBG(rdata
, "callback ev %d\n", event
);
312 rport_ops
->event_callback(lport
, rdata
, event
);
314 if (rdata
->lld_event_callback
) {
315 FC_RPORT_DBG(rdata
, "lld callback ev %d\n", event
);
316 rdata
->lld_event_callback(lport
, rdata
, event
);
318 kref_put(&rdata
->kref
, fc_rport_destroy
);
321 case RPORT_EV_FAILED
:
324 if (rdata
->prli_count
) {
325 mutex_lock(&fc_prov_mutex
);
326 for (type
= 1; type
< FC_FC4_PROV_SIZE
; type
++) {
327 prov
= fc_passive_prov
[type
];
328 if (prov
&& prov
->prlo
)
331 mutex_unlock(&fc_prov_mutex
);
333 port_id
= rdata
->ids
.port_id
;
334 mutex_unlock(&rdata
->rp_mutex
);
336 if (rport_ops
&& rport_ops
->event_callback
) {
337 FC_RPORT_DBG(rdata
, "callback ev %d\n", event
);
338 rport_ops
->event_callback(lport
, rdata
, event
);
340 if (rdata
->lld_event_callback
) {
341 FC_RPORT_DBG(rdata
, "lld callback ev %d\n", event
);
342 rdata
->lld_event_callback(lport
, rdata
, event
);
344 if (cancel_delayed_work_sync(&rdata
->retry_work
))
345 kref_put(&rdata
->kref
, fc_rport_destroy
);
348 * Reset any outstanding exchanges before freeing rport.
350 lport
->tt
.exch_mgr_reset(lport
, 0, port_id
);
351 lport
->tt
.exch_mgr_reset(lport
, port_id
, 0);
354 rpriv
= rport
->dd_data
;
355 rpriv
->rp_state
= RPORT_ST_DELETE
;
356 mutex_lock(&rdata
->rp_mutex
);
358 mutex_unlock(&rdata
->rp_mutex
);
359 fc_remote_port_delete(rport
);
362 mutex_lock(&rdata
->rp_mutex
);
363 if (rdata
->rp_state
== RPORT_ST_DELETE
) {
364 if (port_id
== FC_FID_DIR_SERV
) {
365 rdata
->event
= RPORT_EV_NONE
;
366 mutex_unlock(&rdata
->rp_mutex
);
367 kref_put(&rdata
->kref
, fc_rport_destroy
);
368 } else if ((rdata
->flags
& FC_RP_STARTED
) &&
369 rdata
->major_retries
<
370 lport
->max_rport_retry_count
) {
371 rdata
->major_retries
++;
372 rdata
->event
= RPORT_EV_NONE
;
373 FC_RPORT_DBG(rdata
, "work restart\n");
374 fc_rport_enter_flogi(rdata
);
375 mutex_unlock(&rdata
->rp_mutex
);
377 mutex_unlock(&rdata
->rp_mutex
);
378 FC_RPORT_DBG(rdata
, "work delete\n");
379 mutex_lock(&lport
->disc
.disc_mutex
);
380 list_del_rcu(&rdata
->peers
);
381 mutex_unlock(&lport
->disc
.disc_mutex
);
382 kref_put(&rdata
->kref
, fc_rport_destroy
);
386 * Re-open for events. Reissue READY event if ready.
388 rdata
->event
= RPORT_EV_NONE
;
389 if (rdata
->rp_state
== RPORT_ST_READY
) {
390 FC_RPORT_DBG(rdata
, "work reopen\n");
391 fc_rport_enter_ready(rdata
);
393 mutex_unlock(&rdata
->rp_mutex
);
398 mutex_unlock(&rdata
->rp_mutex
);
401 kref_put(&rdata
->kref
, fc_rport_destroy
);
405 * fc_rport_login() - Start the remote port login state machine
406 * @rdata: The remote port to be logged in to
408 * Initiates the RP state machine. It is called from the LP module.
409 * This function will issue the following commands to the N_Port
410 * identified by the FC ID provided.
416 * Locking Note: Called without the rport lock held. This
417 * function will hold the rport lock, call an _enter_*
418 * function and then unlock the rport.
420 * This indicates the intent to be logged into the remote port.
421 * If it appears we are already logged in, ADISC is used to verify
424 int fc_rport_login(struct fc_rport_priv
*rdata
)
426 mutex_lock(&rdata
->rp_mutex
);
428 if (rdata
->flags
& FC_RP_STARTED
) {
429 FC_RPORT_DBG(rdata
, "port already started\n");
430 mutex_unlock(&rdata
->rp_mutex
);
434 rdata
->flags
|= FC_RP_STARTED
;
435 switch (rdata
->rp_state
) {
437 FC_RPORT_DBG(rdata
, "ADISC port\n");
438 fc_rport_enter_adisc(rdata
);
440 case RPORT_ST_DELETE
:
441 FC_RPORT_DBG(rdata
, "Restart deleted port\n");
444 FC_RPORT_DBG(rdata
, "Login to port\n");
445 fc_rport_enter_flogi(rdata
);
448 FC_RPORT_DBG(rdata
, "Login in progress, state %s\n",
449 fc_rport_state(rdata
));
452 mutex_unlock(&rdata
->rp_mutex
);
456 EXPORT_SYMBOL(fc_rport_login
);
459 * fc_rport_enter_delete() - Schedule a remote port to be deleted
460 * @rdata: The remote port to be deleted
461 * @event: The event to report as the reason for deletion
463 * Allow state change into DELETE only once.
465 * Call queue_work only if there's no event already pending.
466 * Set the new event so that the old pending event will not occur.
467 * Since we have the mutex, even if fc_rport_work() is already started,
468 * it'll see the new event.
470 * Reference counting: does not modify kref
472 static void fc_rport_enter_delete(struct fc_rport_priv
*rdata
,
473 enum fc_rport_event event
)
475 lockdep_assert_held(&rdata
->rp_mutex
);
477 if (rdata
->rp_state
== RPORT_ST_DELETE
)
480 FC_RPORT_DBG(rdata
, "Delete port\n");
482 fc_rport_state_enter(rdata
, RPORT_ST_DELETE
);
484 kref_get(&rdata
->kref
);
485 if (rdata
->event
== RPORT_EV_NONE
&&
486 !queue_work(rport_event_queue
, &rdata
->event_work
))
487 kref_put(&rdata
->kref
, fc_rport_destroy
);
489 rdata
->event
= event
;
493 * fc_rport_logoff() - Logoff and remove a remote port
494 * @rdata: The remote port to be logged off of
496 * Locking Note: Called without the rport lock held. This
497 * function will hold the rport lock, call an _enter_*
498 * function and then unlock the rport.
500 int fc_rport_logoff(struct fc_rport_priv
*rdata
)
502 struct fc_lport
*lport
= rdata
->local_port
;
503 u32 port_id
= rdata
->ids
.port_id
;
505 mutex_lock(&rdata
->rp_mutex
);
507 FC_RPORT_DBG(rdata
, "Remove port\n");
509 rdata
->flags
&= ~FC_RP_STARTED
;
510 if (rdata
->rp_state
== RPORT_ST_DELETE
) {
511 FC_RPORT_DBG(rdata
, "Port in Delete state, not removing\n");
516 * To explicitly Logout, the initiating Nx_Port shall terminate
517 * other open Sequences that it initiated with the destination
518 * Nx_Port prior to performing Logout.
520 lport
->tt
.exch_mgr_reset(lport
, 0, port_id
);
521 lport
->tt
.exch_mgr_reset(lport
, port_id
, 0);
523 fc_rport_enter_logo(rdata
);
526 * Change the state to Delete so that we discard
529 fc_rport_enter_delete(rdata
, RPORT_EV_STOP
);
531 mutex_unlock(&rdata
->rp_mutex
);
534 EXPORT_SYMBOL(fc_rport_logoff
);
537 * fc_rport_enter_ready() - Transition to the RPORT_ST_READY state
538 * @rdata: The remote port that is ready
540 * Reference counting: schedules workqueue, does not modify kref
542 static void fc_rport_enter_ready(struct fc_rport_priv
*rdata
)
544 lockdep_assert_held(&rdata
->rp_mutex
);
546 fc_rport_state_enter(rdata
, RPORT_ST_READY
);
548 FC_RPORT_DBG(rdata
, "Port is Ready\n");
550 kref_get(&rdata
->kref
);
551 if (rdata
->event
== RPORT_EV_NONE
&&
552 !queue_work(rport_event_queue
, &rdata
->event_work
))
553 kref_put(&rdata
->kref
, fc_rport_destroy
);
555 rdata
->event
= RPORT_EV_READY
;
559 * fc_rport_timeout() - Handler for the retry_work timer
560 * @work: Handle to the remote port that has timed out
562 * Locking Note: Called without the rport lock held. This
563 * function will hold the rport lock, call an _enter_*
564 * function and then unlock the rport.
566 * Reference counting: Drops kref on return.
568 static void fc_rport_timeout(struct work_struct
*work
)
570 struct fc_rport_priv
*rdata
=
571 container_of(work
, struct fc_rport_priv
, retry_work
.work
);
573 mutex_lock(&rdata
->rp_mutex
);
574 FC_RPORT_DBG(rdata
, "Port timeout, state %s\n", fc_rport_state(rdata
));
576 switch (rdata
->rp_state
) {
578 fc_rport_enter_flogi(rdata
);
581 fc_rport_enter_plogi(rdata
);
584 fc_rport_enter_prli(rdata
);
587 fc_rport_enter_rtv(rdata
);
590 fc_rport_enter_adisc(rdata
);
592 case RPORT_ST_PLOGI_WAIT
:
595 case RPORT_ST_DELETE
:
599 mutex_unlock(&rdata
->rp_mutex
);
600 kref_put(&rdata
->kref
, fc_rport_destroy
);
604 * fc_rport_error() - Error handler, called once retries have been exhausted
605 * @rdata: The remote port the error is happened on
606 * @err: The error code
608 * Reference counting: does not modify kref
610 static void fc_rport_error(struct fc_rport_priv
*rdata
, int err
)
612 struct fc_lport
*lport
= rdata
->local_port
;
614 lockdep_assert_held(&rdata
->rp_mutex
);
616 FC_RPORT_DBG(rdata
, "Error %d in state %s, retries %d\n",
617 -err
, fc_rport_state(rdata
), rdata
->retries
);
619 switch (rdata
->rp_state
) {
621 rdata
->flags
&= ~FC_RP_STARTED
;
622 fc_rport_enter_delete(rdata
, RPORT_EV_FAILED
);
625 if (lport
->point_to_multipoint
) {
626 rdata
->flags
&= ~FC_RP_STARTED
;
627 fc_rport_enter_delete(rdata
, RPORT_EV_FAILED
);
629 fc_rport_enter_logo(rdata
);
632 fc_rport_enter_ready(rdata
);
635 fc_rport_enter_plogi(rdata
);
638 fc_rport_enter_logo(rdata
);
640 case RPORT_ST_PLOGI_WAIT
:
641 case RPORT_ST_DELETE
:
649 * fc_rport_error_retry() - Handler for remote port state retries
650 * @rdata: The remote port whose state is to be retried
651 * @err: The error code
653 * If the error was an exchange timeout retry immediately,
654 * otherwise wait for E_D_TOV.
656 * Reference counting: increments kref when scheduling retry_work
658 static void fc_rport_error_retry(struct fc_rport_priv
*rdata
, int err
)
660 unsigned long delay
= msecs_to_jiffies(rdata
->e_d_tov
);
662 lockdep_assert_held(&rdata
->rp_mutex
);
664 /* make sure this isn't an FC_EX_CLOSED error, never retry those */
665 if (err
== -FC_EX_CLOSED
)
668 if (rdata
->retries
< rdata
->local_port
->max_rport_retry_count
) {
669 FC_RPORT_DBG(rdata
, "Error %d in state %s, retrying\n",
670 err
, fc_rport_state(rdata
));
672 /* no additional delay on exchange timeouts */
673 if (err
== -FC_EX_TIMEOUT
)
675 kref_get(&rdata
->kref
);
676 if (!schedule_delayed_work(&rdata
->retry_work
, delay
))
677 kref_put(&rdata
->kref
, fc_rport_destroy
);
682 fc_rport_error(rdata
, err
);
686 * fc_rport_login_complete() - Handle parameters and completion of p-mp login.
687 * @rdata: The remote port which we logged into or which logged into us.
688 * @fp: The FLOGI or PLOGI request or response frame
690 * Returns non-zero error if a problem is detected with the frame.
691 * Does not free the frame.
693 * This is only used in point-to-multipoint mode for FIP currently.
695 static int fc_rport_login_complete(struct fc_rport_priv
*rdata
,
698 struct fc_lport
*lport
= rdata
->local_port
;
699 struct fc_els_flogi
*flogi
;
700 unsigned int e_d_tov
;
703 flogi
= fc_frame_payload_get(fp
, sizeof(*flogi
));
707 csp_flags
= ntohs(flogi
->fl_csp
.sp_features
);
709 if (fc_frame_payload_op(fp
) == ELS_FLOGI
) {
710 if (csp_flags
& FC_SP_FT_FPORT
) {
711 FC_RPORT_DBG(rdata
, "Fabric bit set in FLOGI\n");
717 * E_D_TOV is not valid on an incoming FLOGI request.
719 e_d_tov
= ntohl(flogi
->fl_csp
.sp_e_d_tov
);
720 if (csp_flags
& FC_SP_FT_EDTR
)
722 if (e_d_tov
> rdata
->e_d_tov
)
723 rdata
->e_d_tov
= e_d_tov
;
725 rdata
->maxframe_size
= fc_plogi_get_maxframe(flogi
, lport
->mfs
);
730 * fc_rport_flogi_resp() - Handle response to FLOGI request for p-mp mode
731 * @sp: The sequence that the FLOGI was on
732 * @fp: The FLOGI response frame
733 * @rp_arg: The remote port that received the FLOGI response
735 static void fc_rport_flogi_resp(struct fc_seq
*sp
, struct fc_frame
*fp
,
738 struct fc_rport_priv
*rdata
= rp_arg
;
739 struct fc_lport
*lport
= rdata
->local_port
;
740 struct fc_els_flogi
*flogi
;
741 unsigned int r_a_tov
;
745 FC_RPORT_DBG(rdata
, "Received a FLOGI %s\n",
746 IS_ERR(fp
) ? "error" : fc_els_resp_type(fp
));
748 if (fp
== ERR_PTR(-FC_EX_CLOSED
))
751 mutex_lock(&rdata
->rp_mutex
);
753 if (rdata
->rp_state
!= RPORT_ST_FLOGI
) {
754 FC_RPORT_DBG(rdata
, "Received a FLOGI response, but in state "
755 "%s\n", fc_rport_state(rdata
));
762 fc_rport_error(rdata
, PTR_ERR(fp
));
765 opcode
= fc_frame_payload_op(fp
);
766 if (opcode
== ELS_LS_RJT
) {
767 struct fc_els_ls_rjt
*rjt
;
769 rjt
= fc_frame_payload_get(fp
, sizeof(*rjt
));
770 FC_RPORT_DBG(rdata
, "FLOGI ELS rejected, reason %x expl %x\n",
771 rjt
->er_reason
, rjt
->er_explan
);
772 err
= -FC_EX_ELS_RJT
;
774 } else if (opcode
!= ELS_LS_ACC
) {
775 FC_RPORT_DBG(rdata
, "FLOGI ELS invalid opcode %x\n", opcode
);
776 err
= -FC_EX_ELS_RJT
;
779 if (fc_rport_login_complete(rdata
, fp
)) {
780 FC_RPORT_DBG(rdata
, "FLOGI failed, no login\n");
781 err
= -FC_EX_INV_LOGIN
;
785 flogi
= fc_frame_payload_get(fp
, sizeof(*flogi
));
787 err
= -FC_EX_ALLOC_ERR
;
790 r_a_tov
= ntohl(flogi
->fl_csp
.sp_r_a_tov
);
791 if (r_a_tov
> rdata
->r_a_tov
)
792 rdata
->r_a_tov
= r_a_tov
;
794 if (rdata
->ids
.port_name
< lport
->wwpn
)
795 fc_rport_enter_plogi(rdata
);
797 fc_rport_state_enter(rdata
, RPORT_ST_PLOGI_WAIT
);
801 mutex_unlock(&rdata
->rp_mutex
);
803 kref_put(&rdata
->kref
, fc_rport_destroy
);
806 FC_RPORT_DBG(rdata
, "Bad FLOGI response\n");
807 fc_rport_error_retry(rdata
, err
);
812 * fc_rport_enter_flogi() - Send a FLOGI request to the remote port for p-mp
813 * @rdata: The remote port to send a FLOGI to
815 * Reference counting: increments kref when sending ELS
817 static void fc_rport_enter_flogi(struct fc_rport_priv
*rdata
)
819 struct fc_lport
*lport
= rdata
->local_port
;
822 lockdep_assert_held(&rdata
->rp_mutex
);
824 if (!lport
->point_to_multipoint
)
825 return fc_rport_enter_plogi(rdata
);
827 FC_RPORT_DBG(rdata
, "Entered FLOGI state from %s state\n",
828 fc_rport_state(rdata
));
830 fc_rport_state_enter(rdata
, RPORT_ST_FLOGI
);
832 fp
= fc_frame_alloc(lport
, sizeof(struct fc_els_flogi
));
834 return fc_rport_error_retry(rdata
, -FC_EX_ALLOC_ERR
);
836 kref_get(&rdata
->kref
);
837 if (!lport
->tt
.elsct_send(lport
, rdata
->ids
.port_id
, fp
, ELS_FLOGI
,
838 fc_rport_flogi_resp
, rdata
,
839 2 * lport
->r_a_tov
)) {
840 fc_rport_error_retry(rdata
, -FC_EX_XMIT_ERR
);
841 kref_put(&rdata
->kref
, fc_rport_destroy
);
846 * fc_rport_recv_flogi_req() - Handle Fabric Login (FLOGI) request in p-mp mode
847 * @lport: The local port that received the PLOGI request
848 * @rx_fp: The PLOGI request frame
850 * Reference counting: drops kref on return
852 static void fc_rport_recv_flogi_req(struct fc_lport
*lport
,
853 struct fc_frame
*rx_fp
)
855 struct fc_els_flogi
*flp
;
856 struct fc_rport_priv
*rdata
;
857 struct fc_frame
*fp
= rx_fp
;
858 struct fc_seq_els_data rjt_data
;
861 sid
= fc_frame_sid(fp
);
863 FC_RPORT_ID_DBG(lport
, sid
, "Received FLOGI request\n");
865 if (!lport
->point_to_multipoint
) {
866 rjt_data
.reason
= ELS_RJT_UNSUP
;
867 rjt_data
.explan
= ELS_EXPL_NONE
;
871 flp
= fc_frame_payload_get(fp
, sizeof(*flp
));
873 rjt_data
.reason
= ELS_RJT_LOGIC
;
874 rjt_data
.explan
= ELS_EXPL_INV_LEN
;
878 rdata
= fc_rport_lookup(lport
, sid
);
880 rjt_data
.reason
= ELS_RJT_FIP
;
881 rjt_data
.explan
= ELS_EXPL_NOT_NEIGHBOR
;
884 mutex_lock(&rdata
->rp_mutex
);
886 FC_RPORT_DBG(rdata
, "Received FLOGI in %s state\n",
887 fc_rport_state(rdata
));
889 switch (rdata
->rp_state
) {
892 * If received the FLOGI request on RPORT which is INIT state
893 * (means not transition to FLOGI either fc_rport timeout
894 * function didn;t trigger or this end hasn;t received
895 * beacon yet from other end. In that case only, allow RPORT
896 * state machine to continue, otherwise fall through which
897 * causes the code to send reject response.
898 * NOTE; Not checking for FIP->state such as VNMP_UP or
899 * VNMP_CLAIM because if FIP state is not one of those,
900 * RPORT wouldn;t have created and 'rport_lookup' would have
901 * failed anyway in that case.
904 case RPORT_ST_DELETE
:
905 mutex_unlock(&rdata
->rp_mutex
);
906 rjt_data
.reason
= ELS_RJT_FIP
;
907 rjt_data
.explan
= ELS_EXPL_NOT_NEIGHBOR
;
910 case RPORT_ST_PLOGI_WAIT
:
918 * Set the remote port to be deleted and to then restart.
919 * This queues work to be sure exchanges are reset.
921 fc_rport_enter_delete(rdata
, RPORT_EV_LOGO
);
922 mutex_unlock(&rdata
->rp_mutex
);
923 rjt_data
.reason
= ELS_RJT_BUSY
;
924 rjt_data
.explan
= ELS_EXPL_NONE
;
927 if (fc_rport_login_complete(rdata
, fp
)) {
928 mutex_unlock(&rdata
->rp_mutex
);
929 rjt_data
.reason
= ELS_RJT_LOGIC
;
930 rjt_data
.explan
= ELS_EXPL_NONE
;
934 fp
= fc_frame_alloc(lport
, sizeof(*flp
));
938 fc_flogi_fill(lport
, fp
);
939 flp
= fc_frame_payload_get(fp
, sizeof(*flp
));
940 flp
->fl_cmd
= ELS_LS_ACC
;
942 fc_fill_reply_hdr(fp
, rx_fp
, FC_RCTL_ELS_REP
, 0);
943 lport
->tt
.frame_send(lport
, fp
);
946 * Do not proceed with the state machine if our
947 * FLOGI has crossed with an FLOGI from the
948 * remote port; wait for the FLOGI response instead.
950 if (rdata
->rp_state
!= RPORT_ST_FLOGI
) {
951 if (rdata
->ids
.port_name
< lport
->wwpn
)
952 fc_rport_enter_plogi(rdata
);
954 fc_rport_state_enter(rdata
, RPORT_ST_PLOGI_WAIT
);
957 mutex_unlock(&rdata
->rp_mutex
);
958 kref_put(&rdata
->kref
, fc_rport_destroy
);
959 fc_frame_free(rx_fp
);
963 kref_put(&rdata
->kref
, fc_rport_destroy
);
965 fc_seq_els_rsp_send(rx_fp
, ELS_LS_RJT
, &rjt_data
);
966 fc_frame_free(rx_fp
);
970 * fc_rport_plogi_resp() - Handler for ELS PLOGI responses
971 * @sp: The sequence the PLOGI is on
972 * @fp: The PLOGI response frame
973 * @rdata_arg: The remote port that sent the PLOGI response
975 * Locking Note: This function will be called without the rport lock
976 * held, but it will lock, call an _enter_* function or fc_rport_error
977 * and then unlock the rport.
979 static void fc_rport_plogi_resp(struct fc_seq
*sp
, struct fc_frame
*fp
,
982 struct fc_rport_priv
*rdata
= rdata_arg
;
983 struct fc_lport
*lport
= rdata
->local_port
;
984 struct fc_els_flogi
*plp
= NULL
;
989 FC_RPORT_DBG(rdata
, "Received a PLOGI %s\n", fc_els_resp_type(fp
));
991 if (fp
== ERR_PTR(-FC_EX_CLOSED
))
994 mutex_lock(&rdata
->rp_mutex
);
996 if (rdata
->rp_state
!= RPORT_ST_PLOGI
) {
997 FC_RPORT_DBG(rdata
, "Received a PLOGI response, but in state "
998 "%s\n", fc_rport_state(rdata
));
1005 fc_rport_error_retry(rdata
, PTR_ERR(fp
));
1009 op
= fc_frame_payload_op(fp
);
1010 if (op
== ELS_LS_ACC
&&
1011 (plp
= fc_frame_payload_get(fp
, sizeof(*plp
))) != NULL
) {
1012 rdata
->ids
.port_name
= get_unaligned_be64(&plp
->fl_wwpn
);
1013 rdata
->ids
.node_name
= get_unaligned_be64(&plp
->fl_wwnn
);
1015 /* save plogi response sp_features for further reference */
1016 rdata
->sp_features
= ntohs(plp
->fl_csp
.sp_features
);
1018 if (lport
->point_to_multipoint
)
1019 fc_rport_login_complete(rdata
, fp
);
1020 csp_seq
= ntohs(plp
->fl_csp
.sp_tot_seq
);
1021 cssp_seq
= ntohs(plp
->fl_cssp
[3 - 1].cp_con_seq
);
1022 if (cssp_seq
< csp_seq
)
1024 rdata
->max_seq
= csp_seq
;
1025 rdata
->maxframe_size
= fc_plogi_get_maxframe(plp
, lport
->mfs
);
1026 fc_rport_enter_prli(rdata
);
1028 struct fc_els_ls_rjt
*rjt
;
1030 rjt
= fc_frame_payload_get(fp
, sizeof(*rjt
));
1032 FC_RPORT_DBG(rdata
, "PLOGI bad response\n");
1034 FC_RPORT_DBG(rdata
, "PLOGI ELS rejected, reason %x expl %x\n",
1035 rjt
->er_reason
, rjt
->er_explan
);
1036 fc_rport_error_retry(rdata
, -FC_EX_ELS_RJT
);
1041 mutex_unlock(&rdata
->rp_mutex
);
1043 kref_put(&rdata
->kref
, fc_rport_destroy
);
1047 fc_rport_compatible_roles(struct fc_lport
*lport
, struct fc_rport_priv
*rdata
)
1049 if (rdata
->ids
.roles
== FC_PORT_ROLE_UNKNOWN
)
1051 if ((rdata
->ids
.roles
& FC_PORT_ROLE_FCP_TARGET
) &&
1052 (lport
->service_params
& FCP_SPPF_INIT_FCN
))
1054 if ((rdata
->ids
.roles
& FC_PORT_ROLE_FCP_INITIATOR
) &&
1055 (lport
->service_params
& FCP_SPPF_TARG_FCN
))
1061 * fc_rport_enter_plogi() - Send Port Login (PLOGI) request
1062 * @rdata: The remote port to send a PLOGI to
1064 * Reference counting: increments kref when sending ELS
1066 static void fc_rport_enter_plogi(struct fc_rport_priv
*rdata
)
1068 struct fc_lport
*lport
= rdata
->local_port
;
1069 struct fc_frame
*fp
;
1071 lockdep_assert_held(&rdata
->rp_mutex
);
1073 if (!fc_rport_compatible_roles(lport
, rdata
)) {
1074 FC_RPORT_DBG(rdata
, "PLOGI suppressed for incompatible role\n");
1075 fc_rport_state_enter(rdata
, RPORT_ST_PLOGI_WAIT
);
1079 FC_RPORT_DBG(rdata
, "Port entered PLOGI state from %s state\n",
1080 fc_rport_state(rdata
));
1082 fc_rport_state_enter(rdata
, RPORT_ST_PLOGI
);
1084 rdata
->maxframe_size
= FC_MIN_MAX_PAYLOAD
;
1085 fp
= fc_frame_alloc(lport
, sizeof(struct fc_els_flogi
));
1087 FC_RPORT_DBG(rdata
, "%s frame alloc failed\n", __func__
);
1088 fc_rport_error_retry(rdata
, -FC_EX_ALLOC_ERR
);
1091 rdata
->e_d_tov
= lport
->e_d_tov
;
1093 kref_get(&rdata
->kref
);
1094 if (!lport
->tt
.elsct_send(lport
, rdata
->ids
.port_id
, fp
, ELS_PLOGI
,
1095 fc_rport_plogi_resp
, rdata
,
1096 2 * lport
->r_a_tov
)) {
1097 fc_rport_error_retry(rdata
, -FC_EX_XMIT_ERR
);
1098 kref_put(&rdata
->kref
, fc_rport_destroy
);
1103 * fc_rport_prli_resp() - Process Login (PRLI) response handler
1104 * @sp: The sequence the PRLI response was on
1105 * @fp: The PRLI response frame
1106 * @rdata_arg: The remote port that sent the PRLI response
1108 * Locking Note: This function will be called without the rport lock
1109 * held, but it will lock, call an _enter_* function or fc_rport_error
1110 * and then unlock the rport.
1112 static void fc_rport_prli_resp(struct fc_seq
*sp
, struct fc_frame
*fp
,
1115 struct fc_rport_priv
*rdata
= rdata_arg
;
1117 struct fc_els_prli prli
;
1118 struct fc_els_spp spp
;
1120 struct fc_els_spp temp_spp
;
1121 struct fc_els_ls_rjt
*rjt
;
1122 struct fc4_prov
*prov
;
1123 u32 roles
= FC_RPORT_ROLE_UNKNOWN
;
1126 enum fc_els_spp_resp resp_code
;
1128 FC_RPORT_DBG(rdata
, "Received a PRLI %s\n", fc_els_resp_type(fp
));
1130 if (fp
== ERR_PTR(-FC_EX_CLOSED
))
1133 mutex_lock(&rdata
->rp_mutex
);
1135 if (rdata
->rp_state
!= RPORT_ST_PRLI
) {
1136 FC_RPORT_DBG(rdata
, "Received a PRLI response, but in state "
1137 "%s\n", fc_rport_state(rdata
));
1144 fc_rport_error_retry(rdata
, PTR_ERR(fp
));
1148 /* reinitialize remote port roles */
1149 rdata
->ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
1151 op
= fc_frame_payload_op(fp
);
1152 if (op
== ELS_LS_ACC
) {
1153 pp
= fc_frame_payload_get(fp
, sizeof(*pp
));
1155 fc_rport_error_retry(rdata
, -FC_EX_SEQ_ERR
);
1159 resp_code
= (pp
->spp
.spp_flags
& FC_SPP_RESP_MASK
);
1160 FC_RPORT_DBG(rdata
, "PRLI spp_flags = 0x%x spp_type 0x%x\n",
1161 pp
->spp
.spp_flags
, pp
->spp
.spp_type
);
1162 rdata
->spp_type
= pp
->spp
.spp_type
;
1163 if (resp_code
!= FC_SPP_RESP_ACK
) {
1164 if (resp_code
== FC_SPP_RESP_CONF
)
1165 fc_rport_error(rdata
, -FC_EX_SEQ_ERR
);
1167 fc_rport_error_retry(rdata
, -FC_EX_SEQ_ERR
);
1170 if (pp
->prli
.prli_spp_len
< sizeof(pp
->spp
)) {
1171 fc_rport_error_retry(rdata
, -FC_EX_SEQ_ERR
);
1175 fcp_parm
= ntohl(pp
->spp
.spp_params
);
1176 if (fcp_parm
& FCP_SPPF_RETRY
)
1177 rdata
->flags
|= FC_RP_FLAGS_RETRY
;
1178 if (fcp_parm
& FCP_SPPF_CONF_COMPL
)
1179 rdata
->flags
|= FC_RP_FLAGS_CONF_REQ
;
1182 * Call prli provider if we should act as a target
1184 prov
= fc_passive_prov
[rdata
->spp_type
];
1186 memset(&temp_spp
, 0, sizeof(temp_spp
));
1187 prov
->prli(rdata
, pp
->prli
.prli_spp_len
,
1188 &pp
->spp
, &temp_spp
);
1191 * Check if the image pair could be established
1193 if (rdata
->spp_type
!= FC_TYPE_FCP
||
1194 !(pp
->spp
.spp_flags
& FC_SPP_EST_IMG_PAIR
)) {
1196 * Nope; we can't use this port as a target.
1198 fcp_parm
&= ~FCP_SPPF_TARG_FCN
;
1200 rdata
->supported_classes
= FC_COS_CLASS3
;
1201 if (fcp_parm
& FCP_SPPF_INIT_FCN
)
1202 roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
1203 if (fcp_parm
& FCP_SPPF_TARG_FCN
)
1204 roles
|= FC_RPORT_ROLE_FCP_TARGET
;
1206 rdata
->ids
.roles
= roles
;
1207 fc_rport_enter_rtv(rdata
);
1210 rjt
= fc_frame_payload_get(fp
, sizeof(*rjt
));
1212 FC_RPORT_DBG(rdata
, "PRLI bad response\n");
1214 FC_RPORT_DBG(rdata
, "PRLI ELS rejected, reason %x expl %x\n",
1215 rjt
->er_reason
, rjt
->er_explan
);
1216 if (rjt
->er_reason
== ELS_RJT_UNAB
&&
1217 rjt
->er_explan
== ELS_EXPL_PLOGI_REQD
) {
1218 fc_rport_enter_plogi(rdata
);
1222 fc_rport_error_retry(rdata
, FC_EX_ELS_RJT
);
1228 mutex_unlock(&rdata
->rp_mutex
);
1230 kref_put(&rdata
->kref
, fc_rport_destroy
);
1234 * fc_rport_enter_prli() - Send Process Login (PRLI) request
1235 * @rdata: The remote port to send the PRLI request to
1237 * Reference counting: increments kref when sending ELS
1239 static void fc_rport_enter_prli(struct fc_rport_priv
*rdata
)
1241 struct fc_lport
*lport
= rdata
->local_port
;
1243 struct fc_els_prli prli
;
1244 struct fc_els_spp spp
;
1246 struct fc_frame
*fp
;
1247 struct fc4_prov
*prov
;
1249 lockdep_assert_held(&rdata
->rp_mutex
);
1252 * If the rport is one of the well known addresses
1253 * we skip PRLI and RTV and go straight to READY.
1255 if (rdata
->ids
.port_id
>= FC_FID_DOM_MGR
) {
1256 fc_rport_enter_ready(rdata
);
1261 * And if the local port does not support the initiator function
1262 * there's no need to send a PRLI, either.
1264 if (!(lport
->service_params
& FCP_SPPF_INIT_FCN
)) {
1265 fc_rport_enter_ready(rdata
);
1269 FC_RPORT_DBG(rdata
, "Port entered PRLI state from %s state\n",
1270 fc_rport_state(rdata
));
1272 fc_rport_state_enter(rdata
, RPORT_ST_PRLI
);
1274 fp
= fc_frame_alloc(lport
, sizeof(*pp
));
1276 fc_rport_error_retry(rdata
, -FC_EX_ALLOC_ERR
);
1280 fc_prli_fill(lport
, fp
);
1282 prov
= fc_passive_prov
[FC_TYPE_FCP
];
1284 pp
= fc_frame_payload_get(fp
, sizeof(*pp
));
1285 prov
->prli(rdata
, sizeof(pp
->spp
), NULL
, &pp
->spp
);
1288 fc_fill_fc_hdr(fp
, FC_RCTL_ELS_REQ
, rdata
->ids
.port_id
,
1289 fc_host_port_id(lport
->host
), FC_TYPE_ELS
,
1290 FC_FC_FIRST_SEQ
| FC_FC_END_SEQ
| FC_FC_SEQ_INIT
, 0);
1292 kref_get(&rdata
->kref
);
1293 if (!fc_exch_seq_send(lport
, fp
, fc_rport_prli_resp
,
1294 NULL
, rdata
, 2 * lport
->r_a_tov
)) {
1295 fc_rport_error_retry(rdata
, -FC_EX_XMIT_ERR
);
1296 kref_put(&rdata
->kref
, fc_rport_destroy
);
1301 * fc_rport_rtv_resp() - Handler for Request Timeout Value (RTV) responses
1302 * @sp: The sequence the RTV was on
1303 * @fp: The RTV response frame
1304 * @rdata_arg: The remote port that sent the RTV response
1306 * Many targets don't seem to support this.
1308 * Locking Note: This function will be called without the rport lock
1309 * held, but it will lock, call an _enter_* function or fc_rport_error
1310 * and then unlock the rport.
1312 static void fc_rport_rtv_resp(struct fc_seq
*sp
, struct fc_frame
*fp
,
1315 struct fc_rport_priv
*rdata
= rdata_arg
;
1318 FC_RPORT_DBG(rdata
, "Received a RTV %s\n", fc_els_resp_type(fp
));
1320 if (fp
== ERR_PTR(-FC_EX_CLOSED
))
1323 mutex_lock(&rdata
->rp_mutex
);
1325 if (rdata
->rp_state
!= RPORT_ST_RTV
) {
1326 FC_RPORT_DBG(rdata
, "Received a RTV response, but in state "
1327 "%s\n", fc_rport_state(rdata
));
1334 fc_rport_error(rdata
, PTR_ERR(fp
));
1338 op
= fc_frame_payload_op(fp
);
1339 if (op
== ELS_LS_ACC
) {
1340 struct fc_els_rtv_acc
*rtv
;
1344 rtv
= fc_frame_payload_get(fp
, sizeof(*rtv
));
1346 toq
= ntohl(rtv
->rtv_toq
);
1347 tov
= ntohl(rtv
->rtv_r_a_tov
);
1350 if (tov
> rdata
->r_a_tov
)
1351 rdata
->r_a_tov
= tov
;
1352 tov
= ntohl(rtv
->rtv_e_d_tov
);
1353 if (toq
& FC_ELS_RTV_EDRES
)
1357 if (tov
> rdata
->e_d_tov
)
1358 rdata
->e_d_tov
= tov
;
1362 fc_rport_enter_ready(rdata
);
1367 mutex_unlock(&rdata
->rp_mutex
);
1369 kref_put(&rdata
->kref
, fc_rport_destroy
);
1373 * fc_rport_enter_rtv() - Send Request Timeout Value (RTV) request
1374 * @rdata: The remote port to send the RTV request to
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 lockdep_assert_held(&rdata
->rp_mutex
);
1385 FC_RPORT_DBG(rdata
, "Port entered RTV state from %s state\n",
1386 fc_rport_state(rdata
));
1388 fc_rport_state_enter(rdata
, RPORT_ST_RTV
);
1390 fp
= fc_frame_alloc(lport
, sizeof(struct fc_els_rtv
));
1392 fc_rport_error_retry(rdata
, -FC_EX_ALLOC_ERR
);
1396 kref_get(&rdata
->kref
);
1397 if (!lport
->tt
.elsct_send(lport
, rdata
->ids
.port_id
, fp
, ELS_RTV
,
1398 fc_rport_rtv_resp
, rdata
,
1399 2 * lport
->r_a_tov
)) {
1400 fc_rport_error_retry(rdata
, -FC_EX_XMIT_ERR
);
1401 kref_put(&rdata
->kref
, fc_rport_destroy
);
1406 * fc_rport_recv_rtv_req() - Handler for Read Timeout Value (RTV) requests
1407 * @rdata: The remote port that sent the RTV request
1408 * @in_fp: The RTV request frame
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 lockdep_assert_held(&rdata
->rp_mutex
);
1419 lockdep_assert_held(&lport
->lp_mutex
);
1421 FC_RPORT_DBG(rdata
, "Received RTV request\n");
1423 fp
= fc_frame_alloc(lport
, sizeof(*rtv
));
1425 rjt_data
.reason
= ELS_RJT_UNAB
;
1426 rjt_data
.explan
= ELS_EXPL_INSUF_RES
;
1427 fc_seq_els_rsp_send(in_fp
, ELS_LS_RJT
, &rjt_data
);
1430 rtv
= fc_frame_payload_get(fp
, sizeof(*rtv
));
1431 rtv
->rtv_cmd
= ELS_LS_ACC
;
1432 rtv
->rtv_r_a_tov
= htonl(lport
->r_a_tov
);
1433 rtv
->rtv_e_d_tov
= htonl(lport
->e_d_tov
);
1435 fc_fill_reply_hdr(fp
, in_fp
, FC_RCTL_ELS_REP
, 0);
1436 lport
->tt
.frame_send(lport
, fp
);
1438 fc_frame_free(in_fp
);
1442 * fc_rport_logo_resp() - Handler for logout (LOGO) responses
1443 * @sp: The sequence the LOGO was on
1444 * @fp: The LOGO response frame
1445 * @lport_arg: The local port
1447 static void fc_rport_logo_resp(struct fc_seq
*sp
, struct fc_frame
*fp
,
1450 struct fc_rport_priv
*rdata
= rdata_arg
;
1451 struct fc_lport
*lport
= rdata
->local_port
;
1453 FC_RPORT_ID_DBG(lport
, fc_seq_exch(sp
)->did
,
1454 "Received a LOGO %s\n", fc_els_resp_type(fp
));
1457 kref_put(&rdata
->kref
, fc_rport_destroy
);
1461 * fc_rport_enter_logo() - Send a logout (LOGO) request
1462 * @rdata: The remote port to send the LOGO request to
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 lockdep_assert_held(&rdata
->rp_mutex
);
1473 FC_RPORT_DBG(rdata
, "Port sending LOGO from %s state\n",
1474 fc_rport_state(rdata
));
1476 fp
= fc_frame_alloc(lport
, sizeof(struct fc_els_logo
));
1479 kref_get(&rdata
->kref
);
1480 if (!lport
->tt
.elsct_send(lport
, rdata
->ids
.port_id
, fp
, ELS_LOGO
,
1481 fc_rport_logo_resp
, rdata
, 0))
1482 kref_put(&rdata
->kref
, fc_rport_destroy
);
1486 * fc_rport_els_adisc_resp() - Handler for Address Discovery (ADISC) responses
1487 * @sp: The sequence the ADISC response was on
1488 * @fp: The ADISC response frame
1489 * @rdata_arg: The remote port that sent the ADISC response
1491 * Locking Note: This function will be called without the rport lock
1492 * held, but it will lock, call an _enter_* function or fc_rport_error
1493 * and then unlock the rport.
1495 static void fc_rport_adisc_resp(struct fc_seq
*sp
, struct fc_frame
*fp
,
1498 struct fc_rport_priv
*rdata
= rdata_arg
;
1499 struct fc_els_adisc
*adisc
;
1502 FC_RPORT_DBG(rdata
, "Received a ADISC response\n");
1504 if (fp
== ERR_PTR(-FC_EX_CLOSED
))
1507 mutex_lock(&rdata
->rp_mutex
);
1509 if (rdata
->rp_state
!= RPORT_ST_ADISC
) {
1510 FC_RPORT_DBG(rdata
, "Received a ADISC resp but in state %s\n",
1511 fc_rport_state(rdata
));
1518 fc_rport_error(rdata
, PTR_ERR(fp
));
1523 * If address verification failed. Consider us logged out of the rport.
1524 * Since the rport is still in discovery, we want to be
1525 * logged in, so go to PLOGI state. Otherwise, go back to READY.
1527 op
= fc_frame_payload_op(fp
);
1528 adisc
= fc_frame_payload_get(fp
, sizeof(*adisc
));
1529 if (op
!= ELS_LS_ACC
|| !adisc
||
1530 ntoh24(adisc
->adisc_port_id
) != rdata
->ids
.port_id
||
1531 get_unaligned_be64(&adisc
->adisc_wwpn
) != rdata
->ids
.port_name
||
1532 get_unaligned_be64(&adisc
->adisc_wwnn
) != rdata
->ids
.node_name
) {
1533 FC_RPORT_DBG(rdata
, "ADISC error or mismatch\n");
1534 fc_rport_enter_flogi(rdata
);
1536 FC_RPORT_DBG(rdata
, "ADISC OK\n");
1537 fc_rport_enter_ready(rdata
);
1542 mutex_unlock(&rdata
->rp_mutex
);
1544 kref_put(&rdata
->kref
, fc_rport_destroy
);
1548 * fc_rport_enter_adisc() - Send Address Discover (ADISC) request
1549 * @rdata: The remote port to send the ADISC request to
1551 * Reference counting: increments kref when sending ELS
1553 static void fc_rport_enter_adisc(struct fc_rport_priv
*rdata
)
1555 struct fc_lport
*lport
= rdata
->local_port
;
1556 struct fc_frame
*fp
;
1558 lockdep_assert_held(&rdata
->rp_mutex
);
1560 FC_RPORT_DBG(rdata
, "sending ADISC from %s state\n",
1561 fc_rport_state(rdata
));
1563 fc_rport_state_enter(rdata
, RPORT_ST_ADISC
);
1565 fp
= fc_frame_alloc(lport
, sizeof(struct fc_els_adisc
));
1567 fc_rport_error_retry(rdata
, -FC_EX_ALLOC_ERR
);
1570 kref_get(&rdata
->kref
);
1571 if (!lport
->tt
.elsct_send(lport
, rdata
->ids
.port_id
, fp
, ELS_ADISC
,
1572 fc_rport_adisc_resp
, rdata
,
1573 2 * lport
->r_a_tov
)) {
1574 fc_rport_error_retry(rdata
, -FC_EX_XMIT_ERR
);
1575 kref_put(&rdata
->kref
, fc_rport_destroy
);
1580 * fc_rport_recv_adisc_req() - Handler for Address Discovery (ADISC) requests
1581 * @rdata: The remote port that sent the ADISC request
1582 * @in_fp: The ADISC request frame
1584 static void fc_rport_recv_adisc_req(struct fc_rport_priv
*rdata
,
1585 struct fc_frame
*in_fp
)
1587 struct fc_lport
*lport
= rdata
->local_port
;
1588 struct fc_frame
*fp
;
1589 struct fc_els_adisc
*adisc
;
1590 struct fc_seq_els_data rjt_data
;
1592 lockdep_assert_held(&rdata
->rp_mutex
);
1593 lockdep_assert_held(&lport
->lp_mutex
);
1595 FC_RPORT_DBG(rdata
, "Received ADISC request\n");
1597 adisc
= fc_frame_payload_get(in_fp
, sizeof(*adisc
));
1599 rjt_data
.reason
= ELS_RJT_PROT
;
1600 rjt_data
.explan
= ELS_EXPL_INV_LEN
;
1601 fc_seq_els_rsp_send(in_fp
, ELS_LS_RJT
, &rjt_data
);
1605 fp
= fc_frame_alloc(lport
, sizeof(*adisc
));
1608 fc_adisc_fill(lport
, fp
);
1609 adisc
= fc_frame_payload_get(fp
, sizeof(*adisc
));
1610 adisc
->adisc_cmd
= ELS_LS_ACC
;
1611 fc_fill_reply_hdr(fp
, in_fp
, FC_RCTL_ELS_REP
, 0);
1612 lport
->tt
.frame_send(lport
, fp
);
1614 fc_frame_free(in_fp
);
1618 * fc_rport_recv_rls_req() - Handle received Read Link Status request
1619 * @rdata: The remote port that sent the RLS request
1620 * @rx_fp: The PRLI request frame
1622 static void fc_rport_recv_rls_req(struct fc_rport_priv
*rdata
,
1623 struct fc_frame
*rx_fp
)
1626 struct fc_lport
*lport
= rdata
->local_port
;
1627 struct fc_frame
*fp
;
1628 struct fc_els_rls
*rls
;
1629 struct fc_els_rls_resp
*rsp
;
1630 struct fc_els_lesb
*lesb
;
1631 struct fc_seq_els_data rjt_data
;
1632 struct fc_host_statistics
*hst
;
1634 lockdep_assert_held(&rdata
->rp_mutex
);
1636 FC_RPORT_DBG(rdata
, "Received RLS request while in state %s\n",
1637 fc_rport_state(rdata
));
1639 rls
= fc_frame_payload_get(rx_fp
, sizeof(*rls
));
1641 rjt_data
.reason
= ELS_RJT_PROT
;
1642 rjt_data
.explan
= ELS_EXPL_INV_LEN
;
1646 fp
= fc_frame_alloc(lport
, sizeof(*rsp
));
1648 rjt_data
.reason
= ELS_RJT_UNAB
;
1649 rjt_data
.explan
= ELS_EXPL_INSUF_RES
;
1653 rsp
= fc_frame_payload_get(fp
, sizeof(*rsp
));
1654 memset(rsp
, 0, sizeof(*rsp
));
1655 rsp
->rls_cmd
= ELS_LS_ACC
;
1656 lesb
= &rsp
->rls_lesb
;
1657 if (lport
->tt
.get_lesb
) {
1658 /* get LESB from LLD if it supports it */
1659 lport
->tt
.get_lesb(lport
, lesb
);
1661 fc_get_host_stats(lport
->host
);
1662 hst
= &lport
->host_stats
;
1663 lesb
->lesb_link_fail
= htonl(hst
->link_failure_count
);
1664 lesb
->lesb_sync_loss
= htonl(hst
->loss_of_sync_count
);
1665 lesb
->lesb_sig_loss
= htonl(hst
->loss_of_signal_count
);
1666 lesb
->lesb_prim_err
= htonl(hst
->prim_seq_protocol_err_count
);
1667 lesb
->lesb_inv_word
= htonl(hst
->invalid_tx_word_count
);
1668 lesb
->lesb_inv_crc
= htonl(hst
->invalid_crc_count
);
1671 fc_fill_reply_hdr(fp
, rx_fp
, FC_RCTL_ELS_REP
, 0);
1672 lport
->tt
.frame_send(lport
, fp
);
1676 fc_seq_els_rsp_send(rx_fp
, ELS_LS_RJT
, &rjt_data
);
1678 fc_frame_free(rx_fp
);
1682 * fc_rport_recv_els_req() - Handler for validated ELS requests
1683 * @lport: The local port that received the ELS request
1684 * @fp: The ELS request frame
1686 * Handle incoming ELS requests that require port login.
1687 * The ELS opcode has already been validated by the caller.
1689 * Reference counting: does not modify kref
1691 static void fc_rport_recv_els_req(struct fc_lport
*lport
, struct fc_frame
*fp
)
1693 struct fc_rport_priv
*rdata
;
1694 struct fc_seq_els_data els_data
;
1696 lockdep_assert_held(&lport
->lp_mutex
);
1698 rdata
= fc_rport_lookup(lport
, fc_frame_sid(fp
));
1700 FC_RPORT_ID_DBG(lport
, fc_frame_sid(fp
),
1701 "Received ELS 0x%02x from non-logged-in port\n",
1702 fc_frame_payload_op(fp
));
1706 mutex_lock(&rdata
->rp_mutex
);
1708 switch (rdata
->rp_state
) {
1711 case RPORT_ST_READY
:
1712 case RPORT_ST_ADISC
:
1714 case RPORT_ST_PLOGI
:
1715 if (fc_frame_payload_op(fp
) == ELS_PRLI
) {
1716 FC_RPORT_DBG(rdata
, "Reject ELS PRLI "
1717 "while in state %s\n",
1718 fc_rport_state(rdata
));
1719 mutex_unlock(&rdata
->rp_mutex
);
1720 kref_put(&rdata
->kref
, fc_rport_destroy
);
1726 "Reject ELS 0x%02x while in state %s\n",
1727 fc_frame_payload_op(fp
), fc_rport_state(rdata
));
1728 mutex_unlock(&rdata
->rp_mutex
);
1729 kref_put(&rdata
->kref
, fc_rport_destroy
);
1733 switch (fc_frame_payload_op(fp
)) {
1735 fc_rport_recv_prli_req(rdata
, fp
);
1738 fc_rport_recv_prlo_req(rdata
, fp
);
1741 fc_rport_recv_adisc_req(rdata
, fp
);
1744 fc_seq_els_rsp_send(fp
, ELS_RRQ
, NULL
);
1748 fc_seq_els_rsp_send(fp
, ELS_REC
, NULL
);
1752 fc_rport_recv_rls_req(rdata
, fp
);
1755 fc_rport_recv_rtv_req(rdata
, fp
);
1758 fc_frame_free(fp
); /* can't happen */
1762 mutex_unlock(&rdata
->rp_mutex
);
1763 kref_put(&rdata
->kref
, fc_rport_destroy
);
1767 els_data
.reason
= ELS_RJT_UNAB
;
1768 els_data
.explan
= ELS_EXPL_PLOGI_REQD
;
1769 fc_seq_els_rsp_send(fp
, ELS_LS_RJT
, &els_data
);
1774 els_data
.reason
= ELS_RJT_BUSY
;
1775 els_data
.explan
= ELS_EXPL_NONE
;
1776 fc_seq_els_rsp_send(fp
, ELS_LS_RJT
, &els_data
);
1782 * fc_rport_recv_req() - Handler for requests
1783 * @lport: The local port that received the request
1784 * @fp: The request frame
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
;
1792 lockdep_assert_held(&lport
->lp_mutex
);
1795 * Handle FLOGI, PLOGI and LOGO requests separately, since they
1796 * don't require prior login.
1797 * Check for unsupported opcodes first and reject them.
1798 * For some ops, it would be incorrect to reject with "PLOGI required".
1800 switch (fc_frame_payload_op(fp
)) {
1802 fc_rport_recv_flogi_req(lport
, fp
);
1805 fc_rport_recv_plogi_req(lport
, fp
);
1808 fc_rport_recv_logo_req(lport
, fp
);
1817 fc_rport_recv_els_req(lport
, fp
);
1820 els_data
.reason
= ELS_RJT_UNSUP
;
1821 els_data
.explan
= ELS_EXPL_NONE
;
1822 fc_seq_els_rsp_send(fp
, ELS_LS_RJT
, &els_data
);
1827 EXPORT_SYMBOL(fc_rport_recv_req
);
1830 * fc_rport_recv_plogi_req() - Handler for Port Login (PLOGI) requests
1831 * @lport: The local port that received the PLOGI request
1832 * @rx_fp: The PLOGI request frame
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 lockdep_assert_held(&lport
->lp_mutex
);
1848 sid
= fc_frame_sid(fp
);
1850 FC_RPORT_ID_DBG(lport
, sid
, "Received PLOGI request\n");
1852 pl
= fc_frame_payload_get(fp
, sizeof(*pl
));
1854 FC_RPORT_ID_DBG(lport
, sid
, "Received PLOGI too short\n");
1855 rjt_data
.reason
= ELS_RJT_PROT
;
1856 rjt_data
.explan
= ELS_EXPL_INV_LEN
;
1860 disc
= &lport
->disc
;
1861 mutex_lock(&disc
->disc_mutex
);
1862 rdata
= fc_rport_create(lport
, sid
);
1864 mutex_unlock(&disc
->disc_mutex
);
1865 rjt_data
.reason
= ELS_RJT_UNAB
;
1866 rjt_data
.explan
= ELS_EXPL_INSUF_RES
;
1870 mutex_lock(&rdata
->rp_mutex
);
1871 mutex_unlock(&disc
->disc_mutex
);
1873 rdata
->ids
.port_name
= get_unaligned_be64(&pl
->fl_wwpn
);
1874 rdata
->ids
.node_name
= get_unaligned_be64(&pl
->fl_wwnn
);
1877 * If the rport was just created, possibly due to the incoming PLOGI,
1878 * set the state appropriately and accept the PLOGI.
1880 * If we had also sent a PLOGI, and if the received PLOGI is from a
1881 * higher WWPN, we accept it, otherwise an LS_RJT is sent with reason
1882 * "command already in progress".
1884 * XXX TBD: If the session was ready before, the PLOGI should result in
1885 * all outstanding exchanges being reset.
1887 switch (rdata
->rp_state
) {
1889 FC_RPORT_DBG(rdata
, "Received PLOGI in INIT state\n");
1891 case RPORT_ST_PLOGI_WAIT
:
1892 FC_RPORT_DBG(rdata
, "Received PLOGI in PLOGI_WAIT state\n");
1894 case RPORT_ST_PLOGI
:
1895 FC_RPORT_DBG(rdata
, "Received PLOGI in PLOGI state\n");
1896 if (rdata
->ids
.port_name
< lport
->wwpn
) {
1897 mutex_unlock(&rdata
->rp_mutex
);
1898 rjt_data
.reason
= ELS_RJT_INPROG
;
1899 rjt_data
.explan
= ELS_EXPL_NONE
;
1905 case RPORT_ST_READY
:
1906 case RPORT_ST_ADISC
:
1907 FC_RPORT_DBG(rdata
, "Received PLOGI in logged-in state %d "
1908 "- ignored for now\n", rdata
->rp_state
);
1909 /* XXX TBD - should reset */
1911 case RPORT_ST_FLOGI
:
1912 case RPORT_ST_DELETE
:
1913 FC_RPORT_DBG(rdata
, "Received PLOGI in state %s - send busy\n",
1914 fc_rport_state(rdata
));
1915 mutex_unlock(&rdata
->rp_mutex
);
1916 rjt_data
.reason
= ELS_RJT_BUSY
;
1917 rjt_data
.explan
= ELS_EXPL_NONE
;
1920 if (!fc_rport_compatible_roles(lport
, rdata
)) {
1921 FC_RPORT_DBG(rdata
, "Received PLOGI for incompatible role\n");
1922 mutex_unlock(&rdata
->rp_mutex
);
1923 rjt_data
.reason
= ELS_RJT_LOGIC
;
1924 rjt_data
.explan
= ELS_EXPL_NONE
;
1929 * Get session payload size from incoming PLOGI.
1931 rdata
->maxframe_size
= fc_plogi_get_maxframe(pl
, lport
->mfs
);
1934 * Send LS_ACC. If this fails, the originator should retry.
1936 fp
= fc_frame_alloc(lport
, sizeof(*pl
));
1940 fc_plogi_fill(lport
, fp
, ELS_LS_ACC
);
1941 fc_fill_reply_hdr(fp
, rx_fp
, FC_RCTL_ELS_REP
, 0);
1942 lport
->tt
.frame_send(lport
, fp
);
1943 fc_rport_enter_prli(rdata
);
1945 mutex_unlock(&rdata
->rp_mutex
);
1946 fc_frame_free(rx_fp
);
1950 fc_seq_els_rsp_send(fp
, ELS_LS_RJT
, &rjt_data
);
1955 * fc_rport_recv_prli_req() - Handler for process login (PRLI) requests
1956 * @rdata: The remote port that sent the PRLI request
1957 * @rx_fp: The PRLI request frame
1959 static void fc_rport_recv_prli_req(struct fc_rport_priv
*rdata
,
1960 struct fc_frame
*rx_fp
)
1962 struct fc_lport
*lport
= rdata
->local_port
;
1963 struct fc_frame
*fp
;
1965 struct fc_els_prli prli
;
1966 struct fc_els_spp spp
;
1968 struct fc_els_spp
*rspp
; /* request service param page */
1969 struct fc_els_spp
*spp
; /* response spp */
1972 enum fc_els_spp_resp resp
;
1973 struct fc_seq_els_data rjt_data
;
1974 struct fc4_prov
*prov
;
1976 lockdep_assert_held(&rdata
->rp_mutex
);
1978 FC_RPORT_DBG(rdata
, "Received PRLI request while in state %s\n",
1979 fc_rport_state(rdata
));
1981 len
= fr_len(rx_fp
) - sizeof(struct fc_frame_header
);
1982 pp
= fc_frame_payload_get(rx_fp
, sizeof(*pp
));
1985 plen
= ntohs(pp
->prli
.prli_len
);
1986 if ((plen
% 4) != 0 || plen
> len
|| plen
< 16)
1990 plen
= pp
->prli
.prli_spp_len
;
1991 if ((plen
% 4) != 0 || plen
< sizeof(*spp
) ||
1992 plen
> len
|| len
< sizeof(*pp
) || plen
< 12)
1996 fp
= fc_frame_alloc(lport
, len
);
1998 rjt_data
.reason
= ELS_RJT_UNAB
;
1999 rjt_data
.explan
= ELS_EXPL_INSUF_RES
;
2002 pp
= fc_frame_payload_get(fp
, len
);
2005 pp
->prli
.prli_cmd
= ELS_LS_ACC
;
2006 pp
->prli
.prli_spp_len
= plen
;
2007 pp
->prli
.prli_len
= htons(len
);
2008 len
-= sizeof(struct fc_els_prli
);
2011 * Go through all the service parameter pages and build
2012 * response. If plen indicates longer SPP than standard,
2013 * use that. The entire response has been pre-cleared above.
2016 mutex_lock(&fc_prov_mutex
);
2017 while (len
>= plen
) {
2018 rdata
->spp_type
= rspp
->spp_type
;
2019 spp
->spp_type
= rspp
->spp_type
;
2020 spp
->spp_type_ext
= rspp
->spp_type_ext
;
2023 if (rspp
->spp_type
< FC_FC4_PROV_SIZE
) {
2024 enum fc_els_spp_resp active
= 0, passive
= 0;
2026 prov
= fc_active_prov
[rspp
->spp_type
];
2028 active
= prov
->prli(rdata
, plen
, rspp
, spp
);
2029 prov
= fc_passive_prov
[rspp
->spp_type
];
2031 passive
= prov
->prli(rdata
, plen
, rspp
, spp
);
2032 if (!active
|| passive
== FC_SPP_RESP_ACK
)
2036 FC_RPORT_DBG(rdata
, "PRLI rspp type %x "
2037 "active %x passive %x\n",
2038 rspp
->spp_type
, active
, passive
);
2041 if (spp
->spp_flags
& FC_SPP_EST_IMG_PAIR
)
2042 resp
|= FC_SPP_RESP_CONF
;
2044 resp
|= FC_SPP_RESP_INVL
;
2046 spp
->spp_flags
|= resp
;
2048 rspp
= (struct fc_els_spp
*)((char *)rspp
+ plen
);
2049 spp
= (struct fc_els_spp
*)((char *)spp
+ plen
);
2051 mutex_unlock(&fc_prov_mutex
);
2054 * Send LS_ACC. If this fails, the originator should retry.
2056 fc_fill_reply_hdr(fp
, rx_fp
, FC_RCTL_ELS_REP
, 0);
2057 lport
->tt
.frame_send(lport
, fp
);
2062 rjt_data
.reason
= ELS_RJT_PROT
;
2063 rjt_data
.explan
= ELS_EXPL_INV_LEN
;
2065 fc_seq_els_rsp_send(rx_fp
, ELS_LS_RJT
, &rjt_data
);
2067 fc_frame_free(rx_fp
);
2071 * fc_rport_recv_prlo_req() - Handler for process logout (PRLO) requests
2072 * @rdata: The remote port that sent the PRLO request
2073 * @rx_fp: The PRLO request frame
2075 static void fc_rport_recv_prlo_req(struct fc_rport_priv
*rdata
,
2076 struct fc_frame
*rx_fp
)
2078 struct fc_lport
*lport
= rdata
->local_port
;
2079 struct fc_frame
*fp
;
2081 struct fc_els_prlo prlo
;
2082 struct fc_els_spp spp
;
2084 struct fc_els_spp
*rspp
; /* request service param page */
2085 struct fc_els_spp
*spp
; /* response spp */
2088 struct fc_seq_els_data rjt_data
;
2090 lockdep_assert_held(&rdata
->rp_mutex
);
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 * Reference counting: drops kref on return
2147 static void fc_rport_recv_logo_req(struct fc_lport
*lport
, struct fc_frame
*fp
)
2149 struct fc_rport_priv
*rdata
;
2152 lockdep_assert_held(&lport
->lp_mutex
);
2154 fc_seq_els_rsp_send(fp
, ELS_LS_ACC
, NULL
);
2156 sid
= fc_frame_sid(fp
);
2158 rdata
= fc_rport_lookup(lport
, sid
);
2160 mutex_lock(&rdata
->rp_mutex
);
2161 FC_RPORT_DBG(rdata
, "Received LOGO request while in state %s\n",
2162 fc_rport_state(rdata
));
2164 fc_rport_enter_delete(rdata
, RPORT_EV_STOP
);
2165 mutex_unlock(&rdata
->rp_mutex
);
2166 kref_put(&rdata
->kref
, fc_rport_destroy
);
2168 FC_RPORT_ID_DBG(lport
, sid
,
2169 "Received LOGO from non-logged-in port\n");
2174 * fc_rport_flush_queue() - Flush the rport_event_queue
2176 void fc_rport_flush_queue(void)
2178 flush_workqueue(rport_event_queue
);
2180 EXPORT_SYMBOL(fc_rport_flush_queue
);
2183 * fc_rport_fcp_prli() - Handle incoming PRLI for the FCP initiator.
2184 * @rdata: remote port private
2185 * @spp_len: service parameter page length
2186 * @rspp: received service parameter page
2187 * @spp: response service parameter page
2189 * Returns the value for the response code to be placed in spp_flags;
2190 * Returns 0 if not an initiator.
2192 static int fc_rport_fcp_prli(struct fc_rport_priv
*rdata
, u32 spp_len
,
2193 const struct fc_els_spp
*rspp
,
2194 struct fc_els_spp
*spp
)
2196 struct fc_lport
*lport
= rdata
->local_port
;
2199 fcp_parm
= ntohl(rspp
->spp_params
);
2200 rdata
->ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2201 if (fcp_parm
& FCP_SPPF_INIT_FCN
)
2202 rdata
->ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
2203 if (fcp_parm
& FCP_SPPF_TARG_FCN
)
2204 rdata
->ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
2205 if (fcp_parm
& FCP_SPPF_RETRY
)
2206 rdata
->flags
|= FC_RP_FLAGS_RETRY
;
2207 rdata
->supported_classes
= FC_COS_CLASS3
;
2209 if (!(lport
->service_params
& FCP_SPPF_INIT_FCN
))
2212 spp
->spp_flags
|= rspp
->spp_flags
& FC_SPP_EST_IMG_PAIR
;
2215 * OR in our service parameters with other providers (target), if any.
2217 fcp_parm
= ntohl(spp
->spp_params
);
2218 spp
->spp_params
= htonl(fcp_parm
| lport
->service_params
);
2219 return FC_SPP_RESP_ACK
;
2223 * FC-4 provider ops for FCP initiator.
2225 struct fc4_prov fc_rport_fcp_init
= {
2226 .prli
= fc_rport_fcp_prli
,
2230 * fc_rport_t0_prli() - Handle incoming PRLI parameters for type 0
2231 * @rdata: remote port private
2232 * @spp_len: service parameter page length
2233 * @rspp: received service parameter page
2234 * @spp: response service parameter page
2236 static int fc_rport_t0_prli(struct fc_rport_priv
*rdata
, u32 spp_len
,
2237 const struct fc_els_spp
*rspp
,
2238 struct fc_els_spp
*spp
)
2240 if (rspp
->spp_flags
& FC_SPP_EST_IMG_PAIR
)
2241 return FC_SPP_RESP_INVL
;
2242 return FC_SPP_RESP_ACK
;
2246 * FC-4 provider ops for type 0 service parameters.
2248 * This handles the special case of type 0 which is always successful
2249 * but doesn't do anything otherwise.
2251 struct fc4_prov fc_rport_t0_prov
= {
2252 .prli
= fc_rport_t0_prli
,
2256 * fc_setup_rport() - Initialize the rport_event_queue
2258 int fc_setup_rport(void)
2260 rport_event_queue
= create_singlethread_workqueue("fc_rport_eq");
2261 if (!rport_event_queue
)
2267 * fc_destroy_rport() - Destroy the rport_event_queue
2269 void fc_destroy_rport(void)
2271 destroy_workqueue(rport_event_queue
);
2275 * fc_rport_terminate_io() - Stop all outstanding I/O on a remote port
2276 * @rport: The remote port whose I/O should be terminated
2278 void fc_rport_terminate_io(struct fc_rport
*rport
)
2280 struct fc_rport_libfc_priv
*rpriv
= rport
->dd_data
;
2281 struct fc_lport
*lport
= rpriv
->local_port
;
2283 lport
->tt
.exch_mgr_reset(lport
, 0, rport
->port_id
);
2284 lport
->tt
.exch_mgr_reset(lport
, rport
->port_id
, 0);
2286 EXPORT_SYMBOL(fc_rport_terminate_io
);