Lines Matching +full:d +full:- +full:phy
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
18 * underlying hardware for a PHY and a remote PHY is the exactly
52 #define to_sas_host_attrs(host) ((struct sas_host_attrs *)(host)->shost_data)
101 return -EINVAL; \
150 { SAS_PHY_DISABLED, "Phy disabled" },
152 { 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()
229 INIT_LIST_HEAD(&sas_host->rphy_list); in sas_host_setup()
230 mutex_init(&sas_host->lock); in sas_host_setup()
231 sas_host->next_target_id = 0; in sas_host_setup()
232 sas_host->next_expander_id = 0; in sas_host_setup()
233 sas_host->next_port_id = 0; in sas_host_setup()
236 dev_printk(KERN_ERR, dev, "fail to a bsg device %d\n", in sas_host_setup()
237 shost->host_no); in sas_host_setup()
246 struct request_queue *q = to_sas_host_attrs(shost)->q; in sas_host_remove()
265 if (!shost->transportt) in sas_host_match()
267 if (shost->transportt->host_attrs.ac.class != in sas_host_match()
271 i = to_sas_internal(shost->transportt); in sas_host_match()
272 return &i->t.host_attrs.ac == cont; in sas_host_match()
287 * sas_remove_children - tear down a devices SAS data structures
300 * sas_remove_host - tear down a Scsi_Host's SAS data structures
311 sas_remove_children(&shost->shost_gendev); in sas_remove_host()
317 * sas_get_address - return the SAS address of the device
326 return rdev->rphy.identify.sas_address; in sas_get_address()
331 * sas_tlr_supported - checking TLR bit in vpd 0x90
362 rdev->tlr_supported = ret; in sas_tlr_supported()
369 * sas_disable_tlr - setting TLR flags
380 rdev->tlr_enabled = 0; in sas_disable_tlr()
385 * sas_enable_tlr - setting TLR flags
399 rdev->tlr_enabled = 1; in sas_enable_tlr()
409 return rdev->tlr_enabled; in sas_is_tlr_enabled()
414 * SAS Phy attributes
422 struct sas_phy *phy = transport_class_to_phy(dev); \
424 return snprintf(buf, 20, format_string, cast phy->field); \
436 struct sas_phy *phy = transport_class_to_phy(dev); \
438 if (!phy->field) \
440 return get_sas_protocol_names(phy->field, buf); \
452 struct sas_phy *phy = transport_class_to_phy(dev); \
454 return get_sas_linkspeed_names(phy->field, buf); \
464 struct sas_phy *phy = transport_class_to_phy(dev); \
465 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); \
466 struct sas_internal *i = to_sas_internal(shost->transportt); \
475 error = i->f->set_phy_speed(phy, &rates); \
496 struct sas_phy *phy = transport_class_to_phy(dev); \
497 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); \
498 struct sas_internal *i = to_sas_internal(shost->transportt); \
501 error = i->f->get_linkerrors ? i->f->get_linkerrors(phy) : 0; \
504 return snprintf(buf, 20, "%u\n", phy->field); \
516 struct sas_phy *phy = transport_class_to_phy(dev); in show_sas_device_type() local
518 if (!phy->identify.device_type) in show_sas_device_type()
520 return get_sas_device_type_names(phy->identify.device_type, buf); in show_sas_device_type()
527 struct sas_phy *phy = transport_class_to_phy(dev); in do_sas_phy_enable() local
528 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); in do_sas_phy_enable()
529 struct sas_internal *i = to_sas_internal(shost->transportt); in do_sas_phy_enable()
532 error = i->f->phy_enable(phy, enable); in do_sas_phy_enable()
535 phy->enabled = enable; in do_sas_phy_enable()
544 return -EINVAL; in store_sas_phy_enable()
554 return -EINVAL; in store_sas_phy_enable()
564 struct sas_phy *phy = transport_class_to_phy(dev); in show_sas_phy_enable() local
566 return snprintf(buf, 20, "%d\n", phy->enabled); in show_sas_phy_enable()
575 struct sas_phy *phy = transport_class_to_phy(dev); in do_sas_phy_reset() local
576 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); in do_sas_phy_reset()
577 struct sas_internal *i = to_sas_internal(shost->transportt); in do_sas_phy_reset()
580 error = i->f->phy_reset(phy, hard_reset); in do_sas_phy_reset()
583 phy->enabled = 1; in do_sas_phy_reset()
609 sas_phy_simple_attr(identify.phy_identifier, phy_identifier, "%d\n", u8);
623 struct sas_phy *phy = dev_to_phy(dev); in sas_phy_setup() local
624 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); in sas_phy_setup()
625 struct sas_internal *i = to_sas_internal(shost->transportt); in sas_phy_setup()
627 if (i->f->phy_setup) in sas_phy_setup()
628 i->f->phy_setup(phy); in sas_phy_setup()
643 shost = dev_to_shost(dev->parent); in sas_phy_match()
645 if (!shost->transportt) in sas_phy_match()
647 if (shost->transportt->host_attrs.ac.class != in sas_phy_match()
651 i = to_sas_internal(shost->transportt); in sas_phy_match()
652 return &i->phy_attr_cont.ac == cont; in sas_phy_match()
657 struct sas_phy *phy = dev_to_phy(dev); in sas_phy_release() local
658 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); in sas_phy_release()
659 struct sas_internal *i = to_sas_internal(shost->transportt); in sas_phy_release()
661 if (i->f->phy_release) in sas_phy_release()
662 i->f->phy_release(phy); in sas_phy_release()
663 put_device(dev->parent); in sas_phy_release()
664 kfree(phy); in sas_phy_release()
668 * sas_phy_alloc - allocates and initialize a SAS PHY structure
670 * @number: Phy index
672 * Allocates an SAS PHY structure. It will be added in the device tree
677 * SAS PHY allocated or %NULL if the allocation failed.
682 struct sas_phy *phy; in sas_phy_alloc() local
684 phy = kzalloc(sizeof(*phy), GFP_KERNEL); in sas_phy_alloc()
685 if (!phy) in sas_phy_alloc()
688 phy->number = number; in sas_phy_alloc()
689 phy->enabled = 1; in sas_phy_alloc()
691 device_initialize(&phy->dev); in sas_phy_alloc()
692 phy->dev.parent = get_device(parent); in sas_phy_alloc()
693 phy->dev.release = sas_phy_release; in sas_phy_alloc()
694 INIT_LIST_HEAD(&phy->port_siblings); in sas_phy_alloc()
697 dev_set_name(&phy->dev, "phy-%d:%d:%d", shost->host_no, in sas_phy_alloc()
698 rphy->scsi_target_id, number); in sas_phy_alloc()
700 dev_set_name(&phy->dev, "phy-%d:%d", shost->host_no, number); in sas_phy_alloc()
702 transport_setup_device(&phy->dev); in sas_phy_alloc()
704 return phy; in sas_phy_alloc()
709 * sas_phy_add - add a SAS PHY to the device hierarchy
710 * @phy: The PHY to be added
712 * Publishes a SAS PHY to the rest of the system.
714 int sas_phy_add(struct sas_phy *phy) in sas_phy_add() argument
718 error = device_add(&phy->dev); in sas_phy_add()
720 transport_add_device(&phy->dev); in sas_phy_add()
721 transport_configure_device(&phy->dev); in sas_phy_add()
729 * sas_phy_free - free a SAS PHY
730 * @phy: SAS PHY to free
732 * Frees the specified SAS PHY.
735 * This function must only be called on a PHY that has not
738 void sas_phy_free(struct sas_phy *phy) in sas_phy_free() argument
740 transport_destroy_device(&phy->dev); in sas_phy_free()
741 put_device(&phy->dev); in sas_phy_free()
746 * sas_phy_delete - remove SAS PHY
747 * @phy: SAS PHY to remove
749 * Removes the specified SAS PHY. If the SAS PHY has an
750 * associated remote PHY it is removed before.
753 sas_phy_delete(struct sas_phy *phy) in sas_phy_delete() argument
755 struct device *dev = &phy->dev; in sas_phy_delete()
757 /* this happens if the phy is still part of a port when deleted */ in sas_phy_delete()
758 BUG_ON(!list_empty(&phy->port_siblings)); in sas_phy_delete()
768 * scsi_is_sas_phy - check if a struct device represents a SAS PHY
772 * %1 if the device represents a SAS PHY, %0 else
776 return dev->release == sas_phy_release; in scsi_is_sas_phy()
790 return snprintf(buf, 20, format_string, cast port->field); \
797 sas_port_simple_attr(num_phys, num_phys, "%d\n", int);
809 shost = dev_to_shost(dev->parent); in sas_port_match()
811 if (!shost->transportt) in sas_port_match()
813 if (shost->transportt->host_attrs.ac.class != in sas_port_match()
817 i = to_sas_internal(shost->transportt); in sas_port_match()
818 return &i->port_attr_cont.ac == cont; in sas_port_match()
826 BUG_ON(!list_empty(&port->phy_list)); in sas_port_release()
828 put_device(dev->parent); in sas_port_release()
833 struct sas_phy *phy) in sas_port_create_link() argument
837 res = sysfs_create_link(&port->dev.kobj, &phy->dev.kobj, in sas_port_create_link()
838 dev_name(&phy->dev)); in sas_port_create_link()
841 res = sysfs_create_link(&phy->dev.kobj, &port->dev.kobj, "port"); in sas_port_create_link()
846 printk(KERN_ERR "%s: Cannot create port links, err=%d\n", in sas_port_create_link()
851 struct sas_phy *phy) in sas_port_delete_link() argument
853 sysfs_remove_link(&port->dev.kobj, dev_name(&phy->dev)); in sas_port_delete_link()
854 sysfs_remove_link(&phy->dev.kobj, "port"); in sas_port_delete_link()
857 /** sas_port_alloc - allocate and initialize a SAS port structure
877 port->port_identifier = port_id; in sas_port_alloc()
879 device_initialize(&port->dev); in sas_port_alloc()
881 port->dev.parent = get_device(parent); in sas_port_alloc()
882 port->dev.release = sas_port_release; in sas_port_alloc()
884 mutex_init(&port->phy_list_mutex); in sas_port_alloc()
885 INIT_LIST_HEAD(&port->phy_list); in sas_port_alloc()
889 dev_set_name(&port->dev, "port-%d:%d:%d", shost->host_no, in sas_port_alloc()
890 rphy->scsi_target_id, port->port_identifier); in sas_port_alloc()
892 dev_set_name(&port->dev, "port-%d:%d", shost->host_no, in sas_port_alloc()
893 port->port_identifier); in sas_port_alloc()
895 transport_setup_device(&port->dev); in sas_port_alloc()
901 /** sas_port_alloc_num - allocate and initialize a SAS port structure
920 mutex_lock(&sas_host->lock); in sas_port_alloc_num()
925 index = exp->next_port_id++; in sas_port_alloc_num()
927 index = sas_host->next_port_id++; in sas_port_alloc_num()
928 mutex_unlock(&sas_host->lock); in sas_port_alloc_num()
934 * sas_port_add - add a SAS port to the device hierarchy
944 BUG_ON(!list_empty(&port->phy_list)); in sas_port_add()
946 error = device_add(&port->dev); in sas_port_add()
951 transport_add_device(&port->dev); in sas_port_add()
952 transport_configure_device(&port->dev); in sas_port_add()
959 * sas_port_free - free a SAS PORT
970 transport_destroy_device(&port->dev); in sas_port_free()
971 put_device(&port->dev); in sas_port_free()
976 * sas_port_delete - remove SAS PORT
984 struct device *dev = &port->dev; in sas_port_delete()
985 struct sas_phy *phy, *tmp_phy; in sas_port_delete() local
987 if (port->rphy) { in sas_port_delete()
988 sas_rphy_delete(port->rphy); in sas_port_delete()
989 port->rphy = NULL; in sas_port_delete()
992 mutex_lock(&port->phy_list_mutex); in sas_port_delete()
993 list_for_each_entry_safe(phy, tmp_phy, &port->phy_list, in sas_port_delete()
995 sas_port_delete_link(port, phy); in sas_port_delete()
996 list_del_init(&phy->port_siblings); in sas_port_delete()
998 mutex_unlock(&port->phy_list_mutex); in sas_port_delete()
1000 if (port->is_backlink) { in sas_port_delete()
1001 struct device *parent = port->dev.parent; in sas_port_delete()
1003 sysfs_remove_link(&port->dev.kobj, dev_name(parent)); in sas_port_delete()
1004 port->is_backlink = 0; in sas_port_delete()
1015 * scsi_is_sas_port - check if a struct device represents a SAS port
1023 return dev->release == sas_port_release; in scsi_is_sas_port()
1028 * sas_port_get_phy - try to take a reference on a port member
1033 struct sas_phy *phy; in sas_port_get_phy() local
1035 mutex_lock(&port->phy_list_mutex); in sas_port_get_phy()
1036 if (list_empty(&port->phy_list)) in sas_port_get_phy()
1037 phy = NULL; in sas_port_get_phy()
1039 struct list_head *ent = port->phy_list.next; in sas_port_get_phy()
1041 phy = list_entry(ent, typeof(*phy), port_siblings); in sas_port_get_phy()
1042 get_device(&phy->dev); in sas_port_get_phy()
1044 mutex_unlock(&port->phy_list_mutex); in sas_port_get_phy()
1046 return phy; in sas_port_get_phy()
1051 * sas_port_add_phy - add another phy to a port to form a wide port
1052 * @port: port to add the phy to
1053 * @phy: phy to add
1056 * ports must have at least one phy to operated, and all wide ports
1062 void sas_port_add_phy(struct sas_port *port, struct sas_phy *phy) in sas_port_add_phy() argument
1064 mutex_lock(&port->phy_list_mutex); in sas_port_add_phy()
1065 if (unlikely(!list_empty(&phy->port_siblings))) { in sas_port_add_phy()
1069 list_for_each_entry(tmp, &port->phy_list, port_siblings) in sas_port_add_phy()
1070 if (tmp == phy) in sas_port_add_phy()
1072 /* If this trips, you added a phy that was already in sas_port_add_phy()
1074 if (unlikely(tmp != phy)) { in sas_port_add_phy()
1075 …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()
1076 dev_name(&phy->dev)); in sas_port_add_phy()
1080 sas_port_create_link(port, phy); in sas_port_add_phy()
1081 list_add_tail(&phy->port_siblings, &port->phy_list); in sas_port_add_phy()
1082 port->num_phys++; in sas_port_add_phy()
1084 mutex_unlock(&port->phy_list_mutex); in sas_port_add_phy()
1089 * sas_port_delete_phy - remove a phy from a port or wide port
1090 * @port: port to remove the phy from
1091 * @phy: phy to remove
1096 void sas_port_delete_phy(struct sas_port *port, struct sas_phy *phy) in sas_port_delete_phy() argument
1098 mutex_lock(&port->phy_list_mutex); in sas_port_delete_phy()
1099 sas_port_delete_link(port, phy); in sas_port_delete_phy()
1100 list_del_init(&phy->port_siblings); in sas_port_delete_phy()
1101 port->num_phys--; in sas_port_delete_phy()
1102 mutex_unlock(&port->phy_list_mutex); in sas_port_delete_phy()
1109 struct device *parent = port->dev.parent->parent->parent; in sas_port_mark_backlink()
1111 if (port->is_backlink) in sas_port_mark_backlink()
1113 port->is_backlink = 1; in sas_port_mark_backlink()
1114 res = sysfs_create_link(&port->dev.kobj, &parent->kobj, in sas_port_mark_backlink()
1120 printk(KERN_ERR "%s: Cannot create port backlink, err=%d\n", in sas_port_mark_backlink()
1127 * SAS remote PHY attributes.
1137 return snprintf(buf, 20, format_string, cast rphy->field); \
1152 if (!rphy->field) \
1154 return get_sas_protocol_names(rphy->field, buf); \
1168 if (!rphy->identify.device_type) in show_sas_rphy_device_type()
1171 rphy->identify.device_type, buf); in show_sas_rphy_device_type()
1182 struct sas_phy *phy = dev_to_phy(rphy->dev.parent); in show_sas_rphy_enclosure_identifier() local
1183 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); in show_sas_rphy_enclosure_identifier()
1184 struct sas_internal *i = to_sas_internal(shost->transportt); in show_sas_rphy_enclosure_identifier()
1188 error = i->f->get_enclosure_identifier(rphy, &identifier); in show_sas_rphy_enclosure_identifier()
1202 struct sas_phy *phy = dev_to_phy(rphy->dev.parent); in show_sas_rphy_bay_identifier() local
1203 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); in show_sas_rphy_bay_identifier()
1204 struct sas_internal *i = to_sas_internal(shost->transportt); in show_sas_rphy_bay_identifier()
1207 val = i->f->get_bay_identifier(rphy); in show_sas_rphy_bay_identifier()
1210 return sprintf(buf, "%d\n", val); in show_sas_rphy_bay_identifier()
1221 sas_rphy_simple_attr(identify.phy_identifier, phy_identifier, "%d\n", u8);
1222 sas_rphy_simple_attr(scsi_target_id, scsi_target_id, "%d\n", u32);
1235 return -ENOMEM; in sas_read_port_mode_page()
1240 error = -EINVAL; in sas_read_port_mode_page()
1247 if (msdata - buffer > BUF_SIZE - 8) in sas_read_port_mode_page()
1252 rdev->ready_led_meaning = msdata[2] & 0x10 ? 1 : 0; in sas_read_port_mode_page()
1253 rdev->I_T_nexus_loss_timeout = (msdata[4] << 8) + msdata[5]; in sas_read_port_mode_page()
1254 rdev->initiator_response_timeout = (msdata[6] << 8) + msdata[7]; in sas_read_port_mode_page()
1273 return snprintf(buf, 20, format_string, cast rdev->field); \
1281 sas_end_dev_simple_attr(ready_led_meaning, ready_led_meaning, "%d\n", int);
1283 "%d\n", int);
1285 "%d\n", int);
1287 "%d\n", int);
1289 "%d\n", int);
1302 return snprintf(buf, 20, format_string, cast edev->field); \
1318 sas_expander_simple_attr(level, level, "%d\n", int);
1330 shost = dev_to_shost(dev->parent->parent); in sas_rphy_match()
1332 if (!shost->transportt) in sas_rphy_match()
1334 if (shost->transportt->host_attrs.ac.class != in sas_rphy_match()
1338 i = to_sas_internal(shost->transportt); in sas_rphy_match()
1339 return &i->rphy_attr_cont.ac == cont; in sas_rphy_match()
1351 shost = dev_to_shost(dev->parent->parent); in sas_end_dev_match()
1354 if (!shost->transportt) in sas_end_dev_match()
1356 if (shost->transportt->host_attrs.ac.class != in sas_end_dev_match()
1360 i = to_sas_internal(shost->transportt); in sas_end_dev_match()
1361 return &i->end_dev_attr_cont.ac == cont && in sas_end_dev_match()
1362 rphy->identify.device_type == SAS_END_DEVICE; in sas_end_dev_match()
1374 shost = dev_to_shost(dev->parent->parent); in sas_expander_match()
1377 if (!shost->transportt) in sas_expander_match()
1379 if (shost->transportt->host_attrs.ac.class != in sas_expander_match()
1383 i = to_sas_internal(shost->transportt); in sas_expander_match()
1384 return &i->expander_attr_cont.ac == cont && in sas_expander_match()
1385 (rphy->identify.device_type == SAS_EDGE_EXPANDER_DEVICE || in sas_expander_match()
1386 rphy->identify.device_type == SAS_FANOUT_EXPANDER_DEVICE); in sas_expander_match()
1394 put_device(dev->parent); in sas_expander_release()
1403 put_device(dev->parent); in sas_end_device_release()
1408 * sas_rphy_initialize - common rphy initialization
1416 INIT_LIST_HEAD(&rphy->list); in sas_rphy_initialize()
1420 * sas_end_device_alloc - allocate an rphy for an end device
1423 * Allocates an SAS remote PHY structure, connected to @parent.
1426 * SAS PHY allocated or %NULL if the allocation failed.
1430 struct Scsi_Host *shost = dev_to_shost(&parent->dev); in sas_end_device_alloc()
1438 device_initialize(&rdev->rphy.dev); in sas_end_device_alloc()
1439 rdev->rphy.dev.parent = get_device(&parent->dev); in sas_end_device_alloc()
1440 rdev->rphy.dev.release = sas_end_device_release; in sas_end_device_alloc()
1441 if (scsi_is_sas_expander_device(parent->dev.parent)) { in sas_end_device_alloc()
1442 struct sas_rphy *rphy = dev_to_rphy(parent->dev.parent); in sas_end_device_alloc()
1443 dev_set_name(&rdev->rphy.dev, "end_device-%d:%d:%d", in sas_end_device_alloc()
1444 shost->host_no, rphy->scsi_target_id, in sas_end_device_alloc()
1445 parent->port_identifier); in sas_end_device_alloc()
1447 dev_set_name(&rdev->rphy.dev, "end_device-%d:%d", in sas_end_device_alloc()
1448 shost->host_no, parent->port_identifier); in sas_end_device_alloc()
1449 rdev->rphy.identify.device_type = SAS_END_DEVICE; in sas_end_device_alloc()
1450 sas_rphy_initialize(&rdev->rphy); in sas_end_device_alloc()
1451 transport_setup_device(&rdev->rphy.dev); in sas_end_device_alloc()
1453 return &rdev->rphy; in sas_end_device_alloc()
1458 * sas_expander_alloc - allocate an rphy for an end device
1462 * Allocates an SAS remote PHY structure, connected to @parent.
1465 * SAS PHY allocated or %NULL if the allocation failed.
1470 struct Scsi_Host *shost = dev_to_shost(&parent->dev); in sas_expander_alloc()
1482 device_initialize(&rdev->rphy.dev); in sas_expander_alloc()
1483 rdev->rphy.dev.parent = get_device(&parent->dev); in sas_expander_alloc()
1484 rdev->rphy.dev.release = sas_expander_release; in sas_expander_alloc()
1485 mutex_lock(&sas_host->lock); in sas_expander_alloc()
1486 rdev->rphy.scsi_target_id = sas_host->next_expander_id++; in sas_expander_alloc()
1487 mutex_unlock(&sas_host->lock); in sas_expander_alloc()
1488 dev_set_name(&rdev->rphy.dev, "expander-%d:%d", in sas_expander_alloc()
1489 shost->host_no, rdev->rphy.scsi_target_id); in sas_expander_alloc()
1490 rdev->rphy.identify.device_type = type; in sas_expander_alloc()
1491 sas_rphy_initialize(&rdev->rphy); in sas_expander_alloc()
1492 transport_setup_device(&rdev->rphy.dev); in sas_expander_alloc()
1494 return &rdev->rphy; in sas_expander_alloc()
1499 * sas_rphy_add - add a SAS remote PHY to the device hierarchy
1500 * @rphy: The remote PHY to be added
1502 * Publishes a SAS remote PHY to the rest of the system.
1506 struct sas_port *parent = dev_to_sas_port(rphy->dev.parent); in sas_rphy_add()
1507 struct Scsi_Host *shost = dev_to_shost(parent->dev.parent); in sas_rphy_add()
1509 struct sas_identify *identify = &rphy->identify; in sas_rphy_add()
1512 if (parent->rphy) in sas_rphy_add()
1513 return -ENXIO; in sas_rphy_add()
1514 parent->rphy = rphy; in sas_rphy_add()
1516 error = device_add(&rphy->dev); in sas_rphy_add()
1519 transport_add_device(&rphy->dev); in sas_rphy_add()
1520 transport_configure_device(&rphy->dev); in sas_rphy_add()
1522 printk("fail to a bsg device %s\n", dev_name(&rphy->dev)); in sas_rphy_add()
1525 mutex_lock(&sas_host->lock); in sas_rphy_add()
1526 list_add_tail(&rphy->list, &sas_host->rphy_list); in sas_rphy_add()
1527 if (identify->device_type == SAS_END_DEVICE && in sas_rphy_add()
1528 (identify->target_port_protocols & in sas_rphy_add()
1530 rphy->scsi_target_id = sas_host->next_target_id++; in sas_rphy_add()
1531 else if (identify->device_type == SAS_END_DEVICE) in sas_rphy_add()
1532 rphy->scsi_target_id = -1; in sas_rphy_add()
1533 mutex_unlock(&sas_host->lock); in sas_rphy_add()
1535 if (identify->device_type == SAS_END_DEVICE && in sas_rphy_add()
1536 rphy->scsi_target_id != -1) { in sas_rphy_add()
1539 if (identify->target_port_protocols & SAS_PROTOCOL_SSP) in sas_rphy_add()
1544 scsi_scan_target(&rphy->dev, 0, rphy->scsi_target_id, lun, in sas_rphy_add()
1553 * sas_rphy_free - free a SAS remote PHY
1554 * @rphy: SAS remote PHY to free
1556 * Frees the specified SAS remote PHY.
1560 * PHY that has not successfully been added using
1561 * sas_rphy_add() (or has been sas_rphy_remove()'d)
1565 struct device *dev = &rphy->dev; in sas_rphy_free()
1566 struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent); in sas_rphy_free()
1569 mutex_lock(&sas_host->lock); in sas_rphy_free()
1570 list_del(&rphy->list); in sas_rphy_free()
1571 mutex_unlock(&sas_host->lock); in sas_rphy_free()
1580 * sas_rphy_delete - remove and free SAS remote PHY
1581 * @rphy: SAS remote PHY to remove and free
1583 * Removes the specified SAS remote PHY and frees it.
1594 * sas_rphy_unlink - unlink SAS remote PHY
1595 * @rphy: SAS remote phy to unlink from its parent port
1601 struct sas_port *parent = dev_to_sas_port(rphy->dev.parent); in sas_rphy_unlink()
1603 parent->rphy = NULL; in sas_rphy_unlink()
1608 * sas_rphy_remove - remove SAS remote PHY
1609 * @rphy: SAS remote phy to remove
1611 * Removes the specified SAS remote PHY.
1616 struct device *dev = &rphy->dev; in sas_rphy_remove()
1618 switch (rphy->identify.device_type) { in sas_rphy_remove()
1631 bsg_remove_queue(rphy->q); in sas_rphy_remove()
1638 * scsi_is_sas_rphy - check if a struct device represents a SAS remote PHY
1642 * %1 if the device represents a SAS remote PHY, %0 else
1646 return dev->release == sas_end_device_release || in scsi_is_sas_rphy()
1647 dev->release == sas_expander_release; in scsi_is_sas_rphy()
1662 mutex_lock(&sas_host->lock); in sas_user_scan()
1663 list_for_each_entry(rphy, &sas_host->rphy_list, list) { in sas_user_scan()
1664 if (rphy->identify.device_type != SAS_END_DEVICE || in sas_user_scan()
1665 rphy->scsi_target_id == -1) in sas_user_scan()
1669 (id == SCAN_WILD_CARD || id == rphy->scsi_target_id)) { in sas_user_scan()
1670 scsi_scan_target(&rphy->dev, 0, rphy->scsi_target_id, in sas_user_scan()
1674 mutex_unlock(&sas_host->lock); in sas_user_scan()
1685 i->private_##attrb[count] = dev_attr_##field; \
1686 i->private_##attrb[count].attr.mode = perm; \
1687 i->attrb[count] = &i->private_##attrb[count]; \
1692 i->private_##attrb[count] = dev_attr_##field; \
1693 i->private_##attrb[count].attr.mode = perm; \
1695 i->private_##attrb[count].attr.mode = ro_perm; \
1696 i->private_##attrb[count].store = NULL; \
1698 i->attrb[count] = &i->private_##attrb[count]; \
1706 SETUP_TEMPLATE(rphy_attrs, field, S_IRUGO, i->f->func)
1713 !i->f->set_phy_speed, S_IRUGO)
1717 !i->f->func, S_IRUGO)
1723 SETUP_TEMPLATE(phy_attrs, field, S_IRUGO, i->f->func)
1729 SETUP_TEMPLATE(phy_attrs, field, S_IWUSR, i->f->func)
1738 * sas_attach_transport - instantiate SAS transport template
1751 i->t.user_scan = sas_user_scan; in sas_attach_transport()
1753 i->t.host_attrs.ac.attrs = &i->host_attrs[0]; in sas_attach_transport()
1754 i->t.host_attrs.ac.class = &sas_host_class.class; in sas_attach_transport()
1755 i->t.host_attrs.ac.match = sas_host_match; in sas_attach_transport()
1756 transport_container_register(&i->t.host_attrs); in sas_attach_transport()
1757 i->t.host_size = sizeof(struct sas_host_attrs); in sas_attach_transport()
1759 i->phy_attr_cont.ac.class = &sas_phy_class.class; in sas_attach_transport()
1760 i->phy_attr_cont.ac.attrs = &i->phy_attrs[0]; in sas_attach_transport()
1761 i->phy_attr_cont.ac.match = sas_phy_match; in sas_attach_transport()
1762 transport_container_register(&i->phy_attr_cont); in sas_attach_transport()
1764 i->port_attr_cont.ac.class = &sas_port_class.class; in sas_attach_transport()
1765 i->port_attr_cont.ac.attrs = &i->port_attrs[0]; in sas_attach_transport()
1766 i->port_attr_cont.ac.match = sas_port_match; in sas_attach_transport()
1767 transport_container_register(&i->port_attr_cont); in sas_attach_transport()
1769 i->rphy_attr_cont.ac.class = &sas_rphy_class.class; in sas_attach_transport()
1770 i->rphy_attr_cont.ac.attrs = &i->rphy_attrs[0]; in sas_attach_transport()
1771 i->rphy_attr_cont.ac.match = sas_rphy_match; in sas_attach_transport()
1772 transport_container_register(&i->rphy_attr_cont); in sas_attach_transport()
1774 i->end_dev_attr_cont.ac.class = &sas_end_dev_class.class; in sas_attach_transport()
1775 i->end_dev_attr_cont.ac.attrs = &i->end_dev_attrs[0]; in sas_attach_transport()
1776 i->end_dev_attr_cont.ac.match = sas_end_dev_match; in sas_attach_transport()
1777 transport_container_register(&i->end_dev_attr_cont); in sas_attach_transport()
1779 i->expander_attr_cont.ac.class = &sas_expander_class.class; in sas_attach_transport()
1780 i->expander_attr_cont.ac.attrs = &i->expander_attrs[0]; in sas_attach_transport()
1781 i->expander_attr_cont.ac.match = sas_expander_match; in sas_attach_transport()
1782 transport_container_register(&i->expander_attr_cont); in sas_attach_transport()
1784 i->f = ft; in sas_attach_transport()
1805 i->phy_attrs[count] = NULL; in sas_attach_transport()
1809 i->port_attrs[count] = NULL; in sas_attach_transport()
1822 i->rphy_attrs[count] = NULL; in sas_attach_transport()
1830 i->end_dev_attrs[count] = NULL; in sas_attach_transport()
1840 i->expander_attrs[count] = NULL; in sas_attach_transport()
1842 return &i->t; in sas_attach_transport()
1847 * sas_release_transport - release SAS transport template instance
1854 transport_container_unregister(&i->t.host_attrs); in sas_release_transport()
1855 transport_container_unregister(&i->phy_attr_cont); in sas_release_transport()
1856 transport_container_unregister(&i->port_attr_cont); in sas_release_transport()
1857 transport_container_unregister(&i->rphy_attr_cont); in sas_release_transport()
1858 transport_container_unregister(&i->end_dev_attr_cont); in sas_release_transport()
1859 transport_container_unregister(&i->expander_attr_cont); in sas_release_transport()