Lines Matching +full:port +full:- +full:expander

1 // SPDX-License-Identifier: GPL-2.0
3 * Serial Attached SCSI (SAS) Expander discovery and configuration
29 static void sas_port_add_ex_phy(struct sas_port *port, struct ex_phy *ex_phy) in sas_port_add_ex_phy() argument
31 sas_port_add_phy(port, ex_phy->phy); in sas_port_add_ex_phy()
32 ex_phy->port = port; in sas_port_add_ex_phy()
33 ex_phy->phy_state = PHY_DEVICE_DISCOVERED; in sas_port_add_ex_phy()
38 struct expander_device *ex = &dev->ex_dev; in sas_ex_add_parent_port()
39 struct ex_phy *ex_phy = &ex->ex_phy[phy_id]; in sas_ex_add_parent_port()
41 if (!ex->parent_port) { in sas_ex_add_parent_port()
42 ex->parent_port = sas_port_alloc(&dev->rphy->dev, phy_id); in sas_ex_add_parent_port()
44 BUG_ON(!ex->parent_port); in sas_ex_add_parent_port()
45 BUG_ON(sas_port_add(ex->parent_port)); in sas_ex_add_parent_port()
46 sas_port_mark_backlink(ex->parent_port); in sas_ex_add_parent_port()
48 sas_port_add_ex_phy(ex->parent_port, ex_phy); in sas_ex_add_parent_port()
51 /* ---------- SMP task management ---------- */
62 to_sas_internal(dev->port->ha->shost->transportt); in smp_execute_task_sg()
63 struct sas_ha_struct *ha = dev->port->ha; in smp_execute_task_sg()
65 pm_runtime_get_sync(ha->dev); in smp_execute_task_sg()
66 mutex_lock(&dev->ex_dev.cmd_mutex); in smp_execute_task_sg()
68 if (test_bit(SAS_DEV_GONE, &dev->state)) { in smp_execute_task_sg()
69 res = -ECOMM; in smp_execute_task_sg()
75 res = -ENOMEM; in smp_execute_task_sg()
78 task->dev = dev; in smp_execute_task_sg()
79 task->task_proto = dev->tproto; in smp_execute_task_sg()
80 task->smp_task.smp_req = *req; in smp_execute_task_sg()
81 task->smp_task.smp_resp = *resp; in smp_execute_task_sg()
83 task->task_done = sas_task_internal_done; in smp_execute_task_sg()
85 task->slow_task->timer.function = sas_task_internal_timedout; in smp_execute_task_sg()
86 task->slow_task->timer.expires = jiffies + SMP_TIMEOUT*HZ; in smp_execute_task_sg()
87 add_timer(&task->slow_task->timer); in smp_execute_task_sg()
89 res = i->dft->lldd_execute_task(task, GFP_KERNEL); in smp_execute_task_sg()
92 del_timer_sync(&task->slow_task->timer); in smp_execute_task_sg()
97 wait_for_completion(&task->slow_task->completion); in smp_execute_task_sg()
98 res = -ECOMM; in smp_execute_task_sg()
99 if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) { in smp_execute_task_sg()
101 i->dft->lldd_abort_task(task); in smp_execute_task_sg()
102 if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) { in smp_execute_task_sg()
107 if (task->task_status.resp == SAS_TASK_COMPLETE && in smp_execute_task_sg()
108 task->task_status.stat == SAS_SAM_STAT_GOOD) { in smp_execute_task_sg()
112 if (task->task_status.resp == SAS_TASK_COMPLETE && in smp_execute_task_sg()
113 task->task_status.stat == SAS_DATA_UNDERRUN) { in smp_execute_task_sg()
116 res = task->task_status.residual; in smp_execute_task_sg()
119 if (task->task_status.resp == SAS_TASK_COMPLETE && in smp_execute_task_sg()
120 task->task_status.stat == SAS_DATA_OVERRUN) { in smp_execute_task_sg()
121 res = -EMSGSIZE; in smp_execute_task_sg()
124 if (task->task_status.resp == SAS_TASK_UNDELIVERED && in smp_execute_task_sg()
125 task->task_status.stat == SAS_DEVICE_UNKNOWN) in smp_execute_task_sg()
130 SAS_ADDR(dev->sas_addr), in smp_execute_task_sg()
131 task->task_status.resp, in smp_execute_task_sg()
132 task->task_status.stat); in smp_execute_task_sg()
137 mutex_unlock(&dev->ex_dev.cmd_mutex); in smp_execute_task_sg()
138 pm_runtime_put_sync(ha->dev); in smp_execute_task_sg()
156 /* ---------- Allocations ---------- */
173 switch (phy->routing_attr) { in sas_route_char()
175 if (dev->ex_dev.t2t_supp) in sas_route_char()
191 * FIS as described in section J.5 of sas-2 r16 in to_dev_type()
193 if (dr->attached_dev_type == SAS_PHY_UNUSED && dr->attached_sata_dev && in to_dev_type()
194 dr->linkrate >= SAS_LINK_RATE_1_5_GBPS) in to_dev_type()
197 return dr->attached_dev_type; in to_dev_type()
206 struct discover_resp *dr = &disc_resp->disc; in sas_set_ex_phy()
207 struct sas_ha_struct *ha = dev->port->ha; in sas_set_ex_phy()
208 struct expander_device *ex = &dev->ex_dev; in sas_set_ex_phy()
209 struct ex_phy *phy = &ex->ex_phy[phy_id]; in sas_set_ex_phy()
210 struct sas_rphy *rphy = dev->rphy; in sas_set_ex_phy()
211 bool new_phy = !phy->phy; in sas_set_ex_phy()
215 if (WARN_ON_ONCE(test_bit(SAS_HA_ATA_EH_ACTIVE, &ha->state))) in sas_set_ex_phy()
217 phy->phy = sas_phy_alloc(&rphy->dev, phy_id); in sas_set_ex_phy()
220 BUG_ON(!phy->phy); in sas_set_ex_phy()
223 switch (disc_resp->result) { in sas_set_ex_phy()
225 phy->phy_state = PHY_VACANT; in sas_set_ex_phy()
228 phy->phy_state = PHY_NOT_PRESENT; in sas_set_ex_phy()
231 phy->phy_state = PHY_EMPTY; /* do not know yet */ in sas_set_ex_phy()
236 dev_type = phy->attached_dev_type; in sas_set_ex_phy()
237 linkrate = phy->linkrate; in sas_set_ex_phy()
238 memcpy(sas_addr, phy->attached_sas_addr, SAS_ADDR_SIZE); in sas_set_ex_phy()
240 /* Handle vacant phy - rest of dr data is not valid so skip it */ in sas_set_ex_phy()
241 if (phy->phy_state == PHY_VACANT) { in sas_set_ex_phy()
242 memset(phy->attached_sas_addr, 0, SAS_ADDR_SIZE); in sas_set_ex_phy()
243 phy->attached_dev_type = SAS_PHY_UNUSED; in sas_set_ex_phy()
244 if (!test_bit(SAS_HA_ATA_EH_ACTIVE, &ha->state)) { in sas_set_ex_phy()
245 phy->phy_id = phy_id; in sas_set_ex_phy()
251 phy->attached_dev_type = to_dev_type(dr); in sas_set_ex_phy()
252 if (test_bit(SAS_HA_ATA_EH_ACTIVE, &ha->state)) in sas_set_ex_phy()
254 phy->phy_id = phy_id; in sas_set_ex_phy()
255 phy->linkrate = dr->linkrate; in sas_set_ex_phy()
256 phy->attached_sata_host = dr->attached_sata_host; in sas_set_ex_phy()
257 phy->attached_sata_dev = dr->attached_sata_dev; in sas_set_ex_phy()
258 phy->attached_sata_ps = dr->attached_sata_ps; in sas_set_ex_phy()
259 phy->attached_iproto = dr->iproto << 1; in sas_set_ex_phy()
260 phy->attached_tproto = dr->tproto << 1; in sas_set_ex_phy()
264 if (phy->attached_dev_type == SAS_PHY_UNUSED) in sas_set_ex_phy()
265 memset(phy->attached_sas_addr, 0, SAS_ADDR_SIZE); in sas_set_ex_phy()
267 memcpy(phy->attached_sas_addr, dr->attached_sas_addr, SAS_ADDR_SIZE); in sas_set_ex_phy()
268 phy->attached_phy_id = dr->attached_phy_id; in sas_set_ex_phy()
269 phy->phy_change_count = dr->change_count; in sas_set_ex_phy()
270 phy->routing_attr = dr->routing_attr; in sas_set_ex_phy()
271 phy->virtual = dr->virtual; in sas_set_ex_phy()
272 phy->last_da_index = -1; in sas_set_ex_phy()
274 phy->phy->identify.sas_address = SAS_ADDR(phy->attached_sas_addr); in sas_set_ex_phy()
275 phy->phy->identify.device_type = dr->attached_dev_type; in sas_set_ex_phy()
276 phy->phy->identify.initiator_port_protocols = phy->attached_iproto; in sas_set_ex_phy()
277 phy->phy->identify.target_port_protocols = phy->attached_tproto; in sas_set_ex_phy()
278 if (!phy->attached_tproto && dr->attached_sata_dev) in sas_set_ex_phy()
279 phy->phy->identify.target_port_protocols = SAS_PROTOCOL_SATA; in sas_set_ex_phy()
280 phy->phy->identify.phy_identifier = phy_id; in sas_set_ex_phy()
281 phy->phy->minimum_linkrate_hw = dr->hmin_linkrate; in sas_set_ex_phy()
282 phy->phy->maximum_linkrate_hw = dr->hmax_linkrate; in sas_set_ex_phy()
283 phy->phy->minimum_linkrate = dr->pmin_linkrate; in sas_set_ex_phy()
284 phy->phy->maximum_linkrate = dr->pmax_linkrate; in sas_set_ex_phy()
285 phy->phy->negotiated_linkrate = phy->linkrate; in sas_set_ex_phy()
286 phy->phy->enabled = (phy->linkrate != SAS_PHY_DISABLED); in sas_set_ex_phy()
290 if (sas_phy_add(phy->phy)) { in sas_set_ex_phy()
291 sas_phy_free(phy->phy); in sas_set_ex_phy()
296 switch (phy->attached_dev_type) { in sas_set_ex_phy()
304 if (phy->attached_iproto) { in sas_set_ex_phy()
305 if (phy->attached_tproto) in sas_set_ex_phy()
310 if (dr->attached_sata_dev) in sas_set_ex_phy()
327 if (new_phy || phy->attached_dev_type != dev_type || in sas_set_ex_phy()
328 phy->linkrate != linkrate || in sas_set_ex_phy()
329 SAS_ADDR(phy->attached_sas_addr) != SAS_ADDR(sas_addr)) in sas_set_ex_phy()
338 if (test_bit(SAS_HA_ATA_EH_ACTIVE, &ha->state)) in sas_set_ex_phy()
339 set_bit(DISCE_REVALIDATE_DOMAIN, &dev->port->disc.pending); in sas_set_ex_phy()
342 test_bit(SAS_HA_ATA_EH_ACTIVE, &ha->state) ? "ata: " : "", in sas_set_ex_phy()
343 SAS_ADDR(dev->sas_addr), phy->phy_id, in sas_set_ex_phy()
344 sas_route_char(dev, phy), phy->linkrate, in sas_set_ex_phy()
345 SAS_ADDR(phy->attached_sas_addr), type); in sas_set_ex_phy()
348 /* check if we have an existing attached ata device on this expander phy */
351 struct ex_phy *ex_phy = &ex_dev->ex_dev.ex_phy[phy_id]; in sas_ex_to_ata()
355 if (!ex_phy->port) in sas_ex_to_ata()
358 rphy = ex_phy->port->rphy; in sas_ex_to_ata()
377 struct discover_resp *dr = &disc_resp->disc; in sas_ex_phy_discover_helper()
386 if (memcmp(dev->sas_addr, dr->attached_sas_addr, SAS_ADDR_SIZE) == 0) { in sas_ex_phy_discover_helper()
396 struct expander_device *ex = &dev->ex_dev; in sas_ex_phy_discover()
403 return -ENOMEM; in sas_ex_phy_discover()
408 return -ENOMEM; in sas_ex_phy_discover()
413 if (0 <= single && single < ex->num_phys) { in sas_ex_phy_discover()
418 for (i = 0; i < ex->num_phys; i++) { in sas_ex_phy_discover()
433 struct expander_device *ex = &dev->ex_dev; in sas_expander_discover()
436 ex->ex_phy = kcalloc(ex->num_phys, sizeof(*ex->ex_phy), GFP_KERNEL); in sas_expander_discover()
437 if (!ex->ex_phy) in sas_expander_discover()
438 return -ENOMEM; in sas_expander_discover()
440 res = sas_ex_phy_discover(dev, -1); in sas_expander_discover()
446 kfree(ex->ex_phy); in sas_expander_discover()
447 ex->ex_phy = NULL; in sas_expander_discover()
466 return -ENOMEM; in sas_ex_general()
471 return -ENOMEM; in sas_ex_general()
482 SAS_ADDR(dev->sas_addr), res); in sas_ex_general()
484 } else if (rg_resp->result != SMP_RESP_FUNC_ACC) { in sas_ex_general()
486 SAS_ADDR(dev->sas_addr), rg_resp->result); in sas_ex_general()
487 res = rg_resp->result; in sas_ex_general()
491 rg = &rg_resp->rg; in sas_ex_general()
492 dev->ex_dev.ex_change_count = be16_to_cpu(rg->change_count); in sas_ex_general()
493 dev->ex_dev.max_route_indexes = be16_to_cpu(rg->route_indexes); in sas_ex_general()
494 dev->ex_dev.num_phys = min(rg->num_phys, (u8)MAX_EXPANDER_PHYS); in sas_ex_general()
495 dev->ex_dev.t2t_supp = rg->t2t_supp; in sas_ex_general()
496 dev->ex_dev.conf_route_table = rg->conf_route_table; in sas_ex_general()
497 dev->ex_dev.configuring = rg->configuring; in sas_ex_general()
498 memcpy(dev->ex_dev.enclosure_logical_id, in sas_ex_general()
499 rg->enclosure_logical_id, 8); in sas_ex_general()
501 if (dev->ex_dev.configuring) { in sas_ex_general()
502 pr_debug("RG: ex %016llx self-configuring...\n", in sas_ex_general()
503 SAS_ADDR(dev->sas_addr)); in sas_ex_general()
518 struct sas_rphy *rphy = dev->rphy; in ex_assign_manuf_info()
521 memcpy(edev->vendor_id, mi_resp + 12, SAS_EXPANDER_VENDOR_ID_LEN); in ex_assign_manuf_info()
522 memcpy(edev->product_id, mi_resp + 20, SAS_EXPANDER_PRODUCT_ID_LEN); in ex_assign_manuf_info()
523 memcpy(edev->product_rev, mi_resp + 36, in ex_assign_manuf_info()
527 memcpy(edev->component_vendor_id, mi_resp + 40, in ex_assign_manuf_info()
529 edev->component_id = mi_resp[48] << 8 | mi_resp[49]; in ex_assign_manuf_info()
530 edev->component_revision_id = mi_resp[50]; in ex_assign_manuf_info()
545 return -ENOMEM; in sas_ex_manuf_info()
550 return -ENOMEM; in sas_ex_manuf_info()
558 SAS_ADDR(dev->sas_addr), res); in sas_ex_manuf_info()
562 SAS_ADDR(dev->sas_addr), mi_resp[2]); in sas_ex_manuf_info()
586 return -ENOMEM; in sas_smp_phy_control()
591 return -ENOMEM; in sas_smp_phy_control()
598 pc_req[32] = rates->minimum_linkrate << 4; in sas_smp_phy_control()
599 pc_req[33] = rates->maximum_linkrate << 4; in sas_smp_phy_control()
605 SAS_ADDR(dev->sas_addr), phy_id, res); in sas_smp_phy_control()
608 SAS_ADDR(dev->sas_addr), phy_id, pc_resp[2]); in sas_smp_phy_control()
618 struct expander_device *ex = &dev->ex_dev; in sas_ex_disable_phy()
619 struct ex_phy *phy = &ex->ex_phy[phy_id]; in sas_ex_disable_phy()
622 phy->linkrate = SAS_PHY_DISABLED; in sas_ex_disable_phy()
627 struct expander_device *ex = &dev->ex_dev; in sas_ex_disable_port()
630 for (i = 0; i < ex->num_phys; i++) { in sas_ex_disable_port()
631 struct ex_phy *phy = &ex->ex_phy[i]; in sas_ex_disable_port()
633 if (phy->phy_state == PHY_VACANT || in sas_ex_disable_port()
634 phy->phy_state == PHY_NOT_PRESENT) in sas_ex_disable_port()
637 if (SAS_ADDR(phy->attached_sas_addr) == SAS_ADDR(sas_addr)) in sas_ex_disable_port()
642 static int sas_dev_present_in_domain(struct asd_sas_port *port, in sas_dev_present_in_domain() argument
647 if (SAS_ADDR(port->sas_addr) == SAS_ADDR(sas_addr)) in sas_dev_present_in_domain()
649 list_for_each_entry(dev, &port->dev_list, dev_list_node) { in sas_dev_present_in_domain()
650 if (SAS_ADDR(dev->sas_addr) == SAS_ADDR(sas_addr)) in sas_dev_present_in_domain()
663 struct sas_rphy *rphy = dev_to_rphy(phy->dev.parent); in sas_smp_get_phy_events()
668 return -ENOMEM; in sas_smp_get_phy_events()
673 return -ENOMEM; in sas_smp_get_phy_events()
677 req[9] = phy->number; in sas_smp_get_phy_events()
685 phy->invalid_dword_count = get_unaligned_be32(&resp[12]); in sas_smp_get_phy_events()
686 phy->running_disparity_error_count = get_unaligned_be32(&resp[16]); in sas_smp_get_phy_events()
687 phy->loss_of_dword_sync_count = get_unaligned_be32(&resp[20]); in sas_smp_get_phy_events()
688 phy->phy_reset_problem_count = get_unaligned_be32(&resp[24]); in sas_smp_get_phy_events()
710 return -ENOMEM; in sas_get_report_phy_sata()
719 * standards cockup here. sas-2 explicitly specifies the FIS in sas_get_report_phy_sata()
747 struct expander_device *parent_ex = &parent->ex_dev; in sas_ex_get_linkrate()
748 struct sas_port *port; in sas_ex_get_linkrate() local
751 child->pathways = 0; in sas_ex_get_linkrate()
753 port = parent_phy->port; in sas_ex_get_linkrate()
755 for (i = 0; i < parent_ex->num_phys; i++) { in sas_ex_get_linkrate()
756 struct ex_phy *phy = &parent_ex->ex_phy[i]; in sas_ex_get_linkrate()
758 if (phy->phy_state == PHY_VACANT || in sas_ex_get_linkrate()
759 phy->phy_state == PHY_NOT_PRESENT) in sas_ex_get_linkrate()
763 child->min_linkrate = min(parent->min_linkrate, in sas_ex_get_linkrate()
764 phy->linkrate); in sas_ex_get_linkrate()
765 child->max_linkrate = max(parent->max_linkrate, in sas_ex_get_linkrate()
766 phy->linkrate); in sas_ex_get_linkrate()
767 child->pathways++; in sas_ex_get_linkrate()
768 sas_port_add_phy(port, phy->phy); in sas_ex_get_linkrate()
771 child->linkrate = min(parent_phy->linkrate, child->max_linkrate); in sas_ex_get_linkrate()
772 child->pathways = min(child->pathways, parent->pathways); in sas_ex_get_linkrate()
781 child->dev_type = SAS_END_DEVICE; in sas_ex_add_dev()
782 rphy = sas_end_device_alloc(phy->port); in sas_ex_add_dev()
784 return -ENOMEM; in sas_ex_add_dev()
786 child->tproto = phy->attached_tproto; in sas_ex_add_dev()
789 child->rphy = rphy; in sas_ex_add_dev()
790 get_device(&rphy->dev); in sas_ex_add_dev()
791 rphy->identify.phy_identifier = phy_id; in sas_ex_add_dev()
794 list_add_tail(&child->disco_list_node, &parent->port->disco_list); in sas_ex_add_dev()
799 SAS_ADDR(child->sas_addr), in sas_ex_add_dev()
800 SAS_ADDR(parent->sas_addr), phy_id, res); in sas_ex_add_dev()
801 sas_rphy_free(child->rphy); in sas_ex_add_dev()
802 list_del(&child->disco_list_node); in sas_ex_add_dev()
812 struct expander_device *parent_ex = &parent->ex_dev; in sas_ex_discover_end_dev()
813 struct ex_phy *phy = &parent_ex->ex_phy[phy_id]; in sas_ex_discover_end_dev()
817 if (phy->attached_sata_host || phy->attached_sata_ps) in sas_ex_discover_end_dev()
824 kref_get(&parent->kref); in sas_ex_discover_end_dev()
825 child->parent = parent; in sas_ex_discover_end_dev()
826 child->port = parent->port; in sas_ex_discover_end_dev()
827 child->iproto = phy->attached_iproto; in sas_ex_discover_end_dev()
828 memcpy(child->sas_addr, phy->attached_sas_addr, SAS_ADDR_SIZE); in sas_ex_discover_end_dev()
829 sas_hash_addr(child->hashed_sas_addr, child->sas_addr); in sas_ex_discover_end_dev()
830 if (!phy->port) { in sas_ex_discover_end_dev()
831 phy->port = sas_port_alloc(&parent->rphy->dev, phy_id); in sas_ex_discover_end_dev()
832 if (unlikely(!phy->port)) in sas_ex_discover_end_dev()
834 if (unlikely(sas_port_add(phy->port) != 0)) { in sas_ex_discover_end_dev()
835 sas_port_free(phy->port); in sas_ex_discover_end_dev()
840 sas_device_set_phy(child, phy->port); in sas_ex_discover_end_dev()
842 if ((phy->attached_tproto & SAS_PROTOCOL_STP) || phy->attached_sata_dev) { in sas_ex_discover_end_dev()
844 } else if (phy->attached_tproto & SAS_PROTOCOL_SSP) { in sas_ex_discover_end_dev()
848 phy->attached_tproto, SAS_ADDR(parent->sas_addr), in sas_ex_discover_end_dev()
850 res = -ENODEV; in sas_ex_discover_end_dev()
856 list_add_tail(&child->siblings, &parent_ex->children); in sas_ex_discover_end_dev()
860 sas_port_delete(phy->port); in sas_ex_discover_end_dev()
862 phy->port = NULL; in sas_ex_discover_end_dev()
867 /* See if this phy is part of a wide port */
870 struct ex_phy *phy = &parent->ex_dev.ex_phy[phy_id]; in sas_ex_join_wide_port()
873 for (i = 0; i < parent->ex_dev.num_phys; i++) { in sas_ex_join_wide_port()
874 struct ex_phy *ephy = &parent->ex_dev.ex_phy[i]; in sas_ex_join_wide_port()
879 if (!memcmp(phy->attached_sas_addr, ephy->attached_sas_addr, in sas_ex_join_wide_port()
880 SAS_ADDR_SIZE) && ephy->port) { in sas_ex_join_wide_port()
881 sas_port_add_ex_phy(ephy->port, phy); in sas_ex_join_wide_port()
892 struct sas_expander_device *parent_ex = rphy_to_expander_device(parent->rphy); in sas_ex_discover_expander()
893 struct ex_phy *phy = &parent->ex_dev.ex_phy[phy_id]; in sas_ex_discover_expander()
897 struct asd_sas_port *port; in sas_ex_discover_expander() local
900 if (phy->routing_attr == DIRECT_ROUTING) { in sas_ex_discover_expander()
901 pr_warn("ex %016llx:%02d:D <--> ex %016llx:0x%x is not allowed\n", in sas_ex_discover_expander()
902 SAS_ADDR(parent->sas_addr), phy_id, in sas_ex_discover_expander()
903 SAS_ADDR(phy->attached_sas_addr), in sas_ex_discover_expander()
904 phy->attached_phy_id); in sas_ex_discover_expander()
911 phy->port = sas_port_alloc(&parent->rphy->dev, phy_id); in sas_ex_discover_expander()
913 BUG_ON(sas_port_add(phy->port) != 0); in sas_ex_discover_expander()
916 switch (phy->attached_dev_type) { in sas_ex_discover_expander()
918 rphy = sas_expander_alloc(phy->port, in sas_ex_discover_expander()
922 rphy = sas_expander_alloc(phy->port, in sas_ex_discover_expander()
929 port = parent->port; in sas_ex_discover_expander()
930 child->rphy = rphy; in sas_ex_discover_expander()
931 get_device(&rphy->dev); in sas_ex_discover_expander()
933 child->dev_type = phy->attached_dev_type; in sas_ex_discover_expander()
934 kref_get(&parent->kref); in sas_ex_discover_expander()
935 child->parent = parent; in sas_ex_discover_expander()
936 child->port = port; in sas_ex_discover_expander()
937 child->iproto = phy->attached_iproto; in sas_ex_discover_expander()
938 child->tproto = phy->attached_tproto; in sas_ex_discover_expander()
939 memcpy(child->sas_addr, phy->attached_sas_addr, SAS_ADDR_SIZE); in sas_ex_discover_expander()
940 sas_hash_addr(child->hashed_sas_addr, child->sas_addr); in sas_ex_discover_expander()
942 edev->level = parent_ex->level + 1; in sas_ex_discover_expander()
943 parent->port->disc.max_level = max(parent->port->disc.max_level, in sas_ex_discover_expander()
944 edev->level); in sas_ex_discover_expander()
949 spin_lock_irq(&parent->port->dev_list_lock); in sas_ex_discover_expander()
950 list_add_tail(&child->dev_list_node, &parent->port->dev_list); in sas_ex_discover_expander()
951 spin_unlock_irq(&parent->port->dev_list_lock); in sas_ex_discover_expander()
956 spin_lock_irq(&parent->port->dev_list_lock); in sas_ex_discover_expander()
957 list_del(&child->dev_list_node); in sas_ex_discover_expander()
958 spin_unlock_irq(&parent->port->dev_list_lock); in sas_ex_discover_expander()
960 sas_port_delete(phy->port); in sas_ex_discover_expander()
961 phy->port = NULL; in sas_ex_discover_expander()
964 list_add_tail(&child->siblings, &parent->ex_dev.children); in sas_ex_discover_expander()
970 struct expander_device *ex = &dev->ex_dev; in sas_ex_discover_dev()
971 struct ex_phy *ex_phy = &ex->ex_phy[phy_id]; in sas_ex_discover_dev()
976 if (ex_phy->linkrate == SAS_SATA_SPINUP_HOLD) { in sas_ex_discover_dev()
984 if (!dev->parent && sas_phy_match_port_addr(dev->port, ex_phy)) { in sas_ex_discover_dev()
988 if (dev->parent && sas_phy_match_dev_addr(dev->parent, ex_phy)) { in sas_ex_discover_dev()
990 if (ex_phy->routing_attr == TABLE_ROUTING) in sas_ex_discover_dev()
991 sas_configure_phy(dev, phy_id, dev->port->sas_addr, 1); in sas_ex_discover_dev()
995 if (sas_dev_present_in_domain(dev->port, ex_phy->attached_sas_addr)) in sas_ex_discover_dev()
996 sas_ex_disable_port(dev, ex_phy->attached_sas_addr); in sas_ex_discover_dev()
998 if (ex_phy->attached_dev_type == SAS_PHY_UNUSED) { in sas_ex_discover_dev()
999 if (ex_phy->routing_attr == DIRECT_ROUTING) { in sas_ex_discover_dev()
1000 memset(ex_phy->attached_sas_addr, 0, SAS_ADDR_SIZE); in sas_ex_discover_dev()
1001 sas_configure_routing(dev, ex_phy->attached_sas_addr); in sas_ex_discover_dev()
1004 } else if (ex_phy->linkrate == SAS_LINK_RATE_UNKNOWN) in sas_ex_discover_dev()
1007 if (ex_phy->attached_dev_type != SAS_END_DEVICE && in sas_ex_discover_dev()
1008 ex_phy->attached_dev_type != SAS_FANOUT_EXPANDER_DEVICE && in sas_ex_discover_dev()
1009 ex_phy->attached_dev_type != SAS_EDGE_EXPANDER_DEVICE && in sas_ex_discover_dev()
1010 ex_phy->attached_dev_type != SAS_SATA_PENDING) { in sas_ex_discover_dev()
1012 ex_phy->attached_dev_type, in sas_ex_discover_dev()
1013 SAS_ADDR(dev->sas_addr), in sas_ex_discover_dev()
1018 res = sas_configure_routing(dev, ex_phy->attached_sas_addr); in sas_ex_discover_dev()
1021 SAS_ADDR(ex_phy->attached_sas_addr), res); in sas_ex_discover_dev()
1022 sas_disable_routing(dev, ex_phy->attached_sas_addr); in sas_ex_discover_dev()
1027 pr_debug("Attaching ex phy%02d to wide port %016llx\n", in sas_ex_discover_dev()
1028 phy_id, SAS_ADDR(ex_phy->attached_sas_addr)); in sas_ex_discover_dev()
1032 switch (ex_phy->attached_dev_type) { in sas_ex_discover_dev()
1038 if (SAS_ADDR(dev->port->disc.fanout_sas_addr)) { in sas_ex_discover_dev()
1039 pr_debug("second fanout expander %016llx phy%02d attached to ex %016llx phy%02d\n", in sas_ex_discover_dev()
1040 SAS_ADDR(ex_phy->attached_sas_addr), in sas_ex_discover_dev()
1041 ex_phy->attached_phy_id, in sas_ex_discover_dev()
1042 SAS_ADDR(dev->sas_addr), in sas_ex_discover_dev()
1047 memcpy(dev->port->disc.fanout_sas_addr, in sas_ex_discover_dev()
1048 ex_phy->attached_sas_addr, SAS_ADDR_SIZE); in sas_ex_discover_dev()
1059 SAS_ADDR(dev->sas_addr), phy_id); in sas_ex_discover_dev()
1065 struct expander_device *ex = &dev->ex_dev; in sas_find_sub_addr()
1068 for (i = 0; i < ex->num_phys; i++) { in sas_find_sub_addr()
1069 struct ex_phy *phy = &ex->ex_phy[i]; in sas_find_sub_addr()
1071 if (phy->phy_state == PHY_VACANT || in sas_find_sub_addr()
1072 phy->phy_state == PHY_NOT_PRESENT) in sas_find_sub_addr()
1075 if (dev_is_expander(phy->attached_dev_type) && in sas_find_sub_addr()
1076 phy->routing_attr == SUBTRACTIVE_ROUTING) { in sas_find_sub_addr()
1078 memcpy(sub_addr, phy->attached_sas_addr, SAS_ADDR_SIZE); in sas_find_sub_addr()
1088 struct expander_device *ex = &dev->ex_dev; in sas_check_level_subtractive_boundary()
1092 list_for_each_entry(child, &ex->children, siblings) { in sas_check_level_subtractive_boundary()
1093 if (!dev_is_expander(child->dev_type)) in sas_check_level_subtractive_boundary()
1104 pr_notice("ex %016llx->%016llx-?->%016llx diverges from subtractive boundary %016llx\n", in sas_check_level_subtractive_boundary()
1105 SAS_ADDR(dev->sas_addr), in sas_check_level_subtractive_boundary()
1106 SAS_ADDR(child->sas_addr), in sas_check_level_subtractive_boundary()
1117 * sas_ex_discover_devices - discover devices attached to this expander
1118 * @dev: pointer to the expander domain device
1119 * @single: if you want to do a single phy, else set to -1;
1121 * Configure this expander for use with its devices and register the
1122 * devices of this expander.
1126 struct expander_device *ex = &dev->ex_dev; in sas_ex_discover_devices()
1127 int i = 0, end = ex->num_phys; in sas_ex_discover_devices()
1136 struct ex_phy *ex_phy = &ex->ex_phy[i]; in sas_ex_discover_devices()
1138 if (ex_phy->phy_state == PHY_VACANT || in sas_ex_discover_devices()
1139 ex_phy->phy_state == PHY_NOT_PRESENT || in sas_ex_discover_devices()
1140 ex_phy->phy_state == PHY_DEVICE_DISCOVERED) in sas_ex_discover_devices()
1143 switch (ex_phy->linkrate) { in sas_ex_discover_devices()
1164 struct expander_device *ex = &dev->ex_dev; in sas_check_ex_subtractive_boundary()
1168 if (dev->dev_type != SAS_EDGE_EXPANDER_DEVICE) in sas_check_ex_subtractive_boundary()
1171 for (i = 0; i < ex->num_phys; i++) { in sas_check_ex_subtractive_boundary()
1172 struct ex_phy *phy = &ex->ex_phy[i]; in sas_check_ex_subtractive_boundary()
1174 if (phy->phy_state == PHY_VACANT || in sas_check_ex_subtractive_boundary()
1175 phy->phy_state == PHY_NOT_PRESENT) in sas_check_ex_subtractive_boundary()
1178 if (dev_is_expander(phy->attached_dev_type) && in sas_check_ex_subtractive_boundary()
1179 phy->routing_attr == SUBTRACTIVE_ROUTING) { in sas_check_ex_subtractive_boundary()
1182 sub_sas_addr = &phy->attached_sas_addr[0]; in sas_check_ex_subtractive_boundary()
1184 SAS_ADDR(phy->attached_sas_addr)) { in sas_check_ex_subtractive_boundary()
1187 SAS_ADDR(dev->sas_addr), i, in sas_check_ex_subtractive_boundary()
1188 SAS_ADDR(phy->attached_sas_addr), in sas_check_ex_subtractive_boundary()
1205 struct domain_device *parent = child->parent; in sas_print_parent_topology_bug()
1207 pr_notice("%s ex %016llx phy%02d <--> %s ex %016llx phy%02d has %c:%c routing link!\n", in sas_print_parent_topology_bug()
1208 ex_type[parent->dev_type], in sas_print_parent_topology_bug()
1209 SAS_ADDR(parent->sas_addr), in sas_print_parent_topology_bug()
1210 parent_phy->phy_id, in sas_print_parent_topology_bug()
1212 ex_type[child->dev_type], in sas_print_parent_topology_bug()
1213 SAS_ADDR(child->sas_addr), in sas_print_parent_topology_bug()
1214 child_phy->phy_id, in sas_print_parent_topology_bug()
1223 struct sas_discovery *disc = &parent->port->disc; in sas_eeds_valid()
1225 return (SAS_ADDR(disc->eeds_a) == SAS_ADDR(parent->sas_addr) || in sas_eeds_valid()
1226 SAS_ADDR(disc->eeds_a) == SAS_ADDR(child->sas_addr)) && in sas_eeds_valid()
1227 (SAS_ADDR(disc->eeds_b) == SAS_ADDR(parent->sas_addr) || in sas_eeds_valid()
1228 SAS_ADDR(disc->eeds_b) == SAS_ADDR(child->sas_addr)); in sas_eeds_valid()
1236 struct domain_device *parent = child->parent; in sas_check_eeds()
1237 struct sas_discovery *disc = &parent->port->disc; in sas_check_eeds()
1239 if (SAS_ADDR(disc->fanout_sas_addr) != 0) { in sas_check_eeds()
1240 res = -ENODEV; in sas_check_eeds()
1241 …pr_warn("edge ex %016llx phy S:%02d <--> edge ex %016llx phy S:%02d, while there is a fanout ex %0… in sas_check_eeds()
1242 SAS_ADDR(parent->sas_addr), in sas_check_eeds()
1243 parent_phy->phy_id, in sas_check_eeds()
1244 SAS_ADDR(child->sas_addr), in sas_check_eeds()
1245 child_phy->phy_id, in sas_check_eeds()
1246 SAS_ADDR(disc->fanout_sas_addr)); in sas_check_eeds()
1247 } else if (SAS_ADDR(disc->eeds_a) == 0) { in sas_check_eeds()
1248 memcpy(disc->eeds_a, parent->sas_addr, SAS_ADDR_SIZE); in sas_check_eeds()
1249 memcpy(disc->eeds_b, child->sas_addr, SAS_ADDR_SIZE); in sas_check_eeds()
1251 res = -ENODEV; in sas_check_eeds()
1252 pr_warn("edge ex %016llx phy%02d <--> edge ex %016llx phy%02d link forms a third EEDS!\n", in sas_check_eeds()
1253 SAS_ADDR(parent->sas_addr), in sas_check_eeds()
1254 parent_phy->phy_id, in sas_check_eeds()
1255 SAS_ADDR(child->sas_addr), in sas_check_eeds()
1256 child_phy->phy_id); in sas_check_eeds()
1265 struct expander_device *child_ex = &child->ex_dev; in sas_check_edge_expander_topo()
1266 struct expander_device *parent_ex = &child->parent->ex_dev; in sas_check_edge_expander_topo()
1269 child_phy = &child_ex->ex_phy[parent_phy->attached_phy_id]; in sas_check_edge_expander_topo()
1271 if (child->dev_type == SAS_FANOUT_EXPANDER_DEVICE) { in sas_check_edge_expander_topo()
1272 if (parent_phy->routing_attr != SUBTRACTIVE_ROUTING || in sas_check_edge_expander_topo()
1273 child_phy->routing_attr != TABLE_ROUTING) in sas_check_edge_expander_topo()
1275 } else if (parent_phy->routing_attr == SUBTRACTIVE_ROUTING) { in sas_check_edge_expander_topo()
1276 if (child_phy->routing_attr == SUBTRACTIVE_ROUTING) in sas_check_edge_expander_topo()
1278 else if (child_phy->routing_attr != TABLE_ROUTING) in sas_check_edge_expander_topo()
1280 } else if (parent_phy->routing_attr == TABLE_ROUTING) { in sas_check_edge_expander_topo()
1281 if (child_phy->routing_attr != SUBTRACTIVE_ROUTING && in sas_check_edge_expander_topo()
1282 (child_phy->routing_attr != TABLE_ROUTING || in sas_check_edge_expander_topo()
1283 !child_ex->t2t_supp || !parent_ex->t2t_supp)) in sas_check_edge_expander_topo()
1290 return -ENODEV; in sas_check_edge_expander_topo()
1296 struct expander_device *child_ex = &child->ex_dev; in sas_check_fanout_expander_topo()
1299 child_phy = &child_ex->ex_phy[parent_phy->attached_phy_id]; in sas_check_fanout_expander_topo()
1301 if (parent_phy->routing_attr == TABLE_ROUTING && in sas_check_fanout_expander_topo()
1302 child_phy->routing_attr == SUBTRACTIVE_ROUTING) in sas_check_fanout_expander_topo()
1307 return -ENODEV; in sas_check_fanout_expander_topo()
1316 if (!child->parent) in sas_check_parent_topology()
1319 if (!dev_is_expander(child->parent->dev_type)) in sas_check_parent_topology()
1322 parent_ex = &child->parent->ex_dev; in sas_check_parent_topology()
1324 for (i = 0; i < parent_ex->num_phys; i++) { in sas_check_parent_topology()
1325 struct ex_phy *parent_phy = &parent_ex->ex_phy[i]; in sas_check_parent_topology()
1327 if (parent_phy->phy_state == PHY_VACANT || in sas_check_parent_topology()
1328 parent_phy->phy_state == PHY_NOT_PRESENT) in sas_check_parent_topology()
1334 switch (child->parent->dev_type) { in sas_check_parent_topology()
1337 res = -ENODEV; in sas_check_parent_topology()
1341 res = -ENODEV; in sas_check_parent_topology()
1358 struct expander_device *ex = &dev->ex_dev; in sas_configure_present()
1359 struct ex_phy *phy = &ex->ex_phy[phy_id]; in sas_configure_present()
1368 return -ENOMEM; in sas_configure_present()
1373 return -ENOMEM; in sas_configure_present()
1379 for (i = 0; i < ex->max_route_indexes ; i++) { in sas_configure_present()
1388 SAS_ADDR(dev->sas_addr), phy_id, i); in sas_configure_present()
1392 __func__, SAS_ADDR(dev->sas_addr), phy_id, in sas_configure_present()
1410 phy->last_da_index < i) { in sas_configure_present()
1411 phy->last_da_index = i; in sas_configure_present()
1417 res = -1; in sas_configure_present()
1436 return -ENOMEM; in sas_configure_set()
1441 return -ENOMEM; in sas_configure_set()
1458 SAS_ADDR(dev->sas_addr), phy_id, index); in sas_configure_set()
1484 * sas_configure_parent - configure routing table of parent
1485 * @parent: parent expander
1486 * @child: child expander
1487 * @sas_addr: SAS port identifier of device directly attached to child
1488 * @include: whether or not to include @child in the expander routing table
1494 struct expander_device *ex_parent = &parent->ex_dev; in sas_configure_parent()
1498 if (parent->parent) { in sas_configure_parent()
1499 res = sas_configure_parent(parent->parent, parent, sas_addr, in sas_configure_parent()
1505 if (ex_parent->conf_route_table == 0) { in sas_configure_parent()
1506 pr_debug("ex %016llx has self-configuring routing table\n", in sas_configure_parent()
1507 SAS_ADDR(parent->sas_addr)); in sas_configure_parent()
1511 for (i = 0; i < ex_parent->num_phys; i++) { in sas_configure_parent()
1512 struct ex_phy *phy = &ex_parent->ex_phy[i]; in sas_configure_parent()
1514 if ((phy->routing_attr == TABLE_ROUTING) && in sas_configure_parent()
1526 * sas_configure_routing - configure routing
1527 * @dev: expander device
1528 * @sas_addr: port identifier of device directly attached to the expander device
1532 if (dev->parent) in sas_configure_routing()
1533 return sas_configure_parent(dev->parent, dev, sas_addr, 1); in sas_configure_routing()
1539 if (dev->parent) in sas_disable_routing()
1540 return sas_configure_parent(dev->parent, dev, sas_addr, 0); in sas_disable_routing()
1545 * sas_discover_expander - expander discovery
1546 * @dev: pointer to expander domain device
1567 pr_warn("expander %016llx discovery failed(0x%x)\n", in sas_discover_expander()
1568 SAS_ADDR(dev->sas_addr), res); in sas_discover_expander()
1582 static int sas_ex_level_discovery(struct asd_sas_port *port, const int level) in sas_ex_level_discovery() argument
1587 list_for_each_entry(dev, &port->dev_list, dev_list_node) { in sas_ex_level_discovery()
1588 if (dev_is_expander(dev->dev_type)) { in sas_ex_level_discovery()
1590 rphy_to_expander_device(dev->rphy); in sas_ex_level_discovery()
1592 if (level == ex->level) in sas_ex_level_discovery()
1593 res = sas_ex_discover_devices(dev, -1); in sas_ex_level_discovery()
1595 res = sas_ex_discover_devices(port->port_dev, -1); in sas_ex_level_discovery()
1603 static int sas_ex_bfs_disc(struct asd_sas_port *port) in sas_ex_bfs_disc() argument
1609 level = port->disc.max_level; in sas_ex_bfs_disc()
1610 res = sas_ex_level_discovery(port, level); in sas_ex_bfs_disc()
1612 } while (level < port->disc.max_level); in sas_ex_bfs_disc()
1620 struct sas_expander_device *ex = rphy_to_expander_device(dev->rphy); in sas_discover_root_expander()
1622 res = sas_rphy_add(dev->rphy); in sas_discover_root_expander()
1626 ex->level = dev->port->disc.max_level; /* 0 */ in sas_discover_root_expander()
1631 sas_ex_bfs_disc(dev->port); in sas_discover_root_expander()
1636 sas_rphy_remove(dev->rphy); in sas_discover_root_expander()
1641 /* ---------- Domain revalidation ---------- */
1647 memcpy(sas_addr, disc_resp->disc.attached_sas_addr, SAS_ADDR_SIZE); in sas_get_sas_addr_and_dev_type()
1648 *type = to_dev_type(&disc_resp->disc); in sas_get_sas_addr_and_dev_type()
1661 return -ENOMEM; in sas_get_phy_discover()
1670 if (disc_resp->result != SMP_RESP_FUNC_ACC) in sas_get_phy_discover()
1671 res = disc_resp->result; in sas_get_phy_discover()
1685 return -ENOMEM; in sas_get_phy_change_count()
1689 *pcc = disc_resp->disc.change_count; in sas_get_phy_change_count()
1703 return -ENOMEM; in sas_get_phy_attached_dev()
1715 struct expander_device *ex = &dev->ex_dev; in sas_find_bcast_phy()
1719 for (i = from_phy; i < ex->num_phys; i++) { in sas_find_bcast_phy()
1733 if (phy_change_count != ex->ex_phy[i].phy_change_count) { in sas_find_bcast_phy()
1735 ex->ex_phy[i].phy_change_count = in sas_find_bcast_phy()
1752 return -ENOMEM; in sas_get_ex_change_count()
1757 return -ENOMEM; in sas_get_ex_change_count()
1766 if (rg_resp->result != SMP_RESP_FUNC_ACC) { in sas_get_ex_change_count()
1767 res = rg_resp->result; in sas_get_ex_change_count()
1771 *ecc = be16_to_cpu(rg_resp->rg.change_count); in sas_get_ex_change_count()
1778 * sas_find_bcast_dev - find the device issue BROADCAST(CHANGE).
1782 * Add self-configuration expander support. Suppose two expander cascading,
1783 * when the first level expander is self-configuring, hotplug the disks in
1784 * second level expander, BROADCAST(CHANGE) will not only be originated
1785 * in the second level expander, but also be originated in the first level
1786 * expander (see SAS protocol SAS 2r-14, 7.11 for detail), it is to say,
1787 * expander changed count in two level expanders will all increment at least
1795 struct expander_device *ex = &dev->ex_dev; in sas_find_bcast_dev()
1796 int ex_change_count = -1; in sas_find_bcast_dev()
1797 int phy_id = -1; in sas_find_bcast_dev()
1804 if (ex_change_count != -1 && ex_change_count != ex->ex_change_count) { in sas_find_bcast_dev()
1805 /* Just detect if this expander phys phy change count changed, in sas_find_bcast_dev()
1806 * in order to determine if this expander originate BROADCAST, in sas_find_bcast_dev()
1810 if (phy_id != -1) { in sas_find_bcast_dev()
1812 ex->ex_change_count = ex_change_count; in sas_find_bcast_dev()
1814 SAS_ADDR(dev->sas_addr), phy_id); in sas_find_bcast_dev()
1818 SAS_ADDR(dev->sas_addr)); in sas_find_bcast_dev()
1820 list_for_each_entry(ch, &ex->children, siblings) { in sas_find_bcast_dev()
1821 if (dev_is_expander(ch->dev_type)) { in sas_find_bcast_dev()
1831 static void sas_unregister_ex_tree(struct asd_sas_port *port, struct domain_device *dev) in sas_unregister_ex_tree() argument
1833 struct expander_device *ex = &dev->ex_dev; in sas_unregister_ex_tree()
1836 list_for_each_entry_safe(child, n, &ex->children, siblings) { in sas_unregister_ex_tree()
1837 set_bit(SAS_DEV_GONE, &child->state); in sas_unregister_ex_tree()
1838 if (dev_is_expander(child->dev_type)) in sas_unregister_ex_tree()
1839 sas_unregister_ex_tree(port, child); in sas_unregister_ex_tree()
1841 sas_unregister_dev(port, child); in sas_unregister_ex_tree()
1843 sas_unregister_dev(port, dev); in sas_unregister_ex_tree()
1849 struct expander_device *ex_dev = &parent->ex_dev; in sas_unregister_devs_sas_addr()
1850 struct ex_phy *phy = &ex_dev->ex_phy[phy_id]; in sas_unregister_devs_sas_addr()
1854 &ex_dev->children, siblings) { in sas_unregister_devs_sas_addr()
1856 set_bit(SAS_DEV_GONE, &child->state); in sas_unregister_devs_sas_addr()
1857 if (dev_is_expander(child->dev_type)) in sas_unregister_devs_sas_addr()
1858 sas_unregister_ex_tree(parent->port, child); in sas_unregister_devs_sas_addr()
1860 sas_unregister_dev(parent->port, child); in sas_unregister_devs_sas_addr()
1865 sas_disable_routing(parent, phy->attached_sas_addr); in sas_unregister_devs_sas_addr()
1867 memset(phy->attached_sas_addr, 0, SAS_ADDR_SIZE); in sas_unregister_devs_sas_addr()
1868 if (phy->port) { in sas_unregister_devs_sas_addr()
1869 sas_port_delete_phy(phy->port, phy->phy); in sas_unregister_devs_sas_addr()
1870 sas_device_set_phy(found, phy->port); in sas_unregister_devs_sas_addr()
1871 if (phy->port->num_phys == 0) { in sas_unregister_devs_sas_addr()
1872 list_add_tail(&phy->port->del_list, in sas_unregister_devs_sas_addr()
1873 &parent->port->sas_port_del_list); in sas_unregister_devs_sas_addr()
1874 if (ex_dev->parent_port == phy->port) in sas_unregister_devs_sas_addr()
1875 ex_dev->parent_port = NULL; in sas_unregister_devs_sas_addr()
1877 phy->port = NULL; in sas_unregister_devs_sas_addr()
1884 struct expander_device *ex_root = &root->ex_dev; in sas_discover_bfs_by_root_level()
1888 list_for_each_entry(child, &ex_root->children, siblings) { in sas_discover_bfs_by_root_level()
1889 if (dev_is_expander(child->dev_type)) { in sas_discover_bfs_by_root_level()
1891 rphy_to_expander_device(child->rphy); in sas_discover_bfs_by_root_level()
1893 if (level > ex->level) in sas_discover_bfs_by_root_level()
1896 else if (level == ex->level) in sas_discover_bfs_by_root_level()
1897 res = sas_ex_discover_devices(child, -1); in sas_discover_bfs_by_root_level()
1906 struct sas_expander_device *ex = rphy_to_expander_device(dev->rphy); in sas_discover_bfs_by_root()
1907 int level = ex->level+1; in sas_discover_bfs_by_root()
1909 res = sas_ex_discover_devices(dev, -1); in sas_discover_bfs_by_root()
1916 } while (level <= dev->port->disc.max_level); in sas_discover_bfs_by_root()
1923 struct ex_phy *ex_phy = &dev->ex_dev.ex_phy[phy_id]; in sas_discover_new()
1928 SAS_ADDR(dev->sas_addr), phy_id); in sas_discover_new()
1939 list_for_each_entry(child, &dev->ex_dev.children, siblings) { in sas_discover_new()
1941 if (dev_is_expander(child->dev_type)) in sas_discover_new()
1967 struct expander_device *ex = &dev->ex_dev; in sas_rediscover_dev()
1968 struct ex_phy *phy = &ex->ex_phy[phy_id]; in sas_rediscover_dev()
1976 sprintf(msg, ", part of a wide port with phy%02d", sibling); in sas_rediscover_dev()
1979 SAS_ADDR(dev->sas_addr), phy_id, msg); in sas_rediscover_dev()
1984 return -ENOMEM; in sas_rediscover_dev()
1989 phy->phy_state = PHY_NOT_PRESENT; in sas_rediscover_dev()
1993 phy->phy_state = PHY_VACANT; in sas_rediscover_dev()
1998 case -ECOMM: in sas_rediscover_dev()
2007 if ((SAS_ADDR(sas_addr) == 0) || (res == -ECOMM)) { in sas_rediscover_dev()
2008 phy->phy_state = PHY_EMPTY; in sas_rediscover_dev()
2017 } else if (SAS_ADDR(sas_addr) == SAS_ADDR(phy->attached_sas_addr) && in sas_rediscover_dev()
2018 dev_type_flutter(type, phy->attached_dev_type)) { in sas_rediscover_dev()
2024 if (ata_dev && phy->attached_dev_type == SAS_SATA_PENDING) in sas_rediscover_dev()
2027 SAS_ADDR(dev->sas_addr), phy_id, action); in sas_rediscover_dev()
2033 SAS_ADDR(dev->sas_addr), phy_id, in sas_rediscover_dev()
2034 SAS_ADDR(phy->attached_sas_addr)); in sas_rediscover_dev()
2044 * sas_rediscover - revalidate the domain.
2051 * domain.For plugging out, we un-register the device only when it is
2052 * the last phy in the port, for other phys in this port, we just delete it
2053 * from the port.For inserting, we do discovery when it is the
2054 * first phy,for other phys in this port, we add it to the port to
2055 * forming the wide-port.
2059 struct expander_device *ex = &dev->ex_dev; in sas_rediscover()
2060 struct ex_phy *changed_phy = &ex->ex_phy[phy_id]; in sas_rediscover()
2063 bool last = true; /* is this the last phy of the port */ in sas_rediscover()
2066 SAS_ADDR(dev->sas_addr), phy_id); in sas_rediscover()
2068 if (SAS_ADDR(changed_phy->attached_sas_addr) != 0) { in sas_rediscover()
2069 for (i = 0; i < ex->num_phys; i++) { in sas_rediscover()
2070 struct ex_phy *phy = &ex->ex_phy[i]; in sas_rediscover()
2086 * sas_ex_revalidate_domain - revalidate the domain
2087 * @port_dev: port domain device.
2101 struct expander_device *ex = &dev->ex_dev; in sas_ex_revalidate_domain()
2105 phy_id = -1; in sas_ex_revalidate_domain()
2107 if (phy_id == -1) in sas_ex_revalidate_domain()
2111 } while (i < ex->num_phys); in sas_ex_revalidate_domain()
2122 for (phy_id = 0; phy_id < ex_dev->num_phys; phy_id++) { in sas_find_attached_phy_id()
2123 phy = &ex_dev->ex_phy[phy_id]; in sas_find_attached_phy_id()
2128 return -ENODEV; in sas_find_attached_phy_id()
2137 int ret = -EINVAL; in sas_smp_handler()
2143 switch (rphy->identify.device_type) { in sas_smp_handler()
2160 if (job->request_payload.sg_cnt > 1 || in sas_smp_handler()
2161 job->reply_payload.sg_cnt > 1) { in sas_smp_handler()
2163 __func__, job->request_payload.payload_len, in sas_smp_handler()
2164 job->reply_payload.payload_len); in sas_smp_handler()
2168 ret = smp_execute_task_sg(dev, job->request_payload.sg_list, in sas_smp_handler()
2169 job->reply_payload.sg_list); in sas_smp_handler()
2172 rcvlen = job->reply_payload.payload_len - ret; in sas_smp_handler()