Commit 9fb9d328 authored by Joe Eykholt's avatar Joe Eykholt Committed by James Bottomley

[SCSI] libfc: make fc_rport_priv the primary rport interface.

The rport and discovery modules deal with remote ports
before fc_remote_port_add() can be done, because the
full set of rport identifiers is not known at early stages.

In preparation for splitting the fc_rport/fc_rport_priv allocation,
make fc_rport_priv the primary interface for the remote port and
discovery engines.

The FCP / SCSI layers still deal with fc_rport and
fc_rport_libfc_priv, however.
Signed-off-by: default avatarJoe Eykholt <jeykholt@cisco.com>
Signed-off-by: default avatarRobert Love <robert.w.love@intel.com>
Signed-off-by: default avatarJames Bottomley <James.Bottomley@suse.de>
parent 922aa210
......@@ -49,7 +49,6 @@ static void fc_disc_gpn_ft_req(struct fc_disc *);
static void fc_disc_gpn_ft_resp(struct fc_seq *, struct fc_frame *, void *);
static int fc_disc_new_target(struct fc_disc *, struct fc_rport *,
struct fc_rport_identifiers *);
static void fc_disc_del_target(struct fc_disc *, struct fc_rport *);
static void fc_disc_done(struct fc_disc *);
static void fc_disc_timeout(struct work_struct *);
static void fc_disc_single(struct fc_disc *, struct fc_disc_port *);
......@@ -60,27 +59,19 @@ static void fc_disc_restart(struct fc_disc *);
* @lport: Fibre Channel host port instance
* @port_id: remote port port_id to match
*/
struct fc_rport *fc_disc_lookup_rport(const struct fc_lport *lport,
struct fc_rport_priv *fc_disc_lookup_rport(const struct fc_lport *lport,
u32 port_id)
{
const struct fc_disc *disc = &lport->disc;
struct fc_rport *rport, *found = NULL;
struct fc_rport *rport;
struct fc_rport_priv *rdata;
int disc_found = 0;
list_for_each_entry(rdata, &disc->rports, peers) {
rport = PRIV_TO_RPORT(rdata);
if (rport->port_id == port_id) {
disc_found = 1;
found = rport;
break;
if (rport->port_id == port_id)
return rdata;
}
}
if (!disc_found)
found = NULL;
return found;
return NULL;
}
/**
......@@ -93,21 +84,18 @@ struct fc_rport *fc_disc_lookup_rport(const struct fc_lport *lport,
void fc_disc_stop_rports(struct fc_disc *disc)
{
struct fc_lport *lport;
struct fc_rport *rport;
struct fc_rport_priv *rdata, *next;
lport = disc->lport;
mutex_lock(&disc->disc_mutex);
list_for_each_entry_safe(rdata, next, &disc->rports, peers) {
rport = PRIV_TO_RPORT(rdata);
list_del(&rdata->peers);
lport->tt.rport_logoff(rport);
lport->tt.rport_logoff(rdata);
}
list_for_each_entry_safe(rdata, next, &disc->rogue_rports, peers) {
rport = PRIV_TO_RPORT(rdata);
lport->tt.rport_logoff(rport);
lport->tt.rport_logoff(rdata);
}
mutex_unlock(&disc->disc_mutex);
......@@ -116,18 +104,18 @@ void fc_disc_stop_rports(struct fc_disc *disc)
/**
* fc_disc_rport_callback() - Event handler for rport events
* @lport: The lport which is receiving the event
* @rport: The rport which the event has occured on
* @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_disc_rport_callback(struct fc_lport *lport,
struct fc_rport *rport,
struct fc_rport_priv *rdata,
enum fc_rport_event event)
{
struct fc_rport_priv *rdata = rport->dd_data;
struct fc_disc *disc = &lport->disc;
struct fc_rport *rport = PRIV_TO_RPORT(rdata);
FC_DISC_DBG(disc, "Received a %d event for port (%6x)\n", event,
rport->port_id);
......@@ -169,7 +157,6 @@ static void fc_disc_recv_rscn_req(struct fc_seq *sp, struct fc_frame *fp,
struct fc_disc *disc)
{
struct fc_lport *lport;
struct fc_rport *rport;
struct fc_rport_priv *rdata;
struct fc_els_rscn *rp;
struct fc_els_rscn_page *pp;
......@@ -249,11 +236,10 @@ static void fc_disc_recv_rscn_req(struct fc_seq *sp, struct fc_frame *fp,
redisc, lport->state, disc->pending);
list_for_each_entry_safe(dp, next, &disc_ports, peers) {
list_del(&dp->peers);
rport = lport->tt.rport_lookup(lport, dp->ids.port_id);
if (rport) {
rdata = rport->dd_data;
rdata = lport->tt.rport_lookup(lport, dp->ids.port_id);
if (rdata) {
list_del(&rdata->peers);
lport->tt.rport_logoff(rport);
lport->tt.rport_logoff(rdata);
}
fc_disc_single(disc, dp);
}
......@@ -308,16 +294,14 @@ static void fc_disc_recv_req(struct fc_seq *sp, struct fc_frame *fp,
*/
static void fc_disc_restart(struct fc_disc *disc)
{
struct fc_rport *rport;
struct fc_rport_priv *rdata, *next;
struct fc_lport *lport = disc->lport;
FC_DISC_DBG(disc, "Restarting discovery\n");
list_for_each_entry_safe(rdata, next, &disc->rports, peers) {
rport = PRIV_TO_RPORT(rdata);
list_del(&rdata->peers);
lport->tt.rport_logoff(rport);
lport->tt.rport_logoff(rdata);
}
disc->requested = 1;
......@@ -335,6 +319,7 @@ static void fc_disc_start(void (*disc_callback)(struct fc_lport *,
enum fc_disc_event),
struct fc_lport *lport)
{
struct fc_rport_priv *rdata;
struct fc_rport *rport;
struct fc_rport_identifiers ids;
struct fc_disc *disc = &lport->disc;
......@@ -362,8 +347,9 @@ static void fc_disc_start(void (*disc_callback)(struct fc_lport *,
* Handle point-to-point mode as a simple discovery
* of the remote port. Yucky, yucky, yuck, yuck!
*/
rport = disc->lport->ptp_rp;
if (rport) {
rdata = disc->lport->ptp_rp;
if (rdata) {
rport = PRIV_TO_RPORT(rdata);
ids.port_id = rport->port_id;
ids.port_name = rport->port_name;
ids.node_name = rport->node_name;
......@@ -418,7 +404,9 @@ static int fc_disc_new_target(struct fc_disc *disc,
* assigned the same FCID. This should be rare.
* Delete the old one and fall thru to re-create.
*/
fc_disc_del_target(disc, rport);
rdata = rport->dd_data;
list_del(&rdata->peers);
lport->tt.rport_logoff(rdata);
rport = NULL;
}
}
......@@ -426,37 +414,26 @@ static int fc_disc_new_target(struct fc_disc *disc,
ids->port_id != fc_host_port_id(lport->host) &&
ids->port_name != lport->wwpn) {
if (!rport) {
rport = lport->tt.rport_lookup(lport, ids->port_id);
rdata = lport->tt.rport_lookup(lport, ids->port_id);
if (!rport) {
rport = lport->tt.rport_create(lport, ids);
rdata = lport->tt.rport_create(lport, ids);
}
if (!rport)
if (!rdata)
error = -ENOMEM;
else
rport = PRIV_TO_RPORT(rdata);
}
if (rport) {
rdata = rport->dd_data;
rdata->ops = &fc_disc_rport_ops;
rdata->rp_state = RPORT_ST_INIT;
list_add_tail(&rdata->peers, &disc->rogue_rports);
lport->tt.rport_login(rport);
lport->tt.rport_login(rdata);
}
}
return error;
}
/**
* fc_disc_del_target() - Delete a target
* @disc: FC discovery context
* @rport: The remote port to be removed
*/
static void fc_disc_del_target(struct fc_disc *disc, struct fc_rport *rport)
{
struct fc_lport *lport = disc->lport;
struct fc_rport_priv *rdata = rport->dd_data;
list_del(&rdata->peers);
lport->tt.rport_logoff(rport);
}
/**
* fc_disc_done() - Discovery has been completed
* @disc: FC discovery context
......@@ -573,7 +550,6 @@ static int fc_disc_gpn_ft_parse(struct fc_disc *disc, void *buf, size_t len)
size_t tlen;
int error = 0;
struct fc_rport_identifiers ids;
struct fc_rport *rport;
struct fc_rport_priv *rdata;
lport = disc->lport;
......@@ -622,14 +598,13 @@ static int fc_disc_gpn_ft_parse(struct fc_disc *disc, void *buf, size_t len)
if (ids.port_id != fc_host_port_id(lport->host) &&
ids.port_name != lport->wwpn) {
rport = lport->tt.rport_create(lport, &ids);
if (rport) {
rdata = rport->dd_data;
rdata = lport->tt.rport_create(lport, &ids);
if (rdata) {
rdata->ops = &fc_disc_rport_ops;
rdata->local_port = lport;
list_add_tail(&rdata->peers,
&disc->rogue_rports);
lport->tt.rport_login(rport);
lport->tt.rport_login(rdata);
} else
printk(KERN_WARNING "libfc: Failed to allocate "
"memory for the newly discovered port "
......@@ -766,7 +741,6 @@ static void fc_disc_gpn_ft_resp(struct fc_seq *sp, struct fc_frame *fp,
static void fc_disc_single(struct fc_disc *disc, struct fc_disc_port *dp)
{
struct fc_lport *lport;
struct fc_rport *new_rport;
struct fc_rport_priv *rdata;
lport = disc->lport;
......@@ -774,13 +748,12 @@ static void fc_disc_single(struct fc_disc *disc, struct fc_disc_port *dp)
if (dp->ids.port_id == fc_host_port_id(lport->host))
goto out;
new_rport = lport->tt.rport_create(lport, &dp->ids);
if (new_rport) {
rdata = new_rport->dd_data;
rdata = lport->tt.rport_create(lport, &dp->ids);
if (rdata) {
rdata->ops = &fc_disc_rport_ops;
kfree(dp);
list_add_tail(&rdata->peers, &disc->rogue_rports);
lport->tt.rport_login(new_rport);
lport->tt.rport_login(rdata);
}
return;
out:
......
......@@ -32,7 +32,7 @@
* fc_elsct_send - sends ELS/CT frame
*/
static struct fc_seq *fc_elsct_send(struct fc_lport *lport,
struct fc_rport *rport,
struct fc_rport_priv *rdata,
struct fc_frame *fp,
unsigned int op,
void (*resp)(struct fc_seq *,
......@@ -47,7 +47,7 @@ static struct fc_seq *fc_elsct_send(struct fc_lport *lport,
/* ELS requests */
if ((op >= ELS_LS_RJT) && (op <= ELS_AUTH_ELS))
rc = fc_els_fill(lport, rport, fp, op, &r_ctl, &did, &fh_type);
rc = fc_els_fill(lport, rdata, fp, op, &r_ctl, &did, &fh_type);
else
/* CT requests */
rc = fc_ct_fill(lport, fp, op, &r_ctl, &did, &fh_type);
......
......@@ -1308,7 +1308,7 @@ static void fc_fcp_rec(struct fc_fcp_pkt *fsp)
fc_fill_fc_hdr(fp, FC_RCTL_ELS_REQ, rport->port_id,
fc_host_port_id(rp->local_port->host), FC_TYPE_ELS,
FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0);
if (lp->tt.elsct_send(lp, rport, fp, ELS_REC, fc_fcp_rec_resp,
if (lp->tt.elsct_send(lp, rport->dd_data, fp, ELS_REC, fc_fcp_rec_resp,
fsp, jiffies_to_msecs(FC_SCSI_REC_TOV))) {
fc_fcp_pkt_hold(fsp); /* hold while REC outstanding */
return;
......
......@@ -133,16 +133,18 @@ static int fc_frame_drop(struct fc_lport *lport, struct fc_frame *fp)
/**
* fc_lport_rport_callback() - Event handler for rport events
* @lport: The lport which is receiving the event
* @rport: The rport which the event has occured on
* @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 *rport,
struct fc_rport_priv *rdata,
enum fc_rport_event event)
{
struct fc_rport *rport = PRIV_TO_RPORT(rdata);
FC_LPORT_DBG(lport, "Received a %d event for port (%6x)\n", event,
rport->port_id);
......@@ -151,7 +153,7 @@ static void fc_lport_rport_callback(struct fc_lport *lport,
if (rport->port_id == FC_FID_DIR_SERV) {
mutex_lock(&lport->lp_mutex);
if (lport->state == LPORT_ST_DNS) {
lport->dns_rp = rport;
lport->dns_rp = rdata;
fc_lport_enter_rpn_id(lport);
} else {
FC_LPORT_DBG(lport, "Received an CREATED event "
......@@ -160,7 +162,7 @@ static void fc_lport_rport_callback(struct fc_lport *lport,
"in the DNS state, it's in the "
"%d state", rport->port_id,
lport->state);
lport->tt.rport_logoff(rport);
lport->tt.rport_logoff(rdata);
}
mutex_unlock(&lport->lp_mutex);
} else
......@@ -832,7 +834,7 @@ static void fc_lport_recv_req(struct fc_lport *lport, struct fc_seq *sp,
{
struct fc_frame_header *fh = fc_frame_header_get(fp);
void (*recv) (struct fc_seq *, struct fc_frame *, struct fc_lport *);
struct fc_rport *rport;
struct fc_rport_priv *rdata;
u32 s_id;
u32 d_id;
struct fc_seq_els_data rjt_data;
......@@ -888,9 +890,9 @@ static void fc_lport_recv_req(struct fc_lport *lport, struct fc_seq *sp,
s_id = ntoh24(fh->fh_s_id);
d_id = ntoh24(fh->fh_d_id);
rport = lport->tt.rport_lookup(lport, s_id);
if (rport)
lport->tt.rport_recv_req(sp, fp, rport);
rdata = lport->tt.rport_lookup(lport, s_id);
if (rdata)
lport->tt.rport_recv_req(sp, fp, rdata);
else {
rjt_data.fp = NULL;
rjt_data.reason = ELS_RJT_UNAB;
......@@ -1304,7 +1306,6 @@ static struct fc_rport_operations fc_lport_rport_ops = {
*/
static void fc_lport_enter_dns(struct fc_lport *lport)
{
struct fc_rport *rport;
struct fc_rport_priv *rdata;
struct fc_rport_identifiers ids;
......@@ -1318,13 +1319,12 @@ static void fc_lport_enter_dns(struct fc_lport *lport)
fc_lport_state_enter(lport, LPORT_ST_DNS);
rport = lport->tt.rport_create(lport, &ids);
if (!rport)
rdata = lport->tt.rport_create(lport, &ids);
if (!rdata)
goto err;
rdata = rport->dd_data;
rdata->ops = &fc_lport_rport_ops;
lport->tt.rport_login(rport);
lport->tt.rport_login(rdata);
return;
err:
......
This diff is collapsed.
......@@ -249,10 +249,13 @@ static inline void fc_scr_fill(struct fc_lport *lport, struct fc_frame *fp)
/**
* fc_els_fill - Fill in an ELS request frame
*/
static inline int fc_els_fill(struct fc_lport *lport, struct fc_rport *rport,
static inline int fc_els_fill(struct fc_lport *lport,
struct fc_rport_priv *rdata,
struct fc_frame *fp, unsigned int op,
enum fc_rctl *r_ctl, u32 *did, enum fc_fh_type *fh_type)
{
struct fc_rport *rport = PRIV_TO_RPORT(rdata);
switch (op) {
case ELS_PLOGI:
fc_plogi_fill(lport, fp, ELS_PLOGI);
......@@ -272,7 +275,7 @@ static inline int fc_els_fill(struct fc_lport *lport, struct fc_rport *rport,
* is port logo, therefore
* set did to rport id.
*/
if (rport)
if (rdata)
*did = rport->port_id;
break;
......
......@@ -75,10 +75,10 @@ do { \
(lport)->host->host_no, \
(port_id), ##args))
#define FC_RPORT_DBG(rport, fmt, args...) \
#define FC_RPORT_DBG(rdata, fmt, args...) \
do { \
struct fc_rport_priv *rdata = rport->dd_data; \
struct fc_lport *lport = rdata->local_port; \
struct fc_rport *rport = PRIV_TO_RPORT(rdata); \
FC_RPORT_ID_DBG(lport, rport->port_id, fmt, ##args); \
} while (0)
......@@ -185,8 +185,10 @@ enum fc_rport_event {
*/
#define fc_rport_priv fc_rport_libfc_priv
struct fc_rport_priv;
struct fc_rport_operations {
void (*event_callback)(struct fc_lport *, struct fc_rport *,
void (*event_callback)(struct fc_lport *, struct fc_rport_priv *,
enum fc_rport_event);
};
......@@ -422,7 +424,7 @@ struct libfc_function_template {
* STATUS: OPTIONAL
*/
struct fc_seq *(*elsct_send)(struct fc_lport *lport,
struct fc_rport *rport,
struct fc_rport_priv *,
struct fc_frame *fp,
unsigned int op,
void (*resp)(struct fc_seq *,
......@@ -567,7 +569,7 @@ struct libfc_function_template {
/*
* Create a remote port
*/
struct fc_rport *(*rport_create)(struct fc_lport *,
struct fc_rport_priv *(*rport_create)(struct fc_lport *,
struct fc_rport_identifiers *);
/*
......@@ -581,7 +583,7 @@ struct libfc_function_template {
*
* STATUS: OPTIONAL
*/
int (*rport_login)(struct fc_rport *rport);
int (*rport_login)(struct fc_rport_priv *);
/*
* Logoff, and remove the rport from the transport if
......@@ -589,7 +591,7 @@ struct libfc_function_template {
*
* STATUS: OPTIONAL
*/
int (*rport_logoff)(struct fc_rport *rport);
int (*rport_logoff)(struct fc_rport_priv *);
/*
* Recieve a request from a remote port.
......@@ -597,14 +599,14 @@ struct libfc_function_template {
* STATUS: OPTIONAL
*/
void (*rport_recv_req)(struct fc_seq *, struct fc_frame *,
struct fc_rport *);
struct fc_rport_priv *);
/*
* lookup an rport by it's port ID.
*
* STATUS: OPTIONAL
*/
struct fc_rport *(*rport_lookup)(const struct fc_lport *, u32);
struct fc_rport_priv *(*rport_lookup)(const struct fc_lport *, u32);
/*
* Send a fcp cmd from fsp pkt.
......@@ -694,8 +696,8 @@ struct fc_lport {
/* Associations */
struct Scsi_Host *host;
struct list_head ema_list;
struct fc_rport *dns_rp;
struct fc_rport *ptp_rp;
struct fc_rport_priv *dns_rp;
struct fc_rport_priv *ptp_rp;
void *scsi_priv;
struct fc_disc disc;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment