X-Git-Url: http://pilppa.org/gitweb/?a=blobdiff_plain;f=drivers%2Fscsi%2Fscsi_transport_sas.c;h=1fe6b2d01853288adbe0e9b01121a7bc25b888dd;hb=6edad161cd4dfe1df772e7a74ab63cab53b5e8c1;hp=134c44c8538a4ea372b5993abf28de0282538955;hpb=1b9a3917366028cc451a98dd22e3bcd537d4e5c1;p=linux-2.6-omap-h63xx.git diff --git a/drivers/scsi/scsi_transport_sas.c b/drivers/scsi/scsi_transport_sas.c index 134c44c8538..1fe6b2d0185 100644 --- a/drivers/scsi/scsi_transport_sas.c +++ b/drivers/scsi/scsi_transport_sas.c @@ -35,40 +35,7 @@ #include #include - -#define SAS_HOST_ATTRS 0 -#define SAS_PORT_ATTRS 17 -#define SAS_RPORT_ATTRS 7 -#define SAS_END_DEV_ATTRS 3 -#define SAS_EXPANDER_ATTRS 7 - -struct sas_internal { - struct scsi_transport_template t; - struct sas_function_template *f; - - struct class_device_attribute private_host_attrs[SAS_HOST_ATTRS]; - struct class_device_attribute private_phy_attrs[SAS_PORT_ATTRS]; - struct class_device_attribute private_rphy_attrs[SAS_RPORT_ATTRS]; - struct class_device_attribute private_end_dev_attrs[SAS_END_DEV_ATTRS]; - struct class_device_attribute private_expander_attrs[SAS_EXPANDER_ATTRS]; - - struct transport_container phy_attr_cont; - struct transport_container rphy_attr_cont; - struct transport_container end_dev_attr_cont; - struct transport_container expander_attr_cont; - - /* - * The array of null terminated pointers to attributes - * needed by scsi_sysfs.c - */ - struct class_device_attribute *host_attrs[SAS_HOST_ATTRS + 1]; - struct class_device_attribute *phy_attrs[SAS_PORT_ATTRS + 1]; - struct class_device_attribute *rphy_attrs[SAS_RPORT_ATTRS + 1]; - struct class_device_attribute *end_dev_attrs[SAS_END_DEV_ATTRS + 1]; - struct class_device_attribute *expander_attrs[SAS_EXPANDER_ATTRS + 1]; -}; -#define to_sas_internal(tmpl) container_of(tmpl, struct sas_internal, t) - +#include "scsi_sas_internal.h" struct sas_host_attrs { struct list_head rphy_list; struct mutex lock; @@ -98,7 +65,7 @@ get_sas_##title##_names(u32 table_key, char *buf) \ ssize_t len = 0; \ int i; \ \ - for (i = 0; i < sizeof(table)/sizeof(table[0]); i++) { \ + for (i = 0; i < ARRAY_SIZE(table); i++) { \ if (table[i].value & table_key) { \ len += sprintf(buf + len, "%s%s", \ prefix, table[i].name); \ @@ -116,7 +83,7 @@ get_sas_##title##_names(u32 table_key, char *buf) \ ssize_t len = 0; \ int i; \ \ - for (i = 0; i < sizeof(table)/sizeof(table[0]); i++) { \ + for (i = 0; i < ARRAY_SIZE(table); i++) { \ if (table[i].value == table_key) { \ len += sprintf(buf + len, "%s", \ table[i].name); \ @@ -406,8 +373,6 @@ struct sas_phy *sas_phy_alloc(struct device *parent, int number) if (!phy) return NULL; - get_device(parent); - phy->number = number; device_initialize(&phy->dev); @@ -459,10 +424,7 @@ EXPORT_SYMBOL(sas_phy_add); void sas_phy_free(struct sas_phy *phy) { transport_destroy_device(&phy->dev); - put_device(phy->dev.parent); - put_device(phy->dev.parent); - put_device(phy->dev.parent); - kfree(phy); + put_device(&phy->dev); } EXPORT_SYMBOL(sas_phy_free); @@ -484,7 +446,7 @@ sas_phy_delete(struct sas_phy *phy) transport_remove_device(dev); device_del(dev); transport_destroy_device(dev); - put_device(dev->parent); + put_device(dev); } EXPORT_SYMBOL(sas_phy_delete); @@ -785,6 +747,18 @@ static void sas_end_device_release(struct device *dev) kfree(edev); } +/** + * sas_rphy_initialize - common rphy intialization + * @rphy: rphy to initialise + * + * Used by both sas_end_device_alloc() and sas_expander_alloc() to + * initialise the common rphy component of each. + */ +static void sas_rphy_initialize(struct sas_rphy *rphy) +{ + INIT_LIST_HEAD(&rphy->list); +} + /** * sas_end_device_alloc - allocate an rphy for an end device * @@ -800,7 +774,6 @@ struct sas_rphy *sas_end_device_alloc(struct sas_phy *parent) rdev = kzalloc(sizeof(*rdev), GFP_KERNEL); if (!rdev) { - put_device(&parent->dev); return NULL; } @@ -810,6 +783,7 @@ struct sas_rphy *sas_end_device_alloc(struct sas_phy *parent) sprintf(rdev->rphy.dev.bus_id, "end_device-%d:%d-%d", shost->host_no, parent->port_identifier, parent->number); rdev->rphy.identify.device_type = SAS_END_DEVICE; + sas_rphy_initialize(&rdev->rphy); transport_setup_device(&rdev->rphy.dev); return &rdev->rphy; @@ -836,7 +810,6 @@ struct sas_rphy *sas_expander_alloc(struct sas_phy *parent, rdev = kzalloc(sizeof(*rdev), GFP_KERNEL); if (!rdev) { - put_device(&parent->dev); return NULL; } @@ -849,6 +822,7 @@ struct sas_rphy *sas_expander_alloc(struct sas_phy *parent, sprintf(rdev->rphy.dev.bus_id, "expander-%d:%d", shost->host_no, rdev->rphy.scsi_target_id); rdev->rphy.identify.device_type = type; + sas_rphy_initialize(&rdev->rphy); transport_setup_device(&rdev->rphy.dev); return &rdev->rphy; @@ -885,6 +859,8 @@ int sas_rphy_add(struct sas_rphy *rphy) (identify->target_port_protocols & (SAS_PROTOCOL_SSP|SAS_PROTOCOL_STP|SAS_PROTOCOL_SATA))) rphy->scsi_target_id = sas_host->next_target_id++; + else if (identify->device_type == SAS_END_DEVICE) + rphy->scsi_target_id = -1; mutex_unlock(&sas_host->lock); if (identify->device_type == SAS_END_DEVICE && @@ -910,6 +886,7 @@ EXPORT_SYMBOL(sas_rphy_add); */ void sas_rphy_free(struct sas_rphy *rphy) { + struct device *dev = &rphy->dev; struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent); struct sas_host_attrs *sas_host = to_sas_host_attrs(shost); @@ -917,21 +894,9 @@ void sas_rphy_free(struct sas_rphy *rphy) list_del(&rphy->list); mutex_unlock(&sas_host->lock); - transport_destroy_device(&rphy->dev); - put_device(rphy->dev.parent); - put_device(rphy->dev.parent); - put_device(rphy->dev.parent); - if (rphy->identify.device_type == SAS_END_DEVICE) { - struct sas_end_device *edev = rphy_to_end_device(rphy); - - kfree(edev); - } else { - /* must be expander */ - struct sas_expander_device *edev = - rphy_to_expander_device(rphy); + transport_destroy_device(dev); - kfree(edev); - } + put_device(dev); } EXPORT_SYMBOL(sas_rphy_free); @@ -971,7 +936,7 @@ sas_rphy_delete(struct sas_rphy *rphy) parent->rphy = NULL; - put_device(&parent->dev); + put_device(dev); } EXPORT_SYMBOL(sas_rphy_delete); @@ -1004,7 +969,8 @@ static int sas_user_scan(struct Scsi_Host *shost, uint channel, list_for_each_entry(rphy, &sas_host->rphy_list, list) { struct sas_phy *parent = dev_to_phy(rphy->dev.parent); - if (rphy->scsi_target_id == -1) + if (rphy->identify.device_type != SAS_END_DEVICE || + rphy->scsi_target_id == -1) continue; if ((channel == SCAN_WILD_CARD || channel == parent->port_identifier) && @@ -1026,7 +992,6 @@ static int sas_user_scan(struct Scsi_Host *shost, uint channel, #define SETUP_TEMPLATE(attrb, field, perm, test) \ i->private_##attrb[count] = class_device_attr_##field; \ i->private_##attrb[count].attr.mode = perm; \ - i->private_##attrb[count].store = NULL; \ i->attrb[count] = &i->private_##attrb[count]; \ if (test) \ count++