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 void fc_lport_error(struct fc_lport *, struct fc_frame *);
106 static void fc_lport_enter_reset(struct fc_lport *);
107 static void fc_lport_enter_flogi(struct fc_lport *);
108 static void fc_lport_enter_dns(struct fc_lport *);
109 static void fc_lport_enter_rpn_id(struct fc_lport *);
110 static void fc_lport_enter_rft_id(struct fc_lport *);
111 static void fc_lport_enter_scr(struct fc_lport *);
112 static void fc_lport_enter_ready(struct fc_lport *);
113 static void fc_lport_enter_logo(struct fc_lport *);
115 static const char *fc_lport_state_names[] = {
116 [LPORT_ST_DISABLED] = "disabled",
117 [LPORT_ST_FLOGI] = "FLOGI",
118 [LPORT_ST_DNS] = "dNS",
119 [LPORT_ST_RPN_ID] = "RPN_ID",
120 [LPORT_ST_RFT_ID] = "RFT_ID",
121 [LPORT_ST_SCR] = "SCR",
122 [LPORT_ST_READY] = "Ready",
123 [LPORT_ST_LOGO] = "LOGO",
124 [LPORT_ST_RESET] = "reset",
127 static int fc_frame_drop(struct fc_lport *lport, struct fc_frame *fp)
134 * fc_lport_rport_callback() - Event handler for rport events
135 * @lport: The lport which is receiving the event
136 * @rport: The rport which the event has occured on
137 * @event: The event that occured
139 * Locking Note: The rport lock should not be held when calling
142 static void fc_lport_rport_callback(struct fc_lport *lport,
143 struct fc_rport *rport,
144 enum fc_rport_event event)
146 FC_LPORT_DBG(lport, "Received a %d event for port (%6x)\n", event,
150 case RPORT_EV_CREATED:
151 if (rport->port_id == FC_FID_DIR_SERV) {
152 mutex_lock(&lport->lp_mutex);
153 if (lport->state == LPORT_ST_DNS) {
154 lport->dns_rp = rport;
155 fc_lport_enter_rpn_id(lport);
157 FC_LPORT_DBG(lport, "Received an CREATED event "
158 "on port (%6x) for the directory "
159 "server, but the lport is not "
160 "in the DNS state, it's in the "
161 "%d state", rport->port_id,
163 lport->tt.rport_logoff(rport);
165 mutex_unlock(&lport->lp_mutex);
167 FC_LPORT_DBG(lport, "Received an event for port (%6x) "
168 "which is not the directory server\n",
172 case RPORT_EV_FAILED:
174 if (rport->port_id == FC_FID_DIR_SERV) {
175 mutex_lock(&lport->lp_mutex);
176 lport->dns_rp = NULL;
177 mutex_unlock(&lport->lp_mutex);
180 FC_LPORT_DBG(lport, "Received an event for port (%6x) "
181 "which is not the directory server\n",
190 * fc_lport_state() - Return a string which represents the lport's state
191 * @lport: The lport whose state is to converted to a string
193 static const char *fc_lport_state(struct fc_lport *lport)
197 cp = fc_lport_state_names[lport->state];
204 * fc_lport_ptp_setup() - Create an rport for point-to-point mode
205 * @lport: The lport to attach the ptp rport to
206 * @fid: The FID of the ptp rport
207 * @remote_wwpn: The WWPN of the ptp rport
208 * @remote_wwnn: The WWNN of the ptp rport
210 static void fc_lport_ptp_setup(struct fc_lport *lport,
211 u32 remote_fid, u64 remote_wwpn,
214 struct fc_disc_port dp;
217 dp.ids.port_id = remote_fid;
218 dp.ids.port_name = remote_wwpn;
219 dp.ids.node_name = remote_wwnn;
220 dp.ids.roles = FC_RPORT_ROLE_UNKNOWN;
223 lport->tt.rport_logoff(lport->ptp_rp);
224 lport->ptp_rp = NULL;
227 lport->ptp_rp = lport->tt.rport_create(&dp);
229 lport->tt.rport_login(lport->ptp_rp);
231 fc_lport_enter_ready(lport);
234 void fc_get_host_port_type(struct Scsi_Host *shost)
236 /* TODO - currently just NPORT */
237 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
239 EXPORT_SYMBOL(fc_get_host_port_type);
241 void fc_get_host_port_state(struct Scsi_Host *shost)
243 struct fc_lport *lp = shost_priv(shost);
246 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
248 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
250 EXPORT_SYMBOL(fc_get_host_port_state);
252 void fc_get_host_speed(struct Scsi_Host *shost)
254 struct fc_lport *lport = shost_priv(shost);
256 fc_host_speed(shost) = lport->link_speed;
258 EXPORT_SYMBOL(fc_get_host_speed);
260 struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *shost)
262 struct fc_host_statistics *fcoe_stats;
263 struct fc_lport *lp = shost_priv(shost);
264 struct timespec v0, v1;
267 fcoe_stats = &lp->host_stats;
268 memset(fcoe_stats, 0, sizeof(struct fc_host_statistics));
270 jiffies_to_timespec(jiffies, &v0);
271 jiffies_to_timespec(lp->boot_time, &v1);
272 fcoe_stats->seconds_since_last_reset = (v0.tv_sec - v1.tv_sec);
274 for_each_possible_cpu(cpu) {
275 struct fcoe_dev_stats *stats;
277 stats = per_cpu_ptr(lp->dev_stats, cpu);
279 fcoe_stats->tx_frames += stats->TxFrames;
280 fcoe_stats->tx_words += stats->TxWords;
281 fcoe_stats->rx_frames += stats->RxFrames;
282 fcoe_stats->rx_words += stats->RxWords;
283 fcoe_stats->error_frames += stats->ErrorFrames;
284 fcoe_stats->invalid_crc_count += stats->InvalidCRCCount;
285 fcoe_stats->fcp_input_requests += stats->InputRequests;
286 fcoe_stats->fcp_output_requests += stats->OutputRequests;
287 fcoe_stats->fcp_control_requests += stats->ControlRequests;
288 fcoe_stats->fcp_input_megabytes += stats->InputMegabytes;
289 fcoe_stats->fcp_output_megabytes += stats->OutputMegabytes;
290 fcoe_stats->link_failure_count += stats->LinkFailureCount;
292 fcoe_stats->lip_count = -1;
293 fcoe_stats->nos_count = -1;
294 fcoe_stats->loss_of_sync_count = -1;
295 fcoe_stats->loss_of_signal_count = -1;
296 fcoe_stats->prim_seq_protocol_err_count = -1;
297 fcoe_stats->dumped_frames = -1;
300 EXPORT_SYMBOL(fc_get_host_stats);
303 * Fill in FLOGI command for request.
306 fc_lport_flogi_fill(struct fc_lport *lport, struct fc_els_flogi *flogi,
309 struct fc_els_csp *sp;
310 struct fc_els_cssp *cp;
312 memset(flogi, 0, sizeof(*flogi));
313 flogi->fl_cmd = (u8) op;
314 put_unaligned_be64(lport->wwpn, &flogi->fl_wwpn);
315 put_unaligned_be64(lport->wwnn, &flogi->fl_wwnn);
317 sp->sp_hi_ver = 0x20;
318 sp->sp_lo_ver = 0x20;
319 sp->sp_bb_cred = htons(10); /* this gets set by gateway */
320 sp->sp_bb_data = htons((u16) lport->mfs);
321 cp = &flogi->fl_cssp[3 - 1]; /* class 3 parameters */
322 cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ);
323 if (op != ELS_FLOGI) {
324 sp->sp_features = htons(FC_SP_FT_CIRO);
325 sp->sp_tot_seq = htons(255); /* seq. we accept */
326 sp->sp_rel_off = htons(0x1f);
327 sp->sp_e_d_tov = htonl(lport->e_d_tov);
329 cp->cp_rdfs = htons((u16) lport->mfs);
330 cp->cp_con_seq = htons(255);
336 * Add a supported FC-4 type.
338 static void fc_lport_add_fc4_type(struct fc_lport *lport, enum fc_fh_type type)
342 mp = &lport->fcts.ff_type_map[type / FC_NS_BPW];
343 *mp = htonl(ntohl(*mp) | 1UL << (type % FC_NS_BPW));
347 * fc_lport_recv_rlir_req() - Handle received Registered Link Incident Report.
348 * @lport: Fibre Channel local port recieving the RLIR
349 * @sp: current sequence in the RLIR exchange
350 * @fp: RLIR request frame
352 * Locking Note: The lport lock is exected to be held before calling
355 static void fc_lport_recv_rlir_req(struct fc_seq *sp, struct fc_frame *fp,
356 struct fc_lport *lport)
358 FC_LPORT_DBG(lport, "Received RLIR request while in state %s\n",
359 fc_lport_state(lport));
361 lport->tt.seq_els_rsp_send(sp, ELS_LS_ACC, NULL);
366 * fc_lport_recv_echo_req() - Handle received ECHO request
367 * @lport: Fibre Channel local port recieving the ECHO
368 * @sp: current sequence in the ECHO exchange
369 * @fp: ECHO request frame
371 * Locking Note: The lport lock is exected to be held before calling
374 static void fc_lport_recv_echo_req(struct fc_seq *sp, struct fc_frame *in_fp,
375 struct fc_lport *lport)
378 struct fc_exch *ep = fc_seq_exch(sp);
384 FC_LPORT_DBG(lport, "Received RLIR request while in state %s\n",
385 fc_lport_state(lport));
387 len = fr_len(in_fp) - sizeof(struct fc_frame_header);
388 pp = fc_frame_payload_get(in_fp, len);
390 if (len < sizeof(__be32))
391 len = sizeof(__be32);
393 fp = fc_frame_alloc(lport, len);
395 dp = fc_frame_payload_get(fp, len);
397 *((u32 *)dp) = htonl(ELS_LS_ACC << 24);
398 sp = lport->tt.seq_start_next(sp);
399 f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ | FC_FC_END_SEQ;
400 fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid,
401 FC_TYPE_ELS, f_ctl, 0);
402 lport->tt.seq_send(lport, sp, fp);
404 fc_frame_free(in_fp);
408 * fc_lport_recv_echo_req() - Handle received Request Node ID data request
409 * @lport: Fibre Channel local port recieving the RNID
410 * @sp: current sequence in the RNID exchange
411 * @fp: RNID request frame
413 * Locking Note: The lport lock is exected to be held before calling
416 static void fc_lport_recv_rnid_req(struct fc_seq *sp, struct fc_frame *in_fp,
417 struct fc_lport *lport)
420 struct fc_exch *ep = fc_seq_exch(sp);
421 struct fc_els_rnid *req;
423 struct fc_els_rnid_resp rnid;
424 struct fc_els_rnid_cid cid;
425 struct fc_els_rnid_gen gen;
427 struct fc_seq_els_data rjt_data;
432 FC_LPORT_DBG(lport, "Received RNID request while in state %s\n",
433 fc_lport_state(lport));
435 req = fc_frame_payload_get(in_fp, sizeof(*req));
438 rjt_data.reason = ELS_RJT_LOGIC;
439 rjt_data.explan = ELS_EXPL_NONE;
440 lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data);
444 if (fmt != ELS_RNIDF_GEN ||
445 ntohl(lport->rnid_gen.rnid_atype) == 0) {
446 fmt = ELS_RNIDF_NONE; /* nothing to provide */
447 len -= sizeof(rp->gen);
449 fp = fc_frame_alloc(lport, len);
451 rp = fc_frame_payload_get(fp, len);
453 rp->rnid.rnid_cmd = ELS_LS_ACC;
454 rp->rnid.rnid_fmt = fmt;
455 rp->rnid.rnid_cid_len = sizeof(rp->cid);
456 rp->cid.rnid_wwpn = htonll(lport->wwpn);
457 rp->cid.rnid_wwnn = htonll(lport->wwnn);
458 if (fmt == ELS_RNIDF_GEN) {
459 rp->rnid.rnid_sid_len = sizeof(rp->gen);
460 memcpy(&rp->gen, &lport->rnid_gen,
463 sp = lport->tt.seq_start_next(sp);
464 f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ;
465 f_ctl |= FC_FC_END_SEQ | FC_FC_SEQ_INIT;
466 fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid,
467 FC_TYPE_ELS, f_ctl, 0);
468 lport->tt.seq_send(lport, sp, fp);
471 fc_frame_free(in_fp);
475 * fc_lport_recv_adisc_req() - Handle received Address Discovery Request
476 * @lport: Fibre Channel local port recieving the ADISC
477 * @sp: current sequence in the ADISC exchange
478 * @fp: ADISC request frame
480 * Locking Note: The lport lock is expected to be held before calling
483 static void fc_lport_recv_adisc_req(struct fc_seq *sp, struct fc_frame *in_fp,
484 struct fc_lport *lport)
487 struct fc_exch *ep = fc_seq_exch(sp);
488 struct fc_els_adisc *req, *rp;
489 struct fc_seq_els_data rjt_data;
493 FC_LPORT_DBG(lport, "Received ADISC request while in state %s\n",
494 fc_lport_state(lport));
496 req = fc_frame_payload_get(in_fp, sizeof(*req));
499 rjt_data.reason = ELS_RJT_LOGIC;
500 rjt_data.explan = ELS_EXPL_NONE;
501 lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data);
504 fp = fc_frame_alloc(lport, len);
506 rp = fc_frame_payload_get(fp, len);
508 rp->adisc_cmd = ELS_LS_ACC;
509 rp->adisc_wwpn = htonll(lport->wwpn);
510 rp->adisc_wwnn = htonll(lport->wwnn);
511 hton24(rp->adisc_port_id,
512 fc_host_port_id(lport->host));
513 sp = lport->tt.seq_start_next(sp);
514 f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ;
515 f_ctl |= FC_FC_END_SEQ | FC_FC_SEQ_INIT;
516 fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid,
517 FC_TYPE_ELS, f_ctl, 0);
518 lport->tt.seq_send(lport, sp, fp);
521 fc_frame_free(in_fp);
525 * fc_lport_recv_logo_req() - Handle received fabric LOGO request
526 * @lport: Fibre Channel local port recieving the LOGO
527 * @sp: current sequence in the LOGO exchange
528 * @fp: LOGO request frame
530 * Locking Note: The lport lock is exected to be held before calling
533 static void fc_lport_recv_logo_req(struct fc_seq *sp, struct fc_frame *fp,
534 struct fc_lport *lport)
536 lport->tt.seq_els_rsp_send(sp, ELS_LS_ACC, NULL);
537 fc_lport_enter_reset(lport);
542 * fc_fabric_login() - Start the lport state machine
543 * @lport: The lport that should log into the fabric
545 * Locking Note: This function should not be called
546 * with the lport lock held.
548 int fc_fabric_login(struct fc_lport *lport)
552 mutex_lock(&lport->lp_mutex);
553 if (lport->state == LPORT_ST_DISABLED) {
554 fc_lport_enter_reset(lport);
557 mutex_unlock(&lport->lp_mutex);
561 EXPORT_SYMBOL(fc_fabric_login);
564 * fc_linkup() - Handler for transport linkup events
565 * @lport: The lport whose link is up
567 void fc_linkup(struct fc_lport *lport)
569 printk(KERN_INFO "libfc: Link up on port (%6x)\n",
570 fc_host_port_id(lport->host));
572 mutex_lock(&lport->lp_mutex);
573 if (!lport->link_up) {
576 if (lport->state == LPORT_ST_RESET)
577 fc_lport_enter_flogi(lport);
579 mutex_unlock(&lport->lp_mutex);
581 EXPORT_SYMBOL(fc_linkup);
584 * fc_linkdown() - Handler for transport linkdown events
585 * @lport: The lport whose link is down
587 void fc_linkdown(struct fc_lport *lport)
589 mutex_lock(&lport->lp_mutex);
590 printk(KERN_INFO "libfc: Link down on port (%6x)\n",
591 fc_host_port_id(lport->host));
593 if (lport->link_up) {
595 fc_lport_enter_reset(lport);
596 lport->tt.fcp_cleanup(lport);
598 mutex_unlock(&lport->lp_mutex);
600 EXPORT_SYMBOL(fc_linkdown);
603 * fc_fabric_logoff() - Logout of the fabric
604 * @lport: fc_lport pointer to logoff the fabric
607 * 0 for success, -1 for failure
609 int fc_fabric_logoff(struct fc_lport *lport)
611 lport->tt.disc_stop_final(lport);
612 mutex_lock(&lport->lp_mutex);
614 lport->tt.rport_logoff(lport->dns_rp);
615 mutex_unlock(&lport->lp_mutex);
616 lport->tt.rport_flush_queue();
617 mutex_lock(&lport->lp_mutex);
618 fc_lport_enter_logo(lport);
619 mutex_unlock(&lport->lp_mutex);
620 cancel_delayed_work_sync(&lport->retry_work);
623 EXPORT_SYMBOL(fc_fabric_logoff);
626 * fc_lport_destroy() - unregister a fc_lport
627 * @lport: fc_lport pointer to unregister
632 * exit routine for fc_lport instance
633 * clean-up all the allocated memory
634 * and free up other system resources.
637 int fc_lport_destroy(struct fc_lport *lport)
639 mutex_lock(&lport->lp_mutex);
640 lport->state = LPORT_ST_DISABLED;
642 lport->tt.frame_send = fc_frame_drop;
643 mutex_unlock(&lport->lp_mutex);
645 lport->tt.fcp_abort_io(lport);
646 lport->tt.disc_stop_final(lport);
647 lport->tt.exch_mgr_reset(lport, 0, 0);
650 EXPORT_SYMBOL(fc_lport_destroy);
653 * fc_set_mfs() - sets up the mfs for the corresponding fc_lport
654 * @lport: fc_lport pointer to unregister
655 * @mfs: the new mfs for fc_lport
657 * Set mfs for the given fc_lport to the new mfs.
659 * Return: 0 for success
661 int fc_set_mfs(struct fc_lport *lport, u32 mfs)
663 unsigned int old_mfs;
666 mutex_lock(&lport->lp_mutex);
668 old_mfs = lport->mfs;
670 if (mfs >= FC_MIN_MAX_FRAME) {
672 if (mfs > FC_MAX_FRAME)
674 mfs -= sizeof(struct fc_frame_header);
679 if (!rc && mfs < old_mfs)
680 fc_lport_enter_reset(lport);
682 mutex_unlock(&lport->lp_mutex);
686 EXPORT_SYMBOL(fc_set_mfs);
689 * fc_lport_disc_callback() - Callback for discovery events
690 * @lport: FC local port
691 * @event: The discovery event
693 void fc_lport_disc_callback(struct fc_lport *lport, enum fc_disc_event event)
696 case DISC_EV_SUCCESS:
697 FC_LPORT_DBG(lport, "Discovery succeeded\n");
700 printk(KERN_ERR "libfc: Discovery failed for port (%6x)\n",
701 fc_host_port_id(lport->host));
702 mutex_lock(&lport->lp_mutex);
703 fc_lport_enter_reset(lport);
704 mutex_unlock(&lport->lp_mutex);
713 * fc_rport_enter_ready() - Enter the ready state and start discovery
714 * @lport: Fibre Channel local port that is ready
716 * Locking Note: The lport lock is expected to be held before calling
719 static void fc_lport_enter_ready(struct fc_lport *lport)
721 FC_LPORT_DBG(lport, "Entered READY from state %s\n",
722 fc_lport_state(lport));
724 fc_lport_state_enter(lport, LPORT_ST_READY);
726 lport->tt.disc_start(fc_lport_disc_callback, lport);
730 * fc_lport_recv_flogi_req() - Receive a FLOGI request
731 * @sp_in: The sequence the FLOGI is on
732 * @rx_fp: The frame the FLOGI is in
733 * @lport: The lport that recieved the request
735 * A received FLOGI request indicates a point-to-point connection.
736 * Accept it with the common service parameters indicating our N port.
737 * Set up to do a PLOGI if we have the higher-number WWPN.
739 * Locking Note: The lport lock is exected to be held before calling
742 static void fc_lport_recv_flogi_req(struct fc_seq *sp_in,
743 struct fc_frame *rx_fp,
744 struct fc_lport *lport)
747 struct fc_frame_header *fh;
750 struct fc_els_flogi *flp;
751 struct fc_els_flogi *new_flp;
757 FC_LPORT_DBG(lport, "Received FLOGI request while in state %s\n",
758 fc_lport_state(lport));
760 fh = fc_frame_header_get(rx_fp);
761 remote_fid = ntoh24(fh->fh_s_id);
762 flp = fc_frame_payload_get(rx_fp, sizeof(*flp));
765 remote_wwpn = get_unaligned_be64(&flp->fl_wwpn);
766 if (remote_wwpn == lport->wwpn) {
767 printk(KERN_WARNING "libfc: Received FLOGI from port "
768 "with same WWPN %llx\n", remote_wwpn);
771 FC_LPORT_DBG(lport, "FLOGI from port WWPN %llx\n", remote_wwpn);
774 * XXX what is the right thing to do for FIDs?
775 * The originator might expect our S_ID to be 0xfffffe.
776 * But if so, both of us could end up with the same FID.
778 local_fid = FC_LOCAL_PTP_FID_LO;
779 if (remote_wwpn < lport->wwpn) {
780 local_fid = FC_LOCAL_PTP_FID_HI;
781 if (!remote_fid || remote_fid == local_fid)
782 remote_fid = FC_LOCAL_PTP_FID_LO;
783 } else if (!remote_fid) {
784 remote_fid = FC_LOCAL_PTP_FID_HI;
787 fc_host_port_id(lport->host) = local_fid;
789 fp = fc_frame_alloc(lport, sizeof(*flp));
791 sp = lport->tt.seq_start_next(fr_seq(rx_fp));
792 new_flp = fc_frame_payload_get(fp, sizeof(*flp));
793 fc_lport_flogi_fill(lport, new_flp, ELS_FLOGI);
794 new_flp->fl_cmd = (u8) ELS_LS_ACC;
797 * Send the response. If this fails, the originator should
798 * repeat the sequence.
800 f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ | FC_FC_END_SEQ;
801 ep = fc_seq_exch(sp);
802 fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid,
803 FC_TYPE_ELS, f_ctl, 0);
804 lport->tt.seq_send(lport, sp, fp);
807 fc_lport_error(lport, fp);
809 fc_lport_ptp_setup(lport, remote_fid, remote_wwpn,
810 get_unaligned_be64(&flp->fl_wwnn));
812 lport->tt.disc_start(fc_lport_disc_callback, lport);
816 fc_frame_free(rx_fp);
820 * fc_lport_recv_req() - The generic lport request handler
821 * @lport: The lport that received the request
822 * @sp: The sequence the request is on
823 * @fp: The frame the request is in
825 * This function will see if the lport handles the request or
826 * if an rport should handle the request.
828 * Locking Note: This function should not be called with the lport
829 * lock held becuase it will grab the lock.
831 static void fc_lport_recv_req(struct fc_lport *lport, struct fc_seq *sp,
834 struct fc_frame_header *fh = fc_frame_header_get(fp);
835 void (*recv) (struct fc_seq *, struct fc_frame *, struct fc_lport *);
836 struct fc_rport *rport;
839 struct fc_seq_els_data rjt_data;
841 mutex_lock(&lport->lp_mutex);
844 * Handle special ELS cases like FLOGI, LOGO, and
845 * RSCN here. These don't require a session.
846 * Even if we had a session, it might not be ready.
850 else if (fh->fh_type == FC_TYPE_ELS &&
851 fh->fh_r_ctl == FC_RCTL_ELS_REQ) {
856 switch (fc_frame_payload_op(fp)) {
858 recv = fc_lport_recv_flogi_req;
861 fh = fc_frame_header_get(fp);
862 if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI)
863 recv = fc_lport_recv_logo_req;
866 recv = lport->tt.disc_recv_req;
869 recv = fc_lport_recv_echo_req;
872 recv = fc_lport_recv_rlir_req;
875 recv = fc_lport_recv_rnid_req;
878 recv = fc_lport_recv_adisc_req;
887 * If this is a new incoming PLOGI, we won't find it.
889 s_id = ntoh24(fh->fh_s_id);
890 d_id = ntoh24(fh->fh_d_id);
892 rport = lport->tt.rport_lookup(lport, s_id);
894 lport->tt.rport_recv_req(sp, fp, rport);
897 rjt_data.reason = ELS_RJT_UNAB;
898 rjt_data.explan = ELS_EXPL_NONE;
899 lport->tt.seq_els_rsp_send(sp,
906 FC_LPORT_DBG(lport, "dropping invalid frame (eof %x)\n",
910 mutex_unlock(&lport->lp_mutex);
913 * The common exch_done for all request may not be good
914 * if any request requires longer hold on exhange. XXX
916 lport->tt.exch_done(sp);
920 * fc_lport_reset() - Reset an lport
921 * @lport: The lport which should be reset
923 * Locking Note: This functions should not be called with the
926 int fc_lport_reset(struct fc_lport *lport)
928 cancel_delayed_work_sync(&lport->retry_work);
929 mutex_lock(&lport->lp_mutex);
930 fc_lport_enter_reset(lport);
931 mutex_unlock(&lport->lp_mutex);
934 EXPORT_SYMBOL(fc_lport_reset);
937 * fc_lport_reset_locked() - Reset the local port
938 * @lport: Fibre Channel local port to be reset
940 * Locking Note: The lport lock is expected to be held before calling
943 static void fc_lport_reset_locked(struct fc_lport *lport)
946 lport->tt.rport_logoff(lport->dns_rp);
949 lport->tt.rport_logoff(lport->ptp_rp);
950 lport->ptp_rp = NULL;
953 lport->tt.disc_stop(lport);
955 lport->tt.exch_mgr_reset(lport, 0, 0);
956 fc_host_fabric_name(lport->host) = 0;
957 fc_host_port_id(lport->host) = 0;
961 * fc_lport_enter_reset() - Reset the local port
962 * @lport: Fibre Channel local port to be reset
964 * Locking Note: The lport lock is expected to be held before calling
967 static void fc_lport_enter_reset(struct fc_lport *lport)
969 FC_LPORT_DBG(lport, "Entered RESET state from %s state\n",
970 fc_lport_state(lport));
972 fc_lport_state_enter(lport, LPORT_ST_RESET);
973 fc_lport_reset_locked(lport);
975 fc_lport_enter_flogi(lport);
979 * fc_lport_enter_disabled() - disable the local port
980 * @lport: Fibre Channel local port to be reset
982 * Locking Note: The lport lock is expected to be held before calling
985 static void fc_lport_enter_disabled(struct fc_lport *lport)
987 FC_LPORT_DBG(lport, "Entered disabled state from %s state\n",
988 fc_lport_state(lport));
990 fc_lport_state_enter(lport, LPORT_ST_DISABLED);
991 fc_lport_reset_locked(lport);
995 * fc_lport_error() - Handler for any errors
996 * @lport: The fc_lport object
997 * @fp: The frame pointer
999 * If the error was caused by a resource allocation failure
1000 * then wait for half a second and retry, otherwise retry
1001 * after the e_d_tov time.
1003 static void fc_lport_error(struct fc_lport *lport, struct fc_frame *fp)
1005 unsigned long delay = 0;
1006 FC_LPORT_DBG(lport, "Error %ld in state %s, retries %d\n",
1007 PTR_ERR(fp), fc_lport_state(lport),
1008 lport->retry_count);
1010 if (!fp || PTR_ERR(fp) == -FC_EX_TIMEOUT) {
1012 * Memory allocation failure, or the exchange timed out.
1015 if (lport->retry_count < lport->max_retry_count) {
1016 lport->retry_count++;
1018 delay = msecs_to_jiffies(500);
1020 delay = msecs_to_jiffies(lport->e_d_tov);
1022 schedule_delayed_work(&lport->retry_work, delay);
1024 switch (lport->state) {
1025 case LPORT_ST_DISABLED:
1026 case LPORT_ST_READY:
1027 case LPORT_ST_RESET:
1028 case LPORT_ST_RPN_ID:
1029 case LPORT_ST_RFT_ID:
1032 case LPORT_ST_FLOGI:
1034 fc_lport_enter_reset(lport);
1042 * fc_lport_rft_id_resp() - Handle response to Register Fibre
1043 * Channel Types by ID (RPN_ID) request
1044 * @sp: current sequence in RPN_ID exchange
1045 * @fp: response frame
1046 * @lp_arg: Fibre Channel host port instance
1048 * Locking Note: This function will be called without the lport lock
1049 * held, but it will lock, call an _enter_* function or fc_lport_error
1050 * and then unlock the lport.
1052 static void fc_lport_rft_id_resp(struct fc_seq *sp, struct fc_frame *fp,
1055 struct fc_lport *lport = lp_arg;
1056 struct fc_frame_header *fh;
1057 struct fc_ct_hdr *ct;
1059 if (fp == ERR_PTR(-FC_EX_CLOSED))
1062 mutex_lock(&lport->lp_mutex);
1064 FC_LPORT_DBG(lport, "Received a RFT_ID response\n");
1066 if (lport->state != LPORT_ST_RFT_ID) {
1067 FC_LPORT_DBG(lport, "Received a RFT_ID response, but in state "
1068 "%s\n", fc_lport_state(lport));
1075 fc_lport_error(lport, fp);
1079 fh = fc_frame_header_get(fp);
1080 ct = fc_frame_payload_get(fp, sizeof(*ct));
1082 if (fh && ct && fh->fh_type == FC_TYPE_CT &&
1083 ct->ct_fs_type == FC_FST_DIR &&
1084 ct->ct_fs_subtype == FC_NS_SUBTYPE &&
1085 ntohs(ct->ct_cmd) == FC_FS_ACC)
1086 fc_lport_enter_scr(lport);
1088 fc_lport_error(lport, fp);
1092 mutex_unlock(&lport->lp_mutex);
1096 * fc_lport_rpn_id_resp() - Handle response to Register Port
1097 * Name by ID (RPN_ID) request
1098 * @sp: current sequence in RPN_ID exchange
1099 * @fp: response frame
1100 * @lp_arg: Fibre Channel host port instance
1102 * Locking Note: This function will be called without the lport lock
1103 * held, but it will lock, call an _enter_* function or fc_lport_error
1104 * and then unlock the lport.
1106 static void fc_lport_rpn_id_resp(struct fc_seq *sp, struct fc_frame *fp,
1109 struct fc_lport *lport = lp_arg;
1110 struct fc_frame_header *fh;
1111 struct fc_ct_hdr *ct;
1113 if (fp == ERR_PTR(-FC_EX_CLOSED))
1116 mutex_lock(&lport->lp_mutex);
1118 FC_LPORT_DBG(lport, "Received a RPN_ID response\n");
1120 if (lport->state != LPORT_ST_RPN_ID) {
1121 FC_LPORT_DBG(lport, "Received a RPN_ID response, but in state "
1122 "%s\n", fc_lport_state(lport));
1129 fc_lport_error(lport, fp);
1133 fh = fc_frame_header_get(fp);
1134 ct = fc_frame_payload_get(fp, sizeof(*ct));
1135 if (fh && ct && fh->fh_type == FC_TYPE_CT &&
1136 ct->ct_fs_type == FC_FST_DIR &&
1137 ct->ct_fs_subtype == FC_NS_SUBTYPE &&
1138 ntohs(ct->ct_cmd) == FC_FS_ACC)
1139 fc_lport_enter_rft_id(lport);
1141 fc_lport_error(lport, fp);
1146 mutex_unlock(&lport->lp_mutex);
1150 * fc_lport_scr_resp() - Handle response to State Change Register (SCR) request
1151 * @sp: current sequence in SCR exchange
1152 * @fp: response frame
1153 * @lp_arg: Fibre Channel lport port instance that sent the registration request
1155 * Locking Note: This function will be called without the lport lock
1156 * held, but it will lock, call an _enter_* function or fc_lport_error
1157 * and then unlock the lport.
1159 static void fc_lport_scr_resp(struct fc_seq *sp, struct fc_frame *fp,
1162 struct fc_lport *lport = lp_arg;
1165 if (fp == ERR_PTR(-FC_EX_CLOSED))
1168 mutex_lock(&lport->lp_mutex);
1170 FC_LPORT_DBG(lport, "Received a SCR response\n");
1172 if (lport->state != LPORT_ST_SCR) {
1173 FC_LPORT_DBG(lport, "Received a SCR response, but in state "
1174 "%s\n", fc_lport_state(lport));
1181 fc_lport_error(lport, fp);
1185 op = fc_frame_payload_op(fp);
1186 if (op == ELS_LS_ACC)
1187 fc_lport_enter_ready(lport);
1189 fc_lport_error(lport, fp);
1194 mutex_unlock(&lport->lp_mutex);
1198 * fc_lport_enter_scr() - Send a State Change Register (SCR) request
1199 * @lport: Fibre Channel local port to register for state changes
1201 * Locking Note: The lport lock is expected to be held before calling
1204 static void fc_lport_enter_scr(struct fc_lport *lport)
1206 struct fc_frame *fp;
1208 FC_LPORT_DBG(lport, "Entered SCR state from %s state\n",
1209 fc_lport_state(lport));
1211 fc_lport_state_enter(lport, LPORT_ST_SCR);
1213 fp = fc_frame_alloc(lport, sizeof(struct fc_els_scr));
1215 fc_lport_error(lport, fp);
1219 if (!lport->tt.elsct_send(lport, NULL, fp, ELS_SCR,
1220 fc_lport_scr_resp, lport, lport->e_d_tov))
1221 fc_lport_error(lport, fp);
1225 * fc_lport_enter_rft_id() - Register FC4-types with the name server
1226 * @lport: Fibre Channel local port to register
1228 * Locking Note: The lport lock is expected to be held before calling
1231 static void fc_lport_enter_rft_id(struct fc_lport *lport)
1233 struct fc_frame *fp;
1234 struct fc_ns_fts *lps;
1237 FC_LPORT_DBG(lport, "Entered RFT_ID state from %s state\n",
1238 fc_lport_state(lport));
1240 fc_lport_state_enter(lport, LPORT_ST_RFT_ID);
1243 i = sizeof(lps->ff_type_map) / sizeof(lps->ff_type_map[0]);
1245 if (ntohl(lps->ff_type_map[i]) != 0)
1248 /* nothing to register, move on to SCR */
1249 fc_lport_enter_scr(lport);
1253 fp = fc_frame_alloc(lport, sizeof(struct fc_ct_hdr) +
1254 sizeof(struct fc_ns_rft));
1256 fc_lport_error(lport, fp);
1260 if (!lport->tt.elsct_send(lport, NULL, fp, FC_NS_RFT_ID,
1261 fc_lport_rft_id_resp,
1262 lport, lport->e_d_tov))
1263 fc_lport_error(lport, fp);
1267 * fc_rport_enter_rft_id() - Register port name with the name server
1268 * @lport: Fibre Channel local port to register
1270 * Locking Note: The lport lock is expected to be held before calling
1273 static void fc_lport_enter_rpn_id(struct fc_lport *lport)
1275 struct fc_frame *fp;
1277 FC_LPORT_DBG(lport, "Entered RPN_ID state from %s state\n",
1278 fc_lport_state(lport));
1280 fc_lport_state_enter(lport, LPORT_ST_RPN_ID);
1282 fp = fc_frame_alloc(lport, sizeof(struct fc_ct_hdr) +
1283 sizeof(struct fc_ns_rn_id));
1285 fc_lport_error(lport, fp);
1289 if (!lport->tt.elsct_send(lport, NULL, fp, FC_NS_RPN_ID,
1290 fc_lport_rpn_id_resp,
1291 lport, lport->e_d_tov))
1292 fc_lport_error(lport, fp);
1295 static struct fc_rport_operations fc_lport_rport_ops = {
1296 .event_callback = fc_lport_rport_callback,
1300 * fc_rport_enter_dns() - Create a rport to the name server
1301 * @lport: Fibre Channel local port requesting a rport for the name server
1303 * Locking Note: The lport lock is expected to be held before calling
1306 static void fc_lport_enter_dns(struct fc_lport *lport)
1308 struct fc_rport *rport;
1309 struct fc_rport_priv *rdata;
1310 struct fc_disc_port dp;
1312 dp.ids.port_id = FC_FID_DIR_SERV;
1313 dp.ids.port_name = -1;
1314 dp.ids.node_name = -1;
1315 dp.ids.roles = FC_RPORT_ROLE_UNKNOWN;
1318 FC_LPORT_DBG(lport, "Entered DNS state from %s state\n",
1319 fc_lport_state(lport));
1321 fc_lport_state_enter(lport, LPORT_ST_DNS);
1323 rport = lport->tt.rport_create(&dp);
1327 rdata = rport->dd_data;
1328 rdata->ops = &fc_lport_rport_ops;
1329 lport->tt.rport_login(rport);
1333 fc_lport_error(lport, NULL);
1337 * fc_lport_timeout() - Handler for the retry_work timer.
1338 * @work: The work struct of the fc_lport
1340 static void fc_lport_timeout(struct work_struct *work)
1342 struct fc_lport *lport =
1343 container_of(work, struct fc_lport,
1346 mutex_lock(&lport->lp_mutex);
1348 switch (lport->state) {
1349 case LPORT_ST_DISABLED:
1350 case LPORT_ST_READY:
1351 case LPORT_ST_RESET:
1354 case LPORT_ST_FLOGI:
1355 fc_lport_enter_flogi(lport);
1358 fc_lport_enter_dns(lport);
1360 case LPORT_ST_RPN_ID:
1361 fc_lport_enter_rpn_id(lport);
1363 case LPORT_ST_RFT_ID:
1364 fc_lport_enter_rft_id(lport);
1367 fc_lport_enter_scr(lport);
1370 fc_lport_enter_logo(lport);
1374 mutex_unlock(&lport->lp_mutex);
1378 * fc_lport_logo_resp() - Handle response to LOGO request
1379 * @sp: current sequence in LOGO exchange
1380 * @fp: response frame
1381 * @lp_arg: Fibre Channel lport port instance that sent the LOGO request
1383 * Locking Note: This function will be called without the lport lock
1384 * held, but it will lock, call an _enter_* function or fc_lport_error
1385 * and then unlock the lport.
1387 static void fc_lport_logo_resp(struct fc_seq *sp, struct fc_frame *fp,
1390 struct fc_lport *lport = lp_arg;
1393 if (fp == ERR_PTR(-FC_EX_CLOSED))
1396 mutex_lock(&lport->lp_mutex);
1398 FC_LPORT_DBG(lport, "Received a LOGO response\n");
1400 if (lport->state != LPORT_ST_LOGO) {
1401 FC_LPORT_DBG(lport, "Received a LOGO response, but in state "
1402 "%s\n", fc_lport_state(lport));
1409 fc_lport_error(lport, fp);
1413 op = fc_frame_payload_op(fp);
1414 if (op == ELS_LS_ACC)
1415 fc_lport_enter_disabled(lport);
1417 fc_lport_error(lport, fp);
1422 mutex_unlock(&lport->lp_mutex);
1426 * fc_rport_enter_logo() - Logout of the fabric
1427 * @lport: Fibre Channel local port to be logged out
1429 * Locking Note: The lport lock is expected to be held before calling
1432 static void fc_lport_enter_logo(struct fc_lport *lport)
1434 struct fc_frame *fp;
1435 struct fc_els_logo *logo;
1437 FC_LPORT_DBG(lport, "Entered LOGO state from %s state\n",
1438 fc_lport_state(lport));
1440 fc_lport_state_enter(lport, LPORT_ST_LOGO);
1442 fp = fc_frame_alloc(lport, sizeof(*logo));
1444 fc_lport_error(lport, fp);
1448 if (!lport->tt.elsct_send(lport, NULL, fp, ELS_LOGO, fc_lport_logo_resp,
1449 lport, lport->e_d_tov))
1450 fc_lport_error(lport, fp);
1454 * fc_lport_flogi_resp() - Handle response to FLOGI request
1455 * @sp: current sequence in FLOGI exchange
1456 * @fp: response frame
1457 * @lp_arg: Fibre Channel lport port instance that sent the FLOGI request
1459 * Locking Note: This function will be called without the lport lock
1460 * held, but it will lock, call an _enter_* function or fc_lport_error
1461 * and then unlock the lport.
1463 static void fc_lport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp,
1466 struct fc_lport *lport = lp_arg;
1467 struct fc_frame_header *fh;
1468 struct fc_els_flogi *flp;
1471 unsigned int r_a_tov;
1472 unsigned int e_d_tov;
1475 if (fp == ERR_PTR(-FC_EX_CLOSED))
1478 mutex_lock(&lport->lp_mutex);
1480 FC_LPORT_DBG(lport, "Received a FLOGI response\n");
1482 if (lport->state != LPORT_ST_FLOGI) {
1483 FC_LPORT_DBG(lport, "Received a FLOGI response, but in state "
1484 "%s\n", fc_lport_state(lport));
1491 fc_lport_error(lport, fp);
1495 fh = fc_frame_header_get(fp);
1496 did = ntoh24(fh->fh_d_id);
1497 if (fc_frame_payload_op(fp) == ELS_LS_ACC && did != 0) {
1499 printk(KERN_INFO "libfc: Assigned FID (%6x) in FLOGI response\n",
1501 fc_host_port_id(lport->host) = did;
1503 flp = fc_frame_payload_get(fp, sizeof(*flp));
1505 mfs = ntohs(flp->fl_csp.sp_bb_data) &
1507 if (mfs >= FC_SP_MIN_MAX_PAYLOAD &&
1510 csp_flags = ntohs(flp->fl_csp.sp_features);
1511 r_a_tov = ntohl(flp->fl_csp.sp_r_a_tov);
1512 e_d_tov = ntohl(flp->fl_csp.sp_e_d_tov);
1513 if (csp_flags & FC_SP_FT_EDTR)
1515 if ((csp_flags & FC_SP_FT_FPORT) == 0) {
1516 if (e_d_tov > lport->e_d_tov)
1517 lport->e_d_tov = e_d_tov;
1518 lport->r_a_tov = 2 * e_d_tov;
1519 printk(KERN_INFO "libfc: Port (%6x) entered "
1520 "point to point mode\n", did);
1521 fc_lport_ptp_setup(lport, ntoh24(fh->fh_s_id),
1527 lport->e_d_tov = e_d_tov;
1528 lport->r_a_tov = r_a_tov;
1529 fc_host_fabric_name(lport->host) =
1530 get_unaligned_be64(&flp->fl_wwnn);
1531 fc_lport_enter_dns(lport);
1536 csp_flags = ntohs(flp->fl_csp.sp_features);
1537 if ((csp_flags & FC_SP_FT_FPORT) == 0) {
1538 lport->tt.disc_start(fc_lport_disc_callback,
1543 FC_LPORT_DBG(lport, "Bad FLOGI response\n");
1549 mutex_unlock(&lport->lp_mutex);
1553 * fc_rport_enter_flogi() - Send a FLOGI request to the fabric manager
1554 * @lport: Fibre Channel local port to be logged in to the fabric
1556 * Locking Note: The lport lock is expected to be held before calling
1559 void fc_lport_enter_flogi(struct fc_lport *lport)
1561 struct fc_frame *fp;
1563 FC_LPORT_DBG(lport, "Entered FLOGI state from %s state\n",
1564 fc_lport_state(lport));
1566 fc_lport_state_enter(lport, LPORT_ST_FLOGI);
1568 fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi));
1570 return fc_lport_error(lport, fp);
1572 if (!lport->tt.elsct_send(lport, NULL, fp, ELS_FLOGI,
1573 fc_lport_flogi_resp, lport, lport->e_d_tov))
1574 fc_lport_error(lport, fp);
1577 /* Configure a fc_lport */
1578 int fc_lport_config(struct fc_lport *lport)
1580 INIT_DELAYED_WORK(&lport->retry_work, fc_lport_timeout);
1581 mutex_init(&lport->lp_mutex);
1583 fc_lport_state_enter(lport, LPORT_ST_DISABLED);
1585 fc_lport_add_fc4_type(lport, FC_TYPE_FCP);
1586 fc_lport_add_fc4_type(lport, FC_TYPE_CT);
1590 EXPORT_SYMBOL(fc_lport_config);
1592 int fc_lport_init(struct fc_lport *lport)
1594 if (!lport->tt.lport_recv)
1595 lport->tt.lport_recv = fc_lport_recv_req;
1597 if (!lport->tt.lport_reset)
1598 lport->tt.lport_reset = fc_lport_reset;
1600 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
1601 fc_host_node_name(lport->host) = lport->wwnn;
1602 fc_host_port_name(lport->host) = lport->wwpn;
1603 fc_host_supported_classes(lport->host) = FC_COS_CLASS3;
1604 memset(fc_host_supported_fc4s(lport->host), 0,
1605 sizeof(fc_host_supported_fc4s(lport->host)));
1606 fc_host_supported_fc4s(lport->host)[2] = 1;
1607 fc_host_supported_fc4s(lport->host)[7] = 1;
1609 /* This value is also unchanging */
1610 memset(fc_host_active_fc4s(lport->host), 0,
1611 sizeof(fc_host_active_fc4s(lport->host)));
1612 fc_host_active_fc4s(lport->host)[2] = 1;
1613 fc_host_active_fc4s(lport->host)[7] = 1;
1614 fc_host_maxframe_size(lport->host) = lport->mfs;
1615 fc_host_supported_speeds(lport->host) = 0;
1616 if (lport->link_supported_speeds & FC_PORTSPEED_1GBIT)
1617 fc_host_supported_speeds(lport->host) |= FC_PORTSPEED_1GBIT;
1618 if (lport->link_supported_speeds & FC_PORTSPEED_10GBIT)
1619 fc_host_supported_speeds(lport->host) |= FC_PORTSPEED_10GBIT;
1621 INIT_LIST_HEAD(&lport->ema_list);
1624 EXPORT_SYMBOL(fc_lport_init);