Lines Matching +full:local +full:- +full:host
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Maintained at www.Open-FCoE.org
27 * be held while attempting to acquire a greater lock. Here is the hierarchy-
42 * single-threaded workqueue. An rport would never be free'd while in a
92 /* Fabric IDs to use for point-to-point mode, chosen on whims. */
134 * struct fc_bsg_info - FC Passthrough managemet structure
136 * @lport: The local port to pass through a command
138 * @sg: job->reply_payload.sg_list
139 * @nents: job->reply_payload.sg_cnt
152 * fc_frame_drop() - Dummy frame handler
153 * @lport: The local port the frame was received on
163 * fc_lport_rport_callback() - Event handler for rport events
176 rdata->ids.port_id); in fc_lport_rport_callback()
178 mutex_lock(&lport->lp_mutex); in fc_lport_rport_callback()
181 if (lport->state == LPORT_ST_DNS) { in fc_lport_rport_callback()
182 lport->dns_rdata = rdata; in fc_lport_rport_callback()
184 } else if (lport->state == LPORT_ST_FDMI) { in fc_lport_rport_callback()
185 lport->ms_rdata = rdata; in fc_lport_rport_callback()
192 "%d state", rdata->ids.port_id, in fc_lport_rport_callback()
193 lport->state); in fc_lport_rport_callback()
200 if (rdata->ids.port_id == FC_FID_DIR_SERV) in fc_lport_rport_callback()
201 lport->dns_rdata = NULL; in fc_lport_rport_callback()
202 else if (rdata->ids.port_id == FC_FID_MGMT_SERV) in fc_lport_rport_callback()
203 lport->ms_rdata = NULL; in fc_lport_rport_callback()
208 mutex_unlock(&lport->lp_mutex); in fc_lport_rport_callback()
212 * fc_lport_state() - Return a string which represents the lport's state
219 cp = fc_lport_state_names[lport->state]; in fc_lport_state()
226 * fc_lport_ptp_setup() - Create an rport for point-to-point mode
236 lockdep_assert_held(&lport->lp_mutex); in fc_lport_ptp_setup()
238 if (lport->ptp_rdata) { in fc_lport_ptp_setup()
239 fc_rport_logoff(lport->ptp_rdata); in fc_lport_ptp_setup()
240 kref_put(&lport->ptp_rdata->kref, fc_rport_destroy); in fc_lport_ptp_setup()
242 mutex_lock(&lport->disc.disc_mutex); in fc_lport_ptp_setup()
243 lport->ptp_rdata = fc_rport_create(lport, remote_fid); in fc_lport_ptp_setup()
244 kref_get(&lport->ptp_rdata->kref); in fc_lport_ptp_setup()
245 lport->ptp_rdata->ids.port_name = remote_wwpn; in fc_lport_ptp_setup()
246 lport->ptp_rdata->ids.node_name = remote_wwnn; in fc_lport_ptp_setup()
247 mutex_unlock(&lport->disc.disc_mutex); in fc_lport_ptp_setup()
249 fc_rport_login(lport->ptp_rdata); in fc_lport_ptp_setup()
255 * fc_get_host_port_state() - Return the port state of the given Scsi_Host
256 * @shost: The SCSI host whose port state is to be determined
262 mutex_lock(&lport->lp_mutex); in fc_get_host_port_state()
263 if (!lport->link_up) in fc_get_host_port_state()
266 switch (lport->state) { in fc_get_host_port_state()
273 mutex_unlock(&lport->lp_mutex); in fc_get_host_port_state()
278 * fc_get_host_speed() - Return the speed of the given Scsi_Host
279 * @shost: The SCSI host whose port speed is to be determined
285 fc_host_speed(shost) = lport->link_speed; in fc_get_host_speed()
290 * fc_get_host_stats() - Return the Scsi_Host's statistics
291 * @shost: The SCSI host whose statistics are to be returned
301 fc_stats = &lport->host_stats; in fc_get_host_stats()
304 fc_stats->seconds_since_last_reset = (jiffies - lport->boot_time) / HZ; in fc_get_host_stats()
309 stats = per_cpu_ptr(lport->stats, cpu); in fc_get_host_stats()
311 fc_stats->tx_frames += READ_ONCE(stats->TxFrames); in fc_get_host_stats()
312 fc_stats->tx_words += READ_ONCE(stats->TxWords); in fc_get_host_stats()
313 fc_stats->rx_frames += READ_ONCE(stats->RxFrames); in fc_get_host_stats()
314 fc_stats->rx_words += READ_ONCE(stats->RxWords); in fc_get_host_stats()
315 fc_stats->error_frames += READ_ONCE(stats->ErrorFrames); in fc_get_host_stats()
316 fc_stats->invalid_crc_count += READ_ONCE(stats->InvalidCRCCount); in fc_get_host_stats()
317 fc_stats->fcp_input_requests += READ_ONCE(stats->InputRequests); in fc_get_host_stats()
318 fc_stats->fcp_output_requests += READ_ONCE(stats->OutputRequests); in fc_get_host_stats()
319 fc_stats->fcp_control_requests += READ_ONCE(stats->ControlRequests); in fc_get_host_stats()
320 fcp_in_bytes += READ_ONCE(stats->InputBytes); in fc_get_host_stats()
321 fcp_out_bytes += READ_ONCE(stats->OutputBytes); in fc_get_host_stats()
322 fc_stats->fcp_packet_alloc_failures += READ_ONCE(stats->FcpPktAllocFails); in fc_get_host_stats()
323 fc_stats->fcp_packet_aborts += READ_ONCE(stats->FcpPktAborts); in fc_get_host_stats()
324 fc_stats->fcp_frame_alloc_failures += READ_ONCE(stats->FcpFrameAllocFails); in fc_get_host_stats()
325 fc_stats->link_failure_count += READ_ONCE(stats->LinkFailureCount); in fc_get_host_stats()
327 fc_stats->fcp_input_megabytes = div_u64(fcp_in_bytes, 1000000); in fc_get_host_stats()
328 fc_stats->fcp_output_megabytes = div_u64(fcp_out_bytes, 1000000); in fc_get_host_stats()
329 fc_stats->lip_count = -1; in fc_get_host_stats()
330 fc_stats->nos_count = -1; in fc_get_host_stats()
331 fc_stats->loss_of_sync_count = -1; in fc_get_host_stats()
332 fc_stats->loss_of_signal_count = -1; in fc_get_host_stats()
333 fc_stats->prim_seq_protocol_err_count = -1; in fc_get_host_stats()
334 fc_stats->dumped_frames = -1; in fc_get_host_stats()
344 * fc_lport_flogi_fill() - Fill in FLOGI command for request
345 * @lport: The local port the FLOGI is for
357 flogi->fl_cmd = (u8) op; in fc_lport_flogi_fill()
358 put_unaligned_be64(lport->wwpn, &flogi->fl_wwpn); in fc_lport_flogi_fill()
359 put_unaligned_be64(lport->wwnn, &flogi->fl_wwnn); in fc_lport_flogi_fill()
360 sp = &flogi->fl_csp; in fc_lport_flogi_fill()
361 sp->sp_hi_ver = 0x20; in fc_lport_flogi_fill()
362 sp->sp_lo_ver = 0x20; in fc_lport_flogi_fill()
363 sp->sp_bb_cred = htons(10); /* this gets set by gateway */ in fc_lport_flogi_fill()
364 sp->sp_bb_data = htons((u16) lport->mfs); in fc_lport_flogi_fill()
365 cp = &flogi->fl_cssp[3 - 1]; /* class 3 parameters */ in fc_lport_flogi_fill()
366 cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ); in fc_lport_flogi_fill()
368 sp->sp_features = htons(FC_SP_FT_CIRO); in fc_lport_flogi_fill()
369 sp->sp_tot_seq = htons(255); /* seq. we accept */ in fc_lport_flogi_fill()
370 sp->sp_rel_off = htons(0x1f); in fc_lport_flogi_fill()
371 sp->sp_e_d_tov = htonl(lport->e_d_tov); in fc_lport_flogi_fill()
373 cp->cp_rdfs = htons((u16) lport->mfs); in fc_lport_flogi_fill()
374 cp->cp_con_seq = htons(255); in fc_lport_flogi_fill()
375 cp->cp_open_seq = 1; in fc_lport_flogi_fill()
380 * fc_lport_add_fc4_type() - Add a supported FC-4 type to a local port
381 * @lport: The local port to add a new FC-4 type to
382 * @type: The new FC-4 type
388 mp = &lport->fcts.ff_type_map[type / FC_NS_BPW]; in fc_lport_add_fc4_type()
393 * fc_lport_recv_rlir_req() - Handle received Registered Link Incident Report.
394 * @lport: Fibre Channel local port receiving the RLIR
399 lockdep_assert_held(&lport->lp_mutex); in fc_lport_recv_rlir_req()
409 * fc_lport_recv_echo_req() - Handle received ECHO request
410 * @lport: The local port receiving the ECHO
421 lockdep_assert_held(&lport->lp_mutex); in fc_lport_recv_echo_req()
426 len = fr_len(in_fp) - sizeof(struct fc_frame_header); in fc_lport_recv_echo_req()
438 lport->tt.frame_send(lport, fp); in fc_lport_recv_echo_req()
444 * fc_lport_recv_rnid_req() - Handle received Request Node ID data request
445 * @lport: The local port receiving the RNID
462 lockdep_assert_held(&lport->lp_mutex); in fc_lport_recv_rnid_req()
473 fmt = req->rnid_fmt; in fc_lport_recv_rnid_req()
476 ntohl(lport->rnid_gen.rnid_atype) == 0) { in fc_lport_recv_rnid_req()
478 len -= sizeof(rp->gen); in fc_lport_recv_rnid_req()
484 rp->rnid.rnid_cmd = ELS_LS_ACC; in fc_lport_recv_rnid_req()
485 rp->rnid.rnid_fmt = fmt; in fc_lport_recv_rnid_req()
486 rp->rnid.rnid_cid_len = sizeof(rp->cid); in fc_lport_recv_rnid_req()
487 rp->cid.rnid_wwpn = htonll(lport->wwpn); in fc_lport_recv_rnid_req()
488 rp->cid.rnid_wwnn = htonll(lport->wwnn); in fc_lport_recv_rnid_req()
490 rp->rnid.rnid_sid_len = sizeof(rp->gen); in fc_lport_recv_rnid_req()
491 memcpy(&rp->gen, &lport->rnid_gen, in fc_lport_recv_rnid_req()
492 sizeof(rp->gen)); in fc_lport_recv_rnid_req()
495 lport->tt.frame_send(lport, fp); in fc_lport_recv_rnid_req()
502 * fc_lport_recv_logo_req() - Handle received fabric LOGO request
503 * @lport: The local port receiving the LOGO
508 lockdep_assert_held(&lport->lp_mutex); in fc_lport_recv_logo_req()
516 * fc_fabric_login() - Start the lport state machine
517 * @lport: The local port that should log into the fabric
524 int rc = -1; in fc_fabric_login()
526 mutex_lock(&lport->lp_mutex); in fc_fabric_login()
527 if (lport->state == LPORT_ST_DISABLED || in fc_fabric_login()
528 lport->state == LPORT_ST_LOGO) { in fc_fabric_login()
533 mutex_unlock(&lport->lp_mutex); in fc_fabric_login()
540 * __fc_linkup() - Handler for transport linkup events
545 lockdep_assert_held(&lport->lp_mutex); in __fc_linkup()
547 if (!lport->link_up) { in __fc_linkup()
548 lport->link_up = 1; in __fc_linkup()
550 if (lport->state == LPORT_ST_RESET) in __fc_linkup()
556 * fc_linkup() - Handler for transport linkup events
557 * @lport: The local port whose link is up
561 printk(KERN_INFO "host%d: libfc: Link up on port (%6.6x)\n", in fc_linkup()
562 lport->host->host_no, lport->port_id); in fc_linkup()
564 mutex_lock(&lport->lp_mutex); in fc_linkup()
566 mutex_unlock(&lport->lp_mutex); in fc_linkup()
571 * __fc_linkdown() - Handler for transport linkdown events
576 lockdep_assert_held(&lport->lp_mutex); in __fc_linkdown()
578 if (lport->link_up) { in __fc_linkdown()
579 lport->link_up = 0; in __fc_linkdown()
581 lport->tt.fcp_cleanup(lport); in __fc_linkdown()
586 * fc_linkdown() - Handler for transport linkdown events
587 * @lport: The local port whose link is down
591 printk(KERN_INFO "host%d: libfc: Link down on port (%6.6x)\n", in fc_linkdown()
592 lport->host->host_no, lport->port_id); in fc_linkdown()
594 mutex_lock(&lport->lp_mutex); in fc_linkdown()
596 mutex_unlock(&lport->lp_mutex); in fc_linkdown()
601 * fc_fabric_logoff() - Logout of the fabric
602 * @lport: The local port to logoff the fabric
605 * 0 for success, -1 for failure
609 lport->tt.disc_stop_final(lport); in fc_fabric_logoff()
610 mutex_lock(&lport->lp_mutex); in fc_fabric_logoff()
611 if (lport->dns_rdata) in fc_fabric_logoff()
612 fc_rport_logoff(lport->dns_rdata); in fc_fabric_logoff()
613 mutex_unlock(&lport->lp_mutex); in fc_fabric_logoff()
615 mutex_lock(&lport->lp_mutex); in fc_fabric_logoff()
617 mutex_unlock(&lport->lp_mutex); in fc_fabric_logoff()
618 cancel_delayed_work_sync(&lport->retry_work); in fc_fabric_logoff()
624 * fc_lport_destroy() - Unregister a fc_lport
625 * @lport: The local port to unregister
629 * clean-up all the allocated memory
635 mutex_lock(&lport->lp_mutex); in fc_lport_destroy()
636 lport->state = LPORT_ST_DISABLED; in fc_lport_destroy()
637 lport->link_up = 0; in fc_lport_destroy()
638 lport->tt.frame_send = fc_frame_drop; in fc_lport_destroy()
639 mutex_unlock(&lport->lp_mutex); in fc_lport_destroy()
641 lport->tt.fcp_abort_io(lport); in fc_lport_destroy()
642 lport->tt.disc_stop_final(lport); in fc_lport_destroy()
643 lport->tt.exch_mgr_reset(lport, 0, 0); in fc_lport_destroy()
644 cancel_delayed_work_sync(&lport->retry_work); in fc_lport_destroy()
651 * fc_set_mfs() - Set the maximum frame size for a local port
652 * @lport: The local port to set the MFS for
658 int rc = -EINVAL; in fc_set_mfs()
660 mutex_lock(&lport->lp_mutex); in fc_set_mfs()
662 old_mfs = lport->mfs; in fc_set_mfs()
668 mfs -= sizeof(struct fc_frame_header); in fc_set_mfs()
669 lport->mfs = mfs; in fc_set_mfs()
676 mutex_unlock(&lport->lp_mutex); in fc_set_mfs()
683 * fc_lport_disc_callback() - Callback for discovery events
684 * @lport: The local port receiving the event
695 printk(KERN_ERR "host%d: libfc: " in fc_lport_disc_callback()
697 lport->host->host_no, lport->port_id); in fc_lport_disc_callback()
698 mutex_lock(&lport->lp_mutex); in fc_lport_disc_callback()
700 mutex_unlock(&lport->lp_mutex); in fc_lport_disc_callback()
709 * fc_lport_enter_ready() - Enter the ready state and start discovery
710 * @lport: The local port that is ready
714 lockdep_assert_held(&lport->lp_mutex); in fc_lport_enter_ready()
720 if (lport->vport) in fc_lport_enter_ready()
721 fc_vport_set_state(lport->vport, FC_VPORT_ACTIVE); in fc_lport_enter_ready()
724 if (!lport->ptp_rdata) in fc_lport_enter_ready()
725 lport->tt.disc_start(fc_lport_disc_callback, lport); in fc_lport_enter_ready()
729 * fc_lport_set_port_id() - set the local port Port ID
730 * @lport: The local port which will have its Port ID set.
737 lockdep_assert_held(&lport->lp_mutex); in fc_lport_set_port_id()
740 printk(KERN_INFO "host%d: Assigned Port ID %6.6x\n", in fc_lport_set_port_id()
741 lport->host->host_no, port_id); in fc_lport_set_port_id()
743 lport->port_id = port_id; in fc_lport_set_port_id()
746 fc_host_port_id(lport->host) = port_id; in fc_lport_set_port_id()
748 if (lport->tt.lport_set_port_id) in fc_lport_set_port_id()
749 lport->tt.lport_set_port_id(lport, port_id, fp); in fc_lport_set_port_id()
753 * fc_lport_set_local_id() - set the local port Port ID for point-to-multipoint
754 * @lport: The local port which will have its Port ID set.
757 * Called by the lower-level driver when transport sets the local port_id.
763 mutex_lock(&lport->lp_mutex); in fc_lport_set_local_id()
767 switch (lport->state) { in fc_lport_set_local_id()
776 mutex_unlock(&lport->lp_mutex); in fc_lport_set_local_id()
781 * fc_lport_recv_flogi_req() - Receive a FLOGI request
782 * @lport: The local port that received the request
785 * A received FLOGI request indicates a point-to-point connection.
787 * Set up to do a PLOGI if we have the higher-number WWPN.
800 lockdep_assert_held(&lport->lp_mutex); in fc_lport_recv_flogi_req()
809 remote_wwpn = get_unaligned_be64(&flp->fl_wwpn); in fc_lport_recv_flogi_req()
810 if (remote_wwpn == lport->wwpn) { in fc_lport_recv_flogi_req()
811 printk(KERN_WARNING "host%d: libfc: Received FLOGI from port " in fc_lport_recv_flogi_req()
813 lport->host->host_no, remote_wwpn); in fc_lport_recv_flogi_req()
824 if (remote_wwpn < lport->wwpn) { in fc_lport_recv_flogi_req()
838 new_flp->fl_cmd = (u8) ELS_LS_ACC; in fc_lport_recv_flogi_req()
846 hton24(fh->fh_s_id, local_fid); in fc_lport_recv_flogi_req()
847 hton24(fh->fh_d_id, remote_fid); in fc_lport_recv_flogi_req()
848 lport->tt.frame_send(lport, fp); in fc_lport_recv_flogi_req()
854 get_unaligned_be64(&flp->fl_wwnn)); in fc_lport_recv_flogi_req()
860 * fc_lport_recv_els_req() - The generic lport ELS request handler
861 * @lport: The local port that received the request
873 mutex_lock(&lport->lp_mutex); in fc_lport_recv_els_req()
880 if (!lport->link_up) in fc_lport_recv_els_req()
888 if (!lport->point_to_multipoint) in fc_lport_recv_els_req()
900 lport->tt.disc_recv_req(lport, fp); in fc_lport_recv_els_req()
916 mutex_unlock(&lport->lp_mutex); in fc_lport_recv_els_req()
932 * fc_lport_recv() - The generic lport request handler
954 if (fh->fh_type >= FC_FC4_PROV_SIZE) in fc_lport_recv()
956 prov = rcu_dereference(fc_passive_prov[fh->fh_type]); in fc_lport_recv()
957 if (!prov || !try_module_get(prov->module)) in fc_lport_recv()
960 prov->recv(lport, fp); in fc_lport_recv()
961 module_put(prov->module); in fc_lport_recv()
965 FC_LPORT_DBG(lport, "dropping unexpected frame type %x\n", fh->fh_type); in fc_lport_recv()
973 * fc_lport_reset() - Reset a local port
974 * @lport: The local port which should be reset
981 cancel_delayed_work_sync(&lport->retry_work); in fc_lport_reset()
982 mutex_lock(&lport->lp_mutex); in fc_lport_reset()
984 mutex_unlock(&lport->lp_mutex); in fc_lport_reset()
990 * fc_lport_reset_locked() - Reset the local port w/ the lport lock held
991 * @lport: The local port to be reset
995 lockdep_assert_held(&lport->lp_mutex); in fc_lport_reset_locked()
997 if (lport->dns_rdata) { in fc_lport_reset_locked()
998 fc_rport_logoff(lport->dns_rdata); in fc_lport_reset_locked()
999 lport->dns_rdata = NULL; in fc_lport_reset_locked()
1002 if (lport->ptp_rdata) { in fc_lport_reset_locked()
1003 fc_rport_logoff(lport->ptp_rdata); in fc_lport_reset_locked()
1004 kref_put(&lport->ptp_rdata->kref, fc_rport_destroy); in fc_lport_reset_locked()
1005 lport->ptp_rdata = NULL; in fc_lport_reset_locked()
1008 lport->tt.disc_stop(lport); in fc_lport_reset_locked()
1010 lport->tt.exch_mgr_reset(lport, 0, 0); in fc_lport_reset_locked()
1011 fc_host_fabric_name(lport->host) = 0; in fc_lport_reset_locked()
1013 if (lport->port_id && (!lport->point_to_multipoint || !lport->link_up)) in fc_lport_reset_locked()
1018 * fc_lport_enter_reset() - Reset the local port
1019 * @lport: The local port to be reset
1023 lockdep_assert_held(&lport->lp_mutex); in fc_lport_enter_reset()
1028 if (lport->state == LPORT_ST_DISABLED || lport->state == LPORT_ST_LOGO) in fc_lport_enter_reset()
1031 if (lport->vport) { in fc_lport_enter_reset()
1032 if (lport->link_up) in fc_lport_enter_reset()
1033 fc_vport_set_state(lport->vport, FC_VPORT_INITIALIZING); in fc_lport_enter_reset()
1035 fc_vport_set_state(lport->vport, FC_VPORT_LINKDOWN); in fc_lport_enter_reset()
1038 fc_host_post_event(lport->host, fc_get_event_number(), in fc_lport_enter_reset()
1042 if (lport->link_up) in fc_lport_enter_reset()
1047 * fc_lport_enter_disabled() - Disable the local port
1048 * @lport: The local port to be reset
1052 lockdep_assert_held(&lport->lp_mutex); in fc_lport_enter_disabled()
1063 * fc_lport_error() - Handler for any errors
1064 * @lport: The local port that the error was on
1075 IS_ERR(fp) ? -PTR_ERR(fp) : 0, fc_lport_state(lport), in fc_lport_error()
1076 lport->retry_count); in fc_lport_error()
1078 if (PTR_ERR(fp) == -FC_EX_CLOSED) in fc_lport_error()
1086 if (lport->retry_count < lport->max_retry_count) { in fc_lport_error()
1087 lport->retry_count++; in fc_lport_error()
1091 delay = msecs_to_jiffies(lport->e_d_tov); in fc_lport_error()
1093 schedule_delayed_work(&lport->retry_work, delay); in fc_lport_error()
1099 * fc_lport_ns_resp() - Handle response to a name server
1103 * @lp_arg: Fibre Channel host port instance
1118 if (fp == ERR_PTR(-FC_EX_CLOSED)) in fc_lport_ns_resp()
1121 mutex_lock(&lport->lp_mutex); in fc_lport_ns_resp()
1123 if (lport->state < LPORT_ST_RNN_ID || lport->state > LPORT_ST_RFF_ID) { in fc_lport_ns_resp()
1139 if (fh && ct && fh->fh_type == FC_TYPE_CT && in fc_lport_ns_resp()
1140 ct->ct_fs_type == FC_FST_DIR && in fc_lport_ns_resp()
1141 ct->ct_fs_subtype == FC_NS_SUBTYPE && in fc_lport_ns_resp()
1142 ntohs(ct->ct_cmd) == FC_FS_ACC) in fc_lport_ns_resp()
1143 switch (lport->state) { in fc_lport_ns_resp()
1157 if (lport->fdmi_enabled) in fc_lport_ns_resp()
1171 mutex_unlock(&lport->lp_mutex); in fc_lport_ns_resp()
1175 * fc_lport_ms_resp() - Handle response to a management server
1179 * @lp_arg: Fibre Channel host port instance
1191 struct fc_host_attrs *fc_host = shost_to_fc_host(lport->host); in fc_lport_ms_resp()
1194 if (fp == ERR_PTR(-FC_EX_CLOSED)) in fc_lport_ms_resp()
1197 mutex_lock(&lport->lp_mutex); in fc_lport_ms_resp()
1199 if (lport->state < LPORT_ST_RHBA || lport->state > LPORT_ST_DPRT) { in fc_lport_ms_resp()
1215 if (fh && ct && fh->fh_type == FC_TYPE_CT && in fc_lport_ms_resp()
1216 ct->ct_fs_type == FC_FST_MGMT && in fc_lport_ms_resp()
1217 ct->ct_fs_subtype == FC_FDMI_SUBTYPE) { in fc_lport_ms_resp()
1220 ct->ct_reason, in fc_lport_ms_resp()
1221 ct->ct_explan); in fc_lport_ms_resp()
1223 switch (lport->state) { in fc_lport_ms_resp()
1225 if ((ntohs(ct->ct_cmd) == FC_FS_RJT) && fc_host->fdmi_version == FDMI_V2) { in fc_lport_ms_resp()
1226 FC_LPORT_DBG(lport, "Error for FDMI-V2, fall back to FDMI-V1\n"); in fc_lport_ms_resp()
1227 fc_host->fdmi_version = FDMI_V1; in fc_lport_ms_resp()
1231 } else if (ntohs(ct->ct_cmd) == FC_FS_ACC) in fc_lport_ms_resp()
1256 mutex_unlock(&lport->lp_mutex); in fc_lport_ms_resp()
1260 * fc_lport_scr_resp() - Handle response to State Change Register (SCR) request
1277 if (fp == ERR_PTR(-FC_EX_CLOSED)) in fc_lport_scr_resp()
1280 mutex_lock(&lport->lp_mutex); in fc_lport_scr_resp()
1282 if (lport->state != LPORT_ST_SCR) { in fc_lport_scr_resp()
1304 mutex_unlock(&lport->lp_mutex); in fc_lport_scr_resp()
1308 * fc_lport_enter_scr() - Send a SCR (State Change Register) request
1309 * @lport: The local port to register for state changes
1315 lockdep_assert_held(&lport->lp_mutex); in fc_lport_enter_scr()
1328 if (!lport->tt.elsct_send(lport, FC_FID_FCTRL, fp, ELS_SCR, in fc_lport_enter_scr()
1330 2 * lport->r_a_tov)) in fc_lport_enter_scr()
1335 * fc_lport_enter_ns() - register some object with the name server
1336 * @lport: Fibre Channel local port to register
1337 * @state: Local port state
1346 lockdep_assert_held(&lport->lp_mutex); in fc_lport_enter_ns()
1360 len = strnlen(fc_host_symbolic_name(lport->host), 255); in fc_lport_enter_ns()
1368 len = strnlen(fc_host_symbolic_name(lport->host), 255); in fc_lport_enter_ns()
1394 if (!lport->tt.elsct_send(lport, FC_FID_DIR_SERV, fp, cmd, in fc_lport_enter_ns()
1396 lport, 3 * lport->r_a_tov)) in fc_lport_enter_ns()
1405 * fc_lport_enter_dns() - Create a fc_rport for the name server
1406 * @lport: The local port requesting a remote port for the name server
1412 lockdep_assert_held(&lport->lp_mutex); in fc_lport_enter_dns()
1419 mutex_lock(&lport->disc.disc_mutex); in fc_lport_enter_dns()
1421 mutex_unlock(&lport->disc.disc_mutex); in fc_lport_enter_dns()
1425 rdata->ops = &fc_lport_rport_ops; in fc_lport_enter_dns()
1434 * fc_lport_enter_ms() - management server commands
1435 * @lport: Fibre Channel local port to register
1436 * @state: Local port state
1445 struct fc_host_attrs *fc_host = shost_to_fc_host(lport->host); in fc_lport_enter_ms()
1446 lockdep_assert_held(&lport->lp_mutex); in fc_lport_enter_ms()
1460 len -= sizeof(struct fc_fdmi_attr_entry); in fc_lport_enter_ms()
1475 if (fc_host->fdmi_version == FDMI_V2) { in fc_lport_enter_ms()
1495 len -= sizeof(struct fc_fdmi_attr_entry); in fc_lport_enter_ms()
1503 if (fc_host->fdmi_version == FDMI_V2) { in fc_lport_enter_ms()
1544 if (!lport->tt.elsct_send(lport, FC_FID_MGMT_SERV, fp, cmd, in fc_lport_enter_ms()
1546 lport, 3 * lport->r_a_tov)) in fc_lport_enter_ms()
1551 * fc_lport_enter_fdmi() - Create a fc_rport for the management server
1552 * @lport: The local port requesting a remote port for the management server
1558 lockdep_assert_held(&lport->lp_mutex); in fc_lport_enter_fdmi()
1565 mutex_lock(&lport->disc.disc_mutex); in fc_lport_enter_fdmi()
1567 mutex_unlock(&lport->disc.disc_mutex); in fc_lport_enter_fdmi()
1571 rdata->ops = &fc_lport_rport_ops; in fc_lport_enter_fdmi()
1580 * fc_lport_timeout() - Handler for the retry_work timer
1581 * @work: The work struct of the local port
1588 struct fc_host_attrs *fc_host = shost_to_fc_host(lport->host); in fc_lport_timeout()
1590 mutex_lock(&lport->lp_mutex); in fc_lport_timeout()
1592 switch (lport->state) { in fc_lport_timeout()
1610 fc_lport_enter_ns(lport, lport->state); in fc_lport_timeout()
1616 if (fc_host->fdmi_version == FDMI_V2) { in fc_lport_timeout()
1617 FC_LPORT_DBG(lport, "timeout for FDMI-V2 RHBA,fall back to FDMI-V1\n"); in fc_lport_timeout()
1618 fc_host->fdmi_version = FDMI_V1; in fc_lport_timeout()
1637 mutex_unlock(&lport->lp_mutex); in fc_lport_timeout()
1641 * fc_lport_logo_resp() - Handle response to LOGO request
1658 if (fp == ERR_PTR(-FC_EX_CLOSED)) in fc_lport_logo_resp()
1661 mutex_lock(&lport->lp_mutex); in fc_lport_logo_resp()
1663 if (lport->state != LPORT_ST_LOGO) { in fc_lport_logo_resp()
1685 mutex_unlock(&lport->lp_mutex); in fc_lport_logo_resp()
1690 * fc_lport_enter_logo() - Logout of the fabric
1691 * @lport: The local port to be logged out
1698 lockdep_assert_held(&lport->lp_mutex); in fc_lport_enter_logo()
1712 if (!lport->tt.elsct_send(lport, FC_FID_FLOGI, fp, ELS_LOGO, in fc_lport_enter_logo()
1714 2 * lport->r_a_tov)) in fc_lport_enter_logo()
1719 * fc_lport_flogi_resp() - Handle response to FLOGI request
1742 if (fp == ERR_PTR(-FC_EX_CLOSED)) in fc_lport_flogi_resp()
1745 mutex_lock(&lport->lp_mutex); in fc_lport_flogi_resp()
1747 if (lport->state != LPORT_ST_FLOGI) { in fc_lport_flogi_resp()
1762 if (fh->fh_r_ctl != FC_RCTL_ELS_REP || did == 0 || in fc_lport_flogi_resp()
1776 mfs = ntohs(flp->fl_csp.sp_bb_data) & in fc_lport_flogi_resp()
1781 "lport->mfs:%u\n", mfs, lport->mfs); in fc_lport_flogi_resp()
1786 if (mfs <= lport->mfs) { in fc_lport_flogi_resp()
1787 lport->mfs = mfs; in fc_lport_flogi_resp()
1788 fc_host_maxframe_size(lport->host) = mfs; in fc_lport_flogi_resp()
1791 csp_flags = ntohs(flp->fl_csp.sp_features); in fc_lport_flogi_resp()
1792 r_a_tov = ntohl(flp->fl_csp.sp_r_a_tov); in fc_lport_flogi_resp()
1793 e_d_tov = ntohl(flp->fl_csp.sp_e_d_tov); in fc_lport_flogi_resp()
1797 lport->npiv_enabled = !!(csp_flags & FC_SP_FT_NPIV_ACC); in fc_lport_flogi_resp()
1800 if (e_d_tov > lport->e_d_tov) in fc_lport_flogi_resp()
1801 lport->e_d_tov = e_d_tov; in fc_lport_flogi_resp()
1802 lport->r_a_tov = 2 * lport->e_d_tov; in fc_lport_flogi_resp()
1804 printk(KERN_INFO "host%d: libfc: " in fc_lport_flogi_resp()
1806 "point-to-point mode\n", in fc_lport_flogi_resp()
1807 lport->host->host_no, did); in fc_lport_flogi_resp()
1810 &flp->fl_wwpn), in fc_lport_flogi_resp()
1812 &flp->fl_wwnn)); in fc_lport_flogi_resp()
1814 if (e_d_tov > lport->e_d_tov) in fc_lport_flogi_resp()
1815 lport->e_d_tov = e_d_tov; in fc_lport_flogi_resp()
1816 if (r_a_tov > lport->r_a_tov) in fc_lport_flogi_resp()
1817 lport->r_a_tov = r_a_tov; in fc_lport_flogi_resp()
1818 fc_host_fabric_name(lport->host) = in fc_lport_flogi_resp()
1819 get_unaligned_be64(&flp->fl_wwnn); in fc_lport_flogi_resp()
1827 mutex_unlock(&lport->lp_mutex); in fc_lport_flogi_resp()
1832 * fc_lport_enter_flogi() - Send a FLOGI request to the fabric manager
1833 * @lport: Fibre Channel local port to be logged in to the fabric
1839 lockdep_assert_held(&lport->lp_mutex); in fc_lport_enter_flogi()
1846 if (lport->point_to_multipoint) { in fc_lport_enter_flogi()
1847 if (lport->port_id) in fc_lport_enter_flogi()
1856 if (!lport->tt.elsct_send(lport, FC_FID_FLOGI, fp, in fc_lport_enter_flogi()
1857 lport->vport ? ELS_FDISC : ELS_FLOGI, in fc_lport_enter_flogi()
1859 lport->vport ? 2 * lport->r_a_tov : in fc_lport_enter_flogi()
1860 lport->e_d_tov)) in fc_lport_enter_flogi()
1865 * fc_lport_config() - Configure a fc_lport
1866 * @lport: The local port to be configured
1870 INIT_DELAYED_WORK(&lport->retry_work, fc_lport_timeout); in fc_lport_config()
1871 mutex_init(&lport->lp_mutex); in fc_lport_config()
1884 * fc_lport_init() - Initialize the lport layer for a local port
1885 * @lport: The local port to initialize the exchange layer for
1891 fc_host = shost_to_fc_host(lport->host); in fc_lport_init()
1893 /* Set FDMI version to FDMI-2 specification*/ in fc_lport_init()
1894 fc_host->fdmi_version = FDMI_V2; in fc_lport_init()
1896 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT; in fc_lport_init()
1897 fc_host_node_name(lport->host) = lport->wwnn; in fc_lport_init()
1898 fc_host_port_name(lport->host) = lport->wwpn; in fc_lport_init()
1899 fc_host_supported_classes(lport->host) = FC_COS_CLASS3; in fc_lport_init()
1900 memset(fc_host_supported_fc4s(lport->host), 0, in fc_lport_init()
1901 sizeof(fc_host_supported_fc4s(lport->host))); in fc_lport_init()
1902 fc_host_supported_fc4s(lport->host)[2] = 1; in fc_lport_init()
1903 fc_host_supported_fc4s(lport->host)[7] = 1; in fc_lport_init()
1904 fc_host_num_discovered_ports(lport->host) = 4; in fc_lport_init()
1907 memset(fc_host_active_fc4s(lport->host), 0, in fc_lport_init()
1908 sizeof(fc_host_active_fc4s(lport->host))); in fc_lport_init()
1909 fc_host_active_fc4s(lport->host)[2] = 1; in fc_lport_init()
1910 fc_host_active_fc4s(lport->host)[7] = 1; in fc_lport_init()
1911 fc_host_maxframe_size(lport->host) = lport->mfs; in fc_lport_init()
1912 fc_host_supported_speeds(lport->host) = 0; in fc_lport_init()
1913 if (lport->link_supported_speeds & FC_PORTSPEED_1GBIT) in fc_lport_init()
1914 fc_host_supported_speeds(lport->host) |= FC_PORTSPEED_1GBIT; in fc_lport_init()
1915 if (lport->link_supported_speeds & FC_PORTSPEED_10GBIT) in fc_lport_init()
1916 fc_host_supported_speeds(lport->host) |= FC_PORTSPEED_10GBIT; in fc_lport_init()
1917 if (lport->link_supported_speeds & FC_PORTSPEED_40GBIT) in fc_lport_init()
1918 fc_host_supported_speeds(lport->host) |= FC_PORTSPEED_40GBIT; in fc_lport_init()
1919 if (lport->link_supported_speeds & FC_PORTSPEED_100GBIT) in fc_lport_init()
1920 fc_host_supported_speeds(lport->host) |= FC_PORTSPEED_100GBIT; in fc_lport_init()
1921 if (lport->link_supported_speeds & FC_PORTSPEED_25GBIT) in fc_lport_init()
1922 fc_host_supported_speeds(lport->host) |= FC_PORTSPEED_25GBIT; in fc_lport_init()
1923 if (lport->link_supported_speeds & FC_PORTSPEED_50GBIT) in fc_lport_init()
1924 fc_host_supported_speeds(lport->host) |= FC_PORTSPEED_50GBIT; in fc_lport_init()
1925 if (lport->link_supported_speeds & FC_PORTSPEED_100GBIT) in fc_lport_init()
1926 fc_host_supported_speeds(lport->host) |= FC_PORTSPEED_100GBIT; in fc_lport_init()
1930 fc_host_num_discovered_ports(lport->host) = DISCOVERED_PORTS; in fc_lport_init()
1931 fc_host_port_state(lport->host) = FC_PORTSTATE_ONLINE; in fc_lport_init()
1932 fc_host_max_ct_payload(lport->host) = MAX_CT_PAYLOAD; in fc_lport_init()
1933 fc_host_num_ports(lport->host) = NUMBER_OF_PORTS; in fc_lport_init()
1934 fc_host_bootbios_state(lport->host) = 0X00000000; in fc_lport_init()
1935 snprintf(fc_host_bootbios_version(lport->host), in fc_lport_init()
1943 * fc_lport_bsg_resp() - The common response handler for FC Passthrough requests
1952 struct bsg_job *job = info->job; in fc_lport_bsg_resp()
1953 struct fc_bsg_reply *bsg_reply = job->reply; in fc_lport_bsg_resp()
1954 struct fc_lport *lport = info->lport; in fc_lport_bsg_resp()
1960 bsg_reply->result = (PTR_ERR(fp) == -FC_EX_CLOSED) ? in fc_lport_bsg_resp()
1961 -ECONNABORTED : -ETIMEDOUT; in fc_lport_bsg_resp()
1962 job->reply_len = sizeof(uint32_t); in fc_lport_bsg_resp()
1963 bsg_job_done(job, bsg_reply->result, in fc_lport_bsg_resp()
1964 bsg_reply->reply_payload_rcv_len); in fc_lport_bsg_resp()
1969 mutex_lock(&lport->lp_mutex); in fc_lport_bsg_resp()
1971 len = fr_len(fp) - sizeof(*fh); in fc_lport_bsg_resp()
1974 if (fr_sof(fp) == FC_SOF_I3 && !ntohs(fh->fh_seq_cnt)) { in fc_lport_bsg_resp()
1976 unsigned short cmd = (info->rsp_code == FC_FS_ACC) ? in fc_lport_bsg_resp()
1977 ntohs(((struct fc_ct_hdr *)buf)->ct_cmd) : in fc_lport_bsg_resp()
1981 bsg_reply->reply_data.ctels_reply.status = in fc_lport_bsg_resp()
1982 (cmd == info->rsp_code) ? in fc_lport_bsg_resp()
1986 bsg_reply->reply_payload_rcv_len += in fc_lport_bsg_resp()
1987 fc_copy_buffer_to_sglist(buf, len, info->sg, &info->nents, in fc_lport_bsg_resp()
1988 &info->offset, NULL); in fc_lport_bsg_resp()
1991 (ntoh24(fh->fh_f_ctl) & (FC_FC_LAST_SEQ | FC_FC_END_SEQ)) == in fc_lport_bsg_resp()
1993 if (bsg_reply->reply_payload_rcv_len > in fc_lport_bsg_resp()
1994 job->reply_payload.payload_len) in fc_lport_bsg_resp()
1995 bsg_reply->reply_payload_rcv_len = in fc_lport_bsg_resp()
1996 job->reply_payload.payload_len; in fc_lport_bsg_resp()
1997 bsg_reply->result = 0; in fc_lport_bsg_resp()
1998 bsg_job_done(job, bsg_reply->result, in fc_lport_bsg_resp()
1999 bsg_reply->reply_payload_rcv_len); in fc_lport_bsg_resp()
2003 mutex_unlock(&lport->lp_mutex); in fc_lport_bsg_resp()
2007 * fc_lport_els_request() - Send ELS passthrough request
2009 * @lport: The local port sending the request
2023 lockdep_assert_held(&lport->lp_mutex); in fc_lport_els_request()
2025 fp = fc_frame_alloc(lport, job->request_payload.payload_len); in fc_lport_els_request()
2027 return -ENOMEM; in fc_lport_els_request()
2029 len = job->request_payload.payload_len; in fc_lport_els_request()
2032 sg_copy_to_buffer(job->request_payload.sg_list, in fc_lport_els_request()
2033 job->request_payload.sg_cnt, in fc_lport_els_request()
2037 fh->fh_r_ctl = FC_RCTL_ELS_REQ; in fc_lport_els_request()
2038 hton24(fh->fh_d_id, did); in fc_lport_els_request()
2039 hton24(fh->fh_s_id, lport->port_id); in fc_lport_els_request()
2040 fh->fh_type = FC_TYPE_ELS; in fc_lport_els_request()
2041 hton24(fh->fh_f_ctl, FC_FCTL_REQ); in fc_lport_els_request()
2042 fh->fh_cs_ctl = 0; in fc_lport_els_request()
2043 fh->fh_df_ctl = 0; in fc_lport_els_request()
2044 fh->fh_parm_offset = 0; in fc_lport_els_request()
2049 return -ENOMEM; in fc_lport_els_request()
2052 info->job = job; in fc_lport_els_request()
2053 info->lport = lport; in fc_lport_els_request()
2054 info->rsp_code = ELS_LS_ACC; in fc_lport_els_request()
2055 info->nents = job->reply_payload.sg_cnt; in fc_lport_els_request()
2056 info->sg = job->reply_payload.sg_list; in fc_lport_els_request()
2061 return -ECOMM; in fc_lport_els_request()
2067 * fc_lport_ct_request() - Send CT Passthrough request
2069 * @lport: The local port sending the request
2070 * @did: The destination FC-ID
2082 lockdep_assert_held(&lport->lp_mutex); in fc_lport_ct_request()
2085 job->request_payload.payload_len); in fc_lport_ct_request()
2087 return -ENOMEM; in fc_lport_ct_request()
2089 len = job->request_payload.payload_len; in fc_lport_ct_request()
2092 sg_copy_to_buffer(job->request_payload.sg_list, in fc_lport_ct_request()
2093 job->request_payload.sg_cnt, in fc_lport_ct_request()
2097 fh->fh_r_ctl = FC_RCTL_DD_UNSOL_CTL; in fc_lport_ct_request()
2098 hton24(fh->fh_d_id, did); in fc_lport_ct_request()
2099 hton24(fh->fh_s_id, lport->port_id); in fc_lport_ct_request()
2100 fh->fh_type = FC_TYPE_CT; in fc_lport_ct_request()
2101 hton24(fh->fh_f_ctl, FC_FCTL_REQ); in fc_lport_ct_request()
2102 fh->fh_cs_ctl = 0; in fc_lport_ct_request()
2103 fh->fh_df_ctl = 0; in fc_lport_ct_request()
2104 fh->fh_parm_offset = 0; in fc_lport_ct_request()
2109 return -ENOMEM; in fc_lport_ct_request()
2112 info->job = job; in fc_lport_ct_request()
2113 info->lport = lport; in fc_lport_ct_request()
2114 info->rsp_code = FC_FS_ACC; in fc_lport_ct_request()
2115 info->nents = job->reply_payload.sg_cnt; in fc_lport_ct_request()
2116 info->sg = job->reply_payload.sg_list; in fc_lport_ct_request()
2121 return -ECOMM; in fc_lport_ct_request()
2127 * fc_lport_bsg_request() - The common entry point for sending
2133 struct fc_bsg_request *bsg_request = job->request; in fc_lport_bsg_request()
2134 struct fc_bsg_reply *bsg_reply = job->reply; in fc_lport_bsg_request()
2139 int rc = -EINVAL; in fc_lport_bsg_request()
2142 bsg_reply->reply_payload_rcv_len = 0; in fc_lport_bsg_request()
2144 mutex_lock(&lport->lp_mutex); in fc_lport_bsg_request()
2146 switch (bsg_request->msgcode) { in fc_lport_bsg_request()
2152 rdata = rport->dd_data; in fc_lport_bsg_request()
2153 rc = fc_lport_els_request(job, lport, rport->port_id, in fc_lport_bsg_request()
2154 rdata->e_d_tov); in fc_lport_bsg_request()
2162 rdata = rport->dd_data; in fc_lport_bsg_request()
2163 rc = fc_lport_ct_request(job, lport, rport->port_id, in fc_lport_bsg_request()
2164 rdata->e_d_tov); in fc_lport_bsg_request()
2168 did = ntoh24(bsg_request->rqst_data.h_ct.port_id); in fc_lport_bsg_request()
2170 rdata = lport->dns_rdata; in fc_lport_bsg_request()
2173 tov = rdata->e_d_tov; in fc_lport_bsg_request()
2178 tov = rdata->e_d_tov; in fc_lport_bsg_request()
2179 kref_put(&rdata->kref, fc_rport_destroy); in fc_lport_bsg_request()
2186 did = ntoh24(bsg_request->rqst_data.h_els.port_id); in fc_lport_bsg_request()
2187 rc = fc_lport_els_request(job, lport, did, lport->e_d_tov); in fc_lport_bsg_request()
2191 mutex_unlock(&lport->lp_mutex); in fc_lport_bsg_request()