/** * fc_lport_enter_ns() - register some object with the name server * @lport: Fibre Channel local port to register * * Locking Note: The lport lock is expected to be held before calling * this routine. */ static void fc_lport_enter_ns(struct fc_lport *lport, enum fc_lport_state state) { struct fc_frame *fp; enum fc_ns_req cmd; int size = sizeof(struct fc_ct_hdr); size_t len; FC_LPORT_DBG(lport, "Entered %s state from %s state\n", fc_lport_state_names[state], fc_lport_state(lport)); fc_lport_state_enter(lport, state); switch (state) { case LPORT_ST_RNN_ID: cmd = FC_NS_RNN_ID; size += sizeof(struct fc_ns_rn_id); break; case LPORT_ST_RSNN_NN: len = strnlen(fc_host_symbolic_name(lport->host), 255); /* if there is no symbolic name, skip to RFT_ID */ if (!len) return fc_lport_enter_ns(lport, LPORT_ST_RFT_ID); cmd = FC_NS_RSNN_NN; size += sizeof(struct fc_ns_rsnn) + len; break; case LPORT_ST_RSPN_ID: len = strnlen(fc_host_symbolic_name(lport->host), 255); /* if there is no symbolic name, skip to RFT_ID */ if (!len) return fc_lport_enter_ns(lport, LPORT_ST_RFT_ID); cmd = FC_NS_RSPN_ID; size += sizeof(struct fc_ns_rspn) + len; break; case LPORT_ST_RFT_ID: cmd = FC_NS_RFT_ID; size += sizeof(struct fc_ns_rft); break; case LPORT_ST_RFF_ID: cmd = FC_NS_RFF_ID; size += sizeof(struct fc_ns_rff_id); break; default: fc_lport_error(lport, NULL); return; } fp = fc_frame_alloc(lport, size); if (!fp) { fc_lport_error(lport, fp); return; } if (!lport->tt.elsct_send(lport, FC_FID_DIR_SERV, fp, cmd, fc_lport_ns_resp, lport, 3 * lport->r_a_tov)) fc_lport_error(lport, fp); }
/** * fc_lport_rport_callback() - Event handler for rport events * @lport: The lport which is receiving the event * @rdata: private remote port data * @event: The event that occured * * Locking Note: The rport lock should not be held when calling * this function. */ static void fc_lport_rport_callback(struct fc_lport *lport, struct fc_rport_priv *rdata, enum fc_rport_event event) { FC_LPORT_DBG(lport, "Received a %d event for port (%6.6x)\n", event, rdata->ids.port_id); mutex_lock(&lport->lp_mutex); switch (event) { case RPORT_EV_READY: if (lport->state == LPORT_ST_DNS) { lport->dns_rdata = rdata; fc_lport_enter_ns(lport, LPORT_ST_RNN_ID); } else { FC_LPORT_DBG(lport, "Received an READY event " "on port (%6.6x) for the directory " "server, but the lport is not " "in the DNS state, it's in the " "%d state", rdata->ids.port_id, lport->state); lport->tt.rport_logoff(rdata); } break; case RPORT_EV_LOGO: case RPORT_EV_FAILED: case RPORT_EV_STOP: lport->dns_rdata = NULL; break; case RPORT_EV_NONE: break; } mutex_unlock(&lport->lp_mutex); }
static void fc_lport_timeout(struct work_struct *work) { struct fc_lport *lport = container_of(work, struct fc_lport, retry_work.work); mutex_lock(&lport->lp_mutex); switch (lport->state) { case LPORT_ST_DISABLED: WARN_ON(1); break; case LPORT_ST_READY: break; case LPORT_ST_RESET: break; case LPORT_ST_FLOGI: fc_lport_enter_flogi(lport); break; case LPORT_ST_DNS: fc_lport_enter_dns(lport); break; case LPORT_ST_RNN_ID: case LPORT_ST_RSNN_NN: case LPORT_ST_RSPN_ID: case LPORT_ST_RFT_ID: case LPORT_ST_RFF_ID: fc_lport_enter_ns(lport, lport->state); break; case LPORT_ST_FDMI: fc_lport_enter_fdmi(lport); break; case LPORT_ST_RHBA: case LPORT_ST_RPA: case LPORT_ST_DHBA: case LPORT_ST_DPRT: fc_lport_enter_ms(lport, lport->state); break; case LPORT_ST_SCR: fc_lport_enter_scr(lport); break; case LPORT_ST_LOGO: fc_lport_enter_logo(lport); break; } mutex_unlock(&lport->lp_mutex); }
/** * fc_lport_ns_resp() - Handle response to a name server * registration exchange * @sp: current sequence in exchange * @fp: response frame * @lp_arg: Fibre Channel host port instance * * Locking Note: This function will be called without the lport lock * held, but it will lock, call an _enter_* function or fc_lport_error() * and then unlock the lport. */ static void fc_lport_ns_resp(struct fc_seq *sp, struct fc_frame *fp, void *lp_arg) { struct fc_lport *lport = lp_arg; struct fc_frame_header *fh; struct fc_ct_hdr *ct; FC_LPORT_DBG(lport, "Received a ns %s\n", fc_els_resp_type(fp)); if (fp == ERR_PTR(-FC_EX_CLOSED)) return; mutex_lock(&lport->lp_mutex); if (lport->state < LPORT_ST_RNN_ID || lport->state > LPORT_ST_RFF_ID) { FC_LPORT_DBG(lport, "Received a name server response, " "but in state %s\n", fc_lport_state(lport)); if (IS_ERR(fp)) goto err; goto out; } if (IS_ERR(fp)) { fc_lport_error(lport, fp); goto err; } fh = fc_frame_header_get(fp); ct = fc_frame_payload_get(fp, sizeof(*ct)); if (fh && ct && fh->fh_type == FC_TYPE_CT && ct->ct_fs_type == FC_FST_DIR && ct->ct_fs_subtype == FC_NS_SUBTYPE && ntohs(ct->ct_cmd) == FC_FS_ACC) switch (lport->state) { case LPORT_ST_RNN_ID: fc_lport_enter_ns(lport, LPORT_ST_RSNN_NN); break; case LPORT_ST_RSNN_NN: fc_lport_enter_ns(lport, LPORT_ST_RSPN_ID); break; case LPORT_ST_RSPN_ID: fc_lport_enter_ns(lport, LPORT_ST_RFT_ID); break; case LPORT_ST_RFT_ID: fc_lport_enter_ns(lport, LPORT_ST_RFF_ID); break; case LPORT_ST_RFF_ID: fc_lport_enter_scr(lport); break; default: /* should have already been caught by state checks */ break; } else fc_lport_error(lport, fp); out: fc_frame_free(fp); err: mutex_unlock(&lport->lp_mutex); }