Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^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)  * linux/drivers/scsi/scsi_proc.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * The functions in this file provide an interface between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * the PROC file system and the SCSI device drivers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * It is mainly used for debugging, statistics and to pass 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * information directly to the lowlevel driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * (c) 1995 Michael Neuffer neuffer@goofy.zdv.uni-mainz.de 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * Version: 0.99.8   last change: 95/09/13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * generic command parser provided by: 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * Andreas Heilwagen <crashcar@informatik.uni-koblenz.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * generic_proc_info() support of xxxx_info() by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * Michael A. Griffith <grif@acm.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <scsi/scsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <scsi/scsi_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <scsi/scsi_transport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include "scsi_priv.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include "scsi_logging.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) /* 4K page size, but our output routines, use some slack for overruns */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define PROC_BLOCK_SIZE (3*1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) static struct proc_dir_entry *proc_scsi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) /* Protect sht->present and sht->proc_dir */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) static DEFINE_MUTEX(global_host_template_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static ssize_t proc_scsi_host_write(struct file *file, const char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)                            size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	struct Scsi_Host *shost = PDE_DATA(file_inode(file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	ssize_t ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	char *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (count > PROC_BLOCK_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		return -EOVERFLOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	if (!shost->hostt->write_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	page = (char *)__get_free_page(GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	if (page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		if (copy_from_user(page, buf, count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		ret = shost->hostt->write_info(shost, page, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	free_page((unsigned long)page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) static int proc_scsi_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	struct Scsi_Host *shost = m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	return shost->hostt->show_info(m, shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) static int proc_scsi_host_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	return single_open_size(file, proc_scsi_show, PDE_DATA(inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 				4 * PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) static const struct proc_ops proc_scsi_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	.proc_open	= proc_scsi_host_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	.proc_release	= single_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	.proc_read	= seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	.proc_lseek	= seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	.proc_write	= proc_scsi_host_write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  * scsi_proc_hostdir_add - Create directory in /proc for a scsi host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  * @sht: owner of this directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  * Sets sht->proc_dir to the new directory.
^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) void scsi_proc_hostdir_add(struct scsi_host_template *sht)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	if (!sht->show_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	mutex_lock(&global_host_template_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	if (!sht->present++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		sht->proc_dir = proc_mkdir(sht->proc_name, proc_scsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)         	if (!sht->proc_dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			printk(KERN_ERR "%s: proc_mkdir failed for %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			       __func__, sht->proc_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	mutex_unlock(&global_host_template_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)  * scsi_proc_hostdir_rm - remove directory in /proc for a scsi host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  * @sht: owner of directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) void scsi_proc_hostdir_rm(struct scsi_host_template *sht)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	if (!sht->show_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	mutex_lock(&global_host_template_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	if (!--sht->present && sht->proc_dir) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		remove_proc_entry(sht->proc_name, proc_scsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		sht->proc_dir = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	mutex_unlock(&global_host_template_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  * scsi_proc_host_add - Add entry for this host to appropriate /proc dir
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  * @shost: host to add
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) void scsi_proc_host_add(struct Scsi_Host *shost)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	struct scsi_host_template *sht = shost->hostt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	struct proc_dir_entry *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	char name[10];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	if (!sht->proc_dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	sprintf(name,"%d", shost->host_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	p = proc_create_data(name, S_IRUGO | S_IWUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		sht->proc_dir, &proc_scsi_ops, shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		printk(KERN_ERR "%s: Failed to register host %d in"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		       "%s\n", __func__, shost->host_no,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		       sht->proc_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)  * scsi_proc_host_rm - remove this host's entry from /proc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)  * @shost: which host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) void scsi_proc_host_rm(struct Scsi_Host *shost)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	char name[10];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	if (!shost->hostt->proc_dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	sprintf(name,"%d", shost->host_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	remove_proc_entry(name, shost->hostt->proc_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)  * proc_print_scsidevice - return data about this host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)  * @dev: A scsi device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)  * @data: &struct seq_file to output to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)  * Description: prints Host, Channel, Id, Lun, Vendor, Model, Rev, Type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)  * and revision.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static int proc_print_scsidevice(struct device *dev, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	struct scsi_device *sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	struct seq_file *s = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if (!scsi_is_sdev_device(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	sdev = to_scsi_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	seq_printf(s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		"Host: scsi%d Channel: %02d Id: %02d Lun: %02llu\n  Vendor: ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		sdev->host->host_no, sdev->channel, sdev->id, sdev->lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	for (i = 0; i < 8; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		if (sdev->vendor[i] >= 0x20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			seq_putc(s, sdev->vendor[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			seq_putc(s, ' ');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	seq_puts(s, " Model: ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	for (i = 0; i < 16; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		if (sdev->model[i] >= 0x20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 			seq_putc(s, sdev->model[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			seq_putc(s, ' ');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	seq_puts(s, " Rev: ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	for (i = 0; i < 4; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		if (sdev->rev[i] >= 0x20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 			seq_putc(s, sdev->rev[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			seq_putc(s, ' ');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	seq_putc(s, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	seq_printf(s, "  Type:   %s ", scsi_device_type(sdev->type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	seq_printf(s, "               ANSI  SCSI revision: %02x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			sdev->scsi_level - (sdev->scsi_level > 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	if (sdev->scsi_level == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		seq_puts(s, " CCS\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		seq_putc(s, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)  * scsi_add_single_device - Respond to user request to probe for/add device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)  * @host: user-supplied decimal integer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)  * @channel: user-supplied decimal integer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)  * @id: user-supplied decimal integer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  * @lun: user-supplied decimal integer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  * Description: called by writing "scsi add-single-device" to /proc/scsi/scsi.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)  * does scsi_host_lookup() and either user_scan() if that transport
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)  * type supports it, or else scsi_scan_host_selected()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)  * Note: this seems to be aimed exclusively at SCSI parallel busses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) static int scsi_add_single_device(uint host, uint channel, uint id, uint lun)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	struct Scsi_Host *shost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	int error = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	shost = scsi_host_lookup(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	if (!shost)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	if (shost->transportt->user_scan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		error = shost->transportt->user_scan(shost, channel, id, lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		error = scsi_scan_host_selected(shost, channel, id, lun,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 						SCSI_SCAN_MANUAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	scsi_host_put(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)  * scsi_remove_single_device - Respond to user request to remove a device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)  * @host: user-supplied decimal integer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)  * @channel: user-supplied decimal integer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)  * @id: user-supplied decimal integer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)  * @lun: user-supplied decimal integer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)  * Description: called by writing "scsi remove-single-device" to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)  * /proc/scsi/scsi.  Does a scsi_device_lookup() and scsi_remove_device()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) static int scsi_remove_single_device(uint host, uint channel, uint id, uint lun)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	struct scsi_device *sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	struct Scsi_Host *shost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	int error = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	shost = scsi_host_lookup(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	if (!shost)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	sdev = scsi_device_lookup(shost, channel, id, lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	if (sdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		scsi_remove_device(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		scsi_device_put(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	scsi_host_put(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)  * proc_scsi_write - handle writes to /proc/scsi/scsi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)  * @file: not used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)  * @buf: buffer to write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)  * @length: length of buf, at most PAGE_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)  * @ppos: not used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)  * Description: this provides a legacy mechanism to add or remove devices by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)  * Host, Channel, ID, and Lun.  To use,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)  * "echo 'scsi add-single-device 0 1 2 3' > /proc/scsi/scsi" or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)  * "echo 'scsi remove-single-device 0 1 2 3' > /proc/scsi/scsi" with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)  * "0 1 2 3" replaced by the Host, Channel, Id, and Lun.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)  * Note: this seems to be aimed at parallel SCSI. Most modern busses (USB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)  * SATA, Firewire, Fibre Channel, etc) dynamically assign these values to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)  * provide a unique identifier and nothing more.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) static ssize_t proc_scsi_write(struct file *file, const char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 			       size_t length, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	int host, channel, id, lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	char *buffer, *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	if (!buf || length > PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	buffer = (char *)__get_free_page(GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	if (!buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	if (copy_from_user(buffer, buf, length))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	if (length < PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		buffer[length] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	else if (buffer[PAGE_SIZE-1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	 * Usage: echo "scsi add-single-device 0 1 2 3" >/proc/scsi/scsi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	 * with  "0 1 2 3" replaced by your "Host Channel Id Lun".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	if (!strncmp("scsi add-single-device", buffer, 22)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		p = buffer + 23;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		host = simple_strtoul(p, &p, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		channel = simple_strtoul(p + 1, &p, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		id = simple_strtoul(p + 1, &p, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		lun = simple_strtoul(p + 1, &p, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		err = scsi_add_single_device(host, channel, id, lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	 * Usage: echo "scsi remove-single-device 0 1 2 3" >/proc/scsi/scsi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	 * with  "0 1 2 3" replaced by your "Host Channel Id Lun".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	} else if (!strncmp("scsi remove-single-device", buffer, 25)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		p = buffer + 26;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		host = simple_strtoul(p, &p, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		channel = simple_strtoul(p + 1, &p, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		id = simple_strtoul(p + 1, &p, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		lun = simple_strtoul(p + 1, &p, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		err = scsi_remove_single_device(host, channel, id, lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	 * convert success returns so that we return the 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	 * number of bytes consumed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		err = length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	free_page((unsigned long)buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) static inline struct device *next_scsi_device(struct device *start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	struct device *next = bus_find_next_device(&scsi_bus_type, start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	put_device(start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	return next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) static void *scsi_seq_start(struct seq_file *sfile, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	struct device *dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	loff_t n = *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	while ((dev = next_scsi_device(dev))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		if (!n--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 		sfile->private++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	return dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) static void *scsi_seq_next(struct seq_file *sfile, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	(*pos)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	sfile->private++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	return next_scsi_device(v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) static void scsi_seq_stop(struct seq_file *sfile, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	put_device(v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) static int scsi_seq_show(struct seq_file *sfile, void *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	if (!sfile->private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		seq_puts(sfile, "Attached devices:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	return proc_print_scsidevice(dev, sfile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) static const struct seq_operations scsi_seq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	.start	= scsi_seq_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	.next	= scsi_seq_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	.stop	= scsi_seq_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	.show	= scsi_seq_show
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)  * proc_scsi_open - glue function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)  * @inode: not used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)  * @file: passed to single_open()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)  * Associates proc_scsi_show with this file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) static int proc_scsi_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	 * We don't really need this for the write case but it doesn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	 * harm either.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	return seq_open(file, &scsi_seq_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) static const struct proc_ops scsi_scsi_proc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	.proc_open	= proc_scsi_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	.proc_read	= seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	.proc_write	= proc_scsi_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	.proc_lseek	= seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	.proc_release	= seq_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)  * scsi_init_procfs - create scsi and scsi/scsi in procfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) int __init scsi_init_procfs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	struct proc_dir_entry *pde;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	proc_scsi = proc_mkdir("scsi", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	if (!proc_scsi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		goto err1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	pde = proc_create("scsi/scsi", 0, NULL, &scsi_scsi_proc_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	if (!pde)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		goto err2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) err2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	remove_proc_entry("scsi", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) err1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)  * scsi_exit_procfs - Remove scsi/scsi and scsi from procfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) void scsi_exit_procfs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	remove_proc_entry("scsi/scsi", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	remove_proc_entry("scsi", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) }