blob: c6c2e918b990d3645bb5e384f9de4b4aae5804c4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * drivers/s390/char/tape_core.c
3 * basic function of the tape device driver
4 *
5 * S390 and zSeries version
Stefan Bader41117962005-07-27 11:45:04 -07006 * Copyright (C) 2001,2005 IBM Deutschland Entwicklung GmbH, IBM Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * Author(s): Carsten Otte <cotte@de.ibm.com>
8 * Michael Holzheu <holzheu@de.ibm.com>
9 * Tuan Ngo-Anh <ngoanh@de.ibm.com>
10 * Martin Schwidefsky <schwidefsky@de.ibm.com>
Stefan Bader41117962005-07-27 11:45:04 -070011 * Stefan Bader <shbader@de.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 */
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/module.h>
15#include <linux/init.h> // for kernel parameters
16#include <linux/kmod.h> // for requesting modules
17#include <linux/spinlock.h> // for locks
18#include <linux/vmalloc.h>
19#include <linux/list.h>
20
21#include <asm/types.h> // for variable types
22
23#define TAPE_DBF_AREA tape_core_dbf
24
25#include "tape.h"
26#include "tape_std.h"
27
28#define PRINTK_HEADER "TAPE_CORE: "
29
30static void __tape_do_irq (struct ccw_device *, unsigned long, struct irb *);
Martin Schwidefskyc1637532006-12-08 15:53:57 +010031static void tape_delayed_next_request(struct work_struct *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
33/*
34 * One list to contain all tape devices of all disciplines, so
35 * we can assign the devices to minor numbers of the same major
36 * The list is protected by the rwlock
37 */
38static struct list_head tape_device_list = LIST_HEAD_INIT(tape_device_list);
39static DEFINE_RWLOCK(tape_device_lock);
40
41/*
42 * Pointer to debug area.
43 */
44debug_info_t *TAPE_DBF_AREA = NULL;
45EXPORT_SYMBOL(TAPE_DBF_AREA);
46
47/*
48 * Printable strings for tape enumerations.
49 */
50const char *tape_state_verbose[TS_SIZE] =
51{
52 [TS_UNUSED] = "UNUSED",
53 [TS_IN_USE] = "IN_USE",
54 [TS_BLKUSE] = "BLKUSE",
55 [TS_INIT] = "INIT ",
56 [TS_NOT_OPER] = "NOT_OP"
57};
58
59const char *tape_op_verbose[TO_SIZE] =
60{
61 [TO_BLOCK] = "BLK", [TO_BSB] = "BSB",
62 [TO_BSF] = "BSF", [TO_DSE] = "DSE",
63 [TO_FSB] = "FSB", [TO_FSF] = "FSF",
64 [TO_LBL] = "LBL", [TO_NOP] = "NOP",
65 [TO_RBA] = "RBA", [TO_RBI] = "RBI",
66 [TO_RFO] = "RFO", [TO_REW] = "REW",
67 [TO_RUN] = "RUN", [TO_WRI] = "WRI",
68 [TO_WTM] = "WTM", [TO_MSEN] = "MSN",
69 [TO_LOAD] = "LOA", [TO_READ_CONFIG] = "RCF",
70 [TO_READ_ATTMSG] = "RAT",
71 [TO_DIS] = "DIS", [TO_ASSIGN] = "ASS",
72 [TO_UNASSIGN] = "UAS"
73};
74
75static inline int
76busid_to_int(char *bus_id)
77{
78 int dec;
79 int d;
80 char * s;
81
82 for(s = bus_id, d = 0; *s != '\0' && *s != '.'; s++)
83 d = (d * 10) + (*s - '0');
84 dec = d;
85 for(s++, d = 0; *s != '\0' && *s != '.'; s++)
86 d = (d * 10) + (*s - '0');
87 dec = (dec << 8) + d;
88
89 for(s++; *s != '\0'; s++) {
90 if (*s >= '0' && *s <= '9') {
91 d = *s - '0';
92 } else if (*s >= 'a' && *s <= 'f') {
93 d = *s - 'a' + 10;
94 } else {
95 d = *s - 'A' + 10;
96 }
97 dec = (dec << 4) + d;
98 }
99
100 return dec;
101}
102
103/*
104 * Some channel attached tape specific attributes.
105 *
106 * FIXME: In the future the first_minor and blocksize attribute should be
107 * replaced by a link to the cdev tree.
108 */
109static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400110tape_medium_state_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
112 struct tape_device *tdev;
113
114 tdev = (struct tape_device *) dev->driver_data;
115 return scnprintf(buf, PAGE_SIZE, "%i\n", tdev->medium_state);
116}
117
118static
119DEVICE_ATTR(medium_state, 0444, tape_medium_state_show, NULL);
120
121static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400122tape_first_minor_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123{
124 struct tape_device *tdev;
125
126 tdev = (struct tape_device *) dev->driver_data;
127 return scnprintf(buf, PAGE_SIZE, "%i\n", tdev->first_minor);
128}
129
130static
131DEVICE_ATTR(first_minor, 0444, tape_first_minor_show, NULL);
132
133static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400134tape_state_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135{
136 struct tape_device *tdev;
137
138 tdev = (struct tape_device *) dev->driver_data;
139 return scnprintf(buf, PAGE_SIZE, "%s\n", (tdev->first_minor < 0) ?
140 "OFFLINE" : tape_state_verbose[tdev->tape_state]);
141}
142
143static
144DEVICE_ATTR(state, 0444, tape_state_show, NULL);
145
146static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400147tape_operation_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148{
149 struct tape_device *tdev;
150 ssize_t rc;
151
152 tdev = (struct tape_device *) dev->driver_data;
153 if (tdev->first_minor < 0)
154 return scnprintf(buf, PAGE_SIZE, "N/A\n");
155
156 spin_lock_irq(get_ccwdev_lock(tdev->cdev));
157 if (list_empty(&tdev->req_queue))
158 rc = scnprintf(buf, PAGE_SIZE, "---\n");
159 else {
160 struct tape_request *req;
161
162 req = list_entry(tdev->req_queue.next, struct tape_request,
163 list);
164 rc = scnprintf(buf,PAGE_SIZE, "%s\n", tape_op_verbose[req->op]);
165 }
166 spin_unlock_irq(get_ccwdev_lock(tdev->cdev));
167 return rc;
168}
169
170static
171DEVICE_ATTR(operation, 0444, tape_operation_show, NULL);
172
173static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400174tape_blocksize_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175{
176 struct tape_device *tdev;
177
178 tdev = (struct tape_device *) dev->driver_data;
179
180 return scnprintf(buf, PAGE_SIZE, "%i\n", tdev->char_data.block_size);
181}
182
183static
184DEVICE_ATTR(blocksize, 0444, tape_blocksize_show, NULL);
185
186static struct attribute *tape_attrs[] = {
187 &dev_attr_medium_state.attr,
188 &dev_attr_first_minor.attr,
189 &dev_attr_state.attr,
190 &dev_attr_operation.attr,
191 &dev_attr_blocksize.attr,
192 NULL
193};
194
195static struct attribute_group tape_attr_group = {
196 .attrs = tape_attrs,
197};
198
199/*
200 * Tape state functions
201 */
202void
203tape_state_set(struct tape_device *device, enum tape_state newstate)
204{
205 const char *str;
206
207 if (device->tape_state == TS_NOT_OPER) {
208 DBF_EVENT(3, "ts_set err: not oper\n");
209 return;
210 }
211 DBF_EVENT(4, "ts. dev: %x\n", device->first_minor);
Peter Oberparleiterf9760692006-04-10 22:53:49 -0700212 DBF_EVENT(4, "old ts:\t\n");
213 if (device->tape_state < TS_SIZE && device->tape_state >=0 )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 str = tape_state_verbose[device->tape_state];
215 else
216 str = "UNKNOWN TS";
217 DBF_EVENT(4, "%s\n", str);
218 DBF_EVENT(4, "new ts:\t\n");
Peter Oberparleiterf9760692006-04-10 22:53:49 -0700219 if (newstate < TS_SIZE && newstate >= 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 str = tape_state_verbose[newstate];
221 else
222 str = "UNKNOWN TS";
223 DBF_EVENT(4, "%s\n", str);
224 device->tape_state = newstate;
225 wake_up(&device->state_change_wq);
226}
227
228void
229tape_med_state_set(struct tape_device *device, enum tape_medium_state newstate)
230{
231 if (device->medium_state == newstate)
232 return;
233 switch(newstate){
234 case MS_UNLOADED:
235 device->tape_generic_status |= GMT_DR_OPEN(~0);
236 PRINT_INFO("(%s): Tape is unloaded\n",
237 device->cdev->dev.bus_id);
238 break;
239 case MS_LOADED:
240 device->tape_generic_status &= ~GMT_DR_OPEN(~0);
241 PRINT_INFO("(%s): Tape has been mounted\n",
242 device->cdev->dev.bus_id);
243 break;
244 default:
245 // print nothing
246 break;
247 }
248 device->medium_state = newstate;
249 wake_up(&device->state_change_wq);
250}
251
252/*
253 * Stop running ccw. Has to be called with the device lock held.
254 */
255static inline int
Stefan Bader41117962005-07-27 11:45:04 -0700256__tape_cancel_io(struct tape_device *device, struct tape_request *request)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257{
258 int retries;
259 int rc;
260
261 /* Check if interrupt has already been processed */
262 if (request->callback == NULL)
263 return 0;
264
265 rc = 0;
266 for (retries = 0; retries < 5; retries++) {
267 rc = ccw_device_clear(device->cdev, (long) request);
268
Stefan Bader41117962005-07-27 11:45:04 -0700269 switch (rc) {
270 case 0:
271 request->status = TAPE_REQUEST_DONE;
272 return 0;
273 case -EBUSY:
274 request->status = TAPE_REQUEST_CANCEL;
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100275 schedule_delayed_work(&device->tape_dnr, 0);
Stefan Bader41117962005-07-27 11:45:04 -0700276 return 0;
277 case -ENODEV:
278 DBF_EXCEPTION(2, "device gone, retry\n");
279 break;
280 case -EIO:
281 DBF_EXCEPTION(2, "I/O error, retry\n");
282 break;
283 default:
284 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 }
287
288 return rc;
289}
290
291/*
292 * Add device into the sorted list, giving it the first
293 * available minor number.
294 */
295static int
296tape_assign_minor(struct tape_device *device)
297{
298 struct tape_device *tmp;
299 int minor;
300
301 minor = 0;
302 write_lock(&tape_device_lock);
303 list_for_each_entry(tmp, &tape_device_list, node) {
304 if (minor < tmp->first_minor)
305 break;
306 minor += TAPE_MINORS_PER_DEV;
307 }
308 if (minor >= 256) {
309 write_unlock(&tape_device_lock);
310 return -ENODEV;
311 }
312 device->first_minor = minor;
313 list_add_tail(&device->node, &tmp->node);
314 write_unlock(&tape_device_lock);
315 return 0;
316}
317
318/* remove device from the list */
319static void
320tape_remove_minor(struct tape_device *device)
321{
322 write_lock(&tape_device_lock);
323 list_del_init(&device->node);
324 device->first_minor = -1;
325 write_unlock(&tape_device_lock);
326}
327
328/*
329 * Set a device online.
330 *
331 * This function is called by the common I/O layer to move a device from the
332 * detected but offline into the online state.
333 * If we return an error (RC < 0) the device remains in the offline state. This
334 * can happen if the device is assigned somewhere else, for example.
335 */
336int
337tape_generic_online(struct tape_device *device,
338 struct tape_discipline *discipline)
339{
340 int rc;
341
342 DBF_LH(6, "tape_enable_device(%p, %p)\n", device, discipline);
343
344 if (device->tape_state != TS_INIT) {
345 DBF_LH(3, "Tapestate not INIT (%d)\n", device->tape_state);
346 return -EINVAL;
347 }
348
349 /* Let the discipline have a go at the device. */
350 device->discipline = discipline;
351 if (!try_module_get(discipline->owner)) {
352 PRINT_ERR("Cannot get module. Module gone.\n");
353 return -EINVAL;
354 }
355
356 rc = discipline->setup_device(device);
357 if (rc)
358 goto out;
359 rc = tape_assign_minor(device);
360 if (rc)
361 goto out_discipline;
362
363 rc = tapechar_setup_device(device);
364 if (rc)
365 goto out_minor;
366 rc = tapeblock_setup_device(device);
367 if (rc)
368 goto out_char;
369
370 tape_state_set(device, TS_UNUSED);
371
372 DBF_LH(3, "(%08x): Drive set online\n", device->cdev_id);
373
374 return 0;
375
376out_char:
377 tapechar_cleanup_device(device);
378out_discipline:
379 device->discipline->cleanup_device(device);
380 device->discipline = NULL;
381out_minor:
382 tape_remove_minor(device);
383out:
384 module_put(discipline->owner);
385 return rc;
386}
387
388static inline void
389tape_cleanup_device(struct tape_device *device)
390{
391 tapeblock_cleanup_device(device);
392 tapechar_cleanup_device(device);
393 device->discipline->cleanup_device(device);
394 module_put(device->discipline->owner);
395 tape_remove_minor(device);
396 tape_med_state_set(device, MS_UNKNOWN);
397}
398
399/*
400 * Set device offline.
401 *
402 * Called by the common I/O layer if the drive should set offline on user
403 * request. We may prevent this by returning an error.
404 * Manual offline is only allowed while the drive is not in use.
405 */
406int
407tape_generic_offline(struct tape_device *device)
408{
409 if (!device) {
410 PRINT_ERR("tape_generic_offline: no such device\n");
411 return -ENODEV;
412 }
413
414 DBF_LH(3, "(%08x): tape_generic_offline(%p)\n",
415 device->cdev_id, device);
416
417 spin_lock_irq(get_ccwdev_lock(device->cdev));
418 switch (device->tape_state) {
419 case TS_INIT:
420 case TS_NOT_OPER:
421 spin_unlock_irq(get_ccwdev_lock(device->cdev));
422 break;
423 case TS_UNUSED:
424 tape_state_set(device, TS_INIT);
425 spin_unlock_irq(get_ccwdev_lock(device->cdev));
426 tape_cleanup_device(device);
427 break;
428 default:
429 DBF_EVENT(3, "(%08x): Set offline failed "
430 "- drive in use.\n",
431 device->cdev_id);
432 PRINT_WARN("(%s): Set offline failed "
433 "- drive in use.\n",
434 device->cdev->dev.bus_id);
435 spin_unlock_irq(get_ccwdev_lock(device->cdev));
436 return -EBUSY;
437 }
438
439 DBF_LH(3, "(%08x): Drive set offline.\n", device->cdev_id);
440 return 0;
441}
442
443/*
444 * Allocate memory for a new device structure.
445 */
446static struct tape_device *
447tape_alloc_device(void)
448{
449 struct tape_device *device;
450
Eric Sesterhenn88abaab2006-03-24 03:15:31 -0800451 device = kzalloc(sizeof(struct tape_device), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 if (device == NULL) {
453 DBF_EXCEPTION(2, "ti:no mem\n");
454 PRINT_INFO ("can't allocate memory for "
455 "tape info structure\n");
456 return ERR_PTR(-ENOMEM);
457 }
Eric Sesterhenn88abaab2006-03-24 03:15:31 -0800458 device->modeset_byte = kmalloc(1, GFP_KERNEL | GFP_DMA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 if (device->modeset_byte == NULL) {
460 DBF_EXCEPTION(2, "ti:no mem\n");
461 PRINT_INFO("can't allocate memory for modeset byte\n");
462 kfree(device);
463 return ERR_PTR(-ENOMEM);
464 }
465 INIT_LIST_HEAD(&device->req_queue);
466 INIT_LIST_HEAD(&device->node);
467 init_waitqueue_head(&device->state_change_wq);
468 device->tape_state = TS_INIT;
469 device->medium_state = MS_UNKNOWN;
470 *device->modeset_byte = 0;
471 device->first_minor = -1;
472 atomic_set(&device->ref_count, 1);
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100473 INIT_DELAYED_WORK(&device->tape_dnr, tape_delayed_next_request);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
475 return device;
476}
477
478/*
479 * Get a reference to an existing device structure. This will automatically
480 * increment the reference count.
481 */
482struct tape_device *
483tape_get_device_reference(struct tape_device *device)
484{
485 DBF_EVENT(4, "tape_get_device_reference(%p) = %i\n", device,
486 atomic_inc_return(&device->ref_count));
487
488 return device;
489}
490
491/*
492 * Decrease the reference counter of a devices structure. If the
493 * reference counter reaches zero free the device structure.
494 * The function returns a NULL pointer to be used by the caller
495 * for clearing reference pointers.
496 */
497struct tape_device *
498tape_put_device(struct tape_device *device)
499{
500 int remain;
501
502 remain = atomic_dec_return(&device->ref_count);
503 if (remain > 0) {
504 DBF_EVENT(4, "tape_put_device(%p) -> %i\n", device, remain);
505 } else {
506 if (remain < 0) {
507 DBF_EVENT(4, "put device without reference\n");
508 PRINT_ERR("put device without reference\n");
509 } else {
510 DBF_EVENT(4, "tape_free_device(%p)\n", device);
511 kfree(device->modeset_byte);
512 kfree(device);
513 }
514 }
515
516 return NULL;
517}
518
519/*
520 * Find tape device by a device index.
521 */
522struct tape_device *
523tape_get_device(int devindex)
524{
525 struct tape_device *device, *tmp;
526
527 device = ERR_PTR(-ENODEV);
528 read_lock(&tape_device_lock);
529 list_for_each_entry(tmp, &tape_device_list, node) {
530 if (tmp->first_minor / TAPE_MINORS_PER_DEV == devindex) {
531 device = tape_get_device_reference(tmp);
532 break;
533 }
534 }
535 read_unlock(&tape_device_lock);
536 return device;
537}
538
539/*
540 * Driverfs tape probe function.
541 */
542int
543tape_generic_probe(struct ccw_device *cdev)
544{
545 struct tape_device *device;
Heiko Carstensd7cf0d52006-07-18 13:46:58 +0200546 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
548 device = tape_alloc_device();
549 if (IS_ERR(device))
550 return -ENODEV;
Heiko Carstensd7cf0d52006-07-18 13:46:58 +0200551 ccw_device_set_options(cdev, CCWDEV_DO_PATHGROUP);
552 ret = sysfs_create_group(&cdev->dev.kobj, &tape_attr_group);
553 if (ret) {
554 tape_put_device(device);
555 PRINT_ERR("probe failed for tape device %s\n", cdev->dev.bus_id);
556 return ret;
557 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 cdev->dev.driver_data = device;
Heiko Carstensd7cf0d52006-07-18 13:46:58 +0200559 cdev->handler = __tape_do_irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 device->cdev = cdev;
561 device->cdev_id = busid_to_int(cdev->dev.bus_id);
Heiko Carstensd7cf0d52006-07-18 13:46:58 +0200562 PRINT_INFO("tape device %s found\n", cdev->dev.bus_id);
563 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564}
565
566static inline void
567__tape_discard_requests(struct tape_device *device)
568{
569 struct tape_request * request;
570 struct list_head * l, *n;
571
572 list_for_each_safe(l, n, &device->req_queue) {
573 request = list_entry(l, struct tape_request, list);
574 if (request->status == TAPE_REQUEST_IN_IO)
575 request->status = TAPE_REQUEST_DONE;
576 list_del(&request->list);
577
578 /* Decrease ref_count for removed request. */
579 request->device = tape_put_device(device);
580 request->rc = -EIO;
581 if (request->callback != NULL)
582 request->callback(request, request->callback_data);
583 }
584}
585
586/*
587 * Driverfs tape remove function.
588 *
589 * This function is called whenever the common I/O layer detects the device
590 * gone. This can happen at any time and we cannot refuse.
591 */
592void
593tape_generic_remove(struct ccw_device *cdev)
594{
595 struct tape_device * device;
596
597 device = cdev->dev.driver_data;
598 if (!device) {
599 PRINT_ERR("No device pointer in tape_generic_remove!\n");
600 return;
601 }
602 DBF_LH(3, "(%08x): tape_generic_remove(%p)\n", device->cdev_id, cdev);
603
604 spin_lock_irq(get_ccwdev_lock(device->cdev));
605 switch (device->tape_state) {
606 case TS_INIT:
607 tape_state_set(device, TS_NOT_OPER);
608 case TS_NOT_OPER:
609 /*
610 * Nothing to do.
611 */
612 spin_unlock_irq(get_ccwdev_lock(device->cdev));
613 break;
614 case TS_UNUSED:
615 /*
616 * Need only to release the device.
617 */
618 tape_state_set(device, TS_NOT_OPER);
619 spin_unlock_irq(get_ccwdev_lock(device->cdev));
620 tape_cleanup_device(device);
621 break;
622 default:
623 /*
624 * There may be requests on the queue. We will not get
625 * an interrupt for a request that was running. So we
626 * just post them all as I/O errors.
627 */
628 DBF_EVENT(3, "(%08x): Drive in use vanished!\n",
629 device->cdev_id);
630 PRINT_WARN("(%s): Drive in use vanished - "
631 "expect trouble!\n",
632 device->cdev->dev.bus_id);
633 PRINT_WARN("State was %i\n", device->tape_state);
634 tape_state_set(device, TS_NOT_OPER);
635 __tape_discard_requests(device);
636 spin_unlock_irq(get_ccwdev_lock(device->cdev));
637 tape_cleanup_device(device);
638 }
639
640 if (cdev->dev.driver_data != NULL) {
641 sysfs_remove_group(&cdev->dev.kobj, &tape_attr_group);
642 cdev->dev.driver_data = tape_put_device(cdev->dev.driver_data);
643 }
644}
645
646/*
647 * Allocate a new tape ccw request
648 */
649struct tape_request *
650tape_alloc_request(int cplength, int datasize)
651{
652 struct tape_request *request;
653
654 if (datasize > PAGE_SIZE || (cplength*sizeof(struct ccw1)) > PAGE_SIZE)
655 BUG();
656
657 DBF_LH(6, "tape_alloc_request(%d, %d)\n", cplength, datasize);
658
Eric Sesterhenn88abaab2006-03-24 03:15:31 -0800659 request = kzalloc(sizeof(struct tape_request), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 if (request == NULL) {
661 DBF_EXCEPTION(1, "cqra nomem\n");
662 return ERR_PTR(-ENOMEM);
663 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 /* allocate channel program */
665 if (cplength > 0) {
Eric Sesterhenn88abaab2006-03-24 03:15:31 -0800666 request->cpaddr = kcalloc(cplength, sizeof(struct ccw1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 GFP_ATOMIC | GFP_DMA);
668 if (request->cpaddr == NULL) {
669 DBF_EXCEPTION(1, "cqra nomem\n");
670 kfree(request);
671 return ERR_PTR(-ENOMEM);
672 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 }
674 /* alloc small kernel buffer */
675 if (datasize > 0) {
Eric Sesterhenn88abaab2006-03-24 03:15:31 -0800676 request->cpdata = kzalloc(datasize, GFP_KERNEL | GFP_DMA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 if (request->cpdata == NULL) {
678 DBF_EXCEPTION(1, "cqra nomem\n");
Jesper Juhl17fd6822005-11-07 01:01:30 -0800679 kfree(request->cpaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 kfree(request);
681 return ERR_PTR(-ENOMEM);
682 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 }
684 DBF_LH(6, "New request %p(%p/%p)\n", request, request->cpaddr,
685 request->cpdata);
686
687 return request;
688}
689
690/*
691 * Free tape ccw request
692 */
693void
694tape_free_request (struct tape_request * request)
695{
696 DBF_LH(6, "Free request %p\n", request);
697
698 if (request->device != NULL) {
699 request->device = tape_put_device(request->device);
700 }
Jesper Juhl17fd6822005-11-07 01:01:30 -0800701 kfree(request->cpdata);
702 kfree(request->cpaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 kfree(request);
704}
705
Stefan Bader41117962005-07-27 11:45:04 -0700706static inline int
707__tape_start_io(struct tape_device *device, struct tape_request *request)
708{
709 int rc;
710
711#ifdef CONFIG_S390_TAPE_BLOCK
712 if (request->op == TO_BLOCK)
713 device->discipline->check_locate(device, request);
714#endif
715 rc = ccw_device_start(
716 device->cdev,
717 request->cpaddr,
718 (unsigned long) request,
719 0x00,
720 request->options
721 );
722 if (rc == 0) {
723 request->status = TAPE_REQUEST_IN_IO;
724 } else if (rc == -EBUSY) {
725 /* The common I/O subsystem is currently busy. Retry later. */
726 request->status = TAPE_REQUEST_QUEUED;
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100727 schedule_delayed_work(&device->tape_dnr, 0);
Stefan Bader41117962005-07-27 11:45:04 -0700728 rc = 0;
729 } else {
730 /* Start failed. Remove request and indicate failure. */
731 DBF_EVENT(1, "tape: start request failed with RC = %i\n", rc);
732 }
733 return rc;
734}
735
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736static inline void
Stefan Bader41117962005-07-27 11:45:04 -0700737__tape_start_next_request(struct tape_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738{
739 struct list_head *l, *n;
740 struct tape_request *request;
741 int rc;
742
Stefan Bader41117962005-07-27 11:45:04 -0700743 DBF_LH(6, "__tape_start_next_request(%p)\n", device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 /*
745 * Try to start each request on request queue until one is
746 * started successful.
747 */
748 list_for_each_safe(l, n, &device->req_queue) {
749 request = list_entry(l, struct tape_request, list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
Stefan Bader41117962005-07-27 11:45:04 -0700751 /*
752 * Avoid race condition if bottom-half was triggered more than
753 * once.
754 */
755 if (request->status == TAPE_REQUEST_IN_IO)
756 return;
Michael Holzheu5f384332006-03-24 03:15:28 -0800757 /*
758 * Request has already been stopped. We have to wait until
759 * the request is removed from the queue in the interrupt
760 * handling.
761 */
762 if (request->status == TAPE_REQUEST_DONE)
763 return;
Stefan Bader41117962005-07-27 11:45:04 -0700764
765 /*
766 * We wanted to cancel the request but the common I/O layer
767 * was busy at that time. This can only happen if this
768 * function is called by delayed_next_request.
769 * Otherwise we start the next request on the queue.
770 */
771 if (request->status == TAPE_REQUEST_CANCEL) {
772 rc = __tape_cancel_io(device, request);
773 } else {
774 rc = __tape_start_io(device, request);
775 }
776 if (rc == 0)
777 return;
778
779 /* Set ending status. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 request->rc = rc;
781 request->status = TAPE_REQUEST_DONE;
Stefan Bader41117962005-07-27 11:45:04 -0700782
783 /* Remove from request queue. */
784 list_del(&request->list);
785
786 /* Do callback. */
787 if (request->callback != NULL)
788 request->callback(request, request->callback_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 }
790}
791
792static void
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100793tape_delayed_next_request(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794{
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100795 struct tape_device *device =
796 container_of(work, struct tape_device, tape_dnr.work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
Stefan Bader41117962005-07-27 11:45:04 -0700798 DBF_LH(6, "tape_delayed_next_request(%p)\n", device);
799 spin_lock_irq(get_ccwdev_lock(device->cdev));
800 __tape_start_next_request(device);
801 spin_unlock_irq(get_ccwdev_lock(device->cdev));
802}
803
804static inline void
805__tape_end_request(
806 struct tape_device * device,
807 struct tape_request * request,
808 int rc)
809{
810 DBF_LH(6, "__tape_end_request(%p, %p, %i)\n", device, request, rc);
811 if (request) {
812 request->rc = rc;
813 request->status = TAPE_REQUEST_DONE;
814
815 /* Remove from request queue. */
816 list_del(&request->list);
817
818 /* Do callback. */
819 if (request->callback != NULL)
820 request->callback(request, request->callback_data);
821 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
823 /* Start next request. */
824 if (!list_empty(&device->req_queue))
Stefan Bader41117962005-07-27 11:45:04 -0700825 __tape_start_next_request(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826}
827
828/*
829 * Write sense data to console/dbf
830 */
831void
832tape_dump_sense(struct tape_device* device, struct tape_request *request,
833 struct irb *irb)
834{
835 unsigned int *sptr;
836
837 PRINT_INFO("-------------------------------------------------\n");
838 PRINT_INFO("DSTAT : %02x CSTAT: %02x CPA: %04x\n",
839 irb->scsw.dstat, irb->scsw.cstat, irb->scsw.cpa);
840 PRINT_INFO("DEVICE: %s\n", device->cdev->dev.bus_id);
841 if (request != NULL)
842 PRINT_INFO("OP : %s\n", tape_op_verbose[request->op]);
843
844 sptr = (unsigned int *) irb->ecw;
845 PRINT_INFO("Sense data: %08X %08X %08X %08X \n",
846 sptr[0], sptr[1], sptr[2], sptr[3]);
847 PRINT_INFO("Sense data: %08X %08X %08X %08X \n",
848 sptr[4], sptr[5], sptr[6], sptr[7]);
849 PRINT_INFO("--------------------------------------------------\n");
850}
851
852/*
853 * Write sense data to dbf
854 */
855void
856tape_dump_sense_dbf(struct tape_device *device, struct tape_request *request,
857 struct irb *irb)
858{
859 unsigned int *sptr;
860 const char* op;
861
862 if (request != NULL)
863 op = tape_op_verbose[request->op];
864 else
865 op = "---";
866 DBF_EVENT(3, "DSTAT : %02x CSTAT: %02x\n",
867 irb->scsw.dstat,irb->scsw.cstat);
868 DBF_EVENT(3, "DEVICE: %08x OP\t: %s\n", device->cdev_id, op);
869 sptr = (unsigned int *) irb->ecw;
870 DBF_EVENT(3, "%08x %08x\n", sptr[0], sptr[1]);
871 DBF_EVENT(3, "%08x %08x\n", sptr[2], sptr[3]);
872 DBF_EVENT(3, "%08x %08x\n", sptr[4], sptr[5]);
873 DBF_EVENT(3, "%08x %08x\n", sptr[6], sptr[7]);
874}
875
876/*
877 * I/O helper function. Adds the request to the request queue
878 * and starts it if the tape is idle. Has to be called with
879 * the device lock held.
880 */
881static inline int
Stefan Bader41117962005-07-27 11:45:04 -0700882__tape_start_request(struct tape_device *device, struct tape_request *request)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883{
884 int rc;
885
886 switch (request->op) {
887 case TO_MSEN:
888 case TO_ASSIGN:
889 case TO_UNASSIGN:
890 case TO_READ_ATTMSG:
891 if (device->tape_state == TS_INIT)
892 break;
893 if (device->tape_state == TS_UNUSED)
894 break;
895 default:
896 if (device->tape_state == TS_BLKUSE)
897 break;
898 if (device->tape_state != TS_IN_USE)
899 return -ENODEV;
900 }
901
902 /* Increase use count of device for the added request. */
903 request->device = tape_get_device_reference(device);
904
905 if (list_empty(&device->req_queue)) {
906 /* No other requests are on the queue. Start this one. */
Stefan Bader41117962005-07-27 11:45:04 -0700907 rc = __tape_start_io(device, request);
908 if (rc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 return rc;
Stefan Bader41117962005-07-27 11:45:04 -0700910
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 DBF_LH(5, "Request %p added for execution.\n", request);
912 list_add(&request->list, &device->req_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 } else {
914 DBF_LH(5, "Request %p add to queue.\n", request);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 request->status = TAPE_REQUEST_QUEUED;
Stefan Bader41117962005-07-27 11:45:04 -0700916 list_add_tail(&request->list, &device->req_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 }
918 return 0;
919}
920
921/*
922 * Add the request to the request queue, try to start it if the
923 * tape is idle. Return without waiting for end of i/o.
924 */
925int
926tape_do_io_async(struct tape_device *device, struct tape_request *request)
927{
928 int rc;
929
930 DBF_LH(6, "tape_do_io_async(%p, %p)\n", device, request);
931
932 spin_lock_irq(get_ccwdev_lock(device->cdev));
933 /* Add request to request queue and try to start it. */
Stefan Bader41117962005-07-27 11:45:04 -0700934 rc = __tape_start_request(device, request);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 spin_unlock_irq(get_ccwdev_lock(device->cdev));
936 return rc;
937}
938
939/*
940 * tape_do_io/__tape_wake_up
941 * Add the request to the request queue, try to start it if the
942 * tape is idle and wait uninterruptible for its completion.
943 */
944static void
945__tape_wake_up(struct tape_request *request, void *data)
946{
947 request->callback = NULL;
948 wake_up((wait_queue_head_t *) data);
949}
950
951int
952tape_do_io(struct tape_device *device, struct tape_request *request)
953{
954 wait_queue_head_t wq;
955 int rc;
956
957 init_waitqueue_head(&wq);
958 spin_lock_irq(get_ccwdev_lock(device->cdev));
959 /* Setup callback */
960 request->callback = __tape_wake_up;
961 request->callback_data = &wq;
962 /* Add request to request queue and try to start it. */
Stefan Bader41117962005-07-27 11:45:04 -0700963 rc = __tape_start_request(device, request);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 spin_unlock_irq(get_ccwdev_lock(device->cdev));
965 if (rc)
966 return rc;
967 /* Request added to the queue. Wait for its completion. */
968 wait_event(wq, (request->callback == NULL));
969 /* Get rc from request */
970 return request->rc;
971}
972
973/*
974 * tape_do_io_interruptible/__tape_wake_up_interruptible
975 * Add the request to the request queue, try to start it if the
976 * tape is idle and wait uninterruptible for its completion.
977 */
978static void
979__tape_wake_up_interruptible(struct tape_request *request, void *data)
980{
981 request->callback = NULL;
982 wake_up_interruptible((wait_queue_head_t *) data);
983}
984
985int
986tape_do_io_interruptible(struct tape_device *device,
987 struct tape_request *request)
988{
989 wait_queue_head_t wq;
990 int rc;
991
992 init_waitqueue_head(&wq);
993 spin_lock_irq(get_ccwdev_lock(device->cdev));
994 /* Setup callback */
995 request->callback = __tape_wake_up_interruptible;
996 request->callback_data = &wq;
Stefan Bader41117962005-07-27 11:45:04 -0700997 rc = __tape_start_request(device, request);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 spin_unlock_irq(get_ccwdev_lock(device->cdev));
999 if (rc)
1000 return rc;
1001 /* Request added to the queue. Wait for its completion. */
1002 rc = wait_event_interruptible(wq, (request->callback == NULL));
1003 if (rc != -ERESTARTSYS)
1004 /* Request finished normally. */
1005 return request->rc;
Stefan Bader41117962005-07-27 11:45:04 -07001006
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 /* Interrupted by a signal. We have to stop the current request. */
1008 spin_lock_irq(get_ccwdev_lock(device->cdev));
Stefan Bader41117962005-07-27 11:45:04 -07001009 rc = __tape_cancel_io(device, request);
1010 spin_unlock_irq(get_ccwdev_lock(device->cdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 if (rc == 0) {
Stefan Bader41117962005-07-27 11:45:04 -07001012 /* Wait for the interrupt that acknowledges the halt. */
1013 do {
1014 rc = wait_event_interruptible(
1015 wq,
1016 (request->callback == NULL)
1017 );
Michael Holzheu4cd190a2006-03-24 03:15:27 -08001018 } while (rc == -ERESTARTSYS);
Stefan Bader41117962005-07-27 11:45:04 -07001019
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 DBF_EVENT(3, "IO stopped on %08x\n", device->cdev_id);
1021 rc = -ERESTARTSYS;
1022 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 return rc;
1024}
1025
1026/*
Michael Holzheu5f384332006-03-24 03:15:28 -08001027 * Stop running ccw.
1028 */
1029int
1030tape_cancel_io(struct tape_device *device, struct tape_request *request)
1031{
1032 int rc;
1033
1034 spin_lock_irq(get_ccwdev_lock(device->cdev));
1035 rc = __tape_cancel_io(device, request);
1036 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1037 return rc;
1038}
1039
1040/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 * Tape interrupt routine, called from the ccw_device layer
1042 */
1043static void
1044__tape_do_irq (struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
1045{
1046 struct tape_device *device;
1047 struct tape_request *request;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 int rc;
1049
1050 device = (struct tape_device *) cdev->dev.driver_data;
1051 if (device == NULL) {
1052 PRINT_ERR("could not get device structure for %s "
1053 "in interrupt\n", cdev->dev.bus_id);
1054 return;
1055 }
1056 request = (struct tape_request *) intparm;
1057
1058 DBF_LH(6, "__tape_do_irq(device=%p, request=%p)\n", device, request);
1059
1060 /* On special conditions irb is an error pointer */
1061 if (IS_ERR(irb)) {
Stefan Bader41117962005-07-27 11:45:04 -07001062 /* FIXME: What to do with the request? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 switch (PTR_ERR(irb)) {
1064 case -ETIMEDOUT:
1065 PRINT_WARN("(%s): Request timed out\n",
1066 cdev->dev.bus_id);
1067 case -EIO:
Stefan Bader41117962005-07-27 11:45:04 -07001068 __tape_end_request(device, request, -EIO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 break;
1070 default:
1071 PRINT_ERR("(%s): Unexpected i/o error %li\n",
1072 cdev->dev.bus_id,
1073 PTR_ERR(irb));
1074 }
1075 return;
1076 }
1077
Stefan Bader41117962005-07-27 11:45:04 -07001078 /*
1079 * If the condition code is not zero and the start function bit is
1080 * still set, this is an deferred error and the last start I/O did
Stefan Bader842d3fb2006-03-24 03:15:26 -08001081 * not succeed. At this point the condition that caused the deferred
1082 * error might still apply. So we just schedule the request to be
1083 * started later.
Stefan Bader41117962005-07-27 11:45:04 -07001084 */
Michael Holzheu5f384332006-03-24 03:15:28 -08001085 if (irb->scsw.cc != 0 && (irb->scsw.fctl & SCSW_FCTL_START_FUNC) &&
1086 (request->status == TAPE_REQUEST_IN_IO)) {
1087 DBF_EVENT(3,"(%08x): deferred cc=%i, fctl=%i. restarting\n",
1088 device->cdev_id, irb->scsw.cc, irb->scsw.fctl);
Stefan Bader842d3fb2006-03-24 03:15:26 -08001089 request->status = TAPE_REQUEST_QUEUED;
Michael Holzheu5f384332006-03-24 03:15:28 -08001090 schedule_delayed_work(&device->tape_dnr, HZ);
Stefan Bader41117962005-07-27 11:45:04 -07001091 return;
1092 }
1093
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 /* May be an unsolicited irq */
1095 if(request != NULL)
1096 request->rescnt = irb->scsw.count;
1097
1098 if (irb->scsw.dstat != 0x0c) {
1099 /* Set the 'ONLINE' flag depending on sense byte 1 */
1100 if(*(((__u8 *) irb->ecw) + 1) & SENSE_DRIVE_ONLINE)
1101 device->tape_generic_status |= GMT_ONLINE(~0);
1102 else
1103 device->tape_generic_status &= ~GMT_ONLINE(~0);
1104
1105 /*
1106 * Any request that does not come back with channel end
1107 * and device end is unusual. Log the sense data.
1108 */
1109 DBF_EVENT(3,"-- Tape Interrupthandler --\n");
1110 tape_dump_sense_dbf(device, request, irb);
1111 } else {
1112 /* Upon normal completion the device _is_ online */
1113 device->tape_generic_status |= GMT_ONLINE(~0);
1114 }
1115 if (device->tape_state == TS_NOT_OPER) {
1116 DBF_EVENT(6, "tape:device is not operational\n");
1117 return;
1118 }
1119
1120 /*
1121 * Request that were canceled still come back with an interrupt.
1122 * To detect these request the state will be set to TAPE_REQUEST_DONE.
1123 */
1124 if(request != NULL && request->status == TAPE_REQUEST_DONE) {
Stefan Bader41117962005-07-27 11:45:04 -07001125 __tape_end_request(device, request, -EIO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 return;
1127 }
1128
1129 rc = device->discipline->irq(device, request, irb);
1130 /*
1131 * rc < 0 : request finished unsuccessfully.
1132 * rc == TAPE_IO_SUCCESS: request finished successfully.
1133 * rc == TAPE_IO_PENDING: request is still running. Ignore rc.
1134 * rc == TAPE_IO_RETRY: request finished but needs another go.
1135 * rc == TAPE_IO_STOP: request needs to get terminated.
1136 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 switch (rc) {
Stefan Bader41117962005-07-27 11:45:04 -07001138 case TAPE_IO_SUCCESS:
1139 /* Upon normal completion the device _is_ online */
1140 device->tape_generic_status |= GMT_ONLINE(~0);
1141 __tape_end_request(device, request, rc);
1142 break;
1143 case TAPE_IO_PENDING:
1144 break;
1145 case TAPE_IO_RETRY:
1146 rc = __tape_start_io(device, request);
1147 if (rc)
1148 __tape_end_request(device, request, rc);
1149 break;
1150 case TAPE_IO_STOP:
1151 rc = __tape_cancel_io(device, request);
1152 if (rc)
1153 __tape_end_request(device, request, rc);
1154 break;
1155 default:
1156 if (rc > 0) {
1157 DBF_EVENT(6, "xunknownrc\n");
1158 PRINT_ERR("Invalid return code from discipline "
1159 "interrupt function.\n");
1160 __tape_end_request(device, request, -EIO);
1161 } else {
1162 __tape_end_request(device, request, rc);
1163 }
1164 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 }
1166}
1167
1168/*
1169 * Tape device open function used by tape_char & tape_block frontends.
1170 */
1171int
1172tape_open(struct tape_device *device)
1173{
1174 int rc;
1175
1176 spin_lock(get_ccwdev_lock(device->cdev));
1177 if (device->tape_state == TS_NOT_OPER) {
1178 DBF_EVENT(6, "TAPE:nodev\n");
1179 rc = -ENODEV;
1180 } else if (device->tape_state == TS_IN_USE) {
1181 DBF_EVENT(6, "TAPE:dbusy\n");
1182 rc = -EBUSY;
1183 } else if (device->tape_state == TS_BLKUSE) {
1184 DBF_EVENT(6, "TAPE:dbusy\n");
1185 rc = -EBUSY;
1186 } else if (device->discipline != NULL &&
1187 !try_module_get(device->discipline->owner)) {
1188 DBF_EVENT(6, "TAPE:nodisc\n");
1189 rc = -ENODEV;
1190 } else {
1191 tape_state_set(device, TS_IN_USE);
1192 rc = 0;
1193 }
1194 spin_unlock(get_ccwdev_lock(device->cdev));
1195 return rc;
1196}
1197
1198/*
1199 * Tape device release function used by tape_char & tape_block frontends.
1200 */
1201int
1202tape_release(struct tape_device *device)
1203{
1204 spin_lock(get_ccwdev_lock(device->cdev));
1205 if (device->tape_state == TS_IN_USE)
1206 tape_state_set(device, TS_UNUSED);
1207 module_put(device->discipline->owner);
1208 spin_unlock(get_ccwdev_lock(device->cdev));
1209 return 0;
1210}
1211
1212/*
1213 * Execute a magnetic tape command a number of times.
1214 */
1215int
1216tape_mtop(struct tape_device *device, int mt_op, int mt_count)
1217{
1218 tape_mtop_fn fn;
1219 int rc;
1220
1221 DBF_EVENT(6, "TAPE:mtio\n");
1222 DBF_EVENT(6, "TAPE:ioop: %x\n", mt_op);
1223 DBF_EVENT(6, "TAPE:arg: %x\n", mt_count);
1224
1225 if (mt_op < 0 || mt_op >= TAPE_NR_MTOPS)
1226 return -EINVAL;
1227 fn = device->discipline->mtop_array[mt_op];
1228 if (fn == NULL)
1229 return -EINVAL;
1230
1231 /* We assume that the backends can handle count up to 500. */
1232 if (mt_op == MTBSR || mt_op == MTFSR || mt_op == MTFSF ||
1233 mt_op == MTBSF || mt_op == MTFSFM || mt_op == MTBSFM) {
1234 rc = 0;
1235 for (; mt_count > 500; mt_count -= 500)
1236 if ((rc = fn(device, 500)) != 0)
1237 break;
1238 if (rc == 0)
1239 rc = fn(device, mt_count);
1240 } else
1241 rc = fn(device, mt_count);
1242 return rc;
1243
1244}
1245
1246/*
1247 * Tape init function.
1248 */
1249static int
1250tape_init (void)
1251{
Michael Holzheu66a464d2005-06-25 14:55:33 -07001252 TAPE_DBF_AREA = debug_register ( "tape", 2, 2, 4*sizeof(long));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 debug_register_view(TAPE_DBF_AREA, &debug_sprintf_view);
1254#ifdef DBF_LIKE_HELL
1255 debug_set_level(TAPE_DBF_AREA, 6);
1256#endif
Heiko Carstense018ba12006-02-01 03:06:31 -08001257 DBF_EVENT(3, "tape init\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 tape_proc_init();
1259 tapechar_init ();
1260 tapeblock_init ();
1261 return 0;
1262}
1263
1264/*
1265 * Tape exit function.
1266 */
1267static void
1268tape_exit(void)
1269{
1270 DBF_EVENT(6, "tape exit\n");
1271
1272 /* Get rid of the frontends */
1273 tapechar_exit();
1274 tapeblock_exit();
1275 tape_proc_cleanup();
1276 debug_unregister (TAPE_DBF_AREA);
1277}
1278
1279MODULE_AUTHOR("(C) 2001 IBM Deutschland Entwicklung GmbH by Carsten Otte and "
1280 "Michael Holzheu (cotte@de.ibm.com,holzheu@de.ibm.com)");
Heiko Carstense018ba12006-02-01 03:06:31 -08001281MODULE_DESCRIPTION("Linux on zSeries channel attached tape device driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282MODULE_LICENSE("GPL");
1283
1284module_init(tape_init);
1285module_exit(tape_exit);
1286
1287EXPORT_SYMBOL(tape_generic_remove);
1288EXPORT_SYMBOL(tape_generic_probe);
1289EXPORT_SYMBOL(tape_generic_online);
1290EXPORT_SYMBOL(tape_generic_offline);
1291EXPORT_SYMBOL(tape_put_device);
1292EXPORT_SYMBOL(tape_get_device_reference);
1293EXPORT_SYMBOL(tape_state_verbose);
1294EXPORT_SYMBOL(tape_op_verbose);
1295EXPORT_SYMBOL(tape_state_set);
1296EXPORT_SYMBOL(tape_med_state_set);
1297EXPORT_SYMBOL(tape_alloc_request);
1298EXPORT_SYMBOL(tape_free_request);
1299EXPORT_SYMBOL(tape_dump_sense);
1300EXPORT_SYMBOL(tape_dump_sense_dbf);
1301EXPORT_SYMBOL(tape_do_io);
1302EXPORT_SYMBOL(tape_do_io_async);
1303EXPORT_SYMBOL(tape_do_io_interruptible);
Michael Holzheu5f384332006-03-24 03:15:28 -08001304EXPORT_SYMBOL(tape_cancel_io);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305EXPORT_SYMBOL(tape_mtop);