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
;
132 lockdep_assert_held(&lport
->disc
.disc_mutex
);
134 rdata
= fc_rport_lookup(lport
, port_id
);
138 rdata
= kzalloc(sizeof(*rdata
) + lport
->rport_priv_size
, GFP_KERNEL
);
142 rdata
->ids
.node_name
= -1;
143 rdata
->ids
.port_name
= -1;
144 rdata
->ids
.port_id
= port_id
;
145 rdata
->ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
147 kref_init(&rdata
->kref
);
148 mutex_init(&rdata
->rp_mutex
);
149 rdata
->local_port
= lport
;
150 rdata
->rp_state
= RPORT_ST_INIT
;
151 rdata
->event
= RPORT_EV_NONE
;
152 rdata
->flags
= FC_RP_FLAGS_REC_SUPPORTED
;
153 rdata
->e_d_tov
= lport
->e_d_tov
;
154 rdata
->r_a_tov
= lport
->r_a_tov
;
155 rdata
->maxframe_size
= FC_MIN_MAX_PAYLOAD
;
156 INIT_DELAYED_WORK(&rdata
->retry_work
, fc_rport_timeout
);
157 INIT_WORK(&rdata
->event_work
, fc_rport_work
);
158 if (port_id
!= FC_FID_DIR_SERV
) {
159 rdata
->lld_event_callback
= lport
->tt
.rport_event_callback
;
160 list_add_rcu(&rdata
->peers
, &lport
->disc
.rports
);
164 EXPORT_SYMBOL(fc_rport_create
);
167 * fc_rport_destroy() - Free a remote port after last reference is released
168 * @kref: The remote port's kref
170 void fc_rport_destroy(struct kref
*kref
)
172 struct fc_rport_priv
*rdata
;
174 rdata
= container_of(kref
, struct fc_rport_priv
, kref
);
175 kfree_rcu(rdata
, rcu
);
177 EXPORT_SYMBOL(fc_rport_destroy
);
180 * fc_rport_state() - Return a string identifying the remote port's state
181 * @rdata: The remote port
183 static const char *fc_rport_state(struct fc_rport_priv
*rdata
)
187 cp
= fc_rport_state_names
[rdata
->rp_state
];
194 * fc_set_rport_loss_tmo() - Set the remote port loss timeout
195 * @rport: The remote port that gets a new timeout value
196 * @timeout: The new timeout value (in seconds)
198 void fc_set_rport_loss_tmo(struct fc_rport
*rport
, u32 timeout
)
201 rport
->dev_loss_tmo
= timeout
;
203 rport
->dev_loss_tmo
= 1;
205 EXPORT_SYMBOL(fc_set_rport_loss_tmo
);
208 * fc_plogi_get_maxframe() - Get the maximum payload from the common service
209 * parameters in a FLOGI frame
210 * @flp: The FLOGI or PLOGI payload
211 * @maxval: The maximum frame size upper limit; this may be less than what
212 * is in the service parameters
214 static unsigned int fc_plogi_get_maxframe(struct fc_els_flogi
*flp
,
220 * Get max payload from the common service parameters and the
221 * class 3 receive data field size.
223 mfs
= ntohs(flp
->fl_csp
.sp_bb_data
) & FC_SP_BB_DATA_MASK
;
224 if (mfs
>= FC_SP_MIN_MAX_PAYLOAD
&& mfs
< maxval
)
226 mfs
= ntohs(flp
->fl_cssp
[3 - 1].cp_rdfs
);
227 if (mfs
>= FC_SP_MIN_MAX_PAYLOAD
&& mfs
< maxval
)
233 * fc_rport_state_enter() - Change the state of a remote port
234 * @rdata: The remote port whose state should change
235 * @new: The new state
237 static void fc_rport_state_enter(struct fc_rport_priv
*rdata
,
238 enum fc_rport_state
new)
240 lockdep_assert_held(&rdata
->rp_mutex
);
242 if (rdata
->rp_state
!= new)
244 rdata
->rp_state
= new;
248 * fc_rport_work() - Handler for remote port events in the rport_event_queue
249 * @work: Handle to the remote port being dequeued
251 * Reference counting: drops kref on return
253 static void fc_rport_work(struct work_struct
*work
)
256 struct fc_rport_priv
*rdata
=
257 container_of(work
, struct fc_rport_priv
, event_work
);
258 struct fc_rport_libfc_priv
*rpriv
;
259 enum fc_rport_event event
;
260 struct fc_lport
*lport
= rdata
->local_port
;
261 struct fc_rport_operations
*rport_ops
;
262 struct fc_rport_identifiers ids
;
263 struct fc_rport
*rport
;
264 struct fc4_prov
*prov
;
267 mutex_lock(&rdata
->rp_mutex
);
268 event
= rdata
->event
;
269 rport_ops
= rdata
->ops
;
270 rport
= rdata
->rport
;
272 FC_RPORT_DBG(rdata
, "work event %u\n", event
);
277 rdata
->event
= RPORT_EV_NONE
;
278 rdata
->major_retries
= 0;
279 kref_get(&rdata
->kref
);
280 mutex_unlock(&rdata
->rp_mutex
);
283 FC_RPORT_DBG(rdata
, "No rport!\n");
284 rport
= fc_remote_port_add(lport
->host
, 0, &ids
);
287 FC_RPORT_DBG(rdata
, "Failed to add the rport\n");
288 fc_rport_logoff(rdata
);
289 kref_put(&rdata
->kref
, fc_rport_destroy
);
292 mutex_lock(&rdata
->rp_mutex
);
294 FC_RPORT_DBG(rdata
, "rport already allocated\n");
295 rdata
->rport
= rport
;
296 rport
->maxframe_size
= rdata
->maxframe_size
;
297 rport
->supported_classes
= rdata
->supported_classes
;
299 rpriv
= rport
->dd_data
;
300 rpriv
->local_port
= lport
;
301 rpriv
->rp_state
= rdata
->rp_state
;
302 rpriv
->flags
= rdata
->flags
;
303 rpriv
->e_d_tov
= rdata
->e_d_tov
;
304 rpriv
->r_a_tov
= rdata
->r_a_tov
;
305 mutex_unlock(&rdata
->rp_mutex
);
307 if (rport_ops
&& rport_ops
->event_callback
) {
308 FC_RPORT_DBG(rdata
, "callback ev %d\n", event
);
309 rport_ops
->event_callback(lport
, rdata
, event
);
311 if (rdata
->lld_event_callback
) {
312 FC_RPORT_DBG(rdata
, "lld callback ev %d\n", event
);
313 rdata
->lld_event_callback(lport
, rdata
, event
);
315 kref_put(&rdata
->kref
, fc_rport_destroy
);
318 case RPORT_EV_FAILED
:
321 if (rdata
->prli_count
) {
322 mutex_lock(&fc_prov_mutex
);
323 for (type
= 1; type
< FC_FC4_PROV_SIZE
; type
++) {
324 prov
= fc_passive_prov
[type
];
325 if (prov
&& prov
->prlo
)
328 mutex_unlock(&fc_prov_mutex
);
330 port_id
= rdata
->ids
.port_id
;
331 mutex_unlock(&rdata
->rp_mutex
);
333 if (rport_ops
&& rport_ops
->event_callback
) {
334 FC_RPORT_DBG(rdata
, "callback ev %d\n", event
);
335 rport_ops
->event_callback(lport
, rdata
, event
);
337 if (rdata
->lld_event_callback
) {
338 FC_RPORT_DBG(rdata
, "lld callback ev %d\n", event
);
339 rdata
->lld_event_callback(lport
, rdata
, event
);
341 if (cancel_delayed_work_sync(&rdata
->retry_work
))
342 kref_put(&rdata
->kref
, fc_rport_destroy
);
345 * Reset any outstanding exchanges before freeing rport.
347 lport
->tt
.exch_mgr_reset(lport
, 0, port_id
);
348 lport
->tt
.exch_mgr_reset(lport
, port_id
, 0);
351 rpriv
= rport
->dd_data
;
352 rpriv
->rp_state
= RPORT_ST_DELETE
;
353 mutex_lock(&rdata
->rp_mutex
);
355 mutex_unlock(&rdata
->rp_mutex
);
356 fc_remote_port_delete(rport
);
359 mutex_lock(&rdata
->rp_mutex
);
360 if (rdata
->rp_state
== RPORT_ST_DELETE
) {
361 if (port_id
== FC_FID_DIR_SERV
) {
362 rdata
->event
= RPORT_EV_NONE
;
363 mutex_unlock(&rdata
->rp_mutex
);
364 kref_put(&rdata
->kref
, fc_rport_destroy
);
365 } else if ((rdata
->flags
& FC_RP_STARTED
) &&
366 rdata
->major_retries
<
367 lport
->max_rport_retry_count
) {
368 rdata
->major_retries
++;
369 rdata
->event
= RPORT_EV_NONE
;
370 FC_RPORT_DBG(rdata
, "work restart\n");
371 fc_rport_enter_flogi(rdata
);
372 mutex_unlock(&rdata
->rp_mutex
);
374 mutex_unlock(&rdata
->rp_mutex
);
375 FC_RPORT_DBG(rdata
, "work delete\n");
376 mutex_lock(&lport
->disc
.disc_mutex
);
377 list_del_rcu(&rdata
->peers
);
378 mutex_unlock(&lport
->disc
.disc_mutex
);
379 kref_put(&rdata
->kref
, fc_rport_destroy
);
383 * Re-open for events. Reissue READY event if ready.
385 rdata
->event
= RPORT_EV_NONE
;
386 if (rdata
->rp_state
== RPORT_ST_READY
) {
387 FC_RPORT_DBG(rdata
, "work reopen\n");
388 fc_rport_enter_ready(rdata
);
390 mutex_unlock(&rdata
->rp_mutex
);
395 mutex_unlock(&rdata
->rp_mutex
);
398 kref_put(&rdata
->kref
, fc_rport_destroy
);
402 * fc_rport_login() - Start the remote port login state machine
403 * @rdata: The remote port to be logged in to
405 * Initiates the RP state machine. It is called from the LP module.
406 * This function will issue the following commands to the N_Port
407 * identified by the FC ID provided.
413 * Locking Note: Called without the rport lock held. This
414 * function will hold the rport lock, call an _enter_*
415 * function and then unlock the rport.
417 * This indicates the intent to be logged into the remote port.
418 * If it appears we are already logged in, ADISC is used to verify
421 int fc_rport_login(struct fc_rport_priv
*rdata
)
423 mutex_lock(&rdata
->rp_mutex
);
425 if (rdata
->flags
& FC_RP_STARTED
) {
426 FC_RPORT_DBG(rdata
, "port already started\n");
427 mutex_unlock(&rdata
->rp_mutex
);
431 rdata
->flags
|= FC_RP_STARTED
;
432 switch (rdata
->rp_state
) {
434 FC_RPORT_DBG(rdata
, "ADISC port\n");
435 fc_rport_enter_adisc(rdata
);
437 case RPORT_ST_DELETE
:
438 FC_RPORT_DBG(rdata
, "Restart deleted port\n");
441 FC_RPORT_DBG(rdata
, "Login to port\n");
442 fc_rport_enter_flogi(rdata
);
445 FC_RPORT_DBG(rdata
, "Login in progress, state %s\n",
446 fc_rport_state(rdata
));
449 mutex_unlock(&rdata
->rp_mutex
);
453 EXPORT_SYMBOL(fc_rport_login
);
456 * fc_rport_enter_delete() - Schedule a remote port to be deleted
457 * @rdata: The remote port to be deleted
458 * @event: The event to report as the reason for deletion
460 * Allow state change into DELETE only once.
462 * Call queue_work only if there's no event already pending.
463 * Set the new event so that the old pending event will not occur.
464 * Since we have the mutex, even if fc_rport_work() is already started,
465 * it'll see the new event.
467 * Reference counting: does not modify kref
469 static void fc_rport_enter_delete(struct fc_rport_priv
*rdata
,
470 enum fc_rport_event event
)
472 lockdep_assert_held(&rdata
->rp_mutex
);
474 if (rdata
->rp_state
== RPORT_ST_DELETE
)
477 FC_RPORT_DBG(rdata
, "Delete port\n");
479 fc_rport_state_enter(rdata
, RPORT_ST_DELETE
);
481 kref_get(&rdata
->kref
);
482 if (rdata
->event
== RPORT_EV_NONE
&&
483 !queue_work(rport_event_queue
, &rdata
->event_work
))
484 kref_put(&rdata
->kref
, fc_rport_destroy
);
486 rdata
->event
= event
;
490 * fc_rport_logoff() - Logoff and remove a remote port
491 * @rdata: The remote port to be logged off of
493 * Locking Note: Called without the rport lock held. This
494 * function will hold the rport lock, call an _enter_*
495 * function and then unlock the rport.
497 int fc_rport_logoff(struct fc_rport_priv
*rdata
)
499 struct fc_lport
*lport
= rdata
->local_port
;
500 u32 port_id
= rdata
->ids
.port_id
;
502 mutex_lock(&rdata
->rp_mutex
);
504 FC_RPORT_DBG(rdata
, "Remove port\n");
506 rdata
->flags
&= ~FC_RP_STARTED
;
507 if (rdata
->rp_state
== RPORT_ST_DELETE
) {
508 FC_RPORT_DBG(rdata
, "Port in Delete state, not removing\n");
513 * To explicitly Logout, the initiating Nx_Port shall terminate
514 * other open Sequences that it initiated with the destination
515 * Nx_Port prior to performing Logout.
517 lport
->tt
.exch_mgr_reset(lport
, 0, port_id
);
518 lport
->tt
.exch_mgr_reset(lport
, port_id
, 0);
520 fc_rport_enter_logo(rdata
);
523 * Change the state to Delete so that we discard
526 fc_rport_enter_delete(rdata
, RPORT_EV_STOP
);
528 mutex_unlock(&rdata
->rp_mutex
);
531 EXPORT_SYMBOL(fc_rport_logoff
);
534 * fc_rport_enter_ready() - Transition to the RPORT_ST_READY state
535 * @rdata: The remote port that is ready
537 * Reference counting: schedules workqueue, does not modify kref
539 static void fc_rport_enter_ready(struct fc_rport_priv
*rdata
)
541 lockdep_assert_held(&rdata
->rp_mutex
);
543 fc_rport_state_enter(rdata
, RPORT_ST_READY
);
545 FC_RPORT_DBG(rdata
, "Port is Ready\n");
547 kref_get(&rdata
->kref
);
548 if (rdata
->event
== RPORT_EV_NONE
&&
549 !queue_work(rport_event_queue
, &rdata
->event_work
))
550 kref_put(&rdata
->kref
, fc_rport_destroy
);
552 rdata
->event
= RPORT_EV_READY
;
556 * fc_rport_timeout() - Handler for the retry_work timer
557 * @work: Handle to the remote port that has timed out
559 * Locking Note: Called without the rport lock held. This
560 * function will hold the rport lock, call an _enter_*
561 * function and then unlock the rport.
563 * Reference counting: Drops kref on return.
565 static void fc_rport_timeout(struct work_struct
*work
)
567 struct fc_rport_priv
*rdata
=
568 container_of(work
, struct fc_rport_priv
, retry_work
.work
);
570 mutex_lock(&rdata
->rp_mutex
);
571 FC_RPORT_DBG(rdata
, "Port timeout, state %s\n", fc_rport_state(rdata
));
573 switch (rdata
->rp_state
) {
575 fc_rport_enter_flogi(rdata
);
578 fc_rport_enter_plogi(rdata
);
581 fc_rport_enter_prli(rdata
);
584 fc_rport_enter_rtv(rdata
);
587 fc_rport_enter_adisc(rdata
);
589 case RPORT_ST_PLOGI_WAIT
:
592 case RPORT_ST_DELETE
:
596 mutex_unlock(&rdata
->rp_mutex
);
597 kref_put(&rdata
->kref
, fc_rport_destroy
);
601 * fc_rport_error() - Error handler, called once retries have been exhausted
602 * @rdata: The remote port the error is happened on
603 * @err: The error code
605 * Reference counting: does not modify kref
607 static void fc_rport_error(struct fc_rport_priv
*rdata
, int err
)
609 struct fc_lport
*lport
= rdata
->local_port
;
611 lockdep_assert_held(&rdata
->rp_mutex
);
613 FC_RPORT_DBG(rdata
, "Error %d in state %s, retries %d\n",
614 -err
, fc_rport_state(rdata
), rdata
->retries
);
616 switch (rdata
->rp_state
) {
618 rdata
->flags
&= ~FC_RP_STARTED
;
619 fc_rport_enter_delete(rdata
, RPORT_EV_FAILED
);
622 if (lport
->point_to_multipoint
) {
623 rdata
->flags
&= ~FC_RP_STARTED
;
624 fc_rport_enter_delete(rdata
, RPORT_EV_FAILED
);
626 fc_rport_enter_logo(rdata
);
629 fc_rport_enter_ready(rdata
);
633 fc_rport_enter_logo(rdata
);
635 case RPORT_ST_PLOGI_WAIT
:
636 case RPORT_ST_DELETE
:
644 * fc_rport_error_retry() - Handler for remote port state retries
645 * @rdata: The remote port whose state is to be retried
646 * @err: The error code
648 * If the error was an exchange timeout retry immediately,
649 * otherwise wait for E_D_TOV.
651 * Reference counting: increments kref when scheduling retry_work
653 static void fc_rport_error_retry(struct fc_rport_priv
*rdata
, int err
)
655 unsigned long delay
= msecs_to_jiffies(rdata
->e_d_tov
);
657 lockdep_assert_held(&rdata
->rp_mutex
);
659 /* make sure this isn't an FC_EX_CLOSED error, never retry those */
660 if (err
== -FC_EX_CLOSED
)
663 if (rdata
->retries
< rdata
->local_port
->max_rport_retry_count
) {
664 FC_RPORT_DBG(rdata
, "Error %d in state %s, retrying\n",
665 err
, fc_rport_state(rdata
));
667 /* no additional delay on exchange timeouts */
668 if (err
== -FC_EX_TIMEOUT
)
670 kref_get(&rdata
->kref
);
671 if (!schedule_delayed_work(&rdata
->retry_work
, delay
))
672 kref_put(&rdata
->kref
, fc_rport_destroy
);
677 fc_rport_error(rdata
, err
);
681 * fc_rport_login_complete() - Handle parameters and completion of p-mp login.
682 * @rdata: The remote port which we logged into or which logged into us.
683 * @fp: The FLOGI or PLOGI request or response frame
685 * Returns non-zero error if a problem is detected with the frame.
686 * Does not free the frame.
688 * This is only used in point-to-multipoint mode for FIP currently.
690 static int fc_rport_login_complete(struct fc_rport_priv
*rdata
,
693 struct fc_lport
*lport
= rdata
->local_port
;
694 struct fc_els_flogi
*flogi
;
695 unsigned int e_d_tov
;
698 flogi
= fc_frame_payload_get(fp
, sizeof(*flogi
));
702 csp_flags
= ntohs(flogi
->fl_csp
.sp_features
);
704 if (fc_frame_payload_op(fp
) == ELS_FLOGI
) {
705 if (csp_flags
& FC_SP_FT_FPORT
) {
706 FC_RPORT_DBG(rdata
, "Fabric bit set in FLOGI\n");
712 * E_D_TOV is not valid on an incoming FLOGI request.
714 e_d_tov
= ntohl(flogi
->fl_csp
.sp_e_d_tov
);
715 if (csp_flags
& FC_SP_FT_EDTR
)
717 if (e_d_tov
> rdata
->e_d_tov
)
718 rdata
->e_d_tov
= e_d_tov
;
720 rdata
->maxframe_size
= fc_plogi_get_maxframe(flogi
, lport
->mfs
);
725 * fc_rport_flogi_resp() - Handle response to FLOGI request for p-mp mode
726 * @sp: The sequence that the FLOGI was on
727 * @fp: The FLOGI response frame
728 * @rp_arg: The remote port that received the FLOGI response
730 static void fc_rport_flogi_resp(struct fc_seq
*sp
, struct fc_frame
*fp
,
733 struct fc_rport_priv
*rdata
= rp_arg
;
734 struct fc_lport
*lport
= rdata
->local_port
;
735 struct fc_els_flogi
*flogi
;
736 unsigned int r_a_tov
;
740 FC_RPORT_DBG(rdata
, "Received a FLOGI %s\n",
741 IS_ERR(fp
) ? "error" : fc_els_resp_type(fp
));
743 if (fp
== ERR_PTR(-FC_EX_CLOSED
))
746 mutex_lock(&rdata
->rp_mutex
);
748 if (rdata
->rp_state
!= RPORT_ST_FLOGI
) {
749 FC_RPORT_DBG(rdata
, "Received a FLOGI response, but in state "
750 "%s\n", fc_rport_state(rdata
));
757 fc_rport_error(rdata
, PTR_ERR(fp
));
760 opcode
= fc_frame_payload_op(fp
);
761 if (opcode
== ELS_LS_RJT
) {
762 struct fc_els_ls_rjt
*rjt
;
764 rjt
= fc_frame_payload_get(fp
, sizeof(*rjt
));
765 FC_RPORT_DBG(rdata
, "FLOGI ELS rejected, reason %x expl %x\n",
766 rjt
->er_reason
, rjt
->er_explan
);
767 err
= -FC_EX_ELS_RJT
;
769 } else if (opcode
!= ELS_LS_ACC
) {
770 FC_RPORT_DBG(rdata
, "FLOGI ELS invalid opcode %x\n", opcode
);
771 err
= -FC_EX_ELS_RJT
;
774 if (fc_rport_login_complete(rdata
, fp
)) {
775 FC_RPORT_DBG(rdata
, "FLOGI failed, no login\n");
776 err
= -FC_EX_INV_LOGIN
;
780 flogi
= fc_frame_payload_get(fp
, sizeof(*flogi
));
782 err
= -FC_EX_ALLOC_ERR
;
785 r_a_tov
= ntohl(flogi
->fl_csp
.sp_r_a_tov
);
786 if (r_a_tov
> rdata
->r_a_tov
)
787 rdata
->r_a_tov
= r_a_tov
;
789 if (rdata
->ids
.port_name
< lport
->wwpn
)
790 fc_rport_enter_plogi(rdata
);
792 fc_rport_state_enter(rdata
, RPORT_ST_PLOGI_WAIT
);
796 mutex_unlock(&rdata
->rp_mutex
);
798 kref_put(&rdata
->kref
, fc_rport_destroy
);
801 FC_RPORT_DBG(rdata
, "Bad FLOGI response\n");
802 fc_rport_error_retry(rdata
, err
);
807 * fc_rport_enter_flogi() - Send a FLOGI request to the remote port for p-mp
808 * @rdata: The remote port to send a FLOGI to
810 * Reference counting: increments kref when sending ELS
812 static void fc_rport_enter_flogi(struct fc_rport_priv
*rdata
)
814 struct fc_lport
*lport
= rdata
->local_port
;
817 lockdep_assert_held(&rdata
->rp_mutex
);
819 if (!lport
->point_to_multipoint
)
820 return fc_rport_enter_plogi(rdata
);
822 FC_RPORT_DBG(rdata
, "Entered FLOGI state from %s state\n",
823 fc_rport_state(rdata
));
825 fc_rport_state_enter(rdata
, RPORT_ST_FLOGI
);
827 fp
= fc_frame_alloc(lport
, sizeof(struct fc_els_flogi
));
829 return fc_rport_error_retry(rdata
, -FC_EX_ALLOC_ERR
);
831 kref_get(&rdata
->kref
);
832 if (!lport
->tt
.elsct_send(lport
, rdata
->ids
.port_id
, fp
, ELS_FLOGI
,
833 fc_rport_flogi_resp
, rdata
,
834 2 * lport
->r_a_tov
)) {
835 fc_rport_error_retry(rdata
, -FC_EX_XMIT_ERR
);
836 kref_put(&rdata
->kref
, fc_rport_destroy
);
841 * fc_rport_recv_flogi_req() - Handle Fabric Login (FLOGI) request in p-mp mode
842 * @lport: The local port that received the PLOGI request
843 * @rx_fp: The PLOGI request frame
845 * Reference counting: drops kref on return
847 static void fc_rport_recv_flogi_req(struct fc_lport
*lport
,
848 struct fc_frame
*rx_fp
)
850 struct fc_els_flogi
*flp
;
851 struct fc_rport_priv
*rdata
;
852 struct fc_frame
*fp
= rx_fp
;
853 struct fc_seq_els_data rjt_data
;
856 sid
= fc_frame_sid(fp
);
858 FC_RPORT_ID_DBG(lport
, sid
, "Received FLOGI request\n");
860 if (!lport
->point_to_multipoint
) {
861 rjt_data
.reason
= ELS_RJT_UNSUP
;
862 rjt_data
.explan
= ELS_EXPL_NONE
;
866 flp
= fc_frame_payload_get(fp
, sizeof(*flp
));
868 rjt_data
.reason
= ELS_RJT_LOGIC
;
869 rjt_data
.explan
= ELS_EXPL_INV_LEN
;
873 rdata
= fc_rport_lookup(lport
, sid
);
875 rjt_data
.reason
= ELS_RJT_FIP
;
876 rjt_data
.explan
= ELS_EXPL_NOT_NEIGHBOR
;
879 mutex_lock(&rdata
->rp_mutex
);
881 FC_RPORT_DBG(rdata
, "Received FLOGI in %s state\n",
882 fc_rport_state(rdata
));
884 switch (rdata
->rp_state
) {
887 * If received the FLOGI request on RPORT which is INIT state
888 * (means not transition to FLOGI either fc_rport timeout
889 * function didn;t trigger or this end hasn;t received
890 * beacon yet from other end. In that case only, allow RPORT
891 * state machine to continue, otherwise fall through which
892 * causes the code to send reject response.
893 * NOTE; Not checking for FIP->state such as VNMP_UP or
894 * VNMP_CLAIM because if FIP state is not one of those,
895 * RPORT wouldn;t have created and 'rport_lookup' would have
896 * failed anyway in that case.
899 case RPORT_ST_DELETE
:
900 mutex_unlock(&rdata
->rp_mutex
);
901 rjt_data
.reason
= ELS_RJT_FIP
;
902 rjt_data
.explan
= ELS_EXPL_NOT_NEIGHBOR
;
905 case RPORT_ST_PLOGI_WAIT
:
913 * Set the remote port to be deleted and to then restart.
914 * This queues work to be sure exchanges are reset.
916 fc_rport_enter_delete(rdata
, RPORT_EV_LOGO
);
917 mutex_unlock(&rdata
->rp_mutex
);
918 rjt_data
.reason
= ELS_RJT_BUSY
;
919 rjt_data
.explan
= ELS_EXPL_NONE
;
922 if (fc_rport_login_complete(rdata
, fp
)) {
923 mutex_unlock(&rdata
->rp_mutex
);
924 rjt_data
.reason
= ELS_RJT_LOGIC
;
925 rjt_data
.explan
= ELS_EXPL_NONE
;
929 fp
= fc_frame_alloc(lport
, sizeof(*flp
));
933 fc_flogi_fill(lport
, fp
);
934 flp
= fc_frame_payload_get(fp
, sizeof(*flp
));
935 flp
->fl_cmd
= ELS_LS_ACC
;
937 fc_fill_reply_hdr(fp
, rx_fp
, FC_RCTL_ELS_REP
, 0);
938 lport
->tt
.frame_send(lport
, fp
);
941 * Do not proceed with the state machine if our
942 * FLOGI has crossed with an FLOGI from the
943 * remote port; wait for the FLOGI response instead.
945 if (rdata
->rp_state
!= RPORT_ST_FLOGI
) {
946 if (rdata
->ids
.port_name
< lport
->wwpn
)
947 fc_rport_enter_plogi(rdata
);
949 fc_rport_state_enter(rdata
, RPORT_ST_PLOGI_WAIT
);
952 mutex_unlock(&rdata
->rp_mutex
);
953 kref_put(&rdata
->kref
, fc_rport_destroy
);
954 fc_frame_free(rx_fp
);
958 kref_put(&rdata
->kref
, fc_rport_destroy
);
960 fc_seq_els_rsp_send(rx_fp
, ELS_LS_RJT
, &rjt_data
);
961 fc_frame_free(rx_fp
);
965 * fc_rport_plogi_resp() - Handler for ELS PLOGI responses
966 * @sp: The sequence the PLOGI is on
967 * @fp: The PLOGI response frame
968 * @rdata_arg: The remote port that sent the PLOGI response
970 * Locking Note: This function will be called without the rport lock
971 * held, but it will lock, call an _enter_* function or fc_rport_error
972 * and then unlock the rport.
974 static void fc_rport_plogi_resp(struct fc_seq
*sp
, struct fc_frame
*fp
,
977 struct fc_rport_priv
*rdata
= rdata_arg
;
978 struct fc_lport
*lport
= rdata
->local_port
;
979 struct fc_els_flogi
*plp
= NULL
;
984 FC_RPORT_DBG(rdata
, "Received a PLOGI %s\n", fc_els_resp_type(fp
));
986 if (fp
== ERR_PTR(-FC_EX_CLOSED
))
989 mutex_lock(&rdata
->rp_mutex
);
991 if (rdata
->rp_state
!= RPORT_ST_PLOGI
) {
992 FC_RPORT_DBG(rdata
, "Received a PLOGI response, but in state "
993 "%s\n", fc_rport_state(rdata
));
1000 fc_rport_error_retry(rdata
, PTR_ERR(fp
));
1004 op
= fc_frame_payload_op(fp
);
1005 if (op
== ELS_LS_ACC
&&
1006 (plp
= fc_frame_payload_get(fp
, sizeof(*plp
))) != NULL
) {
1007 rdata
->ids
.port_name
= get_unaligned_be64(&plp
->fl_wwpn
);
1008 rdata
->ids
.node_name
= get_unaligned_be64(&plp
->fl_wwnn
);
1010 /* save plogi response sp_features for further reference */
1011 rdata
->sp_features
= ntohs(plp
->fl_csp
.sp_features
);
1013 if (lport
->point_to_multipoint
)
1014 fc_rport_login_complete(rdata
, fp
);
1015 csp_seq
= ntohs(plp
->fl_csp
.sp_tot_seq
);
1016 cssp_seq
= ntohs(plp
->fl_cssp
[3 - 1].cp_con_seq
);
1017 if (cssp_seq
< csp_seq
)
1019 rdata
->max_seq
= csp_seq
;
1020 rdata
->maxframe_size
= fc_plogi_get_maxframe(plp
, lport
->mfs
);
1021 fc_rport_enter_prli(rdata
);
1023 struct fc_els_ls_rjt
*rjt
;
1025 rjt
= fc_frame_payload_get(fp
, sizeof(*rjt
));
1027 FC_RPORT_DBG(rdata
, "PLOGI bad response\n");
1029 FC_RPORT_DBG(rdata
, "PLOGI ELS rejected, reason %x expl %x\n",
1030 rjt
->er_reason
, rjt
->er_explan
);
1031 fc_rport_error_retry(rdata
, -FC_EX_ELS_RJT
);
1036 mutex_unlock(&rdata
->rp_mutex
);
1038 kref_put(&rdata
->kref
, fc_rport_destroy
);
1042 fc_rport_compatible_roles(struct fc_lport
*lport
, struct fc_rport_priv
*rdata
)
1044 if (rdata
->ids
.roles
== FC_PORT_ROLE_UNKNOWN
)
1046 if ((rdata
->ids
.roles
& FC_PORT_ROLE_FCP_TARGET
) &&
1047 (lport
->service_params
& FCP_SPPF_INIT_FCN
))
1049 if ((rdata
->ids
.roles
& FC_PORT_ROLE_FCP_INITIATOR
) &&
1050 (lport
->service_params
& FCP_SPPF_TARG_FCN
))
1056 * fc_rport_enter_plogi() - Send Port Login (PLOGI) request
1057 * @rdata: The remote port to send a PLOGI to
1059 * Reference counting: increments kref when sending ELS
1061 static void fc_rport_enter_plogi(struct fc_rport_priv
*rdata
)
1063 struct fc_lport
*lport
= rdata
->local_port
;
1064 struct fc_frame
*fp
;
1066 lockdep_assert_held(&rdata
->rp_mutex
);
1068 if (!fc_rport_compatible_roles(lport
, rdata
)) {
1069 FC_RPORT_DBG(rdata
, "PLOGI suppressed for incompatible role\n");
1070 fc_rport_state_enter(rdata
, RPORT_ST_PLOGI_WAIT
);
1074 FC_RPORT_DBG(rdata
, "Port entered PLOGI state from %s state\n",
1075 fc_rport_state(rdata
));
1077 fc_rport_state_enter(rdata
, RPORT_ST_PLOGI
);
1079 rdata
->maxframe_size
= FC_MIN_MAX_PAYLOAD
;
1080 fp
= fc_frame_alloc(lport
, sizeof(struct fc_els_flogi
));
1082 FC_RPORT_DBG(rdata
, "%s frame alloc failed\n", __func__
);
1083 fc_rport_error_retry(rdata
, -FC_EX_ALLOC_ERR
);
1086 rdata
->e_d_tov
= lport
->e_d_tov
;
1088 kref_get(&rdata
->kref
);
1089 if (!lport
->tt
.elsct_send(lport
, rdata
->ids
.port_id
, fp
, ELS_PLOGI
,
1090 fc_rport_plogi_resp
, rdata
,
1091 2 * lport
->r_a_tov
)) {
1092 fc_rport_error_retry(rdata
, -FC_EX_XMIT_ERR
);
1093 kref_put(&rdata
->kref
, fc_rport_destroy
);
1098 * fc_rport_prli_resp() - Process Login (PRLI) response handler
1099 * @sp: The sequence the PRLI response was on
1100 * @fp: The PRLI response frame
1101 * @rdata_arg: The remote port that sent the PRLI response
1103 * Locking Note: This function will be called without the rport lock
1104 * held, but it will lock, call an _enter_* function or fc_rport_error
1105 * and then unlock the rport.
1107 static void fc_rport_prli_resp(struct fc_seq
*sp
, struct fc_frame
*fp
,
1110 struct fc_rport_priv
*rdata
= rdata_arg
;
1112 struct fc_els_prli prli
;
1113 struct fc_els_spp spp
;
1115 struct fc_els_spp temp_spp
;
1116 struct fc_els_ls_rjt
*rjt
;
1117 struct fc4_prov
*prov
;
1118 u32 roles
= FC_RPORT_ROLE_UNKNOWN
;
1121 enum fc_els_spp_resp resp_code
;
1123 FC_RPORT_DBG(rdata
, "Received a PRLI %s\n", fc_els_resp_type(fp
));
1125 if (fp
== ERR_PTR(-FC_EX_CLOSED
))
1128 mutex_lock(&rdata
->rp_mutex
);
1130 if (rdata
->rp_state
!= RPORT_ST_PRLI
) {
1131 FC_RPORT_DBG(rdata
, "Received a PRLI response, but in state "
1132 "%s\n", fc_rport_state(rdata
));
1139 fc_rport_error_retry(rdata
, PTR_ERR(fp
));
1143 /* reinitialize remote port roles */
1144 rdata
->ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
1146 op
= fc_frame_payload_op(fp
);
1147 if (op
== ELS_LS_ACC
) {
1148 pp
= fc_frame_payload_get(fp
, sizeof(*pp
));
1150 fc_rport_error_retry(rdata
, -FC_EX_SEQ_ERR
);
1154 resp_code
= (pp
->spp
.spp_flags
& FC_SPP_RESP_MASK
);
1155 FC_RPORT_DBG(rdata
, "PRLI spp_flags = 0x%x spp_type 0x%x\n",
1156 pp
->spp
.spp_flags
, pp
->spp
.spp_type
);
1157 rdata
->spp_type
= pp
->spp
.spp_type
;
1158 if (resp_code
!= FC_SPP_RESP_ACK
) {
1159 if (resp_code
== FC_SPP_RESP_CONF
)
1160 fc_rport_error(rdata
, -FC_EX_SEQ_ERR
);
1162 fc_rport_error_retry(rdata
, -FC_EX_SEQ_ERR
);
1165 if (pp
->prli
.prli_spp_len
< sizeof(pp
->spp
)) {
1166 fc_rport_error_retry(rdata
, -FC_EX_SEQ_ERR
);
1170 fcp_parm
= ntohl(pp
->spp
.spp_params
);
1171 if (fcp_parm
& FCP_SPPF_RETRY
)
1172 rdata
->flags
|= FC_RP_FLAGS_RETRY
;
1173 if (fcp_parm
& FCP_SPPF_CONF_COMPL
)
1174 rdata
->flags
|= FC_RP_FLAGS_CONF_REQ
;
1177 * Call prli provider if we should act as a target
1179 prov
= fc_passive_prov
[rdata
->spp_type
];
1181 memset(&temp_spp
, 0, sizeof(temp_spp
));
1182 prov
->prli(rdata
, pp
->prli
.prli_spp_len
,
1183 &pp
->spp
, &temp_spp
);
1186 * Check if the image pair could be established
1188 if (rdata
->spp_type
!= FC_TYPE_FCP
||
1189 !(pp
->spp
.spp_flags
& FC_SPP_EST_IMG_PAIR
)) {
1191 * Nope; we can't use this port as a target.
1193 fcp_parm
&= ~FCP_SPPF_TARG_FCN
;
1195 rdata
->supported_classes
= FC_COS_CLASS3
;
1196 if (fcp_parm
& FCP_SPPF_INIT_FCN
)
1197 roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
1198 if (fcp_parm
& FCP_SPPF_TARG_FCN
)
1199 roles
|= FC_RPORT_ROLE_FCP_TARGET
;
1201 rdata
->ids
.roles
= roles
;
1202 fc_rport_enter_rtv(rdata
);
1205 rjt
= fc_frame_payload_get(fp
, sizeof(*rjt
));
1207 FC_RPORT_DBG(rdata
, "PRLI bad response\n");
1209 FC_RPORT_DBG(rdata
, "PRLI ELS rejected, reason %x expl %x\n",
1210 rjt
->er_reason
, rjt
->er_explan
);
1211 fc_rport_error_retry(rdata
, FC_EX_ELS_RJT
);
1217 mutex_unlock(&rdata
->rp_mutex
);
1219 kref_put(&rdata
->kref
, fc_rport_destroy
);
1223 * fc_rport_enter_prli() - Send Process Login (PRLI) request
1224 * @rdata: The remote port to send the PRLI request to
1226 * Reference counting: increments kref when sending ELS
1228 static void fc_rport_enter_prli(struct fc_rport_priv
*rdata
)
1230 struct fc_lport
*lport
= rdata
->local_port
;
1232 struct fc_els_prli prli
;
1233 struct fc_els_spp spp
;
1235 struct fc_frame
*fp
;
1236 struct fc4_prov
*prov
;
1238 lockdep_assert_held(&rdata
->rp_mutex
);
1241 * If the rport is one of the well known addresses
1242 * we skip PRLI and RTV and go straight to READY.
1244 if (rdata
->ids
.port_id
>= FC_FID_DOM_MGR
) {
1245 fc_rport_enter_ready(rdata
);
1250 * And if the local port does not support the initiator function
1251 * there's no need to send a PRLI, either.
1253 if (!(lport
->service_params
& FCP_SPPF_INIT_FCN
)) {
1254 fc_rport_enter_ready(rdata
);
1258 FC_RPORT_DBG(rdata
, "Port entered PRLI state from %s state\n",
1259 fc_rport_state(rdata
));
1261 fc_rport_state_enter(rdata
, RPORT_ST_PRLI
);
1263 fp
= fc_frame_alloc(lport
, sizeof(*pp
));
1265 fc_rport_error_retry(rdata
, -FC_EX_ALLOC_ERR
);
1269 fc_prli_fill(lport
, fp
);
1271 prov
= fc_passive_prov
[FC_TYPE_FCP
];
1273 pp
= fc_frame_payload_get(fp
, sizeof(*pp
));
1274 prov
->prli(rdata
, sizeof(pp
->spp
), NULL
, &pp
->spp
);
1277 fc_fill_fc_hdr(fp
, FC_RCTL_ELS_REQ
, rdata
->ids
.port_id
,
1278 fc_host_port_id(lport
->host
), FC_TYPE_ELS
,
1279 FC_FC_FIRST_SEQ
| FC_FC_END_SEQ
| FC_FC_SEQ_INIT
, 0);
1281 kref_get(&rdata
->kref
);
1282 if (!fc_exch_seq_send(lport
, fp
, fc_rport_prli_resp
,
1283 NULL
, rdata
, 2 * lport
->r_a_tov
)) {
1284 fc_rport_error_retry(rdata
, -FC_EX_XMIT_ERR
);
1285 kref_put(&rdata
->kref
, fc_rport_destroy
);
1290 * fc_rport_rtv_resp() - Handler for Request Timeout Value (RTV) responses
1291 * @sp: The sequence the RTV was on
1292 * @fp: The RTV response frame
1293 * @rdata_arg: The remote port that sent the RTV response
1295 * Many targets don't seem to support this.
1297 * Locking Note: This function will be called without the rport lock
1298 * held, but it will lock, call an _enter_* function or fc_rport_error
1299 * and then unlock the rport.
1301 static void fc_rport_rtv_resp(struct fc_seq
*sp
, struct fc_frame
*fp
,
1304 struct fc_rport_priv
*rdata
= rdata_arg
;
1307 FC_RPORT_DBG(rdata
, "Received a RTV %s\n", fc_els_resp_type(fp
));
1309 if (fp
== ERR_PTR(-FC_EX_CLOSED
))
1312 mutex_lock(&rdata
->rp_mutex
);
1314 if (rdata
->rp_state
!= RPORT_ST_RTV
) {
1315 FC_RPORT_DBG(rdata
, "Received a RTV response, but in state "
1316 "%s\n", fc_rport_state(rdata
));
1323 fc_rport_error(rdata
, PTR_ERR(fp
));
1327 op
= fc_frame_payload_op(fp
);
1328 if (op
== ELS_LS_ACC
) {
1329 struct fc_els_rtv_acc
*rtv
;
1333 rtv
= fc_frame_payload_get(fp
, sizeof(*rtv
));
1335 toq
= ntohl(rtv
->rtv_toq
);
1336 tov
= ntohl(rtv
->rtv_r_a_tov
);
1339 if (tov
> rdata
->r_a_tov
)
1340 rdata
->r_a_tov
= tov
;
1341 tov
= ntohl(rtv
->rtv_e_d_tov
);
1342 if (toq
& FC_ELS_RTV_EDRES
)
1346 if (tov
> rdata
->e_d_tov
)
1347 rdata
->e_d_tov
= tov
;
1351 fc_rport_enter_ready(rdata
);
1356 mutex_unlock(&rdata
->rp_mutex
);
1358 kref_put(&rdata
->kref
, fc_rport_destroy
);
1362 * fc_rport_enter_rtv() - Send Request Timeout Value (RTV) request
1363 * @rdata: The remote port to send the RTV request to
1365 * Reference counting: increments kref when sending ELS
1367 static void fc_rport_enter_rtv(struct fc_rport_priv
*rdata
)
1369 struct fc_frame
*fp
;
1370 struct fc_lport
*lport
= rdata
->local_port
;
1372 lockdep_assert_held(&rdata
->rp_mutex
);
1374 FC_RPORT_DBG(rdata
, "Port entered RTV state from %s state\n",
1375 fc_rport_state(rdata
));
1377 fc_rport_state_enter(rdata
, RPORT_ST_RTV
);
1379 fp
= fc_frame_alloc(lport
, sizeof(struct fc_els_rtv
));
1381 fc_rport_error_retry(rdata
, -FC_EX_ALLOC_ERR
);
1385 kref_get(&rdata
->kref
);
1386 if (!lport
->tt
.elsct_send(lport
, rdata
->ids
.port_id
, fp
, ELS_RTV
,
1387 fc_rport_rtv_resp
, rdata
,
1388 2 * lport
->r_a_tov
)) {
1389 fc_rport_error_retry(rdata
, -FC_EX_XMIT_ERR
);
1390 kref_put(&rdata
->kref
, fc_rport_destroy
);
1395 * fc_rport_recv_rtv_req() - Handler for Read Timeout Value (RTV) requests
1396 * @rdata: The remote port that sent the RTV request
1397 * @in_fp: The RTV request frame
1399 static void fc_rport_recv_rtv_req(struct fc_rport_priv
*rdata
,
1400 struct fc_frame
*in_fp
)
1402 struct fc_lport
*lport
= rdata
->local_port
;
1403 struct fc_frame
*fp
;
1404 struct fc_els_rtv_acc
*rtv
;
1405 struct fc_seq_els_data rjt_data
;
1407 lockdep_assert_held(&rdata
->rp_mutex
);
1408 lockdep_assert_held(&lport
->lp_mutex
);
1410 FC_RPORT_DBG(rdata
, "Received RTV request\n");
1412 fp
= fc_frame_alloc(lport
, sizeof(*rtv
));
1414 rjt_data
.reason
= ELS_RJT_UNAB
;
1415 rjt_data
.explan
= ELS_EXPL_INSUF_RES
;
1416 fc_seq_els_rsp_send(in_fp
, ELS_LS_RJT
, &rjt_data
);
1419 rtv
= fc_frame_payload_get(fp
, sizeof(*rtv
));
1420 rtv
->rtv_cmd
= ELS_LS_ACC
;
1421 rtv
->rtv_r_a_tov
= htonl(lport
->r_a_tov
);
1422 rtv
->rtv_e_d_tov
= htonl(lport
->e_d_tov
);
1424 fc_fill_reply_hdr(fp
, in_fp
, FC_RCTL_ELS_REP
, 0);
1425 lport
->tt
.frame_send(lport
, fp
);
1427 fc_frame_free(in_fp
);
1431 * fc_rport_logo_resp() - Handler for logout (LOGO) responses
1432 * @sp: The sequence the LOGO was on
1433 * @fp: The LOGO response frame
1434 * @lport_arg: The local port
1436 static void fc_rport_logo_resp(struct fc_seq
*sp
, struct fc_frame
*fp
,
1439 struct fc_rport_priv
*rdata
= rdata_arg
;
1440 struct fc_lport
*lport
= rdata
->local_port
;
1442 FC_RPORT_ID_DBG(lport
, fc_seq_exch(sp
)->did
,
1443 "Received a LOGO %s\n", fc_els_resp_type(fp
));
1446 kref_put(&rdata
->kref
, fc_rport_destroy
);
1450 * fc_rport_enter_logo() - Send a logout (LOGO) request
1451 * @rdata: The remote port to send the LOGO request to
1453 * Reference counting: increments kref when sending ELS
1455 static void fc_rport_enter_logo(struct fc_rport_priv
*rdata
)
1457 struct fc_lport
*lport
= rdata
->local_port
;
1458 struct fc_frame
*fp
;
1460 lockdep_assert_held(&rdata
->rp_mutex
);
1462 FC_RPORT_DBG(rdata
, "Port sending LOGO from %s state\n",
1463 fc_rport_state(rdata
));
1465 fp
= fc_frame_alloc(lport
, sizeof(struct fc_els_logo
));
1468 kref_get(&rdata
->kref
);
1469 if (!lport
->tt
.elsct_send(lport
, rdata
->ids
.port_id
, fp
, ELS_LOGO
,
1470 fc_rport_logo_resp
, rdata
, 0))
1471 kref_put(&rdata
->kref
, fc_rport_destroy
);
1475 * fc_rport_els_adisc_resp() - Handler for Address Discovery (ADISC) responses
1476 * @sp: The sequence the ADISC response was on
1477 * @fp: The ADISC response frame
1478 * @rdata_arg: The remote port that sent the ADISC response
1480 * Locking Note: This function will be called without the rport lock
1481 * held, but it will lock, call an _enter_* function or fc_rport_error
1482 * and then unlock the rport.
1484 static void fc_rport_adisc_resp(struct fc_seq
*sp
, struct fc_frame
*fp
,
1487 struct fc_rport_priv
*rdata
= rdata_arg
;
1488 struct fc_els_adisc
*adisc
;
1491 FC_RPORT_DBG(rdata
, "Received a ADISC response\n");
1493 if (fp
== ERR_PTR(-FC_EX_CLOSED
))
1496 mutex_lock(&rdata
->rp_mutex
);
1498 if (rdata
->rp_state
!= RPORT_ST_ADISC
) {
1499 FC_RPORT_DBG(rdata
, "Received a ADISC resp but in state %s\n",
1500 fc_rport_state(rdata
));
1507 fc_rport_error(rdata
, PTR_ERR(fp
));
1512 * If address verification failed. Consider us logged out of the rport.
1513 * Since the rport is still in discovery, we want to be
1514 * logged in, so go to PLOGI state. Otherwise, go back to READY.
1516 op
= fc_frame_payload_op(fp
);
1517 adisc
= fc_frame_payload_get(fp
, sizeof(*adisc
));
1518 if (op
!= ELS_LS_ACC
|| !adisc
||
1519 ntoh24(adisc
->adisc_port_id
) != rdata
->ids
.port_id
||
1520 get_unaligned_be64(&adisc
->adisc_wwpn
) != rdata
->ids
.port_name
||
1521 get_unaligned_be64(&adisc
->adisc_wwnn
) != rdata
->ids
.node_name
) {
1522 FC_RPORT_DBG(rdata
, "ADISC error or mismatch\n");
1523 fc_rport_enter_flogi(rdata
);
1525 FC_RPORT_DBG(rdata
, "ADISC OK\n");
1526 fc_rport_enter_ready(rdata
);
1531 mutex_unlock(&rdata
->rp_mutex
);
1533 kref_put(&rdata
->kref
, fc_rport_destroy
);
1537 * fc_rport_enter_adisc() - Send Address Discover (ADISC) request
1538 * @rdata: The remote port to send the ADISC request to
1540 * Reference counting: increments kref when sending ELS
1542 static void fc_rport_enter_adisc(struct fc_rport_priv
*rdata
)
1544 struct fc_lport
*lport
= rdata
->local_port
;
1545 struct fc_frame
*fp
;
1547 lockdep_assert_held(&rdata
->rp_mutex
);
1549 FC_RPORT_DBG(rdata
, "sending ADISC from %s state\n",
1550 fc_rport_state(rdata
));
1552 fc_rport_state_enter(rdata
, RPORT_ST_ADISC
);
1554 fp
= fc_frame_alloc(lport
, sizeof(struct fc_els_adisc
));
1556 fc_rport_error_retry(rdata
, -FC_EX_ALLOC_ERR
);
1559 kref_get(&rdata
->kref
);
1560 if (!lport
->tt
.elsct_send(lport
, rdata
->ids
.port_id
, fp
, ELS_ADISC
,
1561 fc_rport_adisc_resp
, rdata
,
1562 2 * lport
->r_a_tov
)) {
1563 fc_rport_error_retry(rdata
, -FC_EX_XMIT_ERR
);
1564 kref_put(&rdata
->kref
, fc_rport_destroy
);
1569 * fc_rport_recv_adisc_req() - Handler for Address Discovery (ADISC) requests
1570 * @rdata: The remote port that sent the ADISC request
1571 * @in_fp: The ADISC request frame
1573 static void fc_rport_recv_adisc_req(struct fc_rport_priv
*rdata
,
1574 struct fc_frame
*in_fp
)
1576 struct fc_lport
*lport
= rdata
->local_port
;
1577 struct fc_frame
*fp
;
1578 struct fc_els_adisc
*adisc
;
1579 struct fc_seq_els_data rjt_data
;
1581 lockdep_assert_held(&rdata
->rp_mutex
);
1582 lockdep_assert_held(&lport
->lp_mutex
);
1584 FC_RPORT_DBG(rdata
, "Received ADISC request\n");
1586 adisc
= fc_frame_payload_get(in_fp
, sizeof(*adisc
));
1588 rjt_data
.reason
= ELS_RJT_PROT
;
1589 rjt_data
.explan
= ELS_EXPL_INV_LEN
;
1590 fc_seq_els_rsp_send(in_fp
, ELS_LS_RJT
, &rjt_data
);
1594 fp
= fc_frame_alloc(lport
, sizeof(*adisc
));
1597 fc_adisc_fill(lport
, fp
);
1598 adisc
= fc_frame_payload_get(fp
, sizeof(*adisc
));
1599 adisc
->adisc_cmd
= ELS_LS_ACC
;
1600 fc_fill_reply_hdr(fp
, in_fp
, FC_RCTL_ELS_REP
, 0);
1601 lport
->tt
.frame_send(lport
, fp
);
1603 fc_frame_free(in_fp
);
1607 * fc_rport_recv_rls_req() - Handle received Read Link Status request
1608 * @rdata: The remote port that sent the RLS request
1609 * @rx_fp: The PRLI request frame
1611 static void fc_rport_recv_rls_req(struct fc_rport_priv
*rdata
,
1612 struct fc_frame
*rx_fp
)
1615 struct fc_lport
*lport
= rdata
->local_port
;
1616 struct fc_frame
*fp
;
1617 struct fc_els_rls
*rls
;
1618 struct fc_els_rls_resp
*rsp
;
1619 struct fc_els_lesb
*lesb
;
1620 struct fc_seq_els_data rjt_data
;
1621 struct fc_host_statistics
*hst
;
1623 lockdep_assert_held(&rdata
->rp_mutex
);
1625 FC_RPORT_DBG(rdata
, "Received RLS request while in state %s\n",
1626 fc_rport_state(rdata
));
1628 rls
= fc_frame_payload_get(rx_fp
, sizeof(*rls
));
1630 rjt_data
.reason
= ELS_RJT_PROT
;
1631 rjt_data
.explan
= ELS_EXPL_INV_LEN
;
1635 fp
= fc_frame_alloc(lport
, sizeof(*rsp
));
1637 rjt_data
.reason
= ELS_RJT_UNAB
;
1638 rjt_data
.explan
= ELS_EXPL_INSUF_RES
;
1642 rsp
= fc_frame_payload_get(fp
, sizeof(*rsp
));
1643 memset(rsp
, 0, sizeof(*rsp
));
1644 rsp
->rls_cmd
= ELS_LS_ACC
;
1645 lesb
= &rsp
->rls_lesb
;
1646 if (lport
->tt
.get_lesb
) {
1647 /* get LESB from LLD if it supports it */
1648 lport
->tt
.get_lesb(lport
, lesb
);
1650 fc_get_host_stats(lport
->host
);
1651 hst
= &lport
->host_stats
;
1652 lesb
->lesb_link_fail
= htonl(hst
->link_failure_count
);
1653 lesb
->lesb_sync_loss
= htonl(hst
->loss_of_sync_count
);
1654 lesb
->lesb_sig_loss
= htonl(hst
->loss_of_signal_count
);
1655 lesb
->lesb_prim_err
= htonl(hst
->prim_seq_protocol_err_count
);
1656 lesb
->lesb_inv_word
= htonl(hst
->invalid_tx_word_count
);
1657 lesb
->lesb_inv_crc
= htonl(hst
->invalid_crc_count
);
1660 fc_fill_reply_hdr(fp
, rx_fp
, FC_RCTL_ELS_REP
, 0);
1661 lport
->tt
.frame_send(lport
, fp
);
1665 fc_seq_els_rsp_send(rx_fp
, ELS_LS_RJT
, &rjt_data
);
1667 fc_frame_free(rx_fp
);
1671 * fc_rport_recv_els_req() - Handler for validated ELS requests
1672 * @lport: The local port that received the ELS request
1673 * @fp: The ELS request frame
1675 * Handle incoming ELS requests that require port login.
1676 * The ELS opcode has already been validated by the caller.
1678 * Reference counting: does not modify kref
1680 static void fc_rport_recv_els_req(struct fc_lport
*lport
, struct fc_frame
*fp
)
1682 struct fc_rport_priv
*rdata
;
1683 struct fc_seq_els_data els_data
;
1685 lockdep_assert_held(&lport
->lp_mutex
);
1687 rdata
= fc_rport_lookup(lport
, fc_frame_sid(fp
));
1689 FC_RPORT_ID_DBG(lport
, fc_frame_sid(fp
),
1690 "Received ELS 0x%02x from non-logged-in port\n",
1691 fc_frame_payload_op(fp
));
1695 mutex_lock(&rdata
->rp_mutex
);
1697 switch (rdata
->rp_state
) {
1700 case RPORT_ST_READY
:
1701 case RPORT_ST_ADISC
:
1703 case RPORT_ST_PLOGI
:
1704 if (fc_frame_payload_op(fp
) == ELS_PRLI
) {
1705 FC_RPORT_DBG(rdata
, "Reject ELS PRLI "
1706 "while in state %s\n",
1707 fc_rport_state(rdata
));
1708 mutex_unlock(&rdata
->rp_mutex
);
1709 kref_put(&rdata
->kref
, fc_rport_destroy
);
1715 "Reject ELS 0x%02x while in state %s\n",
1716 fc_frame_payload_op(fp
), fc_rport_state(rdata
));
1717 mutex_unlock(&rdata
->rp_mutex
);
1718 kref_put(&rdata
->kref
, fc_rport_destroy
);
1722 switch (fc_frame_payload_op(fp
)) {
1724 fc_rport_recv_prli_req(rdata
, fp
);
1727 fc_rport_recv_prlo_req(rdata
, fp
);
1730 fc_rport_recv_adisc_req(rdata
, fp
);
1733 fc_seq_els_rsp_send(fp
, ELS_RRQ
, NULL
);
1737 fc_seq_els_rsp_send(fp
, ELS_REC
, NULL
);
1741 fc_rport_recv_rls_req(rdata
, fp
);
1744 fc_rport_recv_rtv_req(rdata
, fp
);
1747 fc_frame_free(fp
); /* can't happen */
1751 mutex_unlock(&rdata
->rp_mutex
);
1752 kref_put(&rdata
->kref
, fc_rport_destroy
);
1756 els_data
.reason
= ELS_RJT_UNAB
;
1757 els_data
.explan
= ELS_EXPL_PLOGI_REQD
;
1758 fc_seq_els_rsp_send(fp
, ELS_LS_RJT
, &els_data
);
1763 els_data
.reason
= ELS_RJT_BUSY
;
1764 els_data
.explan
= ELS_EXPL_NONE
;
1765 fc_seq_els_rsp_send(fp
, ELS_LS_RJT
, &els_data
);
1771 * fc_rport_recv_req() - Handler for requests
1772 * @lport: The local port that received the request
1773 * @fp: The request frame
1775 * Reference counting: does not modify kref
1777 void fc_rport_recv_req(struct fc_lport
*lport
, struct fc_frame
*fp
)
1779 struct fc_seq_els_data els_data
;
1781 lockdep_assert_held(&lport
->lp_mutex
);
1784 * Handle FLOGI, PLOGI and LOGO requests separately, since they
1785 * don't require prior login.
1786 * Check for unsupported opcodes first and reject them.
1787 * For some ops, it would be incorrect to reject with "PLOGI required".
1789 switch (fc_frame_payload_op(fp
)) {
1791 fc_rport_recv_flogi_req(lport
, fp
);
1794 fc_rport_recv_plogi_req(lport
, fp
);
1797 fc_rport_recv_logo_req(lport
, fp
);
1806 fc_rport_recv_els_req(lport
, fp
);
1809 els_data
.reason
= ELS_RJT_UNSUP
;
1810 els_data
.explan
= ELS_EXPL_NONE
;
1811 fc_seq_els_rsp_send(fp
, ELS_LS_RJT
, &els_data
);
1816 EXPORT_SYMBOL(fc_rport_recv_req
);
1819 * fc_rport_recv_plogi_req() - Handler for Port Login (PLOGI) requests
1820 * @lport: The local port that received the PLOGI request
1821 * @rx_fp: The PLOGI request frame
1823 * Reference counting: increments kref on return
1825 static void fc_rport_recv_plogi_req(struct fc_lport
*lport
,
1826 struct fc_frame
*rx_fp
)
1828 struct fc_disc
*disc
;
1829 struct fc_rport_priv
*rdata
;
1830 struct fc_frame
*fp
= rx_fp
;
1831 struct fc_els_flogi
*pl
;
1832 struct fc_seq_els_data rjt_data
;
1835 lockdep_assert_held(&lport
->lp_mutex
);
1837 sid
= fc_frame_sid(fp
);
1839 FC_RPORT_ID_DBG(lport
, sid
, "Received PLOGI request\n");
1841 pl
= fc_frame_payload_get(fp
, sizeof(*pl
));
1843 FC_RPORT_ID_DBG(lport
, sid
, "Received PLOGI too short\n");
1844 rjt_data
.reason
= ELS_RJT_PROT
;
1845 rjt_data
.explan
= ELS_EXPL_INV_LEN
;
1849 disc
= &lport
->disc
;
1850 mutex_lock(&disc
->disc_mutex
);
1851 rdata
= fc_rport_create(lport
, sid
);
1853 mutex_unlock(&disc
->disc_mutex
);
1854 rjt_data
.reason
= ELS_RJT_UNAB
;
1855 rjt_data
.explan
= ELS_EXPL_INSUF_RES
;
1859 mutex_lock(&rdata
->rp_mutex
);
1860 mutex_unlock(&disc
->disc_mutex
);
1862 rdata
->ids
.port_name
= get_unaligned_be64(&pl
->fl_wwpn
);
1863 rdata
->ids
.node_name
= get_unaligned_be64(&pl
->fl_wwnn
);
1866 * If the rport was just created, possibly due to the incoming PLOGI,
1867 * set the state appropriately and accept the PLOGI.
1869 * If we had also sent a PLOGI, and if the received PLOGI is from a
1870 * higher WWPN, we accept it, otherwise an LS_RJT is sent with reason
1871 * "command already in progress".
1873 * XXX TBD: If the session was ready before, the PLOGI should result in
1874 * all outstanding exchanges being reset.
1876 switch (rdata
->rp_state
) {
1878 FC_RPORT_DBG(rdata
, "Received PLOGI in INIT state\n");
1880 case RPORT_ST_PLOGI_WAIT
:
1881 FC_RPORT_DBG(rdata
, "Received PLOGI in PLOGI_WAIT state\n");
1883 case RPORT_ST_PLOGI
:
1884 FC_RPORT_DBG(rdata
, "Received PLOGI in PLOGI state\n");
1885 if (rdata
->ids
.port_name
< lport
->wwpn
) {
1886 mutex_unlock(&rdata
->rp_mutex
);
1887 rjt_data
.reason
= ELS_RJT_INPROG
;
1888 rjt_data
.explan
= ELS_EXPL_NONE
;
1894 case RPORT_ST_READY
:
1895 case RPORT_ST_ADISC
:
1896 FC_RPORT_DBG(rdata
, "Received PLOGI in logged-in state %d "
1897 "- ignored for now\n", rdata
->rp_state
);
1898 /* XXX TBD - should reset */
1900 case RPORT_ST_FLOGI
:
1901 case RPORT_ST_DELETE
:
1902 FC_RPORT_DBG(rdata
, "Received PLOGI in state %s - send busy\n",
1903 fc_rport_state(rdata
));
1904 mutex_unlock(&rdata
->rp_mutex
);
1905 rjt_data
.reason
= ELS_RJT_BUSY
;
1906 rjt_data
.explan
= ELS_EXPL_NONE
;
1909 if (!fc_rport_compatible_roles(lport
, rdata
)) {
1910 FC_RPORT_DBG(rdata
, "Received PLOGI for incompatible role\n");
1911 mutex_unlock(&rdata
->rp_mutex
);
1912 rjt_data
.reason
= ELS_RJT_LOGIC
;
1913 rjt_data
.explan
= ELS_EXPL_NONE
;
1918 * Get session payload size from incoming PLOGI.
1920 rdata
->maxframe_size
= fc_plogi_get_maxframe(pl
, lport
->mfs
);
1923 * Send LS_ACC. If this fails, the originator should retry.
1925 fp
= fc_frame_alloc(lport
, sizeof(*pl
));
1929 fc_plogi_fill(lport
, fp
, ELS_LS_ACC
);
1930 fc_fill_reply_hdr(fp
, rx_fp
, FC_RCTL_ELS_REP
, 0);
1931 lport
->tt
.frame_send(lport
, fp
);
1932 fc_rport_enter_prli(rdata
);
1934 mutex_unlock(&rdata
->rp_mutex
);
1935 fc_frame_free(rx_fp
);
1939 fc_seq_els_rsp_send(fp
, ELS_LS_RJT
, &rjt_data
);
1944 * fc_rport_recv_prli_req() - Handler for process login (PRLI) requests
1945 * @rdata: The remote port that sent the PRLI request
1946 * @rx_fp: The PRLI request frame
1948 static void fc_rport_recv_prli_req(struct fc_rport_priv
*rdata
,
1949 struct fc_frame
*rx_fp
)
1951 struct fc_lport
*lport
= rdata
->local_port
;
1952 struct fc_frame
*fp
;
1954 struct fc_els_prli prli
;
1955 struct fc_els_spp spp
;
1957 struct fc_els_spp
*rspp
; /* request service param page */
1958 struct fc_els_spp
*spp
; /* response spp */
1961 enum fc_els_spp_resp resp
;
1962 struct fc_seq_els_data rjt_data
;
1963 struct fc4_prov
*prov
;
1965 lockdep_assert_held(&rdata
->rp_mutex
);
1967 FC_RPORT_DBG(rdata
, "Received PRLI request while in state %s\n",
1968 fc_rport_state(rdata
));
1970 len
= fr_len(rx_fp
) - sizeof(struct fc_frame_header
);
1971 pp
= fc_frame_payload_get(rx_fp
, sizeof(*pp
));
1974 plen
= ntohs(pp
->prli
.prli_len
);
1975 if ((plen
% 4) != 0 || plen
> len
|| plen
< 16)
1979 plen
= pp
->prli
.prli_spp_len
;
1980 if ((plen
% 4) != 0 || plen
< sizeof(*spp
) ||
1981 plen
> len
|| len
< sizeof(*pp
) || plen
< 12)
1985 fp
= fc_frame_alloc(lport
, len
);
1987 rjt_data
.reason
= ELS_RJT_UNAB
;
1988 rjt_data
.explan
= ELS_EXPL_INSUF_RES
;
1991 pp
= fc_frame_payload_get(fp
, len
);
1994 pp
->prli
.prli_cmd
= ELS_LS_ACC
;
1995 pp
->prli
.prli_spp_len
= plen
;
1996 pp
->prli
.prli_len
= htons(len
);
1997 len
-= sizeof(struct fc_els_prli
);
2000 * Go through all the service parameter pages and build
2001 * response. If plen indicates longer SPP than standard,
2002 * use that. The entire response has been pre-cleared above.
2005 mutex_lock(&fc_prov_mutex
);
2006 while (len
>= plen
) {
2007 rdata
->spp_type
= rspp
->spp_type
;
2008 spp
->spp_type
= rspp
->spp_type
;
2009 spp
->spp_type_ext
= rspp
->spp_type_ext
;
2012 if (rspp
->spp_type
< FC_FC4_PROV_SIZE
) {
2013 enum fc_els_spp_resp active
= 0, passive
= 0;
2015 prov
= fc_active_prov
[rspp
->spp_type
];
2017 active
= prov
->prli(rdata
, plen
, rspp
, spp
);
2018 prov
= fc_passive_prov
[rspp
->spp_type
];
2020 passive
= prov
->prli(rdata
, plen
, rspp
, spp
);
2021 if (!active
|| passive
== FC_SPP_RESP_ACK
)
2025 FC_RPORT_DBG(rdata
, "PRLI rspp type %x "
2026 "active %x passive %x\n",
2027 rspp
->spp_type
, active
, passive
);
2030 if (spp
->spp_flags
& FC_SPP_EST_IMG_PAIR
)
2031 resp
|= FC_SPP_RESP_CONF
;
2033 resp
|= FC_SPP_RESP_INVL
;
2035 spp
->spp_flags
|= resp
;
2037 rspp
= (struct fc_els_spp
*)((char *)rspp
+ plen
);
2038 spp
= (struct fc_els_spp
*)((char *)spp
+ plen
);
2040 mutex_unlock(&fc_prov_mutex
);
2043 * Send LS_ACC. If this fails, the originator should retry.
2045 fc_fill_reply_hdr(fp
, rx_fp
, FC_RCTL_ELS_REP
, 0);
2046 lport
->tt
.frame_send(lport
, fp
);
2051 rjt_data
.reason
= ELS_RJT_PROT
;
2052 rjt_data
.explan
= ELS_EXPL_INV_LEN
;
2054 fc_seq_els_rsp_send(rx_fp
, ELS_LS_RJT
, &rjt_data
);
2056 fc_frame_free(rx_fp
);
2060 * fc_rport_recv_prlo_req() - Handler for process logout (PRLO) requests
2061 * @rdata: The remote port that sent the PRLO request
2062 * @rx_fp: The PRLO request frame
2064 static void fc_rport_recv_prlo_req(struct fc_rport_priv
*rdata
,
2065 struct fc_frame
*rx_fp
)
2067 struct fc_lport
*lport
= rdata
->local_port
;
2068 struct fc_frame
*fp
;
2070 struct fc_els_prlo prlo
;
2071 struct fc_els_spp spp
;
2073 struct fc_els_spp
*rspp
; /* request service param page */
2074 struct fc_els_spp
*spp
; /* response spp */
2077 struct fc_seq_els_data rjt_data
;
2079 lockdep_assert_held(&rdata
->rp_mutex
);
2081 FC_RPORT_DBG(rdata
, "Received PRLO request while in state %s\n",
2082 fc_rport_state(rdata
));
2084 len
= fr_len(rx_fp
) - sizeof(struct fc_frame_header
);
2085 pp
= fc_frame_payload_get(rx_fp
, sizeof(*pp
));
2088 plen
= ntohs(pp
->prlo
.prlo_len
);
2096 fp
= fc_frame_alloc(lport
, len
);
2098 rjt_data
.reason
= ELS_RJT_UNAB
;
2099 rjt_data
.explan
= ELS_EXPL_INSUF_RES
;
2103 pp
= fc_frame_payload_get(fp
, len
);
2106 pp
->prlo
.prlo_cmd
= ELS_LS_ACC
;
2107 pp
->prlo
.prlo_obs
= 0x10;
2108 pp
->prlo
.prlo_len
= htons(len
);
2110 spp
->spp_type
= rspp
->spp_type
;
2111 spp
->spp_type_ext
= rspp
->spp_type_ext
;
2112 spp
->spp_flags
= FC_SPP_RESP_ACK
;
2114 fc_rport_enter_prli(rdata
);
2116 fc_fill_reply_hdr(fp
, rx_fp
, FC_RCTL_ELS_REP
, 0);
2117 lport
->tt
.frame_send(lport
, fp
);
2121 rjt_data
.reason
= ELS_RJT_PROT
;
2122 rjt_data
.explan
= ELS_EXPL_INV_LEN
;
2124 fc_seq_els_rsp_send(rx_fp
, ELS_LS_RJT
, &rjt_data
);
2126 fc_frame_free(rx_fp
);
2130 * fc_rport_recv_logo_req() - Handler for logout (LOGO) requests
2131 * @lport: The local port that received the LOGO request
2132 * @fp: The LOGO request frame
2134 * Reference counting: drops kref on return
2136 static void fc_rport_recv_logo_req(struct fc_lport
*lport
, struct fc_frame
*fp
)
2138 struct fc_rport_priv
*rdata
;
2141 lockdep_assert_held(&lport
->lp_mutex
);
2143 fc_seq_els_rsp_send(fp
, ELS_LS_ACC
, NULL
);
2145 sid
= fc_frame_sid(fp
);
2147 rdata
= fc_rport_lookup(lport
, sid
);
2149 mutex_lock(&rdata
->rp_mutex
);
2150 FC_RPORT_DBG(rdata
, "Received LOGO request while in state %s\n",
2151 fc_rport_state(rdata
));
2153 fc_rport_enter_delete(rdata
, RPORT_EV_STOP
);
2154 mutex_unlock(&rdata
->rp_mutex
);
2155 kref_put(&rdata
->kref
, fc_rport_destroy
);
2157 FC_RPORT_ID_DBG(lport
, sid
,
2158 "Received LOGO from non-logged-in port\n");
2163 * fc_rport_flush_queue() - Flush the rport_event_queue
2165 void fc_rport_flush_queue(void)
2167 flush_workqueue(rport_event_queue
);
2169 EXPORT_SYMBOL(fc_rport_flush_queue
);
2172 * fc_rport_fcp_prli() - Handle incoming PRLI for the FCP initiator.
2173 * @rdata: remote port private
2174 * @spp_len: service parameter page length
2175 * @rspp: received service parameter page
2176 * @spp: response service parameter page
2178 * Returns the value for the response code to be placed in spp_flags;
2179 * Returns 0 if not an initiator.
2181 static int fc_rport_fcp_prli(struct fc_rport_priv
*rdata
, u32 spp_len
,
2182 const struct fc_els_spp
*rspp
,
2183 struct fc_els_spp
*spp
)
2185 struct fc_lport
*lport
= rdata
->local_port
;
2188 fcp_parm
= ntohl(rspp
->spp_params
);
2189 rdata
->ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2190 if (fcp_parm
& FCP_SPPF_INIT_FCN
)
2191 rdata
->ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
2192 if (fcp_parm
& FCP_SPPF_TARG_FCN
)
2193 rdata
->ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
2194 if (fcp_parm
& FCP_SPPF_RETRY
)
2195 rdata
->flags
|= FC_RP_FLAGS_RETRY
;
2196 rdata
->supported_classes
= FC_COS_CLASS3
;
2198 if (!(lport
->service_params
& FCP_SPPF_INIT_FCN
))
2201 spp
->spp_flags
|= rspp
->spp_flags
& FC_SPP_EST_IMG_PAIR
;
2204 * OR in our service parameters with other providers (target), if any.
2206 fcp_parm
= ntohl(spp
->spp_params
);
2207 spp
->spp_params
= htonl(fcp_parm
| lport
->service_params
);
2208 return FC_SPP_RESP_ACK
;
2212 * FC-4 provider ops for FCP initiator.
2214 struct fc4_prov fc_rport_fcp_init
= {
2215 .prli
= fc_rport_fcp_prli
,
2219 * fc_rport_t0_prli() - Handle incoming PRLI parameters for type 0
2220 * @rdata: remote port private
2221 * @spp_len: service parameter page length
2222 * @rspp: received service parameter page
2223 * @spp: response service parameter page
2225 static int fc_rport_t0_prli(struct fc_rport_priv
*rdata
, u32 spp_len
,
2226 const struct fc_els_spp
*rspp
,
2227 struct fc_els_spp
*spp
)
2229 if (rspp
->spp_flags
& FC_SPP_EST_IMG_PAIR
)
2230 return FC_SPP_RESP_INVL
;
2231 return FC_SPP_RESP_ACK
;
2235 * FC-4 provider ops for type 0 service parameters.
2237 * This handles the special case of type 0 which is always successful
2238 * but doesn't do anything otherwise.
2240 struct fc4_prov fc_rport_t0_prov
= {
2241 .prli
= fc_rport_t0_prli
,
2245 * fc_setup_rport() - Initialize the rport_event_queue
2247 int fc_setup_rport(void)
2249 rport_event_queue
= create_singlethread_workqueue("fc_rport_eq");
2250 if (!rport_event_queue
)
2256 * fc_destroy_rport() - Destroy the rport_event_queue
2258 void fc_destroy_rport(void)
2260 destroy_workqueue(rport_event_queue
);
2264 * fc_rport_terminate_io() - Stop all outstanding I/O on a remote port
2265 * @rport: The remote port whose I/O should be terminated
2267 void fc_rport_terminate_io(struct fc_rport
*rport
)
2269 struct fc_rport_libfc_priv
*rpriv
= rport
->dd_data
;
2270 struct fc_lport
*lport
= rpriv
->local_port
;
2272 lport
->tt
.exch_mgr_reset(lport
, 0, rport
->port_id
);
2273 lport
->tt
.exch_mgr_reset(lport
, rport
->port_id
, 0);
2275 EXPORT_SYMBOL(fc_rport_terminate_io
);