* [PATCH 2/4] 24-bit types: convert iSCSI to use the __be24 type and macros
2008-09-11 2:14 [PATCH 1/4] 24-bit types: typedef and functions for accessing 3-byte arrays as integers Chris Leech
@ 2008-09-11 2:14 ` Chris Leech
2008-09-11 2:15 ` [PATCH 3/4] 24-bit types: Convert jfs to use the common 24-bit types Chris Leech
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Chris Leech @ 2008-09-11 2:14 UTC (permalink / raw)
To: linux-kernel, linux-scsi
Cc: jfs-discussion, Boaz Harrosh, Harvey Harrison, Chris Leech,
Mike Christie
The calling convention of hton24 is different now, it takes a single u32
as an argument and evaluates to a __be24 lvalue.
Signed-off-by: Chris Leech <christopher.leech@intel.com>
Acked-by: Mike Christie <michaelc@cs.wisc.edu>
---
drivers/scsi/iscsi_tcp.c | 8 ++++----
drivers/scsi/libiscsi.c | 6 +++---
include/scsi/iscsi_proto.h | 46 ++++++++++++++++++--------------------------
3 files changed, 26 insertions(+), 34 deletions(-)
diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index 2a2f009..c9d6e96 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -608,11 +608,11 @@ iscsi_solicit_data_init(struct iscsi_conn *conn, struct iscsi_task *task,
hdr->exp_statsn = r2t->exp_statsn;
hdr->offset = cpu_to_be32(r2t->data_offset);
if (r2t->data_length > conn->max_xmit_dlength) {
- hton24(hdr->dlength, conn->max_xmit_dlength);
+ hdr->dlength = hton24(conn->max_xmit_dlength);
r2t->data_count = conn->max_xmit_dlength;
hdr->flags = 0;
} else {
- hton24(hdr->dlength, r2t->data_length);
+ hdr->dlength = hton24(r2t->data_length);
r2t->data_count = r2t->data_length;
hdr->flags = ISCSI_FLAG_CMD_FINAL;
}
@@ -1311,10 +1311,10 @@ iscsi_solicit_data_cont(struct iscsi_conn *conn, struct iscsi_task *task,
new_offset = r2t->data_offset + r2t->sent;
hdr->offset = cpu_to_be32(new_offset);
if (left > conn->max_xmit_dlength) {
- hton24(hdr->dlength, conn->max_xmit_dlength);
+ hdr->dlength = hton24(conn->max_xmit_dlength);
r2t->data_count = conn->max_xmit_dlength;
} else {
- hton24(hdr->dlength, left);
+ hdr->dlength = hton24(left);
r2t->data_count = left;
hdr->flags = ISCSI_FLAG_CMD_FINAL;
}
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index 299e075..8432318 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -105,12 +105,12 @@ void iscsi_prep_unsolicit_data_pdu(struct iscsi_task *task,
hdr->offset = cpu_to_be32(task->unsol_offset);
if (task->unsol_count > conn->max_xmit_dlength) {
- hton24(hdr->dlength, conn->max_xmit_dlength);
+ hdr->dlength = hton24(conn->max_xmit_dlength);
task->data_count = conn->max_xmit_dlength;
task->unsol_offset += task->data_count;
hdr->flags = 0;
} else {
- hton24(hdr->dlength, task->unsol_count);
+ hdr->dlength = hton24(task->unsol_count);
task->data_count = task->unsol_count;
hdr->flags = ISCSI_FLAG_CMD_FINAL;
}
@@ -269,7 +269,7 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task)
else
task->imm_count = min(out_len,
conn->max_xmit_dlength);
- hton24(hdr->dlength, task->imm_count);
+ hdr->dlength = hton24(task->imm_count);
} else
zero_data(hdr->dlength);
diff --git a/include/scsi/iscsi_proto.h b/include/scsi/iscsi_proto.h
index 429c5ff..a778097 100644
--- a/include/scsi/iscsi_proto.h
+++ b/include/scsi/iscsi_proto.h
@@ -35,15 +35,7 @@
/*
* useful common(control and data pathes) macro
*/
-#undef ntoh24
-#undef hton24
-#define ntoh24(p) (((p)[0] << 16) | ((p)[1] << 8) | ((p)[2]))
-#define hton24(p, v) { \
- p[0] = (((v) >> 16) & 0xFF); \
- p[1] = (((v) >> 8) & 0xFF); \
- p[2] = ((v) & 0xFF); \
-}
-#define zero_data(p) {p[0]=0;p[1]=0;p[2]=0;}
+#define zero_data(x) (x) = (__be24) { .b = { 0, 0, 0 } }
/* initiator tags; opaque for target */
typedef uint32_t __bitwise__ itt_t;
@@ -61,7 +53,7 @@ struct iscsi_hdr {
uint8_t flags; /* Final bit */
uint8_t rsvd2[2];
uint8_t hlength; /* AHSs total length */
- uint8_t dlength[3]; /* Data length */
+ __be24 dlength; /* Data length */
uint8_t lun[8];
itt_t itt; /* Initiator Task Tag, opaque for target */
__be32 ttt; /* Target Task Tag */
@@ -123,7 +115,7 @@ struct iscsi_cmd {
uint8_t flags;
__be16 rsvd2;
uint8_t hlength;
- uint8_t dlength[3];
+ __be24 dlength;
uint8_t lun[8];
itt_t itt; /* Initiator Task Tag */
__be32 data_length;
@@ -169,7 +161,7 @@ struct iscsi_cmd_rsp {
uint8_t response;
uint8_t cmd_status;
uint8_t hlength;
- uint8_t dlength[3];
+ __be24 dlength;
uint8_t rsvd[8];
itt_t itt; /* Initiator Task Tag */
__be32 rsvd1;
@@ -199,7 +191,7 @@ struct iscsi_async {
uint8_t flags;
uint8_t rsvd2[2];
uint8_t rsvd3;
- uint8_t dlength[3];
+ __be24 dlength;
uint8_t lun[8];
uint8_t rsvd4[8];
__be32 statsn;
@@ -227,7 +219,7 @@ struct iscsi_nopout {
uint8_t flags;
__be16 rsvd2;
uint8_t rsvd3;
- uint8_t dlength[3];
+ __be24 dlength;
uint8_t lun[8];
itt_t itt; /* Initiator Task Tag */
__be32 ttt; /* Target Transfer Tag */
@@ -242,7 +234,7 @@ struct iscsi_nopin {
uint8_t flags;
__be16 rsvd2;
uint8_t rsvd3;
- uint8_t dlength[3];
+ __be24 dlength;
uint8_t lun[8];
itt_t itt; /* Initiator Task Tag */
__be32 ttt; /* Target Transfer Tag */
@@ -258,7 +250,7 @@ struct iscsi_tm {
uint8_t flags;
uint8_t rsvd1[2];
uint8_t hlength;
- uint8_t dlength[3];
+ __be24 dlength;
uint8_t lun[8];
itt_t itt; /* Initiator Task Tag */
itt_t rtt; /* Reference Task Tag */
@@ -288,7 +280,7 @@ struct iscsi_tm_rsp {
uint8_t response; /* see Response values below */
uint8_t qualifier;
uint8_t hlength;
- uint8_t dlength[3];
+ __be24 dlength;
uint8_t rsvd2[8];
itt_t itt; /* Initiator Task Tag */
itt_t rtt; /* Reference Task Tag */
@@ -314,7 +306,7 @@ struct iscsi_r2t_rsp {
uint8_t flags;
uint8_t rsvd2[2];
uint8_t hlength;
- uint8_t dlength[3];
+ __be24 dlength;
uint8_t lun[8];
itt_t itt; /* Initiator Task Tag */
__be32 ttt; /* Target Transfer Tag */
@@ -332,7 +324,7 @@ struct iscsi_data {
uint8_t flags;
uint8_t rsvd2[2];
uint8_t rsvd3;
- uint8_t dlength[3];
+ __be24 dlength;
uint8_t lun[8];
itt_t itt;
__be32 ttt;
@@ -352,7 +344,7 @@ struct iscsi_data_rsp {
uint8_t rsvd2;
uint8_t cmd_status;
uint8_t hlength;
- uint8_t dlength[3];
+ __be24 dlength;
uint8_t lun[8];
itt_t itt;
__be32 ttt;
@@ -376,7 +368,7 @@ struct iscsi_text {
uint8_t flags;
uint8_t rsvd2[2];
uint8_t hlength;
- uint8_t dlength[3];
+ __be24 dlength;
uint8_t rsvd4[8];
itt_t itt;
__be32 ttt;
@@ -394,7 +386,7 @@ struct iscsi_text_rsp {
uint8_t flags;
uint8_t rsvd2[2];
uint8_t hlength;
- uint8_t dlength[3];
+ __be24 dlength;
uint8_t rsvd4[8];
itt_t itt;
__be32 ttt;
@@ -412,7 +404,7 @@ struct iscsi_login {
uint8_t max_version; /* Max. version supported */
uint8_t min_version; /* Min. version supported */
uint8_t hlength;
- uint8_t dlength[3];
+ __be24 dlength;
uint8_t isid[6]; /* Initiator Session ID */
__be16 tsih; /* Target Session Handle */
itt_t itt; /* Initiator Task Tag */
@@ -441,7 +433,7 @@ struct iscsi_login_rsp {
uint8_t max_version; /* Max. version supported */
uint8_t active_version; /* Active version */
uint8_t hlength;
- uint8_t dlength[3];
+ __be24 dlength;
uint8_t isid[6]; /* Initiator Session ID */
__be16 tsih; /* Target Session Handle */
itt_t itt; /* Initiator Task Tag */
@@ -499,7 +491,7 @@ struct iscsi_logout {
uint8_t flags;
uint8_t rsvd1[2];
uint8_t hlength;
- uint8_t dlength[3];
+ __be24 dlength;
uint8_t rsvd2[8];
itt_t itt; /* Initiator Task Tag */
__be16 cid;
@@ -526,7 +518,7 @@ struct iscsi_logout_rsp {
uint8_t response; /* see Logout response values below */
uint8_t rsvd2;
uint8_t hlength;
- uint8_t dlength[3];
+ __be24 dlength;
uint8_t rsvd3[8];
itt_t itt; /* Initiator Task Tag */
__be32 rsvd4;
@@ -570,7 +562,7 @@ struct iscsi_reject {
uint8_t reason;
uint8_t rsvd2;
uint8_t hlength;
- uint8_t dlength[3];
+ __be24 dlength;
uint8_t rsvd3[8];
__be32 ffffffff;
uint8_t rsvd4[4];
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH 4/4] 24-bit types: Convert Open-FCoE to use __be24 type and macros
2008-09-11 2:14 [PATCH 1/4] 24-bit types: typedef and functions for accessing 3-byte arrays as integers Chris Leech
2008-09-11 2:14 ` [PATCH 2/4] 24-bit types: convert iSCSI to use the __be24 type and macros Chris Leech
2008-09-11 2:15 ` [PATCH 3/4] 24-bit types: Convert jfs to use the common 24-bit types Chris Leech
@ 2008-09-11 2:15 ` Chris Leech
2008-09-11 8:03 ` [PATCH 1/4] 24-bit types: typedef and functions for accessing 3-byte arrays as integers Boaz Harrosh
3 siblings, 0 replies; 7+ messages in thread
From: Chris Leech @ 2008-09-11 2:15 UTC (permalink / raw)
To: linux-kernel, linux-scsi
Cc: jfs-discussion, Boaz Harrosh, Harvey Harrison, Chris Leech
This converts the Open-FCoE tree to use the common 24-bit types
Signed-off-by: Chris Leech <christopher.leech@intel.com>
---
drivers/scsi/fcoe/fcoe_dev.c | 6 +++---
drivers/scsi/libfc/fc_exch.c | 24 ++++++++++++------------
drivers/scsi/libfc/fc_fcp.c | 2 +-
drivers/scsi/libfc/fc_lport.c | 8 ++++----
drivers/scsi/libfc/fc_ns.c | 14 +++++++-------
drivers/scsi/libfc/fc_rport.c | 4 ++--
include/scsi/fc/fc_els.h | 18 +++++++++---------
include/scsi/fc/fc_fcoe.h | 6 ++----
include/scsi/fc/fc_fs.h | 8 ++++----
include/scsi/fc/fc_gs.h | 2 +-
include/scsi/fc/fc_ns.h | 6 +++---
include/scsi/libfc/libfc.h | 13 -------------
12 files changed, 48 insertions(+), 63 deletions(-)
diff --git a/drivers/scsi/fcoe/fcoe_dev.c b/drivers/scsi/fcoe/fcoe_dev.c
index d5a354f..d5fc479 100644
--- a/drivers/scsi/fcoe/fcoe_dev.c
+++ b/drivers/scsi/fcoe/fcoe_dev.c
@@ -233,7 +233,7 @@ int fcoe_xmit(struct fc_lport *lp, struct fc_frame *fp)
* MAC in this case would have been set by receving the
* FLOGI.
*/
- fc_fcoe_set_mac(fc->data_src_addr, fh->fh_s_id);
+ fc_fcoe_set_mac(fc->data_src_addr, &fh->fh_s_id);
fc->flogi_progress = 0;
}
}
@@ -311,7 +311,7 @@ int fcoe_xmit(struct fc_lport *lp, struct fc_frame *fp)
skb->ip_summed = CHECKSUM_NONE;
eh = (struct ethhdr *)skb_push(skb, hlen + sizeof(struct ethhdr));
if (fc->address_mode == FCOE_FCOUI_ADDR_MODE)
- fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
+ fc_fcoe_set_mac(eh->h_dest, &fh->fh_d_id);
else
/* insert GW address */
memcpy(eh->h_dest, fc->dest_addr, ETH_ALEN);
@@ -516,7 +516,7 @@ static void fcoe_recv_flogi(struct fcoe_softc *fc, struct fc_frame *fp, u8 *sa)
if (compare_ether_addr(fc->data_src_addr, (u8[6]) { 0 }))
dev_unicast_delete(fc->real_dev, fc->data_src_addr,
ETH_ALEN);
- fc_fcoe_set_mac(fc->data_src_addr, fh->fh_d_id);
+ fc_fcoe_set_mac(fc->data_src_addr, &fh->fh_d_id);
dev_unicast_add(fc->real_dev, fc->data_src_addr, ETH_ALEN);
rtnl_unlock();
diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
index 11a03bd..9fd011b 100644
--- a/drivers/scsi/libfc/fc_exch.c
+++ b/drivers/scsi/libfc/fc_exch.c
@@ -278,8 +278,8 @@ static void fc_seq_fill_hdr(struct fc_seq *sp, struct fc_frame *fp)
ep = fc_seq_exch(sp);
- hton24(fh->fh_s_id, ep->sid);
- hton24(fh->fh_d_id, ep->did);
+ fh->fh_s_id = hton24(ep->sid);
+ fh->fh_d_id = hton24(ep->did);
fh->fh_ox_id = htons(ep->oxid);
fh->fh_rx_id = htons(ep->rxid);
fh->fh_seq_id = sp->id;
@@ -892,7 +892,7 @@ int fc_seq_send(struct fc_lport *lp, struct fc_seq *sp,
fr_eof(fp) = FC_EOF_N;
}
- hton24(fh->fh_f_ctl, f_ctl | fill);
+ fh->fh_f_ctl = hton24(f_ctl | fill);
fh->fh_seq_cnt = htons(sp->cnt++);
/*
@@ -992,7 +992,7 @@ static void fc_seq_send_ack(struct fc_seq *sp, const struct fc_frame *rx_fp)
FC_FC_END_SEQ | FC_FC_END_CONN | FC_FC_SEQ_INIT |
FC_FC_RETX_SEQ | FC_FC_UNI_TX;
f_ctl ^= FC_FC_EX_CTX | FC_FC_SEQ_CTX;
- hton24(fh->fh_f_ctl, f_ctl);
+ fh->fh_f_ctl = hton24(f_ctl);
fh->fh_seq_id = rx_fh->fh_seq_id;
fh->fh_seq_cnt = rx_fh->fh_seq_cnt;
@@ -1039,8 +1039,8 @@ fc_exch_send_ba_rjt(struct fc_frame *rx_fp, enum fc_ba_rjt_reason reason,
/*
* seq_id, cs_ctl, df_ctl and param/offset are zero.
*/
- memcpy(fh->fh_s_id, rx_fh->fh_d_id, 3);
- memcpy(fh->fh_d_id, rx_fh->fh_s_id, 3);
+ fh->fh_s_id = rx_fh->fh_d_id;
+ fh->fh_d_id = rx_fh->fh_s_id;
fh->fh_ox_id = rx_fh->fh_rx_id;
fh->fh_rx_id = rx_fh->fh_ox_id;
fh->fh_seq_cnt = rx_fh->fh_seq_cnt;
@@ -1062,7 +1062,7 @@ fc_exch_send_ba_rjt(struct fc_frame *rx_fp, enum fc_ba_rjt_reason reason,
f_ctl ^= FC_FC_EX_CTX | FC_FC_SEQ_CTX;
f_ctl |= FC_FC_LAST_SEQ | FC_FC_END_SEQ;
f_ctl &= ~FC_FC_FIRST_SEQ;
- hton24(fh->fh_f_ctl, f_ctl);
+ fh->fh_f_ctl = hton24(f_ctl);
fr_sof(fp) = fc_sof_class(fr_sof(rx_fp));
fr_eof(fp) = FC_EOF_T;
@@ -1607,12 +1607,12 @@ static void fc_exch_els_rec(struct fc_seq *sp, struct fc_frame *rfp)
memset(acc, 0, sizeof(*acc));
acc->reca_cmd = ELS_LS_ACC;
acc->reca_ox_id = rp->rec_ox_id;
- memcpy(acc->reca_ofid, rp->rec_s_id, 3);
+ acc->reca_ofid = rp->rec_s_id;
acc->reca_rx_id = htons(ep->rxid);
if (ep->sid == ep->oid)
- hton24(acc->reca_rfid, ep->did);
+ acc->reca_rfid = hton24(ep->did);
else
- hton24(acc->reca_rfid, ep->sid);
+ acc->reca_rfid = hton24(ep->sid);
acc->reca_fc4value = htonl(ep->seq.rec_data);
acc->reca_e_stat = htonl(ep->esb_stat & (ESB_ST_RESP |
ESB_ST_SEQ_INIT |
@@ -1704,7 +1704,7 @@ static void fc_exch_rrq(struct fc_exch *ep)
rrq = fc_frame_payload_get(fp, sizeof(*rrq));
memset(rrq, 0, sizeof(*rrq));
rrq->rrq_cmd = ELS_RRQ;
- hton24(rrq->rrq_s_id, ep->sid);
+ rrq->rrq_s_id = hton24(ep->sid);
rrq->rrq_ox_id = htons(ep->oxid);
rrq->rrq_rx_id = htons(ep->rxid);
@@ -1906,7 +1906,7 @@ struct fc_seq *fc_exch_seq_send(struct fc_lport *lp,
}
f_ctl |= ep->f_ctl;
fh = fc_frame_header_get(fp);
- hton24(fh->fh_f_ctl, f_ctl | fill);
+ fh->fh_f_ctl = hton24(f_ctl | fill);
fh->fh_seq_cnt = htons(sp->cnt++);
if (unlikely(lp->tt.frame_send(lp, fp)))
diff --git a/drivers/scsi/libfc/fc_fcp.c b/drivers/scsi/libfc/fc_fcp.c
index 9402eba..6c24724 100644
--- a/drivers/scsi/libfc/fc_fcp.c
+++ b/drivers/scsi/libfc/fc_fcp.c
@@ -1332,7 +1332,7 @@ static void fc_fcp_rec(struct fc_fcp_pkt *fsp)
rec = fc_frame_payload_get(fp, sizeof(*rec));
memset(rec, 0, sizeof(*rec));
rec->rec_cmd = ELS_REC;
- hton24(rec->rec_s_id, lp->fid);
+ rec->rec_s_id = hton24(lp->fid);
rec->rec_ox_id = htons(ox_id);
rec->rec_rx_id = htons(rx_id);
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index b06f519..ad5c5b1 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -244,8 +244,8 @@ static void fc_lport_rnid_req(struct fc_seq *sp, struct fc_frame *in_fp,
rp->rnid.rnid_cmd = ELS_LS_ACC;
rp->rnid.rnid_fmt = fmt;
rp->rnid.rnid_cid_len = sizeof(rp->cid);
- rp->cid.rnid_wwpn = htonll(lp->wwpn);
- rp->cid.rnid_wwnn = htonll(lp->wwnn);
+ rp->cid.rnid_wwpn = cpu_to_be64(lp->wwpn);
+ rp->cid.rnid_wwnn = cpu_to_be64(lp->wwnn);
if (fmt == ELS_RNIDF_GEN) {
rp->rnid.rnid_sid_len = sizeof(rp->gen);
memcpy(&rp->gen, &lp->rnid_gen,
@@ -747,8 +747,8 @@ static void fc_lport_enter_logo(struct fc_lport *lp)
logo = fc_frame_payload_get(fp, sizeof(*logo));
memset(logo, 0, sizeof(*logo));
logo->fl_cmd = ELS_LOGO;
- hton24(logo->fl_n_port_id, lp->fid);
- logo->fl_n_port_wwn = htonll(lp->wwpn);
+ logo->fl_n_port_id = hton24(lp->fid);
+ logo->fl_n_port_wwn = cpu_to_be64(lp->wwpn);
fc_frame_setup(fp, FC_RCTL_ELS_REQ, FC_TYPE_ELS);
fc_frame_set_offset(fp, 0);
diff --git a/drivers/scsi/libfc/fc_ns.c b/drivers/scsi/libfc/fc_ns.c
index 6204bcc..c280913 100644
--- a/drivers/scsi/libfc/fc_ns.c
+++ b/drivers/scsi/libfc/fc_ns.c
@@ -265,7 +265,7 @@ static void fc_ns_enter_reg_ft(struct fc_lport *lp)
FC_NS_RFT_ID,
sizeof(*req) -
sizeof(struct fc_ct_hdr));
- hton24(req->fid.fp_fid, lp->fid);
+ req->fid.fp_fid = hton24(lp->fid);
req->fts = *lps;
fc_frame_setup(fp, FC_RCTL_DD_UNSOL_CTL, FC_TYPE_CT);
if (!lp->tt.exch_seq_send(lp, fp,
@@ -774,7 +774,7 @@ static int fc_ns_gpn_ft_parse(struct fc_lport *lp, void *buf, size_t len)
break;
dp->lp = lp;
dp->ids.port_id = ntoh24(np->fp_fid);
- dp->ids.port_name = ntohll(np->fp_wwpn);
+ dp->ids.port_name = be64_to_cpu(np->fp_wwpn);
dp->ids.node_name = -1;
dp->ids.roles = FC_RPORT_ROLE_UNKNOWN;
error = fc_ns_gnn_id_req(lp, dp);
@@ -934,7 +934,7 @@ static int fc_ns_gpn_id_req(struct fc_lport *lp, struct fc_ns_port *dp)
cp = fc_frame_payload_get(fp, sizeof(*cp));
fc_ns_fill_dns_hdr(lp, &cp->ct, FC_NS_GPN_ID, sizeof(cp->fid));
- hton24(cp->fid.fp_fid, dp->ids.port_id);
+ cp->fid.fp_fid = hton24(dp->ids.port_id);
WARN_ON(!fc_lport_test_ready(lp));
@@ -989,7 +989,7 @@ static void fc_ns_gpn_id_resp(struct fc_seq *sp, struct fc_frame *fp,
fr_len(fp));
break;
}
- dp->ids.port_name = ntohll(cp->wwn);
+ dp->ids.port_name = be64_to_cpu(cp->wwn);
fc_ns_gnn_id_req(lp, dp);
break;
case FC_FS_RJT:
@@ -1137,7 +1137,7 @@ static void fc_ns_enter_reg_pn(struct fc_lport *lp)
req = fc_frame_payload_get(fp, sizeof(*req));
memset(req, 0, sizeof(*req));
fc_lport_fill_dns_hdr(lp, &req->ct, FC_NS_RPN_ID, sizeof(req->rn));
- hton24(req->rn.fr_fid.fp_fid, lp->fid);
+ req->rn.fr_fid.fp_fid = hton24(lp->fid);
put_unaligned_be64(lp->wwpn, &req->rn.fr_wwn);
fc_frame_setup(fp, FC_RCTL_DD_UNSOL_CTL, FC_TYPE_CT);
if (!lp->tt.exch_seq_send(lp, fp,
@@ -1191,7 +1191,7 @@ static int fc_ns_gnn_id_req(struct fc_lport *lp, struct fc_ns_port *dp)
cp = fc_frame_payload_get(fp, sizeof(*cp));
fc_ns_fill_dns_hdr(lp, &cp->ct, FC_NS_GNN_ID, sizeof(cp->fid));
- hton24(cp->fid.fp_fid, dp->ids.port_id);
+ cp->fid.fp_fid = hton24(dp->ids.port_id);
WARN_ON(!fc_lport_test_ready(lp));
@@ -1246,7 +1246,7 @@ static void fc_ns_gnn_id_resp(struct fc_seq *sp, struct fc_frame *fp,
fr_len(fp));
break;
}
- dp->ids.node_name = ntohll(cp->wwn);
+ dp->ids.node_name = be64_to_cpu(cp->wwn);
fc_ns_new_target(lp, NULL, &dp->ids);
break;
case FC_FS_RJT:
diff --git a/drivers/scsi/libfc/fc_rport.c b/drivers/scsi/libfc/fc_rport.c
index cd559dd..0ca4c12 100644
--- a/drivers/scsi/libfc/fc_rport.c
+++ b/drivers/scsi/libfc/fc_rport.c
@@ -857,8 +857,8 @@ static void fc_rport_enter_logo(struct fc_rport *rport)
logo = fc_frame_payload_get(fp, sizeof(*logo));
memset(logo, 0, sizeof(*logo));
logo->fl_cmd = ELS_LOGO;
- hton24(logo->fl_n_port_id, lp->fid);
- logo->fl_n_port_wwn = htonll(lp->wwpn);
+ logo->fl_n_port_id = hton24(lp->fid);
+ logo->fl_n_port_wwn = cpu_to_be64(lp->wwpn);
fc_frame_setup(fp, FC_RCTL_ELS_REQ, FC_TYPE_ELS);
if (!lp->tt.exch_seq_send(lp, fp,
diff --git a/include/scsi/fc/fc_els.h b/include/scsi/fc/fc_els.h
index af4bf0c..c1cfe21 100644
--- a/include/scsi/fc/fc_els.h
+++ b/include/scsi/fc/fc_els.h
@@ -357,7 +357,7 @@ struct fc_els_rrq {
__u8 rrq_cmd; /* command (0x12) */
__u8 rrq_zero[3]; /* specified as zero - part of cmd */
__u8 rrq_resvd; /* reserved */
- __u8 rrq_s_id[3]; /* originator FID */
+ __be24 rrq_s_id; /* originator FID */
__be16 rrq_ox_id; /* originator exchange ID */
__be16 rrq_rx_id; /* responders exchange ID */
};
@@ -369,7 +369,7 @@ struct fc_els_rec {
__u8 rec_cmd; /* command (0x13) */
__u8 rec_zero[3]; /* specified as zero - part of cmd */
__u8 rec_resvd; /* reserved */
- __u8 rec_s_id[3]; /* originator FID */
+ __be24 rec_s_id; /* originator FID */
__be16 rec_ox_id; /* originator exchange ID */
__be16 rec_rx_id; /* responders exchange ID */
};
@@ -383,9 +383,9 @@ struct fc_els_rec_acc {
__be16 reca_ox_id; /* originator exchange ID */
__be16 reca_rx_id; /* responders exchange ID */
__u8 reca_resvd1; /* reserved */
- __u8 reca_ofid[3]; /* originator FID */
+ __be24 reca_ofid; /* originator FID */
__u8 reca_resvd2; /* reserved */
- __u8 reca_rfid[3]; /* responder FID */
+ __be24 reca_rfid; /* responder FID */
__be32 reca_fc4value; /* FC4 value */
__be32 reca_e_stat; /* ESB (exchange status block) status */
};
@@ -407,7 +407,7 @@ struct fc_els_logo {
__u8 fl_cmd; /* command code */
__u8 fl_zero[3]; /* specified as zero - part of cmd */
__u8 fl_resvd; /* reserved */
- __u8 fl_n_port_id[3];/* N port ID */
+ __be24 fl_n_port_id; /* N port ID */
__be64 fl_n_port_wwn; /* port name */
};
@@ -465,7 +465,7 @@ struct fc_els_rscn {
struct fc_els_rscn_page {
__u8 rscn_page_flags; /* event and address format */
- __u8 rscn_fid[3]; /* fabric ID */
+ __be24 rscn_fid; /* fabric ID */
};
#define ELS_RSCN_EV_QUAL_BIT 2 /* shift count for event qualifier */
@@ -598,7 +598,7 @@ struct fc_els_rpl {
struct fc_els_pnb {
__be32 pnb_phys_pn; /* physical port number */
__u8 pnb_resv; /* reserved */
- __u8 pnb_port_id[3]; /* port ID */
+ __be24 pnb_port_id; /* port ID */
__be64 pnb_wwpn; /* port name */
};
@@ -709,7 +709,7 @@ enum fc_els_srl_flag {
struct fc_els_rls {
__u8 rls_cmd; /* command */
__u8 rls_resv[4]; /* reserved - must be zero */
- __u8 rls_port_id[3]; /* port ID */
+ __be24 rls_port_id; /* port ID */
};
/*
@@ -741,7 +741,7 @@ struct fc_els_clir {
__be64 clir_wwpn; /* incident port name */
__be64 clir_wwnn; /* incident port node name */
__u8 clir_port_type; /* incident port type */
- __u8 clir_port_id[3]; /* incident port ID */
+ __be24 clir_port_id; /* incident port ID */
__be64 clir_conn_wwpn; /* connected port name */
__be64 clir_conn_wwnn; /* connected node name */
diff --git a/include/scsi/fc/fc_fcoe.h b/include/scsi/fc/fc_fcoe.h
index b2e07ec..4c0f692 100644
--- a/include/scsi/fc/fc_fcoe.h
+++ b/include/scsi/fc/fc_fcoe.h
@@ -83,14 +83,12 @@ struct fcoe_crc_eof {
/*
* Store OUI + DID into MAC address field.
*/
-static inline void fc_fcoe_set_mac(u8 *mac, u8 *did)
+static inline void fc_fcoe_set_mac(u8 *mac, __be24 *did)
{
mac[0] = (u8) (FC_FCOE_OUI >> 16);
mac[1] = (u8) (FC_FCOE_OUI >> 8);
mac[2] = (u8) FC_FCOE_OUI;
- mac[3] = did[0];
- mac[4] = did[1];
- mac[5] = did[2];
+ *(__be24 *) &mac[3] = *did;
}
/*
diff --git a/include/scsi/fc/fc_fs.h b/include/scsi/fc/fc_fs.h
index ba6df64..125ba15 100644
--- a/include/scsi/fc/fc_fs.h
+++ b/include/scsi/fc/fc_fs.h
@@ -29,14 +29,14 @@
* Frame header
*/
struct fc_frame_header {
- __u8 fh_r_ctl; /* routing control */
- __u8 fh_d_id[3]; /* Destination ID */
+ __u8 fh_r_ctl; /* routing control */
+ __be24 fh_d_id; /* Destination ID */
__u8 fh_cs_ctl; /* class of service control / pri */
- __u8 fh_s_id[3]; /* Source ID */
+ __be24 fh_s_id; /* Source ID */
__u8 fh_type; /* see enum fc_fh_type below */
- __u8 fh_f_ctl[3]; /* frame control */
+ __be24 fh_f_ctl; /* frame control */
__u8 fh_seq_id; /* sequence ID */
__u8 fh_df_ctl; /* data field control */
diff --git a/include/scsi/fc/fc_gs.h b/include/scsi/fc/fc_gs.h
index ffab027..fb082bf 100644
--- a/include/scsi/fc/fc_gs.h
+++ b/include/scsi/fc/fc_gs.h
@@ -27,7 +27,7 @@
struct fc_ct_hdr {
__u8 ct_rev; /* revision */
- __u8 ct_in_id[3]; /* N_Port ID of original requestor */
+ __be24 ct_in_id; /* N_Port ID of original requestor */
__u8 ct_fs_type; /* type of fibre channel service */
__u8 ct_fs_subtype; /* subtype */
__u8 ct_options;
diff --git a/include/scsi/fc/fc_ns.h b/include/scsi/fc/fc_ns.h
index 790d7b9..44c3019 100644
--- a/include/scsi/fc/fc_ns.h
+++ b/include/scsi/fc/fc_ns.h
@@ -76,7 +76,7 @@ struct fc_ns_pt_obj {
*/
struct fc_ns_fid {
__u8 fp_flags; /* flags for responses only */
- __u8 fp_fid[3];
+ __be24 fp_fid;
};
/*
@@ -119,7 +119,7 @@ struct fc_ns_gid_ft {
*/
struct fc_gpn_ft_resp {
__u8 fp_flags; /* see fp_flags definitions above */
- __u8 fp_fid[3]; /* port ID */
+ __be24 fp_fid; /* port ID */
__be32 fp_resvd;
__be64 fp_wwpn; /* port name */
};
@@ -136,7 +136,7 @@ struct fc_ns_gid_pn {
*/
struct fc_gid_pn_resp {
__u8 fp_resvd;
- __u8 fp_fid[3]; /* port ID */
+ __be24 fp_fid; /* port ID */
};
/*
diff --git a/include/scsi/libfc/libfc.h b/include/scsi/libfc/libfc.h
index d8ec019..bfe91cf 100644
--- a/include/scsi/libfc/libfc.h
+++ b/include/scsi/libfc/libfc.h
@@ -53,19 +53,6 @@
#define FC_EX_TIMEOUT 1 /* Exchange timeout */
#define FC_EX_CLOSED 2 /* Exchange closed */
-/* some helpful macros */
-
-#define ntohll(x) be64_to_cpu(x)
-#define htonll(x) cpu_to_be64(x)
-
-#define ntoh24(p) (((p)[0] << 16) | ((p)[1] << 8) | ((p)[2]))
-
-#define hton24(p, v) do { \
- p[0] = (((v) >> 16) & 0xFF); \
- p[1] = (((v) >> 8) & 0xFF); \
- p[2] = ((v) & 0xFF); \
-} while (0)
-
struct fc_exch_mgr;
/*
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH 1/4] 24-bit types: typedef and functions for accessing 3-byte arrays as integers
2008-09-11 2:14 [PATCH 1/4] 24-bit types: typedef and functions for accessing 3-byte arrays as integers Chris Leech
` (2 preceding siblings ...)
2008-09-11 2:15 ` [PATCH 4/4] 24-bit types: Convert Open-FCoE to use __be24 type and macros Chris Leech
@ 2008-09-11 8:03 ` Boaz Harrosh
2008-09-11 14:12 ` Chris Leech
3 siblings, 1 reply; 7+ messages in thread
From: Boaz Harrosh @ 2008-09-11 8:03 UTC (permalink / raw)
To: Chris Leech; +Cc: linux-kernel, linux-scsi, jfs-discussion, Harvey Harrison
Chris Leech wrote:
> Both iSCSI and Fibre Channel make use of 24-bit big-endian values in
> frame headers. This patch defines __be24 and __le24 typedefs for a
> structure wrapped around a 3-byte array, and functions to convert back and
> forth to a 32-bit integer.
>
> The undefs in iscsi_proto.h are because of the different calling
> convention for the existing hton24 macro in the iSCSI code. iSCSI will
> be converted in a subsequent patch.
>
> The undefs in fs/jfs/endian24.h allow JFS to continue using it's own le24
> conversion macros. JFS is converted to use these types and functions in a
> subsequent patch.
>
> Change from last posting:
>
> Moved the 24-bit inline functions to their own header instead of having
> duplicate definitions in linux/byteorder.h and linux/byteorder/generic.h
>
> Signed-off-by: Chris Leech <christopher.leech@intel.com>
> ---
>
> fs/jfs/endian24.h | 5 ++++
> include/linux/byteorder.h | 9 ++++++++
> include/linux/byteorder/generic.h | 10 ++++++++
> include/linux/endian24.h | 44 +++++++++++++++++++++++++++++++++++++
> include/linux/types.h | 2 ++
> include/scsi/iscsi_proto.h | 2 ++
> 6 files changed, 72 insertions(+), 0 deletions(-)
> create mode 100644 include/linux/endian24.h
>
>
> diff --git a/fs/jfs/endian24.h b/fs/jfs/endian24.h
> index fa92f7f..45b6397 100644
> --- a/fs/jfs/endian24.h
> +++ b/fs/jfs/endian24.h
> @@ -33,6 +33,9 @@
> ((__x & (__u32)0x00ff0000UL) >> 16) )); \
> })
>
> +#undef __cpu_to_le24
> +#undef __le24_to_cpu
> +
Does #undef also work on inline functions? I didn't know that
> #if (defined(__KERNEL__) && defined(__LITTLE_ENDIAN)) || (defined(__BYTE_ORDER) && (__BYTE_ORDER == __LITTLE_ENDIAN))
> #define __cpu_to_le24(x) ((__u32)(x))
> #define __le24_to_cpu(x) ((__u32)(x))
> @@ -42,6 +45,8 @@
> #endif
>
> #ifdef __KERNEL__
> + #undef cpu_to_le24
> + #undef le24_to_cpu
> #define cpu_to_le24 __cpu_to_le24
> #define le24_to_cpu __le24_to_cpu
> #endif
> diff --git a/include/linux/byteorder.h b/include/linux/byteorder.h
> index 29f002d..2334e3f 100644
> --- a/include/linux/byteorder.h
> +++ b/include/linux/byteorder.h
> @@ -3,6 +3,7 @@
>
> #include <linux/types.h>
> #include <linux/swab.h>
> +#include <linux/endian24.h>
>
> #if defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN)
> # error Fix asm/byteorder.h to define one endianness
> @@ -280,15 +281,19 @@ static inline __be64 __cpu_to_be64p(const __u64 *p)
> #ifdef __KERNEL__
>
> # define le16_to_cpu __le16_to_cpu
> +# define le24_to_cpu __le24_to_cpu
> # define le32_to_cpu __le32_to_cpu
> # define le64_to_cpu __le64_to_cpu
> # define be16_to_cpu __be16_to_cpu
> +# define be24_to_cpu __be24_to_cpu
> # define be32_to_cpu __be32_to_cpu
> # define be64_to_cpu __be64_to_cpu
> # define cpu_to_le16 __cpu_to_le16
> +# define cpu_to_le24 __cpu_to_le24
> # define cpu_to_le32 __cpu_to_le32
> # define cpu_to_le64 __cpu_to_le64
> # define cpu_to_be16 __cpu_to_be16
> +# define cpu_to_be24 __cpu_to_be24
> # define cpu_to_be32 __cpu_to_be32
> # define cpu_to_be64 __cpu_to_be64
>
> @@ -332,11 +337,15 @@ static inline __be64 __cpu_to_be64p(const __u64 *p)
> # define ___htons(x) __cpu_to_be16(x)
> # define ___ntohl(x) __be32_to_cpu(x)
> # define ___ntohs(x) __be16_to_cpu(x)
> +# define ___hton24(x) __cpu_to_be24(x)
> +# define ___ntoh24(x) __be24_to_cpu(x)
>
> # define htonl(x) ___htonl(x)
> # define ntohl(x) ___ntohl(x)
> # define htons(x) ___htons(x)
> # define ntohs(x) ___ntohs(x)
> +# define hton24(x) ___hton24(x)
> +# define ntoh24(x) ___ntoh24(x)
>
> static inline void le16_add_cpu(__le16 *var, u16 val)
> {
> diff --git a/include/linux/byteorder/generic.h b/include/linux/byteorder/generic.h
> index 0846e6b..87cbec2 100644
> --- a/include/linux/byteorder/generic.h
> +++ b/include/linux/byteorder/generic.h
> @@ -1,6 +1,8 @@
> #ifndef _LINUX_BYTEORDER_GENERIC_H
> #define _LINUX_BYTEORDER_GENERIC_H
>
> +#include <linux/endian24.h>
> +
> /*
> * linux/byteorder_generic.h
> * Generic Byte-reordering support
> @@ -86,12 +88,16 @@
> #define le64_to_cpu __le64_to_cpu
> #define cpu_to_le32 __cpu_to_le32
> #define le32_to_cpu __le32_to_cpu
> +#define cpu_to_le24 __cpu_to_le24
> +#define le24_to_cpu __le24_to_cpu
> #define cpu_to_le16 __cpu_to_le16
> #define le16_to_cpu __le16_to_cpu
> #define cpu_to_be64 __cpu_to_be64
> #define be64_to_cpu __be64_to_cpu
> #define cpu_to_be32 __cpu_to_be32
> #define be32_to_cpu __be32_to_cpu
> +#define cpu_to_be24 __cpu_to_be24
> +#define be24_to_cpu __be24_to_cpu
> #define cpu_to_be16 __cpu_to_be16
> #define be16_to_cpu __be16_to_cpu
> #define cpu_to_le64p __cpu_to_le64p
> @@ -134,11 +140,15 @@
> #define ___htons(x) __cpu_to_be16(x)
> #define ___ntohl(x) __be32_to_cpu(x)
> #define ___ntohs(x) __be16_to_cpu(x)
> +#define ___hton24(x) __cpu_to_be24(x)
> +#define ___ntoh24(x) __be24_to_cpu(x)
>
> #define htonl(x) ___htonl(x)
> #define ntohl(x) ___ntohl(x)
> #define htons(x) ___htons(x)
> #define ntohs(x) ___ntohs(x)
> +#define hton24(x) ___hton24(x)
> +#define ntoh24(x) ___ntoh24(x)
>
> static inline void le16_add_cpu(__le16 *var, u16 val)
> {
> diff --git a/include/linux/endian24.h b/include/linux/endian24.h
> new file mode 100644
> index 0000000..beffa57
> --- /dev/null
> +++ b/include/linux/endian24.h
> @@ -0,0 +1,44 @@
> +#ifndef _LINUX_ENDIAN24_H
> +#define _LINUX_ENDIAN24_H
> +
> +#if !defined(_LINUX_BYTEORDER_H) && !defined(_LINUX_BYTEORDER_GENERIC_H)
> +#error "do not include linux/endian24.h directly, use asm/byteorder.h instead"
> +#endif
> +
> +/**
> + * __le24_to_cpu - read a 3-byte array as a 24-bit little-endian integer
> + * @x: __le24, a structure wrapper around a 3-byte array
> + */
> +static __always_inline __u32 __le24_to_cpu(const __le24 x)
> +{
> + return (__u32) ((x.b[2] << 16) | (x.b[1] << 8) | (x.b[0]));
> +}
> +
> +/**
> + * __cpu_to_le24 - store a value in a 3-byte array in little-endian format
> + * @x: __u32, there is no checking to ensure only the lower 24 bits are set
> + */
> +static __always_inline __le24 __cpu_to_le24(const __u32 x)
> +{
> + return (__le24) { { x & 0xff, (x >> 8) & 0xff, (x >> 16) & 0xff } };
> +}
> +
> +/**
> + * __be24_to_cpu - read a 3-byte array as a 24-bit big-endian integer
> + * @x: __be24, a structure wrapper around a 3-byte array
> + */
> +static __always_inline __u32 __be24_to_cpu(const __be24 x)
> +{
> + return (__u32) ((x.b[0] << 16) | (x.b[1] << 8) | (x.b[2]));
> +}
> +
> +/**
> + * __cpu_to_be24 - store a value in a 3-byte array in big-endian format
> + * @x: __u32, there is no checking to ensure only the lower 24 bits are set
> + */
> +static __always_inline __be24 __cpu_to_be24(const __u32 x)
> +{
> + return (__be24) { { (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff } };
> +}
> +
> +#endif /* _LINUX_ENDIAN24_H */
> diff --git a/include/linux/types.h b/include/linux/types.h
> index d4a9ce6..85fcff7 100644
> --- a/include/linux/types.h
> +++ b/include/linux/types.h
> @@ -188,6 +188,8 @@ typedef __u64 __bitwise __be64;
> typedef __u16 __bitwise __sum16;
> typedef __u32 __bitwise __wsum;
>
> +typedef struct { __u8 b[3]; } __be24, __le24;
> +
> #ifdef __KERNEL__
> typedef unsigned __bitwise__ gfp_t;
>
> diff --git a/include/scsi/iscsi_proto.h b/include/scsi/iscsi_proto.h
> index f2a2c11..429c5ff 100644
> --- a/include/scsi/iscsi_proto.h
> +++ b/include/scsi/iscsi_proto.h
> @@ -35,6 +35,8 @@
> /*
> * useful common(control and data pathes) macro
> */
> +#undef ntoh24
> +#undef hton24
> #define ntoh24(p) (((p)[0] << 16) | ((p)[1] << 8) | ((p)[2]))
> #define hton24(p, v) { \
> p[0] = (((v) >> 16) & 0xFF); \
>
Thanks that looks grate.
Boaz
^ permalink raw reply [flat|nested] 7+ messages in thread