24-bit types: typedef and functions for accessing 3-byte arrays as integers
Subsystems (4)
PATCH 1/4 24-bit types: typedef and functions for accessing 3-byte arrays as integers
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
---
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
fs/jfs/endian24.h +5 -0
@@ -33,6 +33,9 @@ ((__x & (__u32)0x00ff0000UL) >> 16) )); \ }) +#undef __cpu_to_le24 +#undef __le24_to_cpu +#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
include/linux/byteorder.h +9 -0
@@ -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) {
include/linux/byteorder/generic.h +10 -0
@@ -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) {
include/linux/endian24.h new file +44 -0
44 lines not on this page · raw message
include/linux/types.h +2 -0
@@ -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 ;
include/scsi/iscsi_proto.h +2 -0
@@ -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); \
PATCH 2/4 24-bit types: convert iSCSI to use the __be24 type and macros
The calling convention of hton24 is different now, it takes a single u32 as an argument and evaluates to a __be24 lvalue.
---
drivers/scsi/iscsi_tcp.c | 8 ++++---- drivers/scsi/libiscsi.c | 6 +++--- include/scsi/iscsi_proto.h | 46 ++++++++++++++++++-------------------------- 3 files changed, 26 insertions(+), 34 deletions(-)
drivers/scsi/iscsi_tcp.c +4 -4
@@ -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 ; }
drivers/scsi/libiscsi.c +3 -3
@@ -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);
include/scsi/iscsi_proto.h +19 -27
160 lines not on this page · raw message
PATCH 3/4 24-bit types: Convert jfs to use the common 24-bit types
In reply to Chris LeechFrom: Dave Kleikamp <[email protected]>
This patch cleans up some of the ugliness in the jfs headers and uses the common 24-bit types instead of its private definitions.
---
fs/jfs/endian24.h | 54 ---------------------------------------------------- fs/jfs/jfs_types.h | 22 ++++++++++----------- fs/jfs/jfs_xtree.h | 16 ++++++++------- 3 files changed, 18 insertions(+), 74 deletions(-) delete mode 100644 fs/jfs/endian24.h
fs/jfs/endian24.h deleted +0 -54
@@ -1,54 +0,0 @@ -/* -* Copyright (C) International Business Machines Corp., 2001 -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ -#ifndef _H_ENDIAN24 -#define _H_ENDIAN24 - -/* -* endian24.h: -* -* Endian conversion for 24-byte data -* -*/ -#define __swab24 (x) \ -({ \ - __u32 __x = (x); \ - ((__u32)( \ - ((__x & (__u32)0x000000ffUL) << 16) | \ - (__x & (__u32)0x0000ff00UL) | \ - ((__x & (__u32)0x00ff0000UL) >> 16) )); \ -}) - -#undef __cpu_to_le24 -#undef __le24_to_cpu - -#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)) -#else -#define __cpu_to_le24 (x) __swab24(x) -#define __le24_to_cpu (x) __swab24(x) -#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 - -#endif /* !_H_ENDIAN24 */
fs/jfs/jfs_types.h +10 -12
@@ -30,8 +30,6 @@#include <linux/types.h> #include <linux/nls.h> -#include "endian24.h" -/* * transaction and lock id's *
@@ -62,7 +60,7 @@ struct timestruc_t {*/ typedef struct {unsigned len:24 ; -unsigned off1:8 ; +u8 off1;u32 off2; }lxd_t ;
@@ -90,8 +88,8 @@ struct lxdlist {* physical xd (pxd) */ typedef struct { -unsigned len:24 ; -unsigned addr1:8 ; +__le24 len; +u8 addr1;__le32 addr2; }pxd_t ;
@@ -122,13 +120,13 @@ struct pxdlist {* data extent descriptor (dxd) */ typedef struct { -unsigned flag:8 ;/* 1: flags */ -unsigned rsrvd:24 ; -__le32 size;/* 4: size in byte */ -unsigned len:24 ;/* 3: length in unit of fsblksize */ -unsigned addr1:8 ;/* 1: address in unit of fsblksize */ -__le32 addr2;/* 4: address in unit of fsblksize */ -}dxd_t ;/* - 16 - */ +u8 flag;/* 1: flags */ +u8 rsrvd[3 ]; +__le32 size;/* 4: size in byte */ +__le24 len;/* 3: length in unit of fsblksize */ +u8 addr1;/* 1: address in unit of fsblksize */ +__le32 addr2;/* 4: address in unit of fsblksize */ +}dxd_t ;/* - 16 - */ /* dxd_t flags */ #define DXD_INDEX 0x80/* B+-tree index */
fs/jfs/jfs_xtree.h +8 -8
@@ -29,14 +29,14 @@* extent allocation descriptor (xad) */ typedef struct xad { -unsigned flag:8 ;/* 1: flag */ -unsigned rsvrd:16 ;/* 2: reserved */ -unsigned off1:8 ;/* 1: offset in unit of fsblksize */ -__le32 off2;/* 4: offset in unit of fsblksize */ -unsigned len:24 ;/* 3: length in unit of fsblksize */ -unsigned addr1:8 ;/* 1: address in unit of fsblksize */ -__le32 addr2;/* 4: address in unit of fsblksize */ -}xad_t ;/* (16) */ +u8 flag;/* 1: flag */ +u8 rsvrd[2 ];/* 2: reserved */ +u8 off1;/* 1: offset in unit of fsblksize */ +__le32 off2;/* 4: offset in unit of fsblksize */ +__le24 len;/* 3: length in unit of fsblksize */ +u8 addr1;/* 1: address in unit of fsblksize */ +__le32 addr2;/* 4: address in unit of fsblksize */ +}xad_t ;/* (16) */ #define MAXXLEN ((1 << 24) - 1)
PATCH 4/4 24-bit types: Convert Open-FCoE to use __be24 type and macros
In reply to Chris LeechThis converts the Open-FCoE tree to use the common 24-bit types
---
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(-)
drivers/scsi/fcoe/fcoe_dev.c +3 -3
@@ -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 ();
drivers/scsi/libfc/fc_exch.c +12 -12
@@ -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)))
drivers/scsi/libfc/fc_fcp.c +1 -1
@@ -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);
drivers/scsi/libfc/fc_lport.c +4 -4
@@ -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 );
drivers/scsi/libfc/fc_ns.c +7 -7
@@ -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 :
drivers/scsi/libfc/fc_rport.c +2 -2
@@ -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,
include/scsi/fc/fc_els.h +9 -9
@@ -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 */
include/scsi/fc/fc_fcoe.h +2 -4
@@ -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; }/*
include/scsi/fc/fc_fs.h +4 -4
@@ -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 */
include/scsi/fc/fc_gs.h +1 -1
@@ -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;
include/scsi/fc/fc_ns.h +3 -3
@@ -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 */ };/*
include/scsi/libfc/libfc.h +0 -13
@@ -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 ;/*
Quoted 36 lines · Chris Leech
Both iSCSI and Fibre Channel make use of 24-bit big-endian values in frame headers. This patch defines
__be24and__le24typedefs 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.hare 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.hallow 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.handlinux/byteorder/generic.hSigned-off-by Chris Leech <[email protected]>---
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.hfs/jfs/endian24.h +0
-0
fs/jfs/endian24.h line 38
Quoted 6 lines
fs/jfs/endian24.h +3
-0@@ -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
Quoted 175 lines
fs/jfs/endian24.h +2
-0#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 include/linux/byteorder.h +9
-0@@ -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) {include/linux/byteorder/generic.h +10
-0@@ -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) {include/linux/endian24.h new file +44
-0@@ -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 */ include/linux/types.h +2
-0@@ -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 ;include/scsi/iscsi_proto.h +0
-0
include/scsi/iscsi_proto.h line 42
Quoted 8 lines
include/scsi/iscsi_proto.h +2
-0@@ -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
Quoted 8 lines · Boaz Harrosh
Quoted 8 lines
fs/jfs/endian24.h +0
-0@@ -33,6 +33,9 @@ ((__x & (__u32)0x00ff0000UL) >> 16) )); \ })
Quoted 5 lines
fs/jfs/endian24.h line 38
Quoted 3 lines
fs/jfs/endian24.h +3
-0+#undef __cpu_to_le24 +#undef __le24_to_cpu +Does #undef also work on inline functions? I didn't know that
No, it doesn't and those two lines don't do anything. The two below do, so this file gets touched anyway, and the JFS patch deletes the entire file. I'll fix this is there's some other reason to redo the patchset again.
Quoted 12 lines
Quoted 12 lines
fs/jfs/endian24.h +2
-0#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
Boaz Harrosh
Reviewed-byQuoted 14 lines · Chris Leech
Quoted 8 lines · Boaz Harrosh
Quoted 8 lines
fs/jfs/endian24.h +0
-0@@ -33,6 +33,9 @@ ((__x & (__u32)0x00ff0000UL) >> 16) )); \ })Quoted 4 lines
fs/jfs/endian24.h line 38
Quoted 3 lines
fs/jfs/endian24.h +3
-0+#undef __cpu_to_le24 +#undef __le24_to_cpu +Does #undef also work on inline functions? I didn't know that
Quoted 5 lines
No, it doesn't and those two lines don't do anything. The two below do, so this file gets touched anyway, and the JFS patch deletes the entire file. I'll fix this is there's some other reason to redo the patchset again.
Sorry my bad, yes they get removed one patch later. No need to resubmit just for that I think
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
fs/jfs/endian24.h +0
-0#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
Quoted 6 lines
Quoted 6 lines
fs/jfs/endian24.h line 52
Quoted 6 lines
fs/jfs/endian24.h +2
-0#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
Thanks again for doing this
on all patches