Commit f211fa51 authored by Joe Eykholt's avatar Joe Eykholt Committed by James Bottomley

[SCSI] libfc: make rport structure optional

Allow a struct fc_rport_priv to have no fc_rport associated with it.
This sets up to remove the need for "rogue" rports.

Add a few fields to fc_rport_priv that are needed before the fc_rport
is created.  These are the ids, maxframe_size, classes, and rport pointer.

Remove the macro PRIV_TO_RPORT().  Just use rdata->rport where appropriate.

To take the place of the get_device()/put_device ops that were used to
hold both the rport and rdata, add a reference count to rdata structures
using kref.  When kref_get decrements the refcount to zero, a new template
function releasing the rdata should be called.  This will take care of
freeing the rdata and releasing the hold on the rport (for now).  After
subsequent patches make the rport truly optional, this release function
will simply free the rdata.

Remove the simple inline function fc_rport_set_name(), which becomes
semanticly ambiguous otherwise.  The caller will set the port_name and
node_name in the rdata->Ids, which will later be copied to the rport
when it its created.
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 a46f327a
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
static void fc_disc_gpn_ft_req(struct fc_disc *); 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 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 *, static int fc_disc_new_target(struct fc_disc *, struct fc_rport_priv *,
struct fc_rport_identifiers *); struct fc_rport_identifiers *);
static void fc_disc_done(struct fc_disc *); static void fc_disc_done(struct fc_disc *);
static void fc_disc_timeout(struct work_struct *); static void fc_disc_timeout(struct work_struct *);
...@@ -63,12 +63,10 @@ struct fc_rport_priv *fc_disc_lookup_rport(const struct fc_lport *lport, ...@@ -63,12 +63,10 @@ struct fc_rport_priv *fc_disc_lookup_rport(const struct fc_lport *lport,
u32 port_id) u32 port_id)
{ {
const struct fc_disc *disc = &lport->disc; const struct fc_disc *disc = &lport->disc;
struct fc_rport *rport;
struct fc_rport_priv *rdata; struct fc_rport_priv *rdata;
list_for_each_entry(rdata, &disc->rports, peers) { list_for_each_entry(rdata, &disc->rports, peers) {
rport = PRIV_TO_RPORT(rdata); if (rdata->ids.port_id == port_id)
if (rport->port_id == port_id)
return rdata; return rdata;
} }
return NULL; return NULL;
...@@ -115,10 +113,9 @@ static void fc_disc_rport_callback(struct fc_lport *lport, ...@@ -115,10 +113,9 @@ static void fc_disc_rport_callback(struct fc_lport *lport,
enum fc_rport_event event) enum fc_rport_event event)
{ {
struct fc_disc *disc = &lport->disc; 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, FC_DISC_DBG(disc, "Received a %d event for port (%6x)\n", event,
rport->port_id); rdata->ids.port_id);
switch (event) { switch (event) {
case RPORT_EV_CREATED: case RPORT_EV_CREATED:
...@@ -320,8 +317,6 @@ static void fc_disc_start(void (*disc_callback)(struct fc_lport *, ...@@ -320,8 +317,6 @@ static void fc_disc_start(void (*disc_callback)(struct fc_lport *,
struct fc_lport *lport) struct fc_lport *lport)
{ {
struct fc_rport_priv *rdata; struct fc_rport_priv *rdata;
struct fc_rport *rport;
struct fc_rport_identifiers ids;
struct fc_disc *disc = &lport->disc; struct fc_disc *disc = &lport->disc;
/* /*
...@@ -349,18 +344,12 @@ static void fc_disc_start(void (*disc_callback)(struct fc_lport *, ...@@ -349,18 +344,12 @@ static void fc_disc_start(void (*disc_callback)(struct fc_lport *,
*/ */
rdata = disc->lport->ptp_rp; rdata = disc->lport->ptp_rp;
if (rdata) { if (rdata) {
rport = PRIV_TO_RPORT(rdata); kref_get(&rdata->kref);
ids.port_id = rport->port_id; if (!fc_disc_new_target(disc, rdata, &rdata->ids)) {
ids.port_name = rport->port_name;
ids.node_name = rport->node_name;
ids.roles = FC_RPORT_ROLE_UNKNOWN;
get_device(&rport->dev);
if (!fc_disc_new_target(disc, rport, &ids)) {
disc->event = DISC_EV_SUCCESS; disc->event = DISC_EV_SUCCESS;
fc_disc_done(disc); fc_disc_done(disc);
} }
put_device(&rport->dev); kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
} else { } else {
fc_disc_gpn_ft_req(disc); /* get ports by FC-4 type */ fc_disc_gpn_ft_req(disc); /* get ports by FC-4 type */
} }
...@@ -375,28 +364,27 @@ static struct fc_rport_operations fc_disc_rport_ops = { ...@@ -375,28 +364,27 @@ static struct fc_rport_operations fc_disc_rport_ops = {
/** /**
* fc_disc_new_target() - Handle new target found by discovery * fc_disc_new_target() - Handle new target found by discovery
* @lport: FC local port * @lport: FC local port
* @rport: The previous FC remote port (NULL if new remote port) * @rdata: The previous FC remote port priv (NULL if new remote port)
* @ids: Identifiers for the new FC remote port * @ids: Identifiers for the new FC remote port
* *
* Locking Note: This function expects that the disc_mutex is locked * Locking Note: This function expects that the disc_mutex is locked
* before it is called. * before it is called.
*/ */
static int fc_disc_new_target(struct fc_disc *disc, static int fc_disc_new_target(struct fc_disc *disc,
struct fc_rport *rport, struct fc_rport_priv *rdata,
struct fc_rport_identifiers *ids) struct fc_rport_identifiers *ids)
{ {
struct fc_lport *lport = disc->lport; struct fc_lport *lport = disc->lport;
struct fc_rport_priv *rdata;
int error = 0; int error = 0;
if (rport && ids->port_name) { if (rdata && ids->port_name) {
if (rport->port_name == -1) { if (rdata->ids.port_name == -1) {
/* /*
* Set WWN and fall through to notify of create. * Set WWN and fall through to notify of create.
*/ */
fc_rport_set_name(rport, ids->port_name, rdata->ids.port_name = ids->port_name;
rport->node_name); rdata->ids.node_name = ids->node_name;
} else if (rport->port_name != ids->port_name) { } else if (rdata->ids.port_name != ids->port_name) {
/* /*
* This is a new port with the same FCID as * This is a new port with the same FCID as
* a previously-discovered port. Presumably the old * a previously-discovered port. Presumably the old
...@@ -404,27 +392,23 @@ static int fc_disc_new_target(struct fc_disc *disc, ...@@ -404,27 +392,23 @@ static int fc_disc_new_target(struct fc_disc *disc,
* assigned the same FCID. This should be rare. * assigned the same FCID. This should be rare.
* Delete the old one and fall thru to re-create. * Delete the old one and fall thru to re-create.
*/ */
rdata = rport->dd_data;
list_del(&rdata->peers); list_del(&rdata->peers);
lport->tt.rport_logoff(rdata); lport->tt.rport_logoff(rdata);
rport = NULL; rdata = NULL;
} }
} }
if (((ids->port_name != -1) || (ids->port_id != -1)) && if (((ids->port_name != -1) || (ids->port_id != -1)) &&
ids->port_id != fc_host_port_id(lport->host) && ids->port_id != fc_host_port_id(lport->host) &&
ids->port_name != lport->wwpn) { ids->port_name != lport->wwpn) {
if (!rport) { if (!rdata) {
rdata = lport->tt.rport_lookup(lport, ids->port_id); rdata = lport->tt.rport_lookup(lport, ids->port_id);
if (!rport) { if (!rdata) {
rdata = lport->tt.rport_create(lport, ids); rdata = lport->tt.rport_create(lport, ids);
if (!rdata)
error = -ENOMEM;
} }
if (!rdata)
error = -ENOMEM;
else
rport = PRIV_TO_RPORT(rdata);
} }
if (rport) { if (rdata) {
rdata = rport->dd_data;
rdata->ops = &fc_disc_rport_ops; rdata->ops = &fc_disc_rport_ops;
rdata->rp_state = RPORT_ST_INIT; rdata->rp_state = RPORT_ST_INIT;
list_add_tail(&rdata->peers, &disc->rogue_rports); list_add_tail(&rdata->peers, &disc->rogue_rports);
......
...@@ -143,14 +143,12 @@ static void fc_lport_rport_callback(struct fc_lport *lport, ...@@ -143,14 +143,12 @@ static void fc_lport_rport_callback(struct fc_lport *lport,
struct fc_rport_priv *rdata, struct fc_rport_priv *rdata,
enum fc_rport_event event) 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, FC_LPORT_DBG(lport, "Received a %d event for port (%6x)\n", event,
rport->port_id); rdata->ids.port_id);
switch (event) { switch (event) {
case RPORT_EV_CREATED: case RPORT_EV_CREATED:
if (rport->port_id == FC_FID_DIR_SERV) { if (rdata->ids.port_id == FC_FID_DIR_SERV) {
mutex_lock(&lport->lp_mutex); mutex_lock(&lport->lp_mutex);
if (lport->state == LPORT_ST_DNS) { if (lport->state == LPORT_ST_DNS) {
lport->dns_rp = rdata; lport->dns_rp = rdata;
...@@ -160,7 +158,7 @@ static void fc_lport_rport_callback(struct fc_lport *lport, ...@@ -160,7 +158,7 @@ static void fc_lport_rport_callback(struct fc_lport *lport,
"on port (%6x) for the directory " "on port (%6x) for the directory "
"server, but the lport is not " "server, but the lport is not "
"in the DNS state, it's in the " "in the DNS state, it's in the "
"%d state", rport->port_id, "%d state", rdata->ids.port_id,
lport->state); lport->state);
lport->tt.rport_logoff(rdata); lport->tt.rport_logoff(rdata);
} }
...@@ -168,12 +166,12 @@ static void fc_lport_rport_callback(struct fc_lport *lport, ...@@ -168,12 +166,12 @@ static void fc_lport_rport_callback(struct fc_lport *lport,
} else } else
FC_LPORT_DBG(lport, "Received an event for port (%6x) " FC_LPORT_DBG(lport, "Received an event for port (%6x) "
"which is not the directory server\n", "which is not the directory server\n",
rport->port_id); rdata->ids.port_id);
break; break;
case RPORT_EV_LOGO: case RPORT_EV_LOGO:
case RPORT_EV_FAILED: case RPORT_EV_FAILED:
case RPORT_EV_STOP: case RPORT_EV_STOP:
if (rport->port_id == FC_FID_DIR_SERV) { if (rdata->ids.port_id == FC_FID_DIR_SERV) {
mutex_lock(&lport->lp_mutex); mutex_lock(&lport->lp_mutex);
lport->dns_rp = NULL; lport->dns_rp = NULL;
mutex_unlock(&lport->lp_mutex); mutex_unlock(&lport->lp_mutex);
...@@ -181,7 +179,7 @@ static void fc_lport_rport_callback(struct fc_lport *lport, ...@@ -181,7 +179,7 @@ static void fc_lport_rport_callback(struct fc_lport *lport,
} else } else
FC_LPORT_DBG(lport, "Received an event for port (%6x) " FC_LPORT_DBG(lport, "Received an event for port (%6x) "
"which is not the directory server\n", "which is not the directory server\n",
rport->port_id); rdata->ids.port_id);
break; break;
case RPORT_EV_NONE: case RPORT_EV_NONE:
break; break;
......
This diff is collapsed.
...@@ -76,11 +76,7 @@ do { \ ...@@ -76,11 +76,7 @@ do { \
(port_id), ##args)) (port_id), ##args))
#define FC_RPORT_DBG(rdata, fmt, args...) \ #define FC_RPORT_DBG(rdata, fmt, args...) \
do { \ FC_RPORT_ID_DBG((rdata)->local_port, (rdata)->ids.port_id, fmt, ##args)
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)
#define FC_FCP_DBG(pkt, fmt, args...) \ #define FC_FCP_DBG(pkt, fmt, args...) \
FC_CHECK_LOGGING(FC_FCP_LOGGING, \ FC_CHECK_LOGGING(FC_FCP_LOGGING, \
...@@ -195,9 +191,13 @@ struct fc_rport_operations { ...@@ -195,9 +191,13 @@ struct fc_rport_operations {
/** /**
* struct fc_rport_libfc_priv - libfc internal information about a remote port * struct fc_rport_libfc_priv - libfc internal information about a remote port
* @local_port: Fibre Channel host port instance * @local_port: Fibre Channel host port instance
* @rport: transport remote port
* @kref: reference counter
* @rp_state: state tracks progress of PLOGI, PRLI, and RTV exchanges * @rp_state: state tracks progress of PLOGI, PRLI, and RTV exchanges
* @ids: remote port identifiers and roles
* @flags: REC and RETRY supported flags * @flags: REC and RETRY supported flags
* @max_seq: maximum number of concurrent sequences * @max_seq: maximum number of concurrent sequences
* @maxframe_size: maximum frame size
* @retries: retry count in current state * @retries: retry count in current state
* @e_d_tov: error detect timeout value (in msec) * @e_d_tov: error detect timeout value (in msec)
* @r_a_tov: resource allocation timeout value (in msec) * @r_a_tov: resource allocation timeout value (in msec)
...@@ -207,11 +207,15 @@ struct fc_rport_operations { ...@@ -207,11 +207,15 @@ struct fc_rport_operations {
*/ */
struct fc_rport_libfc_priv { struct fc_rport_libfc_priv {
struct fc_lport *local_port; struct fc_lport *local_port;
struct fc_rport *rport;
struct kref kref;
enum fc_rport_state rp_state; enum fc_rport_state rp_state;
struct fc_rport_identifiers ids;
u16 flags; u16 flags;
#define FC_RP_FLAGS_REC_SUPPORTED (1 << 0) #define FC_RP_FLAGS_REC_SUPPORTED (1 << 0)
#define FC_RP_FLAGS_RETRY (1 << 1) #define FC_RP_FLAGS_RETRY (1 << 1)
u16 max_seq; u16 max_seq;
u16 maxframe_size;
unsigned int retries; unsigned int retries;
unsigned int e_d_tov; unsigned int e_d_tov;
unsigned int r_a_tov; unsigned int r_a_tov;
...@@ -222,19 +226,12 @@ struct fc_rport_libfc_priv { ...@@ -222,19 +226,12 @@ struct fc_rport_libfc_priv {
struct fc_rport_operations *ops; struct fc_rport_operations *ops;
struct list_head peers; struct list_head peers;
struct work_struct event_work; struct work_struct event_work;
u32 supported_classes;
}; };
#define PRIV_TO_RPORT(x) \
((struct fc_rport *)((void *)(x) - sizeof(struct fc_rport)))
#define RPORT_TO_PRIV(x) \ #define RPORT_TO_PRIV(x) \
((struct fc_rport_libfc_priv *)((void *)(x) + sizeof(struct fc_rport))) ((struct fc_rport_libfc_priv *)((void *)(x) + sizeof(struct fc_rport)))
static inline void fc_rport_set_name(struct fc_rport *rport, u64 wwpn, u64 wwnn)
{
rport->node_name = wwnn;
rport->port_name = wwpn;
}
/* /*
* fcoe stats structure * fcoe stats structure
*/ */
...@@ -608,6 +605,12 @@ struct libfc_function_template { ...@@ -608,6 +605,12 @@ struct libfc_function_template {
*/ */
struct fc_rport_priv *(*rport_lookup)(const struct fc_lport *, u32); struct fc_rport_priv *(*rport_lookup)(const struct fc_lport *, u32);
/*
* Destroy an rport after final kref_put().
* The argument is a pointer to the kref inside the fc_rport_priv.
*/
void (*rport_destroy)(struct kref *);
/* /*
* Send a fcp cmd from fsp pkt. * Send a fcp cmd from fsp pkt.
* Called with the SCSI host lock unlocked and irqs disabled. * Called with the SCSI host lock unlocked and irqs disabled.
......
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