Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  *    tape device driver for S/390 and zSeries tapes.
0004  *
0005  *  S390 and zSeries version
0006  *    Copyright IBM Corp. 2001
0007  *    Author(s): Carsten Otte <cotte@de.ibm.com>
0008  *       Michael Holzheu <holzheu@de.ibm.com>
0009  *       Tuan Ngo-Anh <ngoanh@de.ibm.com>
0010  *
0011  * PROCFS Functions
0012  */
0013 
0014 #define KMSG_COMPONENT "tape"
0015 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
0016 
0017 #include <linux/module.h>
0018 #include <linux/vmalloc.h>
0019 #include <linux/seq_file.h>
0020 #include <linux/proc_fs.h>
0021 
0022 #define TAPE_DBF_AREA   tape_core_dbf
0023 
0024 #include "tape.h"
0025 
0026 static const char *tape_med_st_verbose[MS_SIZE] =
0027 {
0028     [MS_UNKNOWN] = "UNKNOWN ",
0029     [MS_LOADED] = "LOADED  ",
0030     [MS_UNLOADED] = "UNLOADED"
0031 };
0032 
0033 /* our proc tapedevices entry */
0034 static struct proc_dir_entry *tape_proc_devices;
0035 
0036 /*
0037  * Show function for /proc/tapedevices
0038  */
0039 static int tape_proc_show(struct seq_file *m, void *v)
0040 {
0041     struct tape_device *device;
0042     struct tape_request *request;
0043     const char *str;
0044     unsigned long n;
0045 
0046     n = (unsigned long) v - 1;
0047     if (!n) {
0048         seq_printf(m, "TapeNo\tBusID      CuType/Model\t"
0049             "DevType/Model\tBlkSize\tState\tOp\tMedState\n");
0050     }
0051     device = tape_find_device(n);
0052     if (IS_ERR(device))
0053         return 0;
0054     spin_lock_irq(get_ccwdev_lock(device->cdev));
0055     seq_printf(m, "%d\t", (int) n);
0056     seq_printf(m, "%-10.10s ", dev_name(&device->cdev->dev));
0057     seq_printf(m, "%04X/", device->cdev->id.cu_type);
0058     seq_printf(m, "%02X\t", device->cdev->id.cu_model);
0059     seq_printf(m, "%04X/", device->cdev->id.dev_type);
0060     seq_printf(m, "%02X\t\t", device->cdev->id.dev_model);
0061     if (device->char_data.block_size == 0)
0062         seq_printf(m, "auto\t");
0063     else
0064         seq_printf(m, "%i\t", device->char_data.block_size);
0065     if (device->tape_state >= 0 &&
0066         device->tape_state < TS_SIZE)
0067         str = tape_state_verbose[device->tape_state];
0068     else
0069         str = "UNKNOWN";
0070     seq_printf(m, "%s\t", str);
0071     if (!list_empty(&device->req_queue)) {
0072         request = list_entry(device->req_queue.next,
0073                      struct tape_request, list);
0074         str = tape_op_verbose[request->op];
0075     } else
0076         str = "---";
0077     seq_printf(m, "%s\t", str);
0078     seq_printf(m, "%s\n", tape_med_st_verbose[device->medium_state]);
0079     spin_unlock_irq(get_ccwdev_lock(device->cdev));
0080     tape_put_device(device);
0081         return 0;
0082 }
0083 
0084 static void *tape_proc_start(struct seq_file *m, loff_t *pos)
0085 {
0086     if (*pos >= 256 / TAPE_MINORS_PER_DEV)
0087         return NULL;
0088     return (void *)((unsigned long) *pos + 1);
0089 }
0090 
0091 static void *tape_proc_next(struct seq_file *m, void *v, loff_t *pos)
0092 {
0093     ++*pos;
0094     return tape_proc_start(m, pos);
0095 }
0096 
0097 static void tape_proc_stop(struct seq_file *m, void *v)
0098 {
0099 }
0100 
0101 static const struct seq_operations tape_proc_seq = {
0102     .start      = tape_proc_start,
0103     .next       = tape_proc_next,
0104     .stop       = tape_proc_stop,
0105     .show       = tape_proc_show,
0106 };
0107 
0108 /*
0109  * Initialize procfs stuff on startup
0110  */
0111 void
0112 tape_proc_init(void)
0113 {
0114     tape_proc_devices = proc_create_seq("tapedevices", 0444, NULL,
0115                         &tape_proc_seq);
0116 }
0117 
0118 /*
0119  * Cleanup all stuff registered to the procfs
0120  */
0121 void
0122 tape_proc_cleanup(void)
0123 {
0124     if (tape_proc_devices != NULL)
0125         remove_proc_entry ("tapedevices", NULL);
0126 }