2 * Copyright(c) 2007 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 * These comments only apply to the 'port code' which consists of the lport,
24 * disc and rport blocks.
28 * The lport, disc and rport blocks all have mutexes that are used to protect
29 * those objects. The main motivation for these locks is to prevent from
30 * having an lport reset just before we send a frame. In that scenario the
31 * lport's FID would get set to zero and then we'd send a frame with an
32 * invalid SID. We also need to ensure that states don't change unexpectedly
33 * while processing another state.
37 * The following heirarchy defines the locking rules. A greater lock
38 * may be held before acquiring a lesser lock, but a lesser lock should never
39 * be held while attempting to acquire a greater lock. Here is the heirarchy-
41 * lport > disc, lport > rport, disc > rport
45 * The callbacks cause complications with this scheme. There is a callback
46 * from the rport (to either lport or disc) and a callback from disc
49 * As rports exit the rport state machine a callback is made to the owner of
50 * the rport to notify success or failure. Since the callback is likely to
51 * cause the lport or disc to grab its lock we cannot hold the rport lock
52 * while making the callback. To ensure that the rport is not free'd while
53 * processing the callback the rport callbacks are serialized through a
54 * single-threaded workqueue. An rport would never be free'd while in a
55 * callback handler becuase no other rport work in this queue can be executed
58 * When discovery succeeds or fails a callback is made to the lport as
59 * notification. Currently, succesful discovery causes the lport to take no
60 * action. A failure will cause the lport to reset. There is likely a circular
61 * locking problem with this implementation.
67 * The critical sections protected by the lport's mutex are quite broad and
68 * may be improved upon in the future. The lport code and its locking doesn't
69 * influence the I/O path, so excessive locking doesn't penalize I/O
72 * The strategy is to lock whenever processing a request or response. Note
73 * that every _enter_* function corresponds to a state change. They generally
74 * change the lports state and then send a request out on the wire. We lock
75 * before calling any of these functions to protect that state change. This
76 * means that the entry points into the lport block manage the locks while
77 * the state machine can transition between states (i.e. _enter_* functions)
78 * while always staying protected.
80 * When handling responses we also hold the lport mutex broadly. When the
81 * lport receives the response frame it locks the mutex and then calls the
82 * appropriate handler for the particuar response. Generally a response will
83 * trigger a state change and so the lock must already be held.
85 * Retries also have to consider the locking. The retries occur from a work
86 * context and the work function will lock the lport and then retry the state
87 * (i.e. _enter_* function).
90 #include <linux/timer.h>
91 #include <asm/unaligned.h>
93 #include <scsi/fc/fc_gs.h>
95 #include <scsi/libfc.h>
96 #include <scsi/fc_encode.h>
98 /* Fabric IDs to use for point-to-point mode, chosen on whims. */
99 #define FC_LOCAL_PTP_FID_LO 0x010101
100 #define FC_LOCAL_PTP_FID_HI 0x010102
102 #define DNS_DELAY 3 /* Discovery delay after RSCN (in seconds)*/
104 static int fc_lport_debug
;
106 #define FC_DEBUG_LPORT(fmt...) \
108 if (fc_lport_debug) \
112 static void fc_lport_error(struct fc_lport
*, struct fc_frame
*);
114 static void fc_lport_enter_reset(struct fc_lport
*);
115 static void fc_lport_enter_flogi(struct fc_lport
*);
116 static void fc_lport_enter_dns(struct fc_lport
*);
117 static void fc_lport_enter_rpn_id(struct fc_lport
*);
118 static void fc_lport_enter_rft_id(struct fc_lport
*);
119 static void fc_lport_enter_scr(struct fc_lport
*);
120 static void fc_lport_enter_ready(struct fc_lport
*);
121 static void fc_lport_enter_logo(struct fc_lport
*);
123 static const char *fc_lport_state_names
[] = {
124 [LPORT_ST_NONE
] = "none",
125 [LPORT_ST_FLOGI
] = "FLOGI",
126 [LPORT_ST_DNS
] = "dNS",
127 [LPORT_ST_RPN_ID
] = "RPN_ID",
128 [LPORT_ST_RFT_ID
] = "RFT_ID",
129 [LPORT_ST_SCR
] = "SCR",
130 [LPORT_ST_READY
] = "Ready",
131 [LPORT_ST_LOGO
] = "LOGO",
132 [LPORT_ST_RESET
] = "reset",
135 static int fc_frame_drop(struct fc_lport
*lport
, struct fc_frame
*fp
)
142 * fc_lport_rport_callback() - Event handler for rport events
143 * @lport: The lport which is receiving the event
144 * @rport: The rport which the event has occured on
145 * @event: The event that occured
147 * Locking Note: The rport lock should not be held when calling
150 static void fc_lport_rport_callback(struct fc_lport
*lport
,
151 struct fc_rport
*rport
,
152 enum fc_rport_event event
)
154 FC_DEBUG_LPORT("Received a %d event for port (%6x)\n", event
,
158 case RPORT_EV_CREATED
:
159 if (rport
->port_id
== FC_FID_DIR_SERV
) {
160 mutex_lock(&lport
->lp_mutex
);
161 if (lport
->state
== LPORT_ST_DNS
) {
162 lport
->dns_rp
= rport
;
163 fc_lport_enter_rpn_id(lport
);
165 FC_DEBUG_LPORT("Received an CREATED event on "
166 "port (%6x) for the directory "
167 "server, but the lport is not "
168 "in the DNS state, it's in the "
169 "%d state", rport
->port_id
,
171 lport
->tt
.rport_logoff(rport
);
173 mutex_unlock(&lport
->lp_mutex
);
175 FC_DEBUG_LPORT("Received an event for port (%6x) "
176 "which is not the directory server\n",
180 case RPORT_EV_FAILED
:
182 if (rport
->port_id
== FC_FID_DIR_SERV
) {
183 mutex_lock(&lport
->lp_mutex
);
184 lport
->dns_rp
= NULL
;
185 mutex_unlock(&lport
->lp_mutex
);
188 FC_DEBUG_LPORT("Received an event for port (%6x) "
189 "which is not the directory server\n",
198 * fc_lport_state() - Return a string which represents the lport's state
199 * @lport: The lport whose state is to converted to a string
201 static const char *fc_lport_state(struct fc_lport
*lport
)
205 cp
= fc_lport_state_names
[lport
->state
];
212 * fc_lport_ptp_setup() - Create an rport for point-to-point mode
213 * @lport: The lport to attach the ptp rport to
214 * @fid: The FID of the ptp rport
215 * @remote_wwpn: The WWPN of the ptp rport
216 * @remote_wwnn: The WWNN of the ptp rport
218 static void fc_lport_ptp_setup(struct fc_lport
*lport
,
219 u32 remote_fid
, u64 remote_wwpn
,
222 struct fc_disc_port dp
;
225 dp
.ids
.port_id
= remote_fid
;
226 dp
.ids
.port_name
= remote_wwpn
;
227 dp
.ids
.node_name
= remote_wwnn
;
228 dp
.ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
231 lport
->tt
.rport_logoff(lport
->ptp_rp
);
232 lport
->ptp_rp
= NULL
;
235 lport
->ptp_rp
= lport
->tt
.rport_create(&dp
);
237 lport
->tt
.rport_login(lport
->ptp_rp
);
239 fc_lport_enter_ready(lport
);
242 void fc_get_host_port_type(struct Scsi_Host
*shost
)
244 /* TODO - currently just NPORT */
245 fc_host_port_type(shost
) = FC_PORTTYPE_NPORT
;
247 EXPORT_SYMBOL(fc_get_host_port_type
);
249 void fc_get_host_port_state(struct Scsi_Host
*shost
)
251 struct fc_lport
*lp
= shost_priv(shost
);
254 fc_host_port_state(shost
) = FC_PORTSTATE_ONLINE
;
256 fc_host_port_state(shost
) = FC_PORTSTATE_OFFLINE
;
258 EXPORT_SYMBOL(fc_get_host_port_state
);
260 void fc_get_host_speed(struct Scsi_Host
*shost
)
262 struct fc_lport
*lport
= shost_priv(shost
);
264 fc_host_speed(shost
) = lport
->link_speed
;
266 EXPORT_SYMBOL(fc_get_host_speed
);
268 struct fc_host_statistics
*fc_get_host_stats(struct Scsi_Host
*shost
)
270 struct fc_host_statistics
*fcoe_stats
;
271 struct fc_lport
*lp
= shost_priv(shost
);
272 struct timespec v0
, v1
;
275 fcoe_stats
= &lp
->host_stats
;
276 memset(fcoe_stats
, 0, sizeof(struct fc_host_statistics
));
278 jiffies_to_timespec(jiffies
, &v0
);
279 jiffies_to_timespec(lp
->boot_time
, &v1
);
280 fcoe_stats
->seconds_since_last_reset
= (v0
.tv_sec
- v1
.tv_sec
);
282 for_each_possible_cpu(cpu
) {
283 struct fcoe_dev_stats
*stats
;
285 stats
= per_cpu_ptr(lp
->dev_stats
, cpu
);
287 fcoe_stats
->tx_frames
+= stats
->TxFrames
;
288 fcoe_stats
->tx_words
+= stats
->TxWords
;
289 fcoe_stats
->rx_frames
+= stats
->RxFrames
;
290 fcoe_stats
->rx_words
+= stats
->RxWords
;
291 fcoe_stats
->error_frames
+= stats
->ErrorFrames
;
292 fcoe_stats
->invalid_crc_count
+= stats
->InvalidCRCCount
;
293 fcoe_stats
->fcp_input_requests
+= stats
->InputRequests
;
294 fcoe_stats
->fcp_output_requests
+= stats
->OutputRequests
;
295 fcoe_stats
->fcp_control_requests
+= stats
->ControlRequests
;
296 fcoe_stats
->fcp_input_megabytes
+= stats
->InputMegabytes
;
297 fcoe_stats
->fcp_output_megabytes
+= stats
->OutputMegabytes
;
298 fcoe_stats
->link_failure_count
+= stats
->LinkFailureCount
;
300 fcoe_stats
->lip_count
= -1;
301 fcoe_stats
->nos_count
= -1;
302 fcoe_stats
->loss_of_sync_count
= -1;
303 fcoe_stats
->loss_of_signal_count
= -1;
304 fcoe_stats
->prim_seq_protocol_err_count
= -1;
305 fcoe_stats
->dumped_frames
= -1;
308 EXPORT_SYMBOL(fc_get_host_stats
);
311 * Fill in FLOGI command for request.
314 fc_lport_flogi_fill(struct fc_lport
*lport
, struct fc_els_flogi
*flogi
,
317 struct fc_els_csp
*sp
;
318 struct fc_els_cssp
*cp
;
320 memset(flogi
, 0, sizeof(*flogi
));
321 flogi
->fl_cmd
= (u8
) op
;
322 put_unaligned_be64(lport
->wwpn
, &flogi
->fl_wwpn
);
323 put_unaligned_be64(lport
->wwnn
, &flogi
->fl_wwnn
);
325 sp
->sp_hi_ver
= 0x20;
326 sp
->sp_lo_ver
= 0x20;
327 sp
->sp_bb_cred
= htons(10); /* this gets set by gateway */
328 sp
->sp_bb_data
= htons((u16
) lport
->mfs
);
329 cp
= &flogi
->fl_cssp
[3 - 1]; /* class 3 parameters */
330 cp
->cp_class
= htons(FC_CPC_VALID
| FC_CPC_SEQ
);
331 if (op
!= ELS_FLOGI
) {
332 sp
->sp_features
= htons(FC_SP_FT_CIRO
);
333 sp
->sp_tot_seq
= htons(255); /* seq. we accept */
334 sp
->sp_rel_off
= htons(0x1f);
335 sp
->sp_e_d_tov
= htonl(lport
->e_d_tov
);
337 cp
->cp_rdfs
= htons((u16
) lport
->mfs
);
338 cp
->cp_con_seq
= htons(255);
344 * Add a supported FC-4 type.
346 static void fc_lport_add_fc4_type(struct fc_lport
*lport
, enum fc_fh_type type
)
350 mp
= &lport
->fcts
.ff_type_map
[type
/ FC_NS_BPW
];
351 *mp
= htonl(ntohl(*mp
) | 1UL << (type
% FC_NS_BPW
));
355 * fc_lport_recv_rlir_req() - Handle received Registered Link Incident Report.
356 * @lport: Fibre Channel local port recieving the RLIR
357 * @sp: current sequence in the RLIR exchange
358 * @fp: RLIR request frame
360 * Locking Note: The lport lock is exected to be held before calling
363 static void fc_lport_recv_rlir_req(struct fc_seq
*sp
, struct fc_frame
*fp
,
364 struct fc_lport
*lport
)
366 FC_DEBUG_LPORT("Received RLIR request while in state %s\n",
367 fc_lport_state(lport
));
369 lport
->tt
.seq_els_rsp_send(sp
, ELS_LS_ACC
, NULL
);
374 * fc_lport_recv_echo_req() - Handle received ECHO request
375 * @lport: Fibre Channel local port recieving the ECHO
376 * @sp: current sequence in the ECHO exchange
377 * @fp: ECHO request frame
379 * Locking Note: The lport lock is exected to be held before calling
382 static void fc_lport_recv_echo_req(struct fc_seq
*sp
, struct fc_frame
*in_fp
,
383 struct fc_lport
*lport
)
386 struct fc_exch
*ep
= fc_seq_exch(sp
);
392 FC_DEBUG_LPORT("Received RLIR request while in state %s\n",
393 fc_lport_state(lport
));
395 len
= fr_len(in_fp
) - sizeof(struct fc_frame_header
);
396 pp
= fc_frame_payload_get(in_fp
, len
);
398 if (len
< sizeof(__be32
))
399 len
= sizeof(__be32
);
401 fp
= fc_frame_alloc(lport
, len
);
403 dp
= fc_frame_payload_get(fp
, len
);
405 *((u32
*)dp
) = htonl(ELS_LS_ACC
<< 24);
406 sp
= lport
->tt
.seq_start_next(sp
);
407 f_ctl
= FC_FC_EX_CTX
| FC_FC_LAST_SEQ
| FC_FC_END_SEQ
;
408 fc_fill_fc_hdr(fp
, FC_RCTL_ELS_REP
, ep
->did
, ep
->sid
,
409 FC_TYPE_ELS
, f_ctl
, 0);
410 lport
->tt
.seq_send(lport
, sp
, fp
);
412 fc_frame_free(in_fp
);
416 * fc_lport_recv_echo_req() - Handle received Request Node ID data request
417 * @lport: Fibre Channel local port recieving the RNID
418 * @sp: current sequence in the RNID exchange
419 * @fp: RNID request frame
421 * Locking Note: The lport lock is exected to be held before calling
424 static void fc_lport_recv_rnid_req(struct fc_seq
*sp
, struct fc_frame
*in_fp
,
425 struct fc_lport
*lport
)
428 struct fc_exch
*ep
= fc_seq_exch(sp
);
429 struct fc_els_rnid
*req
;
431 struct fc_els_rnid_resp rnid
;
432 struct fc_els_rnid_cid cid
;
433 struct fc_els_rnid_gen gen
;
435 struct fc_seq_els_data rjt_data
;
440 FC_DEBUG_LPORT("Received RNID request while in state %s\n",
441 fc_lport_state(lport
));
443 req
= fc_frame_payload_get(in_fp
, sizeof(*req
));
446 rjt_data
.reason
= ELS_RJT_LOGIC
;
447 rjt_data
.explan
= ELS_EXPL_NONE
;
448 lport
->tt
.seq_els_rsp_send(sp
, ELS_LS_RJT
, &rjt_data
);
452 if (fmt
!= ELS_RNIDF_GEN
||
453 ntohl(lport
->rnid_gen
.rnid_atype
) == 0) {
454 fmt
= ELS_RNIDF_NONE
; /* nothing to provide */
455 len
-= sizeof(rp
->gen
);
457 fp
= fc_frame_alloc(lport
, len
);
459 rp
= fc_frame_payload_get(fp
, len
);
461 rp
->rnid
.rnid_cmd
= ELS_LS_ACC
;
462 rp
->rnid
.rnid_fmt
= fmt
;
463 rp
->rnid
.rnid_cid_len
= sizeof(rp
->cid
);
464 rp
->cid
.rnid_wwpn
= htonll(lport
->wwpn
);
465 rp
->cid
.rnid_wwnn
= htonll(lport
->wwnn
);
466 if (fmt
== ELS_RNIDF_GEN
) {
467 rp
->rnid
.rnid_sid_len
= sizeof(rp
->gen
);
468 memcpy(&rp
->gen
, &lport
->rnid_gen
,
471 sp
= lport
->tt
.seq_start_next(sp
);
472 f_ctl
= FC_FC_EX_CTX
| FC_FC_LAST_SEQ
;
473 f_ctl
|= FC_FC_END_SEQ
| FC_FC_SEQ_INIT
;
474 fc_fill_fc_hdr(fp
, FC_RCTL_ELS_REP
, ep
->did
, ep
->sid
,
475 FC_TYPE_ELS
, f_ctl
, 0);
476 lport
->tt
.seq_send(lport
, sp
, fp
);
479 fc_frame_free(in_fp
);
483 * fc_lport_recv_adisc_req() - Handle received Address Discovery Request
484 * @lport: Fibre Channel local port recieving the ADISC
485 * @sp: current sequence in the ADISC exchange
486 * @fp: ADISC request frame
488 * Locking Note: The lport lock is expected to be held before calling
491 static void fc_lport_recv_adisc_req(struct fc_seq
*sp
, struct fc_frame
*in_fp
,
492 struct fc_lport
*lport
)
495 struct fc_exch
*ep
= fc_seq_exch(sp
);
496 struct fc_els_adisc
*req
, *rp
;
497 struct fc_seq_els_data rjt_data
;
501 FC_DEBUG_LPORT("Received ADISC request while in state %s\n",
502 fc_lport_state(lport
));
504 req
= fc_frame_payload_get(in_fp
, sizeof(*req
));
507 rjt_data
.reason
= ELS_RJT_LOGIC
;
508 rjt_data
.explan
= ELS_EXPL_NONE
;
509 lport
->tt
.seq_els_rsp_send(sp
, ELS_LS_RJT
, &rjt_data
);
512 fp
= fc_frame_alloc(lport
, len
);
514 rp
= fc_frame_payload_get(fp
, len
);
516 rp
->adisc_cmd
= ELS_LS_ACC
;
517 rp
->adisc_wwpn
= htonll(lport
->wwpn
);
518 rp
->adisc_wwnn
= htonll(lport
->wwnn
);
519 hton24(rp
->adisc_port_id
,
520 fc_host_port_id(lport
->host
));
521 sp
= lport
->tt
.seq_start_next(sp
);
522 f_ctl
= FC_FC_EX_CTX
| FC_FC_LAST_SEQ
;
523 f_ctl
|= FC_FC_END_SEQ
| FC_FC_SEQ_INIT
;
524 fc_fill_fc_hdr(fp
, FC_RCTL_ELS_REP
, ep
->did
, ep
->sid
,
525 FC_TYPE_ELS
, f_ctl
, 0);
526 lport
->tt
.seq_send(lport
, sp
, fp
);
529 fc_frame_free(in_fp
);
533 * fc_lport_recv_logo_req() - Handle received fabric LOGO request
534 * @lport: Fibre Channel local port recieving the LOGO
535 * @sp: current sequence in the LOGO exchange
536 * @fp: LOGO request frame
538 * Locking Note: The lport lock is exected to be held before calling
541 static void fc_lport_recv_logo_req(struct fc_seq
*sp
, struct fc_frame
*fp
,
542 struct fc_lport
*lport
)
544 lport
->tt
.seq_els_rsp_send(sp
, ELS_LS_ACC
, NULL
);
545 fc_lport_enter_reset(lport
);
550 * fc_fabric_login() - Start the lport state machine
551 * @lport: The lport that should log into the fabric
553 * Locking Note: This function should not be called
554 * with the lport lock held.
556 int fc_fabric_login(struct fc_lport
*lport
)
560 mutex_lock(&lport
->lp_mutex
);
561 if (lport
->state
== LPORT_ST_NONE
) {
562 fc_lport_enter_reset(lport
);
565 mutex_unlock(&lport
->lp_mutex
);
569 EXPORT_SYMBOL(fc_fabric_login
);
572 * fc_linkup() - Handler for transport linkup events
573 * @lport: The lport whose link is up
575 void fc_linkup(struct fc_lport
*lport
)
577 FC_DEBUG_LPORT("Link is up for port (%6x)\n",
578 fc_host_port_id(lport
->host
));
580 mutex_lock(&lport
->lp_mutex
);
581 if (!lport
->link_up
) {
584 if (lport
->state
== LPORT_ST_RESET
)
585 fc_lport_enter_flogi(lport
);
587 mutex_unlock(&lport
->lp_mutex
);
589 EXPORT_SYMBOL(fc_linkup
);
592 * fc_linkdown() - Handler for transport linkdown events
593 * @lport: The lport whose link is down
595 void fc_linkdown(struct fc_lport
*lport
)
597 mutex_lock(&lport
->lp_mutex
);
598 FC_DEBUG_LPORT("Link is down for port (%6x)\n",
599 fc_host_port_id(lport
->host
));
601 if (lport
->link_up
) {
603 fc_lport_enter_reset(lport
);
604 lport
->tt
.fcp_cleanup(lport
);
606 mutex_unlock(&lport
->lp_mutex
);
608 EXPORT_SYMBOL(fc_linkdown
);
611 * fc_fabric_logoff() - Logout of the fabric
612 * @lport: fc_lport pointer to logoff the fabric
615 * 0 for success, -1 for failure
617 int fc_fabric_logoff(struct fc_lport
*lport
)
619 lport
->tt
.disc_stop_final(lport
);
620 mutex_lock(&lport
->lp_mutex
);
622 lport
->tt
.rport_logoff(lport
->dns_rp
);
623 mutex_unlock(&lport
->lp_mutex
);
624 lport
->tt
.rport_flush_queue();
625 mutex_lock(&lport
->lp_mutex
);
626 fc_lport_enter_logo(lport
);
627 mutex_unlock(&lport
->lp_mutex
);
628 cancel_delayed_work_sync(&lport
->retry_work
);
631 EXPORT_SYMBOL(fc_fabric_logoff
);
634 * fc_lport_destroy() - unregister a fc_lport
635 * @lport: fc_lport pointer to unregister
640 * exit routine for fc_lport instance
641 * clean-up all the allocated memory
642 * and free up other system resources.
645 int fc_lport_destroy(struct fc_lport
*lport
)
647 mutex_lock(&lport
->lp_mutex
);
648 lport
->state
= LPORT_ST_NONE
;
650 lport
->tt
.frame_send
= fc_frame_drop
;
651 mutex_unlock(&lport
->lp_mutex
);
653 lport
->tt
.fcp_abort_io(lport
);
654 lport
->tt
.exch_mgr_reset(lport
, 0, 0);
657 EXPORT_SYMBOL(fc_lport_destroy
);
660 * fc_set_mfs() - sets up the mfs for the corresponding fc_lport
661 * @lport: fc_lport pointer to unregister
662 * @mfs: the new mfs for fc_lport
664 * Set mfs for the given fc_lport to the new mfs.
666 * Return: 0 for success
668 int fc_set_mfs(struct fc_lport
*lport
, u32 mfs
)
670 unsigned int old_mfs
;
673 mutex_lock(&lport
->lp_mutex
);
675 old_mfs
= lport
->mfs
;
677 if (mfs
>= FC_MIN_MAX_FRAME
) {
679 if (mfs
> FC_MAX_FRAME
)
681 mfs
-= sizeof(struct fc_frame_header
);
686 if (!rc
&& mfs
< old_mfs
)
687 fc_lport_enter_reset(lport
);
689 mutex_unlock(&lport
->lp_mutex
);
693 EXPORT_SYMBOL(fc_set_mfs
);
696 * fc_lport_disc_callback() - Callback for discovery events
697 * @lport: FC local port
698 * @event: The discovery event
700 void fc_lport_disc_callback(struct fc_lport
*lport
, enum fc_disc_event event
)
703 case DISC_EV_SUCCESS
:
704 FC_DEBUG_LPORT("Got a SUCCESS event for port (%6x)\n",
705 fc_host_port_id(lport
->host
));
708 FC_DEBUG_LPORT("Got a FAILED event for port (%6x)\n",
709 fc_host_port_id(lport
->host
));
710 mutex_lock(&lport
->lp_mutex
);
711 fc_lport_enter_reset(lport
);
712 mutex_unlock(&lport
->lp_mutex
);
721 * fc_rport_enter_ready() - Enter the ready state and start discovery
722 * @lport: Fibre Channel local port that is ready
724 * Locking Note: The lport lock is expected to be held before calling
727 static void fc_lport_enter_ready(struct fc_lport
*lport
)
729 FC_DEBUG_LPORT("Port (%6x) entered Ready from state %s\n",
730 fc_host_port_id(lport
->host
), fc_lport_state(lport
));
732 fc_lport_state_enter(lport
, LPORT_ST_READY
);
734 lport
->tt
.disc_start(fc_lport_disc_callback
, lport
);
738 * fc_lport_recv_flogi_req() - Receive a FLOGI request
739 * @sp_in: The sequence the FLOGI is on
740 * @rx_fp: The frame the FLOGI is in
741 * @lport: The lport that recieved the request
743 * A received FLOGI request indicates a point-to-point connection.
744 * Accept it with the common service parameters indicating our N port.
745 * Set up to do a PLOGI if we have the higher-number WWPN.
747 * Locking Note: The lport lock is exected to be held before calling
750 static void fc_lport_recv_flogi_req(struct fc_seq
*sp_in
,
751 struct fc_frame
*rx_fp
,
752 struct fc_lport
*lport
)
755 struct fc_frame_header
*fh
;
758 struct fc_els_flogi
*flp
;
759 struct fc_els_flogi
*new_flp
;
765 FC_DEBUG_LPORT("Received FLOGI request while in state %s\n",
766 fc_lport_state(lport
));
768 fh
= fc_frame_header_get(rx_fp
);
769 remote_fid
= ntoh24(fh
->fh_s_id
);
770 flp
= fc_frame_payload_get(rx_fp
, sizeof(*flp
));
773 remote_wwpn
= get_unaligned_be64(&flp
->fl_wwpn
);
774 if (remote_wwpn
== lport
->wwpn
) {
775 FC_DBG("FLOGI from port with same WWPN %llx "
776 "possible configuration error\n",
777 (unsigned long long)remote_wwpn
);
780 FC_DBG("FLOGI from port WWPN %llx\n", (unsigned long long)remote_wwpn
);
783 * XXX what is the right thing to do for FIDs?
784 * The originator might expect our S_ID to be 0xfffffe.
785 * But if so, both of us could end up with the same FID.
787 local_fid
= FC_LOCAL_PTP_FID_LO
;
788 if (remote_wwpn
< lport
->wwpn
) {
789 local_fid
= FC_LOCAL_PTP_FID_HI
;
790 if (!remote_fid
|| remote_fid
== local_fid
)
791 remote_fid
= FC_LOCAL_PTP_FID_LO
;
792 } else if (!remote_fid
) {
793 remote_fid
= FC_LOCAL_PTP_FID_HI
;
796 fc_host_port_id(lport
->host
) = local_fid
;
798 fp
= fc_frame_alloc(lport
, sizeof(*flp
));
800 sp
= lport
->tt
.seq_start_next(fr_seq(rx_fp
));
801 new_flp
= fc_frame_payload_get(fp
, sizeof(*flp
));
802 fc_lport_flogi_fill(lport
, new_flp
, ELS_FLOGI
);
803 new_flp
->fl_cmd
= (u8
) ELS_LS_ACC
;
806 * Send the response. If this fails, the originator should
807 * repeat the sequence.
809 f_ctl
= FC_FC_EX_CTX
| FC_FC_LAST_SEQ
| FC_FC_END_SEQ
;
810 ep
= fc_seq_exch(sp
);
811 fc_fill_fc_hdr(fp
, FC_RCTL_ELS_REP
, ep
->did
, ep
->sid
,
812 FC_TYPE_ELS
, f_ctl
, 0);
813 lport
->tt
.seq_send(lport
, sp
, fp
);
816 fc_lport_error(lport
, fp
);
818 fc_lport_ptp_setup(lport
, remote_fid
, remote_wwpn
,
819 get_unaligned_be64(&flp
->fl_wwnn
));
821 lport
->tt
.disc_start(fc_lport_disc_callback
, lport
);
825 fc_frame_free(rx_fp
);
829 * fc_lport_recv_req() - The generic lport request handler
830 * @lport: The lport that received the request
831 * @sp: The sequence the request is on
832 * @fp: The frame the request is in
834 * This function will see if the lport handles the request or
835 * if an rport should handle the request.
837 * Locking Note: This function should not be called with the lport
838 * lock held becuase it will grab the lock.
840 static void fc_lport_recv_req(struct fc_lport
*lport
, struct fc_seq
*sp
,
843 struct fc_frame_header
*fh
= fc_frame_header_get(fp
);
844 void (*recv
) (struct fc_seq
*, struct fc_frame
*, struct fc_lport
*);
845 struct fc_rport
*rport
;
848 struct fc_seq_els_data rjt_data
;
850 mutex_lock(&lport
->lp_mutex
);
853 * Handle special ELS cases like FLOGI, LOGO, and
854 * RSCN here. These don't require a session.
855 * Even if we had a session, it might not be ready.
857 if (fh
->fh_type
== FC_TYPE_ELS
&& fh
->fh_r_ctl
== FC_RCTL_ELS_REQ
) {
862 switch (fc_frame_payload_op(fp
)) {
864 recv
= fc_lport_recv_flogi_req
;
867 fh
= fc_frame_header_get(fp
);
868 if (ntoh24(fh
->fh_s_id
) == FC_FID_FLOGI
)
869 recv
= fc_lport_recv_logo_req
;
872 recv
= lport
->tt
.disc_recv_req
;
875 recv
= fc_lport_recv_echo_req
;
878 recv
= fc_lport_recv_rlir_req
;
881 recv
= fc_lport_recv_rnid_req
;
884 recv
= fc_lport_recv_adisc_req
;
893 * If this is a new incoming PLOGI, we won't find it.
895 s_id
= ntoh24(fh
->fh_s_id
);
896 d_id
= ntoh24(fh
->fh_d_id
);
898 rport
= lport
->tt
.rport_lookup(lport
, s_id
);
900 lport
->tt
.rport_recv_req(sp
, fp
, rport
);
903 rjt_data
.reason
= ELS_RJT_UNAB
;
904 rjt_data
.explan
= ELS_EXPL_NONE
;
905 lport
->tt
.seq_els_rsp_send(sp
,
912 FC_DBG("dropping invalid frame (eof %x)\n", fr_eof(fp
));
915 mutex_unlock(&lport
->lp_mutex
);
918 * The common exch_done for all request may not be good
919 * if any request requires longer hold on exhange. XXX
921 lport
->tt
.exch_done(sp
);
925 * fc_lport_reset() - Reset an lport
926 * @lport: The lport which should be reset
928 * Locking Note: This functions should not be called with the
931 int fc_lport_reset(struct fc_lport
*lport
)
933 cancel_delayed_work_sync(&lport
->retry_work
);
934 mutex_lock(&lport
->lp_mutex
);
935 fc_lport_enter_reset(lport
);
936 mutex_unlock(&lport
->lp_mutex
);
939 EXPORT_SYMBOL(fc_lport_reset
);
942 * fc_rport_enter_reset() - Reset the local port
943 * @lport: Fibre Channel local port to be reset
945 * Locking Note: The lport lock is expected to be held before calling
948 static void fc_lport_enter_reset(struct fc_lport
*lport
)
950 FC_DEBUG_LPORT("Port (%6x) entered RESET state from %s state\n",
951 fc_host_port_id(lport
->host
), fc_lport_state(lport
));
953 fc_lport_state_enter(lport
, LPORT_ST_RESET
);
956 lport
->tt
.rport_logoff(lport
->dns_rp
);
959 lport
->tt
.rport_logoff(lport
->ptp_rp
);
960 lport
->ptp_rp
= NULL
;
963 lport
->tt
.disc_stop(lport
);
965 lport
->tt
.exch_mgr_reset(lport
, 0, 0);
966 fc_host_fabric_name(lport
->host
) = 0;
967 fc_host_port_id(lport
->host
) = 0;
970 fc_lport_enter_flogi(lport
);
974 * fc_lport_error() - Handler for any errors
975 * @lport: The fc_lport object
976 * @fp: The frame pointer
978 * If the error was caused by a resource allocation failure
979 * then wait for half a second and retry, otherwise retry
980 * after the e_d_tov time.
982 static void fc_lport_error(struct fc_lport
*lport
, struct fc_frame
*fp
)
984 unsigned long delay
= 0;
985 FC_DEBUG_LPORT("Error %ld in state %s, retries %d\n",
986 PTR_ERR(fp
), fc_lport_state(lport
),
989 if (!fp
|| PTR_ERR(fp
) == -FC_EX_TIMEOUT
) {
991 * Memory allocation failure, or the exchange timed out.
994 if (lport
->retry_count
< lport
->max_retry_count
) {
995 lport
->retry_count
++;
997 delay
= msecs_to_jiffies(500);
999 delay
= msecs_to_jiffies(lport
->e_d_tov
);
1001 schedule_delayed_work(&lport
->retry_work
, delay
);
1003 switch (lport
->state
) {
1005 case LPORT_ST_READY
:
1006 case LPORT_ST_RESET
:
1007 case LPORT_ST_RPN_ID
:
1008 case LPORT_ST_RFT_ID
:
1011 case LPORT_ST_FLOGI
:
1013 fc_lport_enter_reset(lport
);
1021 * fc_lport_rft_id_resp() - Handle response to Register Fibre
1022 * Channel Types by ID (RPN_ID) request
1023 * @sp: current sequence in RPN_ID exchange
1024 * @fp: response frame
1025 * @lp_arg: Fibre Channel host port instance
1027 * Locking Note: This function will be called without the lport lock
1028 * held, but it will lock, call an _enter_* function or fc_lport_error
1029 * and then unlock the lport.
1031 static void fc_lport_rft_id_resp(struct fc_seq
*sp
, struct fc_frame
*fp
,
1034 struct fc_lport
*lport
= lp_arg
;
1035 struct fc_frame_header
*fh
;
1036 struct fc_ct_hdr
*ct
;
1038 if (fp
== ERR_PTR(-FC_EX_CLOSED
))
1041 mutex_lock(&lport
->lp_mutex
);
1043 FC_DEBUG_LPORT("Received a RFT_ID response\n");
1045 if (lport
->state
!= LPORT_ST_RFT_ID
) {
1046 FC_DBG("Received a RFT_ID response, but in state %s\n",
1047 fc_lport_state(lport
));
1054 fc_lport_error(lport
, fp
);
1058 fh
= fc_frame_header_get(fp
);
1059 ct
= fc_frame_payload_get(fp
, sizeof(*ct
));
1061 if (fh
&& ct
&& fh
->fh_type
== FC_TYPE_CT
&&
1062 ct
->ct_fs_type
== FC_FST_DIR
&&
1063 ct
->ct_fs_subtype
== FC_NS_SUBTYPE
&&
1064 ntohs(ct
->ct_cmd
) == FC_FS_ACC
)
1065 fc_lport_enter_scr(lport
);
1067 fc_lport_error(lport
, fp
);
1071 mutex_unlock(&lport
->lp_mutex
);
1075 * fc_lport_rpn_id_resp() - Handle response to Register Port
1076 * Name by ID (RPN_ID) request
1077 * @sp: current sequence in RPN_ID exchange
1078 * @fp: response frame
1079 * @lp_arg: Fibre Channel host port instance
1081 * Locking Note: This function will be called without the lport lock
1082 * held, but it will lock, call an _enter_* function or fc_lport_error
1083 * and then unlock the lport.
1085 static void fc_lport_rpn_id_resp(struct fc_seq
*sp
, struct fc_frame
*fp
,
1088 struct fc_lport
*lport
= lp_arg
;
1089 struct fc_frame_header
*fh
;
1090 struct fc_ct_hdr
*ct
;
1092 if (fp
== ERR_PTR(-FC_EX_CLOSED
))
1095 mutex_lock(&lport
->lp_mutex
);
1097 FC_DEBUG_LPORT("Received a RPN_ID response\n");
1099 if (lport
->state
!= LPORT_ST_RPN_ID
) {
1100 FC_DBG("Received a RPN_ID response, but in state %s\n",
1101 fc_lport_state(lport
));
1108 fc_lport_error(lport
, fp
);
1112 fh
= fc_frame_header_get(fp
);
1113 ct
= fc_frame_payload_get(fp
, sizeof(*ct
));
1114 if (fh
&& ct
&& fh
->fh_type
== FC_TYPE_CT
&&
1115 ct
->ct_fs_type
== FC_FST_DIR
&&
1116 ct
->ct_fs_subtype
== FC_NS_SUBTYPE
&&
1117 ntohs(ct
->ct_cmd
) == FC_FS_ACC
)
1118 fc_lport_enter_rft_id(lport
);
1120 fc_lport_error(lport
, fp
);
1125 mutex_unlock(&lport
->lp_mutex
);
1129 * fc_lport_scr_resp() - Handle response to State Change Register (SCR) request
1130 * @sp: current sequence in SCR exchange
1131 * @fp: response frame
1132 * @lp_arg: Fibre Channel lport port instance that sent the registration request
1134 * Locking Note: This function will be called without the lport lock
1135 * held, but it will lock, call an _enter_* function or fc_lport_error
1136 * and then unlock the lport.
1138 static void fc_lport_scr_resp(struct fc_seq
*sp
, struct fc_frame
*fp
,
1141 struct fc_lport
*lport
= lp_arg
;
1144 if (fp
== ERR_PTR(-FC_EX_CLOSED
))
1147 mutex_lock(&lport
->lp_mutex
);
1149 FC_DEBUG_LPORT("Received a SCR response\n");
1151 if (lport
->state
!= LPORT_ST_SCR
) {
1152 FC_DBG("Received a SCR response, but in state %s\n",
1153 fc_lport_state(lport
));
1160 fc_lport_error(lport
, fp
);
1164 op
= fc_frame_payload_op(fp
);
1165 if (op
== ELS_LS_ACC
)
1166 fc_lport_enter_ready(lport
);
1168 fc_lport_error(lport
, fp
);
1173 mutex_unlock(&lport
->lp_mutex
);
1177 * fc_lport_enter_scr() - Send a State Change Register (SCR) request
1178 * @lport: Fibre Channel local port to register for state changes
1180 * Locking Note: The lport lock is expected to be held before calling
1183 static void fc_lport_enter_scr(struct fc_lport
*lport
)
1185 struct fc_frame
*fp
;
1187 FC_DEBUG_LPORT("Port (%6x) entered SCR state from %s state\n",
1188 fc_host_port_id(lport
->host
), fc_lport_state(lport
));
1190 fc_lport_state_enter(lport
, LPORT_ST_SCR
);
1192 fp
= fc_frame_alloc(lport
, sizeof(struct fc_els_scr
));
1194 fc_lport_error(lport
, fp
);
1198 if (!lport
->tt
.elsct_send(lport
, NULL
, fp
, ELS_SCR
,
1199 fc_lport_scr_resp
, lport
, lport
->e_d_tov
))
1200 fc_lport_error(lport
, fp
);
1204 * fc_lport_enter_rft_id() - Register FC4-types with the name server
1205 * @lport: Fibre Channel local port to register
1207 * Locking Note: The lport lock is expected to be held before calling
1210 static void fc_lport_enter_rft_id(struct fc_lport
*lport
)
1212 struct fc_frame
*fp
;
1213 struct fc_ns_fts
*lps
;
1216 FC_DEBUG_LPORT("Port (%6x) entered RFT_ID state from %s state\n",
1217 fc_host_port_id(lport
->host
), fc_lport_state(lport
));
1219 fc_lport_state_enter(lport
, LPORT_ST_RFT_ID
);
1222 i
= sizeof(lps
->ff_type_map
) / sizeof(lps
->ff_type_map
[0]);
1224 if (ntohl(lps
->ff_type_map
[i
]) != 0)
1227 /* nothing to register, move on to SCR */
1228 fc_lport_enter_scr(lport
);
1232 fp
= fc_frame_alloc(lport
, sizeof(struct fc_ct_hdr
) +
1233 sizeof(struct fc_ns_rft
));
1235 fc_lport_error(lport
, fp
);
1239 if (!lport
->tt
.elsct_send(lport
, NULL
, fp
, FC_NS_RFT_ID
,
1240 fc_lport_rft_id_resp
,
1241 lport
, lport
->e_d_tov
))
1242 fc_lport_error(lport
, fp
);
1246 * fc_rport_enter_rft_id() - Register port name with the name server
1247 * @lport: Fibre Channel local port to register
1249 * Locking Note: The lport lock is expected to be held before calling
1252 static void fc_lport_enter_rpn_id(struct fc_lport
*lport
)
1254 struct fc_frame
*fp
;
1256 FC_DEBUG_LPORT("Port (%6x) entered RPN_ID state from %s state\n",
1257 fc_host_port_id(lport
->host
), fc_lport_state(lport
));
1259 fc_lport_state_enter(lport
, LPORT_ST_RPN_ID
);
1261 fp
= fc_frame_alloc(lport
, sizeof(struct fc_ct_hdr
) +
1262 sizeof(struct fc_ns_rn_id
));
1264 fc_lport_error(lport
, fp
);
1268 if (!lport
->tt
.elsct_send(lport
, NULL
, fp
, FC_NS_RPN_ID
,
1269 fc_lport_rpn_id_resp
,
1270 lport
, lport
->e_d_tov
))
1271 fc_lport_error(lport
, fp
);
1274 static struct fc_rport_operations fc_lport_rport_ops
= {
1275 .event_callback
= fc_lport_rport_callback
,
1279 * fc_rport_enter_dns() - Create a rport to the name server
1280 * @lport: Fibre Channel local port requesting a rport for the name server
1282 * Locking Note: The lport lock is expected to be held before calling
1285 static void fc_lport_enter_dns(struct fc_lport
*lport
)
1287 struct fc_rport
*rport
;
1288 struct fc_rport_libfc_priv
*rdata
;
1289 struct fc_disc_port dp
;
1291 dp
.ids
.port_id
= FC_FID_DIR_SERV
;
1292 dp
.ids
.port_name
= -1;
1293 dp
.ids
.node_name
= -1;
1294 dp
.ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
1297 FC_DEBUG_LPORT("Port (%6x) entered DNS state from %s state\n",
1298 fc_host_port_id(lport
->host
), fc_lport_state(lport
));
1300 fc_lport_state_enter(lport
, LPORT_ST_DNS
);
1302 rport
= lport
->tt
.rport_create(&dp
);
1306 rdata
= rport
->dd_data
;
1307 rdata
->ops
= &fc_lport_rport_ops
;
1308 lport
->tt
.rport_login(rport
);
1312 fc_lport_error(lport
, NULL
);
1316 * fc_lport_timeout() - Handler for the retry_work timer.
1317 * @work: The work struct of the fc_lport
1319 static void fc_lport_timeout(struct work_struct
*work
)
1321 struct fc_lport
*lport
=
1322 container_of(work
, struct fc_lport
,
1325 mutex_lock(&lport
->lp_mutex
);
1327 switch (lport
->state
) {
1329 case LPORT_ST_READY
:
1330 case LPORT_ST_RESET
:
1333 case LPORT_ST_FLOGI
:
1334 fc_lport_enter_flogi(lport
);
1337 fc_lport_enter_dns(lport
);
1339 case LPORT_ST_RPN_ID
:
1340 fc_lport_enter_rpn_id(lport
);
1342 case LPORT_ST_RFT_ID
:
1343 fc_lport_enter_rft_id(lport
);
1346 fc_lport_enter_scr(lport
);
1349 fc_lport_enter_logo(lport
);
1353 mutex_unlock(&lport
->lp_mutex
);
1357 * fc_lport_logo_resp() - Handle response to LOGO request
1358 * @sp: current sequence in LOGO exchange
1359 * @fp: response frame
1360 * @lp_arg: Fibre Channel lport port instance that sent the LOGO request
1362 * Locking Note: This function will be called without the lport lock
1363 * held, but it will lock, call an _enter_* function or fc_lport_error
1364 * and then unlock the lport.
1366 static void fc_lport_logo_resp(struct fc_seq
*sp
, struct fc_frame
*fp
,
1369 struct fc_lport
*lport
= lp_arg
;
1372 if (fp
== ERR_PTR(-FC_EX_CLOSED
))
1375 mutex_lock(&lport
->lp_mutex
);
1377 FC_DEBUG_LPORT("Received a LOGO response\n");
1379 if (lport
->state
!= LPORT_ST_LOGO
) {
1380 FC_DBG("Received a LOGO response, but in state %s\n",
1381 fc_lport_state(lport
));
1388 fc_lport_error(lport
, fp
);
1392 op
= fc_frame_payload_op(fp
);
1393 if (op
== ELS_LS_ACC
)
1394 fc_lport_enter_reset(lport
);
1396 fc_lport_error(lport
, fp
);
1401 mutex_unlock(&lport
->lp_mutex
);
1405 * fc_rport_enter_logo() - Logout of the fabric
1406 * @lport: Fibre Channel local port to be logged out
1408 * Locking Note: The lport lock is expected to be held before calling
1411 static void fc_lport_enter_logo(struct fc_lport
*lport
)
1413 struct fc_frame
*fp
;
1414 struct fc_els_logo
*logo
;
1416 FC_DEBUG_LPORT("Port (%6x) entered LOGO state from %s state\n",
1417 fc_host_port_id(lport
->host
), fc_lport_state(lport
));
1419 fc_lport_state_enter(lport
, LPORT_ST_LOGO
);
1421 fp
= fc_frame_alloc(lport
, sizeof(*logo
));
1423 fc_lport_error(lport
, fp
);
1427 if (!lport
->tt
.elsct_send(lport
, NULL
, fp
, ELS_LOGO
, fc_lport_logo_resp
,
1428 lport
, lport
->e_d_tov
))
1429 fc_lport_error(lport
, fp
);
1433 * fc_lport_flogi_resp() - Handle response to FLOGI request
1434 * @sp: current sequence in FLOGI exchange
1435 * @fp: response frame
1436 * @lp_arg: Fibre Channel lport port instance that sent the FLOGI request
1438 * Locking Note: This function will be called without the lport lock
1439 * held, but it will lock, call an _enter_* function or fc_lport_error
1440 * and then unlock the lport.
1442 static void fc_lport_flogi_resp(struct fc_seq
*sp
, struct fc_frame
*fp
,
1445 struct fc_lport
*lport
= lp_arg
;
1446 struct fc_frame_header
*fh
;
1447 struct fc_els_flogi
*flp
;
1450 unsigned int r_a_tov
;
1451 unsigned int e_d_tov
;
1454 if (fp
== ERR_PTR(-FC_EX_CLOSED
))
1457 mutex_lock(&lport
->lp_mutex
);
1459 FC_DEBUG_LPORT("Received a FLOGI response\n");
1461 if (lport
->state
!= LPORT_ST_FLOGI
) {
1462 FC_DBG("Received a FLOGI response, but in state %s\n",
1463 fc_lport_state(lport
));
1470 fc_lport_error(lport
, fp
);
1474 fh
= fc_frame_header_get(fp
);
1475 did
= ntoh24(fh
->fh_d_id
);
1476 if (fc_frame_payload_op(fp
) == ELS_LS_ACC
&& did
!= 0) {
1478 FC_DEBUG_LPORT("Assigned fid %x\n", did
);
1479 fc_host_port_id(lport
->host
) = did
;
1481 flp
= fc_frame_payload_get(fp
, sizeof(*flp
));
1483 mfs
= ntohs(flp
->fl_csp
.sp_bb_data
) &
1485 if (mfs
>= FC_SP_MIN_MAX_PAYLOAD
&&
1488 csp_flags
= ntohs(flp
->fl_csp
.sp_features
);
1489 r_a_tov
= ntohl(flp
->fl_csp
.sp_r_a_tov
);
1490 e_d_tov
= ntohl(flp
->fl_csp
.sp_e_d_tov
);
1491 if (csp_flags
& FC_SP_FT_EDTR
)
1493 if ((csp_flags
& FC_SP_FT_FPORT
) == 0) {
1494 if (e_d_tov
> lport
->e_d_tov
)
1495 lport
->e_d_tov
= e_d_tov
;
1496 lport
->r_a_tov
= 2 * e_d_tov
;
1497 FC_DBG("Point-to-Point mode\n");
1498 fc_lport_ptp_setup(lport
, ntoh24(fh
->fh_s_id
),
1504 lport
->e_d_tov
= e_d_tov
;
1505 lport
->r_a_tov
= r_a_tov
;
1506 fc_host_fabric_name(lport
->host
) =
1507 get_unaligned_be64(&flp
->fl_wwnn
);
1508 fc_lport_enter_dns(lport
);
1513 csp_flags
= ntohs(flp
->fl_csp
.sp_features
);
1514 if ((csp_flags
& FC_SP_FT_FPORT
) == 0) {
1515 lport
->tt
.disc_start(fc_lport_disc_callback
,
1520 FC_DBG("bad FLOGI response\n");
1526 mutex_unlock(&lport
->lp_mutex
);
1530 * fc_rport_enter_flogi() - Send a FLOGI request to the fabric manager
1531 * @lport: Fibre Channel local port to be logged in to the fabric
1533 * Locking Note: The lport lock is expected to be held before calling
1536 void fc_lport_enter_flogi(struct fc_lport
*lport
)
1538 struct fc_frame
*fp
;
1540 FC_DEBUG_LPORT("Processing FLOGI state\n");
1542 fc_lport_state_enter(lport
, LPORT_ST_FLOGI
);
1544 fp
= fc_frame_alloc(lport
, sizeof(struct fc_els_flogi
));
1546 return fc_lport_error(lport
, fp
);
1548 if (!lport
->tt
.elsct_send(lport
, NULL
, fp
, ELS_FLOGI
,
1549 fc_lport_flogi_resp
, lport
, lport
->e_d_tov
))
1550 fc_lport_error(lport
, fp
);
1553 /* Configure a fc_lport */
1554 int fc_lport_config(struct fc_lport
*lport
)
1556 INIT_DELAYED_WORK(&lport
->retry_work
, fc_lport_timeout
);
1557 mutex_init(&lport
->lp_mutex
);
1559 fc_lport_state_enter(lport
, LPORT_ST_NONE
);
1561 fc_lport_add_fc4_type(lport
, FC_TYPE_FCP
);
1562 fc_lport_add_fc4_type(lport
, FC_TYPE_CT
);
1566 EXPORT_SYMBOL(fc_lport_config
);
1568 int fc_lport_init(struct fc_lport
*lport
)
1570 if (!lport
->tt
.lport_recv
)
1571 lport
->tt
.lport_recv
= fc_lport_recv_req
;
1573 if (!lport
->tt
.lport_reset
)
1574 lport
->tt
.lport_reset
= fc_lport_reset
;
1576 fc_host_port_type(lport
->host
) = FC_PORTTYPE_NPORT
;
1577 fc_host_node_name(lport
->host
) = lport
->wwnn
;
1578 fc_host_port_name(lport
->host
) = lport
->wwpn
;
1579 fc_host_supported_classes(lport
->host
) = FC_COS_CLASS3
;
1580 memset(fc_host_supported_fc4s(lport
->host
), 0,
1581 sizeof(fc_host_supported_fc4s(lport
->host
)));
1582 fc_host_supported_fc4s(lport
->host
)[2] = 1;
1583 fc_host_supported_fc4s(lport
->host
)[7] = 1;
1585 /* This value is also unchanging */
1586 memset(fc_host_active_fc4s(lport
->host
), 0,
1587 sizeof(fc_host_active_fc4s(lport
->host
)));
1588 fc_host_active_fc4s(lport
->host
)[2] = 1;
1589 fc_host_active_fc4s(lport
->host
)[7] = 1;
1590 fc_host_maxframe_size(lport
->host
) = lport
->mfs
;
1591 fc_host_supported_speeds(lport
->host
) = 0;
1592 if (lport
->link_supported_speeds
& FC_PORTSPEED_1GBIT
)
1593 fc_host_supported_speeds(lport
->host
) |= FC_PORTSPEED_1GBIT
;
1594 if (lport
->link_supported_speeds
& FC_PORTSPEED_10GBIT
)
1595 fc_host_supported_speeds(lport
->host
) |= FC_PORTSPEED_10GBIT
;
1599 EXPORT_SYMBOL(fc_lport_init
);