From 6b5d6c443a9b4fd71b633cef66b5db4de8a85787 Mon Sep 17 00:00:00 2001 From: Mike Christie Date: Tue, 21 Apr 2009 15:32:32 -0500 Subject: [SCSI] cxgb3i, iser, iscsi_tcp: set target can queue Set target can queue limit to the number of preallocated session tasks we have. This along with the cxgb3i can_queue patch will fix a throughput problem where it could only queue one LU worth of data at a time. Signed-off-by: Mike Christie Signed-off-by: James Bottomley --- include/scsi/libiscsi.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include/scsi') diff --git a/include/scsi/libiscsi.h b/include/scsi/libiscsi.h index 7ffaed2f94dd..0289f5745fb9 100644 --- a/include/scsi/libiscsi.h +++ b/include/scsi/libiscsi.h @@ -36,6 +36,7 @@ struct scsi_transport_template; struct scsi_host_template; struct scsi_device; struct Scsi_Host; +struct scsi_target; struct scsi_cmnd; struct socket; struct iscsi_transport; @@ -350,6 +351,7 @@ extern struct Scsi_Host *iscsi_host_alloc(struct scsi_host_template *sht, bool xmit_can_sleep); extern void iscsi_host_remove(struct Scsi_Host *shost); extern void iscsi_host_free(struct Scsi_Host *shost); +extern int iscsi_target_alloc(struct scsi_target *starget); /* * session management -- cgit v1.2.3 From b4c6f54632ad664a3d9e7f05e4ea0f1803e32755 Mon Sep 17 00:00:00 2001 From: Abhijeet Joglekar Date: Tue, 21 Apr 2009 16:27:04 -0700 Subject: [SCSI] libfc: Track rogue remote ports Rogue ports are currently not tracked on any list. The only reference to them is through any outstanding exchanges pending on the rogue ports. If the module is removed while a retry is set on a rogue port (say a Plogi retry for instance), this retry is not cancelled because there is no reference to the rogue port in the discovery rports list. Thus the local port can clean itself up, delete the exchange pool, and then the rogue port timeout can fire and try to start up another exchange. This patch tracks the rogue ports in a new list disc->rogue_rports. Creating a new list instead of using the disc->rports list keeps remote port code change to a minimum. 1) Whenever a rogue port is created, it is immediately added to the disc->rogue_rports list. 2) When the rogues port goes to ready, it is removed from the rogue list and the real remote port is added to the disc->rports list 3) The removal of the rogue from the disc->rogue_rports list is done in the context of the fc_rport_work() workQ thread in discovery callback. 4) Real rports are removed from the disc->rports list like before. Lookup is done only in the real rports list. This avoids making large changes to the remote port code. 5) In fc_disc_stop_rports, the rogues list is traversed in addition to the real list to stop the rogue ports and issue logoffs on them. This way, rogue ports get cleaned up when the local port goes away. 6) rogue remote ports are not removed from the list right away, but removed late in fc_rport_work() context, multiple threads can find the same remote port in the list and call rport_logoff(). Rport_logoff() only continues with the logoff if port is not in NONE state, thus preventing multiple logoffs and multiple list deletions. 7) Since the rport is removed from the disc list at a later stage (in the disc callback), incoming frames can find the rport even if rport_logoff() has been called on the rport. When rport_logoff() is called, the rport state is set to NONE, and we are trying to cancel all exchanges and retries on that port. While in this state, if an incoming Plogi/Prli/Logo or other frames match the rport, we should not reply because the rport is in the NONE state. Just drop the frame, since the rport will be deleted soon in the disc callback (fc_rport_work) 8) In fc_disc_single(), remove rport lookup and call to fc_disc_del_target. fc_disc_single() is called from recv_rscn_req() where rport lookup and rport_logoff is already done. Signed-off-by: Abhijeet Joglekar Signed-off-by: Robert Love Signed-off-by: James Bottomley --- drivers/scsi/libfc/fc_disc.c | 36 +++++++++++++++++++++++++----------- drivers/scsi/libfc/fc_rport.c | 28 ++++++++++++++++++++++++++++ include/scsi/libfc.h | 1 + 3 files changed, 54 insertions(+), 11 deletions(-) (limited to 'include/scsi') diff --git a/drivers/scsi/libfc/fc_disc.c b/drivers/scsi/libfc/fc_disc.c index 44806307f831..4c880656990b 100644 --- a/drivers/scsi/libfc/fc_disc.c +++ b/drivers/scsi/libfc/fc_disc.c @@ -113,6 +113,11 @@ void fc_disc_stop_rports(struct fc_disc *disc) lport->tt.rport_logoff(rport); } + list_for_each_entry_safe(rdata, next, &disc->rogue_rports, peers) { + rport = PRIV_TO_RPORT(rdata); + lport->tt.rport_logoff(rport); + } + mutex_unlock(&disc->disc_mutex); } @@ -131,23 +136,32 @@ static void fc_disc_rport_callback(struct fc_lport *lport, { struct fc_rport_libfc_priv *rdata = rport->dd_data; struct fc_disc *disc = &lport->disc; - int found = 0; FC_DEBUG_DISC("Received a %d event for port (%6x)\n", event, rport->port_id); - if (event == RPORT_EV_CREATED) { + switch (event) { + case RPORT_EV_CREATED: if (disc) { - found = 1; mutex_lock(&disc->disc_mutex); list_add_tail(&rdata->peers, &disc->rports); mutex_unlock(&disc->disc_mutex); } + break; + case RPORT_EV_LOGO: + case RPORT_EV_FAILED: + case RPORT_EV_STOP: + mutex_lock(&disc->disc_mutex); + mutex_lock(&rdata->rp_mutex); + if (rdata->trans_state == FC_PORTSTATE_ROGUE) + list_del(&rdata->peers); + mutex_unlock(&rdata->rp_mutex); + mutex_unlock(&disc->disc_mutex); + break; + default: + break; } - if (!found) - FC_DEBUG_DISC("The rport (%6x) is not maintained " - "by the discovery layer\n", rport->port_id); } /** @@ -439,6 +453,7 @@ static int fc_disc_new_target(struct fc_disc *disc, rdata = rport->dd_data; rdata->ops = &fc_disc_rport_ops; rdata->rp_state = RPORT_ST_INIT; + list_add_tail(&rdata->peers, &disc->rogue_rports); lport->tt.rport_login(rport); } } @@ -630,6 +645,8 @@ static int fc_disc_gpn_ft_parse(struct fc_disc *disc, void *buf, size_t len) rdata = rport->dd_data; rdata->ops = &fc_disc_rport_ops; rdata->local_port = lport; + list_add_tail(&rdata->peers, + &disc->rogue_rports); lport->tt.rport_login(rport); } else FC_DBG("Failed to allocate memory for " @@ -769,7 +786,6 @@ static void fc_disc_gpn_ft_resp(struct fc_seq *sp, struct fc_frame *fp, static void fc_disc_single(struct fc_disc *disc, struct fc_disc_port *dp) { struct fc_lport *lport; - struct fc_rport *rport; struct fc_rport *new_rport; struct fc_rport_libfc_priv *rdata; @@ -778,15 +794,12 @@ static void fc_disc_single(struct fc_disc *disc, struct fc_disc_port *dp) if (dp->ids.port_id == fc_host_port_id(lport->host)) goto out; - rport = lport->tt.rport_lookup(lport, dp->ids.port_id); - if (rport) - fc_disc_del_target(disc, rport); - new_rport = lport->tt.rport_create(dp); if (new_rport) { rdata = new_rport->dd_data; rdata->ops = &fc_disc_rport_ops; kfree(dp); + list_add_tail(&rdata->peers, &disc->rogue_rports); lport->tt.rport_login(new_rport); } return; @@ -848,6 +861,7 @@ int fc_disc_init(struct fc_lport *lport) INIT_DELAYED_WORK(&disc->disc_work, fc_disc_timeout); mutex_init(&disc->disc_mutex); INIT_LIST_HEAD(&disc->rports); + INIT_LIST_HEAD(&disc->rogue_rports); disc->lport = lport; disc->delay = FC_DISC_DELAY; diff --git a/drivers/scsi/libfc/fc_rport.c b/drivers/scsi/libfc/fc_rport.c index eef70b4b7b92..5bf7a949f051 100644 --- a/drivers/scsi/libfc/fc_rport.c +++ b/drivers/scsi/libfc/fc_rport.c @@ -267,6 +267,10 @@ static void fc_rport_work(struct work_struct *work) "(%6x).\n", ids.port_id); event = RPORT_EV_FAILED; } + if (rport->port_id != FC_FID_DIR_SERV) + if (rport_ops->event_callback) + rport_ops->event_callback(lport, rport, + RPORT_EV_FAILED); put_device(&rport->dev); rport = new_rport; rdata = new_rport->dd_data; @@ -325,11 +329,20 @@ int fc_rport_login(struct fc_rport *rport) int fc_rport_logoff(struct fc_rport *rport) { struct fc_rport_libfc_priv *rdata = rport->dd_data; + struct fc_lport *lport = rdata->local_port; mutex_lock(&rdata->rp_mutex); FC_DEBUG_RPORT("Remove port (%6x)\n", rport->port_id); + if (rdata->rp_state == RPORT_ST_NONE) { + FC_DEBUG_RPORT("(%6x): Port (%6x) in NONE state," + " not removing", fc_host_port_id(lport->host), + rport->port_id); + mutex_unlock(&rdata->rp_mutex); + goto out; + } + fc_rport_enter_logo(rport); /* @@ -349,6 +362,7 @@ int fc_rport_logoff(struct fc_rport *rport) mutex_unlock(&rdata->rp_mutex); +out: return 0; } @@ -1015,6 +1029,8 @@ static void fc_rport_recv_plogi_req(struct fc_rport *rport, default: FC_DEBUG_RPORT("incoming PLOGI from %x in unexpected " "state %d\n", sid, rdata->rp_state); + fc_frame_free(fp); + return; break; } @@ -1106,6 +1122,8 @@ static void fc_rport_recv_prli_req(struct fc_rport *rport, reason = ELS_RJT_NONE; break; default: + fc_frame_free(rx_fp); + return; break; } len = fr_len(rx_fp) - sizeof(*fh); @@ -1235,6 +1253,11 @@ static void fc_rport_recv_prlo_req(struct fc_rport *rport, struct fc_seq *sp, "while in state %s\n", ntoh24(fh->fh_s_id), fc_rport_state(rport)); + if (rdata->rp_state == RPORT_ST_NONE) { + fc_frame_free(fp); + return; + } + rjt_data.fp = NULL; rjt_data.reason = ELS_RJT_UNAB; rjt_data.explan = ELS_EXPL_NONE; @@ -1264,6 +1287,11 @@ static void fc_rport_recv_logo_req(struct fc_rport *rport, struct fc_seq *sp, "while in state %s\n", ntoh24(fh->fh_s_id), fc_rport_state(rport)); + if (rdata->rp_state == RPORT_ST_NONE) { + fc_frame_free(fp); + return; + } + rdata->event = RPORT_EV_LOGO; queue_work(rport_event_queue, &rdata->event_work); diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h index 0303a6a098cc..45f9cc642c46 100644 --- a/include/scsi/libfc.h +++ b/include/scsi/libfc.h @@ -637,6 +637,7 @@ struct fc_disc { enum fc_disc_event); struct list_head rports; + struct list_head rogue_rports; struct fc_lport *lport; struct mutex disc_mutex; struct fc_gpn_ft_resp partial_buf; /* partial name buffer */ -- cgit v1.2.3 From a29e7646f42a325a7f6cce34adbeb52e8db15566 Mon Sep 17 00:00:00 2001 From: Robert Love Date: Tue, 21 Apr 2009 16:27:41 -0700 Subject: [SCSI] libfc: Fix compilation warnings with allmodconfig When building with a .config generated from 'make allmodconfig' some build warnings are generated. This patch corrects the warnings, adds a FC_FID_NONE (= 0) enumeration for FC-IDs and cleans up one variable naming to meet our variable naming conventions. For example, fc_lport's should be named "lport," not "lp." Signed-off-by: Robert Love Signed-off-by: James Bottomley --- drivers/scsi/libfc/fc_elsct.c | 2 +- drivers/scsi/libfc/fc_fcp.c | 7 +++---- drivers/scsi/libfc/fc_rport.c | 2 +- include/scsi/fc/fc_fs.h | 1 + 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'include/scsi') diff --git a/drivers/scsi/libfc/fc_elsct.c b/drivers/scsi/libfc/fc_elsct.c index dd47fe619d1e..5878b34bff18 100644 --- a/drivers/scsi/libfc/fc_elsct.c +++ b/drivers/scsi/libfc/fc_elsct.c @@ -41,7 +41,7 @@ static struct fc_seq *fc_elsct_send(struct fc_lport *lport, void *arg, u32 timer_msec) { enum fc_rctl r_ctl; - u32 did; + u32 did = FC_FID_NONE; enum fc_fh_type fh_type; int rc; diff --git a/drivers/scsi/libfc/fc_fcp.c b/drivers/scsi/libfc/fc_fcp.c index f555ae99ad40..521f996f9b13 100644 --- a/drivers/scsi/libfc/fc_fcp.c +++ b/drivers/scsi/libfc/fc_fcp.c @@ -713,7 +713,7 @@ done: static void fc_fcp_recv(struct fc_seq *seq, struct fc_frame *fp, void *arg) { struct fc_fcp_pkt *fsp = (struct fc_fcp_pkt *)arg; - struct fc_lport *lp; + struct fc_lport *lport = fsp->lp; struct fc_frame_header *fh; struct fcp_txrdy *dd; u8 r_ctl; @@ -724,9 +724,8 @@ static void fc_fcp_recv(struct fc_seq *seq, struct fc_frame *fp, void *arg) fh = fc_frame_header_get(fp); r_ctl = fh->fh_r_ctl; - lp = fsp->lp; - if (!(lp->state & LPORT_ST_READY)) + if (!(lport->state & LPORT_ST_READY)) goto out; if (fc_fcp_lock_pkt(fsp)) goto out; @@ -779,7 +778,7 @@ errout: if (IS_ERR(fp)) fc_fcp_error(fsp, fp); else if (rc == -ENOMEM) - fc_fcp_reduce_can_queue(lp); + fc_fcp_reduce_can_queue(lport); } static void fc_fcp_resp(struct fc_fcp_pkt *fsp, struct fc_frame *fp) diff --git a/drivers/scsi/libfc/fc_rport.c b/drivers/scsi/libfc/fc_rport.c index e675f5ac30cc..747d73c5c8af 100644 --- a/drivers/scsi/libfc/fc_rport.c +++ b/drivers/scsi/libfc/fc_rport.c @@ -509,7 +509,7 @@ static void fc_rport_plogi_resp(struct fc_seq *sp, struct fc_frame *fp, struct fc_rport *rport = rp_arg; struct fc_rport_libfc_priv *rdata = rport->dd_data; struct fc_lport *lport = rdata->local_port; - struct fc_els_flogi *plp; + struct fc_els_flogi *plp = NULL; unsigned int tov; u16 csp_seq; u16 cssp_seq; diff --git a/include/scsi/fc/fc_fs.h b/include/scsi/fc/fc_fs.h index 1b7af3a64c7c..ac4cd38c860e 100644 --- a/include/scsi/fc/fc_fs.h +++ b/include/scsi/fc/fc_fs.h @@ -149,6 +149,7 @@ enum fc_rctl { * Well-known fabric addresses. */ enum fc_well_known_fid { + FC_FID_NONE = 0x000000, /* No destination */ FC_FID_BCAST = 0xffffff, /* broadcast */ FC_FID_FLOGI = 0xfffffe, /* fabric login */ FC_FID_FCTRL = 0xfffffd, /* fabric controller */ -- cgit v1.2.3 From 71f32e31e5638df37904697e2d04182935add85d Mon Sep 17 00:00:00 2001 From: Boaz Harrosh Date: Sun, 19 Apr 2009 19:11:42 +0300 Subject: [SCSI] libosd: OSD2r05: Prepare for rev5 attribute list changes In OSD2r05 draft each attribute list element header was changed so attribute-value would be 8 bytes aligned. In OSD2r01-r04 it was aligned on 2 bytes. (This is because in OSD2r01 the complete element was 8 bytes padded at end but the header was not adjusted and caused permanent miss-alignment.) OSD1 elements are not padded and might be or might not be aligned. OSD1 is still supported. In this code we do all the code re-factoring to separate OSD1/OSD2 differences but do not change actual wire format. All wire format changes will happen in one patch later, for bisect-ability. Signed-off-by: Boaz Harrosh Signed-off-by: James Bottomley --- drivers/scsi/osd/osd_initiator.c | 86 +++++++++++++++++++++++++++++++--------- include/scsi/osd_protocol.h | 20 +++++++--- 2 files changed, 83 insertions(+), 23 deletions(-) (limited to 'include/scsi') diff --git a/drivers/scsi/osd/osd_initiator.c b/drivers/scsi/osd/osd_initiator.c index 76de88962237..e266f803aa96 100644 --- a/drivers/scsi/osd/osd_initiator.c +++ b/drivers/scsi/osd/osd_initiator.c @@ -205,6 +205,69 @@ static unsigned _osd_req_alist_elem_size(struct osd_request *or, unsigned len) osdv2_attr_list_elem_size(len); } +static void _osd_req_alist_elem_encode(struct osd_request *or, + void *attr_last, const struct osd_attr *oa) +{ + if (osd_req_is_ver1(or)) { + struct osdv1_attributes_list_element *attr = attr_last; + + attr->attr_page = cpu_to_be32(oa->attr_page); + attr->attr_id = cpu_to_be32(oa->attr_id); + attr->attr_bytes = cpu_to_be16(oa->len); + memcpy(attr->attr_val, oa->val_ptr, oa->len); + } else { + struct osdv2_attributes_list_element *attr = attr_last; + + attr->attr_page = cpu_to_be32(oa->attr_page); + attr->attr_id = cpu_to_be32(oa->attr_id); + attr->attr_bytes = cpu_to_be16(oa->len); + memcpy(attr->attr_val, oa->val_ptr, oa->len); + } +} + +static int _osd_req_alist_elem_decode(struct osd_request *or, + void *cur_p, struct osd_attr *oa, unsigned max_bytes) +{ + unsigned inc; + if (osd_req_is_ver1(or)) { + struct osdv1_attributes_list_element *attr = cur_p; + + if (max_bytes < sizeof(*attr)) + return -1; + + oa->len = be16_to_cpu(attr->attr_bytes); + inc = _osd_req_alist_elem_size(or, oa->len); + if (inc > max_bytes) + return -1; + + oa->attr_page = be32_to_cpu(attr->attr_page); + oa->attr_id = be32_to_cpu(attr->attr_id); + + /* OSD1: On empty attributes we return a pointer to 2 bytes + * of zeros. This keeps similar behaviour with OSD2. + * (See below) + */ + oa->val_ptr = likely(oa->len) ? attr->attr_val : + (u8 *)&attr->attr_bytes; + } else { + struct osdv2_attributes_list_element *attr = cur_p; + + if (max_bytes < sizeof(*attr)) + return -1; + + oa->len = be16_to_cpu(attr->attr_bytes); + inc = _osd_req_alist_elem_size(or, oa->len); + if (inc > max_bytes) + return -1; + + oa->attr_page = be32_to_cpu(attr->attr_page); + oa->attr_id = be32_to_cpu(attr->attr_id); + + oa->val_ptr = attr->attr_val; + } + return inc; +} + static unsigned _osd_req_alist_size(struct osd_request *or, void *list_head) { return osd_req_is_ver1(or) ? @@ -798,7 +861,6 @@ int osd_req_add_set_attr_list(struct osd_request *or, attr_last = or->set_attr.buff + total_bytes; for (; nelem; --nelem) { - struct osd_attributes_list_element *attr; unsigned elem_size = _osd_req_alist_elem_size(or, oa->len); total_bytes += elem_size; @@ -811,11 +873,7 @@ int osd_req_add_set_attr_list(struct osd_request *or, or->set_attr.buff + or->set_attr.total_bytes; } - attr = attr_last; - attr->attr_page = cpu_to_be32(oa->attr_page); - attr->attr_id = cpu_to_be32(oa->attr_id); - attr->attr_bytes = cpu_to_be16(oa->len); - memcpy(attr->attr_val, oa->val_ptr, oa->len); + _osd_req_alist_elem_encode(or, attr_last, oa); attr_last += elem_size; ++oa; @@ -1070,15 +1128,10 @@ int osd_req_decode_get_attr_list(struct osd_request *or, } for (n = 0; (n < *nelem) && (cur_bytes < returned_bytes); ++n) { - struct osd_attributes_list_element *attr = cur_p; - unsigned inc; + int inc = _osd_req_alist_elem_decode(or, cur_p, oa, + returned_bytes - cur_bytes); - oa->len = be16_to_cpu(attr->attr_bytes); - inc = _osd_req_alist_elem_size(or, oa->len); - OSD_DEBUG("oa->len=%d inc=%d cur_bytes=%d\n", - oa->len, inc, cur_bytes); - cur_bytes += inc; - if (cur_bytes > returned_bytes) { + if (inc < 0) { OSD_ERR("BAD FOOD from target. list not valid!" "c=%d r=%d n=%d\n", cur_bytes, returned_bytes, n); @@ -1086,10 +1139,7 @@ int osd_req_decode_get_attr_list(struct osd_request *or, break; } - oa->attr_page = be32_to_cpu(attr->attr_page); - oa->attr_id = be32_to_cpu(attr->attr_id); - oa->val_ptr = attr->attr_val; - + cur_bytes += inc; cur_p += inc; ++oa; } diff --git a/include/scsi/osd_protocol.h b/include/scsi/osd_protocol.h index cd3cbf764650..fa8343ce3ca2 100644 --- a/include/scsi/osd_protocol.h +++ b/include/scsi/osd_protocol.h @@ -300,15 +300,25 @@ struct osd_attributes_list_attrid { __be32 attr_id; } __packed; +/* + * NOTE: v1: is not aligned. + */ +struct osdv1_attributes_list_element { + __be32 attr_page; + __be32 attr_id; + __be16 attr_bytes; /* valid bytes at attr_val without padding */ + u8 attr_val[0]; +} __packed; + /* * osd2r03: 7.1.3.3 List entry format for retrieved attributes and * for setting attributes - * NOTE: v2 is 8-bytes aligned, v1 is not aligned. + * NOTE: v2 is 8-bytes aligned */ -struct osd_attributes_list_element { +struct osdv2_attributes_list_element { __be32 attr_page; __be32 attr_id; - __be16 attr_bytes; + __be16 attr_bytes; /* valid bytes at attr_val without padding */ u8 attr_val[0]; } __packed; @@ -324,13 +334,13 @@ enum { static inline unsigned osdv1_attr_list_elem_size(unsigned len) { - return ALIGN(len + sizeof(struct osd_attributes_list_element), + return ALIGN(len + sizeof(struct osdv1_attributes_list_element), OSDv1_ATTRIBUTES_ELEM_ALIGN); } static inline unsigned osdv2_attr_list_elem_size(unsigned len) { - return ALIGN(len + sizeof(struct osd_attributes_list_element), + return ALIGN(len + sizeof(struct osdv2_attributes_list_element), OSD_ATTRIBUTES_ELEM_ALIGN); } -- cgit v1.2.3 From f8d3a644bec74fd55dbfb11f95af7bf98fa963dc Mon Sep 17 00:00:00 2001 From: Boaz Harrosh Date: Sun, 19 Apr 2009 19:13:39 +0300 Subject: [SCSI] libosd: OSD2r05: OSD_CRYPTO_KEYID_SIZE will grow 20 => 32 bytes In OSD2r04 draft, cryptographic key size changed to 32 bytes from OSD1's 20 bytes. This causes a couple of on-the-wire structures to change, including the CDB. In this patch the OSD1/OSD2 handling is separated out in regard to affected structures, but on-the-wire is still the same. All on the wire changes will be submitted in one patch for bisect-ability. Signed-off-by: Boaz Harrosh Signed-off-by: James Bottomley --- drivers/scsi/osd/osd_initiator.c | 30 +++++++++++++++++----- include/scsi/osd_protocol.h | 55 ++++++++++++++++++++++++++++++++-------- 2 files changed, 68 insertions(+), 17 deletions(-) (limited to 'include/scsi') diff --git a/drivers/scsi/osd/osd_initiator.c b/drivers/scsi/osd/osd_initiator.c index e266f803aa96..f61ab84ad20b 100644 --- a/drivers/scsi/osd/osd_initiator.c +++ b/drivers/scsi/osd/osd_initiator.c @@ -345,9 +345,9 @@ _osd_req_sec_params(struct osd_request *or) struct osd_cdb *ocdb = &or->cdb; if (osd_req_is_ver1(or)) - return &ocdb->v1.sec_params; + return (struct osd_security_parameters *)&ocdb->v1.sec_params; else - return &ocdb->v2.sec_params; + return (struct osd_security_parameters *)&ocdb->v2.sec_params; } void osd_dev_init(struct osd_dev *osdd, struct scsi_device *scsi_device) @@ -1209,6 +1209,24 @@ static int _osd_req_finalize_attr_page(struct osd_request *or) return ret; } +static inline void osd_sec_parms_set_out_offset(bool is_v1, + struct osd_security_parameters *sec_parms, osd_cdb_offset offset) +{ + if (is_v1) + sec_parms->v1.data_out_integrity_check_offset = offset; + else + sec_parms->v2.data_out_integrity_check_offset = offset; +} + +static inline void osd_sec_parms_set_in_offset(bool is_v1, + struct osd_security_parameters *sec_parms, osd_cdb_offset offset) +{ + if (is_v1) + sec_parms->v1.data_in_integrity_check_offset = offset; + else + sec_parms->v2.data_in_integrity_check_offset = offset; +} + static int _osd_req_finalize_data_integrity(struct osd_request *or, bool has_in, bool has_out, const u8 *cap_key) { @@ -1232,8 +1250,8 @@ static int _osd_req_finalize_data_integrity(struct osd_request *or, or->out_data_integ.get_attributes_bytes = cpu_to_be64( or->enc_get_attr.total_bytes); - sec_parms->data_out_integrity_check_offset = - osd_req_encode_offset(or, or->out.total_bytes, &pad); + osd_sec_parms_set_out_offset(osd_req_is_ver1(or), sec_parms, + osd_req_encode_offset(or, or->out.total_bytes, &pad)); ret = _req_append_segment(or, pad, &seg, or->out.last_seg, &or->out); @@ -1253,8 +1271,8 @@ static int _osd_req_finalize_data_integrity(struct osd_request *or, }; unsigned pad; - sec_parms->data_in_integrity_check_offset = - osd_req_encode_offset(or, or->in.total_bytes, &pad); + osd_sec_parms_set_in_offset(osd_req_is_ver1(or), sec_parms, + osd_req_encode_offset(or, or->in.total_bytes, &pad)); ret = _req_append_segment(or, pad, &seg, or->in.last_seg, &or->in); diff --git a/include/scsi/osd_protocol.h b/include/scsi/osd_protocol.h index fa8343ce3ca2..bbeceeb0e553 100644 --- a/include/scsi/osd_protocol.h +++ b/include/scsi/osd_protocol.h @@ -33,8 +33,10 @@ enum { OSD_CAP_LEN = OSDv1_CAP_LEN,/* FIXME: Pete rev-001 sup */ OSD_SYSTEMID_LEN = 20, - OSD_CRYPTO_KEYID_SIZE = 20, + OSDv1_CRYPTO_KEYID_SIZE = 20, /*FIXME: OSDv2_CRYPTO_KEYID_SIZE = 32,*/ + OSDv2_CRYPTO_KEYID_SIZE = 20, + OSD_CRYPTO_KEYID_SIZE = OSDv2_CRYPTO_KEYID_SIZE, OSD_CRYPTO_SEED_SIZE = 4, OSD_CRYPTO_NONCE_SIZE = 12, OSD_MAX_SENSE_LEN = 252, /* from SPC-3 */ @@ -204,29 +206,40 @@ struct osd_cdb_head { /*80*/ /*160 v1*/ -/*184 v2*/ -struct osd_security_parameters { -/*160*/u8 integrity_check_value[OSD_CRYPTO_KEYID_SIZE]; +struct osdv1_security_parameters { +/*160*/u8 integrity_check_value[OSDv1_CRYPTO_KEYID_SIZE]; /*180*/u8 request_nonce[OSD_CRYPTO_NONCE_SIZE]; /*192*/osd_cdb_offset data_in_integrity_check_offset; /*196*/osd_cdb_offset data_out_integrity_check_offset; } __packed; /*200 v1*/ -/*224 v2*/ -/* FIXME: osdv2_security_parameters */ +/*184 v2*/ +struct osdv2_security_parameters { +/*184*/u8 integrity_check_value[OSDv2_CRYPTO_KEYID_SIZE]; +/*216*/u8 request_nonce[OSD_CRYPTO_NONCE_SIZE]; +/*228*/osd_cdb_offset data_in_integrity_check_offset; +/*232*/osd_cdb_offset data_out_integrity_check_offset; +} __packed; +/*236 v2*/ + +struct osd_security_parameters { + union { + struct osdv1_security_parameters v1; + struct osdv2_security_parameters v2; + }; +}; struct osdv1_cdb { struct osd_cdb_head h; u8 caps[OSDv1_CAP_LEN]; - struct osd_security_parameters sec_params; + struct osdv1_security_parameters sec_params; } __packed; struct osdv2_cdb { struct osd_cdb_head h; u8 caps[OSD_CAP_LEN]; - struct osd_security_parameters sec_params; - /* FIXME: osdv2_security_parameters */ + struct osdv2_security_parameters sec_params; } __packed; struct osd_cdb { @@ -429,15 +442,35 @@ struct osd_data_out_integrity_info { __be64 data_bytes; __be64 set_attributes_bytes; __be64 get_attributes_bytes; - __be64 integrity_check_value; + __u8 integrity_check_value[OSD_CRYPTO_KEYID_SIZE]; } __packed; +/* Same osd_data_out_integrity_info is used for OSD2/OSD1. The only difference + * Is the sizeof the structure since in OSD1 the last array is smaller. Use + * below for version independent handling of this structure + */ +static inline int osd_data_out_integrity_info_sizeof(bool is_ver1) +{ + return sizeof(struct osd_data_out_integrity_info) - + (is_ver1 * (OSDv2_CRYPTO_KEYID_SIZE - OSDv1_CRYPTO_KEYID_SIZE)); +} + struct osd_data_in_integrity_info { __be64 data_bytes; __be64 retrieved_attributes_bytes; - __be64 integrity_check_value; + __u8 integrity_check_value[OSD_CRYPTO_KEYID_SIZE]; } __packed; +/* Same osd_data_in_integrity_info is used for OSD2/OSD1. The only difference + * Is the sizeof the structure since in OSD1 the last array is smaller. Use + * below for version independent handling of this structure + */ +static inline int osd_data_in_integrity_info_sizeof(bool is_ver1) +{ + return sizeof(struct osd_data_in_integrity_info) - + (is_ver1 * (OSDv2_CRYPTO_KEYID_SIZE - OSDv1_CRYPTO_KEYID_SIZE)); +} + struct osd_timestamp { u8 time[6]; /* number of milliseconds since 1/1/1970 UT (big endian) */ } __packed; -- cgit v1.2.3 From e9da4d7f731dafc2b93ce7b31aa09c4d935ef978 Mon Sep 17 00:00:00 2001 From: Boaz Harrosh Date: Sun, 19 Apr 2009 19:17:54 +0300 Subject: [SCSI] libosd: OSD2r05: on-the-wire changes for latest OSD2 revision 5. OSC's OSD2 target: [git clone git://git.open-osd.org/osc-osd/ master] (Initiator code prior to this patch must use: "git checkout CDB_VER_OSD2r01" in the target tree above) This is a summery of the wire changes: * OSDv2_ADDITIONAL_CDB_LENGTH == 192 => 228 (Total CDB is now 236 bytes) * Attributes List Element Header grew, so attribute values are 8 bytes aligned. * Cryptographic keys and signatures are 20 => 32 * Few new definitions. (Still missing new standard definitions attribute values, these do not change wire format and will be added later when needed) Signed-off-by: Boaz Harrosh Signed-off-by: James Bottomley --- drivers/scsi/osd/osd_initiator.c | 7 ++++++- include/scsi/osd_protocol.h | 23 +++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) (limited to 'include/scsi') diff --git a/drivers/scsi/osd/osd_initiator.c b/drivers/scsi/osd/osd_initiator.c index f61ab84ad20b..1ce6b24abab2 100644 --- a/drivers/scsi/osd/osd_initiator.c +++ b/drivers/scsi/osd/osd_initiator.c @@ -263,7 +263,12 @@ static int _osd_req_alist_elem_decode(struct osd_request *or, oa->attr_page = be32_to_cpu(attr->attr_page); oa->attr_id = be32_to_cpu(attr->attr_id); - oa->val_ptr = attr->attr_val; + /* OSD2: For convenience, on empty attributes, we return 8 bytes + * of zeros here. This keeps the same behaviour with OSD2r04, + * and is nice with null terminating ASCII fields. + * oa->val_ptr == NULL marks the end-of-list, or error. + */ + oa->val_ptr = likely(oa->len) ? attr->attr_val : attr->reserved; } return inc; } diff --git a/include/scsi/osd_protocol.h b/include/scsi/osd_protocol.h index bbeceeb0e553..62b2ab8c69d4 100644 --- a/include/scsi/osd_protocol.h +++ b/include/scsi/osd_protocol.h @@ -24,18 +24,17 @@ enum { OSDv1_ADDITIONAL_CDB_LENGTH = 192, OSDv1_TOTAL_CDB_LEN = OSDv1_ADDITIONAL_CDB_LENGTH + 8, OSDv1_CAP_LEN = 80, + /* Latest supported version */ -/* OSD_ADDITIONAL_CDB_LENGTH = 216,*/ + OSDv2_ADDITIONAL_CDB_LENGTH = 228, OSD_ADDITIONAL_CDB_LENGTH = - OSDv1_ADDITIONAL_CDB_LENGTH, /* FIXME: Pete rev-001 sup */ + OSDv2_ADDITIONAL_CDB_LENGTH, OSD_TOTAL_CDB_LEN = OSD_ADDITIONAL_CDB_LENGTH + 8, -/* OSD_CAP_LEN = 104,*/ - OSD_CAP_LEN = OSDv1_CAP_LEN,/* FIXME: Pete rev-001 sup */ + OSD_CAP_LEN = 104, OSD_SYSTEMID_LEN = 20, OSDv1_CRYPTO_KEYID_SIZE = 20, - /*FIXME: OSDv2_CRYPTO_KEYID_SIZE = 32,*/ - OSDv2_CRYPTO_KEYID_SIZE = 20, + OSDv2_CRYPTO_KEYID_SIZE = 32, OSD_CRYPTO_KEYID_SIZE = OSDv2_CRYPTO_KEYID_SIZE, OSD_CRYPTO_SEED_SIZE = 4, OSD_CRYPTO_NONCE_SIZE = 12, @@ -166,7 +165,11 @@ struct osd_cdb_head { /* called allocation_length in some commands */ /*32*/ __be64 length; /*40*/ __be64 start_address; -/*48*/ __be32 list_identifier;/* Rarely used */ + union { +/*48*/ __be32 list_identifier;/* Rarely used */ + /* OSD2r05 5.2.5 CDB continuation length */ +/*48*/ __be32 cdb_continuation_length; + }; } __packed v2; }; /*52*/ union { /* selected attributes mode Page/List/Single */ @@ -331,6 +334,7 @@ struct osdv1_attributes_list_element { struct osdv2_attributes_list_element { __be32 attr_page; __be32 attr_id; + u8 reserved[6]; __be16 attr_bytes; /* valid bytes at attr_val without padding */ u8 attr_val[0]; } __packed; @@ -520,7 +524,7 @@ enum osd_capability_bit_masks { OSD_SEC_CAP_NONE1 = BIT(8), OSD_SEC_CAP_NONE2 = BIT(9), - OSD_SEC_CAP_NONE3 = BIT(10), + OSD_SEC_GBL_REM = BIT(10), /*v2 only*/ OSD_SEC_CAP_QUERY = BIT(11), /*v2 only*/ OSD_SEC_CAP_M_OBJECT = BIT(12), /*v2 only*/ OSD_SEC_CAP_POL_SEC = BIT(13), @@ -595,8 +599,7 @@ struct osdv1_capability { struct osd_capability { struct osd_capability_head h; -/* struct osd_cap_object_descriptor od;*/ - struct osdv1_cap_object_descriptor od; /* FIXME: Pete rev-001 sup */ + struct osd_cap_object_descriptor od; } __packed; /** -- cgit v1.2.3