Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * tape device driver for S/390 and zSeries tapes. |
| 3 | * |
| 4 | * S390 and zSeries version |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 5 | * Copyright IBM Corp. 2001 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * Author(s): Carsten Otte <cotte@de.ibm.com> |
| 7 | * Michael Holzheu <holzheu@de.ibm.com> |
| 8 | * Tuan Ngo-Anh <ngoanh@de.ibm.com> |
| 9 | * |
| 10 | * PROCFS Functions |
| 11 | */ |
| 12 | |
Michael Holzheu | bb50991 | 2009-12-18 17:43:21 +0100 | [diff] [blame] | 13 | #define KMSG_COMPONENT "tape" |
| 14 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 15 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/module.h> |
| 17 | #include <linux/vmalloc.h> |
| 18 | #include <linux/seq_file.h> |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 19 | #include <linux/proc_fs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
| 21 | #define TAPE_DBF_AREA tape_core_dbf |
| 22 | |
| 23 | #include "tape.h" |
| 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | static const char *tape_med_st_verbose[MS_SIZE] = |
| 26 | { |
| 27 | [MS_UNKNOWN] = "UNKNOWN ", |
| 28 | [MS_LOADED] = "LOADED ", |
| 29 | [MS_UNLOADED] = "UNLOADED" |
| 30 | }; |
| 31 | |
| 32 | /* our proc tapedevices entry */ |
| 33 | static struct proc_dir_entry *tape_proc_devices; |
| 34 | |
| 35 | /* |
| 36 | * Show function for /proc/tapedevices |
| 37 | */ |
| 38 | static int tape_proc_show(struct seq_file *m, void *v) |
| 39 | { |
| 40 | struct tape_device *device; |
| 41 | struct tape_request *request; |
| 42 | const char *str; |
| 43 | unsigned long n; |
| 44 | |
| 45 | n = (unsigned long) v - 1; |
| 46 | if (!n) { |
| 47 | seq_printf(m, "TapeNo\tBusID CuType/Model\t" |
| 48 | "DevType/Model\tBlkSize\tState\tOp\tMedState\n"); |
| 49 | } |
Martin Schwidefsky | 8fd138c | 2009-12-07 12:52:03 +0100 | [diff] [blame] | 50 | device = tape_find_device(n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | if (IS_ERR(device)) |
| 52 | return 0; |
| 53 | spin_lock_irq(get_ccwdev_lock(device->cdev)); |
| 54 | seq_printf(m, "%d\t", (int) n); |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 55 | seq_printf(m, "%-10.10s ", dev_name(&device->cdev->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | seq_printf(m, "%04X/", device->cdev->id.cu_type); |
| 57 | seq_printf(m, "%02X\t", device->cdev->id.cu_model); |
| 58 | seq_printf(m, "%04X/", device->cdev->id.dev_type); |
| 59 | seq_printf(m, "%02X\t\t", device->cdev->id.dev_model); |
| 60 | if (device->char_data.block_size == 0) |
| 61 | seq_printf(m, "auto\t"); |
| 62 | else |
| 63 | seq_printf(m, "%i\t", device->char_data.block_size); |
| 64 | if (device->tape_state >= 0 && |
| 65 | device->tape_state < TS_SIZE) |
| 66 | str = tape_state_verbose[device->tape_state]; |
| 67 | else |
| 68 | str = "UNKNOWN"; |
| 69 | seq_printf(m, "%s\t", str); |
| 70 | if (!list_empty(&device->req_queue)) { |
| 71 | request = list_entry(device->req_queue.next, |
| 72 | struct tape_request, list); |
| 73 | str = tape_op_verbose[request->op]; |
| 74 | } else |
| 75 | str = "---"; |
| 76 | seq_printf(m, "%s\t", str); |
| 77 | seq_printf(m, "%s\n", tape_med_st_verbose[device->medium_state]); |
| 78 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
| 79 | tape_put_device(device); |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | static void *tape_proc_start(struct seq_file *m, loff_t *pos) |
| 84 | { |
| 85 | if (*pos >= 256 / TAPE_MINORS_PER_DEV) |
| 86 | return NULL; |
| 87 | return (void *)((unsigned long) *pos + 1); |
| 88 | } |
| 89 | |
| 90 | static void *tape_proc_next(struct seq_file *m, void *v, loff_t *pos) |
| 91 | { |
| 92 | ++*pos; |
| 93 | return tape_proc_start(m, pos); |
| 94 | } |
| 95 | |
| 96 | static void tape_proc_stop(struct seq_file *m, void *v) |
| 97 | { |
| 98 | } |
| 99 | |
Jan Engelhardt | 5c81cdb | 2008-01-26 14:11:29 +0100 | [diff] [blame] | 100 | static const struct seq_operations tape_proc_seq = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | .start = tape_proc_start, |
| 102 | .next = tape_proc_next, |
| 103 | .stop = tape_proc_stop, |
| 104 | .show = tape_proc_show, |
| 105 | }; |
| 106 | |
| 107 | static int tape_proc_open(struct inode *inode, struct file *file) |
| 108 | { |
| 109 | return seq_open(file, &tape_proc_seq); |
| 110 | } |
| 111 | |
Arjan van de Ven | d54b1fd | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 112 | static const struct file_operations tape_proc_ops = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | { |
Denis V. Lunev | 8b59400 | 2008-04-29 01:02:20 -0700 | [diff] [blame] | 114 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | .open = tape_proc_open, |
| 116 | .read = seq_read, |
| 117 | .llseek = seq_lseek, |
| 118 | .release = seq_release, |
| 119 | }; |
| 120 | |
| 121 | /* |
| 122 | * Initialize procfs stuff on startup |
| 123 | */ |
| 124 | void |
| 125 | tape_proc_init(void) |
| 126 | { |
| 127 | tape_proc_devices = |
Denis V. Lunev | 8b59400 | 2008-04-29 01:02:20 -0700 | [diff] [blame] | 128 | proc_create("tapedevices", S_IFREG | S_IRUGO | S_IWUSR, NULL, |
| 129 | &tape_proc_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | if (tape_proc_devices == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | return; |
| 132 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | /* |
| 136 | * Cleanup all stuff registered to the procfs |
| 137 | */ |
| 138 | void |
| 139 | tape_proc_cleanup(void) |
| 140 | { |
| 141 | if (tape_proc_devices != NULL) |
Alexey Dobriyan | c74c120 | 2008-04-29 01:01:44 -0700 | [diff] [blame] | 142 | remove_proc_entry ("tapedevices", NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | } |