Commit b0ed4336 authored by Hannes Reinecke's avatar Hannes Reinecke Committed by James Bottomley

[SCSI] add scsi_host and scsi_target to scsi_bus

This patch implements scsi_host and scsi_target device types
and adds both to the scsi_bus.
Signed-off-by: default avatarHannes Reinecke <hare@suse.de>
Signed-off-by: default avatarKay Sievers <kay.sievers@vrfy.org>
Signed-off-by: default avatarJames Bottomley <James.Bottomley@HansenPartnership.com>
parent cb6b7f40
...@@ -284,6 +284,11 @@ static void scsi_host_dev_release(struct device *dev) ...@@ -284,6 +284,11 @@ static void scsi_host_dev_release(struct device *dev)
kfree(shost); kfree(shost);
} }
struct device_type scsi_host_type = {
.name = "scsi_host",
.release = scsi_host_dev_release,
};
/** /**
* scsi_host_alloc - register a scsi host adapter instance. * scsi_host_alloc - register a scsi host adapter instance.
* @sht: pointer to scsi host template * @sht: pointer to scsi host template
...@@ -383,7 +388,10 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize) ...@@ -383,7 +388,10 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
device_initialize(&shost->shost_gendev); device_initialize(&shost->shost_gendev);
snprintf(shost->shost_gendev.bus_id, BUS_ID_SIZE, "host%d", snprintf(shost->shost_gendev.bus_id, BUS_ID_SIZE, "host%d",
shost->host_no); shost->host_no);
shost->shost_gendev.release = scsi_host_dev_release; #ifndef CONFIG_SYSFS_DEPRECATED
shost->shost_gendev.bus = &scsi_bus_type;
#endif
shost->shost_gendev.type = &scsi_host_type;
device_initialize(&shost->shost_dev); device_initialize(&shost->shost_dev);
shost->shost_dev.parent = &shost->shost_gendev; shost->shost_dev.parent = &shost->shost_gendev;
...@@ -496,7 +504,7 @@ void scsi_exit_hosts(void) ...@@ -496,7 +504,7 @@ void scsi_exit_hosts(void)
int scsi_is_host_device(const struct device *dev) int scsi_is_host_device(const struct device *dev)
{ {
return dev->release == scsi_host_dev_release; return dev->type == &scsi_host_type;
} }
EXPORT_SYMBOL(scsi_is_host_device); EXPORT_SYMBOL(scsi_is_host_device);
......
...@@ -190,10 +190,14 @@ void scsi_proc_host_rm(struct Scsi_Host *shost) ...@@ -190,10 +190,14 @@ void scsi_proc_host_rm(struct Scsi_Host *shost)
*/ */
static int proc_print_scsidevice(struct device *dev, void *data) static int proc_print_scsidevice(struct device *dev, void *data)
{ {
struct scsi_device *sdev = to_scsi_device(dev); struct scsi_device *sdev;
struct seq_file *s = data; struct seq_file *s = data;
int i; int i;
if (!scsi_is_sdev_device(dev))
goto out;
sdev = to_scsi_device(dev);
seq_printf(s, seq_printf(s,
"Host: scsi%d Channel: %02d Id: %02d Lun: %02d\n Vendor: ", "Host: scsi%d Channel: %02d Id: %02d Lun: %02d\n Vendor: ",
sdev->host->host_no, sdev->channel, sdev->id, sdev->lun); sdev->host->host_no, sdev->channel, sdev->id, sdev->lun);
...@@ -230,6 +234,7 @@ static int proc_print_scsidevice(struct device *dev, void *data) ...@@ -230,6 +234,7 @@ static int proc_print_scsidevice(struct device *dev, void *data)
else else
seq_printf(s, "\n"); seq_printf(s, "\n");
out:
return 0; return 0;
} }
......
...@@ -331,9 +331,14 @@ static void scsi_target_dev_release(struct device *dev) ...@@ -331,9 +331,14 @@ static void scsi_target_dev_release(struct device *dev)
put_device(parent); put_device(parent);
} }
struct device_type scsi_target_type = {
.name = "scsi_target",
.release = scsi_target_dev_release,
};
int scsi_is_target_device(const struct device *dev) int scsi_is_target_device(const struct device *dev)
{ {
return dev->release == scsi_target_dev_release; return dev->type == &scsi_target_type;
} }
EXPORT_SYMBOL(scsi_is_target_device); EXPORT_SYMBOL(scsi_is_target_device);
...@@ -391,9 +396,12 @@ static struct scsi_target *scsi_alloc_target(struct device *parent, ...@@ -391,9 +396,12 @@ static struct scsi_target *scsi_alloc_target(struct device *parent,
device_initialize(dev); device_initialize(dev);
starget->reap_ref = 1; starget->reap_ref = 1;
dev->parent = get_device(parent); dev->parent = get_device(parent);
dev->release = scsi_target_dev_release;
sprintf(dev->bus_id, "target%d:%d:%d", sprintf(dev->bus_id, "target%d:%d:%d",
shost->host_no, channel, id); shost->host_no, channel, id);
#ifndef CONFIG_SYSFS_DEPRECATED
dev->bus = &scsi_bus_type;
#endif
dev->type = &scsi_target_type;
starget->id = id; starget->id = id;
starget->channel = channel; starget->channel = channel;
INIT_LIST_HEAD(&starget->siblings); INIT_LIST_HEAD(&starget->siblings);
......
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
#include "scsi_priv.h" #include "scsi_priv.h"
#include "scsi_logging.h" #include "scsi_logging.h"
static struct device_type scsi_dev_type;
static const struct { static const struct {
enum scsi_device_state value; enum scsi_device_state value;
char *name; char *name;
...@@ -335,7 +337,12 @@ static struct class sdev_class = { ...@@ -335,7 +337,12 @@ static struct class sdev_class = {
/* all probing is done in the individual ->probe routines */ /* all probing is done in the individual ->probe routines */
static int scsi_bus_match(struct device *dev, struct device_driver *gendrv) static int scsi_bus_match(struct device *dev, struct device_driver *gendrv)
{ {
struct scsi_device *sdp = to_scsi_device(dev); struct scsi_device *sdp;
if (dev->type != &scsi_dev_type)
return 0;
sdp = to_scsi_device(dev);
if (sdp->no_uld_attach) if (sdp->no_uld_attach)
return 0; return 0;
return (sdp->inq_periph_qual == SCSI_INQ_PQ_CON)? 1: 0; return (sdp->inq_periph_qual == SCSI_INQ_PQ_CON)? 1: 0;
...@@ -351,10 +358,16 @@ static int scsi_bus_uevent(struct device *dev, struct kobj_uevent_env *env) ...@@ -351,10 +358,16 @@ static int scsi_bus_uevent(struct device *dev, struct kobj_uevent_env *env)
static int scsi_bus_suspend(struct device * dev, pm_message_t state) static int scsi_bus_suspend(struct device * dev, pm_message_t state)
{ {
struct device_driver *drv = dev->driver; struct device_driver *drv;
struct scsi_device *sdev = to_scsi_device(dev); struct scsi_device *sdev;
int err; int err;
if (dev->type != &scsi_dev_type)
return 0;
drv = dev->driver;
sdev = to_scsi_device(dev);
err = scsi_device_quiesce(sdev); err = scsi_device_quiesce(sdev);
if (err) if (err)
return err; return err;
...@@ -370,10 +383,16 @@ static int scsi_bus_suspend(struct device * dev, pm_message_t state) ...@@ -370,10 +383,16 @@ static int scsi_bus_suspend(struct device * dev, pm_message_t state)
static int scsi_bus_resume(struct device * dev) static int scsi_bus_resume(struct device * dev)
{ {
struct device_driver *drv = dev->driver; struct device_driver *drv;
struct scsi_device *sdev = to_scsi_device(dev); struct scsi_device *sdev;
int err = 0; int err = 0;
if (dev->type != &scsi_dev_type)
return 0;
drv = dev->driver;
sdev = to_scsi_device(dev);
if (drv && drv->resume) if (drv && drv->resume)
err = drv->resume(dev); err = drv->resume(dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment