Lines Matching +full:parent +full:- +full:child
1 // SPDX-License-Identifier: GPL-2.0
29 /* ---------- SMP task management ---------- */
34 struct sas_task *task = slow->task; in smp_task_timedout()
37 spin_lock_irqsave(&task->task_state_lock, flags); in smp_task_timedout()
38 if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) { in smp_task_timedout()
39 task->task_state_flags |= SAS_TASK_STATE_ABORTED; in smp_task_timedout()
40 complete(&task->slow_task->completion); in smp_task_timedout()
42 spin_unlock_irqrestore(&task->task_state_lock, flags); in smp_task_timedout()
47 del_timer(&task->slow_task->timer); in smp_task_done()
48 complete(&task->slow_task->completion); in smp_task_done()
60 to_sas_internal(dev->port->ha->core.shost->transportt); in smp_execute_task_sg()
62 mutex_lock(&dev->ex_dev.cmd_mutex); in smp_execute_task_sg()
64 if (test_bit(SAS_DEV_GONE, &dev->state)) { in smp_execute_task_sg()
65 res = -ECOMM; in smp_execute_task_sg()
71 res = -ENOMEM; in smp_execute_task_sg()
74 task->dev = dev; in smp_execute_task_sg()
75 task->task_proto = dev->tproto; in smp_execute_task_sg()
76 task->smp_task.smp_req = *req; in smp_execute_task_sg()
77 task->smp_task.smp_resp = *resp; in smp_execute_task_sg()
79 task->task_done = smp_task_done; in smp_execute_task_sg()
81 task->slow_task->timer.function = smp_task_timedout; in smp_execute_task_sg()
82 task->slow_task->timer.expires = jiffies + SMP_TIMEOUT*HZ; in smp_execute_task_sg()
83 add_timer(&task->slow_task->timer); in smp_execute_task_sg()
85 res = i->dft->lldd_execute_task(task, GFP_KERNEL); in smp_execute_task_sg()
88 del_timer(&task->slow_task->timer); in smp_execute_task_sg()
93 wait_for_completion(&task->slow_task->completion); in smp_execute_task_sg()
94 res = -ECOMM; in smp_execute_task_sg()
95 if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) { in smp_execute_task_sg()
97 i->dft->lldd_abort_task(task); in smp_execute_task_sg()
98 if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) { in smp_execute_task_sg()
103 if (task->task_status.resp == SAS_TASK_COMPLETE && in smp_execute_task_sg()
104 task->task_status.stat == SAM_STAT_GOOD) { in smp_execute_task_sg()
108 if (task->task_status.resp == SAS_TASK_COMPLETE && in smp_execute_task_sg()
109 task->task_status.stat == SAS_DATA_UNDERRUN) { in smp_execute_task_sg()
112 res = task->task_status.residual; in smp_execute_task_sg()
115 if (task->task_status.resp == SAS_TASK_COMPLETE && in smp_execute_task_sg()
116 task->task_status.stat == SAS_DATA_OVERRUN) { in smp_execute_task_sg()
117 res = -EMSGSIZE; in smp_execute_task_sg()
120 if (task->task_status.resp == SAS_TASK_UNDELIVERED && in smp_execute_task_sg()
121 task->task_status.stat == SAS_DEVICE_UNKNOWN) in smp_execute_task_sg()
126 SAS_ADDR(dev->sas_addr), in smp_execute_task_sg()
127 task->task_status.resp, in smp_execute_task_sg()
128 task->task_status.stat); in smp_execute_task_sg()
133 mutex_unlock(&dev->ex_dev.cmd_mutex); in smp_execute_task_sg()
151 /* ---------- Allocations ---------- */
168 switch (phy->routing_attr) { in sas_route_char()
170 if (dev->ex_dev.t2t_supp) in sas_route_char()
186 * FIS as described in section J.5 of sas-2 r16 in to_dev_type()
188 if (dr->attached_dev_type == SAS_PHY_UNUSED && dr->attached_sata_dev && in to_dev_type()
189 dr->linkrate >= SAS_LINK_RATE_1_5_GBPS) in to_dev_type()
192 return dr->attached_dev_type; in to_dev_type()
201 struct discover_resp *dr = &resp->disc; in sas_set_ex_phy()
202 struct sas_ha_struct *ha = dev->port->ha; in sas_set_ex_phy()
203 struct expander_device *ex = &dev->ex_dev; in sas_set_ex_phy()
204 struct ex_phy *phy = &ex->ex_phy[phy_id]; in sas_set_ex_phy()
205 struct sas_rphy *rphy = dev->rphy; in sas_set_ex_phy()
206 bool new_phy = !phy->phy; in sas_set_ex_phy()
210 if (WARN_ON_ONCE(test_bit(SAS_HA_ATA_EH_ACTIVE, &ha->state))) in sas_set_ex_phy()
212 phy->phy = sas_phy_alloc(&rphy->dev, phy_id); in sas_set_ex_phy()
215 BUG_ON(!phy->phy); in sas_set_ex_phy()
218 switch (resp->result) { in sas_set_ex_phy()
220 phy->phy_state = PHY_VACANT; in sas_set_ex_phy()
223 phy->phy_state = PHY_NOT_PRESENT; in sas_set_ex_phy()
226 phy->phy_state = PHY_EMPTY; /* do not know yet */ in sas_set_ex_phy()
231 dev_type = phy->attached_dev_type; in sas_set_ex_phy()
232 linkrate = phy->linkrate; in sas_set_ex_phy()
233 memcpy(sas_addr, phy->attached_sas_addr, SAS_ADDR_SIZE); in sas_set_ex_phy()
235 /* Handle vacant phy - rest of dr data is not valid so skip it */ in sas_set_ex_phy()
236 if (phy->phy_state == PHY_VACANT) { in sas_set_ex_phy()
237 memset(phy->attached_sas_addr, 0, SAS_ADDR_SIZE); in sas_set_ex_phy()
238 phy->attached_dev_type = SAS_PHY_UNUSED; in sas_set_ex_phy()
239 if (!test_bit(SAS_HA_ATA_EH_ACTIVE, &ha->state)) { in sas_set_ex_phy()
240 phy->phy_id = phy_id; in sas_set_ex_phy()
246 phy->attached_dev_type = to_dev_type(dr); in sas_set_ex_phy()
247 if (test_bit(SAS_HA_ATA_EH_ACTIVE, &ha->state)) in sas_set_ex_phy()
249 phy->phy_id = phy_id; in sas_set_ex_phy()
250 phy->linkrate = dr->linkrate; in sas_set_ex_phy()
251 phy->attached_sata_host = dr->attached_sata_host; in sas_set_ex_phy()
252 phy->attached_sata_dev = dr->attached_sata_dev; in sas_set_ex_phy()
253 phy->attached_sata_ps = dr->attached_sata_ps; in sas_set_ex_phy()
254 phy->attached_iproto = dr->iproto << 1; in sas_set_ex_phy()
255 phy->attached_tproto = dr->tproto << 1; in sas_set_ex_phy()
259 if (phy->attached_dev_type == SAS_PHY_UNUSED || in sas_set_ex_phy()
260 phy->linkrate < SAS_LINK_RATE_1_5_GBPS) in sas_set_ex_phy()
261 memset(phy->attached_sas_addr, 0, SAS_ADDR_SIZE); in sas_set_ex_phy()
263 memcpy(phy->attached_sas_addr, dr->attached_sas_addr, SAS_ADDR_SIZE); in sas_set_ex_phy()
264 phy->attached_phy_id = dr->attached_phy_id; in sas_set_ex_phy()
265 phy->phy_change_count = dr->change_count; in sas_set_ex_phy()
266 phy->routing_attr = dr->routing_attr; in sas_set_ex_phy()
267 phy->virtual = dr->virtual; in sas_set_ex_phy()
268 phy->last_da_index = -1; in sas_set_ex_phy()
270 phy->phy->identify.sas_address = SAS_ADDR(phy->attached_sas_addr); in sas_set_ex_phy()
271 phy->phy->identify.device_type = dr->attached_dev_type; in sas_set_ex_phy()
272 phy->phy->identify.initiator_port_protocols = phy->attached_iproto; in sas_set_ex_phy()
273 phy->phy->identify.target_port_protocols = phy->attached_tproto; in sas_set_ex_phy()
274 if (!phy->attached_tproto && dr->attached_sata_dev) in sas_set_ex_phy()
275 phy->phy->identify.target_port_protocols = SAS_PROTOCOL_SATA; in sas_set_ex_phy()
276 phy->phy->identify.phy_identifier = phy_id; in sas_set_ex_phy()
277 phy->phy->minimum_linkrate_hw = dr->hmin_linkrate; in sas_set_ex_phy()
278 phy->phy->maximum_linkrate_hw = dr->hmax_linkrate; in sas_set_ex_phy()
279 phy->phy->minimum_linkrate = dr->pmin_linkrate; in sas_set_ex_phy()
280 phy->phy->maximum_linkrate = dr->pmax_linkrate; in sas_set_ex_phy()
281 phy->phy->negotiated_linkrate = phy->linkrate; in sas_set_ex_phy()
282 phy->phy->enabled = (phy->linkrate != SAS_PHY_DISABLED); in sas_set_ex_phy()
286 if (sas_phy_add(phy->phy)) { in sas_set_ex_phy()
287 sas_phy_free(phy->phy); in sas_set_ex_phy()
292 switch (phy->attached_dev_type) { in sas_set_ex_phy()
300 if (phy->attached_iproto) { in sas_set_ex_phy()
301 if (phy->attached_tproto) in sas_set_ex_phy()
306 if (dr->attached_sata_dev) in sas_set_ex_phy()
323 if (new_phy || phy->attached_dev_type != dev_type || in sas_set_ex_phy()
324 phy->linkrate != linkrate || in sas_set_ex_phy()
325 SAS_ADDR(phy->attached_sas_addr) != SAS_ADDR(sas_addr)) in sas_set_ex_phy()
334 if (test_bit(SAS_HA_ATA_EH_ACTIVE, &ha->state)) in sas_set_ex_phy()
335 set_bit(DISCE_REVALIDATE_DOMAIN, &dev->port->disc.pending); in sas_set_ex_phy()
338 test_bit(SAS_HA_ATA_EH_ACTIVE, &ha->state) ? "ata: " : "", in sas_set_ex_phy()
339 SAS_ADDR(dev->sas_addr), phy->phy_id, in sas_set_ex_phy()
340 sas_route_char(dev, phy), phy->linkrate, in sas_set_ex_phy()
341 SAS_ADDR(phy->attached_sas_addr), type); in sas_set_ex_phy()
347 struct ex_phy *ex_phy = &ex_dev->ex_dev.ex_phy[phy_id]; in sas_ex_to_ata()
351 if (!ex_phy->port) in sas_ex_to_ata()
354 rphy = ex_phy->port->rphy; in sas_ex_to_ata()
381 dr = &((struct smp_resp *)disc_resp)->disc; in sas_ex_phy_discover_helper()
382 if (memcmp(dev->sas_addr, dr->attached_sas_addr, SAS_ADDR_SIZE) == 0) { in sas_ex_phy_discover_helper()
392 struct expander_device *ex = &dev->ex_dev; in sas_ex_phy_discover()
399 return -ENOMEM; in sas_ex_phy_discover()
404 return -ENOMEM; in sas_ex_phy_discover()
409 if (0 <= single && single < ex->num_phys) { in sas_ex_phy_discover()
414 for (i = 0; i < ex->num_phys; i++) { in sas_ex_phy_discover()
429 struct expander_device *ex = &dev->ex_dev; in sas_expander_discover()
432 ex->ex_phy = kcalloc(ex->num_phys, sizeof(*ex->ex_phy), GFP_KERNEL); in sas_expander_discover()
433 if (!ex->ex_phy) in sas_expander_discover()
434 return -ENOMEM; in sas_expander_discover()
436 res = sas_ex_phy_discover(dev, -1); in sas_expander_discover()
442 kfree(ex->ex_phy); in sas_expander_discover()
443 ex->ex_phy = NULL; in sas_expander_discover()
452 struct report_general_resp *rg = &resp->rg; in ex_assign_report_general()
454 dev->ex_dev.ex_change_count = be16_to_cpu(rg->change_count); in ex_assign_report_general()
455 dev->ex_dev.max_route_indexes = be16_to_cpu(rg->route_indexes); in ex_assign_report_general()
456 dev->ex_dev.num_phys = min(rg->num_phys, (u8)MAX_EXPANDER_PHYS); in ex_assign_report_general()
457 dev->ex_dev.t2t_supp = rg->t2t_supp; in ex_assign_report_general()
458 dev->ex_dev.conf_route_table = rg->conf_route_table; in ex_assign_report_general()
459 dev->ex_dev.configuring = rg->configuring; in ex_assign_report_general()
460 memcpy(dev->ex_dev.enclosure_logical_id, rg->enclosure_logical_id, 8); in ex_assign_report_general()
475 return -ENOMEM; in sas_ex_general()
480 return -ENOMEM; in sas_ex_general()
491 SAS_ADDR(dev->sas_addr), res); in sas_ex_general()
493 } else if (rg_resp->result != SMP_RESP_FUNC_ACC) { in sas_ex_general()
495 SAS_ADDR(dev->sas_addr), rg_resp->result); in sas_ex_general()
496 res = rg_resp->result; in sas_ex_general()
502 if (dev->ex_dev.configuring) { in sas_ex_general()
503 pr_debug("RG: ex %016llx self-configuring...\n", in sas_ex_general()
504 SAS_ADDR(dev->sas_addr)); in sas_ex_general()
519 struct sas_rphy *rphy = dev->rphy; in ex_assign_manuf_info()
522 memcpy(edev->vendor_id, mi_resp + 12, SAS_EXPANDER_VENDOR_ID_LEN); in ex_assign_manuf_info()
523 memcpy(edev->product_id, mi_resp + 20, SAS_EXPANDER_PRODUCT_ID_LEN); in ex_assign_manuf_info()
524 memcpy(edev->product_rev, mi_resp + 36, in ex_assign_manuf_info()
528 memcpy(edev->component_vendor_id, mi_resp + 40, in ex_assign_manuf_info()
530 edev->component_id = mi_resp[48] << 8 | mi_resp[49]; in ex_assign_manuf_info()
531 edev->component_revision_id = mi_resp[50]; in ex_assign_manuf_info()
546 return -ENOMEM; in sas_ex_manuf_info()
551 return -ENOMEM; in sas_ex_manuf_info()
559 SAS_ADDR(dev->sas_addr), res); in sas_ex_manuf_info()
563 SAS_ADDR(dev->sas_addr), mi_resp[2]); in sas_ex_manuf_info()
587 return -ENOMEM; in sas_smp_phy_control()
592 return -ENOMEM; in sas_smp_phy_control()
599 pc_req[32] = rates->minimum_linkrate << 4; in sas_smp_phy_control()
600 pc_req[33] = rates->maximum_linkrate << 4; in sas_smp_phy_control()
606 SAS_ADDR(dev->sas_addr), phy_id, res); in sas_smp_phy_control()
609 SAS_ADDR(dev->sas_addr), phy_id, pc_resp[2]); in sas_smp_phy_control()
619 struct expander_device *ex = &dev->ex_dev; in sas_ex_disable_phy()
620 struct ex_phy *phy = &ex->ex_phy[phy_id]; in sas_ex_disable_phy()
623 phy->linkrate = SAS_PHY_DISABLED; in sas_ex_disable_phy()
628 struct expander_device *ex = &dev->ex_dev; in sas_ex_disable_port()
631 for (i = 0; i < ex->num_phys; i++) { in sas_ex_disable_port()
632 struct ex_phy *phy = &ex->ex_phy[i]; in sas_ex_disable_port()
634 if (phy->phy_state == PHY_VACANT || in sas_ex_disable_port()
635 phy->phy_state == PHY_NOT_PRESENT) in sas_ex_disable_port()
638 if (SAS_ADDR(phy->attached_sas_addr) == SAS_ADDR(sas_addr)) in sas_ex_disable_port()
648 if (SAS_ADDR(port->sas_addr) == SAS_ADDR(sas_addr)) in sas_dev_present_in_domain()
650 list_for_each_entry(dev, &port->dev_list, dev_list_node) { in sas_dev_present_in_domain()
651 if (SAS_ADDR(dev->sas_addr) == SAS_ADDR(sas_addr)) in sas_dev_present_in_domain()
664 struct sas_rphy *rphy = dev_to_rphy(phy->dev.parent); in sas_smp_get_phy_events()
669 return -ENOMEM; in sas_smp_get_phy_events()
674 return -ENOMEM; in sas_smp_get_phy_events()
678 req[9] = phy->number; in sas_smp_get_phy_events()
686 phy->invalid_dword_count = get_unaligned_be32(&resp[12]); in sas_smp_get_phy_events()
687 phy->running_disparity_error_count = get_unaligned_be32(&resp[16]); in sas_smp_get_phy_events()
688 phy->loss_of_dword_sync_count = get_unaligned_be32(&resp[20]); in sas_smp_get_phy_events()
689 phy->phy_reset_problem_count = get_unaligned_be32(&resp[24]); in sas_smp_get_phy_events()
711 return -ENOMEM; in sas_get_report_phy_sata()
720 * standards cockup here. sas-2 explicitly specifies the FIS in sas_get_report_phy_sata()
744 static void sas_ex_get_linkrate(struct domain_device *parent, in sas_ex_get_linkrate() argument
745 struct domain_device *child, in sas_ex_get_linkrate() argument
748 struct expander_device *parent_ex = &parent->ex_dev; in sas_ex_get_linkrate()
752 child->pathways = 0; in sas_ex_get_linkrate()
754 port = parent_phy->port; in sas_ex_get_linkrate()
756 for (i = 0; i < parent_ex->num_phys; i++) { in sas_ex_get_linkrate()
757 struct ex_phy *phy = &parent_ex->ex_phy[i]; in sas_ex_get_linkrate()
759 if (phy->phy_state == PHY_VACANT || in sas_ex_get_linkrate()
760 phy->phy_state == PHY_NOT_PRESENT) in sas_ex_get_linkrate()
763 if (SAS_ADDR(phy->attached_sas_addr) == in sas_ex_get_linkrate()
764 SAS_ADDR(child->sas_addr)) { in sas_ex_get_linkrate()
766 child->min_linkrate = min(parent->min_linkrate, in sas_ex_get_linkrate()
767 phy->linkrate); in sas_ex_get_linkrate()
768 child->max_linkrate = max(parent->max_linkrate, in sas_ex_get_linkrate()
769 phy->linkrate); in sas_ex_get_linkrate()
770 child->pathways++; in sas_ex_get_linkrate()
771 sas_port_add_phy(port, phy->phy); in sas_ex_get_linkrate()
774 child->linkrate = min(parent_phy->linkrate, child->max_linkrate); in sas_ex_get_linkrate()
775 child->pathways = min(child->pathways, parent->pathways); in sas_ex_get_linkrate()
779 struct domain_device *parent, int phy_id) in sas_ex_discover_end_dev() argument
781 struct expander_device *parent_ex = &parent->ex_dev; in sas_ex_discover_end_dev()
782 struct ex_phy *phy = &parent_ex->ex_phy[phy_id]; in sas_ex_discover_end_dev()
783 struct domain_device *child = NULL; in sas_ex_discover_end_dev() local
787 if (phy->attached_sata_host || phy->attached_sata_ps) in sas_ex_discover_end_dev()
790 child = sas_alloc_device(); in sas_ex_discover_end_dev()
791 if (!child) in sas_ex_discover_end_dev()
794 kref_get(&parent->kref); in sas_ex_discover_end_dev()
795 child->parent = parent; in sas_ex_discover_end_dev()
796 child->port = parent->port; in sas_ex_discover_end_dev()
797 child->iproto = phy->attached_iproto; in sas_ex_discover_end_dev()
798 memcpy(child->sas_addr, phy->attached_sas_addr, SAS_ADDR_SIZE); in sas_ex_discover_end_dev()
799 sas_hash_addr(child->hashed_sas_addr, child->sas_addr); in sas_ex_discover_end_dev()
800 if (!phy->port) { in sas_ex_discover_end_dev()
801 phy->port = sas_port_alloc(&parent->rphy->dev, phy_id); in sas_ex_discover_end_dev()
802 if (unlikely(!phy->port)) in sas_ex_discover_end_dev()
804 if (unlikely(sas_port_add(phy->port) != 0)) { in sas_ex_discover_end_dev()
805 sas_port_free(phy->port); in sas_ex_discover_end_dev()
809 sas_ex_get_linkrate(parent, child, phy); in sas_ex_discover_end_dev()
810 sas_device_set_phy(child, phy->port); in sas_ex_discover_end_dev()
813 if ((phy->attached_tproto & SAS_PROTOCOL_STP) || phy->attached_sata_dev) { in sas_ex_discover_end_dev()
814 if (child->linkrate > parent->min_linkrate) { in sas_ex_discover_end_dev()
815 struct sas_phy *cphy = child->phy; in sas_ex_discover_end_dev()
816 enum sas_linkrate min_prate = cphy->minimum_linkrate, in sas_ex_discover_end_dev()
817 parent_min_lrate = parent->min_linkrate, in sas_ex_discover_end_dev()
821 .maximum_linkrate = parent->min_linkrate, in sas_ex_discover_end_dev()
827 SAS_ADDR(child->sas_addr), phy_id); in sas_ex_discover_end_dev()
828 ret = sas_smp_phy_control(parent, phy_id, in sas_ex_discover_end_dev()
832 SAS_ADDR(child->sas_addr), phy_id, ret); in sas_ex_discover_end_dev()
836 SAS_ADDR(child->sas_addr), phy_id); in sas_ex_discover_end_dev()
837 child->linkrate = child->min_linkrate; in sas_ex_discover_end_dev()
839 res = sas_get_ata_info(child, phy); in sas_ex_discover_end_dev()
843 sas_init_dev(child); in sas_ex_discover_end_dev()
844 res = sas_ata_init(child); in sas_ex_discover_end_dev()
847 rphy = sas_end_device_alloc(phy->port); in sas_ex_discover_end_dev()
850 rphy->identify.phy_identifier = phy_id; in sas_ex_discover_end_dev()
852 child->rphy = rphy; in sas_ex_discover_end_dev()
853 get_device(&rphy->dev); in sas_ex_discover_end_dev()
855 list_add_tail(&child->disco_list_node, &parent->port->disco_list); in sas_ex_discover_end_dev()
857 res = sas_discover_sata(child); in sas_ex_discover_end_dev()
860 SAS_ADDR(child->sas_addr), in sas_ex_discover_end_dev()
861 SAS_ADDR(parent->sas_addr), phy_id, res); in sas_ex_discover_end_dev()
866 if (phy->attached_tproto & SAS_PROTOCOL_SSP) { in sas_ex_discover_end_dev()
867 child->dev_type = SAS_END_DEVICE; in sas_ex_discover_end_dev()
868 rphy = sas_end_device_alloc(phy->port); in sas_ex_discover_end_dev()
872 child->tproto = phy->attached_tproto; in sas_ex_discover_end_dev()
873 sas_init_dev(child); in sas_ex_discover_end_dev()
875 child->rphy = rphy; in sas_ex_discover_end_dev()
876 get_device(&rphy->dev); in sas_ex_discover_end_dev()
877 rphy->identify.phy_identifier = phy_id; in sas_ex_discover_end_dev()
878 sas_fill_in_rphy(child, rphy); in sas_ex_discover_end_dev()
880 list_add_tail(&child->disco_list_node, &parent->port->disco_list); in sas_ex_discover_end_dev()
882 res = sas_discover_end_dev(child); in sas_ex_discover_end_dev()
885 SAS_ADDR(child->sas_addr), in sas_ex_discover_end_dev()
886 SAS_ADDR(parent->sas_addr), phy_id, res); in sas_ex_discover_end_dev()
891 phy->attached_tproto, SAS_ADDR(parent->sas_addr), in sas_ex_discover_end_dev()
896 list_add_tail(&child->siblings, &parent_ex->children); in sas_ex_discover_end_dev()
897 return child; in sas_ex_discover_end_dev()
900 sas_rphy_free(child->rphy); in sas_ex_discover_end_dev()
901 list_del(&child->disco_list_node); in sas_ex_discover_end_dev()
902 spin_lock_irq(&parent->port->dev_list_lock); in sas_ex_discover_end_dev()
903 list_del(&child->dev_list_node); in sas_ex_discover_end_dev()
904 spin_unlock_irq(&parent->port->dev_list_lock); in sas_ex_discover_end_dev()
906 sas_port_delete(phy->port); in sas_ex_discover_end_dev()
908 phy->port = NULL; in sas_ex_discover_end_dev()
909 sas_put_device(child); in sas_ex_discover_end_dev()
914 static bool sas_ex_join_wide_port(struct domain_device *parent, int phy_id) in sas_ex_join_wide_port() argument
916 struct ex_phy *phy = &parent->ex_dev.ex_phy[phy_id]; in sas_ex_join_wide_port()
919 for (i = 0; i < parent->ex_dev.num_phys; i++) { in sas_ex_join_wide_port()
920 struct ex_phy *ephy = &parent->ex_dev.ex_phy[i]; in sas_ex_join_wide_port()
925 if (!memcmp(phy->attached_sas_addr, ephy->attached_sas_addr, in sas_ex_join_wide_port()
926 SAS_ADDR_SIZE) && ephy->port) { in sas_ex_join_wide_port()
927 sas_port_add_phy(ephy->port, phy->phy); in sas_ex_join_wide_port()
928 phy->port = ephy->port; in sas_ex_join_wide_port()
929 phy->phy_state = PHY_DEVICE_DISCOVERED; in sas_ex_join_wide_port()
938 struct domain_device *parent, int phy_id) in sas_ex_discover_expander() argument
940 struct sas_expander_device *parent_ex = rphy_to_expander_device(parent->rphy); in sas_ex_discover_expander()
941 struct ex_phy *phy = &parent->ex_dev.ex_phy[phy_id]; in sas_ex_discover_expander()
942 struct domain_device *child = NULL; in sas_ex_discover_expander() local
948 if (phy->routing_attr == DIRECT_ROUTING) { in sas_ex_discover_expander()
949 pr_warn("ex %016llx:%02d:D <--> ex %016llx:0x%x is not allowed\n", in sas_ex_discover_expander()
950 SAS_ADDR(parent->sas_addr), phy_id, in sas_ex_discover_expander()
951 SAS_ADDR(phy->attached_sas_addr), in sas_ex_discover_expander()
952 phy->attached_phy_id); in sas_ex_discover_expander()
955 child = sas_alloc_device(); in sas_ex_discover_expander()
956 if (!child) in sas_ex_discover_expander()
959 phy->port = sas_port_alloc(&parent->rphy->dev, phy_id); in sas_ex_discover_expander()
961 BUG_ON(sas_port_add(phy->port) != 0); in sas_ex_discover_expander()
964 switch (phy->attached_dev_type) { in sas_ex_discover_expander()
966 rphy = sas_expander_alloc(phy->port, in sas_ex_discover_expander()
970 rphy = sas_expander_alloc(phy->port, in sas_ex_discover_expander()
977 port = parent->port; in sas_ex_discover_expander()
978 child->rphy = rphy; in sas_ex_discover_expander()
979 get_device(&rphy->dev); in sas_ex_discover_expander()
981 child->dev_type = phy->attached_dev_type; in sas_ex_discover_expander()
982 kref_get(&parent->kref); in sas_ex_discover_expander()
983 child->parent = parent; in sas_ex_discover_expander()
984 child->port = port; in sas_ex_discover_expander()
985 child->iproto = phy->attached_iproto; in sas_ex_discover_expander()
986 child->tproto = phy->attached_tproto; in sas_ex_discover_expander()
987 memcpy(child->sas_addr, phy->attached_sas_addr, SAS_ADDR_SIZE); in sas_ex_discover_expander()
988 sas_hash_addr(child->hashed_sas_addr, child->sas_addr); in sas_ex_discover_expander()
989 sas_ex_get_linkrate(parent, child, phy); in sas_ex_discover_expander()
990 edev->level = parent_ex->level + 1; in sas_ex_discover_expander()
991 parent->port->disc.max_level = max(parent->port->disc.max_level, in sas_ex_discover_expander()
992 edev->level); in sas_ex_discover_expander()
993 sas_init_dev(child); in sas_ex_discover_expander()
994 sas_fill_in_rphy(child, rphy); in sas_ex_discover_expander()
997 spin_lock_irq(&parent->port->dev_list_lock); in sas_ex_discover_expander()
998 list_add_tail(&child->dev_list_node, &parent->port->dev_list); in sas_ex_discover_expander()
999 spin_unlock_irq(&parent->port->dev_list_lock); in sas_ex_discover_expander()
1001 res = sas_discover_expander(child); in sas_ex_discover_expander()
1004 spin_lock_irq(&parent->port->dev_list_lock); in sas_ex_discover_expander()
1005 list_del(&child->dev_list_node); in sas_ex_discover_expander()
1006 spin_unlock_irq(&parent->port->dev_list_lock); in sas_ex_discover_expander()
1007 sas_put_device(child); in sas_ex_discover_expander()
1008 sas_port_delete(phy->port); in sas_ex_discover_expander()
1009 phy->port = NULL; in sas_ex_discover_expander()
1012 list_add_tail(&child->siblings, &parent->ex_dev.children); in sas_ex_discover_expander()
1013 return child; in sas_ex_discover_expander()
1018 struct expander_device *ex = &dev->ex_dev; in sas_ex_discover_dev()
1019 struct ex_phy *ex_phy = &ex->ex_phy[phy_id]; in sas_ex_discover_dev()
1020 struct domain_device *child = NULL; in sas_ex_discover_dev() local
1024 if (ex_phy->linkrate == SAS_SATA_SPINUP_HOLD) { in sas_ex_discover_dev()
1031 /* Parent and domain coherency */ in sas_ex_discover_dev()
1032 if (!dev->parent && (SAS_ADDR(ex_phy->attached_sas_addr) == in sas_ex_discover_dev()
1033 SAS_ADDR(dev->port->sas_addr))) { in sas_ex_discover_dev()
1037 if (dev->parent && (SAS_ADDR(ex_phy->attached_sas_addr) == in sas_ex_discover_dev()
1038 SAS_ADDR(dev->parent->sas_addr))) { in sas_ex_discover_dev()
1040 if (ex_phy->routing_attr == TABLE_ROUTING) in sas_ex_discover_dev()
1041 sas_configure_phy(dev, phy_id, dev->port->sas_addr, 1); in sas_ex_discover_dev()
1045 if (sas_dev_present_in_domain(dev->port, ex_phy->attached_sas_addr)) in sas_ex_discover_dev()
1046 sas_ex_disable_port(dev, ex_phy->attached_sas_addr); in sas_ex_discover_dev()
1048 if (ex_phy->attached_dev_type == SAS_PHY_UNUSED) { in sas_ex_discover_dev()
1049 if (ex_phy->routing_attr == DIRECT_ROUTING) { in sas_ex_discover_dev()
1050 memset(ex_phy->attached_sas_addr, 0, SAS_ADDR_SIZE); in sas_ex_discover_dev()
1051 sas_configure_routing(dev, ex_phy->attached_sas_addr); in sas_ex_discover_dev()
1054 } else if (ex_phy->linkrate == SAS_LINK_RATE_UNKNOWN) in sas_ex_discover_dev()
1057 if (ex_phy->attached_dev_type != SAS_END_DEVICE && in sas_ex_discover_dev()
1058 ex_phy->attached_dev_type != SAS_FANOUT_EXPANDER_DEVICE && in sas_ex_discover_dev()
1059 ex_phy->attached_dev_type != SAS_EDGE_EXPANDER_DEVICE && in sas_ex_discover_dev()
1060 ex_phy->attached_dev_type != SAS_SATA_PENDING) { in sas_ex_discover_dev()
1062 ex_phy->attached_dev_type, in sas_ex_discover_dev()
1063 SAS_ADDR(dev->sas_addr), in sas_ex_discover_dev()
1068 res = sas_configure_routing(dev, ex_phy->attached_sas_addr); in sas_ex_discover_dev()
1071 SAS_ADDR(ex_phy->attached_sas_addr), res); in sas_ex_discover_dev()
1072 sas_disable_routing(dev, ex_phy->attached_sas_addr); in sas_ex_discover_dev()
1078 phy_id, SAS_ADDR(ex_phy->attached_sas_addr)); in sas_ex_discover_dev()
1082 switch (ex_phy->attached_dev_type) { in sas_ex_discover_dev()
1085 child = sas_ex_discover_end_dev(dev, phy_id); in sas_ex_discover_dev()
1088 if (SAS_ADDR(dev->port->disc.fanout_sas_addr)) { in sas_ex_discover_dev()
1090 SAS_ADDR(ex_phy->attached_sas_addr), in sas_ex_discover_dev()
1091 ex_phy->attached_phy_id, in sas_ex_discover_dev()
1092 SAS_ADDR(dev->sas_addr), in sas_ex_discover_dev()
1097 memcpy(dev->port->disc.fanout_sas_addr, in sas_ex_discover_dev()
1098 ex_phy->attached_sas_addr, SAS_ADDR_SIZE); in sas_ex_discover_dev()
1101 child = sas_ex_discover_expander(dev, phy_id); in sas_ex_discover_dev()
1107 if (!child) in sas_ex_discover_dev()
1109 SAS_ADDR(dev->sas_addr), phy_id); in sas_ex_discover_dev()
1115 struct expander_device *ex = &dev->ex_dev; in sas_find_sub_addr()
1118 for (i = 0; i < ex->num_phys; i++) { in sas_find_sub_addr()
1119 struct ex_phy *phy = &ex->ex_phy[i]; in sas_find_sub_addr()
1121 if (phy->phy_state == PHY_VACANT || in sas_find_sub_addr()
1122 phy->phy_state == PHY_NOT_PRESENT) in sas_find_sub_addr()
1125 if (dev_is_expander(phy->attached_dev_type) && in sas_find_sub_addr()
1126 phy->routing_attr == SUBTRACTIVE_ROUTING) { in sas_find_sub_addr()
1128 memcpy(sub_addr, phy->attached_sas_addr, SAS_ADDR_SIZE); in sas_find_sub_addr()
1138 struct expander_device *ex = &dev->ex_dev; in sas_check_level_subtractive_boundary()
1139 struct domain_device *child; in sas_check_level_subtractive_boundary() local
1142 list_for_each_entry(child, &ex->children, siblings) { in sas_check_level_subtractive_boundary()
1143 if (!dev_is_expander(child->dev_type)) in sas_check_level_subtractive_boundary()
1146 sas_find_sub_addr(child, sub_addr); in sas_check_level_subtractive_boundary()
1151 if (sas_find_sub_addr(child, s2) && in sas_check_level_subtractive_boundary()
1154 pr_notice("ex %016llx->%016llx-?->%016llx diverges from subtractive boundary %016llx\n", in sas_check_level_subtractive_boundary()
1155 SAS_ADDR(dev->sas_addr), in sas_check_level_subtractive_boundary()
1156 SAS_ADDR(child->sas_addr), in sas_check_level_subtractive_boundary()
1160 sas_ex_disable_port(child, s2); in sas_check_level_subtractive_boundary()
1167 * sas_ex_discover_devices - discover devices attached to this expander
1169 * @single: if you want to do a single phy, else set to -1;
1176 struct expander_device *ex = &dev->ex_dev; in sas_ex_discover_devices()
1177 int i = 0, end = ex->num_phys; in sas_ex_discover_devices()
1186 struct ex_phy *ex_phy = &ex->ex_phy[i]; in sas_ex_discover_devices()
1188 if (ex_phy->phy_state == PHY_VACANT || in sas_ex_discover_devices()
1189 ex_phy->phy_state == PHY_NOT_PRESENT || in sas_ex_discover_devices()
1190 ex_phy->phy_state == PHY_DEVICE_DISCOVERED) in sas_ex_discover_devices()
1193 switch (ex_phy->linkrate) { in sas_ex_discover_devices()
1214 struct expander_device *ex = &dev->ex_dev; in sas_check_ex_subtractive_boundary()
1218 if (dev->dev_type != SAS_EDGE_EXPANDER_DEVICE) in sas_check_ex_subtractive_boundary()
1221 for (i = 0; i < ex->num_phys; i++) { in sas_check_ex_subtractive_boundary()
1222 struct ex_phy *phy = &ex->ex_phy[i]; in sas_check_ex_subtractive_boundary()
1224 if (phy->phy_state == PHY_VACANT || in sas_check_ex_subtractive_boundary()
1225 phy->phy_state == PHY_NOT_PRESENT) in sas_check_ex_subtractive_boundary()
1228 if (dev_is_expander(phy->attached_dev_type) && in sas_check_ex_subtractive_boundary()
1229 phy->routing_attr == SUBTRACTIVE_ROUTING) { in sas_check_ex_subtractive_boundary()
1232 sub_sas_addr = &phy->attached_sas_addr[0]; in sas_check_ex_subtractive_boundary()
1234 SAS_ADDR(phy->attached_sas_addr)) { in sas_check_ex_subtractive_boundary()
1237 SAS_ADDR(dev->sas_addr), i, in sas_check_ex_subtractive_boundary()
1238 SAS_ADDR(phy->attached_sas_addr), in sas_check_ex_subtractive_boundary()
1247 static void sas_print_parent_topology_bug(struct domain_device *child, in sas_print_parent_topology_bug() argument
1255 struct domain_device *parent = child->parent; in sas_print_parent_topology_bug() local
1257 pr_notice("%s ex %016llx phy%02d <--> %s ex %016llx phy%02d has %c:%c routing link!\n", in sas_print_parent_topology_bug()
1258 ex_type[parent->dev_type], in sas_print_parent_topology_bug()
1259 SAS_ADDR(parent->sas_addr), in sas_print_parent_topology_bug()
1260 parent_phy->phy_id, in sas_print_parent_topology_bug()
1262 ex_type[child->dev_type], in sas_print_parent_topology_bug()
1263 SAS_ADDR(child->sas_addr), in sas_print_parent_topology_bug()
1264 child_phy->phy_id, in sas_print_parent_topology_bug()
1266 sas_route_char(parent, parent_phy), in sas_print_parent_topology_bug()
1267 sas_route_char(child, child_phy)); in sas_print_parent_topology_bug()
1270 static int sas_check_eeds(struct domain_device *child, in sas_check_eeds() argument
1275 struct domain_device *parent = child->parent; in sas_check_eeds() local
1277 if (SAS_ADDR(parent->port->disc.fanout_sas_addr) != 0) { in sas_check_eeds()
1278 res = -ENODEV; in sas_check_eeds()
1279 …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()
1280 SAS_ADDR(parent->sas_addr), in sas_check_eeds()
1281 parent_phy->phy_id, in sas_check_eeds()
1282 SAS_ADDR(child->sas_addr), in sas_check_eeds()
1283 child_phy->phy_id, in sas_check_eeds()
1284 SAS_ADDR(parent->port->disc.fanout_sas_addr)); in sas_check_eeds()
1285 } else if (SAS_ADDR(parent->port->disc.eeds_a) == 0) { in sas_check_eeds()
1286 memcpy(parent->port->disc.eeds_a, parent->sas_addr, in sas_check_eeds()
1288 memcpy(parent->port->disc.eeds_b, child->sas_addr, in sas_check_eeds()
1290 } else if (((SAS_ADDR(parent->port->disc.eeds_a) == in sas_check_eeds()
1291 SAS_ADDR(parent->sas_addr)) || in sas_check_eeds()
1292 (SAS_ADDR(parent->port->disc.eeds_a) == in sas_check_eeds()
1293 SAS_ADDR(child->sas_addr))) in sas_check_eeds()
1295 ((SAS_ADDR(parent->port->disc.eeds_b) == in sas_check_eeds()
1296 SAS_ADDR(parent->sas_addr)) || in sas_check_eeds()
1297 (SAS_ADDR(parent->port->disc.eeds_b) == in sas_check_eeds()
1298 SAS_ADDR(child->sas_addr)))) in sas_check_eeds()
1301 res = -ENODEV; in sas_check_eeds()
1302 pr_warn("edge ex %016llx phy%02d <--> edge ex %016llx phy%02d link forms a third EEDS!\n", in sas_check_eeds()
1303 SAS_ADDR(parent->sas_addr), in sas_check_eeds()
1304 parent_phy->phy_id, in sas_check_eeds()
1305 SAS_ADDR(child->sas_addr), in sas_check_eeds()
1306 child_phy->phy_id); in sas_check_eeds()
1314 static int sas_check_parent_topology(struct domain_device *child) in sas_check_parent_topology() argument
1316 struct expander_device *child_ex = &child->ex_dev; in sas_check_parent_topology()
1321 if (!child->parent) in sas_check_parent_topology()
1324 if (!dev_is_expander(child->parent->dev_type)) in sas_check_parent_topology()
1327 parent_ex = &child->parent->ex_dev; in sas_check_parent_topology()
1329 for (i = 0; i < parent_ex->num_phys; i++) { in sas_check_parent_topology()
1330 struct ex_phy *parent_phy = &parent_ex->ex_phy[i]; in sas_check_parent_topology()
1333 if (parent_phy->phy_state == PHY_VACANT || in sas_check_parent_topology()
1334 parent_phy->phy_state == PHY_NOT_PRESENT) in sas_check_parent_topology()
1337 if (SAS_ADDR(parent_phy->attached_sas_addr) != SAS_ADDR(child->sas_addr)) in sas_check_parent_topology()
1340 child_phy = &child_ex->ex_phy[parent_phy->attached_phy_id]; in sas_check_parent_topology()
1342 switch (child->parent->dev_type) { in sas_check_parent_topology()
1344 if (child->dev_type == SAS_FANOUT_EXPANDER_DEVICE) { in sas_check_parent_topology()
1345 if (parent_phy->routing_attr != SUBTRACTIVE_ROUTING || in sas_check_parent_topology()
1346 child_phy->routing_attr != TABLE_ROUTING) { in sas_check_parent_topology()
1347 sas_print_parent_topology_bug(child, parent_phy, child_phy); in sas_check_parent_topology()
1348 res = -ENODEV; in sas_check_parent_topology()
1350 } else if (parent_phy->routing_attr == SUBTRACTIVE_ROUTING) { in sas_check_parent_topology()
1351 if (child_phy->routing_attr == SUBTRACTIVE_ROUTING) { in sas_check_parent_topology()
1352 res = sas_check_eeds(child, parent_phy, child_phy); in sas_check_parent_topology()
1353 } else if (child_phy->routing_attr != TABLE_ROUTING) { in sas_check_parent_topology()
1354 sas_print_parent_topology_bug(child, parent_phy, child_phy); in sas_check_parent_topology()
1355 res = -ENODEV; in sas_check_parent_topology()
1357 } else if (parent_phy->routing_attr == TABLE_ROUTING) { in sas_check_parent_topology()
1358 if (child_phy->routing_attr == SUBTRACTIVE_ROUTING || in sas_check_parent_topology()
1359 (child_phy->routing_attr == TABLE_ROUTING && in sas_check_parent_topology()
1360 child_ex->t2t_supp && parent_ex->t2t_supp)) { in sas_check_parent_topology()
1363 sas_print_parent_topology_bug(child, parent_phy, child_phy); in sas_check_parent_topology()
1364 res = -ENODEV; in sas_check_parent_topology()
1369 if (parent_phy->routing_attr != TABLE_ROUTING || in sas_check_parent_topology()
1370 child_phy->routing_attr != SUBTRACTIVE_ROUTING) { in sas_check_parent_topology()
1371 sas_print_parent_topology_bug(child, parent_phy, child_phy); in sas_check_parent_topology()
1372 res = -ENODEV; in sas_check_parent_topology()
1390 struct expander_device *ex = &dev->ex_dev; in sas_configure_present()
1391 struct ex_phy *phy = &ex->ex_phy[phy_id]; in sas_configure_present()
1400 return -ENOMEM; in sas_configure_present()
1405 return -ENOMEM; in sas_configure_present()
1411 for (i = 0; i < ex->max_route_indexes ; i++) { in sas_configure_present()
1420 SAS_ADDR(dev->sas_addr), phy_id, i); in sas_configure_present()
1424 __func__, SAS_ADDR(dev->sas_addr), phy_id, in sas_configure_present()
1442 phy->last_da_index < i) { in sas_configure_present()
1443 phy->last_da_index = i; in sas_configure_present()
1449 res = -1; in sas_configure_present()
1468 return -ENOMEM; in sas_configure_set()
1473 return -ENOMEM; in sas_configure_set()
1490 SAS_ADDR(dev->sas_addr), phy_id, index); in sas_configure_set()
1515 * sas_configure_parent - configure routing table of parent
1516 * @parent: parent expander
1517 * @child: child expander
1518 * @sas_addr: SAS port identifier of device directly attached to child
1519 * @include: whether or not to include @child in the expander routing table
1521 static int sas_configure_parent(struct domain_device *parent, in sas_configure_parent() argument
1522 struct domain_device *child, in sas_configure_parent() argument
1525 struct expander_device *ex_parent = &parent->ex_dev; in sas_configure_parent()
1529 if (parent->parent) { in sas_configure_parent()
1530 res = sas_configure_parent(parent->parent, parent, sas_addr, in sas_configure_parent()
1536 if (ex_parent->conf_route_table == 0) { in sas_configure_parent()
1537 pr_debug("ex %016llx has self-configuring routing table\n", in sas_configure_parent()
1538 SAS_ADDR(parent->sas_addr)); in sas_configure_parent()
1542 for (i = 0; i < ex_parent->num_phys; i++) { in sas_configure_parent()
1543 struct ex_phy *phy = &ex_parent->ex_phy[i]; in sas_configure_parent()
1545 if ((phy->routing_attr == TABLE_ROUTING) && in sas_configure_parent()
1546 (SAS_ADDR(phy->attached_sas_addr) == in sas_configure_parent()
1547 SAS_ADDR(child->sas_addr))) { in sas_configure_parent()
1548 res = sas_configure_phy(parent, i, sas_addr, include); in sas_configure_parent()
1558 * sas_configure_routing - configure routing
1564 if (dev->parent) in sas_configure_routing()
1565 return sas_configure_parent(dev->parent, dev, sas_addr, 1); in sas_configure_routing()
1571 if (dev->parent) in sas_disable_routing()
1572 return sas_configure_parent(dev->parent, dev, sas_addr, 0); in sas_disable_routing()
1577 * sas_discover_expander - expander discovery
1600 SAS_ADDR(dev->sas_addr), res); in sas_discover_expander()
1619 list_for_each_entry(dev, &port->dev_list, dev_list_node) { in sas_ex_level_discovery()
1620 if (dev_is_expander(dev->dev_type)) { in sas_ex_level_discovery()
1622 rphy_to_expander_device(dev->rphy); in sas_ex_level_discovery()
1624 if (level == ex->level) in sas_ex_level_discovery()
1625 res = sas_ex_discover_devices(dev, -1); in sas_ex_level_discovery()
1627 res = sas_ex_discover_devices(port->port_dev, -1); in sas_ex_level_discovery()
1641 level = port->disc.max_level; in sas_ex_bfs_disc()
1644 } while (level < port->disc.max_level); in sas_ex_bfs_disc()
1652 struct sas_expander_device *ex = rphy_to_expander_device(dev->rphy); in sas_discover_root_expander()
1654 res = sas_rphy_add(dev->rphy); in sas_discover_root_expander()
1658 ex->level = dev->port->disc.max_level; /* 0 */ in sas_discover_root_expander()
1663 sas_ex_bfs_disc(dev->port); in sas_discover_root_expander()
1668 sas_rphy_remove(dev->rphy); in sas_discover_root_expander()
1673 /* ---------- Domain revalidation ---------- */
1683 return -ENOMEM; in sas_get_phy_discover()
1692 else if (disc_resp->result != SMP_RESP_FUNC_ACC) { in sas_get_phy_discover()
1693 res = disc_resp->result; in sas_get_phy_discover()
1709 return -ENOMEM; in sas_get_phy_change_count()
1713 *pcc = disc_resp->disc.change_count; in sas_get_phy_change_count()
1728 return -ENOMEM; in sas_get_phy_attached_dev()
1729 dr = &disc_resp->disc; in sas_get_phy_attached_dev()
1733 memcpy(sas_addr, disc_resp->disc.attached_sas_addr, in sas_get_phy_attached_dev()
1746 struct expander_device *ex = &dev->ex_dev; in sas_find_bcast_phy()
1750 for (i = from_phy; i < ex->num_phys; i++) { in sas_find_bcast_phy()
1764 if (phy_change_count != ex->ex_phy[i].phy_change_count) { in sas_find_bcast_phy()
1766 ex->ex_phy[i].phy_change_count = in sas_find_bcast_phy()
1783 return -ENOMEM; in sas_get_ex_change_count()
1788 return -ENOMEM; in sas_get_ex_change_count()
1797 if (rg_resp->result != SMP_RESP_FUNC_ACC) { in sas_get_ex_change_count()
1798 res = rg_resp->result; in sas_get_ex_change_count()
1802 *ecc = be16_to_cpu(rg_resp->rg.change_count); in sas_get_ex_change_count()
1809 * sas_find_bcast_dev - find the device issue BROADCAST(CHANGE).
1813 * Add self-configuration expander support. Suppose two expander cascading,
1814 * when the first level expander is self-configuring, hotplug the disks in
1817 * expander (see SAS protocol SAS 2r-14, 7.11 for detail), it is to say,
1826 struct expander_device *ex = &dev->ex_dev; in sas_find_bcast_dev()
1827 int ex_change_count = -1; in sas_find_bcast_dev()
1828 int phy_id = -1; in sas_find_bcast_dev()
1835 if (ex_change_count != -1 && ex_change_count != ex->ex_change_count) { in sas_find_bcast_dev()
1841 if (phy_id != -1) { in sas_find_bcast_dev()
1843 ex->ex_change_count = ex_change_count; in sas_find_bcast_dev()
1845 SAS_ADDR(dev->sas_addr), phy_id); in sas_find_bcast_dev()
1849 SAS_ADDR(dev->sas_addr)); in sas_find_bcast_dev()
1851 list_for_each_entry(ch, &ex->children, siblings) { in sas_find_bcast_dev()
1852 if (dev_is_expander(ch->dev_type)) { in sas_find_bcast_dev()
1864 struct expander_device *ex = &dev->ex_dev; in sas_unregister_ex_tree()
1865 struct domain_device *child, *n; in sas_unregister_ex_tree() local
1867 list_for_each_entry_safe(child, n, &ex->children, siblings) { in sas_unregister_ex_tree()
1868 set_bit(SAS_DEV_GONE, &child->state); in sas_unregister_ex_tree()
1869 if (dev_is_expander(child->dev_type)) in sas_unregister_ex_tree()
1870 sas_unregister_ex_tree(port, child); in sas_unregister_ex_tree()
1872 sas_unregister_dev(port, child); in sas_unregister_ex_tree()
1877 static void sas_unregister_devs_sas_addr(struct domain_device *parent, in sas_unregister_devs_sas_addr() argument
1880 struct expander_device *ex_dev = &parent->ex_dev; in sas_unregister_devs_sas_addr()
1881 struct ex_phy *phy = &ex_dev->ex_phy[phy_id]; in sas_unregister_devs_sas_addr()
1882 struct domain_device *child, *n, *found = NULL; in sas_unregister_devs_sas_addr() local
1884 list_for_each_entry_safe(child, n, in sas_unregister_devs_sas_addr()
1885 &ex_dev->children, siblings) { in sas_unregister_devs_sas_addr()
1886 if (SAS_ADDR(child->sas_addr) == in sas_unregister_devs_sas_addr()
1887 SAS_ADDR(phy->attached_sas_addr)) { in sas_unregister_devs_sas_addr()
1888 set_bit(SAS_DEV_GONE, &child->state); in sas_unregister_devs_sas_addr()
1889 if (dev_is_expander(child->dev_type)) in sas_unregister_devs_sas_addr()
1890 sas_unregister_ex_tree(parent->port, child); in sas_unregister_devs_sas_addr()
1892 sas_unregister_dev(parent->port, child); in sas_unregister_devs_sas_addr()
1893 found = child; in sas_unregister_devs_sas_addr()
1897 sas_disable_routing(parent, phy->attached_sas_addr); in sas_unregister_devs_sas_addr()
1899 memset(phy->attached_sas_addr, 0, SAS_ADDR_SIZE); in sas_unregister_devs_sas_addr()
1900 if (phy->port) { in sas_unregister_devs_sas_addr()
1901 sas_port_delete_phy(phy->port, phy->phy); in sas_unregister_devs_sas_addr()
1902 sas_device_set_phy(found, phy->port); in sas_unregister_devs_sas_addr()
1903 if (phy->port->num_phys == 0) in sas_unregister_devs_sas_addr()
1904 list_add_tail(&phy->port->del_list, in sas_unregister_devs_sas_addr()
1905 &parent->port->sas_port_del_list); in sas_unregister_devs_sas_addr()
1906 phy->port = NULL; in sas_unregister_devs_sas_addr()
1913 struct expander_device *ex_root = &root->ex_dev; in sas_discover_bfs_by_root_level()
1914 struct domain_device *child; in sas_discover_bfs_by_root_level() local
1917 list_for_each_entry(child, &ex_root->children, siblings) { in sas_discover_bfs_by_root_level()
1918 if (dev_is_expander(child->dev_type)) { in sas_discover_bfs_by_root_level()
1920 rphy_to_expander_device(child->rphy); in sas_discover_bfs_by_root_level()
1922 if (level > ex->level) in sas_discover_bfs_by_root_level()
1923 res = sas_discover_bfs_by_root_level(child, in sas_discover_bfs_by_root_level()
1925 else if (level == ex->level) in sas_discover_bfs_by_root_level()
1926 res = sas_ex_discover_devices(child, -1); in sas_discover_bfs_by_root_level()
1935 struct sas_expander_device *ex = rphy_to_expander_device(dev->rphy); in sas_discover_bfs_by_root()
1936 int level = ex->level+1; in sas_discover_bfs_by_root()
1938 res = sas_ex_discover_devices(dev, -1); in sas_discover_bfs_by_root()
1945 } while (level <= dev->port->disc.max_level); in sas_discover_bfs_by_root()
1952 struct ex_phy *ex_phy = &dev->ex_dev.ex_phy[phy_id]; in sas_discover_new()
1953 struct domain_device *child; in sas_discover_new() local
1957 SAS_ADDR(dev->sas_addr), phy_id); in sas_discover_new()
1968 list_for_each_entry(child, &dev->ex_dev.children, siblings) { in sas_discover_new()
1969 if (SAS_ADDR(child->sas_addr) == in sas_discover_new()
1970 SAS_ADDR(ex_phy->attached_sas_addr)) { in sas_discover_new()
1971 if (dev_is_expander(child->dev_type)) in sas_discover_new()
1972 res = sas_discover_bfs_by_root(child); in sas_discover_new()
1997 struct expander_device *ex = &dev->ex_dev; in sas_rediscover_dev()
1998 struct ex_phy *phy = &ex->ex_phy[phy_id]; in sas_rediscover_dev()
2008 SAS_ADDR(dev->sas_addr), phy_id, msg); in sas_rediscover_dev()
2014 phy->phy_state = PHY_NOT_PRESENT; in sas_rediscover_dev()
2018 phy->phy_state = PHY_VACANT; in sas_rediscover_dev()
2023 case -ECOMM: in sas_rediscover_dev()
2029 if ((SAS_ADDR(sas_addr) == 0) || (res == -ECOMM)) { in sas_rediscover_dev()
2030 phy->phy_state = PHY_EMPTY; in sas_rediscover_dev()
2038 } else if (SAS_ADDR(sas_addr) == SAS_ADDR(phy->attached_sas_addr) && in sas_rediscover_dev()
2039 dev_type_flutter(type, phy->attached_dev_type)) { in sas_rediscover_dev()
2045 if (ata_dev && phy->attached_dev_type == SAS_SATA_PENDING) in sas_rediscover_dev()
2048 SAS_ADDR(dev->sas_addr), phy_id, action); in sas_rediscover_dev()
2054 SAS_ADDR(dev->sas_addr), phy_id, in sas_rediscover_dev()
2055 SAS_ADDR(phy->attached_sas_addr)); in sas_rediscover_dev()
2062 * sas_rediscover - revalidate the domain.
2069 * domain.For plugging out, we un-register the device only when it is
2073 * forming the wide-port.
2077 struct expander_device *ex = &dev->ex_dev; in sas_rediscover()
2078 struct ex_phy *changed_phy = &ex->ex_phy[phy_id]; in sas_rediscover()
2084 SAS_ADDR(dev->sas_addr), phy_id); in sas_rediscover()
2086 if (SAS_ADDR(changed_phy->attached_sas_addr) != 0) { in sas_rediscover()
2087 for (i = 0; i < ex->num_phys; i++) { in sas_rediscover()
2088 struct ex_phy *phy = &ex->ex_phy[i]; in sas_rediscover()
2092 if (SAS_ADDR(phy->attached_sas_addr) == in sas_rediscover()
2093 SAS_ADDR(changed_phy->attached_sas_addr)) { in sas_rediscover()
2105 * sas_ex_revalidate_domain - revalidate the domain
2120 struct expander_device *ex = &dev->ex_dev; in sas_ex_revalidate_domain()
2124 phy_id = -1; in sas_ex_revalidate_domain()
2126 if (phy_id == -1) in sas_ex_revalidate_domain()
2130 } while (i < ex->num_phys); in sas_ex_revalidate_domain()
2140 int ret = -EINVAL; in sas_smp_handler()
2146 switch (rphy->identify.device_type) { in sas_smp_handler()
2163 if (job->request_payload.sg_cnt > 1 || in sas_smp_handler()
2164 job->reply_payload.sg_cnt > 1) { in sas_smp_handler()
2166 __func__, job->request_payload.payload_len, in sas_smp_handler()
2167 job->reply_payload.payload_len); in sas_smp_handler()
2171 ret = smp_execute_task_sg(dev, job->request_payload.sg_list, in sas_smp_handler()
2172 job->reply_payload.sg_list); in sas_smp_handler()
2175 rcvlen = job->reply_payload.payload_len - ret; in sas_smp_handler()