Lines Matching +full:phy +full:- +full:device

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2005-2006 Dell Inc.
13 * introduces two additional intermediate objects: The SAS PHY
14 * as represented by struct sas_phy defines an "outgoing" PHY on
15 * a SAS HBA or Expander, and the SAS remote PHY represented by
16 * struct sas_rphy defines an "incoming" PHY on a SAS Expander or
17 * end device. Note that this is purely a software concept, the
18 * underlying hardware for a PHY and a remote PHY is the exactly
51 #define to_sas_host_attrs(host) ((struct sas_host_attrs *)(host)->shost_data)
100 return -EINVAL; \
126 { SAS_END_DEVICE, "end device" },
149 { SAS_PHY_DISABLED, "Phy disabled" },
151 { SAS_SATA_SPINUP_HOLD, "Spin-up hold" },
163 struct sas_rphy *rphy = target_to_rphy(sdev->sdev_target); in sas_bitfield_name_search()
166 BUG_ON(rphy->identify.device_type != SAS_END_DEVICE); in sas_bitfield_name_search()
174 struct Scsi_Host *shost = dev_to_shost(job->dev); in sas_smp_dispatch()
177 if (!scsi_is_host_device(job->dev)) in sas_smp_dispatch()
178 rphy = dev_to_rphy(job->dev); in sas_smp_dispatch()
180 if (!job->reply_payload.payload_len) { in sas_smp_dispatch()
181 dev_warn(job->dev, "space for a smp response is missing\n"); in sas_smp_dispatch()
182 bsg_job_done(job, -EINVAL, 0); in sas_smp_dispatch()
186 to_sas_internal(shost->transportt)->f->smp_handler(job, shost, rphy); in sas_smp_dispatch()
194 if (!to_sas_internal(shost->transportt)->f->smp_handler) { in sas_bsg_initialize()
195 printk("%s can't handle SMP requests\n", shost->hostt->name); in sas_bsg_initialize()
200 q = bsg_setup_queue(&rphy->dev, dev_name(&rphy->dev), NULL, in sas_bsg_initialize()
204 rphy->q = q; in sas_bsg_initialize()
208 snprintf(name, sizeof(name), "sas_host%d", shost->host_no); in sas_bsg_initialize()
209 q = bsg_setup_queue(&shost->shost_gendev, name, NULL, in sas_bsg_initialize()
213 to_sas_host_attrs(shost)->q = q; in sas_bsg_initialize()
223 static int sas_host_setup(struct transport_container *tc, struct device *dev, in sas_host_setup()
224 struct device *cdev) in sas_host_setup()
228 struct device *dma_dev = shost->dma_dev; in sas_host_setup()
230 INIT_LIST_HEAD(&sas_host->rphy_list); in sas_host_setup()
231 mutex_init(&sas_host->lock); in sas_host_setup()
232 sas_host->next_target_id = 0; in sas_host_setup()
233 sas_host->next_expander_id = 0; in sas_host_setup()
234 sas_host->next_port_id = 0; in sas_host_setup()
237 dev_printk(KERN_ERR, dev, "fail to a bsg device %d\n", in sas_host_setup()
238 shost->host_no); in sas_host_setup()
240 if (dma_dev->dma_mask) { in sas_host_setup()
241 shost->opt_sectors = min_t(unsigned int, shost->max_sectors, in sas_host_setup()
248 static int sas_host_remove(struct transport_container *tc, struct device *dev, in sas_host_remove()
249 struct device *cdev) in sas_host_remove()
252 struct request_queue *q = to_sas_host_attrs(shost)->q; in sas_host_remove()
262 struct device *dev) in sas_host_match()
271 if (!shost->transportt) in sas_host_match()
273 if (shost->transportt->host_attrs.ac.class != in sas_host_match()
277 i = to_sas_internal(shost->transportt); in sas_host_match()
278 return &i->t.host_attrs.ac == cont; in sas_host_match()
281 static int do_sas_phy_delete(struct device *dev, void *data) in do_sas_phy_delete()
293 * sas_remove_children - tear down a devices SAS data structures
294 * @dev: device belonging to the sas object
298 void sas_remove_children(struct device *dev) in sas_remove_children()
306 * sas_remove_host - tear down a Scsi_Host's SAS data structures
317 sas_remove_children(&shost->shost_gendev); in sas_remove_host()
323 * sas_get_address - return the SAS address of the device
324 * @sdev: scsi device
326 * Returns the SAS address of the scsi device
332 return rdev->rphy.identify.sas_address; in sas_get_address()
337 * sas_tlr_supported - checking TLR bit in vpd 0x90
338 * @sdev: scsi device struct
360 * has a 4 byte header and then one entry per device port in sas_tlr_supported()
368 rdev->tlr_supported = ret; in sas_tlr_supported()
375 * sas_disable_tlr - setting TLR flags
376 * @sdev: scsi device struct
386 rdev->tlr_enabled = 0; in sas_disable_tlr()
391 * sas_enable_tlr - setting TLR flags
392 * @sdev: scsi device struct
405 rdev->tlr_enabled = 1; in sas_enable_tlr()
415 return rdev->tlr_enabled; in sas_is_tlr_enabled()
420 * sas_ata_ncq_prio_supported - Check for ATA NCQ command priority support
421 * @sdev: SCSI device
423 * Check if an ATA device supports NCQ priority using VPD page 89h (ATA
433 vpd = rcu_dereference(sdev->vpd_pg89); in sas_ata_ncq_prio_supported()
434 if (vpd && vpd->len >= 214) in sas_ata_ncq_prio_supported()
435 ncq_prio_supported = (vpd->data[213] >> 4) & 1; in sas_ata_ncq_prio_supported()
443 * SAS Phy attributes
448 show_sas_phy_##name(struct device *dev, \
451 struct sas_phy *phy = transport_class_to_phy(dev); \
453 return snprintf(buf, 20, format_string, cast phy->field); \
462 show_sas_phy_##name(struct device *dev, \
465 struct sas_phy *phy = transport_class_to_phy(dev); \
467 if (!phy->field) \
469 return get_sas_protocol_names(phy->field, buf); \
478 show_sas_phy_##field(struct device *dev, \
481 struct sas_phy *phy = transport_class_to_phy(dev); \
483 return get_sas_linkspeed_names(phy->field, buf); \
489 store_sas_phy_##field(struct device *dev, \
493 struct sas_phy *phy = transport_class_to_phy(dev); \
494 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); \
495 struct sas_internal *i = to_sas_internal(shost->transportt); \
504 error = i->f->set_phy_speed(phy, &rates); \
522 show_sas_phy_##field(struct device *dev, \
525 struct sas_phy *phy = transport_class_to_phy(dev); \
526 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); \
527 struct sas_internal *i = to_sas_internal(shost->transportt); \
530 error = i->f->get_linkerrors ? i->f->get_linkerrors(phy) : 0; \
533 return snprintf(buf, 20, "%u\n", phy->field); \
542 show_sas_device_type(struct device *dev, in show_sas_device_type()
545 struct sas_phy *phy = transport_class_to_phy(dev); in show_sas_device_type() local
547 if (!phy->identify.device_type) in show_sas_device_type()
549 return get_sas_device_type_names(phy->identify.device_type, buf); in show_sas_device_type()
553 static ssize_t do_sas_phy_enable(struct device *dev, in do_sas_phy_enable()
556 struct sas_phy *phy = transport_class_to_phy(dev); in do_sas_phy_enable() local
557 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); in do_sas_phy_enable()
558 struct sas_internal *i = to_sas_internal(shost->transportt); in do_sas_phy_enable()
561 error = i->f->phy_enable(phy, enable); in do_sas_phy_enable()
564 phy->enabled = enable; in do_sas_phy_enable()
569 store_sas_phy_enable(struct device *dev, struct device_attribute *attr, in store_sas_phy_enable()
573 return -EINVAL; in store_sas_phy_enable()
583 return -EINVAL; in store_sas_phy_enable()
590 show_sas_phy_enable(struct device *dev, struct device_attribute *attr, in show_sas_phy_enable()
593 struct sas_phy *phy = transport_class_to_phy(dev); in show_sas_phy_enable() local
595 return snprintf(buf, 20, "%d\n", phy->enabled); in show_sas_phy_enable()
602 do_sas_phy_reset(struct device *dev, size_t count, int hard_reset) in do_sas_phy_reset()
604 struct sas_phy *phy = transport_class_to_phy(dev); in do_sas_phy_reset() local
605 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); in do_sas_phy_reset()
606 struct sas_internal *i = to_sas_internal(shost->transportt); in do_sas_phy_reset()
609 error = i->f->phy_reset(phy, hard_reset); in do_sas_phy_reset()
612 phy->enabled = 1; in do_sas_phy_reset()
617 store_sas_link_reset(struct device *dev, struct device_attribute *attr, in store_sas_link_reset()
625 store_sas_hard_reset(struct device *dev, struct device_attribute *attr, in store_sas_hard_reset()
649 static int sas_phy_setup(struct transport_container *tc, struct device *dev, in sas_phy_setup()
650 struct device *cdev) in sas_phy_setup()
652 struct sas_phy *phy = dev_to_phy(dev); in sas_phy_setup() local
653 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); in sas_phy_setup()
654 struct sas_internal *i = to_sas_internal(shost->transportt); in sas_phy_setup()
656 if (i->f->phy_setup) in sas_phy_setup()
657 i->f->phy_setup(phy); in sas_phy_setup()
665 static int sas_phy_match(struct attribute_container *cont, struct device *dev) in sas_phy_match()
672 shost = dev_to_shost(dev->parent); in sas_phy_match()
674 if (!shost->transportt) in sas_phy_match()
676 if (shost->transportt->host_attrs.ac.class != in sas_phy_match()
680 i = to_sas_internal(shost->transportt); in sas_phy_match()
681 return &i->phy_attr_cont.ac == cont; in sas_phy_match()
684 static void sas_phy_release(struct device *dev) in sas_phy_release()
686 struct sas_phy *phy = dev_to_phy(dev); in sas_phy_release() local
687 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); in sas_phy_release()
688 struct sas_internal *i = to_sas_internal(shost->transportt); in sas_phy_release()
690 if (i->f->phy_release) in sas_phy_release()
691 i->f->phy_release(phy); in sas_phy_release()
692 put_device(dev->parent); in sas_phy_release()
693 kfree(phy); in sas_phy_release()
697 * sas_phy_alloc - allocates and initialize a SAS PHY structure
698 * @parent: Parent device
699 * @number: Phy index
701 * Allocates an SAS PHY structure. It will be added in the device tree
702 * below the device specified by @parent, which has to be either a Scsi_Host
706 * SAS PHY allocated or %NULL if the allocation failed.
708 struct sas_phy *sas_phy_alloc(struct device *parent, int number) in sas_phy_alloc()
711 struct sas_phy *phy; in sas_phy_alloc() local
713 phy = kzalloc(sizeof(*phy), GFP_KERNEL); in sas_phy_alloc()
714 if (!phy) in sas_phy_alloc()
717 phy->number = number; in sas_phy_alloc()
718 phy->enabled = 1; in sas_phy_alloc()
720 device_initialize(&phy->dev); in sas_phy_alloc()
721 phy->dev.parent = get_device(parent); in sas_phy_alloc()
722 phy->dev.release = sas_phy_release; in sas_phy_alloc()
723 INIT_LIST_HEAD(&phy->port_siblings); in sas_phy_alloc()
726 dev_set_name(&phy->dev, "phy-%d:%d:%d", shost->host_no, in sas_phy_alloc()
727 rphy->scsi_target_id, number); in sas_phy_alloc()
729 dev_set_name(&phy->dev, "phy-%d:%d", shost->host_no, number); in sas_phy_alloc()
731 transport_setup_device(&phy->dev); in sas_phy_alloc()
733 return phy; in sas_phy_alloc()
738 * sas_phy_add - add a SAS PHY to the device hierarchy
739 * @phy: The PHY to be added
741 * Publishes a SAS PHY to the rest of the system.
743 int sas_phy_add(struct sas_phy *phy) in sas_phy_add() argument
747 error = device_add(&phy->dev); in sas_phy_add()
751 error = transport_add_device(&phy->dev); in sas_phy_add()
753 device_del(&phy->dev); in sas_phy_add()
756 transport_configure_device(&phy->dev); in sas_phy_add()
763 * sas_phy_free - free a SAS PHY
764 * @phy: SAS PHY to free
766 * Frees the specified SAS PHY.
769 * This function must only be called on a PHY that has not
772 void sas_phy_free(struct sas_phy *phy) in sas_phy_free() argument
774 transport_destroy_device(&phy->dev); in sas_phy_free()
775 put_device(&phy->dev); in sas_phy_free()
780 * sas_phy_delete - remove SAS PHY
781 * @phy: SAS PHY to remove
783 * Removes the specified SAS PHY. If the SAS PHY has an
784 * associated remote PHY it is removed before.
787 sas_phy_delete(struct sas_phy *phy) in sas_phy_delete() argument
789 struct device *dev = &phy->dev; in sas_phy_delete()
791 /* this happens if the phy is still part of a port when deleted */ in sas_phy_delete()
792 BUG_ON(!list_empty(&phy->port_siblings)); in sas_phy_delete()
802 * scsi_is_sas_phy - check if a struct device represents a SAS PHY
803 * @dev: device to check
806 * %1 if the device represents a SAS PHY, %0 else
808 int scsi_is_sas_phy(const struct device *dev) in scsi_is_sas_phy()
810 return dev->release == sas_phy_release; in scsi_is_sas_phy()
819 show_sas_port_##name(struct device *dev, \
824 return snprintf(buf, 20, format_string, cast port->field); \
836 static int sas_port_match(struct attribute_container *cont, struct device *dev) in sas_port_match()
843 shost = dev_to_shost(dev->parent); in sas_port_match()
845 if (!shost->transportt) in sas_port_match()
847 if (shost->transportt->host_attrs.ac.class != in sas_port_match()
851 i = to_sas_internal(shost->transportt); in sas_port_match()
852 return &i->port_attr_cont.ac == cont; in sas_port_match()
856 static void sas_port_release(struct device *dev) in sas_port_release()
860 BUG_ON(!list_empty(&port->phy_list)); in sas_port_release()
862 put_device(dev->parent); in sas_port_release()
867 struct sas_phy *phy) in sas_port_create_link() argument
871 res = sysfs_create_link(&port->dev.kobj, &phy->dev.kobj, in sas_port_create_link()
872 dev_name(&phy->dev)); in sas_port_create_link()
875 res = sysfs_create_link(&phy->dev.kobj, &port->dev.kobj, "port"); in sas_port_create_link()
885 struct sas_phy *phy) in sas_port_delete_link() argument
887 sysfs_remove_link(&port->dev.kobj, dev_name(&phy->dev)); in sas_port_delete_link()
888 sysfs_remove_link(&phy->dev.kobj, "port"); in sas_port_delete_link()
891 /** sas_port_alloc - allocate and initialize a SAS port structure
893 * @parent: parent device
896 * Allocates a SAS port structure. It will be added to the device tree
897 * below the device specified by @parent which must be either a Scsi_Host
902 struct sas_port *sas_port_alloc(struct device *parent, int port_id) in sas_port_alloc()
911 port->port_identifier = port_id; in sas_port_alloc()
913 device_initialize(&port->dev); in sas_port_alloc()
915 port->dev.parent = get_device(parent); in sas_port_alloc()
916 port->dev.release = sas_port_release; in sas_port_alloc()
918 mutex_init(&port->phy_list_mutex); in sas_port_alloc()
919 INIT_LIST_HEAD(&port->phy_list); in sas_port_alloc()
923 dev_set_name(&port->dev, "port-%d:%d:%d", shost->host_no, in sas_port_alloc()
924 rphy->scsi_target_id, port->port_identifier); in sas_port_alloc()
926 dev_set_name(&port->dev, "port-%d:%d", shost->host_no, in sas_port_alloc()
927 port->port_identifier); in sas_port_alloc()
929 transport_setup_device(&port->dev); in sas_port_alloc()
935 /** sas_port_alloc_num - allocate and initialize a SAS port structure
937 * @parent: parent device
942 * the device tree below the device specified by @parent which must be
947 struct sas_port *sas_port_alloc_num(struct device *parent) in sas_port_alloc_num()
954 mutex_lock(&sas_host->lock); in sas_port_alloc_num()
959 index = exp->next_port_id++; in sas_port_alloc_num()
961 index = sas_host->next_port_id++; in sas_port_alloc_num()
962 mutex_unlock(&sas_host->lock); in sas_port_alloc_num()
968 * sas_port_add - add a SAS port to the device hierarchy
978 BUG_ON(!list_empty(&port->phy_list)); in sas_port_add()
980 error = device_add(&port->dev); in sas_port_add()
985 transport_add_device(&port->dev); in sas_port_add()
986 transport_configure_device(&port->dev); in sas_port_add()
993 * sas_port_free - free a SAS PORT
1004 transport_destroy_device(&port->dev); in sas_port_free()
1005 put_device(&port->dev); in sas_port_free()
1010 * sas_port_delete - remove SAS PORT
1018 struct device *dev = &port->dev; in sas_port_delete()
1019 struct sas_phy *phy, *tmp_phy; in sas_port_delete() local
1021 if (port->rphy) { in sas_port_delete()
1022 sas_rphy_delete(port->rphy); in sas_port_delete()
1023 port->rphy = NULL; in sas_port_delete()
1026 mutex_lock(&port->phy_list_mutex); in sas_port_delete()
1027 list_for_each_entry_safe(phy, tmp_phy, &port->phy_list, in sas_port_delete()
1029 sas_port_delete_link(port, phy); in sas_port_delete()
1030 list_del_init(&phy->port_siblings); in sas_port_delete()
1032 mutex_unlock(&port->phy_list_mutex); in sas_port_delete()
1034 if (port->is_backlink) { in sas_port_delete()
1035 struct device *parent = port->dev.parent; in sas_port_delete()
1037 sysfs_remove_link(&port->dev.kobj, dev_name(parent)); in sas_port_delete()
1038 port->is_backlink = 0; in sas_port_delete()
1049 * scsi_is_sas_port - check if a struct device represents a SAS port
1050 * @dev: device to check
1053 * %1 if the device represents a SAS Port, %0 else
1055 int scsi_is_sas_port(const struct device *dev) in scsi_is_sas_port()
1057 return dev->release == sas_port_release; in scsi_is_sas_port()
1062 * sas_port_get_phy - try to take a reference on a port member
1067 struct sas_phy *phy; in sas_port_get_phy() local
1069 mutex_lock(&port->phy_list_mutex); in sas_port_get_phy()
1070 if (list_empty(&port->phy_list)) in sas_port_get_phy()
1071 phy = NULL; in sas_port_get_phy()
1073 struct list_head *ent = port->phy_list.next; in sas_port_get_phy()
1075 phy = list_entry(ent, typeof(*phy), port_siblings); in sas_port_get_phy()
1076 get_device(&phy->dev); in sas_port_get_phy()
1078 mutex_unlock(&port->phy_list_mutex); in sas_port_get_phy()
1080 return phy; in sas_port_get_phy()
1085 * sas_port_add_phy - add another phy to a port to form a wide port
1086 * @port: port to add the phy to
1087 * @phy: phy to add
1090 * ports must have at least one phy to operated, and all wide ports
1093 * connected to a remote device is a port, so ports must be formed on
1096 void sas_port_add_phy(struct sas_port *port, struct sas_phy *phy) in sas_port_add_phy() argument
1098 mutex_lock(&port->phy_list_mutex); in sas_port_add_phy()
1099 if (unlikely(!list_empty(&phy->port_siblings))) { in sas_port_add_phy()
1103 list_for_each_entry(tmp, &port->phy_list, port_siblings) in sas_port_add_phy()
1104 if (tmp == phy) in sas_port_add_phy()
1106 /* If this trips, you added a phy that was already in sas_port_add_phy()
1108 if (unlikely(tmp != phy)) { in sas_port_add_phy()
1109 …dev_printk(KERN_ERR, &port->dev, "trying to add phy %s fails: it's already part of another port\n", in sas_port_add_phy()
1110 dev_name(&phy->dev)); in sas_port_add_phy()
1114 sas_port_create_link(port, phy); in sas_port_add_phy()
1115 list_add_tail(&phy->port_siblings, &port->phy_list); in sas_port_add_phy()
1116 port->num_phys++; in sas_port_add_phy()
1118 mutex_unlock(&port->phy_list_mutex); in sas_port_add_phy()
1123 * sas_port_delete_phy - remove a phy from a port or wide port
1124 * @port: port to remove the phy from
1125 * @phy: phy to remove
1130 void sas_port_delete_phy(struct sas_port *port, struct sas_phy *phy) in sas_port_delete_phy() argument
1132 mutex_lock(&port->phy_list_mutex); in sas_port_delete_phy()
1133 sas_port_delete_link(port, phy); in sas_port_delete_phy()
1134 list_del_init(&phy->port_siblings); in sas_port_delete_phy()
1135 port->num_phys--; in sas_port_delete_phy()
1136 mutex_unlock(&port->phy_list_mutex); in sas_port_delete_phy()
1143 struct device *parent = port->dev.parent->parent->parent; in sas_port_mark_backlink()
1145 if (port->is_backlink) in sas_port_mark_backlink()
1147 port->is_backlink = 1; in sas_port_mark_backlink()
1148 res = sysfs_create_link(&port->dev.kobj, &parent->kobj, in sas_port_mark_backlink()
1161 * SAS remote PHY attributes.
1166 show_sas_rphy_##name(struct device *dev, \
1171 return snprintf(buf, 20, format_string, cast rphy->field); \
1181 show_sas_rphy_##name(struct device *dev, \
1186 if (!rphy->field) \
1188 return get_sas_protocol_names(rphy->field, buf); \
1197 show_sas_rphy_device_type(struct device *dev, in show_sas_rphy_device_type()
1202 if (!rphy->identify.device_type) in show_sas_rphy_device_type()
1205 rphy->identify.device_type, buf); in show_sas_rphy_device_type()
1212 show_sas_rphy_enclosure_identifier(struct device *dev, in show_sas_rphy_enclosure_identifier()
1216 struct sas_phy *phy = dev_to_phy(rphy->dev.parent); in show_sas_rphy_enclosure_identifier() local
1217 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); in show_sas_rphy_enclosure_identifier()
1218 struct sas_internal *i = to_sas_internal(shost->transportt); in show_sas_rphy_enclosure_identifier()
1222 error = i->f->get_enclosure_identifier(rphy, &identifier); in show_sas_rphy_enclosure_identifier()
1232 show_sas_rphy_bay_identifier(struct device *dev, in show_sas_rphy_bay_identifier()
1236 struct sas_phy *phy = dev_to_phy(rphy->dev.parent); in show_sas_rphy_bay_identifier() local
1237 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); in show_sas_rphy_bay_identifier()
1238 struct sas_internal *i = to_sas_internal(shost->transportt); in show_sas_rphy_bay_identifier()
1241 val = i->f->get_bay_identifier(rphy); in show_sas_rphy_bay_identifier()
1269 return -ENOMEM; in sas_read_port_mode_page()
1280 if (msdata - buffer > BUF_SIZE - 8) in sas_read_port_mode_page()
1285 rdev->ready_led_meaning = msdata[2] & 0x10 ? 1 : 0; in sas_read_port_mode_page()
1286 rdev->I_T_nexus_loss_timeout = (msdata[4] << 8) + msdata[5]; in sas_read_port_mode_page()
1287 rdev->initiator_response_timeout = (msdata[6] << 8) + msdata[7]; in sas_read_port_mode_page()
1300 show_sas_end_dev_##name(struct device *dev, \
1306 return snprintf(buf, 20, format_string, cast rdev->field); \
1329 show_sas_expander_##name(struct device *dev, \
1335 return snprintf(buf, 20, format_string, cast edev->field); \
1356 static int sas_rphy_match(struct attribute_container *cont, struct device *dev) in sas_rphy_match()
1363 shost = dev_to_shost(dev->parent->parent); in sas_rphy_match()
1365 if (!shost->transportt) in sas_rphy_match()
1367 if (shost->transportt->host_attrs.ac.class != in sas_rphy_match()
1371 i = to_sas_internal(shost->transportt); in sas_rphy_match()
1372 return &i->rphy_attr_cont.ac == cont; in sas_rphy_match()
1376 struct device *dev) in sas_end_dev_match()
1384 shost = dev_to_shost(dev->parent->parent); in sas_end_dev_match()
1387 if (!shost->transportt) in sas_end_dev_match()
1389 if (shost->transportt->host_attrs.ac.class != in sas_end_dev_match()
1393 i = to_sas_internal(shost->transportt); in sas_end_dev_match()
1394 return &i->end_dev_attr_cont.ac == cont && in sas_end_dev_match()
1395 rphy->identify.device_type == SAS_END_DEVICE; in sas_end_dev_match()
1399 struct device *dev) in sas_expander_match()
1407 shost = dev_to_shost(dev->parent->parent); in sas_expander_match()
1410 if (!shost->transportt) in sas_expander_match()
1412 if (shost->transportt->host_attrs.ac.class != in sas_expander_match()
1416 i = to_sas_internal(shost->transportt); in sas_expander_match()
1417 return &i->expander_attr_cont.ac == cont && in sas_expander_match()
1418 (rphy->identify.device_type == SAS_EDGE_EXPANDER_DEVICE || in sas_expander_match()
1419 rphy->identify.device_type == SAS_FANOUT_EXPANDER_DEVICE); in sas_expander_match()
1422 static void sas_expander_release(struct device *dev) in sas_expander_release()
1427 put_device(dev->parent); in sas_expander_release()
1431 static void sas_end_device_release(struct device *dev) in sas_end_device_release()
1436 put_device(dev->parent); in sas_end_device_release()
1441 * sas_rphy_initialize - common rphy initialization
1449 INIT_LIST_HEAD(&rphy->list); in sas_rphy_initialize()
1453 * sas_end_device_alloc - allocate an rphy for an end device
1456 * Allocates an SAS remote PHY structure, connected to @parent.
1459 * SAS PHY allocated or %NULL if the allocation failed.
1463 struct Scsi_Host *shost = dev_to_shost(&parent->dev); in sas_end_device_alloc()
1471 device_initialize(&rdev->rphy.dev); in sas_end_device_alloc()
1472 rdev->rphy.dev.parent = get_device(&parent->dev); in sas_end_device_alloc()
1473 rdev->rphy.dev.release = sas_end_device_release; in sas_end_device_alloc()
1474 if (scsi_is_sas_expander_device(parent->dev.parent)) { in sas_end_device_alloc()
1475 struct sas_rphy *rphy = dev_to_rphy(parent->dev.parent); in sas_end_device_alloc()
1476 dev_set_name(&rdev->rphy.dev, "end_device-%d:%d:%d", in sas_end_device_alloc()
1477 shost->host_no, rphy->scsi_target_id, in sas_end_device_alloc()
1478 parent->port_identifier); in sas_end_device_alloc()
1480 dev_set_name(&rdev->rphy.dev, "end_device-%d:%d", in sas_end_device_alloc()
1481 shost->host_no, parent->port_identifier); in sas_end_device_alloc()
1482 rdev->rphy.identify.device_type = SAS_END_DEVICE; in sas_end_device_alloc()
1483 sas_rphy_initialize(&rdev->rphy); in sas_end_device_alloc()
1484 transport_setup_device(&rdev->rphy.dev); in sas_end_device_alloc()
1486 return &rdev->rphy; in sas_end_device_alloc()
1491 * sas_expander_alloc - allocate an rphy for an end device
1495 * Allocates an SAS remote PHY structure, connected to @parent.
1498 * SAS PHY allocated or %NULL if the allocation failed.
1503 struct Scsi_Host *shost = dev_to_shost(&parent->dev); in sas_expander_alloc()
1515 device_initialize(&rdev->rphy.dev); in sas_expander_alloc()
1516 rdev->rphy.dev.parent = get_device(&parent->dev); in sas_expander_alloc()
1517 rdev->rphy.dev.release = sas_expander_release; in sas_expander_alloc()
1518 mutex_lock(&sas_host->lock); in sas_expander_alloc()
1519 rdev->rphy.scsi_target_id = sas_host->next_expander_id++; in sas_expander_alloc()
1520 mutex_unlock(&sas_host->lock); in sas_expander_alloc()
1521 dev_set_name(&rdev->rphy.dev, "expander-%d:%d", in sas_expander_alloc()
1522 shost->host_no, rdev->rphy.scsi_target_id); in sas_expander_alloc()
1523 rdev->rphy.identify.device_type = type; in sas_expander_alloc()
1524 sas_rphy_initialize(&rdev->rphy); in sas_expander_alloc()
1525 transport_setup_device(&rdev->rphy.dev); in sas_expander_alloc()
1527 return &rdev->rphy; in sas_expander_alloc()
1532 * sas_rphy_add - add a SAS remote PHY to the device hierarchy
1533 * @rphy: The remote PHY to be added
1535 * Publishes a SAS remote PHY to the rest of the system.
1539 struct sas_port *parent = dev_to_sas_port(rphy->dev.parent); in sas_rphy_add()
1540 struct Scsi_Host *shost = dev_to_shost(parent->dev.parent); in sas_rphy_add()
1542 struct sas_identify *identify = &rphy->identify; in sas_rphy_add()
1545 if (parent->rphy) in sas_rphy_add()
1546 return -ENXIO; in sas_rphy_add()
1547 parent->rphy = rphy; in sas_rphy_add()
1549 error = device_add(&rphy->dev); in sas_rphy_add()
1552 transport_add_device(&rphy->dev); in sas_rphy_add()
1553 transport_configure_device(&rphy->dev); in sas_rphy_add()
1555 printk("fail to a bsg device %s\n", dev_name(&rphy->dev)); in sas_rphy_add()
1558 mutex_lock(&sas_host->lock); in sas_rphy_add()
1559 list_add_tail(&rphy->list, &sas_host->rphy_list); in sas_rphy_add()
1560 if (identify->device_type == SAS_END_DEVICE && in sas_rphy_add()
1561 (identify->target_port_protocols & in sas_rphy_add()
1563 rphy->scsi_target_id = sas_host->next_target_id++; in sas_rphy_add()
1564 else if (identify->device_type == SAS_END_DEVICE) in sas_rphy_add()
1565 rphy->scsi_target_id = -1; in sas_rphy_add()
1566 mutex_unlock(&sas_host->lock); in sas_rphy_add()
1568 if (identify->device_type == SAS_END_DEVICE && in sas_rphy_add()
1569 rphy->scsi_target_id != -1) { in sas_rphy_add()
1572 if (identify->target_port_protocols & SAS_PROTOCOL_SSP) in sas_rphy_add()
1577 scsi_scan_target(&rphy->dev, 0, rphy->scsi_target_id, lun, in sas_rphy_add()
1586 * sas_rphy_free - free a SAS remote PHY
1587 * @rphy: SAS remote PHY to free
1589 * Frees the specified SAS remote PHY.
1593 * PHY that has not successfully been added using
1598 struct device *dev = &rphy->dev; in sas_rphy_free()
1599 struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent); in sas_rphy_free()
1602 mutex_lock(&sas_host->lock); in sas_rphy_free()
1603 list_del(&rphy->list); in sas_rphy_free()
1604 mutex_unlock(&sas_host->lock); in sas_rphy_free()
1613 * sas_rphy_delete - remove and free SAS remote PHY
1614 * @rphy: SAS remote PHY to remove and free
1616 * Removes the specified SAS remote PHY and frees it.
1627 * sas_rphy_unlink - unlink SAS remote PHY
1628 * @rphy: SAS remote phy to unlink from its parent port
1634 struct sas_port *parent = dev_to_sas_port(rphy->dev.parent); in sas_rphy_unlink()
1636 parent->rphy = NULL; in sas_rphy_unlink()
1641 * sas_rphy_remove - remove SAS remote PHY
1642 * @rphy: SAS remote phy to remove
1644 * Removes the specified SAS remote PHY.
1649 struct device *dev = &rphy->dev; in sas_rphy_remove()
1651 switch (rphy->identify.device_type) { in sas_rphy_remove()
1664 bsg_remove_queue(rphy->q); in sas_rphy_remove()
1671 * scsi_is_sas_rphy - check if a struct device represents a SAS remote PHY
1672 * @dev: device to check
1675 * %1 if the device represents a SAS remote PHY, %0 else
1677 int scsi_is_sas_rphy(const struct device *dev) in scsi_is_sas_rphy()
1679 return dev->release == sas_end_device_release || in scsi_is_sas_rphy()
1680 dev->release == sas_expander_release; in scsi_is_sas_rphy()
1695 mutex_lock(&sas_host->lock); in sas_user_scan()
1696 list_for_each_entry(rphy, &sas_host->rphy_list, list) { in sas_user_scan()
1697 if (rphy->identify.device_type != SAS_END_DEVICE || in sas_user_scan()
1698 rphy->scsi_target_id == -1) in sas_user_scan()
1702 (id == SCAN_WILD_CARD || id == rphy->scsi_target_id)) { in sas_user_scan()
1703 scsi_scan_target(&rphy->dev, 0, rphy->scsi_target_id, in sas_user_scan()
1707 mutex_unlock(&sas_host->lock); in sas_user_scan()
1718 i->private_##attrb[count] = dev_attr_##field; \
1719 i->private_##attrb[count].attr.mode = perm; \
1720 i->attrb[count] = &i->private_##attrb[count]; \
1725 i->private_##attrb[count] = dev_attr_##field; \
1726 i->private_##attrb[count].attr.mode = perm; \
1728 i->private_##attrb[count].attr.mode = ro_perm; \
1729 i->private_##attrb[count].store = NULL; \
1731 i->attrb[count] = &i->private_##attrb[count]; \
1739 SETUP_TEMPLATE(rphy_attrs, field, S_IRUGO, i->f->func)
1746 !i->f->set_phy_speed, S_IRUGO)
1750 !i->f->func, S_IRUGO)
1756 SETUP_TEMPLATE(phy_attrs, field, S_IRUGO, i->f->func)
1762 SETUP_TEMPLATE(phy_attrs, field, S_IWUSR, i->f->func)
1771 * sas_attach_transport - instantiate SAS transport template
1784 i->t.user_scan = sas_user_scan; in sas_attach_transport()
1786 i->t.host_attrs.ac.attrs = &i->host_attrs[0]; in sas_attach_transport()
1787 i->t.host_attrs.ac.class = &sas_host_class.class; in sas_attach_transport()
1788 i->t.host_attrs.ac.match = sas_host_match; in sas_attach_transport()
1789 transport_container_register(&i->t.host_attrs); in sas_attach_transport()
1790 i->t.host_size = sizeof(struct sas_host_attrs); in sas_attach_transport()
1792 i->phy_attr_cont.ac.class = &sas_phy_class.class; in sas_attach_transport()
1793 i->phy_attr_cont.ac.attrs = &i->phy_attrs[0]; in sas_attach_transport()
1794 i->phy_attr_cont.ac.match = sas_phy_match; in sas_attach_transport()
1795 transport_container_register(&i->phy_attr_cont); in sas_attach_transport()
1797 i->port_attr_cont.ac.class = &sas_port_class.class; in sas_attach_transport()
1798 i->port_attr_cont.ac.attrs = &i->port_attrs[0]; in sas_attach_transport()
1799 i->port_attr_cont.ac.match = sas_port_match; in sas_attach_transport()
1800 transport_container_register(&i->port_attr_cont); in sas_attach_transport()
1802 i->rphy_attr_cont.ac.class = &sas_rphy_class.class; in sas_attach_transport()
1803 i->rphy_attr_cont.ac.attrs = &i->rphy_attrs[0]; in sas_attach_transport()
1804 i->rphy_attr_cont.ac.match = sas_rphy_match; in sas_attach_transport()
1805 transport_container_register(&i->rphy_attr_cont); in sas_attach_transport()
1807 i->end_dev_attr_cont.ac.class = &sas_end_dev_class.class; in sas_attach_transport()
1808 i->end_dev_attr_cont.ac.attrs = &i->end_dev_attrs[0]; in sas_attach_transport()
1809 i->end_dev_attr_cont.ac.match = sas_end_dev_match; in sas_attach_transport()
1810 transport_container_register(&i->end_dev_attr_cont); in sas_attach_transport()
1812 i->expander_attr_cont.ac.class = &sas_expander_class.class; in sas_attach_transport()
1813 i->expander_attr_cont.ac.attrs = &i->expander_attrs[0]; in sas_attach_transport()
1814 i->expander_attr_cont.ac.match = sas_expander_match; in sas_attach_transport()
1815 transport_container_register(&i->expander_attr_cont); in sas_attach_transport()
1817 i->f = ft; in sas_attach_transport()
1838 i->phy_attrs[count] = NULL; in sas_attach_transport()
1842 i->port_attrs[count] = NULL; in sas_attach_transport()
1855 i->rphy_attrs[count] = NULL; in sas_attach_transport()
1863 i->end_dev_attrs[count] = NULL; in sas_attach_transport()
1873 i->expander_attrs[count] = NULL; in sas_attach_transport()
1875 return &i->t; in sas_attach_transport()
1880 * sas_release_transport - release SAS transport template instance
1887 transport_container_unregister(&i->t.host_attrs); in sas_release_transport()
1888 transport_container_unregister(&i->phy_attr_cont); in sas_release_transport()
1889 transport_container_unregister(&i->port_attr_cont); in sas_release_transport()
1890 transport_container_unregister(&i->rphy_attr_cont); in sas_release_transport()
1891 transport_container_unregister(&i->end_dev_attr_cont); in sas_release_transport()
1892 transport_container_unregister(&i->expander_attr_cont); in sas_release_transport()