// SPDX-License-Identifier: GPL-2.0-only /* * Copyright(c) 2007 - 2008 Intel Corporation. All rights reserved. * * Maintained at www.Open-FCoE.org
*/
/* * RPORT GENERAL INFO * * This file contains all processing regarding fc_rports. It contains the * rport state machine and does all rport interaction with the transport class. * There should be no other places in libfc that interact directly with the * transport class in regards to adding and deleting rports. * * fc_rport's represent N_Port's within the fabric.
*/
/* * RPORT LOCKING * * The rport should never hold the rport mutex and then attempt to acquire * either the lport or disc mutexes. The rport's mutex is considered lesser * than both the lport's mutex and the disc mutex. Refer to fc_lport.c for * more comments on the hierarchy. * * The locking strategy is similar to the lport's strategy. The lock protects * the rport's states and is held and released by the entry points to the rport * block. All _enter_* functions correspond to rport states and expect the rport * mutex to be locked before calling them. This means that rports only handle * one request or response at a time, since they're not critical for the I/O * path this potential over-use of the mutex is acceptable.
*/
/* * RPORT REFERENCE COUNTING * * A rport reference should be taken when: * - an rport is allocated * - a workqueue item is scheduled * - an ELS request is send * The reference should be dropped when: * - the workqueue function has finished * - the ELS response is handled * - an rport is removed
*/
/** * fc_rport_lookup() - Lookup a remote port by port_id * @lport: The local port to lookup the remote port on * @port_id: The remote port ID to look up * * The reference count of the fc_rport_priv structure is * increased by one.
*/ struct fc_rport_priv *fc_rport_lookup(conststruct fc_lport *lport,
u32 port_id)
{ struct fc_rport_priv *rdata = NULL, *tmp_rdata;
/** * fc_rport_create() - Create a new remote port * @lport: The local port this remote port will be associated with * @port_id: The identifiers for the new remote port * * The remote port will start in the INIT state.
*/ struct fc_rport_priv *fc_rport_create(struct fc_lport *lport, u32 port_id)
{ struct fc_rport_priv *rdata;
size_t rport_priv_size = sizeof(*rdata);
/** * fc_rport_destroy() - Free a remote port after last reference is released * @kref: The remote port's kref
*/ void fc_rport_destroy(struct kref *kref)
{ struct fc_rport_priv *rdata;
/** * fc_rport_state() - Return a string identifying the remote port's state * @rdata: The remote port
*/ staticconstchar *fc_rport_state(struct fc_rport_priv *rdata)
{ constchar *cp;
/** * fc_set_rport_loss_tmo() - Set the remote port loss timeout * @rport: The remote port that gets a new timeout value * @timeout: The new timeout value (in seconds)
*/ void fc_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout)
{ if (timeout)
rport->dev_loss_tmo = timeout; else
rport->dev_loss_tmo = 1;
}
EXPORT_SYMBOL(fc_set_rport_loss_tmo);
/** * fc_plogi_get_maxframe() - Get the maximum payload from the common service * parameters in a FLOGI frame * @flp: The FLOGI or PLOGI payload * @maxval: The maximum frame size upper limit; this may be less than what * is in the service parameters
*/ staticunsignedint fc_plogi_get_maxframe(struct fc_els_flogi *flp, unsignedint maxval)
{ unsignedint mfs;
/* * Get max payload from the common service parameters and the * class 3 receive data field size.
*/
mfs = ntohs(flp->fl_csp.sp_bb_data) & FC_SP_BB_DATA_MASK; if (mfs >= FC_SP_MIN_MAX_PAYLOAD && mfs < maxval)
maxval = mfs;
mfs = ntohs(flp->fl_cssp[3 - 1].cp_rdfs); if (mfs >= FC_SP_MIN_MAX_PAYLOAD && mfs < maxval)
maxval = mfs; return maxval;
}
/** * fc_rport_state_enter() - Change the state of a remote port * @rdata: The remote port whose state should change * @new: The new state
*/ staticvoid fc_rport_state_enter(struct fc_rport_priv *rdata, enum fc_rport_state new)
{
lockdep_assert_held(&rdata->rp_mutex);
if (rport_ops && rport_ops->event_callback) {
FC_RPORT_DBG(rdata, "callback ev %d\n", event);
rport_ops->event_callback(lport, rdata, event);
} if (rdata->lld_event_callback) {
FC_RPORT_DBG(rdata, "lld callback ev %d\n", event);
rdata->lld_event_callback(lport, rdata, event);
}
kref_put(&rdata->kref, fc_rport_destroy); break;
case RPORT_EV_FAILED: case RPORT_EV_LOGO: case RPORT_EV_STOP: if (rdata->prli_count) {
mutex_lock(&fc_prov_mutex); for (type = 1; type < FC_FC4_PROV_SIZE; type++) {
prov = fc_passive_prov[type]; if (prov && prov->prlo)
prov->prlo(rdata);
}
mutex_unlock(&fc_prov_mutex);
}
port_id = rdata->ids.port_id;
mutex_unlock(&rdata->rp_mutex);
if (rport_ops && rport_ops->event_callback) {
FC_RPORT_DBG(rdata, "callback ev %d\n", event);
rport_ops->event_callback(lport, rdata, event);
} if (rdata->lld_event_callback) {
FC_RPORT_DBG(rdata, "lld callback ev %d\n", event);
rdata->lld_event_callback(lport, rdata, event);
} if (cancel_delayed_work_sync(&rdata->retry_work))
kref_put(&rdata->kref, fc_rport_destroy);
/* * Reset any outstanding exchanges before freeing rport.
*/
lport->tt.exch_mgr_reset(lport, 0, port_id);
lport->tt.exch_mgr_reset(lport, port_id, 0);
/** * fc_rport_login() - Start the remote port login state machine * @rdata: The remote port to be logged in to * * Initiates the RP state machine. It is called from the LP module. * This function will issue the following commands to the N_Port * identified by the FC ID provided. * * - PLOGI * - PRLI * - RTV * * Locking Note: Called without the rport lock held. This * function will hold the rport lock, call an _enter_* * function and then unlock the rport. * * This indicates the intent to be logged into the remote port. * If it appears we are already logged in, ADISC is used to verify * the setup.
*/ int fc_rport_login(struct fc_rport_priv *rdata)
{
mutex_lock(&rdata->rp_mutex);
rdata->flags |= FC_RP_STARTED; switch (rdata->rp_state) { case RPORT_ST_READY:
FC_RPORT_DBG(rdata, "ADISC port\n");
fc_rport_enter_adisc(rdata); break; case RPORT_ST_DELETE:
FC_RPORT_DBG(rdata, "Restart deleted port\n"); break; case RPORT_ST_INIT:
FC_RPORT_DBG(rdata, "Login to port\n");
fc_rport_enter_flogi(rdata); break; default:
FC_RPORT_DBG(rdata, "Login in progress, state %s\n",
fc_rport_state(rdata)); break;
}
mutex_unlock(&rdata->rp_mutex);
return 0;
}
EXPORT_SYMBOL(fc_rport_login);
/** * fc_rport_enter_delete() - Schedule a remote port to be deleted * @rdata: The remote port to be deleted * @event: The event to report as the reason for deletion * * Allow state change into DELETE only once. * * Call queue_work only if there's no event already pending. * Set the new event so that the old pending event will not occur. * Since we have the mutex, even if fc_rport_work() is already started, * it'll see the new event. * * Reference counting: does not modify kref
*/ staticvoid fc_rport_enter_delete(struct fc_rport_priv *rdata, enum fc_rport_event event)
{
lockdep_assert_held(&rdata->rp_mutex);
if (rdata->rp_state == RPORT_ST_DELETE) return;
FC_RPORT_DBG(rdata, "Delete port\n");
fc_rport_state_enter(rdata, RPORT_ST_DELETE);
if (rdata->event == RPORT_EV_NONE) {
kref_get(&rdata->kref); if (!queue_work(rport_event_queue, &rdata->event_work))
kref_put(&rdata->kref, fc_rport_destroy);
}
rdata->event = event;
}
/** * fc_rport_logoff() - Logoff and remove a remote port * @rdata: The remote port to be logged off of * * Locking Note: Called without the rport lock held. This * function will hold the rport lock, call an _enter_* * function and then unlock the rport.
*/ int fc_rport_logoff(struct fc_rport_priv *rdata)
{ struct fc_lport *lport = rdata->local_port;
u32 port_id = rdata->ids.port_id;
mutex_lock(&rdata->rp_mutex);
FC_RPORT_DBG(rdata, "Remove port\n");
rdata->flags &= ~FC_RP_STARTED; if (rdata->rp_state == RPORT_ST_DELETE) {
FC_RPORT_DBG(rdata, "Port in Delete state, not removing\n"); goto out;
} /* * FC-LS states: * To explicitly Logout, the initiating Nx_Port shall terminate * other open Sequences that it initiated with the destination * Nx_Port prior to performing Logout.
*/
lport->tt.exch_mgr_reset(lport, 0, port_id);
lport->tt.exch_mgr_reset(lport, port_id, 0);
fc_rport_enter_logo(rdata);
/* * Change the state to Delete so that we discard * the response.
*/
fc_rport_enter_delete(rdata, RPORT_EV_STOP);
out:
mutex_unlock(&rdata->rp_mutex); return 0;
}
EXPORT_SYMBOL(fc_rport_logoff);
/** * fc_rport_enter_ready() - Transition to the RPORT_ST_READY state * @rdata: The remote port that is ready * * Reference counting: schedules workqueue, does not modify kref
*/ staticvoid fc_rport_enter_ready(struct fc_rport_priv *rdata)
{
lockdep_assert_held(&rdata->rp_mutex);
fc_rport_state_enter(rdata, RPORT_ST_READY);
FC_RPORT_DBG(rdata, "Port is Ready\n");
kref_get(&rdata->kref); if (rdata->event == RPORT_EV_NONE &&
!queue_work(rport_event_queue, &rdata->event_work))
kref_put(&rdata->kref, fc_rport_destroy);
rdata->event = RPORT_EV_READY;
}
/** * fc_rport_timeout() - Handler for the retry_work timer * @work: Handle to the remote port that has timed out * * Locking Note: Called without the rport lock held. This * function will hold the rport lock, call an _enter_* * function and then unlock the rport. * * Reference counting: Drops kref on return.
*/ staticvoid fc_rport_timeout(struct work_struct *work)
{ struct fc_rport_priv *rdata =
container_of(work, struct fc_rport_priv, retry_work.work);
mutex_lock(&rdata->rp_mutex);
FC_RPORT_DBG(rdata, "Port timeout, state %s\n", fc_rport_state(rdata));
switch (rdata->rp_state) { case RPORT_ST_FLOGI:
fc_rport_enter_flogi(rdata); break; case RPORT_ST_PLOGI:
fc_rport_enter_plogi(rdata); break; case RPORT_ST_PRLI:
fc_rport_enter_prli(rdata); break; case RPORT_ST_RTV:
fc_rport_enter_rtv(rdata); break; case RPORT_ST_ADISC:
fc_rport_enter_adisc(rdata); break; case RPORT_ST_PLOGI_WAIT: case RPORT_ST_READY: case RPORT_ST_INIT: case RPORT_ST_DELETE: break;
}
/** * fc_rport_error() - Error handler, called once retries have been exhausted * @rdata: The remote port the error is happened on * @err: The error code * * Reference counting: does not modify kref
*/ staticvoid fc_rport_error(struct fc_rport_priv *rdata, int err)
{ struct fc_lport *lport = rdata->local_port;
lockdep_assert_held(&rdata->rp_mutex);
FC_RPORT_DBG(rdata, "Error %d in state %s, retries %d\n",
-err, fc_rport_state(rdata), rdata->retries);
switch (rdata->rp_state) { case RPORT_ST_FLOGI:
rdata->flags &= ~FC_RP_STARTED;
fc_rport_enter_delete(rdata, RPORT_EV_FAILED); break; case RPORT_ST_PLOGI: if (lport->point_to_multipoint) {
rdata->flags &= ~FC_RP_STARTED;
fc_rport_enter_delete(rdata, RPORT_EV_FAILED);
} else
fc_rport_enter_logo(rdata); break; case RPORT_ST_RTV:
fc_rport_enter_ready(rdata); break; case RPORT_ST_PRLI:
fc_rport_enter_plogi(rdata); break; case RPORT_ST_ADISC:
fc_rport_enter_logo(rdata); break; case RPORT_ST_PLOGI_WAIT: case RPORT_ST_DELETE: case RPORT_ST_READY: case RPORT_ST_INIT: break;
}
}
/** * fc_rport_error_retry() - Handler for remote port state retries * @rdata: The remote port whose state is to be retried * @err: The error code * * If the error was an exchange timeout retry immediately, * otherwise wait for E_D_TOV. * * Reference counting: increments kref when scheduling retry_work
*/ staticvoid fc_rport_error_retry(struct fc_rport_priv *rdata, int err)
{ unsignedlong delay = msecs_to_jiffies(rdata->e_d_tov);
lockdep_assert_held(&rdata->rp_mutex);
/* make sure this isn't an FC_EX_CLOSED error, never retry those */ if (err == -FC_EX_CLOSED) goto out;
if (rdata->retries < rdata->local_port->max_rport_retry_count) {
FC_RPORT_DBG(rdata, "Error %d in state %s, retrying\n",
err, fc_rport_state(rdata));
rdata->retries++; /* no additional delay on exchange timeouts */ if (err == -FC_EX_TIMEOUT)
delay = 0;
kref_get(&rdata->kref); if (!schedule_delayed_work(&rdata->retry_work, delay))
kref_put(&rdata->kref, fc_rport_destroy); return;
}
out:
fc_rport_error(rdata, err);
}
/** * fc_rport_login_complete() - Handle parameters and completion of p-mp login. * @rdata: The remote port which we logged into or which logged into us. * @fp: The FLOGI or PLOGI request or response frame * * Returns non-zero error if a problem is detected with the frame. * Does not free the frame. * * This is only used in point-to-multipoint mode for FIP currently.
*/ staticint fc_rport_login_complete(struct fc_rport_priv *rdata, struct fc_frame *fp)
{ struct fc_lport *lport = rdata->local_port; struct fc_els_flogi *flogi; unsignedint e_d_tov;
u16 csp_flags;
flogi = fc_frame_payload_get(fp, sizeof(*flogi)); if (!flogi) return -EINVAL;
csp_flags = ntohs(flogi->fl_csp.sp_features);
if (fc_frame_payload_op(fp) == ELS_FLOGI) { if (csp_flags & FC_SP_FT_FPORT) {
FC_RPORT_DBG(rdata, "Fabric bit set in FLOGI\n"); return -EINVAL;
}
} else {
/* * E_D_TOV is not valid on an incoming FLOGI request.
*/
e_d_tov = ntohl(flogi->fl_csp.sp_e_d_tov); if (csp_flags & FC_SP_FT_EDTR)
e_d_tov /= 1000000; if (e_d_tov > rdata->e_d_tov)
rdata->e_d_tov = e_d_tov;
}
rdata->maxframe_size = fc_plogi_get_maxframe(flogi, lport->mfs); return 0;
}
/** * fc_rport_flogi_resp() - Handle response to FLOGI request for p-mp mode * @sp: The sequence that the FLOGI was on * @fp: The FLOGI response frame * @rp_arg: The remote port that received the FLOGI response
*/ staticvoid fc_rport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp, void *rp_arg)
{ struct fc_rport_priv *rdata = rp_arg; struct fc_lport *lport = rdata->local_port; struct fc_els_flogi *flogi; unsignedint r_a_tov;
u8 opcode; int err = 0;
FC_RPORT_DBG(rdata, "Received a FLOGI %s\n",
IS_ERR(fp) ? "error" : fc_els_resp_type(fp));
if (fp == ERR_PTR(-FC_EX_CLOSED)) goto put;
mutex_lock(&rdata->rp_mutex);
if (rdata->rp_state != RPORT_ST_FLOGI) {
FC_RPORT_DBG(rdata, "Received a FLOGI response, but in state " "%s\n", fc_rport_state(rdata)); if (IS_ERR(fp)) goto err; goto out;
}
if (IS_ERR(fp)) {
fc_rport_error(rdata, PTR_ERR(fp)); goto err;
}
opcode = fc_frame_payload_op(fp); if (opcode == ELS_LS_RJT) { struct fc_els_ls_rjt *rjt;
/** * fc_rport_enter_flogi() - Send a FLOGI request to the remote port for p-mp * @rdata: The remote port to send a FLOGI to * * Reference counting: increments kref when sending ELS
*/ staticvoid fc_rport_enter_flogi(struct fc_rport_priv *rdata)
{ struct fc_lport *lport = rdata->local_port; struct fc_frame *fp;
lockdep_assert_held(&rdata->rp_mutex);
if (!lport->point_to_multipoint) return fc_rport_enter_plogi(rdata);
FC_RPORT_DBG(rdata, "Entered FLOGI state from %s state\n",
fc_rport_state(rdata));
fc_rport_state_enter(rdata, RPORT_ST_FLOGI);
fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi)); if (!fp) return fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
FC_RPORT_DBG(rdata, "Received FLOGI in %s state\n",
fc_rport_state(rdata));
switch (rdata->rp_state) { case RPORT_ST_INIT: /* * If received the FLOGI request on RPORT which is INIT state * (means not transition to FLOGI either fc_rport timeout * function didn;t trigger or this end hasn;t received * beacon yet from other end. In that case only, allow RPORT * state machine to continue, otherwise fall through which * causes the code to send reject response. * NOTE; Not checking for FIP->state such as VNMP_UP or * VNMP_CLAIM because if FIP state is not one of those, * RPORT wouldn;t have created and 'rport_lookup' would have * failed anyway in that case.
*/ break; case RPORT_ST_DELETE:
mutex_unlock(&rdata->rp_mutex);
rjt_data.reason = ELS_RJT_FIP;
rjt_data.explan = ELS_EXPL_NOT_NEIGHBOR; goto reject_put; case RPORT_ST_FLOGI: case RPORT_ST_PLOGI_WAIT: case RPORT_ST_PLOGI: break; case RPORT_ST_PRLI: case RPORT_ST_RTV: case RPORT_ST_READY: case RPORT_ST_ADISC: /* * Set the remote port to be deleted and to then restart. * This queues work to be sure exchanges are reset.
*/
fc_rport_enter_delete(rdata, RPORT_EV_LOGO);
mutex_unlock(&rdata->rp_mutex);
rjt_data.reason = ELS_RJT_BUSY;
rjt_data.explan = ELS_EXPL_NONE; goto reject_put;
} if (fc_rport_login_complete(rdata, fp)) {
mutex_unlock(&rdata->rp_mutex);
rjt_data.reason = ELS_RJT_LOGIC;
rjt_data.explan = ELS_EXPL_NONE; goto reject_put;
}
fp = fc_frame_alloc(lport, sizeof(*flp)); if (!fp) goto out;
/* * Do not proceed with the state machine if our * FLOGI has crossed with an FLOGI from the * remote port; wait for the FLOGI response instead.
*/ if (rdata->rp_state != RPORT_ST_FLOGI) { if (rdata->ids.port_name < lport->wwpn)
fc_rport_enter_plogi(rdata); else
fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
}
out:
mutex_unlock(&rdata->rp_mutex);
kref_put(&rdata->kref, fc_rport_destroy);
fc_frame_free(rx_fp); return;
/** * fc_rport_plogi_resp() - Handler for ELS PLOGI responses * @sp: The sequence the PLOGI is on * @fp: The PLOGI response frame * @rdata_arg: The remote port that sent the PLOGI response * * Locking Note: This function will be called without the rport lock * held, but it will lock, call an _enter_* function or fc_rport_error * and then unlock the rport.
*/ staticvoid fc_rport_plogi_resp(struct fc_seq *sp, struct fc_frame *fp, void *rdata_arg)
{ struct fc_rport_priv *rdata = rdata_arg; struct fc_lport *lport = rdata->local_port; struct fc_els_flogi *plp = NULL;
u16 csp_seq;
u16 cssp_seq;
u8 op;
FC_RPORT_DBG(rdata, "Received a PLOGI %s\n", fc_els_resp_type(fp));
if (fp == ERR_PTR(-FC_EX_CLOSED)) goto put;
mutex_lock(&rdata->rp_mutex);
if (rdata->rp_state != RPORT_ST_PLOGI) {
FC_RPORT_DBG(rdata, "Received a PLOGI response, but in state " "%s\n", fc_rport_state(rdata)); if (IS_ERR(fp)) goto err; goto out;
}
if (IS_ERR(fp)) {
fc_rport_error_retry(rdata, PTR_ERR(fp)); goto err;
}
/** * fc_rport_prli_resp() - Process Login (PRLI) response handler * @sp: The sequence the PRLI response was on * @fp: The PRLI response frame * @rdata_arg: The remote port that sent the PRLI response * * Locking Note: This function will be called without the rport lock * held, but it will lock, call an _enter_* function or fc_rport_error * and then unlock the rport.
*/ staticvoid fc_rport_prli_resp(struct fc_seq *sp, struct fc_frame *fp, void *rdata_arg)
{ struct fc_rport_priv *rdata = rdata_arg; struct { struct fc_els_prli prli; struct fc_els_spp spp;
} *pp; struct fc_els_spp temp_spp; struct fc_els_ls_rjt *rjt; struct fc4_prov *prov;
u32 roles = FC_RPORT_ROLE_UNKNOWN;
u32 fcp_parm = 0;
u8 op; enum fc_els_spp_resp resp_code;
FC_RPORT_DBG(rdata, "Received a PRLI %s\n", fc_els_resp_type(fp));
if (fp == ERR_PTR(-FC_EX_CLOSED)) goto put;
mutex_lock(&rdata->rp_mutex);
if (rdata->rp_state != RPORT_ST_PRLI) {
FC_RPORT_DBG(rdata, "Received a PRLI response, but in state " "%s\n", fc_rport_state(rdata)); if (IS_ERR(fp)) goto err; goto out;
}
if (IS_ERR(fp)) {
fc_rport_error_retry(rdata, PTR_ERR(fp)); goto err;
}
/* reinitialize remote port roles */
rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
op = fc_frame_payload_op(fp); if (op == ELS_LS_ACC) {
pp = fc_frame_payload_get(fp, sizeof(*pp)); if (!pp) {
fc_rport_error_retry(rdata, -FC_EX_SEQ_ERR); goto out;
}
rdata->spp_type = pp->spp.spp_type; if (resp_code != FC_SPP_RESP_ACK) { if (resp_code == FC_SPP_RESP_CONF)
fc_rport_error(rdata, -FC_EX_SEQ_ERR); else
fc_rport_error_retry(rdata, -FC_EX_SEQ_ERR); goto out;
} if (pp->prli.prli_spp_len < sizeof(pp->spp)) {
fc_rport_error_retry(rdata, -FC_EX_SEQ_ERR); goto out;
}
fcp_parm = ntohl(pp->spp.spp_params); if (fcp_parm & FCP_SPPF_RETRY)
rdata->flags |= FC_RP_FLAGS_RETRY; if (fcp_parm & FCP_SPPF_CONF_COMPL)
rdata->flags |= FC_RP_FLAGS_CONF_REQ;
/* * Call prli provider if we should act as a target
*/ if (rdata->spp_type < FC_FC4_PROV_SIZE) {
prov = fc_passive_prov[rdata->spp_type]; if (prov) {
memset(&temp_spp, 0, sizeof(temp_spp));
prov->prli(rdata, pp->prli.prli_spp_len,
&pp->spp, &temp_spp);
}
} /* * Check if the image pair could be established
*/ if (rdata->spp_type != FC_TYPE_FCP ||
!(pp->spp.spp_flags & FC_SPP_EST_IMG_PAIR)) { /* * Nope; we can't use this port as a target.
*/
fcp_parm &= ~FCP_SPPF_TARG_FCN;
}
rdata->supported_classes = FC_COS_CLASS3; if (fcp_parm & FCP_SPPF_INIT_FCN)
roles |= FC_RPORT_ROLE_FCP_INITIATOR; if (fcp_parm & FCP_SPPF_TARG_FCN)
roles |= FC_RPORT_ROLE_FCP_TARGET;
/** * fc_rport_enter_prli() - Send Process Login (PRLI) request * @rdata: The remote port to send the PRLI request to * * Reference counting: increments kref when sending ELS
*/ staticvoid fc_rport_enter_prli(struct fc_rport_priv *rdata)
{ struct fc_lport *lport = rdata->local_port; struct { struct fc_els_prli prli; struct fc_els_spp spp;
} *pp; struct fc_frame *fp; struct fc4_prov *prov;
lockdep_assert_held(&rdata->rp_mutex);
/* * If the rport is one of the well known addresses * we skip PRLI and RTV and go straight to READY.
*/ if (rdata->ids.port_id >= FC_FID_DOM_MGR) {
fc_rport_enter_ready(rdata); return;
}
/* * And if the local port does not support the initiator function * there's no need to send a PRLI, either.
*/ if (!(lport->service_params & FCP_SPPF_INIT_FCN)) {
fc_rport_enter_ready(rdata); return;
}
FC_RPORT_DBG(rdata, "Port entered PRLI state from %s state\n",
fc_rport_state(rdata));
/** * fc_rport_rtv_resp() - Handler for Request Timeout Value (RTV) responses * @sp: The sequence the RTV was on * @fp: The RTV response frame * @rdata_arg: The remote port that sent the RTV response * * Many targets don't seem to support this. * * Locking Note: This function will be called without the rport lock * held, but it will lock, call an _enter_* function or fc_rport_error * and then unlock the rport.
*/ staticvoid fc_rport_rtv_resp(struct fc_seq *sp, struct fc_frame *fp, void *rdata_arg)
{ struct fc_rport_priv *rdata = rdata_arg;
u8 op;
FC_RPORT_DBG(rdata, "Received a RTV %s\n", fc_els_resp_type(fp));
if (fp == ERR_PTR(-FC_EX_CLOSED)) goto put;
mutex_lock(&rdata->rp_mutex);
if (rdata->rp_state != RPORT_ST_RTV) {
FC_RPORT_DBG(rdata, "Received a RTV response, but in state " "%s\n", fc_rport_state(rdata)); if (IS_ERR(fp)) goto err; goto out;
}
if (IS_ERR(fp)) {
fc_rport_error(rdata, PTR_ERR(fp)); goto err;
}
op = fc_frame_payload_op(fp); if (op == ELS_LS_ACC) { struct fc_els_rtv_acc *rtv;
u32 toq;
u32 tov;
rtv = fc_frame_payload_get(fp, sizeof(*rtv)); if (rtv) {
toq = ntohl(rtv->rtv_toq);
tov = ntohl(rtv->rtv_r_a_tov); if (tov == 0)
tov = 1; if (tov > rdata->r_a_tov)
rdata->r_a_tov = tov;
tov = ntohl(rtv->rtv_e_d_tov); if (toq & FC_ELS_RTV_EDRES)
tov /= 1000000; if (tov == 0)
tov = 1; if (tov > rdata->e_d_tov)
rdata->e_d_tov = tov;
}
}
/** * fc_rport_enter_rtv() - Send Request Timeout Value (RTV) request * @rdata: The remote port to send the RTV request to * * Reference counting: increments kref when sending ELS
*/ staticvoid fc_rport_enter_rtv(struct fc_rport_priv *rdata)
{ struct fc_frame *fp; struct fc_lport *lport = rdata->local_port;
lockdep_assert_held(&rdata->rp_mutex);
FC_RPORT_DBG(rdata, "Port entered RTV state from %s state\n",
fc_rport_state(rdata));
/** * fc_rport_recv_rtv_req() - Handler for Read Timeout Value (RTV) requests * @rdata: The remote port that sent the RTV request * @in_fp: The RTV request frame
*/ staticvoid fc_rport_recv_rtv_req(struct fc_rport_priv *rdata, struct fc_frame *in_fp)
{ struct fc_lport *lport = rdata->local_port; struct fc_frame *fp; struct fc_els_rtv_acc *rtv; struct fc_seq_els_data rjt_data;
/** * fc_rport_logo_resp() - Handler for logout (LOGO) responses * @sp: The sequence the LOGO was on * @fp: The LOGO response frame * @rdata_arg: The remote port
*/ staticvoid fc_rport_logo_resp(struct fc_seq *sp, struct fc_frame *fp, void *rdata_arg)
{ struct fc_rport_priv *rdata = rdata_arg; struct fc_lport *lport = rdata->local_port;
FC_RPORT_ID_DBG(lport, fc_seq_exch(sp)->did, "Received a LOGO %s\n", fc_els_resp_type(fp)); if (!IS_ERR(fp))
fc_frame_free(fp);
kref_put(&rdata->kref, fc_rport_destroy);
}
/** * fc_rport_enter_logo() - Send a logout (LOGO) request * @rdata: The remote port to send the LOGO request to * * Reference counting: increments kref when sending ELS
*/ staticvoid fc_rport_enter_logo(struct fc_rport_priv *rdata)
{ struct fc_lport *lport = rdata->local_port; struct fc_frame *fp;
lockdep_assert_held(&rdata->rp_mutex);
FC_RPORT_DBG(rdata, "Port sending LOGO from %s state\n",
fc_rport_state(rdata));
fp = fc_frame_alloc(lport, sizeof(struct fc_els_logo)); if (!fp) return;
kref_get(&rdata->kref); if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_LOGO,
fc_rport_logo_resp, rdata, 0))
kref_put(&rdata->kref, fc_rport_destroy);
}
/** * fc_rport_adisc_resp() - Handler for Address Discovery (ADISC) responses * @sp: The sequence the ADISC response was on * @fp: The ADISC response frame * @rdata_arg: The remote port that sent the ADISC response * * Locking Note: This function will be called without the rport lock * held, but it will lock, call an _enter_* function or fc_rport_error * and then unlock the rport.
*/ staticvoid fc_rport_adisc_resp(struct fc_seq *sp, struct fc_frame *fp, void *rdata_arg)
{ struct fc_rport_priv *rdata = rdata_arg; struct fc_els_adisc *adisc;
u8 op;
FC_RPORT_DBG(rdata, "Received a ADISC response\n");
if (fp == ERR_PTR(-FC_EX_CLOSED)) goto put;
mutex_lock(&rdata->rp_mutex);
if (rdata->rp_state != RPORT_ST_ADISC) {
FC_RPORT_DBG(rdata, "Received a ADISC resp but in state %s\n",
fc_rport_state(rdata)); if (IS_ERR(fp)) goto err; goto out;
}
if (IS_ERR(fp)) {
fc_rport_error(rdata, PTR_ERR(fp)); goto err;
}
/* * If address verification failed. Consider us logged out of the rport. * Since the rport is still in discovery, we want to be * logged in, so go to PLOGI state. Otherwise, go back to READY.
*/
op = fc_frame_payload_op(fp);
adisc = fc_frame_payload_get(fp, sizeof(*adisc)); if (op != ELS_LS_ACC || !adisc ||
ntoh24(adisc->adisc_port_id) != rdata->ids.port_id ||
get_unaligned_be64(&adisc->adisc_wwpn) != rdata->ids.port_name ||
get_unaligned_be64(&adisc->adisc_wwnn) != rdata->ids.node_name) {
FC_RPORT_DBG(rdata, "ADISC error or mismatch\n");
fc_rport_enter_flogi(rdata);
} else {
FC_RPORT_DBG(rdata, "ADISC OK\n");
fc_rport_enter_ready(rdata);
}
out:
fc_frame_free(fp);
err:
mutex_unlock(&rdata->rp_mutex);
put:
kref_put(&rdata->kref, fc_rport_destroy);
}
/** * fc_rport_enter_adisc() - Send Address Discover (ADISC) request * @rdata: The remote port to send the ADISC request to * * Reference counting: increments kref when sending ELS
*/ staticvoid fc_rport_enter_adisc(struct fc_rport_priv *rdata)
{ struct fc_lport *lport = rdata->local_port; struct fc_frame *fp;
lockdep_assert_held(&rdata->rp_mutex);
FC_RPORT_DBG(rdata, "sending ADISC from %s state\n",
fc_rport_state(rdata));
/** * fc_rport_recv_rls_req() - Handle received Read Link Status request * @rdata: The remote port that sent the RLS request * @rx_fp: The PRLI request frame
*/ staticvoid fc_rport_recv_rls_req(struct fc_rport_priv *rdata, struct fc_frame *rx_fp)
/** * fc_rport_recv_els_req() - Handler for validated ELS requests * @lport: The local port that received the ELS request * @fp: The ELS request frame * * Handle incoming ELS requests that require port login. * The ELS opcode has already been validated by the caller. * * Reference counting: does not modify kref
*/ staticvoid fc_rport_recv_els_req(struct fc_lport *lport, struct fc_frame *fp)
{ struct fc_rport_priv *rdata; struct fc_seq_els_data els_data;
lockdep_assert_held(&lport->lp_mutex);
rdata = fc_rport_lookup(lport, fc_frame_sid(fp)); if (!rdata) {
FC_RPORT_ID_DBG(lport, fc_frame_sid(fp), "Received ELS 0x%02x from non-logged-in port\n",
fc_frame_payload_op(fp)); goto reject;
}
mutex_lock(&rdata->rp_mutex);
switch (rdata->rp_state) { case RPORT_ST_PRLI: case RPORT_ST_RTV: case RPORT_ST_READY: case RPORT_ST_ADISC: break; case RPORT_ST_PLOGI: if (fc_frame_payload_op(fp) == ELS_PRLI) {
FC_RPORT_DBG(rdata, "Reject ELS PRLI " "while in state %s\n",
fc_rport_state(rdata));
mutex_unlock(&rdata->rp_mutex);
kref_put(&rdata->kref, fc_rport_destroy); goto busy;
}
fallthrough; default:
FC_RPORT_DBG(rdata, "Reject ELS 0x%02x while in state %s\n",
fc_frame_payload_op(fp), fc_rport_state(rdata));
mutex_unlock(&rdata->rp_mutex);
kref_put(&rdata->kref, fc_rport_destroy); goto reject;
}
switch (fc_frame_payload_op(fp)) { case ELS_PRLI:
fc_rport_recv_prli_req(rdata, fp); break; case ELS_PRLO:
fc_rport_recv_prlo_req(rdata, fp); break; case ELS_ADISC:
fc_rport_recv_adisc_req(rdata, fp); break; case ELS_RRQ:
fc_seq_els_rsp_send(fp, ELS_RRQ, NULL);
fc_frame_free(fp); break; case ELS_REC:
fc_seq_els_rsp_send(fp, ELS_REC, NULL);
fc_frame_free(fp); break; case ELS_RLS:
fc_rport_recv_rls_req(rdata, fp); break; case ELS_RTV:
fc_rport_recv_rtv_req(rdata, fp); break; default:
fc_frame_free(fp); /* can't happen */ break;
}
/** * fc_rport_recv_req() - Handler for requests * @lport: The local port that received the request * @fp: The request frame * * Reference counting: does not modify kref
*/ void fc_rport_recv_req(struct fc_lport *lport, struct fc_frame *fp)
{ struct fc_seq_els_data els_data;
lockdep_assert_held(&lport->lp_mutex);
/* * Handle FLOGI, PLOGI and LOGO requests separately, since they * don't require prior login. * Check for unsupported opcodes first and reject them. * For some ops, it would be incorrect to reject with "PLOGI required".
*/ switch (fc_frame_payload_op(fp)) { case ELS_FLOGI:
fc_rport_recv_flogi_req(lport, fp); break; case ELS_PLOGI:
fc_rport_recv_plogi_req(lport, fp); break; case ELS_LOGO:
fc_rport_recv_logo_req(lport, fp); break; case ELS_PRLI: case ELS_PRLO: case ELS_ADISC: case ELS_RRQ: case ELS_REC: case ELS_RLS: case ELS_RTV:
fc_rport_recv_els_req(lport, fp); break; default:
els_data.reason = ELS_RJT_UNSUP;
els_data.explan = ELS_EXPL_NONE;
fc_seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
fc_frame_free(fp); break;
}
}
EXPORT_SYMBOL(fc_rport_recv_req);
/** * fc_rport_recv_plogi_req() - Handler for Port Login (PLOGI) requests * @lport: The local port that received the PLOGI request * @rx_fp: The PLOGI request frame * * Reference counting: increments kref on return
*/ staticvoid fc_rport_recv_plogi_req(struct fc_lport *lport, struct fc_frame *rx_fp)
{ struct fc_disc *disc; struct fc_rport_priv *rdata; struct fc_frame *fp = rx_fp; struct fc_els_flogi *pl; struct fc_seq_els_data rjt_data;
u32 sid;
/* * If the rport was just created, possibly due to the incoming PLOGI, * set the state appropriately and accept the PLOGI. * * If we had also sent a PLOGI, and if the received PLOGI is from a * higher WWPN, we accept it, otherwise an LS_RJT is sent with reason * "command already in progress". * * XXX TBD: If the session was ready before, the PLOGI should result in * all outstanding exchanges being reset.
*/ switch (rdata->rp_state) { case RPORT_ST_INIT:
FC_RPORT_DBG(rdata, "Received PLOGI in INIT state\n"); break; case RPORT_ST_PLOGI_WAIT:
FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI_WAIT state\n"); break; case RPORT_ST_PLOGI:
FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI state\n"); if (rdata->ids.port_name < lport->wwpn) {
mutex_unlock(&rdata->rp_mutex);
rjt_data.reason = ELS_RJT_INPROG;
rjt_data.explan = ELS_EXPL_NONE; goto reject;
} break; case RPORT_ST_PRLI: case RPORT_ST_RTV: case RPORT_ST_READY: case RPORT_ST_ADISC:
FC_RPORT_DBG(rdata, "Received PLOGI in logged-in state %d " "- ignored for now\n", rdata->rp_state); /* XXX TBD - should reset */ break; case RPORT_ST_FLOGI: case RPORT_ST_DELETE:
FC_RPORT_DBG(rdata, "Received PLOGI in state %s - send busy\n",
fc_rport_state(rdata));
mutex_unlock(&rdata->rp_mutex);
rjt_data.reason = ELS_RJT_BUSY;
rjt_data.explan = ELS_EXPL_NONE; goto reject;
} if (!fc_rport_compatible_roles(lport, rdata)) {
FC_RPORT_DBG(rdata, "Received PLOGI for incompatible role\n");
mutex_unlock(&rdata->rp_mutex);
rjt_data.reason = ELS_RJT_LOGIC;
rjt_data.explan = ELS_EXPL_NONE; goto reject;
}
/* * Get session payload size from incoming PLOGI.
*/
rdata->maxframe_size = fc_plogi_get_maxframe(pl, lport->mfs);
/* * Send LS_ACC. If this fails, the originator should retry.
*/
fp = fc_frame_alloc(lport, sizeof(*pl)); if (!fp) goto out;
/* * Go through all the service parameter pages and build * response. If plen indicates longer SPP than standard, * use that. The entire response has been pre-cleared above.
*/
spp = &pp->spp;
mutex_lock(&fc_prov_mutex); while (len >= plen) {
rdata->spp_type = rspp->spp_type;
spp->spp_type = rspp->spp_type;
spp->spp_type_ext = rspp->spp_type_ext;
resp = 0;
if (rspp->spp_type < FC_FC4_PROV_SIZE) { enum fc_els_spp_resp active = 0, passive = 0;
/** * fc_rport_recv_logo_req() - Handler for logout (LOGO) requests * @lport: The local port that received the LOGO request * @fp: The LOGO request frame * * Reference counting: drops kref on return
*/ staticvoid fc_rport_recv_logo_req(struct fc_lport *lport, struct fc_frame *fp)
{ struct fc_rport_priv *rdata;
u32 sid;
lockdep_assert_held(&lport->lp_mutex);
fc_seq_els_rsp_send(fp, ELS_LS_ACC, NULL);
sid = fc_frame_sid(fp);
rdata = fc_rport_lookup(lport, sid); if (rdata) {
mutex_lock(&rdata->rp_mutex);
FC_RPORT_DBG(rdata, "Received LOGO request while in state %s\n",
fc_rport_state(rdata));
fc_rport_enter_delete(rdata, RPORT_EV_STOP);
mutex_unlock(&rdata->rp_mutex);
kref_put(&rdata->kref, fc_rport_destroy);
} else
FC_RPORT_ID_DBG(lport, sid, "Received LOGO from non-logged-in port\n");
fc_frame_free(fp);
}
/** * fc_rport_fcp_prli() - Handle incoming PRLI for the FCP initiator. * @rdata: remote port private * @spp_len: service parameter page length * @rspp: received service parameter page * @spp: response service parameter page * * Returns the value for the response code to be placed in spp_flags; * Returns 0 if not an initiator.
*/ staticint fc_rport_fcp_prli(struct fc_rport_priv *rdata, u32 spp_len, conststruct fc_els_spp *rspp, struct fc_els_spp *spp)
{ struct fc_lport *lport = rdata->local_port;
u32 fcp_parm;
fcp_parm = ntohl(rspp->spp_params);
rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN; if (fcp_parm & FCP_SPPF_INIT_FCN)
rdata->ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; if (fcp_parm & FCP_SPPF_TARG_FCN)
rdata->ids.roles |= FC_RPORT_ROLE_FCP_TARGET; if (fcp_parm & FCP_SPPF_RETRY)
rdata->flags |= FC_RP_FLAGS_RETRY;
rdata->supported_classes = FC_COS_CLASS3;
if (!(lport->service_params & FCP_SPPF_INIT_FCN)) return 0;
/* * OR in our service parameters with other providers (target), if any.
*/
fcp_parm = ntohl(spp->spp_params);
spp->spp_params = htonl(fcp_parm | lport->service_params); return FC_SPP_RESP_ACK;
}
/** * fc_rport_t0_prli() - Handle incoming PRLI parameters for type 0 * @rdata: remote port private * @spp_len: service parameter page length * @rspp: received service parameter page * @spp: response service parameter page
*/ staticint fc_rport_t0_prli(struct fc_rport_priv *rdata, u32 spp_len, conststruct fc_els_spp *rspp, struct fc_els_spp *spp)
{ if (rspp->spp_flags & FC_SPP_EST_IMG_PAIR) return FC_SPP_RESP_INVL; return FC_SPP_RESP_ACK;
}
/* * FC-4 provider ops for type 0 service parameters. * * This handles the special case of type 0 which is always successful * but doesn't do anything otherwise.
*/ struct fc4_prov fc_rport_t0_prov = {
.prli = fc_rport_t0_prli,
};
/** * fc_setup_rport() - Initialize the rport_event_queue
*/ int fc_setup_rport(void)
{
rport_event_queue =
alloc_ordered_workqueue("%s", WQ_MEM_RECLAIM, "fc_rport_eq"); if (!rport_event_queue) return -ENOMEM; return 0;
}
/** * fc_rport_terminate_io() - Stop all outstanding I/O on a remote port * @rport: The remote port whose I/O should be terminated
*/ void fc_rport_terminate_io(struct fc_rport *rport)
{ struct fc_rport_libfc_priv *rpriv = rport->dd_data; struct fc_lport *lport = rpriv->local_port;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.