Skip to content

Commit

Permalink
scsi: qla2xxx: Introduce the be_id_t and le_id_t data types for FC sr…
Browse files Browse the repository at this point in the history
…c/dst IDs

Introduce the be_id_t and le_id_t data types for Fibre Channel source and
destination ID formats supported by the firmware instead of using an
uint8_t[3] array. Introduce functions for converting from and to the
port_id_t data types. This patch does not change the behavior of the
qla2xxx driver but improves source code readability and also allows the
compiler to verify the endianness of Fibre Channel IDs.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
  • Loading branch information
Bart Van Assche authored and Martin K. Petersen committed Aug 13, 2019
1 parent fb32509 commit df95f39
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 173 deletions.
71 changes: 65 additions & 6 deletions drivers/scsi/qla2xxx/qla_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@
#include <scsi/scsi_transport_fc.h>
#include <scsi/scsi_bsg_fc.h>

/* Big endian Fibre Channel S_ID (source ID) or D_ID (destination ID). */
typedef struct {
uint8_t domain;
uint8_t area;
uint8_t al_pa;
} be_id_t;

/* Little endian Fibre Channel S_ID (source ID) or D_ID (destination ID). */
typedef struct {
uint8_t al_pa;
uint8_t area;
uint8_t domain;
} le_id_t;

#include "qla_bsg.h"
#include "qla_dsd.h"
#include "qla_nx.h"
Expand Down Expand Up @@ -343,6 +357,51 @@ typedef union {
} port_id_t;
#define INVALID_PORT_ID 0xFFFFFF

static inline le_id_t be_id_to_le(be_id_t id)
{
le_id_t res;

res.domain = id.domain;
res.area = id.area;
res.al_pa = id.al_pa;

return res;
}

static inline be_id_t le_id_to_be(le_id_t id)
{
be_id_t res;

res.domain = id.domain;
res.area = id.area;
res.al_pa = id.al_pa;

return res;
}

static inline port_id_t be_to_port_id(be_id_t id)
{
port_id_t res;

res.b.domain = id.domain;
res.b.area = id.area;
res.b.al_pa = id.al_pa;
res.b.rsvd_1 = 0;

return res;
}

static inline be_id_t port_id_to_be_id(port_id_t port_id)
{
be_id_t res;

res.domain = port_id.b.domain;
res.area = port_id.b.area;
res.al_pa = port_id.b.al_pa;

return res;
}

struct els_logo_payload {
uint8_t opcode;
uint8_t rsvd[3];
Expand Down Expand Up @@ -2746,7 +2805,7 @@ struct ct_sns_req {
/* GA_NXT, GPN_ID, GNN_ID, GFT_ID, GFPN_ID */
struct {
uint8_t reserved;
uint8_t port_id[3];
be_id_t port_id;
} port_id;

struct {
Expand All @@ -2765,21 +2824,21 @@ struct ct_sns_req {

struct {
uint8_t reserved;
uint8_t port_id[3];
be_id_t port_id;
uint8_t fc4_types[32];
} rft_id;

struct {
uint8_t reserved;
uint8_t port_id[3];
be_id_t port_id;
uint16_t reserved2;
uint8_t fc4_feature;
uint8_t fc4_type;
} rff_id;

struct {
uint8_t reserved;
uint8_t port_id[3];
be_id_t port_id;
uint8_t node_name[8];
} rnn_id;

Expand Down Expand Up @@ -2866,7 +2925,7 @@ struct ct_rsp_hdr {

struct ct_sns_gid_pt_data {
uint8_t control_byte;
uint8_t port_id[3];
be_id_t port_id;
};

/* It's the same for both GPN_FT and GNN_FT */
Expand Down Expand Up @@ -2896,7 +2955,7 @@ struct ct_sns_rsp {
union {
struct {
uint8_t port_type;
uint8_t port_id[3];
be_id_t port_id;
uint8_t port_name[8];
uint8_t sym_port_name_len;
uint8_t sym_port_name[255];
Expand Down
62 changes: 17 additions & 45 deletions drivers/scsi/qla2xxx/qla_gs.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,7 @@ qla2x00_ga_nxt(scsi_qla_host_t *vha, fc_port_t *fcport)
ct_rsp = &ha->ct_sns->p.rsp;

/* Prepare CT arguments -- port_id */
ct_req->req.port_id.port_id[0] = fcport->d_id.b.domain;
ct_req->req.port_id.port_id[1] = fcport->d_id.b.area;
ct_req->req.port_id.port_id[2] = fcport->d_id.b.al_pa;
ct_req->req.port_id.port_id = port_id_to_be_id(fcport->d_id);

/* Execute MS IOCB */
rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Expand All @@ -242,9 +240,7 @@ qla2x00_ga_nxt(scsi_qla_host_t *vha, fc_port_t *fcport)
rval = QLA_FUNCTION_FAILED;
} else {
/* Populate fc_port_t entry. */
fcport->d_id.b.domain = ct_rsp->rsp.ga_nxt.port_id[0];
fcport->d_id.b.area = ct_rsp->rsp.ga_nxt.port_id[1];
fcport->d_id.b.al_pa = ct_rsp->rsp.ga_nxt.port_id[2];
fcport->d_id = be_to_port_id(ct_rsp->rsp.ga_nxt.port_id);

memcpy(fcport->node_name, ct_rsp->rsp.ga_nxt.node_name,
WWN_SIZE);
Expand Down Expand Up @@ -337,9 +333,7 @@ qla2x00_gid_pt(scsi_qla_host_t *vha, sw_info_t *list)
/* Set port IDs in switch info list. */
for (i = 0; i < ha->max_fibre_devices; i++) {
gid_data = &ct_rsp->rsp.gid_pt.entries[i];
list[i].d_id.b.domain = gid_data->port_id[0];
list[i].d_id.b.area = gid_data->port_id[1];
list[i].d_id.b.al_pa = gid_data->port_id[2];
list[i].d_id = be_to_port_id(gid_data->port_id);
memset(list[i].fabric_port_name, 0, WWN_SIZE);
list[i].fp_speed = PORT_SPEED_UNKNOWN;

Expand Down Expand Up @@ -403,9 +397,7 @@ qla2x00_gpn_id(scsi_qla_host_t *vha, sw_info_t *list)
ct_rsp = &ha->ct_sns->p.rsp;

/* Prepare CT arguments -- port_id */
ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
ct_req->req.port_id.port_id = port_id_to_be_id(list[i].d_id);

/* Execute MS IOCB */
rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Expand Down Expand Up @@ -472,9 +464,7 @@ qla2x00_gnn_id(scsi_qla_host_t *vha, sw_info_t *list)
ct_rsp = &ha->ct_sns->p.rsp;

/* Prepare CT arguments -- port_id */
ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
ct_req->req.port_id.port_id = port_id_to_be_id(list[i].d_id);

/* Execute MS IOCB */
rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Expand Down Expand Up @@ -639,9 +629,7 @@ static int qla_async_rftid(scsi_qla_host_t *vha, port_id_t *d_id)
ct_req = qla2x00_prep_ct_req(ct_sns, RFT_ID_CMD, RFT_ID_RSP_SIZE);

/* Prepare CT arguments -- port_id, FC-4 types */
ct_req->req.rft_id.port_id[0] = vha->d_id.b.domain;
ct_req->req.rft_id.port_id[1] = vha->d_id.b.area;
ct_req->req.rft_id.port_id[2] = vha->d_id.b.al_pa;
ct_req->req.rft_id.port_id = port_id_to_be_id(vha->d_id);
ct_req->req.rft_id.fc4_types[2] = 0x01; /* FCP-3 */

if (vha->flags.nvme_enabled)
Expand Down Expand Up @@ -737,9 +725,7 @@ static int qla_async_rffid(scsi_qla_host_t *vha, port_id_t *d_id,
ct_req = qla2x00_prep_ct_req(ct_sns, RFF_ID_CMD, RFF_ID_RSP_SIZE);

/* Prepare CT arguments -- port_id, FC-4 feature, FC-4 type */
ct_req->req.rff_id.port_id[0] = d_id->b.domain;
ct_req->req.rff_id.port_id[1] = d_id->b.area;
ct_req->req.rff_id.port_id[2] = d_id->b.al_pa;
ct_req->req.rff_id.port_id = port_id_to_be_id(*d_id);
ct_req->req.rff_id.fc4_feature = fc4feature;
ct_req->req.rff_id.fc4_type = fc4type; /* SCSI - FCP */

Expand Down Expand Up @@ -830,9 +816,7 @@ static int qla_async_rnnid(scsi_qla_host_t *vha, port_id_t *d_id,
ct_req = qla2x00_prep_ct_req(ct_sns, RNN_ID_CMD, RNN_ID_RSP_SIZE);

/* Prepare CT arguments -- port_id, node_name */
ct_req->req.rnn_id.port_id[0] = vha->d_id.b.domain;
ct_req->req.rnn_id.port_id[1] = vha->d_id.b.area;
ct_req->req.rnn_id.port_id[2] = vha->d_id.b.al_pa;
ct_req->req.rnn_id.port_id = port_id_to_be_id(vha->d_id);
memcpy(ct_req->req.rnn_id.node_name, vha->node_name, WWN_SIZE);

sp->u.iocb_cmd.u.ctarg.req_size = RNN_ID_REQ_SIZE;
Expand Down Expand Up @@ -2728,9 +2712,7 @@ qla2x00_gfpn_id(scsi_qla_host_t *vha, sw_info_t *list)
ct_rsp = &ha->ct_sns->p.rsp;

/* Prepare CT arguments -- port_id */
ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
ct_req->req.port_id.port_id = port_id_to_be_id(list[i].d_id);

/* Execute MS IOCB */
rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Expand Down Expand Up @@ -2934,9 +2916,7 @@ qla2x00_gff_id(scsi_qla_host_t *vha, sw_info_t *list)
ct_rsp = &ha->ct_sns->p.rsp;

/* Prepare CT arguments -- port_id */
ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
ct_req->req.port_id.port_id = port_id_to_be_id(list[i].d_id);

/* Execute MS IOCB */
rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Expand Down Expand Up @@ -3293,20 +3273,18 @@ static void qla2x00_async_gpnid_sp_done(void *s, int res)
if (res)
ql_dbg(ql_dbg_disc, vha, 0x2066,
"Async done-%s fail res %x rscn gen %d ID %3phC. %8phC\n",
sp->name, res, sp->gen1, ct_req->req.port_id.port_id,
sp->name, res, sp->gen1, &ct_req->req.port_id.port_id,
ct_rsp->rsp.gpn_id.port_name);
else
ql_dbg(ql_dbg_disc, vha, 0x2066,
"Async done-%s good rscn gen %d ID %3phC. %8phC\n",
sp->name, sp->gen1, ct_req->req.port_id.port_id,
sp->name, sp->gen1, &ct_req->req.port_id.port_id,
ct_rsp->rsp.gpn_id.port_name);

memset(&ea, 0, sizeof(ea));
memcpy(ea.port_name, ct_rsp->rsp.gpn_id.port_name, WWN_SIZE);
ea.sp = sp;
ea.id.b.domain = ct_req->req.port_id.port_id[0];
ea.id.b.area = ct_req->req.port_id.port_id[1];
ea.id.b.al_pa = ct_req->req.port_id.port_id[2];
ea.id = be_to_port_id(ct_req->req.port_id.port_id);
ea.rc = res;
ea.event = FCME_GPNID_DONE;

Expand Down Expand Up @@ -3417,9 +3395,7 @@ int qla24xx_async_gpnid(scsi_qla_host_t *vha, port_id_t *id)
ct_req = qla2x00_prep_ct_req(ct_sns, GPN_ID_CMD, GPN_ID_RSP_SIZE);

/* GPN_ID req */
ct_req->req.port_id.port_id[0] = id->b.domain;
ct_req->req.port_id.port_id[1] = id->b.area;
ct_req->req.port_id.port_id[2] = id->b.al_pa;
ct_req->req.port_id.port_id = port_id_to_be_id(*id);

sp->u.iocb_cmd.u.ctarg.req_size = GPN_ID_REQ_SIZE;
sp->u.iocb_cmd.u.ctarg.rsp_size = GPN_ID_RSP_SIZE;
Expand All @@ -3430,7 +3406,7 @@ int qla24xx_async_gpnid(scsi_qla_host_t *vha, port_id_t *id)

ql_dbg(ql_dbg_disc, vha, 0x2067,
"Async-%s hdl=%x ID %3phC.\n", sp->name,
sp->handle, ct_req->req.port_id.port_id);
sp->handle, &ct_req->req.port_id.port_id);

rval = qla2x00_start_sp(sp);
if (rval != QLA_SUCCESS)
Expand Down Expand Up @@ -4332,9 +4308,7 @@ int qla24xx_async_gnnid(scsi_qla_host_t *vha, fc_port_t *fcport)
GNN_ID_RSP_SIZE);

/* GNN_ID req */
ct_req->req.port_id.port_id[0] = fcport->d_id.b.domain;
ct_req->req.port_id.port_id[1] = fcport->d_id.b.area;
ct_req->req.port_id.port_id[2] = fcport->d_id.b.al_pa;
ct_req->req.port_id.port_id = port_id_to_be_id(fcport->d_id);


/* req & rsp use the same buffer */
Expand Down Expand Up @@ -4464,9 +4438,7 @@ int qla24xx_async_gfpnid(scsi_qla_host_t *vha, fc_port_t *fcport)
GFPN_ID_RSP_SIZE);

/* GFPN_ID req */
ct_req->req.port_id.port_id[0] = fcport->d_id.b.domain;
ct_req->req.port_id.port_id[1] = fcport->d_id.b.area;
ct_req->req.port_id.port_id[2] = fcport->d_id.b.al_pa;
ct_req->req.port_id.port_id = port_id_to_be_id(fcport->d_id);


/* req & rsp use the same buffer */
Expand Down
2 changes: 1 addition & 1 deletion drivers/scsi/qla2xxx/qla_nvme.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ struct pt_ls4_rx_unsol {
uint32_t exchange_address;
uint8_t d_id[3];
uint8_t r_ctl;
uint8_t s_id[3];
be_id_t s_id;
uint8_t cs_ctl;
uint8_t f_ctl[3];
uint8_t type;
Expand Down
Loading

0 comments on commit df95f39

Please sign in to comment.