diff options
author | Tejun Heo <htejun@gmail.com> | 2007-04-17 10:44:07 -0400 |
---|---|---|
committer | Jeff Garzik <jeff@garzik.org> | 2007-04-28 14:16:03 -0400 |
commit | f31871951b38daf2d7ca17daad59fdb735062da3 (patch) | |
tree | 4286402eaf679b6fb73e893d8e51bb693559091d /drivers/ata/libata-scsi.c | |
parent | ecef7253235e7a9365afe08a508e11bed91c1c11 (diff) |
libata: separate out ata_host_alloc() and ata_host_register()
Reorganize ata_host_alloc() and its subroutines into the following
three functions.
* ata_host_alloc() : allocates host and its ports. shost is not
registered automatically.
* ata_scsi_add_hosts() : allocates and adds shosts associated with an
ATA host. Used by ata_host_register().
* ata_host_register() : takes a fully initialized ata_host structure
and registers it to libata layer and probes it.
Only ata_host_alloc() and ata_host_register() are exported.
ata_device_add() is rewritten using the above functions. This patch
does not introduce any observable behavior change. Things worth
mentioning.
* print_id is assigned at registration time and LLDs are allowed to
overallocate ports and reduce host->n_ports during initialization.
ata_host_register() will throw away unused ports automatically.
* All SCSI host initialization stuff now resides in
ata_scsi_add_hosts() in libata-scsi.c, where it should be.
* ipr is now the only user of ata_host_init(). Either kill it by
converting ipr to use ata_host_alloc() and friends or rename and
move it to libata-scsi.c
Signed-off-by: Tejun Heo <htejun@gmail.com>
Signed-off-by: Jeff Garzik <jeff@garzik.org>
Diffstat (limited to 'drivers/ata/libata-scsi.c')
-rw-r--r-- | drivers/ata/libata-scsi.c | 68 |
1 files changed, 56 insertions, 12 deletions
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 563ef0bfb038..9afba2ba489e 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c | |||
@@ -104,7 +104,7 @@ static const u8 def_control_mpage[CONTROL_MPAGE_LEN] = { | |||
104 | * libata transport template. libata doesn't do real transport stuff. | 104 | * libata transport template. libata doesn't do real transport stuff. |
105 | * It just needs the eh_timed_out hook. | 105 | * It just needs the eh_timed_out hook. |
106 | */ | 106 | */ |
107 | struct scsi_transport_template ata_scsi_transport_template = { | 107 | static struct scsi_transport_template ata_scsi_transport_template = { |
108 | .eh_strategy_handler = ata_scsi_error, | 108 | .eh_strategy_handler = ata_scsi_error, |
109 | .eh_timed_out = ata_scsi_timed_out, | 109 | .eh_timed_out = ata_scsi_timed_out, |
110 | .user_scan = ata_scsi_user_scan, | 110 | .user_scan = ata_scsi_user_scan, |
@@ -2961,6 +2961,48 @@ void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd, | |||
2961 | } | 2961 | } |
2962 | } | 2962 | } |
2963 | 2963 | ||
2964 | int ata_scsi_add_hosts(struct ata_host *host, struct scsi_host_template *sht) | ||
2965 | { | ||
2966 | int i, rc; | ||
2967 | |||
2968 | for (i = 0; i < host->n_ports; i++) { | ||
2969 | struct ata_port *ap = host->ports[i]; | ||
2970 | struct Scsi_Host *shost; | ||
2971 | |||
2972 | rc = -ENOMEM; | ||
2973 | shost = scsi_host_alloc(sht, sizeof(struct ata_port *)); | ||
2974 | if (!shost) | ||
2975 | goto err_alloc; | ||
2976 | |||
2977 | *(struct ata_port **)&shost->hostdata[0] = ap; | ||
2978 | ap->scsi_host = shost; | ||
2979 | |||
2980 | shost->transportt = &ata_scsi_transport_template; | ||
2981 | shost->unique_id = ap->print_id; | ||
2982 | shost->max_id = 16; | ||
2983 | shost->max_lun = 1; | ||
2984 | shost->max_channel = 1; | ||
2985 | shost->max_cmd_len = 16; | ||
2986 | |||
2987 | rc = scsi_add_host(ap->scsi_host, ap->host->dev); | ||
2988 | if (rc) | ||
2989 | goto err_add; | ||
2990 | } | ||
2991 | |||
2992 | return 0; | ||
2993 | |||
2994 | err_add: | ||
2995 | scsi_host_put(host->ports[i]->scsi_host); | ||
2996 | err_alloc: | ||
2997 | while (--i >= 0) { | ||
2998 | struct Scsi_Host *shost = host->ports[i]->scsi_host; | ||
2999 | |||
3000 | scsi_remove_host(shost); | ||
3001 | scsi_host_put(shost); | ||
3002 | } | ||
3003 | return rc; | ||
3004 | } | ||
3005 | |||
2964 | void ata_scsi_scan_host(struct ata_port *ap) | 3006 | void ata_scsi_scan_host(struct ata_port *ap) |
2965 | { | 3007 | { |
2966 | unsigned int i; | 3008 | unsigned int i; |
@@ -3237,21 +3279,21 @@ struct ata_port *ata_sas_port_alloc(struct ata_host *host, | |||
3237 | struct ata_port_info *port_info, | 3279 | struct ata_port_info *port_info, |
3238 | struct Scsi_Host *shost) | 3280 | struct Scsi_Host *shost) |
3239 | { | 3281 | { |
3240 | struct ata_port *ap = kzalloc(sizeof(*ap), GFP_KERNEL); | 3282 | struct ata_port *ap; |
3241 | struct ata_probe_ent *ent; | ||
3242 | 3283 | ||
3284 | ap = ata_port_alloc(host); | ||
3243 | if (!ap) | 3285 | if (!ap) |
3244 | return NULL; | 3286 | return NULL; |
3245 | 3287 | ||
3246 | ent = ata_probe_ent_alloc(host->dev, port_info); | 3288 | ap->port_no = 0; |
3247 | if (!ent) { | ||
3248 | kfree(ap); | ||
3249 | return NULL; | ||
3250 | } | ||
3251 | |||
3252 | ata_port_init(ap, host, ent, 0); | ||
3253 | ap->lock = shost->host_lock; | 3289 | ap->lock = shost->host_lock; |
3254 | devm_kfree(host->dev, ent); | 3290 | ap->pio_mask = port_info->pio_mask; |
3291 | ap->mwdma_mask = port_info->mwdma_mask; | ||
3292 | ap->udma_mask = port_info->udma_mask; | ||
3293 | ap->flags |= port_info->flags; | ||
3294 | ap->ops = port_info->port_ops; | ||
3295 | ap->cbl = ATA_CBL_SATA; | ||
3296 | |||
3255 | return ap; | 3297 | return ap; |
3256 | } | 3298 | } |
3257 | EXPORT_SYMBOL_GPL(ata_sas_port_alloc); | 3299 | EXPORT_SYMBOL_GPL(ata_sas_port_alloc); |
@@ -3307,8 +3349,10 @@ int ata_sas_port_init(struct ata_port *ap) | |||
3307 | { | 3349 | { |
3308 | int rc = ap->ops->port_start(ap); | 3350 | int rc = ap->ops->port_start(ap); |
3309 | 3351 | ||
3310 | if (!rc) | 3352 | if (!rc) { |
3353 | ap->print_id = ata_print_id++; | ||
3311 | rc = ata_bus_probe(ap); | 3354 | rc = ata_bus_probe(ap); |
3355 | } | ||
3312 | 3356 | ||
3313 | return rc; | 3357 | return rc; |
3314 | } | 3358 | } |