^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * tape device driver for S/390 and zSeries tapes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * S390 and zSeries version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright IBM Corp. 2001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Author(s): Carsten Otte <cotte@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Michael Holzheu <holzheu@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Tuan Ngo-Anh <ngoanh@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * PROCFS Functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #define KMSG_COMPONENT "tape"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define TAPE_DBF_AREA tape_core_dbf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include "tape.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static const char *tape_med_st_verbose[MS_SIZE] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) [MS_UNKNOWN] = "UNKNOWN ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) [MS_LOADED] = "LOADED ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) [MS_UNLOADED] = "UNLOADED"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /* our proc tapedevices entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static struct proc_dir_entry *tape_proc_devices;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * Show function for /proc/tapedevices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static int tape_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct tape_device *device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct tape_request *request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) const char *str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) unsigned long n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) n = (unsigned long) v - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) if (!n) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) seq_printf(m, "TapeNo\tBusID CuType/Model\t"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) "DevType/Model\tBlkSize\tState\tOp\tMedState\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) device = tape_find_device(n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) if (IS_ERR(device))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) spin_lock_irq(get_ccwdev_lock(device->cdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) seq_printf(m, "%d\t", (int) n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) seq_printf(m, "%-10.10s ", dev_name(&device->cdev->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) seq_printf(m, "%04X/", device->cdev->id.cu_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) seq_printf(m, "%02X\t", device->cdev->id.cu_model);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) seq_printf(m, "%04X/", device->cdev->id.dev_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) seq_printf(m, "%02X\t\t", device->cdev->id.dev_model);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) if (device->char_data.block_size == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) seq_printf(m, "auto\t");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) seq_printf(m, "%i\t", device->char_data.block_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) if (device->tape_state >= 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) device->tape_state < TS_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) str = tape_state_verbose[device->tape_state];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) str = "UNKNOWN";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) seq_printf(m, "%s\t", str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if (!list_empty(&device->req_queue)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) request = list_entry(device->req_queue.next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct tape_request, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) str = tape_op_verbose[request->op];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) str = "---";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) seq_printf(m, "%s\t", str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) seq_printf(m, "%s\n", tape_med_st_verbose[device->medium_state]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) spin_unlock_irq(get_ccwdev_lock(device->cdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) tape_put_device(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) static void *tape_proc_start(struct seq_file *m, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) if (*pos >= 256 / TAPE_MINORS_PER_DEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) return (void *)((unsigned long) *pos + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) static void *tape_proc_next(struct seq_file *m, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) ++*pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) return tape_proc_start(m, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) static void tape_proc_stop(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static const struct seq_operations tape_proc_seq = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) .start = tape_proc_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) .next = tape_proc_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) .stop = tape_proc_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) .show = tape_proc_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * Initialize procfs stuff on startup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) tape_proc_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) tape_proc_devices = proc_create_seq("tapedevices", 0444, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) &tape_proc_seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * Cleanup all stuff registered to the procfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) tape_proc_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (tape_proc_devices != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) remove_proc_entry ("tapedevices", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }