#include <scsi/scsi_transport.h>
#include <scsi/scsi_transport_sas.h>
-
-#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;
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); \
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); \
if (!phy)
return NULL;
- get_device(parent);
-
phy->number = number;
device_initialize(&phy->dev);
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);
transport_remove_device(dev);
device_del(dev);
transport_destroy_device(dev);
- put_device(dev->parent);
+ put_device(dev);
}
EXPORT_SYMBOL(sas_phy_delete);
sas_expander_simple_attr(level, level, "%d\n", int);
static DECLARE_TRANSPORT_CLASS(sas_rphy_class,
- "sas_rphy", NULL, NULL, NULL);
+ "sas_device", NULL, NULL, NULL);
static int sas_rphy_match(struct attribute_container *cont, struct device *dev)
{
i = to_sas_internal(shost->transportt);
return &i->end_dev_attr_cont.ac == cont &&
- rphy->identify.device_type == SAS_END_DEVICE &&
- /* FIXME: remove contained eventually */
- rphy->contained;
+ rphy->identify.device_type == SAS_END_DEVICE;
}
static int sas_expander_match(struct attribute_container *cont,
i = to_sas_internal(shost->transportt);
return &i->expander_attr_cont.ac == cont &&
(rphy->identify.device_type == SAS_EDGE_EXPANDER_DEVICE ||
- rphy->identify.device_type == SAS_FANOUT_EXPANDER_DEVICE) &&
- /* FIXME: remove contained eventually */
- rphy->contained;
+ rphy->identify.device_type == SAS_FANOUT_EXPANDER_DEVICE);
}
-static void sas_rphy_release(struct device *dev)
+static void sas_expander_release(struct device *dev)
{
struct sas_rphy *rphy = dev_to_rphy(dev);
+ struct sas_expander_device *edev = rphy_to_expander_device(rphy);
put_device(dev->parent);
- kfree(rphy);
+ kfree(edev);
+}
+
+static void sas_end_device_release(struct device *dev)
+{
+ struct sas_rphy *rphy = dev_to_rphy(dev);
+ struct sas_end_device *edev = rphy_to_end_device(rphy);
+
+ put_device(dev->parent);
+ kfree(edev);
}
/**
- * sas_rphy_alloc -- allocates and initialize a SAS remote PHY structure
- * @parent: SAS PHY this remote PHY is conneted to
- *
- * Allocates an SAS remote PHY structure, connected to @parent.
+ * sas_rphy_initialize - common rphy intialization
+ * @rphy: rphy to initialise
*
- * Returns:
- * SAS PHY allocated or %NULL if the allocation failed.
+ * Used by both sas_end_device_alloc() and sas_expander_alloc() to
+ * initialise the common rphy component of each.
*/
-struct sas_rphy *sas_rphy_alloc(struct sas_phy *parent)
+static void sas_rphy_initialize(struct sas_rphy *rphy)
{
- struct Scsi_Host *shost = dev_to_shost(&parent->dev);
- struct sas_rphy *rphy;
-
- rphy = kzalloc(sizeof(*rphy), GFP_KERNEL);
- if (!rphy) {
- put_device(&parent->dev);
- return NULL;
- }
-
- device_initialize(&rphy->dev);
- rphy->dev.parent = get_device(&parent->dev);
- rphy->dev.release = sas_rphy_release;
- sprintf(rphy->dev.bus_id, "rphy-%d:%d-%d",
- shost->host_no, parent->port_identifier, parent->number);
- transport_setup_device(&rphy->dev);
-
- return rphy;
+ INIT_LIST_HEAD(&rphy->list);
}
-EXPORT_SYMBOL(sas_rphy_alloc);
/**
* sas_end_device_alloc - allocate an rphy for an end device
rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
if (!rdev) {
- put_device(&parent->dev);
return NULL;
}
device_initialize(&rdev->rphy.dev);
rdev->rphy.dev.parent = get_device(&parent->dev);
- rdev->rphy.dev.release = sas_rphy_release;
- sprintf(rdev->rphy.dev.bus_id, "rphy-%d:%d-%d",
+ rdev->rphy.dev.release = sas_end_device_release;
+ 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;
- /* FIXME: mark the rphy as being contained in a larger structure */
- rdev->rphy.contained = 1;
+ sas_rphy_initialize(&rdev->rphy);
transport_setup_device(&rdev->rphy.dev);
return &rdev->rphy;
rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
if (!rdev) {
- put_device(&parent->dev);
return NULL;
}
device_initialize(&rdev->rphy.dev);
rdev->rphy.dev.parent = get_device(&parent->dev);
- rdev->rphy.dev.release = sas_rphy_release;
+ rdev->rphy.dev.release = sas_expander_release;
mutex_lock(&sas_host->lock);
rdev->rphy.scsi_target_id = sas_host->next_expander_id++;
mutex_unlock(&sas_host->lock);
sprintf(rdev->rphy.dev.bus_id, "expander-%d:%d",
shost->host_no, rdev->rphy.scsi_target_id);
rdev->rphy.identify.device_type = type;
- /* FIXME: mark the rphy as being contained in a larger structure */
- rdev->rphy.contained = 1;
+ sas_rphy_initialize(&rdev->rphy);
transport_setup_device(&rdev->rphy.dev);
return &rdev->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 &&
*/
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);
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);
- kfree(rphy);
+ transport_destroy_device(dev);
+
+ put_device(dev);
}
EXPORT_SYMBOL(sas_rphy_free);
parent->rphy = NULL;
- put_device(&parent->dev);
+ put_device(dev);
}
EXPORT_SYMBOL(sas_rphy_delete);
*/
int scsi_is_sas_rphy(const struct device *dev)
{
- return dev->release == sas_rphy_release;
+ return dev->release == sas_end_device_release ||
+ dev->release == sas_expander_release;
}
EXPORT_SYMBOL(scsi_is_sas_rphy);
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) &&
#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++