Lines Matching refs:device

64 MODULE_DESCRIPTION("Linux on S/390 DASD device driver,"
91 * SECTION: Operations on the device structure.
99 * Allocate memory for a new device structure.
103 struct dasd_device *device;
105 device = kzalloc(sizeof(struct dasd_device), GFP_ATOMIC);
106 if (!device)
109 /* Get two pages for normal block device operations. */
110 device->ccw_mem = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
111 if (!device->ccw_mem) {
112 kfree(device);
116 device->erp_mem = (void *) get_zeroed_page(GFP_ATOMIC | GFP_DMA);
117 if (!device->erp_mem) {
118 free_pages((unsigned long) device->ccw_mem, 1);
119 kfree(device);
123 device->ese_mem = (void *)__get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
124 if (!device->ese_mem) {
125 free_page((unsigned long) device->erp_mem);
126 free_pages((unsigned long) device->ccw_mem, 1);
127 kfree(device);
131 dasd_init_chunklist(&device->ccw_chunks, device->ccw_mem, PAGE_SIZE*2);
132 dasd_init_chunklist(&device->erp_chunks, device->erp_mem, PAGE_SIZE);
133 dasd_init_chunklist(&device->ese_chunks, device->ese_mem, PAGE_SIZE * 2);
134 spin_lock_init(&device->mem_lock);
135 atomic_set(&device->tasklet_scheduled, 0);
136 tasklet_init(&device->tasklet, dasd_device_tasklet,
137 (unsigned long) device);
138 INIT_LIST_HEAD(&device->ccw_queue);
139 timer_setup(&device->timer, dasd_device_timeout, 0);
140 INIT_WORK(&device->kick_work, do_kick_device);
141 INIT_WORK(&device->restore_device, do_restore_device);
142 INIT_WORK(&device->reload_device, do_reload_device);
143 INIT_WORK(&device->requeue_requests, do_requeue_requests);
144 device->state = DASD_STATE_NEW;
145 device->target = DASD_STATE_NEW;
146 mutex_init(&device->state_mutex);
147 spin_lock_init(&device->profile.lock);
148 return device;
152 * Free memory of a device structure.
154 void dasd_free_device(struct dasd_device *device)
156 kfree(device->private);
157 free_pages((unsigned long) device->ese_mem, 1);
158 free_page((unsigned long) device->erp_mem);
159 free_pages((unsigned long) device->ccw_mem, 1);
160 kfree(device);
164 * Allocate memory for a new device structure.
173 /* open_count = 0 means device online but not in use */
191 * Free memory of a device structure.
200 * Make a new device known to the system.
202 static int dasd_state_new_to_known(struct dasd_device *device)
207 * As long as the device is not in state DASD_STATE_NEW we want to
210 dasd_get_device(device);
212 if (device->block) {
213 rc = dasd_alloc_queue(device->block);
215 dasd_put_device(device);
219 device->state = DASD_STATE_KNOWN;
224 * Let the system forget about a device.
226 static int dasd_state_known_to_new(struct dasd_device *device)
228 /* Disable extended error reporting for this device. */
229 dasd_eer_disable(device);
230 device->state = DASD_STATE_NEW;
232 if (device->block)
233 dasd_free_queue(device->block);
236 dasd_put_device(device);
254 * Request the irq line for the device.
256 static int dasd_state_known_to_basic(struct dasd_device *device)
258 struct dasd_block *block = device->block;
271 dasd_profile_on(&device->block->profile);
273 device->debugfs_dentry =
274 dasd_debugfs_setup(dev_name(&device->cdev->dev),
276 dasd_profile_init(&device->profile, device->debugfs_dentry);
277 dasd_hosts_init(device->debugfs_dentry, device);
279 /* register 'device' debug area, used for all DBF_DEV_XXX calls */
280 device->debug_area = debug_register(dev_name(&device->cdev->dev), 4, 1,
282 debug_register_view(device->debug_area, &debug_sprintf_view);
283 debug_set_level(device->debug_area, DBF_WARNING);
284 DBF_DEV_EVENT(DBF_EMERG, device, "%s", "debug area created");
286 device->state = DASD_STATE_BASIC;
292 * Release the irq line for the device. Terminate any running i/o.
294 static int dasd_state_basic_to_known(struct dasd_device *device)
298 if (device->discipline->basic_to_known) {
299 rc = device->discipline->basic_to_known(device);
304 if (device->block) {
305 dasd_profile_exit(&device->block->profile);
306 debugfs_remove(device->block->debugfs_dentry);
307 dasd_gendisk_free(device->block);
308 dasd_block_clear_timer(device->block);
310 rc = dasd_flush_device_queue(device);
313 dasd_device_clear_timer(device);
314 dasd_profile_exit(&device->profile);
315 dasd_hosts_exit(device);
316 debugfs_remove(device->debugfs_dentry);
317 DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device);
318 if (device->debug_area != NULL) {
319 debug_unregister(device->debug_area);
320 device->debug_area = NULL;
322 device->state = DASD_STATE_KNOWN;
328 * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
336 * device is setup.
337 * In case the analysis returns an error, the device setup is stopped
340 static int dasd_state_basic_to_ready(struct dasd_device *device)
347 block = device->block;
354 device->state = DASD_STATE_UNFMT;
355 disk = device->block->gdp;
362 if (device->discipline->setup_blk_queue)
363 device->discipline->setup_blk_queue(block);
366 device->state = DASD_STATE_READY;
369 device->state = DASD_STATE_BASIC;
373 device->state = DASD_STATE_READY;
376 if (device->discipline->basic_to_ready)
377 rc = device->discipline->basic_to_ready(device);
382 int _wait_for_empty_queues(struct dasd_device *device)
384 if (device->block)
385 return list_empty(&device->ccw_queue) &&
386 list_empty(&device->block->ccw_queue);
388 return list_empty(&device->ccw_queue);
392 * Remove device from block device layer. Destroy dirty buffers.
396 static int dasd_state_ready_to_basic(struct dasd_device *device)
400 device->state = DASD_STATE_BASIC;
401 if (device->block) {
402 struct dasd_block *block = device->block;
405 device->state = DASD_STATE_READY;
419 static int dasd_state_unfmt_to_basic(struct dasd_device *device)
421 device->state = DASD_STATE_BASIC;
426 * Make the device online and schedule the bottom half to start
431 dasd_state_ready_to_online(struct dasd_device * device)
437 device->state = DASD_STATE_ONLINE;
438 if (device->block) {
439 dasd_schedule_block_bh(device->block);
440 if ((device->features & DASD_FEATURE_USERAW)) {
441 disk = device->block->gdp;
445 disk = device->block->bdev->bd_disk;
457 static int dasd_state_online_to_ready(struct dasd_device *device)
464 if (device->discipline->online_to_ready) {
465 rc = device->discipline->online_to_ready(device);
470 device->state = DASD_STATE_READY;
471 if (device->block && !(device->features & DASD_FEATURE_USERAW)) {
472 disk = device->block->bdev->bd_disk;
484 static int dasd_increase_state(struct dasd_device *device)
489 if (device->state == DASD_STATE_NEW &&
490 device->target >= DASD_STATE_KNOWN)
491 rc = dasd_state_new_to_known(device);
494 device->state == DASD_STATE_KNOWN &&
495 device->target >= DASD_STATE_BASIC)
496 rc = dasd_state_known_to_basic(device);
499 device->state == DASD_STATE_BASIC &&
500 device->target >= DASD_STATE_READY)
501 rc = dasd_state_basic_to_ready(device);
504 device->state == DASD_STATE_UNFMT &&
505 device->target > DASD_STATE_UNFMT)
509 device->state == DASD_STATE_READY &&
510 device->target >= DASD_STATE_ONLINE)
511 rc = dasd_state_ready_to_online(device);
519 static int dasd_decrease_state(struct dasd_device *device)
524 if (device->state == DASD_STATE_ONLINE &&
525 device->target <= DASD_STATE_READY)
526 rc = dasd_state_online_to_ready(device);
529 device->state == DASD_STATE_READY &&
530 device->target <= DASD_STATE_BASIC)
531 rc = dasd_state_ready_to_basic(device);
534 device->state == DASD_STATE_UNFMT &&
535 device->target <= DASD_STATE_BASIC)
536 rc = dasd_state_unfmt_to_basic(device);
539 device->state == DASD_STATE_BASIC &&
540 device->target <= DASD_STATE_KNOWN)
541 rc = dasd_state_basic_to_known(device);
544 device->state == DASD_STATE_KNOWN &&
545 device->target <= DASD_STATE_NEW)
546 rc = dasd_state_known_to_new(device);
554 static void dasd_change_state(struct dasd_device *device)
558 if (device->state == device->target)
561 if (device->state < device->target)
562 rc = dasd_increase_state(device);
564 rc = dasd_decrease_state(device);
568 device->target = device->state;
570 /* let user-space know that the device status changed */
571 kobject_uevent(&device->cdev->dev.kobj, KOBJ_CHANGE);
573 if (device->state == device->target)
585 struct dasd_device *device = container_of(work, struct dasd_device, kick_work);
586 mutex_lock(&device->state_mutex);
587 dasd_change_state(device);
588 mutex_unlock(&device->state_mutex);
589 dasd_schedule_device_bh(device);
590 dasd_put_device(device);
593 void dasd_kick_device(struct dasd_device *device)
595 dasd_get_device(device);
597 if (!schedule_work(&device->kick_work))
598 dasd_put_device(device);
608 struct dasd_device *device = container_of(work, struct dasd_device,
610 device->discipline->reload(device);
611 dasd_put_device(device);
614 void dasd_reload_device(struct dasd_device *device)
616 dasd_get_device(device);
618 if (!schedule_work(&device->reload_device))
619 dasd_put_device(device);
629 struct dasd_device *device = container_of(work, struct dasd_device,
631 device->cdev->drv->restore(device->cdev);
632 dasd_put_device(device);
635 void dasd_restore_device(struct dasd_device *device)
637 dasd_get_device(device);
639 if (!schedule_work(&device->restore_device))
640 dasd_put_device(device);
644 * Set the target state for a device and starts the state change.
646 void dasd_set_target_state(struct dasd_device *device, int target)
648 dasd_get_device(device);
649 mutex_lock(&device->state_mutex);
653 if (device->target != target) {
654 if (device->state == target)
656 device->target = target;
658 if (device->state != device->target)
659 dasd_change_state(device);
660 mutex_unlock(&device->state_mutex);
661 dasd_put_device(device);
666 * Enable devices with device numbers in [from..to].
668 static inline int _wait_for_device(struct dasd_device *device)
670 return (device->state == device->target);
673 void dasd_enable_device(struct dasd_device *device)
675 dasd_set_target_state(device, DASD_STATE_ONLINE);
676 if (device->state <= DASD_STATE_KNOWN)
677 /* No discipline for device found. */
678 dasd_set_target_state(device, DASD_STATE_NEW);
680 wait_event(dasd_init_waitq, _wait_for_device(device));
682 dasd_reload_device(device);
683 if (device->discipline->kick_validate)
684 device->discipline->kick_validate(device);
689 * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
709 struct dasd_device *device;
735 * We count the request for the start device, even though it may run on
736 * some other device due to error recovery. This way we make sure that
739 device = cqr->startdev;
740 if (!device->profile.data)
743 spin_lock(get_ccwdev_lock(device->cdev));
744 counter = 1; /* request is not yet queued on the start device */
745 list_for_each(l, &device->ccw_queue)
748 spin_unlock(get_ccwdev_lock(device->cdev));
750 spin_lock(&device->profile.lock);
751 device->profile.data->dasd_io_nr_req[counter]++;
753 device->profile.data->dasd_read_nr_req[counter]++;
754 spin_unlock(&device->profile.lock);
821 struct dasd_device *device;
826 device = cqr->startdev;
829 device->profile.data))
888 spin_lock(&device->profile.lock);
889 if (device->profile.data) {
890 data = device->profile.data;
895 dasd_profile_end_add_data(device->profile.data,
904 spin_unlock(&device->profile.lock);
1196 struct dasd_device *device;
1199 device = m->private;
1200 dasd_get_device(device);
1202 if (device->discipline->hosts_print)
1203 rc = device->discipline->hosts_print(device, m);
1205 dasd_put_device(device);
1211 static void dasd_hosts_exit(struct dasd_device *device)
1213 debugfs_remove(device->hosts_dentry);
1214 device->hosts_dentry = NULL;
1218 struct dasd_device *device)
1228 device, &dasd_hosts_fops);
1230 device->hosts_dentry = pde;
1234 struct dasd_device *device,
1248 spin_lock_irqsave(&device->mem_lock, flags);
1249 data = chunk = dasd_alloc_chunk(&device->ccw_chunks, size);
1250 spin_unlock_irqrestore(&device->mem_lock, flags);
1270 dasd_get_device(device);
1277 struct dasd_device *device)
1291 spin_lock_irqsave(&device->mem_lock, flags);
1292 cqr = dasd_alloc_chunk(&device->ese_chunks, size);
1293 spin_unlock_irqrestore(&device->mem_lock, flags);
1312 dasd_get_device(device);
1318 void dasd_sfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
1322 spin_lock_irqsave(&device->mem_lock, flags);
1323 dasd_free_chunk(&device->ccw_chunks, cqr->mem_chunk);
1324 spin_unlock_irqrestore(&device->mem_lock, flags);
1325 dasd_put_device(device);
1329 void dasd_ffree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
1333 spin_lock_irqsave(&device->mem_lock, flags);
1334 dasd_free_chunk(&device->ese_chunks, cqr);
1335 spin_unlock_irqrestore(&device->mem_lock, flags);
1336 dasd_put_device(device);
1345 struct dasd_device *device;
1349 device = cqr->startdev;
1350 if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
1351 DBF_DEV_EVENT(DBF_WARNING, device,
1355 *(unsigned int *) device->discipline->name);
1363 * Timer keeps device runnig.
1369 struct dasd_device *device;
1378 device = (struct dasd_device *) cqr->startdev;
1380 rc = ccw_device_clear(device->cdev, (long) cqr);
1386 DBF_DEV_EVENT(DBF_DEBUG, device,
1391 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1392 "device gone, retry");
1396 * device not valid so no I/O could be running
1404 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1412 dev_err(&device->cdev->dev, "An error occurred in the "
1413 "DASD device driver, reason=%s\n", errorstring);
1419 dasd_schedule_device_bh(device);
1430 struct dasd_device *device;
1440 device = (struct dasd_device *) cqr->startdev;
1443 test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags)) &&
1445 DBF_DEV_EVENT(DBF_DEBUG, device, "start_IO: return request %p "
1454 dev_err(&device->cdev->dev, "An error occurred in the DASD "
1455 "device driver, reason=%s\n", errorstring);
1463 cqr->lpm &= dasd_path_get_opm(device);
1465 cqr->lpm = dasd_path_get_opm(device);
1475 rc = ccw_device_tm_start(device->cdev, cqr->cpaddr,
1478 rc = ccw_device_start(device->cdev, cqr->cpaddr,
1486 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1487 "start_IO: device busy, retry later");
1498 DBF_DEV_EVENT(DBF_WARNING, device,
1501 } else if (cqr->lpm != dasd_path_get_opm(device)) {
1502 cqr->lpm = dasd_path_get_opm(device);
1503 DBF_DEV_EVENT(DBF_DEBUG, device, "%s",
1507 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1510 dasd_generic_last_path_gone(device);
1511 dasd_path_no_path(device);
1512 dasd_path_set_tbvpm(device,
1514 device->cdev));
1518 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1519 "start_IO: -ENODEV device gone, retry");
1522 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1523 "start_IO: -EIO device gone, retry");
1527 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1528 "start_IO: -EINVAL device currently "
1534 dev_err(&device->cdev->dev,
1535 "An error occurred in the DASD device driver, "
1556 struct dasd_device *device;
1558 device = from_timer(device, t, timer);
1559 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1561 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
1562 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1563 dasd_schedule_device_bh(device);
1567 * Setup timeout for a device in jiffies.
1569 void dasd_device_set_timer(struct dasd_device *device, int expires)
1572 del_timer(&device->timer);
1574 mod_timer(&device->timer, jiffies + expires);
1579 * Clear timeout for a device.
1581 void dasd_device_clear_timer(struct dasd_device *device)
1583 del_timer(&device->timer);
1591 struct dasd_device *device;
1603 device = dasd_device_from_cdev_locked(cdev);
1604 if (IS_ERR(device)) {
1606 "unable to get device from cdev");
1611 device != cqr->startdev ||
1615 "invalid device in request");
1616 dasd_put_device(device);
1623 dasd_device_clear_timer(device);
1624 dasd_schedule_device_bh(device);
1625 dasd_put_device(device);
1628 void dasd_generic_handle_state_change(struct dasd_device *device)
1631 dasd_eer_snss(device);
1633 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
1634 dasd_schedule_device_bh(device);
1635 if (device->block) {
1636 dasd_schedule_block_bh(device->block);
1637 if (device->block->request_queue)
1638 blk_mq_run_hw_queues(device->block->request_queue,
1653 struct dasd_device *device = NULL;
1658 device = block->base;
1659 if (!device || !device->discipline->is_ese)
1661 if (!device->discipline->is_ese(device))
1688 struct dasd_device *device;
1701 device = cqr->startdev;
1703 dasd_device_clear_timer(device);
1705 dasd_schedule_device_bh(device);
1729 device = dasd_device_from_cdev_locked(cdev);
1730 if (IS_ERR(device))
1733 if (device->discipline == dasd_diag_discipline_pointer) {
1734 dasd_put_device(device);
1753 * Stop device and check exhaust level.
1756 dasd_generic_space_exhaust(device, cqr);
1757 device->discipline->ext_pool_exhaust(device, cqr);
1758 dasd_put_device(device);
1763 device->discipline->dump_sense_dbf(device, irb, "int");
1765 if (device->features & DASD_FEATURE_ERPLOG)
1766 device->discipline->dump_sense(device, cqr, irb);
1767 device->discipline->check_for_device_change(device, cqr, irb);
1768 dasd_put_device(device);
1773 device = dasd_device_from_cdev_locked(cdev);
1774 if (!IS_ERR(device)) {
1775 device->discipline->check_attention(device,
1777 dasd_put_device(device);
1784 device = (struct dasd_device *) cqr->startdev;
1785 if (!device ||
1786 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
1788 "invalid device in request");
1799 device->discipline->ese_read(cqr, irb);
1802 dasd_device_clear_timer(device);
1803 dasd_schedule_device_bh(device);
1806 fcqr = device->discipline->ese_format(device, cqr, irb);
1817 dasd_schedule_device_bh(device);
1822 list_add(&fcqr->devlist, &device->ccw_queue);
1823 dasd_schedule_device_bh(device);
1832 dasd_device_clear_timer(device);
1834 dasd_schedule_device_bh(device);
1840 DBF_DEV_EVENT(DBF_DEBUG, device, "invalid status: bus_id %s, "
1853 if (cqr->devlist.next != &device->ccw_queue) {
1863 device->discipline->handle_hpf_error)
1864 device->discipline->handle_hpf_error(device, irb);
1871 if (cqr->lpm == dasd_path_get_opm(device))
1872 DBF_DEV_EVENT(DBF_DEBUG, device,
1877 cqr->lpm = dasd_path_get_opm(device);
1884 (!device->stopped)) {
1885 if (device->discipline->start_IO(next) == 0)
1889 dasd_device_set_timer(device, expires);
1891 dasd_device_clear_timer(device);
1892 dasd_schedule_device_bh(device);
1898 struct dasd_device *device;
1900 device = dasd_device_from_cdev_locked(cdev);
1902 if (IS_ERR(device))
1904 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
1905 device->state != device->target ||
1906 !device->discipline->check_for_device_change){
1907 dasd_put_device(device);
1910 if (device->discipline->dump_sense_dbf)
1911 device->discipline->dump_sense_dbf(device, irb, "uc");
1912 device->discipline->check_for_device_change(device, NULL, irb);
1913 dasd_put_device(device);
1923 static void __dasd_device_recovery(struct dasd_device *device,
1935 list_for_each_safe(l, n, &device->ccw_queue) {
1948 static void __dasd_device_process_ccw_queue(struct dasd_device *device,
1955 list_for_each_safe(l, n, &device->ccw_queue) {
1964 __dasd_device_recovery(device, cqr);
1971 static void __dasd_process_cqr(struct dasd_device *device,
1989 dev_err(&device->cdev->dev,
1990 "An error occurred in the DASD device driver, "
2002 static void __dasd_device_process_final_queue(struct dasd_device *device,
2014 __dasd_process_cqr(device, cqr);
2017 __dasd_process_cqr(device, cqr);
2027 static void __dasd_device_check_expire(struct dasd_device *device)
2031 if (list_empty(&device->ccw_queue))
2033 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
2036 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
2043 if (device->discipline->term_IO(cqr) != 0) {
2045 dev_err(&device->cdev->dev,
2050 dasd_device_set_timer(device, 5*HZ);
2052 dev_err(&device->cdev->dev,
2061 * return 1 when device is not eligible for IO
2063 static int __dasd_device_is_unusable(struct dasd_device *device,
2068 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) &&
2069 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
2076 if (device->stopped) {
2077 if (device->stopped & mask) {
2082 /* CQR is not able to change device to
2086 /* CQR required to get device operational. */
2095 static void __dasd_device_start_head(struct dasd_device *device)
2100 if (list_empty(&device->ccw_queue))
2102 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
2105 /* if device is not usable return request to upper layer */
2106 if (__dasd_device_is_unusable(device, cqr)) {
2109 dasd_schedule_device_bh(device);
2113 rc = device->discipline->start_IO(cqr);
2115 dasd_device_set_timer(device, cqr->expires);
2117 dasd_schedule_device_bh(device);
2120 dasd_device_set_timer(device, 50);
2123 static void __dasd_device_check_path_events(struct dasd_device *device)
2127 if (!dasd_path_get_tbvpm(device))
2130 if (device->stopped &
2133 rc = device->discipline->pe_handler(device,
2134 dasd_path_get_tbvpm(device));
2136 dasd_device_set_timer(device, 50);
2138 dasd_path_clear_all_verify(device);
2147 * this function is called!. In other words, when 'device' is a base
2148 * device then all block layer requests must have been removed before
2151 int dasd_flush_device_queue(struct dasd_device *device)
2158 spin_lock_irq(get_ccwdev_lock(device->cdev));
2160 list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
2164 rc = device->discipline->term_IO(cqr);
2167 dev_err(&device->cdev->dev,
2184 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2197 __dasd_device_process_final_queue(device, &flush_queue);
2203 * Acquire the device lock and process queues for the device.
2207 struct dasd_device *device = (struct dasd_device *) data;
2210 atomic_set (&device->tasklet_scheduled, 0);
2212 spin_lock_irq(get_ccwdev_lock(device->cdev));
2214 __dasd_device_check_expire(device);
2216 __dasd_device_process_ccw_queue(device, &final_queue);
2217 __dasd_device_check_path_events(device);
2218 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2220 __dasd_device_process_final_queue(device, &final_queue);
2221 spin_lock_irq(get_ccwdev_lock(device->cdev));
2223 __dasd_device_start_head(device);
2224 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2227 dasd_put_device(device);
2231 * Schedules a call to dasd_tasklet over the device tasklet.
2233 void dasd_schedule_device_bh(struct dasd_device *device)
2236 if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
2238 dasd_get_device(device);
2239 tasklet_hi_schedule(&device->tasklet);
2243 void dasd_device_set_stop_bits(struct dasd_device *device, int bits)
2245 device->stopped |= bits;
2249 void dasd_device_remove_stop_bits(struct dasd_device *device, int bits)
2251 device->stopped &= ~bits;
2252 if (!device->stopped)
2258 * Queue a request to the head of the device ccw_queue.
2263 struct dasd_device *device;
2266 device = cqr->startdev;
2267 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2269 list_add(&cqr->devlist, &device->ccw_queue);
2271 dasd_schedule_device_bh(device);
2272 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2277 * Queue a request to the tail of the device ccw_queue.
2282 struct dasd_device *device;
2285 device = cqr->startdev;
2286 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2288 list_add_tail(&cqr->devlist, &device->ccw_queue);
2290 dasd_schedule_device_bh(device);
2291 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2309 struct dasd_device *device;
2312 device = cqr->startdev;
2313 spin_lock_irq(get_ccwdev_lock(device->cdev));
2315 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2324 struct dasd_device *device;
2329 device = cqr->startdev;
2332 device->discipline->handle_terminated_request(cqr);
2336 erp_fn = device->discipline->erp_action(cqr);
2343 __dasd_process_erp(device, cqr);
2363 struct dasd_device *device;
2370 device = maincqr->startdev;
2380 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2387 if (device->stopped & ~DASD_STOPPED_PENDING &&
2389 (!dasd_eer_enabled(device))) {
2395 * Don't try to start requests if device is in
2398 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
2404 * Don't try to start requests if device is stopped
2410 generic_waitq, !(device->stopped));
2417 wait_event(generic_waitq, !(device->stopped));
2467 struct dasd_device *device;
2474 device = cqr->startdev;
2478 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2485 if (device->stopped & ~DASD_STOPPED_PENDING &&
2487 !dasd_eer_enabled(device)) {
2493 /*Don't try to start requests if device is stopped*/
2496 generic_waitq, !device->stopped);
2503 wait_event(generic_waitq, !(device->stopped));
2549 * Queue a request to the tail of the device ccw_queue and wait for
2577 * Queue a request to the tail of the device ccw_queue and wait
2592 static inline int _dasd_term_running_cqr(struct dasd_device *device)
2597 if (list_empty(&device->ccw_queue))
2599 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
2600 rc = device->discipline->term_IO(cqr);
2613 struct dasd_device *device;
2616 device = cqr->startdev;
2617 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2623 spin_lock_irq(get_ccwdev_lock(device->cdev));
2624 rc = _dasd_term_running_cqr(device);
2626 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2636 list_add(&cqr->devlist, device->ccw_queue.next);
2639 dasd_schedule_device_bh(device);
2641 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2653 dasd_schedule_device_bh(device);
2654 if (device->block)
2655 dasd_schedule_block_bh(device->block);
2672 struct dasd_device *device = cqr->startdev;
2682 rc = device->discipline->term_IO(cqr);
2684 dev_err(&device->cdev->dev,
2694 dasd_schedule_device_bh(device);
2700 struct dasd_device *device = cqr->startdev;
2704 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2706 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2757 static void __dasd_process_erp(struct dasd_device *device,
2763 DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
2765 dev_err(&device->cdev->dev, "ERP failed for the DASD\n");
2766 erp_fn = device->discipline->erp_postaction(cqr);
2926 /* Don't try to start requests if device is stopped */
3080 * Schedules a call to dasd_tasklet over the device tasklet.
3087 /* life cycle of block is bound to it's base device */
3095 * SECTION: external block device operations
3117 "device not ready for request %p", req);
3123 * if device is stopped do not fetch new requests
3129 "device stopped request %p", req);
3197 struct dasd_device *device;
3207 device = cqr->startdev ? cqr->startdev : block->base;
3208 if (!device->blk_timeout) {
3212 DBF_DEV_EVENT(DBF_WARNING, device,
3217 spin_lock(get_ccwdev_lock(device->cdev));
3254 spin_unlock(get_ccwdev_lock(device->cdev));
3365 " Cannot open unrecognized device");
3431 * end of block device operations
3457 * Is the device read-only?
3459 * readonly device attribute, but how it is configured in z/VM.
3461 int dasd_device_is_ro(struct dasd_device *device)
3469 ccw_device_get_id(device->cdev, &dev_id);
3525 void dasd_generic_free_discipline(struct dasd_device *device)
3528 if (device->discipline) {
3529 if (device->discipline->uncheck_device)
3530 device->discipline->uncheck_device(device);
3531 module_put(device->discipline->owner);
3532 device->discipline = NULL;
3534 if (device->base_discipline) {
3535 module_put(device->base_discipline->owner);
3536 device->base_discipline = NULL;
3547 struct dasd_device *device;
3550 device = dasd_device_from_cdev(cdev);
3551 if (IS_ERR(device)) {
3555 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags) &&
3556 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3558 dasd_put_device(device);
3563 * This device is removed unconditionally. Set offline
3567 dasd_set_target_state(device, DASD_STATE_NEW);
3569 /* dasd_delete_device destroys the device reference. */
3570 block = device->block;
3571 dasd_delete_device(device);
3573 * life cycle of block is bound to device, so delete it after
3574 * device was safely removed
3584 * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
3585 * the device is detected for the first time and is supposed to be used
3592 struct dasd_device *device;
3597 device = dasd_create_device(cdev);
3598 if (IS_ERR(device))
3599 return PTR_ERR(device);
3602 if (device->features & DASD_FEATURE_USEDIAG) {
3612 dasd_delete_device(device);
3621 dasd_delete_device(device);
3627 dasd_delete_device(device);
3632 dasd_delete_device(device);
3635 device->base_discipline = base_discipline;
3636 device->discipline = discipline;
3638 /* check_device will allocate block device if necessary */
3639 rc = discipline->check_device(device);
3645 dasd_delete_device(device);
3649 dasd_set_target_state(device, DASD_STATE_ONLINE);
3650 if (device->state <= DASD_STATE_KNOWN) {
3654 dasd_set_target_state(device, DASD_STATE_NEW);
3655 if (device->block)
3656 dasd_free_block(device->block);
3657 dasd_delete_device(device);
3659 pr_debug("dasd_generic device %s found\n",
3662 wait_event(dasd_init_waitq, _wait_for_device(device));
3664 dasd_put_device(device);
3671 struct dasd_device *device;
3678 device = dasd_device_from_cdev_locked(cdev);
3679 if (IS_ERR(device)) {
3681 return PTR_ERR(device);
3685 * We must make sure that this device is currently not in use.
3690 if (device->block) {
3691 max_count = device->block->bdev ? 0 : -1;
3692 open_count = atomic_read(&device->block->open_count);
3711 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
3712 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3714 &device->flags);
3720 set_bit(DASD_FLAG_OFFLINE, &device->flags);
3727 if (test_and_clear_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags) &&
3728 !test_and_set_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3732 * If we want to set the device safe offline all IO operations
3737 if (device->block) {
3738 rc = fsync_bdev(device->block->bdev);
3742 dasd_schedule_device_bh(device);
3744 _wait_for_empty_queues(device));
3756 if (!test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3760 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
3764 dasd_set_target_state(device, DASD_STATE_NEW);
3765 /* dasd_delete_device destroys the device reference. */
3766 block = device->block;
3767 dasd_delete_device(device);
3769 * life cycle of block is bound to device, so delete it after
3770 * device was safely removed
3780 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
3781 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
3783 dasd_put_device(device);
3789 int dasd_generic_last_path_gone(struct dasd_device *device)
3793 dev_warn(&device->cdev->dev, "No operational channel path is left "
3794 "for the device\n");
3795 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "last path gone");
3797 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
3799 if (device->state < DASD_STATE_BASIC)
3802 list_for_each_entry(cqr, &device->ccw_queue, devlist)
3808 dasd_device_set_stop_bits(device, DASD_STOPPED_DC_WAIT);
3809 dasd_device_clear_timer(device);
3810 dasd_schedule_device_bh(device);
3815 int dasd_generic_path_operational(struct dasd_device *device)
3817 dev_info(&device->cdev->dev, "A channel path to the device has become "
3819 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "path operational");
3820 dasd_device_remove_stop_bits(device, DASD_STOPPED_DC_WAIT);
3821 if (device->stopped & DASD_UNRESUMED_PM) {
3822 dasd_device_remove_stop_bits(device, DASD_UNRESUMED_PM);
3823 dasd_restore_device(device);
3826 dasd_schedule_device_bh(device);
3827 if (device->block) {
3828 dasd_schedule_block_bh(device->block);
3829 if (device->block->request_queue)
3830 blk_mq_run_hw_queues(device->block->request_queue,
3834 if (!device->stopped)
3843 struct dasd_device *device;
3846 device = dasd_device_from_cdev_locked(cdev);
3847 if (IS_ERR(device))
3854 dasd_path_no_path(device);
3855 ret = dasd_generic_last_path_gone(device);
3859 if (dasd_path_get_opm(device))
3860 ret = dasd_generic_path_operational(device);
3863 dasd_put_device(device);
3870 struct dasd_device *device;
3873 device = dasd_device_from_cdev_locked(cdev);
3874 if (IS_ERR(device))
3877 oldopm = dasd_path_get_opm(device);
3880 dasd_path_notoper(device, chp);
3883 dasd_path_available(device, chp);
3884 dasd_schedule_device_bh(device);
3887 if (!dasd_path_is_operational(device, chp) &&
3888 !dasd_path_need_verify(device, chp)) {
3894 dasd_path_available(device, chp);
3895 dasd_schedule_device_bh(device);
3897 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3899 if (device->discipline->kick_validate)
3900 device->discipline->kick_validate(device);
3903 hpfpm = dasd_path_get_hpfpm(device);
3904 ifccpm = dasd_path_get_ifccpm(device);
3905 if (!dasd_path_get_opm(device) && hpfpm) {
3907 * device has no operational paths but at least one path is
3911 if (device->discipline->disable_hpf)
3912 device->discipline->disable_hpf(device);
3913 dasd_device_set_stop_bits(device, DASD_STOPPED_NOT_ACC);
3914 dasd_path_set_tbvpm(device, hpfpm);
3915 dasd_schedule_device_bh(device);
3916 dasd_schedule_requeue(device);
3917 } else if (!dasd_path_get_opm(device) && ifccpm) {
3919 * device has no operational paths but at least one path is
3923 dasd_path_set_tbvpm(device, ifccpm);
3924 dasd_schedule_device_bh(device);
3926 if (oldopm && !dasd_path_get_opm(device) && !hpfpm && !ifccpm) {
3927 dev_warn(&device->cdev->dev,
3928 "No verified channel paths remain for the device\n");
3929 DBF_DEV_EVENT(DBF_WARNING, device,
3931 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
3932 dasd_device_set_stop_bits(device,
3935 dasd_put_device(device);
3939 int dasd_generic_verify_path(struct dasd_device *device, __u8 lpm)
3941 if (!dasd_path_get_opm(device) && lpm) {
3942 dasd_path_set_opm(device, lpm);
3943 dasd_generic_path_operational(device);
3945 dasd_path_add_opm(device, lpm);
3950 void dasd_generic_space_exhaust(struct dasd_device *device,
3953 dasd_eer_write(device, NULL, DASD_EER_NOSPC);
3955 if (device->state < DASD_STATE_BASIC)
3963 dasd_device_set_stop_bits(device, DASD_STOPPED_NOSPC);
3964 dasd_device_clear_timer(device);
3965 dasd_schedule_device_bh(device);
3969 void dasd_generic_space_avail(struct dasd_device *device)
3971 dev_info(&device->cdev->dev, "Extent pool space is available\n");
3972 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "space available");
3974 dasd_device_remove_stop_bits(device, DASD_STOPPED_NOSPC);
3975 dasd_schedule_device_bh(device);
3977 if (device->block) {
3978 dasd_schedule_block_bh(device->block);
3979 if (device->block->request_queue)
3980 blk_mq_run_hw_queues(device->block->request_queue, true);
3982 if (!device->stopped)
3990 static int dasd_generic_requeue_all_requests(struct dasd_device *device)
3992 struct dasd_block *block = device->block;
4022 dasd_schedule_device_bh(device);
4028 struct dasd_device *device = container_of(work, struct dasd_device,
4030 dasd_generic_requeue_all_requests(device);
4031 dasd_device_remove_stop_bits(device, DASD_STOPPED_NOT_ACC);
4032 if (device->block)
4033 dasd_schedule_block_bh(device->block);
4034 dasd_put_device(device);
4037 void dasd_schedule_requeue(struct dasd_device *device)
4039 dasd_get_device(device);
4041 if (!schedule_work(&device->requeue_requests))
4042 dasd_put_device(device);
4048 struct dasd_device *device = dasd_device_from_cdev(cdev);
4050 if (IS_ERR(device))
4051 return PTR_ERR(device);
4053 /* mark device as suspended */
4054 set_bit(DASD_FLAG_SUSPENDED, &device->flags);
4056 if (device->discipline->freeze)
4057 device->discipline->freeze(device);
4060 dasd_device_set_stop_bits(device, DASD_STOPPED_PM);
4062 return dasd_generic_requeue_all_requests(device);
4068 struct dasd_device *device = dasd_device_from_cdev(cdev);
4071 if (IS_ERR(device))
4072 return PTR_ERR(device);
4075 dasd_device_remove_stop_bits(device,
4078 dasd_schedule_device_bh(device);
4082 * if device is stopped do nothing e.g. for disconnected devices
4084 if (device->discipline->restore && !(device->stopped))
4085 rc = device->discipline->restore(device);
4086 if (rc || device->stopped)
4091 device->stopped |= DASD_UNRESUMED_PM;
4093 if (device->block) {
4094 dasd_schedule_block_bh(device->block);
4095 if (device->block->request_queue)
4096 blk_mq_run_hw_queues(device->block->request_queue,
4100 clear_bit(DASD_FLAG_SUSPENDED, &device->flags);
4101 dasd_put_device(device);
4106 static struct dasd_ccw_req *dasd_generic_build_rdc(struct dasd_device *device,
4113 cqr = dasd_smalloc_request(magic, 1 /* RDC */, rdc_buffer_size, device,
4118 dev_err(&device->cdev->dev,
4119 "An error occurred in the DASD device driver, "
4129 cqr->startdev = device;
4130 cqr->memdev = device;
4139 int dasd_generic_read_dev_chars(struct dasd_device *device, int magic,
4145 cqr = dasd_generic_build_rdc(device, rdc_buffer_size, magic);
4193 struct dasd_device *device;
4195 device = dasd_device_from_cdev(cdev);
4196 if (IS_ERR(device))
4199 if (device->block)
4200 dasd_schedule_block_bh(device->block);
4202 dasd_schedule_device_bh(device);
4204 wait_event(shutdown_waitq, _wait_for_empty_queues(device));
4252 pr_info("The DASD device driver could not be initialized\n");