2 * Serial Attached SCSI (SAS) Expander discovery and configuration
4 * Copyright (C) 2005 Adaptec, Inc. All rights reserved.
5 * Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
7 * This file is licensed under GPLv2.
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <linux/pci.h>
26 #include <linux/scatterlist.h>
28 #include "sas_internal.h"
30 #include <scsi/scsi_transport.h>
31 #include <scsi/scsi_transport_sas.h>
32 #include "../scsi_sas_internal.h"
34 static int sas_discover_expander(struct domain_device *dev);
35 static int sas_configure_routing(struct domain_device *dev, u8 *sas_addr);
36 static int sas_configure_phy(struct domain_device *dev, int phy_id,
37 u8 *sas_addr, int include);
38 static int sas_disable_routing(struct domain_device *dev, u8 *sas_addr);
41 /* FIXME: smp needs to migrate into the sas class */
42 static ssize_t smp_portal_read(struct kobject *, char *, loff_t, size_t);
43 static ssize_t smp_portal_write(struct kobject *, char *, loff_t, size_t);
46 /* ---------- SMP task management ---------- */
48 static void smp_task_timedout(unsigned long _task)
50 struct sas_task *task = (void *) _task;
53 spin_lock_irqsave(&task->task_state_lock, flags);
54 if (!(task->task_state_flags & SAS_TASK_STATE_DONE))
55 task->task_state_flags |= SAS_TASK_STATE_ABORTED;
56 spin_unlock_irqrestore(&task->task_state_lock, flags);
58 complete(&task->completion);
61 static void smp_task_done(struct sas_task *task)
63 if (!del_timer(&task->timer))
65 complete(&task->completion);
68 /* Give it some long enough timeout. In seconds. */
69 #define SMP_TIMEOUT 10
71 static int smp_execute_task(struct domain_device *dev, void *req, int req_size,
72 void *resp, int resp_size)
75 struct sas_task *task = NULL;
76 struct sas_internal *i =
77 to_sas_internal(dev->port->ha->core.shost->transportt);
79 for (retry = 0; retry < 3; retry++) {
80 task = sas_alloc_task(GFP_KERNEL);
85 task->task_proto = dev->tproto;
86 sg_init_one(&task->smp_task.smp_req, req, req_size);
87 sg_init_one(&task->smp_task.smp_resp, resp, resp_size);
89 task->task_done = smp_task_done;
91 task->timer.data = (unsigned long) task;
92 task->timer.function = smp_task_timedout;
93 task->timer.expires = jiffies + SMP_TIMEOUT*HZ;
94 add_timer(&task->timer);
96 res = i->dft->lldd_execute_task(task, 1, GFP_KERNEL);
99 del_timer(&task->timer);
100 SAS_DPRINTK("executing SMP task failed:%d\n", res);
104 wait_for_completion(&task->completion);
106 if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
107 SAS_DPRINTK("smp task timed out or aborted\n");
108 i->dft->lldd_abort_task(task);
109 if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) {
110 SAS_DPRINTK("SMP task aborted and not done\n");
114 if (task->task_status.resp == SAS_TASK_COMPLETE &&
115 task->task_status.stat == SAM_GOOD) {
119 SAS_DPRINTK("%s: task to dev %016llx response: 0x%x "
120 "status 0x%x\n", __FUNCTION__,
121 SAS_ADDR(dev->sas_addr),
122 task->task_status.resp,
123 task->task_status.stat);
129 BUG_ON(retry == 3 && task != NULL);
136 /* ---------- Allocations ---------- */
138 static inline void *alloc_smp_req(int size)
140 u8 *p = kzalloc(size, GFP_KERNEL);
146 static inline void *alloc_smp_resp(int size)
148 return kzalloc(size, GFP_KERNEL);
151 /* ---------- Expander configuration ---------- */
153 static void sas_set_ex_phy(struct domain_device *dev, int phy_id,
156 struct expander_device *ex = &dev->ex_dev;
157 struct ex_phy *phy = &ex->ex_phy[phy_id];
158 struct smp_resp *resp = disc_resp;
159 struct discover_resp *dr = &resp->disc;
160 struct sas_rphy *rphy = dev->rphy;
161 int rediscover = (phy->phy != NULL);
164 phy->phy = sas_phy_alloc(&rphy->dev, phy_id);
166 /* FIXME: error_handling */
170 switch (resp->result) {
171 case SMP_RESP_PHY_VACANT:
172 phy->phy_state = PHY_VACANT;
175 phy->phy_state = PHY_NOT_PRESENT;
177 case SMP_RESP_FUNC_ACC:
178 phy->phy_state = PHY_EMPTY; /* do not know yet */
182 phy->phy_id = phy_id;
183 phy->attached_dev_type = dr->attached_dev_type;
184 phy->linkrate = dr->linkrate;
185 phy->attached_sata_host = dr->attached_sata_host;
186 phy->attached_sata_dev = dr->attached_sata_dev;
187 phy->attached_sata_ps = dr->attached_sata_ps;
188 phy->attached_iproto = dr->iproto << 1;
189 phy->attached_tproto = dr->tproto << 1;
190 memcpy(phy->attached_sas_addr, dr->attached_sas_addr, SAS_ADDR_SIZE);
191 phy->attached_phy_id = dr->attached_phy_id;
192 phy->phy_change_count = dr->change_count;
193 phy->routing_attr = dr->routing_attr;
194 phy->virtual = dr->virtual;
195 phy->last_da_index = -1;
197 phy->phy->identify.initiator_port_protocols = phy->attached_iproto;
198 phy->phy->identify.target_port_protocols = phy->attached_tproto;
199 phy->phy->identify.phy_identifier = phy_id;
200 phy->phy->minimum_linkrate_hw = dr->hmin_linkrate;
201 phy->phy->maximum_linkrate_hw = dr->hmax_linkrate;
202 phy->phy->minimum_linkrate = dr->pmin_linkrate;
203 phy->phy->maximum_linkrate = dr->pmax_linkrate;
204 phy->phy->negotiated_linkrate = phy->linkrate;
207 sas_phy_add(phy->phy);
209 SAS_DPRINTK("ex %016llx phy%02d:%c attached: %016llx\n",
210 SAS_ADDR(dev->sas_addr), phy->phy_id,
211 phy->routing_attr == TABLE_ROUTING ? 'T' :
212 phy->routing_attr == DIRECT_ROUTING ? 'D' :
213 phy->routing_attr == SUBTRACTIVE_ROUTING ? 'S' : '?',
214 SAS_ADDR(phy->attached_sas_addr));
219 #define DISCOVER_REQ_SIZE 16
220 #define DISCOVER_RESP_SIZE 56
222 static int sas_ex_phy_discover(struct domain_device *dev, int single)
224 struct expander_device *ex = &dev->ex_dev;
229 disc_req = alloc_smp_req(DISCOVER_REQ_SIZE);
233 disc_resp = alloc_smp_req(DISCOVER_RESP_SIZE);
239 disc_req[1] = SMP_DISCOVER;
241 if (0 <= single && single < ex->num_phys) {
242 disc_req[9] = single;
243 res = smp_execute_task(dev, disc_req, DISCOVER_REQ_SIZE,
244 disc_resp, DISCOVER_RESP_SIZE);
247 sas_set_ex_phy(dev, single, disc_resp);
251 for (i = 0; i < ex->num_phys; i++) {
253 res = smp_execute_task(dev, disc_req,
254 DISCOVER_REQ_SIZE, disc_resp,
258 sas_set_ex_phy(dev, i, disc_resp);
267 static int sas_expander_discover(struct domain_device *dev)
269 struct expander_device *ex = &dev->ex_dev;
272 ex->ex_phy = kzalloc(sizeof(*ex->ex_phy)*ex->num_phys, GFP_KERNEL);
276 res = sas_ex_phy_discover(dev, -1);
287 #define MAX_EXPANDER_PHYS 128
289 static void ex_assign_report_general(struct domain_device *dev,
290 struct smp_resp *resp)
292 struct report_general_resp *rg = &resp->rg;
294 dev->ex_dev.ex_change_count = be16_to_cpu(rg->change_count);
295 dev->ex_dev.max_route_indexes = be16_to_cpu(rg->route_indexes);
296 dev->ex_dev.num_phys = min(rg->num_phys, (u8)MAX_EXPANDER_PHYS);
297 dev->ex_dev.conf_route_table = rg->conf_route_table;
298 dev->ex_dev.configuring = rg->configuring;
299 memcpy(dev->ex_dev.enclosure_logical_id, rg->enclosure_logical_id, 8);
302 #define RG_REQ_SIZE 8
303 #define RG_RESP_SIZE 32
305 static int sas_ex_general(struct domain_device *dev)
308 struct smp_resp *rg_resp;
312 rg_req = alloc_smp_req(RG_REQ_SIZE);
316 rg_resp = alloc_smp_resp(RG_RESP_SIZE);
322 rg_req[1] = SMP_REPORT_GENERAL;
324 for (i = 0; i < 5; i++) {
325 res = smp_execute_task(dev, rg_req, RG_REQ_SIZE, rg_resp,
329 SAS_DPRINTK("RG to ex %016llx failed:0x%x\n",
330 SAS_ADDR(dev->sas_addr), res);
332 } else if (rg_resp->result != SMP_RESP_FUNC_ACC) {
333 SAS_DPRINTK("RG:ex %016llx returned SMP result:0x%x\n",
334 SAS_ADDR(dev->sas_addr), rg_resp->result);
335 res = rg_resp->result;
339 ex_assign_report_general(dev, rg_resp);
341 if (dev->ex_dev.configuring) {
342 SAS_DPRINTK("RG: ex %llx self-configuring...\n",
343 SAS_ADDR(dev->sas_addr));
344 schedule_timeout_interruptible(5*HZ);
354 static void ex_assign_manuf_info(struct domain_device *dev, void
357 u8 *mi_resp = _mi_resp;
358 struct sas_rphy *rphy = dev->rphy;
359 struct sas_expander_device *edev = rphy_to_expander_device(rphy);
361 memcpy(edev->vendor_id, mi_resp + 12, SAS_EXPANDER_VENDOR_ID_LEN);
362 memcpy(edev->product_id, mi_resp + 20, SAS_EXPANDER_PRODUCT_ID_LEN);
363 memcpy(edev->product_rev, mi_resp + 36,
364 SAS_EXPANDER_PRODUCT_REV_LEN);
366 if (mi_resp[8] & 1) {
367 memcpy(edev->component_vendor_id, mi_resp + 40,
368 SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN);
369 edev->component_id = mi_resp[48] << 8 | mi_resp[49];
370 edev->component_revision_id = mi_resp[50];
374 #define MI_REQ_SIZE 8
375 #define MI_RESP_SIZE 64
377 static int sas_ex_manuf_info(struct domain_device *dev)
383 mi_req = alloc_smp_req(MI_REQ_SIZE);
387 mi_resp = alloc_smp_resp(MI_RESP_SIZE);
393 mi_req[1] = SMP_REPORT_MANUF_INFO;
395 res = smp_execute_task(dev, mi_req, MI_REQ_SIZE, mi_resp,MI_RESP_SIZE);
397 SAS_DPRINTK("MI: ex %016llx failed:0x%x\n",
398 SAS_ADDR(dev->sas_addr), res);
400 } else if (mi_resp[2] != SMP_RESP_FUNC_ACC) {
401 SAS_DPRINTK("MI ex %016llx returned SMP result:0x%x\n",
402 SAS_ADDR(dev->sas_addr), mi_resp[2]);
406 ex_assign_manuf_info(dev, mi_resp);
413 #define PC_REQ_SIZE 44
414 #define PC_RESP_SIZE 8
416 int sas_smp_phy_control(struct domain_device *dev, int phy_id,
417 enum phy_func phy_func,
418 struct sas_phy_linkrates *rates)
424 pc_req = alloc_smp_req(PC_REQ_SIZE);
428 pc_resp = alloc_smp_resp(PC_RESP_SIZE);
434 pc_req[1] = SMP_PHY_CONTROL;
436 pc_req[10]= phy_func;
438 pc_req[32] = rates->minimum_linkrate << 4;
439 pc_req[33] = rates->maximum_linkrate << 4;
442 res = smp_execute_task(dev, pc_req, PC_REQ_SIZE, pc_resp,PC_RESP_SIZE);
449 static void sas_ex_disable_phy(struct domain_device *dev, int phy_id)
451 struct expander_device *ex = &dev->ex_dev;
452 struct ex_phy *phy = &ex->ex_phy[phy_id];
454 sas_smp_phy_control(dev, phy_id, PHY_FUNC_DISABLE, NULL);
455 phy->linkrate = SAS_PHY_DISABLED;
458 static void sas_ex_disable_port(struct domain_device *dev, u8 *sas_addr)
460 struct expander_device *ex = &dev->ex_dev;
463 for (i = 0; i < ex->num_phys; i++) {
464 struct ex_phy *phy = &ex->ex_phy[i];
466 if (phy->phy_state == PHY_VACANT ||
467 phy->phy_state == PHY_NOT_PRESENT)
470 if (SAS_ADDR(phy->attached_sas_addr) == SAS_ADDR(sas_addr))
471 sas_ex_disable_phy(dev, i);
475 static int sas_dev_present_in_domain(struct asd_sas_port *port,
478 struct domain_device *dev;
480 if (SAS_ADDR(port->sas_addr) == SAS_ADDR(sas_addr))
482 list_for_each_entry(dev, &port->dev_list, dev_list_node) {
483 if (SAS_ADDR(dev->sas_addr) == SAS_ADDR(sas_addr))
489 #define RPEL_REQ_SIZE 16
490 #define RPEL_RESP_SIZE 32
491 int sas_smp_get_phy_events(struct sas_phy *phy)
494 struct sas_rphy *rphy = dev_to_rphy(phy->dev.parent);
495 struct domain_device *dev = sas_find_dev_by_rphy(rphy);
496 u8 *req = alloc_smp_req(RPEL_REQ_SIZE);
497 u8 *resp = kzalloc(RPEL_RESP_SIZE, GFP_KERNEL);
502 req[1] = SMP_REPORT_PHY_ERR_LOG;
503 req[9] = phy->number;
505 res = smp_execute_task(dev, req, RPEL_REQ_SIZE,
506 resp, RPEL_RESP_SIZE);
511 phy->invalid_dword_count = scsi_to_u32(&resp[12]);
512 phy->running_disparity_error_count = scsi_to_u32(&resp[16]);
513 phy->loss_of_dword_sync_count = scsi_to_u32(&resp[20]);
514 phy->phy_reset_problem_count = scsi_to_u32(&resp[24]);
522 #define RPS_REQ_SIZE 16
523 #define RPS_RESP_SIZE 60
525 static int sas_get_report_phy_sata(struct domain_device *dev,
527 struct smp_resp *rps_resp)
530 u8 *rps_req = alloc_smp_req(RPS_REQ_SIZE);
535 rps_req[1] = SMP_REPORT_PHY_SATA;
538 res = smp_execute_task(dev, rps_req, RPS_REQ_SIZE,
539 rps_resp, RPS_RESP_SIZE);
545 static void sas_ex_get_linkrate(struct domain_device *parent,
546 struct domain_device *child,
547 struct ex_phy *parent_phy)
549 struct expander_device *parent_ex = &parent->ex_dev;
550 struct sas_port *port;
555 port = parent_phy->port;
557 for (i = 0; i < parent_ex->num_phys; i++) {
558 struct ex_phy *phy = &parent_ex->ex_phy[i];
560 if (phy->phy_state == PHY_VACANT ||
561 phy->phy_state == PHY_NOT_PRESENT)
564 if (SAS_ADDR(phy->attached_sas_addr) ==
565 SAS_ADDR(child->sas_addr)) {
567 child->min_linkrate = min(parent->min_linkrate,
569 child->max_linkrate = max(parent->max_linkrate,
572 sas_port_add_phy(port, phy->phy);
575 child->linkrate = min(parent_phy->linkrate, child->max_linkrate);
576 child->pathways = min(child->pathways, parent->pathways);
579 static struct domain_device *sas_ex_discover_end_dev(
580 struct domain_device *parent, int phy_id)
582 struct expander_device *parent_ex = &parent->ex_dev;
583 struct ex_phy *phy = &parent_ex->ex_phy[phy_id];
584 struct domain_device *child = NULL;
585 struct sas_rphy *rphy;
588 if (phy->attached_sata_host || phy->attached_sata_ps)
591 child = kzalloc(sizeof(*child), GFP_KERNEL);
595 child->parent = parent;
596 child->port = parent->port;
597 child->iproto = phy->attached_iproto;
598 memcpy(child->sas_addr, phy->attached_sas_addr, SAS_ADDR_SIZE);
599 sas_hash_addr(child->hashed_sas_addr, child->sas_addr);
601 phy->port = sas_port_alloc(&parent->rphy->dev, phy_id);
602 if (unlikely(!phy->port))
604 if (unlikely(sas_port_add(phy->port) != 0)) {
605 sas_port_free(phy->port);
609 sas_ex_get_linkrate(parent, child, phy);
611 if ((phy->attached_tproto & SAS_PROTO_STP) || phy->attached_sata_dev) {
612 child->dev_type = SATA_DEV;
613 if (phy->attached_tproto & SAS_PROTO_STP)
614 child->tproto = phy->attached_tproto;
615 if (phy->attached_sata_dev)
616 child->tproto |= SATA_DEV;
617 res = sas_get_report_phy_sata(parent, phy_id,
618 &child->sata_dev.rps_resp);
620 SAS_DPRINTK("report phy sata to %016llx:0x%x returned "
621 "0x%x\n", SAS_ADDR(parent->sas_addr),
625 memcpy(child->frame_rcvd, &child->sata_dev.rps_resp.rps.fis,
626 sizeof(struct dev_to_host_fis));
628 res = sas_discover_sata(child);
630 SAS_DPRINTK("sas_discover_sata() for device %16llx at "
631 "%016llx:0x%x returned 0x%x\n",
632 SAS_ADDR(child->sas_addr),
633 SAS_ADDR(parent->sas_addr), phy_id, res);
636 } else if (phy->attached_tproto & SAS_PROTO_SSP) {
637 child->dev_type = SAS_END_DEV;
638 rphy = sas_end_device_alloc(phy->port);
639 /* FIXME: error handling */
642 child->tproto = phy->attached_tproto;
646 sas_fill_in_rphy(child, rphy);
648 spin_lock(&parent->port->dev_list_lock);
649 list_add_tail(&child->dev_list_node, &parent->port->dev_list);
650 spin_unlock(&parent->port->dev_list_lock);
652 res = sas_discover_end_dev(child);
654 SAS_DPRINTK("sas_discover_end_dev() for device %16llx "
655 "at %016llx:0x%x returned 0x%x\n",
656 SAS_ADDR(child->sas_addr),
657 SAS_ADDR(parent->sas_addr), phy_id, res);
661 SAS_DPRINTK("target proto 0x%x at %016llx:0x%x not handled\n",
662 phy->attached_tproto, SAS_ADDR(parent->sas_addr),
666 list_add_tail(&child->siblings, &parent_ex->children);
670 list_del(&child->dev_list_node);
672 sas_port_delete(phy->port);
679 static struct domain_device *sas_ex_discover_expander(
680 struct domain_device *parent, int phy_id)
682 struct sas_expander_device *parent_ex = rphy_to_expander_device(parent->rphy);
683 struct ex_phy *phy = &parent->ex_dev.ex_phy[phy_id];
684 struct domain_device *child = NULL;
685 struct sas_rphy *rphy;
686 struct sas_expander_device *edev;
687 struct asd_sas_port *port;
690 if (phy->routing_attr == DIRECT_ROUTING) {
691 SAS_DPRINTK("ex %016llx:0x%x:D <--> ex %016llx:0x%x is not "
693 SAS_ADDR(parent->sas_addr), phy_id,
694 SAS_ADDR(phy->attached_sas_addr),
695 phy->attached_phy_id);
698 child = kzalloc(sizeof(*child), GFP_KERNEL);
702 phy->port = sas_port_alloc(&parent->rphy->dev, phy_id);
703 /* FIXME: better error handling */
704 BUG_ON(sas_port_add(phy->port) != 0);
707 switch (phy->attached_dev_type) {
709 rphy = sas_expander_alloc(phy->port,
710 SAS_EDGE_EXPANDER_DEVICE);
713 rphy = sas_expander_alloc(phy->port,
714 SAS_FANOUT_EXPANDER_DEVICE);
717 rphy = NULL; /* shut gcc up */
722 edev = rphy_to_expander_device(rphy);
723 child->dev_type = phy->attached_dev_type;
724 child->parent = parent;
726 child->iproto = phy->attached_iproto;
727 child->tproto = phy->attached_tproto;
728 memcpy(child->sas_addr, phy->attached_sas_addr, SAS_ADDR_SIZE);
729 sas_hash_addr(child->hashed_sas_addr, child->sas_addr);
730 sas_ex_get_linkrate(parent, child, phy);
731 edev->level = parent_ex->level + 1;
732 parent->port->disc.max_level = max(parent->port->disc.max_level,
735 sas_fill_in_rphy(child, rphy);
738 spin_lock(&parent->port->dev_list_lock);
739 list_add_tail(&child->dev_list_node, &parent->port->dev_list);
740 spin_unlock(&parent->port->dev_list_lock);
742 res = sas_discover_expander(child);
747 list_add_tail(&child->siblings, &parent->ex_dev.children);
751 static int sas_ex_discover_dev(struct domain_device *dev, int phy_id)
753 struct expander_device *ex = &dev->ex_dev;
754 struct ex_phy *ex_phy = &ex->ex_phy[phy_id];
755 struct domain_device *child = NULL;
759 if (ex_phy->linkrate == SAS_SATA_SPINUP_HOLD) {
760 if (!sas_smp_phy_control(dev, phy_id, PHY_FUNC_LINK_RESET, NULL))
761 res = sas_ex_phy_discover(dev, phy_id);
766 /* Parent and domain coherency */
767 if (!dev->parent && (SAS_ADDR(ex_phy->attached_sas_addr) ==
768 SAS_ADDR(dev->port->sas_addr))) {
769 sas_add_parent_port(dev, phy_id);
772 if (dev->parent && (SAS_ADDR(ex_phy->attached_sas_addr) ==
773 SAS_ADDR(dev->parent->sas_addr))) {
774 sas_add_parent_port(dev, phy_id);
775 if (ex_phy->routing_attr == TABLE_ROUTING)
776 sas_configure_phy(dev, phy_id, dev->port->sas_addr, 1);
780 if (sas_dev_present_in_domain(dev->port, ex_phy->attached_sas_addr))
781 sas_ex_disable_port(dev, ex_phy->attached_sas_addr);
783 if (ex_phy->attached_dev_type == NO_DEVICE) {
784 if (ex_phy->routing_attr == DIRECT_ROUTING) {
785 memset(ex_phy->attached_sas_addr, 0, SAS_ADDR_SIZE);
786 sas_configure_routing(dev, ex_phy->attached_sas_addr);
789 } else if (ex_phy->linkrate == SAS_LINK_RATE_UNKNOWN)
792 if (ex_phy->attached_dev_type != SAS_END_DEV &&
793 ex_phy->attached_dev_type != FANOUT_DEV &&
794 ex_phy->attached_dev_type != EDGE_DEV) {
795 SAS_DPRINTK("unknown device type(0x%x) attached to ex %016llx "
796 "phy 0x%x\n", ex_phy->attached_dev_type,
797 SAS_ADDR(dev->sas_addr),
802 res = sas_configure_routing(dev, ex_phy->attached_sas_addr);
804 SAS_DPRINTK("configure routing for dev %016llx "
805 "reported 0x%x. Forgotten\n",
806 SAS_ADDR(ex_phy->attached_sas_addr), res);
807 sas_disable_routing(dev, ex_phy->attached_sas_addr);
811 switch (ex_phy->attached_dev_type) {
813 child = sas_ex_discover_end_dev(dev, phy_id);
816 if (SAS_ADDR(dev->port->disc.fanout_sas_addr)) {
817 SAS_DPRINTK("second fanout expander %016llx phy 0x%x "
818 "attached to ex %016llx phy 0x%x\n",
819 SAS_ADDR(ex_phy->attached_sas_addr),
820 ex_phy->attached_phy_id,
821 SAS_ADDR(dev->sas_addr),
823 sas_ex_disable_phy(dev, phy_id);
826 memcpy(dev->port->disc.fanout_sas_addr,
827 ex_phy->attached_sas_addr, SAS_ADDR_SIZE);
830 child = sas_ex_discover_expander(dev, phy_id);
839 for (i = 0; i < ex->num_phys; i++) {
840 if (ex->ex_phy[i].phy_state == PHY_VACANT ||
841 ex->ex_phy[i].phy_state == PHY_NOT_PRESENT)
844 if (SAS_ADDR(ex->ex_phy[i].attached_sas_addr) ==
845 SAS_ADDR(child->sas_addr))
846 ex->ex_phy[i].phy_state= PHY_DEVICE_DISCOVERED;
853 static int sas_find_sub_addr(struct domain_device *dev, u8 *sub_addr)
855 struct expander_device *ex = &dev->ex_dev;
858 for (i = 0; i < ex->num_phys; i++) {
859 struct ex_phy *phy = &ex->ex_phy[i];
861 if (phy->phy_state == PHY_VACANT ||
862 phy->phy_state == PHY_NOT_PRESENT)
865 if ((phy->attached_dev_type == EDGE_DEV ||
866 phy->attached_dev_type == FANOUT_DEV) &&
867 phy->routing_attr == SUBTRACTIVE_ROUTING) {
869 memcpy(sub_addr, phy->attached_sas_addr,SAS_ADDR_SIZE);
877 static int sas_check_level_subtractive_boundary(struct domain_device *dev)
879 struct expander_device *ex = &dev->ex_dev;
880 struct domain_device *child;
881 u8 sub_addr[8] = {0, };
883 list_for_each_entry(child, &ex->children, siblings) {
884 if (child->dev_type != EDGE_DEV &&
885 child->dev_type != FANOUT_DEV)
887 if (sub_addr[0] == 0) {
888 sas_find_sub_addr(child, sub_addr);
893 if (sas_find_sub_addr(child, s2) &&
894 (SAS_ADDR(sub_addr) != SAS_ADDR(s2))) {
896 SAS_DPRINTK("ex %016llx->%016llx-?->%016llx "
897 "diverges from subtractive "
898 "boundary %016llx\n",
899 SAS_ADDR(dev->sas_addr),
900 SAS_ADDR(child->sas_addr),
904 sas_ex_disable_port(child, s2);
911 * sas_ex_discover_devices -- discover devices attached to this expander
912 * dev: pointer to the expander domain device
913 * single: if you want to do a single phy, else set to -1;
915 * Configure this expander for use with its devices and register the
916 * devices of this expander.
918 static int sas_ex_discover_devices(struct domain_device *dev, int single)
920 struct expander_device *ex = &dev->ex_dev;
921 int i = 0, end = ex->num_phys;
924 if (0 <= single && single < end) {
929 for ( ; i < end; i++) {
930 struct ex_phy *ex_phy = &ex->ex_phy[i];
932 if (ex_phy->phy_state == PHY_VACANT ||
933 ex_phy->phy_state == PHY_NOT_PRESENT ||
934 ex_phy->phy_state == PHY_DEVICE_DISCOVERED)
937 switch (ex_phy->linkrate) {
938 case SAS_PHY_DISABLED:
939 case SAS_PHY_RESET_PROBLEM:
940 case SAS_SATA_PORT_SELECTOR:
943 res = sas_ex_discover_dev(dev, i);
951 sas_check_level_subtractive_boundary(dev);
956 static int sas_check_ex_subtractive_boundary(struct domain_device *dev)
958 struct expander_device *ex = &dev->ex_dev;
960 u8 *sub_sas_addr = NULL;
962 if (dev->dev_type != EDGE_DEV)
965 for (i = 0; i < ex->num_phys; i++) {
966 struct ex_phy *phy = &ex->ex_phy[i];
968 if (phy->phy_state == PHY_VACANT ||
969 phy->phy_state == PHY_NOT_PRESENT)
972 if ((phy->attached_dev_type == FANOUT_DEV ||
973 phy->attached_dev_type == EDGE_DEV) &&
974 phy->routing_attr == SUBTRACTIVE_ROUTING) {
977 sub_sas_addr = &phy->attached_sas_addr[0];
978 else if (SAS_ADDR(sub_sas_addr) !=
979 SAS_ADDR(phy->attached_sas_addr)) {
981 SAS_DPRINTK("ex %016llx phy 0x%x "
982 "diverges(%016llx) on subtractive "
983 "boundary(%016llx). Disabled\n",
984 SAS_ADDR(dev->sas_addr), i,
985 SAS_ADDR(phy->attached_sas_addr),
986 SAS_ADDR(sub_sas_addr));
987 sas_ex_disable_phy(dev, i);
994 static void sas_print_parent_topology_bug(struct domain_device *child,
995 struct ex_phy *parent_phy,
996 struct ex_phy *child_phy)
998 static const char ra_char[] = {
999 [DIRECT_ROUTING] = 'D',
1000 [SUBTRACTIVE_ROUTING] = 'S',
1001 [TABLE_ROUTING] = 'T',
1003 static const char *ex_type[] = {
1004 [EDGE_DEV] = "edge",
1005 [FANOUT_DEV] = "fanout",
1007 struct domain_device *parent = child->parent;
1009 sas_printk("%s ex %016llx phy 0x%x <--> %s ex %016llx phy 0x%x "
1010 "has %c:%c routing link!\n",
1012 ex_type[parent->dev_type],
1013 SAS_ADDR(parent->sas_addr),
1016 ex_type[child->dev_type],
1017 SAS_ADDR(child->sas_addr),
1020 ra_char[parent_phy->routing_attr],
1021 ra_char[child_phy->routing_attr]);
1024 static int sas_check_eeds(struct domain_device *child,
1025 struct ex_phy *parent_phy,
1026 struct ex_phy *child_phy)
1029 struct domain_device *parent = child->parent;
1031 if (SAS_ADDR(parent->port->disc.fanout_sas_addr) != 0) {
1033 SAS_DPRINTK("edge ex %016llx phy S:0x%x <--> edge ex %016llx "
1034 "phy S:0x%x, while there is a fanout ex %016llx\n",
1035 SAS_ADDR(parent->sas_addr),
1037 SAS_ADDR(child->sas_addr),
1039 SAS_ADDR(parent->port->disc.fanout_sas_addr));
1040 } else if (SAS_ADDR(parent->port->disc.eeds_a) == 0) {
1041 memcpy(parent->port->disc.eeds_a, parent->sas_addr,
1043 memcpy(parent->port->disc.eeds_b, child->sas_addr,
1045 } else if (((SAS_ADDR(parent->port->disc.eeds_a) ==
1046 SAS_ADDR(parent->sas_addr)) ||
1047 (SAS_ADDR(parent->port->disc.eeds_a) ==
1048 SAS_ADDR(child->sas_addr)))
1050 ((SAS_ADDR(parent->port->disc.eeds_b) ==
1051 SAS_ADDR(parent->sas_addr)) ||
1052 (SAS_ADDR(parent->port->disc.eeds_b) ==
1053 SAS_ADDR(child->sas_addr))))
1057 SAS_DPRINTK("edge ex %016llx phy 0x%x <--> edge ex %016llx "
1058 "phy 0x%x link forms a third EEDS!\n",
1059 SAS_ADDR(parent->sas_addr),
1061 SAS_ADDR(child->sas_addr),
1068 /* Here we spill over 80 columns. It is intentional.
1070 static int sas_check_parent_topology(struct domain_device *child)
1072 struct expander_device *child_ex = &child->ex_dev;
1073 struct expander_device *parent_ex;
1080 if (child->parent->dev_type != EDGE_DEV &&
1081 child->parent->dev_type != FANOUT_DEV)
1084 parent_ex = &child->parent->ex_dev;
1086 for (i = 0; i < parent_ex->num_phys; i++) {
1087 struct ex_phy *parent_phy = &parent_ex->ex_phy[i];
1088 struct ex_phy *child_phy;
1090 if (parent_phy->phy_state == PHY_VACANT ||
1091 parent_phy->phy_state == PHY_NOT_PRESENT)
1094 if (SAS_ADDR(parent_phy->attached_sas_addr) != SAS_ADDR(child->sas_addr))
1097 child_phy = &child_ex->ex_phy[parent_phy->attached_phy_id];
1099 switch (child->parent->dev_type) {
1101 if (child->dev_type == FANOUT_DEV) {
1102 if (parent_phy->routing_attr != SUBTRACTIVE_ROUTING ||
1103 child_phy->routing_attr != TABLE_ROUTING) {
1104 sas_print_parent_topology_bug(child, parent_phy, child_phy);
1107 } else if (parent_phy->routing_attr == SUBTRACTIVE_ROUTING) {
1108 if (child_phy->routing_attr == SUBTRACTIVE_ROUTING) {
1109 res = sas_check_eeds(child, parent_phy, child_phy);
1110 } else if (child_phy->routing_attr != TABLE_ROUTING) {
1111 sas_print_parent_topology_bug(child, parent_phy, child_phy);
1114 } else if (parent_phy->routing_attr == TABLE_ROUTING &&
1115 child_phy->routing_attr != SUBTRACTIVE_ROUTING) {
1116 sas_print_parent_topology_bug(child, parent_phy, child_phy);
1121 if (parent_phy->routing_attr != TABLE_ROUTING ||
1122 child_phy->routing_attr != SUBTRACTIVE_ROUTING) {
1123 sas_print_parent_topology_bug(child, parent_phy, child_phy);
1135 #define RRI_REQ_SIZE 16
1136 #define RRI_RESP_SIZE 44
1138 static int sas_configure_present(struct domain_device *dev, int phy_id,
1139 u8 *sas_addr, int *index, int *present)
1142 struct expander_device *ex = &dev->ex_dev;
1143 struct ex_phy *phy = &ex->ex_phy[phy_id];
1150 rri_req = alloc_smp_req(RRI_REQ_SIZE);
1154 rri_resp = alloc_smp_resp(RRI_RESP_SIZE);
1160 rri_req[1] = SMP_REPORT_ROUTE_INFO;
1161 rri_req[9] = phy_id;
1163 for (i = 0; i < ex->max_route_indexes ; i++) {
1164 *(__be16 *)(rri_req+6) = cpu_to_be16(i);
1165 res = smp_execute_task(dev, rri_req, RRI_REQ_SIZE, rri_resp,
1170 if (res == SMP_RESP_NO_INDEX) {
1171 SAS_DPRINTK("overflow of indexes: dev %016llx "
1172 "phy 0x%x index 0x%x\n",
1173 SAS_ADDR(dev->sas_addr), phy_id, i);
1175 } else if (res != SMP_RESP_FUNC_ACC) {
1176 SAS_DPRINTK("%s: dev %016llx phy 0x%x index 0x%x "
1177 "result 0x%x\n", __FUNCTION__,
1178 SAS_ADDR(dev->sas_addr), phy_id, i, res);
1181 if (SAS_ADDR(sas_addr) != 0) {
1182 if (SAS_ADDR(rri_resp+16) == SAS_ADDR(sas_addr)) {
1184 if ((rri_resp[12] & 0x80) == 0x80)
1189 } else if (SAS_ADDR(rri_resp+16) == 0) {
1194 } else if (SAS_ADDR(rri_resp+16) == 0 &&
1195 phy->last_da_index < i) {
1196 phy->last_da_index = i;
1209 #define CRI_REQ_SIZE 44
1210 #define CRI_RESP_SIZE 8
1212 static int sas_configure_set(struct domain_device *dev, int phy_id,
1213 u8 *sas_addr, int index, int include)
1219 cri_req = alloc_smp_req(CRI_REQ_SIZE);
1223 cri_resp = alloc_smp_resp(CRI_RESP_SIZE);
1229 cri_req[1] = SMP_CONF_ROUTE_INFO;
1230 *(__be16 *)(cri_req+6) = cpu_to_be16(index);
1231 cri_req[9] = phy_id;
1232 if (SAS_ADDR(sas_addr) == 0 || !include)
1233 cri_req[12] |= 0x80;
1234 memcpy(cri_req+16, sas_addr, SAS_ADDR_SIZE);
1236 res = smp_execute_task(dev, cri_req, CRI_REQ_SIZE, cri_resp,
1241 if (res == SMP_RESP_NO_INDEX) {
1242 SAS_DPRINTK("overflow of indexes: dev %016llx phy 0x%x "
1244 SAS_ADDR(dev->sas_addr), phy_id, index);
1252 static int sas_configure_phy(struct domain_device *dev, int phy_id,
1253 u8 *sas_addr, int include)
1259 res = sas_configure_present(dev, phy_id, sas_addr, &index, &present);
1262 if (include ^ present)
1263 return sas_configure_set(dev, phy_id, sas_addr, index,include);
1269 * sas_configure_parent -- configure routing table of parent
1270 * parent: parent expander
1271 * child: child expander
1272 * sas_addr: SAS port identifier of device directly attached to child
1274 static int sas_configure_parent(struct domain_device *parent,
1275 struct domain_device *child,
1276 u8 *sas_addr, int include)
1278 struct expander_device *ex_parent = &parent->ex_dev;
1282 if (parent->parent) {
1283 res = sas_configure_parent(parent->parent, parent, sas_addr,
1289 if (ex_parent->conf_route_table == 0) {
1290 SAS_DPRINTK("ex %016llx has self-configuring routing table\n",
1291 SAS_ADDR(parent->sas_addr));
1295 for (i = 0; i < ex_parent->num_phys; i++) {
1296 struct ex_phy *phy = &ex_parent->ex_phy[i];
1298 if ((phy->routing_attr == TABLE_ROUTING) &&
1299 (SAS_ADDR(phy->attached_sas_addr) ==
1300 SAS_ADDR(child->sas_addr))) {
1301 res = sas_configure_phy(parent, i, sas_addr, include);
1311 * sas_configure_routing -- configure routing
1312 * dev: expander device
1313 * sas_addr: port identifier of device directly attached to the expander device
1315 static int sas_configure_routing(struct domain_device *dev, u8 *sas_addr)
1318 return sas_configure_parent(dev->parent, dev, sas_addr, 1);
1322 static int sas_disable_routing(struct domain_device *dev, u8 *sas_addr)
1325 return sas_configure_parent(dev->parent, dev, sas_addr, 0);
1330 #define SMP_BIN_ATTR_NAME "smp_portal"
1332 static void sas_ex_smp_hook(struct domain_device *dev)
1334 struct expander_device *ex_dev = &dev->ex_dev;
1335 struct bin_attribute *bin_attr = &ex_dev->smp_bin_attr;
1337 memset(bin_attr, 0, sizeof(*bin_attr));
1339 bin_attr->attr.name = SMP_BIN_ATTR_NAME;
1340 bin_attr->attr.owner = THIS_MODULE;
1341 bin_attr->attr.mode = 0600;
1344 bin_attr->private = NULL;
1345 bin_attr->read = smp_portal_read;
1346 bin_attr->write= smp_portal_write;
1347 bin_attr->mmap = NULL;
1349 ex_dev->smp_portal_pid = -1;
1350 init_MUTEX(&ex_dev->smp_sema);
1355 * sas_discover_expander -- expander discovery
1356 * @ex: pointer to expander domain device
1358 * See comment in sas_discover_sata().
1360 static int sas_discover_expander(struct domain_device *dev)
1364 res = sas_notify_lldd_dev_found(dev);
1368 res = sas_ex_general(dev);
1371 res = sas_ex_manuf_info(dev);
1375 res = sas_expander_discover(dev);
1377 SAS_DPRINTK("expander %016llx discovery failed(0x%x)\n",
1378 SAS_ADDR(dev->sas_addr), res);
1382 sas_check_ex_subtractive_boundary(dev);
1383 res = sas_check_parent_topology(dev);
1388 sas_notify_lldd_dev_gone(dev);
1392 static int sas_ex_level_discovery(struct asd_sas_port *port, const int level)
1395 struct domain_device *dev;
1397 list_for_each_entry(dev, &port->dev_list, dev_list_node) {
1398 if (dev->dev_type == EDGE_DEV ||
1399 dev->dev_type == FANOUT_DEV) {
1400 struct sas_expander_device *ex =
1401 rphy_to_expander_device(dev->rphy);
1403 if (level == ex->level)
1404 res = sas_ex_discover_devices(dev, -1);
1406 res = sas_ex_discover_devices(port->port_dev, -1);
1414 static int sas_ex_bfs_disc(struct asd_sas_port *port)
1420 level = port->disc.max_level;
1421 res = sas_ex_level_discovery(port, level);
1423 } while (level < port->disc.max_level);
1428 int sas_discover_root_expander(struct domain_device *dev)
1431 struct sas_expander_device *ex = rphy_to_expander_device(dev->rphy);
1433 res = sas_rphy_add(dev->rphy);
1437 ex->level = dev->port->disc.max_level; /* 0 */
1438 res = sas_discover_expander(dev);
1442 sas_ex_bfs_disc(dev->port);
1447 sas_rphy_delete(dev->rphy);
1451 sas_rphy_free(dev->rphy);
1456 /* ---------- Domain revalidation ---------- */
1458 static int sas_get_phy_discover(struct domain_device *dev,
1459 int phy_id, struct smp_resp *disc_resp)
1464 disc_req = alloc_smp_req(DISCOVER_REQ_SIZE);
1468 disc_req[1] = SMP_DISCOVER;
1469 disc_req[9] = phy_id;
1471 res = smp_execute_task(dev, disc_req, DISCOVER_REQ_SIZE,
1472 disc_resp, DISCOVER_RESP_SIZE);
1475 else if (disc_resp->result != SMP_RESP_FUNC_ACC) {
1476 res = disc_resp->result;
1484 static int sas_get_phy_change_count(struct domain_device *dev,
1485 int phy_id, int *pcc)
1488 struct smp_resp *disc_resp;
1490 disc_resp = alloc_smp_resp(DISCOVER_RESP_SIZE);
1494 res = sas_get_phy_discover(dev, phy_id, disc_resp);
1496 *pcc = disc_resp->disc.change_count;
1502 static int sas_get_phy_attached_sas_addr(struct domain_device *dev,
1503 int phy_id, u8 *attached_sas_addr)
1506 struct smp_resp *disc_resp;
1507 struct discover_resp *dr;
1509 disc_resp = alloc_smp_resp(DISCOVER_RESP_SIZE);
1512 dr = &disc_resp->disc;
1514 res = sas_get_phy_discover(dev, phy_id, disc_resp);
1516 memcpy(attached_sas_addr,disc_resp->disc.attached_sas_addr,8);
1517 if (dr->attached_dev_type == 0)
1518 memset(attached_sas_addr, 0, 8);
1524 static int sas_find_bcast_phy(struct domain_device *dev, int *phy_id,
1527 struct expander_device *ex = &dev->ex_dev;
1531 for (i = from_phy; i < ex->num_phys; i++) {
1532 int phy_change_count = 0;
1534 res = sas_get_phy_change_count(dev, i, &phy_change_count);
1537 else if (phy_change_count != ex->ex_phy[i].phy_change_count) {
1538 ex->ex_phy[i].phy_change_count = phy_change_count;
1547 static int sas_get_ex_change_count(struct domain_device *dev, int *ecc)
1551 struct smp_resp *rg_resp;
1553 rg_req = alloc_smp_req(RG_REQ_SIZE);
1557 rg_resp = alloc_smp_resp(RG_RESP_SIZE);
1563 rg_req[1] = SMP_REPORT_GENERAL;
1565 res = smp_execute_task(dev, rg_req, RG_REQ_SIZE, rg_resp,
1569 if (rg_resp->result != SMP_RESP_FUNC_ACC) {
1570 res = rg_resp->result;
1574 *ecc = be16_to_cpu(rg_resp->rg.change_count);
1581 static int sas_find_bcast_dev(struct domain_device *dev,
1582 struct domain_device **src_dev)
1584 struct expander_device *ex = &dev->ex_dev;
1585 int ex_change_count = -1;
1588 res = sas_get_ex_change_count(dev, &ex_change_count);
1591 if (ex_change_count != -1 &&
1592 ex_change_count != ex->ex_change_count) {
1594 ex->ex_change_count = ex_change_count;
1596 struct domain_device *ch;
1598 list_for_each_entry(ch, &ex->children, siblings) {
1599 if (ch->dev_type == EDGE_DEV ||
1600 ch->dev_type == FANOUT_DEV) {
1601 res = sas_find_bcast_dev(ch, src_dev);
1611 static void sas_unregister_ex_tree(struct domain_device *dev)
1613 struct expander_device *ex = &dev->ex_dev;
1614 struct domain_device *child, *n;
1616 list_for_each_entry_safe(child, n, &ex->children, siblings) {
1617 if (child->dev_type == EDGE_DEV ||
1618 child->dev_type == FANOUT_DEV)
1619 sas_unregister_ex_tree(child);
1621 sas_unregister_dev(child);
1623 sas_unregister_dev(dev);
1626 static void sas_unregister_devs_sas_addr(struct domain_device *parent,
1629 struct expander_device *ex_dev = &parent->ex_dev;
1630 struct ex_phy *phy = &ex_dev->ex_phy[phy_id];
1631 struct domain_device *child, *n;
1633 list_for_each_entry_safe(child, n, &ex_dev->children, siblings) {
1634 if (SAS_ADDR(child->sas_addr) ==
1635 SAS_ADDR(phy->attached_sas_addr)) {
1636 if (child->dev_type == EDGE_DEV ||
1637 child->dev_type == FANOUT_DEV)
1638 sas_unregister_ex_tree(child);
1640 sas_unregister_dev(child);
1644 sas_disable_routing(parent, phy->attached_sas_addr);
1645 memset(phy->attached_sas_addr, 0, SAS_ADDR_SIZE);
1646 sas_port_delete_phy(phy->port, phy->phy);
1647 if (phy->port->num_phys == 0)
1648 sas_port_delete(phy->port);
1652 static int sas_discover_bfs_by_root_level(struct domain_device *root,
1655 struct expander_device *ex_root = &root->ex_dev;
1656 struct domain_device *child;
1659 list_for_each_entry(child, &ex_root->children, siblings) {
1660 if (child->dev_type == EDGE_DEV ||
1661 child->dev_type == FANOUT_DEV) {
1662 struct sas_expander_device *ex =
1663 rphy_to_expander_device(child->rphy);
1665 if (level > ex->level)
1666 res = sas_discover_bfs_by_root_level(child,
1668 else if (level == ex->level)
1669 res = sas_ex_discover_devices(child, -1);
1675 static int sas_discover_bfs_by_root(struct domain_device *dev)
1678 struct sas_expander_device *ex = rphy_to_expander_device(dev->rphy);
1679 int level = ex->level+1;
1681 res = sas_ex_discover_devices(dev, -1);
1685 res = sas_discover_bfs_by_root_level(dev, level);
1688 } while (level <= dev->port->disc.max_level);
1693 static int sas_discover_new(struct domain_device *dev, int phy_id)
1695 struct ex_phy *ex_phy = &dev->ex_dev.ex_phy[phy_id];
1696 struct domain_device *child;
1699 SAS_DPRINTK("ex %016llx phy%d new device attached\n",
1700 SAS_ADDR(dev->sas_addr), phy_id);
1701 res = sas_ex_phy_discover(dev, phy_id);
1704 res = sas_ex_discover_devices(dev, phy_id);
1707 list_for_each_entry(child, &dev->ex_dev.children, siblings) {
1708 if (SAS_ADDR(child->sas_addr) ==
1709 SAS_ADDR(ex_phy->attached_sas_addr)) {
1710 if (child->dev_type == EDGE_DEV ||
1711 child->dev_type == FANOUT_DEV)
1712 res = sas_discover_bfs_by_root(child);
1720 static int sas_rediscover_dev(struct domain_device *dev, int phy_id)
1722 struct expander_device *ex = &dev->ex_dev;
1723 struct ex_phy *phy = &ex->ex_phy[phy_id];
1724 u8 attached_sas_addr[8];
1727 res = sas_get_phy_attached_sas_addr(dev, phy_id, attached_sas_addr);
1729 case SMP_RESP_NO_PHY:
1730 phy->phy_state = PHY_NOT_PRESENT;
1731 sas_unregister_devs_sas_addr(dev, phy_id);
1733 case SMP_RESP_PHY_VACANT:
1734 phy->phy_state = PHY_VACANT;
1735 sas_unregister_devs_sas_addr(dev, phy_id);
1737 case SMP_RESP_FUNC_ACC:
1741 if (SAS_ADDR(attached_sas_addr) == 0) {
1742 phy->phy_state = PHY_EMPTY;
1743 sas_unregister_devs_sas_addr(dev, phy_id);
1744 } else if (SAS_ADDR(attached_sas_addr) ==
1745 SAS_ADDR(phy->attached_sas_addr)) {
1746 SAS_DPRINTK("ex %016llx phy 0x%x broadcast flutter\n",
1747 SAS_ADDR(dev->sas_addr), phy_id);
1748 sas_ex_phy_discover(dev, phy_id);
1750 res = sas_discover_new(dev, phy_id);
1755 static int sas_rediscover(struct domain_device *dev, const int phy_id)
1757 struct expander_device *ex = &dev->ex_dev;
1758 struct ex_phy *changed_phy = &ex->ex_phy[phy_id];
1762 SAS_DPRINTK("ex %016llx phy%d originated BROADCAST(CHANGE)\n",
1763 SAS_ADDR(dev->sas_addr), phy_id);
1765 if (SAS_ADDR(changed_phy->attached_sas_addr) != 0) {
1766 for (i = 0; i < ex->num_phys; i++) {
1767 struct ex_phy *phy = &ex->ex_phy[i];
1771 if (SAS_ADDR(phy->attached_sas_addr) ==
1772 SAS_ADDR(changed_phy->attached_sas_addr)) {
1773 SAS_DPRINTK("phy%d part of wide port with "
1774 "phy%d\n", phy_id, i);
1778 res = sas_rediscover_dev(dev, phy_id);
1780 res = sas_discover_new(dev, phy_id);
1786 * sas_revalidate_domain -- revalidate the domain
1787 * @port: port to the domain of interest
1789 * NOTE: this process _must_ quit (return) as soon as any connection
1790 * errors are encountered. Connection recovery is done elsewhere.
1791 * Discover process only interrogates devices in order to discover the
1794 int sas_ex_revalidate_domain(struct domain_device *port_dev)
1797 struct domain_device *dev = NULL;
1799 res = sas_find_bcast_dev(port_dev, &dev);
1803 struct expander_device *ex = &dev->ex_dev;
1808 res = sas_find_bcast_phy(dev, &phy_id, i);
1811 res = sas_rediscover(dev, phy_id);
1813 } while (i < ex->num_phys);
1820 /* ---------- SMP portal ---------- */
1822 static ssize_t smp_portal_write(struct kobject *kobj, char *buf, loff_t offs,
1825 struct domain_device *dev = to_dom_device(kobj);
1826 struct expander_device *ex = &dev->ex_dev;
1833 down_interruptible(&ex->smp_sema);
1836 ex->smp_req = kzalloc(size, GFP_USER);
1841 memcpy(ex->smp_req, buf, size);
1842 ex->smp_req_size = size;
1843 ex->smp_portal_pid = current->pid;
1849 static ssize_t smp_portal_read(struct kobject *kobj, char *buf, loff_t offs,
1852 struct domain_device *dev = to_dom_device(kobj);
1853 struct expander_device *ex = &dev->ex_dev;
1857 /* XXX: sysfs gives us an offset of 0x10 or 0x8 while in fact
1861 down_interruptible(&ex->smp_sema);
1862 if (!ex->smp_req || ex->smp_portal_pid != current->pid)
1870 smp_resp = alloc_smp_resp(size);
1873 res = smp_execute_task(dev, ex->smp_req, ex->smp_req_size,
1876 memcpy(buf, smp_resp, size);
1884 ex->smp_req_size = 0;
1885 ex->smp_portal_pid = -1;