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
23 * $Id: //depot/sas-class/sas_expander.c#60 $
26 #include <linux/pci.h>
27 #include <linux/scatterlist.h>
29 #include "sas_internal.h"
30 #include <scsi/sas/sas_task.h>
31 #include <scsi/sas/sas_discover.h>
33 #include <scsi/scsi_transport.h>
34 #include <scsi/scsi_transport_sas.h>
35 #include "../scsi_sas_internal.h"
37 static int sas_discover_expander(struct domain_device *dev);
38 static int sas_configure_routing(struct domain_device *dev, u8 *sas_addr);
39 static int sas_disable_routing(struct domain_device *dev, u8 *sas_addr);
42 /* FIXME: smp needs to migrate into the sas class */
43 static ssize_t smp_portal_read(struct kobject *, char *, loff_t, size_t);
44 static ssize_t smp_portal_write(struct kobject *, char *, loff_t, size_t);
47 /* ---------- SMP task management ---------- */
49 static void smp_task_timedout(unsigned long _task)
51 struct sas_task *task = (void *) _task;
54 spin_lock_irqsave(&task->task_state_lock, flags);
55 if (!(task->task_state_flags & SAS_TASK_STATE_DONE))
56 task->task_state_flags |= SAS_TASK_STATE_ABORTED;
57 spin_unlock_irqrestore(&task->task_state_lock, flags);
59 complete(&task->completion);
62 static void smp_task_done(struct sas_task *task)
64 if (!del_timer(&task->timer))
66 complete(&task->completion);
69 /* Give it some long enough timeout. In seconds. */
70 #define SMP_TIMEOUT 10
72 static int smp_execute_task(struct domain_device *dev, void *req, int req_size,
73 void *resp, int resp_size)
76 struct sas_task *task = sas_alloc_task(GFP_KERNEL);
77 struct sas_internal *i =
78 to_sas_internal(dev->port->ha->core.shost->transportt);
84 task->task_proto = dev->tproto;
85 sg_init_one(&task->smp_task.smp_req, req, req_size);
86 sg_init_one(&task->smp_task.smp_resp, resp, resp_size);
88 task->task_done = smp_task_done;
90 task->timer.data = (unsigned long) task;
91 task->timer.function = smp_task_timedout;
92 task->timer.expires = jiffies + SMP_TIMEOUT*HZ;
93 add_timer(&task->timer);
95 res = i->dft->lldd_execute_task(task, 1, GFP_KERNEL);
98 del_timer(&task->timer);
99 SAS_DPRINTK("executing SMP task failed:%d\n", res);
103 wait_for_completion(&task->completion);
105 if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
106 SAS_DPRINTK("smp task timed out or aborted\n");
107 i->dft->lldd_abort_task(task);
108 if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) {
109 SAS_DPRINTK("SMP task aborted and not done\n");
113 if (task->task_status.resp == SAS_TASK_COMPLETE &&
114 task->task_status.stat == SAM_GOOD)
117 SAS_DPRINTK("%s: task to dev %016llx response: 0x%x "
118 "status 0x%x\n", __FUNCTION__,
119 SAS_ADDR(dev->sas_addr),
120 task->task_status.resp,
121 task->task_status.stat);
127 /* ---------- Allocations ---------- */
129 static inline void *alloc_smp_req(int size)
131 u8 *p = kzalloc(size, GFP_KERNEL);
137 static inline void *alloc_smp_resp(int size)
139 return kzalloc(size, GFP_KERNEL);
142 /* ---------- Expander configuration ---------- */
144 static void sas_set_ex_phy(struct domain_device *dev, int phy_id,
147 struct expander_device *ex = &dev->ex_dev;
148 struct ex_phy *phy = &ex->ex_phy[phy_id];
149 struct smp_resp *resp = disc_resp;
150 struct discover_resp *dr = &resp->disc;
151 struct sas_rphy *rphy = dev->rphy;
153 phy->phy = sas_phy_alloc(&rphy->dev, phy_id);
154 dev_printk(KERN_ERR, &phy->phy->dev, "ALLOCATED\n\n");
156 /* FIXME: error_handling */
159 switch (resp->result) {
160 case SMP_RESP_PHY_VACANT:
161 phy->phy_state = PHY_VACANT;
164 phy->phy_state = PHY_NOT_PRESENT;
166 case SMP_RESP_FUNC_ACC:
167 phy->phy_state = PHY_EMPTY; /* do not know yet */
171 phy->phy_id = phy_id;
172 phy->attached_dev_type = dr->attached_dev_type;
173 phy->linkrate = dr->linkrate;
174 phy->attached_sata_host = dr->attached_sata_host;
175 phy->attached_sata_dev = dr->attached_sata_dev;
176 phy->attached_sata_ps = dr->attached_sata_ps;
177 phy->attached_iproto = dr->iproto << 1;
178 phy->attached_tproto = dr->tproto << 1;
179 memcpy(phy->attached_sas_addr, dr->attached_sas_addr, SAS_ADDR_SIZE);
180 phy->attached_phy_id = dr->attached_phy_id;
181 phy->phy_change_count = dr->change_count;
182 phy->routing_attr = dr->routing_attr;
183 phy->virtual = dr->virtual;
184 phy->last_da_index = -1;
186 /* FIXME: This probably isn't right, but it will do for now*/
187 phy->phy->local_attached = 1;
189 phy->phy->identify.initiator_port_protocols = phy->attached_iproto;
190 phy->phy->identify.target_port_protocols = phy->attached_tproto;
191 phy->phy->identify.phy_identifier = phy_id;
192 phy->phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
193 phy->phy->maximum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
194 phy->phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;
195 phy->phy->maximum_linkrate = SAS_LINK_RATE_3_0_GBPS;
196 switch (phy->linkrate) {
197 case PHY_LINKRATE_1_5:
198 phy->phy->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS;
201 phy->phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS;
204 phy->phy->negotiated_linkrate = SAS_LINK_RATE_6_0_GBPS;
207 phy->phy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN;
211 sas_phy_add(phy->phy);
213 SAS_DPRINTK("ex %016llx phy%02d:%c attached: %016llx\n",
214 SAS_ADDR(dev->sas_addr), phy->phy_id,
215 phy->routing_attr == TABLE_ROUTING ? 'T' :
216 phy->routing_attr == DIRECT_ROUTING ? 'D' :
217 phy->routing_attr == SUBTRACTIVE_ROUTING ? 'S' : '?',
218 SAS_ADDR(phy->attached_sas_addr));
223 #define DISCOVER_REQ_SIZE 16
224 #define DISCOVER_RESP_SIZE 56
226 static int sas_ex_phy_discover(struct domain_device *dev, int single)
228 struct expander_device *ex = &dev->ex_dev;
233 disc_req = alloc_smp_req(DISCOVER_REQ_SIZE);
237 disc_resp = alloc_smp_req(DISCOVER_RESP_SIZE);
243 disc_req[1] = SMP_DISCOVER;
245 if (0 <= single && single < ex->num_phys) {
246 disc_req[9] = single;
247 res = smp_execute_task(dev, disc_req, DISCOVER_REQ_SIZE,
248 disc_resp, DISCOVER_RESP_SIZE);
251 sas_set_ex_phy(dev, single, disc_resp);
255 for (i = 0; i < ex->num_phys; i++) {
257 res = smp_execute_task(dev, disc_req,
258 DISCOVER_REQ_SIZE, disc_resp,
262 sas_set_ex_phy(dev, i, disc_resp);
271 static int sas_expander_discover(struct domain_device *dev)
273 struct expander_device *ex = &dev->ex_dev;
276 ex->ex_phy = kzalloc(sizeof(*ex->ex_phy)*ex->num_phys, GFP_KERNEL);
280 res = sas_ex_phy_discover(dev, -1);
291 #define MAX_EXPANDER_PHYS 128
293 static inline void ex_assign_report_general(struct domain_device *dev,
294 struct smp_resp *resp)
296 struct report_general_resp *rg = &resp->rg;
298 dev->ex_dev.ex_change_count = be16_to_cpu(rg->change_count);
299 dev->ex_dev.max_route_indexes = be16_to_cpu(rg->route_indexes);
300 dev->ex_dev.num_phys = min(rg->num_phys, (u8)MAX_EXPANDER_PHYS);
301 dev->ex_dev.conf_route_table = rg->conf_route_table;
302 dev->ex_dev.configuring = rg->configuring;
303 memcpy(dev->ex_dev.enclosure_logical_id, rg->enclosure_logical_id, 8);
306 #define RG_REQ_SIZE 8
307 #define RG_RESP_SIZE 32
309 static int sas_ex_general(struct domain_device *dev)
312 struct smp_resp *rg_resp;
316 rg_req = alloc_smp_req(RG_REQ_SIZE);
320 rg_resp = alloc_smp_resp(RG_RESP_SIZE);
326 rg_req[1] = SMP_REPORT_GENERAL;
328 for (i = 0; i < 5; i++) {
329 res = smp_execute_task(dev, rg_req, RG_REQ_SIZE, rg_resp,
333 SAS_DPRINTK("RG to ex %016llx failed:0x%x\n",
334 SAS_ADDR(dev->sas_addr), res);
336 } else if (rg_resp->result != SMP_RESP_FUNC_ACC) {
337 SAS_DPRINTK("RG:ex %016llx returned SMP result:0x%x\n",
338 SAS_ADDR(dev->sas_addr), rg_resp->result);
339 res = rg_resp->result;
343 ex_assign_report_general(dev, rg_resp);
345 if (dev->ex_dev.configuring) {
346 SAS_DPRINTK("RG: ex %llx self-configuring...\n",
347 SAS_ADDR(dev->sas_addr));
348 schedule_timeout_interruptible(5*HZ);
358 static inline void ex_assign_manuf_info(struct domain_device *dev, void
361 u8 *mi_resp = _mi_resp;
362 struct sas_rphy *rphy = dev->rphy;
363 struct sas_expander_device *edev = rphy_to_expander_device(rphy);
365 memcpy(edev->vendor_id, mi_resp + 12, SAS_EXPANDER_VENDOR_ID_LEN);
366 memcpy(edev->product_id, mi_resp + 20, SAS_EXPANDER_PRODUCT_ID_LEN);
367 memcpy(edev->product_rev, mi_resp + 36,
368 SAS_EXPANDER_PRODUCT_REV_LEN);
370 if (mi_resp[8] & 1) {
371 memcpy(edev->component_vendor_id, mi_resp + 40,
372 SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN);
373 edev->component_id = mi_resp[48] << 8 | mi_resp[49];
374 edev->component_revision_id = mi_resp[50];
378 #define MI_REQ_SIZE 8
379 #define MI_RESP_SIZE 64
381 static int sas_ex_manuf_info(struct domain_device *dev)
387 mi_req = alloc_smp_req(MI_REQ_SIZE);
391 mi_resp = alloc_smp_resp(MI_RESP_SIZE);
397 mi_req[1] = SMP_REPORT_MANUF_INFO;
399 res = smp_execute_task(dev, mi_req, MI_REQ_SIZE, mi_resp,MI_RESP_SIZE);
401 SAS_DPRINTK("MI: ex %016llx failed:0x%x\n",
402 SAS_ADDR(dev->sas_addr), res);
404 } else if (mi_resp[2] != SMP_RESP_FUNC_ACC) {
405 SAS_DPRINTK("MI ex %016llx returned SMP result:0x%x\n",
406 SAS_ADDR(dev->sas_addr), mi_resp[2]);
410 ex_assign_manuf_info(dev, mi_resp);
417 #define PC_REQ_SIZE 44
418 #define PC_RESP_SIZE 8
420 static int smp_phy_control(struct domain_device *dev, int phy_id,
421 enum phy_func phy_func)
427 pc_req = alloc_smp_req(PC_REQ_SIZE);
431 pc_resp = alloc_smp_resp(PC_RESP_SIZE);
437 pc_req[1] = SMP_PHY_CONTROL;
439 pc_req[10]= phy_func;
441 res = smp_execute_task(dev, pc_req, PC_REQ_SIZE, pc_resp,PC_RESP_SIZE);
448 static inline void sas_ex_disable_phy(struct domain_device *dev, int phy_id)
450 struct expander_device *ex = &dev->ex_dev;
451 struct ex_phy *phy = &ex->ex_phy[phy_id];
453 smp_phy_control(dev, phy_id, PHY_FUNC_DISABLE);
454 phy->linkrate = PHY_DISABLED;
457 static inline void sas_ex_disable_port(struct domain_device *dev, u8 *sas_addr)
459 struct expander_device *ex = &dev->ex_dev;
462 for (i = 0; i < ex->num_phys; i++) {
463 struct ex_phy *phy = &ex->ex_phy[i];
465 if (phy->phy_state == PHY_VACANT ||
466 phy->phy_state == PHY_NOT_PRESENT)
469 if (SAS_ADDR(phy->attached_sas_addr) == SAS_ADDR(sas_addr))
470 sas_ex_disable_phy(dev, i);
474 static inline int sas_dev_present_in_domain(struct sas_port *port,
477 struct domain_device *dev;
479 if (SAS_ADDR(port->sas_addr) == SAS_ADDR(sas_addr))
481 list_for_each_entry(dev, &port->dev_list, dev_list_node) {
482 if (SAS_ADDR(dev->sas_addr) == SAS_ADDR(sas_addr))
488 #define RPS_REQ_SIZE 16
489 #define RPS_RESP_SIZE 60
491 static inline int sas_get_report_phy_sata(struct domain_device *dev,
493 struct smp_resp *rps_resp)
496 u8 *rps_req = alloc_smp_req(RPS_REQ_SIZE);
501 rps_req[1] = SMP_REPORT_PHY_SATA;
504 res = smp_execute_task(dev, rps_req, RPS_REQ_SIZE,
505 rps_resp, RPS_RESP_SIZE);
511 static inline void sas_ex_get_linkrate(struct domain_device *parent,
512 struct domain_device *child,
513 struct ex_phy *parent_phy)
515 struct expander_device *parent_ex = &parent->ex_dev;
520 for (i = 0; i < parent_ex->num_phys; i++) {
521 struct ex_phy *phy = &parent_ex->ex_phy[i];
523 if (phy->phy_state == PHY_VACANT ||
524 phy->phy_state == PHY_NOT_PRESENT)
527 if (SAS_ADDR(phy->attached_sas_addr) ==
528 SAS_ADDR(child->sas_addr)) {
530 child->min_linkrate = min(parent->min_linkrate,
532 child->max_linkrate = max(parent->max_linkrate,
537 child->linkrate = min(parent_phy->linkrate, child->max_linkrate);
538 child->pathways = min(child->pathways, parent->pathways);
541 static struct domain_device *sas_ex_discover_end_dev(
542 struct domain_device *parent, int phy_id)
544 struct expander_device *parent_ex = &parent->ex_dev;
545 struct ex_phy *phy = &parent_ex->ex_phy[phy_id];
546 struct domain_device *child = NULL;
547 struct sas_rphy *rphy;
550 if (phy->attached_sata_host || phy->attached_sata_ps)
553 child = kzalloc(sizeof(*child), GFP_KERNEL);
557 child->parent = parent;
558 child->port = parent->port;
559 child->iproto = phy->attached_iproto;
560 memcpy(child->sas_addr, phy->attached_sas_addr, SAS_ADDR_SIZE);
561 sas_hash_addr(child->hashed_sas_addr, child->sas_addr);
562 sas_ex_get_linkrate(parent, child, phy);
564 if ((phy->attached_tproto & SAS_PROTO_STP) || phy->attached_sata_dev) {
565 child->dev_type = SATA_DEV;
566 if (phy->attached_tproto & SAS_PROTO_STP)
567 child->tproto = phy->attached_tproto;
568 if (phy->attached_sata_dev)
569 child->tproto |= SATA_DEV;
570 res = sas_get_report_phy_sata(parent, phy_id,
571 &child->sata_dev.rps_resp);
573 SAS_DPRINTK("report phy sata to %016llx:0x%x returned "
574 "0x%x\n", SAS_ADDR(parent->sas_addr),
579 memcpy(child->frame_rcvd, &child->sata_dev.rps_resp.rps.fis,
580 sizeof(struct dev_to_host_fis));
582 res = sas_discover_sata(child);
584 SAS_DPRINTK("sas_discover_sata() for device %16llx at "
585 "%016llx:0x%x returned 0x%x\n",
586 SAS_ADDR(child->sas_addr),
587 SAS_ADDR(parent->sas_addr), phy_id, res);
591 } else if (phy->attached_tproto & SAS_PROTO_SSP) {
592 child->dev_type = SAS_END_DEV;
593 rphy = sas_end_device_alloc(phy->phy);
594 /* FIXME: error handling */
596 child->tproto = phy->attached_tproto;
600 rphy->identify.phy_identifier = phy->phy->identify.phy_identifier;
601 rphy->identify.device_type = SAS_END_DEVICE;
602 rphy->identify.sas_address = SAS_ADDR(child->sas_addr);
603 rphy->identify.initiator_port_protocols = child->iproto;
604 rphy->identify.target_port_protocols = child->tproto;
606 spin_lock(&parent->port->dev_list_lock);
607 list_add_tail(&child->dev_list_node, &parent->port->dev_list);
608 spin_unlock(&parent->port->dev_list_lock);
610 res = sas_discover_end_dev(child);
612 SAS_DPRINTK("sas_discover_end_dev() for device %16llx "
613 "at %016llx:0x%x returned 0x%x\n",
614 SAS_ADDR(child->sas_addr),
615 SAS_ADDR(parent->sas_addr), phy_id, res);
620 SAS_DPRINTK("target proto 0x%x at %016llx:0x%x not handled\n",
621 phy->attached_tproto, SAS_ADDR(parent->sas_addr),
625 list_add_tail(&child->siblings, &parent_ex->children);
629 static struct domain_device *sas_ex_discover_expander(
630 struct domain_device *parent, int phy_id)
632 struct sas_expander_device *parent_ex = rphy_to_expander_device(parent->rphy);
633 struct ex_phy *phy = &parent->ex_dev.ex_phy[phy_id];
634 struct domain_device *child = NULL;
635 struct sas_rphy *rphy;
636 struct sas_expander_device *edev;
639 if (phy->routing_attr == DIRECT_ROUTING) {
640 SAS_DPRINTK("ex %016llx:0x%x:D <--> ex %016llx:0x%x is not "
642 SAS_ADDR(parent->sas_addr), phy_id,
643 SAS_ADDR(phy->attached_sas_addr),
644 phy->attached_phy_id);
647 child = kzalloc(sizeof(*child), GFP_KERNEL);
650 switch (phy->attached_dev_type) {
652 rphy = sas_expander_alloc(phy->phy, SAS_EDGE_EXPANDER_DEVICE);
655 rphy = sas_expander_alloc(phy->phy, SAS_FANOUT_EXPANDER_DEVICE);
658 rphy = NULL; /* shut gcc up */
662 edev = rphy_to_expander_device(rphy);
663 child->dev_type = phy->attached_dev_type;
664 child->parent = parent;
665 child->port = parent->port;
666 child->iproto = phy->attached_iproto;
667 child->tproto = phy->attached_tproto;
668 memcpy(child->sas_addr, phy->attached_sas_addr, SAS_ADDR_SIZE);
669 sas_hash_addr(child->hashed_sas_addr, child->sas_addr);
670 sas_ex_get_linkrate(parent, child, phy);
671 edev->level = parent_ex->level + 1;
672 parent->port->disc.max_level = max(parent->port->disc.max_level,
675 res = sas_discover_expander(child);
683 static int sas_ex_discover_dev(struct domain_device *dev, int phy_id)
685 struct expander_device *ex = &dev->ex_dev;
686 struct ex_phy *ex_phy = &ex->ex_phy[phy_id];
687 struct domain_device *child = NULL;
691 if (ex_phy->linkrate == PHY_SPINUP_HOLD) {
692 if (!smp_phy_control(dev, phy_id, PHY_FUNC_LINK_RESET))
693 res = sas_ex_phy_discover(dev, phy_id);
698 /* Parent and domain coherency */
699 if (!dev->parent && (SAS_ADDR(ex_phy->attached_sas_addr) ==
700 SAS_ADDR(dev->port->sas_addr)))
702 if (dev->parent && (SAS_ADDR(ex_phy->attached_sas_addr) ==
703 SAS_ADDR(dev->parent->sas_addr)))
705 if (sas_dev_present_in_domain(dev->port, ex_phy->attached_sas_addr))
706 sas_ex_disable_port(dev, ex_phy->attached_sas_addr);
708 if (ex_phy->attached_dev_type == NO_DEVICE) {
709 if (ex_phy->routing_attr == DIRECT_ROUTING) {
710 memset(ex_phy->attached_sas_addr, 0, SAS_ADDR_SIZE);
711 sas_configure_routing(dev, ex_phy->attached_sas_addr);
714 } else if (ex_phy->linkrate == PHY_LINKRATE_UNKNOWN)
717 if (ex_phy->attached_dev_type != SAS_END_DEV &&
718 ex_phy->attached_dev_type != FANOUT_DEV &&
719 ex_phy->attached_dev_type != EDGE_DEV) {
720 SAS_DPRINTK("unknown device type(0x%x) attached to ex %016llx "
721 "phy 0x%x\n", ex_phy->attached_dev_type,
722 SAS_ADDR(dev->sas_addr),
727 res = sas_configure_routing(dev, ex_phy->attached_sas_addr);
729 SAS_DPRINTK("configure routing for dev %016llx "
730 "reported 0x%x. Forgotten\n",
731 SAS_ADDR(ex_phy->attached_sas_addr), res);
732 sas_disable_routing(dev, ex_phy->attached_sas_addr);
736 switch (ex_phy->attached_dev_type) {
738 child = sas_ex_discover_end_dev(dev, phy_id);
741 if (SAS_ADDR(dev->port->disc.fanout_sas_addr)) {
742 SAS_DPRINTK("second fanout expander %016llx phy 0x%x "
743 "attached to ex %016llx phy 0x%x\n",
744 SAS_ADDR(ex_phy->attached_sas_addr),
745 ex_phy->attached_phy_id,
746 SAS_ADDR(dev->sas_addr),
748 sas_ex_disable_phy(dev, phy_id);
751 memcpy(dev->port->disc.fanout_sas_addr,
752 ex_phy->attached_sas_addr, SAS_ADDR_SIZE);
755 child = sas_ex_discover_expander(dev, phy_id);
764 for (i = 0; i < ex->num_phys; i++) {
765 if (ex->ex_phy[i].phy_state == PHY_VACANT ||
766 ex->ex_phy[i].phy_state == PHY_NOT_PRESENT)
769 if (SAS_ADDR(ex->ex_phy[i].attached_sas_addr) ==
770 SAS_ADDR(child->sas_addr))
771 ex->ex_phy[i].phy_state= PHY_DEVICE_DISCOVERED;
778 static inline int sas_find_sub_addr(struct domain_device *dev, u8 *sub_addr)
780 struct expander_device *ex = &dev->ex_dev;
783 for (i = 0; i < ex->num_phys; i++) {
784 struct ex_phy *phy = &ex->ex_phy[i];
786 if (phy->phy_state == PHY_VACANT ||
787 phy->phy_state == PHY_NOT_PRESENT)
790 if ((phy->attached_dev_type == EDGE_DEV ||
791 phy->attached_dev_type == FANOUT_DEV) &&
792 phy->routing_attr == SUBTRACTIVE_ROUTING) {
794 memcpy(sub_addr, phy->attached_sas_addr,SAS_ADDR_SIZE);
802 static int sas_check_level_subtractive_boundary(struct domain_device *dev)
804 struct expander_device *ex = &dev->ex_dev;
805 struct domain_device *child;
806 u8 sub_addr[8] = {0, };
808 list_for_each_entry(child, &ex->children, siblings) {
809 if (child->dev_type != EDGE_DEV &&
810 child->dev_type != FANOUT_DEV)
812 if (sub_addr[0] == 0) {
813 sas_find_sub_addr(child, sub_addr);
818 if (sas_find_sub_addr(child, s2) &&
819 (SAS_ADDR(sub_addr) != SAS_ADDR(s2))) {
821 SAS_DPRINTK("ex %016llx->%016llx-?->%016llx "
822 "diverges from subtractive "
823 "boundary %016llx\n",
824 SAS_ADDR(dev->sas_addr),
825 SAS_ADDR(child->sas_addr),
829 sas_ex_disable_port(child, s2);
836 * sas_ex_discover_devices -- discover devices attached to this expander
837 * dev: pointer to the expander domain device
838 * single: if you want to do a single phy, else set to -1;
840 * Configure this expander for use with its devices and register the
841 * devices of this expander.
843 static int sas_ex_discover_devices(struct domain_device *dev, int single)
845 struct expander_device *ex = &dev->ex_dev;
846 int i = 0, end = ex->num_phys;
849 if (0 <= single && single < end) {
854 for ( ; i < end; i++) {
855 struct ex_phy *ex_phy = &ex->ex_phy[i];
857 if (ex_phy->phy_state == PHY_VACANT ||
858 ex_phy->phy_state == PHY_NOT_PRESENT ||
859 ex_phy->phy_state == PHY_DEVICE_DISCOVERED)
862 switch (ex_phy->linkrate) {
864 case PHY_RESET_PROBLEM:
865 case PHY_PORT_SELECTOR:
868 res = sas_ex_discover_dev(dev, i);
876 sas_check_level_subtractive_boundary(dev);
881 static int sas_check_ex_subtractive_boundary(struct domain_device *dev)
883 struct expander_device *ex = &dev->ex_dev;
885 u8 *sub_sas_addr = NULL;
887 if (dev->dev_type != EDGE_DEV)
890 for (i = 0; i < ex->num_phys; i++) {
891 struct ex_phy *phy = &ex->ex_phy[i];
893 if (phy->phy_state == PHY_VACANT ||
894 phy->phy_state == PHY_NOT_PRESENT)
897 if ((phy->attached_dev_type == FANOUT_DEV ||
898 phy->attached_dev_type == EDGE_DEV) &&
899 phy->routing_attr == SUBTRACTIVE_ROUTING) {
902 sub_sas_addr = &phy->attached_sas_addr[0];
903 else if (SAS_ADDR(sub_sas_addr) !=
904 SAS_ADDR(phy->attached_sas_addr)) {
906 SAS_DPRINTK("ex %016llx phy 0x%x "
907 "diverges(%016llx) on subtractive "
908 "boundary(%016llx). Disabled\n",
909 SAS_ADDR(dev->sas_addr), i,
910 SAS_ADDR(phy->attached_sas_addr),
911 SAS_ADDR(sub_sas_addr));
912 sas_ex_disable_phy(dev, i);
919 static inline void sas_print_parent_topology_bug(struct domain_device *child,
920 struct ex_phy *parent_phy,
921 struct ex_phy *child_phy)
923 static const char ra_char[] = {
924 [DIRECT_ROUTING] = 'D',
925 [SUBTRACTIVE_ROUTING] = 'S',
926 [TABLE_ROUTING] = 'T',
928 static const char *ex_type[] = {
930 [FANOUT_DEV] = "fanout",
932 struct domain_device *parent = child->parent;
934 sas_printk("%s ex %016llx phy 0x%x <--> %s ex %016llx phy 0x%x "
935 "has %c:%c routing link!\n",
937 ex_type[parent->dev_type],
938 SAS_ADDR(parent->sas_addr),
941 ex_type[child->dev_type],
942 SAS_ADDR(child->sas_addr),
945 ra_char[parent_phy->routing_attr],
946 ra_char[child_phy->routing_attr]);
949 static inline int sas_check_eeds(struct domain_device *child,
950 struct ex_phy *parent_phy,
951 struct ex_phy *child_phy)
954 struct domain_device *parent = child->parent;
956 if (SAS_ADDR(parent->port->disc.fanout_sas_addr) != 0) {
958 SAS_DPRINTK("edge ex %016llx phy S:0x%x <--> edge ex %016llx "
959 "phy S:0x%x, while there is a fanout ex %016llx\n",
960 SAS_ADDR(parent->sas_addr),
962 SAS_ADDR(child->sas_addr),
964 SAS_ADDR(parent->port->disc.fanout_sas_addr));
965 } else if (SAS_ADDR(parent->port->disc.eeds_a) == 0) {
966 memcpy(parent->port->disc.eeds_a, parent->sas_addr,
968 memcpy(parent->port->disc.eeds_b, child->sas_addr,
970 } else if (((SAS_ADDR(parent->port->disc.eeds_a) ==
971 SAS_ADDR(parent->sas_addr)) ||
972 (SAS_ADDR(parent->port->disc.eeds_a) ==
973 SAS_ADDR(child->sas_addr)))
975 ((SAS_ADDR(parent->port->disc.eeds_b) ==
976 SAS_ADDR(parent->sas_addr)) ||
977 (SAS_ADDR(parent->port->disc.eeds_b) ==
978 SAS_ADDR(child->sas_addr))))
982 SAS_DPRINTK("edge ex %016llx phy 0x%x <--> edge ex %016llx "
983 "phy 0x%x link forms a third EEDS!\n",
984 SAS_ADDR(parent->sas_addr),
986 SAS_ADDR(child->sas_addr),
993 /* Here we spill over 80 columns. It is intentional.
995 static int sas_check_parent_topology(struct domain_device *child)
997 struct expander_device *child_ex = &child->ex_dev;
998 struct expander_device *parent_ex;
1005 if (child->parent->dev_type != EDGE_DEV &&
1006 child->parent->dev_type != FANOUT_DEV)
1009 parent_ex = &child->parent->ex_dev;
1011 for (i = 0; i < parent_ex->num_phys; i++) {
1012 struct ex_phy *parent_phy = &parent_ex->ex_phy[i];
1013 struct ex_phy *child_phy;
1015 if (parent_phy->phy_state == PHY_VACANT ||
1016 parent_phy->phy_state == PHY_NOT_PRESENT)
1019 if (SAS_ADDR(parent_phy->attached_sas_addr) != SAS_ADDR(child->sas_addr))
1022 child_phy = &child_ex->ex_phy[parent_phy->attached_phy_id];
1024 switch (child->parent->dev_type) {
1026 if (child->dev_type == FANOUT_DEV) {
1027 if (parent_phy->routing_attr != SUBTRACTIVE_ROUTING ||
1028 child_phy->routing_attr != TABLE_ROUTING) {
1029 sas_print_parent_topology_bug(child, parent_phy, child_phy);
1032 } else if (parent_phy->routing_attr == SUBTRACTIVE_ROUTING) {
1033 if (child_phy->routing_attr == SUBTRACTIVE_ROUTING) {
1034 res = sas_check_eeds(child, parent_phy, child_phy);
1035 } else if (child_phy->routing_attr != TABLE_ROUTING) {
1036 sas_print_parent_topology_bug(child, parent_phy, child_phy);
1039 } else if (parent_phy->routing_attr == TABLE_ROUTING &&
1040 child_phy->routing_attr != SUBTRACTIVE_ROUTING) {
1041 sas_print_parent_topology_bug(child, parent_phy, child_phy);
1046 if (parent_phy->routing_attr != TABLE_ROUTING ||
1047 child_phy->routing_attr != SUBTRACTIVE_ROUTING) {
1048 sas_print_parent_topology_bug(child, parent_phy, child_phy);
1060 #define RRI_REQ_SIZE 16
1061 #define RRI_RESP_SIZE 44
1063 static int sas_configure_present(struct domain_device *dev, int phy_id,
1064 u8 *sas_addr, int *index, int *present)
1067 struct expander_device *ex = &dev->ex_dev;
1068 struct ex_phy *phy = &ex->ex_phy[phy_id];
1075 rri_req = alloc_smp_req(RRI_REQ_SIZE);
1079 rri_resp = alloc_smp_resp(RRI_RESP_SIZE);
1085 rri_req[1] = SMP_REPORT_ROUTE_INFO;
1086 rri_req[9] = phy_id;
1088 for (i = 0; i < ex->max_route_indexes ; i++) {
1089 *(__be16 *)(rri_req+6) = cpu_to_be16(i);
1090 res = smp_execute_task(dev, rri_req, RRI_REQ_SIZE, rri_resp,
1095 if (res == SMP_RESP_NO_INDEX) {
1096 SAS_DPRINTK("overflow of indexes: dev %016llx "
1097 "phy 0x%x index 0x%x\n",
1098 SAS_ADDR(dev->sas_addr), phy_id, i);
1100 } else if (res != SMP_RESP_FUNC_ACC) {
1101 SAS_DPRINTK("%s: dev %016llx phy 0x%x index 0x%x "
1102 "result 0x%x\n", __FUNCTION__,
1103 SAS_ADDR(dev->sas_addr), phy_id, i, res);
1106 if (SAS_ADDR(sas_addr) != 0) {
1107 if (SAS_ADDR(rri_resp+16) == SAS_ADDR(sas_addr)) {
1109 if ((rri_resp[12] & 0x80) == 0x80)
1114 } else if (SAS_ADDR(rri_resp+16) == 0) {
1119 } else if (SAS_ADDR(rri_resp+16) == 0 &&
1120 phy->last_da_index < i) {
1121 phy->last_da_index = i;
1134 #define CRI_REQ_SIZE 44
1135 #define CRI_RESP_SIZE 8
1137 static int sas_configure_set(struct domain_device *dev, int phy_id,
1138 u8 *sas_addr, int index, int include)
1144 cri_req = alloc_smp_req(CRI_REQ_SIZE);
1148 cri_resp = alloc_smp_resp(CRI_RESP_SIZE);
1154 cri_req[1] = SMP_CONF_ROUTE_INFO;
1155 *(__be16 *)(cri_req+6) = cpu_to_be16(index);
1156 cri_req[9] = phy_id;
1157 if (SAS_ADDR(sas_addr) == 0 || !include)
1158 cri_req[12] |= 0x80;
1159 memcpy(cri_req+16, sas_addr, SAS_ADDR_SIZE);
1161 res = smp_execute_task(dev, cri_req, CRI_REQ_SIZE, cri_resp,
1166 if (res == SMP_RESP_NO_INDEX) {
1167 SAS_DPRINTK("overflow of indexes: dev %016llx phy 0x%x "
1169 SAS_ADDR(dev->sas_addr), phy_id, index);
1177 static inline int sas_configure_phy(struct domain_device *dev, int phy_id,
1178 u8 *sas_addr, int include)
1184 res = sas_configure_present(dev, phy_id, sas_addr, &index, &present);
1187 if (include ^ present)
1188 return sas_configure_set(dev, phy_id, sas_addr, index,include);
1194 * sas_configure_parent -- configure routing table of parent
1195 * parent: parent expander
1196 * child: child expander
1197 * sas_addr: SAS port identifier of device directly attached to child
1199 static int sas_configure_parent(struct domain_device *parent,
1200 struct domain_device *child,
1201 u8 *sas_addr, int include)
1203 struct expander_device *ex_parent = &parent->ex_dev;
1207 if (parent->parent) {
1208 res = sas_configure_parent(parent->parent, parent, sas_addr,
1214 if (ex_parent->conf_route_table == 0) {
1215 SAS_DPRINTK("ex %016llx has self-configuring routing table\n",
1216 SAS_ADDR(parent->sas_addr));
1220 for (i = 0; i < ex_parent->num_phys; i++) {
1221 struct ex_phy *phy = &ex_parent->ex_phy[i];
1223 if ((phy->routing_attr == TABLE_ROUTING) &&
1224 (SAS_ADDR(phy->attached_sas_addr) ==
1225 SAS_ADDR(child->sas_addr))) {
1226 res = sas_configure_phy(parent, i, sas_addr, include);
1236 * sas_configure_routing -- configure routing
1237 * dev: expander device
1238 * sas_addr: port identifier of device directly attached to the expander device
1240 static int sas_configure_routing(struct domain_device *dev, u8 *sas_addr)
1243 return sas_configure_parent(dev->parent, dev, sas_addr, 1);
1247 static int sas_disable_routing(struct domain_device *dev, u8 *sas_addr)
1250 return sas_configure_parent(dev->parent, dev, sas_addr, 0);
1255 #define SMP_BIN_ATTR_NAME "smp_portal"
1257 static void sas_ex_smp_hook(struct domain_device *dev)
1259 struct expander_device *ex_dev = &dev->ex_dev;
1260 struct bin_attribute *bin_attr = &ex_dev->smp_bin_attr;
1262 memset(bin_attr, 0, sizeof(*bin_attr));
1264 bin_attr->attr.name = SMP_BIN_ATTR_NAME;
1265 bin_attr->attr.owner = THIS_MODULE;
1266 bin_attr->attr.mode = 0600;
1269 bin_attr->private = NULL;
1270 bin_attr->read = smp_portal_read;
1271 bin_attr->write= smp_portal_write;
1272 bin_attr->mmap = NULL;
1274 ex_dev->smp_portal_pid = -1;
1275 init_MUTEX(&ex_dev->smp_sema);
1280 * sas_discover_expander -- expander discovery
1281 * @ex: pointer to expander domain device
1283 * See comment in sas_discover_sata().
1285 static int sas_discover_expander(struct domain_device *dev)
1289 res = sas_notify_lldd_dev_found(dev);
1293 res = sas_ex_general(dev);
1296 res = sas_ex_manuf_info(dev);
1300 res = sas_expander_discover(dev);
1302 SAS_DPRINTK("expander %016llx discovery failed(0x%x)\n",
1303 SAS_ADDR(dev->sas_addr), res);
1307 sas_check_ex_subtractive_boundary(dev);
1308 res = sas_check_parent_topology(dev);
1313 sas_notify_lldd_dev_gone(dev);
1317 static int sas_ex_level_discovery(struct sas_port *port, const int level)
1320 struct domain_device *dev;
1322 list_for_each_entry(dev, &port->dev_list, dev_list_node) {
1323 if (dev->dev_type == EDGE_DEV ||
1324 dev->dev_type == FANOUT_DEV) {
1325 struct sas_expander_device *ex =
1326 rphy_to_expander_device(dev->rphy);
1328 if (level == ex->level)
1329 res = sas_ex_discover_devices(dev, -1);
1336 static int sas_ex_bfs_disc(struct sas_port *port)
1342 level = port->disc.max_level;
1343 res = sas_ex_level_discovery(port, level);
1345 } while (level < port->disc.max_level);
1350 int sas_discover_root_expander(struct domain_device *dev)
1353 struct sas_expander_device *ex = rphy_to_expander_device(dev->rphy);
1355 sas_rphy_add(dev->rphy);
1357 ex->level = dev->port->disc.max_level; /* 0 */
1358 res = sas_discover_expander(dev);
1360 sas_ex_bfs_disc(dev->port);
1365 /* ---------- Domain revalidation ---------- */
1367 static int sas_get_phy_discover(struct domain_device *dev,
1368 int phy_id, struct smp_resp *disc_resp)
1373 disc_req = alloc_smp_req(DISCOVER_REQ_SIZE);
1377 disc_req[1] = SMP_DISCOVER;
1378 disc_req[9] = phy_id;
1380 res = smp_execute_task(dev, disc_req, DISCOVER_REQ_SIZE,
1381 disc_resp, DISCOVER_RESP_SIZE);
1384 else if (disc_resp->result != SMP_RESP_FUNC_ACC) {
1385 res = disc_resp->result;
1393 static int sas_get_phy_change_count(struct domain_device *dev,
1394 int phy_id, int *pcc)
1397 struct smp_resp *disc_resp;
1399 disc_resp = alloc_smp_resp(DISCOVER_RESP_SIZE);
1403 res = sas_get_phy_discover(dev, phy_id, disc_resp);
1405 *pcc = disc_resp->disc.change_count;
1411 static int sas_get_phy_attached_sas_addr(struct domain_device *dev,
1412 int phy_id, u8 *attached_sas_addr)
1415 struct smp_resp *disc_resp;
1417 disc_resp = alloc_smp_resp(DISCOVER_RESP_SIZE);
1421 res = sas_get_phy_discover(dev, phy_id, disc_resp);
1423 memcpy(attached_sas_addr,disc_resp->disc.attached_sas_addr,8);
1429 static int sas_find_bcast_phy(struct domain_device *dev, int *phy_id,
1432 struct expander_device *ex = &dev->ex_dev;
1436 for (i = from_phy; i < ex->num_phys; i++) {
1437 int phy_change_count = 0;
1439 res = sas_get_phy_change_count(dev, i, &phy_change_count);
1442 else if (phy_change_count != ex->ex_phy[i].phy_change_count) {
1443 ex->ex_phy[i].phy_change_count = phy_change_count;
1452 static int sas_get_ex_change_count(struct domain_device *dev, int *ecc)
1456 struct smp_resp *rg_resp;
1458 rg_req = alloc_smp_req(RG_REQ_SIZE);
1462 rg_resp = alloc_smp_resp(RG_RESP_SIZE);
1468 rg_req[1] = SMP_REPORT_GENERAL;
1470 res = smp_execute_task(dev, rg_req, RG_REQ_SIZE, rg_resp,
1474 if (rg_resp->result != SMP_RESP_FUNC_ACC) {
1475 res = rg_resp->result;
1479 *ecc = be16_to_cpu(rg_resp->rg.change_count);
1486 static int sas_find_bcast_dev(struct domain_device *dev,
1487 struct domain_device **src_dev)
1489 struct expander_device *ex = &dev->ex_dev;
1490 int ex_change_count = -1;
1493 res = sas_get_ex_change_count(dev, &ex_change_count);
1496 if (ex_change_count != -1 &&
1497 ex_change_count != ex->ex_change_count) {
1499 ex->ex_change_count = ex_change_count;
1501 struct domain_device *ch;
1503 list_for_each_entry(ch, &ex->children, siblings) {
1504 if (ch->dev_type == EDGE_DEV ||
1505 ch->dev_type == FANOUT_DEV) {
1506 res = sas_find_bcast_dev(ch, src_dev);
1516 static void sas_unregister_ex_tree(struct domain_device *dev)
1518 struct expander_device *ex = &dev->ex_dev;
1519 struct domain_device *child, *n;
1521 list_for_each_entry_safe(child, n, &ex->children, siblings) {
1522 if (child->dev_type == EDGE_DEV ||
1523 child->dev_type == FANOUT_DEV)
1524 sas_unregister_ex_tree(child);
1526 sas_unregister_dev(child);
1528 sas_unregister_dev(dev);
1531 static void sas_unregister_devs_sas_addr(struct domain_device *parent,
1534 struct expander_device *ex_dev = &parent->ex_dev;
1535 struct ex_phy *phy = &ex_dev->ex_phy[phy_id];
1536 struct domain_device *child, *n;
1538 list_for_each_entry_safe(child, n, &ex_dev->children, siblings) {
1539 if (SAS_ADDR(child->sas_addr) ==
1540 SAS_ADDR(phy->attached_sas_addr)) {
1541 if (child->dev_type == EDGE_DEV ||
1542 child->dev_type == FANOUT_DEV)
1543 sas_unregister_ex_tree(child);
1545 sas_unregister_dev(child);
1549 sas_disable_routing(parent, phy->attached_sas_addr);
1550 memset(phy->attached_sas_addr, 0, SAS_ADDR_SIZE);
1553 static int sas_discover_bfs_by_root_level(struct domain_device *root,
1556 struct expander_device *ex_root = &root->ex_dev;
1557 struct domain_device *child;
1560 list_for_each_entry(child, &ex_root->children, siblings) {
1561 if (child->dev_type == EDGE_DEV ||
1562 child->dev_type == FANOUT_DEV) {
1563 struct sas_expander_device *ex =
1564 rphy_to_expander_device(child->rphy);
1566 if (level > ex->level)
1567 res = sas_discover_bfs_by_root_level(child,
1569 else if (level == ex->level)
1570 res = sas_ex_discover_devices(child, -1);
1576 static int sas_discover_bfs_by_root(struct domain_device *dev)
1579 struct sas_expander_device *ex = rphy_to_expander_device(dev->rphy);
1580 int level = ex->level+1;
1582 res = sas_ex_discover_devices(dev, -1);
1586 res = sas_discover_bfs_by_root_level(dev, level);
1589 } while (level <= dev->port->disc.max_level);
1594 static inline int sas_discover_new(struct domain_device *dev, int phy_id)
1596 struct ex_phy *ex_phy = &dev->ex_dev.ex_phy[phy_id];
1597 struct domain_device *child;
1600 SAS_DPRINTK("ex %016llx phy%d new device attached\n",
1601 SAS_ADDR(dev->sas_addr), phy_id);
1602 res = sas_ex_phy_discover(dev, phy_id);
1605 res = sas_ex_discover_devices(dev, phy_id);
1608 list_for_each_entry(child, &dev->ex_dev.children, siblings) {
1609 if (SAS_ADDR(child->sas_addr) ==
1610 SAS_ADDR(ex_phy->attached_sas_addr)) {
1611 if (child->dev_type == EDGE_DEV ||
1612 child->dev_type == FANOUT_DEV)
1613 res = sas_discover_bfs_by_root(child);
1621 static int sas_rediscover_dev(struct domain_device *dev, int phy_id)
1623 struct expander_device *ex = &dev->ex_dev;
1624 struct ex_phy *phy = &ex->ex_phy[phy_id];
1625 u8 attached_sas_addr[8];
1628 res = sas_get_phy_attached_sas_addr(dev, phy_id, attached_sas_addr);
1630 case SMP_RESP_NO_PHY:
1631 phy->phy_state = PHY_NOT_PRESENT;
1632 sas_unregister_devs_sas_addr(dev, phy_id);
1634 case SMP_RESP_PHY_VACANT:
1635 phy->phy_state = PHY_VACANT;
1636 sas_unregister_devs_sas_addr(dev, phy_id);
1638 case SMP_RESP_FUNC_ACC:
1642 if (SAS_ADDR(attached_sas_addr) == 0) {
1643 phy->phy_state = PHY_EMPTY;
1644 sas_unregister_devs_sas_addr(dev, phy_id);
1645 } else if (SAS_ADDR(attached_sas_addr) ==
1646 SAS_ADDR(phy->attached_sas_addr)) {
1647 SAS_DPRINTK("ex %016llx phy 0x%x broadcast flutter\n",
1648 SAS_ADDR(dev->sas_addr), phy_id);
1650 res = sas_discover_new(dev, phy_id);
1655 static int sas_rediscover(struct domain_device *dev, const int phy_id)
1657 struct expander_device *ex = &dev->ex_dev;
1658 struct ex_phy *changed_phy = &ex->ex_phy[phy_id];
1662 SAS_DPRINTK("ex %016llx phy%d originated BROADCAST(CHANGE)\n",
1663 SAS_ADDR(dev->sas_addr), phy_id);
1665 if (SAS_ADDR(changed_phy->attached_sas_addr) != 0) {
1666 for (i = 0; i < ex->num_phys; i++) {
1667 struct ex_phy *phy = &ex->ex_phy[i];
1671 if (SAS_ADDR(phy->attached_sas_addr) ==
1672 SAS_ADDR(changed_phy->attached_sas_addr)) {
1673 SAS_DPRINTK("phy%d part of wide port with "
1674 "phy%d\n", phy_id, i);
1678 res = sas_rediscover_dev(dev, phy_id);
1680 res = sas_discover_new(dev, phy_id);
1686 * sas_revalidate_domain -- revalidate the domain
1687 * @port: port to the domain of interest
1689 * NOTE: this process _must_ quit (return) as soon as any connection
1690 * errors are encountered. Connection recovery is done elsewhere.
1691 * Discover process only interrogates devices in order to discover the
1694 int sas_ex_revalidate_domain(struct domain_device *port_dev)
1697 struct domain_device *dev = NULL;
1699 res = sas_find_bcast_dev(port_dev, &dev);
1703 struct expander_device *ex = &dev->ex_dev;
1708 res = sas_find_bcast_phy(dev, &phy_id, i);
1711 res = sas_rediscover(dev, phy_id);
1713 } while (i < ex->num_phys);
1720 /* ---------- SMP portal ---------- */
1722 static ssize_t smp_portal_write(struct kobject *kobj, char *buf, loff_t offs,
1725 struct domain_device *dev = to_dom_device(kobj);
1726 struct expander_device *ex = &dev->ex_dev;
1733 down_interruptible(&ex->smp_sema);
1736 ex->smp_req = kzalloc(size, GFP_USER);
1741 memcpy(ex->smp_req, buf, size);
1742 ex->smp_req_size = size;
1743 ex->smp_portal_pid = current->pid;
1749 static ssize_t smp_portal_read(struct kobject *kobj, char *buf, loff_t offs,
1752 struct domain_device *dev = to_dom_device(kobj);
1753 struct expander_device *ex = &dev->ex_dev;
1757 /* XXX: sysfs gives us an offset of 0x10 or 0x8 while in fact
1761 down_interruptible(&ex->smp_sema);
1762 if (!ex->smp_req || ex->smp_portal_pid != current->pid)
1770 smp_resp = alloc_smp_resp(size);
1773 res = smp_execute_task(dev, ex->smp_req, ex->smp_req_size,
1776 memcpy(buf, smp_resp, size);
1784 ex->smp_req_size = 0;
1785 ex->smp_portal_pid = -1;