From 1f08be80bef6f7a3faaa728db836b47ff742f41f Mon Sep 17 00:00:00 2001 From: Sebastian Ott Date: Wed, 5 Sep 2012 14:18:22 +0200 Subject: s390/dasd: move wake_up call Ensure that all work is done when the process waiting for a dasd state change is woken up. With this change it is save to assume that after a userspace triggered state change and a udev settle invocation there are no unexpected users of a dasd device. Acked-by: Stefan Weinhuber Signed-off-by: Sebastian Ott Signed-off-by: Martin Schwidefsky --- drivers/s390/block/dasd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers/s390/block') diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c index 15370a2c5ff0..6498d15f874f 100644 --- a/drivers/s390/block/dasd.c +++ b/drivers/s390/block/dasd.c @@ -534,11 +534,11 @@ static void dasd_change_state(struct dasd_device *device) if (rc) device->target = device->state; - if (device->state == device->target) - wake_up(&dasd_init_waitq); - /* let user-space know that the device status changed */ kobject_uevent(&device->cdev->dev.kobj, KOBJ_CHANGE); + + if (device->state == device->target) + wake_up(&dasd_init_waitq); } /* -- cgit v1.2.3 From 12d7b1078bb374fc3e2955b9f2815415a66157b6 Mon Sep 17 00:00:00 2001 From: Stefan Haberland Date: Tue, 11 Sep 2012 15:10:58 +0200 Subject: s390/dasd: fix pathgroup race If a new path is available we need to verify the path data. If it is the first path for a device the stop bits are removed after path verification. If a pathgroup is established we need to set system characteristics for the lcu. Therefore I/O has to be started. If the device is stopped the set system characteristics worker may block the path verification worker and the device is blocked. Turn on failfast for set system characteristics CQR to prevent a deadlock with the path verification worker. If a pathgroup is established on a device that is not in use trigger path verification. Maybe we were not informed about a working path. Signed-off-by: Stefan Haberland Reviewed-by: Stefan Weinhuber Signed-off-by: Martin Schwidefsky --- drivers/s390/block/dasd.c | 11 +++++++++++ drivers/s390/block/dasd_eckd.c | 32 +++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 7 deletions(-) (limited to 'drivers/s390/block') diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c index 6498d15f874f..0595c763dafd 100644 --- a/drivers/s390/block/dasd.c +++ b/drivers/s390/block/dasd.c @@ -2157,6 +2157,7 @@ static int _dasd_sleep_on(struct dasd_ccw_req *maincqr, int interruptible) test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) && (!dasd_eer_enabled(device))) { cqr->status = DASD_CQR_FAILED; + cqr->intrc = -EAGAIN; continue; } /* Don't try to start requests if device is stopped */ @@ -3270,6 +3271,16 @@ void dasd_generic_path_event(struct ccw_device *cdev, int *path_event) dasd_schedule_device_bh(device); } if (path_event[chp] & PE_PATHGROUP_ESTABLISHED) { + if (!(device->path_data.opm & eventlpm) && + !(device->path_data.tbvpm & eventlpm)) { + /* + * we can not establish a pathgroup on an + * unavailable path, so trigger a path + * verification first + */ + device->path_data.tbvpm |= eventlpm; + dasd_schedule_device_bh(device); + } DBF_DEV_EVENT(DBF_WARNING, device, "%s", "Pathgroup re-established\n"); if (device->discipline->kick_validate) diff --git a/drivers/s390/block/dasd_eckd.c b/drivers/s390/block/dasd_eckd.c index 2fb2b9ea97ec..c48c72abbefc 100644 --- a/drivers/s390/block/dasd_eckd.c +++ b/drivers/s390/block/dasd_eckd.c @@ -1507,7 +1507,8 @@ static struct dasd_ccw_req *dasd_eckd_build_psf_ssc(struct dasd_device *device, * call might change behaviour of DASD devices. */ static int -dasd_eckd_psf_ssc(struct dasd_device *device, int enable_pav) +dasd_eckd_psf_ssc(struct dasd_device *device, int enable_pav, + unsigned long flags) { struct dasd_ccw_req *cqr; int rc; @@ -1516,10 +1517,19 @@ dasd_eckd_psf_ssc(struct dasd_device *device, int enable_pav) if (IS_ERR(cqr)) return PTR_ERR(cqr); + /* + * set flags e.g. turn on failfast, to prevent blocking + * the calling function should handle failed requests + */ + cqr->flags |= flags; + rc = dasd_sleep_on(cqr); if (!rc) /* trigger CIO to reprobe devices */ css_schedule_reprobe(); + else if (cqr->intrc == -EAGAIN) + rc = -EAGAIN; + dasd_sfree_request(cqr, cqr->memdev); return rc; } @@ -1527,7 +1537,8 @@ dasd_eckd_psf_ssc(struct dasd_device *device, int enable_pav) /* * Valide storage server of current device. */ -static void dasd_eckd_validate_server(struct dasd_device *device) +static int dasd_eckd_validate_server(struct dasd_device *device, + unsigned long flags) { int rc; struct dasd_eckd_private *private; @@ -1536,17 +1547,18 @@ static void dasd_eckd_validate_server(struct dasd_device *device) private = (struct dasd_eckd_private *) device->private; if (private->uid.type == UA_BASE_PAV_ALIAS || private->uid.type == UA_HYPER_PAV_ALIAS) - return; + return 0; if (dasd_nopav || MACHINE_IS_VM) enable_pav = 0; else enable_pav = 1; - rc = dasd_eckd_psf_ssc(device, enable_pav); + rc = dasd_eckd_psf_ssc(device, enable_pav, flags); /* may be requested feature is not available on server, * therefore just report error and go ahead */ DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "PSF-SSC for SSID %04x " "returned rc=%d", private->uid.ssid, rc); + return rc; } /* @@ -1556,7 +1568,13 @@ static void dasd_eckd_do_validate_server(struct work_struct *work) { struct dasd_device *device = container_of(work, struct dasd_device, kick_validate); - dasd_eckd_validate_server(device); + if (dasd_eckd_validate_server(device, DASD_CQR_FLAGS_FAILFAST) + == -EAGAIN) { + /* schedule worker again if failed */ + schedule_work(&device->kick_validate); + return; + } + dasd_put_device(device); } @@ -1685,7 +1703,7 @@ dasd_eckd_check_characteristics(struct dasd_device *device) if (rc) goto out_err2; - dasd_eckd_validate_server(device); + dasd_eckd_validate_server(device, 0); /* device may report different configuration data after LCU setup */ rc = dasd_eckd_read_conf(device); @@ -4153,7 +4171,7 @@ static int dasd_eckd_restore_device(struct dasd_device *device) rc = dasd_alias_make_device_known_to_lcu(device); if (rc) return rc; - dasd_eckd_validate_server(device); + dasd_eckd_validate_server(device, DASD_CQR_FLAGS_FAILFAST); /* RE-Read Configuration Data */ rc = dasd_eckd_read_conf(device); -- cgit v1.2.3 From 03429f34c22cedc3300a81e13d5790450cc468af Mon Sep 17 00:00:00 2001 From: Stefan Haberland Date: Tue, 11 Sep 2012 17:19:12 +0200 Subject: s390/dasd: fix read unit address configuration loop Read unit address is done for all devices during online processing to read out LCU features. This is also done after disconnect/connect a LCU. Some older storage hardware does not provide the capability to read unit address configuration. This leads to a loop trying to read unit address configuration every 30 seconds. The device is still operational but logs are flooded with error messages. Fix the loop by recognizing a command reject saying that the suborder for ruac is not supported. Signed-off-by: Stefan Haberland Signed-off-by: Martin Schwidefsky --- drivers/s390/block/dasd_alias.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'drivers/s390/block') diff --git a/drivers/s390/block/dasd_alias.c b/drivers/s390/block/dasd_alias.c index 157defe5e069..6b556995bb33 100644 --- a/drivers/s390/block/dasd_alias.c +++ b/drivers/s390/block/dasd_alias.c @@ -384,6 +384,29 @@ static void _remove_device_from_lcu(struct alias_lcu *lcu, group->next = NULL; }; +static int +suborder_not_supported(struct dasd_ccw_req *cqr) +{ + char *sense; + char reason; + char msg_format; + char msg_no; + + sense = dasd_get_sense(&cqr->irb); + if (!sense) + return 0; + + reason = sense[0]; + msg_format = (sense[7] & 0xF0); + msg_no = (sense[7] & 0x0F); + + /* command reject, Format 0 MSG 4 - invalid parameter */ + if ((reason == 0x80) && (msg_format == 0x00) && (msg_no == 0x04)) + return 1; + + return 0; +} + static int read_unit_address_configuration(struct dasd_device *device, struct alias_lcu *lcu) { @@ -435,6 +458,8 @@ static int read_unit_address_configuration(struct dasd_device *device, do { rc = dasd_sleep_on(cqr); + if (rc && suborder_not_supported(cqr)) + return -EOPNOTSUPP; } while (rc && (cqr->retries > 0)); if (rc) { spin_lock_irqsave(&lcu->lock, flags); @@ -521,7 +546,7 @@ static void lcu_update_work(struct work_struct *work) * processing the data */ spin_lock_irqsave(&lcu->lock, flags); - if (rc || (lcu->flags & NEED_UAC_UPDATE)) { + if ((rc && (rc != -EOPNOTSUPP)) || (lcu->flags & NEED_UAC_UPDATE)) { DBF_DEV_EVENT(DBF_WARNING, device, "could not update" " alias data in lcu (rc = %d), retry later", rc); schedule_delayed_work(&lcu->ruac_data.dwork, 30*HZ); -- cgit v1.2.3 From 382b73663529b756914cf17a9912c9cf00cf0025 Mon Sep 17 00:00:00 2001 From: Sebastian Ott Date: Tue, 28 Aug 2012 16:43:36 +0200 Subject: s390: add eadm facility bits Add the eadm facility bits to the css characteristics and move them to a new header. Signed-off-by: Sebastian Ott Signed-off-by: Martin Schwidefsky --- arch/s390/include/asm/chsc.h | 28 ---------------------------- arch/s390/include/asm/css_chars.h | 39 +++++++++++++++++++++++++++++++++++++++ arch/s390/include/asm/scsw.h | 2 +- drivers/s390/block/dasd_eckd.c | 3 +-- drivers/s390/cio/chsc.h | 1 + 5 files changed, 42 insertions(+), 31 deletions(-) create mode 100644 arch/s390/include/asm/css_chars.h (limited to 'drivers/s390/block') diff --git a/arch/s390/include/asm/chsc.h b/arch/s390/include/asm/chsc.h index bf115b49f444..aea451fd182e 100644 --- a/arch/s390/include/asm/chsc.h +++ b/arch/s390/include/asm/chsc.h @@ -125,32 +125,4 @@ struct chsc_cpd_info { #define CHSC_INFO_CPD _IOWR(CHSC_IOCTL_MAGIC, 0x87, struct chsc_cpd_info) #define CHSC_INFO_DCAL _IOWR(CHSC_IOCTL_MAGIC, 0x88, struct chsc_dcal) -#ifdef __KERNEL__ - -struct css_general_char { - u64 : 12; - u32 dynio : 1; /* bit 12 */ - u32 : 28; - u32 aif : 1; /* bit 41 */ - u32 : 3; - u32 mcss : 1; /* bit 45 */ - u32 fcs : 1; /* bit 46 */ - u32 : 1; - u32 ext_mb : 1; /* bit 48 */ - u32 : 7; - u32 aif_tdd : 1; /* bit 56 */ - u32 : 1; - u32 qebsm : 1; /* bit 58 */ - u32 : 8; - u32 aif_osa : 1; /* bit 67 */ - u32 : 14; - u32 cib : 1; /* bit 82 */ - u32 : 5; - u32 fcx : 1; /* bit 88 */ - u32 : 7; -}__attribute__((packed)); - -extern struct css_general_char css_general_characteristics; - -#endif /* __KERNEL__ */ #endif diff --git a/arch/s390/include/asm/css_chars.h b/arch/s390/include/asm/css_chars.h new file mode 100644 index 000000000000..a06ebc2623fb --- /dev/null +++ b/arch/s390/include/asm/css_chars.h @@ -0,0 +1,39 @@ +#ifndef _ASM_CSS_CHARS_H +#define _ASM_CSS_CHARS_H + +#include + +#ifdef __KERNEL__ + +struct css_general_char { + u64 : 12; + u32 dynio : 1; /* bit 12 */ + u32 : 4; + u32 eadm : 1; /* bit 17 */ + u32 : 23; + u32 aif : 1; /* bit 41 */ + u32 : 3; + u32 mcss : 1; /* bit 45 */ + u32 fcs : 1; /* bit 46 */ + u32 : 1; + u32 ext_mb : 1; /* bit 48 */ + u32 : 7; + u32 aif_tdd : 1; /* bit 56 */ + u32 : 1; + u32 qebsm : 1; /* bit 58 */ + u32 : 8; + u32 aif_osa : 1; /* bit 67 */ + u32 : 12; + u32 eadm_rf : 1; /* bit 80 */ + u32 : 1; + u32 cib : 1; /* bit 82 */ + u32 : 5; + u32 fcx : 1; /* bit 88 */ + u32 : 19; + u32 alt_ssi : 1; /* bit 108 */ +} __packed; + +extern struct css_general_char css_general_characteristics; + +#endif /* __KERNEL__ */ +#endif diff --git a/arch/s390/include/asm/scsw.h b/arch/s390/include/asm/scsw.h index 4071d00978cb..8096bfe67424 100644 --- a/arch/s390/include/asm/scsw.h +++ b/arch/s390/include/asm/scsw.h @@ -9,7 +9,7 @@ #define _ASM_S390_SCSW_H_ #include -#include +#include #include /** diff --git a/drivers/s390/block/dasd_eckd.c b/drivers/s390/block/dasd_eckd.c index c48c72abbefc..ed03c22b215e 100644 --- a/drivers/s390/block/dasd_eckd.c +++ b/drivers/s390/block/dasd_eckd.c @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -31,8 +32,6 @@ #include "dasd_int.h" #include "dasd_eckd.h" -#include "../cio/chsc.h" - #ifdef PRINTK_HEADER #undef PRINTK_HEADER diff --git a/drivers/s390/cio/chsc.h b/drivers/s390/cio/chsc.h index 3f15b2aaeaea..b5261f318fe8 100644 --- a/drivers/s390/cio/chsc.h +++ b/drivers/s390/cio/chsc.h @@ -3,6 +3,7 @@ #include #include +#include #include #include #include -- cgit v1.2.3 From f30664e2c85c7804f07c636bbe99f35e0b2d4c76 Mon Sep 17 00:00:00 2001 From: Sebastian Ott Date: Tue, 28 Aug 2012 16:50:38 +0200 Subject: s390: add scm block driver Block device driver for Storage Class Memory (SCM). This driver provides a block device interface for each available SCM increment. Signed-off-by: Sebastian Ott Signed-off-by: Martin Schwidefsky --- drivers/s390/block/Kconfig | 11 ++ drivers/s390/block/Makefile | 3 + drivers/s390/block/scm_blk.c | 414 +++++++++++++++++++++++++++++++++++++++++++ drivers/s390/block/scm_blk.h | 79 +++++++++ drivers/s390/block/scm_drv.c | 90 ++++++++++ 5 files changed, 597 insertions(+) create mode 100644 drivers/s390/block/scm_blk.c create mode 100644 drivers/s390/block/scm_blk.h create mode 100644 drivers/s390/block/scm_drv.c (limited to 'drivers/s390/block') diff --git a/drivers/s390/block/Kconfig b/drivers/s390/block/Kconfig index 8e477bb1f3f6..18178b64e89a 100644 --- a/drivers/s390/block/Kconfig +++ b/drivers/s390/block/Kconfig @@ -70,3 +70,14 @@ config DASD_EER This driver provides a character device interface to the DASD extended error reporting. This is only needed if you want to use applications written for the EER facility. + +config SCM_BLOCK + def_tristate m + prompt "Support for Storage Class Memory" + depends on S390 && BLOCK && EADM_SCH && SCM_BUS + help + Block device driver for Storage Class Memory (SCM). This driver + provides a block device interface for each available SCM increment. + + To compile this driver as a module, choose M here: the + module will be called scm_block. diff --git a/drivers/s390/block/Makefile b/drivers/s390/block/Makefile index 0a89e080b389..b64e2b32c753 100644 --- a/drivers/s390/block/Makefile +++ b/drivers/s390/block/Makefile @@ -17,3 +17,6 @@ obj-$(CONFIG_DASD_ECKD) += dasd_eckd_mod.o obj-$(CONFIG_DASD_FBA) += dasd_fba_mod.o obj-$(CONFIG_BLK_DEV_XPRAM) += xpram.o obj-$(CONFIG_DCSSBLK) += dcssblk.o + +scm_block-objs := scm_drv.o scm_blk.o +obj-$(CONFIG_SCM_BLOCK) += scm_block.o diff --git a/drivers/s390/block/scm_blk.c b/drivers/s390/block/scm_blk.c new file mode 100644 index 000000000000..634ad58cbef6 --- /dev/null +++ b/drivers/s390/block/scm_blk.c @@ -0,0 +1,414 @@ +/* + * Block driver for s390 storage class memory. + * + * Copyright IBM Corp. 2012 + * Author(s): Sebastian Ott + */ + +#define KMSG_COMPONENT "scm_block" +#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include "scm_blk.h" + +debug_info_t *scm_debug; +static int scm_major; +static DEFINE_SPINLOCK(list_lock); +static LIST_HEAD(inactive_requests); +static unsigned int nr_requests = 64; +static atomic_t nr_devices = ATOMIC_INIT(0); +module_param(nr_requests, uint, S_IRUGO); +MODULE_PARM_DESC(nr_requests, "Number of parallel requests."); + +MODULE_DESCRIPTION("Block driver for s390 storage class memory."); +MODULE_LICENSE("GPL"); +MODULE_ALIAS("scm:scmdev*"); + +static void __scm_free_rq(struct scm_request *scmrq) +{ + struct aob_rq_header *aobrq = to_aobrq(scmrq); + + free_page((unsigned long) scmrq->aob); + free_page((unsigned long) scmrq->aidaw); + kfree(aobrq); +} + +static void scm_free_rqs(void) +{ + struct list_head *iter, *safe; + struct scm_request *scmrq; + + spin_lock_irq(&list_lock); + list_for_each_safe(iter, safe, &inactive_requests) { + scmrq = list_entry(iter, struct scm_request, list); + list_del(&scmrq->list); + __scm_free_rq(scmrq); + } + spin_unlock_irq(&list_lock); +} + +static int __scm_alloc_rq(void) +{ + struct aob_rq_header *aobrq; + struct scm_request *scmrq; + + aobrq = kzalloc(sizeof(*aobrq) + sizeof(*scmrq), GFP_KERNEL); + if (!aobrq) + return -ENOMEM; + + scmrq = (void *) aobrq->data; + scmrq->aidaw = (void *) get_zeroed_page(GFP_DMA); + scmrq->aob = (void *) get_zeroed_page(GFP_DMA); + if (!scmrq->aob || !scmrq->aidaw) { + __scm_free_rq(scmrq); + return -ENOMEM; + } + INIT_LIST_HEAD(&scmrq->list); + spin_lock_irq(&list_lock); + list_add(&scmrq->list, &inactive_requests); + spin_unlock_irq(&list_lock); + + return 0; +} + +static int scm_alloc_rqs(unsigned int nrqs) +{ + int ret = 0; + + while (nrqs-- && !ret) + ret = __scm_alloc_rq(); + + return ret; +} + +static struct scm_request *scm_request_fetch(void) +{ + struct scm_request *scmrq = NULL; + + spin_lock(&list_lock); + if (list_empty(&inactive_requests)) + goto out; + scmrq = list_first_entry(&inactive_requests, struct scm_request, list); + list_del(&scmrq->list); +out: + spin_unlock(&list_lock); + return scmrq; +} + +static void scm_request_done(struct scm_request *scmrq) +{ + unsigned long flags; + + spin_lock_irqsave(&list_lock, flags); + list_add(&scmrq->list, &inactive_requests); + spin_unlock_irqrestore(&list_lock, flags); +} + +static int scm_open(struct block_device *blkdev, fmode_t mode) +{ + return scm_get_ref(); +} + +static int scm_release(struct gendisk *gendisk, fmode_t mode) +{ + scm_put_ref(); + return 0; +} + +static const struct block_device_operations scm_blk_devops = { + .owner = THIS_MODULE, + .open = scm_open, + .release = scm_release, +}; + +static void scm_request_prepare(struct scm_request *scmrq) +{ + struct scm_blk_dev *bdev = scmrq->bdev; + struct scm_device *scmdev = bdev->gendisk->private_data; + struct aidaw *aidaw = scmrq->aidaw; + struct msb *msb = &scmrq->aob->msb[0]; + struct req_iterator iter; + struct bio_vec *bv; + + msb->bs = MSB_BS_4K; + scmrq->aob->request.msb_count = 1; + msb->scm_addr = scmdev->address + + ((u64) blk_rq_pos(scmrq->request) << 9); + msb->oc = (rq_data_dir(scmrq->request) == READ) ? + MSB_OC_READ : MSB_OC_WRITE; + msb->flags |= MSB_FLAG_IDA; + msb->data_addr = (u64) aidaw; + + rq_for_each_segment(bv, scmrq->request, iter) { + WARN_ON(bv->bv_offset); + msb->blk_count += bv->bv_len >> 12; + aidaw->data_addr = (u64) page_address(bv->bv_page); + aidaw++; + } +} + +static inline void scm_request_init(struct scm_blk_dev *bdev, + struct scm_request *scmrq, + struct request *req) +{ + struct aob_rq_header *aobrq = to_aobrq(scmrq); + struct aob *aob = scmrq->aob; + + memset(aob, 0, sizeof(*aob)); + memset(scmrq->aidaw, 0, PAGE_SIZE); + aobrq->scmdev = bdev->scmdev; + aob->request.cmd_code = ARQB_CMD_MOVE; + aob->request.data = (u64) aobrq; + scmrq->request = req; + scmrq->bdev = bdev; + scmrq->retries = 4; + scmrq->error = 0; +} + +static void scm_ensure_queue_restart(struct scm_blk_dev *bdev) +{ + if (atomic_read(&bdev->queued_reqs)) { + /* Queue restart is triggered by the next interrupt. */ + return; + } + blk_delay_queue(bdev->rq, SCM_QUEUE_DELAY); +} + +static void scm_request_requeue(struct scm_request *scmrq) +{ + struct scm_blk_dev *bdev = scmrq->bdev; + + blk_requeue_request(bdev->rq, scmrq->request); + scm_request_done(scmrq); + scm_ensure_queue_restart(bdev); +} + +static void scm_request_finish(struct scm_request *scmrq) +{ + blk_end_request_all(scmrq->request, scmrq->error); + scm_request_done(scmrq); +} + +static void scm_blk_request(struct request_queue *rq) +{ + struct scm_device *scmdev = rq->queuedata; + struct scm_blk_dev *bdev = dev_get_drvdata(&scmdev->dev); + struct scm_request *scmrq; + struct request *req; + int ret; + + while ((req = blk_peek_request(rq))) { + if (req->cmd_type != REQ_TYPE_FS) + continue; + + scmrq = scm_request_fetch(); + if (!scmrq) { + SCM_LOG(5, "no request"); + scm_ensure_queue_restart(bdev); + return; + } + scm_request_init(bdev, scmrq, req); + scm_request_prepare(scmrq); + blk_start_request(req); + + ret = scm_start_aob(scmrq->aob); + if (ret) { + SCM_LOG(5, "no subchannel"); + scm_request_requeue(scmrq); + return; + } + atomic_inc(&bdev->queued_reqs); + } +} + +static void __scmrq_log_error(struct scm_request *scmrq) +{ + struct aob *aob = scmrq->aob; + + if (scmrq->error == -ETIMEDOUT) + SCM_LOG(1, "Request timeout"); + else { + SCM_LOG(1, "Request error"); + SCM_LOG_HEX(1, &aob->response, sizeof(aob->response)); + } + if (scmrq->retries) + SCM_LOG(1, "Retry request"); + else + pr_err("An I/O operation to SCM failed with rc=%d\n", + scmrq->error); +} + +void scm_blk_irq(struct scm_device *scmdev, void *data, int error) +{ + struct scm_request *scmrq = data; + struct scm_blk_dev *bdev = scmrq->bdev; + + scmrq->error = error; + if (error) + __scmrq_log_error(scmrq); + + spin_lock(&bdev->lock); + list_add_tail(&scmrq->list, &bdev->finished_requests); + spin_unlock(&bdev->lock); + tasklet_hi_schedule(&bdev->tasklet); +} + +static void scm_blk_tasklet(struct scm_blk_dev *bdev) +{ + struct scm_request *scmrq; + unsigned long flags; + + spin_lock_irqsave(&bdev->lock, flags); + while (!list_empty(&bdev->finished_requests)) { + scmrq = list_first_entry(&bdev->finished_requests, + struct scm_request, list); + list_del(&scmrq->list); + spin_unlock_irqrestore(&bdev->lock, flags); + + if (scmrq->error && scmrq->retries-- > 0) { + if (scm_start_aob(scmrq->aob)) { + spin_lock_irqsave(&bdev->rq_lock, flags); + scm_request_requeue(scmrq); + spin_unlock_irqrestore(&bdev->rq_lock, flags); + } + /* Request restarted or requeued, handle next. */ + spin_lock_irqsave(&bdev->lock, flags); + continue; + } + scm_request_finish(scmrq); + atomic_dec(&bdev->queued_reqs); + spin_lock_irqsave(&bdev->lock, flags); + } + spin_unlock_irqrestore(&bdev->lock, flags); + /* Look out for more requests. */ + blk_run_queue(bdev->rq); +} + +int scm_blk_dev_setup(struct scm_blk_dev *bdev, struct scm_device *scmdev) +{ + struct request_queue *rq; + int len, ret = -ENOMEM; + unsigned int devindex, nr_max_blk; + + devindex = atomic_inc_return(&nr_devices) - 1; + /* scma..scmz + scmaa..scmzz */ + if (devindex > 701) { + ret = -ENODEV; + goto out; + } + + bdev->scmdev = scmdev; + spin_lock_init(&bdev->rq_lock); + spin_lock_init(&bdev->lock); + INIT_LIST_HEAD(&bdev->finished_requests); + atomic_set(&bdev->queued_reqs, 0); + tasklet_init(&bdev->tasklet, + (void (*)(unsigned long)) scm_blk_tasklet, + (unsigned long) bdev); + + rq = blk_init_queue(scm_blk_request, &bdev->rq_lock); + if (!rq) + goto out; + + bdev->rq = rq; + nr_max_blk = min(scmdev->nr_max_block, + (unsigned int) (PAGE_SIZE / sizeof(struct aidaw))); + + blk_queue_logical_block_size(rq, 1 << 12); + blk_queue_max_hw_sectors(rq, nr_max_blk << 3); /* 8 * 512 = blk_size */ + blk_queue_max_segments(rq, nr_max_blk); + queue_flag_set_unlocked(QUEUE_FLAG_NONROT, rq); + + bdev->gendisk = alloc_disk(SCM_NR_PARTS); + if (!bdev->gendisk) + goto out_queue; + + rq->queuedata = scmdev; + bdev->gendisk->driverfs_dev = &scmdev->dev; + bdev->gendisk->private_data = scmdev; + bdev->gendisk->fops = &scm_blk_devops; + bdev->gendisk->queue = rq; + bdev->gendisk->major = scm_major; + bdev->gendisk->first_minor = devindex * SCM_NR_PARTS; + + len = snprintf(bdev->gendisk->disk_name, DISK_NAME_LEN, "scm"); + if (devindex > 25) { + len += snprintf(bdev->gendisk->disk_name + len, + DISK_NAME_LEN - len, "%c", + 'a' + (devindex / 26) - 1); + devindex = devindex % 26; + } + snprintf(bdev->gendisk->disk_name + len, DISK_NAME_LEN - len, "%c", + 'a' + devindex); + + /* 512 byte sectors */ + set_capacity(bdev->gendisk, scmdev->size >> 9); + add_disk(bdev->gendisk); + return 0; + +out_queue: + blk_cleanup_queue(rq); +out: + atomic_dec(&nr_devices); + return ret; +} + +void scm_blk_dev_cleanup(struct scm_blk_dev *bdev) +{ + tasklet_kill(&bdev->tasklet); + del_gendisk(bdev->gendisk); + blk_cleanup_queue(bdev->gendisk->queue); + put_disk(bdev->gendisk); +} + +static int __init scm_blk_init(void) +{ + int ret; + + ret = register_blkdev(0, "scm"); + if (ret < 0) + goto out; + + scm_major = ret; + if (scm_alloc_rqs(nr_requests)) + goto out_unreg; + + scm_debug = debug_register("scm_log", 16, 1, 16); + if (!scm_debug) + goto out_free; + + debug_register_view(scm_debug, &debug_hex_ascii_view); + debug_set_level(scm_debug, 2); + + ret = scm_drv_init(); + if (ret) + goto out_dbf; + + return ret; + +out_dbf: + debug_unregister(scm_debug); +out_free: + scm_free_rqs(); +out_unreg: + unregister_blkdev(scm_major, "scm"); +out: + return ret; +} +module_init(scm_blk_init); + +static void __exit scm_blk_cleanup(void) +{ + scm_drv_cleanup(); + debug_unregister(scm_debug); + scm_free_rqs(); + unregister_blkdev(scm_major, "scm"); +} +module_exit(scm_blk_cleanup); diff --git a/drivers/s390/block/scm_blk.h b/drivers/s390/block/scm_blk.h new file mode 100644 index 000000000000..5aba5612588f --- /dev/null +++ b/drivers/s390/block/scm_blk.h @@ -0,0 +1,79 @@ +#ifndef SCM_BLK_H +#define SCM_BLK_H + +#include +#include +#include +#include +#include + +#include +#include + +#define SCM_NR_PARTS 8 +#define SCM_QUEUE_DELAY 5 + +struct scm_blk_dev { + struct tasklet_struct tasklet; + struct request_queue *rq; + struct gendisk *gendisk; + struct scm_device *scmdev; + spinlock_t rq_lock; /* guard the request queue */ + spinlock_t lock; /* guard the rest of the blockdev */ + atomic_t queued_reqs; + struct list_head finished_requests; +}; + +struct scm_request { + struct scm_blk_dev *bdev; + struct request *request; + struct aidaw *aidaw; + struct aob *aob; + struct list_head list; + u8 retries; + int error; +}; + +#define to_aobrq(rq) container_of((void *) rq, struct aob_rq_header, data) + +int scm_blk_dev_setup(struct scm_blk_dev *, struct scm_device *); +void scm_blk_dev_cleanup(struct scm_blk_dev *); +void scm_blk_irq(struct scm_device *, void *, int); + +int scm_drv_init(void); +void scm_drv_cleanup(void); + + +extern debug_info_t *scm_debug; + +#define SCM_LOG(imp, txt) do { \ + debug_text_event(scm_debug, imp, txt); \ + } while (0) + +static inline void SCM_LOG_HEX(int level, void *data, int length) +{ + if (level > scm_debug->level) + return; + while (length > 0) { + debug_event(scm_debug, level, data, length); + length -= scm_debug->buf_size; + data += scm_debug->buf_size; + } +} + +static inline void SCM_LOG_STATE(int level, struct scm_device *scmdev) +{ + struct { + u64 address; + u8 oper_state; + u8 rank; + } __packed data = { + .address = scmdev->address, + .oper_state = scmdev->attrs.oper_state, + .rank = scmdev->attrs.rank, + }; + + SCM_LOG_HEX(level, &data, sizeof(data)); +} + +#endif /* SCM_BLK_H */ diff --git a/drivers/s390/block/scm_drv.c b/drivers/s390/block/scm_drv.c new file mode 100644 index 000000000000..fce711a63060 --- /dev/null +++ b/drivers/s390/block/scm_drv.c @@ -0,0 +1,90 @@ +/* + * Device driver for s390 storage class memory. + * + * Copyright IBM Corp. 2012 + * Author(s): Sebastian Ott + */ + +#define KMSG_COMPONENT "scm_block" +#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt + +#include +#include +#include +#include +#include "scm_blk.h" + +static void notify(struct scm_device *scmdev) +{ + pr_info("%lu: The capabilities of the SCM increment changed\n", + (unsigned long) scmdev->address); + SCM_LOG(2, "State changed"); + SCM_LOG_STATE(2, scmdev); +} + +static int scm_probe(struct scm_device *scmdev) +{ + struct scm_blk_dev *bdev; + int ret; + + SCM_LOG(2, "probe"); + SCM_LOG_STATE(2, scmdev); + + if (scmdev->attrs.oper_state != OP_STATE_GOOD) + return -EINVAL; + + bdev = kzalloc(sizeof(*bdev), GFP_KERNEL); + if (!bdev) + return -ENOMEM; + + spin_lock_irq(&scmdev->lock); + dev_set_drvdata(&scmdev->dev, bdev); + spin_unlock_irq(&scmdev->lock); + + ret = scm_blk_dev_setup(bdev, scmdev); + if (ret) { + spin_lock_irq(&scmdev->lock); + dev_set_drvdata(&scmdev->dev, NULL); + spin_unlock_irq(&scmdev->lock); + kfree(bdev); + goto out; + } + +out: + return ret; +} + +static int scm_remove(struct scm_device *scmdev) +{ + struct scm_blk_dev *bdev; + + spin_lock_irq(&scmdev->lock); + bdev = dev_get_drvdata(&scmdev->dev); + dev_set_drvdata(&scmdev->dev, NULL); + spin_unlock_irq(&scmdev->lock); + scm_blk_dev_cleanup(bdev); + kfree(bdev); + + return 0; +} + +static struct scm_driver scm_drv = { + .drv = { + .name = "scm_block", + .owner = THIS_MODULE, + }, + .notify = notify, + .probe = scm_probe, + .remove = scm_remove, + .handler = scm_blk_irq, +}; + +int __init scm_drv_init(void) +{ + return scm_driver_register(&scm_drv); +} + +void scm_drv_cleanup(void) +{ + scm_driver_unregister(&scm_drv); +} -- cgit v1.2.3 From 0d804b20735d974534abb422f723d404b779433a Mon Sep 17 00:00:00 2001 From: Sebastian Ott Date: Tue, 28 Aug 2012 16:51:19 +0200 Subject: s390/scm_block: force cluster writes Force writes to Storage Class Memory (SCM) to be in done in clusters. Signed-off-by: Sebastian Ott Signed-off-by: Martin Schwidefsky --- drivers/s390/block/Kconfig | 7 ++ drivers/s390/block/Makefile | 3 + drivers/s390/block/scm_blk.c | 37 +++++- drivers/s390/block/scm_blk.h | 38 ++++++ drivers/s390/block/scm_blk_cluster.c | 228 +++++++++++++++++++++++++++++++++++ 5 files changed, 310 insertions(+), 3 deletions(-) create mode 100644 drivers/s390/block/scm_blk_cluster.c (limited to 'drivers/s390/block') diff --git a/drivers/s390/block/Kconfig b/drivers/s390/block/Kconfig index 18178b64e89a..4a3b62326183 100644 --- a/drivers/s390/block/Kconfig +++ b/drivers/s390/block/Kconfig @@ -81,3 +81,10 @@ config SCM_BLOCK To compile this driver as a module, choose M here: the module will be called scm_block. + +config SCM_BLOCK_CLUSTER_WRITE + def_bool y + prompt "SCM force cluster writes" + depends on SCM_BLOCK + help + Force writes to Storage Class Memory (SCM) to be in done in clusters. diff --git a/drivers/s390/block/Makefile b/drivers/s390/block/Makefile index b64e2b32c753..c2f4e673e031 100644 --- a/drivers/s390/block/Makefile +++ b/drivers/s390/block/Makefile @@ -19,4 +19,7 @@ obj-$(CONFIG_BLK_DEV_XPRAM) += xpram.o obj-$(CONFIG_DCSSBLK) += dcssblk.o scm_block-objs := scm_drv.o scm_blk.o +ifdef CONFIG_SCM_BLOCK_CLUSTER_WRITE +scm_block-objs += scm_blk_cluster.o +endif obj-$(CONFIG_SCM_BLOCK) += scm_block.o diff --git a/drivers/s390/block/scm_blk.c b/drivers/s390/block/scm_blk.c index 634ad58cbef6..9978ad4433cb 100644 --- a/drivers/s390/block/scm_blk.c +++ b/drivers/s390/block/scm_blk.c @@ -37,6 +37,7 @@ static void __scm_free_rq(struct scm_request *scmrq) free_page((unsigned long) scmrq->aob); free_page((unsigned long) scmrq->aidaw); + __scm_free_rq_cluster(scmrq); kfree(aobrq); } @@ -70,6 +71,12 @@ static int __scm_alloc_rq(void) __scm_free_rq(scmrq); return -ENOMEM; } + + if (__scm_alloc_rq_cluster(scmrq)) { + __scm_free_rq(scmrq); + return -ENOMEM; + } + INIT_LIST_HEAD(&scmrq->list); spin_lock_irq(&list_lock); list_add(&scmrq->list, &inactive_requests); @@ -170,6 +177,7 @@ static inline void scm_request_init(struct scm_blk_dev *bdev, scmrq->bdev = bdev; scmrq->retries = 4; scmrq->error = 0; + scm_request_cluster_init(scmrq); } static void scm_ensure_queue_restart(struct scm_blk_dev *bdev) @@ -181,17 +189,19 @@ static void scm_ensure_queue_restart(struct scm_blk_dev *bdev) blk_delay_queue(bdev->rq, SCM_QUEUE_DELAY); } -static void scm_request_requeue(struct scm_request *scmrq) +void scm_request_requeue(struct scm_request *scmrq) { struct scm_blk_dev *bdev = scmrq->bdev; + scm_release_cluster(scmrq); blk_requeue_request(bdev->rq, scmrq->request); scm_request_done(scmrq); scm_ensure_queue_restart(bdev); } -static void scm_request_finish(struct scm_request *scmrq) +void scm_request_finish(struct scm_request *scmrq) { + scm_release_cluster(scmrq); blk_end_request_all(scmrq->request, scmrq->error); scm_request_done(scmrq); } @@ -215,6 +225,16 @@ static void scm_blk_request(struct request_queue *rq) return; } scm_request_init(bdev, scmrq, req); + if (!scm_reserve_cluster(scmrq)) { + SCM_LOG(5, "cluster busy"); + scm_request_done(scmrq); + return; + } + if (scm_need_cluster_request(scmrq)) { + blk_start_request(req); + scm_initiate_cluster_request(scmrq); + return; + } scm_request_prepare(scmrq); blk_start_request(req); @@ -282,6 +302,13 @@ static void scm_blk_tasklet(struct scm_blk_dev *bdev) spin_lock_irqsave(&bdev->lock, flags); continue; } + + if (scm_test_cluster_request(scmrq)) { + scm_cluster_request_irq(scmrq); + spin_lock_irqsave(&bdev->lock, flags); + continue; + } + scm_request_finish(scmrq); atomic_dec(&bdev->queued_reqs); spin_lock_irqsave(&bdev->lock, flags); @@ -325,6 +352,7 @@ int scm_blk_dev_setup(struct scm_blk_dev *bdev, struct scm_device *scmdev) blk_queue_max_hw_sectors(rq, nr_max_blk << 3); /* 8 * 512 = blk_size */ blk_queue_max_segments(rq, nr_max_blk); queue_flag_set_unlocked(QUEUE_FLAG_NONROT, rq); + scm_blk_dev_cluster_setup(bdev); bdev->gendisk = alloc_disk(SCM_NR_PARTS); if (!bdev->gendisk) @@ -370,7 +398,10 @@ void scm_blk_dev_cleanup(struct scm_blk_dev *bdev) static int __init scm_blk_init(void) { - int ret; + int ret = -EINVAL; + + if (!scm_cluster_size_valid()) + goto out; ret = register_blkdev(0, "scm"); if (ret < 0) diff --git a/drivers/s390/block/scm_blk.h b/drivers/s390/block/scm_blk.h index 5aba5612588f..7ac6bad919ef 100644 --- a/drivers/s390/block/scm_blk.h +++ b/drivers/s390/block/scm_blk.h @@ -22,6 +22,9 @@ struct scm_blk_dev { spinlock_t lock; /* guard the rest of the blockdev */ atomic_t queued_reqs; struct list_head finished_requests; +#ifdef CONFIG_SCM_BLOCK_CLUSTER_WRITE + struct list_head cluster_list; +#endif }; struct scm_request { @@ -32,6 +35,13 @@ struct scm_request { struct list_head list; u8 retries; int error; +#ifdef CONFIG_SCM_BLOCK_CLUSTER_WRITE + struct { + enum {CLUSTER_NONE, CLUSTER_READ, CLUSTER_WRITE} state; + struct list_head list; + void **buf; + } cluster; +#endif }; #define to_aobrq(rq) container_of((void *) rq, struct aob_rq_header, data) @@ -40,9 +50,37 @@ int scm_blk_dev_setup(struct scm_blk_dev *, struct scm_device *); void scm_blk_dev_cleanup(struct scm_blk_dev *); void scm_blk_irq(struct scm_device *, void *, int); +void scm_request_finish(struct scm_request *); +void scm_request_requeue(struct scm_request *); + int scm_drv_init(void); void scm_drv_cleanup(void); +#ifdef CONFIG_SCM_BLOCK_CLUSTER_WRITE +void __scm_free_rq_cluster(struct scm_request *); +int __scm_alloc_rq_cluster(struct scm_request *); +void scm_request_cluster_init(struct scm_request *); +bool scm_reserve_cluster(struct scm_request *); +void scm_release_cluster(struct scm_request *); +void scm_blk_dev_cluster_setup(struct scm_blk_dev *); +bool scm_need_cluster_request(struct scm_request *); +void scm_initiate_cluster_request(struct scm_request *); +void scm_cluster_request_irq(struct scm_request *); +bool scm_test_cluster_request(struct scm_request *); +bool scm_cluster_size_valid(void); +#else +#define __scm_free_rq_cluster(scmrq) {} +#define __scm_alloc_rq_cluster(scmrq) 0 +#define scm_request_cluster_init(scmrq) {} +#define scm_reserve_cluster(scmrq) true +#define scm_release_cluster(scmrq) {} +#define scm_blk_dev_cluster_setup(bdev) {} +#define scm_need_cluster_request(scmrq) false +#define scm_initiate_cluster_request(scmrq) {} +#define scm_cluster_request_irq(scmrq) {} +#define scm_test_cluster_request(scmrq) false +#define scm_cluster_size_valid() true +#endif extern debug_info_t *scm_debug; diff --git a/drivers/s390/block/scm_blk_cluster.c b/drivers/s390/block/scm_blk_cluster.c new file mode 100644 index 000000000000..f4bb61b0cea1 --- /dev/null +++ b/drivers/s390/block/scm_blk_cluster.c @@ -0,0 +1,228 @@ +/* + * Block driver for s390 storage class memory. + * + * Copyright IBM Corp. 2012 + * Author(s): Sebastian Ott + */ + +#include +#include +#include +#include +#include +#include +#include +#include "scm_blk.h" + +static unsigned int write_cluster_size = 64; +module_param(write_cluster_size, uint, S_IRUGO); +MODULE_PARM_DESC(write_cluster_size, + "Number of pages used for contiguous writes."); + +#define CLUSTER_SIZE (write_cluster_size * PAGE_SIZE) + +void __scm_free_rq_cluster(struct scm_request *scmrq) +{ + int i; + + if (!scmrq->cluster.buf) + return; + + for (i = 0; i < 2 * write_cluster_size; i++) + free_page((unsigned long) scmrq->cluster.buf[i]); + + kfree(scmrq->cluster.buf); +} + +int __scm_alloc_rq_cluster(struct scm_request *scmrq) +{ + int i; + + scmrq->cluster.buf = kzalloc(sizeof(void *) * 2 * write_cluster_size, + GFP_KERNEL); + if (!scmrq->cluster.buf) + return -ENOMEM; + + for (i = 0; i < 2 * write_cluster_size; i++) { + scmrq->cluster.buf[i] = (void *) get_zeroed_page(GFP_DMA); + if (!scmrq->cluster.buf[i]) + return -ENOMEM; + } + INIT_LIST_HEAD(&scmrq->cluster.list); + return 0; +} + +void scm_request_cluster_init(struct scm_request *scmrq) +{ + scmrq->cluster.state = CLUSTER_NONE; +} + +static bool clusters_intersect(struct scm_request *A, struct scm_request *B) +{ + unsigned long firstA, lastA, firstB, lastB; + + firstA = ((u64) blk_rq_pos(A->request) << 9) / CLUSTER_SIZE; + lastA = (((u64) blk_rq_pos(A->request) << 9) + + blk_rq_bytes(A->request) - 1) / CLUSTER_SIZE; + + firstB = ((u64) blk_rq_pos(B->request) << 9) / CLUSTER_SIZE; + lastB = (((u64) blk_rq_pos(B->request) << 9) + + blk_rq_bytes(B->request) - 1) / CLUSTER_SIZE; + + return (firstB <= lastA && firstA <= lastB); +} + +bool scm_reserve_cluster(struct scm_request *scmrq) +{ + struct scm_blk_dev *bdev = scmrq->bdev; + struct scm_request *iter; + + if (write_cluster_size == 0) + return true; + + spin_lock(&bdev->lock); + list_for_each_entry(iter, &bdev->cluster_list, cluster.list) { + if (clusters_intersect(scmrq, iter) && + (rq_data_dir(scmrq->request) == WRITE || + rq_data_dir(iter->request) == WRITE)) { + spin_unlock(&bdev->lock); + return false; + } + } + list_add(&scmrq->cluster.list, &bdev->cluster_list); + spin_unlock(&bdev->lock); + + return true; +} + +void scm_release_cluster(struct scm_request *scmrq) +{ + struct scm_blk_dev *bdev = scmrq->bdev; + unsigned long flags; + + if (write_cluster_size == 0) + return; + + spin_lock_irqsave(&bdev->lock, flags); + list_del(&scmrq->cluster.list); + spin_unlock_irqrestore(&bdev->lock, flags); +} + +void scm_blk_dev_cluster_setup(struct scm_blk_dev *bdev) +{ + INIT_LIST_HEAD(&bdev->cluster_list); + blk_queue_io_opt(bdev->rq, CLUSTER_SIZE); +} + +static void scm_prepare_cluster_request(struct scm_request *scmrq) +{ + struct scm_blk_dev *bdev = scmrq->bdev; + struct scm_device *scmdev = bdev->gendisk->private_data; + struct request *req = scmrq->request; + struct aidaw *aidaw = scmrq->aidaw; + struct msb *msb = &scmrq->aob->msb[0]; + struct req_iterator iter; + struct bio_vec *bv; + int i = 0; + u64 addr; + + switch (scmrq->cluster.state) { + case CLUSTER_NONE: + scmrq->cluster.state = CLUSTER_READ; + /* fall through */ + case CLUSTER_READ: + scmrq->aob->request.msb_count = 1; + msb->bs = MSB_BS_4K; + msb->oc = MSB_OC_READ; + msb->flags = MSB_FLAG_IDA; + msb->data_addr = (u64) aidaw; + msb->blk_count = write_cluster_size; + + addr = scmdev->address + ((u64) blk_rq_pos(req) << 9); + msb->scm_addr = round_down(addr, CLUSTER_SIZE); + + if (msb->scm_addr != + round_down(addr + (u64) blk_rq_bytes(req) - 1, + CLUSTER_SIZE)) + msb->blk_count = 2 * write_cluster_size; + + for (i = 0; i < msb->blk_count; i++) { + aidaw->data_addr = (u64) scmrq->cluster.buf[i]; + aidaw++; + } + + break; + case CLUSTER_WRITE: + msb->oc = MSB_OC_WRITE; + + for (addr = msb->scm_addr; + addr < scmdev->address + ((u64) blk_rq_pos(req) << 9); + addr += PAGE_SIZE) { + aidaw->data_addr = (u64) scmrq->cluster.buf[i]; + aidaw++; + i++; + } + rq_for_each_segment(bv, req, iter) { + aidaw->data_addr = (u64) page_address(bv->bv_page); + aidaw++; + i++; + } + for (; i < msb->blk_count; i++) { + aidaw->data_addr = (u64) scmrq->cluster.buf[i]; + aidaw++; + } + break; + } +} + +bool scm_need_cluster_request(struct scm_request *scmrq) +{ + if (rq_data_dir(scmrq->request) == READ) + return false; + + return blk_rq_bytes(scmrq->request) < CLUSTER_SIZE; +} + +/* Called with queue lock held. */ +void scm_initiate_cluster_request(struct scm_request *scmrq) +{ + scm_prepare_cluster_request(scmrq); + if (scm_start_aob(scmrq->aob)) + scm_request_requeue(scmrq); +} + +bool scm_test_cluster_request(struct scm_request *scmrq) +{ + return scmrq->cluster.state != CLUSTER_NONE; +} + +void scm_cluster_request_irq(struct scm_request *scmrq) +{ + struct scm_blk_dev *bdev = scmrq->bdev; + unsigned long flags; + + switch (scmrq->cluster.state) { + case CLUSTER_NONE: + BUG(); + break; + case CLUSTER_READ: + if (scmrq->error) { + scm_request_finish(scmrq); + break; + } + scmrq->cluster.state = CLUSTER_WRITE; + spin_lock_irqsave(&bdev->rq_lock, flags); + scm_initiate_cluster_request(scmrq); + spin_unlock_irqrestore(&bdev->rq_lock, flags); + break; + case CLUSTER_WRITE: + scm_request_finish(scmrq); + break; + } +} + +bool scm_cluster_size_valid(void) +{ + return write_cluster_size == 0 || write_cluster_size == 32 || + write_cluster_size == 64 || write_cluster_size == 128; +} -- cgit v1.2.3 From c3e6d407c0c09fb46a391bdd0a28827472825de7 Mon Sep 17 00:00:00 2001 From: Sebastian Ott Date: Tue, 4 Sep 2012 19:36:41 +0200 Subject: s390/scm: remove superfluous lock Remove the spinlock from struct scm_device. drvdata and attributes are guarded via device_lock. Signed-off-by: Sebastian Ott Signed-off-by: Martin Schwidefsky --- arch/s390/include/asm/eadm.h | 2 -- drivers/s390/block/scm_drv.c | 11 +---------- drivers/s390/cio/scm.c | 6 ++---- 3 files changed, 3 insertions(+), 16 deletions(-) (limited to 'drivers/s390/block') diff --git a/arch/s390/include/asm/eadm.h b/arch/s390/include/asm/eadm.h index 4d6e103f6e26..8d4847191ecc 100644 --- a/arch/s390/include/asm/eadm.h +++ b/arch/s390/include/asm/eadm.h @@ -3,7 +3,6 @@ #include #include -#include struct arqb { u64 data; @@ -83,7 +82,6 @@ struct scm_device { u64 size; unsigned int nr_max_block; struct device dev; - spinlock_t lock; struct { unsigned int persistence:4; unsigned int oper_state:4; diff --git a/drivers/s390/block/scm_drv.c b/drivers/s390/block/scm_drv.c index fce711a63060..349966f6fc52 100644 --- a/drivers/s390/block/scm_drv.c +++ b/drivers/s390/block/scm_drv.c @@ -9,7 +9,6 @@ #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt #include -#include #include #include #include "scm_blk.h" @@ -37,15 +36,10 @@ static int scm_probe(struct scm_device *scmdev) if (!bdev) return -ENOMEM; - spin_lock_irq(&scmdev->lock); dev_set_drvdata(&scmdev->dev, bdev); - spin_unlock_irq(&scmdev->lock); - ret = scm_blk_dev_setup(bdev, scmdev); if (ret) { - spin_lock_irq(&scmdev->lock); dev_set_drvdata(&scmdev->dev, NULL); - spin_unlock_irq(&scmdev->lock); kfree(bdev); goto out; } @@ -56,12 +50,9 @@ out: static int scm_remove(struct scm_device *scmdev) { - struct scm_blk_dev *bdev; + struct scm_blk_dev *bdev = dev_get_drvdata(&scmdev->dev); - spin_lock_irq(&scmdev->lock); - bdev = dev_get_drvdata(&scmdev->dev); dev_set_drvdata(&scmdev->dev, NULL); - spin_unlock_irq(&scmdev->lock); scm_blk_dev_cleanup(bdev); kfree(bdev); diff --git a/drivers/s390/cio/scm.c b/drivers/s390/cio/scm.c index aa4476e92050..bcf20f3aa51b 100644 --- a/drivers/s390/cio/scm.c +++ b/drivers/s390/cio/scm.c @@ -5,7 +5,6 @@ * Author(s): Sebastian Ott */ -#include #include #include #include @@ -134,9 +133,9 @@ static ssize_t show_##name(struct device *dev, \ struct scm_device *scmdev = to_scm_dev(dev); \ int ret; \ \ - spin_lock(&scmdev->lock); \ + device_lock(dev); \ ret = sprintf(buf, "%u\n", scmdev->attrs.name); \ - spin_unlock(&scmdev->lock); \ + device_unlock(dev); \ \ return ret; \ } \ @@ -193,7 +192,6 @@ static void scmdev_setup(struct scm_device *scmdev, struct sale *sale, scmdev->dev.bus = &scm_bus_type; scmdev->dev.release = scmdev_release; scmdev->dev.groups = scmdev_attr_groups; - spin_lock_init(&scmdev->lock); } /* -- cgit v1.2.3 From 24996edce547fd981c089db9a12717fd76a51160 Mon Sep 17 00:00:00 2001 From: Sebastian Ott Date: Tue, 4 Sep 2012 19:37:51 +0200 Subject: s390/scm: reorder scm_remove Do not reset drvdata before the block device is cleaned up. With a non-empty block queue drvdata could be accessed. Signed-off-by: Sebastian Ott Signed-off-by: Martin Schwidefsky --- drivers/s390/block/scm_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/s390/block') diff --git a/drivers/s390/block/scm_drv.c b/drivers/s390/block/scm_drv.c index 349966f6fc52..9fa0a908607b 100644 --- a/drivers/s390/block/scm_drv.c +++ b/drivers/s390/block/scm_drv.c @@ -52,8 +52,8 @@ static int scm_remove(struct scm_device *scmdev) { struct scm_blk_dev *bdev = dev_get_drvdata(&scmdev->dev); - dev_set_drvdata(&scmdev->dev, NULL); scm_blk_dev_cleanup(bdev); + dev_set_drvdata(&scmdev->dev, NULL); kfree(bdev); return 0; -- cgit v1.2.3 From 2267a0c85c4314b64440b9a1e3442d2eb90a719f Mon Sep 17 00:00:00 2001 From: Heiko Carstens Date: Thu, 6 Sep 2012 14:47:30 +0200 Subject: s390/dasd: fix return value for non-existent ioctls For non-existent ioctls -ENOTTY should be returned. Signed-off-by: Heiko Carstens Signed-off-by: Martin Schwidefsky --- drivers/s390/block/dasd_ioctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/s390/block') diff --git a/drivers/s390/block/dasd_ioctl.c b/drivers/s390/block/dasd_ioctl.c index 654c6921a6d4..8252f37d04ed 100644 --- a/drivers/s390/block/dasd_ioctl.c +++ b/drivers/s390/block/dasd_ioctl.c @@ -292,12 +292,12 @@ out: #else static int dasd_ioctl_reset_profile(struct dasd_block *block) { - return -ENOSYS; + return -ENOTTY; } static int dasd_ioctl_read_profile(struct dasd_block *block, void __user *argp) { - return -ENOSYS; + return -ENOTTY; } #endif -- cgit v1.2.3 From a8f6db4d2990d6866ba5d9c699cfc0835b9d8859 Mon Sep 17 00:00:00 2001 From: Heiko Carstens Date: Thu, 6 Sep 2012 15:13:34 +0200 Subject: s390/etr,stp: use -EOPNOTSUPP instead of -ENOSYS Change -ENOSYS to -EOPNOTSUPP. Return value is used only internally. Signed-off-by: Heiko Carstens Signed-off-by: Martin Schwidefsky --- arch/s390/include/asm/etr.h | 8 ++++---- arch/s390/kernel/time.c | 4 ++-- drivers/s390/block/dasd_eckd.c | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'drivers/s390/block') diff --git a/arch/s390/include/asm/etr.h b/arch/s390/include/asm/etr.h index a24b03b9fb64..629b79a93165 100644 --- a/arch/s390/include/asm/etr.h +++ b/arch/s390/include/asm/etr.h @@ -140,7 +140,7 @@ struct etr_ptff_qto { /* Inline assembly helper functions */ static inline int etr_setr(struct etr_eacr *ctrl) { - int rc = -ENOSYS; + int rc = -EOPNOTSUPP; asm volatile( " .insn s,0xb2160000,%1\n" @@ -154,7 +154,7 @@ static inline int etr_setr(struct etr_eacr *ctrl) /* Stores a format 1 aib with 64 bytes */ static inline int etr_stetr(struct etr_aib *aib) { - int rc = -ENOSYS; + int rc = -EOPNOTSUPP; asm volatile( " .insn s,0xb2170000,%1\n" @@ -169,7 +169,7 @@ static inline int etr_stetr(struct etr_aib *aib) static inline int etr_steai(struct etr_aib *aib, unsigned int func) { register unsigned int reg0 asm("0") = func; - int rc = -ENOSYS; + int rc = -EOPNOTSUPP; asm volatile( " .insn s,0xb2b30000,%1\n" @@ -190,7 +190,7 @@ static inline int etr_ptff(void *ptff_block, unsigned int func) { register unsigned int reg0 asm("0") = func; register unsigned long reg1 asm("1") = (unsigned long) ptff_block; - int rc = -ENOSYS; + int rc = -EOPNOTSUPP; asm volatile( " .word 0x0104\n" diff --git a/arch/s390/kernel/time.c b/arch/s390/kernel/time.c index dcec960fc724..2db1011b8b19 100644 --- a/arch/s390/kernel/time.c +++ b/arch/s390/kernel/time.c @@ -329,7 +329,7 @@ static unsigned long clock_sync_flags; * The synchronous get_clock function. It will write the current clock * value to the clock pointer and return 0 if the clock is in sync with * the external time source. If the clock mode is local it will return - * -ENOSYS and -EAGAIN if the clock is not in sync with the external + * -EOPNOTSUPP and -EAGAIN if the clock is not in sync with the external * reference. */ int get_sync_clock(unsigned long long *clock) @@ -347,7 +347,7 @@ int get_sync_clock(unsigned long long *clock) return 0; if (!test_bit(CLOCK_SYNC_HAS_ETR, &clock_sync_flags) && !test_bit(CLOCK_SYNC_HAS_STP, &clock_sync_flags)) - return -ENOSYS; + return -EOPNOTSUPP; if (!test_bit(CLOCK_SYNC_ETR, &clock_sync_flags) && !test_bit(CLOCK_SYNC_STP, &clock_sync_flags)) return -EACCES; diff --git a/drivers/s390/block/dasd_eckd.c b/drivers/s390/block/dasd_eckd.c index ed03c22b215e..e1bb930124dd 100644 --- a/drivers/s390/block/dasd_eckd.c +++ b/drivers/s390/block/dasd_eckd.c @@ -211,7 +211,7 @@ check_XRC (struct ccw1 *de_ccw, rc = get_sync_clock(&data->ep_sys_time); /* Ignore return code if sync clock is switched off. */ - if (rc == -ENOSYS || rc == -EACCES) + if (rc == -EOPNOTSUPP || rc == -EACCES) rc = 0; de_ccw->count = sizeof(struct DE_eckd_data); @@ -322,7 +322,7 @@ static int check_XRC_on_prefix(struct PFX_eckd_data *pfxdata, rc = get_sync_clock(&pfxdata->define_extent.ep_sys_time); /* Ignore return code if sync clock is switched off. */ - if (rc == -ENOSYS || rc == -EACCES) + if (rc == -EOPNOTSUPP || rc == -EACCES) rc = 0; return rc; } -- cgit v1.2.3 From 3bc9fef9cc1e4047c3a3c51d84cc1c5d2ef03cea Mon Sep 17 00:00:00 2001 From: Stefan Haberland Date: Thu, 20 Sep 2012 18:37:36 +0200 Subject: s390/dasd: check count address during online setting A common way to prepare a z/VM mini disk is to format the real device with a z/VM tool like CPFMTXA and then define a mini disk that excludes the first cylinder, i.e. the cylinder 0 of the virtual disk is located at cylinder 1 of the real device. The DASD device driver will recognize such a mini disk as formatted, as the uniform record layout on the disk matches that of an LDL formatted device. However, the cylinder value in the 'count' field of the ECKD records matches the geometry of the real device, and not that of the mini disk, so I/O requests will fail with 'record not found' errors. To make the mini disk usable, it needs to be formatted with a tool like dasdfmt. To enable tools like distribution installation tools to recognize this situation, the DASD device driver should report such a mini disk as 'not formatted'. To this end we need to extend the device recognition code to check not just for proper record sizes, but also for proper cylinder/head/record values. Signed-off-by: Stefan Haberland Reviewed-by: Stefan Weinhuber Signed-off-by: Martin Schwidefsky --- drivers/s390/block/dasd_eckd.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'drivers/s390/block') diff --git a/drivers/s390/block/dasd_eckd.c b/drivers/s390/block/dasd_eckd.c index e1bb930124dd..108332b44d98 100644 --- a/drivers/s390/block/dasd_eckd.c +++ b/drivers/s390/block/dasd_eckd.c @@ -139,6 +139,10 @@ dasd_eckd_set_online(struct ccw_device *cdev) static const int sizes_trk0[] = { 28, 148, 84 }; #define LABEL_SIZE 140 +/* head and record addresses of count_area read in analysis ccw */ +static const int count_area_head[] = { 0, 0, 0, 0, 2 }; +static const int count_area_rec[] = { 1, 2, 3, 4, 1 }; + static inline unsigned int round_up_multiple(unsigned int no, unsigned int mult) { @@ -1939,7 +1943,10 @@ static int dasd_eckd_end_analysis(struct dasd_block *block) count_area = NULL; for (i = 0; i < 3; i++) { if (private->count_area[i].kl != 4 || - private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4) { + private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4 || + private->count_area[i].cyl != 0 || + private->count_area[i].head != count_area_head[i] || + private->count_area[i].record != count_area_rec[i]) { private->uses_cdl = 0; break; } @@ -1951,7 +1958,10 @@ static int dasd_eckd_end_analysis(struct dasd_block *block) for (i = 0; i < 5; i++) { if ((private->count_area[i].kl != 0) || (private->count_area[i].dl != - private->count_area[0].dl)) + private->count_area[0].dl) || + private->count_area[i].cyl != 0 || + private->count_area[i].head != count_area_head[i] || + private->count_area[i].record != count_area_rec[i]) break; } if (i == 5) -- cgit v1.2.3 From 521b3d790c16fad9d83c72d610c1e416ad3f7ae3 Mon Sep 17 00:00:00 2001 From: Sebastian Ott Date: Mon, 1 Oct 2012 09:12:01 +0200 Subject: s390/dcssblk: cleanup device attribute usage Let the driver core handle device attribute creation and removal. This will simplify the code and eliminates races between attribute availability and userspace notification via uevents. Signed-off-by: Sebastian Ott Signed-off-by: Martin Schwidefsky --- drivers/s390/block/dcssblk.c | 52 ++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 29 deletions(-) (limited to 'drivers/s390/block') diff --git a/drivers/s390/block/dcssblk.c b/drivers/s390/block/dcssblk.c index a5a55da2a1ac..b6ad0de07930 100644 --- a/drivers/s390/block/dcssblk.c +++ b/drivers/s390/block/dcssblk.c @@ -69,23 +69,9 @@ static ssize_t dcssblk_add_store(struct device * dev, struct device_attribute *a size_t count); static ssize_t dcssblk_remove_store(struct device * dev, struct device_attribute *attr, const char * buf, size_t count); -static ssize_t dcssblk_save_store(struct device * dev, struct device_attribute *attr, const char * buf, - size_t count); -static ssize_t dcssblk_save_show(struct device *dev, struct device_attribute *attr, char *buf); -static ssize_t dcssblk_shared_store(struct device * dev, struct device_attribute *attr, const char * buf, - size_t count); -static ssize_t dcssblk_shared_show(struct device *dev, struct device_attribute *attr, char *buf); -static ssize_t dcssblk_seglist_show(struct device *dev, - struct device_attribute *attr, - char *buf); static DEVICE_ATTR(add, S_IWUSR, NULL, dcssblk_add_store); static DEVICE_ATTR(remove, S_IWUSR, NULL, dcssblk_remove_store); -static DEVICE_ATTR(save, S_IWUSR | S_IRUSR, dcssblk_save_show, - dcssblk_save_store); -static DEVICE_ATTR(shared, S_IWUSR | S_IRUSR, dcssblk_shared_show, - dcssblk_shared_store); -static DEVICE_ATTR(seglist, S_IRUSR, dcssblk_seglist_show, NULL); static struct device *dcssblk_root_dev; @@ -416,6 +402,8 @@ out: up_write(&dcssblk_devices_sem); return rc; } +static DEVICE_ATTR(shared, S_IWUSR | S_IRUSR, dcssblk_shared_show, + dcssblk_shared_store); /* * device attribute for save operation on current copy @@ -476,6 +464,8 @@ dcssblk_save_store(struct device *dev, struct device_attribute *attr, const char up_write(&dcssblk_devices_sem); return count; } +static DEVICE_ATTR(save, S_IWUSR | S_IRUSR, dcssblk_save_show, + dcssblk_save_store); /* * device attribute for showing all segments in a device @@ -502,6 +492,21 @@ dcssblk_seglist_show(struct device *dev, struct device_attribute *attr, up_read(&dcssblk_devices_sem); return i; } +static DEVICE_ATTR(seglist, S_IRUSR, dcssblk_seglist_show, NULL); + +static struct attribute *dcssblk_dev_attrs[] = { + &dev_attr_shared.attr, + &dev_attr_save.attr, + &dev_attr_seglist.attr, + NULL, +}; +static struct attribute_group dcssblk_dev_attr_group = { + .attrs = dcssblk_dev_attrs, +}; +static const struct attribute_group *dcssblk_dev_attr_groups[] = { + &dcssblk_dev_attr_group, + NULL, +}; /* * device attribute for adding devices @@ -590,6 +595,7 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char dev_set_name(&dev_info->dev, dev_info->segment_name); dev_info->dev.release = dcssblk_release_segment; + dev_info->dev.groups = dcssblk_dev_attr_groups; INIT_LIST_HEAD(&dev_info->lh); dev_info->gd = alloc_disk(DCSSBLK_MINORS_PER_DISK); if (dev_info->gd == NULL) { @@ -637,21 +643,10 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char * register the device */ rc = device_register(&dev_info->dev); - if (rc) { - module_put(THIS_MODULE); - goto dev_list_del; - } - get_device(&dev_info->dev); - rc = device_create_file(&dev_info->dev, &dev_attr_shared); - if (rc) - goto unregister_dev; - rc = device_create_file(&dev_info->dev, &dev_attr_save); - if (rc) - goto unregister_dev; - rc = device_create_file(&dev_info->dev, &dev_attr_seglist); if (rc) - goto unregister_dev; + goto put_dev; + get_device(&dev_info->dev); add_disk(dev_info->gd); switch (dev_info->segment_type) { @@ -668,12 +663,11 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char rc = count; goto out; -unregister_dev: +put_dev: list_del(&dev_info->lh); blk_cleanup_queue(dev_info->dcssblk_queue); dev_info->gd->queue = NULL; put_disk(dev_info->gd); - device_unregister(&dev_info->dev); list_for_each_entry(seg_info, &dev_info->seg_list, lh) { segment_unload(seg_info->segment_name); } -- cgit v1.2.3