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()
892 * sas_port_alloc - allocate and initialize a SAS port structure
894 * @parent: parent device
897 * Allocates a SAS port structure. It will be added to the device tree
898 * below the device specified by @parent which must be either a Scsi_Host
903 struct sas_port *sas_port_alloc(struct device *parent, int port_id) in sas_port_alloc()
912 port->port_identifier = port_id; in sas_port_alloc()
914 device_initialize(&port->dev); in sas_port_alloc()
916 port->dev.parent = get_device(parent); in sas_port_alloc()
917 port->dev.release = sas_port_release; in sas_port_alloc()
919 mutex_init(&port->phy_list_mutex); in sas_port_alloc()
920 INIT_LIST_HEAD(&port->phy_list); in sas_port_alloc()
924 dev_set_name(&port->dev, "port-%d:%d:%d", shost->host_no, in sas_port_alloc()
925 rphy->scsi_target_id, port->port_identifier); in sas_port_alloc()
927 dev_set_name(&port->dev, "port-%d:%d", shost->host_no, in sas_port_alloc()
928 port->port_identifier); in sas_port_alloc()
930 transport_setup_device(&port->dev); in sas_port_alloc()
937 * sas_port_alloc_num - allocate and initialize a SAS port structure
939 * @parent: parent device
944 * the device tree below the device specified by @parent which must be
949 struct sas_port *sas_port_alloc_num(struct device *parent) in sas_port_alloc_num()
956 mutex_lock(&sas_host->lock); in sas_port_alloc_num()
961 index = exp->next_port_id++; in sas_port_alloc_num()
963 index = sas_host->next_port_id++; in sas_port_alloc_num()
964 mutex_unlock(&sas_host->lock); in sas_port_alloc_num()
970 * sas_port_add - add a SAS port to the device hierarchy
980 BUG_ON(!list_empty(&port->phy_list)); in sas_port_add()
982 error = device_add(&port->dev); in sas_port_add()
987 transport_add_device(&port->dev); in sas_port_add()
988 transport_configure_device(&port->dev); in sas_port_add()
995 * sas_port_free - free a SAS PORT
1006 transport_destroy_device(&port->dev); in sas_port_free()
1007 put_device(&port->dev); in sas_port_free()
1012 * sas_port_delete - remove SAS PORT
1020 struct device *dev = &port->dev; in sas_port_delete()
1021 struct sas_phy *phy, *tmp_phy; in sas_port_delete() local
1023 if (port->rphy) { in sas_port_delete()
1024 sas_rphy_delete(port->rphy); in sas_port_delete()
1025 port->rphy = NULL; in sas_port_delete()
1028 mutex_lock(&port->phy_list_mutex); in sas_port_delete()
1029 list_for_each_entry_safe(phy, tmp_phy, &port->phy_list, in sas_port_delete()
1031 sas_port_delete_link(port, phy); in sas_port_delete()
1032 list_del_init(&phy->port_siblings); in sas_port_delete()
1034 mutex_unlock(&port->phy_list_mutex); in sas_port_delete()
1036 if (port->is_backlink) { in sas_port_delete()
1037 struct device *parent = port->dev.parent; in sas_port_delete()
1039 sysfs_remove_link(&port->dev.kobj, dev_name(parent)); in sas_port_delete()
1040 port->is_backlink = 0; in sas_port_delete()
1051 * scsi_is_sas_port - check if a struct device represents a SAS port
1052 * @dev: device to check
1055 * %1 if the device represents a SAS Port, %0 else
1057 int scsi_is_sas_port(const struct device *dev) in scsi_is_sas_port()
1059 return dev->release == sas_port_release; in scsi_is_sas_port()
1064 * sas_port_get_phy - try to take a reference on a port member
1069 struct sas_phy *phy; in sas_port_get_phy() local
1071 mutex_lock(&port->phy_list_mutex); in sas_port_get_phy()
1072 if (list_empty(&port->phy_list)) in sas_port_get_phy()
1073 phy = NULL; in sas_port_get_phy()
1075 struct list_head *ent = port->phy_list.next; in sas_port_get_phy()
1077 phy = list_entry(ent, typeof(*phy), port_siblings); in sas_port_get_phy()
1078 get_device(&phy->dev); in sas_port_get_phy()
1080 mutex_unlock(&port->phy_list_mutex); in sas_port_get_phy()
1082 return phy; in sas_port_get_phy()
1087 * sas_port_add_phy - add another phy to a port to form a wide port
1088 * @port: port to add the phy to
1089 * @phy: phy to add
1092 * ports must have at least one phy to operated, and all wide ports
1095 * connected to a remote device is a port, so ports must be formed on
1098 void sas_port_add_phy(struct sas_port *port, struct sas_phy *phy) in sas_port_add_phy() argument
1100 mutex_lock(&port->phy_list_mutex); in sas_port_add_phy()
1101 if (unlikely(!list_empty(&phy->port_siblings))) { in sas_port_add_phy()
1105 list_for_each_entry(tmp, &port->phy_list, port_siblings) in sas_port_add_phy()
1106 if (tmp == phy) in sas_port_add_phy()
1108 /* If this trips, you added a phy that was already in sas_port_add_phy()
1110 if (unlikely(tmp != phy)) { in sas_port_add_phy()
1111 …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()
1112 dev_name(&phy->dev)); in sas_port_add_phy()
1116 sas_port_create_link(port, phy); in sas_port_add_phy()
1117 list_add_tail(&phy->port_siblings, &port->phy_list); in sas_port_add_phy()
1118 port->num_phys++; in sas_port_add_phy()
1120 mutex_unlock(&port->phy_list_mutex); in sas_port_add_phy()
1125 * sas_port_delete_phy - remove a phy from a port or wide port
1126 * @port: port to remove the phy from
1127 * @phy: phy to remove
1132 void sas_port_delete_phy(struct sas_port *port, struct sas_phy *phy) in sas_port_delete_phy() argument
1134 mutex_lock(&port->phy_list_mutex); in sas_port_delete_phy()
1135 sas_port_delete_link(port, phy); in sas_port_delete_phy()
1136 list_del_init(&phy->port_siblings); in sas_port_delete_phy()
1137 port->num_phys--; in sas_port_delete_phy()
1138 mutex_unlock(&port->phy_list_mutex); in sas_port_delete_phy()
1145 struct device *parent = port->dev.parent->parent->parent; in sas_port_mark_backlink()
1147 if (port->is_backlink) in sas_port_mark_backlink()
1149 port->is_backlink = 1; in sas_port_mark_backlink()
1150 res = sysfs_create_link(&port->dev.kobj, &parent->kobj, in sas_port_mark_backlink()
1163 * SAS remote PHY attributes.
1168 show_sas_rphy_##name(struct device *dev, \
1173 return snprintf(buf, 20, format_string, cast rphy->field); \
1183 show_sas_rphy_##name(struct device *dev, \
1188 if (!rphy->field) \
1190 return get_sas_protocol_names(rphy->field, buf); \
1199 show_sas_rphy_device_type(struct device *dev, in show_sas_rphy_device_type()
1204 if (!rphy->identify.device_type) in show_sas_rphy_device_type()
1207 rphy->identify.device_type, buf); in show_sas_rphy_device_type()
1214 show_sas_rphy_enclosure_identifier(struct device *dev, in show_sas_rphy_enclosure_identifier()
1218 struct sas_phy *phy = dev_to_phy(rphy->dev.parent); in show_sas_rphy_enclosure_identifier() local
1219 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); in show_sas_rphy_enclosure_identifier()
1220 struct sas_internal *i = to_sas_internal(shost->transportt); in show_sas_rphy_enclosure_identifier()
1224 error = i->f->get_enclosure_identifier(rphy, &identifier); in show_sas_rphy_enclosure_identifier()
1234 show_sas_rphy_bay_identifier(struct device *dev, in show_sas_rphy_bay_identifier()
1238 struct sas_phy *phy = dev_to_phy(rphy->dev.parent); in show_sas_rphy_bay_identifier() local
1239 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); in show_sas_rphy_bay_identifier()
1240 struct sas_internal *i = to_sas_internal(shost->transportt); in show_sas_rphy_bay_identifier()
1243 val = i->f->get_bay_identifier(rphy); in show_sas_rphy_bay_identifier()
1271 return -ENOMEM; in sas_read_port_mode_page()
1282 if (msdata - buffer > BUF_SIZE - 8) in sas_read_port_mode_page()
1287 rdev->ready_led_meaning = msdata[2] & 0x10 ? 1 : 0; in sas_read_port_mode_page()
1288 rdev->I_T_nexus_loss_timeout = (msdata[4] << 8) + msdata[5]; in sas_read_port_mode_page()
1289 rdev->initiator_response_timeout = (msdata[6] << 8) + msdata[7]; in sas_read_port_mode_page()
1302 show_sas_end_dev_##name(struct device *dev, \
1308 return snprintf(buf, 20, format_string, cast rdev->field); \
1331 show_sas_expander_##name(struct device *dev, \
1337 return snprintf(buf, 20, format_string, cast edev->field); \
1358 static int sas_rphy_match(struct attribute_container *cont, struct device *dev) in sas_rphy_match()
1365 shost = dev_to_shost(dev->parent->parent); in sas_rphy_match()
1367 if (!shost->transportt) in sas_rphy_match()
1369 if (shost->transportt->host_attrs.ac.class != in sas_rphy_match()
1373 i = to_sas_internal(shost->transportt); in sas_rphy_match()
1374 return &i->rphy_attr_cont.ac == cont; in sas_rphy_match()
1378 struct device *dev) in sas_end_dev_match()
1386 shost = dev_to_shost(dev->parent->parent); in sas_end_dev_match()
1389 if (!shost->transportt) in sas_end_dev_match()
1391 if (shost->transportt->host_attrs.ac.class != in sas_end_dev_match()
1395 i = to_sas_internal(shost->transportt); in sas_end_dev_match()
1396 return &i->end_dev_attr_cont.ac == cont && in sas_end_dev_match()
1397 rphy->identify.device_type == SAS_END_DEVICE; in sas_end_dev_match()
1401 struct device *dev) in sas_expander_match()
1409 shost = dev_to_shost(dev->parent->parent); in sas_expander_match()
1412 if (!shost->transportt) in sas_expander_match()
1414 if (shost->transportt->host_attrs.ac.class != in sas_expander_match()
1418 i = to_sas_internal(shost->transportt); in sas_expander_match()
1419 return &i->expander_attr_cont.ac == cont && in sas_expander_match()
1420 (rphy->identify.device_type == SAS_EDGE_EXPANDER_DEVICE || in sas_expander_match()
1421 rphy->identify.device_type == SAS_FANOUT_EXPANDER_DEVICE); in sas_expander_match()
1424 static void sas_expander_release(struct device *dev) in sas_expander_release()
1429 put_device(dev->parent); in sas_expander_release()
1433 static void sas_end_device_release(struct device *dev) in sas_end_device_release()
1438 put_device(dev->parent); in sas_end_device_release()
1443 * sas_rphy_initialize - common rphy initialization
1451 INIT_LIST_HEAD(&rphy->list); in sas_rphy_initialize()
1455 * sas_end_device_alloc - allocate an rphy for an end device
1458 * Allocates an SAS remote PHY structure, connected to @parent.
1461 * SAS PHY allocated or %NULL if the allocation failed.
1465 struct Scsi_Host *shost = dev_to_shost(&parent->dev); in sas_end_device_alloc()
1473 device_initialize(&rdev->rphy.dev); in sas_end_device_alloc()
1474 rdev->rphy.dev.parent = get_device(&parent->dev); in sas_end_device_alloc()
1475 rdev->rphy.dev.release = sas_end_device_release; in sas_end_device_alloc()
1476 if (scsi_is_sas_expander_device(parent->dev.parent)) { in sas_end_device_alloc()
1477 struct sas_rphy *rphy = dev_to_rphy(parent->dev.parent); in sas_end_device_alloc()
1478 dev_set_name(&rdev->rphy.dev, "end_device-%d:%d:%d", in sas_end_device_alloc()
1479 shost->host_no, rphy->scsi_target_id, in sas_end_device_alloc()
1480 parent->port_identifier); in sas_end_device_alloc()
1482 dev_set_name(&rdev->rphy.dev, "end_device-%d:%d", in sas_end_device_alloc()
1483 shost->host_no, parent->port_identifier); in sas_end_device_alloc()
1484 rdev->rphy.identify.device_type = SAS_END_DEVICE; in sas_end_device_alloc()
1485 sas_rphy_initialize(&rdev->rphy); in sas_end_device_alloc()
1486 transport_setup_device(&rdev->rphy.dev); in sas_end_device_alloc()
1488 return &rdev->rphy; in sas_end_device_alloc()
1493 * sas_expander_alloc - allocate an rphy for an end device
1497 * Allocates an SAS remote PHY structure, connected to @parent.
1500 * SAS PHY allocated or %NULL if the allocation failed.
1505 struct Scsi_Host *shost = dev_to_shost(&parent->dev); in sas_expander_alloc()
1517 device_initialize(&rdev->rphy.dev); in sas_expander_alloc()
1518 rdev->rphy.dev.parent = get_device(&parent->dev); in sas_expander_alloc()
1519 rdev->rphy.dev.release = sas_expander_release; in sas_expander_alloc()
1520 mutex_lock(&sas_host->lock); in sas_expander_alloc()
1521 rdev->rphy.scsi_target_id = sas_host->next_expander_id++; in sas_expander_alloc()
1522 mutex_unlock(&sas_host->lock); in sas_expander_alloc()
1523 dev_set_name(&rdev->rphy.dev, "expander-%d:%d", in sas_expander_alloc()
1524 shost->host_no, rdev->rphy.scsi_target_id); in sas_expander_alloc()
1525 rdev->rphy.identify.device_type = type; in sas_expander_alloc()
1526 sas_rphy_initialize(&rdev->rphy); in sas_expander_alloc()
1527 transport_setup_device(&rdev->rphy.dev); in sas_expander_alloc()
1529 return &rdev->rphy; in sas_expander_alloc()
1534 * sas_rphy_add - add a SAS remote PHY to the device hierarchy
1535 * @rphy: The remote PHY to be added
1537 * Publishes a SAS remote PHY to the rest of the system.
1541 struct sas_port *parent = dev_to_sas_port(rphy->dev.parent); in sas_rphy_add()
1542 struct Scsi_Host *shost = dev_to_shost(parent->dev.parent); in sas_rphy_add()
1544 struct sas_identify *identify = &rphy->identify; in sas_rphy_add()
1547 if (parent->rphy) in sas_rphy_add()
1548 return -ENXIO; in sas_rphy_add()
1549 parent->rphy = rphy; in sas_rphy_add()
1551 error = device_add(&rphy->dev); in sas_rphy_add()
1554 transport_add_device(&rphy->dev); in sas_rphy_add()
1555 transport_configure_device(&rphy->dev); in sas_rphy_add()
1557 printk("fail to a bsg device %s\n", dev_name(&rphy->dev)); in sas_rphy_add()
1560 mutex_lock(&sas_host->lock); in sas_rphy_add()
1561 list_add_tail(&rphy->list, &sas_host->rphy_list); in sas_rphy_add()
1562 if (identify->device_type == SAS_END_DEVICE && in sas_rphy_add()
1563 (identify->target_port_protocols & in sas_rphy_add()
1565 rphy->scsi_target_id = sas_host->next_target_id++; in sas_rphy_add()
1566 else if (identify->device_type == SAS_END_DEVICE) in sas_rphy_add()
1567 rphy->scsi_target_id = -1; in sas_rphy_add()
1568 mutex_unlock(&sas_host->lock); in sas_rphy_add()
1570 if (identify->device_type == SAS_END_DEVICE && in sas_rphy_add()
1571 rphy->scsi_target_id != -1) { in sas_rphy_add()
1574 if (identify->target_port_protocols & SAS_PROTOCOL_SSP) in sas_rphy_add()
1579 scsi_scan_target(&rphy->dev, 0, rphy->scsi_target_id, lun, in sas_rphy_add()
1588 * sas_rphy_free - free a SAS remote PHY
1589 * @rphy: SAS remote PHY to free
1591 * Frees the specified SAS remote PHY.
1595 * PHY that has not successfully been added using
1600 struct device *dev = &rphy->dev; in sas_rphy_free()
1601 struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent); in sas_rphy_free()
1604 mutex_lock(&sas_host->lock); in sas_rphy_free()
1605 list_del(&rphy->list); in sas_rphy_free()
1606 mutex_unlock(&sas_host->lock); in sas_rphy_free()
1615 * sas_rphy_delete - remove and free SAS remote PHY
1616 * @rphy: SAS remote PHY to remove and free
1618 * Removes the specified SAS remote PHY and frees it.
1629 * sas_rphy_unlink - unlink SAS remote PHY
1630 * @rphy: SAS remote phy to unlink from its parent port
1636 struct sas_port *parent = dev_to_sas_port(rphy->dev.parent); in sas_rphy_unlink()
1638 parent->rphy = NULL; in sas_rphy_unlink()
1643 * sas_rphy_remove - remove SAS remote PHY
1644 * @rphy: SAS remote phy to remove
1646 * Removes the specified SAS remote PHY.
1651 struct device *dev = &rphy->dev; in sas_rphy_remove()
1653 switch (rphy->identify.device_type) { in sas_rphy_remove()
1666 bsg_remove_queue(rphy->q); in sas_rphy_remove()
1673 * scsi_is_sas_rphy - check if a struct device represents a SAS remote PHY
1674 * @dev: device to check
1677 * %1 if the device represents a SAS remote PHY, %0 else
1679 int scsi_is_sas_rphy(const struct device *dev) in scsi_is_sas_rphy()
1681 return dev->release == sas_end_device_release || in scsi_is_sas_rphy()
1682 dev->release == sas_expander_release; in scsi_is_sas_rphy()
1697 mutex_lock(&sas_host->lock); in sas_user_scan()
1698 list_for_each_entry(rphy, &sas_host->rphy_list, list) { in sas_user_scan()
1699 if (rphy->identify.device_type != SAS_END_DEVICE || in sas_user_scan()
1700 rphy->scsi_target_id == -1) in sas_user_scan()
1704 (id == SCAN_WILD_CARD || id == rphy->scsi_target_id)) { in sas_user_scan()
1705 scsi_scan_target(&rphy->dev, 0, rphy->scsi_target_id, in sas_user_scan()
1709 mutex_unlock(&sas_host->lock); in sas_user_scan()
1720 i->private_##attrb[count] = dev_attr_##field; \
1721 i->private_##attrb[count].attr.mode = perm; \
1722 i->attrb[count] = &i->private_##attrb[count]; \
1727 i->private_##attrb[count] = dev_attr_##field; \
1728 i->private_##attrb[count].attr.mode = perm; \
1730 i->private_##attrb[count].attr.mode = ro_perm; \
1731 i->private_##attrb[count].store = NULL; \
1733 i->attrb[count] = &i->private_##attrb[count]; \
1741 SETUP_TEMPLATE(rphy_attrs, field, S_IRUGO, i->f->func)
1748 !i->f->set_phy_speed, S_IRUGO)
1752 !i->f->func, S_IRUGO)
1758 SETUP_TEMPLATE(phy_attrs, field, S_IRUGO, i->f->func)
1764 SETUP_TEMPLATE(phy_attrs, field, S_IWUSR, i->f->func)
1773 * sas_attach_transport - instantiate SAS transport template
1786 i->t.user_scan = sas_user_scan; in sas_attach_transport()
1788 i->t.host_attrs.ac.attrs = &i->host_attrs[0]; in sas_attach_transport()
1789 i->t.host_attrs.ac.class = &sas_host_class.class; in sas_attach_transport()
1790 i->t.host_attrs.ac.match = sas_host_match; in sas_attach_transport()
1791 transport_container_register(&i->t.host_attrs); in sas_attach_transport()
1792 i->t.host_size = sizeof(struct sas_host_attrs); in sas_attach_transport()
1794 i->phy_attr_cont.ac.class = &sas_phy_class.class; in sas_attach_transport()
1795 i->phy_attr_cont.ac.attrs = &i->phy_attrs[0]; in sas_attach_transport()
1796 i->phy_attr_cont.ac.match = sas_phy_match; in sas_attach_transport()
1797 transport_container_register(&i->phy_attr_cont); in sas_attach_transport()
1799 i->port_attr_cont.ac.class = &sas_port_class.class; in sas_attach_transport()
1800 i->port_attr_cont.ac.attrs = &i->port_attrs[0]; in sas_attach_transport()
1801 i->port_attr_cont.ac.match = sas_port_match; in sas_attach_transport()
1802 transport_container_register(&i->port_attr_cont); in sas_attach_transport()
1804 i->rphy_attr_cont.ac.class = &sas_rphy_class.class; in sas_attach_transport()
1805 i->rphy_attr_cont.ac.attrs = &i->rphy_attrs[0]; in sas_attach_transport()
1806 i->rphy_attr_cont.ac.match = sas_rphy_match; in sas_attach_transport()
1807 transport_container_register(&i->rphy_attr_cont); in sas_attach_transport()
1809 i->end_dev_attr_cont.ac.class = &sas_end_dev_class.class; in sas_attach_transport()
1810 i->end_dev_attr_cont.ac.attrs = &i->end_dev_attrs[0]; in sas_attach_transport()
1811 i->end_dev_attr_cont.ac.match = sas_end_dev_match; in sas_attach_transport()
1812 transport_container_register(&i->end_dev_attr_cont); in sas_attach_transport()
1814 i->expander_attr_cont.ac.class = &sas_expander_class.class; in sas_attach_transport()
1815 i->expander_attr_cont.ac.attrs = &i->expander_attrs[0]; in sas_attach_transport()
1816 i->expander_attr_cont.ac.match = sas_expander_match; in sas_attach_transport()
1817 transport_container_register(&i->expander_attr_cont); in sas_attach_transport()
1819 i->f = ft; in sas_attach_transport()
1840 i->phy_attrs[count] = NULL; in sas_attach_transport()
1844 i->port_attrs[count] = NULL; in sas_attach_transport()
1857 i->rphy_attrs[count] = NULL; in sas_attach_transport()
1865 i->end_dev_attrs[count] = NULL; in sas_attach_transport()
1875 i->expander_attrs[count] = NULL; in sas_attach_transport()
1877 return &i->t; in sas_attach_transport()
1882 * sas_release_transport - release SAS transport template instance
1889 transport_container_unregister(&i->t.host_attrs); in sas_release_transport()
1890 transport_container_unregister(&i->phy_attr_cont); in sas_release_transport()
1891 transport_container_unregister(&i->port_attr_cont); in sas_release_transport()
1892 transport_container_unregister(&i->rphy_attr_cont); in sas_release_transport()
1893 transport_container_unregister(&i->end_dev_attr_cont); in sas_release_transport()
1894 transport_container_unregister(&i->expander_attr_cont); in sas_release_transport()