142e9a92fSRobert Love /* 242e9a92fSRobert Love * Copyright(c) 2007 Intel Corporation. All rights reserved. 342e9a92fSRobert Love * 442e9a92fSRobert Love * This program is free software; you can redistribute it and/or modify it 542e9a92fSRobert Love * under the terms and conditions of the GNU General Public License, 642e9a92fSRobert Love * version 2, as published by the Free Software Foundation. 742e9a92fSRobert Love * 842e9a92fSRobert Love * This program is distributed in the hope it will be useful, but WITHOUT 942e9a92fSRobert Love * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1042e9a92fSRobert Love * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 1142e9a92fSRobert Love * more details. 1242e9a92fSRobert Love * 1342e9a92fSRobert Love * You should have received a copy of the GNU General Public License along with 1442e9a92fSRobert Love * this program; if not, write to the Free Software Foundation, Inc., 1542e9a92fSRobert Love * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 1642e9a92fSRobert Love * 1742e9a92fSRobert Love * Maintained at www.Open-FCoE.org 1842e9a92fSRobert Love */ 1942e9a92fSRobert Love 2042e9a92fSRobert Love /* 2142e9a92fSRobert Love * PORT LOCKING NOTES 2242e9a92fSRobert Love * 2342e9a92fSRobert Love * These comments only apply to the 'port code' which consists of the lport, 2442e9a92fSRobert Love * disc and rport blocks. 2542e9a92fSRobert Love * 2642e9a92fSRobert Love * MOTIVATION 2742e9a92fSRobert Love * 2842e9a92fSRobert Love * The lport, disc and rport blocks all have mutexes that are used to protect 2942e9a92fSRobert Love * those objects. The main motivation for these locks is to prevent from 3042e9a92fSRobert Love * having an lport reset just before we send a frame. In that scenario the 3142e9a92fSRobert Love * lport's FID would get set to zero and then we'd send a frame with an 3242e9a92fSRobert Love * invalid SID. We also need to ensure that states don't change unexpectedly 3342e9a92fSRobert Love * while processing another state. 3442e9a92fSRobert Love * 3542e9a92fSRobert Love * HEIRARCHY 3642e9a92fSRobert Love * 3742e9a92fSRobert Love * The following heirarchy defines the locking rules. A greater lock 3842e9a92fSRobert Love * may be held before acquiring a lesser lock, but a lesser lock should never 3942e9a92fSRobert Love * be held while attempting to acquire a greater lock. Here is the heirarchy- 4042e9a92fSRobert Love * 4142e9a92fSRobert Love * lport > disc, lport > rport, disc > rport 4242e9a92fSRobert Love * 4342e9a92fSRobert Love * CALLBACKS 4442e9a92fSRobert Love * 4542e9a92fSRobert Love * The callbacks cause complications with this scheme. There is a callback 4642e9a92fSRobert Love * from the rport (to either lport or disc) and a callback from disc 4742e9a92fSRobert Love * (to the lport). 4842e9a92fSRobert Love * 4942e9a92fSRobert Love * As rports exit the rport state machine a callback is made to the owner of 5042e9a92fSRobert Love * the rport to notify success or failure. Since the callback is likely to 5142e9a92fSRobert Love * cause the lport or disc to grab its lock we cannot hold the rport lock 5242e9a92fSRobert Love * while making the callback. To ensure that the rport is not free'd while 5342e9a92fSRobert Love * processing the callback the rport callbacks are serialized through a 5442e9a92fSRobert Love * single-threaded workqueue. An rport would never be free'd while in a 5542e9a92fSRobert Love * callback handler becuase no other rport work in this queue can be executed 5642e9a92fSRobert Love * at the same time. 5742e9a92fSRobert Love * 5842e9a92fSRobert Love * When discovery succeeds or fails a callback is made to the lport as 5942e9a92fSRobert Love * notification. Currently, succesful discovery causes the lport to take no 6042e9a92fSRobert Love * action. A failure will cause the lport to reset. There is likely a circular 6142e9a92fSRobert Love * locking problem with this implementation. 6242e9a92fSRobert Love */ 6342e9a92fSRobert Love 6442e9a92fSRobert Love /* 6542e9a92fSRobert Love * LPORT LOCKING 6642e9a92fSRobert Love * 6742e9a92fSRobert Love * The critical sections protected by the lport's mutex are quite broad and 6842e9a92fSRobert Love * may be improved upon in the future. The lport code and its locking doesn't 6942e9a92fSRobert Love * influence the I/O path, so excessive locking doesn't penalize I/O 7042e9a92fSRobert Love * performance. 7142e9a92fSRobert Love * 7242e9a92fSRobert Love * The strategy is to lock whenever processing a request or response. Note 7342e9a92fSRobert Love * that every _enter_* function corresponds to a state change. They generally 7442e9a92fSRobert Love * change the lports state and then send a request out on the wire. We lock 7542e9a92fSRobert Love * before calling any of these functions to protect that state change. This 7642e9a92fSRobert Love * means that the entry points into the lport block manage the locks while 7742e9a92fSRobert Love * the state machine can transition between states (i.e. _enter_* functions) 7842e9a92fSRobert Love * while always staying protected. 7942e9a92fSRobert Love * 8042e9a92fSRobert Love * When handling responses we also hold the lport mutex broadly. When the 8142e9a92fSRobert Love * lport receives the response frame it locks the mutex and then calls the 8242e9a92fSRobert Love * appropriate handler for the particuar response. Generally a response will 8342e9a92fSRobert Love * trigger a state change and so the lock must already be held. 8442e9a92fSRobert Love * 8542e9a92fSRobert Love * Retries also have to consider the locking. The retries occur from a work 8642e9a92fSRobert Love * context and the work function will lock the lport and then retry the state 8742e9a92fSRobert Love * (i.e. _enter_* function). 8842e9a92fSRobert Love */ 8942e9a92fSRobert Love 9042e9a92fSRobert Love #include <linux/timer.h> 9142e9a92fSRobert Love #include <asm/unaligned.h> 9242e9a92fSRobert Love 9342e9a92fSRobert Love #include <scsi/fc/fc_gs.h> 9442e9a92fSRobert Love 9542e9a92fSRobert Love #include <scsi/libfc.h> 9642e9a92fSRobert Love #include <scsi/fc_encode.h> 9742e9a92fSRobert Love 988866a5d9SRobert Love #include "fc_libfc.h" 998866a5d9SRobert Love 10042e9a92fSRobert Love /* Fabric IDs to use for point-to-point mode, chosen on whims. */ 10142e9a92fSRobert Love #define FC_LOCAL_PTP_FID_LO 0x010101 10242e9a92fSRobert Love #define FC_LOCAL_PTP_FID_HI 0x010102 10342e9a92fSRobert Love 10442e9a92fSRobert Love #define DNS_DELAY 3 /* Discovery delay after RSCN (in seconds)*/ 10542e9a92fSRobert Love 10642e9a92fSRobert Love static void fc_lport_error(struct fc_lport *, struct fc_frame *); 10742e9a92fSRobert Love 10842e9a92fSRobert Love static void fc_lport_enter_reset(struct fc_lport *); 10942e9a92fSRobert Love static void fc_lport_enter_flogi(struct fc_lport *); 11042e9a92fSRobert Love static void fc_lport_enter_dns(struct fc_lport *); 111c9c7bd7aSChris Leech static void fc_lport_enter_rnn_id(struct fc_lport *); 1125baa17c3SChris Leech static void fc_lport_enter_rsnn_nn(struct fc_lport *); 11342e9a92fSRobert Love static void fc_lport_enter_rft_id(struct fc_lport *); 11442e9a92fSRobert Love static void fc_lport_enter_scr(struct fc_lport *); 11542e9a92fSRobert Love static void fc_lport_enter_ready(struct fc_lport *); 11642e9a92fSRobert Love static void fc_lport_enter_logo(struct fc_lport *); 11742e9a92fSRobert Love 11842e9a92fSRobert Love static const char *fc_lport_state_names[] = { 119b1d9fd55SJoe Eykholt [LPORT_ST_DISABLED] = "disabled", 12042e9a92fSRobert Love [LPORT_ST_FLOGI] = "FLOGI", 12142e9a92fSRobert Love [LPORT_ST_DNS] = "dNS", 122c9c7bd7aSChris Leech [LPORT_ST_RNN_ID] = "RNN_ID", 1235baa17c3SChris Leech [LPORT_ST_RSNN_NN] = "RSNN_NN", 12442e9a92fSRobert Love [LPORT_ST_RFT_ID] = "RFT_ID", 12542e9a92fSRobert Love [LPORT_ST_SCR] = "SCR", 12642e9a92fSRobert Love [LPORT_ST_READY] = "Ready", 12742e9a92fSRobert Love [LPORT_ST_LOGO] = "LOGO", 12842e9a92fSRobert Love [LPORT_ST_RESET] = "reset", 12942e9a92fSRobert Love }; 13042e9a92fSRobert Love 13142e9a92fSRobert Love static int fc_frame_drop(struct fc_lport *lport, struct fc_frame *fp) 13242e9a92fSRobert Love { 13342e9a92fSRobert Love fc_frame_free(fp); 13442e9a92fSRobert Love return 0; 13542e9a92fSRobert Love } 13642e9a92fSRobert Love 13742e9a92fSRobert Love /** 13834f42a07SRobert Love * fc_lport_rport_callback() - Event handler for rport events 13942e9a92fSRobert Love * @lport: The lport which is receiving the event 1409fb9d328SJoe Eykholt * @rdata: private remote port data 14142e9a92fSRobert Love * @event: The event that occured 14242e9a92fSRobert Love * 14342e9a92fSRobert Love * Locking Note: The rport lock should not be held when calling 14442e9a92fSRobert Love * this function. 14542e9a92fSRobert Love */ 14642e9a92fSRobert Love static void fc_lport_rport_callback(struct fc_lport *lport, 1479fb9d328SJoe Eykholt struct fc_rport_priv *rdata, 14842e9a92fSRobert Love enum fc_rport_event event) 14942e9a92fSRobert Love { 1507414705eSRobert Love FC_LPORT_DBG(lport, "Received a %d event for port (%6x)\n", event, 151f211fa51SJoe Eykholt rdata->ids.port_id); 15242e9a92fSRobert Love 153b5cbf083SJoe Eykholt mutex_lock(&lport->lp_mutex); 15442e9a92fSRobert Love switch (event) { 1554c0f62b5SJoe Eykholt case RPORT_EV_READY: 15642e9a92fSRobert Love if (lport->state == LPORT_ST_DNS) { 1579fb9d328SJoe Eykholt lport->dns_rp = rdata; 158c9c7bd7aSChris Leech fc_lport_enter_rnn_id(lport); 15942e9a92fSRobert Love } else { 1604c0f62b5SJoe Eykholt FC_LPORT_DBG(lport, "Received an READY event " 1617414705eSRobert Love "on port (%6x) for the directory " 16242e9a92fSRobert Love "server, but the lport is not " 16342e9a92fSRobert Love "in the DNS state, it's in the " 164f211fa51SJoe Eykholt "%d state", rdata->ids.port_id, 16542e9a92fSRobert Love lport->state); 1669fb9d328SJoe Eykholt lport->tt.rport_logoff(rdata); 16742e9a92fSRobert Love } 16842e9a92fSRobert Love break; 16942e9a92fSRobert Love case RPORT_EV_LOGO: 17042e9a92fSRobert Love case RPORT_EV_FAILED: 17142e9a92fSRobert Love case RPORT_EV_STOP: 17242e9a92fSRobert Love lport->dns_rp = NULL; 17342e9a92fSRobert Love break; 17442e9a92fSRobert Love case RPORT_EV_NONE: 17542e9a92fSRobert Love break; 17642e9a92fSRobert Love } 177b5cbf083SJoe Eykholt mutex_unlock(&lport->lp_mutex); 17842e9a92fSRobert Love } 17942e9a92fSRobert Love 18042e9a92fSRobert Love /** 18134f42a07SRobert Love * fc_lport_state() - Return a string which represents the lport's state 18242e9a92fSRobert Love * @lport: The lport whose state is to converted to a string 18342e9a92fSRobert Love */ 18442e9a92fSRobert Love static const char *fc_lport_state(struct fc_lport *lport) 18542e9a92fSRobert Love { 18642e9a92fSRobert Love const char *cp; 18742e9a92fSRobert Love 18842e9a92fSRobert Love cp = fc_lport_state_names[lport->state]; 18942e9a92fSRobert Love if (!cp) 19042e9a92fSRobert Love cp = "unknown"; 19142e9a92fSRobert Love return cp; 19242e9a92fSRobert Love } 19342e9a92fSRobert Love 19442e9a92fSRobert Love /** 19534f42a07SRobert Love * fc_lport_ptp_setup() - Create an rport for point-to-point mode 19642e9a92fSRobert Love * @lport: The lport to attach the ptp rport to 19742e9a92fSRobert Love * @fid: The FID of the ptp rport 19842e9a92fSRobert Love * @remote_wwpn: The WWPN of the ptp rport 19942e9a92fSRobert Love * @remote_wwnn: The WWNN of the ptp rport 20042e9a92fSRobert Love */ 20142e9a92fSRobert Love static void fc_lport_ptp_setup(struct fc_lport *lport, 20242e9a92fSRobert Love u32 remote_fid, u64 remote_wwpn, 20342e9a92fSRobert Love u64 remote_wwnn) 20442e9a92fSRobert Love { 20548f00902SJoe Eykholt mutex_lock(&lport->disc.disc_mutex); 20648f00902SJoe Eykholt if (lport->ptp_rp) 20742e9a92fSRobert Love lport->tt.rport_logoff(lport->ptp_rp); 2089737e6a7SRobert Love lport->ptp_rp = lport->tt.rport_create(lport, remote_fid); 2099737e6a7SRobert Love lport->ptp_rp->ids.port_name = remote_wwpn; 2109737e6a7SRobert Love lport->ptp_rp->ids.node_name = remote_wwnn; 21148f00902SJoe Eykholt mutex_unlock(&lport->disc.disc_mutex); 21242e9a92fSRobert Love 21342e9a92fSRobert Love lport->tt.rport_login(lport->ptp_rp); 21442e9a92fSRobert Love 21542e9a92fSRobert Love fc_lport_enter_ready(lport); 21642e9a92fSRobert Love } 21742e9a92fSRobert Love 21842e9a92fSRobert Love void fc_get_host_port_type(struct Scsi_Host *shost) 21942e9a92fSRobert Love { 22042e9a92fSRobert Love /* TODO - currently just NPORT */ 22142e9a92fSRobert Love fc_host_port_type(shost) = FC_PORTTYPE_NPORT; 22242e9a92fSRobert Love } 22342e9a92fSRobert Love EXPORT_SYMBOL(fc_get_host_port_type); 22442e9a92fSRobert Love 22542e9a92fSRobert Love void fc_get_host_port_state(struct Scsi_Host *shost) 22642e9a92fSRobert Love { 22742e9a92fSRobert Love struct fc_lport *lp = shost_priv(shost); 22842e9a92fSRobert Love 2298faecddbSChris Leech mutex_lock(&lp->lp_mutex); 2308faecddbSChris Leech if (!lp->link_up) 2318faecddbSChris Leech fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN; 23242e9a92fSRobert Love else 2338faecddbSChris Leech switch (lp->state) { 2348faecddbSChris Leech case LPORT_ST_READY: 2358faecddbSChris Leech fc_host_port_state(shost) = FC_PORTSTATE_ONLINE; 2368faecddbSChris Leech break; 2378faecddbSChris Leech default: 23842e9a92fSRobert Love fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; 23942e9a92fSRobert Love } 2408faecddbSChris Leech mutex_unlock(&lp->lp_mutex); 2418faecddbSChris Leech } 24242e9a92fSRobert Love EXPORT_SYMBOL(fc_get_host_port_state); 24342e9a92fSRobert Love 24442e9a92fSRobert Love void fc_get_host_speed(struct Scsi_Host *shost) 24542e9a92fSRobert Love { 24642e9a92fSRobert Love struct fc_lport *lport = shost_priv(shost); 24742e9a92fSRobert Love 24842e9a92fSRobert Love fc_host_speed(shost) = lport->link_speed; 24942e9a92fSRobert Love } 25042e9a92fSRobert Love EXPORT_SYMBOL(fc_get_host_speed); 25142e9a92fSRobert Love 25242e9a92fSRobert Love struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *shost) 25342e9a92fSRobert Love { 25442e9a92fSRobert Love struct fc_host_statistics *fcoe_stats; 25542e9a92fSRobert Love struct fc_lport *lp = shost_priv(shost); 25642e9a92fSRobert Love struct timespec v0, v1; 257582b45bcSRobert Love unsigned int cpu; 25842e9a92fSRobert Love 25942e9a92fSRobert Love fcoe_stats = &lp->host_stats; 26042e9a92fSRobert Love memset(fcoe_stats, 0, sizeof(struct fc_host_statistics)); 26142e9a92fSRobert Love 26242e9a92fSRobert Love jiffies_to_timespec(jiffies, &v0); 26342e9a92fSRobert Love jiffies_to_timespec(lp->boot_time, &v1); 26442e9a92fSRobert Love fcoe_stats->seconds_since_last_reset = (v0.tv_sec - v1.tv_sec); 26542e9a92fSRobert Love 266582b45bcSRobert Love for_each_possible_cpu(cpu) { 267582b45bcSRobert Love struct fcoe_dev_stats *stats; 268582b45bcSRobert Love 269582b45bcSRobert Love stats = per_cpu_ptr(lp->dev_stats, cpu); 270582b45bcSRobert Love 27142e9a92fSRobert Love fcoe_stats->tx_frames += stats->TxFrames; 27242e9a92fSRobert Love fcoe_stats->tx_words += stats->TxWords; 27342e9a92fSRobert Love fcoe_stats->rx_frames += stats->RxFrames; 27442e9a92fSRobert Love fcoe_stats->rx_words += stats->RxWords; 27542e9a92fSRobert Love fcoe_stats->error_frames += stats->ErrorFrames; 27642e9a92fSRobert Love fcoe_stats->invalid_crc_count += stats->InvalidCRCCount; 27742e9a92fSRobert Love fcoe_stats->fcp_input_requests += stats->InputRequests; 27842e9a92fSRobert Love fcoe_stats->fcp_output_requests += stats->OutputRequests; 27942e9a92fSRobert Love fcoe_stats->fcp_control_requests += stats->ControlRequests; 28042e9a92fSRobert Love fcoe_stats->fcp_input_megabytes += stats->InputMegabytes; 28142e9a92fSRobert Love fcoe_stats->fcp_output_megabytes += stats->OutputMegabytes; 28242e9a92fSRobert Love fcoe_stats->link_failure_count += stats->LinkFailureCount; 28342e9a92fSRobert Love } 28442e9a92fSRobert Love fcoe_stats->lip_count = -1; 28542e9a92fSRobert Love fcoe_stats->nos_count = -1; 28642e9a92fSRobert Love fcoe_stats->loss_of_sync_count = -1; 28742e9a92fSRobert Love fcoe_stats->loss_of_signal_count = -1; 28842e9a92fSRobert Love fcoe_stats->prim_seq_protocol_err_count = -1; 28942e9a92fSRobert Love fcoe_stats->dumped_frames = -1; 29042e9a92fSRobert Love return fcoe_stats; 29142e9a92fSRobert Love } 29242e9a92fSRobert Love EXPORT_SYMBOL(fc_get_host_stats); 29342e9a92fSRobert Love 29442e9a92fSRobert Love /* 29542e9a92fSRobert Love * Fill in FLOGI command for request. 29642e9a92fSRobert Love */ 29742e9a92fSRobert Love static void 29842e9a92fSRobert Love fc_lport_flogi_fill(struct fc_lport *lport, struct fc_els_flogi *flogi, 29942e9a92fSRobert Love unsigned int op) 30042e9a92fSRobert Love { 30142e9a92fSRobert Love struct fc_els_csp *sp; 30242e9a92fSRobert Love struct fc_els_cssp *cp; 30342e9a92fSRobert Love 30442e9a92fSRobert Love memset(flogi, 0, sizeof(*flogi)); 30542e9a92fSRobert Love flogi->fl_cmd = (u8) op; 30642e9a92fSRobert Love put_unaligned_be64(lport->wwpn, &flogi->fl_wwpn); 30742e9a92fSRobert Love put_unaligned_be64(lport->wwnn, &flogi->fl_wwnn); 30842e9a92fSRobert Love sp = &flogi->fl_csp; 30942e9a92fSRobert Love sp->sp_hi_ver = 0x20; 31042e9a92fSRobert Love sp->sp_lo_ver = 0x20; 31142e9a92fSRobert Love sp->sp_bb_cred = htons(10); /* this gets set by gateway */ 31242e9a92fSRobert Love sp->sp_bb_data = htons((u16) lport->mfs); 31342e9a92fSRobert Love cp = &flogi->fl_cssp[3 - 1]; /* class 3 parameters */ 31442e9a92fSRobert Love cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ); 31542e9a92fSRobert Love if (op != ELS_FLOGI) { 31642e9a92fSRobert Love sp->sp_features = htons(FC_SP_FT_CIRO); 31742e9a92fSRobert Love sp->sp_tot_seq = htons(255); /* seq. we accept */ 31842e9a92fSRobert Love sp->sp_rel_off = htons(0x1f); 31942e9a92fSRobert Love sp->sp_e_d_tov = htonl(lport->e_d_tov); 32042e9a92fSRobert Love 32142e9a92fSRobert Love cp->cp_rdfs = htons((u16) lport->mfs); 32242e9a92fSRobert Love cp->cp_con_seq = htons(255); 32342e9a92fSRobert Love cp->cp_open_seq = 1; 32442e9a92fSRobert Love } 32542e9a92fSRobert Love } 32642e9a92fSRobert Love 32742e9a92fSRobert Love /* 32842e9a92fSRobert Love * Add a supported FC-4 type. 32942e9a92fSRobert Love */ 33042e9a92fSRobert Love static void fc_lport_add_fc4_type(struct fc_lport *lport, enum fc_fh_type type) 33142e9a92fSRobert Love { 33242e9a92fSRobert Love __be32 *mp; 33342e9a92fSRobert Love 33442e9a92fSRobert Love mp = &lport->fcts.ff_type_map[type / FC_NS_BPW]; 33542e9a92fSRobert Love *mp = htonl(ntohl(*mp) | 1UL << (type % FC_NS_BPW)); 33642e9a92fSRobert Love } 33742e9a92fSRobert Love 33842e9a92fSRobert Love /** 33934f42a07SRobert Love * fc_lport_recv_rlir_req() - Handle received Registered Link Incident Report. 34042e9a92fSRobert Love * @lport: Fibre Channel local port recieving the RLIR 34142e9a92fSRobert Love * @sp: current sequence in the RLIR exchange 34242e9a92fSRobert Love * @fp: RLIR request frame 34342e9a92fSRobert Love * 3441b69bc06SJoe Eykholt * Locking Note: The lport lock is expected to be held before calling 34542e9a92fSRobert Love * this function. 34642e9a92fSRobert Love */ 34742e9a92fSRobert Love static void fc_lport_recv_rlir_req(struct fc_seq *sp, struct fc_frame *fp, 34842e9a92fSRobert Love struct fc_lport *lport) 34942e9a92fSRobert Love { 3507414705eSRobert Love FC_LPORT_DBG(lport, "Received RLIR request while in state %s\n", 35142e9a92fSRobert Love fc_lport_state(lport)); 35242e9a92fSRobert Love 35342e9a92fSRobert Love lport->tt.seq_els_rsp_send(sp, ELS_LS_ACC, NULL); 35442e9a92fSRobert Love fc_frame_free(fp); 35542e9a92fSRobert Love } 35642e9a92fSRobert Love 35742e9a92fSRobert Love /** 35834f42a07SRobert Love * fc_lport_recv_echo_req() - Handle received ECHO request 35942e9a92fSRobert Love * @lport: Fibre Channel local port recieving the ECHO 36042e9a92fSRobert Love * @sp: current sequence in the ECHO exchange 36142e9a92fSRobert Love * @fp: ECHO request frame 36242e9a92fSRobert Love * 3631b69bc06SJoe Eykholt * Locking Note: The lport lock is expected to be held before calling 36442e9a92fSRobert Love * this function. 36542e9a92fSRobert Love */ 36642e9a92fSRobert Love static void fc_lport_recv_echo_req(struct fc_seq *sp, struct fc_frame *in_fp, 36742e9a92fSRobert Love struct fc_lport *lport) 36842e9a92fSRobert Love { 36942e9a92fSRobert Love struct fc_frame *fp; 37042e9a92fSRobert Love struct fc_exch *ep = fc_seq_exch(sp); 37142e9a92fSRobert Love unsigned int len; 37242e9a92fSRobert Love void *pp; 37342e9a92fSRobert Love void *dp; 37442e9a92fSRobert Love u32 f_ctl; 37542e9a92fSRobert Love 3761b69bc06SJoe Eykholt FC_LPORT_DBG(lport, "Received ECHO request while in state %s\n", 37742e9a92fSRobert Love fc_lport_state(lport)); 37842e9a92fSRobert Love 37942e9a92fSRobert Love len = fr_len(in_fp) - sizeof(struct fc_frame_header); 38042e9a92fSRobert Love pp = fc_frame_payload_get(in_fp, len); 38142e9a92fSRobert Love 38242e9a92fSRobert Love if (len < sizeof(__be32)) 38342e9a92fSRobert Love len = sizeof(__be32); 38442e9a92fSRobert Love 38542e9a92fSRobert Love fp = fc_frame_alloc(lport, len); 38642e9a92fSRobert Love if (fp) { 38742e9a92fSRobert Love dp = fc_frame_payload_get(fp, len); 38842e9a92fSRobert Love memcpy(dp, pp, len); 3891b69bc06SJoe Eykholt *((__be32 *)dp) = htonl(ELS_LS_ACC << 24); 39042e9a92fSRobert Love sp = lport->tt.seq_start_next(sp); 39142e9a92fSRobert Love f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ | FC_FC_END_SEQ; 39242e9a92fSRobert Love fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid, 39342e9a92fSRobert Love FC_TYPE_ELS, f_ctl, 0); 39442e9a92fSRobert Love lport->tt.seq_send(lport, sp, fp); 39542e9a92fSRobert Love } 39642e9a92fSRobert Love fc_frame_free(in_fp); 39742e9a92fSRobert Love } 39842e9a92fSRobert Love 39942e9a92fSRobert Love /** 4001b69bc06SJoe Eykholt * fc_lport_recv_rnid_req() - Handle received Request Node ID data request 4011b69bc06SJoe Eykholt * @sp: The sequence in the RNID exchange 4021b69bc06SJoe Eykholt * @fp: The RNID request frame 4031b69bc06SJoe Eykholt * @lport: The local port recieving the RNID 40442e9a92fSRobert Love * 4051b69bc06SJoe Eykholt * Locking Note: The lport lock is expected to be held before calling 40642e9a92fSRobert Love * this function. 40742e9a92fSRobert Love */ 40842e9a92fSRobert Love static void fc_lport_recv_rnid_req(struct fc_seq *sp, struct fc_frame *in_fp, 40942e9a92fSRobert Love struct fc_lport *lport) 41042e9a92fSRobert Love { 41142e9a92fSRobert Love struct fc_frame *fp; 41242e9a92fSRobert Love struct fc_exch *ep = fc_seq_exch(sp); 41342e9a92fSRobert Love struct fc_els_rnid *req; 41442e9a92fSRobert Love struct { 41542e9a92fSRobert Love struct fc_els_rnid_resp rnid; 41642e9a92fSRobert Love struct fc_els_rnid_cid cid; 41742e9a92fSRobert Love struct fc_els_rnid_gen gen; 41842e9a92fSRobert Love } *rp; 41942e9a92fSRobert Love struct fc_seq_els_data rjt_data; 42042e9a92fSRobert Love u8 fmt; 42142e9a92fSRobert Love size_t len; 42242e9a92fSRobert Love u32 f_ctl; 42342e9a92fSRobert Love 4247414705eSRobert Love FC_LPORT_DBG(lport, "Received RNID request while in state %s\n", 42542e9a92fSRobert Love fc_lport_state(lport)); 42642e9a92fSRobert Love 42742e9a92fSRobert Love req = fc_frame_payload_get(in_fp, sizeof(*req)); 42842e9a92fSRobert Love if (!req) { 42942e9a92fSRobert Love rjt_data.fp = NULL; 43042e9a92fSRobert Love rjt_data.reason = ELS_RJT_LOGIC; 43142e9a92fSRobert Love rjt_data.explan = ELS_EXPL_NONE; 43242e9a92fSRobert Love lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data); 43342e9a92fSRobert Love } else { 43442e9a92fSRobert Love fmt = req->rnid_fmt; 43542e9a92fSRobert Love len = sizeof(*rp); 43642e9a92fSRobert Love if (fmt != ELS_RNIDF_GEN || 43742e9a92fSRobert Love ntohl(lport->rnid_gen.rnid_atype) == 0) { 43842e9a92fSRobert Love fmt = ELS_RNIDF_NONE; /* nothing to provide */ 43942e9a92fSRobert Love len -= sizeof(rp->gen); 44042e9a92fSRobert Love } 44142e9a92fSRobert Love fp = fc_frame_alloc(lport, len); 44242e9a92fSRobert Love if (fp) { 44342e9a92fSRobert Love rp = fc_frame_payload_get(fp, len); 44442e9a92fSRobert Love memset(rp, 0, len); 44542e9a92fSRobert Love rp->rnid.rnid_cmd = ELS_LS_ACC; 44642e9a92fSRobert Love rp->rnid.rnid_fmt = fmt; 44742e9a92fSRobert Love rp->rnid.rnid_cid_len = sizeof(rp->cid); 44842e9a92fSRobert Love rp->cid.rnid_wwpn = htonll(lport->wwpn); 44942e9a92fSRobert Love rp->cid.rnid_wwnn = htonll(lport->wwnn); 45042e9a92fSRobert Love if (fmt == ELS_RNIDF_GEN) { 45142e9a92fSRobert Love rp->rnid.rnid_sid_len = sizeof(rp->gen); 45242e9a92fSRobert Love memcpy(&rp->gen, &lport->rnid_gen, 45342e9a92fSRobert Love sizeof(rp->gen)); 45442e9a92fSRobert Love } 45542e9a92fSRobert Love sp = lport->tt.seq_start_next(sp); 45642e9a92fSRobert Love f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ; 45742e9a92fSRobert Love f_ctl |= FC_FC_END_SEQ | FC_FC_SEQ_INIT; 45842e9a92fSRobert Love fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid, 45942e9a92fSRobert Love FC_TYPE_ELS, f_ctl, 0); 46042e9a92fSRobert Love lport->tt.seq_send(lport, sp, fp); 46142e9a92fSRobert Love } 46242e9a92fSRobert Love } 46342e9a92fSRobert Love fc_frame_free(in_fp); 46442e9a92fSRobert Love } 46542e9a92fSRobert Love 46642e9a92fSRobert Love /** 46734f42a07SRobert Love * fc_lport_recv_logo_req() - Handle received fabric LOGO request 46842e9a92fSRobert Love * @lport: Fibre Channel local port recieving the LOGO 46942e9a92fSRobert Love * @sp: current sequence in the LOGO exchange 47042e9a92fSRobert Love * @fp: LOGO request frame 47142e9a92fSRobert Love * 47242e9a92fSRobert Love * Locking Note: The lport lock is exected to be held before calling 47342e9a92fSRobert Love * this function. 47442e9a92fSRobert Love */ 47542e9a92fSRobert Love static void fc_lport_recv_logo_req(struct fc_seq *sp, struct fc_frame *fp, 47642e9a92fSRobert Love struct fc_lport *lport) 47742e9a92fSRobert Love { 47842e9a92fSRobert Love lport->tt.seq_els_rsp_send(sp, ELS_LS_ACC, NULL); 47942e9a92fSRobert Love fc_lport_enter_reset(lport); 48042e9a92fSRobert Love fc_frame_free(fp); 48142e9a92fSRobert Love } 48242e9a92fSRobert Love 48342e9a92fSRobert Love /** 48434f42a07SRobert Love * fc_fabric_login() - Start the lport state machine 48542e9a92fSRobert Love * @lport: The lport that should log into the fabric 48642e9a92fSRobert Love * 48742e9a92fSRobert Love * Locking Note: This function should not be called 48842e9a92fSRobert Love * with the lport lock held. 48942e9a92fSRobert Love */ 49042e9a92fSRobert Love int fc_fabric_login(struct fc_lport *lport) 49142e9a92fSRobert Love { 49242e9a92fSRobert Love int rc = -1; 49342e9a92fSRobert Love 49442e9a92fSRobert Love mutex_lock(&lport->lp_mutex); 495b1d9fd55SJoe Eykholt if (lport->state == LPORT_ST_DISABLED) { 49642e9a92fSRobert Love fc_lport_enter_reset(lport); 49742e9a92fSRobert Love rc = 0; 49842e9a92fSRobert Love } 49942e9a92fSRobert Love mutex_unlock(&lport->lp_mutex); 50042e9a92fSRobert Love 50142e9a92fSRobert Love return rc; 50242e9a92fSRobert Love } 50342e9a92fSRobert Love EXPORT_SYMBOL(fc_fabric_login); 50442e9a92fSRobert Love 50542e9a92fSRobert Love /** 5068faecddbSChris Leech * __fc_linkup() - Handler for transport linkup events 5078faecddbSChris Leech * @lport: The lport whose link is up 5088faecddbSChris Leech * 5098faecddbSChris Leech * Locking: must be called with the lp_mutex held 5108faecddbSChris Leech */ 5118faecddbSChris Leech void __fc_linkup(struct fc_lport *lport) 5128faecddbSChris Leech { 5138faecddbSChris Leech if (!lport->link_up) { 5148faecddbSChris Leech lport->link_up = 1; 5158faecddbSChris Leech 5168faecddbSChris Leech if (lport->state == LPORT_ST_RESET) 5178faecddbSChris Leech fc_lport_enter_flogi(lport); 5188faecddbSChris Leech } 5198faecddbSChris Leech } 5208faecddbSChris Leech 5218faecddbSChris Leech /** 52234f42a07SRobert Love * fc_linkup() - Handler for transport linkup events 52342e9a92fSRobert Love * @lport: The lport whose link is up 52442e9a92fSRobert Love */ 52542e9a92fSRobert Love void fc_linkup(struct fc_lport *lport) 52642e9a92fSRobert Love { 5277414705eSRobert Love printk(KERN_INFO "libfc: Link up on port (%6x)\n", 52842e9a92fSRobert Love fc_host_port_id(lport->host)); 52942e9a92fSRobert Love 53042e9a92fSRobert Love mutex_lock(&lport->lp_mutex); 5318faecddbSChris Leech __fc_linkup(lport); 53242e9a92fSRobert Love mutex_unlock(&lport->lp_mutex); 53342e9a92fSRobert Love } 53442e9a92fSRobert Love EXPORT_SYMBOL(fc_linkup); 53542e9a92fSRobert Love 53642e9a92fSRobert Love /** 5378faecddbSChris Leech * __fc_linkdown() - Handler for transport linkdown events 5388faecddbSChris Leech * @lport: The lport whose link is down 5398faecddbSChris Leech * 5408faecddbSChris Leech * Locking: must be called with the lp_mutex held 5418faecddbSChris Leech */ 5428faecddbSChris Leech void __fc_linkdown(struct fc_lport *lport) 5438faecddbSChris Leech { 5448faecddbSChris Leech if (lport->link_up) { 5458faecddbSChris Leech lport->link_up = 0; 5468faecddbSChris Leech fc_lport_enter_reset(lport); 5478faecddbSChris Leech lport->tt.fcp_cleanup(lport); 5488faecddbSChris Leech } 5498faecddbSChris Leech } 5508faecddbSChris Leech 5518faecddbSChris Leech /** 55234f42a07SRobert Love * fc_linkdown() - Handler for transport linkdown events 55342e9a92fSRobert Love * @lport: The lport whose link is down 55442e9a92fSRobert Love */ 55542e9a92fSRobert Love void fc_linkdown(struct fc_lport *lport) 55642e9a92fSRobert Love { 5577414705eSRobert Love printk(KERN_INFO "libfc: Link down on port (%6x)\n", 55842e9a92fSRobert Love fc_host_port_id(lport->host)); 55942e9a92fSRobert Love 5608faecddbSChris Leech mutex_lock(&lport->lp_mutex); 5618faecddbSChris Leech __fc_linkdown(lport); 56242e9a92fSRobert Love mutex_unlock(&lport->lp_mutex); 56342e9a92fSRobert Love } 56442e9a92fSRobert Love EXPORT_SYMBOL(fc_linkdown); 56542e9a92fSRobert Love 56642e9a92fSRobert Love /** 56734f42a07SRobert Love * fc_fabric_logoff() - Logout of the fabric 56842e9a92fSRobert Love * @lport: fc_lport pointer to logoff the fabric 56942e9a92fSRobert Love * 57042e9a92fSRobert Love * Return value: 57142e9a92fSRobert Love * 0 for success, -1 for failure 57234f42a07SRobert Love */ 57342e9a92fSRobert Love int fc_fabric_logoff(struct fc_lport *lport) 57442e9a92fSRobert Love { 57542e9a92fSRobert Love lport->tt.disc_stop_final(lport); 57642e9a92fSRobert Love mutex_lock(&lport->lp_mutex); 577a0fd2e49SAbhijeet Joglekar if (lport->dns_rp) 578a0fd2e49SAbhijeet Joglekar lport->tt.rport_logoff(lport->dns_rp); 579a0fd2e49SAbhijeet Joglekar mutex_unlock(&lport->lp_mutex); 580a0fd2e49SAbhijeet Joglekar lport->tt.rport_flush_queue(); 581a0fd2e49SAbhijeet Joglekar mutex_lock(&lport->lp_mutex); 58242e9a92fSRobert Love fc_lport_enter_logo(lport); 58342e9a92fSRobert Love mutex_unlock(&lport->lp_mutex); 584f7db2c15SSteve Ma cancel_delayed_work_sync(&lport->retry_work); 58542e9a92fSRobert Love return 0; 58642e9a92fSRobert Love } 58742e9a92fSRobert Love EXPORT_SYMBOL(fc_fabric_logoff); 58842e9a92fSRobert Love 58942e9a92fSRobert Love /** 59034f42a07SRobert Love * fc_lport_destroy() - unregister a fc_lport 59142e9a92fSRobert Love * @lport: fc_lport pointer to unregister 59242e9a92fSRobert Love * 59342e9a92fSRobert Love * Return value: 59442e9a92fSRobert Love * None 59542e9a92fSRobert Love * Note: 59642e9a92fSRobert Love * exit routine for fc_lport instance 59742e9a92fSRobert Love * clean-up all the allocated memory 59842e9a92fSRobert Love * and free up other system resources. 59942e9a92fSRobert Love * 60034f42a07SRobert Love */ 60142e9a92fSRobert Love int fc_lport_destroy(struct fc_lport *lport) 60242e9a92fSRobert Love { 603bbf15669SAbhijeet Joglekar mutex_lock(&lport->lp_mutex); 604b1d9fd55SJoe Eykholt lport->state = LPORT_ST_DISABLED; 605bbf15669SAbhijeet Joglekar lport->link_up = 0; 60642e9a92fSRobert Love lport->tt.frame_send = fc_frame_drop; 607bbf15669SAbhijeet Joglekar mutex_unlock(&lport->lp_mutex); 608bbf15669SAbhijeet Joglekar 60942e9a92fSRobert Love lport->tt.fcp_abort_io(lport); 610e9ba8b42SJoe Eykholt lport->tt.disc_stop_final(lport); 6111f6ff364SAbhijeet Joglekar lport->tt.exch_mgr_reset(lport, 0, 0); 61242e9a92fSRobert Love return 0; 61342e9a92fSRobert Love } 61442e9a92fSRobert Love EXPORT_SYMBOL(fc_lport_destroy); 61542e9a92fSRobert Love 61642e9a92fSRobert Love /** 61734f42a07SRobert Love * fc_set_mfs() - sets up the mfs for the corresponding fc_lport 61842e9a92fSRobert Love * @lport: fc_lport pointer to unregister 61942e9a92fSRobert Love * @mfs: the new mfs for fc_lport 62042e9a92fSRobert Love * 62142e9a92fSRobert Love * Set mfs for the given fc_lport to the new mfs. 62242e9a92fSRobert Love * 62342e9a92fSRobert Love * Return: 0 for success 62434f42a07SRobert Love */ 62542e9a92fSRobert Love int fc_set_mfs(struct fc_lport *lport, u32 mfs) 62642e9a92fSRobert Love { 62742e9a92fSRobert Love unsigned int old_mfs; 62842e9a92fSRobert Love int rc = -EINVAL; 62942e9a92fSRobert Love 63042e9a92fSRobert Love mutex_lock(&lport->lp_mutex); 63142e9a92fSRobert Love 63242e9a92fSRobert Love old_mfs = lport->mfs; 63342e9a92fSRobert Love 63442e9a92fSRobert Love if (mfs >= FC_MIN_MAX_FRAME) { 63542e9a92fSRobert Love mfs &= ~3; 63642e9a92fSRobert Love if (mfs > FC_MAX_FRAME) 63742e9a92fSRobert Love mfs = FC_MAX_FRAME; 63842e9a92fSRobert Love mfs -= sizeof(struct fc_frame_header); 63942e9a92fSRobert Love lport->mfs = mfs; 64042e9a92fSRobert Love rc = 0; 64142e9a92fSRobert Love } 64242e9a92fSRobert Love 64342e9a92fSRobert Love if (!rc && mfs < old_mfs) 64442e9a92fSRobert Love fc_lport_enter_reset(lport); 64542e9a92fSRobert Love 64642e9a92fSRobert Love mutex_unlock(&lport->lp_mutex); 64742e9a92fSRobert Love 64842e9a92fSRobert Love return rc; 64942e9a92fSRobert Love } 65042e9a92fSRobert Love EXPORT_SYMBOL(fc_set_mfs); 65142e9a92fSRobert Love 65242e9a92fSRobert Love /** 65334f42a07SRobert Love * fc_lport_disc_callback() - Callback for discovery events 65442e9a92fSRobert Love * @lport: FC local port 65542e9a92fSRobert Love * @event: The discovery event 65642e9a92fSRobert Love */ 65742e9a92fSRobert Love void fc_lport_disc_callback(struct fc_lport *lport, enum fc_disc_event event) 65842e9a92fSRobert Love { 65942e9a92fSRobert Love switch (event) { 66042e9a92fSRobert Love case DISC_EV_SUCCESS: 6617414705eSRobert Love FC_LPORT_DBG(lport, "Discovery succeeded\n"); 66242e9a92fSRobert Love break; 66342e9a92fSRobert Love case DISC_EV_FAILED: 6647414705eSRobert Love printk(KERN_ERR "libfc: Discovery failed for port (%6x)\n", 66542e9a92fSRobert Love fc_host_port_id(lport->host)); 66642e9a92fSRobert Love mutex_lock(&lport->lp_mutex); 66742e9a92fSRobert Love fc_lport_enter_reset(lport); 66842e9a92fSRobert Love mutex_unlock(&lport->lp_mutex); 66942e9a92fSRobert Love break; 67042e9a92fSRobert Love case DISC_EV_NONE: 67142e9a92fSRobert Love WARN_ON(1); 67242e9a92fSRobert Love break; 67342e9a92fSRobert Love } 67442e9a92fSRobert Love } 67542e9a92fSRobert Love 67642e9a92fSRobert Love /** 67734f42a07SRobert Love * fc_rport_enter_ready() - Enter the ready state and start discovery 67842e9a92fSRobert Love * @lport: Fibre Channel local port that is ready 67942e9a92fSRobert Love * 68042e9a92fSRobert Love * Locking Note: The lport lock is expected to be held before calling 68142e9a92fSRobert Love * this routine. 68242e9a92fSRobert Love */ 68342e9a92fSRobert Love static void fc_lport_enter_ready(struct fc_lport *lport) 68442e9a92fSRobert Love { 6857414705eSRobert Love FC_LPORT_DBG(lport, "Entered READY from state %s\n", 6867414705eSRobert Love fc_lport_state(lport)); 68742e9a92fSRobert Love 68842e9a92fSRobert Love fc_lport_state_enter(lport, LPORT_ST_READY); 6898faecddbSChris Leech if (lport->vport) 6908faecddbSChris Leech fc_vport_set_state(lport->vport, FC_VPORT_ACTIVE); 6918faecddbSChris Leech fc_vports_linkchange(lport); 69242e9a92fSRobert Love 69329d898e9SJoe Eykholt if (!lport->ptp_rp) 69442e9a92fSRobert Love lport->tt.disc_start(fc_lport_disc_callback, lport); 69542e9a92fSRobert Love } 69642e9a92fSRobert Love 69742e9a92fSRobert Love /** 69834f42a07SRobert Love * fc_lport_recv_flogi_req() - Receive a FLOGI request 69942e9a92fSRobert Love * @sp_in: The sequence the FLOGI is on 70042e9a92fSRobert Love * @rx_fp: The frame the FLOGI is in 70142e9a92fSRobert Love * @lport: The lport that recieved the request 70242e9a92fSRobert Love * 70342e9a92fSRobert Love * A received FLOGI request indicates a point-to-point connection. 70442e9a92fSRobert Love * Accept it with the common service parameters indicating our N port. 70542e9a92fSRobert Love * Set up to do a PLOGI if we have the higher-number WWPN. 70642e9a92fSRobert Love * 7071b69bc06SJoe Eykholt * Locking Note: The lport lock is expected to be held before calling 70842e9a92fSRobert Love * this function. 70942e9a92fSRobert Love */ 71042e9a92fSRobert Love static void fc_lport_recv_flogi_req(struct fc_seq *sp_in, 71142e9a92fSRobert Love struct fc_frame *rx_fp, 71242e9a92fSRobert Love struct fc_lport *lport) 71342e9a92fSRobert Love { 71442e9a92fSRobert Love struct fc_frame *fp; 71542e9a92fSRobert Love struct fc_frame_header *fh; 71642e9a92fSRobert Love struct fc_seq *sp; 71742e9a92fSRobert Love struct fc_exch *ep; 71842e9a92fSRobert Love struct fc_els_flogi *flp; 71942e9a92fSRobert Love struct fc_els_flogi *new_flp; 72042e9a92fSRobert Love u64 remote_wwpn; 72142e9a92fSRobert Love u32 remote_fid; 72242e9a92fSRobert Love u32 local_fid; 72342e9a92fSRobert Love u32 f_ctl; 72442e9a92fSRobert Love 7257414705eSRobert Love FC_LPORT_DBG(lport, "Received FLOGI request while in state %s\n", 72642e9a92fSRobert Love fc_lport_state(lport)); 72742e9a92fSRobert Love 72842e9a92fSRobert Love fh = fc_frame_header_get(rx_fp); 72942e9a92fSRobert Love remote_fid = ntoh24(fh->fh_s_id); 73042e9a92fSRobert Love flp = fc_frame_payload_get(rx_fp, sizeof(*flp)); 73142e9a92fSRobert Love if (!flp) 73242e9a92fSRobert Love goto out; 73342e9a92fSRobert Love remote_wwpn = get_unaligned_be64(&flp->fl_wwpn); 73442e9a92fSRobert Love if (remote_wwpn == lport->wwpn) { 7357414705eSRobert Love printk(KERN_WARNING "libfc: Received FLOGI from port " 7367414705eSRobert Love "with same WWPN %llx\n", remote_wwpn); 73742e9a92fSRobert Love goto out; 73842e9a92fSRobert Love } 7397414705eSRobert Love FC_LPORT_DBG(lport, "FLOGI from port WWPN %llx\n", remote_wwpn); 74042e9a92fSRobert Love 74142e9a92fSRobert Love /* 74242e9a92fSRobert Love * XXX what is the right thing to do for FIDs? 74342e9a92fSRobert Love * The originator might expect our S_ID to be 0xfffffe. 74442e9a92fSRobert Love * But if so, both of us could end up with the same FID. 74542e9a92fSRobert Love */ 74642e9a92fSRobert Love local_fid = FC_LOCAL_PTP_FID_LO; 74742e9a92fSRobert Love if (remote_wwpn < lport->wwpn) { 74842e9a92fSRobert Love local_fid = FC_LOCAL_PTP_FID_HI; 74942e9a92fSRobert Love if (!remote_fid || remote_fid == local_fid) 75042e9a92fSRobert Love remote_fid = FC_LOCAL_PTP_FID_LO; 75142e9a92fSRobert Love } else if (!remote_fid) { 75242e9a92fSRobert Love remote_fid = FC_LOCAL_PTP_FID_HI; 75342e9a92fSRobert Love } 75442e9a92fSRobert Love 75542e9a92fSRobert Love fc_host_port_id(lport->host) = local_fid; 75642e9a92fSRobert Love 75742e9a92fSRobert Love fp = fc_frame_alloc(lport, sizeof(*flp)); 75842e9a92fSRobert Love if (fp) { 75942e9a92fSRobert Love sp = lport->tt.seq_start_next(fr_seq(rx_fp)); 76042e9a92fSRobert Love new_flp = fc_frame_payload_get(fp, sizeof(*flp)); 76142e9a92fSRobert Love fc_lport_flogi_fill(lport, new_flp, ELS_FLOGI); 76242e9a92fSRobert Love new_flp->fl_cmd = (u8) ELS_LS_ACC; 76342e9a92fSRobert Love 76442e9a92fSRobert Love /* 76542e9a92fSRobert Love * Send the response. If this fails, the originator should 76642e9a92fSRobert Love * repeat the sequence. 76742e9a92fSRobert Love */ 76842e9a92fSRobert Love f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ | FC_FC_END_SEQ; 76942e9a92fSRobert Love ep = fc_seq_exch(sp); 77042e9a92fSRobert Love fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid, 77142e9a92fSRobert Love FC_TYPE_ELS, f_ctl, 0); 77242e9a92fSRobert Love lport->tt.seq_send(lport, sp, fp); 77342e9a92fSRobert Love 77442e9a92fSRobert Love } else { 77542e9a92fSRobert Love fc_lport_error(lport, fp); 77642e9a92fSRobert Love } 77742e9a92fSRobert Love fc_lport_ptp_setup(lport, remote_fid, remote_wwpn, 77842e9a92fSRobert Love get_unaligned_be64(&flp->fl_wwnn)); 77942e9a92fSRobert Love 78042e9a92fSRobert Love out: 78142e9a92fSRobert Love sp = fr_seq(rx_fp); 78242e9a92fSRobert Love fc_frame_free(rx_fp); 78342e9a92fSRobert Love } 78442e9a92fSRobert Love 78542e9a92fSRobert Love /** 78634f42a07SRobert Love * fc_lport_recv_req() - The generic lport request handler 78742e9a92fSRobert Love * @lport: The lport that received the request 78842e9a92fSRobert Love * @sp: The sequence the request is on 78942e9a92fSRobert Love * @fp: The frame the request is in 79042e9a92fSRobert Love * 79142e9a92fSRobert Love * This function will see if the lport handles the request or 79242e9a92fSRobert Love * if an rport should handle the request. 79342e9a92fSRobert Love * 79442e9a92fSRobert Love * Locking Note: This function should not be called with the lport 79542e9a92fSRobert Love * lock held becuase it will grab the lock. 79642e9a92fSRobert Love */ 79742e9a92fSRobert Love static void fc_lport_recv_req(struct fc_lport *lport, struct fc_seq *sp, 79842e9a92fSRobert Love struct fc_frame *fp) 79942e9a92fSRobert Love { 80042e9a92fSRobert Love struct fc_frame_header *fh = fc_frame_header_get(fp); 80142e9a92fSRobert Love void (*recv) (struct fc_seq *, struct fc_frame *, struct fc_lport *); 80242e9a92fSRobert Love 80342e9a92fSRobert Love mutex_lock(&lport->lp_mutex); 80442e9a92fSRobert Love 80542e9a92fSRobert Love /* 80642e9a92fSRobert Love * Handle special ELS cases like FLOGI, LOGO, and 80742e9a92fSRobert Love * RSCN here. These don't require a session. 80842e9a92fSRobert Love * Even if we had a session, it might not be ready. 80942e9a92fSRobert Love */ 810e9ba8b42SJoe Eykholt if (!lport->link_up) 811e9ba8b42SJoe Eykholt fc_frame_free(fp); 812e9ba8b42SJoe Eykholt else if (fh->fh_type == FC_TYPE_ELS && 813e9ba8b42SJoe Eykholt fh->fh_r_ctl == FC_RCTL_ELS_REQ) { 81442e9a92fSRobert Love /* 81542e9a92fSRobert Love * Check opcode. 81642e9a92fSRobert Love */ 817131203a1SJoe Eykholt recv = lport->tt.rport_recv_req; 81842e9a92fSRobert Love switch (fc_frame_payload_op(fp)) { 81942e9a92fSRobert Love case ELS_FLOGI: 82042e9a92fSRobert Love recv = fc_lport_recv_flogi_req; 82142e9a92fSRobert Love break; 82242e9a92fSRobert Love case ELS_LOGO: 82342e9a92fSRobert Love fh = fc_frame_header_get(fp); 82442e9a92fSRobert Love if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI) 82542e9a92fSRobert Love recv = fc_lport_recv_logo_req; 82642e9a92fSRobert Love break; 82742e9a92fSRobert Love case ELS_RSCN: 82842e9a92fSRobert Love recv = lport->tt.disc_recv_req; 82942e9a92fSRobert Love break; 83042e9a92fSRobert Love case ELS_ECHO: 83142e9a92fSRobert Love recv = fc_lport_recv_echo_req; 83242e9a92fSRobert Love break; 83342e9a92fSRobert Love case ELS_RLIR: 83442e9a92fSRobert Love recv = fc_lport_recv_rlir_req; 83542e9a92fSRobert Love break; 83642e9a92fSRobert Love case ELS_RNID: 83742e9a92fSRobert Love recv = fc_lport_recv_rnid_req; 83842e9a92fSRobert Love break; 83942e9a92fSRobert Love } 84042e9a92fSRobert Love 84142e9a92fSRobert Love recv(sp, fp, lport); 84242e9a92fSRobert Love } else { 8437414705eSRobert Love FC_LPORT_DBG(lport, "dropping invalid frame (eof %x)\n", 8447414705eSRobert Love fr_eof(fp)); 84542e9a92fSRobert Love fc_frame_free(fp); 84642e9a92fSRobert Love } 84742e9a92fSRobert Love mutex_unlock(&lport->lp_mutex); 84842e9a92fSRobert Love 84942e9a92fSRobert Love /* 85042e9a92fSRobert Love * The common exch_done for all request may not be good 85142e9a92fSRobert Love * if any request requires longer hold on exhange. XXX 85242e9a92fSRobert Love */ 85342e9a92fSRobert Love lport->tt.exch_done(sp); 85442e9a92fSRobert Love } 85542e9a92fSRobert Love 85642e9a92fSRobert Love /** 85734f42a07SRobert Love * fc_lport_reset() - Reset an lport 85842e9a92fSRobert Love * @lport: The lport which should be reset 85942e9a92fSRobert Love * 86042e9a92fSRobert Love * Locking Note: This functions should not be called with the 86142e9a92fSRobert Love * lport lock held. 86242e9a92fSRobert Love */ 86342e9a92fSRobert Love int fc_lport_reset(struct fc_lport *lport) 86442e9a92fSRobert Love { 865f7db2c15SSteve Ma cancel_delayed_work_sync(&lport->retry_work); 86642e9a92fSRobert Love mutex_lock(&lport->lp_mutex); 86742e9a92fSRobert Love fc_lport_enter_reset(lport); 86842e9a92fSRobert Love mutex_unlock(&lport->lp_mutex); 86942e9a92fSRobert Love return 0; 87042e9a92fSRobert Love } 87142e9a92fSRobert Love EXPORT_SYMBOL(fc_lport_reset); 87242e9a92fSRobert Love 87342e9a92fSRobert Love /** 8741190d925SJoe Eykholt * fc_lport_reset_locked() - Reset the local port 87542e9a92fSRobert Love * @lport: Fibre Channel local port to be reset 87642e9a92fSRobert Love * 87742e9a92fSRobert Love * Locking Note: The lport lock is expected to be held before calling 87842e9a92fSRobert Love * this routine. 87942e9a92fSRobert Love */ 8801190d925SJoe Eykholt static void fc_lport_reset_locked(struct fc_lport *lport) 88142e9a92fSRobert Love { 88242e9a92fSRobert Love if (lport->dns_rp) 88342e9a92fSRobert Love lport->tt.rport_logoff(lport->dns_rp); 88442e9a92fSRobert Love 88542e9a92fSRobert Love lport->ptp_rp = NULL; 88642e9a92fSRobert Love 88742e9a92fSRobert Love lport->tt.disc_stop(lport); 88842e9a92fSRobert Love 8891f6ff364SAbhijeet Joglekar lport->tt.exch_mgr_reset(lport, 0, 0); 89042e9a92fSRobert Love fc_host_fabric_name(lport->host) = 0; 89142e9a92fSRobert Love fc_host_port_id(lport->host) = 0; 8921190d925SJoe Eykholt } 89342e9a92fSRobert Love 8941190d925SJoe Eykholt /** 8951190d925SJoe Eykholt * fc_lport_enter_reset() - Reset the local port 8961190d925SJoe Eykholt * @lport: Fibre Channel local port to be reset 8971190d925SJoe Eykholt * 8981190d925SJoe Eykholt * Locking Note: The lport lock is expected to be held before calling 8991190d925SJoe Eykholt * this routine. 9001190d925SJoe Eykholt */ 9011190d925SJoe Eykholt static void fc_lport_enter_reset(struct fc_lport *lport) 9021190d925SJoe Eykholt { 9031190d925SJoe Eykholt FC_LPORT_DBG(lport, "Entered RESET state from %s state\n", 9041190d925SJoe Eykholt fc_lport_state(lport)); 9051190d925SJoe Eykholt 9068faecddbSChris Leech if (lport->vport) { 9078faecddbSChris Leech if (lport->link_up) 9088faecddbSChris Leech fc_vport_set_state(lport->vport, FC_VPORT_INITIALIZING); 9098faecddbSChris Leech else 9108faecddbSChris Leech fc_vport_set_state(lport->vport, FC_VPORT_LINKDOWN); 9118faecddbSChris Leech } 9121190d925SJoe Eykholt fc_lport_state_enter(lport, LPORT_ST_RESET); 9138faecddbSChris Leech fc_vports_linkchange(lport); 9141190d925SJoe Eykholt fc_lport_reset_locked(lport); 915bc0e17f6SVasu Dev if (lport->link_up) 91642e9a92fSRobert Love fc_lport_enter_flogi(lport); 91742e9a92fSRobert Love } 91842e9a92fSRobert Love 91942e9a92fSRobert Love /** 9201190d925SJoe Eykholt * fc_lport_enter_disabled() - disable the local port 9211190d925SJoe Eykholt * @lport: Fibre Channel local port to be reset 9221190d925SJoe Eykholt * 9231190d925SJoe Eykholt * Locking Note: The lport lock is expected to be held before calling 9241190d925SJoe Eykholt * this routine. 9251190d925SJoe Eykholt */ 9261190d925SJoe Eykholt static void fc_lport_enter_disabled(struct fc_lport *lport) 9271190d925SJoe Eykholt { 9281190d925SJoe Eykholt FC_LPORT_DBG(lport, "Entered disabled state from %s state\n", 9291190d925SJoe Eykholt fc_lport_state(lport)); 9301190d925SJoe Eykholt 9311190d925SJoe Eykholt fc_lport_state_enter(lport, LPORT_ST_DISABLED); 9328faecddbSChris Leech fc_vports_linkchange(lport); 9331190d925SJoe Eykholt fc_lport_reset_locked(lport); 9341190d925SJoe Eykholt } 9351190d925SJoe Eykholt 9361190d925SJoe Eykholt /** 93734f42a07SRobert Love * fc_lport_error() - Handler for any errors 93842e9a92fSRobert Love * @lport: The fc_lport object 93942e9a92fSRobert Love * @fp: The frame pointer 94042e9a92fSRobert Love * 94142e9a92fSRobert Love * If the error was caused by a resource allocation failure 94242e9a92fSRobert Love * then wait for half a second and retry, otherwise retry 94342e9a92fSRobert Love * after the e_d_tov time. 94442e9a92fSRobert Love */ 94542e9a92fSRobert Love static void fc_lport_error(struct fc_lport *lport, struct fc_frame *fp) 94642e9a92fSRobert Love { 94742e9a92fSRobert Love unsigned long delay = 0; 9487414705eSRobert Love FC_LPORT_DBG(lport, "Error %ld in state %s, retries %d\n", 94942e9a92fSRobert Love PTR_ERR(fp), fc_lport_state(lport), 95042e9a92fSRobert Love lport->retry_count); 95142e9a92fSRobert Love 95242e9a92fSRobert Love if (!fp || PTR_ERR(fp) == -FC_EX_TIMEOUT) { 95342e9a92fSRobert Love /* 95442e9a92fSRobert Love * Memory allocation failure, or the exchange timed out. 95542e9a92fSRobert Love * Retry after delay 95642e9a92fSRobert Love */ 95742e9a92fSRobert Love if (lport->retry_count < lport->max_retry_count) { 95842e9a92fSRobert Love lport->retry_count++; 95942e9a92fSRobert Love if (!fp) 96042e9a92fSRobert Love delay = msecs_to_jiffies(500); 96142e9a92fSRobert Love else 96242e9a92fSRobert Love delay = msecs_to_jiffies(lport->e_d_tov); 96342e9a92fSRobert Love 96442e9a92fSRobert Love schedule_delayed_work(&lport->retry_work, delay); 96542e9a92fSRobert Love } else { 96642e9a92fSRobert Love switch (lport->state) { 967b1d9fd55SJoe Eykholt case LPORT_ST_DISABLED: 96842e9a92fSRobert Love case LPORT_ST_READY: 96942e9a92fSRobert Love case LPORT_ST_RESET: 970c9c7bd7aSChris Leech case LPORT_ST_RNN_ID: 9715baa17c3SChris Leech case LPORT_ST_RSNN_NN: 97242e9a92fSRobert Love case LPORT_ST_RFT_ID: 97342e9a92fSRobert Love case LPORT_ST_SCR: 97442e9a92fSRobert Love case LPORT_ST_DNS: 97542e9a92fSRobert Love case LPORT_ST_FLOGI: 97642e9a92fSRobert Love case LPORT_ST_LOGO: 97742e9a92fSRobert Love fc_lport_enter_reset(lport); 97842e9a92fSRobert Love break; 97942e9a92fSRobert Love } 98042e9a92fSRobert Love } 98142e9a92fSRobert Love } 98242e9a92fSRobert Love } 98342e9a92fSRobert Love 98442e9a92fSRobert Love /** 98534f42a07SRobert Love * fc_lport_rft_id_resp() - Handle response to Register Fibre 98628cc0e31SChris Leech * Channel Types by ID (RFT_ID) request 98728cc0e31SChris Leech * @sp: current sequence in RFT_ID exchange 98842e9a92fSRobert Love * @fp: response frame 98942e9a92fSRobert Love * @lp_arg: Fibre Channel host port instance 99042e9a92fSRobert Love * 99142e9a92fSRobert Love * Locking Note: This function will be called without the lport lock 99242e9a92fSRobert Love * held, but it will lock, call an _enter_* function or fc_lport_error 99342e9a92fSRobert Love * and then unlock the lport. 99442e9a92fSRobert Love */ 99542e9a92fSRobert Love static void fc_lport_rft_id_resp(struct fc_seq *sp, struct fc_frame *fp, 99642e9a92fSRobert Love void *lp_arg) 99742e9a92fSRobert Love { 99842e9a92fSRobert Love struct fc_lport *lport = lp_arg; 99942e9a92fSRobert Love struct fc_frame_header *fh; 100042e9a92fSRobert Love struct fc_ct_hdr *ct; 100142e9a92fSRobert Love 1002f657d299SJoe Eykholt FC_LPORT_DBG(lport, "Received a RFT_ID %s\n", fc_els_resp_type(fp)); 1003f657d299SJoe Eykholt 100442e9a92fSRobert Love if (fp == ERR_PTR(-FC_EX_CLOSED)) 100542e9a92fSRobert Love return; 100642e9a92fSRobert Love 100742e9a92fSRobert Love mutex_lock(&lport->lp_mutex); 100842e9a92fSRobert Love 100942e9a92fSRobert Love if (lport->state != LPORT_ST_RFT_ID) { 10107414705eSRobert Love FC_LPORT_DBG(lport, "Received a RFT_ID response, but in state " 10117414705eSRobert Love "%s\n", fc_lport_state(lport)); 101276f6804eSAbhijeet Joglekar if (IS_ERR(fp)) 101376f6804eSAbhijeet Joglekar goto err; 101442e9a92fSRobert Love goto out; 101542e9a92fSRobert Love } 101642e9a92fSRobert Love 101776f6804eSAbhijeet Joglekar if (IS_ERR(fp)) { 101876f6804eSAbhijeet Joglekar fc_lport_error(lport, fp); 101976f6804eSAbhijeet Joglekar goto err; 102076f6804eSAbhijeet Joglekar } 102176f6804eSAbhijeet Joglekar 102242e9a92fSRobert Love fh = fc_frame_header_get(fp); 102342e9a92fSRobert Love ct = fc_frame_payload_get(fp, sizeof(*ct)); 102442e9a92fSRobert Love 102542e9a92fSRobert Love if (fh && ct && fh->fh_type == FC_TYPE_CT && 102642e9a92fSRobert Love ct->ct_fs_type == FC_FST_DIR && 102742e9a92fSRobert Love ct->ct_fs_subtype == FC_NS_SUBTYPE && 102842e9a92fSRobert Love ntohs(ct->ct_cmd) == FC_FS_ACC) 102942e9a92fSRobert Love fc_lport_enter_scr(lport); 103042e9a92fSRobert Love else 103142e9a92fSRobert Love fc_lport_error(lport, fp); 103242e9a92fSRobert Love out: 103342e9a92fSRobert Love fc_frame_free(fp); 103442e9a92fSRobert Love err: 103542e9a92fSRobert Love mutex_unlock(&lport->lp_mutex); 103642e9a92fSRobert Love } 103742e9a92fSRobert Love 103842e9a92fSRobert Love /** 10395baa17c3SChris Leech * fc_lport_rsnn_nn_resp() - Handle response to Register Symbolic Node Name 10405baa17c3SChris Leech * by Node Name (RSNN_NN) request 10415baa17c3SChris Leech * @sp: current sequence in RSNN_NN exchange 10425baa17c3SChris Leech * @fp: response frame 10435baa17c3SChris Leech * @lp_arg: Fibre Channel host port instance 10445baa17c3SChris Leech * 10455baa17c3SChris Leech * Locking Note: This function will be called without the lport lock 10465baa17c3SChris Leech * held, but it will lock, call an _enter_* function or fc_lport_error 10475baa17c3SChris Leech * and then unlock the lport. 10485baa17c3SChris Leech */ 10495baa17c3SChris Leech static void fc_lport_rsnn_nn_resp(struct fc_seq *sp, struct fc_frame *fp, 10505baa17c3SChris Leech void *lp_arg) 10515baa17c3SChris Leech { 10525baa17c3SChris Leech struct fc_lport *lport = lp_arg; 10535baa17c3SChris Leech struct fc_frame_header *fh; 10545baa17c3SChris Leech struct fc_ct_hdr *ct; 10555baa17c3SChris Leech 10565baa17c3SChris Leech FC_LPORT_DBG(lport, "Received a RSNN_NN %s\n", fc_els_resp_type(fp)); 10575baa17c3SChris Leech 10585baa17c3SChris Leech if (fp == ERR_PTR(-FC_EX_CLOSED)) 10595baa17c3SChris Leech return; 10605baa17c3SChris Leech 10615baa17c3SChris Leech mutex_lock(&lport->lp_mutex); 10625baa17c3SChris Leech 10635baa17c3SChris Leech if (lport->state != LPORT_ST_RSNN_NN) { 10645baa17c3SChris Leech FC_LPORT_DBG(lport, "Received a RSNN_NN response, but in state " 10655baa17c3SChris Leech "%s\n", fc_lport_state(lport)); 10665baa17c3SChris Leech if (IS_ERR(fp)) 10675baa17c3SChris Leech goto err; 10685baa17c3SChris Leech goto out; 10695baa17c3SChris Leech } 10705baa17c3SChris Leech 10715baa17c3SChris Leech if (IS_ERR(fp)) { 10725baa17c3SChris Leech fc_lport_error(lport, fp); 10735baa17c3SChris Leech goto err; 10745baa17c3SChris Leech } 10755baa17c3SChris Leech 10765baa17c3SChris Leech fh = fc_frame_header_get(fp); 10775baa17c3SChris Leech ct = fc_frame_payload_get(fp, sizeof(*ct)); 10785baa17c3SChris Leech if (fh && ct && fh->fh_type == FC_TYPE_CT && 10795baa17c3SChris Leech ct->ct_fs_type == FC_FST_DIR && 10805baa17c3SChris Leech ct->ct_fs_subtype == FC_NS_SUBTYPE && 10815baa17c3SChris Leech ntohs(ct->ct_cmd) == FC_FS_ACC) 10825baa17c3SChris Leech fc_lport_enter_rsnn_nn(lport); 10835baa17c3SChris Leech else 10845baa17c3SChris Leech fc_lport_error(lport, fp); 10855baa17c3SChris Leech 10865baa17c3SChris Leech out: 10875baa17c3SChris Leech fc_frame_free(fp); 10885baa17c3SChris Leech err: 10895baa17c3SChris Leech mutex_unlock(&lport->lp_mutex); 10905baa17c3SChris Leech } 10915baa17c3SChris Leech 10925baa17c3SChris Leech /** 1093c9c7bd7aSChris Leech * fc_lport_rnn_id_resp() - Handle response to Register Node 1094c9c7bd7aSChris Leech * Name by ID (RNN_ID) request 1095c9c7bd7aSChris Leech * @sp: current sequence in RNN_ID exchange 1096c9c7bd7aSChris Leech * @fp: response frame 1097c9c7bd7aSChris Leech * @lp_arg: Fibre Channel host port instance 1098c9c7bd7aSChris Leech * 1099c9c7bd7aSChris Leech * Locking Note: This function will be called without the lport lock 1100c9c7bd7aSChris Leech * held, but it will lock, call an _enter_* function or fc_lport_error 1101c9c7bd7aSChris Leech * and then unlock the lport. 1102c9c7bd7aSChris Leech */ 1103c9c7bd7aSChris Leech static void fc_lport_rnn_id_resp(struct fc_seq *sp, struct fc_frame *fp, 1104c9c7bd7aSChris Leech void *lp_arg) 1105c9c7bd7aSChris Leech { 1106c9c7bd7aSChris Leech struct fc_lport *lport = lp_arg; 1107c9c7bd7aSChris Leech struct fc_frame_header *fh; 1108c9c7bd7aSChris Leech struct fc_ct_hdr *ct; 1109c9c7bd7aSChris Leech 1110c9c7bd7aSChris Leech FC_LPORT_DBG(lport, "Received a RNN_ID %s\n", fc_els_resp_type(fp)); 1111c9c7bd7aSChris Leech 1112c9c7bd7aSChris Leech if (fp == ERR_PTR(-FC_EX_CLOSED)) 1113c9c7bd7aSChris Leech return; 1114c9c7bd7aSChris Leech 1115c9c7bd7aSChris Leech mutex_lock(&lport->lp_mutex); 1116c9c7bd7aSChris Leech 1117c9c7bd7aSChris Leech if (lport->state != LPORT_ST_RNN_ID) { 1118c9c7bd7aSChris Leech FC_LPORT_DBG(lport, "Received a RNN_ID response, but in state " 1119c9c7bd7aSChris Leech "%s\n", fc_lport_state(lport)); 1120c9c7bd7aSChris Leech if (IS_ERR(fp)) 1121c9c7bd7aSChris Leech goto err; 1122c9c7bd7aSChris Leech goto out; 1123c9c7bd7aSChris Leech } 1124c9c7bd7aSChris Leech 1125c9c7bd7aSChris Leech if (IS_ERR(fp)) { 1126c9c7bd7aSChris Leech fc_lport_error(lport, fp); 1127c9c7bd7aSChris Leech goto err; 1128c9c7bd7aSChris Leech } 1129c9c7bd7aSChris Leech 1130c9c7bd7aSChris Leech fh = fc_frame_header_get(fp); 1131c9c7bd7aSChris Leech ct = fc_frame_payload_get(fp, sizeof(*ct)); 1132c9c7bd7aSChris Leech if (fh && ct && fh->fh_type == FC_TYPE_CT && 1133c9c7bd7aSChris Leech ct->ct_fs_type == FC_FST_DIR && 1134c9c7bd7aSChris Leech ct->ct_fs_subtype == FC_NS_SUBTYPE && 1135c9c7bd7aSChris Leech ntohs(ct->ct_cmd) == FC_FS_ACC) 1136c9c7bd7aSChris Leech fc_lport_enter_rft_id(lport); 1137c9c7bd7aSChris Leech else 1138c9c7bd7aSChris Leech fc_lport_error(lport, fp); 1139c9c7bd7aSChris Leech 1140c9c7bd7aSChris Leech out: 1141c9c7bd7aSChris Leech fc_frame_free(fp); 1142c9c7bd7aSChris Leech err: 1143c9c7bd7aSChris Leech mutex_unlock(&lport->lp_mutex); 1144c9c7bd7aSChris Leech } 1145c9c7bd7aSChris Leech 1146c9c7bd7aSChris Leech /** 114734f42a07SRobert Love * fc_lport_scr_resp() - Handle response to State Change Register (SCR) request 114842e9a92fSRobert Love * @sp: current sequence in SCR exchange 114942e9a92fSRobert Love * @fp: response frame 115042e9a92fSRobert Love * @lp_arg: Fibre Channel lport port instance that sent the registration request 115142e9a92fSRobert Love * 115242e9a92fSRobert Love * Locking Note: This function will be called without the lport lock 115342e9a92fSRobert Love * held, but it will lock, call an _enter_* function or fc_lport_error 115442e9a92fSRobert Love * and then unlock the lport. 115542e9a92fSRobert Love */ 115642e9a92fSRobert Love static void fc_lport_scr_resp(struct fc_seq *sp, struct fc_frame *fp, 115742e9a92fSRobert Love void *lp_arg) 115842e9a92fSRobert Love { 115942e9a92fSRobert Love struct fc_lport *lport = lp_arg; 116042e9a92fSRobert Love u8 op; 116142e9a92fSRobert Love 1162f657d299SJoe Eykholt FC_LPORT_DBG(lport, "Received a SCR %s\n", fc_els_resp_type(fp)); 1163f657d299SJoe Eykholt 116442e9a92fSRobert Love if (fp == ERR_PTR(-FC_EX_CLOSED)) 116542e9a92fSRobert Love return; 116642e9a92fSRobert Love 116742e9a92fSRobert Love mutex_lock(&lport->lp_mutex); 116842e9a92fSRobert Love 116942e9a92fSRobert Love if (lport->state != LPORT_ST_SCR) { 11707414705eSRobert Love FC_LPORT_DBG(lport, "Received a SCR response, but in state " 11717414705eSRobert Love "%s\n", fc_lport_state(lport)); 117276f6804eSAbhijeet Joglekar if (IS_ERR(fp)) 117376f6804eSAbhijeet Joglekar goto err; 117442e9a92fSRobert Love goto out; 117542e9a92fSRobert Love } 117642e9a92fSRobert Love 117776f6804eSAbhijeet Joglekar if (IS_ERR(fp)) { 117876f6804eSAbhijeet Joglekar fc_lport_error(lport, fp); 117976f6804eSAbhijeet Joglekar goto err; 118076f6804eSAbhijeet Joglekar } 118176f6804eSAbhijeet Joglekar 118242e9a92fSRobert Love op = fc_frame_payload_op(fp); 118342e9a92fSRobert Love if (op == ELS_LS_ACC) 118442e9a92fSRobert Love fc_lport_enter_ready(lport); 118542e9a92fSRobert Love else 118642e9a92fSRobert Love fc_lport_error(lport, fp); 118742e9a92fSRobert Love 118842e9a92fSRobert Love out: 118942e9a92fSRobert Love fc_frame_free(fp); 119042e9a92fSRobert Love err: 119142e9a92fSRobert Love mutex_unlock(&lport->lp_mutex); 119242e9a92fSRobert Love } 119342e9a92fSRobert Love 119442e9a92fSRobert Love /** 119534f42a07SRobert Love * fc_lport_enter_scr() - Send a State Change Register (SCR) request 119642e9a92fSRobert Love * @lport: Fibre Channel local port to register for state changes 119742e9a92fSRobert Love * 119842e9a92fSRobert Love * Locking Note: The lport lock is expected to be held before calling 119942e9a92fSRobert Love * this routine. 120042e9a92fSRobert Love */ 120142e9a92fSRobert Love static void fc_lport_enter_scr(struct fc_lport *lport) 120242e9a92fSRobert Love { 120342e9a92fSRobert Love struct fc_frame *fp; 120442e9a92fSRobert Love 12057414705eSRobert Love FC_LPORT_DBG(lport, "Entered SCR state from %s state\n", 12067414705eSRobert Love fc_lport_state(lport)); 120742e9a92fSRobert Love 120842e9a92fSRobert Love fc_lport_state_enter(lport, LPORT_ST_SCR); 120942e9a92fSRobert Love 121042e9a92fSRobert Love fp = fc_frame_alloc(lport, sizeof(struct fc_els_scr)); 121142e9a92fSRobert Love if (!fp) { 121242e9a92fSRobert Love fc_lport_error(lport, fp); 121342e9a92fSRobert Love return; 121442e9a92fSRobert Love } 121542e9a92fSRobert Love 1216a46f327aSJoe Eykholt if (!lport->tt.elsct_send(lport, FC_FID_FCTRL, fp, ELS_SCR, 121742e9a92fSRobert Love fc_lport_scr_resp, lport, lport->e_d_tov)) 12188f550f93SChris Leech fc_lport_error(lport, NULL); 121942e9a92fSRobert Love } 122042e9a92fSRobert Love 122142e9a92fSRobert Love /** 122234f42a07SRobert Love * fc_lport_enter_rft_id() - Register FC4-types with the name server 122342e9a92fSRobert Love * @lport: Fibre Channel local port to register 122442e9a92fSRobert Love * 122542e9a92fSRobert Love * Locking Note: The lport lock is expected to be held before calling 122642e9a92fSRobert Love * this routine. 122742e9a92fSRobert Love */ 122842e9a92fSRobert Love static void fc_lport_enter_rft_id(struct fc_lport *lport) 122942e9a92fSRobert Love { 123042e9a92fSRobert Love struct fc_frame *fp; 123142e9a92fSRobert Love struct fc_ns_fts *lps; 123242e9a92fSRobert Love int i; 123342e9a92fSRobert Love 12347414705eSRobert Love FC_LPORT_DBG(lport, "Entered RFT_ID state from %s state\n", 12357414705eSRobert Love fc_lport_state(lport)); 123642e9a92fSRobert Love 123742e9a92fSRobert Love fc_lport_state_enter(lport, LPORT_ST_RFT_ID); 123842e9a92fSRobert Love 123942e9a92fSRobert Love lps = &lport->fcts; 124042e9a92fSRobert Love i = sizeof(lps->ff_type_map) / sizeof(lps->ff_type_map[0]); 124142e9a92fSRobert Love while (--i >= 0) 124242e9a92fSRobert Love if (ntohl(lps->ff_type_map[i]) != 0) 124342e9a92fSRobert Love break; 124442e9a92fSRobert Love if (i < 0) { 124542e9a92fSRobert Love /* nothing to register, move on to SCR */ 124642e9a92fSRobert Love fc_lport_enter_scr(lport); 124742e9a92fSRobert Love return; 124842e9a92fSRobert Love } 124942e9a92fSRobert Love 125042e9a92fSRobert Love fp = fc_frame_alloc(lport, sizeof(struct fc_ct_hdr) + 125142e9a92fSRobert Love sizeof(struct fc_ns_rft)); 125242e9a92fSRobert Love if (!fp) { 125342e9a92fSRobert Love fc_lport_error(lport, fp); 125442e9a92fSRobert Love return; 125542e9a92fSRobert Love } 125642e9a92fSRobert Love 1257a46f327aSJoe Eykholt if (!lport->tt.elsct_send(lport, FC_FID_DIR_SERV, fp, FC_NS_RFT_ID, 125842e9a92fSRobert Love fc_lport_rft_id_resp, 125942e9a92fSRobert Love lport, lport->e_d_tov)) 126042e9a92fSRobert Love fc_lport_error(lport, fp); 126142e9a92fSRobert Love } 126242e9a92fSRobert Love 1263c9c7bd7aSChris Leech /** 12645baa17c3SChris Leech * fc_rport_enter_rsnn_nn() - Register symbolic node name with the name server 12655baa17c3SChris Leech * @lport: Fibre Channel local port to register 12665baa17c3SChris Leech * 12675baa17c3SChris Leech * Locking Note: The lport lock is expected to be held before calling 12685baa17c3SChris Leech * this routine. 12695baa17c3SChris Leech */ 12705baa17c3SChris Leech static void fc_lport_enter_rsnn_nn(struct fc_lport *lport) 12715baa17c3SChris Leech { 12725baa17c3SChris Leech struct fc_frame *fp; 12735baa17c3SChris Leech size_t len; 12745baa17c3SChris Leech 12755baa17c3SChris Leech FC_LPORT_DBG(lport, "Entered RSNN_NN state from %s state\n", 12765baa17c3SChris Leech fc_lport_state(lport)); 12775baa17c3SChris Leech 12785baa17c3SChris Leech fc_lport_state_enter(lport, LPORT_ST_RSNN_NN); 12795baa17c3SChris Leech 12805baa17c3SChris Leech len = strnlen(fc_host_symbolic_name(lport->host), 255); 12815baa17c3SChris Leech fp = fc_frame_alloc(lport, sizeof(struct fc_ct_hdr) + 12825baa17c3SChris Leech sizeof(struct fc_ns_rsnn) + len); 12835baa17c3SChris Leech if (!fp) { 12845baa17c3SChris Leech fc_lport_error(lport, fp); 12855baa17c3SChris Leech return; 12865baa17c3SChris Leech } 12875baa17c3SChris Leech 12885baa17c3SChris Leech if (!lport->tt.elsct_send(lport, FC_FID_DIR_SERV, fp, FC_NS_RSNN_NN, 12895baa17c3SChris Leech fc_lport_rsnn_nn_resp, 12905baa17c3SChris Leech lport, lport->e_d_tov)) 12915baa17c3SChris Leech fc_lport_error(lport, fp); 12925baa17c3SChris Leech } 12935baa17c3SChris Leech 12945baa17c3SChris Leech /** 1295c9c7bd7aSChris Leech * fc_rport_enter_rnn_id() - Register node name with the name server 1296c9c7bd7aSChris Leech * @lport: Fibre Channel local port to register 1297c9c7bd7aSChris Leech * 1298c9c7bd7aSChris Leech * Locking Note: The lport lock is expected to be held before calling 1299c9c7bd7aSChris Leech * this routine. 1300c9c7bd7aSChris Leech */ 1301c9c7bd7aSChris Leech static void fc_lport_enter_rnn_id(struct fc_lport *lport) 1302c9c7bd7aSChris Leech { 1303c9c7bd7aSChris Leech struct fc_frame *fp; 1304c9c7bd7aSChris Leech 1305c9c7bd7aSChris Leech FC_LPORT_DBG(lport, "Entered RNN_ID state from %s state\n", 1306c9c7bd7aSChris Leech fc_lport_state(lport)); 1307c9c7bd7aSChris Leech 1308c9c7bd7aSChris Leech fc_lport_state_enter(lport, LPORT_ST_RNN_ID); 1309c9c7bd7aSChris Leech 1310c9c7bd7aSChris Leech fp = fc_frame_alloc(lport, sizeof(struct fc_ct_hdr) + 1311c9c7bd7aSChris Leech sizeof(struct fc_ns_rn_id)); 1312c9c7bd7aSChris Leech if (!fp) { 1313c9c7bd7aSChris Leech fc_lport_error(lport, fp); 1314c9c7bd7aSChris Leech return; 1315c9c7bd7aSChris Leech } 1316c9c7bd7aSChris Leech 1317c9c7bd7aSChris Leech if (!lport->tt.elsct_send(lport, FC_FID_DIR_SERV, fp, FC_NS_RNN_ID, 1318c9c7bd7aSChris Leech fc_lport_rnn_id_resp, 1319c9c7bd7aSChris Leech lport, lport->e_d_tov)) 1320c9c7bd7aSChris Leech fc_lport_error(lport, fp); 1321c9c7bd7aSChris Leech } 1322c9c7bd7aSChris Leech 132342e9a92fSRobert Love static struct fc_rport_operations fc_lport_rport_ops = { 132442e9a92fSRobert Love .event_callback = fc_lport_rport_callback, 132542e9a92fSRobert Love }; 132642e9a92fSRobert Love 132742e9a92fSRobert Love /** 132834f42a07SRobert Love * fc_rport_enter_dns() - Create a rport to the name server 132942e9a92fSRobert Love * @lport: Fibre Channel local port requesting a rport for the name server 133042e9a92fSRobert Love * 133142e9a92fSRobert Love * Locking Note: The lport lock is expected to be held before calling 133242e9a92fSRobert Love * this routine. 133342e9a92fSRobert Love */ 133442e9a92fSRobert Love static void fc_lport_enter_dns(struct fc_lport *lport) 133542e9a92fSRobert Love { 1336ab28f1fdSJoe Eykholt struct fc_rport_priv *rdata; 133742e9a92fSRobert Love 13387414705eSRobert Love FC_LPORT_DBG(lport, "Entered DNS state from %s state\n", 13397414705eSRobert Love fc_lport_state(lport)); 134042e9a92fSRobert Love 134142e9a92fSRobert Love fc_lport_state_enter(lport, LPORT_ST_DNS); 134242e9a92fSRobert Love 134348f00902SJoe Eykholt mutex_lock(&lport->disc.disc_mutex); 13449737e6a7SRobert Love rdata = lport->tt.rport_create(lport, FC_FID_DIR_SERV); 134548f00902SJoe Eykholt mutex_unlock(&lport->disc.disc_mutex); 13469fb9d328SJoe Eykholt if (!rdata) 134742e9a92fSRobert Love goto err; 134842e9a92fSRobert Love 134942e9a92fSRobert Love rdata->ops = &fc_lport_rport_ops; 13509fb9d328SJoe Eykholt lport->tt.rport_login(rdata); 135142e9a92fSRobert Love return; 135242e9a92fSRobert Love 135342e9a92fSRobert Love err: 135442e9a92fSRobert Love fc_lport_error(lport, NULL); 135542e9a92fSRobert Love } 135642e9a92fSRobert Love 135742e9a92fSRobert Love /** 135834f42a07SRobert Love * fc_lport_timeout() - Handler for the retry_work timer. 135942e9a92fSRobert Love * @work: The work struct of the fc_lport 136042e9a92fSRobert Love */ 136142e9a92fSRobert Love static void fc_lport_timeout(struct work_struct *work) 136242e9a92fSRobert Love { 136342e9a92fSRobert Love struct fc_lport *lport = 136442e9a92fSRobert Love container_of(work, struct fc_lport, 136542e9a92fSRobert Love retry_work.work); 136642e9a92fSRobert Love 136742e9a92fSRobert Love mutex_lock(&lport->lp_mutex); 136842e9a92fSRobert Love 136942e9a92fSRobert Love switch (lport->state) { 1370b1d9fd55SJoe Eykholt case LPORT_ST_DISABLED: 137142e9a92fSRobert Love WARN_ON(1); 137242e9a92fSRobert Love break; 137322655ac2SJoe Eykholt case LPORT_ST_READY: 137422655ac2SJoe Eykholt WARN_ON(1); 137522655ac2SJoe Eykholt break; 137622655ac2SJoe Eykholt case LPORT_ST_RESET: 137722655ac2SJoe Eykholt break; 137842e9a92fSRobert Love case LPORT_ST_FLOGI: 137942e9a92fSRobert Love fc_lport_enter_flogi(lport); 138042e9a92fSRobert Love break; 138142e9a92fSRobert Love case LPORT_ST_DNS: 138242e9a92fSRobert Love fc_lport_enter_dns(lport); 138342e9a92fSRobert Love break; 1384c9c7bd7aSChris Leech case LPORT_ST_RNN_ID: 1385c9c7bd7aSChris Leech fc_lport_enter_rnn_id(lport); 1386c9c7bd7aSChris Leech break; 13875baa17c3SChris Leech case LPORT_ST_RSNN_NN: 13885baa17c3SChris Leech fc_lport_enter_rsnn_nn(lport); 13895baa17c3SChris Leech break; 139042e9a92fSRobert Love case LPORT_ST_RFT_ID: 139142e9a92fSRobert Love fc_lport_enter_rft_id(lport); 139242e9a92fSRobert Love break; 139342e9a92fSRobert Love case LPORT_ST_SCR: 139442e9a92fSRobert Love fc_lport_enter_scr(lport); 139542e9a92fSRobert Love break; 139642e9a92fSRobert Love case LPORT_ST_LOGO: 139742e9a92fSRobert Love fc_lport_enter_logo(lport); 139842e9a92fSRobert Love break; 139942e9a92fSRobert Love } 140042e9a92fSRobert Love 140142e9a92fSRobert Love mutex_unlock(&lport->lp_mutex); 140242e9a92fSRobert Love } 140342e9a92fSRobert Love 140442e9a92fSRobert Love /** 140534f42a07SRobert Love * fc_lport_logo_resp() - Handle response to LOGO request 140642e9a92fSRobert Love * @sp: current sequence in LOGO exchange 140742e9a92fSRobert Love * @fp: response frame 140842e9a92fSRobert Love * @lp_arg: Fibre Channel lport port instance that sent the LOGO request 140942e9a92fSRobert Love * 141042e9a92fSRobert Love * Locking Note: This function will be called without the lport lock 141142e9a92fSRobert Love * held, but it will lock, call an _enter_* function or fc_lport_error 141242e9a92fSRobert Love * and then unlock the lport. 141342e9a92fSRobert Love */ 141411b56188SChris Leech void fc_lport_logo_resp(struct fc_seq *sp, struct fc_frame *fp, 141542e9a92fSRobert Love void *lp_arg) 141642e9a92fSRobert Love { 141742e9a92fSRobert Love struct fc_lport *lport = lp_arg; 141842e9a92fSRobert Love u8 op; 141942e9a92fSRobert Love 1420f657d299SJoe Eykholt FC_LPORT_DBG(lport, "Received a LOGO %s\n", fc_els_resp_type(fp)); 1421f657d299SJoe Eykholt 142242e9a92fSRobert Love if (fp == ERR_PTR(-FC_EX_CLOSED)) 142342e9a92fSRobert Love return; 142442e9a92fSRobert Love 142542e9a92fSRobert Love mutex_lock(&lport->lp_mutex); 142642e9a92fSRobert Love 142742e9a92fSRobert Love if (lport->state != LPORT_ST_LOGO) { 14287414705eSRobert Love FC_LPORT_DBG(lport, "Received a LOGO response, but in state " 14297414705eSRobert Love "%s\n", fc_lport_state(lport)); 143076f6804eSAbhijeet Joglekar if (IS_ERR(fp)) 143176f6804eSAbhijeet Joglekar goto err; 143242e9a92fSRobert Love goto out; 143342e9a92fSRobert Love } 143442e9a92fSRobert Love 143576f6804eSAbhijeet Joglekar if (IS_ERR(fp)) { 143676f6804eSAbhijeet Joglekar fc_lport_error(lport, fp); 143776f6804eSAbhijeet Joglekar goto err; 143876f6804eSAbhijeet Joglekar } 143976f6804eSAbhijeet Joglekar 144042e9a92fSRobert Love op = fc_frame_payload_op(fp); 144142e9a92fSRobert Love if (op == ELS_LS_ACC) 14421190d925SJoe Eykholt fc_lport_enter_disabled(lport); 144342e9a92fSRobert Love else 144442e9a92fSRobert Love fc_lport_error(lport, fp); 144542e9a92fSRobert Love 144642e9a92fSRobert Love out: 144742e9a92fSRobert Love fc_frame_free(fp); 144842e9a92fSRobert Love err: 144942e9a92fSRobert Love mutex_unlock(&lport->lp_mutex); 145042e9a92fSRobert Love } 145111b56188SChris Leech EXPORT_SYMBOL(fc_lport_logo_resp); 145242e9a92fSRobert Love 145342e9a92fSRobert Love /** 145434f42a07SRobert Love * fc_rport_enter_logo() - Logout of the fabric 145542e9a92fSRobert Love * @lport: Fibre Channel local port to be logged out 145642e9a92fSRobert Love * 145742e9a92fSRobert Love * Locking Note: The lport lock is expected to be held before calling 145842e9a92fSRobert Love * this routine. 145942e9a92fSRobert Love */ 146042e9a92fSRobert Love static void fc_lport_enter_logo(struct fc_lport *lport) 146142e9a92fSRobert Love { 146242e9a92fSRobert Love struct fc_frame *fp; 146342e9a92fSRobert Love struct fc_els_logo *logo; 146442e9a92fSRobert Love 14657414705eSRobert Love FC_LPORT_DBG(lport, "Entered LOGO state from %s state\n", 14667414705eSRobert Love fc_lport_state(lport)); 146742e9a92fSRobert Love 146842e9a92fSRobert Love fc_lport_state_enter(lport, LPORT_ST_LOGO); 14698faecddbSChris Leech fc_vports_linkchange(lport); 147042e9a92fSRobert Love 147142e9a92fSRobert Love fp = fc_frame_alloc(lport, sizeof(*logo)); 147242e9a92fSRobert Love if (!fp) { 147342e9a92fSRobert Love fc_lport_error(lport, fp); 147442e9a92fSRobert Love return; 147542e9a92fSRobert Love } 147642e9a92fSRobert Love 1477a46f327aSJoe Eykholt if (!lport->tt.elsct_send(lport, FC_FID_FLOGI, fp, ELS_LOGO, 1478a46f327aSJoe Eykholt fc_lport_logo_resp, lport, lport->e_d_tov)) 14798f550f93SChris Leech fc_lport_error(lport, NULL); 148042e9a92fSRobert Love } 148142e9a92fSRobert Love 148242e9a92fSRobert Love /** 148334f42a07SRobert Love * fc_lport_flogi_resp() - Handle response to FLOGI request 148442e9a92fSRobert Love * @sp: current sequence in FLOGI exchange 148542e9a92fSRobert Love * @fp: response frame 148642e9a92fSRobert Love * @lp_arg: Fibre Channel lport port instance that sent the FLOGI request 148742e9a92fSRobert Love * 148842e9a92fSRobert Love * Locking Note: This function will be called without the lport lock 148942e9a92fSRobert Love * held, but it will lock, call an _enter_* function or fc_lport_error 149042e9a92fSRobert Love * and then unlock the lport. 149142e9a92fSRobert Love */ 149211b56188SChris Leech void fc_lport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp, 149342e9a92fSRobert Love void *lp_arg) 149442e9a92fSRobert Love { 149542e9a92fSRobert Love struct fc_lport *lport = lp_arg; 149642e9a92fSRobert Love struct fc_frame_header *fh; 149742e9a92fSRobert Love struct fc_els_flogi *flp; 149842e9a92fSRobert Love u32 did; 149942e9a92fSRobert Love u16 csp_flags; 150042e9a92fSRobert Love unsigned int r_a_tov; 150142e9a92fSRobert Love unsigned int e_d_tov; 150242e9a92fSRobert Love u16 mfs; 150342e9a92fSRobert Love 1504f657d299SJoe Eykholt FC_LPORT_DBG(lport, "Received a FLOGI %s\n", fc_els_resp_type(fp)); 1505f657d299SJoe Eykholt 150642e9a92fSRobert Love if (fp == ERR_PTR(-FC_EX_CLOSED)) 150742e9a92fSRobert Love return; 150842e9a92fSRobert Love 150942e9a92fSRobert Love mutex_lock(&lport->lp_mutex); 151042e9a92fSRobert Love 151142e9a92fSRobert Love if (lport->state != LPORT_ST_FLOGI) { 15127414705eSRobert Love FC_LPORT_DBG(lport, "Received a FLOGI response, but in state " 15137414705eSRobert Love "%s\n", fc_lport_state(lport)); 151476f6804eSAbhijeet Joglekar if (IS_ERR(fp)) 151576f6804eSAbhijeet Joglekar goto err; 151642e9a92fSRobert Love goto out; 151742e9a92fSRobert Love } 151842e9a92fSRobert Love 151976f6804eSAbhijeet Joglekar if (IS_ERR(fp)) { 152076f6804eSAbhijeet Joglekar fc_lport_error(lport, fp); 152176f6804eSAbhijeet Joglekar goto err; 152276f6804eSAbhijeet Joglekar } 152376f6804eSAbhijeet Joglekar 152442e9a92fSRobert Love fh = fc_frame_header_get(fp); 152542e9a92fSRobert Love did = ntoh24(fh->fh_d_id); 152642e9a92fSRobert Love if (fc_frame_payload_op(fp) == ELS_LS_ACC && did != 0) { 152742e9a92fSRobert Love 15287414705eSRobert Love printk(KERN_INFO "libfc: Assigned FID (%6x) in FLOGI response\n", 15297414705eSRobert Love did); 153042e9a92fSRobert Love fc_host_port_id(lport->host) = did; 153142e9a92fSRobert Love 153242e9a92fSRobert Love flp = fc_frame_payload_get(fp, sizeof(*flp)); 153342e9a92fSRobert Love if (flp) { 153442e9a92fSRobert Love mfs = ntohs(flp->fl_csp.sp_bb_data) & 153542e9a92fSRobert Love FC_SP_BB_DATA_MASK; 153642e9a92fSRobert Love if (mfs >= FC_SP_MIN_MAX_PAYLOAD && 153742e9a92fSRobert Love mfs < lport->mfs) 153842e9a92fSRobert Love lport->mfs = mfs; 153942e9a92fSRobert Love csp_flags = ntohs(flp->fl_csp.sp_features); 154042e9a92fSRobert Love r_a_tov = ntohl(flp->fl_csp.sp_r_a_tov); 154142e9a92fSRobert Love e_d_tov = ntohl(flp->fl_csp.sp_e_d_tov); 154242e9a92fSRobert Love if (csp_flags & FC_SP_FT_EDTR) 154342e9a92fSRobert Love e_d_tov /= 1000000; 1544db36c06cSChris Leech 1545db36c06cSChris Leech lport->npiv_enabled = !!(csp_flags & FC_SP_FT_NPIV_ACC); 1546db36c06cSChris Leech 154742e9a92fSRobert Love if ((csp_flags & FC_SP_FT_FPORT) == 0) { 154842e9a92fSRobert Love if (e_d_tov > lport->e_d_tov) 154942e9a92fSRobert Love lport->e_d_tov = e_d_tov; 155042e9a92fSRobert Love lport->r_a_tov = 2 * e_d_tov; 15517414705eSRobert Love printk(KERN_INFO "libfc: Port (%6x) entered " 15527414705eSRobert Love "point to point mode\n", did); 155342e9a92fSRobert Love fc_lport_ptp_setup(lport, ntoh24(fh->fh_s_id), 155442e9a92fSRobert Love get_unaligned_be64( 155542e9a92fSRobert Love &flp->fl_wwpn), 155642e9a92fSRobert Love get_unaligned_be64( 155742e9a92fSRobert Love &flp->fl_wwnn)); 155842e9a92fSRobert Love } else { 155942e9a92fSRobert Love lport->e_d_tov = e_d_tov; 156042e9a92fSRobert Love lport->r_a_tov = r_a_tov; 156142e9a92fSRobert Love fc_host_fabric_name(lport->host) = 156242e9a92fSRobert Love get_unaligned_be64(&flp->fl_wwnn); 156342e9a92fSRobert Love fc_lport_enter_dns(lport); 156442e9a92fSRobert Love } 156542e9a92fSRobert Love } 156642e9a92fSRobert Love } else { 15677414705eSRobert Love FC_LPORT_DBG(lport, "Bad FLOGI response\n"); 156842e9a92fSRobert Love } 156942e9a92fSRobert Love 157042e9a92fSRobert Love out: 157142e9a92fSRobert Love fc_frame_free(fp); 157242e9a92fSRobert Love err: 157342e9a92fSRobert Love mutex_unlock(&lport->lp_mutex); 157442e9a92fSRobert Love } 157511b56188SChris Leech EXPORT_SYMBOL(fc_lport_flogi_resp); 157642e9a92fSRobert Love 157742e9a92fSRobert Love /** 157834f42a07SRobert Love * fc_rport_enter_flogi() - Send a FLOGI request to the fabric manager 157942e9a92fSRobert Love * @lport: Fibre Channel local port to be logged in to the fabric 158042e9a92fSRobert Love * 158142e9a92fSRobert Love * Locking Note: The lport lock is expected to be held before calling 158242e9a92fSRobert Love * this routine. 158342e9a92fSRobert Love */ 158442e9a92fSRobert Love void fc_lport_enter_flogi(struct fc_lport *lport) 158542e9a92fSRobert Love { 158642e9a92fSRobert Love struct fc_frame *fp; 158742e9a92fSRobert Love 15887414705eSRobert Love FC_LPORT_DBG(lport, "Entered FLOGI state from %s state\n", 15897414705eSRobert Love fc_lport_state(lport)); 159042e9a92fSRobert Love 159142e9a92fSRobert Love fc_lport_state_enter(lport, LPORT_ST_FLOGI); 159242e9a92fSRobert Love 159342e9a92fSRobert Love fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi)); 159442e9a92fSRobert Love if (!fp) 159542e9a92fSRobert Love return fc_lport_error(lport, fp); 159642e9a92fSRobert Love 1597db36c06cSChris Leech if (!lport->tt.elsct_send(lport, FC_FID_FLOGI, fp, 1598db36c06cSChris Leech lport->vport ? ELS_FDISC : ELS_FLOGI, 159942e9a92fSRobert Love fc_lport_flogi_resp, lport, lport->e_d_tov)) 16008f550f93SChris Leech fc_lport_error(lport, NULL); 160142e9a92fSRobert Love } 160242e9a92fSRobert Love 160342e9a92fSRobert Love /* Configure a fc_lport */ 160442e9a92fSRobert Love int fc_lport_config(struct fc_lport *lport) 160542e9a92fSRobert Love { 160642e9a92fSRobert Love INIT_DELAYED_WORK(&lport->retry_work, fc_lport_timeout); 160742e9a92fSRobert Love mutex_init(&lport->lp_mutex); 160842e9a92fSRobert Love 1609b1d9fd55SJoe Eykholt fc_lport_state_enter(lport, LPORT_ST_DISABLED); 161042e9a92fSRobert Love 161142e9a92fSRobert Love fc_lport_add_fc4_type(lport, FC_TYPE_FCP); 161242e9a92fSRobert Love fc_lport_add_fc4_type(lport, FC_TYPE_CT); 161342e9a92fSRobert Love 161442e9a92fSRobert Love return 0; 161542e9a92fSRobert Love } 161642e9a92fSRobert Love EXPORT_SYMBOL(fc_lport_config); 161742e9a92fSRobert Love 161842e9a92fSRobert Love int fc_lport_init(struct fc_lport *lport) 161942e9a92fSRobert Love { 162042e9a92fSRobert Love if (!lport->tt.lport_recv) 162142e9a92fSRobert Love lport->tt.lport_recv = fc_lport_recv_req; 162242e9a92fSRobert Love 162342e9a92fSRobert Love if (!lport->tt.lport_reset) 162442e9a92fSRobert Love lport->tt.lport_reset = fc_lport_reset; 162542e9a92fSRobert Love 162642e9a92fSRobert Love fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT; 162742e9a92fSRobert Love fc_host_node_name(lport->host) = lport->wwnn; 162842e9a92fSRobert Love fc_host_port_name(lport->host) = lport->wwpn; 162942e9a92fSRobert Love fc_host_supported_classes(lport->host) = FC_COS_CLASS3; 163042e9a92fSRobert Love memset(fc_host_supported_fc4s(lport->host), 0, 163142e9a92fSRobert Love sizeof(fc_host_supported_fc4s(lport->host))); 163242e9a92fSRobert Love fc_host_supported_fc4s(lport->host)[2] = 1; 163342e9a92fSRobert Love fc_host_supported_fc4s(lport->host)[7] = 1; 163442e9a92fSRobert Love 163542e9a92fSRobert Love /* This value is also unchanging */ 163642e9a92fSRobert Love memset(fc_host_active_fc4s(lport->host), 0, 163742e9a92fSRobert Love sizeof(fc_host_active_fc4s(lport->host))); 163842e9a92fSRobert Love fc_host_active_fc4s(lport->host)[2] = 1; 163942e9a92fSRobert Love fc_host_active_fc4s(lport->host)[7] = 1; 164042e9a92fSRobert Love fc_host_maxframe_size(lport->host) = lport->mfs; 164142e9a92fSRobert Love fc_host_supported_speeds(lport->host) = 0; 164242e9a92fSRobert Love if (lport->link_supported_speeds & FC_PORTSPEED_1GBIT) 164342e9a92fSRobert Love fc_host_supported_speeds(lport->host) |= FC_PORTSPEED_1GBIT; 164442e9a92fSRobert Love if (lport->link_supported_speeds & FC_PORTSPEED_10GBIT) 164542e9a92fSRobert Love fc_host_supported_speeds(lport->host) |= FC_PORTSPEED_10GBIT; 164642e9a92fSRobert Love 164742e9a92fSRobert Love return 0; 164842e9a92fSRobert Love } 164942e9a92fSRobert Love EXPORT_SYMBOL(fc_lport_init); 1650