From 251748a99e631a2c46edcf9e519cfc60fae8153d Mon Sep 17 00:00:00 2001 From: Joe Eykholt Date: Tue, 20 Jul 2010 15:20:56 -0700 Subject: [SCSI] libfc: add fc_frame_sid() and fc_frame_did() functions To pave the way for eliminating exchanges from incoming requests, add simple inline fc_frame_sid() and fc_frame_did() functions which get the FC_IDs from the frame header. This can be almost as efficient as getting them from the sequence/exchange. Move ntohll, htonll, ntoh24 and hton24 to since we need them there and that's included by Signed-off-by: Joe Eykholt Signed-off-by: Robert Love Signed-off-by: James Bottomley --- include/scsi/fc_frame.h | 45 ++++++++++++++++++++++++++++++++++++++++++++- include/scsi/libfc.h | 18 ------------------ 2 files changed, 44 insertions(+), 19 deletions(-) (limited to 'include/scsi') diff --git a/include/scsi/fc_frame.h b/include/scsi/fc_frame.h index 29dd97d5b53a..4ad02041b667 100644 --- a/include/scsi/fc_frame.h +++ b/include/scsi/fc_frame.h @@ -30,6 +30,23 @@ #include +/* some helpful macros */ + +#define ntohll(x) be64_to_cpu(x) +#define htonll(x) cpu_to_be64(x) + +static inline u32 ntoh24(const u8 *p) +{ + return (p[0] << 16) | (p[1] << 8) | p[2]; +} + +static inline void hton24(u8 *p, u32 v) +{ + p[0] = (v >> 16) & 0xff; + p[1] = (v >> 8) & 0xff; + p[2] = v & 0xff; +} + /* * The fc_frame interface is used to pass frame data between functions. * The frame includes the data buffer, length, and SOF / EOF delimiter types. @@ -137,6 +154,16 @@ static inline int fc_frame_is_linear(struct fc_frame *fp) return !skb_is_nonlinear(fp_skb(fp)); } +/* + * Get frame header from message in fc_frame structure. + * This version doesn't do a length check. + */ +static inline +struct fc_frame_header *__fc_frame_header_get(const struct fc_frame *fp) +{ + return (struct fc_frame_header *)fr_hdr(fp); +} + /* * Get frame header from message in fc_frame structure. * This hides a cast and provides a place to add some checking. @@ -145,7 +172,23 @@ static inline struct fc_frame_header *fc_frame_header_get(const struct fc_frame *fp) { WARN_ON(fr_len(fp) < sizeof(struct fc_frame_header)); - return (struct fc_frame_header *) fr_hdr(fp); + return __fc_frame_header_get(fp); +} + +/* + * Get source FC_ID (S_ID) from frame header in message. + */ +static inline u32 fc_frame_sid(const struct fc_frame *fp) +{ + return ntoh24(__fc_frame_header_get(fp)->fh_s_id); +} + +/* + * Get destination FC_ID (D_ID) from frame header in message. + */ +static inline u32 fc_frame_did(const struct fc_frame *fp) +{ + return ntoh24(__fc_frame_header_get(fp)->fh_d_id); } /* diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h index e6f07fba432c..f1ce793f33b3 100644 --- a/include/scsi/libfc.h +++ b/include/scsi/libfc.h @@ -42,24 +42,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) - - -static inline u32 ntoh24(const u8 *p) -{ - return (p[0] << 16) | (p[1] << 8) | p[2]; -} - -static inline void hton24(u8 *p, u32 v) -{ - p[0] = (v >> 16) & 0xff; - p[1] = (v >> 8) & 0xff; - p[2] = v & 0xff; -} - /** * enum fc_lport_state - Local port states * @LPORT_ST_DISABLED: Disabled -- cgit v1.2.3