From 123521830c0ea35055b900d2ff0b73bb129e08cb Mon Sep 17 00:00:00 2001 From: Nicholas Bellinger Date: Fri, 27 May 2011 11:16:33 +0000 Subject: iscsi: Resolve iscsi_proto.h naming conflicts with drivers/target/iscsi This patch renames the following iscsi_proto.h structures to avoid namespace issues with drivers/target/iscsi/iscsi_target_core.h: *) struct iscsi_cmd -> struct iscsi_scsi_req *) struct iscsi_cmd_rsp -> struct iscsi_scsi_rsp *) struct iscsi_login -> struct iscsi_login_req This patch includes useful ISCSI_FLAG_LOGIN_[CURRENT,NEXT]_STAGE*, and ISCSI_FLAG_SNACK_TYPE_* definitions used by iscsi_target_mod, and fixes the incorrect definition of struct iscsi_snack to following RFC-3720 Section 10.16. SNACK Request. Also, this patch updates libiscsi, iSER, be2iscsi, and bn2xi to use the updated structure definitions in a handful of locations. Signed-off-by: Mike Christie Signed-off-by: Nicholas A. Bellinger --- include/scsi/iscsi_proto.h | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/scsi/iscsi_proto.h b/include/scsi/iscsi_proto.h index dd0a52cea95a..a9c9058ffc60 100644 --- a/include/scsi/iscsi_proto.h +++ b/include/scsi/iscsi_proto.h @@ -116,7 +116,7 @@ struct iscsi_ahs_hdr { #define ISCSI_CDB_SIZE 16 /* iSCSI PDU Header */ -struct iscsi_cmd { +struct iscsi_scsi_req { uint8_t opcode; uint8_t flags; __be16 rsvd2; @@ -161,7 +161,7 @@ struct iscsi_ecdb_ahdr { }; /* SCSI Response Header */ -struct iscsi_cmd_rsp { +struct iscsi_scsi_rsp { uint8_t opcode; uint8_t flags; uint8_t response; @@ -406,7 +406,7 @@ struct iscsi_text_rsp { }; /* Login Header */ -struct iscsi_login { +struct iscsi_login_req { uint8_t opcode; uint8_t flags; uint8_t max_version; /* Max. version supported */ @@ -427,7 +427,13 @@ struct iscsi_login { #define ISCSI_FLAG_LOGIN_TRANSIT 0x80 #define ISCSI_FLAG_LOGIN_CONTINUE 0x40 #define ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK 0x0C /* 2 bits */ +#define ISCSI_FLAG_LOGIN_CURRENT_STAGE1 0x04 +#define ISCSI_FLAG_LOGIN_CURRENT_STAGE2 0x08 +#define ISCSI_FLAG_LOGIN_CURRENT_STAGE3 0x0C #define ISCSI_FLAG_LOGIN_NEXT_STAGE_MASK 0x03 /* 2 bits */ +#define ISCSI_FLAG_LOGIN_NEXT_STAGE1 0x01 +#define ISCSI_FLAG_LOGIN_NEXT_STAGE2 0x02 +#define ISCSI_FLAG_LOGIN_NEXT_STAGE3 0x03 #define ISCSI_LOGIN_CURRENT_STAGE(flags) \ ((flags & ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK) >> 2) @@ -550,17 +556,25 @@ struct iscsi_logout_rsp { struct iscsi_snack { uint8_t opcode; uint8_t flags; - uint8_t rsvd2[14]; + uint8_t rsvd2[2]; + uint8_t hlength; + uint8_t dlength[3]; + uint8_t lun[8]; itt_t itt; + __be32 ttt; + uint8_t rsvd3[4]; + __be32 exp_statsn; + uint8_t rsvd4[8]; __be32 begrun; __be32 runlength; - __be32 exp_statsn; - __be32 rsvd3; - __be32 exp_datasn; - uint8_t rsvd6[8]; }; /* SNACK PDU flags */ +#define ISCSI_FLAG_SNACK_TYPE_DATA 0 +#define ISCSI_FLAG_SNACK_TYPE_R2T 0 +#define ISCSI_FLAG_SNACK_TYPE_STATUS 1 +#define ISCSI_FLAG_SNACK_TYPE_DATA_ACK 2 +#define ISCSI_FLAG_SNACK_TYPE_RDATA 3 #define ISCSI_FLAG_SNACK_TYPE_MASK 0x0F /* 4 bits */ /* Reject Message Header */ -- cgit v1.2.3 From 55bdabdf41b6ee99e22e9d78a895b001fb1d852e Mon Sep 17 00:00:00 2001 From: Andy Grover Date: Thu, 16 Jun 2011 15:57:09 -0700 Subject: iscsi: Use struct scsi_lun in iscsi structs instead of u8[8] struct scsi_lun is also just a struct with an array of 8 octets (64 bits) but using it instead in iscsi structs lets us call scsilun_to_int without a cast, and also lets us copy it using assignment, instead of memcpy(). Signed-off-by: Andy Grover Signed-off-by: James Bottomley --- drivers/scsi/be2iscsi/be_main.c | 5 ++--- drivers/scsi/bnx2i/bnx2i_hwi.c | 8 ++++---- drivers/scsi/libiscsi.c | 14 +++++++------- include/scsi/iscsi_proto.h | 18 +++++++++--------- include/scsi/libiscsi.h | 2 +- 5 files changed, 23 insertions(+), 24 deletions(-) (limited to 'include') diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c index 94b9a07845d5..7b967ed48962 100644 --- a/drivers/scsi/be2iscsi/be_main.c +++ b/drivers/scsi/be2iscsi/be_main.c @@ -3963,11 +3963,10 @@ static int beiscsi_iotask(struct iscsi_task *task, struct scatterlist *sg, } memcpy(&io_task->cmd_bhs->iscsi_data_pdu. dw[offsetof(struct amap_pdu_data_out, lun) / 32], - io_task->cmd_bhs->iscsi_hdr.lun, sizeof(struct scsi_lun)); + &io_task->cmd_bhs->iscsi_hdr.lun, sizeof(struct scsi_lun)); AMAP_SET_BITS(struct amap_iscsi_wrb, lun, pwrb, - cpu_to_be16((unsigned short)io_task->cmd_bhs->iscsi_hdr. - lun[0])); + cpu_to_be16(*(unsigned short *)&io_task->cmd_bhs->iscsi_hdr.lun)); AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb, xferlen); AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb, io_task->pwrb_handle->wrb_index); diff --git a/drivers/scsi/bnx2i/bnx2i_hwi.c b/drivers/scsi/bnx2i/bnx2i_hwi.c index 1b160e12afa3..2b119cc3eac5 100644 --- a/drivers/scsi/bnx2i/bnx2i_hwi.c +++ b/drivers/scsi/bnx2i/bnx2i_hwi.c @@ -430,7 +430,7 @@ int bnx2i_send_iscsi_tmf(struct bnx2i_conn *bnx2i_conn, default: tmfabort_wqe->ref_itt = RESERVED_ITT; } - memcpy(scsi_lun, tmfabort_hdr->lun, sizeof(struct scsi_lun)); + memcpy(scsi_lun, &tmfabort_hdr->lun, sizeof(struct scsi_lun)); tmfabort_wqe->lun[0] = be32_to_cpu(scsi_lun[0]); tmfabort_wqe->lun[1] = be32_to_cpu(scsi_lun[1]); @@ -547,7 +547,7 @@ int bnx2i_send_iscsi_nopout(struct bnx2i_conn *bnx2i_conn, nopout_wqe->op_code = nopout_hdr->opcode; nopout_wqe->op_attr = ISCSI_FLAG_CMD_FINAL; - memcpy(nopout_wqe->lun, nopout_hdr->lun, 8); + memcpy(nopout_wqe->lun, &nopout_hdr->lun, 8); if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) { u32 tmp = nopout_wqe->lun[0]; @@ -1711,7 +1711,7 @@ static int bnx2i_process_nopin_mesg(struct iscsi_session *session, hdr->flags = ISCSI_FLAG_CMD_FINAL; hdr->itt = task->hdr->itt; hdr->ttt = cpu_to_be32(nop_in->ttt); - memcpy(hdr->lun, nop_in->lun, 8); + memcpy(&hdr->lun, nop_in->lun, 8); } done: __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0); @@ -1754,7 +1754,7 @@ static void bnx2i_process_async_mesg(struct iscsi_session *session, resp_hdr->opcode = async_cqe->op_code; resp_hdr->flags = 0x80; - memcpy(resp_hdr->lun, async_cqe->lun, 8); + memcpy(&resp_hdr->lun, async_cqe->lun, 8); resp_hdr->exp_cmdsn = cpu_to_be32(async_cqe->exp_cmd_sn); resp_hdr->max_cmdsn = cpu_to_be32(async_cqe->max_cmd_sn); diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c index c552cd7850ac..57175a7d2ef0 100644 --- a/drivers/scsi/libiscsi.c +++ b/drivers/scsi/libiscsi.c @@ -169,7 +169,7 @@ void iscsi_prep_data_out_pdu(struct iscsi_task *task, struct iscsi_r2t_info *r2t hdr->datasn = cpu_to_be32(r2t->datasn); r2t->datasn++; hdr->opcode = ISCSI_OP_SCSI_DATA_OUT; - memcpy(hdr->lun, task->lun, sizeof(hdr->lun)); + hdr->lun = task->lun; hdr->itt = task->hdr_itt; hdr->exp_statsn = r2t->exp_statsn; hdr->offset = cpu_to_be32(r2t->data_offset + r2t->sent); @@ -296,7 +296,7 @@ static int iscsi_check_tmf_restrictions(struct iscsi_task *task, int opcode) /* * Allow PDUs for unrelated LUNs */ - hdr_lun = scsilun_to_int((struct scsi_lun *)tmf->lun); + hdr_lun = scsilun_to_int(&tmf->lun); if (hdr_lun != task->sc->device->lun) return 0; /* fall through */ @@ -389,8 +389,8 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task) return rc; hdr->opcode = ISCSI_OP_SCSI_CMD; hdr->flags = ISCSI_ATTR_SIMPLE; - int_to_scsilun(sc->device->lun, (struct scsi_lun *)hdr->lun); - memcpy(task->lun, hdr->lun, sizeof(task->lun)); + int_to_scsilun(sc->device->lun, &hdr->lun); + task->lun = hdr->lun; hdr->exp_statsn = cpu_to_be32(conn->exp_statsn); cmd_len = sc->cmd_len; if (cmd_len < ISCSI_CDB_SIZE) @@ -968,7 +968,7 @@ static void iscsi_send_nopout(struct iscsi_conn *conn, struct iscsi_nopin *rhdr) hdr.flags = ISCSI_FLAG_CMD_FINAL; if (rhdr) { - memcpy(hdr.lun, rhdr->lun, 8); + hdr.lun = rhdr->lun; hdr.ttt = rhdr->ttt; hdr.itt = RESERVED_ITT; } else @@ -2092,7 +2092,7 @@ static void iscsi_prep_abort_task_pdu(struct iscsi_task *task, hdr->opcode = ISCSI_OP_SCSI_TMFUNC | ISCSI_OP_IMMEDIATE; hdr->flags = ISCSI_TM_FUNC_ABORT_TASK & ISCSI_FLAG_TM_FUNC_MASK; hdr->flags |= ISCSI_FLAG_CMD_FINAL; - memcpy(hdr->lun, task->lun, sizeof(hdr->lun)); + hdr->lun = task->lun; hdr->rtt = task->hdr_itt; hdr->refcmdsn = task->cmdsn; } @@ -2233,7 +2233,7 @@ static void iscsi_prep_lun_reset_pdu(struct scsi_cmnd *sc, struct iscsi_tm *hdr) hdr->opcode = ISCSI_OP_SCSI_TMFUNC | ISCSI_OP_IMMEDIATE; hdr->flags = ISCSI_TM_FUNC_LOGICAL_UNIT_RESET & ISCSI_FLAG_TM_FUNC_MASK; hdr->flags |= ISCSI_FLAG_CMD_FINAL; - int_to_scsilun(sc->device->lun, (struct scsi_lun *)hdr->lun); + int_to_scsilun(sc->device->lun, &hdr->lun); hdr->rtt = RESERVED_ITT; } diff --git a/include/scsi/iscsi_proto.h b/include/scsi/iscsi_proto.h index a9c9058ffc60..f5f83534fc13 100644 --- a/include/scsi/iscsi_proto.h +++ b/include/scsi/iscsi_proto.h @@ -60,7 +60,7 @@ struct iscsi_hdr { uint8_t rsvd2[2]; uint8_t hlength; /* AHSs total length */ uint8_t dlength[3]; /* Data length */ - uint8_t lun[8]; + struct scsi_lun lun; itt_t itt; /* Initiator Task Tag, opaque for target */ __be32 ttt; /* Target Task Tag */ __be32 statsn; @@ -122,7 +122,7 @@ struct iscsi_scsi_req { __be16 rsvd2; uint8_t hlength; uint8_t dlength[3]; - uint8_t lun[8]; + struct scsi_lun lun; itt_t itt; /* Initiator Task Tag */ __be32 data_length; __be32 cmdsn; @@ -198,7 +198,7 @@ struct iscsi_async { uint8_t rsvd2[2]; uint8_t rsvd3; uint8_t dlength[3]; - uint8_t lun[8]; + struct scsi_lun lun; uint8_t rsvd4[8]; __be32 statsn; __be32 exp_cmdsn; @@ -226,7 +226,7 @@ struct iscsi_nopout { __be16 rsvd2; uint8_t rsvd3; uint8_t dlength[3]; - uint8_t lun[8]; + struct scsi_lun lun; itt_t itt; /* Initiator Task Tag */ __be32 ttt; /* Target Transfer Tag */ __be32 cmdsn; @@ -241,7 +241,7 @@ struct iscsi_nopin { __be16 rsvd2; uint8_t rsvd3; uint8_t dlength[3]; - uint8_t lun[8]; + struct scsi_lun lun; itt_t itt; /* Initiator Task Tag */ __be32 ttt; /* Target Transfer Tag */ __be32 statsn; @@ -257,7 +257,7 @@ struct iscsi_tm { uint8_t rsvd1[2]; uint8_t hlength; uint8_t dlength[3]; - uint8_t lun[8]; + struct scsi_lun lun; itt_t itt; /* Initiator Task Tag */ itt_t rtt; /* Reference Task Tag */ __be32 cmdsn; @@ -315,7 +315,7 @@ struct iscsi_r2t_rsp { uint8_t rsvd2[2]; uint8_t hlength; uint8_t dlength[3]; - uint8_t lun[8]; + struct scsi_lun lun; itt_t itt; /* Initiator Task Tag */ __be32 ttt; /* Target Transfer Tag */ __be32 statsn; @@ -333,7 +333,7 @@ struct iscsi_data { uint8_t rsvd2[2]; uint8_t rsvd3; uint8_t dlength[3]; - uint8_t lun[8]; + struct scsi_lun lun; itt_t itt; __be32 ttt; __be32 rsvd4; @@ -353,7 +353,7 @@ struct iscsi_data_rsp { uint8_t cmd_status; uint8_t hlength; uint8_t dlength[3]; - uint8_t lun[8]; + struct scsi_lun lun; itt_t itt; __be32 ttt; __be32 statsn; diff --git a/include/scsi/libiscsi.h b/include/scsi/libiscsi.h index 0f4367751b71..cedcff371c88 100644 --- a/include/scsi/libiscsi.h +++ b/include/scsi/libiscsi.h @@ -115,7 +115,7 @@ struct iscsi_task { /* copied values in case we need to send tmfs */ itt_t hdr_itt; __be32 cmdsn; - uint8_t lun[8]; + struct scsi_lun lun; int itt; /* this ITT */ -- cgit v1.2.3 From 8304bbceee505742925b487fd8ea56e1f8b4b805 Mon Sep 17 00:00:00 2001 From: Nicholas Bellinger Date: Tue, 22 Mar 2011 14:14:09 -0700 Subject: iscsi: Add Serial Number Arithmetic LT and GT into iscsi_proto.h This patch moves the iscsi_sna_lt() and iscsi_sna_lte(), along with iscsi_sna_gt() and iscsi_sna_gte() from iscsi_target_mod into static inlines inside of include/scsi/iscsi_proto.h This patch also includes the ISCSI_HDR_LEN and ISCSI_CRC_LEN definitions. (Added JesperJ simpliciation for iscsi_sna_* usage) Signed-off-by: Mark Rustad Signed-off-by: Mike Christie Signed-off-by: Nicholas A. Bellinger --- drivers/scsi/libiscsi.c | 16 ---------------- include/scsi/iscsi_proto.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 16 deletions(-) (limited to 'include') diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c index 57175a7d2ef0..256a999d010b 100644 --- a/drivers/scsi/libiscsi.c +++ b/drivers/scsi/libiscsi.c @@ -84,22 +84,6 @@ MODULE_PARM_DESC(debug_libiscsi_eh, __func__, ##arg); \ } while (0); -/* Serial Number Arithmetic, 32 bits, less than, RFC1982 */ -#define SNA32_CHECK 2147483648UL - -static int iscsi_sna_lt(u32 n1, u32 n2) -{ - return n1 != n2 && ((n1 < n2 && (n2 - n1 < SNA32_CHECK)) || - (n1 > n2 && (n2 - n1 < SNA32_CHECK))); -} - -/* Serial Number Arithmetic, 32 bits, less than, RFC1982 */ -static int iscsi_sna_lte(u32 n1, u32 n2) -{ - return n1 == n2 || ((n1 < n2 && (n2 - n1 < SNA32_CHECK)) || - (n1 > n2 && (n2 - n1 < SNA32_CHECK))); -} - inline void iscsi_conn_queue_work(struct iscsi_conn *conn) { struct Scsi_Host *shost = conn->session->host; diff --git a/include/scsi/iscsi_proto.h b/include/scsi/iscsi_proto.h index f5f83534fc13..988ba06b3ad6 100644 --- a/include/scsi/iscsi_proto.h +++ b/include/scsi/iscsi_proto.h @@ -29,9 +29,39 @@ /* default iSCSI listen port for incoming connections */ #define ISCSI_LISTEN_PORT 3260 +/* iSCSI header length */ +#define ISCSI_HDR_LEN 48 + +/* iSCSI CRC32C length */ +#define ISCSI_CRC_LEN 4 + /* Padding word length */ #define ISCSI_PAD_LEN 4 +/* + * Serial Number Arithmetic, 32 bits, RFC1982 + */ + +static inline int iscsi_sna_lt(u32 n1, u32 n2) +{ + return (s32)(n1 - n2) < 0; +} + +static inline int iscsi_sna_lte(u32 n1, u32 n2) +{ + return (s32)(n1 - n2) <= 0; +} + +static inline int iscsi_sna_gt(u32 n1, u32 n2) +{ + return (s32)(n1 - n2) > 0; +} + +static inline int iscsi_sna_gte(u32 n1, u32 n2) +{ + return (s32)(n1 - n2) >= 0; +} + /* * useful common(control and data pathes) macro */ -- cgit v1.2.3 From 36a26c69b4c70396ef569c3452690fba0c1dec08 Mon Sep 17 00:00:00 2001 From: Nicholas Bellinger Date: Tue, 26 Jul 2011 00:35:26 -0700 Subject: kernel.h: Add DIV_ROUND_UP_ULL and DIV_ROUND_UP_SECTOR_T macro usage Add new DIV_ROUND_UP_SECTOR_T macro usage for 32-bit architectures requiring a new DIV_ROUND_UP_ULL, and existing 64-bit usage with DIV_ROUND_UP. Reported-by: Linus Torvalds Reported-by: Andrew Morton Signed-off-by: Nicholas A. Bellinger --- include/linux/kernel.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include') diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 567a6f7bbeed..2642497c36fb 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -56,6 +56,14 @@ #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) +#define DIV_ROUND_UP_ULL(ll,d) \ + ({ unsigned long long _tmp = (ll)+(d)-1; do_div(_tmp, d); _tmp; }) + +#if BITS_PER_LONG == 32 +# define DIV_ROUND_UP_SECTOR_T(ll,d) DIV_ROUND_UP_ULL(ll, d) +#else +# define DIV_ROUND_UP_SECTOR_T(ll,d) DIV_ROUND_UP(ll,d) +#endif /* The `const' in roundup() prevents gcc-3.3 from calling __divdi3 */ #define roundup(x, y) ( \ -- cgit v1.2.3