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 *); 113c9866a54SChris Leech static void fc_lport_enter_rspn_id(struct fc_lport *); 11442e9a92fSRobert Love static void fc_lport_enter_rft_id(struct fc_lport *); 11542e9a92fSRobert Love static void fc_lport_enter_scr(struct fc_lport *); 11642e9a92fSRobert Love static void fc_lport_enter_ready(struct fc_lport *); 11742e9a92fSRobert Love static void fc_lport_enter_logo(struct fc_lport *); 11842e9a92fSRobert Love 11942e9a92fSRobert Love static const char *fc_lport_state_names[] = { 120b1d9fd55SJoe Eykholt [LPORT_ST_DISABLED] = "disabled", 12142e9a92fSRobert Love [LPORT_ST_FLOGI] = "FLOGI", 12242e9a92fSRobert Love [LPORT_ST_DNS] = "dNS", 123c9c7bd7aSChris Leech [LPORT_ST_RNN_ID] = "RNN_ID", 1245baa17c3SChris Leech [LPORT_ST_RSNN_NN] = "RSNN_NN", 125c9866a54SChris Leech [LPORT_ST_RSPN_ID] = "RSPN_ID", 12642e9a92fSRobert Love [LPORT_ST_RFT_ID] = "RFT_ID", 12742e9a92fSRobert Love [LPORT_ST_SCR] = "SCR", 12842e9a92fSRobert Love [LPORT_ST_READY] = "Ready", 12942e9a92fSRobert Love [LPORT_ST_LOGO] = "LOGO", 13042e9a92fSRobert Love [LPORT_ST_RESET] = "reset", 13142e9a92fSRobert Love }; 13242e9a92fSRobert Love 13342e9a92fSRobert Love static int fc_frame_drop(struct fc_lport *lport, struct fc_frame *fp) 13442e9a92fSRobert Love { 13542e9a92fSRobert Love fc_frame_free(fp); 13642e9a92fSRobert Love return 0; 13742e9a92fSRobert Love } 13842e9a92fSRobert Love 13942e9a92fSRobert Love /** 14034f42a07SRobert Love * fc_lport_rport_callback() - Event handler for rport events 14142e9a92fSRobert Love * @lport: The lport which is receiving the event 1429fb9d328SJoe Eykholt * @rdata: private remote port data 14342e9a92fSRobert Love * @event: The event that occured 14442e9a92fSRobert Love * 14542e9a92fSRobert Love * Locking Note: The rport lock should not be held when calling 14642e9a92fSRobert Love * this function. 14742e9a92fSRobert Love */ 14842e9a92fSRobert Love static void fc_lport_rport_callback(struct fc_lport *lport, 1499fb9d328SJoe Eykholt struct fc_rport_priv *rdata, 15042e9a92fSRobert Love enum fc_rport_event event) 15142e9a92fSRobert Love { 1527414705eSRobert Love FC_LPORT_DBG(lport, "Received a %d event for port (%6x)\n", event, 153f211fa51SJoe Eykholt rdata->ids.port_id); 15442e9a92fSRobert Love 155b5cbf083SJoe Eykholt mutex_lock(&lport->lp_mutex); 15642e9a92fSRobert Love switch (event) { 1574c0f62b5SJoe Eykholt case RPORT_EV_READY: 15842e9a92fSRobert Love if (lport->state == LPORT_ST_DNS) { 1599fb9d328SJoe Eykholt lport->dns_rp = rdata; 160c9c7bd7aSChris Leech fc_lport_enter_rnn_id(lport); 16142e9a92fSRobert Love } else { 1624c0f62b5SJoe Eykholt FC_LPORT_DBG(lport, "Received an READY event " 1637414705eSRobert Love "on port (%6x) for the directory " 16442e9a92fSRobert Love "server, but the lport is not " 16542e9a92fSRobert Love "in the DNS state, it's in the " 166f211fa51SJoe Eykholt "%d state", rdata->ids.port_id, 16742e9a92fSRobert Love lport->state); 1689fb9d328SJoe Eykholt lport->tt.rport_logoff(rdata); 16942e9a92fSRobert Love } 17042e9a92fSRobert Love break; 17142e9a92fSRobert Love case RPORT_EV_LOGO: 17242e9a92fSRobert Love case RPORT_EV_FAILED: 17342e9a92fSRobert Love case RPORT_EV_STOP: 17442e9a92fSRobert Love lport->dns_rp = NULL; 17542e9a92fSRobert Love break; 17642e9a92fSRobert Love case RPORT_EV_NONE: 17742e9a92fSRobert Love break; 17842e9a92fSRobert Love } 179b5cbf083SJoe Eykholt mutex_unlock(&lport->lp_mutex); 18042e9a92fSRobert Love } 18142e9a92fSRobert Love 18242e9a92fSRobert Love /** 18334f42a07SRobert Love * fc_lport_state() - Return a string which represents the lport's state 18442e9a92fSRobert Love * @lport: The lport whose state is to converted to a string 18542e9a92fSRobert Love */ 18642e9a92fSRobert Love static const char *fc_lport_state(struct fc_lport *lport) 18742e9a92fSRobert Love { 18842e9a92fSRobert Love const char *cp; 18942e9a92fSRobert Love 19042e9a92fSRobert Love cp = fc_lport_state_names[lport->state]; 19142e9a92fSRobert Love if (!cp) 19242e9a92fSRobert Love cp = "unknown"; 19342e9a92fSRobert Love return cp; 19442e9a92fSRobert Love } 19542e9a92fSRobert Love 19642e9a92fSRobert Love /** 19734f42a07SRobert Love * fc_lport_ptp_setup() - Create an rport for point-to-point mode 19842e9a92fSRobert Love * @lport: The lport to attach the ptp rport to 19942e9a92fSRobert Love * @fid: The FID of the ptp rport 20042e9a92fSRobert Love * @remote_wwpn: The WWPN of the ptp rport 20142e9a92fSRobert Love * @remote_wwnn: The WWNN of the ptp rport 20242e9a92fSRobert Love */ 20342e9a92fSRobert Love static void fc_lport_ptp_setup(struct fc_lport *lport, 20442e9a92fSRobert Love u32 remote_fid, u64 remote_wwpn, 20542e9a92fSRobert Love u64 remote_wwnn) 20642e9a92fSRobert Love { 20748f00902SJoe Eykholt mutex_lock(&lport->disc.disc_mutex); 20848f00902SJoe Eykholt if (lport->ptp_rp) 20942e9a92fSRobert Love lport->tt.rport_logoff(lport->ptp_rp); 2109737e6a7SRobert Love lport->ptp_rp = lport->tt.rport_create(lport, remote_fid); 2119737e6a7SRobert Love lport->ptp_rp->ids.port_name = remote_wwpn; 2129737e6a7SRobert Love lport->ptp_rp->ids.node_name = remote_wwnn; 21348f00902SJoe Eykholt mutex_unlock(&lport->disc.disc_mutex); 21442e9a92fSRobert Love 21542e9a92fSRobert Love lport->tt.rport_login(lport->ptp_rp); 21642e9a92fSRobert Love 21742e9a92fSRobert Love fc_lport_enter_ready(lport); 21842e9a92fSRobert Love } 21942e9a92fSRobert Love 22042e9a92fSRobert Love void fc_get_host_port_type(struct Scsi_Host *shost) 22142e9a92fSRobert Love { 22242e9a92fSRobert Love /* TODO - currently just NPORT */ 22342e9a92fSRobert Love fc_host_port_type(shost) = FC_PORTTYPE_NPORT; 22442e9a92fSRobert Love } 22542e9a92fSRobert Love EXPORT_SYMBOL(fc_get_host_port_type); 22642e9a92fSRobert Love 22742e9a92fSRobert Love void fc_get_host_port_state(struct Scsi_Host *shost) 22842e9a92fSRobert Love { 22942e9a92fSRobert Love struct fc_lport *lp = shost_priv(shost); 23042e9a92fSRobert Love 2318faecddbSChris Leech mutex_lock(&lp->lp_mutex); 2328faecddbSChris Leech if (!lp->link_up) 2338faecddbSChris Leech fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN; 23442e9a92fSRobert Love else 2358faecddbSChris Leech switch (lp->state) { 2368faecddbSChris Leech case LPORT_ST_READY: 2378faecddbSChris Leech fc_host_port_state(shost) = FC_PORTSTATE_ONLINE; 2388faecddbSChris Leech break; 2398faecddbSChris Leech default: 24042e9a92fSRobert Love fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; 24142e9a92fSRobert Love } 2428faecddbSChris Leech mutex_unlock(&lp->lp_mutex); 2438faecddbSChris Leech } 24442e9a92fSRobert Love EXPORT_SYMBOL(fc_get_host_port_state); 24542e9a92fSRobert Love 24642e9a92fSRobert Love void fc_get_host_speed(struct Scsi_Host *shost) 24742e9a92fSRobert Love { 24842e9a92fSRobert Love struct fc_lport *lport = shost_priv(shost); 24942e9a92fSRobert Love 25042e9a92fSRobert Love fc_host_speed(shost) = lport->link_speed; 25142e9a92fSRobert Love } 25242e9a92fSRobert Love EXPORT_SYMBOL(fc_get_host_speed); 25342e9a92fSRobert Love 25442e9a92fSRobert Love struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *shost) 25542e9a92fSRobert Love { 25642e9a92fSRobert Love struct fc_host_statistics *fcoe_stats; 25742e9a92fSRobert Love struct fc_lport *lp = shost_priv(shost); 25842e9a92fSRobert Love struct timespec v0, v1; 259582b45bcSRobert Love unsigned int cpu; 26042e9a92fSRobert Love 26142e9a92fSRobert Love fcoe_stats = &lp->host_stats; 26242e9a92fSRobert Love memset(fcoe_stats, 0, sizeof(struct fc_host_statistics)); 26342e9a92fSRobert Love 26442e9a92fSRobert Love jiffies_to_timespec(jiffies, &v0); 26542e9a92fSRobert Love jiffies_to_timespec(lp->boot_time, &v1); 26642e9a92fSRobert Love fcoe_stats->seconds_since_last_reset = (v0.tv_sec - v1.tv_sec); 26742e9a92fSRobert Love 268582b45bcSRobert Love for_each_possible_cpu(cpu) { 269582b45bcSRobert Love struct fcoe_dev_stats *stats; 270582b45bcSRobert Love 271582b45bcSRobert Love stats = per_cpu_ptr(lp->dev_stats, cpu); 272582b45bcSRobert Love 27342e9a92fSRobert Love fcoe_stats->tx_frames += stats->TxFrames; 27442e9a92fSRobert Love fcoe_stats->tx_words += stats->TxWords; 27542e9a92fSRobert Love fcoe_stats->rx_frames += stats->RxFrames; 27642e9a92fSRobert Love fcoe_stats->rx_words += stats->RxWords; 27742e9a92fSRobert Love fcoe_stats->error_frames += stats->ErrorFrames; 27842e9a92fSRobert Love fcoe_stats->invalid_crc_count += stats->InvalidCRCCount; 27942e9a92fSRobert Love fcoe_stats->fcp_input_requests += stats->InputRequests; 28042e9a92fSRobert Love fcoe_stats->fcp_output_requests += stats->OutputRequests; 28142e9a92fSRobert Love fcoe_stats->fcp_control_requests += stats->ControlRequests; 28242e9a92fSRobert Love fcoe_stats->fcp_input_megabytes += stats->InputMegabytes; 28342e9a92fSRobert Love fcoe_stats->fcp_output_megabytes += stats->OutputMegabytes; 28442e9a92fSRobert Love fcoe_stats->link_failure_count += stats->LinkFailureCount; 28542e9a92fSRobert Love } 28642e9a92fSRobert Love fcoe_stats->lip_count = -1; 28742e9a92fSRobert Love fcoe_stats->nos_count = -1; 28842e9a92fSRobert Love fcoe_stats->loss_of_sync_count = -1; 28942e9a92fSRobert Love fcoe_stats->loss_of_signal_count = -1; 29042e9a92fSRobert Love fcoe_stats->prim_seq_protocol_err_count = -1; 29142e9a92fSRobert Love fcoe_stats->dumped_frames = -1; 29242e9a92fSRobert Love return fcoe_stats; 29342e9a92fSRobert Love } 29442e9a92fSRobert Love EXPORT_SYMBOL(fc_get_host_stats); 29542e9a92fSRobert Love 29642e9a92fSRobert Love /* 29742e9a92fSRobert Love * Fill in FLOGI command for request. 29842e9a92fSRobert Love */ 29942e9a92fSRobert Love static void 30042e9a92fSRobert Love fc_lport_flogi_fill(struct fc_lport *lport, struct fc_els_flogi *flogi, 30142e9a92fSRobert Love unsigned int op) 30242e9a92fSRobert Love { 30342e9a92fSRobert Love struct fc_els_csp *sp; 30442e9a92fSRobert Love struct fc_els_cssp *cp; 30542e9a92fSRobert Love 30642e9a92fSRobert Love memset(flogi, 0, sizeof(*flogi)); 30742e9a92fSRobert Love flogi->fl_cmd = (u8) op; 30842e9a92fSRobert Love put_unaligned_be64(lport->wwpn, &flogi->fl_wwpn); 30942e9a92fSRobert Love put_unaligned_be64(lport->wwnn, &flogi->fl_wwnn); 31042e9a92fSRobert Love sp = &flogi->fl_csp; 31142e9a92fSRobert Love sp->sp_hi_ver = 0x20; 31242e9a92fSRobert Love sp->sp_lo_ver = 0x20; 31342e9a92fSRobert Love sp->sp_bb_cred = htons(10); /* this gets set by gateway */ 31442e9a92fSRobert Love sp->sp_bb_data = htons((u16) lport->mfs); 31542e9a92fSRobert Love cp = &flogi->fl_cssp[3 - 1]; /* class 3 parameters */ 31642e9a92fSRobert Love cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ); 31742e9a92fSRobert Love if (op != ELS_FLOGI) { 31842e9a92fSRobert Love sp->sp_features = htons(FC_SP_FT_CIRO); 31942e9a92fSRobert Love sp->sp_tot_seq = htons(255); /* seq. we accept */ 32042e9a92fSRobert Love sp->sp_rel_off = htons(0x1f); 32142e9a92fSRobert Love sp->sp_e_d_tov = htonl(lport->e_d_tov); 32242e9a92fSRobert Love 32342e9a92fSRobert Love cp->cp_rdfs = htons((u16) lport->mfs); 32442e9a92fSRobert Love cp->cp_con_seq = htons(255); 32542e9a92fSRobert Love cp->cp_open_seq = 1; 32642e9a92fSRobert Love } 32742e9a92fSRobert Love } 32842e9a92fSRobert Love 32942e9a92fSRobert Love /* 33042e9a92fSRobert Love * Add a supported FC-4 type. 33142e9a92fSRobert Love */ 33242e9a92fSRobert Love static void fc_lport_add_fc4_type(struct fc_lport *lport, enum fc_fh_type type) 33342e9a92fSRobert Love { 33442e9a92fSRobert Love __be32 *mp; 33542e9a92fSRobert Love 33642e9a92fSRobert Love mp = &lport->fcts.ff_type_map[type / FC_NS_BPW]; 33742e9a92fSRobert Love *mp = htonl(ntohl(*mp) | 1UL << (type % FC_NS_BPW)); 33842e9a92fSRobert Love } 33942e9a92fSRobert Love 34042e9a92fSRobert Love /** 34134f42a07SRobert Love * fc_lport_recv_rlir_req() - Handle received Registered Link Incident Report. 34242e9a92fSRobert Love * @lport: Fibre Channel local port recieving the RLIR 34342e9a92fSRobert Love * @sp: current sequence in the RLIR exchange 34442e9a92fSRobert Love * @fp: RLIR request frame 34542e9a92fSRobert Love * 3461b69bc06SJoe Eykholt * Locking Note: The lport lock is expected to be held before calling 34742e9a92fSRobert Love * this function. 34842e9a92fSRobert Love */ 34942e9a92fSRobert Love static void fc_lport_recv_rlir_req(struct fc_seq *sp, struct fc_frame *fp, 35042e9a92fSRobert Love struct fc_lport *lport) 35142e9a92fSRobert Love { 3527414705eSRobert Love FC_LPORT_DBG(lport, "Received RLIR request while in state %s\n", 35342e9a92fSRobert Love fc_lport_state(lport)); 35442e9a92fSRobert Love 35542e9a92fSRobert Love lport->tt.seq_els_rsp_send(sp, ELS_LS_ACC, NULL); 35642e9a92fSRobert Love fc_frame_free(fp); 35742e9a92fSRobert Love } 35842e9a92fSRobert Love 35942e9a92fSRobert Love /** 36034f42a07SRobert Love * fc_lport_recv_echo_req() - Handle received ECHO request 36142e9a92fSRobert Love * @lport: Fibre Channel local port recieving the ECHO 36242e9a92fSRobert Love * @sp: current sequence in the ECHO exchange 36342e9a92fSRobert Love * @fp: ECHO request frame 36442e9a92fSRobert Love * 3651b69bc06SJoe Eykholt * Locking Note: The lport lock is expected to be held before calling 36642e9a92fSRobert Love * this function. 36742e9a92fSRobert Love */ 36842e9a92fSRobert Love static void fc_lport_recv_echo_req(struct fc_seq *sp, struct fc_frame *in_fp, 36942e9a92fSRobert Love struct fc_lport *lport) 37042e9a92fSRobert Love { 37142e9a92fSRobert Love struct fc_frame *fp; 37242e9a92fSRobert Love struct fc_exch *ep = fc_seq_exch(sp); 37342e9a92fSRobert Love unsigned int len; 37442e9a92fSRobert Love void *pp; 37542e9a92fSRobert Love void *dp; 37642e9a92fSRobert Love u32 f_ctl; 37742e9a92fSRobert Love 3781b69bc06SJoe Eykholt FC_LPORT_DBG(lport, "Received ECHO request while in state %s\n", 37942e9a92fSRobert Love fc_lport_state(lport)); 38042e9a92fSRobert Love 38142e9a92fSRobert Love len = fr_len(in_fp) - sizeof(struct fc_frame_header); 38242e9a92fSRobert Love pp = fc_frame_payload_get(in_fp, len); 38342e9a92fSRobert Love 38442e9a92fSRobert Love if (len < sizeof(__be32)) 38542e9a92fSRobert Love len = sizeof(__be32); 38642e9a92fSRobert Love 38742e9a92fSRobert Love fp = fc_frame_alloc(lport, len); 38842e9a92fSRobert Love if (fp) { 38942e9a92fSRobert Love dp = fc_frame_payload_get(fp, len); 39042e9a92fSRobert Love memcpy(dp, pp, len); 3911b69bc06SJoe Eykholt *((__be32 *)dp) = htonl(ELS_LS_ACC << 24); 39242e9a92fSRobert Love sp = lport->tt.seq_start_next(sp); 39342e9a92fSRobert Love f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ | FC_FC_END_SEQ; 39442e9a92fSRobert Love fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid, 39542e9a92fSRobert Love FC_TYPE_ELS, f_ctl, 0); 39642e9a92fSRobert Love lport->tt.seq_send(lport, sp, fp); 39742e9a92fSRobert Love } 39842e9a92fSRobert Love fc_frame_free(in_fp); 39942e9a92fSRobert Love } 40042e9a92fSRobert Love 40142e9a92fSRobert Love /** 4021b69bc06SJoe Eykholt * fc_lport_recv_rnid_req() - Handle received Request Node ID data request 4031b69bc06SJoe Eykholt * @sp: The sequence in the RNID exchange 4041b69bc06SJoe Eykholt * @fp: The RNID request frame 4051b69bc06SJoe Eykholt * @lport: The local port recieving the RNID 40642e9a92fSRobert Love * 4071b69bc06SJoe Eykholt * Locking Note: The lport lock is expected to be held before calling 40842e9a92fSRobert Love * this function. 40942e9a92fSRobert Love */ 41042e9a92fSRobert Love static void fc_lport_recv_rnid_req(struct fc_seq *sp, struct fc_frame *in_fp, 41142e9a92fSRobert Love struct fc_lport *lport) 41242e9a92fSRobert Love { 41342e9a92fSRobert Love struct fc_frame *fp; 41442e9a92fSRobert Love struct fc_exch *ep = fc_seq_exch(sp); 41542e9a92fSRobert Love struct fc_els_rnid *req; 41642e9a92fSRobert Love struct { 41742e9a92fSRobert Love struct fc_els_rnid_resp rnid; 41842e9a92fSRobert Love struct fc_els_rnid_cid cid; 41942e9a92fSRobert Love struct fc_els_rnid_gen gen; 42042e9a92fSRobert Love } *rp; 42142e9a92fSRobert Love struct fc_seq_els_data rjt_data; 42242e9a92fSRobert Love u8 fmt; 42342e9a92fSRobert Love size_t len; 42442e9a92fSRobert Love u32 f_ctl; 42542e9a92fSRobert Love 4267414705eSRobert Love FC_LPORT_DBG(lport, "Received RNID request while in state %s\n", 42742e9a92fSRobert Love fc_lport_state(lport)); 42842e9a92fSRobert Love 42942e9a92fSRobert Love req = fc_frame_payload_get(in_fp, sizeof(*req)); 43042e9a92fSRobert Love if (!req) { 43142e9a92fSRobert Love rjt_data.fp = NULL; 43242e9a92fSRobert Love rjt_data.reason = ELS_RJT_LOGIC; 43342e9a92fSRobert Love rjt_data.explan = ELS_EXPL_NONE; 43442e9a92fSRobert Love lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data); 43542e9a92fSRobert Love } else { 43642e9a92fSRobert Love fmt = req->rnid_fmt; 43742e9a92fSRobert Love len = sizeof(*rp); 43842e9a92fSRobert Love if (fmt != ELS_RNIDF_GEN || 43942e9a92fSRobert Love ntohl(lport->rnid_gen.rnid_atype) == 0) { 44042e9a92fSRobert Love fmt = ELS_RNIDF_NONE; /* nothing to provide */ 44142e9a92fSRobert Love len -= sizeof(rp->gen); 44242e9a92fSRobert Love } 44342e9a92fSRobert Love fp = fc_frame_alloc(lport, len); 44442e9a92fSRobert Love if (fp) { 44542e9a92fSRobert Love rp = fc_frame_payload_get(fp, len); 44642e9a92fSRobert Love memset(rp, 0, len); 44742e9a92fSRobert Love rp->rnid.rnid_cmd = ELS_LS_ACC; 44842e9a92fSRobert Love rp->rnid.rnid_fmt = fmt; 44942e9a92fSRobert Love rp->rnid.rnid_cid_len = sizeof(rp->cid); 45042e9a92fSRobert Love rp->cid.rnid_wwpn = htonll(lport->wwpn); 45142e9a92fSRobert Love rp->cid.rnid_wwnn = htonll(lport->wwnn); 45242e9a92fSRobert Love if (fmt == ELS_RNIDF_GEN) { 45342e9a92fSRobert Love rp->rnid.rnid_sid_len = sizeof(rp->gen); 45442e9a92fSRobert Love memcpy(&rp->gen, &lport->rnid_gen, 45542e9a92fSRobert Love sizeof(rp->gen)); 45642e9a92fSRobert Love } 45742e9a92fSRobert Love sp = lport->tt.seq_start_next(sp); 45842e9a92fSRobert Love f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ; 45942e9a92fSRobert Love f_ctl |= FC_FC_END_SEQ | FC_FC_SEQ_INIT; 46042e9a92fSRobert Love fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid, 46142e9a92fSRobert Love FC_TYPE_ELS, f_ctl, 0); 46242e9a92fSRobert Love lport->tt.seq_send(lport, sp, fp); 46342e9a92fSRobert Love } 46442e9a92fSRobert Love } 46542e9a92fSRobert Love fc_frame_free(in_fp); 46642e9a92fSRobert Love } 46742e9a92fSRobert Love 46842e9a92fSRobert Love /** 46934f42a07SRobert Love * fc_lport_recv_logo_req() - Handle received fabric LOGO request 47042e9a92fSRobert Love * @lport: Fibre Channel local port recieving the LOGO 47142e9a92fSRobert Love * @sp: current sequence in the LOGO exchange 47242e9a92fSRobert Love * @fp: LOGO request frame 47342e9a92fSRobert Love * 47442e9a92fSRobert Love * Locking Note: The lport lock is exected to be held before calling 47542e9a92fSRobert Love * this function. 47642e9a92fSRobert Love */ 47742e9a92fSRobert Love static void fc_lport_recv_logo_req(struct fc_seq *sp, struct fc_frame *fp, 47842e9a92fSRobert Love struct fc_lport *lport) 47942e9a92fSRobert Love { 48042e9a92fSRobert Love lport->tt.seq_els_rsp_send(sp, ELS_LS_ACC, NULL); 48142e9a92fSRobert Love fc_lport_enter_reset(lport); 48242e9a92fSRobert Love fc_frame_free(fp); 48342e9a92fSRobert Love } 48442e9a92fSRobert Love 48542e9a92fSRobert Love /** 48634f42a07SRobert Love * fc_fabric_login() - Start the lport state machine 48742e9a92fSRobert Love * @lport: The lport that should log into the fabric 48842e9a92fSRobert Love * 48942e9a92fSRobert Love * Locking Note: This function should not be called 49042e9a92fSRobert Love * with the lport lock held. 49142e9a92fSRobert Love */ 49242e9a92fSRobert Love int fc_fabric_login(struct fc_lport *lport) 49342e9a92fSRobert Love { 49442e9a92fSRobert Love int rc = -1; 49542e9a92fSRobert Love 49642e9a92fSRobert Love mutex_lock(&lport->lp_mutex); 497b1d9fd55SJoe Eykholt if (lport->state == LPORT_ST_DISABLED) { 49842e9a92fSRobert Love fc_lport_enter_reset(lport); 49942e9a92fSRobert Love rc = 0; 50042e9a92fSRobert Love } 50142e9a92fSRobert Love mutex_unlock(&lport->lp_mutex); 50242e9a92fSRobert Love 50342e9a92fSRobert Love return rc; 50442e9a92fSRobert Love } 50542e9a92fSRobert Love EXPORT_SYMBOL(fc_fabric_login); 50642e9a92fSRobert Love 50742e9a92fSRobert Love /** 5088faecddbSChris Leech * __fc_linkup() - Handler for transport linkup events 5098faecddbSChris Leech * @lport: The lport whose link is up 5108faecddbSChris Leech * 5118faecddbSChris Leech * Locking: must be called with the lp_mutex held 5128faecddbSChris Leech */ 5138faecddbSChris Leech void __fc_linkup(struct fc_lport *lport) 5148faecddbSChris Leech { 5158faecddbSChris Leech if (!lport->link_up) { 5168faecddbSChris Leech lport->link_up = 1; 5178faecddbSChris Leech 5188faecddbSChris Leech if (lport->state == LPORT_ST_RESET) 5198faecddbSChris Leech fc_lport_enter_flogi(lport); 5208faecddbSChris Leech } 5218faecddbSChris Leech } 5228faecddbSChris Leech 5238faecddbSChris Leech /** 52434f42a07SRobert Love * fc_linkup() - Handler for transport linkup events 52542e9a92fSRobert Love * @lport: The lport whose link is up 52642e9a92fSRobert Love */ 52742e9a92fSRobert Love void fc_linkup(struct fc_lport *lport) 52842e9a92fSRobert Love { 5297414705eSRobert Love printk(KERN_INFO "libfc: Link up on port (%6x)\n", 53042e9a92fSRobert Love fc_host_port_id(lport->host)); 53142e9a92fSRobert Love 53242e9a92fSRobert Love mutex_lock(&lport->lp_mutex); 5338faecddbSChris Leech __fc_linkup(lport); 53442e9a92fSRobert Love mutex_unlock(&lport->lp_mutex); 53542e9a92fSRobert Love } 53642e9a92fSRobert Love EXPORT_SYMBOL(fc_linkup); 53742e9a92fSRobert Love 53842e9a92fSRobert Love /** 5398faecddbSChris Leech * __fc_linkdown() - Handler for transport linkdown events 5408faecddbSChris Leech * @lport: The lport whose link is down 5418faecddbSChris Leech * 5428faecddbSChris Leech * Locking: must be called with the lp_mutex held 5438faecddbSChris Leech */ 5448faecddbSChris Leech void __fc_linkdown(struct fc_lport *lport) 5458faecddbSChris Leech { 5468faecddbSChris Leech if (lport->link_up) { 5478faecddbSChris Leech lport->link_up = 0; 5488faecddbSChris Leech fc_lport_enter_reset(lport); 5498faecddbSChris Leech lport->tt.fcp_cleanup(lport); 5508faecddbSChris Leech } 5518faecddbSChris Leech } 5528faecddbSChris Leech 5538faecddbSChris Leech /** 55434f42a07SRobert Love * fc_linkdown() - Handler for transport linkdown events 55542e9a92fSRobert Love * @lport: The lport whose link is down 55642e9a92fSRobert Love */ 55742e9a92fSRobert Love void fc_linkdown(struct fc_lport *lport) 55842e9a92fSRobert Love { 5597414705eSRobert Love printk(KERN_INFO "libfc: Link down on port (%6x)\n", 56042e9a92fSRobert Love fc_host_port_id(lport->host)); 56142e9a92fSRobert Love 5628faecddbSChris Leech mutex_lock(&lport->lp_mutex); 5638faecddbSChris Leech __fc_linkdown(lport); 56442e9a92fSRobert Love mutex_unlock(&lport->lp_mutex); 56542e9a92fSRobert Love } 56642e9a92fSRobert Love EXPORT_SYMBOL(fc_linkdown); 56742e9a92fSRobert Love 56842e9a92fSRobert Love /** 56934f42a07SRobert Love * fc_fabric_logoff() - Logout of the fabric 57042e9a92fSRobert Love * @lport: fc_lport pointer to logoff the fabric 57142e9a92fSRobert Love * 57242e9a92fSRobert Love * Return value: 57342e9a92fSRobert Love * 0 for success, -1 for failure 57434f42a07SRobert Love */ 57542e9a92fSRobert Love int fc_fabric_logoff(struct fc_lport *lport) 57642e9a92fSRobert Love { 57742e9a92fSRobert Love lport->tt.disc_stop_final(lport); 57842e9a92fSRobert Love mutex_lock(&lport->lp_mutex); 579a0fd2e49SAbhijeet Joglekar if (lport->dns_rp) 580a0fd2e49SAbhijeet Joglekar lport->tt.rport_logoff(lport->dns_rp); 581a0fd2e49SAbhijeet Joglekar mutex_unlock(&lport->lp_mutex); 582a0fd2e49SAbhijeet Joglekar lport->tt.rport_flush_queue(); 583a0fd2e49SAbhijeet Joglekar mutex_lock(&lport->lp_mutex); 58442e9a92fSRobert Love fc_lport_enter_logo(lport); 58542e9a92fSRobert Love mutex_unlock(&lport->lp_mutex); 586f7db2c15SSteve Ma cancel_delayed_work_sync(&lport->retry_work); 58742e9a92fSRobert Love return 0; 58842e9a92fSRobert Love } 58942e9a92fSRobert Love EXPORT_SYMBOL(fc_fabric_logoff); 59042e9a92fSRobert Love 59142e9a92fSRobert Love /** 59234f42a07SRobert Love * fc_lport_destroy() - unregister a fc_lport 59342e9a92fSRobert Love * @lport: fc_lport pointer to unregister 59442e9a92fSRobert Love * 59542e9a92fSRobert Love * Return value: 59642e9a92fSRobert Love * None 59742e9a92fSRobert Love * Note: 59842e9a92fSRobert Love * exit routine for fc_lport instance 59942e9a92fSRobert Love * clean-up all the allocated memory 60042e9a92fSRobert Love * and free up other system resources. 60142e9a92fSRobert Love * 60234f42a07SRobert Love */ 60342e9a92fSRobert Love int fc_lport_destroy(struct fc_lport *lport) 60442e9a92fSRobert Love { 605bbf15669SAbhijeet Joglekar mutex_lock(&lport->lp_mutex); 606b1d9fd55SJoe Eykholt lport->state = LPORT_ST_DISABLED; 607bbf15669SAbhijeet Joglekar lport->link_up = 0; 60842e9a92fSRobert Love lport->tt.frame_send = fc_frame_drop; 609bbf15669SAbhijeet Joglekar mutex_unlock(&lport->lp_mutex); 610bbf15669SAbhijeet Joglekar 61142e9a92fSRobert Love lport->tt.fcp_abort_io(lport); 612e9ba8b42SJoe Eykholt lport->tt.disc_stop_final(lport); 6131f6ff364SAbhijeet Joglekar lport->tt.exch_mgr_reset(lport, 0, 0); 61442e9a92fSRobert Love return 0; 61542e9a92fSRobert Love } 61642e9a92fSRobert Love EXPORT_SYMBOL(fc_lport_destroy); 61742e9a92fSRobert Love 61842e9a92fSRobert Love /** 61934f42a07SRobert Love * fc_set_mfs() - sets up the mfs for the corresponding fc_lport 62042e9a92fSRobert Love * @lport: fc_lport pointer to unregister 62142e9a92fSRobert Love * @mfs: the new mfs for fc_lport 62242e9a92fSRobert Love * 62342e9a92fSRobert Love * Set mfs for the given fc_lport to the new mfs. 62442e9a92fSRobert Love * 62542e9a92fSRobert Love * Return: 0 for success 62634f42a07SRobert Love */ 62742e9a92fSRobert Love int fc_set_mfs(struct fc_lport *lport, u32 mfs) 62842e9a92fSRobert Love { 62942e9a92fSRobert Love unsigned int old_mfs; 63042e9a92fSRobert Love int rc = -EINVAL; 63142e9a92fSRobert Love 63242e9a92fSRobert Love mutex_lock(&lport->lp_mutex); 63342e9a92fSRobert Love 63442e9a92fSRobert Love old_mfs = lport->mfs; 63542e9a92fSRobert Love 63642e9a92fSRobert Love if (mfs >= FC_MIN_MAX_FRAME) { 63742e9a92fSRobert Love mfs &= ~3; 63842e9a92fSRobert Love if (mfs > FC_MAX_FRAME) 63942e9a92fSRobert Love mfs = FC_MAX_FRAME; 64042e9a92fSRobert Love mfs -= sizeof(struct fc_frame_header); 64142e9a92fSRobert Love lport->mfs = mfs; 64242e9a92fSRobert Love rc = 0; 64342e9a92fSRobert Love } 64442e9a92fSRobert Love 64542e9a92fSRobert Love if (!rc && mfs < old_mfs) 64642e9a92fSRobert Love fc_lport_enter_reset(lport); 64742e9a92fSRobert Love 64842e9a92fSRobert Love mutex_unlock(&lport->lp_mutex); 64942e9a92fSRobert Love 65042e9a92fSRobert Love return rc; 65142e9a92fSRobert Love } 65242e9a92fSRobert Love EXPORT_SYMBOL(fc_set_mfs); 65342e9a92fSRobert Love 65442e9a92fSRobert Love /** 65534f42a07SRobert Love * fc_lport_disc_callback() - Callback for discovery events 65642e9a92fSRobert Love * @lport: FC local port 65742e9a92fSRobert Love * @event: The discovery event 65842e9a92fSRobert Love */ 65942e9a92fSRobert Love void fc_lport_disc_callback(struct fc_lport *lport, enum fc_disc_event event) 66042e9a92fSRobert Love { 66142e9a92fSRobert Love switch (event) { 66242e9a92fSRobert Love case DISC_EV_SUCCESS: 6637414705eSRobert Love FC_LPORT_DBG(lport, "Discovery succeeded\n"); 66442e9a92fSRobert Love break; 66542e9a92fSRobert Love case DISC_EV_FAILED: 6667414705eSRobert Love printk(KERN_ERR "libfc: Discovery failed for port (%6x)\n", 66742e9a92fSRobert Love fc_host_port_id(lport->host)); 66842e9a92fSRobert Love mutex_lock(&lport->lp_mutex); 66942e9a92fSRobert Love fc_lport_enter_reset(lport); 67042e9a92fSRobert Love mutex_unlock(&lport->lp_mutex); 67142e9a92fSRobert Love break; 67242e9a92fSRobert Love case DISC_EV_NONE: 67342e9a92fSRobert Love WARN_ON(1); 67442e9a92fSRobert Love break; 67542e9a92fSRobert Love } 67642e9a92fSRobert Love } 67742e9a92fSRobert Love 67842e9a92fSRobert Love /** 67934f42a07SRobert Love * fc_rport_enter_ready() - Enter the ready state and start discovery 68042e9a92fSRobert Love * @lport: Fibre Channel local port that is ready 68142e9a92fSRobert Love * 68242e9a92fSRobert Love * Locking Note: The lport lock is expected to be held before calling 68342e9a92fSRobert Love * this routine. 68442e9a92fSRobert Love */ 68542e9a92fSRobert Love static void fc_lport_enter_ready(struct fc_lport *lport) 68642e9a92fSRobert Love { 6877414705eSRobert Love FC_LPORT_DBG(lport, "Entered READY from state %s\n", 6887414705eSRobert Love fc_lport_state(lport)); 68942e9a92fSRobert Love 69042e9a92fSRobert Love fc_lport_state_enter(lport, LPORT_ST_READY); 6918faecddbSChris Leech if (lport->vport) 6928faecddbSChris Leech fc_vport_set_state(lport->vport, FC_VPORT_ACTIVE); 6938faecddbSChris Leech fc_vports_linkchange(lport); 69442e9a92fSRobert Love 69529d898e9SJoe Eykholt if (!lport->ptp_rp) 69642e9a92fSRobert Love lport->tt.disc_start(fc_lport_disc_callback, lport); 69742e9a92fSRobert Love } 69842e9a92fSRobert Love 69942e9a92fSRobert Love /** 70034f42a07SRobert Love * fc_lport_recv_flogi_req() - Receive a FLOGI request 70142e9a92fSRobert Love * @sp_in: The sequence the FLOGI is on 70242e9a92fSRobert Love * @rx_fp: The frame the FLOGI is in 70342e9a92fSRobert Love * @lport: The lport that recieved the request 70442e9a92fSRobert Love * 70542e9a92fSRobert Love * A received FLOGI request indicates a point-to-point connection. 70642e9a92fSRobert Love * Accept it with the common service parameters indicating our N port. 70742e9a92fSRobert Love * Set up to do a PLOGI if we have the higher-number WWPN. 70842e9a92fSRobert Love * 7091b69bc06SJoe Eykholt * Locking Note: The lport lock is expected to be held before calling 71042e9a92fSRobert Love * this function. 71142e9a92fSRobert Love */ 71242e9a92fSRobert Love static void fc_lport_recv_flogi_req(struct fc_seq *sp_in, 71342e9a92fSRobert Love struct fc_frame *rx_fp, 71442e9a92fSRobert Love struct fc_lport *lport) 71542e9a92fSRobert Love { 71642e9a92fSRobert Love struct fc_frame *fp; 71742e9a92fSRobert Love struct fc_frame_header *fh; 71842e9a92fSRobert Love struct fc_seq *sp; 71942e9a92fSRobert Love struct fc_exch *ep; 72042e9a92fSRobert Love struct fc_els_flogi *flp; 72142e9a92fSRobert Love struct fc_els_flogi *new_flp; 72242e9a92fSRobert Love u64 remote_wwpn; 72342e9a92fSRobert Love u32 remote_fid; 72442e9a92fSRobert Love u32 local_fid; 72542e9a92fSRobert Love u32 f_ctl; 72642e9a92fSRobert Love 7277414705eSRobert Love FC_LPORT_DBG(lport, "Received FLOGI request while in state %s\n", 72842e9a92fSRobert Love fc_lport_state(lport)); 72942e9a92fSRobert Love 73042e9a92fSRobert Love fh = fc_frame_header_get(rx_fp); 73142e9a92fSRobert Love remote_fid = ntoh24(fh->fh_s_id); 73242e9a92fSRobert Love flp = fc_frame_payload_get(rx_fp, sizeof(*flp)); 73342e9a92fSRobert Love if (!flp) 73442e9a92fSRobert Love goto out; 73542e9a92fSRobert Love remote_wwpn = get_unaligned_be64(&flp->fl_wwpn); 73642e9a92fSRobert Love if (remote_wwpn == lport->wwpn) { 7377414705eSRobert Love printk(KERN_WARNING "libfc: Received FLOGI from port " 7387414705eSRobert Love "with same WWPN %llx\n", remote_wwpn); 73942e9a92fSRobert Love goto out; 74042e9a92fSRobert Love } 7417414705eSRobert Love FC_LPORT_DBG(lport, "FLOGI from port WWPN %llx\n", remote_wwpn); 74242e9a92fSRobert Love 74342e9a92fSRobert Love /* 74442e9a92fSRobert Love * XXX what is the right thing to do for FIDs? 74542e9a92fSRobert Love * The originator might expect our S_ID to be 0xfffffe. 74642e9a92fSRobert Love * But if so, both of us could end up with the same FID. 74742e9a92fSRobert Love */ 74842e9a92fSRobert Love local_fid = FC_LOCAL_PTP_FID_LO; 74942e9a92fSRobert Love if (remote_wwpn < lport->wwpn) { 75042e9a92fSRobert Love local_fid = FC_LOCAL_PTP_FID_HI; 75142e9a92fSRobert Love if (!remote_fid || remote_fid == local_fid) 75242e9a92fSRobert Love remote_fid = FC_LOCAL_PTP_FID_LO; 75342e9a92fSRobert Love } else if (!remote_fid) { 75442e9a92fSRobert Love remote_fid = FC_LOCAL_PTP_FID_HI; 75542e9a92fSRobert Love } 75642e9a92fSRobert Love 75742e9a92fSRobert Love fc_host_port_id(lport->host) = local_fid; 75842e9a92fSRobert Love 75942e9a92fSRobert Love fp = fc_frame_alloc(lport, sizeof(*flp)); 76042e9a92fSRobert Love if (fp) { 76142e9a92fSRobert Love sp = lport->tt.seq_start_next(fr_seq(rx_fp)); 76242e9a92fSRobert Love new_flp = fc_frame_payload_get(fp, sizeof(*flp)); 76342e9a92fSRobert Love fc_lport_flogi_fill(lport, new_flp, ELS_FLOGI); 76442e9a92fSRobert Love new_flp->fl_cmd = (u8) ELS_LS_ACC; 76542e9a92fSRobert Love 76642e9a92fSRobert Love /* 76742e9a92fSRobert Love * Send the response. If this fails, the originator should 76842e9a92fSRobert Love * repeat the sequence. 76942e9a92fSRobert Love */ 77042e9a92fSRobert Love f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ | FC_FC_END_SEQ; 77142e9a92fSRobert Love ep = fc_seq_exch(sp); 77242e9a92fSRobert Love fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid, 77342e9a92fSRobert Love FC_TYPE_ELS, f_ctl, 0); 77442e9a92fSRobert Love lport->tt.seq_send(lport, sp, fp); 77542e9a92fSRobert Love 77642e9a92fSRobert Love } else { 77742e9a92fSRobert Love fc_lport_error(lport, fp); 77842e9a92fSRobert Love } 77942e9a92fSRobert Love fc_lport_ptp_setup(lport, remote_fid, remote_wwpn, 78042e9a92fSRobert Love get_unaligned_be64(&flp->fl_wwnn)); 78142e9a92fSRobert Love 78242e9a92fSRobert Love out: 78342e9a92fSRobert Love sp = fr_seq(rx_fp); 78442e9a92fSRobert Love fc_frame_free(rx_fp); 78542e9a92fSRobert Love } 78642e9a92fSRobert Love 78742e9a92fSRobert Love /** 78834f42a07SRobert Love * fc_lport_recv_req() - The generic lport request handler 78942e9a92fSRobert Love * @lport: The lport that received the request 79042e9a92fSRobert Love * @sp: The sequence the request is on 79142e9a92fSRobert Love * @fp: The frame the request is in 79242e9a92fSRobert Love * 79342e9a92fSRobert Love * This function will see if the lport handles the request or 79442e9a92fSRobert Love * if an rport should handle the request. 79542e9a92fSRobert Love * 79642e9a92fSRobert Love * Locking Note: This function should not be called with the lport 79742e9a92fSRobert Love * lock held becuase it will grab the lock. 79842e9a92fSRobert Love */ 79942e9a92fSRobert Love static void fc_lport_recv_req(struct fc_lport *lport, struct fc_seq *sp, 80042e9a92fSRobert Love struct fc_frame *fp) 80142e9a92fSRobert Love { 80242e9a92fSRobert Love struct fc_frame_header *fh = fc_frame_header_get(fp); 80342e9a92fSRobert Love void (*recv) (struct fc_seq *, struct fc_frame *, struct fc_lport *); 80442e9a92fSRobert Love 80542e9a92fSRobert Love mutex_lock(&lport->lp_mutex); 80642e9a92fSRobert Love 80742e9a92fSRobert Love /* 80842e9a92fSRobert Love * Handle special ELS cases like FLOGI, LOGO, and 80942e9a92fSRobert Love * RSCN here. These don't require a session. 81042e9a92fSRobert Love * Even if we had a session, it might not be ready. 81142e9a92fSRobert Love */ 812e9ba8b42SJoe Eykholt if (!lport->link_up) 813e9ba8b42SJoe Eykholt fc_frame_free(fp); 814e9ba8b42SJoe Eykholt else if (fh->fh_type == FC_TYPE_ELS && 815e9ba8b42SJoe Eykholt fh->fh_r_ctl == FC_RCTL_ELS_REQ) { 81642e9a92fSRobert Love /* 81742e9a92fSRobert Love * Check opcode. 81842e9a92fSRobert Love */ 819131203a1SJoe Eykholt recv = lport->tt.rport_recv_req; 82042e9a92fSRobert Love switch (fc_frame_payload_op(fp)) { 82142e9a92fSRobert Love case ELS_FLOGI: 82242e9a92fSRobert Love recv = fc_lport_recv_flogi_req; 82342e9a92fSRobert Love break; 82442e9a92fSRobert Love case ELS_LOGO: 82542e9a92fSRobert Love fh = fc_frame_header_get(fp); 82642e9a92fSRobert Love if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI) 82742e9a92fSRobert Love recv = fc_lport_recv_logo_req; 82842e9a92fSRobert Love break; 82942e9a92fSRobert Love case ELS_RSCN: 83042e9a92fSRobert Love recv = lport->tt.disc_recv_req; 83142e9a92fSRobert Love break; 83242e9a92fSRobert Love case ELS_ECHO: 83342e9a92fSRobert Love recv = fc_lport_recv_echo_req; 83442e9a92fSRobert Love break; 83542e9a92fSRobert Love case ELS_RLIR: 83642e9a92fSRobert Love recv = fc_lport_recv_rlir_req; 83742e9a92fSRobert Love break; 83842e9a92fSRobert Love case ELS_RNID: 83942e9a92fSRobert Love recv = fc_lport_recv_rnid_req; 84042e9a92fSRobert Love break; 84142e9a92fSRobert Love } 84242e9a92fSRobert Love 84342e9a92fSRobert Love recv(sp, fp, lport); 84442e9a92fSRobert Love } else { 8457414705eSRobert Love FC_LPORT_DBG(lport, "dropping invalid frame (eof %x)\n", 8467414705eSRobert Love fr_eof(fp)); 84742e9a92fSRobert Love fc_frame_free(fp); 84842e9a92fSRobert Love } 84942e9a92fSRobert Love mutex_unlock(&lport->lp_mutex); 85042e9a92fSRobert Love 85142e9a92fSRobert Love /* 85242e9a92fSRobert Love * The common exch_done for all request may not be good 85342e9a92fSRobert Love * if any request requires longer hold on exhange. XXX 85442e9a92fSRobert Love */ 85542e9a92fSRobert Love lport->tt.exch_done(sp); 85642e9a92fSRobert Love } 85742e9a92fSRobert Love 85842e9a92fSRobert Love /** 85934f42a07SRobert Love * fc_lport_reset() - Reset an lport 86042e9a92fSRobert Love * @lport: The lport which should be reset 86142e9a92fSRobert Love * 86242e9a92fSRobert Love * Locking Note: This functions should not be called with the 86342e9a92fSRobert Love * lport lock held. 86442e9a92fSRobert Love */ 86542e9a92fSRobert Love int fc_lport_reset(struct fc_lport *lport) 86642e9a92fSRobert Love { 867f7db2c15SSteve Ma cancel_delayed_work_sync(&lport->retry_work); 86842e9a92fSRobert Love mutex_lock(&lport->lp_mutex); 86942e9a92fSRobert Love fc_lport_enter_reset(lport); 87042e9a92fSRobert Love mutex_unlock(&lport->lp_mutex); 87142e9a92fSRobert Love return 0; 87242e9a92fSRobert Love } 87342e9a92fSRobert Love EXPORT_SYMBOL(fc_lport_reset); 87442e9a92fSRobert Love 87542e9a92fSRobert Love /** 8761190d925SJoe Eykholt * fc_lport_reset_locked() - Reset the local port 87742e9a92fSRobert Love * @lport: Fibre Channel local port to be reset 87842e9a92fSRobert Love * 87942e9a92fSRobert Love * Locking Note: The lport lock is expected to be held before calling 88042e9a92fSRobert Love * this routine. 88142e9a92fSRobert Love */ 8821190d925SJoe Eykholt static void fc_lport_reset_locked(struct fc_lport *lport) 88342e9a92fSRobert Love { 88442e9a92fSRobert Love if (lport->dns_rp) 88542e9a92fSRobert Love lport->tt.rport_logoff(lport->dns_rp); 88642e9a92fSRobert Love 88742e9a92fSRobert Love lport->ptp_rp = NULL; 88842e9a92fSRobert Love 88942e9a92fSRobert Love lport->tt.disc_stop(lport); 89042e9a92fSRobert Love 8911f6ff364SAbhijeet Joglekar lport->tt.exch_mgr_reset(lport, 0, 0); 89242e9a92fSRobert Love fc_host_fabric_name(lport->host) = 0; 89342e9a92fSRobert Love fc_host_port_id(lport->host) = 0; 8941190d925SJoe Eykholt } 89542e9a92fSRobert Love 8961190d925SJoe Eykholt /** 8971190d925SJoe Eykholt * fc_lport_enter_reset() - Reset the local port 8981190d925SJoe Eykholt * @lport: Fibre Channel local port to be reset 8991190d925SJoe Eykholt * 9001190d925SJoe Eykholt * Locking Note: The lport lock is expected to be held before calling 9011190d925SJoe Eykholt * this routine. 9021190d925SJoe Eykholt */ 9031190d925SJoe Eykholt static void fc_lport_enter_reset(struct fc_lport *lport) 9041190d925SJoe Eykholt { 9051190d925SJoe Eykholt FC_LPORT_DBG(lport, "Entered RESET state from %s state\n", 9061190d925SJoe Eykholt fc_lport_state(lport)); 9071190d925SJoe Eykholt 9088faecddbSChris Leech if (lport->vport) { 9098faecddbSChris Leech if (lport->link_up) 9108faecddbSChris Leech fc_vport_set_state(lport->vport, FC_VPORT_INITIALIZING); 9118faecddbSChris Leech else 9128faecddbSChris Leech fc_vport_set_state(lport->vport, FC_VPORT_LINKDOWN); 9138faecddbSChris Leech } 9141190d925SJoe Eykholt fc_lport_state_enter(lport, LPORT_ST_RESET); 9158faecddbSChris Leech fc_vports_linkchange(lport); 9161190d925SJoe Eykholt fc_lport_reset_locked(lport); 917bc0e17f6SVasu Dev if (lport->link_up) 91842e9a92fSRobert Love fc_lport_enter_flogi(lport); 91942e9a92fSRobert Love } 92042e9a92fSRobert Love 92142e9a92fSRobert Love /** 9221190d925SJoe Eykholt * fc_lport_enter_disabled() - disable the local port 9231190d925SJoe Eykholt * @lport: Fibre Channel local port to be reset 9241190d925SJoe Eykholt * 9251190d925SJoe Eykholt * Locking Note: The lport lock is expected to be held before calling 9261190d925SJoe Eykholt * this routine. 9271190d925SJoe Eykholt */ 9281190d925SJoe Eykholt static void fc_lport_enter_disabled(struct fc_lport *lport) 9291190d925SJoe Eykholt { 9301190d925SJoe Eykholt FC_LPORT_DBG(lport, "Entered disabled state from %s state\n", 9311190d925SJoe Eykholt fc_lport_state(lport)); 9321190d925SJoe Eykholt 9331190d925SJoe Eykholt fc_lport_state_enter(lport, LPORT_ST_DISABLED); 9348faecddbSChris Leech fc_vports_linkchange(lport); 9351190d925SJoe Eykholt fc_lport_reset_locked(lport); 9361190d925SJoe Eykholt } 9371190d925SJoe Eykholt 9381190d925SJoe Eykholt /** 93934f42a07SRobert Love * fc_lport_error() - Handler for any errors 94042e9a92fSRobert Love * @lport: The fc_lport object 94142e9a92fSRobert Love * @fp: The frame pointer 94242e9a92fSRobert Love * 94342e9a92fSRobert Love * If the error was caused by a resource allocation failure 94442e9a92fSRobert Love * then wait for half a second and retry, otherwise retry 94542e9a92fSRobert Love * after the e_d_tov time. 94642e9a92fSRobert Love */ 94742e9a92fSRobert Love static void fc_lport_error(struct fc_lport *lport, struct fc_frame *fp) 94842e9a92fSRobert Love { 94942e9a92fSRobert Love unsigned long delay = 0; 9507414705eSRobert Love FC_LPORT_DBG(lport, "Error %ld in state %s, retries %d\n", 95142e9a92fSRobert Love PTR_ERR(fp), fc_lport_state(lport), 95242e9a92fSRobert Love lport->retry_count); 95342e9a92fSRobert Love 95442e9a92fSRobert Love if (!fp || PTR_ERR(fp) == -FC_EX_TIMEOUT) { 95542e9a92fSRobert Love /* 95642e9a92fSRobert Love * Memory allocation failure, or the exchange timed out. 95742e9a92fSRobert Love * Retry after delay 95842e9a92fSRobert Love */ 95942e9a92fSRobert Love if (lport->retry_count < lport->max_retry_count) { 96042e9a92fSRobert Love lport->retry_count++; 96142e9a92fSRobert Love if (!fp) 96242e9a92fSRobert Love delay = msecs_to_jiffies(500); 96342e9a92fSRobert Love else 96442e9a92fSRobert Love delay = msecs_to_jiffies(lport->e_d_tov); 96542e9a92fSRobert Love 96642e9a92fSRobert Love schedule_delayed_work(&lport->retry_work, delay); 96742e9a92fSRobert Love } else { 96842e9a92fSRobert Love switch (lport->state) { 969b1d9fd55SJoe Eykholt case LPORT_ST_DISABLED: 97042e9a92fSRobert Love case LPORT_ST_READY: 97142e9a92fSRobert Love case LPORT_ST_RESET: 972c9c7bd7aSChris Leech case LPORT_ST_RNN_ID: 9735baa17c3SChris Leech case LPORT_ST_RSNN_NN: 974c9866a54SChris Leech case LPORT_ST_RSPN_ID: 97542e9a92fSRobert Love case LPORT_ST_RFT_ID: 97642e9a92fSRobert Love case LPORT_ST_SCR: 97742e9a92fSRobert Love case LPORT_ST_DNS: 97842e9a92fSRobert Love case LPORT_ST_FLOGI: 97942e9a92fSRobert Love case LPORT_ST_LOGO: 98042e9a92fSRobert Love fc_lport_enter_reset(lport); 98142e9a92fSRobert Love break; 98242e9a92fSRobert Love } 98342e9a92fSRobert Love } 98442e9a92fSRobert Love } 98542e9a92fSRobert Love } 98642e9a92fSRobert Love 98742e9a92fSRobert Love /** 9887cccc157SChris Leech * fc_lport_ns_resp() - Handle response to a name server 9897cccc157SChris Leech * registration exchange 9907cccc157SChris Leech * @sp: current sequence in exchange 99142e9a92fSRobert Love * @fp: response frame 99242e9a92fSRobert Love * @lp_arg: Fibre Channel host port instance 99342e9a92fSRobert Love * 99442e9a92fSRobert Love * Locking Note: This function will be called without the lport lock 99542e9a92fSRobert Love * held, but it will lock, call an _enter_* function or fc_lport_error 99642e9a92fSRobert Love * and then unlock the lport. 99742e9a92fSRobert Love */ 9987cccc157SChris Leech static void fc_lport_ns_resp(struct fc_seq *sp, struct fc_frame *fp, 99942e9a92fSRobert Love void *lp_arg) 100042e9a92fSRobert Love { 100142e9a92fSRobert Love struct fc_lport *lport = lp_arg; 100242e9a92fSRobert Love struct fc_frame_header *fh; 100342e9a92fSRobert Love struct fc_ct_hdr *ct; 100442e9a92fSRobert Love 10057cccc157SChris Leech FC_LPORT_DBG(lport, "Received a ns %s\n", fc_els_resp_type(fp)); 1006f657d299SJoe Eykholt 100742e9a92fSRobert Love if (fp == ERR_PTR(-FC_EX_CLOSED)) 100842e9a92fSRobert Love return; 100942e9a92fSRobert Love 101042e9a92fSRobert Love mutex_lock(&lport->lp_mutex); 101142e9a92fSRobert Love 10127cccc157SChris Leech if (lport->state < LPORT_ST_RNN_ID || lport->state > LPORT_ST_RFT_ID) { 10137cccc157SChris Leech FC_LPORT_DBG(lport, "Received a name server response, " 10147cccc157SChris Leech "but in state %s\n", fc_lport_state(lport)); 101576f6804eSAbhijeet Joglekar if (IS_ERR(fp)) 101676f6804eSAbhijeet Joglekar goto err; 101742e9a92fSRobert Love goto out; 101842e9a92fSRobert Love } 101942e9a92fSRobert Love 102076f6804eSAbhijeet Joglekar if (IS_ERR(fp)) { 102176f6804eSAbhijeet Joglekar fc_lport_error(lport, fp); 102276f6804eSAbhijeet Joglekar goto err; 102376f6804eSAbhijeet Joglekar } 102476f6804eSAbhijeet Joglekar 102542e9a92fSRobert Love fh = fc_frame_header_get(fp); 102642e9a92fSRobert Love ct = fc_frame_payload_get(fp, sizeof(*ct)); 102742e9a92fSRobert Love 102842e9a92fSRobert Love if (fh && ct && fh->fh_type == FC_TYPE_CT && 102942e9a92fSRobert Love ct->ct_fs_type == FC_FST_DIR && 103042e9a92fSRobert Love ct->ct_fs_subtype == FC_NS_SUBTYPE && 103142e9a92fSRobert Love ntohs(ct->ct_cmd) == FC_FS_ACC) 10327cccc157SChris Leech switch (lport->state) { 10337cccc157SChris Leech case LPORT_ST_RNN_ID: 10345baa17c3SChris Leech fc_lport_enter_rsnn_nn(lport); 10357cccc157SChris Leech break; 10367cccc157SChris Leech case LPORT_ST_RSNN_NN: 10377cccc157SChris Leech fc_lport_enter_rspn_id(lport); 10387cccc157SChris Leech break; 10397cccc157SChris Leech case LPORT_ST_RSPN_ID: 1040c9c7bd7aSChris Leech fc_lport_enter_rft_id(lport); 10417cccc157SChris Leech break; 10427cccc157SChris Leech case LPORT_ST_RFT_ID: 10437cccc157SChris Leech fc_lport_enter_scr(lport); 10447cccc157SChris Leech break; 10457cccc157SChris Leech default: 10467cccc157SChris Leech /* should have already been caught by state checks */ 10477cccc157SChris Leech break; 10487cccc157SChris Leech } 1049c9c7bd7aSChris Leech else 1050c9c7bd7aSChris Leech fc_lport_error(lport, fp); 1051c9c7bd7aSChris Leech out: 1052c9c7bd7aSChris Leech fc_frame_free(fp); 1053c9c7bd7aSChris Leech err: 1054c9c7bd7aSChris Leech mutex_unlock(&lport->lp_mutex); 1055c9c7bd7aSChris Leech } 1056c9c7bd7aSChris Leech 1057c9c7bd7aSChris Leech /** 105834f42a07SRobert Love * fc_lport_scr_resp() - Handle response to State Change Register (SCR) request 105942e9a92fSRobert Love * @sp: current sequence in SCR exchange 106042e9a92fSRobert Love * @fp: response frame 106142e9a92fSRobert Love * @lp_arg: Fibre Channel lport port instance that sent the registration request 106242e9a92fSRobert Love * 106342e9a92fSRobert Love * Locking Note: This function will be called without the lport lock 106442e9a92fSRobert Love * held, but it will lock, call an _enter_* function or fc_lport_error 106542e9a92fSRobert Love * and then unlock the lport. 106642e9a92fSRobert Love */ 106742e9a92fSRobert Love static void fc_lport_scr_resp(struct fc_seq *sp, struct fc_frame *fp, 106842e9a92fSRobert Love void *lp_arg) 106942e9a92fSRobert Love { 107042e9a92fSRobert Love struct fc_lport *lport = lp_arg; 107142e9a92fSRobert Love u8 op; 107242e9a92fSRobert Love 1073f657d299SJoe Eykholt FC_LPORT_DBG(lport, "Received a SCR %s\n", fc_els_resp_type(fp)); 1074f657d299SJoe Eykholt 107542e9a92fSRobert Love if (fp == ERR_PTR(-FC_EX_CLOSED)) 107642e9a92fSRobert Love return; 107742e9a92fSRobert Love 107842e9a92fSRobert Love mutex_lock(&lport->lp_mutex); 107942e9a92fSRobert Love 108042e9a92fSRobert Love if (lport->state != LPORT_ST_SCR) { 10817414705eSRobert Love FC_LPORT_DBG(lport, "Received a SCR response, but in state " 10827414705eSRobert Love "%s\n", fc_lport_state(lport)); 108376f6804eSAbhijeet Joglekar if (IS_ERR(fp)) 108476f6804eSAbhijeet Joglekar goto err; 108542e9a92fSRobert Love goto out; 108642e9a92fSRobert Love } 108742e9a92fSRobert Love 108876f6804eSAbhijeet Joglekar if (IS_ERR(fp)) { 108976f6804eSAbhijeet Joglekar fc_lport_error(lport, fp); 109076f6804eSAbhijeet Joglekar goto err; 109176f6804eSAbhijeet Joglekar } 109276f6804eSAbhijeet Joglekar 109342e9a92fSRobert Love op = fc_frame_payload_op(fp); 109442e9a92fSRobert Love if (op == ELS_LS_ACC) 109542e9a92fSRobert Love fc_lport_enter_ready(lport); 109642e9a92fSRobert Love else 109742e9a92fSRobert Love fc_lport_error(lport, fp); 109842e9a92fSRobert Love 109942e9a92fSRobert Love out: 110042e9a92fSRobert Love fc_frame_free(fp); 110142e9a92fSRobert Love err: 110242e9a92fSRobert Love mutex_unlock(&lport->lp_mutex); 110342e9a92fSRobert Love } 110442e9a92fSRobert Love 110542e9a92fSRobert Love /** 110634f42a07SRobert Love * fc_lport_enter_scr() - Send a State Change Register (SCR) request 110742e9a92fSRobert Love * @lport: Fibre Channel local port to register for state changes 110842e9a92fSRobert Love * 110942e9a92fSRobert Love * Locking Note: The lport lock is expected to be held before calling 111042e9a92fSRobert Love * this routine. 111142e9a92fSRobert Love */ 111242e9a92fSRobert Love static void fc_lport_enter_scr(struct fc_lport *lport) 111342e9a92fSRobert Love { 111442e9a92fSRobert Love struct fc_frame *fp; 111542e9a92fSRobert Love 11167414705eSRobert Love FC_LPORT_DBG(lport, "Entered SCR state from %s state\n", 11177414705eSRobert Love fc_lport_state(lport)); 111842e9a92fSRobert Love 111942e9a92fSRobert Love fc_lport_state_enter(lport, LPORT_ST_SCR); 112042e9a92fSRobert Love 112142e9a92fSRobert Love fp = fc_frame_alloc(lport, sizeof(struct fc_els_scr)); 112242e9a92fSRobert Love if (!fp) { 112342e9a92fSRobert Love fc_lport_error(lport, fp); 112442e9a92fSRobert Love return; 112542e9a92fSRobert Love } 112642e9a92fSRobert Love 1127a46f327aSJoe Eykholt if (!lport->tt.elsct_send(lport, FC_FID_FCTRL, fp, ELS_SCR, 112842e9a92fSRobert Love fc_lport_scr_resp, lport, lport->e_d_tov)) 11298f550f93SChris Leech fc_lport_error(lport, NULL); 113042e9a92fSRobert Love } 113142e9a92fSRobert Love 113242e9a92fSRobert Love /** 113334f42a07SRobert Love * fc_lport_enter_rft_id() - Register FC4-types with the name server 113442e9a92fSRobert Love * @lport: Fibre Channel local port to register 113542e9a92fSRobert Love * 113642e9a92fSRobert Love * Locking Note: The lport lock is expected to be held before calling 113742e9a92fSRobert Love * this routine. 113842e9a92fSRobert Love */ 113942e9a92fSRobert Love static void fc_lport_enter_rft_id(struct fc_lport *lport) 114042e9a92fSRobert Love { 114142e9a92fSRobert Love struct fc_frame *fp; 114242e9a92fSRobert Love struct fc_ns_fts *lps; 114342e9a92fSRobert Love int i; 114442e9a92fSRobert Love 11457414705eSRobert Love FC_LPORT_DBG(lport, "Entered RFT_ID state from %s state\n", 11467414705eSRobert Love fc_lport_state(lport)); 114742e9a92fSRobert Love 114842e9a92fSRobert Love fc_lport_state_enter(lport, LPORT_ST_RFT_ID); 114942e9a92fSRobert Love 115042e9a92fSRobert Love lps = &lport->fcts; 115142e9a92fSRobert Love i = sizeof(lps->ff_type_map) / sizeof(lps->ff_type_map[0]); 115242e9a92fSRobert Love while (--i >= 0) 115342e9a92fSRobert Love if (ntohl(lps->ff_type_map[i]) != 0) 115442e9a92fSRobert Love break; 115542e9a92fSRobert Love if (i < 0) { 115642e9a92fSRobert Love /* nothing to register, move on to SCR */ 115742e9a92fSRobert Love fc_lport_enter_scr(lport); 115842e9a92fSRobert Love return; 115942e9a92fSRobert Love } 116042e9a92fSRobert Love 116142e9a92fSRobert Love fp = fc_frame_alloc(lport, sizeof(struct fc_ct_hdr) + 116242e9a92fSRobert Love sizeof(struct fc_ns_rft)); 116342e9a92fSRobert Love if (!fp) { 116442e9a92fSRobert Love fc_lport_error(lport, fp); 116542e9a92fSRobert Love return; 116642e9a92fSRobert Love } 116742e9a92fSRobert Love 1168a46f327aSJoe Eykholt if (!lport->tt.elsct_send(lport, FC_FID_DIR_SERV, fp, FC_NS_RFT_ID, 11697cccc157SChris Leech fc_lport_ns_resp, 117042e9a92fSRobert Love lport, lport->e_d_tov)) 117142e9a92fSRobert Love fc_lport_error(lport, fp); 117242e9a92fSRobert Love } 117342e9a92fSRobert Love 1174c9c7bd7aSChris Leech /** 1175c9866a54SChris Leech * fc_rport_enter_rspn_id() - Register symbolic port name with the name server 1176c9866a54SChris Leech * @lport: Fibre Channel local port to register 1177c9866a54SChris Leech * 1178c9866a54SChris Leech * Locking Note: The lport lock is expected to be held before calling 1179c9866a54SChris Leech * this routine. 1180c9866a54SChris Leech */ 1181c9866a54SChris Leech static void fc_lport_enter_rspn_id(struct fc_lport *lport) 1182c9866a54SChris Leech { 1183c9866a54SChris Leech struct fc_frame *fp; 1184c9866a54SChris Leech size_t len; 1185c9866a54SChris Leech 1186c9866a54SChris Leech FC_LPORT_DBG(lport, "Entered RSPN_ID state from %s state\n", 1187c9866a54SChris Leech fc_lport_state(lport)); 1188c9866a54SChris Leech 1189c9866a54SChris Leech fc_lport_state_enter(lport, LPORT_ST_RSPN_ID); 1190c9866a54SChris Leech 1191c9866a54SChris Leech len = strnlen(fc_host_symbolic_name(lport->host), 255); 1192c9866a54SChris Leech fp = fc_frame_alloc(lport, sizeof(struct fc_ct_hdr) + 1193c9866a54SChris Leech sizeof(struct fc_ns_rspn) + len); 1194c9866a54SChris Leech if (!fp) { 1195c9866a54SChris Leech fc_lport_error(lport, fp); 1196c9866a54SChris Leech return; 1197c9866a54SChris Leech } 1198c9866a54SChris Leech 1199c9866a54SChris Leech if (!lport->tt.elsct_send(lport, FC_FID_DIR_SERV, fp, FC_NS_RSPN_ID, 12007cccc157SChris Leech fc_lport_ns_resp, 1201c9866a54SChris Leech lport, lport->e_d_tov)) 1202c9866a54SChris Leech fc_lport_error(lport, fp); 1203c9866a54SChris Leech } 1204c9866a54SChris Leech 1205c9866a54SChris Leech /** 12065baa17c3SChris Leech * fc_rport_enter_rsnn_nn() - Register symbolic node name with the name server 12075baa17c3SChris Leech * @lport: Fibre Channel local port to register 12085baa17c3SChris Leech * 12095baa17c3SChris Leech * Locking Note: The lport lock is expected to be held before calling 12105baa17c3SChris Leech * this routine. 12115baa17c3SChris Leech */ 12125baa17c3SChris Leech static void fc_lport_enter_rsnn_nn(struct fc_lport *lport) 12135baa17c3SChris Leech { 12145baa17c3SChris Leech struct fc_frame *fp; 12155baa17c3SChris Leech size_t len; 12165baa17c3SChris Leech 12175baa17c3SChris Leech FC_LPORT_DBG(lport, "Entered RSNN_NN state from %s state\n", 12185baa17c3SChris Leech fc_lport_state(lport)); 12195baa17c3SChris Leech 12205baa17c3SChris Leech fc_lport_state_enter(lport, LPORT_ST_RSNN_NN); 12215baa17c3SChris Leech 12225baa17c3SChris Leech len = strnlen(fc_host_symbolic_name(lport->host), 255); 12235baa17c3SChris Leech fp = fc_frame_alloc(lport, sizeof(struct fc_ct_hdr) + 12245baa17c3SChris Leech sizeof(struct fc_ns_rsnn) + len); 12255baa17c3SChris Leech if (!fp) { 12265baa17c3SChris Leech fc_lport_error(lport, fp); 12275baa17c3SChris Leech return; 12285baa17c3SChris Leech } 12295baa17c3SChris Leech 12305baa17c3SChris Leech if (!lport->tt.elsct_send(lport, FC_FID_DIR_SERV, fp, FC_NS_RSNN_NN, 12317cccc157SChris Leech fc_lport_ns_resp, 12325baa17c3SChris Leech lport, lport->e_d_tov)) 12335baa17c3SChris Leech fc_lport_error(lport, fp); 12345baa17c3SChris Leech } 12355baa17c3SChris Leech 12365baa17c3SChris Leech /** 1237c9c7bd7aSChris Leech * fc_rport_enter_rnn_id() - Register node name with the name server 1238c9c7bd7aSChris Leech * @lport: Fibre Channel local port to register 1239c9c7bd7aSChris Leech * 1240c9c7bd7aSChris Leech * Locking Note: The lport lock is expected to be held before calling 1241c9c7bd7aSChris Leech * this routine. 1242c9c7bd7aSChris Leech */ 1243c9c7bd7aSChris Leech static void fc_lport_enter_rnn_id(struct fc_lport *lport) 1244c9c7bd7aSChris Leech { 1245c9c7bd7aSChris Leech struct fc_frame *fp; 1246c9c7bd7aSChris Leech 1247c9c7bd7aSChris Leech FC_LPORT_DBG(lport, "Entered RNN_ID state from %s state\n", 1248c9c7bd7aSChris Leech fc_lport_state(lport)); 1249c9c7bd7aSChris Leech 1250c9c7bd7aSChris Leech fc_lport_state_enter(lport, LPORT_ST_RNN_ID); 1251c9c7bd7aSChris Leech 1252c9c7bd7aSChris Leech fp = fc_frame_alloc(lport, sizeof(struct fc_ct_hdr) + 1253c9c7bd7aSChris Leech sizeof(struct fc_ns_rn_id)); 1254c9c7bd7aSChris Leech if (!fp) { 1255c9c7bd7aSChris Leech fc_lport_error(lport, fp); 1256c9c7bd7aSChris Leech return; 1257c9c7bd7aSChris Leech } 1258c9c7bd7aSChris Leech 1259c9c7bd7aSChris Leech if (!lport->tt.elsct_send(lport, FC_FID_DIR_SERV, fp, FC_NS_RNN_ID, 12607cccc157SChris Leech fc_lport_ns_resp, 1261c9c7bd7aSChris Leech lport, lport->e_d_tov)) 1262c9c7bd7aSChris Leech fc_lport_error(lport, fp); 1263c9c7bd7aSChris Leech } 1264c9c7bd7aSChris Leech 126542e9a92fSRobert Love static struct fc_rport_operations fc_lport_rport_ops = { 126642e9a92fSRobert Love .event_callback = fc_lport_rport_callback, 126742e9a92fSRobert Love }; 126842e9a92fSRobert Love 126942e9a92fSRobert Love /** 127034f42a07SRobert Love * fc_rport_enter_dns() - Create a rport to the name server 127142e9a92fSRobert Love * @lport: Fibre Channel local port requesting a rport for the name server 127242e9a92fSRobert Love * 127342e9a92fSRobert Love * Locking Note: The lport lock is expected to be held before calling 127442e9a92fSRobert Love * this routine. 127542e9a92fSRobert Love */ 127642e9a92fSRobert Love static void fc_lport_enter_dns(struct fc_lport *lport) 127742e9a92fSRobert Love { 1278ab28f1fdSJoe Eykholt struct fc_rport_priv *rdata; 127942e9a92fSRobert Love 12807414705eSRobert Love FC_LPORT_DBG(lport, "Entered DNS state from %s state\n", 12817414705eSRobert Love fc_lport_state(lport)); 128242e9a92fSRobert Love 128342e9a92fSRobert Love fc_lport_state_enter(lport, LPORT_ST_DNS); 128442e9a92fSRobert Love 128548f00902SJoe Eykholt mutex_lock(&lport->disc.disc_mutex); 12869737e6a7SRobert Love rdata = lport->tt.rport_create(lport, FC_FID_DIR_SERV); 128748f00902SJoe Eykholt mutex_unlock(&lport->disc.disc_mutex); 12889fb9d328SJoe Eykholt if (!rdata) 128942e9a92fSRobert Love goto err; 129042e9a92fSRobert Love 129142e9a92fSRobert Love rdata->ops = &fc_lport_rport_ops; 12929fb9d328SJoe Eykholt lport->tt.rport_login(rdata); 129342e9a92fSRobert Love return; 129442e9a92fSRobert Love 129542e9a92fSRobert Love err: 129642e9a92fSRobert Love fc_lport_error(lport, NULL); 129742e9a92fSRobert Love } 129842e9a92fSRobert Love 129942e9a92fSRobert Love /** 130034f42a07SRobert Love * fc_lport_timeout() - Handler for the retry_work timer. 130142e9a92fSRobert Love * @work: The work struct of the fc_lport 130242e9a92fSRobert Love */ 130342e9a92fSRobert Love static void fc_lport_timeout(struct work_struct *work) 130442e9a92fSRobert Love { 130542e9a92fSRobert Love struct fc_lport *lport = 130642e9a92fSRobert Love container_of(work, struct fc_lport, 130742e9a92fSRobert Love retry_work.work); 130842e9a92fSRobert Love 130942e9a92fSRobert Love mutex_lock(&lport->lp_mutex); 131042e9a92fSRobert Love 131142e9a92fSRobert Love switch (lport->state) { 1312b1d9fd55SJoe Eykholt case LPORT_ST_DISABLED: 131342e9a92fSRobert Love WARN_ON(1); 131442e9a92fSRobert Love break; 131522655ac2SJoe Eykholt case LPORT_ST_READY: 131622655ac2SJoe Eykholt WARN_ON(1); 131722655ac2SJoe Eykholt break; 131822655ac2SJoe Eykholt case LPORT_ST_RESET: 131922655ac2SJoe Eykholt break; 132042e9a92fSRobert Love case LPORT_ST_FLOGI: 132142e9a92fSRobert Love fc_lport_enter_flogi(lport); 132242e9a92fSRobert Love break; 132342e9a92fSRobert Love case LPORT_ST_DNS: 132442e9a92fSRobert Love fc_lport_enter_dns(lport); 132542e9a92fSRobert Love break; 1326c9c7bd7aSChris Leech case LPORT_ST_RNN_ID: 1327c9c7bd7aSChris Leech fc_lport_enter_rnn_id(lport); 1328c9c7bd7aSChris Leech break; 13295baa17c3SChris Leech case LPORT_ST_RSNN_NN: 13305baa17c3SChris Leech fc_lport_enter_rsnn_nn(lport); 13315baa17c3SChris Leech break; 1332c9866a54SChris Leech case LPORT_ST_RSPN_ID: 1333c9866a54SChris Leech fc_lport_enter_rspn_id(lport); 1334c9866a54SChris Leech break; 133542e9a92fSRobert Love case LPORT_ST_RFT_ID: 133642e9a92fSRobert Love fc_lport_enter_rft_id(lport); 133742e9a92fSRobert Love break; 133842e9a92fSRobert Love case LPORT_ST_SCR: 133942e9a92fSRobert Love fc_lport_enter_scr(lport); 134042e9a92fSRobert Love break; 134142e9a92fSRobert Love case LPORT_ST_LOGO: 134242e9a92fSRobert Love fc_lport_enter_logo(lport); 134342e9a92fSRobert Love break; 134442e9a92fSRobert Love } 134542e9a92fSRobert Love 134642e9a92fSRobert Love mutex_unlock(&lport->lp_mutex); 134742e9a92fSRobert Love } 134842e9a92fSRobert Love 134942e9a92fSRobert Love /** 135034f42a07SRobert Love * fc_lport_logo_resp() - Handle response to LOGO request 135142e9a92fSRobert Love * @sp: current sequence in LOGO exchange 135242e9a92fSRobert Love * @fp: response frame 135342e9a92fSRobert Love * @lp_arg: Fibre Channel lport port instance that sent the LOGO request 135442e9a92fSRobert Love * 135542e9a92fSRobert Love * Locking Note: This function will be called without the lport lock 135642e9a92fSRobert Love * held, but it will lock, call an _enter_* function or fc_lport_error 135742e9a92fSRobert Love * and then unlock the lport. 135842e9a92fSRobert Love */ 135911b56188SChris Leech void fc_lport_logo_resp(struct fc_seq *sp, struct fc_frame *fp, 136042e9a92fSRobert Love void *lp_arg) 136142e9a92fSRobert Love { 136242e9a92fSRobert Love struct fc_lport *lport = lp_arg; 136342e9a92fSRobert Love u8 op; 136442e9a92fSRobert Love 1365f657d299SJoe Eykholt FC_LPORT_DBG(lport, "Received a LOGO %s\n", fc_els_resp_type(fp)); 1366f657d299SJoe Eykholt 136742e9a92fSRobert Love if (fp == ERR_PTR(-FC_EX_CLOSED)) 136842e9a92fSRobert Love return; 136942e9a92fSRobert Love 137042e9a92fSRobert Love mutex_lock(&lport->lp_mutex); 137142e9a92fSRobert Love 137242e9a92fSRobert Love if (lport->state != LPORT_ST_LOGO) { 13737414705eSRobert Love FC_LPORT_DBG(lport, "Received a LOGO response, but in state " 13747414705eSRobert Love "%s\n", fc_lport_state(lport)); 137576f6804eSAbhijeet Joglekar if (IS_ERR(fp)) 137676f6804eSAbhijeet Joglekar goto err; 137742e9a92fSRobert Love goto out; 137842e9a92fSRobert Love } 137942e9a92fSRobert Love 138076f6804eSAbhijeet Joglekar if (IS_ERR(fp)) { 138176f6804eSAbhijeet Joglekar fc_lport_error(lport, fp); 138276f6804eSAbhijeet Joglekar goto err; 138376f6804eSAbhijeet Joglekar } 138476f6804eSAbhijeet Joglekar 138542e9a92fSRobert Love op = fc_frame_payload_op(fp); 138642e9a92fSRobert Love if (op == ELS_LS_ACC) 13871190d925SJoe Eykholt fc_lport_enter_disabled(lport); 138842e9a92fSRobert Love else 138942e9a92fSRobert Love fc_lport_error(lport, fp); 139042e9a92fSRobert Love 139142e9a92fSRobert Love out: 139242e9a92fSRobert Love fc_frame_free(fp); 139342e9a92fSRobert Love err: 139442e9a92fSRobert Love mutex_unlock(&lport->lp_mutex); 139542e9a92fSRobert Love } 139611b56188SChris Leech EXPORT_SYMBOL(fc_lport_logo_resp); 139742e9a92fSRobert Love 139842e9a92fSRobert Love /** 139934f42a07SRobert Love * fc_rport_enter_logo() - Logout of the fabric 140042e9a92fSRobert Love * @lport: Fibre Channel local port to be logged out 140142e9a92fSRobert Love * 140242e9a92fSRobert Love * Locking Note: The lport lock is expected to be held before calling 140342e9a92fSRobert Love * this routine. 140442e9a92fSRobert Love */ 140542e9a92fSRobert Love static void fc_lport_enter_logo(struct fc_lport *lport) 140642e9a92fSRobert Love { 140742e9a92fSRobert Love struct fc_frame *fp; 140842e9a92fSRobert Love struct fc_els_logo *logo; 140942e9a92fSRobert Love 14107414705eSRobert Love FC_LPORT_DBG(lport, "Entered LOGO state from %s state\n", 14117414705eSRobert Love fc_lport_state(lport)); 141242e9a92fSRobert Love 141342e9a92fSRobert Love fc_lport_state_enter(lport, LPORT_ST_LOGO); 14148faecddbSChris Leech fc_vports_linkchange(lport); 141542e9a92fSRobert Love 141642e9a92fSRobert Love fp = fc_frame_alloc(lport, sizeof(*logo)); 141742e9a92fSRobert Love if (!fp) { 141842e9a92fSRobert Love fc_lport_error(lport, fp); 141942e9a92fSRobert Love return; 142042e9a92fSRobert Love } 142142e9a92fSRobert Love 1422a46f327aSJoe Eykholt if (!lport->tt.elsct_send(lport, FC_FID_FLOGI, fp, ELS_LOGO, 1423a46f327aSJoe Eykholt fc_lport_logo_resp, lport, lport->e_d_tov)) 14248f550f93SChris Leech fc_lport_error(lport, NULL); 142542e9a92fSRobert Love } 142642e9a92fSRobert Love 142742e9a92fSRobert Love /** 142834f42a07SRobert Love * fc_lport_flogi_resp() - Handle response to FLOGI request 142942e9a92fSRobert Love * @sp: current sequence in FLOGI exchange 143042e9a92fSRobert Love * @fp: response frame 143142e9a92fSRobert Love * @lp_arg: Fibre Channel lport port instance that sent the FLOGI request 143242e9a92fSRobert Love * 143342e9a92fSRobert Love * Locking Note: This function will be called without the lport lock 143442e9a92fSRobert Love * held, but it will lock, call an _enter_* function or fc_lport_error 143542e9a92fSRobert Love * and then unlock the lport. 143642e9a92fSRobert Love */ 143711b56188SChris Leech void fc_lport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp, 143842e9a92fSRobert Love void *lp_arg) 143942e9a92fSRobert Love { 144042e9a92fSRobert Love struct fc_lport *lport = lp_arg; 144142e9a92fSRobert Love struct fc_frame_header *fh; 144242e9a92fSRobert Love struct fc_els_flogi *flp; 144342e9a92fSRobert Love u32 did; 144442e9a92fSRobert Love u16 csp_flags; 144542e9a92fSRobert Love unsigned int r_a_tov; 144642e9a92fSRobert Love unsigned int e_d_tov; 144742e9a92fSRobert Love u16 mfs; 144842e9a92fSRobert Love 1449f657d299SJoe Eykholt FC_LPORT_DBG(lport, "Received a FLOGI %s\n", fc_els_resp_type(fp)); 1450f657d299SJoe Eykholt 145142e9a92fSRobert Love if (fp == ERR_PTR(-FC_EX_CLOSED)) 145242e9a92fSRobert Love return; 145342e9a92fSRobert Love 145442e9a92fSRobert Love mutex_lock(&lport->lp_mutex); 145542e9a92fSRobert Love 145642e9a92fSRobert Love if (lport->state != LPORT_ST_FLOGI) { 14577414705eSRobert Love FC_LPORT_DBG(lport, "Received a FLOGI response, but in state " 14587414705eSRobert Love "%s\n", fc_lport_state(lport)); 145976f6804eSAbhijeet Joglekar if (IS_ERR(fp)) 146076f6804eSAbhijeet Joglekar goto err; 146142e9a92fSRobert Love goto out; 146242e9a92fSRobert Love } 146342e9a92fSRobert Love 146476f6804eSAbhijeet Joglekar if (IS_ERR(fp)) { 146576f6804eSAbhijeet Joglekar fc_lport_error(lport, fp); 146676f6804eSAbhijeet Joglekar goto err; 146776f6804eSAbhijeet Joglekar } 146876f6804eSAbhijeet Joglekar 146942e9a92fSRobert Love fh = fc_frame_header_get(fp); 147042e9a92fSRobert Love did = ntoh24(fh->fh_d_id); 147142e9a92fSRobert Love if (fc_frame_payload_op(fp) == ELS_LS_ACC && did != 0) { 147242e9a92fSRobert Love 14737414705eSRobert Love printk(KERN_INFO "libfc: Assigned FID (%6x) in FLOGI response\n", 14747414705eSRobert Love did); 147542e9a92fSRobert Love fc_host_port_id(lport->host) = did; 147642e9a92fSRobert Love 147742e9a92fSRobert Love flp = fc_frame_payload_get(fp, sizeof(*flp)); 147842e9a92fSRobert Love if (flp) { 147942e9a92fSRobert Love mfs = ntohs(flp->fl_csp.sp_bb_data) & 148042e9a92fSRobert Love FC_SP_BB_DATA_MASK; 148142e9a92fSRobert Love if (mfs >= FC_SP_MIN_MAX_PAYLOAD && 148242e9a92fSRobert Love mfs < lport->mfs) 148342e9a92fSRobert Love lport->mfs = mfs; 148442e9a92fSRobert Love csp_flags = ntohs(flp->fl_csp.sp_features); 148542e9a92fSRobert Love r_a_tov = ntohl(flp->fl_csp.sp_r_a_tov); 148642e9a92fSRobert Love e_d_tov = ntohl(flp->fl_csp.sp_e_d_tov); 148742e9a92fSRobert Love if (csp_flags & FC_SP_FT_EDTR) 148842e9a92fSRobert Love e_d_tov /= 1000000; 1489db36c06cSChris Leech 1490db36c06cSChris Leech lport->npiv_enabled = !!(csp_flags & FC_SP_FT_NPIV_ACC); 1491db36c06cSChris Leech 149242e9a92fSRobert Love if ((csp_flags & FC_SP_FT_FPORT) == 0) { 149342e9a92fSRobert Love if (e_d_tov > lport->e_d_tov) 149442e9a92fSRobert Love lport->e_d_tov = e_d_tov; 149542e9a92fSRobert Love lport->r_a_tov = 2 * e_d_tov; 14967414705eSRobert Love printk(KERN_INFO "libfc: Port (%6x) entered " 14977414705eSRobert Love "point to point mode\n", did); 149842e9a92fSRobert Love fc_lport_ptp_setup(lport, ntoh24(fh->fh_s_id), 149942e9a92fSRobert Love get_unaligned_be64( 150042e9a92fSRobert Love &flp->fl_wwpn), 150142e9a92fSRobert Love get_unaligned_be64( 150242e9a92fSRobert Love &flp->fl_wwnn)); 150342e9a92fSRobert Love } else { 150442e9a92fSRobert Love lport->e_d_tov = e_d_tov; 150542e9a92fSRobert Love lport->r_a_tov = r_a_tov; 150642e9a92fSRobert Love fc_host_fabric_name(lport->host) = 150742e9a92fSRobert Love get_unaligned_be64(&flp->fl_wwnn); 150842e9a92fSRobert Love fc_lport_enter_dns(lport); 150942e9a92fSRobert Love } 151042e9a92fSRobert Love } 151142e9a92fSRobert Love } else { 15127414705eSRobert Love FC_LPORT_DBG(lport, "Bad FLOGI response\n"); 151342e9a92fSRobert Love } 151442e9a92fSRobert Love 151542e9a92fSRobert Love out: 151642e9a92fSRobert Love fc_frame_free(fp); 151742e9a92fSRobert Love err: 151842e9a92fSRobert Love mutex_unlock(&lport->lp_mutex); 151942e9a92fSRobert Love } 152011b56188SChris Leech EXPORT_SYMBOL(fc_lport_flogi_resp); 152142e9a92fSRobert Love 152242e9a92fSRobert Love /** 152334f42a07SRobert Love * fc_rport_enter_flogi() - Send a FLOGI request to the fabric manager 152442e9a92fSRobert Love * @lport: Fibre Channel local port to be logged in to the fabric 152542e9a92fSRobert Love * 152642e9a92fSRobert Love * Locking Note: The lport lock is expected to be held before calling 152742e9a92fSRobert Love * this routine. 152842e9a92fSRobert Love */ 152942e9a92fSRobert Love void fc_lport_enter_flogi(struct fc_lport *lport) 153042e9a92fSRobert Love { 153142e9a92fSRobert Love struct fc_frame *fp; 153242e9a92fSRobert Love 15337414705eSRobert Love FC_LPORT_DBG(lport, "Entered FLOGI state from %s state\n", 15347414705eSRobert Love fc_lport_state(lport)); 153542e9a92fSRobert Love 153642e9a92fSRobert Love fc_lport_state_enter(lport, LPORT_ST_FLOGI); 153742e9a92fSRobert Love 153842e9a92fSRobert Love fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi)); 153942e9a92fSRobert Love if (!fp) 154042e9a92fSRobert Love return fc_lport_error(lport, fp); 154142e9a92fSRobert Love 1542db36c06cSChris Leech if (!lport->tt.elsct_send(lport, FC_FID_FLOGI, fp, 1543db36c06cSChris Leech lport->vport ? ELS_FDISC : ELS_FLOGI, 154442e9a92fSRobert Love fc_lport_flogi_resp, lport, lport->e_d_tov)) 15458f550f93SChris Leech fc_lport_error(lport, NULL); 154642e9a92fSRobert Love } 154742e9a92fSRobert Love 154842e9a92fSRobert Love /* Configure a fc_lport */ 154942e9a92fSRobert Love int fc_lport_config(struct fc_lport *lport) 155042e9a92fSRobert Love { 155142e9a92fSRobert Love INIT_DELAYED_WORK(&lport->retry_work, fc_lport_timeout); 155242e9a92fSRobert Love mutex_init(&lport->lp_mutex); 155342e9a92fSRobert Love 1554b1d9fd55SJoe Eykholt fc_lport_state_enter(lport, LPORT_ST_DISABLED); 155542e9a92fSRobert Love 155642e9a92fSRobert Love fc_lport_add_fc4_type(lport, FC_TYPE_FCP); 155742e9a92fSRobert Love fc_lport_add_fc4_type(lport, FC_TYPE_CT); 155842e9a92fSRobert Love 155942e9a92fSRobert Love return 0; 156042e9a92fSRobert Love } 156142e9a92fSRobert Love EXPORT_SYMBOL(fc_lport_config); 156242e9a92fSRobert Love 156342e9a92fSRobert Love int fc_lport_init(struct fc_lport *lport) 156442e9a92fSRobert Love { 156542e9a92fSRobert Love if (!lport->tt.lport_recv) 156642e9a92fSRobert Love lport->tt.lport_recv = fc_lport_recv_req; 156742e9a92fSRobert Love 156842e9a92fSRobert Love if (!lport->tt.lport_reset) 156942e9a92fSRobert Love lport->tt.lport_reset = fc_lport_reset; 157042e9a92fSRobert Love 157142e9a92fSRobert Love fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT; 157242e9a92fSRobert Love fc_host_node_name(lport->host) = lport->wwnn; 157342e9a92fSRobert Love fc_host_port_name(lport->host) = lport->wwpn; 157442e9a92fSRobert Love fc_host_supported_classes(lport->host) = FC_COS_CLASS3; 157542e9a92fSRobert Love memset(fc_host_supported_fc4s(lport->host), 0, 157642e9a92fSRobert Love sizeof(fc_host_supported_fc4s(lport->host))); 157742e9a92fSRobert Love fc_host_supported_fc4s(lport->host)[2] = 1; 157842e9a92fSRobert Love fc_host_supported_fc4s(lport->host)[7] = 1; 157942e9a92fSRobert Love 158042e9a92fSRobert Love /* This value is also unchanging */ 158142e9a92fSRobert Love memset(fc_host_active_fc4s(lport->host), 0, 158242e9a92fSRobert Love sizeof(fc_host_active_fc4s(lport->host))); 158342e9a92fSRobert Love fc_host_active_fc4s(lport->host)[2] = 1; 158442e9a92fSRobert Love fc_host_active_fc4s(lport->host)[7] = 1; 158542e9a92fSRobert Love fc_host_maxframe_size(lport->host) = lport->mfs; 158642e9a92fSRobert Love fc_host_supported_speeds(lport->host) = 0; 158742e9a92fSRobert Love if (lport->link_supported_speeds & FC_PORTSPEED_1GBIT) 158842e9a92fSRobert Love fc_host_supported_speeds(lport->host) |= FC_PORTSPEED_1GBIT; 158942e9a92fSRobert Love if (lport->link_supported_speeds & FC_PORTSPEED_10GBIT) 159042e9a92fSRobert Love fc_host_supported_speeds(lport->host) |= FC_PORTSPEED_10GBIT; 159142e9a92fSRobert Love 159242e9a92fSRobert Love return 0; 159342e9a92fSRobert Love } 159442e9a92fSRobert Love EXPORT_SYMBOL(fc_lport_init); 1595