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), 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, 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 Phy attributes
425 show_sas_phy_##name(struct device *dev, \
428 struct sas_phy *phy = transport_class_to_phy(dev); \
430 return snprintf(buf, 20, format_string, cast phy->field); \
439 show_sas_phy_##name(struct device *dev, \
442 struct sas_phy *phy = transport_class_to_phy(dev); \
444 if (!phy->field) \
446 return get_sas_protocol_names(phy->field, buf); \
455 show_sas_phy_##field(struct device *dev, \
458 struct sas_phy *phy = transport_class_to_phy(dev); \
460 return get_sas_linkspeed_names(phy->field, buf); \
466 store_sas_phy_##field(struct device *dev, \
470 struct sas_phy *phy = transport_class_to_phy(dev); \
471 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); \
472 struct sas_internal *i = to_sas_internal(shost->transportt); \
481 error = i->f->set_phy_speed(phy, &rates); \
499 show_sas_phy_##field(struct device *dev, \
502 struct sas_phy *phy = transport_class_to_phy(dev); \
503 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); \
504 struct sas_internal *i = to_sas_internal(shost->transportt); \
507 error = i->f->get_linkerrors ? i->f->get_linkerrors(phy) : 0; \
510 return snprintf(buf, 20, "%u\n", phy->field); \
519 show_sas_device_type(struct device *dev, in show_sas_device_type()
522 struct sas_phy *phy = transport_class_to_phy(dev); in show_sas_device_type() local
524 if (!phy->identify.device_type) in show_sas_device_type()
526 return get_sas_device_type_names(phy->identify.device_type, buf); in show_sas_device_type()
530 static ssize_t do_sas_phy_enable(struct device *dev, in do_sas_phy_enable()
533 struct sas_phy *phy = transport_class_to_phy(dev); in do_sas_phy_enable() local
534 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); in do_sas_phy_enable()
535 struct sas_internal *i = to_sas_internal(shost->transportt); in do_sas_phy_enable()
538 error = i->f->phy_enable(phy, enable); in do_sas_phy_enable()
541 phy->enabled = enable; in do_sas_phy_enable()
546 store_sas_phy_enable(struct device *dev, struct device_attribute *attr, in store_sas_phy_enable()
550 return -EINVAL; in store_sas_phy_enable()
560 return -EINVAL; in store_sas_phy_enable()
567 show_sas_phy_enable(struct device *dev, struct device_attribute *attr, in show_sas_phy_enable()
570 struct sas_phy *phy = transport_class_to_phy(dev); in show_sas_phy_enable() local
572 return snprintf(buf, 20, "%d\n", phy->enabled); in show_sas_phy_enable()
579 do_sas_phy_reset(struct device *dev, size_t count, int hard_reset) in do_sas_phy_reset()
581 struct sas_phy *phy = transport_class_to_phy(dev); in do_sas_phy_reset() local
582 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); in do_sas_phy_reset()
583 struct sas_internal *i = to_sas_internal(shost->transportt); in do_sas_phy_reset()
586 error = i->f->phy_reset(phy, hard_reset); in do_sas_phy_reset()
589 phy->enabled = 1; in do_sas_phy_reset()
594 store_sas_link_reset(struct device *dev, struct device_attribute *attr, in store_sas_link_reset()
602 store_sas_hard_reset(struct device *dev, struct device_attribute *attr, in store_sas_hard_reset()
626 static int sas_phy_setup(struct transport_container *tc, struct device *dev, in sas_phy_setup()
627 struct device *cdev) in sas_phy_setup()
629 struct sas_phy *phy = dev_to_phy(dev); in sas_phy_setup() local
630 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); in sas_phy_setup()
631 struct sas_internal *i = to_sas_internal(shost->transportt); in sas_phy_setup()
633 if (i->f->phy_setup) in sas_phy_setup()
634 i->f->phy_setup(phy); in sas_phy_setup()
642 static int sas_phy_match(struct attribute_container *cont, struct device *dev) in sas_phy_match()
649 shost = dev_to_shost(dev->parent); in sas_phy_match()
651 if (!shost->transportt) in sas_phy_match()
653 if (shost->transportt->host_attrs.ac.class != in sas_phy_match()
657 i = to_sas_internal(shost->transportt); in sas_phy_match()
658 return &i->phy_attr_cont.ac == cont; in sas_phy_match()
661 static void sas_phy_release(struct device *dev) in sas_phy_release()
663 struct sas_phy *phy = dev_to_phy(dev); in sas_phy_release() local
664 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); in sas_phy_release()
665 struct sas_internal *i = to_sas_internal(shost->transportt); in sas_phy_release()
667 if (i->f->phy_release) in sas_phy_release()
668 i->f->phy_release(phy); in sas_phy_release()
669 put_device(dev->parent); in sas_phy_release()
670 kfree(phy); in sas_phy_release()
674 * sas_phy_alloc - allocates and initialize a SAS PHY structure
675 * @parent: Parent device
676 * @number: Phy index
678 * Allocates an SAS PHY structure. It will be added in the device tree
679 * below the device specified by @parent, which has to be either a Scsi_Host
683 * SAS PHY allocated or %NULL if the allocation failed.
685 struct sas_phy *sas_phy_alloc(struct device *parent, int number) in sas_phy_alloc()
688 struct sas_phy *phy; in sas_phy_alloc() local
690 phy = kzalloc(sizeof(*phy), GFP_KERNEL); in sas_phy_alloc()
691 if (!phy) in sas_phy_alloc()
694 phy->number = number; in sas_phy_alloc()
695 phy->enabled = 1; in sas_phy_alloc()
697 device_initialize(&phy->dev); in sas_phy_alloc()
698 phy->dev.parent = get_device(parent); in sas_phy_alloc()
699 phy->dev.release = sas_phy_release; in sas_phy_alloc()
700 INIT_LIST_HEAD(&phy->port_siblings); in sas_phy_alloc()
703 dev_set_name(&phy->dev, "phy-%d:%d:%d", shost->host_no, in sas_phy_alloc()
704 rphy->scsi_target_id, number); in sas_phy_alloc()
706 dev_set_name(&phy->dev, "phy-%d:%d", shost->host_no, number); in sas_phy_alloc()
708 transport_setup_device(&phy->dev); in sas_phy_alloc()
710 return phy; in sas_phy_alloc()
715 * sas_phy_add - add a SAS PHY to the device hierarchy
716 * @phy: The PHY to be added
718 * Publishes a SAS PHY to the rest of the system.
720 int sas_phy_add(struct sas_phy *phy) in sas_phy_add() argument
724 error = device_add(&phy->dev); in sas_phy_add()
728 error = transport_add_device(&phy->dev); in sas_phy_add()
730 device_del(&phy->dev); in sas_phy_add()
733 transport_configure_device(&phy->dev); in sas_phy_add()
740 * sas_phy_free - free a SAS PHY
741 * @phy: SAS PHY to free
743 * Frees the specified SAS PHY.
746 * This function must only be called on a PHY that has not
749 void sas_phy_free(struct sas_phy *phy) in sas_phy_free() argument
751 transport_destroy_device(&phy->dev); in sas_phy_free()
752 put_device(&phy->dev); in sas_phy_free()
757 * sas_phy_delete - remove SAS PHY
758 * @phy: SAS PHY to remove
760 * Removes the specified SAS PHY. If the SAS PHY has an
761 * associated remote PHY it is removed before.
764 sas_phy_delete(struct sas_phy *phy) in sas_phy_delete() argument
766 struct device *dev = &phy->dev; in sas_phy_delete()
768 /* this happens if the phy is still part of a port when deleted */ in sas_phy_delete()
769 BUG_ON(!list_empty(&phy->port_siblings)); in sas_phy_delete()
779 * scsi_is_sas_phy - check if a struct device represents a SAS PHY
780 * @dev: device to check
783 * %1 if the device represents a SAS PHY, %0 else
785 int scsi_is_sas_phy(const struct device *dev) in scsi_is_sas_phy()
787 return dev->release == sas_phy_release; in scsi_is_sas_phy()
796 show_sas_port_##name(struct device *dev, \
801 return snprintf(buf, 20, format_string, cast port->field); \
813 static int sas_port_match(struct attribute_container *cont, struct device *dev) in sas_port_match()
820 shost = dev_to_shost(dev->parent); in sas_port_match()
822 if (!shost->transportt) in sas_port_match()
824 if (shost->transportt->host_attrs.ac.class != in sas_port_match()
828 i = to_sas_internal(shost->transportt); in sas_port_match()
829 return &i->port_attr_cont.ac == cont; in sas_port_match()
833 static void sas_port_release(struct device *dev) in sas_port_release()
837 BUG_ON(!list_empty(&port->phy_list)); in sas_port_release()
839 put_device(dev->parent); in sas_port_release()
844 struct sas_phy *phy) in sas_port_create_link() argument
848 res = sysfs_create_link(&port->dev.kobj, &phy->dev.kobj, in sas_port_create_link()
849 dev_name(&phy->dev)); in sas_port_create_link()
852 res = sysfs_create_link(&phy->dev.kobj, &port->dev.kobj, "port"); in sas_port_create_link()
862 struct sas_phy *phy) in sas_port_delete_link() argument
864 sysfs_remove_link(&port->dev.kobj, dev_name(&phy->dev)); in sas_port_delete_link()
865 sysfs_remove_link(&phy->dev.kobj, "port"); in sas_port_delete_link()
868 /** sas_port_alloc - allocate and initialize a SAS port structure
870 * @parent: parent device
873 * Allocates a SAS port structure. It will be added to the device tree
874 * below the device specified by @parent which must be either a Scsi_Host
879 struct sas_port *sas_port_alloc(struct device *parent, int port_id) in sas_port_alloc()
888 port->port_identifier = port_id; in sas_port_alloc()
890 device_initialize(&port->dev); in sas_port_alloc()
892 port->dev.parent = get_device(parent); in sas_port_alloc()
893 port->dev.release = sas_port_release; in sas_port_alloc()
895 mutex_init(&port->phy_list_mutex); in sas_port_alloc()
896 INIT_LIST_HEAD(&port->phy_list); in sas_port_alloc()
900 dev_set_name(&port->dev, "port-%d:%d:%d", shost->host_no, in sas_port_alloc()
901 rphy->scsi_target_id, port->port_identifier); in sas_port_alloc()
903 dev_set_name(&port->dev, "port-%d:%d", shost->host_no, in sas_port_alloc()
904 port->port_identifier); in sas_port_alloc()
906 transport_setup_device(&port->dev); in sas_port_alloc()
912 /** sas_port_alloc_num - allocate and initialize a SAS port structure
914 * @parent: parent device
919 * the device tree below the device specified by @parent which must be
924 struct sas_port *sas_port_alloc_num(struct device *parent) in sas_port_alloc_num()
931 mutex_lock(&sas_host->lock); in sas_port_alloc_num()
936 index = exp->next_port_id++; in sas_port_alloc_num()
938 index = sas_host->next_port_id++; in sas_port_alloc_num()
939 mutex_unlock(&sas_host->lock); in sas_port_alloc_num()
945 * sas_port_add - add a SAS port to the device hierarchy
955 BUG_ON(!list_empty(&port->phy_list)); in sas_port_add()
957 error = device_add(&port->dev); in sas_port_add()
962 transport_add_device(&port->dev); in sas_port_add()
963 transport_configure_device(&port->dev); in sas_port_add()
970 * sas_port_free - free a SAS PORT
981 transport_destroy_device(&port->dev); in sas_port_free()
982 put_device(&port->dev); in sas_port_free()
987 * sas_port_delete - remove SAS PORT
995 struct device *dev = &port->dev; in sas_port_delete()
996 struct sas_phy *phy, *tmp_phy; in sas_port_delete() local
998 if (port->rphy) { in sas_port_delete()
999 sas_rphy_delete(port->rphy); in sas_port_delete()
1000 port->rphy = NULL; in sas_port_delete()
1003 mutex_lock(&port->phy_list_mutex); in sas_port_delete()
1004 list_for_each_entry_safe(phy, tmp_phy, &port->phy_list, in sas_port_delete()
1006 sas_port_delete_link(port, phy); in sas_port_delete()
1007 list_del_init(&phy->port_siblings); in sas_port_delete()
1009 mutex_unlock(&port->phy_list_mutex); in sas_port_delete()
1011 if (port->is_backlink) { in sas_port_delete()
1012 struct device *parent = port->dev.parent; in sas_port_delete()
1014 sysfs_remove_link(&port->dev.kobj, dev_name(parent)); in sas_port_delete()
1015 port->is_backlink = 0; in sas_port_delete()
1026 * scsi_is_sas_port - check if a struct device represents a SAS port
1027 * @dev: device to check
1030 * %1 if the device represents a SAS Port, %0 else
1032 int scsi_is_sas_port(const struct device *dev) in scsi_is_sas_port()
1034 return dev->release == sas_port_release; in scsi_is_sas_port()
1039 * sas_port_get_phy - try to take a reference on a port member
1044 struct sas_phy *phy; in sas_port_get_phy() local
1046 mutex_lock(&port->phy_list_mutex); in sas_port_get_phy()
1047 if (list_empty(&port->phy_list)) in sas_port_get_phy()
1048 phy = NULL; in sas_port_get_phy()
1050 struct list_head *ent = port->phy_list.next; in sas_port_get_phy()
1052 phy = list_entry(ent, typeof(*phy), port_siblings); in sas_port_get_phy()
1053 get_device(&phy->dev); in sas_port_get_phy()
1055 mutex_unlock(&port->phy_list_mutex); in sas_port_get_phy()
1057 return phy; in sas_port_get_phy()
1062 * sas_port_add_phy - add another phy to a port to form a wide port
1063 * @port: port to add the phy to
1064 * @phy: phy to add
1067 * ports must have at least one phy to operated, and all wide ports
1070 * connected to a remote device is a port, so ports must be formed on
1073 void sas_port_add_phy(struct sas_port *port, struct sas_phy *phy) in sas_port_add_phy() argument
1075 mutex_lock(&port->phy_list_mutex); in sas_port_add_phy()
1076 if (unlikely(!list_empty(&phy->port_siblings))) { in sas_port_add_phy()
1080 list_for_each_entry(tmp, &port->phy_list, port_siblings) in sas_port_add_phy()
1081 if (tmp == phy) in sas_port_add_phy()
1083 /* If this trips, you added a phy that was already in sas_port_add_phy()
1085 if (unlikely(tmp != phy)) { in sas_port_add_phy()
1086 …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()
1087 dev_name(&phy->dev)); in sas_port_add_phy()
1091 sas_port_create_link(port, phy); in sas_port_add_phy()
1092 list_add_tail(&phy->port_siblings, &port->phy_list); in sas_port_add_phy()
1093 port->num_phys++; in sas_port_add_phy()
1095 mutex_unlock(&port->phy_list_mutex); in sas_port_add_phy()
1100 * sas_port_delete_phy - remove a phy from a port or wide port
1101 * @port: port to remove the phy from
1102 * @phy: phy to remove
1107 void sas_port_delete_phy(struct sas_port *port, struct sas_phy *phy) in sas_port_delete_phy() argument
1109 mutex_lock(&port->phy_list_mutex); in sas_port_delete_phy()
1110 sas_port_delete_link(port, phy); in sas_port_delete_phy()
1111 list_del_init(&phy->port_siblings); in sas_port_delete_phy()
1112 port->num_phys--; in sas_port_delete_phy()
1113 mutex_unlock(&port->phy_list_mutex); in sas_port_delete_phy()
1120 struct device *parent = port->dev.parent->parent->parent; in sas_port_mark_backlink()
1122 if (port->is_backlink) in sas_port_mark_backlink()
1124 port->is_backlink = 1; in sas_port_mark_backlink()
1125 res = sysfs_create_link(&port->dev.kobj, &parent->kobj, in sas_port_mark_backlink()
1138 * SAS remote PHY attributes.
1143 show_sas_rphy_##name(struct device *dev, \
1148 return snprintf(buf, 20, format_string, cast rphy->field); \
1158 show_sas_rphy_##name(struct device *dev, \
1163 if (!rphy->field) \
1165 return get_sas_protocol_names(rphy->field, buf); \
1174 show_sas_rphy_device_type(struct device *dev, in show_sas_rphy_device_type()
1179 if (!rphy->identify.device_type) in show_sas_rphy_device_type()
1182 rphy->identify.device_type, buf); in show_sas_rphy_device_type()
1189 show_sas_rphy_enclosure_identifier(struct device *dev, in show_sas_rphy_enclosure_identifier()
1193 struct sas_phy *phy = dev_to_phy(rphy->dev.parent); in show_sas_rphy_enclosure_identifier() local
1194 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); in show_sas_rphy_enclosure_identifier()
1195 struct sas_internal *i = to_sas_internal(shost->transportt); in show_sas_rphy_enclosure_identifier()
1199 error = i->f->get_enclosure_identifier(rphy, &identifier); in show_sas_rphy_enclosure_identifier()
1209 show_sas_rphy_bay_identifier(struct device *dev, in show_sas_rphy_bay_identifier()
1213 struct sas_phy *phy = dev_to_phy(rphy->dev.parent); in show_sas_rphy_bay_identifier() local
1214 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); in show_sas_rphy_bay_identifier()
1215 struct sas_internal *i = to_sas_internal(shost->transportt); in show_sas_rphy_bay_identifier()
1218 val = i->f->get_bay_identifier(rphy); in show_sas_rphy_bay_identifier()
1246 return -ENOMEM; in sas_read_port_mode_page()
1257 if (msdata - buffer > BUF_SIZE - 8) in sas_read_port_mode_page()
1262 rdev->ready_led_meaning = msdata[2] & 0x10 ? 1 : 0; in sas_read_port_mode_page()
1263 rdev->I_T_nexus_loss_timeout = (msdata[4] << 8) + msdata[5]; in sas_read_port_mode_page()
1264 rdev->initiator_response_timeout = (msdata[6] << 8) + msdata[7]; in sas_read_port_mode_page()
1277 show_sas_end_dev_##name(struct device *dev, \
1283 return snprintf(buf, 20, format_string, cast rdev->field); \
1306 show_sas_expander_##name(struct device *dev, \
1312 return snprintf(buf, 20, format_string, cast edev->field); \
1333 static int sas_rphy_match(struct attribute_container *cont, struct device *dev) in sas_rphy_match()
1340 shost = dev_to_shost(dev->parent->parent); in sas_rphy_match()
1342 if (!shost->transportt) in sas_rphy_match()
1344 if (shost->transportt->host_attrs.ac.class != in sas_rphy_match()
1348 i = to_sas_internal(shost->transportt); in sas_rphy_match()
1349 return &i->rphy_attr_cont.ac == cont; in sas_rphy_match()
1353 struct device *dev) in sas_end_dev_match()
1361 shost = dev_to_shost(dev->parent->parent); in sas_end_dev_match()
1364 if (!shost->transportt) in sas_end_dev_match()
1366 if (shost->transportt->host_attrs.ac.class != in sas_end_dev_match()
1370 i = to_sas_internal(shost->transportt); in sas_end_dev_match()
1371 return &i->end_dev_attr_cont.ac == cont && in sas_end_dev_match()
1372 rphy->identify.device_type == SAS_END_DEVICE; in sas_end_dev_match()
1376 struct device *dev) in sas_expander_match()
1384 shost = dev_to_shost(dev->parent->parent); in sas_expander_match()
1387 if (!shost->transportt) in sas_expander_match()
1389 if (shost->transportt->host_attrs.ac.class != in sas_expander_match()
1393 i = to_sas_internal(shost->transportt); in sas_expander_match()
1394 return &i->expander_attr_cont.ac == cont && in sas_expander_match()
1395 (rphy->identify.device_type == SAS_EDGE_EXPANDER_DEVICE || in sas_expander_match()
1396 rphy->identify.device_type == SAS_FANOUT_EXPANDER_DEVICE); in sas_expander_match()
1399 static void sas_expander_release(struct device *dev) in sas_expander_release()
1404 put_device(dev->parent); in sas_expander_release()
1408 static void sas_end_device_release(struct device *dev) in sas_end_device_release()
1413 put_device(dev->parent); in sas_end_device_release()
1418 * sas_rphy_initialize - common rphy initialization
1426 INIT_LIST_HEAD(&rphy->list); in sas_rphy_initialize()
1430 * sas_end_device_alloc - allocate an rphy for an end device
1433 * Allocates an SAS remote PHY structure, connected to @parent.
1436 * SAS PHY allocated or %NULL if the allocation failed.
1440 struct Scsi_Host *shost = dev_to_shost(&parent->dev); in sas_end_device_alloc()
1448 device_initialize(&rdev->rphy.dev); in sas_end_device_alloc()
1449 rdev->rphy.dev.parent = get_device(&parent->dev); in sas_end_device_alloc()
1450 rdev->rphy.dev.release = sas_end_device_release; in sas_end_device_alloc()
1451 if (scsi_is_sas_expander_device(parent->dev.parent)) { in sas_end_device_alloc()
1452 struct sas_rphy *rphy = dev_to_rphy(parent->dev.parent); in sas_end_device_alloc()
1453 dev_set_name(&rdev->rphy.dev, "end_device-%d:%d:%d", in sas_end_device_alloc()
1454 shost->host_no, rphy->scsi_target_id, in sas_end_device_alloc()
1455 parent->port_identifier); in sas_end_device_alloc()
1457 dev_set_name(&rdev->rphy.dev, "end_device-%d:%d", in sas_end_device_alloc()
1458 shost->host_no, parent->port_identifier); in sas_end_device_alloc()
1459 rdev->rphy.identify.device_type = SAS_END_DEVICE; in sas_end_device_alloc()
1460 sas_rphy_initialize(&rdev->rphy); in sas_end_device_alloc()
1461 transport_setup_device(&rdev->rphy.dev); in sas_end_device_alloc()
1463 return &rdev->rphy; in sas_end_device_alloc()
1468 * sas_expander_alloc - allocate an rphy for an end device
1472 * Allocates an SAS remote PHY structure, connected to @parent.
1475 * SAS PHY allocated or %NULL if the allocation failed.
1480 struct Scsi_Host *shost = dev_to_shost(&parent->dev); in sas_expander_alloc()
1492 device_initialize(&rdev->rphy.dev); in sas_expander_alloc()
1493 rdev->rphy.dev.parent = get_device(&parent->dev); in sas_expander_alloc()
1494 rdev->rphy.dev.release = sas_expander_release; in sas_expander_alloc()
1495 mutex_lock(&sas_host->lock); in sas_expander_alloc()
1496 rdev->rphy.scsi_target_id = sas_host->next_expander_id++; in sas_expander_alloc()
1497 mutex_unlock(&sas_host->lock); in sas_expander_alloc()
1498 dev_set_name(&rdev->rphy.dev, "expander-%d:%d", in sas_expander_alloc()
1499 shost->host_no, rdev->rphy.scsi_target_id); in sas_expander_alloc()
1500 rdev->rphy.identify.device_type = type; in sas_expander_alloc()
1501 sas_rphy_initialize(&rdev->rphy); in sas_expander_alloc()
1502 transport_setup_device(&rdev->rphy.dev); in sas_expander_alloc()
1504 return &rdev->rphy; in sas_expander_alloc()
1509 * sas_rphy_add - add a SAS remote PHY to the device hierarchy
1510 * @rphy: The remote PHY to be added
1512 * Publishes a SAS remote PHY to the rest of the system.
1516 struct sas_port *parent = dev_to_sas_port(rphy->dev.parent); in sas_rphy_add()
1517 struct Scsi_Host *shost = dev_to_shost(parent->dev.parent); in sas_rphy_add()
1519 struct sas_identify *identify = &rphy->identify; in sas_rphy_add()
1522 if (parent->rphy) in sas_rphy_add()
1523 return -ENXIO; in sas_rphy_add()
1524 parent->rphy = rphy; in sas_rphy_add()
1526 error = device_add(&rphy->dev); in sas_rphy_add()
1529 transport_add_device(&rphy->dev); in sas_rphy_add()
1530 transport_configure_device(&rphy->dev); in sas_rphy_add()
1532 printk("fail to a bsg device %s\n", dev_name(&rphy->dev)); in sas_rphy_add()
1535 mutex_lock(&sas_host->lock); in sas_rphy_add()
1536 list_add_tail(&rphy->list, &sas_host->rphy_list); in sas_rphy_add()
1537 if (identify->device_type == SAS_END_DEVICE && in sas_rphy_add()
1538 (identify->target_port_protocols & in sas_rphy_add()
1540 rphy->scsi_target_id = sas_host->next_target_id++; in sas_rphy_add()
1541 else if (identify->device_type == SAS_END_DEVICE) in sas_rphy_add()
1542 rphy->scsi_target_id = -1; in sas_rphy_add()
1543 mutex_unlock(&sas_host->lock); in sas_rphy_add()
1545 if (identify->device_type == SAS_END_DEVICE && in sas_rphy_add()
1546 rphy->scsi_target_id != -1) { in sas_rphy_add()
1549 if (identify->target_port_protocols & SAS_PROTOCOL_SSP) in sas_rphy_add()
1554 scsi_scan_target(&rphy->dev, 0, rphy->scsi_target_id, lun, in sas_rphy_add()
1563 * sas_rphy_free - free a SAS remote PHY
1564 * @rphy: SAS remote PHY to free
1566 * Frees the specified SAS remote PHY.
1570 * PHY that has not successfully been added using
1575 struct device *dev = &rphy->dev; in sas_rphy_free()
1576 struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent); in sas_rphy_free()
1579 mutex_lock(&sas_host->lock); in sas_rphy_free()
1580 list_del(&rphy->list); in sas_rphy_free()
1581 mutex_unlock(&sas_host->lock); in sas_rphy_free()
1590 * sas_rphy_delete - remove and free SAS remote PHY
1591 * @rphy: SAS remote PHY to remove and free
1593 * Removes the specified SAS remote PHY and frees it.
1604 * sas_rphy_unlink - unlink SAS remote PHY
1605 * @rphy: SAS remote phy to unlink from its parent port
1611 struct sas_port *parent = dev_to_sas_port(rphy->dev.parent); in sas_rphy_unlink()
1613 parent->rphy = NULL; in sas_rphy_unlink()
1618 * sas_rphy_remove - remove SAS remote PHY
1619 * @rphy: SAS remote phy to remove
1621 * Removes the specified SAS remote PHY.
1626 struct device *dev = &rphy->dev; in sas_rphy_remove()
1628 switch (rphy->identify.device_type) { in sas_rphy_remove()
1641 bsg_remove_queue(rphy->q); in sas_rphy_remove()
1648 * scsi_is_sas_rphy - check if a struct device represents a SAS remote PHY
1649 * @dev: device to check
1652 * %1 if the device represents a SAS remote PHY, %0 else
1654 int scsi_is_sas_rphy(const struct device *dev) in scsi_is_sas_rphy()
1656 return dev->release == sas_end_device_release || in scsi_is_sas_rphy()
1657 dev->release == sas_expander_release; in scsi_is_sas_rphy()
1672 mutex_lock(&sas_host->lock); in sas_user_scan()
1673 list_for_each_entry(rphy, &sas_host->rphy_list, list) { in sas_user_scan()
1674 if (rphy->identify.device_type != SAS_END_DEVICE || in sas_user_scan()
1675 rphy->scsi_target_id == -1) in sas_user_scan()
1679 (id == SCAN_WILD_CARD || id == rphy->scsi_target_id)) { in sas_user_scan()
1680 scsi_scan_target(&rphy->dev, 0, rphy->scsi_target_id, in sas_user_scan()
1684 mutex_unlock(&sas_host->lock); in sas_user_scan()
1695 i->private_##attrb[count] = dev_attr_##field; \
1696 i->private_##attrb[count].attr.mode = perm; \
1697 i->attrb[count] = &i->private_##attrb[count]; \
1702 i->private_##attrb[count] = dev_attr_##field; \
1703 i->private_##attrb[count].attr.mode = perm; \
1705 i->private_##attrb[count].attr.mode = ro_perm; \
1706 i->private_##attrb[count].store = NULL; \
1708 i->attrb[count] = &i->private_##attrb[count]; \
1716 SETUP_TEMPLATE(rphy_attrs, field, S_IRUGO, i->f->func)
1723 !i->f->set_phy_speed, S_IRUGO)
1727 !i->f->func, S_IRUGO)
1733 SETUP_TEMPLATE(phy_attrs, field, S_IRUGO, i->f->func)
1739 SETUP_TEMPLATE(phy_attrs, field, S_IWUSR, i->f->func)
1748 * sas_attach_transport - instantiate SAS transport template
1761 i->t.user_scan = sas_user_scan; in sas_attach_transport()
1763 i->t.host_attrs.ac.attrs = &i->host_attrs[0]; in sas_attach_transport()
1764 i->t.host_attrs.ac.class = &sas_host_class.class; in sas_attach_transport()
1765 i->t.host_attrs.ac.match = sas_host_match; in sas_attach_transport()
1766 transport_container_register(&i->t.host_attrs); in sas_attach_transport()
1767 i->t.host_size = sizeof(struct sas_host_attrs); in sas_attach_transport()
1769 i->phy_attr_cont.ac.class = &sas_phy_class.class; in sas_attach_transport()
1770 i->phy_attr_cont.ac.attrs = &i->phy_attrs[0]; in sas_attach_transport()
1771 i->phy_attr_cont.ac.match = sas_phy_match; in sas_attach_transport()
1772 transport_container_register(&i->phy_attr_cont); in sas_attach_transport()
1774 i->port_attr_cont.ac.class = &sas_port_class.class; in sas_attach_transport()
1775 i->port_attr_cont.ac.attrs = &i->port_attrs[0]; in sas_attach_transport()
1776 i->port_attr_cont.ac.match = sas_port_match; in sas_attach_transport()
1777 transport_container_register(&i->port_attr_cont); in sas_attach_transport()
1779 i->rphy_attr_cont.ac.class = &sas_rphy_class.class; in sas_attach_transport()
1780 i->rphy_attr_cont.ac.attrs = &i->rphy_attrs[0]; in sas_attach_transport()
1781 i->rphy_attr_cont.ac.match = sas_rphy_match; in sas_attach_transport()
1782 transport_container_register(&i->rphy_attr_cont); in sas_attach_transport()
1784 i->end_dev_attr_cont.ac.class = &sas_end_dev_class.class; in sas_attach_transport()
1785 i->end_dev_attr_cont.ac.attrs = &i->end_dev_attrs[0]; in sas_attach_transport()
1786 i->end_dev_attr_cont.ac.match = sas_end_dev_match; in sas_attach_transport()
1787 transport_container_register(&i->end_dev_attr_cont); in sas_attach_transport()
1789 i->expander_attr_cont.ac.class = &sas_expander_class.class; in sas_attach_transport()
1790 i->expander_attr_cont.ac.attrs = &i->expander_attrs[0]; in sas_attach_transport()
1791 i->expander_attr_cont.ac.match = sas_expander_match; in sas_attach_transport()
1792 transport_container_register(&i->expander_attr_cont); in sas_attach_transport()
1794 i->f = ft; in sas_attach_transport()
1815 i->phy_attrs[count] = NULL; in sas_attach_transport()
1819 i->port_attrs[count] = NULL; in sas_attach_transport()
1832 i->rphy_attrs[count] = NULL; in sas_attach_transport()
1840 i->end_dev_attrs[count] = NULL; in sas_attach_transport()
1850 i->expander_attrs[count] = NULL; in sas_attach_transport()
1852 return &i->t; in sas_attach_transport()
1857 * sas_release_transport - release SAS transport template instance
1864 transport_container_unregister(&i->t.host_attrs); in sas_release_transport()
1865 transport_container_unregister(&i->phy_attr_cont); in sas_release_transport()
1866 transport_container_unregister(&i->port_attr_cont); in sas_release_transport()
1867 transport_container_unregister(&i->rphy_attr_cont); in sas_release_transport()
1868 transport_container_unregister(&i->end_dev_attr_cont); in sas_release_transport()
1869 transport_container_unregister(&i->expander_attr_cont); in sas_release_transport()