From c531b9b49b146e1535dbed006d15e58f4f528f7e Mon Sep 17 00:00:00 2001 From: Bhanu Prakash Gollapudi Date: Fri, 8 Oct 2010 17:12:36 -0700 Subject: [SCSI] libfc: Do not let disc work cancel itself When number of NPIV ports created are greater than the xids allocated per pool -- for eg., creating 255 NPIV ports on a system with nr_cpu_ids of 32, with each pool containing 128 xids -- and then generating a link event - for eg., shutdown/no shutdown -- on the switch port causes the hang with the following stack trace. Call Trace: schedule_timeout+0x19d/0x230 wait_for_common+0xc0/0x170 __cancel_work_timer+0xcf/0x1b0 fc_disc_stop+0x16/0x30 [libfc] fc_lport_reset_locked+0x47/0x90 [libfc] fc_lport_enter_reset+0x67/0xe0 [libfc] fc_lport_disc_callback+0xbc/0xe0 [libfc] fc_disc_done+0xa8/0xf0 [libfc] fc_disc_timeout+0x29/0x40 [libfc] run_workqueue+0xb8/0x140 worker_thread+0x96/0x110 kthread+0x96/0xa0 child_rip+0xa/0x20 Fix is to not cancel the disc_work if discovery is already stopped, thus allowing lport state machine to restart and try discovery again. Signed-off-by: Bhanu Prakash Gollapudi Acked-by: Joe Eykholt Signed-off-by: Robert Love Signed-off-by: James Bottomley --- include/scsi/libfc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/scsi') diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h index 14be49b..f986ab7 100644 --- a/include/scsi/libfc.h +++ b/include/scsi/libfc.h @@ -721,7 +721,7 @@ struct libfc_function_template { * struct fc_disc - Discovery context * @retry_count: Number of retries * @pending: 1 if discovery is pending, 0 if not - * @requesting: 1 if discovery has been requested, 0 if not + * @requested: 1 if discovery has been requested, 0 if not * @seq_count: Number of sequences used for discovery * @buf_len: Length of the discovery buffer * @disc_id: Discovery ID -- cgit v1.1 From e96e72c45a1e78e9266dd70113b851395a440ef3 Mon Sep 17 00:00:00 2001 From: Boaz Harrosh Date: Tue, 19 Oct 2010 14:22:21 +0200 Subject: [SCSI] libosd: Support for scatter gather write/read commands This patch adds the Scatter-Gather (sg) API to libosd. Scatter-gather enables a write/read of multiple none-contiguous areas of an object, in a single call. The extents may overlap and/or be in any order. The Scatter-Gather list is sent to the target in what is called a "cdb continuation segment". This is yet another possible segment in the osd-out-buffer. It is unlike all other segments in that it sits before the actual "data" segment (which until now was always first), and that it is signed by itself and not part of the data buffer. This is because the cdb-continuation-segment is considered a spill-over of the CDB data, and is therefor signed under OSD_SEC_CAPKEY and higher. TODO: A new osd_finalize_request_ex version should be supplied so the @caps received on the network also contains a size parameter and can be spilled over into the "cdb continuation segment". Thanks to John Chandy for the original code, and investigations. And the implementation of SG support in the osd-target. Original-coded-by: John Chandy Signed-off-by: Boaz Harrosh Signed-off-by: James Bottomley --- include/scsi/osd_initiator.h | 9 ++++++++- include/scsi/osd_protocol.h | 42 ++++++++++++++++++++++++++++++++++++++++++ include/scsi/osd_types.h | 5 +++++ 3 files changed, 55 insertions(+), 1 deletion(-) (limited to 'include/scsi') diff --git a/include/scsi/osd_initiator.h b/include/scsi/osd_initiator.h index a8f3701..169a5dc 100644 --- a/include/scsi/osd_initiator.h +++ b/include/scsi/osd_initiator.h @@ -137,7 +137,7 @@ struct osd_request { void *buff; unsigned alloc_size; /* 0 here means: don't call kfree */ unsigned total_bytes; - } set_attr, enc_get_attr, get_attr; + } cdb_cont, set_attr, enc_get_attr, get_attr; struct _osd_io_info { struct bio *bio; @@ -448,6 +448,13 @@ void osd_req_read(struct osd_request *or, int osd_req_read_kern(struct osd_request *or, const struct osd_obj_id *obj, u64 offset, void *buff, u64 len); +/* Scatter/Gather write/read commands */ +int osd_req_write_sg(struct osd_request *or, + const struct osd_obj_id *obj, struct bio *bio, + const struct osd_sg_entry *sglist, unsigned numentries); +int osd_req_read_sg(struct osd_request *or, + const struct osd_obj_id *obj, struct bio *bio, + const struct osd_sg_entry *sglist, unsigned numentries); /* * Root/Partition/Collection/Object Attributes commands */ diff --git a/include/scsi/osd_protocol.h b/include/scsi/osd_protocol.h index 6856612..a6026da 100644 --- a/include/scsi/osd_protocol.h +++ b/include/scsi/osd_protocol.h @@ -631,4 +631,46 @@ static inline void osd_sec_set_caps(struct osd_capability_head *cap, put_unaligned_le16(bit_mask, &cap->permissions_bit_mask); } +/* osd2r05a sec 5.3: CDB continuation segment formats */ +enum osd_continuation_segment_format { + CDB_CONTINUATION_FORMAT_V2 = 0x01, +}; + +struct osd_continuation_segment_header { + u8 format; + u8 reserved1; + __be16 service_action; + __be32 reserved2; + u8 integrity_check[OSDv2_CRYPTO_KEYID_SIZE]; +} __packed; + +/* osd2r05a sec 5.4.1: CDB continuation descriptors */ +enum osd_continuation_descriptor_type { + NO_MORE_DESCRIPTORS = 0x0000, + SCATTER_GATHER_LIST = 0x0001, + QUERY_LIST = 0x0002, + USER_OBJECT = 0x0003, + COPY_USER_OBJECT_SOURCE = 0x0101, + EXTENSION_CAPABILITIES = 0xFFEE +}; + +struct osd_continuation_descriptor_header { + __be16 type; + u8 reserved; + u8 pad_length; + __be32 length; +} __packed; + + +/* osd2r05a sec 5.4.2: Scatter/gather list */ +struct osd_sg_list_entry { + __be64 offset; + __be64 len; +}; + +struct osd_sg_continuation_descriptor { + struct osd_continuation_descriptor_header hdr; + struct osd_sg_list_entry entries[]; +}; + #endif /* ndef __OSD_PROTOCOL_H__ */ diff --git a/include/scsi/osd_types.h b/include/scsi/osd_types.h index 3f5e88c..bd0be7e 100644 --- a/include/scsi/osd_types.h +++ b/include/scsi/osd_types.h @@ -37,4 +37,9 @@ struct osd_attr { void *val_ptr; /* in network order */ }; +struct osd_sg_entry { + u64 offset; + u64 len; +}; + #endif /* ndef __OSD_TYPES_H__ */ -- cgit v1.1 From 6dd1d8a7953cdc203c6eb694ce8eafe2dcd3e9da Mon Sep 17 00:00:00 2001 From: Boaz Harrosh Date: Tue, 19 Oct 2010 16:13:50 +0200 Subject: [SCSI] libosd: write/read_sg_kern API This is a trivial addition to the SG API that can receive kernel pointers. It is only used by the out-of-tree test module. So it's immediate need is questionable. For maintenance ease it might just get in, as it's very small. John. do you need this in the Kernel, or is it only for osd_ktest.ko? Signed-off-by: John A. Chandy Signed-off-by: Boaz Harrosh Signed-off-by: James Bottomley --- include/scsi/osd_initiator.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'include/scsi') diff --git a/include/scsi/osd_initiator.h b/include/scsi/osd_initiator.h index 169a5dc..53a9e88 100644 --- a/include/scsi/osd_initiator.h +++ b/include/scsi/osd_initiator.h @@ -455,6 +455,13 @@ int osd_req_write_sg(struct osd_request *or, int osd_req_read_sg(struct osd_request *or, const struct osd_obj_id *obj, struct bio *bio, const struct osd_sg_entry *sglist, unsigned numentries); +int osd_req_write_sg_kern(struct osd_request *or, + const struct osd_obj_id *obj, void **buff, + const struct osd_sg_entry *sglist, unsigned numentries); +int osd_req_read_sg_kern(struct osd_request *or, + const struct osd_obj_id *obj, void **buff, + const struct osd_sg_entry *sglist, unsigned numentries); + /* * Root/Partition/Collection/Object Attributes commands */ -- cgit v1.1 From f281233d3eba15fb225d21ae2e228fd4553d824a Mon Sep 17 00:00:00 2001 From: Jeff Garzik Date: Tue, 16 Nov 2010 02:10:29 -0500 Subject: SCSI host lock push-down Move the mid-layer's ->queuecommand() invocation from being locked with the host lock to being unlocked to facilitate speeding up the critical path for drivers who don't need this lock taken anyway. The patch below presents a simple SCSI host lock push-down as an equivalent transformation. No locking or other behavior should change with this patch. All existing bugs and locking orders are preserved. Additionally, add one parameter to queuecommand, struct Scsi_Host * and remove one parameter from queuecommand, void (*done)(struct scsi_cmnd *) Scsi_Host* is a convenient pointer that most host drivers need anyway, and 'done' is redundant to struct scsi_cmnd->scsi_done. Minimal code disturbance was attempted with this change. Most drivers needed only two one-line modifications for their host lock push-down. Signed-off-by: Jeff Garzik Acked-by: James Bottomley Signed-off-by: Linus Torvalds --- include/scsi/libfc.h | 3 +-- include/scsi/libiscsi.h | 3 +-- include/scsi/libsas.h | 3 +-- include/scsi/scsi_host.h | 23 +++++++++++++++++++++-- 4 files changed, 24 insertions(+), 8 deletions(-) (limited to 'include/scsi') diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h index f986ab7..5c4c167 100644 --- a/include/scsi/libfc.h +++ b/include/scsi/libfc.h @@ -1006,8 +1006,7 @@ void fc_fcp_destroy(struct fc_lport *); /* * SCSI INTERACTION LAYER *****************************/ -int fc_queuecommand(struct scsi_cmnd *, - void (*done)(struct scsi_cmnd *)); +int fc_queuecommand(struct Scsi_Host *, struct scsi_cmnd *); int fc_eh_abort(struct scsi_cmnd *); int fc_eh_device_reset(struct scsi_cmnd *); int fc_eh_host_reset(struct scsi_cmnd *); diff --git a/include/scsi/libiscsi.h b/include/scsi/libiscsi.h index ae5196a..b81d969 100644 --- a/include/scsi/libiscsi.h +++ b/include/scsi/libiscsi.h @@ -341,8 +341,7 @@ extern int iscsi_eh_abort(struct scsi_cmnd *sc); extern int iscsi_eh_recover_target(struct scsi_cmnd *sc); extern int iscsi_eh_session_reset(struct scsi_cmnd *sc); extern int iscsi_eh_device_reset(struct scsi_cmnd *sc); -extern int iscsi_queuecommand(struct scsi_cmnd *sc, - void (*done)(struct scsi_cmnd *)); +extern int iscsi_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *sc); /* * iSCSI host helpers. diff --git a/include/scsi/libsas.h b/include/scsi/libsas.h index 3dec194..90ce527 100644 --- a/include/scsi/libsas.h +++ b/include/scsi/libsas.h @@ -621,8 +621,7 @@ int sas_set_phy_speed(struct sas_phy *phy, int sas_phy_enable(struct sas_phy *phy, int enabled); int sas_phy_reset(struct sas_phy *phy, int hard_reset); int sas_queue_up(struct sas_task *task); -extern int sas_queuecommand(struct scsi_cmnd *, - void (*scsi_done)(struct scsi_cmnd *)); +extern int sas_queuecommand(struct Scsi_Host * ,struct scsi_cmnd *); extern int sas_target_alloc(struct scsi_target *); extern int sas_slave_alloc(struct scsi_device *); extern int sas_slave_configure(struct scsi_device *); diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h index d0a6a84..e7e3858 100644 --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -127,8 +127,7 @@ struct scsi_host_template { * * STATUS: REQUIRED */ - int (* queuecommand)(struct scsi_cmnd *, - void (*done)(struct scsi_cmnd *)); + int (* queuecommand)(struct Scsi_Host *, struct scsi_cmnd *); /* * The transfer functions are used to queue a scsi command to @@ -505,6 +504,25 @@ struct scsi_host_template { }; /* + * Temporary #define for host lock push down. Can be removed when all + * drivers have been updated to take advantage of unlocked + * queuecommand. + * + */ +#define DEF_SCSI_QCMD(func_name) \ + int func_name(struct Scsi_Host *shost, struct scsi_cmnd *cmd) \ + { \ + unsigned long irq_flags; \ + int rc; \ + spin_lock_irqsave(shost->host_lock, irq_flags); \ + scsi_cmd_get_serial(shost, cmd); \ + rc = func_name##_lck (cmd, cmd->scsi_done); \ + spin_unlock_irqrestore(shost->host_lock, irq_flags); \ + return rc; \ + } + + +/* * shost state: If you alter this, you also need to alter scsi_sysfs.c * (for the ascii descriptions) and the state model enforcer: * scsi_host_set_state() @@ -752,6 +770,7 @@ extern struct Scsi_Host *scsi_host_get(struct Scsi_Host *); extern void scsi_host_put(struct Scsi_Host *t); extern struct Scsi_Host *scsi_host_lookup(unsigned short); extern const char *scsi_host_state_name(enum scsi_host_state); +extern void scsi_cmd_get_serial(struct Scsi_Host *, struct scsi_cmnd *); extern u64 scsi_calculate_bounce_limit(struct Scsi_Host *); -- cgit v1.1