2 * Copyright(c) 2007 - 2008 Intel Corporation. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
17 * Maintained at www.Open-FCoE.org
23 * This file contains all processing regarding fc_rports. It contains the
24 * rport state machine and does all rport interaction with the transport class.
25 * There should be no other places in libfc that interact directly with the
26 * transport class in regards to adding and deleting rports.
28 * fc_rport's represent N_Port's within the fabric.
34 * The rport should never hold the rport mutex and then attempt to acquire
35 * either the lport or disc mutexes. The rport's mutex is considered lesser
36 * than both the lport's mutex and the disc mutex. Refer to fc_lport.c for
37 * more comments on the hierarchy.
39 * The locking strategy is similar to the lport's strategy. The lock protects
40 * the rport's states and is held and released by the entry points to the rport
41 * block. All _enter_* functions correspond to rport states and expect the rport
42 * mutex to be locked before calling them. This means that rports only handle
43 * one request or response at a time, since they're not critical for the I/O
44 * path this potential over-use of the mutex is acceptable.
48 * RPORT REFERENCE COUNTING
50 * A rport reference should be taken when:
51 * - an rport is allocated
52 * - a workqueue item is scheduled
53 * - an ELS request is send
54 * The reference should be dropped when:
55 * - the workqueue function has finished
56 * - the ELS response is handled
57 * - an rport is removed
60 #include <linux/kernel.h>
61 #include <linux/spinlock.h>
62 #include <linux/interrupt.h>
63 #include <linux/slab.h>
64 #include <linux/rcupdate.h>
65 #include <linux/timer.h>
66 #include <linux/workqueue.h>
67 #include <linux/export.h>
68 #include <linux/rculist.h>
70 #include <asm/unaligned.h>
72 #include <scsi/libfc.h>
73 #include <scsi/fc_encode.h>
77 static struct workqueue_struct
*rport_event_queue
;
79 static void fc_rport_enter_flogi(struct fc_rport_priv
*);
80 static void fc_rport_enter_plogi(struct fc_rport_priv
*);
81 static void fc_rport_enter_prli(struct fc_rport_priv
*);
82 static void fc_rport_enter_rtv(struct fc_rport_priv
*);
83 static void fc_rport_enter_ready(struct fc_rport_priv
*);
84 static void fc_rport_enter_logo(struct fc_rport_priv
*);
85 static void fc_rport_enter_adisc(struct fc_rport_priv
*);
87 static void fc_rport_recv_plogi_req(struct fc_lport
*, struct fc_frame
*);
88 static void fc_rport_recv_prli_req(struct fc_rport_priv
*, struct fc_frame
*);
89 static void fc_rport_recv_prlo_req(struct fc_rport_priv
*, struct fc_frame
*);
90 static void fc_rport_recv_logo_req(struct fc_lport
*, struct fc_frame
*);
91 static void fc_rport_timeout(struct work_struct
*);
92 static void fc_rport_error(struct fc_rport_priv
*, int);
93 static void fc_rport_error_retry(struct fc_rport_priv
*, int);
94 static void fc_rport_work(struct work_struct
*);
96 static const char *fc_rport_state_names
[] = {
97 [RPORT_ST_INIT
] = "Init",
98 [RPORT_ST_FLOGI
] = "FLOGI",
99 [RPORT_ST_PLOGI_WAIT
] = "PLOGI_WAIT",
100 [RPORT_ST_PLOGI
] = "PLOGI",
101 [RPORT_ST_PRLI
] = "PRLI",
102 [RPORT_ST_RTV
] = "RTV",
103 [RPORT_ST_READY
] = "Ready",
104 [RPORT_ST_ADISC
] = "ADISC",
105 [RPORT_ST_DELETE
] = "Delete",
109 * fc_rport_lookup() - Lookup a remote port by port_id
110 * @lport: The local port to lookup the remote port on
111 * @port_id: The remote port ID to look up
113 * The reference count of the fc_rport_priv structure is
116 struct fc_rport_priv
*fc_rport_lookup(const struct fc_lport
*lport
,
119 struct fc_rport_priv
*rdata
= NULL
, *tmp_rdata
;
122 list_for_each_entry_rcu(tmp_rdata
, &lport
->disc
.rports
, peers
)
123 if (tmp_rdata
->ids
.port_id
== port_id
&&
124 kref_get_unless_zero(&tmp_rdata
->kref
)) {
131 EXPORT_SYMBOL(fc_rport_lookup
);
134 * fc_rport_create() - Create a new remote port
135 * @lport: The local port this remote port will be associated with
136 * @ids: The identifiers for the new remote port
138 * The remote port will start in the INIT state.
140 struct fc_rport_priv
*fc_rport_create(struct fc_lport
*lport
, u32 port_id
)
142 struct fc_rport_priv
*rdata
;
144 lockdep_assert_held(&lport
->disc
.disc_mutex
);
146 rdata
= fc_rport_lookup(lport
, port_id
);
150 rdata
= kzalloc(sizeof(*rdata
) + lport
->rport_priv_size
, GFP_KERNEL
);
154 rdata
->ids
.node_name
= -1;
155 rdata
->ids
.port_name
= -1;
156 rdata
->ids
.port_id
= port_id
;
157 rdata
->ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
159 kref_init(&rdata
->kref
);
160 mutex_init(&rdata
->rp_mutex
);
161 rdata
->local_port
= lport
;
162 rdata
->rp_state
= RPORT_ST_INIT
;
163 rdata
->event
= RPORT_EV_NONE
;
164 rdata
->flags
= FC_RP_FLAGS_REC_SUPPORTED
;
165 rdata
->e_d_tov
= lport
->e_d_tov
;
166 rdata
->r_a_tov
= lport
->r_a_tov
;
167 rdata
->maxframe_size
= FC_MIN_MAX_PAYLOAD
;
168 INIT_DELAYED_WORK(&rdata
->retry_work
, fc_rport_timeout
);
169 INIT_WORK(&rdata
->event_work
, fc_rport_work
);
170 if (port_id
!= FC_FID_DIR_SERV
) {
171 rdata
->lld_event_callback
= lport
->tt
.rport_event_callback
;
172 list_add_rcu(&rdata
->peers
, &lport
->disc
.rports
);
176 EXPORT_SYMBOL(fc_rport_create
);
179 * fc_rport_destroy() - Free a remote port after last reference is released
180 * @kref: The remote port's kref
182 void fc_rport_destroy(struct kref
*kref
)
184 struct fc_rport_priv
*rdata
;
186 rdata
= container_of(kref
, struct fc_rport_priv
, kref
);
187 kfree_rcu(rdata
, rcu
);
189 EXPORT_SYMBOL(fc_rport_destroy
);
192 * fc_rport_state() - Return a string identifying the remote port's state
193 * @rdata: The remote port
195 static const char *fc_rport_state(struct fc_rport_priv
*rdata
)
199 cp
= fc_rport_state_names
[rdata
->rp_state
];
206 * fc_set_rport_loss_tmo() - Set the remote port loss timeout
207 * @rport: The remote port that gets a new timeout value
208 * @timeout: The new timeout value (in seconds)
210 void fc_set_rport_loss_tmo(struct fc_rport
*rport
, u32 timeout
)
213 rport
->dev_loss_tmo
= timeout
;
215 rport
->dev_loss_tmo
= 1;
217 EXPORT_SYMBOL(fc_set_rport_loss_tmo
);
220 * fc_plogi_get_maxframe() - Get the maximum payload from the common service
221 * parameters in a FLOGI frame
222 * @flp: The FLOGI or PLOGI payload
223 * @maxval: The maximum frame size upper limit; this may be less than what
224 * is in the service parameters
226 static unsigned int fc_plogi_get_maxframe(struct fc_els_flogi
*flp
,
232 * Get max payload from the common service parameters and the
233 * class 3 receive data field size.
235 mfs
= ntohs(flp
->fl_csp
.sp_bb_data
) & FC_SP_BB_DATA_MASK
;
236 if (mfs
>= FC_SP_MIN_MAX_PAYLOAD
&& mfs
< maxval
)
238 mfs
= ntohs(flp
->fl_cssp
[3 - 1].cp_rdfs
);
239 if (mfs
>= FC_SP_MIN_MAX_PAYLOAD
&& mfs
< maxval
)
245 * fc_rport_state_enter() - Change the state of a remote port
246 * @rdata: The remote port whose state should change
247 * @new: The new state
249 static void fc_rport_state_enter(struct fc_rport_priv
*rdata
,
250 enum fc_rport_state
new)
252 lockdep_assert_held(&rdata
->rp_mutex
);
254 if (rdata
->rp_state
!= new)
256 rdata
->rp_state
= new;
260 * fc_rport_work() - Handler for remote port events in the rport_event_queue
261 * @work: Handle to the remote port being dequeued
263 * Reference counting: drops kref on return
265 static void fc_rport_work(struct work_struct
*work
)
268 struct fc_rport_priv
*rdata
=
269 container_of(work
, struct fc_rport_priv
, event_work
);
270 struct fc_rport_libfc_priv
*rpriv
;
271 enum fc_rport_event event
;
272 struct fc_lport
*lport
= rdata
->local_port
;
273 struct fc_rport_operations
*rport_ops
;
274 struct fc_rport_identifiers ids
;
275 struct fc_rport
*rport
;
276 struct fc4_prov
*prov
;
279 mutex_lock(&rdata
->rp_mutex
);
280 event
= rdata
->event
;
281 rport_ops
= rdata
->ops
;
282 rport
= rdata
->rport
;
284 FC_RPORT_DBG(rdata
, "work event %u\n", event
);
289 rdata
->event
= RPORT_EV_NONE
;
290 rdata
->major_retries
= 0;
291 kref_get(&rdata
->kref
);
292 mutex_unlock(&rdata
->rp_mutex
);
295 FC_RPORT_DBG(rdata
, "No rport!\n");
296 rport
= fc_remote_port_add(lport
->host
, 0, &ids
);
299 FC_RPORT_DBG(rdata
, "Failed to add the rport\n");
300 fc_rport_logoff(rdata
);
301 kref_put(&rdata
->kref
, fc_rport_destroy
);
304 mutex_lock(&rdata
->rp_mutex
);
306 FC_RPORT_DBG(rdata
, "rport already allocated\n");
307 rdata
->rport
= rport
;
308 rport
->maxframe_size
= rdata
->maxframe_size
;
309 rport
->supported_classes
= rdata
->supported_classes
;
311 rpriv
= rport
->dd_data
;
312 rpriv
->local_port
= lport
;
313 rpriv
->rp_state
= rdata
->rp_state
;
314 rpriv
->flags
= rdata
->flags
;
315 rpriv
->e_d_tov
= rdata
->e_d_tov
;
316 rpriv
->r_a_tov
= rdata
->r_a_tov
;
317 mutex_unlock(&rdata
->rp_mutex
);
319 if (rport_ops
&& rport_ops
->event_callback
) {
320 FC_RPORT_DBG(rdata
, "callback ev %d\n", event
);
321 rport_ops
->event_callback(lport
, rdata
, event
);
323 if (rdata
->lld_event_callback
) {
324 FC_RPORT_DBG(rdata
, "lld callback ev %d\n", event
);
325 rdata
->lld_event_callback(lport
, rdata
, event
);
327 kref_put(&rdata
->kref
, fc_rport_destroy
);
330 case RPORT_EV_FAILED
:
333 if (rdata
->prli_count
) {
334 mutex_lock(&fc_prov_mutex
);
335 for (type
= 1; type
< FC_FC4_PROV_SIZE
; type
++) {
336 prov
= fc_passive_prov
[type
];
337 if (prov
&& prov
->prlo
)
340 mutex_unlock(&fc_prov_mutex
);
342 port_id
= rdata
->ids
.port_id
;
343 mutex_unlock(&rdata
->rp_mutex
);
345 if (rport_ops
&& rport_ops
->event_callback
) {
346 FC_RPORT_DBG(rdata
, "callback ev %d\n", event
);
347 rport_ops
->event_callback(lport
, rdata
, event
);
349 if (rdata
->lld_event_callback
) {
350 FC_RPORT_DBG(rdata
, "lld callback ev %d\n", event
);
351 rdata
->lld_event_callback(lport
, rdata
, event
);
353 if (cancel_delayed_work_sync(&rdata
->retry_work
))
354 kref_put(&rdata
->kref
, fc_rport_destroy
);
357 * Reset any outstanding exchanges before freeing rport.
359 lport
->tt
.exch_mgr_reset(lport
, 0, port_id
);
360 lport
->tt
.exch_mgr_reset(lport
, port_id
, 0);
363 rpriv
= rport
->dd_data
;
364 rpriv
->rp_state
= RPORT_ST_DELETE
;
365 mutex_lock(&rdata
->rp_mutex
);
367 mutex_unlock(&rdata
->rp_mutex
);
368 fc_remote_port_delete(rport
);
371 mutex_lock(&rdata
->rp_mutex
);
372 if (rdata
->rp_state
== RPORT_ST_DELETE
) {
373 if (port_id
== FC_FID_DIR_SERV
) {
374 rdata
->event
= RPORT_EV_NONE
;
375 mutex_unlock(&rdata
->rp_mutex
);
376 kref_put(&rdata
->kref
, fc_rport_destroy
);
377 } else if ((rdata
->flags
& FC_RP_STARTED
) &&
378 rdata
->major_retries
<
379 lport
->max_rport_retry_count
) {
380 rdata
->major_retries
++;
381 rdata
->event
= RPORT_EV_NONE
;
382 FC_RPORT_DBG(rdata
, "work restart\n");
383 fc_rport_enter_flogi(rdata
);
384 mutex_unlock(&rdata
->rp_mutex
);
386 mutex_unlock(&rdata
->rp_mutex
);
387 FC_RPORT_DBG(rdata
, "work delete\n");
388 mutex_lock(&lport
->disc
.disc_mutex
);
389 list_del_rcu(&rdata
->peers
);
390 mutex_unlock(&lport
->disc
.disc_mutex
);
391 kref_put(&rdata
->kref
, fc_rport_destroy
);
395 * Re-open for events. Reissue READY event if ready.
397 rdata
->event
= RPORT_EV_NONE
;
398 if (rdata
->rp_state
== RPORT_ST_READY
) {
399 FC_RPORT_DBG(rdata
, "work reopen\n");
400 fc_rport_enter_ready(rdata
);
402 mutex_unlock(&rdata
->rp_mutex
);
407 mutex_unlock(&rdata
->rp_mutex
);
410 kref_put(&rdata
->kref
, fc_rport_destroy
);
414 * fc_rport_login() - Start the remote port login state machine
415 * @rdata: The remote port to be logged in to
417 * Initiates the RP state machine. It is called from the LP module.
418 * This function will issue the following commands to the N_Port
419 * identified by the FC ID provided.
425 * Locking Note: Called without the rport lock held. This
426 * function will hold the rport lock, call an _enter_*
427 * function and then unlock the rport.
429 * This indicates the intent to be logged into the remote port.
430 * If it appears we are already logged in, ADISC is used to verify
433 int fc_rport_login(struct fc_rport_priv
*rdata
)
435 mutex_lock(&rdata
->rp_mutex
);
437 if (rdata
->flags
& FC_RP_STARTED
) {
438 FC_RPORT_DBG(rdata
, "port already started\n");
439 mutex_unlock(&rdata
->rp_mutex
);
443 rdata
->flags
|= FC_RP_STARTED
;
444 switch (rdata
->rp_state
) {
446 FC_RPORT_DBG(rdata
, "ADISC port\n");
447 fc_rport_enter_adisc(rdata
);
449 case RPORT_ST_DELETE
:
450 FC_RPORT_DBG(rdata
, "Restart deleted port\n");
453 FC_RPORT_DBG(rdata
, "Login to port\n");
454 fc_rport_enter_flogi(rdata
);
457 FC_RPORT_DBG(rdata
, "Login in progress, state %s\n",
458 fc_rport_state(rdata
));
461 mutex_unlock(&rdata
->rp_mutex
);
465 EXPORT_SYMBOL(fc_rport_login
);
468 * fc_rport_enter_delete() - Schedule a remote port to be deleted
469 * @rdata: The remote port to be deleted
470 * @event: The event to report as the reason for deletion
472 * Allow state change into DELETE only once.
474 * Call queue_work only if there's no event already pending.
475 * Set the new event so that the old pending event will not occur.
476 * Since we have the mutex, even if fc_rport_work() is already started,
477 * it'll see the new event.
479 * Reference counting: does not modify kref
481 static void fc_rport_enter_delete(struct fc_rport_priv
*rdata
,
482 enum fc_rport_event event
)
484 lockdep_assert_held(&rdata
->rp_mutex
);
486 if (rdata
->rp_state
== RPORT_ST_DELETE
)
489 FC_RPORT_DBG(rdata
, "Delete port\n");
491 fc_rport_state_enter(rdata
, RPORT_ST_DELETE
);
493 kref_get(&rdata
->kref
);
494 if (rdata
->event
== RPORT_EV_NONE
&&
495 !queue_work(rport_event_queue
, &rdata
->event_work
))
496 kref_put(&rdata
->kref
, fc_rport_destroy
);
498 rdata
->event
= event
;
502 * fc_rport_logoff() - Logoff and remove a remote port
503 * @rdata: The remote port to be logged off of
505 * Locking Note: Called without the rport lock held. This
506 * function will hold the rport lock, call an _enter_*
507 * function and then unlock the rport.
509 int fc_rport_logoff(struct fc_rport_priv
*rdata
)
511 struct fc_lport
*lport
= rdata
->local_port
;
512 u32 port_id
= rdata
->ids
.port_id
;
514 mutex_lock(&rdata
->rp_mutex
);
516 FC_RPORT_DBG(rdata
, "Remove port\n");
518 rdata
->flags
&= ~FC_RP_STARTED
;
519 if (rdata
->rp_state
== RPORT_ST_DELETE
) {
520 FC_RPORT_DBG(rdata
, "Port in Delete state, not removing\n");
525 * To explicitly Logout, the initiating Nx_Port shall terminate
526 * other open Sequences that it initiated with the destination
527 * Nx_Port prior to performing Logout.
529 lport
->tt
.exch_mgr_reset(lport
, 0, port_id
);
530 lport
->tt
.exch_mgr_reset(lport
, port_id
, 0);
532 fc_rport_enter_logo(rdata
);
535 * Change the state to Delete so that we discard
538 fc_rport_enter_delete(rdata
, RPORT_EV_STOP
);
540 mutex_unlock(&rdata
->rp_mutex
);
543 EXPORT_SYMBOL(fc_rport_logoff
);
546 * fc_rport_enter_ready() - Transition to the RPORT_ST_READY state
547 * @rdata: The remote port that is ready
549 * Reference counting: schedules workqueue, does not modify kref
551 static void fc_rport_enter_ready(struct fc_rport_priv
*rdata
)
553 lockdep_assert_held(&rdata
->rp_mutex
);
555 fc_rport_state_enter(rdata
, RPORT_ST_READY
);
557 FC_RPORT_DBG(rdata
, "Port is Ready\n");
559 kref_get(&rdata
->kref
);
560 if (rdata
->event
== RPORT_EV_NONE
&&
561 !queue_work(rport_event_queue
, &rdata
->event_work
))
562 kref_put(&rdata
->kref
, fc_rport_destroy
);
564 rdata
->event
= RPORT_EV_READY
;
568 * fc_rport_timeout() - Handler for the retry_work timer
569 * @work: Handle to the remote port that has timed out
571 * Locking Note: Called without the rport lock held. This
572 * function will hold the rport lock, call an _enter_*
573 * function and then unlock the rport.
575 * Reference counting: Drops kref on return.
577 static void fc_rport_timeout(struct work_struct
*work
)
579 struct fc_rport_priv
*rdata
=
580 container_of(work
, struct fc_rport_priv
, retry_work
.work
);
582 mutex_lock(&rdata
->rp_mutex
);
583 FC_RPORT_DBG(rdata
, "Port timeout, state %s\n", fc_rport_state(rdata
));
585 switch (rdata
->rp_state
) {
587 fc_rport_enter_flogi(rdata
);
590 fc_rport_enter_plogi(rdata
);
593 fc_rport_enter_prli(rdata
);
596 fc_rport_enter_rtv(rdata
);
599 fc_rport_enter_adisc(rdata
);
601 case RPORT_ST_PLOGI_WAIT
:
604 case RPORT_ST_DELETE
:
608 mutex_unlock(&rdata
->rp_mutex
);
609 kref_put(&rdata
->kref
, fc_rport_destroy
);
613 * fc_rport_error() - Error handler, called once retries have been exhausted
614 * @rdata: The remote port the error is happened on
615 * @err: The error code
617 * Reference counting: does not modify kref
619 static void fc_rport_error(struct fc_rport_priv
*rdata
, int err
)
621 struct fc_lport
*lport
= rdata
->local_port
;
623 lockdep_assert_held(&rdata
->rp_mutex
);
625 FC_RPORT_DBG(rdata
, "Error %d in state %s, retries %d\n",
626 -err
, fc_rport_state(rdata
), rdata
->retries
);
628 switch (rdata
->rp_state
) {
630 rdata
->flags
&= ~FC_RP_STARTED
;
631 fc_rport_enter_delete(rdata
, RPORT_EV_FAILED
);
634 if (lport
->point_to_multipoint
) {
635 rdata
->flags
&= ~FC_RP_STARTED
;
636 fc_rport_enter_delete(rdata
, RPORT_EV_FAILED
);
638 fc_rport_enter_logo(rdata
);
641 fc_rport_enter_ready(rdata
);
645 fc_rport_enter_logo(rdata
);
647 case RPORT_ST_PLOGI_WAIT
:
648 case RPORT_ST_DELETE
:
656 * fc_rport_error_retry() - Handler for remote port state retries
657 * @rdata: The remote port whose state is to be retried
658 * @err: The error code
660 * If the error was an exchange timeout retry immediately,
661 * otherwise wait for E_D_TOV.
663 * Reference counting: increments kref when scheduling retry_work
665 static void fc_rport_error_retry(struct fc_rport_priv
*rdata
, int err
)
667 unsigned long delay
= msecs_to_jiffies(rdata
->e_d_tov
);
669 lockdep_assert_held(&rdata
->rp_mutex
);
671 /* make sure this isn't an FC_EX_CLOSED error, never retry those */
672 if (err
== -FC_EX_CLOSED
)
675 if (rdata
->retries
< rdata
->local_port
->max_rport_retry_count
) {
676 FC_RPORT_DBG(rdata
, "Error %d in state %s, retrying\n",
677 err
, fc_rport_state(rdata
));
679 /* no additional delay on exchange timeouts */
680 if (err
== -FC_EX_TIMEOUT
)
682 kref_get(&rdata
->kref
);
683 if (!schedule_delayed_work(&rdata
->retry_work
, delay
))
684 kref_put(&rdata
->kref
, fc_rport_destroy
);
689 fc_rport_error(rdata
, err
);
693 * fc_rport_login_complete() - Handle parameters and completion of p-mp login.
694 * @rdata: The remote port which we logged into or which logged into us.
695 * @fp: The FLOGI or PLOGI request or response frame
697 * Returns non-zero error if a problem is detected with the frame.
698 * Does not free the frame.
700 * This is only used in point-to-multipoint mode for FIP currently.
702 static int fc_rport_login_complete(struct fc_rport_priv
*rdata
,
705 struct fc_lport
*lport
= rdata
->local_port
;
706 struct fc_els_flogi
*flogi
;
707 unsigned int e_d_tov
;
710 flogi
= fc_frame_payload_get(fp
, sizeof(*flogi
));
714 csp_flags
= ntohs(flogi
->fl_csp
.sp_features
);
716 if (fc_frame_payload_op(fp
) == ELS_FLOGI
) {
717 if (csp_flags
& FC_SP_FT_FPORT
) {
718 FC_RPORT_DBG(rdata
, "Fabric bit set in FLOGI\n");
724 * E_D_TOV is not valid on an incoming FLOGI request.
726 e_d_tov
= ntohl(flogi
->fl_csp
.sp_e_d_tov
);
727 if (csp_flags
& FC_SP_FT_EDTR
)
729 if (e_d_tov
> rdata
->e_d_tov
)
730 rdata
->e_d_tov
= e_d_tov
;
732 rdata
->maxframe_size
= fc_plogi_get_maxframe(flogi
, lport
->mfs
);
737 * fc_rport_flogi_resp() - Handle response to FLOGI request for p-mp mode
738 * @sp: The sequence that the FLOGI was on
739 * @fp: The FLOGI response frame
740 * @rp_arg: The remote port that received the FLOGI response
742 static void fc_rport_flogi_resp(struct fc_seq
*sp
, struct fc_frame
*fp
,
745 struct fc_rport_priv
*rdata
= rp_arg
;
746 struct fc_lport
*lport
= rdata
->local_port
;
747 struct fc_els_flogi
*flogi
;
748 unsigned int r_a_tov
;
752 FC_RPORT_DBG(rdata
, "Received a FLOGI %s\n",
753 IS_ERR(fp
) ? "error" : fc_els_resp_type(fp
));
755 if (fp
== ERR_PTR(-FC_EX_CLOSED
))
758 mutex_lock(&rdata
->rp_mutex
);
760 if (rdata
->rp_state
!= RPORT_ST_FLOGI
) {
761 FC_RPORT_DBG(rdata
, "Received a FLOGI response, but in state "
762 "%s\n", fc_rport_state(rdata
));
769 fc_rport_error(rdata
, PTR_ERR(fp
));
772 opcode
= fc_frame_payload_op(fp
);
773 if (opcode
== ELS_LS_RJT
) {
774 struct fc_els_ls_rjt
*rjt
;
776 rjt
= fc_frame_payload_get(fp
, sizeof(*rjt
));
777 FC_RPORT_DBG(rdata
, "FLOGI ELS rejected, reason %x expl %x\n",
778 rjt
->er_reason
, rjt
->er_explan
);
779 err
= -FC_EX_ELS_RJT
;
781 } else if (opcode
!= ELS_LS_ACC
) {
782 FC_RPORT_DBG(rdata
, "FLOGI ELS invalid opcode %x\n", opcode
);
783 err
= -FC_EX_ELS_RJT
;
786 if (fc_rport_login_complete(rdata
, fp
)) {
787 FC_RPORT_DBG(rdata
, "FLOGI failed, no login\n");
788 err
= -FC_EX_INV_LOGIN
;
792 flogi
= fc_frame_payload_get(fp
, sizeof(*flogi
));
794 err
= -FC_EX_ALLOC_ERR
;
797 r_a_tov
= ntohl(flogi
->fl_csp
.sp_r_a_tov
);
798 if (r_a_tov
> rdata
->r_a_tov
)
799 rdata
->r_a_tov
= r_a_tov
;
801 if (rdata
->ids
.port_name
< lport
->wwpn
)
802 fc_rport_enter_plogi(rdata
);
804 fc_rport_state_enter(rdata
, RPORT_ST_PLOGI_WAIT
);
808 mutex_unlock(&rdata
->rp_mutex
);
810 kref_put(&rdata
->kref
, fc_rport_destroy
);
813 FC_RPORT_DBG(rdata
, "Bad FLOGI response\n");
814 fc_rport_error_retry(rdata
, err
);
819 * fc_rport_enter_flogi() - Send a FLOGI request to the remote port for p-mp
820 * @rdata: The remote port to send a FLOGI to
822 * Reference counting: increments kref when sending ELS
824 static void fc_rport_enter_flogi(struct fc_rport_priv
*rdata
)
826 struct fc_lport
*lport
= rdata
->local_port
;
829 lockdep_assert_held(&rdata
->rp_mutex
);
831 if (!lport
->point_to_multipoint
)
832 return fc_rport_enter_plogi(rdata
);
834 FC_RPORT_DBG(rdata
, "Entered FLOGI state from %s state\n",
835 fc_rport_state(rdata
));
837 fc_rport_state_enter(rdata
, RPORT_ST_FLOGI
);
839 fp
= fc_frame_alloc(lport
, sizeof(struct fc_els_flogi
));
841 return fc_rport_error_retry(rdata
, -FC_EX_ALLOC_ERR
);
843 kref_get(&rdata
->kref
);
844 if (!lport
->tt
.elsct_send(lport
, rdata
->ids
.port_id
, fp
, ELS_FLOGI
,
845 fc_rport_flogi_resp
, rdata
,
846 2 * lport
->r_a_tov
)) {
847 fc_rport_error_retry(rdata
, -FC_EX_XMIT_ERR
);
848 kref_put(&rdata
->kref
, fc_rport_destroy
);
853 * fc_rport_recv_flogi_req() - Handle Fabric Login (FLOGI) request in p-mp mode
854 * @lport: The local port that received the PLOGI request
855 * @rx_fp: The PLOGI request frame
857 * Reference counting: drops kref on return
859 static void fc_rport_recv_flogi_req(struct fc_lport
*lport
,
860 struct fc_frame
*rx_fp
)
862 struct fc_els_flogi
*flp
;
863 struct fc_rport_priv
*rdata
;
864 struct fc_frame
*fp
= rx_fp
;
865 struct fc_seq_els_data rjt_data
;
868 sid
= fc_frame_sid(fp
);
870 FC_RPORT_ID_DBG(lport
, sid
, "Received FLOGI request\n");
872 if (!lport
->point_to_multipoint
) {
873 rjt_data
.reason
= ELS_RJT_UNSUP
;
874 rjt_data
.explan
= ELS_EXPL_NONE
;
878 flp
= fc_frame_payload_get(fp
, sizeof(*flp
));
880 rjt_data
.reason
= ELS_RJT_LOGIC
;
881 rjt_data
.explan
= ELS_EXPL_INV_LEN
;
885 rdata
= fc_rport_lookup(lport
, sid
);
887 rjt_data
.reason
= ELS_RJT_FIP
;
888 rjt_data
.explan
= ELS_EXPL_NOT_NEIGHBOR
;
891 mutex_lock(&rdata
->rp_mutex
);
893 FC_RPORT_DBG(rdata
, "Received FLOGI in %s state\n",
894 fc_rport_state(rdata
));
896 switch (rdata
->rp_state
) {
899 * If received the FLOGI request on RPORT which is INIT state
900 * (means not transition to FLOGI either fc_rport timeout
901 * function didn;t trigger or this end hasn;t received
902 * beacon yet from other end. In that case only, allow RPORT
903 * state machine to continue, otherwise fall through which
904 * causes the code to send reject response.
905 * NOTE; Not checking for FIP->state such as VNMP_UP or
906 * VNMP_CLAIM because if FIP state is not one of those,
907 * RPORT wouldn;t have created and 'rport_lookup' would have
908 * failed anyway in that case.
911 case RPORT_ST_DELETE
:
912 mutex_unlock(&rdata
->rp_mutex
);
913 rjt_data
.reason
= ELS_RJT_FIP
;
914 rjt_data
.explan
= ELS_EXPL_NOT_NEIGHBOR
;
917 case RPORT_ST_PLOGI_WAIT
:
925 * Set the remote port to be deleted and to then restart.
926 * This queues work to be sure exchanges are reset.
928 fc_rport_enter_delete(rdata
, RPORT_EV_LOGO
);
929 mutex_unlock(&rdata
->rp_mutex
);
930 rjt_data
.reason
= ELS_RJT_BUSY
;
931 rjt_data
.explan
= ELS_EXPL_NONE
;
934 if (fc_rport_login_complete(rdata
, fp
)) {
935 mutex_unlock(&rdata
->rp_mutex
);
936 rjt_data
.reason
= ELS_RJT_LOGIC
;
937 rjt_data
.explan
= ELS_EXPL_NONE
;
941 fp
= fc_frame_alloc(lport
, sizeof(*flp
));
945 fc_flogi_fill(lport
, fp
);
946 flp
= fc_frame_payload_get(fp
, sizeof(*flp
));
947 flp
->fl_cmd
= ELS_LS_ACC
;
949 fc_fill_reply_hdr(fp
, rx_fp
, FC_RCTL_ELS_REP
, 0);
950 lport
->tt
.frame_send(lport
, fp
);
953 * Do not proceed with the state machine if our
954 * FLOGI has crossed with an FLOGI from the
955 * remote port; wait for the FLOGI response instead.
957 if (rdata
->rp_state
!= RPORT_ST_FLOGI
) {
958 if (rdata
->ids
.port_name
< lport
->wwpn
)
959 fc_rport_enter_plogi(rdata
);
961 fc_rport_state_enter(rdata
, RPORT_ST_PLOGI_WAIT
);
964 mutex_unlock(&rdata
->rp_mutex
);
965 kref_put(&rdata
->kref
, fc_rport_destroy
);
966 fc_frame_free(rx_fp
);
970 kref_put(&rdata
->kref
, fc_rport_destroy
);
972 fc_seq_els_rsp_send(rx_fp
, ELS_LS_RJT
, &rjt_data
);
973 fc_frame_free(rx_fp
);
977 * fc_rport_plogi_resp() - Handler for ELS PLOGI responses
978 * @sp: The sequence the PLOGI is on
979 * @fp: The PLOGI response frame
980 * @rdata_arg: The remote port that sent the PLOGI response
982 * Locking Note: This function will be called without the rport lock
983 * held, but it will lock, call an _enter_* function or fc_rport_error
984 * and then unlock the rport.
986 static void fc_rport_plogi_resp(struct fc_seq
*sp
, struct fc_frame
*fp
,
989 struct fc_rport_priv
*rdata
= rdata_arg
;
990 struct fc_lport
*lport
= rdata
->local_port
;
991 struct fc_els_flogi
*plp
= NULL
;
996 FC_RPORT_DBG(rdata
, "Received a PLOGI %s\n", fc_els_resp_type(fp
));
998 if (fp
== ERR_PTR(-FC_EX_CLOSED
))
1001 mutex_lock(&rdata
->rp_mutex
);
1003 if (rdata
->rp_state
!= RPORT_ST_PLOGI
) {
1004 FC_RPORT_DBG(rdata
, "Received a PLOGI response, but in state "
1005 "%s\n", fc_rport_state(rdata
));
1012 fc_rport_error_retry(rdata
, PTR_ERR(fp
));
1016 op
= fc_frame_payload_op(fp
);
1017 if (op
== ELS_LS_ACC
&&
1018 (plp
= fc_frame_payload_get(fp
, sizeof(*plp
))) != NULL
) {
1019 rdata
->ids
.port_name
= get_unaligned_be64(&plp
->fl_wwpn
);
1020 rdata
->ids
.node_name
= get_unaligned_be64(&plp
->fl_wwnn
);
1022 /* save plogi response sp_features for further reference */
1023 rdata
->sp_features
= ntohs(plp
->fl_csp
.sp_features
);
1025 if (lport
->point_to_multipoint
)
1026 fc_rport_login_complete(rdata
, fp
);
1027 csp_seq
= ntohs(plp
->fl_csp
.sp_tot_seq
);
1028 cssp_seq
= ntohs(plp
->fl_cssp
[3 - 1].cp_con_seq
);
1029 if (cssp_seq
< csp_seq
)
1031 rdata
->max_seq
= csp_seq
;
1032 rdata
->maxframe_size
= fc_plogi_get_maxframe(plp
, lport
->mfs
);
1033 fc_rport_enter_prli(rdata
);
1035 struct fc_els_ls_rjt
*rjt
;
1037 rjt
= fc_frame_payload_get(fp
, sizeof(*rjt
));
1039 FC_RPORT_DBG(rdata
, "PLOGI bad response\n");
1041 FC_RPORT_DBG(rdata
, "PLOGI ELS rejected, reason %x expl %x\n",
1042 rjt
->er_reason
, rjt
->er_explan
);
1043 fc_rport_error_retry(rdata
, -FC_EX_ELS_RJT
);
1048 mutex_unlock(&rdata
->rp_mutex
);
1050 kref_put(&rdata
->kref
, fc_rport_destroy
);
1054 fc_rport_compatible_roles(struct fc_lport
*lport
, struct fc_rport_priv
*rdata
)
1056 if (rdata
->ids
.roles
== FC_PORT_ROLE_UNKNOWN
)
1058 if ((rdata
->ids
.roles
& FC_PORT_ROLE_FCP_TARGET
) &&
1059 (lport
->service_params
& FCP_SPPF_INIT_FCN
))
1061 if ((rdata
->ids
.roles
& FC_PORT_ROLE_FCP_INITIATOR
) &&
1062 (lport
->service_params
& FCP_SPPF_TARG_FCN
))
1068 * fc_rport_enter_plogi() - Send Port Login (PLOGI) request
1069 * @rdata: The remote port to send a PLOGI to
1071 * Reference counting: increments kref when sending ELS
1073 static void fc_rport_enter_plogi(struct fc_rport_priv
*rdata
)
1075 struct fc_lport
*lport
= rdata
->local_port
;
1076 struct fc_frame
*fp
;
1078 lockdep_assert_held(&rdata
->rp_mutex
);
1080 if (!fc_rport_compatible_roles(lport
, rdata
)) {
1081 FC_RPORT_DBG(rdata
, "PLOGI suppressed for incompatible role\n");
1082 fc_rport_state_enter(rdata
, RPORT_ST_PLOGI_WAIT
);
1086 FC_RPORT_DBG(rdata
, "Port entered PLOGI state from %s state\n",
1087 fc_rport_state(rdata
));
1089 fc_rport_state_enter(rdata
, RPORT_ST_PLOGI
);
1091 rdata
->maxframe_size
= FC_MIN_MAX_PAYLOAD
;
1092 fp
= fc_frame_alloc(lport
, sizeof(struct fc_els_flogi
));
1094 FC_RPORT_DBG(rdata
, "%s frame alloc failed\n", __func__
);
1095 fc_rport_error_retry(rdata
, -FC_EX_ALLOC_ERR
);
1098 rdata
->e_d_tov
= lport
->e_d_tov
;
1100 kref_get(&rdata
->kref
);
1101 if (!lport
->tt
.elsct_send(lport
, rdata
->ids
.port_id
, fp
, ELS_PLOGI
,
1102 fc_rport_plogi_resp
, rdata
,
1103 2 * lport
->r_a_tov
)) {
1104 fc_rport_error_retry(rdata
, -FC_EX_XMIT_ERR
);
1105 kref_put(&rdata
->kref
, fc_rport_destroy
);
1110 * fc_rport_prli_resp() - Process Login (PRLI) response handler
1111 * @sp: The sequence the PRLI response was on
1112 * @fp: The PRLI response frame
1113 * @rdata_arg: The remote port that sent the PRLI response
1115 * Locking Note: This function will be called without the rport lock
1116 * held, but it will lock, call an _enter_* function or fc_rport_error
1117 * and then unlock the rport.
1119 static void fc_rport_prli_resp(struct fc_seq
*sp
, struct fc_frame
*fp
,
1122 struct fc_rport_priv
*rdata
= rdata_arg
;
1124 struct fc_els_prli prli
;
1125 struct fc_els_spp spp
;
1127 struct fc_els_spp temp_spp
;
1128 struct fc_els_ls_rjt
*rjt
;
1129 struct fc4_prov
*prov
;
1130 u32 roles
= FC_RPORT_ROLE_UNKNOWN
;
1133 enum fc_els_spp_resp resp_code
;
1135 FC_RPORT_DBG(rdata
, "Received a PRLI %s\n", fc_els_resp_type(fp
));
1137 if (fp
== ERR_PTR(-FC_EX_CLOSED
))
1140 mutex_lock(&rdata
->rp_mutex
);
1142 if (rdata
->rp_state
!= RPORT_ST_PRLI
) {
1143 FC_RPORT_DBG(rdata
, "Received a PRLI response, but in state "
1144 "%s\n", fc_rport_state(rdata
));
1151 fc_rport_error_retry(rdata
, PTR_ERR(fp
));
1155 /* reinitialize remote port roles */
1156 rdata
->ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
1158 op
= fc_frame_payload_op(fp
);
1159 if (op
== ELS_LS_ACC
) {
1160 pp
= fc_frame_payload_get(fp
, sizeof(*pp
));
1162 fc_rport_error_retry(rdata
, -FC_EX_SEQ_ERR
);
1166 resp_code
= (pp
->spp
.spp_flags
& FC_SPP_RESP_MASK
);
1167 FC_RPORT_DBG(rdata
, "PRLI spp_flags = 0x%x spp_type 0x%x\n",
1168 pp
->spp
.spp_flags
, pp
->spp
.spp_type
);
1169 rdata
->spp_type
= pp
->spp
.spp_type
;
1170 if (resp_code
!= FC_SPP_RESP_ACK
) {
1171 if (resp_code
== FC_SPP_RESP_CONF
)
1172 fc_rport_error(rdata
, -FC_EX_SEQ_ERR
);
1174 fc_rport_error_retry(rdata
, -FC_EX_SEQ_ERR
);
1177 if (pp
->prli
.prli_spp_len
< sizeof(pp
->spp
)) {
1178 fc_rport_error_retry(rdata
, -FC_EX_SEQ_ERR
);
1182 fcp_parm
= ntohl(pp
->spp
.spp_params
);
1183 if (fcp_parm
& FCP_SPPF_RETRY
)
1184 rdata
->flags
|= FC_RP_FLAGS_RETRY
;
1185 if (fcp_parm
& FCP_SPPF_CONF_COMPL
)
1186 rdata
->flags
|= FC_RP_FLAGS_CONF_REQ
;
1189 * Call prli provider if we should act as a target
1191 prov
= fc_passive_prov
[rdata
->spp_type
];
1193 memset(&temp_spp
, 0, sizeof(temp_spp
));
1194 prov
->prli(rdata
, pp
->prli
.prli_spp_len
,
1195 &pp
->spp
, &temp_spp
);
1198 * Check if the image pair could be established
1200 if (rdata
->spp_type
!= FC_TYPE_FCP
||
1201 !(pp
->spp
.spp_flags
& FC_SPP_EST_IMG_PAIR
)) {
1203 * Nope; we can't use this port as a target.
1205 fcp_parm
&= ~FCP_SPPF_TARG_FCN
;
1207 rdata
->supported_classes
= FC_COS_CLASS3
;
1208 if (fcp_parm
& FCP_SPPF_INIT_FCN
)
1209 roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
1210 if (fcp_parm
& FCP_SPPF_TARG_FCN
)
1211 roles
|= FC_RPORT_ROLE_FCP_TARGET
;
1213 rdata
->ids
.roles
= roles
;
1214 fc_rport_enter_rtv(rdata
);
1217 rjt
= fc_frame_payload_get(fp
, sizeof(*rjt
));
1219 FC_RPORT_DBG(rdata
, "PRLI bad response\n");
1221 FC_RPORT_DBG(rdata
, "PRLI ELS rejected, reason %x expl %x\n",
1222 rjt
->er_reason
, rjt
->er_explan
);
1223 fc_rport_error_retry(rdata
, FC_EX_ELS_RJT
);
1229 mutex_unlock(&rdata
->rp_mutex
);
1231 kref_put(&rdata
->kref
, fc_rport_destroy
);
1235 * fc_rport_enter_prli() - Send Process Login (PRLI) request
1236 * @rdata: The remote port to send the PRLI request to
1238 * Reference counting: increments kref when sending ELS
1240 static void fc_rport_enter_prli(struct fc_rport_priv
*rdata
)
1242 struct fc_lport
*lport
= rdata
->local_port
;
1244 struct fc_els_prli prli
;
1245 struct fc_els_spp spp
;
1247 struct fc_frame
*fp
;
1248 struct fc4_prov
*prov
;
1250 lockdep_assert_held(&rdata
->rp_mutex
);
1253 * If the rport is one of the well known addresses
1254 * we skip PRLI and RTV and go straight to READY.
1256 if (rdata
->ids
.port_id
>= FC_FID_DOM_MGR
) {
1257 fc_rport_enter_ready(rdata
);
1262 * And if the local port does not support the initiator function
1263 * there's no need to send a PRLI, either.
1265 if (!(lport
->service_params
& FCP_SPPF_INIT_FCN
)) {
1266 fc_rport_enter_ready(rdata
);
1270 FC_RPORT_DBG(rdata
, "Port entered PRLI state from %s state\n",
1271 fc_rport_state(rdata
));
1273 fc_rport_state_enter(rdata
, RPORT_ST_PRLI
);
1275 fp
= fc_frame_alloc(lport
, sizeof(*pp
));
1277 fc_rport_error_retry(rdata
, -FC_EX_ALLOC_ERR
);
1281 fc_prli_fill(lport
, fp
);
1283 prov
= fc_passive_prov
[FC_TYPE_FCP
];
1285 pp
= fc_frame_payload_get(fp
, sizeof(*pp
));
1286 prov
->prli(rdata
, sizeof(pp
->spp
), NULL
, &pp
->spp
);
1289 fc_fill_fc_hdr(fp
, FC_RCTL_ELS_REQ
, rdata
->ids
.port_id
,
1290 fc_host_port_id(lport
->host
), FC_TYPE_ELS
,
1291 FC_FC_FIRST_SEQ
| FC_FC_END_SEQ
| FC_FC_SEQ_INIT
, 0);
1293 kref_get(&rdata
->kref
);
1294 if (!fc_exch_seq_send(lport
, fp
, fc_rport_prli_resp
,
1295 NULL
, rdata
, 2 * lport
->r_a_tov
)) {
1296 fc_rport_error_retry(rdata
, -FC_EX_XMIT_ERR
);
1297 kref_put(&rdata
->kref
, fc_rport_destroy
);
1302 * fc_rport_rtv_resp() - Handler for Request Timeout Value (RTV) responses
1303 * @sp: The sequence the RTV was on
1304 * @fp: The RTV response frame
1305 * @rdata_arg: The remote port that sent the RTV response
1307 * Many targets don't seem to support this.
1309 * Locking Note: This function will be called without the rport lock
1310 * held, but it will lock, call an _enter_* function or fc_rport_error
1311 * and then unlock the rport.
1313 static void fc_rport_rtv_resp(struct fc_seq
*sp
, struct fc_frame
*fp
,
1316 struct fc_rport_priv
*rdata
= rdata_arg
;
1319 FC_RPORT_DBG(rdata
, "Received a RTV %s\n", fc_els_resp_type(fp
));
1321 if (fp
== ERR_PTR(-FC_EX_CLOSED
))
1324 mutex_lock(&rdata
->rp_mutex
);
1326 if (rdata
->rp_state
!= RPORT_ST_RTV
) {
1327 FC_RPORT_DBG(rdata
, "Received a RTV response, but in state "
1328 "%s\n", fc_rport_state(rdata
));
1335 fc_rport_error(rdata
, PTR_ERR(fp
));
1339 op
= fc_frame_payload_op(fp
);
1340 if (op
== ELS_LS_ACC
) {
1341 struct fc_els_rtv_acc
*rtv
;
1345 rtv
= fc_frame_payload_get(fp
, sizeof(*rtv
));
1347 toq
= ntohl(rtv
->rtv_toq
);
1348 tov
= ntohl(rtv
->rtv_r_a_tov
);
1351 if (tov
> rdata
->r_a_tov
)
1352 rdata
->r_a_tov
= tov
;
1353 tov
= ntohl(rtv
->rtv_e_d_tov
);
1354 if (toq
& FC_ELS_RTV_EDRES
)
1358 if (tov
> rdata
->e_d_tov
)
1359 rdata
->e_d_tov
= tov
;
1363 fc_rport_enter_ready(rdata
);
1368 mutex_unlock(&rdata
->rp_mutex
);
1370 kref_put(&rdata
->kref
, fc_rport_destroy
);
1374 * fc_rport_enter_rtv() - Send Request Timeout Value (RTV) request
1375 * @rdata: The remote port to send the RTV request to
1377 * Reference counting: increments kref when sending ELS
1379 static void fc_rport_enter_rtv(struct fc_rport_priv
*rdata
)
1381 struct fc_frame
*fp
;
1382 struct fc_lport
*lport
= rdata
->local_port
;
1384 lockdep_assert_held(&rdata
->rp_mutex
);
1386 FC_RPORT_DBG(rdata
, "Port entered RTV state from %s state\n",
1387 fc_rport_state(rdata
));
1389 fc_rport_state_enter(rdata
, RPORT_ST_RTV
);
1391 fp
= fc_frame_alloc(lport
, sizeof(struct fc_els_rtv
));
1393 fc_rport_error_retry(rdata
, -FC_EX_ALLOC_ERR
);
1397 kref_get(&rdata
->kref
);
1398 if (!lport
->tt
.elsct_send(lport
, rdata
->ids
.port_id
, fp
, ELS_RTV
,
1399 fc_rport_rtv_resp
, rdata
,
1400 2 * lport
->r_a_tov
)) {
1401 fc_rport_error_retry(rdata
, -FC_EX_XMIT_ERR
);
1402 kref_put(&rdata
->kref
, fc_rport_destroy
);
1407 * fc_rport_recv_rtv_req() - Handler for Read Timeout Value (RTV) requests
1408 * @rdata: The remote port that sent the RTV request
1409 * @in_fp: The RTV request frame
1411 static void fc_rport_recv_rtv_req(struct fc_rport_priv
*rdata
,
1412 struct fc_frame
*in_fp
)
1414 struct fc_lport
*lport
= rdata
->local_port
;
1415 struct fc_frame
*fp
;
1416 struct fc_els_rtv_acc
*rtv
;
1417 struct fc_seq_els_data rjt_data
;
1419 lockdep_assert_held(&rdata
->rp_mutex
);
1420 lockdep_assert_held(&lport
->lp_mutex
);
1422 FC_RPORT_DBG(rdata
, "Received RTV request\n");
1424 fp
= fc_frame_alloc(lport
, sizeof(*rtv
));
1426 rjt_data
.reason
= ELS_RJT_UNAB
;
1427 rjt_data
.explan
= ELS_EXPL_INSUF_RES
;
1428 fc_seq_els_rsp_send(in_fp
, ELS_LS_RJT
, &rjt_data
);
1431 rtv
= fc_frame_payload_get(fp
, sizeof(*rtv
));
1432 rtv
->rtv_cmd
= ELS_LS_ACC
;
1433 rtv
->rtv_r_a_tov
= htonl(lport
->r_a_tov
);
1434 rtv
->rtv_e_d_tov
= htonl(lport
->e_d_tov
);
1436 fc_fill_reply_hdr(fp
, in_fp
, FC_RCTL_ELS_REP
, 0);
1437 lport
->tt
.frame_send(lport
, fp
);
1439 fc_frame_free(in_fp
);
1443 * fc_rport_logo_resp() - Handler for logout (LOGO) responses
1444 * @sp: The sequence the LOGO was on
1445 * @fp: The LOGO response frame
1446 * @lport_arg: The local port
1448 static void fc_rport_logo_resp(struct fc_seq
*sp
, struct fc_frame
*fp
,
1451 struct fc_rport_priv
*rdata
= rdata_arg
;
1452 struct fc_lport
*lport
= rdata
->local_port
;
1454 FC_RPORT_ID_DBG(lport
, fc_seq_exch(sp
)->did
,
1455 "Received a LOGO %s\n", fc_els_resp_type(fp
));
1458 kref_put(&rdata
->kref
, fc_rport_destroy
);
1462 * fc_rport_enter_logo() - Send a logout (LOGO) request
1463 * @rdata: The remote port to send the LOGO request to
1465 * Reference counting: increments kref when sending ELS
1467 static void fc_rport_enter_logo(struct fc_rport_priv
*rdata
)
1469 struct fc_lport
*lport
= rdata
->local_port
;
1470 struct fc_frame
*fp
;
1472 lockdep_assert_held(&rdata
->rp_mutex
);
1474 FC_RPORT_DBG(rdata
, "Port sending LOGO from %s state\n",
1475 fc_rport_state(rdata
));
1477 fp
= fc_frame_alloc(lport
, sizeof(struct fc_els_logo
));
1480 kref_get(&rdata
->kref
);
1481 if (!lport
->tt
.elsct_send(lport
, rdata
->ids
.port_id
, fp
, ELS_LOGO
,
1482 fc_rport_logo_resp
, rdata
, 0))
1483 kref_put(&rdata
->kref
, fc_rport_destroy
);
1487 * fc_rport_els_adisc_resp() - Handler for Address Discovery (ADISC) responses
1488 * @sp: The sequence the ADISC response was on
1489 * @fp: The ADISC response frame
1490 * @rdata_arg: The remote port that sent the ADISC response
1492 * Locking Note: This function will be called without the rport lock
1493 * held, but it will lock, call an _enter_* function or fc_rport_error
1494 * and then unlock the rport.
1496 static void fc_rport_adisc_resp(struct fc_seq
*sp
, struct fc_frame
*fp
,
1499 struct fc_rport_priv
*rdata
= rdata_arg
;
1500 struct fc_els_adisc
*adisc
;
1503 FC_RPORT_DBG(rdata
, "Received a ADISC response\n");
1505 if (fp
== ERR_PTR(-FC_EX_CLOSED
))
1508 mutex_lock(&rdata
->rp_mutex
);
1510 if (rdata
->rp_state
!= RPORT_ST_ADISC
) {
1511 FC_RPORT_DBG(rdata
, "Received a ADISC resp but in state %s\n",
1512 fc_rport_state(rdata
));
1519 fc_rport_error(rdata
, PTR_ERR(fp
));
1524 * If address verification failed. Consider us logged out of the rport.
1525 * Since the rport is still in discovery, we want to be
1526 * logged in, so go to PLOGI state. Otherwise, go back to READY.
1528 op
= fc_frame_payload_op(fp
);
1529 adisc
= fc_frame_payload_get(fp
, sizeof(*adisc
));
1530 if (op
!= ELS_LS_ACC
|| !adisc
||
1531 ntoh24(adisc
->adisc_port_id
) != rdata
->ids
.port_id
||
1532 get_unaligned_be64(&adisc
->adisc_wwpn
) != rdata
->ids
.port_name
||
1533 get_unaligned_be64(&adisc
->adisc_wwnn
) != rdata
->ids
.node_name
) {
1534 FC_RPORT_DBG(rdata
, "ADISC error or mismatch\n");
1535 fc_rport_enter_flogi(rdata
);
1537 FC_RPORT_DBG(rdata
, "ADISC OK\n");
1538 fc_rport_enter_ready(rdata
);
1543 mutex_unlock(&rdata
->rp_mutex
);
1545 kref_put(&rdata
->kref
, fc_rport_destroy
);
1549 * fc_rport_enter_adisc() - Send Address Discover (ADISC) request
1550 * @rdata: The remote port to send the ADISC request to
1552 * Reference counting: increments kref when sending ELS
1554 static void fc_rport_enter_adisc(struct fc_rport_priv
*rdata
)
1556 struct fc_lport
*lport
= rdata
->local_port
;
1557 struct fc_frame
*fp
;
1559 lockdep_assert_held(&rdata
->rp_mutex
);
1561 FC_RPORT_DBG(rdata
, "sending ADISC from %s state\n",
1562 fc_rport_state(rdata
));
1564 fc_rport_state_enter(rdata
, RPORT_ST_ADISC
);
1566 fp
= fc_frame_alloc(lport
, sizeof(struct fc_els_adisc
));
1568 fc_rport_error_retry(rdata
, -FC_EX_ALLOC_ERR
);
1571 kref_get(&rdata
->kref
);
1572 if (!lport
->tt
.elsct_send(lport
, rdata
->ids
.port_id
, fp
, ELS_ADISC
,
1573 fc_rport_adisc_resp
, rdata
,
1574 2 * lport
->r_a_tov
)) {
1575 fc_rport_error_retry(rdata
, -FC_EX_XMIT_ERR
);
1576 kref_put(&rdata
->kref
, fc_rport_destroy
);
1581 * fc_rport_recv_adisc_req() - Handler for Address Discovery (ADISC) requests
1582 * @rdata: The remote port that sent the ADISC request
1583 * @in_fp: The ADISC request frame
1585 static void fc_rport_recv_adisc_req(struct fc_rport_priv
*rdata
,
1586 struct fc_frame
*in_fp
)
1588 struct fc_lport
*lport
= rdata
->local_port
;
1589 struct fc_frame
*fp
;
1590 struct fc_els_adisc
*adisc
;
1591 struct fc_seq_els_data rjt_data
;
1593 lockdep_assert_held(&rdata
->rp_mutex
);
1594 lockdep_assert_held(&lport
->lp_mutex
);
1596 FC_RPORT_DBG(rdata
, "Received ADISC request\n");
1598 adisc
= fc_frame_payload_get(in_fp
, sizeof(*adisc
));
1600 rjt_data
.reason
= ELS_RJT_PROT
;
1601 rjt_data
.explan
= ELS_EXPL_INV_LEN
;
1602 fc_seq_els_rsp_send(in_fp
, ELS_LS_RJT
, &rjt_data
);
1606 fp
= fc_frame_alloc(lport
, sizeof(*adisc
));
1609 fc_adisc_fill(lport
, fp
);
1610 adisc
= fc_frame_payload_get(fp
, sizeof(*adisc
));
1611 adisc
->adisc_cmd
= ELS_LS_ACC
;
1612 fc_fill_reply_hdr(fp
, in_fp
, FC_RCTL_ELS_REP
, 0);
1613 lport
->tt
.frame_send(lport
, fp
);
1615 fc_frame_free(in_fp
);
1619 * fc_rport_recv_rls_req() - Handle received Read Link Status request
1620 * @rdata: The remote port that sent the RLS request
1621 * @rx_fp: The PRLI request frame
1623 static void fc_rport_recv_rls_req(struct fc_rport_priv
*rdata
,
1624 struct fc_frame
*rx_fp
)
1627 struct fc_lport
*lport
= rdata
->local_port
;
1628 struct fc_frame
*fp
;
1629 struct fc_els_rls
*rls
;
1630 struct fc_els_rls_resp
*rsp
;
1631 struct fc_els_lesb
*lesb
;
1632 struct fc_seq_els_data rjt_data
;
1633 struct fc_host_statistics
*hst
;
1635 lockdep_assert_held(&rdata
->rp_mutex
);
1637 FC_RPORT_DBG(rdata
, "Received RLS request while in state %s\n",
1638 fc_rport_state(rdata
));
1640 rls
= fc_frame_payload_get(rx_fp
, sizeof(*rls
));
1642 rjt_data
.reason
= ELS_RJT_PROT
;
1643 rjt_data
.explan
= ELS_EXPL_INV_LEN
;
1647 fp
= fc_frame_alloc(lport
, sizeof(*rsp
));
1649 rjt_data
.reason
= ELS_RJT_UNAB
;
1650 rjt_data
.explan
= ELS_EXPL_INSUF_RES
;
1654 rsp
= fc_frame_payload_get(fp
, sizeof(*rsp
));
1655 memset(rsp
, 0, sizeof(*rsp
));
1656 rsp
->rls_cmd
= ELS_LS_ACC
;
1657 lesb
= &rsp
->rls_lesb
;
1658 if (lport
->tt
.get_lesb
) {
1659 /* get LESB from LLD if it supports it */
1660 lport
->tt
.get_lesb(lport
, lesb
);
1662 fc_get_host_stats(lport
->host
);
1663 hst
= &lport
->host_stats
;
1664 lesb
->lesb_link_fail
= htonl(hst
->link_failure_count
);
1665 lesb
->lesb_sync_loss
= htonl(hst
->loss_of_sync_count
);
1666 lesb
->lesb_sig_loss
= htonl(hst
->loss_of_signal_count
);
1667 lesb
->lesb_prim_err
= htonl(hst
->prim_seq_protocol_err_count
);
1668 lesb
->lesb_inv_word
= htonl(hst
->invalid_tx_word_count
);
1669 lesb
->lesb_inv_crc
= htonl(hst
->invalid_crc_count
);
1672 fc_fill_reply_hdr(fp
, rx_fp
, FC_RCTL_ELS_REP
, 0);
1673 lport
->tt
.frame_send(lport
, fp
);
1677 fc_seq_els_rsp_send(rx_fp
, ELS_LS_RJT
, &rjt_data
);
1679 fc_frame_free(rx_fp
);
1683 * fc_rport_recv_els_req() - Handler for validated ELS requests
1684 * @lport: The local port that received the ELS request
1685 * @fp: The ELS request frame
1687 * Handle incoming ELS requests that require port login.
1688 * The ELS opcode has already been validated by the caller.
1690 * Reference counting: does not modify kref
1692 static void fc_rport_recv_els_req(struct fc_lport
*lport
, struct fc_frame
*fp
)
1694 struct fc_rport_priv
*rdata
;
1695 struct fc_seq_els_data els_data
;
1697 lockdep_assert_held(&lport
->lp_mutex
);
1699 rdata
= fc_rport_lookup(lport
, fc_frame_sid(fp
));
1701 FC_RPORT_ID_DBG(lport
, fc_frame_sid(fp
),
1702 "Received ELS 0x%02x from non-logged-in port\n",
1703 fc_frame_payload_op(fp
));
1707 mutex_lock(&rdata
->rp_mutex
);
1709 switch (rdata
->rp_state
) {
1712 case RPORT_ST_READY
:
1713 case RPORT_ST_ADISC
:
1715 case RPORT_ST_PLOGI
:
1716 if (fc_frame_payload_op(fp
) == ELS_PRLI
) {
1717 FC_RPORT_DBG(rdata
, "Reject ELS PRLI "
1718 "while in state %s\n",
1719 fc_rport_state(rdata
));
1720 mutex_unlock(&rdata
->rp_mutex
);
1721 kref_put(&rdata
->kref
, fc_rport_destroy
);
1727 "Reject ELS 0x%02x while in state %s\n",
1728 fc_frame_payload_op(fp
), fc_rport_state(rdata
));
1729 mutex_unlock(&rdata
->rp_mutex
);
1730 kref_put(&rdata
->kref
, fc_rport_destroy
);
1734 switch (fc_frame_payload_op(fp
)) {
1736 fc_rport_recv_prli_req(rdata
, fp
);
1739 fc_rport_recv_prlo_req(rdata
, fp
);
1742 fc_rport_recv_adisc_req(rdata
, fp
);
1745 fc_seq_els_rsp_send(fp
, ELS_RRQ
, NULL
);
1749 fc_seq_els_rsp_send(fp
, ELS_REC
, NULL
);
1753 fc_rport_recv_rls_req(rdata
, fp
);
1756 fc_rport_recv_rtv_req(rdata
, fp
);
1759 fc_frame_free(fp
); /* can't happen */
1763 mutex_unlock(&rdata
->rp_mutex
);
1764 kref_put(&rdata
->kref
, fc_rport_destroy
);
1768 els_data
.reason
= ELS_RJT_UNAB
;
1769 els_data
.explan
= ELS_EXPL_PLOGI_REQD
;
1770 fc_seq_els_rsp_send(fp
, ELS_LS_RJT
, &els_data
);
1775 els_data
.reason
= ELS_RJT_BUSY
;
1776 els_data
.explan
= ELS_EXPL_NONE
;
1777 fc_seq_els_rsp_send(fp
, ELS_LS_RJT
, &els_data
);
1783 * fc_rport_recv_req() - Handler for requests
1784 * @lport: The local port that received the request
1785 * @fp: The request frame
1787 * Reference counting: does not modify kref
1789 void fc_rport_recv_req(struct fc_lport
*lport
, struct fc_frame
*fp
)
1791 struct fc_seq_els_data els_data
;
1793 lockdep_assert_held(&lport
->lp_mutex
);
1796 * Handle FLOGI, PLOGI and LOGO requests separately, since they
1797 * don't require prior login.
1798 * Check for unsupported opcodes first and reject them.
1799 * For some ops, it would be incorrect to reject with "PLOGI required".
1801 switch (fc_frame_payload_op(fp
)) {
1803 fc_rport_recv_flogi_req(lport
, fp
);
1806 fc_rport_recv_plogi_req(lport
, fp
);
1809 fc_rport_recv_logo_req(lport
, fp
);
1818 fc_rport_recv_els_req(lport
, fp
);
1821 els_data
.reason
= ELS_RJT_UNSUP
;
1822 els_data
.explan
= ELS_EXPL_NONE
;
1823 fc_seq_els_rsp_send(fp
, ELS_LS_RJT
, &els_data
);
1828 EXPORT_SYMBOL(fc_rport_recv_req
);
1831 * fc_rport_recv_plogi_req() - Handler for Port Login (PLOGI) requests
1832 * @lport: The local port that received the PLOGI request
1833 * @rx_fp: The PLOGI request frame
1835 * Reference counting: increments kref on return
1837 static void fc_rport_recv_plogi_req(struct fc_lport
*lport
,
1838 struct fc_frame
*rx_fp
)
1840 struct fc_disc
*disc
;
1841 struct fc_rport_priv
*rdata
;
1842 struct fc_frame
*fp
= rx_fp
;
1843 struct fc_els_flogi
*pl
;
1844 struct fc_seq_els_data rjt_data
;
1847 lockdep_assert_held(&lport
->lp_mutex
);
1849 sid
= fc_frame_sid(fp
);
1851 FC_RPORT_ID_DBG(lport
, sid
, "Received PLOGI request\n");
1853 pl
= fc_frame_payload_get(fp
, sizeof(*pl
));
1855 FC_RPORT_ID_DBG(lport
, sid
, "Received PLOGI too short\n");
1856 rjt_data
.reason
= ELS_RJT_PROT
;
1857 rjt_data
.explan
= ELS_EXPL_INV_LEN
;
1861 disc
= &lport
->disc
;
1862 mutex_lock(&disc
->disc_mutex
);
1863 rdata
= fc_rport_create(lport
, sid
);
1865 mutex_unlock(&disc
->disc_mutex
);
1866 rjt_data
.reason
= ELS_RJT_UNAB
;
1867 rjt_data
.explan
= ELS_EXPL_INSUF_RES
;
1871 mutex_lock(&rdata
->rp_mutex
);
1872 mutex_unlock(&disc
->disc_mutex
);
1874 rdata
->ids
.port_name
= get_unaligned_be64(&pl
->fl_wwpn
);
1875 rdata
->ids
.node_name
= get_unaligned_be64(&pl
->fl_wwnn
);
1878 * If the rport was just created, possibly due to the incoming PLOGI,
1879 * set the state appropriately and accept the PLOGI.
1881 * If we had also sent a PLOGI, and if the received PLOGI is from a
1882 * higher WWPN, we accept it, otherwise an LS_RJT is sent with reason
1883 * "command already in progress".
1885 * XXX TBD: If the session was ready before, the PLOGI should result in
1886 * all outstanding exchanges being reset.
1888 switch (rdata
->rp_state
) {
1890 FC_RPORT_DBG(rdata
, "Received PLOGI in INIT state\n");
1892 case RPORT_ST_PLOGI_WAIT
:
1893 FC_RPORT_DBG(rdata
, "Received PLOGI in PLOGI_WAIT state\n");
1895 case RPORT_ST_PLOGI
:
1896 FC_RPORT_DBG(rdata
, "Received PLOGI in PLOGI state\n");
1897 if (rdata
->ids
.port_name
< lport
->wwpn
) {
1898 mutex_unlock(&rdata
->rp_mutex
);
1899 rjt_data
.reason
= ELS_RJT_INPROG
;
1900 rjt_data
.explan
= ELS_EXPL_NONE
;
1906 case RPORT_ST_READY
:
1907 case RPORT_ST_ADISC
:
1908 FC_RPORT_DBG(rdata
, "Received PLOGI in logged-in state %d "
1909 "- ignored for now\n", rdata
->rp_state
);
1910 /* XXX TBD - should reset */
1912 case RPORT_ST_FLOGI
:
1913 case RPORT_ST_DELETE
:
1914 FC_RPORT_DBG(rdata
, "Received PLOGI in state %s - send busy\n",
1915 fc_rport_state(rdata
));
1916 mutex_unlock(&rdata
->rp_mutex
);
1917 rjt_data
.reason
= ELS_RJT_BUSY
;
1918 rjt_data
.explan
= ELS_EXPL_NONE
;
1921 if (!fc_rport_compatible_roles(lport
, rdata
)) {
1922 FC_RPORT_DBG(rdata
, "Received PLOGI for incompatible role\n");
1923 mutex_unlock(&rdata
->rp_mutex
);
1924 rjt_data
.reason
= ELS_RJT_LOGIC
;
1925 rjt_data
.explan
= ELS_EXPL_NONE
;
1930 * Get session payload size from incoming PLOGI.
1932 rdata
->maxframe_size
= fc_plogi_get_maxframe(pl
, lport
->mfs
);
1935 * Send LS_ACC. If this fails, the originator should retry.
1937 fp
= fc_frame_alloc(lport
, sizeof(*pl
));
1941 fc_plogi_fill(lport
, fp
, ELS_LS_ACC
);
1942 fc_fill_reply_hdr(fp
, rx_fp
, FC_RCTL_ELS_REP
, 0);
1943 lport
->tt
.frame_send(lport
, fp
);
1944 fc_rport_enter_prli(rdata
);
1946 mutex_unlock(&rdata
->rp_mutex
);
1947 fc_frame_free(rx_fp
);
1951 fc_seq_els_rsp_send(fp
, ELS_LS_RJT
, &rjt_data
);
1956 * fc_rport_recv_prli_req() - Handler for process login (PRLI) requests
1957 * @rdata: The remote port that sent the PRLI request
1958 * @rx_fp: The PRLI request frame
1960 static void fc_rport_recv_prli_req(struct fc_rport_priv
*rdata
,
1961 struct fc_frame
*rx_fp
)
1963 struct fc_lport
*lport
= rdata
->local_port
;
1964 struct fc_frame
*fp
;
1966 struct fc_els_prli prli
;
1967 struct fc_els_spp spp
;
1969 struct fc_els_spp
*rspp
; /* request service param page */
1970 struct fc_els_spp
*spp
; /* response spp */
1973 enum fc_els_spp_resp resp
;
1974 struct fc_seq_els_data rjt_data
;
1975 struct fc4_prov
*prov
;
1977 lockdep_assert_held(&rdata
->rp_mutex
);
1979 FC_RPORT_DBG(rdata
, "Received PRLI request while in state %s\n",
1980 fc_rport_state(rdata
));
1982 len
= fr_len(rx_fp
) - sizeof(struct fc_frame_header
);
1983 pp
= fc_frame_payload_get(rx_fp
, sizeof(*pp
));
1986 plen
= ntohs(pp
->prli
.prli_len
);
1987 if ((plen
% 4) != 0 || plen
> len
|| plen
< 16)
1991 plen
= pp
->prli
.prli_spp_len
;
1992 if ((plen
% 4) != 0 || plen
< sizeof(*spp
) ||
1993 plen
> len
|| len
< sizeof(*pp
) || plen
< 12)
1997 fp
= fc_frame_alloc(lport
, len
);
1999 rjt_data
.reason
= ELS_RJT_UNAB
;
2000 rjt_data
.explan
= ELS_EXPL_INSUF_RES
;
2003 pp
= fc_frame_payload_get(fp
, len
);
2006 pp
->prli
.prli_cmd
= ELS_LS_ACC
;
2007 pp
->prli
.prli_spp_len
= plen
;
2008 pp
->prli
.prli_len
= htons(len
);
2009 len
-= sizeof(struct fc_els_prli
);
2012 * Go through all the service parameter pages and build
2013 * response. If plen indicates longer SPP than standard,
2014 * use that. The entire response has been pre-cleared above.
2017 mutex_lock(&fc_prov_mutex
);
2018 while (len
>= plen
) {
2019 rdata
->spp_type
= rspp
->spp_type
;
2020 spp
->spp_type
= rspp
->spp_type
;
2021 spp
->spp_type_ext
= rspp
->spp_type_ext
;
2024 if (rspp
->spp_type
< FC_FC4_PROV_SIZE
) {
2025 enum fc_els_spp_resp active
= 0, passive
= 0;
2027 prov
= fc_active_prov
[rspp
->spp_type
];
2029 active
= prov
->prli(rdata
, plen
, rspp
, spp
);
2030 prov
= fc_passive_prov
[rspp
->spp_type
];
2032 passive
= prov
->prli(rdata
, plen
, rspp
, spp
);
2033 if (!active
|| passive
== FC_SPP_RESP_ACK
)
2037 FC_RPORT_DBG(rdata
, "PRLI rspp type %x "
2038 "active %x passive %x\n",
2039 rspp
->spp_type
, active
, passive
);
2042 if (spp
->spp_flags
& FC_SPP_EST_IMG_PAIR
)
2043 resp
|= FC_SPP_RESP_CONF
;
2045 resp
|= FC_SPP_RESP_INVL
;
2047 spp
->spp_flags
|= resp
;
2049 rspp
= (struct fc_els_spp
*)((char *)rspp
+ plen
);
2050 spp
= (struct fc_els_spp
*)((char *)spp
+ plen
);
2052 mutex_unlock(&fc_prov_mutex
);
2055 * Send LS_ACC. If this fails, the originator should retry.
2057 fc_fill_reply_hdr(fp
, rx_fp
, FC_RCTL_ELS_REP
, 0);
2058 lport
->tt
.frame_send(lport
, fp
);
2063 rjt_data
.reason
= ELS_RJT_PROT
;
2064 rjt_data
.explan
= ELS_EXPL_INV_LEN
;
2066 fc_seq_els_rsp_send(rx_fp
, ELS_LS_RJT
, &rjt_data
);
2068 fc_frame_free(rx_fp
);
2072 * fc_rport_recv_prlo_req() - Handler for process logout (PRLO) requests
2073 * @rdata: The remote port that sent the PRLO request
2074 * @rx_fp: The PRLO request frame
2076 static void fc_rport_recv_prlo_req(struct fc_rport_priv
*rdata
,
2077 struct fc_frame
*rx_fp
)
2079 struct fc_lport
*lport
= rdata
->local_port
;
2080 struct fc_frame
*fp
;
2082 struct fc_els_prlo prlo
;
2083 struct fc_els_spp spp
;
2085 struct fc_els_spp
*rspp
; /* request service param page */
2086 struct fc_els_spp
*spp
; /* response spp */
2089 struct fc_seq_els_data rjt_data
;
2091 lockdep_assert_held(&rdata
->rp_mutex
);
2093 FC_RPORT_DBG(rdata
, "Received PRLO request while in state %s\n",
2094 fc_rport_state(rdata
));
2096 len
= fr_len(rx_fp
) - sizeof(struct fc_frame_header
);
2097 pp
= fc_frame_payload_get(rx_fp
, sizeof(*pp
));
2100 plen
= ntohs(pp
->prlo
.prlo_len
);
2108 fp
= fc_frame_alloc(lport
, len
);
2110 rjt_data
.reason
= ELS_RJT_UNAB
;
2111 rjt_data
.explan
= ELS_EXPL_INSUF_RES
;
2115 pp
= fc_frame_payload_get(fp
, len
);
2118 pp
->prlo
.prlo_cmd
= ELS_LS_ACC
;
2119 pp
->prlo
.prlo_obs
= 0x10;
2120 pp
->prlo
.prlo_len
= htons(len
);
2122 spp
->spp_type
= rspp
->spp_type
;
2123 spp
->spp_type_ext
= rspp
->spp_type_ext
;
2124 spp
->spp_flags
= FC_SPP_RESP_ACK
;
2126 fc_rport_enter_prli(rdata
);
2128 fc_fill_reply_hdr(fp
, rx_fp
, FC_RCTL_ELS_REP
, 0);
2129 lport
->tt
.frame_send(lport
, fp
);
2133 rjt_data
.reason
= ELS_RJT_PROT
;
2134 rjt_data
.explan
= ELS_EXPL_INV_LEN
;
2136 fc_seq_els_rsp_send(rx_fp
, ELS_LS_RJT
, &rjt_data
);
2138 fc_frame_free(rx_fp
);
2142 * fc_rport_recv_logo_req() - Handler for logout (LOGO) requests
2143 * @lport: The local port that received the LOGO request
2144 * @fp: The LOGO request frame
2146 * Reference counting: drops kref on return
2148 static void fc_rport_recv_logo_req(struct fc_lport
*lport
, struct fc_frame
*fp
)
2150 struct fc_rport_priv
*rdata
;
2153 lockdep_assert_held(&lport
->lp_mutex
);
2155 fc_seq_els_rsp_send(fp
, ELS_LS_ACC
, NULL
);
2157 sid
= fc_frame_sid(fp
);
2159 rdata
= fc_rport_lookup(lport
, sid
);
2161 mutex_lock(&rdata
->rp_mutex
);
2162 FC_RPORT_DBG(rdata
, "Received LOGO request while in state %s\n",
2163 fc_rport_state(rdata
));
2165 fc_rport_enter_delete(rdata
, RPORT_EV_STOP
);
2166 mutex_unlock(&rdata
->rp_mutex
);
2167 kref_put(&rdata
->kref
, fc_rport_destroy
);
2169 FC_RPORT_ID_DBG(lport
, sid
,
2170 "Received LOGO from non-logged-in port\n");
2175 * fc_rport_flush_queue() - Flush the rport_event_queue
2177 void fc_rport_flush_queue(void)
2179 flush_workqueue(rport_event_queue
);
2181 EXPORT_SYMBOL(fc_rport_flush_queue
);
2184 * fc_rport_fcp_prli() - Handle incoming PRLI for the FCP initiator.
2185 * @rdata: remote port private
2186 * @spp_len: service parameter page length
2187 * @rspp: received service parameter page
2188 * @spp: response service parameter page
2190 * Returns the value for the response code to be placed in spp_flags;
2191 * Returns 0 if not an initiator.
2193 static int fc_rport_fcp_prli(struct fc_rport_priv
*rdata
, u32 spp_len
,
2194 const struct fc_els_spp
*rspp
,
2195 struct fc_els_spp
*spp
)
2197 struct fc_lport
*lport
= rdata
->local_port
;
2200 fcp_parm
= ntohl(rspp
->spp_params
);
2201 rdata
->ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2202 if (fcp_parm
& FCP_SPPF_INIT_FCN
)
2203 rdata
->ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
2204 if (fcp_parm
& FCP_SPPF_TARG_FCN
)
2205 rdata
->ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
2206 if (fcp_parm
& FCP_SPPF_RETRY
)
2207 rdata
->flags
|= FC_RP_FLAGS_RETRY
;
2208 rdata
->supported_classes
= FC_COS_CLASS3
;
2210 if (!(lport
->service_params
& FCP_SPPF_INIT_FCN
))
2213 spp
->spp_flags
|= rspp
->spp_flags
& FC_SPP_EST_IMG_PAIR
;
2216 * OR in our service parameters with other providers (target), if any.
2218 fcp_parm
= ntohl(spp
->spp_params
);
2219 spp
->spp_params
= htonl(fcp_parm
| lport
->service_params
);
2220 return FC_SPP_RESP_ACK
;
2224 * FC-4 provider ops for FCP initiator.
2226 struct fc4_prov fc_rport_fcp_init
= {
2227 .prli
= fc_rport_fcp_prli
,
2231 * fc_rport_t0_prli() - Handle incoming PRLI parameters for type 0
2232 * @rdata: remote port private
2233 * @spp_len: service parameter page length
2234 * @rspp: received service parameter page
2235 * @spp: response service parameter page
2237 static int fc_rport_t0_prli(struct fc_rport_priv
*rdata
, u32 spp_len
,
2238 const struct fc_els_spp
*rspp
,
2239 struct fc_els_spp
*spp
)
2241 if (rspp
->spp_flags
& FC_SPP_EST_IMG_PAIR
)
2242 return FC_SPP_RESP_INVL
;
2243 return FC_SPP_RESP_ACK
;
2247 * FC-4 provider ops for type 0 service parameters.
2249 * This handles the special case of type 0 which is always successful
2250 * but doesn't do anything otherwise.
2252 struct fc4_prov fc_rport_t0_prov
= {
2253 .prli
= fc_rport_t0_prli
,
2257 * fc_setup_rport() - Initialize the rport_event_queue
2259 int fc_setup_rport(void)
2261 rport_event_queue
= create_singlethread_workqueue("fc_rport_eq");
2262 if (!rport_event_queue
)
2268 * fc_destroy_rport() - Destroy the rport_event_queue
2270 void fc_destroy_rport(void)
2272 destroy_workqueue(rport_event_queue
);
2276 * fc_rport_terminate_io() - Stop all outstanding I/O on a remote port
2277 * @rport: The remote port whose I/O should be terminated
2279 void fc_rport_terminate_io(struct fc_rport
*rport
)
2281 struct fc_rport_libfc_priv
*rpriv
= rport
->dd_data
;
2282 struct fc_lport
*lport
= rpriv
->local_port
;
2284 lport
->tt
.exch_mgr_reset(lport
, 0, rport
->port_id
);
2285 lport
->tt
.exch_mgr_reset(lport
, rport
->port_id
, 0);
2287 EXPORT_SYMBOL(fc_rport_terminate_io
);