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 <linux/unaligned.h>
60 #include <scsi/libfc.h>
62 #include "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 * @port_id: 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
);
137 kref_put(&rdata
->kref
, fc_rport_destroy
);
141 if (lport
->rport_priv_size
> 0)
142 rport_priv_size
= lport
->rport_priv_size
;
143 rdata
= kzalloc(rport_priv_size
, GFP_KERNEL
);
147 rdata
->ids
.node_name
= -1;
148 rdata
->ids
.port_name
= -1;
149 rdata
->ids
.port_id
= port_id
;
150 rdata
->ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
152 kref_init(&rdata
->kref
);
153 mutex_init(&rdata
->rp_mutex
);
154 rdata
->local_port
= lport
;
155 rdata
->rp_state
= RPORT_ST_INIT
;
156 rdata
->event
= RPORT_EV_NONE
;
157 rdata
->flags
= FC_RP_FLAGS_REC_SUPPORTED
;
158 rdata
->e_d_tov
= lport
->e_d_tov
;
159 rdata
->r_a_tov
= lport
->r_a_tov
;
160 rdata
->maxframe_size
= FC_MIN_MAX_PAYLOAD
;
161 INIT_DELAYED_WORK(&rdata
->retry_work
, fc_rport_timeout
);
162 INIT_WORK(&rdata
->event_work
, fc_rport_work
);
163 if (port_id
!= FC_FID_DIR_SERV
) {
164 rdata
->lld_event_callback
= lport
->tt
.rport_event_callback
;
165 list_add_rcu(&rdata
->peers
, &lport
->disc
.rports
);
169 EXPORT_SYMBOL(fc_rport_create
);
172 * fc_rport_destroy() - Free a remote port after last reference is released
173 * @kref: The remote port's kref
175 void fc_rport_destroy(struct kref
*kref
)
177 struct fc_rport_priv
*rdata
;
179 rdata
= container_of(kref
, struct fc_rport_priv
, kref
);
180 kfree_rcu(rdata
, rcu
);
182 EXPORT_SYMBOL(fc_rport_destroy
);
185 * fc_rport_state() - Return a string identifying the remote port's state
186 * @rdata: The remote port
188 static const char *fc_rport_state(struct fc_rport_priv
*rdata
)
192 cp
= fc_rport_state_names
[rdata
->rp_state
];
199 * fc_set_rport_loss_tmo() - Set the remote port loss timeout
200 * @rport: The remote port that gets a new timeout value
201 * @timeout: The new timeout value (in seconds)
203 void fc_set_rport_loss_tmo(struct fc_rport
*rport
, u32 timeout
)
206 rport
->dev_loss_tmo
= timeout
;
208 rport
->dev_loss_tmo
= 1;
210 EXPORT_SYMBOL(fc_set_rport_loss_tmo
);
213 * fc_plogi_get_maxframe() - Get the maximum payload from the common service
214 * parameters in a FLOGI frame
215 * @flp: The FLOGI or PLOGI payload
216 * @maxval: The maximum frame size upper limit; this may be less than what
217 * is in the service parameters
219 static unsigned int fc_plogi_get_maxframe(struct fc_els_flogi
*flp
,
225 * Get max payload from the common service parameters and the
226 * class 3 receive data field size.
228 mfs
= ntohs(flp
->fl_csp
.sp_bb_data
) & FC_SP_BB_DATA_MASK
;
229 if (mfs
>= FC_SP_MIN_MAX_PAYLOAD
&& mfs
< maxval
)
231 mfs
= ntohs(flp
->fl_cssp
[3 - 1].cp_rdfs
);
232 if (mfs
>= FC_SP_MIN_MAX_PAYLOAD
&& mfs
< maxval
)
238 * fc_rport_state_enter() - Change the state of a remote port
239 * @rdata: The remote port whose state should change
240 * @new: The new state
242 static void fc_rport_state_enter(struct fc_rport_priv
*rdata
,
243 enum fc_rport_state
new)
245 lockdep_assert_held(&rdata
->rp_mutex
);
247 if (rdata
->rp_state
!= new)
249 rdata
->rp_state
= new;
253 * fc_rport_work() - Handler for remote port events in the rport_event_queue
254 * @work: Handle to the remote port being dequeued
256 * Reference counting: drops kref on return
258 static void fc_rport_work(struct work_struct
*work
)
261 struct fc_rport_priv
*rdata
=
262 container_of(work
, struct fc_rport_priv
, event_work
);
263 struct fc_rport_libfc_priv
*rpriv
;
264 enum fc_rport_event event
;
265 struct fc_lport
*lport
= rdata
->local_port
;
266 struct fc_rport_operations
*rport_ops
;
267 struct fc_rport_identifiers ids
;
268 struct fc_rport
*rport
;
269 struct fc4_prov
*prov
;
272 mutex_lock(&rdata
->rp_mutex
);
273 event
= rdata
->event
;
274 rport_ops
= rdata
->ops
;
275 rport
= rdata
->rport
;
277 FC_RPORT_DBG(rdata
, "work event %u\n", event
);
282 rdata
->event
= RPORT_EV_NONE
;
283 rdata
->major_retries
= 0;
284 kref_get(&rdata
->kref
);
285 mutex_unlock(&rdata
->rp_mutex
);
288 FC_RPORT_DBG(rdata
, "No rport!\n");
289 rport
= fc_remote_port_add(lport
->host
, 0, &ids
);
292 FC_RPORT_DBG(rdata
, "Failed to add the rport\n");
293 fc_rport_logoff(rdata
);
294 kref_put(&rdata
->kref
, fc_rport_destroy
);
297 mutex_lock(&rdata
->rp_mutex
);
299 FC_RPORT_DBG(rdata
, "rport already allocated\n");
300 rdata
->rport
= rport
;
301 rport
->maxframe_size
= rdata
->maxframe_size
;
302 rport
->supported_classes
= rdata
->supported_classes
;
304 rpriv
= rport
->dd_data
;
305 rpriv
->local_port
= lport
;
306 rpriv
->rp_state
= rdata
->rp_state
;
307 rpriv
->flags
= rdata
->flags
;
308 rpriv
->e_d_tov
= rdata
->e_d_tov
;
309 rpriv
->r_a_tov
= rdata
->r_a_tov
;
310 mutex_unlock(&rdata
->rp_mutex
);
312 if (rport_ops
&& rport_ops
->event_callback
) {
313 FC_RPORT_DBG(rdata
, "callback ev %d\n", event
);
314 rport_ops
->event_callback(lport
, rdata
, event
);
316 if (rdata
->lld_event_callback
) {
317 FC_RPORT_DBG(rdata
, "lld callback ev %d\n", event
);
318 rdata
->lld_event_callback(lport
, rdata
, event
);
320 kref_put(&rdata
->kref
, fc_rport_destroy
);
323 case RPORT_EV_FAILED
:
326 if (rdata
->prli_count
) {
327 mutex_lock(&fc_prov_mutex
);
328 for (type
= 1; type
< FC_FC4_PROV_SIZE
; type
++) {
329 prov
= fc_passive_prov
[type
];
330 if (prov
&& prov
->prlo
)
333 mutex_unlock(&fc_prov_mutex
);
335 port_id
= rdata
->ids
.port_id
;
336 mutex_unlock(&rdata
->rp_mutex
);
338 if (rport_ops
&& rport_ops
->event_callback
) {
339 FC_RPORT_DBG(rdata
, "callback ev %d\n", event
);
340 rport_ops
->event_callback(lport
, rdata
, event
);
342 if (rdata
->lld_event_callback
) {
343 FC_RPORT_DBG(rdata
, "lld callback ev %d\n", event
);
344 rdata
->lld_event_callback(lport
, rdata
, event
);
346 if (cancel_delayed_work_sync(&rdata
->retry_work
))
347 kref_put(&rdata
->kref
, fc_rport_destroy
);
350 * Reset any outstanding exchanges before freeing rport.
352 lport
->tt
.exch_mgr_reset(lport
, 0, port_id
);
353 lport
->tt
.exch_mgr_reset(lport
, port_id
, 0);
356 rpriv
= rport
->dd_data
;
357 rpriv
->rp_state
= RPORT_ST_DELETE
;
358 mutex_lock(&rdata
->rp_mutex
);
360 mutex_unlock(&rdata
->rp_mutex
);
361 fc_remote_port_delete(rport
);
364 mutex_lock(&rdata
->rp_mutex
);
365 if (rdata
->rp_state
== RPORT_ST_DELETE
) {
366 if (port_id
== FC_FID_DIR_SERV
) {
367 rdata
->event
= RPORT_EV_NONE
;
368 mutex_unlock(&rdata
->rp_mutex
);
369 kref_put(&rdata
->kref
, fc_rport_destroy
);
370 } else if ((rdata
->flags
& FC_RP_STARTED
) &&
371 rdata
->major_retries
<
372 lport
->max_rport_retry_count
) {
373 rdata
->major_retries
++;
374 rdata
->event
= RPORT_EV_NONE
;
375 FC_RPORT_DBG(rdata
, "work restart\n");
376 fc_rport_enter_flogi(rdata
);
377 mutex_unlock(&rdata
->rp_mutex
);
379 mutex_unlock(&rdata
->rp_mutex
);
380 FC_RPORT_DBG(rdata
, "work delete\n");
381 mutex_lock(&lport
->disc
.disc_mutex
);
382 list_del_rcu(&rdata
->peers
);
383 mutex_unlock(&lport
->disc
.disc_mutex
);
384 kref_put(&rdata
->kref
, fc_rport_destroy
);
388 * Re-open for events. Reissue READY event if ready.
390 rdata
->event
= RPORT_EV_NONE
;
391 if (rdata
->rp_state
== RPORT_ST_READY
) {
392 FC_RPORT_DBG(rdata
, "work reopen\n");
393 fc_rport_enter_ready(rdata
);
395 mutex_unlock(&rdata
->rp_mutex
);
400 mutex_unlock(&rdata
->rp_mutex
);
403 kref_put(&rdata
->kref
, fc_rport_destroy
);
407 * fc_rport_login() - Start the remote port login state machine
408 * @rdata: The remote port to be logged in to
410 * Initiates the RP state machine. It is called from the LP module.
411 * This function will issue the following commands to the N_Port
412 * identified by the FC ID provided.
418 * Locking Note: Called without the rport lock held. This
419 * function will hold the rport lock, call an _enter_*
420 * function and then unlock the rport.
422 * This indicates the intent to be logged into the remote port.
423 * If it appears we are already logged in, ADISC is used to verify
426 int fc_rport_login(struct fc_rport_priv
*rdata
)
428 mutex_lock(&rdata
->rp_mutex
);
430 if (rdata
->flags
& FC_RP_STARTED
) {
431 FC_RPORT_DBG(rdata
, "port already started\n");
432 mutex_unlock(&rdata
->rp_mutex
);
436 rdata
->flags
|= FC_RP_STARTED
;
437 switch (rdata
->rp_state
) {
439 FC_RPORT_DBG(rdata
, "ADISC port\n");
440 fc_rport_enter_adisc(rdata
);
442 case RPORT_ST_DELETE
:
443 FC_RPORT_DBG(rdata
, "Restart deleted port\n");
446 FC_RPORT_DBG(rdata
, "Login to port\n");
447 fc_rport_enter_flogi(rdata
);
450 FC_RPORT_DBG(rdata
, "Login in progress, state %s\n",
451 fc_rport_state(rdata
));
454 mutex_unlock(&rdata
->rp_mutex
);
458 EXPORT_SYMBOL(fc_rport_login
);
461 * fc_rport_enter_delete() - Schedule a remote port to be deleted
462 * @rdata: The remote port to be deleted
463 * @event: The event to report as the reason for deletion
465 * Allow state change into DELETE only once.
467 * Call queue_work only if there's no event already pending.
468 * Set the new event so that the old pending event will not occur.
469 * Since we have the mutex, even if fc_rport_work() is already started,
470 * it'll see the new event.
472 * Reference counting: does not modify kref
474 static void fc_rport_enter_delete(struct fc_rport_priv
*rdata
,
475 enum fc_rport_event event
)
477 lockdep_assert_held(&rdata
->rp_mutex
);
479 if (rdata
->rp_state
== RPORT_ST_DELETE
)
482 FC_RPORT_DBG(rdata
, "Delete port\n");
484 fc_rport_state_enter(rdata
, RPORT_ST_DELETE
);
486 if (rdata
->event
== RPORT_EV_NONE
) {
487 kref_get(&rdata
->kref
);
488 if (!queue_work(rport_event_queue
, &rdata
->event_work
))
489 kref_put(&rdata
->kref
, fc_rport_destroy
);
492 rdata
->event
= event
;
496 * fc_rport_logoff() - Logoff and remove a remote port
497 * @rdata: The remote port to be logged off of
499 * Locking Note: Called without the rport lock held. This
500 * function will hold the rport lock, call an _enter_*
501 * function and then unlock the rport.
503 int fc_rport_logoff(struct fc_rport_priv
*rdata
)
505 struct fc_lport
*lport
= rdata
->local_port
;
506 u32 port_id
= rdata
->ids
.port_id
;
508 mutex_lock(&rdata
->rp_mutex
);
510 FC_RPORT_DBG(rdata
, "Remove port\n");
512 rdata
->flags
&= ~FC_RP_STARTED
;
513 if (rdata
->rp_state
== RPORT_ST_DELETE
) {
514 FC_RPORT_DBG(rdata
, "Port in Delete state, not removing\n");
519 * To explicitly Logout, the initiating Nx_Port shall terminate
520 * other open Sequences that it initiated with the destination
521 * Nx_Port prior to performing Logout.
523 lport
->tt
.exch_mgr_reset(lport
, 0, port_id
);
524 lport
->tt
.exch_mgr_reset(lport
, port_id
, 0);
526 fc_rport_enter_logo(rdata
);
529 * Change the state to Delete so that we discard
532 fc_rport_enter_delete(rdata
, RPORT_EV_STOP
);
534 mutex_unlock(&rdata
->rp_mutex
);
537 EXPORT_SYMBOL(fc_rport_logoff
);
540 * fc_rport_enter_ready() - Transition to the RPORT_ST_READY state
541 * @rdata: The remote port that is ready
543 * Reference counting: schedules workqueue, does not modify kref
545 static void fc_rport_enter_ready(struct fc_rport_priv
*rdata
)
547 lockdep_assert_held(&rdata
->rp_mutex
);
549 fc_rport_state_enter(rdata
, RPORT_ST_READY
);
551 FC_RPORT_DBG(rdata
, "Port is Ready\n");
553 kref_get(&rdata
->kref
);
554 if (rdata
->event
== RPORT_EV_NONE
&&
555 !queue_work(rport_event_queue
, &rdata
->event_work
))
556 kref_put(&rdata
->kref
, fc_rport_destroy
);
558 rdata
->event
= RPORT_EV_READY
;
562 * fc_rport_timeout() - Handler for the retry_work timer
563 * @work: Handle to the remote port that has timed out
565 * Locking Note: Called without the rport lock held. This
566 * function will hold the rport lock, call an _enter_*
567 * function and then unlock the rport.
569 * Reference counting: Drops kref on return.
571 static void fc_rport_timeout(struct work_struct
*work
)
573 struct fc_rport_priv
*rdata
=
574 container_of(work
, struct fc_rport_priv
, retry_work
.work
);
576 mutex_lock(&rdata
->rp_mutex
);
577 FC_RPORT_DBG(rdata
, "Port timeout, state %s\n", fc_rport_state(rdata
));
579 switch (rdata
->rp_state
) {
581 fc_rport_enter_flogi(rdata
);
584 fc_rport_enter_plogi(rdata
);
587 fc_rport_enter_prli(rdata
);
590 fc_rport_enter_rtv(rdata
);
593 fc_rport_enter_adisc(rdata
);
595 case RPORT_ST_PLOGI_WAIT
:
598 case RPORT_ST_DELETE
:
602 mutex_unlock(&rdata
->rp_mutex
);
603 kref_put(&rdata
->kref
, fc_rport_destroy
);
607 * fc_rport_error() - Error handler, called once retries have been exhausted
608 * @rdata: The remote port the error is happened on
609 * @err: The error code
611 * Reference counting: does not modify kref
613 static void fc_rport_error(struct fc_rport_priv
*rdata
, int err
)
615 struct fc_lport
*lport
= rdata
->local_port
;
617 lockdep_assert_held(&rdata
->rp_mutex
);
619 FC_RPORT_DBG(rdata
, "Error %d in state %s, retries %d\n",
620 -err
, fc_rport_state(rdata
), rdata
->retries
);
622 switch (rdata
->rp_state
) {
624 rdata
->flags
&= ~FC_RP_STARTED
;
625 fc_rport_enter_delete(rdata
, RPORT_EV_FAILED
);
628 if (lport
->point_to_multipoint
) {
629 rdata
->flags
&= ~FC_RP_STARTED
;
630 fc_rport_enter_delete(rdata
, RPORT_EV_FAILED
);
632 fc_rport_enter_logo(rdata
);
635 fc_rport_enter_ready(rdata
);
638 fc_rport_enter_plogi(rdata
);
641 fc_rport_enter_logo(rdata
);
643 case RPORT_ST_PLOGI_WAIT
:
644 case RPORT_ST_DELETE
:
652 * fc_rport_error_retry() - Handler for remote port state retries
653 * @rdata: The remote port whose state is to be retried
654 * @err: The error code
656 * If the error was an exchange timeout retry immediately,
657 * otherwise wait for E_D_TOV.
659 * Reference counting: increments kref when scheduling retry_work
661 static void fc_rport_error_retry(struct fc_rport_priv
*rdata
, int err
)
663 unsigned long delay
= msecs_to_jiffies(rdata
->e_d_tov
);
665 lockdep_assert_held(&rdata
->rp_mutex
);
667 /* make sure this isn't an FC_EX_CLOSED error, never retry those */
668 if (err
== -FC_EX_CLOSED
)
671 if (rdata
->retries
< rdata
->local_port
->max_rport_retry_count
) {
672 FC_RPORT_DBG(rdata
, "Error %d in state %s, retrying\n",
673 err
, fc_rport_state(rdata
));
675 /* no additional delay on exchange timeouts */
676 if (err
== -FC_EX_TIMEOUT
)
678 kref_get(&rdata
->kref
);
679 if (!schedule_delayed_work(&rdata
->retry_work
, delay
))
680 kref_put(&rdata
->kref
, fc_rport_destroy
);
685 fc_rport_error(rdata
, err
);
689 * fc_rport_login_complete() - Handle parameters and completion of p-mp login.
690 * @rdata: The remote port which we logged into or which logged into us.
691 * @fp: The FLOGI or PLOGI request or response frame
693 * Returns non-zero error if a problem is detected with the frame.
694 * Does not free the frame.
696 * This is only used in point-to-multipoint mode for FIP currently.
698 static int fc_rport_login_complete(struct fc_rport_priv
*rdata
,
701 struct fc_lport
*lport
= rdata
->local_port
;
702 struct fc_els_flogi
*flogi
;
703 unsigned int e_d_tov
;
706 flogi
= fc_frame_payload_get(fp
, sizeof(*flogi
));
710 csp_flags
= ntohs(flogi
->fl_csp
.sp_features
);
712 if (fc_frame_payload_op(fp
) == ELS_FLOGI
) {
713 if (csp_flags
& FC_SP_FT_FPORT
) {
714 FC_RPORT_DBG(rdata
, "Fabric bit set in FLOGI\n");
720 * E_D_TOV is not valid on an incoming FLOGI request.
722 e_d_tov
= ntohl(flogi
->fl_csp
.sp_e_d_tov
);
723 if (csp_flags
& FC_SP_FT_EDTR
)
725 if (e_d_tov
> rdata
->e_d_tov
)
726 rdata
->e_d_tov
= e_d_tov
;
728 rdata
->maxframe_size
= fc_plogi_get_maxframe(flogi
, lport
->mfs
);
733 * fc_rport_flogi_resp() - Handle response to FLOGI request for p-mp mode
734 * @sp: The sequence that the FLOGI was on
735 * @fp: The FLOGI response frame
736 * @rp_arg: The remote port that received the FLOGI response
738 static void fc_rport_flogi_resp(struct fc_seq
*sp
, struct fc_frame
*fp
,
741 struct fc_rport_priv
*rdata
= rp_arg
;
742 struct fc_lport
*lport
= rdata
->local_port
;
743 struct fc_els_flogi
*flogi
;
744 unsigned int r_a_tov
;
748 FC_RPORT_DBG(rdata
, "Received a FLOGI %s\n",
749 IS_ERR(fp
) ? "error" : fc_els_resp_type(fp
));
751 if (fp
== ERR_PTR(-FC_EX_CLOSED
))
754 mutex_lock(&rdata
->rp_mutex
);
756 if (rdata
->rp_state
!= RPORT_ST_FLOGI
) {
757 FC_RPORT_DBG(rdata
, "Received a FLOGI response, but in state "
758 "%s\n", fc_rport_state(rdata
));
765 fc_rport_error(rdata
, PTR_ERR(fp
));
768 opcode
= fc_frame_payload_op(fp
);
769 if (opcode
== ELS_LS_RJT
) {
770 struct fc_els_ls_rjt
*rjt
;
772 rjt
= fc_frame_payload_get(fp
, sizeof(*rjt
));
773 FC_RPORT_DBG(rdata
, "FLOGI ELS rejected, reason %x expl %x\n",
774 rjt
->er_reason
, rjt
->er_explan
);
775 err
= -FC_EX_ELS_RJT
;
777 } else if (opcode
!= ELS_LS_ACC
) {
778 FC_RPORT_DBG(rdata
, "FLOGI ELS invalid opcode %x\n", opcode
);
779 err
= -FC_EX_ELS_RJT
;
782 if (fc_rport_login_complete(rdata
, fp
)) {
783 FC_RPORT_DBG(rdata
, "FLOGI failed, no login\n");
784 err
= -FC_EX_INV_LOGIN
;
788 flogi
= fc_frame_payload_get(fp
, sizeof(*flogi
));
790 err
= -FC_EX_ALLOC_ERR
;
793 r_a_tov
= ntohl(flogi
->fl_csp
.sp_r_a_tov
);
794 if (r_a_tov
> rdata
->r_a_tov
)
795 rdata
->r_a_tov
= r_a_tov
;
797 if (rdata
->ids
.port_name
< lport
->wwpn
)
798 fc_rport_enter_plogi(rdata
);
800 fc_rport_state_enter(rdata
, RPORT_ST_PLOGI_WAIT
);
804 mutex_unlock(&rdata
->rp_mutex
);
806 kref_put(&rdata
->kref
, fc_rport_destroy
);
809 FC_RPORT_DBG(rdata
, "Bad FLOGI response\n");
810 fc_rport_error_retry(rdata
, err
);
815 * fc_rport_enter_flogi() - Send a FLOGI request to the remote port for p-mp
816 * @rdata: The remote port to send a FLOGI to
818 * Reference counting: increments kref when sending ELS
820 static void fc_rport_enter_flogi(struct fc_rport_priv
*rdata
)
822 struct fc_lport
*lport
= rdata
->local_port
;
825 lockdep_assert_held(&rdata
->rp_mutex
);
827 if (!lport
->point_to_multipoint
)
828 return fc_rport_enter_plogi(rdata
);
830 FC_RPORT_DBG(rdata
, "Entered FLOGI state from %s state\n",
831 fc_rport_state(rdata
));
833 fc_rport_state_enter(rdata
, RPORT_ST_FLOGI
);
835 fp
= fc_frame_alloc(lport
, sizeof(struct fc_els_flogi
));
837 return fc_rport_error_retry(rdata
, -FC_EX_ALLOC_ERR
);
839 kref_get(&rdata
->kref
);
840 if (!lport
->tt
.elsct_send(lport
, rdata
->ids
.port_id
, fp
, ELS_FLOGI
,
841 fc_rport_flogi_resp
, rdata
,
842 2 * lport
->r_a_tov
)) {
843 fc_rport_error_retry(rdata
, -FC_EX_XMIT_ERR
);
844 kref_put(&rdata
->kref
, fc_rport_destroy
);
849 * fc_rport_recv_flogi_req() - Handle Fabric Login (FLOGI) request in p-mp mode
850 * @lport: The local port that received the PLOGI request
851 * @rx_fp: The PLOGI request frame
853 * Reference counting: drops kref on return
855 static void fc_rport_recv_flogi_req(struct fc_lport
*lport
,
856 struct fc_frame
*rx_fp
)
858 struct fc_els_flogi
*flp
;
859 struct fc_rport_priv
*rdata
;
860 struct fc_frame
*fp
= rx_fp
;
861 struct fc_seq_els_data rjt_data
;
864 sid
= fc_frame_sid(fp
);
866 FC_RPORT_ID_DBG(lport
, sid
, "Received FLOGI request\n");
868 if (!lport
->point_to_multipoint
) {
869 rjt_data
.reason
= ELS_RJT_UNSUP
;
870 rjt_data
.explan
= ELS_EXPL_NONE
;
874 flp
= fc_frame_payload_get(fp
, sizeof(*flp
));
876 rjt_data
.reason
= ELS_RJT_LOGIC
;
877 rjt_data
.explan
= ELS_EXPL_INV_LEN
;
881 rdata
= fc_rport_lookup(lport
, sid
);
883 rjt_data
.reason
= ELS_RJT_FIP
;
884 rjt_data
.explan
= ELS_EXPL_NOT_NEIGHBOR
;
887 mutex_lock(&rdata
->rp_mutex
);
889 FC_RPORT_DBG(rdata
, "Received FLOGI in %s state\n",
890 fc_rport_state(rdata
));
892 switch (rdata
->rp_state
) {
895 * If received the FLOGI request on RPORT which is INIT state
896 * (means not transition to FLOGI either fc_rport timeout
897 * function didn;t trigger or this end hasn;t received
898 * beacon yet from other end. In that case only, allow RPORT
899 * state machine to continue, otherwise fall through which
900 * causes the code to send reject response.
901 * NOTE; Not checking for FIP->state such as VNMP_UP or
902 * VNMP_CLAIM because if FIP state is not one of those,
903 * RPORT wouldn;t have created and 'rport_lookup' would have
904 * failed anyway in that case.
907 case RPORT_ST_DELETE
:
908 mutex_unlock(&rdata
->rp_mutex
);
909 rjt_data
.reason
= ELS_RJT_FIP
;
910 rjt_data
.explan
= ELS_EXPL_NOT_NEIGHBOR
;
913 case RPORT_ST_PLOGI_WAIT
:
921 * Set the remote port to be deleted and to then restart.
922 * This queues work to be sure exchanges are reset.
924 fc_rport_enter_delete(rdata
, RPORT_EV_LOGO
);
925 mutex_unlock(&rdata
->rp_mutex
);
926 rjt_data
.reason
= ELS_RJT_BUSY
;
927 rjt_data
.explan
= ELS_EXPL_NONE
;
930 if (fc_rport_login_complete(rdata
, fp
)) {
931 mutex_unlock(&rdata
->rp_mutex
);
932 rjt_data
.reason
= ELS_RJT_LOGIC
;
933 rjt_data
.explan
= ELS_EXPL_NONE
;
937 fp
= fc_frame_alloc(lport
, sizeof(*flp
));
941 fc_flogi_fill(lport
, fp
);
942 flp
= fc_frame_payload_get(fp
, sizeof(*flp
));
943 flp
->fl_cmd
= ELS_LS_ACC
;
945 fc_fill_reply_hdr(fp
, rx_fp
, FC_RCTL_ELS_REP
, 0);
946 lport
->tt
.frame_send(lport
, fp
);
949 * Do not proceed with the state machine if our
950 * FLOGI has crossed with an FLOGI from the
951 * remote port; wait for the FLOGI response instead.
953 if (rdata
->rp_state
!= RPORT_ST_FLOGI
) {
954 if (rdata
->ids
.port_name
< lport
->wwpn
)
955 fc_rport_enter_plogi(rdata
);
957 fc_rport_state_enter(rdata
, RPORT_ST_PLOGI_WAIT
);
960 mutex_unlock(&rdata
->rp_mutex
);
961 kref_put(&rdata
->kref
, fc_rport_destroy
);
962 fc_frame_free(rx_fp
);
966 kref_put(&rdata
->kref
, fc_rport_destroy
);
968 fc_seq_els_rsp_send(rx_fp
, ELS_LS_RJT
, &rjt_data
);
969 fc_frame_free(rx_fp
);
973 * fc_rport_plogi_resp() - Handler for ELS PLOGI responses
974 * @sp: The sequence the PLOGI is on
975 * @fp: The PLOGI response frame
976 * @rdata_arg: The remote port that sent the PLOGI response
978 * Locking Note: This function will be called without the rport lock
979 * held, but it will lock, call an _enter_* function or fc_rport_error
980 * and then unlock the rport.
982 static void fc_rport_plogi_resp(struct fc_seq
*sp
, struct fc_frame
*fp
,
985 struct fc_rport_priv
*rdata
= rdata_arg
;
986 struct fc_lport
*lport
= rdata
->local_port
;
987 struct fc_els_flogi
*plp
= NULL
;
992 FC_RPORT_DBG(rdata
, "Received a PLOGI %s\n", fc_els_resp_type(fp
));
994 if (fp
== ERR_PTR(-FC_EX_CLOSED
))
997 mutex_lock(&rdata
->rp_mutex
);
999 if (rdata
->rp_state
!= RPORT_ST_PLOGI
) {
1000 FC_RPORT_DBG(rdata
, "Received a PLOGI response, but in state "
1001 "%s\n", fc_rport_state(rdata
));
1008 fc_rport_error_retry(rdata
, PTR_ERR(fp
));
1012 op
= fc_frame_payload_op(fp
);
1013 if (op
== ELS_LS_ACC
&&
1014 (plp
= fc_frame_payload_get(fp
, sizeof(*plp
))) != NULL
) {
1015 rdata
->ids
.port_name
= get_unaligned_be64(&plp
->fl_wwpn
);
1016 rdata
->ids
.node_name
= get_unaligned_be64(&plp
->fl_wwnn
);
1018 /* save plogi response sp_features for further reference */
1019 rdata
->sp_features
= ntohs(plp
->fl_csp
.sp_features
);
1021 if (lport
->point_to_multipoint
)
1022 fc_rport_login_complete(rdata
, fp
);
1023 csp_seq
= ntohs(plp
->fl_csp
.sp_tot_seq
);
1024 cssp_seq
= ntohs(plp
->fl_cssp
[3 - 1].cp_con_seq
);
1025 if (cssp_seq
< csp_seq
)
1027 rdata
->max_seq
= csp_seq
;
1028 rdata
->maxframe_size
= fc_plogi_get_maxframe(plp
, lport
->mfs
);
1029 fc_rport_enter_prli(rdata
);
1031 struct fc_els_ls_rjt
*rjt
;
1033 rjt
= fc_frame_payload_get(fp
, sizeof(*rjt
));
1035 FC_RPORT_DBG(rdata
, "PLOGI bad response\n");
1037 FC_RPORT_DBG(rdata
, "PLOGI ELS rejected, reason %x expl %x\n",
1038 rjt
->er_reason
, rjt
->er_explan
);
1039 fc_rport_error_retry(rdata
, -FC_EX_ELS_RJT
);
1044 mutex_unlock(&rdata
->rp_mutex
);
1046 kref_put(&rdata
->kref
, fc_rport_destroy
);
1050 fc_rport_compatible_roles(struct fc_lport
*lport
, struct fc_rport_priv
*rdata
)
1052 if (rdata
->ids
.roles
== FC_PORT_ROLE_UNKNOWN
)
1054 if ((rdata
->ids
.roles
& FC_PORT_ROLE_FCP_TARGET
) &&
1055 (lport
->service_params
& FCP_SPPF_INIT_FCN
))
1057 if ((rdata
->ids
.roles
& FC_PORT_ROLE_FCP_INITIATOR
) &&
1058 (lport
->service_params
& FCP_SPPF_TARG_FCN
))
1064 * fc_rport_enter_plogi() - Send Port Login (PLOGI) request
1065 * @rdata: The remote port to send a PLOGI to
1067 * Reference counting: increments kref when sending ELS
1069 static void fc_rport_enter_plogi(struct fc_rport_priv
*rdata
)
1071 struct fc_lport
*lport
= rdata
->local_port
;
1072 struct fc_frame
*fp
;
1074 lockdep_assert_held(&rdata
->rp_mutex
);
1076 if (!fc_rport_compatible_roles(lport
, rdata
)) {
1077 FC_RPORT_DBG(rdata
, "PLOGI suppressed for incompatible role\n");
1078 fc_rport_state_enter(rdata
, RPORT_ST_PLOGI_WAIT
);
1082 FC_RPORT_DBG(rdata
, "Port entered PLOGI state from %s state\n",
1083 fc_rport_state(rdata
));
1085 fc_rport_state_enter(rdata
, RPORT_ST_PLOGI
);
1087 rdata
->maxframe_size
= FC_MIN_MAX_PAYLOAD
;
1088 fp
= fc_frame_alloc(lport
, sizeof(struct fc_els_flogi
));
1090 FC_RPORT_DBG(rdata
, "%s frame alloc failed\n", __func__
);
1091 fc_rport_error_retry(rdata
, -FC_EX_ALLOC_ERR
);
1094 rdata
->e_d_tov
= lport
->e_d_tov
;
1096 kref_get(&rdata
->kref
);
1097 if (!lport
->tt
.elsct_send(lport
, rdata
->ids
.port_id
, fp
, ELS_PLOGI
,
1098 fc_rport_plogi_resp
, rdata
,
1099 2 * lport
->r_a_tov
)) {
1100 fc_rport_error_retry(rdata
, -FC_EX_XMIT_ERR
);
1101 kref_put(&rdata
->kref
, fc_rport_destroy
);
1106 * fc_rport_prli_resp() - Process Login (PRLI) response handler
1107 * @sp: The sequence the PRLI response was on
1108 * @fp: The PRLI response frame
1109 * @rdata_arg: The remote port that sent the PRLI response
1111 * Locking Note: This function will be called without the rport lock
1112 * held, but it will lock, call an _enter_* function or fc_rport_error
1113 * and then unlock the rport.
1115 static void fc_rport_prli_resp(struct fc_seq
*sp
, struct fc_frame
*fp
,
1118 struct fc_rport_priv
*rdata
= rdata_arg
;
1120 struct fc_els_prli prli
;
1121 struct fc_els_spp spp
;
1123 struct fc_els_spp temp_spp
;
1124 struct fc_els_ls_rjt
*rjt
;
1125 struct fc4_prov
*prov
;
1126 u32 roles
= FC_RPORT_ROLE_UNKNOWN
;
1129 enum fc_els_spp_resp resp_code
;
1131 FC_RPORT_DBG(rdata
, "Received a PRLI %s\n", fc_els_resp_type(fp
));
1133 if (fp
== ERR_PTR(-FC_EX_CLOSED
))
1136 mutex_lock(&rdata
->rp_mutex
);
1138 if (rdata
->rp_state
!= RPORT_ST_PRLI
) {
1139 FC_RPORT_DBG(rdata
, "Received a PRLI response, but in state "
1140 "%s\n", fc_rport_state(rdata
));
1147 fc_rport_error_retry(rdata
, PTR_ERR(fp
));
1151 /* reinitialize remote port roles */
1152 rdata
->ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
1154 op
= fc_frame_payload_op(fp
);
1155 if (op
== ELS_LS_ACC
) {
1156 pp
= fc_frame_payload_get(fp
, sizeof(*pp
));
1158 fc_rport_error_retry(rdata
, -FC_EX_SEQ_ERR
);
1162 resp_code
= (pp
->spp
.spp_flags
& FC_SPP_RESP_MASK
);
1163 FC_RPORT_DBG(rdata
, "PRLI spp_flags = 0x%x spp_type 0x%x\n",
1164 pp
->spp
.spp_flags
, pp
->spp
.spp_type
);
1166 rdata
->spp_type
= pp
->spp
.spp_type
;
1167 if (resp_code
!= FC_SPP_RESP_ACK
) {
1168 if (resp_code
== FC_SPP_RESP_CONF
)
1169 fc_rport_error(rdata
, -FC_EX_SEQ_ERR
);
1171 fc_rport_error_retry(rdata
, -FC_EX_SEQ_ERR
);
1174 if (pp
->prli
.prli_spp_len
< sizeof(pp
->spp
)) {
1175 fc_rport_error_retry(rdata
, -FC_EX_SEQ_ERR
);
1179 fcp_parm
= ntohl(pp
->spp
.spp_params
);
1180 if (fcp_parm
& FCP_SPPF_RETRY
)
1181 rdata
->flags
|= FC_RP_FLAGS_RETRY
;
1182 if (fcp_parm
& FCP_SPPF_CONF_COMPL
)
1183 rdata
->flags
|= FC_RP_FLAGS_CONF_REQ
;
1186 * Call prli provider if we should act as a target
1188 if (rdata
->spp_type
< FC_FC4_PROV_SIZE
) {
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
);
1197 * Check if the image pair could be established
1199 if (rdata
->spp_type
!= FC_TYPE_FCP
||
1200 !(pp
->spp
.spp_flags
& FC_SPP_EST_IMG_PAIR
)) {
1202 * Nope; we can't use this port as a target.
1204 fcp_parm
&= ~FCP_SPPF_TARG_FCN
;
1206 rdata
->supported_classes
= FC_COS_CLASS3
;
1207 if (fcp_parm
& FCP_SPPF_INIT_FCN
)
1208 roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
1209 if (fcp_parm
& FCP_SPPF_TARG_FCN
)
1210 roles
|= FC_RPORT_ROLE_FCP_TARGET
;
1212 rdata
->ids
.roles
= roles
;
1213 fc_rport_enter_rtv(rdata
);
1216 rjt
= fc_frame_payload_get(fp
, sizeof(*rjt
));
1218 FC_RPORT_DBG(rdata
, "PRLI bad response\n");
1220 FC_RPORT_DBG(rdata
, "PRLI ELS rejected, reason %x expl %x\n",
1221 rjt
->er_reason
, rjt
->er_explan
);
1222 if (rjt
->er_reason
== ELS_RJT_UNAB
&&
1223 rjt
->er_explan
== ELS_EXPL_PLOGI_REQD
) {
1224 fc_rport_enter_plogi(rdata
);
1228 fc_rport_error_retry(rdata
, FC_EX_ELS_RJT
);
1234 mutex_unlock(&rdata
->rp_mutex
);
1236 kref_put(&rdata
->kref
, fc_rport_destroy
);
1240 * fc_rport_enter_prli() - Send Process Login (PRLI) request
1241 * @rdata: The remote port to send the PRLI request to
1243 * Reference counting: increments kref when sending ELS
1245 static void fc_rport_enter_prli(struct fc_rport_priv
*rdata
)
1247 struct fc_lport
*lport
= rdata
->local_port
;
1249 struct fc_els_prli prli
;
1250 struct fc_els_spp spp
;
1252 struct fc_frame
*fp
;
1253 struct fc4_prov
*prov
;
1255 lockdep_assert_held(&rdata
->rp_mutex
);
1258 * If the rport is one of the well known addresses
1259 * we skip PRLI and RTV and go straight to READY.
1261 if (rdata
->ids
.port_id
>= FC_FID_DOM_MGR
) {
1262 fc_rport_enter_ready(rdata
);
1267 * And if the local port does not support the initiator function
1268 * there's no need to send a PRLI, either.
1270 if (!(lport
->service_params
& FCP_SPPF_INIT_FCN
)) {
1271 fc_rport_enter_ready(rdata
);
1275 FC_RPORT_DBG(rdata
, "Port entered PRLI state from %s state\n",
1276 fc_rport_state(rdata
));
1278 fc_rport_state_enter(rdata
, RPORT_ST_PRLI
);
1280 fp
= fc_frame_alloc(lport
, sizeof(*pp
));
1282 fc_rport_error_retry(rdata
, -FC_EX_ALLOC_ERR
);
1286 fc_prli_fill(lport
, fp
);
1288 prov
= fc_passive_prov
[FC_TYPE_FCP
];
1290 pp
= fc_frame_payload_get(fp
, sizeof(*pp
));
1291 prov
->prli(rdata
, sizeof(pp
->spp
), NULL
, &pp
->spp
);
1294 fc_fill_fc_hdr(fp
, FC_RCTL_ELS_REQ
, rdata
->ids
.port_id
,
1295 fc_host_port_id(lport
->host
), FC_TYPE_ELS
,
1296 FC_FC_FIRST_SEQ
| FC_FC_END_SEQ
| FC_FC_SEQ_INIT
, 0);
1298 kref_get(&rdata
->kref
);
1299 if (!fc_exch_seq_send(lport
, fp
, fc_rport_prli_resp
,
1300 NULL
, rdata
, 2 * lport
->r_a_tov
)) {
1301 fc_rport_error_retry(rdata
, -FC_EX_XMIT_ERR
);
1302 kref_put(&rdata
->kref
, fc_rport_destroy
);
1307 * fc_rport_rtv_resp() - Handler for Request Timeout Value (RTV) responses
1308 * @sp: The sequence the RTV was on
1309 * @fp: The RTV response frame
1310 * @rdata_arg: The remote port that sent the RTV response
1312 * Many targets don't seem to support this.
1314 * Locking Note: This function will be called without the rport lock
1315 * held, but it will lock, call an _enter_* function or fc_rport_error
1316 * and then unlock the rport.
1318 static void fc_rport_rtv_resp(struct fc_seq
*sp
, struct fc_frame
*fp
,
1321 struct fc_rport_priv
*rdata
= rdata_arg
;
1324 FC_RPORT_DBG(rdata
, "Received a RTV %s\n", fc_els_resp_type(fp
));
1326 if (fp
== ERR_PTR(-FC_EX_CLOSED
))
1329 mutex_lock(&rdata
->rp_mutex
);
1331 if (rdata
->rp_state
!= RPORT_ST_RTV
) {
1332 FC_RPORT_DBG(rdata
, "Received a RTV response, but in state "
1333 "%s\n", fc_rport_state(rdata
));
1340 fc_rport_error(rdata
, PTR_ERR(fp
));
1344 op
= fc_frame_payload_op(fp
);
1345 if (op
== ELS_LS_ACC
) {
1346 struct fc_els_rtv_acc
*rtv
;
1350 rtv
= fc_frame_payload_get(fp
, sizeof(*rtv
));
1352 toq
= ntohl(rtv
->rtv_toq
);
1353 tov
= ntohl(rtv
->rtv_r_a_tov
);
1356 if (tov
> rdata
->r_a_tov
)
1357 rdata
->r_a_tov
= tov
;
1358 tov
= ntohl(rtv
->rtv_e_d_tov
);
1359 if (toq
& FC_ELS_RTV_EDRES
)
1363 if (tov
> rdata
->e_d_tov
)
1364 rdata
->e_d_tov
= tov
;
1368 fc_rport_enter_ready(rdata
);
1373 mutex_unlock(&rdata
->rp_mutex
);
1375 kref_put(&rdata
->kref
, fc_rport_destroy
);
1379 * fc_rport_enter_rtv() - Send Request Timeout Value (RTV) request
1380 * @rdata: The remote port to send the RTV request to
1382 * Reference counting: increments kref when sending ELS
1384 static void fc_rport_enter_rtv(struct fc_rport_priv
*rdata
)
1386 struct fc_frame
*fp
;
1387 struct fc_lport
*lport
= rdata
->local_port
;
1389 lockdep_assert_held(&rdata
->rp_mutex
);
1391 FC_RPORT_DBG(rdata
, "Port entered RTV state from %s state\n",
1392 fc_rport_state(rdata
));
1394 fc_rport_state_enter(rdata
, RPORT_ST_RTV
);
1396 fp
= fc_frame_alloc(lport
, sizeof(struct fc_els_rtv
));
1398 fc_rport_error_retry(rdata
, -FC_EX_ALLOC_ERR
);
1402 kref_get(&rdata
->kref
);
1403 if (!lport
->tt
.elsct_send(lport
, rdata
->ids
.port_id
, fp
, ELS_RTV
,
1404 fc_rport_rtv_resp
, rdata
,
1405 2 * lport
->r_a_tov
)) {
1406 fc_rport_error_retry(rdata
, -FC_EX_XMIT_ERR
);
1407 kref_put(&rdata
->kref
, fc_rport_destroy
);
1412 * fc_rport_recv_rtv_req() - Handler for Read Timeout Value (RTV) requests
1413 * @rdata: The remote port that sent the RTV request
1414 * @in_fp: The RTV request frame
1416 static void fc_rport_recv_rtv_req(struct fc_rport_priv
*rdata
,
1417 struct fc_frame
*in_fp
)
1419 struct fc_lport
*lport
= rdata
->local_port
;
1420 struct fc_frame
*fp
;
1421 struct fc_els_rtv_acc
*rtv
;
1422 struct fc_seq_els_data rjt_data
;
1424 lockdep_assert_held(&rdata
->rp_mutex
);
1425 lockdep_assert_held(&lport
->lp_mutex
);
1427 FC_RPORT_DBG(rdata
, "Received RTV request\n");
1429 fp
= fc_frame_alloc(lport
, sizeof(*rtv
));
1431 rjt_data
.reason
= ELS_RJT_UNAB
;
1432 rjt_data
.explan
= ELS_EXPL_INSUF_RES
;
1433 fc_seq_els_rsp_send(in_fp
, ELS_LS_RJT
, &rjt_data
);
1436 rtv
= fc_frame_payload_get(fp
, sizeof(*rtv
));
1437 rtv
->rtv_cmd
= ELS_LS_ACC
;
1438 rtv
->rtv_r_a_tov
= htonl(lport
->r_a_tov
);
1439 rtv
->rtv_e_d_tov
= htonl(lport
->e_d_tov
);
1441 fc_fill_reply_hdr(fp
, in_fp
, FC_RCTL_ELS_REP
, 0);
1442 lport
->tt
.frame_send(lport
, fp
);
1444 fc_frame_free(in_fp
);
1448 * fc_rport_logo_resp() - Handler for logout (LOGO) responses
1449 * @sp: The sequence the LOGO was on
1450 * @fp: The LOGO response frame
1451 * @rdata_arg: The remote port
1453 static void fc_rport_logo_resp(struct fc_seq
*sp
, struct fc_frame
*fp
,
1456 struct fc_rport_priv
*rdata
= rdata_arg
;
1457 struct fc_lport
*lport
= rdata
->local_port
;
1459 FC_RPORT_ID_DBG(lport
, fc_seq_exch(sp
)->did
,
1460 "Received a LOGO %s\n", fc_els_resp_type(fp
));
1463 kref_put(&rdata
->kref
, fc_rport_destroy
);
1467 * fc_rport_enter_logo() - Send a logout (LOGO) request
1468 * @rdata: The remote port to send the LOGO request to
1470 * Reference counting: increments kref when sending ELS
1472 static void fc_rport_enter_logo(struct fc_rport_priv
*rdata
)
1474 struct fc_lport
*lport
= rdata
->local_port
;
1475 struct fc_frame
*fp
;
1477 lockdep_assert_held(&rdata
->rp_mutex
);
1479 FC_RPORT_DBG(rdata
, "Port sending LOGO from %s state\n",
1480 fc_rport_state(rdata
));
1482 fp
= fc_frame_alloc(lport
, sizeof(struct fc_els_logo
));
1485 kref_get(&rdata
->kref
);
1486 if (!lport
->tt
.elsct_send(lport
, rdata
->ids
.port_id
, fp
, ELS_LOGO
,
1487 fc_rport_logo_resp
, rdata
, 0))
1488 kref_put(&rdata
->kref
, fc_rport_destroy
);
1492 * fc_rport_adisc_resp() - Handler for Address Discovery (ADISC) responses
1493 * @sp: The sequence the ADISC response was on
1494 * @fp: The ADISC response frame
1495 * @rdata_arg: The remote port that sent the ADISC response
1497 * Locking Note: This function will be called without the rport lock
1498 * held, but it will lock, call an _enter_* function or fc_rport_error
1499 * and then unlock the rport.
1501 static void fc_rport_adisc_resp(struct fc_seq
*sp
, struct fc_frame
*fp
,
1504 struct fc_rport_priv
*rdata
= rdata_arg
;
1505 struct fc_els_adisc
*adisc
;
1508 FC_RPORT_DBG(rdata
, "Received a ADISC response\n");
1510 if (fp
== ERR_PTR(-FC_EX_CLOSED
))
1513 mutex_lock(&rdata
->rp_mutex
);
1515 if (rdata
->rp_state
!= RPORT_ST_ADISC
) {
1516 FC_RPORT_DBG(rdata
, "Received a ADISC resp but in state %s\n",
1517 fc_rport_state(rdata
));
1524 fc_rport_error(rdata
, PTR_ERR(fp
));
1529 * If address verification failed. Consider us logged out of the rport.
1530 * Since the rport is still in discovery, we want to be
1531 * logged in, so go to PLOGI state. Otherwise, go back to READY.
1533 op
= fc_frame_payload_op(fp
);
1534 adisc
= fc_frame_payload_get(fp
, sizeof(*adisc
));
1535 if (op
!= ELS_LS_ACC
|| !adisc
||
1536 ntoh24(adisc
->adisc_port_id
) != rdata
->ids
.port_id
||
1537 get_unaligned_be64(&adisc
->adisc_wwpn
) != rdata
->ids
.port_name
||
1538 get_unaligned_be64(&adisc
->adisc_wwnn
) != rdata
->ids
.node_name
) {
1539 FC_RPORT_DBG(rdata
, "ADISC error or mismatch\n");
1540 fc_rport_enter_flogi(rdata
);
1542 FC_RPORT_DBG(rdata
, "ADISC OK\n");
1543 fc_rport_enter_ready(rdata
);
1548 mutex_unlock(&rdata
->rp_mutex
);
1550 kref_put(&rdata
->kref
, fc_rport_destroy
);
1554 * fc_rport_enter_adisc() - Send Address Discover (ADISC) request
1555 * @rdata: The remote port to send the ADISC request to
1557 * Reference counting: increments kref when sending ELS
1559 static void fc_rport_enter_adisc(struct fc_rport_priv
*rdata
)
1561 struct fc_lport
*lport
= rdata
->local_port
;
1562 struct fc_frame
*fp
;
1564 lockdep_assert_held(&rdata
->rp_mutex
);
1566 FC_RPORT_DBG(rdata
, "sending ADISC from %s state\n",
1567 fc_rport_state(rdata
));
1569 fc_rport_state_enter(rdata
, RPORT_ST_ADISC
);
1571 fp
= fc_frame_alloc(lport
, sizeof(struct fc_els_adisc
));
1573 fc_rport_error_retry(rdata
, -FC_EX_ALLOC_ERR
);
1576 kref_get(&rdata
->kref
);
1577 if (!lport
->tt
.elsct_send(lport
, rdata
->ids
.port_id
, fp
, ELS_ADISC
,
1578 fc_rport_adisc_resp
, rdata
,
1579 2 * lport
->r_a_tov
)) {
1580 fc_rport_error_retry(rdata
, -FC_EX_XMIT_ERR
);
1581 kref_put(&rdata
->kref
, fc_rport_destroy
);
1586 * fc_rport_recv_adisc_req() - Handler for Address Discovery (ADISC) requests
1587 * @rdata: The remote port that sent the ADISC request
1588 * @in_fp: The ADISC request frame
1590 static void fc_rport_recv_adisc_req(struct fc_rport_priv
*rdata
,
1591 struct fc_frame
*in_fp
)
1593 struct fc_lport
*lport
= rdata
->local_port
;
1594 struct fc_frame
*fp
;
1595 struct fc_els_adisc
*adisc
;
1596 struct fc_seq_els_data rjt_data
;
1598 lockdep_assert_held(&rdata
->rp_mutex
);
1599 lockdep_assert_held(&lport
->lp_mutex
);
1601 FC_RPORT_DBG(rdata
, "Received ADISC request\n");
1603 adisc
= fc_frame_payload_get(in_fp
, sizeof(*adisc
));
1605 rjt_data
.reason
= ELS_RJT_PROT
;
1606 rjt_data
.explan
= ELS_EXPL_INV_LEN
;
1607 fc_seq_els_rsp_send(in_fp
, ELS_LS_RJT
, &rjt_data
);
1611 fp
= fc_frame_alloc(lport
, sizeof(*adisc
));
1614 fc_adisc_fill(lport
, fp
);
1615 adisc
= fc_frame_payload_get(fp
, sizeof(*adisc
));
1616 adisc
->adisc_cmd
= ELS_LS_ACC
;
1617 fc_fill_reply_hdr(fp
, in_fp
, FC_RCTL_ELS_REP
, 0);
1618 lport
->tt
.frame_send(lport
, fp
);
1620 fc_frame_free(in_fp
);
1624 * fc_rport_recv_rls_req() - Handle received Read Link Status request
1625 * @rdata: The remote port that sent the RLS request
1626 * @rx_fp: The PRLI request frame
1628 static void fc_rport_recv_rls_req(struct fc_rport_priv
*rdata
,
1629 struct fc_frame
*rx_fp
)
1632 struct fc_lport
*lport
= rdata
->local_port
;
1633 struct fc_frame
*fp
;
1634 struct fc_els_rls
*rls
;
1635 struct fc_els_rls_resp
*rsp
;
1636 struct fc_els_lesb
*lesb
;
1637 struct fc_seq_els_data rjt_data
;
1638 struct fc_host_statistics
*hst
;
1640 lockdep_assert_held(&rdata
->rp_mutex
);
1642 FC_RPORT_DBG(rdata
, "Received RLS request while in state %s\n",
1643 fc_rport_state(rdata
));
1645 rls
= fc_frame_payload_get(rx_fp
, sizeof(*rls
));
1647 rjt_data
.reason
= ELS_RJT_PROT
;
1648 rjt_data
.explan
= ELS_EXPL_INV_LEN
;
1652 fp
= fc_frame_alloc(lport
, sizeof(*rsp
));
1654 rjt_data
.reason
= ELS_RJT_UNAB
;
1655 rjt_data
.explan
= ELS_EXPL_INSUF_RES
;
1659 rsp
= fc_frame_payload_get(fp
, sizeof(*rsp
));
1660 memset(rsp
, 0, sizeof(*rsp
));
1661 rsp
->rls_cmd
= ELS_LS_ACC
;
1662 lesb
= &rsp
->rls_lesb
;
1663 if (lport
->tt
.get_lesb
) {
1664 /* get LESB from LLD if it supports it */
1665 lport
->tt
.get_lesb(lport
, lesb
);
1667 fc_get_host_stats(lport
->host
);
1668 hst
= &lport
->host_stats
;
1669 lesb
->lesb_link_fail
= htonl(hst
->link_failure_count
);
1670 lesb
->lesb_sync_loss
= htonl(hst
->loss_of_sync_count
);
1671 lesb
->lesb_sig_loss
= htonl(hst
->loss_of_signal_count
);
1672 lesb
->lesb_prim_err
= htonl(hst
->prim_seq_protocol_err_count
);
1673 lesb
->lesb_inv_word
= htonl(hst
->invalid_tx_word_count
);
1674 lesb
->lesb_inv_crc
= htonl(hst
->invalid_crc_count
);
1677 fc_fill_reply_hdr(fp
, rx_fp
, FC_RCTL_ELS_REP
, 0);
1678 lport
->tt
.frame_send(lport
, fp
);
1682 fc_seq_els_rsp_send(rx_fp
, ELS_LS_RJT
, &rjt_data
);
1684 fc_frame_free(rx_fp
);
1688 * fc_rport_recv_els_req() - Handler for validated ELS requests
1689 * @lport: The local port that received the ELS request
1690 * @fp: The ELS request frame
1692 * Handle incoming ELS requests that require port login.
1693 * The ELS opcode has already been validated by the caller.
1695 * Reference counting: does not modify kref
1697 static void fc_rport_recv_els_req(struct fc_lport
*lport
, struct fc_frame
*fp
)
1699 struct fc_rport_priv
*rdata
;
1700 struct fc_seq_els_data els_data
;
1702 lockdep_assert_held(&lport
->lp_mutex
);
1704 rdata
= fc_rport_lookup(lport
, fc_frame_sid(fp
));
1706 FC_RPORT_ID_DBG(lport
, fc_frame_sid(fp
),
1707 "Received ELS 0x%02x from non-logged-in port\n",
1708 fc_frame_payload_op(fp
));
1712 mutex_lock(&rdata
->rp_mutex
);
1714 switch (rdata
->rp_state
) {
1717 case RPORT_ST_READY
:
1718 case RPORT_ST_ADISC
:
1720 case RPORT_ST_PLOGI
:
1721 if (fc_frame_payload_op(fp
) == ELS_PRLI
) {
1722 FC_RPORT_DBG(rdata
, "Reject ELS PRLI "
1723 "while in state %s\n",
1724 fc_rport_state(rdata
));
1725 mutex_unlock(&rdata
->rp_mutex
);
1726 kref_put(&rdata
->kref
, fc_rport_destroy
);
1732 "Reject ELS 0x%02x while in state %s\n",
1733 fc_frame_payload_op(fp
), fc_rport_state(rdata
));
1734 mutex_unlock(&rdata
->rp_mutex
);
1735 kref_put(&rdata
->kref
, fc_rport_destroy
);
1739 switch (fc_frame_payload_op(fp
)) {
1741 fc_rport_recv_prli_req(rdata
, fp
);
1744 fc_rport_recv_prlo_req(rdata
, fp
);
1747 fc_rport_recv_adisc_req(rdata
, fp
);
1750 fc_seq_els_rsp_send(fp
, ELS_RRQ
, NULL
);
1754 fc_seq_els_rsp_send(fp
, ELS_REC
, NULL
);
1758 fc_rport_recv_rls_req(rdata
, fp
);
1761 fc_rport_recv_rtv_req(rdata
, fp
);
1764 fc_frame_free(fp
); /* can't happen */
1768 mutex_unlock(&rdata
->rp_mutex
);
1769 kref_put(&rdata
->kref
, fc_rport_destroy
);
1773 els_data
.reason
= ELS_RJT_UNAB
;
1774 els_data
.explan
= ELS_EXPL_PLOGI_REQD
;
1775 fc_seq_els_rsp_send(fp
, ELS_LS_RJT
, &els_data
);
1780 els_data
.reason
= ELS_RJT_BUSY
;
1781 els_data
.explan
= ELS_EXPL_NONE
;
1782 fc_seq_els_rsp_send(fp
, ELS_LS_RJT
, &els_data
);
1788 * fc_rport_recv_req() - Handler for requests
1789 * @lport: The local port that received the request
1790 * @fp: The request frame
1792 * Reference counting: does not modify kref
1794 void fc_rport_recv_req(struct fc_lport
*lport
, struct fc_frame
*fp
)
1796 struct fc_seq_els_data els_data
;
1798 lockdep_assert_held(&lport
->lp_mutex
);
1801 * Handle FLOGI, PLOGI and LOGO requests separately, since they
1802 * don't require prior login.
1803 * Check for unsupported opcodes first and reject them.
1804 * For some ops, it would be incorrect to reject with "PLOGI required".
1806 switch (fc_frame_payload_op(fp
)) {
1808 fc_rport_recv_flogi_req(lport
, fp
);
1811 fc_rport_recv_plogi_req(lport
, fp
);
1814 fc_rport_recv_logo_req(lport
, fp
);
1823 fc_rport_recv_els_req(lport
, fp
);
1826 els_data
.reason
= ELS_RJT_UNSUP
;
1827 els_data
.explan
= ELS_EXPL_NONE
;
1828 fc_seq_els_rsp_send(fp
, ELS_LS_RJT
, &els_data
);
1833 EXPORT_SYMBOL(fc_rport_recv_req
);
1836 * fc_rport_recv_plogi_req() - Handler for Port Login (PLOGI) requests
1837 * @lport: The local port that received the PLOGI request
1838 * @rx_fp: The PLOGI request frame
1840 * Reference counting: increments kref on return
1842 static void fc_rport_recv_plogi_req(struct fc_lport
*lport
,
1843 struct fc_frame
*rx_fp
)
1845 struct fc_disc
*disc
;
1846 struct fc_rport_priv
*rdata
;
1847 struct fc_frame
*fp
= rx_fp
;
1848 struct fc_els_flogi
*pl
;
1849 struct fc_seq_els_data rjt_data
;
1852 lockdep_assert_held(&lport
->lp_mutex
);
1854 sid
= fc_frame_sid(fp
);
1856 FC_RPORT_ID_DBG(lport
, sid
, "Received PLOGI request\n");
1858 pl
= fc_frame_payload_get(fp
, sizeof(*pl
));
1860 FC_RPORT_ID_DBG(lport
, sid
, "Received PLOGI too short\n");
1861 rjt_data
.reason
= ELS_RJT_PROT
;
1862 rjt_data
.explan
= ELS_EXPL_INV_LEN
;
1866 disc
= &lport
->disc
;
1867 mutex_lock(&disc
->disc_mutex
);
1868 rdata
= fc_rport_create(lport
, sid
);
1870 mutex_unlock(&disc
->disc_mutex
);
1871 rjt_data
.reason
= ELS_RJT_UNAB
;
1872 rjt_data
.explan
= ELS_EXPL_INSUF_RES
;
1876 mutex_lock(&rdata
->rp_mutex
);
1877 mutex_unlock(&disc
->disc_mutex
);
1879 rdata
->ids
.port_name
= get_unaligned_be64(&pl
->fl_wwpn
);
1880 rdata
->ids
.node_name
= get_unaligned_be64(&pl
->fl_wwnn
);
1883 * If the rport was just created, possibly due to the incoming PLOGI,
1884 * set the state appropriately and accept the PLOGI.
1886 * If we had also sent a PLOGI, and if the received PLOGI is from a
1887 * higher WWPN, we accept it, otherwise an LS_RJT is sent with reason
1888 * "command already in progress".
1890 * XXX TBD: If the session was ready before, the PLOGI should result in
1891 * all outstanding exchanges being reset.
1893 switch (rdata
->rp_state
) {
1895 FC_RPORT_DBG(rdata
, "Received PLOGI in INIT state\n");
1897 case RPORT_ST_PLOGI_WAIT
:
1898 FC_RPORT_DBG(rdata
, "Received PLOGI in PLOGI_WAIT state\n");
1900 case RPORT_ST_PLOGI
:
1901 FC_RPORT_DBG(rdata
, "Received PLOGI in PLOGI state\n");
1902 if (rdata
->ids
.port_name
< lport
->wwpn
) {
1903 mutex_unlock(&rdata
->rp_mutex
);
1904 rjt_data
.reason
= ELS_RJT_INPROG
;
1905 rjt_data
.explan
= ELS_EXPL_NONE
;
1911 case RPORT_ST_READY
:
1912 case RPORT_ST_ADISC
:
1913 FC_RPORT_DBG(rdata
, "Received PLOGI in logged-in state %d "
1914 "- ignored for now\n", rdata
->rp_state
);
1915 /* XXX TBD - should reset */
1917 case RPORT_ST_FLOGI
:
1918 case RPORT_ST_DELETE
:
1919 FC_RPORT_DBG(rdata
, "Received PLOGI in state %s - send busy\n",
1920 fc_rport_state(rdata
));
1921 mutex_unlock(&rdata
->rp_mutex
);
1922 rjt_data
.reason
= ELS_RJT_BUSY
;
1923 rjt_data
.explan
= ELS_EXPL_NONE
;
1926 if (!fc_rport_compatible_roles(lport
, rdata
)) {
1927 FC_RPORT_DBG(rdata
, "Received PLOGI for incompatible role\n");
1928 mutex_unlock(&rdata
->rp_mutex
);
1929 rjt_data
.reason
= ELS_RJT_LOGIC
;
1930 rjt_data
.explan
= ELS_EXPL_NONE
;
1935 * Get session payload size from incoming PLOGI.
1937 rdata
->maxframe_size
= fc_plogi_get_maxframe(pl
, lport
->mfs
);
1940 * Send LS_ACC. If this fails, the originator should retry.
1942 fp
= fc_frame_alloc(lport
, sizeof(*pl
));
1946 fc_plogi_fill(lport
, fp
, ELS_LS_ACC
);
1947 fc_fill_reply_hdr(fp
, rx_fp
, FC_RCTL_ELS_REP
, 0);
1948 lport
->tt
.frame_send(lport
, fp
);
1949 fc_rport_enter_prli(rdata
);
1951 mutex_unlock(&rdata
->rp_mutex
);
1952 fc_frame_free(rx_fp
);
1956 fc_seq_els_rsp_send(fp
, ELS_LS_RJT
, &rjt_data
);
1961 * fc_rport_recv_prli_req() - Handler for process login (PRLI) requests
1962 * @rdata: The remote port that sent the PRLI request
1963 * @rx_fp: The PRLI request frame
1965 static void fc_rport_recv_prli_req(struct fc_rport_priv
*rdata
,
1966 struct fc_frame
*rx_fp
)
1968 struct fc_lport
*lport
= rdata
->local_port
;
1969 struct fc_frame
*fp
;
1971 struct fc_els_prli prli
;
1972 struct fc_els_spp spp
;
1974 struct fc_els_spp
*rspp
; /* request service param page */
1975 struct fc_els_spp
*spp
; /* response spp */
1978 enum fc_els_spp_resp resp
;
1979 struct fc_seq_els_data rjt_data
;
1980 struct fc4_prov
*prov
;
1982 lockdep_assert_held(&rdata
->rp_mutex
);
1984 FC_RPORT_DBG(rdata
, "Received PRLI request while in state %s\n",
1985 fc_rport_state(rdata
));
1987 len
= fr_len(rx_fp
) - sizeof(struct fc_frame_header
);
1988 pp
= fc_frame_payload_get(rx_fp
, sizeof(*pp
));
1991 plen
= ntohs(pp
->prli
.prli_len
);
1992 if ((plen
% 4) != 0 || plen
> len
|| plen
< 16)
1996 plen
= pp
->prli
.prli_spp_len
;
1997 if ((plen
% 4) != 0 || plen
< sizeof(*spp
) ||
1998 plen
> len
|| len
< sizeof(*pp
) || plen
< 12)
2002 fp
= fc_frame_alloc(lport
, len
);
2004 rjt_data
.reason
= ELS_RJT_UNAB
;
2005 rjt_data
.explan
= ELS_EXPL_INSUF_RES
;
2008 pp
= fc_frame_payload_get(fp
, len
);
2011 pp
->prli
.prli_cmd
= ELS_LS_ACC
;
2012 pp
->prli
.prli_spp_len
= plen
;
2013 pp
->prli
.prli_len
= htons(len
);
2014 len
-= sizeof(struct fc_els_prli
);
2017 * Go through all the service parameter pages and build
2018 * response. If plen indicates longer SPP than standard,
2019 * use that. The entire response has been pre-cleared above.
2022 mutex_lock(&fc_prov_mutex
);
2023 while (len
>= plen
) {
2024 rdata
->spp_type
= rspp
->spp_type
;
2025 spp
->spp_type
= rspp
->spp_type
;
2026 spp
->spp_type_ext
= rspp
->spp_type_ext
;
2029 if (rspp
->spp_type
< FC_FC4_PROV_SIZE
) {
2030 enum fc_els_spp_resp active
= 0, passive
= 0;
2032 prov
= fc_active_prov
[rspp
->spp_type
];
2034 active
= prov
->prli(rdata
, plen
, rspp
, spp
);
2035 prov
= fc_passive_prov
[rspp
->spp_type
];
2037 passive
= prov
->prli(rdata
, plen
, rspp
, spp
);
2038 if (!active
|| passive
== FC_SPP_RESP_ACK
)
2042 FC_RPORT_DBG(rdata
, "PRLI rspp type %x "
2043 "active %x passive %x\n",
2044 rspp
->spp_type
, active
, passive
);
2047 if (spp
->spp_flags
& FC_SPP_EST_IMG_PAIR
)
2048 resp
|= FC_SPP_RESP_CONF
;
2050 resp
|= FC_SPP_RESP_INVL
;
2052 spp
->spp_flags
|= resp
;
2054 rspp
= (struct fc_els_spp
*)((char *)rspp
+ plen
);
2055 spp
= (struct fc_els_spp
*)((char *)spp
+ plen
);
2057 mutex_unlock(&fc_prov_mutex
);
2060 * Send LS_ACC. If this fails, the originator should retry.
2062 fc_fill_reply_hdr(fp
, rx_fp
, FC_RCTL_ELS_REP
, 0);
2063 lport
->tt
.frame_send(lport
, fp
);
2068 rjt_data
.reason
= ELS_RJT_PROT
;
2069 rjt_data
.explan
= ELS_EXPL_INV_LEN
;
2071 fc_seq_els_rsp_send(rx_fp
, ELS_LS_RJT
, &rjt_data
);
2073 fc_frame_free(rx_fp
);
2077 * fc_rport_recv_prlo_req() - Handler for process logout (PRLO) requests
2078 * @rdata: The remote port that sent the PRLO request
2079 * @rx_fp: The PRLO request frame
2081 static void fc_rport_recv_prlo_req(struct fc_rport_priv
*rdata
,
2082 struct fc_frame
*rx_fp
)
2084 struct fc_lport
*lport
= rdata
->local_port
;
2085 struct fc_frame
*fp
;
2087 struct fc_els_prlo prlo
;
2088 struct fc_els_spp spp
;
2090 struct fc_els_spp
*rspp
; /* request service param page */
2091 struct fc_els_spp
*spp
; /* response spp */
2094 struct fc_seq_els_data rjt_data
;
2096 lockdep_assert_held(&rdata
->rp_mutex
);
2098 FC_RPORT_DBG(rdata
, "Received PRLO request while in state %s\n",
2099 fc_rport_state(rdata
));
2101 len
= fr_len(rx_fp
) - sizeof(struct fc_frame_header
);
2102 pp
= fc_frame_payload_get(rx_fp
, sizeof(*pp
));
2105 plen
= ntohs(pp
->prlo
.prlo_len
);
2113 fp
= fc_frame_alloc(lport
, len
);
2115 rjt_data
.reason
= ELS_RJT_UNAB
;
2116 rjt_data
.explan
= ELS_EXPL_INSUF_RES
;
2120 pp
= fc_frame_payload_get(fp
, len
);
2123 pp
->prlo
.prlo_cmd
= ELS_LS_ACC
;
2124 pp
->prlo
.prlo_obs
= 0x10;
2125 pp
->prlo
.prlo_len
= htons(len
);
2127 spp
->spp_type
= rspp
->spp_type
;
2128 spp
->spp_type_ext
= rspp
->spp_type_ext
;
2129 spp
->spp_flags
= FC_SPP_RESP_ACK
;
2131 fc_rport_enter_prli(rdata
);
2133 fc_fill_reply_hdr(fp
, rx_fp
, FC_RCTL_ELS_REP
, 0);
2134 lport
->tt
.frame_send(lport
, fp
);
2138 rjt_data
.reason
= ELS_RJT_PROT
;
2139 rjt_data
.explan
= ELS_EXPL_INV_LEN
;
2141 fc_seq_els_rsp_send(rx_fp
, ELS_LS_RJT
, &rjt_data
);
2143 fc_frame_free(rx_fp
);
2147 * fc_rport_recv_logo_req() - Handler for logout (LOGO) requests
2148 * @lport: The local port that received the LOGO request
2149 * @fp: The LOGO request frame
2151 * Reference counting: drops kref on return
2153 static void fc_rport_recv_logo_req(struct fc_lport
*lport
, struct fc_frame
*fp
)
2155 struct fc_rport_priv
*rdata
;
2158 lockdep_assert_held(&lport
->lp_mutex
);
2160 fc_seq_els_rsp_send(fp
, ELS_LS_ACC
, NULL
);
2162 sid
= fc_frame_sid(fp
);
2164 rdata
= fc_rport_lookup(lport
, sid
);
2166 mutex_lock(&rdata
->rp_mutex
);
2167 FC_RPORT_DBG(rdata
, "Received LOGO request while in state %s\n",
2168 fc_rport_state(rdata
));
2170 fc_rport_enter_delete(rdata
, RPORT_EV_STOP
);
2171 mutex_unlock(&rdata
->rp_mutex
);
2172 kref_put(&rdata
->kref
, fc_rport_destroy
);
2174 FC_RPORT_ID_DBG(lport
, sid
,
2175 "Received LOGO from non-logged-in port\n");
2180 * fc_rport_flush_queue() - Flush the rport_event_queue
2182 void fc_rport_flush_queue(void)
2184 flush_workqueue(rport_event_queue
);
2186 EXPORT_SYMBOL(fc_rport_flush_queue
);
2189 * fc_rport_fcp_prli() - Handle incoming PRLI for the FCP initiator.
2190 * @rdata: remote port private
2191 * @spp_len: service parameter page length
2192 * @rspp: received service parameter page
2193 * @spp: response service parameter page
2195 * Returns the value for the response code to be placed in spp_flags;
2196 * Returns 0 if not an initiator.
2198 static int fc_rport_fcp_prli(struct fc_rport_priv
*rdata
, u32 spp_len
,
2199 const struct fc_els_spp
*rspp
,
2200 struct fc_els_spp
*spp
)
2202 struct fc_lport
*lport
= rdata
->local_port
;
2205 fcp_parm
= ntohl(rspp
->spp_params
);
2206 rdata
->ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2207 if (fcp_parm
& FCP_SPPF_INIT_FCN
)
2208 rdata
->ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
2209 if (fcp_parm
& FCP_SPPF_TARG_FCN
)
2210 rdata
->ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
2211 if (fcp_parm
& FCP_SPPF_RETRY
)
2212 rdata
->flags
|= FC_RP_FLAGS_RETRY
;
2213 rdata
->supported_classes
= FC_COS_CLASS3
;
2215 if (!(lport
->service_params
& FCP_SPPF_INIT_FCN
))
2218 spp
->spp_flags
|= rspp
->spp_flags
& FC_SPP_EST_IMG_PAIR
;
2221 * OR in our service parameters with other providers (target), if any.
2223 fcp_parm
= ntohl(spp
->spp_params
);
2224 spp
->spp_params
= htonl(fcp_parm
| lport
->service_params
);
2225 return FC_SPP_RESP_ACK
;
2229 * FC-4 provider ops for FCP initiator.
2231 struct fc4_prov fc_rport_fcp_init
= {
2232 .prli
= fc_rport_fcp_prli
,
2236 * fc_rport_t0_prli() - Handle incoming PRLI parameters for type 0
2237 * @rdata: remote port private
2238 * @spp_len: service parameter page length
2239 * @rspp: received service parameter page
2240 * @spp: response service parameter page
2242 static int fc_rport_t0_prli(struct fc_rport_priv
*rdata
, u32 spp_len
,
2243 const struct fc_els_spp
*rspp
,
2244 struct fc_els_spp
*spp
)
2246 if (rspp
->spp_flags
& FC_SPP_EST_IMG_PAIR
)
2247 return FC_SPP_RESP_INVL
;
2248 return FC_SPP_RESP_ACK
;
2252 * FC-4 provider ops for type 0 service parameters.
2254 * This handles the special case of type 0 which is always successful
2255 * but doesn't do anything otherwise.
2257 struct fc4_prov fc_rport_t0_prov
= {
2258 .prli
= fc_rport_t0_prli
,
2262 * fc_setup_rport() - Initialize the rport_event_queue
2264 int fc_setup_rport(void)
2267 alloc_ordered_workqueue("%s", WQ_MEM_RECLAIM
, "fc_rport_eq");
2268 if (!rport_event_queue
)
2274 * fc_destroy_rport() - Destroy the rport_event_queue
2276 void fc_destroy_rport(void)
2278 destroy_workqueue(rport_event_queue
);
2282 * fc_rport_terminate_io() - Stop all outstanding I/O on a remote port
2283 * @rport: The remote port whose I/O should be terminated
2285 void fc_rport_terminate_io(struct fc_rport
*rport
)
2287 struct fc_rport_libfc_priv
*rpriv
= rport
->dd_data
;
2288 struct fc_lport
*lport
= rpriv
->local_port
;
2290 lport
->tt
.exch_mgr_reset(lport
, 0, rport
->port_id
);
2291 lport
->tt
.exch_mgr_reset(lport
, rport
->port_id
, 0);
2293 EXPORT_SYMBOL(fc_rport_terminate_io
);