Lines Matching refs:device
52 MODULE_DESCRIPTION("Linux on S/390 DASD device driver,"
76 * SECTION: Operations on the device structure.
84 * Allocate memory for a new device structure.
88 struct dasd_device *device;
90 device = kzalloc(sizeof(struct dasd_device), GFP_ATOMIC);
91 if (!device)
94 /* Get two pages for normal block device operations. */
95 device->ccw_mem = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
96 if (!device->ccw_mem) {
97 kfree(device);
101 device->erp_mem = (void *) get_zeroed_page(GFP_ATOMIC | GFP_DMA);
102 if (!device->erp_mem) {
103 free_pages((unsigned long) device->ccw_mem, 1);
104 kfree(device);
108 device->ese_mem = (void *)__get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
109 if (!device->ese_mem) {
110 free_page((unsigned long) device->erp_mem);
111 free_pages((unsigned long) device->ccw_mem, 1);
112 kfree(device);
116 dasd_init_chunklist(&device->ccw_chunks, device->ccw_mem, PAGE_SIZE*2);
117 dasd_init_chunklist(&device->erp_chunks, device->erp_mem, PAGE_SIZE);
118 dasd_init_chunklist(&device->ese_chunks, device->ese_mem, PAGE_SIZE * 2);
119 spin_lock_init(&device->mem_lock);
120 atomic_set(&device->tasklet_scheduled, 0);
121 tasklet_init(&device->tasklet, dasd_device_tasklet,
122 (unsigned long) device);
123 INIT_LIST_HEAD(&device->ccw_queue);
124 timer_setup(&device->timer, dasd_device_timeout, 0);
125 INIT_WORK(&device->kick_work, do_kick_device);
126 INIT_WORK(&device->reload_device, do_reload_device);
127 INIT_WORK(&device->requeue_requests, do_requeue_requests);
128 device->state = DASD_STATE_NEW;
129 device->target = DASD_STATE_NEW;
130 mutex_init(&device->state_mutex);
131 spin_lock_init(&device->profile.lock);
132 return device;
136 * Free memory of a device structure.
138 void dasd_free_device(struct dasd_device *device)
140 kfree(device->private);
141 free_pages((unsigned long) device->ese_mem, 1);
142 free_page((unsigned long) device->erp_mem);
143 free_pages((unsigned long) device->ccw_mem, 1);
144 kfree(device);
148 * Allocate memory for a new device structure.
157 /* open_count = 0 means device online but not in use */
175 * Free memory of a device structure.
184 * Make a new device known to the system.
186 static int dasd_state_new_to_known(struct dasd_device *device)
189 * As long as the device is not in state DASD_STATE_NEW we want to
192 dasd_get_device(device);
193 device->state = DASD_STATE_KNOWN;
198 * Let the system forget about a device.
200 static int dasd_state_known_to_new(struct dasd_device *device)
202 /* Disable extended error reporting for this device. */
203 dasd_eer_disable(device);
204 device->state = DASD_STATE_NEW;
207 dasd_put_device(device);
225 * Request the irq line for the device.
227 static int dasd_state_known_to_basic(struct dasd_device *device)
229 struct dasd_block *block = device->block;
242 dasd_profile_on(&device->block->profile);
244 device->debugfs_dentry =
245 dasd_debugfs_setup(dev_name(&device->cdev->dev),
247 dasd_profile_init(&device->profile, device->debugfs_dentry);
248 dasd_hosts_init(device->debugfs_dentry, device);
250 /* register 'device' debug area, used for all DBF_DEV_XXX calls */
251 device->debug_area = debug_register(dev_name(&device->cdev->dev), 4, 1,
253 debug_register_view(device->debug_area, &debug_sprintf_view);
254 debug_set_level(device->debug_area, DBF_WARNING);
255 DBF_DEV_EVENT(DBF_EMERG, device, "%s", "debug area created");
257 device->state = DASD_STATE_BASIC;
263 * Release the irq line for the device. Terminate any running i/o.
265 static int dasd_state_basic_to_known(struct dasd_device *device)
269 if (device->discipline->basic_to_known) {
270 rc = device->discipline->basic_to_known(device);
275 if (device->block) {
276 dasd_profile_exit(&device->block->profile);
277 debugfs_remove(device->block->debugfs_dentry);
278 dasd_gendisk_free(device->block);
279 dasd_block_clear_timer(device->block);
281 rc = dasd_flush_device_queue(device);
284 dasd_device_clear_timer(device);
285 dasd_profile_exit(&device->profile);
286 dasd_hosts_exit(device);
287 debugfs_remove(device->debugfs_dentry);
288 DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device);
289 if (device->debug_area != NULL) {
290 debug_unregister(device->debug_area);
291 device->debug_area = NULL;
293 device->state = DASD_STATE_KNOWN;
299 * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
307 * device is setup.
308 * In case the analysis returns an error, the device setup is stopped
311 static int dasd_state_basic_to_ready(struct dasd_device *device)
318 block = device->block;
325 device->state = DASD_STATE_UNFMT;
326 disk = device->block->gdp;
333 if (device->discipline->setup_blk_queue)
334 device->discipline->setup_blk_queue(block);
337 device->state = DASD_STATE_READY;
340 device->state = DASD_STATE_BASIC;
344 device->state = DASD_STATE_READY;
347 if (device->discipline->basic_to_ready)
348 rc = device->discipline->basic_to_ready(device);
353 int _wait_for_empty_queues(struct dasd_device *device)
355 if (device->block)
356 return list_empty(&device->ccw_queue) &&
357 list_empty(&device->block->ccw_queue);
359 return list_empty(&device->ccw_queue);
363 * Remove device from block device layer. Destroy dirty buffers.
367 static int dasd_state_ready_to_basic(struct dasd_device *device)
371 device->state = DASD_STATE_BASIC;
372 if (device->block) {
373 struct dasd_block *block = device->block;
376 device->state = DASD_STATE_READY;
390 static int dasd_state_unfmt_to_basic(struct dasd_device *device)
392 device->state = DASD_STATE_BASIC;
397 * Make the device online and schedule the bottom half to start
402 dasd_state_ready_to_online(struct dasd_device * device)
404 device->state = DASD_STATE_ONLINE;
405 if (device->block) {
406 dasd_schedule_block_bh(device->block);
407 if ((device->features & DASD_FEATURE_USERAW)) {
408 kobject_uevent(&disk_to_dev(device->block->gdp)->kobj,
412 disk_uevent(device->block->bdev->bd_disk, KOBJ_CHANGE);
420 static int dasd_state_online_to_ready(struct dasd_device *device)
424 if (device->discipline->online_to_ready) {
425 rc = device->discipline->online_to_ready(device);
430 device->state = DASD_STATE_READY;
431 if (device->block && !(device->features & DASD_FEATURE_USERAW))
432 disk_uevent(device->block->bdev->bd_disk, KOBJ_CHANGE);
439 static int dasd_increase_state(struct dasd_device *device)
444 if (device->state == DASD_STATE_NEW &&
445 device->target >= DASD_STATE_KNOWN)
446 rc = dasd_state_new_to_known(device);
449 device->state == DASD_STATE_KNOWN &&
450 device->target >= DASD_STATE_BASIC)
451 rc = dasd_state_known_to_basic(device);
454 device->state == DASD_STATE_BASIC &&
455 device->target >= DASD_STATE_READY)
456 rc = dasd_state_basic_to_ready(device);
459 device->state == DASD_STATE_UNFMT &&
460 device->target > DASD_STATE_UNFMT)
464 device->state == DASD_STATE_READY &&
465 device->target >= DASD_STATE_ONLINE)
466 rc = dasd_state_ready_to_online(device);
474 static int dasd_decrease_state(struct dasd_device *device)
479 if (device->state == DASD_STATE_ONLINE &&
480 device->target <= DASD_STATE_READY)
481 rc = dasd_state_online_to_ready(device);
484 device->state == DASD_STATE_READY &&
485 device->target <= DASD_STATE_BASIC)
486 rc = dasd_state_ready_to_basic(device);
489 device->state == DASD_STATE_UNFMT &&
490 device->target <= DASD_STATE_BASIC)
491 rc = dasd_state_unfmt_to_basic(device);
494 device->state == DASD_STATE_BASIC &&
495 device->target <= DASD_STATE_KNOWN)
496 rc = dasd_state_basic_to_known(device);
499 device->state == DASD_STATE_KNOWN &&
500 device->target <= DASD_STATE_NEW)
501 rc = dasd_state_known_to_new(device);
509 static void dasd_change_state(struct dasd_device *device)
513 if (device->state == device->target)
516 if (device->state < device->target)
517 rc = dasd_increase_state(device);
519 rc = dasd_decrease_state(device);
523 device->target = device->state;
525 /* let user-space know that the device status changed */
526 kobject_uevent(&device->cdev->dev.kobj, KOBJ_CHANGE);
528 if (device->state == device->target)
540 struct dasd_device *device = container_of(work, struct dasd_device, kick_work);
541 mutex_lock(&device->state_mutex);
542 dasd_change_state(device);
543 mutex_unlock(&device->state_mutex);
544 dasd_schedule_device_bh(device);
545 dasd_put_device(device);
548 void dasd_kick_device(struct dasd_device *device)
550 dasd_get_device(device);
552 if (!schedule_work(&device->kick_work))
553 dasd_put_device(device);
563 struct dasd_device *device = container_of(work, struct dasd_device,
565 device->discipline->reload(device);
566 dasd_put_device(device);
569 void dasd_reload_device(struct dasd_device *device)
571 dasd_get_device(device);
573 if (!schedule_work(&device->reload_device))
574 dasd_put_device(device);
579 * Set the target state for a device and starts the state change.
581 void dasd_set_target_state(struct dasd_device *device, int target)
583 dasd_get_device(device);
584 mutex_lock(&device->state_mutex);
588 if (device->target != target) {
589 if (device->state == target)
591 device->target = target;
593 if (device->state != device->target)
594 dasd_change_state(device);
595 mutex_unlock(&device->state_mutex);
596 dasd_put_device(device);
600 * Enable devices with device numbers in [from..to].
602 static inline int _wait_for_device(struct dasd_device *device)
604 return (device->state == device->target);
607 void dasd_enable_device(struct dasd_device *device)
609 dasd_set_target_state(device, DASD_STATE_ONLINE);
610 if (device->state <= DASD_STATE_KNOWN)
611 /* No discipline for device found. */
612 dasd_set_target_state(device, DASD_STATE_NEW);
614 wait_event(dasd_init_waitq, _wait_for_device(device));
616 dasd_reload_device(device);
617 if (device->discipline->kick_validate)
618 device->discipline->kick_validate(device);
623 * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
643 struct dasd_device *device;
669 * We count the request for the start device, even though it may run on
670 * some other device due to error recovery. This way we make sure that
673 device = cqr->startdev;
674 if (!device->profile.data)
677 spin_lock(get_ccwdev_lock(device->cdev));
678 counter = 1; /* request is not yet queued on the start device */
679 list_for_each(l, &device->ccw_queue)
682 spin_unlock(get_ccwdev_lock(device->cdev));
684 spin_lock(&device->profile.lock);
685 device->profile.data->dasd_io_nr_req[counter]++;
687 device->profile.data->dasd_read_nr_req[counter]++;
688 spin_unlock(&device->profile.lock);
755 struct dasd_device *device;
760 device = cqr->startdev;
763 device->profile.data))
822 spin_lock(&device->profile.lock);
823 if (device->profile.data) {
824 data = device->profile.data;
829 dasd_profile_end_add_data(device->profile.data,
838 spin_unlock(&device->profile.lock);
1130 struct dasd_device *device;
1133 device = m->private;
1134 dasd_get_device(device);
1136 if (device->discipline->hosts_print)
1137 rc = device->discipline->hosts_print(device, m);
1139 dasd_put_device(device);
1145 static void dasd_hosts_exit(struct dasd_device *device)
1147 debugfs_remove(device->hosts_dentry);
1148 device->hosts_dentry = NULL;
1152 struct dasd_device *device)
1162 device, &dasd_hosts_fops);
1164 device->hosts_dentry = pde;
1168 struct dasd_device *device,
1182 spin_lock_irqsave(&device->mem_lock, flags);
1183 data = chunk = dasd_alloc_chunk(&device->ccw_chunks, size);
1184 spin_unlock_irqrestore(&device->mem_lock, flags);
1204 dasd_get_device(device);
1211 struct dasd_device *device)
1225 spin_lock_irqsave(&device->mem_lock, flags);
1226 cqr = dasd_alloc_chunk(&device->ese_chunks, size);
1227 spin_unlock_irqrestore(&device->mem_lock, flags);
1246 dasd_get_device(device);
1252 void dasd_sfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
1256 spin_lock_irqsave(&device->mem_lock, flags);
1257 dasd_free_chunk(&device->ccw_chunks, cqr->mem_chunk);
1258 spin_unlock_irqrestore(&device->mem_lock, flags);
1259 dasd_put_device(device);
1263 void dasd_ffree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
1267 spin_lock_irqsave(&device->mem_lock, flags);
1268 dasd_free_chunk(&device->ese_chunks, cqr);
1269 spin_unlock_irqrestore(&device->mem_lock, flags);
1270 dasd_put_device(device);
1279 struct dasd_device *device;
1283 device = cqr->startdev;
1284 if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
1285 DBF_DEV_EVENT(DBF_WARNING, device,
1289 *(unsigned int *) device->discipline->name);
1297 * Timer keeps device runnig.
1303 struct dasd_device *device;
1312 device = (struct dasd_device *) cqr->startdev;
1314 rc = ccw_device_clear(device->cdev, (long) cqr);
1320 DBF_DEV_EVENT(DBF_DEBUG, device,
1325 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1326 "device gone, retry");
1330 * device not valid so no I/O could be running
1338 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1346 dev_err(&device->cdev->dev, "An error occurred in the "
1347 "DASD device driver, reason=%s\n", errorstring);
1353 dasd_schedule_device_bh(device);
1364 struct dasd_device *device;
1374 device = (struct dasd_device *) cqr->startdev;
1377 test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags)) &&
1379 DBF_DEV_EVENT(DBF_DEBUG, device, "start_IO: return request %p "
1388 dev_err(&device->cdev->dev, "An error occurred in the DASD "
1389 "device driver, reason=%s\n", errorstring);
1397 cqr->lpm &= dasd_path_get_opm(device);
1399 cqr->lpm = dasd_path_get_opm(device);
1409 rc = ccw_device_tm_start(device->cdev, cqr->cpaddr,
1412 rc = ccw_device_start(device->cdev, cqr->cpaddr,
1420 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1421 "start_IO: device busy, retry later");
1432 DBF_DEV_EVENT(DBF_WARNING, device,
1435 } else if (cqr->lpm != dasd_path_get_opm(device)) {
1436 cqr->lpm = dasd_path_get_opm(device);
1437 DBF_DEV_EVENT(DBF_DEBUG, device, "%s",
1441 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1444 dasd_generic_last_path_gone(device);
1445 dasd_path_no_path(device);
1446 dasd_path_set_tbvpm(device,
1448 device->cdev));
1452 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1453 "start_IO: -ENODEV device gone, retry");
1455 dasd_handle_autoquiesce(device, cqr, DASD_EER_STARTIO);
1458 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1459 "start_IO: -EIO device gone, retry");
1462 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1463 "start_IO: -EINVAL device currently "
1469 dev_err(&device->cdev->dev,
1470 "An error occurred in the DASD device driver, "
1491 struct dasd_device *device;
1493 device = from_timer(device, t, timer);
1494 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1496 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
1497 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1498 dasd_schedule_device_bh(device);
1502 * Setup timeout for a device in jiffies.
1504 void dasd_device_set_timer(struct dasd_device *device, int expires)
1507 del_timer(&device->timer);
1509 mod_timer(&device->timer, jiffies + expires);
1514 * Clear timeout for a device.
1516 void dasd_device_clear_timer(struct dasd_device *device)
1518 del_timer(&device->timer);
1526 struct dasd_device *device;
1538 device = dasd_device_from_cdev_locked(cdev);
1539 if (IS_ERR(device)) {
1541 "unable to get device from cdev");
1546 device != cqr->startdev ||
1550 "invalid device in request");
1551 dasd_put_device(device);
1558 dasd_device_clear_timer(device);
1559 dasd_schedule_device_bh(device);
1560 dasd_put_device(device);
1563 void dasd_generic_handle_state_change(struct dasd_device *device)
1566 dasd_eer_snss(device);
1568 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
1569 dasd_schedule_device_bh(device);
1570 if (device->block) {
1571 dasd_schedule_block_bh(device->block);
1572 if (device->block->gdp)
1573 blk_mq_run_hw_queues(device->block->gdp->queue, true);
1587 struct dasd_device *device = NULL;
1592 device = block->base;
1593 if (!device || !device->discipline->is_ese)
1595 if (!device->discipline->is_ese(device))
1622 struct dasd_device *device;
1635 device = cqr->startdev;
1637 dasd_device_clear_timer(device);
1639 dasd_schedule_device_bh(device);
1663 device = dasd_device_from_cdev_locked(cdev);
1664 if (IS_ERR(device))
1667 if (device->discipline == dasd_diag_discipline_pointer) {
1668 dasd_put_device(device);
1687 * Stop device and check exhaust level.
1690 dasd_generic_space_exhaust(device, cqr);
1691 device->discipline->ext_pool_exhaust(device, cqr);
1692 dasd_put_device(device);
1697 device->discipline->dump_sense_dbf(device, irb, "int");
1699 if (device->features & DASD_FEATURE_ERPLOG)
1700 device->discipline->dump_sense(device, cqr, irb);
1701 device->discipline->check_for_device_change(device, cqr, irb);
1702 dasd_put_device(device);
1707 device = dasd_device_from_cdev_locked(cdev);
1708 if (!IS_ERR(device)) {
1709 device->discipline->check_attention(device,
1711 dasd_put_device(device);
1718 device = (struct dasd_device *) cqr->startdev;
1719 if (!device ||
1720 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
1722 "invalid device in request");
1733 device->discipline->ese_read(cqr, irb);
1736 dasd_device_clear_timer(device);
1737 dasd_schedule_device_bh(device);
1740 fcqr = device->discipline->ese_format(device, cqr, irb);
1751 dasd_schedule_device_bh(device);
1756 list_add(&fcqr->devlist, &device->ccw_queue);
1757 dasd_schedule_device_bh(device);
1766 dasd_device_clear_timer(device);
1768 dasd_schedule_device_bh(device);
1774 DBF_DEV_EVENT(DBF_DEBUG, device, "invalid status: bus_id %s, "
1787 if (cqr->devlist.next != &device->ccw_queue) {
1797 device->discipline->handle_hpf_error)
1798 device->discipline->handle_hpf_error(device, irb);
1805 if (cqr->lpm == dasd_path_get_opm(device))
1806 DBF_DEV_EVENT(DBF_DEBUG, device,
1811 cqr->lpm = dasd_path_get_opm(device);
1818 (!device->stopped)) {
1819 if (device->discipline->start_IO(next) == 0)
1823 dasd_device_set_timer(device, expires);
1825 dasd_device_clear_timer(device);
1826 dasd_schedule_device_bh(device);
1832 struct dasd_device *device;
1834 device = dasd_device_from_cdev_locked(cdev);
1836 if (IS_ERR(device))
1838 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
1839 device->state != device->target ||
1840 !device->discipline->check_for_device_change){
1841 dasd_put_device(device);
1844 if (device->discipline->dump_sense_dbf)
1845 device->discipline->dump_sense_dbf(device, irb, "uc");
1846 device->discipline->check_for_device_change(device, NULL, irb);
1847 dasd_put_device(device);
1857 static void __dasd_device_recovery(struct dasd_device *device,
1869 list_for_each_safe(l, n, &device->ccw_queue) {
1882 static void __dasd_device_process_ccw_queue(struct dasd_device *device,
1889 list_for_each_safe(l, n, &device->ccw_queue) {
1898 __dasd_device_recovery(device, cqr);
1905 static void __dasd_process_cqr(struct dasd_device *device,
1923 dev_err(&device->cdev->dev,
1924 "An error occurred in the DASD device driver, "
1936 static void __dasd_device_process_final_queue(struct dasd_device *device,
1948 __dasd_process_cqr(device, cqr);
1951 __dasd_process_cqr(device, cqr);
1958 * check if device should be autoquiesced due to too many timeouts
1960 static void __dasd_device_check_autoquiesce_timeout(struct dasd_device *device,
1963 if ((device->default_retries - cqr->retries) >= device->aq_timeouts)
1964 dasd_handle_autoquiesce(device, cqr, DASD_EER_TIMEOUTS);
1971 static void __dasd_device_check_expire(struct dasd_device *device)
1975 if (list_empty(&device->ccw_queue))
1977 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
1980 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
1987 if (device->discipline->term_IO(cqr) != 0) {
1989 dev_err(&device->cdev->dev,
1994 dasd_device_set_timer(device, 5*HZ);
1996 dev_err(&device->cdev->dev,
2001 __dasd_device_check_autoquiesce_timeout(device, cqr);
2006 * return 1 when device is not eligible for IO
2008 static int __dasd_device_is_unusable(struct dasd_device *device,
2013 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) &&
2014 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
2021 if (device->stopped) {
2022 if (device->stopped & mask) {
2027 /* CQR is not able to change device to
2031 /* CQR required to get device operational. */
2040 static void __dasd_device_start_head(struct dasd_device *device)
2045 if (list_empty(&device->ccw_queue))
2047 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
2050 /* if device is not usable return request to upper layer */
2051 if (__dasd_device_is_unusable(device, cqr)) {
2054 dasd_schedule_device_bh(device);
2058 rc = device->discipline->start_IO(cqr);
2060 dasd_device_set_timer(device, cqr->expires);
2062 dasd_schedule_device_bh(device);
2065 dasd_device_set_timer(device, 50);
2068 static void __dasd_device_check_path_events(struct dasd_device *device)
2073 tbvpm = dasd_path_get_tbvpm(device);
2074 fcsecpm = dasd_path_get_fcsecpm(device);
2079 if (device->stopped & ~(DASD_STOPPED_DC_WAIT))
2082 dasd_path_clear_all_verify(device);
2083 dasd_path_clear_all_fcsec(device);
2085 rc = device->discipline->pe_handler(device, tbvpm, fcsecpm);
2087 dasd_path_add_tbvpm(device, tbvpm);
2088 dasd_path_add_fcsecpm(device, fcsecpm);
2089 dasd_device_set_timer(device, 50);
2099 * this function is called!. In other words, when 'device' is a base
2100 * device then all block layer requests must have been removed before
2103 int dasd_flush_device_queue(struct dasd_device *device)
2110 spin_lock_irq(get_ccwdev_lock(device->cdev));
2112 list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
2116 rc = device->discipline->term_IO(cqr);
2119 dev_err(&device->cdev->dev,
2136 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2149 __dasd_device_process_final_queue(device, &flush_queue);
2155 * Acquire the device lock and process queues for the device.
2159 struct dasd_device *device = (struct dasd_device *) data;
2162 atomic_set (&device->tasklet_scheduled, 0);
2164 spin_lock_irq(get_ccwdev_lock(device->cdev));
2166 __dasd_device_check_expire(device);
2168 __dasd_device_process_ccw_queue(device, &final_queue);
2169 __dasd_device_check_path_events(device);
2170 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2172 __dasd_device_process_final_queue(device, &final_queue);
2173 spin_lock_irq(get_ccwdev_lock(device->cdev));
2175 __dasd_device_start_head(device);
2176 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2179 dasd_put_device(device);
2183 * Schedules a call to dasd_tasklet over the device tasklet.
2185 void dasd_schedule_device_bh(struct dasd_device *device)
2188 if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
2190 dasd_get_device(device);
2191 tasklet_hi_schedule(&device->tasklet);
2195 void dasd_device_set_stop_bits(struct dasd_device *device, int bits)
2197 device->stopped |= bits;
2201 void dasd_device_remove_stop_bits(struct dasd_device *device, int bits)
2203 device->stopped &= ~bits;
2204 if (!device->stopped)
2210 * Queue a request to the head of the device ccw_queue.
2215 struct dasd_device *device;
2218 device = cqr->startdev;
2219 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2221 list_add(&cqr->devlist, &device->ccw_queue);
2223 dasd_schedule_device_bh(device);
2224 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2229 * Queue a request to the tail of the device ccw_queue.
2234 struct dasd_device *device;
2237 device = cqr->startdev;
2238 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2240 list_add_tail(&cqr->devlist, &device->ccw_queue);
2242 dasd_schedule_device_bh(device);
2243 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2261 struct dasd_device *device;
2264 device = cqr->startdev;
2265 spin_lock_irq(get_ccwdev_lock(device->cdev));
2267 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2276 struct dasd_device *device;
2281 device = cqr->startdev;
2284 device->discipline->handle_terminated_request(cqr);
2288 erp_fn = device->discipline->erp_action(cqr);
2295 __dasd_process_erp(device, cqr);
2315 struct dasd_device *device;
2322 device = maincqr->startdev;
2332 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2339 if (device->stopped & ~DASD_STOPPED_PENDING &&
2341 !dasd_eer_enabled(device) && device->aq_mask == 0) {
2347 * Don't try to start requests if device is in
2350 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
2356 * Don't try to start requests if device is stopped
2362 generic_waitq, !(device->stopped));
2369 wait_event(generic_waitq, !(device->stopped));
2419 struct dasd_device *device;
2426 device = cqr->startdev;
2430 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2437 if (device->stopped & ~DASD_STOPPED_PENDING &&
2439 !dasd_eer_enabled(device)) {
2445 /*Don't try to start requests if device is stopped*/
2448 generic_waitq, !device->stopped);
2455 wait_event(generic_waitq, !(device->stopped));
2501 * Queue a request to the tail of the device ccw_queue and wait for
2529 * Queue a request to the tail of the device ccw_queue and wait
2544 static inline int _dasd_term_running_cqr(struct dasd_device *device)
2549 if (list_empty(&device->ccw_queue))
2551 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
2552 rc = device->discipline->term_IO(cqr);
2565 struct dasd_device *device;
2568 device = cqr->startdev;
2569 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2575 spin_lock_irq(get_ccwdev_lock(device->cdev));
2576 rc = _dasd_term_running_cqr(device);
2578 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2588 list_add(&cqr->devlist, device->ccw_queue.next);
2591 dasd_schedule_device_bh(device);
2593 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2605 dasd_schedule_device_bh(device);
2606 if (device->block)
2607 dasd_schedule_block_bh(device->block);
2624 struct dasd_device *device = cqr->startdev;
2634 rc = device->discipline->term_IO(cqr);
2636 dev_err(&device->cdev->dev,
2646 dasd_schedule_device_bh(device);
2652 struct dasd_device *device = cqr->startdev;
2656 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2658 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2709 static void __dasd_process_erp(struct dasd_device *device,
2715 DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
2717 dev_err(&device->cdev->dev, "ERP failed for the DASD\n");
2718 erp_fn = device->discipline->erp_postaction(cqr);
2881 /* Don't try to start requests if device is stopped */
3035 * Schedules a call to dasd_tasklet over the device tasklet.
3042 /* life cycle of block is bound to it's base device */
3050 * SECTION: external block device operations
3072 "device not ready for request %p", req);
3078 * if device is stopped do not fetch new requests
3084 "device stopped request %p", req);
3152 struct dasd_device *device;
3162 device = cqr->startdev ? cqr->startdev : block->base;
3163 if (!device->blk_timeout) {
3167 DBF_DEV_EVENT(DBF_WARNING, device,
3172 spin_lock(get_ccwdev_lock(device->cdev));
3209 spin_unlock(get_ccwdev_lock(device->cdev));
3281 " Cannot open unrecognized device");
3346 * end of block device operations
3372 * Is the device read-only?
3374 * readonly device attribute, but how it is configured in z/VM.
3376 int dasd_device_is_ro(struct dasd_device *device)
3384 ccw_device_get_id(device->cdev, &dev_id);
3429 void dasd_generic_free_discipline(struct dasd_device *device)
3432 if (device->discipline) {
3433 if (device->discipline->uncheck_device)
3434 device->discipline->uncheck_device(device);
3435 module_put(device->discipline->owner);
3436 device->discipline = NULL;
3438 if (device->base_discipline) {
3439 module_put(device->base_discipline->owner);
3440 device->base_discipline = NULL;
3451 struct dasd_device *device;
3454 device = dasd_device_from_cdev(cdev);
3455 if (IS_ERR(device))
3458 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags) &&
3459 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3461 dasd_put_device(device);
3465 * This device is removed unconditionally. Set offline
3469 dasd_set_target_state(device, DASD_STATE_NEW);
3471 /* dasd_delete_device destroys the device reference. */
3472 block = device->block;
3473 dasd_delete_device(device);
3475 * life cycle of block is bound to device, so delete it after
3476 * device was safely removed
3484 * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
3485 * the device is detected for the first time and is supposed to be used
3492 struct dasd_device *device;
3493 struct device *dev;
3500 device = dasd_create_device(cdev);
3501 if (IS_ERR(device))
3502 return PTR_ERR(device);
3505 if (device->features & DASD_FEATURE_USEDIAG) {
3514 dasd_delete_device(device);
3522 dasd_delete_device(device);
3528 dasd_delete_device(device);
3531 device->base_discipline = base_discipline;
3533 dasd_delete_device(device);
3536 device->discipline = discipline;
3538 /* check_device will allocate block device if necessary */
3539 rc = discipline->check_device(device);
3543 dasd_delete_device(device);
3547 dasd_set_target_state(device, DASD_STATE_ONLINE);
3548 if (device->state <= DASD_STATE_KNOWN) {
3551 dasd_set_target_state(device, DASD_STATE_NEW);
3552 if (device->block)
3553 dasd_free_block(device->block);
3554 dasd_delete_device(device);
3556 dev_dbg(dev, "dasd_generic device found\n");
3559 wait_event(dasd_init_waitq, _wait_for_device(device));
3561 dasd_put_device(device);
3569 struct dasd_device *device;
3572 struct device *dev;
3578 device = dasd_device_from_cdev_locked(cdev);
3579 if (IS_ERR(device)) {
3581 return PTR_ERR(device);
3585 * We must make sure that this device is currently not in use.
3590 if (device->block) {
3591 max_count = device->block->bdev ? 0 : -1;
3592 open_count = atomic_read(&device->block->open_count);
3610 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
3611 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3613 &device->flags);
3619 set_bit(DASD_FLAG_OFFLINE, &device->flags);
3626 if (test_and_clear_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags) &&
3627 !test_and_set_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3631 * If we want to set the device safe offline all IO operations
3636 if (device->block)
3637 bdev_mark_dead(device->block->bdev, false);
3638 dasd_schedule_device_bh(device);
3640 _wait_for_empty_queues(device));
3652 if (!test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3656 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
3660 dasd_set_target_state(device, DASD_STATE_NEW);
3661 /* dasd_delete_device destroys the device reference. */
3662 block = device->block;
3663 dasd_delete_device(device);
3665 * life cycle of block is bound to device, so delete it after
3666 * device was safely removed
3676 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
3677 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
3679 dasd_put_device(device);
3685 int dasd_generic_last_path_gone(struct dasd_device *device)
3689 dev_warn(&device->cdev->dev, "No operational channel path is left "
3690 "for the device\n");
3691 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "last path gone");
3693 dasd_handle_autoquiesce(device, NULL, DASD_EER_NOPATH);
3695 if (device->state < DASD_STATE_BASIC)
3698 list_for_each_entry(cqr, &device->ccw_queue, devlist)
3704 dasd_device_set_stop_bits(device, DASD_STOPPED_DC_WAIT);
3705 dasd_device_clear_timer(device);
3706 dasd_schedule_device_bh(device);
3711 int dasd_generic_path_operational(struct dasd_device *device)
3713 dev_info(&device->cdev->dev, "A channel path to the device has become "
3715 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "path operational");
3716 dasd_device_remove_stop_bits(device, DASD_STOPPED_DC_WAIT);
3717 dasd_schedule_device_bh(device);
3718 if (device->block) {
3719 dasd_schedule_block_bh(device->block);
3720 if (device->block->gdp)
3721 blk_mq_run_hw_queues(device->block->gdp->queue, true);
3724 if (!device->stopped)
3733 struct dasd_device *device;
3736 device = dasd_device_from_cdev_locked(cdev);
3737 if (IS_ERR(device))
3744 dasd_path_no_path(device);
3745 ret = dasd_generic_last_path_gone(device);
3749 if (dasd_path_get_opm(device))
3750 ret = dasd_generic_path_operational(device);
3753 dasd_put_device(device);
3760 struct dasd_device *device;
3763 device = dasd_device_from_cdev_locked(cdev);
3764 if (IS_ERR(device))
3767 oldopm = dasd_path_get_opm(device);
3770 dasd_path_notoper(device, chp);
3773 dasd_path_available(device, chp);
3774 dasd_schedule_device_bh(device);
3777 if (!dasd_path_is_operational(device, chp) &&
3778 !dasd_path_need_verify(device, chp)) {
3784 dasd_path_available(device, chp);
3785 dasd_schedule_device_bh(device);
3787 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3789 if (device->discipline->kick_validate)
3790 device->discipline->kick_validate(device);
3793 dasd_path_fcsec_update(device, chp);
3794 dasd_schedule_device_bh(device);
3797 hpfpm = dasd_path_get_hpfpm(device);
3798 ifccpm = dasd_path_get_ifccpm(device);
3799 if (!dasd_path_get_opm(device) && hpfpm) {
3801 * device has no operational paths but at least one path is
3805 if (device->discipline->disable_hpf)
3806 device->discipline->disable_hpf(device);
3807 dasd_device_set_stop_bits(device, DASD_STOPPED_NOT_ACC);
3808 dasd_path_set_tbvpm(device, hpfpm);
3809 dasd_schedule_device_bh(device);
3810 dasd_schedule_requeue(device);
3811 } else if (!dasd_path_get_opm(device) && ifccpm) {
3813 * device has no operational paths but at least one path is
3817 dasd_path_set_tbvpm(device, ifccpm);
3818 dasd_schedule_device_bh(device);
3820 if (oldopm && !dasd_path_get_opm(device) && !hpfpm && !ifccpm) {
3821 dev_warn(&device->cdev->dev,
3822 "No verified channel paths remain for the device\n");
3823 DBF_DEV_EVENT(DBF_WARNING, device,
3826 dasd_handle_autoquiesce(device, NULL, DASD_EER_NOPATH);
3827 dasd_device_set_stop_bits(device,
3830 dasd_put_device(device);
3834 int dasd_generic_verify_path(struct dasd_device *device, __u8 lpm)
3836 if (!dasd_path_get_opm(device) && lpm) {
3837 dasd_path_set_opm(device, lpm);
3838 dasd_generic_path_operational(device);
3840 dasd_path_add_opm(device, lpm);
3845 void dasd_generic_space_exhaust(struct dasd_device *device,
3849 dasd_handle_autoquiesce(device, NULL, DASD_EER_NOSPC);
3851 if (device->state < DASD_STATE_BASIC)
3859 dasd_device_set_stop_bits(device, DASD_STOPPED_NOSPC);
3860 dasd_device_clear_timer(device);
3861 dasd_schedule_device_bh(device);
3865 void dasd_generic_space_avail(struct dasd_device *device)
3867 dev_info(&device->cdev->dev, "Extent pool space is available\n");
3868 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "space available");
3870 dasd_device_remove_stop_bits(device, DASD_STOPPED_NOSPC);
3871 dasd_schedule_device_bh(device);
3873 if (device->block) {
3874 dasd_schedule_block_bh(device->block);
3875 if (device->block->gdp)
3876 blk_mq_run_hw_queues(device->block->gdp->queue, true);
3878 if (!device->stopped)
3886 int dasd_generic_requeue_all_requests(struct dasd_device *device)
3888 struct dasd_block *block = device->block;
3918 dasd_schedule_device_bh(device);
3925 struct dasd_device *device = container_of(work, struct dasd_device,
3927 dasd_generic_requeue_all_requests(device);
3928 dasd_device_remove_stop_bits(device, DASD_STOPPED_NOT_ACC);
3929 if (device->block)
3930 dasd_schedule_block_bh(device->block);
3931 dasd_put_device(device);
3934 void dasd_schedule_requeue(struct dasd_device *device)
3936 dasd_get_device(device);
3938 if (!schedule_work(&device->requeue_requests))
3939 dasd_put_device(device);
3943 static int dasd_handle_autoquiesce(struct dasd_device *device,
3948 if (dasd_eer_enabled(device))
3949 dasd_eer_write(device, cqr, reason);
3951 if (!test_bit(reason, &device->aq_mask))
3955 if (dasd_eer_enabled(device))
3956 dasd_eer_write(device, NULL, DASD_EER_AUTOQUIESCE);
3958 dev_info(&device->cdev->dev,
3960 dasd_device_set_stop_bits(device, DASD_STOPPED_QUIESCE);
3962 if (device->features & DASD_FEATURE_REQUEUEQUIESCE)
3963 dasd_schedule_requeue(device);
3968 static struct dasd_ccw_req *dasd_generic_build_rdc(struct dasd_device *device,
3975 cqr = dasd_smalloc_request(magic, 1 /* RDC */, rdc_buffer_size, device,
3980 dev_err(&device->cdev->dev,
3981 "An error occurred in the DASD device driver, "
3991 cqr->startdev = device;
3992 cqr->memdev = device;
4001 int dasd_generic_read_dev_chars(struct dasd_device *device, int magic,
4007 cqr = dasd_generic_build_rdc(device, rdc_buffer_size, magic);
4054 struct dasd_device *device;
4056 device = dasd_device_from_cdev(cdev);
4057 if (IS_ERR(device))
4060 if (device->block)
4061 dasd_schedule_block_bh(device->block);
4063 dasd_schedule_device_bh(device);
4065 wait_event(shutdown_waitq, _wait_for_empty_queues(device));
4113 pr_info("The DASD device driver could not be initialized\n");