aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/scsi_transport_sas.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/scsi_transport_sas.c')
-rw-r--r--drivers/scsi/scsi_transport_sas.c67
1 files changed, 9 insertions, 58 deletions
diff --git a/drivers/scsi/scsi_transport_sas.c b/drivers/scsi/scsi_transport_sas.c
index 134c44c8538a..8b6d65e21bae 100644
--- a/drivers/scsi/scsi_transport_sas.c
+++ b/drivers/scsi/scsi_transport_sas.c
@@ -35,40 +35,7 @@
35#include <scsi/scsi_transport.h> 35#include <scsi/scsi_transport.h>
36#include <scsi/scsi_transport_sas.h> 36#include <scsi/scsi_transport_sas.h>
37 37
38 38#include "scsi_sas_internal.h"
39#define SAS_HOST_ATTRS 0
40#define SAS_PORT_ATTRS 17
41#define SAS_RPORT_ATTRS 7
42#define SAS_END_DEV_ATTRS 3
43#define SAS_EXPANDER_ATTRS 7
44
45struct sas_internal {
46 struct scsi_transport_template t;
47 struct sas_function_template *f;
48
49 struct class_device_attribute private_host_attrs[SAS_HOST_ATTRS];
50 struct class_device_attribute private_phy_attrs[SAS_PORT_ATTRS];
51 struct class_device_attribute private_rphy_attrs[SAS_RPORT_ATTRS];
52 struct class_device_attribute private_end_dev_attrs[SAS_END_DEV_ATTRS];
53 struct class_device_attribute private_expander_attrs[SAS_EXPANDER_ATTRS];
54
55 struct transport_container phy_attr_cont;
56 struct transport_container rphy_attr_cont;
57 struct transport_container end_dev_attr_cont;
58 struct transport_container expander_attr_cont;
59
60 /*
61 * The array of null terminated pointers to attributes
62 * needed by scsi_sysfs.c
63 */
64 struct class_device_attribute *host_attrs[SAS_HOST_ATTRS + 1];
65 struct class_device_attribute *phy_attrs[SAS_PORT_ATTRS + 1];
66 struct class_device_attribute *rphy_attrs[SAS_RPORT_ATTRS + 1];
67 struct class_device_attribute *end_dev_attrs[SAS_END_DEV_ATTRS + 1];
68 struct class_device_attribute *expander_attrs[SAS_EXPANDER_ATTRS + 1];
69};
70#define to_sas_internal(tmpl) container_of(tmpl, struct sas_internal, t)
71
72struct sas_host_attrs { 39struct sas_host_attrs {
73 struct list_head rphy_list; 40 struct list_head rphy_list;
74 struct mutex lock; 41 struct mutex lock;
@@ -406,8 +373,6 @@ struct sas_phy *sas_phy_alloc(struct device *parent, int number)
406 if (!phy) 373 if (!phy)
407 return NULL; 374 return NULL;
408 375
409 get_device(parent);
410
411 phy->number = number; 376 phy->number = number;
412 377
413 device_initialize(&phy->dev); 378 device_initialize(&phy->dev);
@@ -459,10 +424,7 @@ EXPORT_SYMBOL(sas_phy_add);
459void sas_phy_free(struct sas_phy *phy) 424void sas_phy_free(struct sas_phy *phy)
460{ 425{
461 transport_destroy_device(&phy->dev); 426 transport_destroy_device(&phy->dev);
462 put_device(phy->dev.parent); 427 put_device(&phy->dev);
463 put_device(phy->dev.parent);
464 put_device(phy->dev.parent);
465 kfree(phy);
466} 428}
467EXPORT_SYMBOL(sas_phy_free); 429EXPORT_SYMBOL(sas_phy_free);
468 430
@@ -484,7 +446,7 @@ sas_phy_delete(struct sas_phy *phy)
484 transport_remove_device(dev); 446 transport_remove_device(dev);
485 device_del(dev); 447 device_del(dev);
486 transport_destroy_device(dev); 448 transport_destroy_device(dev);
487 put_device(dev->parent); 449 put_device(dev);
488} 450}
489EXPORT_SYMBOL(sas_phy_delete); 451EXPORT_SYMBOL(sas_phy_delete);
490 452
@@ -800,7 +762,6 @@ struct sas_rphy *sas_end_device_alloc(struct sas_phy *parent)
800 762
801 rdev = kzalloc(sizeof(*rdev), GFP_KERNEL); 763 rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
802 if (!rdev) { 764 if (!rdev) {
803 put_device(&parent->dev);
804 return NULL; 765 return NULL;
805 } 766 }
806 767
@@ -836,7 +797,6 @@ struct sas_rphy *sas_expander_alloc(struct sas_phy *parent,
836 797
837 rdev = kzalloc(sizeof(*rdev), GFP_KERNEL); 798 rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
838 if (!rdev) { 799 if (!rdev) {
839 put_device(&parent->dev);
840 return NULL; 800 return NULL;
841 } 801 }
842 802
@@ -885,6 +845,8 @@ int sas_rphy_add(struct sas_rphy *rphy)
885 (identify->target_port_protocols & 845 (identify->target_port_protocols &
886 (SAS_PROTOCOL_SSP|SAS_PROTOCOL_STP|SAS_PROTOCOL_SATA))) 846 (SAS_PROTOCOL_SSP|SAS_PROTOCOL_STP|SAS_PROTOCOL_SATA)))
887 rphy->scsi_target_id = sas_host->next_target_id++; 847 rphy->scsi_target_id = sas_host->next_target_id++;
848 else if (identify->device_type == SAS_END_DEVICE)
849 rphy->scsi_target_id = -1;
888 mutex_unlock(&sas_host->lock); 850 mutex_unlock(&sas_host->lock);
889 851
890 if (identify->device_type == SAS_END_DEVICE && 852 if (identify->device_type == SAS_END_DEVICE &&
@@ -910,6 +872,7 @@ EXPORT_SYMBOL(sas_rphy_add);
910 */ 872 */
911void sas_rphy_free(struct sas_rphy *rphy) 873void sas_rphy_free(struct sas_rphy *rphy)
912{ 874{
875 struct device *dev = &rphy->dev;
913 struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent); 876 struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent);
914 struct sas_host_attrs *sas_host = to_sas_host_attrs(shost); 877 struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
915 878
@@ -917,21 +880,9 @@ void sas_rphy_free(struct sas_rphy *rphy)
917 list_del(&rphy->list); 880 list_del(&rphy->list);
918 mutex_unlock(&sas_host->lock); 881 mutex_unlock(&sas_host->lock);
919 882
920 transport_destroy_device(&rphy->dev); 883 transport_destroy_device(dev);
921 put_device(rphy->dev.parent);
922 put_device(rphy->dev.parent);
923 put_device(rphy->dev.parent);
924 if (rphy->identify.device_type == SAS_END_DEVICE) {
925 struct sas_end_device *edev = rphy_to_end_device(rphy);
926
927 kfree(edev);
928 } else {
929 /* must be expander */
930 struct sas_expander_device *edev =
931 rphy_to_expander_device(rphy);
932 884
933 kfree(edev); 885 put_device(dev);
934 }
935} 886}
936EXPORT_SYMBOL(sas_rphy_free); 887EXPORT_SYMBOL(sas_rphy_free);
937 888
@@ -971,7 +922,7 @@ sas_rphy_delete(struct sas_rphy *rphy)
971 922
972 parent->rphy = NULL; 923 parent->rphy = NULL;
973 924
974 put_device(&parent->dev); 925 put_device(dev);
975} 926}
976EXPORT_SYMBOL(sas_rphy_delete); 927EXPORT_SYMBOL(sas_rphy_delete);
977 928