Commit | Line | Data |
---|---|---|
86b89cb0 | 1 | // SPDX-License-Identifier: GPL-2.0 |
2908d778 JB |
2 | /* |
3 | * Serial Attached SCSI (SAS) Discover process | |
4 | * | |
5 | * Copyright (C) 2005 Adaptec, Inc. All rights reserved. | |
6 | * Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com> | |
2908d778 JB |
7 | */ |
8 | ||
2908d778 | 9 | #include <linux/scatterlist.h> |
5a0e3ad6 | 10 | #include <linux/slab.h> |
303694ee | 11 | #include <linux/async.h> |
2908d778 JB |
12 | #include <scsi/scsi_host.h> |
13 | #include <scsi/scsi_eh.h> | |
14 | #include "sas_internal.h" | |
15 | ||
16 | #include <scsi/scsi_transport.h> | |
17 | #include <scsi/scsi_transport_sas.h> | |
756f173f | 18 | #include <scsi/sas_ata.h> |
2908d778 JB |
19 | #include "../scsi_sas_internal.h" |
20 | ||
21 | /* ---------- Basic task processing for discovery purposes ---------- */ | |
22 | ||
23 | void sas_init_dev(struct domain_device *dev) | |
24 | { | |
89d3cf6a | 25 | switch (dev->dev_type) { |
aa9f8328 | 26 | case SAS_END_DEVICE: |
5db45bdc | 27 | INIT_LIST_HEAD(&dev->ssp_dev.eh_list_node); |
89d3cf6a | 28 | break; |
aa9f8328 JB |
29 | case SAS_EDGE_EXPANDER_DEVICE: |
30 | case SAS_FANOUT_EXPANDER_DEVICE: | |
89d3cf6a JS |
31 | INIT_LIST_HEAD(&dev->ex_dev.children); |
32 | mutex_init(&dev->ex_dev.cmd_mutex); | |
33 | break; | |
89d3cf6a JS |
34 | default: |
35 | break; | |
36 | } | |
2908d778 JB |
37 | } |
38 | ||
2908d778 JB |
39 | /* ---------- Domain device discovery ---------- */ |
40 | ||
41 | /** | |
121246ae | 42 | * sas_get_port_device - Discover devices which caused port creation |
2908d778 JB |
43 | * @port: pointer to struct sas_port of interest |
44 | * | |
45 | * Devices directly attached to a HA port, have no parent. This is | |
46 | * how we know they are (domain) "root" devices. All other devices | |
47 | * do, and should have their "parent" pointer set appropriately as | |
48 | * soon as a child device is discovered. | |
49 | */ | |
50 | static int sas_get_port_device(struct asd_sas_port *port) | |
51 | { | |
2908d778 JB |
52 | struct asd_sas_phy *phy; |
53 | struct sas_rphy *rphy; | |
54 | struct domain_device *dev; | |
b2024459 | 55 | int rc = -ENODEV; |
2908d778 | 56 | |
735f7d2f | 57 | dev = sas_alloc_device(); |
2908d778 JB |
58 | if (!dev) |
59 | return -ENOMEM; | |
60 | ||
899fcf40 | 61 | spin_lock_irq(&port->phy_list_lock); |
2908d778 | 62 | if (list_empty(&port->phy_list)) { |
899fcf40 | 63 | spin_unlock_irq(&port->phy_list_lock); |
735f7d2f | 64 | sas_put_device(dev); |
2908d778 JB |
65 | return -ENODEV; |
66 | } | |
67 | phy = container_of(port->phy_list.next, struct asd_sas_phy, port_phy_el); | |
68 | spin_lock(&phy->frame_rcvd_lock); | |
69 | memcpy(dev->frame_rcvd, phy->frame_rcvd, min(sizeof(dev->frame_rcvd), | |
70 | (size_t)phy->frame_rcvd_size)); | |
71 | spin_unlock(&phy->frame_rcvd_lock); | |
899fcf40 | 72 | spin_unlock_irq(&port->phy_list_lock); |
2908d778 JB |
73 | |
74 | if (dev->frame_rcvd[0] == 0x34 && port->oob_mode == SATA_OOB_MODE) { | |
75 | struct dev_to_host_fis *fis = | |
76 | (struct dev_to_host_fis *) dev->frame_rcvd; | |
77 | if (fis->interrupt_reason == 1 && fis->lbal == 1 && | |
78 | fis->byte_count_low==0x69 && fis->byte_count_high == 0x96 | |
79 | && (fis->device & ~0x10) == 0) | |
aa9f8328 | 80 | dev->dev_type = SAS_SATA_PM; |
2908d778 | 81 | else |
aa9f8328 | 82 | dev->dev_type = SAS_SATA_DEV; |
5929faf3 | 83 | dev->tproto = SAS_PROTOCOL_SATA; |
f70267f3 | 84 | } else if (port->oob_mode == SAS_OOB_MODE) { |
2908d778 JB |
85 | struct sas_identify_frame *id = |
86 | (struct sas_identify_frame *) dev->frame_rcvd; | |
87 | dev->dev_type = id->dev_type; | |
88 | dev->iproto = id->initiator_bits; | |
89 | dev->tproto = id->target_bits; | |
f70267f3 JY |
90 | } else { |
91 | /* If the oob mode is OOB_NOT_CONNECTED, the port is | |
92 | * disconnected due to race with PHY down. We cannot | |
93 | * continue to discover this port | |
94 | */ | |
95 | sas_put_device(dev); | |
96 | pr_warn("Port %016llx is disconnected when discovering\n", | |
97 | SAS_ADDR(port->attached_sas_addr)); | |
98 | return -ENODEV; | |
2908d778 JB |
99 | } |
100 | ||
101 | sas_init_dev(dev); | |
102 | ||
b2024459 | 103 | dev->port = port; |
2908d778 | 104 | switch (dev->dev_type) { |
aa9f8328 | 105 | case SAS_SATA_DEV: |
b2024459 DW |
106 | rc = sas_ata_init(dev); |
107 | if (rc) { | |
108 | rphy = NULL; | |
109 | break; | |
110 | } | |
df561f66 | 111 | fallthrough; |
aa9f8328 | 112 | case SAS_END_DEVICE: |
2908d778 JB |
113 | rphy = sas_end_device_alloc(port->port); |
114 | break; | |
aa9f8328 | 115 | case SAS_EDGE_EXPANDER_DEVICE: |
2908d778 JB |
116 | rphy = sas_expander_alloc(port->port, |
117 | SAS_EDGE_EXPANDER_DEVICE); | |
118 | break; | |
aa9f8328 | 119 | case SAS_FANOUT_EXPANDER_DEVICE: |
2908d778 JB |
120 | rphy = sas_expander_alloc(port->port, |
121 | SAS_FANOUT_EXPANDER_DEVICE); | |
122 | break; | |
2908d778 | 123 | default: |
15ba7806 | 124 | pr_warn("ERROR: Unidentified device type %d\n", dev->dev_type); |
2908d778 JB |
125 | rphy = NULL; |
126 | break; | |
127 | } | |
128 | ||
129 | if (!rphy) { | |
735f7d2f | 130 | sas_put_device(dev); |
b2024459 | 131 | return rc; |
2908d778 | 132 | } |
899fcf40 | 133 | |
2908d778 JB |
134 | rphy->identify.phy_identifier = phy->phy->identify.phy_identifier; |
135 | memcpy(dev->sas_addr, port->attached_sas_addr, SAS_ADDR_SIZE); | |
136 | sas_fill_in_rphy(dev, rphy); | |
137 | sas_hash_addr(dev->hashed_sas_addr, dev->sas_addr); | |
138 | port->port_dev = dev; | |
2908d778 JB |
139 | dev->linkrate = port->linkrate; |
140 | dev->min_linkrate = port->linkrate; | |
141 | dev->max_linkrate = port->linkrate; | |
142 | dev->pathways = port->num_phys; | |
143 | memset(port->disc.fanout_sas_addr, 0, SAS_ADDR_SIZE); | |
144 | memset(port->disc.eeds_a, 0, SAS_ADDR_SIZE); | |
145 | memset(port->disc.eeds_b, 0, SAS_ADDR_SIZE); | |
146 | port->disc.max_level = 0; | |
f41a0c44 | 147 | sas_device_set_phy(dev, port->port); |
2908d778 JB |
148 | |
149 | dev->rphy = rphy; | |
9487669f | 150 | get_device(&dev->rphy->dev); |
87c8331f | 151 | |
aa9f8328 | 152 | if (dev_is_sata(dev) || dev->dev_type == SAS_END_DEVICE) |
87c8331f DW |
153 | list_add_tail(&dev->disco_list_node, &port->disco_list); |
154 | else { | |
155 | spin_lock_irq(&port->dev_list_lock); | |
156 | list_add_tail(&dev->dev_list_node, &port->dev_list); | |
157 | spin_unlock_irq(&port->dev_list_lock); | |
158 | } | |
2908d778 | 159 | |
ec236e52 DW |
160 | spin_lock_irq(&port->phy_list_lock); |
161 | list_for_each_entry(phy, &port->phy_list, port_phy_el) | |
162 | sas_phy_set_target(phy, dev); | |
163 | spin_unlock_irq(&port->phy_list_lock); | |
164 | ||
2908d778 JB |
165 | return 0; |
166 | } | |
167 | ||
168 | /* ---------- Discover and Revalidate ---------- */ | |
169 | ||
2908d778 JB |
170 | int sas_notify_lldd_dev_found(struct domain_device *dev) |
171 | { | |
172 | int res = 0; | |
173 | struct sas_ha_struct *sas_ha = dev->port->ha; | |
174 | struct Scsi_Host *shost = sas_ha->core.shost; | |
175 | struct sas_internal *i = to_sas_internal(shost->transportt); | |
176 | ||
303694ee DW |
177 | if (!i->dft->lldd_dev_found) |
178 | return 0; | |
179 | ||
180 | res = i->dft->lldd_dev_found(dev); | |
181 | if (res) { | |
b3e3d4c6 | 182 | pr_warn("driver on host %s cannot handle device %016llx, error:%d\n", |
15ba7806 JG |
183 | dev_name(sas_ha->dev), |
184 | SAS_ADDR(dev->sas_addr), res); | |
2908d778 | 185 | } |
303694ee DW |
186 | set_bit(SAS_DEV_FOUND, &dev->state); |
187 | kref_get(&dev->kref); | |
2908d778 JB |
188 | return res; |
189 | } | |
190 | ||
191 | ||
192 | void sas_notify_lldd_dev_gone(struct domain_device *dev) | |
193 | { | |
194 | struct sas_ha_struct *sas_ha = dev->port->ha; | |
195 | struct Scsi_Host *shost = sas_ha->core.shost; | |
196 | struct sas_internal *i = to_sas_internal(shost->transportt); | |
197 | ||
303694ee DW |
198 | if (!i->dft->lldd_dev_gone) |
199 | return; | |
200 | ||
201 | if (test_and_clear_bit(SAS_DEV_FOUND, &dev->state)) { | |
2908d778 | 202 | i->dft->lldd_dev_gone(dev); |
735f7d2f DW |
203 | sas_put_device(dev); |
204 | } | |
2908d778 JB |
205 | } |
206 | ||
0558f33c | 207 | static void sas_probe_devices(struct asd_sas_port *port) |
92625f9b DW |
208 | { |
209 | struct domain_device *dev, *n; | |
92625f9b | 210 | |
9508a66f DW |
211 | /* devices must be domain members before link recovery and probe */ |
212 | list_for_each_entry(dev, &port->disco_list, disco_list_node) { | |
92625f9b DW |
213 | spin_lock_irq(&port->dev_list_lock); |
214 | list_add_tail(&dev->dev_list_node, &port->dev_list); | |
215 | spin_unlock_irq(&port->dev_list_lock); | |
9508a66f | 216 | } |
92625f9b | 217 | |
9508a66f | 218 | sas_probe_sata(port); |
92625f9b | 219 | |
9508a66f DW |
220 | list_for_each_entry_safe(dev, n, &port->disco_list, disco_list_node) { |
221 | int err; | |
222 | ||
223 | err = sas_rphy_add(dev->rphy); | |
224 | if (err) | |
225 | sas_fail_probe(dev, __func__, err); | |
226 | else | |
92625f9b DW |
227 | list_del_init(&dev->disco_list_node); |
228 | } | |
229 | } | |
2908d778 | 230 | |
303694ee DW |
231 | static void sas_suspend_devices(struct work_struct *work) |
232 | { | |
233 | struct asd_sas_phy *phy; | |
234 | struct domain_device *dev; | |
235 | struct sas_discovery_event *ev = to_sas_discovery_event(work); | |
236 | struct asd_sas_port *port = ev->port; | |
237 | struct Scsi_Host *shost = port->ha->core.shost; | |
238 | struct sas_internal *si = to_sas_internal(shost->transportt); | |
239 | ||
240 | clear_bit(DISCE_SUSPEND, &port->disc.pending); | |
241 | ||
242 | sas_suspend_sata(port); | |
243 | ||
244 | /* lldd is free to forget the domain_device across the | |
245 | * suspension, we force the issue here to keep the reference | |
246 | * counts aligned | |
247 | */ | |
248 | list_for_each_entry(dev, &port->dev_list, dev_list_node) | |
249 | sas_notify_lldd_dev_gone(dev); | |
250 | ||
251 | /* we are suspending, so we know events are disabled and | |
252 | * phy_list is not being mutated | |
253 | */ | |
254 | list_for_each_entry(phy, &port->phy_list, port_phy_el) { | |
640208a1 | 255 | if (si->dft->lldd_port_deformed) |
303694ee DW |
256 | si->dft->lldd_port_deformed(phy); |
257 | phy->suspended = 1; | |
258 | port->suspended = 1; | |
259 | } | |
260 | } | |
261 | ||
262 | static void sas_resume_devices(struct work_struct *work) | |
263 | { | |
264 | struct sas_discovery_event *ev = to_sas_discovery_event(work); | |
265 | struct asd_sas_port *port = ev->port; | |
266 | ||
267 | clear_bit(DISCE_RESUME, &port->disc.pending); | |
268 | ||
269 | sas_resume_sata(port); | |
270 | } | |
271 | ||
2908d778 | 272 | /** |
121246ae BVA |
273 | * sas_discover_end_dev - discover an end device (SSP, etc) |
274 | * @dev: pointer to domain device of interest | |
2908d778 JB |
275 | * |
276 | * See comment in sas_discover_sata(). | |
277 | */ | |
278 | int sas_discover_end_dev(struct domain_device *dev) | |
279 | { | |
280 | int res; | |
281 | ||
282 | res = sas_notify_lldd_dev_found(dev); | |
283 | if (res) | |
92625f9b | 284 | return res; |
2908d778 | 285 | |
2908d778 | 286 | return 0; |
2908d778 JB |
287 | } |
288 | ||
289 | /* ---------- Device registration and unregistration ---------- */ | |
290 | ||
735f7d2f DW |
291 | void sas_free_device(struct kref *kref) |
292 | { | |
293 | struct domain_device *dev = container_of(kref, typeof(*dev), kref); | |
294 | ||
9487669f DW |
295 | put_device(&dev->rphy->dev); |
296 | dev->rphy = NULL; | |
297 | ||
735f7d2f DW |
298 | if (dev->parent) |
299 | sas_put_device(dev->parent); | |
300 | ||
f41a0c44 DW |
301 | sas_port_put_phy(dev->phy); |
302 | dev->phy = NULL; | |
303 | ||
735f7d2f | 304 | /* remove the phys and ports, everything else should be gone */ |
924a3541 | 305 | if (dev_is_expander(dev->dev_type)) |
735f7d2f DW |
306 | kfree(dev->ex_dev.ex_phy); |
307 | ||
8abda4d2 | 308 | if (dev_is_sata(dev) && dev->sata_dev.ap) { |
b6240a4d | 309 | ata_sas_tport_delete(dev->sata_dev.ap); |
8abda4d2 | 310 | ata_sas_port_destroy(dev->sata_dev.ap); |
2fa4a326 JY |
311 | ata_host_put(dev->sata_dev.ata_host); |
312 | dev->sata_dev.ata_host = NULL; | |
8abda4d2 DW |
313 | dev->sata_dev.ap = NULL; |
314 | } | |
315 | ||
735f7d2f DW |
316 | kfree(dev); |
317 | } | |
318 | ||
1a34c064 | 319 | static void sas_unregister_common_dev(struct asd_sas_port *port, struct domain_device *dev) |
2908d778 | 320 | { |
5db45bdc DW |
321 | struct sas_ha_struct *ha = port->ha; |
322 | ||
2908d778 JB |
323 | sas_notify_lldd_dev_gone(dev); |
324 | if (!dev->parent) | |
325 | dev->port->port_dev = NULL; | |
326 | else | |
327 | list_del_init(&dev->siblings); | |
1a34c064 DW |
328 | |
329 | spin_lock_irq(&port->dev_list_lock); | |
2908d778 | 330 | list_del_init(&dev->dev_list_node); |
e4a9c373 DW |
331 | if (dev_is_sata(dev)) |
332 | sas_ata_end_eh(dev->sata_dev.ap); | |
1a34c064 | 333 | spin_unlock_irq(&port->dev_list_lock); |
735f7d2f | 334 | |
5db45bdc | 335 | spin_lock_irq(&ha->lock); |
aa9f8328 | 336 | if (dev->dev_type == SAS_END_DEVICE && |
5db45bdc DW |
337 | !list_empty(&dev->ssp_dev.eh_list_node)) { |
338 | list_del_init(&dev->ssp_dev.eh_list_node); | |
339 | ha->eh_active--; | |
340 | } | |
341 | spin_unlock_irq(&ha->lock); | |
342 | ||
735f7d2f | 343 | sas_put_device(dev); |
2908d778 JB |
344 | } |
345 | ||
0558f33c | 346 | void sas_destruct_devices(struct asd_sas_port *port) |
2908d778 | 347 | { |
87c8331f | 348 | struct domain_device *dev, *n; |
87c8331f DW |
349 | |
350 | list_for_each_entry_safe(dev, n, &port->destroy_list, disco_list_node) { | |
351 | list_del_init(&dev->disco_list_node); | |
352 | ||
2908d778 JB |
353 | sas_remove_children(&dev->rphy->dev); |
354 | sas_rphy_delete(dev->rphy); | |
87c8331f | 355 | sas_unregister_common_dev(port, dev); |
87c8331f DW |
356 | } |
357 | } | |
358 | ||
0558f33c JY |
359 | static void sas_destruct_ports(struct asd_sas_port *port) |
360 | { | |
361 | struct sas_port *sas_port, *p; | |
362 | ||
363 | list_for_each_entry_safe(sas_port, p, &port->sas_port_del_list, del_list) { | |
364 | list_del_init(&sas_port->del_list); | |
365 | sas_port_delete(sas_port); | |
366 | } | |
367 | } | |
368 | ||
87c8331f DW |
369 | void sas_unregister_dev(struct asd_sas_port *port, struct domain_device *dev) |
370 | { | |
371 | if (!test_bit(SAS_DEV_DESTROY, &dev->state) && | |
372 | !list_empty(&dev->disco_list_node)) { | |
373 | /* this rphy never saw sas_rphy_add */ | |
374 | list_del_init(&dev->disco_list_node); | |
375 | sas_rphy_free(dev->rphy); | |
87c8331f | 376 | sas_unregister_common_dev(port, dev); |
9487669f | 377 | return; |
87c8331f DW |
378 | } |
379 | ||
9487669f | 380 | if (!test_and_set_bit(SAS_DEV_DESTROY, &dev->state)) { |
87c8331f DW |
381 | sas_rphy_unlink(dev->rphy); |
382 | list_move_tail(&dev->disco_list_node, &port->destroy_list); | |
2908d778 | 383 | } |
2908d778 JB |
384 | } |
385 | ||
7d05919a | 386 | void sas_unregister_domain_devices(struct asd_sas_port *port, int gone) |
2908d778 JB |
387 | { |
388 | struct domain_device *dev, *n; | |
389 | ||
7d05919a DW |
390 | list_for_each_entry_safe_reverse(dev, n, &port->dev_list, dev_list_node) { |
391 | if (gone) | |
392 | set_bit(SAS_DEV_GONE, &dev->state); | |
1a34c064 | 393 | sas_unregister_dev(port, dev); |
7d05919a DW |
394 | } |
395 | ||
87c8331f DW |
396 | list_for_each_entry_safe(dev, n, &port->disco_list, disco_list_node) |
397 | sas_unregister_dev(port, dev); | |
2908d778 JB |
398 | |
399 | port->port->rphy = NULL; | |
400 | ||
401 | } | |
402 | ||
f41a0c44 DW |
403 | void sas_device_set_phy(struct domain_device *dev, struct sas_port *port) |
404 | { | |
405 | struct sas_ha_struct *ha; | |
406 | struct sas_phy *new_phy; | |
407 | ||
408 | if (!dev) | |
409 | return; | |
410 | ||
411 | ha = dev->port->ha; | |
412 | new_phy = sas_port_get_phy(port); | |
413 | ||
414 | /* pin and record last seen phy */ | |
415 | spin_lock_irq(&ha->phy_port_lock); | |
416 | if (new_phy) { | |
417 | sas_port_put_phy(dev->phy); | |
418 | dev->phy = new_phy; | |
419 | } | |
420 | spin_unlock_irq(&ha->phy_port_lock); | |
421 | } | |
422 | ||
2908d778 JB |
423 | /* ---------- Discovery and Revalidation ---------- */ |
424 | ||
425 | /** | |
121246ae BVA |
426 | * sas_discover_domain - discover the domain |
427 | * @work: work structure embedded in port domain device. | |
2908d778 JB |
428 | * |
429 | * NOTE: this process _must_ quit (return) as soon as any connection | |
430 | * errors are encountered. Connection recovery is done elsewhere. | |
431 | * Discover process only interrogates devices in order to discover the | |
432 | * domain. | |
433 | */ | |
c4028958 | 434 | static void sas_discover_domain(struct work_struct *work) |
2908d778 | 435 | { |
6f63caae | 436 | struct domain_device *dev; |
2908d778 | 437 | int error = 0; |
22b9153f | 438 | struct sas_discovery_event *ev = to_sas_discovery_event(work); |
c4028958 | 439 | struct asd_sas_port *port = ev->port; |
2908d778 | 440 | |
b15ebe0b | 441 | clear_bit(DISCE_DISCOVER_DOMAIN, &port->disc.pending); |
2908d778 JB |
442 | |
443 | if (port->port_dev) | |
6f63caae DW |
444 | return; |
445 | ||
446 | error = sas_get_port_device(port); | |
447 | if (error) | |
448 | return; | |
449 | dev = port->port_dev; | |
2908d778 | 450 | |
15ba7806 JG |
451 | pr_debug("DOING DISCOVERY on port %d, pid:%d\n", port->id, |
452 | task_pid_nr(current)); | |
2908d778 | 453 | |
6f63caae | 454 | switch (dev->dev_type) { |
aa9f8328 | 455 | case SAS_END_DEVICE: |
6f63caae | 456 | error = sas_discover_end_dev(dev); |
2908d778 | 457 | break; |
aa9f8328 JB |
458 | case SAS_EDGE_EXPANDER_DEVICE: |
459 | case SAS_FANOUT_EXPANDER_DEVICE: | |
6f63caae | 460 | error = sas_discover_root_expander(dev); |
2908d778 | 461 | break; |
aa9f8328 JB |
462 | case SAS_SATA_DEV: |
463 | case SAS_SATA_PM: | |
15c73d5a | 464 | #ifdef CONFIG_SCSI_SAS_ATA |
6f63caae | 465 | error = sas_discover_sata(dev); |
2908d778 | 466 | break; |
15c73d5a | 467 | #else |
15ba7806 | 468 | pr_notice("ATA device seen but CONFIG_SCSI_SAS_ATA=N so cannot attach\n"); |
15c73d5a | 469 | /* Fall through */ |
b9142174 | 470 | #endif |
da1fb290 | 471 | /* Fall through - only for the #else condition above. */ |
2908d778 | 472 | default: |
b9142174 | 473 | error = -ENXIO; |
15ba7806 | 474 | pr_err("unhandled device %d\n", dev->dev_type); |
2908d778 JB |
475 | break; |
476 | } | |
477 | ||
478 | if (error) { | |
6f63caae | 479 | sas_rphy_free(dev->rphy); |
87c8331f | 480 | list_del_init(&dev->disco_list_node); |
9d720d82 | 481 | spin_lock_irq(&port->dev_list_lock); |
6f63caae | 482 | list_del_init(&dev->dev_list_node); |
9d720d82 | 483 | spin_unlock_irq(&port->dev_list_lock); |
88808398 | 484 | |
735f7d2f | 485 | sas_put_device(dev); |
2908d778 JB |
486 | port->port_dev = NULL; |
487 | } | |
488 | ||
0558f33c JY |
489 | sas_probe_devices(port); |
490 | ||
15ba7806 JG |
491 | pr_debug("DONE DISCOVERY on port %d, pid:%d, result:%d\n", port->id, |
492 | task_pid_nr(current), error); | |
2908d778 JB |
493 | } |
494 | ||
c4028958 | 495 | static void sas_revalidate_domain(struct work_struct *work) |
2908d778 JB |
496 | { |
497 | int res = 0; | |
22b9153f | 498 | struct sas_discovery_event *ev = to_sas_discovery_event(work); |
c4028958 | 499 | struct asd_sas_port *port = ev->port; |
87c8331f | 500 | struct sas_ha_struct *ha = port->ha; |
6302ce4d | 501 | struct domain_device *ddev = port->port_dev; |
87c8331f DW |
502 | |
503 | /* prevent revalidation from finding sata links in recovery */ | |
504 | mutex_lock(&ha->disco_mutex); | |
505 | if (test_bit(SAS_HA_ATA_EH_ACTIVE, &ha->state)) { | |
15ba7806 JG |
506 | pr_debug("REVALIDATION DEFERRED on port %d, pid:%d\n", |
507 | port->id, task_pid_nr(current)); | |
87c8331f DW |
508 | goto out; |
509 | } | |
2908d778 | 510 | |
b15ebe0b | 511 | clear_bit(DISCE_REVALIDATE_DOMAIN, &port->disc.pending); |
2908d778 | 512 | |
15ba7806 JG |
513 | pr_debug("REVALIDATING DOMAIN on port %d, pid:%d\n", port->id, |
514 | task_pid_nr(current)); | |
87c8331f | 515 | |
924a3541 | 516 | if (ddev && dev_is_expander(ddev->dev_type)) |
6302ce4d | 517 | res = sas_ex_revalidate_domain(ddev); |
2908d778 | 518 | |
15ba7806 JG |
519 | pr_debug("done REVALIDATING DOMAIN on port %d, pid:%d, res 0x%x\n", |
520 | port->id, task_pid_nr(current), res); | |
87c8331f DW |
521 | out: |
522 | mutex_unlock(&ha->disco_mutex); | |
0558f33c JY |
523 | |
524 | sas_destruct_devices(port); | |
525 | sas_destruct_ports(port); | |
526 | sas_probe_devices(port); | |
2908d778 JB |
527 | } |
528 | ||
529 | /* ---------- Events ---------- */ | |
530 | ||
22b9153f | 531 | static void sas_chain_work(struct sas_ha_struct *ha, struct sas_work *sw) |
b1124cd3 | 532 | { |
22b9153f DW |
533 | /* chained work is not subject to SA_HA_DRAINING or |
534 | * SAS_HA_REGISTERED, because it is either submitted in the | |
535 | * workqueue, or known to be submitted from a context that is | |
536 | * not racing against draining | |
537 | */ | |
93bdbd06 | 538 | queue_work(ha->disco_q, &sw->work); |
b1124cd3 DW |
539 | } |
540 | ||
541 | static void sas_chain_event(int event, unsigned long *pending, | |
22b9153f | 542 | struct sas_work *sw, |
b1124cd3 DW |
543 | struct sas_ha_struct *ha) |
544 | { | |
545 | if (!test_and_set_bit(event, pending)) { | |
546 | unsigned long flags; | |
547 | ||
e4a9c373 | 548 | spin_lock_irqsave(&ha->lock, flags); |
22b9153f | 549 | sas_chain_work(ha, sw); |
e4a9c373 | 550 | spin_unlock_irqrestore(&ha->lock, flags); |
b1124cd3 DW |
551 | } |
552 | } | |
553 | ||
2908d778 JB |
554 | int sas_discover_event(struct asd_sas_port *port, enum discover_event ev) |
555 | { | |
556 | struct sas_discovery *disc; | |
557 | ||
558 | if (!port) | |
559 | return 0; | |
560 | disc = &port->disc; | |
561 | ||
562 | BUG_ON(ev >= DISC_NUM_EVENTS); | |
563 | ||
b1124cd3 | 564 | sas_chain_event(ev, &disc->pending, &disc->disc_work[ev].work, port->ha); |
2908d778 JB |
565 | |
566 | return 0; | |
567 | } | |
568 | ||
569 | /** | |
121246ae BVA |
570 | * sas_init_disc - initialize the discovery struct in the port |
571 | * @disc: port discovery structure | |
2908d778 JB |
572 | * @port: pointer to struct port |
573 | * | |
574 | * Called when the ports are being initialized. | |
575 | */ | |
576 | void sas_init_disc(struct sas_discovery *disc, struct asd_sas_port *port) | |
577 | { | |
578 | int i; | |
579 | ||
c4028958 | 580 | static const work_func_t sas_event_fns[DISC_NUM_EVENTS] = { |
2908d778 JB |
581 | [DISCE_DISCOVER_DOMAIN] = sas_discover_domain, |
582 | [DISCE_REVALIDATE_DOMAIN] = sas_revalidate_domain, | |
303694ee DW |
583 | [DISCE_SUSPEND] = sas_suspend_devices, |
584 | [DISCE_RESUME] = sas_resume_devices, | |
2908d778 JB |
585 | }; |
586 | ||
2908d778 | 587 | disc->pending = 0; |
c4028958 | 588 | for (i = 0; i < DISC_NUM_EVENTS; i++) { |
22b9153f | 589 | INIT_SAS_WORK(&disc->disc_work[i].work, sas_event_fns[i]); |
c4028958 DH |
590 | disc->disc_work[i].port = port; |
591 | } | |
2908d778 | 592 | } |