cregit-Linux how code gets into the kernel

Release 4.11 drivers/scsi/libfc/fc_rport.c

/*
 * Copyright(c) 2007 - 2008 Intel Corporation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * 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
 */

#include <linux/kernel.h>
#include <linux/spinlock.h>
#include <linux/interrupt.h>
#include <linux/slab.h>
#include <linux/rcupdate.h>
#include <linux/timer.h>
#include <linux/workqueue.h>
#include <linux/export.h>
#include <linux/rculist.h>

#include <asm/unaligned.h>

#include <scsi/libfc.h>
#include <scsi/fc_encode.h>

#include "fc_libfc.h"


static struct workqueue_struct *rport_event_queue;

static void fc_rport_enter_flogi(struct fc_rport_priv *);
static void fc_rport_enter_plogi(struct fc_rport_priv *);
static void fc_rport_enter_prli(struct fc_rport_priv *);
static void fc_rport_enter_rtv(struct fc_rport_priv *);
static void fc_rport_enter_ready(struct fc_rport_priv *);
static void fc_rport_enter_logo(struct fc_rport_priv *);
static void fc_rport_enter_adisc(struct fc_rport_priv *);

static void fc_rport_recv_plogi_req(struct fc_lport *, struct fc_frame *);
static void fc_rport_recv_prli_req(struct fc_rport_priv *, struct fc_frame *);
static void fc_rport_recv_prlo_req(struct fc_rport_priv *, struct fc_frame *);
static void fc_rport_recv_logo_req(struct fc_lport *, struct fc_frame *);
static void fc_rport_timeout(struct work_struct *);
static void fc_rport_error(struct fc_rport_priv *, int);
static void fc_rport_error_retry(struct fc_rport_priv *, int);
static void fc_rport_work(struct work_struct *);


static const char *fc_rport_state_names[] = {
	[RPORT_ST_INIT] = "Init",
	[RPORT_ST_FLOGI] = "FLOGI",
	[RPORT_ST_PLOGI_WAIT] = "PLOGI_WAIT",
	[RPORT_ST_PLOGI] = "PLOGI",
	[RPORT_ST_PRLI] = "PRLI",
	[RPORT_ST_RTV] = "RTV",
	[RPORT_ST_READY] = "Ready",
	[RPORT_ST_ADISC] = "ADISC",
	[RPORT_ST_DELETE] = "Delete",
};

/**
 * 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(const struct fc_lport *lport, u32 port_id) { struct fc_rport_priv *rdata = NULL, *tmp_rdata; rcu_read_lock(); list_for_each_entry_rcu(tmp_rdata, &lport->disc.rports, peers) if (tmp_rdata->ids.port_id == port_id && kref_get_unless_zero(&tmp_rdata->kref)) { rdata = tmp_rdata; break; } rcu_read_unlock(); return rdata; }

Contributors

PersonTokensPropCommitsCommitProp
Joe Eykholt4058.82%266.67%
Hannes Reinecke2841.18%133.33%
Total68100.00%3100.00%

EXPORT_SYMBOL(fc_rport_lookup); /** * fc_rport_create() - Create a new remote port * @lport: The local port this remote port will be associated with * @ids: The identifiers for the new remote port * * The remote port will start in the INIT state. * * Locking note: must be called with the disc_mutex held. */
struct fc_rport_priv *fc_rport_create(struct fc_lport *lport, u32 port_id) { struct fc_rport_priv *rdata; rdata = fc_rport_lookup(lport, port_id); if (rdata) return rdata; rdata = kzalloc(sizeof(*rdata) + lport->rport_priv_size, GFP_KERNEL); if (!rdata) return NULL; rdata->ids.node_name = -1; rdata->ids.port_name = -1; rdata->ids.port_id = port_id; rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN; kref_init(&rdata->kref); mutex_init(&rdata->rp_mutex); rdata->local_port = lport; rdata->rp_state = RPORT_ST_INIT; rdata->event = RPORT_EV_NONE; rdata->flags = FC_RP_FLAGS_REC_SUPPORTED; rdata->e_d_tov = lport->e_d_tov; rdata->r_a_tov = lport->r_a_tov; rdata->maxframe_size = FC_MIN_MAX_PAYLOAD; INIT_DELAYED_WORK(&rdata->retry_work, fc_rport_timeout); INIT_WORK(&rdata->event_work, fc_rport_work); if (port_id != FC_FID_DIR_SERV) { rdata->lld_event_callback = lport->tt.rport_event_callback; list_add_rcu(&rdata->peers, &lport->disc.rports); } return rdata; }

Contributors

PersonTokensPropCommitsCommitProp
Robert Love12960.56%215.38%
Joe Eykholt7133.33%969.23%
Bhanu Prakash Gollapudi125.63%17.69%
Hannes Reinecke10.47%17.69%
Total213100.00%13100.00%

EXPORT_SYMBOL(fc_rport_create); /** * 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; rdata = container_of(kref, struct fc_rport_priv, kref); kfree_rcu(rdata, rcu); }

Contributors

PersonTokensPropCommitsCommitProp
Joe Eykholt3294.12%375.00%
Lai Jiangshan25.88%125.00%
Total34100.00%4100.00%

EXPORT_SYMBOL(fc_rport_destroy); /** * fc_rport_state() - Return a string identifying the remote port's state * @rdata: The remote port */
static const char *fc_rport_state(struct fc_rport_priv *rdata) { const char *cp; cp = fc_rport_state_names[rdata->rp_state]; if (!cp) cp = "Unknown"; return cp; }

Contributors

PersonTokensPropCommitsCommitProp
Robert Love3794.87%150.00%
Joe Eykholt25.13%150.00%
Total39100.00%2100.00%

/** * 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; }

Contributors

PersonTokensPropCommitsCommitProp
Robert Love2996.67%150.00%
Mike Christie13.33%150.00%
Total30100.00%2100.00%

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 */
static unsigned int fc_plogi_get_maxframe(struct fc_els_flogi *flp, unsigned int maxval) { unsigned int 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; }

Contributors

PersonTokensPropCommitsCommitProp
Robert Love81100.00%1100.00%
Total81100.00%1100.00%

/** * fc_rport_state_enter() - Change the state of a remote port * @rdata: The remote port whose state should change * @new: The new state * * Locking Note: Called with the rport lock held */
static void fc_rport_state_enter(struct fc_rport_priv *rdata, enum fc_rport_state new) { if (rdata->rp_state != new) rdata->retries = 0; rdata->rp_state = new; }

Contributors

PersonTokensPropCommitsCommitProp
Robert Love3394.29%150.00%
Joe Eykholt25.71%150.00%
Total35100.00%2100.00%

/** * fc_rport_work() - Handler for remote port events in the rport_event_queue * @work: Handle to the remote port being dequeued * * Reference counting: drops kref on return */
static void fc_rport_work(struct work_struct *work) { u32 port_id; struct fc_rport_priv *rdata = container_of(work, struct fc_rport_priv, event_work); struct fc_rport_libfc_priv *rpriv; enum fc_rport_event event; struct fc_lport *lport = rdata->local_port; struct fc_rport_operations *rport_ops; struct fc_rport_identifiers ids; struct fc_rport *rport; struct fc4_prov *prov; u8 type; mutex_lock(&rdata->rp_mutex); event = rdata->event; rport_ops = rdata->ops; rport = rdata->rport; FC_RPORT_DBG(rdata, "work event %u\n", event); switch (event) { case RPORT_EV_READY: ids = rdata->ids; rdata->event = RPORT_EV_NONE; rdata->major_retries = 0; kref_get(&rdata->kref); mutex_unlock(&rdata->rp_mutex); if (!rport) { FC_RPORT_DBG(rdata, "No rport!\n"); rport = fc_remote_port_add(lport->host, 0, &ids); } if (!rport) { FC_RPORT_DBG(rdata, "Failed to add the rport\n"); fc_rport_logoff(rdata); kref_put(&rdata->kref, fc_rport_destroy); return; } mutex_lock(&rdata->rp_mutex); if (rdata->rport) FC_RPORT_DBG(rdata, "rport already allocated\n"); rdata->rport = rport; rport->maxframe_size = rdata->maxframe_size; rport->supported_classes = rdata->supported_classes; rpriv = rport->dd_data; rpriv->local_port = lport; rpriv->rp_state = rdata->rp_state; rpriv->flags = rdata->flags; rpriv->e_d_tov = rdata->e_d_tov; rpriv->r_a_tov = rdata->r_a_tov; 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); } 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); if (rport) { rpriv = rport->dd_data; rpriv->rp_state = RPORT_ST_DELETE; mutex_lock(&rdata->rp_mutex); rdata->rport = NULL; mutex_unlock(&rdata->rp_mutex); fc_remote_port_delete(rport); } mutex_lock(&rdata->rp_mutex); if (rdata->rp_state == RPORT_ST_DELETE) { if (port_id == FC_FID_DIR_SERV) { rdata->event = RPORT_EV_NONE; mutex_unlock(&rdata->rp_mutex); kref_put(&rdata->kref, fc_rport_destroy); } else if ((rdata->flags & FC_RP_STARTED) && rdata->major_retries < lport->max_rport_retry_count) { rdata->major_retries++; rdata->event = RPORT_EV_NONE; FC_RPORT_DBG(rdata, "work restart\n"); fc_rport_enter_flogi(rdata); mutex_unlock(&rdata->rp_mutex); } else { FC_RPORT_DBG(rdata, "work delete\n"); mutex_lock(&lport->disc.disc_mutex); list_del_rcu(&rdata->peers); mutex_unlock(&lport->disc.disc_mutex); mutex_unlock(&rdata->rp_mutex); kref_put(&rdata->kref, fc_rport_destroy); } } else { /* * Re-open for events. Reissue READY event if ready. */ rdata->event = RPORT_EV_NONE; if (rdata->rp_state == RPORT_ST_READY) { FC_RPORT_DBG(rdata, "work reopen\n"); fc_rport_enter_ready(rdata); } mutex_unlock(&rdata->rp_mutex); } break; default: mutex_unlock(&rdata->rp_mutex); break; } kref_put(&rdata->kref, fc_rport_destroy); }

Contributors

PersonTokensPropCommitsCommitProp
Joe Eykholt45955.98%1557.69%
Robert Love18622.68%27.69%
Hannes Reinecke657.93%519.23%
Bhanu Prakash Gollapudi566.83%13.85%
Abhijeet Joglekar455.49%27.69%
Neerav Parikh91.10%13.85%
Total820100.00%26100.00%

/** * 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); if (rdata->flags & FC_RP_STARTED) { FC_RPORT_DBG(rdata, "port already started\n"); mutex_unlock(&rdata->rp_mutex); return 0; } 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; }

Contributors

PersonTokensPropCommitsCommitProp
Joe Eykholt4837.50%660.00%
Hannes Reinecke4535.16%220.00%
Robert Love3527.34%220.00%
Total128100.00%10100.00%

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 * * Locking Note: Called with the rport lock held. * * 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 */
static void fc_rport_enter_delete(struct fc_rport_priv *rdata, enum fc_rport_event event) { if (rdata->rp_state == RPORT_ST_DELETE) return; FC_RPORT_DBG(rdata, "Delete port\n"); fc_rport_state_enter(rdata, RPORT_ST_DELETE); 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 = event; }

Contributors

PersonTokensPropCommitsCommitProp
Joe Eykholt6175.31%250.00%
Hannes Reinecke2024.69%250.00%
Total81100.00%4100.00%

/** * 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; }

Contributors

PersonTokensPropCommitsCommitProp
Hannes Reinecke4536.59%110.00%
Robert Love4334.96%220.00%
Joe Eykholt2016.26%660.00%
Abhijeet Joglekar1512.20%110.00%
Total123100.00%10100.00%

EXPORT_SYMBOL(fc_rport_logoff); /** * fc_rport_enter_ready() - Transition to the RPORT_ST_READY state * @rdata: The remote port that is ready * * Locking Note: The rport lock is expected to be held before calling * this routine. * * Reference counting: schedules workqueue, does not modify kref */
static void fc_rport_enter_ready(struct fc_rport_priv *rdata) { 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; }

Contributors

PersonTokensPropCommitsCommitProp
Robert Love3348.53%225.00%
Hannes Reinecke2029.41%225.00%
Joe Eykholt1522.06%450.00%
Total68100.00%8100.00%

/** * 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. */
static void 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; } mutex_unlock(&rdata->rp_mutex); kref_put(&rdata->kref, fc_rport_destroy); }

Contributors

PersonTokensPropCommitsCommitProp
Robert Love8362.88%111.11%
Joe Eykholt2720.45%555.56%
Hannes Reinecke2216.67%333.33%
Total132100.00%9100.00%

/** * fc_rport_error() - Error handler, called once retries have been exhausted * @rdata: The remote port the error is happened on * @err: The error code * * Locking Note: The rport lock is expected to be held before * calling this routine * * Reference counting: does not modify kref */
static void fc_rport_error(struct fc_rport_priv *rdata, int err) { struct fc_lport *lport = rdata->local_port; 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: 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; } }

Contributors

PersonTokensPropCommitsCommitProp
Joe Eykholt4735.07%545.45%
Hannes Reinecke4231.34%218.18%
Robert Love2417.91%218.18%
Christopher Leech1914.18%19.09%
Abhijeet Joglekar21.49%19.09%
Total134100.00%11100.00%

/** * 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. * * Locking Note: The rport lock is expected to be held before * calling this routine * * Reference counting: increments kref when scheduling retry_work */
static void fc_rport_error_retry(struct fc_rport_priv *rdata, int err) { unsigned long delay = msecs_to_jiffies(rdata->e_d_tov); /* 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); }

Contributors

PersonTokensPropCommitsCommitProp
Joe Eykholt8267.21%114.29%
Hannes Reinecke3125.41%457.14%
Hillf Danton64.92%114.29%
Krishna Mohan32.46%114.29%
Total122100.00%7100.00%

/** * 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. */
static int 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; unsigned int 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; }

Contributors

PersonTokensPropCommitsCommitProp
Joe Eykholt155100.00%1100.00%
Total155100.00%1100.00%

/** * 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 */
static void 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; unsigned int 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; rjt = fc_frame_payload_get(fp, sizeof(*rjt)); FC_RPORT_DBG(rdata, "FLOGI ELS rejected, reason %x expl %x\n", rjt->er_reason, rjt->er_explan); err = -FC_EX_ELS_RJT; goto bad; } else if (opcode != ELS_LS_ACC) { FC_RPORT_DBG(rdata, "FLOGI ELS invalid opcode %x\n", opcode); err = -FC_EX_ELS_RJT; goto bad; } if (fc_rport_login_complete(rdata, fp)) { FC_RPORT_DBG(rdata, "FLOGI failed, no login\n"); err = -FC_EX_INV_LOGIN; goto bad; } flogi = fc_frame_payload_get(fp, sizeof(*flogi)); if (!flogi) { err = -FC_EX_ALLOC_ERR; goto bad; } r_a_tov = ntohl(flogi->fl_csp.sp_r_a_tov); if (r_a_tov > rdata->r_a_tov) rdata->r_a_tov = r_a_tov; if (rdata->ids.port_name < lport->wwpn) fc_rport_enter_plogi(rdata); else fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT); out: fc_frame_free(fp); err: mutex_unlock(&rdata->rp_mutex); put: kref_put(&rdata->kref, fc_rport_destroy); return; bad: FC_RPORT_DBG(rdata, "Bad FLOGI response\n"); fc_rport_error_retry(rdata, err); goto out; }

Contributors

PersonTokensPropCommitsCommitProp
Joe Eykholt26167.62%116.67%
Hannes Reinecke11930.83%350.00%
Hillf Danton51.30%116.67%
Bart Van Assche10.26%116.67%
Total386100.00%6100.00%

/** * fc_rport_enter_flogi() - Send a FLOGI request to the remote port for p-mp * @rdata: The remote port to send a FLOGI to * * Locking Note: The rport lock is expected to be held before calling * this routine. * * Reference counting: increments kref when sending ELS */
static void fc_rport_enter_flogi(struct fc_rport_priv *rdata) { struct fc_lport *lport = rdata->local_port; struct fc_frame *fp;