.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * libata-scsi.c - helper library for ATA |
---|
3 | 4 | * |
---|
4 | | - * Maintained by: Tejun Heo <tj@kernel.org> |
---|
5 | | - * Please ALWAYS copy linux-ide@vger.kernel.org |
---|
6 | | - * on emails. |
---|
7 | | - * |
---|
8 | 5 | * Copyright 2003-2004 Red Hat, Inc. All rights reserved. |
---|
9 | 6 | * Copyright 2003-2004 Jeff Garzik |
---|
10 | | - * |
---|
11 | | - * |
---|
12 | | - * This program is free software; you can redistribute it and/or modify |
---|
13 | | - * it under the terms of the GNU General Public License as published by |
---|
14 | | - * the Free Software Foundation; either version 2, or (at your option) |
---|
15 | | - * any later version. |
---|
16 | | - * |
---|
17 | | - * This program is distributed in the hope that it will be useful, |
---|
18 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
19 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
20 | | - * GNU General Public License for more details. |
---|
21 | | - * |
---|
22 | | - * You should have received a copy of the GNU General Public License |
---|
23 | | - * along with this program; see the file COPYING. If not, write to |
---|
24 | | - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
25 | | - * |
---|
26 | 7 | * |
---|
27 | 8 | * libata documentation is available via 'make {ps|pdf}docs', |
---|
28 | 9 | * as Documentation/driver-api/libata.rst |
---|
.. | .. |
---|
30 | 11 | * Hardware documentation available from |
---|
31 | 12 | * - http://www.t10.org/ |
---|
32 | 13 | * - http://www.t13.org/ |
---|
33 | | - * |
---|
34 | 14 | */ |
---|
35 | 15 | |
---|
| 16 | +#include <linux/compat.h> |
---|
36 | 17 | #include <linux/slab.h> |
---|
37 | 18 | #include <linux/kernel.h> |
---|
38 | 19 | #include <linux/blkdev.h> |
---|
.. | .. |
---|
51 | 32 | #include <linux/suspend.h> |
---|
52 | 33 | #include <asm/unaligned.h> |
---|
53 | 34 | #include <linux/ioprio.h> |
---|
| 35 | +#include <linux/of.h> |
---|
54 | 36 | |
---|
55 | 37 | #include "libata.h" |
---|
56 | 38 | #include "libata-transport.h" |
---|
57 | 39 | |
---|
58 | | -#define ATA_SCSI_RBUF_SIZE 4096 |
---|
| 40 | +#define ATA_SCSI_RBUF_SIZE 576 |
---|
59 | 41 | |
---|
60 | 42 | static DEFINE_SPINLOCK(ata_scsi_rbuf_lock); |
---|
61 | 43 | static u8 ata_scsi_rbuf[ATA_SCSI_RBUF_SIZE]; |
---|
.. | .. |
---|
64 | 46 | |
---|
65 | 47 | static struct ata_device *__ata_scsi_find_dev(struct ata_port *ap, |
---|
66 | 48 | const struct scsi_device *scsidev); |
---|
67 | | -static struct ata_device *ata_scsi_find_dev(struct ata_port *ap, |
---|
68 | | - const struct scsi_device *scsidev); |
---|
69 | 49 | |
---|
70 | 50 | #define RW_RECOVERY_MPAGE 0x1 |
---|
71 | 51 | #define RW_RECOVERY_MPAGE_LEN 12 |
---|
.. | .. |
---|
105 | 85 | 0, 30 /* extended self test time, see 05-359r1 */ |
---|
106 | 86 | }; |
---|
107 | 87 | |
---|
108 | | -static const char *ata_lpm_policy_names[] = { |
---|
109 | | - [ATA_LPM_UNKNOWN] = "max_performance", |
---|
110 | | - [ATA_LPM_MAX_POWER] = "max_performance", |
---|
111 | | - [ATA_LPM_MED_POWER] = "medium_power", |
---|
112 | | - [ATA_LPM_MED_POWER_WITH_DIPM] = "med_power_with_dipm", |
---|
113 | | - [ATA_LPM_MIN_POWER_WITH_PARTIAL] = "min_power_with_partial", |
---|
114 | | - [ATA_LPM_MIN_POWER] = "min_power", |
---|
115 | | -}; |
---|
116 | | - |
---|
117 | | -static ssize_t ata_scsi_lpm_store(struct device *device, |
---|
118 | | - struct device_attribute *attr, |
---|
119 | | - const char *buf, size_t count) |
---|
120 | | -{ |
---|
121 | | - struct Scsi_Host *shost = class_to_shost(device); |
---|
122 | | - struct ata_port *ap = ata_shost_to_port(shost); |
---|
123 | | - struct ata_link *link; |
---|
124 | | - struct ata_device *dev; |
---|
125 | | - enum ata_lpm_policy policy; |
---|
126 | | - unsigned long flags; |
---|
127 | | - |
---|
128 | | - /* UNKNOWN is internal state, iterate from MAX_POWER */ |
---|
129 | | - for (policy = ATA_LPM_MAX_POWER; |
---|
130 | | - policy < ARRAY_SIZE(ata_lpm_policy_names); policy++) { |
---|
131 | | - const char *name = ata_lpm_policy_names[policy]; |
---|
132 | | - |
---|
133 | | - if (strncmp(name, buf, strlen(name)) == 0) |
---|
134 | | - break; |
---|
135 | | - } |
---|
136 | | - if (policy == ARRAY_SIZE(ata_lpm_policy_names)) |
---|
137 | | - return -EINVAL; |
---|
138 | | - |
---|
139 | | - spin_lock_irqsave(ap->lock, flags); |
---|
140 | | - |
---|
141 | | - ata_for_each_link(link, ap, EDGE) { |
---|
142 | | - ata_for_each_dev(dev, &ap->link, ENABLED) { |
---|
143 | | - if (dev->horkage & ATA_HORKAGE_NOLPM) { |
---|
144 | | - count = -EOPNOTSUPP; |
---|
145 | | - goto out_unlock; |
---|
146 | | - } |
---|
147 | | - } |
---|
148 | | - } |
---|
149 | | - |
---|
150 | | - ap->target_lpm_policy = policy; |
---|
151 | | - ata_port_schedule_eh(ap); |
---|
152 | | -out_unlock: |
---|
153 | | - spin_unlock_irqrestore(ap->lock, flags); |
---|
154 | | - return count; |
---|
155 | | -} |
---|
156 | | - |
---|
157 | | -static ssize_t ata_scsi_lpm_show(struct device *dev, |
---|
158 | | - struct device_attribute *attr, char *buf) |
---|
159 | | -{ |
---|
160 | | - struct Scsi_Host *shost = class_to_shost(dev); |
---|
161 | | - struct ata_port *ap = ata_shost_to_port(shost); |
---|
162 | | - |
---|
163 | | - if (ap->target_lpm_policy >= ARRAY_SIZE(ata_lpm_policy_names)) |
---|
164 | | - return -EINVAL; |
---|
165 | | - |
---|
166 | | - return snprintf(buf, PAGE_SIZE, "%s\n", |
---|
167 | | - ata_lpm_policy_names[ap->target_lpm_policy]); |
---|
168 | | -} |
---|
169 | | -DEVICE_ATTR(link_power_management_policy, S_IRUGO | S_IWUSR, |
---|
170 | | - ata_scsi_lpm_show, ata_scsi_lpm_store); |
---|
171 | | -EXPORT_SYMBOL_GPL(dev_attr_link_power_management_policy); |
---|
172 | | - |
---|
173 | 88 | static ssize_t ata_scsi_park_show(struct device *device, |
---|
174 | 89 | struct device_attribute *attr, char *buf) |
---|
175 | 90 | { |
---|
.. | .. |
---|
178 | 93 | struct ata_link *link; |
---|
179 | 94 | struct ata_device *dev; |
---|
180 | 95 | unsigned long now; |
---|
181 | | - unsigned int uninitialized_var(msecs); |
---|
| 96 | + unsigned int msecs; |
---|
182 | 97 | int rc = 0; |
---|
183 | 98 | |
---|
184 | 99 | ap = ata_shost_to_port(sdev->host); |
---|
.. | .. |
---|
273 | 188 | ata_scsi_park_show, ata_scsi_park_store); |
---|
274 | 189 | EXPORT_SYMBOL_GPL(dev_attr_unload_heads); |
---|
275 | 190 | |
---|
276 | | -static ssize_t ata_ncq_prio_enable_show(struct device *device, |
---|
277 | | - struct device_attribute *attr, |
---|
278 | | - char *buf) |
---|
279 | | -{ |
---|
280 | | - struct scsi_device *sdev = to_scsi_device(device); |
---|
281 | | - struct ata_port *ap; |
---|
282 | | - struct ata_device *dev; |
---|
283 | | - bool ncq_prio_enable; |
---|
284 | | - int rc = 0; |
---|
285 | | - |
---|
286 | | - ap = ata_shost_to_port(sdev->host); |
---|
287 | | - |
---|
288 | | - spin_lock_irq(ap->lock); |
---|
289 | | - dev = ata_scsi_find_dev(ap, sdev); |
---|
290 | | - if (!dev) { |
---|
291 | | - rc = -ENODEV; |
---|
292 | | - goto unlock; |
---|
293 | | - } |
---|
294 | | - |
---|
295 | | - ncq_prio_enable = dev->flags & ATA_DFLAG_NCQ_PRIO_ENABLE; |
---|
296 | | - |
---|
297 | | -unlock: |
---|
298 | | - spin_unlock_irq(ap->lock); |
---|
299 | | - |
---|
300 | | - return rc ? rc : snprintf(buf, 20, "%u\n", ncq_prio_enable); |
---|
301 | | -} |
---|
302 | | - |
---|
303 | | -static ssize_t ata_ncq_prio_enable_store(struct device *device, |
---|
304 | | - struct device_attribute *attr, |
---|
305 | | - const char *buf, size_t len) |
---|
306 | | -{ |
---|
307 | | - struct scsi_device *sdev = to_scsi_device(device); |
---|
308 | | - struct ata_port *ap; |
---|
309 | | - struct ata_device *dev; |
---|
310 | | - long int input; |
---|
311 | | - int rc; |
---|
312 | | - |
---|
313 | | - rc = kstrtol(buf, 10, &input); |
---|
314 | | - if (rc) |
---|
315 | | - return rc; |
---|
316 | | - if ((input < 0) || (input > 1)) |
---|
317 | | - return -EINVAL; |
---|
318 | | - |
---|
319 | | - ap = ata_shost_to_port(sdev->host); |
---|
320 | | - dev = ata_scsi_find_dev(ap, sdev); |
---|
321 | | - if (unlikely(!dev)) |
---|
322 | | - return -ENODEV; |
---|
323 | | - |
---|
324 | | - spin_lock_irq(ap->lock); |
---|
325 | | - if (input) |
---|
326 | | - dev->flags |= ATA_DFLAG_NCQ_PRIO_ENABLE; |
---|
327 | | - else |
---|
328 | | - dev->flags &= ~ATA_DFLAG_NCQ_PRIO_ENABLE; |
---|
329 | | - |
---|
330 | | - dev->link->eh_info.action |= ATA_EH_REVALIDATE; |
---|
331 | | - dev->link->eh_info.flags |= ATA_EHI_QUIET; |
---|
332 | | - ata_port_schedule_eh(ap); |
---|
333 | | - spin_unlock_irq(ap->lock); |
---|
334 | | - |
---|
335 | | - ata_port_wait_eh(ap); |
---|
336 | | - |
---|
337 | | - if (input) { |
---|
338 | | - spin_lock_irq(ap->lock); |
---|
339 | | - if (!(dev->flags & ATA_DFLAG_NCQ_PRIO)) { |
---|
340 | | - dev->flags &= ~ATA_DFLAG_NCQ_PRIO_ENABLE; |
---|
341 | | - rc = -EIO; |
---|
342 | | - } |
---|
343 | | - spin_unlock_irq(ap->lock); |
---|
344 | | - } |
---|
345 | | - |
---|
346 | | - return rc ? rc : len; |
---|
347 | | -} |
---|
348 | | - |
---|
349 | | -DEVICE_ATTR(ncq_prio_enable, S_IRUGO | S_IWUSR, |
---|
350 | | - ata_ncq_prio_enable_show, ata_ncq_prio_enable_store); |
---|
351 | | -EXPORT_SYMBOL_GPL(dev_attr_ncq_prio_enable); |
---|
352 | | - |
---|
353 | 191 | void ata_scsi_set_sense(struct ata_device *dev, struct scsi_cmnd *cmd, |
---|
354 | 192 | u8 sk, u8 asc, u8 ascq) |
---|
355 | 193 | { |
---|
.. | .. |
---|
398 | 236 | field, 0xff, 0); |
---|
399 | 237 | } |
---|
400 | 238 | |
---|
401 | | -static ssize_t |
---|
402 | | -ata_scsi_em_message_store(struct device *dev, struct device_attribute *attr, |
---|
403 | | - const char *buf, size_t count) |
---|
404 | | -{ |
---|
405 | | - struct Scsi_Host *shost = class_to_shost(dev); |
---|
406 | | - struct ata_port *ap = ata_shost_to_port(shost); |
---|
407 | | - if (ap->ops->em_store && (ap->flags & ATA_FLAG_EM)) |
---|
408 | | - return ap->ops->em_store(ap, buf, count); |
---|
409 | | - return -EINVAL; |
---|
410 | | -} |
---|
411 | | - |
---|
412 | | -static ssize_t |
---|
413 | | -ata_scsi_em_message_show(struct device *dev, struct device_attribute *attr, |
---|
414 | | - char *buf) |
---|
415 | | -{ |
---|
416 | | - struct Scsi_Host *shost = class_to_shost(dev); |
---|
417 | | - struct ata_port *ap = ata_shost_to_port(shost); |
---|
418 | | - |
---|
419 | | - if (ap->ops->em_show && (ap->flags & ATA_FLAG_EM)) |
---|
420 | | - return ap->ops->em_show(ap, buf); |
---|
421 | | - return -EINVAL; |
---|
422 | | -} |
---|
423 | | -DEVICE_ATTR(em_message, S_IRUGO | S_IWUSR, |
---|
424 | | - ata_scsi_em_message_show, ata_scsi_em_message_store); |
---|
425 | | -EXPORT_SYMBOL_GPL(dev_attr_em_message); |
---|
426 | | - |
---|
427 | | -static ssize_t |
---|
428 | | -ata_scsi_em_message_type_show(struct device *dev, struct device_attribute *attr, |
---|
429 | | - char *buf) |
---|
430 | | -{ |
---|
431 | | - struct Scsi_Host *shost = class_to_shost(dev); |
---|
432 | | - struct ata_port *ap = ata_shost_to_port(shost); |
---|
433 | | - |
---|
434 | | - return snprintf(buf, 23, "%d\n", ap->em_message_type); |
---|
435 | | -} |
---|
436 | | -DEVICE_ATTR(em_message_type, S_IRUGO, |
---|
437 | | - ata_scsi_em_message_type_show, NULL); |
---|
438 | | -EXPORT_SYMBOL_GPL(dev_attr_em_message_type); |
---|
439 | | - |
---|
440 | | -static ssize_t |
---|
441 | | -ata_scsi_activity_show(struct device *dev, struct device_attribute *attr, |
---|
442 | | - char *buf) |
---|
443 | | -{ |
---|
444 | | - struct scsi_device *sdev = to_scsi_device(dev); |
---|
445 | | - struct ata_port *ap = ata_shost_to_port(sdev->host); |
---|
446 | | - struct ata_device *atadev = ata_scsi_find_dev(ap, sdev); |
---|
447 | | - |
---|
448 | | - if (atadev && ap->ops->sw_activity_show && |
---|
449 | | - (ap->flags & ATA_FLAG_SW_ACTIVITY)) |
---|
450 | | - return ap->ops->sw_activity_show(atadev, buf); |
---|
451 | | - return -EINVAL; |
---|
452 | | -} |
---|
453 | | - |
---|
454 | | -static ssize_t |
---|
455 | | -ata_scsi_activity_store(struct device *dev, struct device_attribute *attr, |
---|
456 | | - const char *buf, size_t count) |
---|
457 | | -{ |
---|
458 | | - struct scsi_device *sdev = to_scsi_device(dev); |
---|
459 | | - struct ata_port *ap = ata_shost_to_port(sdev->host); |
---|
460 | | - struct ata_device *atadev = ata_scsi_find_dev(ap, sdev); |
---|
461 | | - enum sw_activity val; |
---|
462 | | - int rc; |
---|
463 | | - |
---|
464 | | - if (atadev && ap->ops->sw_activity_store && |
---|
465 | | - (ap->flags & ATA_FLAG_SW_ACTIVITY)) { |
---|
466 | | - val = simple_strtoul(buf, NULL, 0); |
---|
467 | | - switch (val) { |
---|
468 | | - case OFF: case BLINK_ON: case BLINK_OFF: |
---|
469 | | - rc = ap->ops->sw_activity_store(atadev, val); |
---|
470 | | - if (!rc) |
---|
471 | | - return count; |
---|
472 | | - else |
---|
473 | | - return rc; |
---|
474 | | - } |
---|
475 | | - } |
---|
476 | | - return -EINVAL; |
---|
477 | | -} |
---|
478 | | -DEVICE_ATTR(sw_activity, S_IWUSR | S_IRUGO, ata_scsi_activity_show, |
---|
479 | | - ata_scsi_activity_store); |
---|
480 | | -EXPORT_SYMBOL_GPL(dev_attr_sw_activity); |
---|
481 | | - |
---|
482 | 239 | struct device_attribute *ata_common_sdev_attrs[] = { |
---|
483 | 240 | &dev_attr_unload_heads, |
---|
484 | | - &dev_attr_ncq_prio_enable, |
---|
485 | 241 | NULL |
---|
486 | 242 | }; |
---|
487 | 243 | EXPORT_SYMBOL_GPL(ata_common_sdev_attrs); |
---|
.. | .. |
---|
514 | 270 | |
---|
515 | 271 | return 0; |
---|
516 | 272 | } |
---|
| 273 | +EXPORT_SYMBOL_GPL(ata_std_bios_param); |
---|
517 | 274 | |
---|
518 | 275 | /** |
---|
519 | 276 | * ata_scsi_unlock_native_capacity - unlock native capacity |
---|
.. | .. |
---|
543 | 300 | spin_unlock_irqrestore(ap->lock, flags); |
---|
544 | 301 | ata_port_wait_eh(ap); |
---|
545 | 302 | } |
---|
| 303 | +EXPORT_SYMBOL_GPL(ata_scsi_unlock_native_capacity); |
---|
546 | 304 | |
---|
547 | 305 | /** |
---|
548 | 306 | * ata_get_identity - Handler for HDIO_GET_IDENTITY ioctl |
---|
.. | .. |
---|
639 | 397 | if (args[0] == ATA_CMD_SMART) { /* hack -- ide driver does this too */ |
---|
640 | 398 | scsi_cmd[6] = args[3]; |
---|
641 | 399 | scsi_cmd[8] = args[1]; |
---|
642 | | - scsi_cmd[10] = 0x4f; |
---|
643 | | - scsi_cmd[12] = 0xc2; |
---|
| 400 | + scsi_cmd[10] = ATA_SMART_LBAM_PASS; |
---|
| 401 | + scsi_cmd[12] = ATA_SMART_LBAH_PASS; |
---|
644 | 402 | } else { |
---|
645 | 403 | scsi_cmd[6] = args[1]; |
---|
646 | 404 | } |
---|
.. | .. |
---|
777 | 535 | return 0; |
---|
778 | 536 | } |
---|
779 | 537 | |
---|
| 538 | +/* |
---|
| 539 | + * This handles both native and compat commands, so anything added |
---|
| 540 | + * here must have a compatible argument, or check in_compat_syscall() |
---|
| 541 | + */ |
---|
780 | 542 | int ata_sas_scsi_ioctl(struct ata_port *ap, struct scsi_device *scsidev, |
---|
781 | | - int cmd, void __user *arg) |
---|
| 543 | + unsigned int cmd, void __user *arg) |
---|
782 | 544 | { |
---|
783 | 545 | unsigned long val; |
---|
784 | 546 | int rc = -EINVAL; |
---|
.. | .. |
---|
789 | 551 | spin_lock_irqsave(ap->lock, flags); |
---|
790 | 552 | val = ata_ioc32(ap); |
---|
791 | 553 | spin_unlock_irqrestore(ap->lock, flags); |
---|
| 554 | +#ifdef CONFIG_COMPAT |
---|
| 555 | + if (in_compat_syscall()) |
---|
| 556 | + return put_user(val, (compat_ulong_t __user *)arg); |
---|
| 557 | +#endif |
---|
792 | 558 | return put_user(val, (unsigned long __user *)arg); |
---|
793 | 559 | |
---|
794 | 560 | case HDIO_SET_32BIT: |
---|
.. | .. |
---|
829 | 595 | } |
---|
830 | 596 | EXPORT_SYMBOL_GPL(ata_sas_scsi_ioctl); |
---|
831 | 597 | |
---|
832 | | -int ata_scsi_ioctl(struct scsi_device *scsidev, int cmd, void __user *arg) |
---|
| 598 | +int ata_scsi_ioctl(struct scsi_device *scsidev, unsigned int cmd, |
---|
| 599 | + void __user *arg) |
---|
833 | 600 | { |
---|
834 | 601 | return ata_sas_scsi_ioctl(ata_shost_to_port(scsidev->host), |
---|
835 | 602 | scsidev, cmd, arg); |
---|
.. | .. |
---|
882 | 649 | { |
---|
883 | 650 | struct scsi_cmnd *scmd = qc->scsicmd; |
---|
884 | 651 | |
---|
885 | | - qc->extrabytes = scmd->request->extra_len; |
---|
| 652 | + qc->extrabytes = scmd->extra_len; |
---|
886 | 653 | qc->nbytes = scsi_bufflen(scmd) + qc->extrabytes; |
---|
887 | 654 | } |
---|
888 | 655 | |
---|
.. | .. |
---|
1221 | 988 | scsi_set_sense_information(sb, SCSI_SENSE_BUFFERSIZE, block); |
---|
1222 | 989 | } |
---|
1223 | 990 | |
---|
1224 | | -static void ata_scsi_sdev_config(struct scsi_device *sdev) |
---|
| 991 | +void ata_scsi_sdev_config(struct scsi_device *sdev) |
---|
1225 | 992 | { |
---|
1226 | 993 | sdev->use_10_for_rw = 1; |
---|
1227 | 994 | sdev->use_10_for_ms = 1; |
---|
.. | .. |
---|
1236 | 1003 | } |
---|
1237 | 1004 | |
---|
1238 | 1005 | /** |
---|
1239 | | - * atapi_drain_needed - Check whether data transfer may overflow |
---|
| 1006 | + * ata_scsi_dma_need_drain - Check whether data transfer may overflow |
---|
1240 | 1007 | * @rq: request to be checked |
---|
1241 | 1008 | * |
---|
1242 | 1009 | * ATAPI commands which transfer variable length data to host |
---|
.. | .. |
---|
1250 | 1017 | * RETURNS: |
---|
1251 | 1018 | * 1 if ; otherwise, 0. |
---|
1252 | 1019 | */ |
---|
1253 | | -static int atapi_drain_needed(struct request *rq) |
---|
| 1020 | +bool ata_scsi_dma_need_drain(struct request *rq) |
---|
1254 | 1021 | { |
---|
1255 | | - if (likely(!blk_rq_is_passthrough(rq))) |
---|
1256 | | - return 0; |
---|
1257 | | - |
---|
1258 | | - if (!blk_rq_bytes(rq) || op_is_write(req_op(rq))) |
---|
1259 | | - return 0; |
---|
1260 | | - |
---|
1261 | 1022 | return atapi_cmd_type(scsi_req(rq)->cmd[0]) == ATAPI_MISC; |
---|
1262 | 1023 | } |
---|
| 1024 | +EXPORT_SYMBOL_GPL(ata_scsi_dma_need_drain); |
---|
1263 | 1025 | |
---|
1264 | | -static int ata_scsi_dev_config(struct scsi_device *sdev, |
---|
1265 | | - struct ata_device *dev) |
---|
| 1026 | +int ata_scsi_dev_config(struct scsi_device *sdev, struct ata_device *dev) |
---|
1266 | 1027 | { |
---|
1267 | 1028 | struct request_queue *q = sdev->request_queue; |
---|
1268 | 1029 | |
---|
.. | .. |
---|
1273 | 1034 | blk_queue_max_hw_sectors(q, dev->max_sectors); |
---|
1274 | 1035 | |
---|
1275 | 1036 | if (dev->class == ATA_DEV_ATAPI) { |
---|
1276 | | - void *buf; |
---|
1277 | | - |
---|
1278 | 1037 | sdev->sector_size = ATA_SECT_SIZE; |
---|
1279 | 1038 | |
---|
1280 | 1039 | /* set DMA padding */ |
---|
1281 | 1040 | blk_queue_update_dma_pad(q, ATA_DMA_PAD_SZ - 1); |
---|
1282 | 1041 | |
---|
1283 | | - /* configure draining */ |
---|
1284 | | - buf = kmalloc(ATAPI_MAX_DRAIN, q->bounce_gfp | GFP_KERNEL); |
---|
1285 | | - if (!buf) { |
---|
| 1042 | + /* make room for appending the drain */ |
---|
| 1043 | + blk_queue_max_segments(q, queue_max_segments(q) - 1); |
---|
| 1044 | + |
---|
| 1045 | + sdev->dma_drain_len = ATAPI_MAX_DRAIN; |
---|
| 1046 | + sdev->dma_drain_buf = kmalloc(sdev->dma_drain_len, |
---|
| 1047 | + q->bounce_gfp | GFP_KERNEL); |
---|
| 1048 | + if (!sdev->dma_drain_buf) { |
---|
1286 | 1049 | ata_dev_err(dev, "drain buffer allocation failed\n"); |
---|
1287 | 1050 | return -ENOMEM; |
---|
1288 | 1051 | } |
---|
1289 | | - |
---|
1290 | | - blk_queue_dma_drain(q, atapi_drain_needed, buf, ATAPI_MAX_DRAIN); |
---|
1291 | 1052 | } else { |
---|
1292 | 1053 | sdev->sector_size = ata_id_logical_sector_size(dev->id); |
---|
1293 | 1054 | sdev->manage_start_stop = 1; |
---|
.. | .. |
---|
1317 | 1078 | depth = min(ATA_MAX_QUEUE, depth); |
---|
1318 | 1079 | scsi_change_queue_depth(sdev, depth); |
---|
1319 | 1080 | } |
---|
1320 | | - |
---|
1321 | | - blk_queue_flush_queueable(q, false); |
---|
1322 | 1081 | |
---|
1323 | 1082 | if (dev->flags & ATA_DFLAG_TRUSTED) |
---|
1324 | 1083 | sdev->security_supported = 1; |
---|
.. | .. |
---|
1352 | 1111 | |
---|
1353 | 1112 | return rc; |
---|
1354 | 1113 | } |
---|
| 1114 | +EXPORT_SYMBOL_GPL(ata_scsi_slave_config); |
---|
1355 | 1115 | |
---|
1356 | 1116 | /** |
---|
1357 | 1117 | * ata_scsi_slave_destroy - SCSI device is about to be destroyed |
---|
.. | .. |
---|
1370 | 1130 | void ata_scsi_slave_destroy(struct scsi_device *sdev) |
---|
1371 | 1131 | { |
---|
1372 | 1132 | struct ata_port *ap = ata_shost_to_port(sdev->host); |
---|
1373 | | - struct request_queue *q = sdev->request_queue; |
---|
1374 | 1133 | unsigned long flags; |
---|
1375 | 1134 | struct ata_device *dev; |
---|
1376 | 1135 | |
---|
.. | .. |
---|
1387 | 1146 | } |
---|
1388 | 1147 | spin_unlock_irqrestore(ap->lock, flags); |
---|
1389 | 1148 | |
---|
1390 | | - kfree(q->dma_drain_buffer); |
---|
1391 | | - q->dma_drain_buffer = NULL; |
---|
1392 | | - q->dma_drain_size = 0; |
---|
| 1149 | + kfree(sdev->dma_drain_buf); |
---|
1393 | 1150 | } |
---|
1394 | | - |
---|
1395 | | -/** |
---|
1396 | | - * __ata_change_queue_depth - helper for ata_scsi_change_queue_depth |
---|
1397 | | - * @ap: ATA port to which the device change the queue depth |
---|
1398 | | - * @sdev: SCSI device to configure queue depth for |
---|
1399 | | - * @queue_depth: new queue depth |
---|
1400 | | - * |
---|
1401 | | - * libsas and libata have different approaches for associating a sdev to |
---|
1402 | | - * its ata_port. |
---|
1403 | | - * |
---|
1404 | | - */ |
---|
1405 | | -int __ata_change_queue_depth(struct ata_port *ap, struct scsi_device *sdev, |
---|
1406 | | - int queue_depth) |
---|
1407 | | -{ |
---|
1408 | | - struct ata_device *dev; |
---|
1409 | | - unsigned long flags; |
---|
1410 | | - |
---|
1411 | | - if (queue_depth < 1 || queue_depth == sdev->queue_depth) |
---|
1412 | | - return sdev->queue_depth; |
---|
1413 | | - |
---|
1414 | | - dev = ata_scsi_find_dev(ap, sdev); |
---|
1415 | | - if (!dev || !ata_dev_enabled(dev)) |
---|
1416 | | - return sdev->queue_depth; |
---|
1417 | | - |
---|
1418 | | - /* NCQ enabled? */ |
---|
1419 | | - spin_lock_irqsave(ap->lock, flags); |
---|
1420 | | - dev->flags &= ~ATA_DFLAG_NCQ_OFF; |
---|
1421 | | - if (queue_depth == 1 || !ata_ncq_enabled(dev)) { |
---|
1422 | | - dev->flags |= ATA_DFLAG_NCQ_OFF; |
---|
1423 | | - queue_depth = 1; |
---|
1424 | | - } |
---|
1425 | | - spin_unlock_irqrestore(ap->lock, flags); |
---|
1426 | | - |
---|
1427 | | - /* limit and apply queue depth */ |
---|
1428 | | - queue_depth = min(queue_depth, sdev->host->can_queue); |
---|
1429 | | - queue_depth = min(queue_depth, ata_id_queue_depth(dev->id)); |
---|
1430 | | - queue_depth = min(queue_depth, ATA_MAX_QUEUE); |
---|
1431 | | - |
---|
1432 | | - if (sdev->queue_depth == queue_depth) |
---|
1433 | | - return -EINVAL; |
---|
1434 | | - |
---|
1435 | | - return scsi_change_queue_depth(sdev, queue_depth); |
---|
1436 | | -} |
---|
1437 | | - |
---|
1438 | | -/** |
---|
1439 | | - * ata_scsi_change_queue_depth - SCSI callback for queue depth config |
---|
1440 | | - * @sdev: SCSI device to configure queue depth for |
---|
1441 | | - * @queue_depth: new queue depth |
---|
1442 | | - * |
---|
1443 | | - * This is libata standard hostt->change_queue_depth callback. |
---|
1444 | | - * SCSI will call into this callback when user tries to set queue |
---|
1445 | | - * depth via sysfs. |
---|
1446 | | - * |
---|
1447 | | - * LOCKING: |
---|
1448 | | - * SCSI layer (we don't care) |
---|
1449 | | - * |
---|
1450 | | - * RETURNS: |
---|
1451 | | - * Newly configured queue depth. |
---|
1452 | | - */ |
---|
1453 | | -int ata_scsi_change_queue_depth(struct scsi_device *sdev, int queue_depth) |
---|
1454 | | -{ |
---|
1455 | | - struct ata_port *ap = ata_shost_to_port(sdev->host); |
---|
1456 | | - |
---|
1457 | | - return __ata_change_queue_depth(ap, sdev, queue_depth); |
---|
1458 | | -} |
---|
| 1151 | +EXPORT_SYMBOL_GPL(ata_scsi_slave_destroy); |
---|
1459 | 1152 | |
---|
1460 | 1153 | /** |
---|
1461 | 1154 | * ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command |
---|
.. | .. |
---|
2362 | 2055 | */ |
---|
2363 | 2056 | static unsigned int ata_scsiop_inq_89(struct ata_scsi_args *args, u8 *rbuf) |
---|
2364 | 2057 | { |
---|
2365 | | - struct ata_taskfile tf; |
---|
2366 | | - |
---|
2367 | | - memset(&tf, 0, sizeof(tf)); |
---|
2368 | | - |
---|
2369 | 2058 | rbuf[1] = 0x89; /* our page code */ |
---|
2370 | 2059 | rbuf[2] = (0x238 >> 8); /* page size fixed at 238h */ |
---|
2371 | 2060 | rbuf[3] = (0x238 & 0xff); |
---|
.. | .. |
---|
2374 | 2063 | memcpy(&rbuf[16], "libata ", 16); |
---|
2375 | 2064 | memcpy(&rbuf[32], DRV_VERSION, 4); |
---|
2376 | 2065 | |
---|
2377 | | - /* we don't store the ATA device signature, so we fake it */ |
---|
2378 | | - |
---|
2379 | | - tf.command = ATA_DRDY; /* really, this is Status reg */ |
---|
2380 | | - tf.lbal = 0x1; |
---|
2381 | | - tf.nsect = 0x1; |
---|
2382 | | - |
---|
2383 | | - ata_tf_to_fis(&tf, 0, 1, &rbuf[36]); /* TODO: PMP? */ |
---|
2384 | 2066 | rbuf[36] = 0x34; /* force D2H Reg FIS (34h) */ |
---|
| 2067 | + rbuf[37] = (1 << 7); /* bit 7 indicates Command FIS */ |
---|
| 2068 | + /* TODO: PMP? */ |
---|
| 2069 | + |
---|
| 2070 | + /* we don't store the ATA device signature, so we fake it */ |
---|
| 2071 | + rbuf[38] = ATA_DRDY; /* really, this is Status reg */ |
---|
| 2072 | + rbuf[40] = 0x1; |
---|
| 2073 | + rbuf[48] = 0x1; |
---|
2385 | 2074 | |
---|
2386 | 2075 | rbuf[56] = ATA_CMD_ID_ATA; |
---|
2387 | 2076 | |
---|
.. | .. |
---|
3017 | 2706 | * This inconsistency confuses several controllers which |
---|
3018 | 2707 | * perform PIO using DMA such as Intel AHCIs and sil3124/32. |
---|
3019 | 2708 | * These controllers use actual number of transferred bytes to |
---|
3020 | | - * update DMA poitner and transfer of 4n+2 bytes make those |
---|
| 2709 | + * update DMA pointer and transfer of 4n+2 bytes make those |
---|
3021 | 2710 | * controller push DMA pointer by 4n+4 bytes because SATA data |
---|
3022 | 2711 | * FISes are aligned to 4 bytes. This causes data corruption |
---|
3023 | 2712 | * and buffer overrun. |
---|
.. | .. |
---|
3053 | 2742 | return 0; |
---|
3054 | 2743 | } |
---|
3055 | 2744 | |
---|
3056 | | -static struct ata_device *ata_find_dev(struct ata_port *ap, int devno) |
---|
| 2745 | +static struct ata_device *ata_find_dev(struct ata_port *ap, unsigned int devno) |
---|
3057 | 2746 | { |
---|
3058 | | - if (!sata_pmp_attached(ap)) { |
---|
3059 | | - if (likely(devno >= 0 && |
---|
3060 | | - devno < ata_link_max_devices(&ap->link))) |
---|
| 2747 | + /* |
---|
| 2748 | + * For the non-PMP case, ata_link_max_devices() returns 1 (SATA case), |
---|
| 2749 | + * or 2 (IDE master + slave case). However, the former case includes |
---|
| 2750 | + * libsas hosted devices which are numbered per scsi host, leading |
---|
| 2751 | + * to devno potentially being larger than 0 but with each struct |
---|
| 2752 | + * ata_device having its own struct ata_port and struct ata_link. |
---|
| 2753 | + * To accommodate these, ignore devno and always use device number 0. |
---|
| 2754 | + */ |
---|
| 2755 | + if (likely(!sata_pmp_attached(ap))) { |
---|
| 2756 | + int link_max_devices = ata_link_max_devices(&ap->link); |
---|
| 2757 | + |
---|
| 2758 | + if (link_max_devices == 1) |
---|
| 2759 | + return &ap->link.device[0]; |
---|
| 2760 | + |
---|
| 2761 | + if (devno < link_max_devices) |
---|
3061 | 2762 | return &ap->link.device[devno]; |
---|
3062 | | - } else { |
---|
3063 | | - if (likely(devno >= 0 && |
---|
3064 | | - devno < ap->nr_pmp_links)) |
---|
3065 | | - return &ap->pmp_link[devno].device[0]; |
---|
| 2763 | + |
---|
| 2764 | + return NULL; |
---|
3066 | 2765 | } |
---|
| 2766 | + |
---|
| 2767 | + /* |
---|
| 2768 | + * For PMP-attached devices, the device number corresponds to C |
---|
| 2769 | + * (channel) of SCSI [H:C:I:L], indicating the port pmp link |
---|
| 2770 | + * for the device. |
---|
| 2771 | + */ |
---|
| 2772 | + if (devno < ap->nr_pmp_links) |
---|
| 2773 | + return &ap->pmp_link[devno].device[0]; |
---|
3067 | 2774 | |
---|
3068 | 2775 | return NULL; |
---|
3069 | 2776 | } |
---|
.. | .. |
---|
3103 | 2810 | * RETURNS: |
---|
3104 | 2811 | * Associated ATA device, or %NULL if not found. |
---|
3105 | 2812 | */ |
---|
3106 | | -static struct ata_device * |
---|
| 2813 | +struct ata_device * |
---|
3107 | 2814 | ata_scsi_find_dev(struct ata_port *ap, const struct scsi_device *scsidev) |
---|
3108 | 2815 | { |
---|
3109 | 2816 | struct ata_device *dev = __ata_scsi_find_dev(ap, scsidev); |
---|
.. | .. |
---|
3614 | 3321 | case REPORT_LUNS: |
---|
3615 | 3322 | case REQUEST_SENSE: |
---|
3616 | 3323 | case SYNCHRONIZE_CACHE: |
---|
| 3324 | + case SYNCHRONIZE_CACHE_16: |
---|
3617 | 3325 | case REZERO_UNIT: |
---|
3618 | 3326 | case SEEK_6: |
---|
3619 | 3327 | case SEEK_10: |
---|
.. | .. |
---|
4280 | 3988 | return ata_scsi_write_same_xlat; |
---|
4281 | 3989 | |
---|
4282 | 3990 | case SYNCHRONIZE_CACHE: |
---|
| 3991 | + case SYNCHRONIZE_CACHE_16: |
---|
4283 | 3992 | if (ata_try_flush_cache(dev)) |
---|
4284 | 3993 | return ata_scsi_flush_xlat; |
---|
4285 | 3994 | break; |
---|
.. | .. |
---|
4327 | 4036 | * Prints the contents of a SCSI command via printk(). |
---|
4328 | 4037 | */ |
---|
4329 | 4038 | |
---|
4330 | | -static inline void ata_scsi_dump_cdb(struct ata_port *ap, |
---|
4331 | | - struct scsi_cmnd *cmd) |
---|
| 4039 | +void ata_scsi_dump_cdb(struct ata_port *ap, struct scsi_cmnd *cmd) |
---|
4332 | 4040 | { |
---|
4333 | 4041 | #ifdef ATA_VERBOSE_DEBUG |
---|
4334 | 4042 | struct scsi_device *scsidev = cmd->device; |
---|
.. | .. |
---|
4340 | 4048 | #endif |
---|
4341 | 4049 | } |
---|
4342 | 4050 | |
---|
4343 | | -static inline int __ata_scsi_queuecmd(struct scsi_cmnd *scmd, |
---|
4344 | | - struct ata_device *dev) |
---|
| 4051 | +int __ata_scsi_queuecmd(struct scsi_cmnd *scmd, struct ata_device *dev) |
---|
4345 | 4052 | { |
---|
| 4053 | + struct ata_port *ap = dev->link->ap; |
---|
4346 | 4054 | u8 scsi_op = scmd->cmnd[0]; |
---|
4347 | 4055 | ata_xlat_func_t xlat_func; |
---|
4348 | | - int rc = 0; |
---|
| 4056 | + |
---|
| 4057 | + /* |
---|
| 4058 | + * scsi_queue_rq() will defer commands if scsi_host_in_recovery(). |
---|
| 4059 | + * However, this check is done without holding the ap->lock (a libata |
---|
| 4060 | + * specific lock), so we can have received an error irq since then, |
---|
| 4061 | + * therefore we must check if EH is pending, while holding ap->lock. |
---|
| 4062 | + */ |
---|
| 4063 | + if (ap->pflags & (ATA_PFLAG_EH_PENDING | ATA_PFLAG_EH_IN_PROGRESS)) |
---|
| 4064 | + return SCSI_MLQUEUE_DEVICE_BUSY; |
---|
| 4065 | + |
---|
| 4066 | + if (unlikely(!scmd->cmd_len)) |
---|
| 4067 | + goto bad_cdb_len; |
---|
4349 | 4068 | |
---|
4350 | 4069 | if (dev->class == ATA_DEV_ATA || dev->class == ATA_DEV_ZAC) { |
---|
4351 | | - if (unlikely(!scmd->cmd_len || scmd->cmd_len > dev->cdb_len)) |
---|
| 4070 | + if (unlikely(scmd->cmd_len > dev->cdb_len)) |
---|
4352 | 4071 | goto bad_cdb_len; |
---|
4353 | 4072 | |
---|
4354 | 4073 | xlat_func = ata_get_xlat_func(dev, scsi_op); |
---|
4355 | | - } else { |
---|
4356 | | - if (unlikely(!scmd->cmd_len)) |
---|
| 4074 | + } else if (likely((scsi_op != ATA_16) || !atapi_passthru16)) { |
---|
| 4075 | + /* relay SCSI command to ATAPI device */ |
---|
| 4076 | + int len = COMMAND_SIZE(scsi_op); |
---|
| 4077 | + |
---|
| 4078 | + if (unlikely(len > scmd->cmd_len || |
---|
| 4079 | + len > dev->cdb_len || |
---|
| 4080 | + scmd->cmd_len > ATAPI_CDB_LEN)) |
---|
4357 | 4081 | goto bad_cdb_len; |
---|
4358 | 4082 | |
---|
4359 | | - xlat_func = NULL; |
---|
4360 | | - if (likely((scsi_op != ATA_16) || !atapi_passthru16)) { |
---|
4361 | | - /* relay SCSI command to ATAPI device */ |
---|
4362 | | - int len = COMMAND_SIZE(scsi_op); |
---|
4363 | | - if (unlikely(len > scmd->cmd_len || |
---|
4364 | | - len > dev->cdb_len || |
---|
4365 | | - scmd->cmd_len > ATAPI_CDB_LEN)) |
---|
4366 | | - goto bad_cdb_len; |
---|
| 4083 | + xlat_func = atapi_xlat; |
---|
| 4084 | + } else { |
---|
| 4085 | + /* ATA_16 passthru, treat as an ATA command */ |
---|
| 4086 | + if (unlikely(scmd->cmd_len > 16)) |
---|
| 4087 | + goto bad_cdb_len; |
---|
4367 | 4088 | |
---|
4368 | | - xlat_func = atapi_xlat; |
---|
4369 | | - } else { |
---|
4370 | | - /* ATA_16 passthru, treat as an ATA command */ |
---|
4371 | | - if (unlikely(scmd->cmd_len > 16)) |
---|
4372 | | - goto bad_cdb_len; |
---|
4373 | | - |
---|
4374 | | - xlat_func = ata_get_xlat_func(dev, scsi_op); |
---|
4375 | | - } |
---|
| 4089 | + xlat_func = ata_get_xlat_func(dev, scsi_op); |
---|
4376 | 4090 | } |
---|
4377 | 4091 | |
---|
4378 | 4092 | if (xlat_func) |
---|
4379 | | - rc = ata_scsi_translate(dev, scmd, xlat_func); |
---|
4380 | | - else |
---|
4381 | | - ata_scsi_simulate(dev, scmd); |
---|
| 4093 | + return ata_scsi_translate(dev, scmd, xlat_func); |
---|
4382 | 4094 | |
---|
4383 | | - return rc; |
---|
| 4095 | + ata_scsi_simulate(dev, scmd); |
---|
| 4096 | + |
---|
| 4097 | + return 0; |
---|
4384 | 4098 | |
---|
4385 | 4099 | bad_cdb_len: |
---|
4386 | 4100 | DPRINTK("bad CDB len=%u, scsi_op=0x%02x, max=%u\n", |
---|
.. | .. |
---|
4435 | 4149 | |
---|
4436 | 4150 | return rc; |
---|
4437 | 4151 | } |
---|
| 4152 | +EXPORT_SYMBOL_GPL(ata_scsi_queuecmd); |
---|
4438 | 4153 | |
---|
4439 | 4154 | /** |
---|
4440 | 4155 | * ata_scsi_simulate - simulate SCSI command on ATA device |
---|
.. | .. |
---|
4491 | 4206 | ata_scsi_rbuf_fill(&args, ata_scsiop_inq_b6); |
---|
4492 | 4207 | break; |
---|
4493 | 4208 | } |
---|
4494 | | - /* Fallthrough */ |
---|
| 4209 | + fallthrough; |
---|
4495 | 4210 | default: |
---|
4496 | 4211 | ata_scsi_set_invalid_field(dev, cmd, 2, 0xff); |
---|
4497 | 4212 | break; |
---|
.. | .. |
---|
4527 | 4242 | * turning this into a no-op. |
---|
4528 | 4243 | */ |
---|
4529 | 4244 | case SYNCHRONIZE_CACHE: |
---|
4530 | | - /* fall through */ |
---|
| 4245 | + case SYNCHRONIZE_CACHE_16: |
---|
| 4246 | + fallthrough; |
---|
4531 | 4247 | |
---|
4532 | 4248 | /* no-op's, complete with success */ |
---|
4533 | 4249 | case REZERO_UNIT: |
---|
.. | .. |
---|
4543 | 4259 | break; |
---|
4544 | 4260 | |
---|
4545 | 4261 | case MAINTENANCE_IN: |
---|
4546 | | - if (scsicmd[1] == MI_REPORT_SUPPORTED_OPERATION_CODES) |
---|
| 4262 | + if ((scsicmd[1] & 0x1f) == MI_REPORT_SUPPORTED_OPERATION_CODES) |
---|
4547 | 4263 | ata_scsi_rbuf_fill(&args, ata_scsiop_maint_in); |
---|
4548 | 4264 | else |
---|
4549 | 4265 | ata_scsi_set_invalid_field(dev, cmd, 1, 0xff); |
---|
.. | .. |
---|
4607 | 4323 | return rc; |
---|
4608 | 4324 | } |
---|
4609 | 4325 | |
---|
| 4326 | +#ifdef CONFIG_OF |
---|
| 4327 | +static void ata_scsi_assign_ofnode(struct ata_device *dev, struct ata_port *ap) |
---|
| 4328 | +{ |
---|
| 4329 | + struct scsi_device *sdev = dev->sdev; |
---|
| 4330 | + struct device *d = ap->host->dev; |
---|
| 4331 | + struct device_node *np = d->of_node; |
---|
| 4332 | + struct device_node *child; |
---|
| 4333 | + |
---|
| 4334 | + for_each_available_child_of_node(np, child) { |
---|
| 4335 | + int ret; |
---|
| 4336 | + u32 val; |
---|
| 4337 | + |
---|
| 4338 | + ret = of_property_read_u32(child, "reg", &val); |
---|
| 4339 | + if (ret) |
---|
| 4340 | + continue; |
---|
| 4341 | + if (val == dev->devno) { |
---|
| 4342 | + dev_dbg(d, "found matching device node\n"); |
---|
| 4343 | + sdev->sdev_gendev.of_node = child; |
---|
| 4344 | + return; |
---|
| 4345 | + } |
---|
| 4346 | + } |
---|
| 4347 | +} |
---|
| 4348 | +#else |
---|
| 4349 | +static void ata_scsi_assign_ofnode(struct ata_device *dev, struct ata_port *ap) |
---|
| 4350 | +{ |
---|
| 4351 | +} |
---|
| 4352 | +#endif |
---|
| 4353 | + |
---|
4610 | 4354 | void ata_scsi_scan_host(struct ata_port *ap, int sync) |
---|
4611 | 4355 | { |
---|
4612 | 4356 | int tries = 5; |
---|
.. | .. |
---|
4632 | 4376 | NULL); |
---|
4633 | 4377 | if (!IS_ERR(sdev)) { |
---|
4634 | 4378 | dev->sdev = sdev; |
---|
| 4379 | + ata_scsi_assign_ofnode(dev, ap); |
---|
4635 | 4380 | scsi_device_put(sdev); |
---|
4636 | 4381 | } else { |
---|
4637 | 4382 | dev->sdev = NULL; |
---|
.. | .. |
---|
4825 | 4570 | return; |
---|
4826 | 4571 | } |
---|
4827 | 4572 | |
---|
4828 | | - /* |
---|
4829 | | - * XXX - UGLY HACK |
---|
4830 | | - * |
---|
4831 | | - * The block layer suspend/resume path is fundamentally broken due |
---|
4832 | | - * to freezable kthreads and workqueue and may deadlock if a block |
---|
4833 | | - * device gets removed while resume is in progress. I don't know |
---|
4834 | | - * what the solution is short of removing freezable kthreads and |
---|
4835 | | - * workqueues altogether. |
---|
4836 | | - * |
---|
4837 | | - * The following is an ugly hack to avoid kicking off device |
---|
4838 | | - * removal while freezer is active. This is a joke but does avoid |
---|
4839 | | - * this particular deadlock scenario. |
---|
4840 | | - * |
---|
4841 | | - * https://bugzilla.kernel.org/show_bug.cgi?id=62801 |
---|
4842 | | - * http://marc.info/?l=linux-kernel&m=138695698516487 |
---|
4843 | | - */ |
---|
4844 | | -#ifdef CONFIG_FREEZER |
---|
4845 | | - while (pm_freezing) |
---|
4846 | | - msleep(10); |
---|
4847 | | -#endif |
---|
4848 | | - |
---|
4849 | 4573 | DPRINTK("ENTER\n"); |
---|
4850 | 4574 | mutex_lock(&ap->scsi_scan_mutex); |
---|
4851 | 4575 | |
---|
.. | .. |
---|
4974 | 4698 | |
---|
4975 | 4699 | spin_unlock_irqrestore(ap->lock, flags); |
---|
4976 | 4700 | mutex_unlock(&ap->scsi_scan_mutex); |
---|
4977 | | -} |
---|
4978 | | - |
---|
4979 | | -/** |
---|
4980 | | - * ata_sas_port_alloc - Allocate port for a SAS attached SATA device |
---|
4981 | | - * @host: ATA host container for all SAS ports |
---|
4982 | | - * @port_info: Information from low-level host driver |
---|
4983 | | - * @shost: SCSI host that the scsi device is attached to |
---|
4984 | | - * |
---|
4985 | | - * LOCKING: |
---|
4986 | | - * PCI/etc. bus probe sem. |
---|
4987 | | - * |
---|
4988 | | - * RETURNS: |
---|
4989 | | - * ata_port pointer on success / NULL on failure. |
---|
4990 | | - */ |
---|
4991 | | - |
---|
4992 | | -struct ata_port *ata_sas_port_alloc(struct ata_host *host, |
---|
4993 | | - struct ata_port_info *port_info, |
---|
4994 | | - struct Scsi_Host *shost) |
---|
4995 | | -{ |
---|
4996 | | - struct ata_port *ap; |
---|
4997 | | - |
---|
4998 | | - ap = ata_port_alloc(host); |
---|
4999 | | - if (!ap) |
---|
5000 | | - return NULL; |
---|
5001 | | - |
---|
5002 | | - ap->port_no = 0; |
---|
5003 | | - ap->lock = &host->lock; |
---|
5004 | | - ap->pio_mask = port_info->pio_mask; |
---|
5005 | | - ap->mwdma_mask = port_info->mwdma_mask; |
---|
5006 | | - ap->udma_mask = port_info->udma_mask; |
---|
5007 | | - ap->flags |= port_info->flags; |
---|
5008 | | - ap->ops = port_info->port_ops; |
---|
5009 | | - ap->cbl = ATA_CBL_SATA; |
---|
5010 | | - |
---|
5011 | | - return ap; |
---|
5012 | | -} |
---|
5013 | | -EXPORT_SYMBOL_GPL(ata_sas_port_alloc); |
---|
5014 | | - |
---|
5015 | | -/** |
---|
5016 | | - * ata_sas_port_start - Set port up for dma. |
---|
5017 | | - * @ap: Port to initialize |
---|
5018 | | - * |
---|
5019 | | - * Called just after data structures for each port are |
---|
5020 | | - * initialized. |
---|
5021 | | - * |
---|
5022 | | - * May be used as the port_start() entry in ata_port_operations. |
---|
5023 | | - * |
---|
5024 | | - * LOCKING: |
---|
5025 | | - * Inherited from caller. |
---|
5026 | | - */ |
---|
5027 | | -int ata_sas_port_start(struct ata_port *ap) |
---|
5028 | | -{ |
---|
5029 | | - /* |
---|
5030 | | - * the port is marked as frozen at allocation time, but if we don't |
---|
5031 | | - * have new eh, we won't thaw it |
---|
5032 | | - */ |
---|
5033 | | - if (!ap->ops->error_handler) |
---|
5034 | | - ap->pflags &= ~ATA_PFLAG_FROZEN; |
---|
5035 | | - return 0; |
---|
5036 | | -} |
---|
5037 | | -EXPORT_SYMBOL_GPL(ata_sas_port_start); |
---|
5038 | | - |
---|
5039 | | -/** |
---|
5040 | | - * ata_port_stop - Undo ata_sas_port_start() |
---|
5041 | | - * @ap: Port to shut down |
---|
5042 | | - * |
---|
5043 | | - * May be used as the port_stop() entry in ata_port_operations. |
---|
5044 | | - * |
---|
5045 | | - * LOCKING: |
---|
5046 | | - * Inherited from caller. |
---|
5047 | | - */ |
---|
5048 | | - |
---|
5049 | | -void ata_sas_port_stop(struct ata_port *ap) |
---|
5050 | | -{ |
---|
5051 | | -} |
---|
5052 | | -EXPORT_SYMBOL_GPL(ata_sas_port_stop); |
---|
5053 | | - |
---|
5054 | | -/** |
---|
5055 | | - * ata_sas_async_probe - simply schedule probing and return |
---|
5056 | | - * @ap: Port to probe |
---|
5057 | | - * |
---|
5058 | | - * For batch scheduling of probe for sas attached ata devices, assumes |
---|
5059 | | - * the port has already been through ata_sas_port_init() |
---|
5060 | | - */ |
---|
5061 | | -void ata_sas_async_probe(struct ata_port *ap) |
---|
5062 | | -{ |
---|
5063 | | - __ata_port_probe(ap); |
---|
5064 | | -} |
---|
5065 | | -EXPORT_SYMBOL_GPL(ata_sas_async_probe); |
---|
5066 | | - |
---|
5067 | | -int ata_sas_sync_probe(struct ata_port *ap) |
---|
5068 | | -{ |
---|
5069 | | - return ata_port_probe(ap); |
---|
5070 | | -} |
---|
5071 | | -EXPORT_SYMBOL_GPL(ata_sas_sync_probe); |
---|
5072 | | - |
---|
5073 | | - |
---|
5074 | | -/** |
---|
5075 | | - * ata_sas_port_init - Initialize a SATA device |
---|
5076 | | - * @ap: SATA port to initialize |
---|
5077 | | - * |
---|
5078 | | - * LOCKING: |
---|
5079 | | - * PCI/etc. bus probe sem. |
---|
5080 | | - * |
---|
5081 | | - * RETURNS: |
---|
5082 | | - * Zero on success, non-zero on error. |
---|
5083 | | - */ |
---|
5084 | | - |
---|
5085 | | -int ata_sas_port_init(struct ata_port *ap) |
---|
5086 | | -{ |
---|
5087 | | - int rc = ap->ops->port_start(ap); |
---|
5088 | | - |
---|
5089 | | - if (rc) |
---|
5090 | | - return rc; |
---|
5091 | | - ap->print_id = atomic_inc_return(&ata_print_id); |
---|
5092 | | - return 0; |
---|
5093 | | -} |
---|
5094 | | -EXPORT_SYMBOL_GPL(ata_sas_port_init); |
---|
5095 | | - |
---|
5096 | | -int ata_sas_tport_add(struct device *parent, struct ata_port *ap) |
---|
5097 | | -{ |
---|
5098 | | - return ata_tport_add(parent, ap); |
---|
5099 | | -} |
---|
5100 | | -EXPORT_SYMBOL_GPL(ata_sas_tport_add); |
---|
5101 | | - |
---|
5102 | | -void ata_sas_tport_delete(struct ata_port *ap) |
---|
5103 | | -{ |
---|
5104 | | - ata_tport_delete(ap); |
---|
5105 | | -} |
---|
5106 | | -EXPORT_SYMBOL_GPL(ata_sas_tport_delete); |
---|
5107 | | - |
---|
5108 | | -/** |
---|
5109 | | - * ata_sas_port_destroy - Destroy a SATA port allocated by ata_sas_port_alloc |
---|
5110 | | - * @ap: SATA port to destroy |
---|
5111 | | - * |
---|
5112 | | - */ |
---|
5113 | | - |
---|
5114 | | -void ata_sas_port_destroy(struct ata_port *ap) |
---|
5115 | | -{ |
---|
5116 | | - if (ap->ops->port_stop) |
---|
5117 | | - ap->ops->port_stop(ap); |
---|
5118 | | - kfree(ap); |
---|
5119 | | -} |
---|
5120 | | -EXPORT_SYMBOL_GPL(ata_sas_port_destroy); |
---|
5121 | | - |
---|
5122 | | -/** |
---|
5123 | | - * ata_sas_slave_configure - Default slave_config routine for libata devices |
---|
5124 | | - * @sdev: SCSI device to configure |
---|
5125 | | - * @ap: ATA port to which SCSI device is attached |
---|
5126 | | - * |
---|
5127 | | - * RETURNS: |
---|
5128 | | - * Zero. |
---|
5129 | | - */ |
---|
5130 | | - |
---|
5131 | | -int ata_sas_slave_configure(struct scsi_device *sdev, struct ata_port *ap) |
---|
5132 | | -{ |
---|
5133 | | - ata_scsi_sdev_config(sdev); |
---|
5134 | | - ata_scsi_dev_config(sdev, ap->link.device); |
---|
5135 | | - return 0; |
---|
5136 | | -} |
---|
5137 | | -EXPORT_SYMBOL_GPL(ata_sas_slave_configure); |
---|
5138 | | - |
---|
5139 | | -/** |
---|
5140 | | - * ata_sas_queuecmd - Issue SCSI cdb to libata-managed device |
---|
5141 | | - * @cmd: SCSI command to be sent |
---|
5142 | | - * @ap: ATA port to which the command is being sent |
---|
5143 | | - * |
---|
5144 | | - * RETURNS: |
---|
5145 | | - * Return value from __ata_scsi_queuecmd() if @cmd can be queued, |
---|
5146 | | - * 0 otherwise. |
---|
5147 | | - */ |
---|
5148 | | - |
---|
5149 | | -int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap) |
---|
5150 | | -{ |
---|
5151 | | - int rc = 0; |
---|
5152 | | - |
---|
5153 | | - ata_scsi_dump_cdb(ap, cmd); |
---|
5154 | | - |
---|
5155 | | - if (likely(ata_dev_enabled(ap->link.device))) |
---|
5156 | | - rc = __ata_scsi_queuecmd(cmd, ap->link.device); |
---|
5157 | | - else { |
---|
5158 | | - cmd->result = (DID_BAD_TARGET << 16); |
---|
5159 | | - cmd->scsi_done(cmd); |
---|
5160 | | - } |
---|
5161 | | - return rc; |
---|
5162 | | -} |
---|
5163 | | -EXPORT_SYMBOL_GPL(ata_sas_queuecmd); |
---|
5164 | | - |
---|
5165 | | -int ata_sas_allocate_tag(struct ata_port *ap) |
---|
5166 | | -{ |
---|
5167 | | - unsigned int max_queue = ap->host->n_tags; |
---|
5168 | | - unsigned int i, tag; |
---|
5169 | | - |
---|
5170 | | - for (i = 0, tag = ap->sas_last_tag + 1; i < max_queue; i++, tag++) { |
---|
5171 | | - tag = tag < max_queue ? tag : 0; |
---|
5172 | | - |
---|
5173 | | - /* the last tag is reserved for internal command. */ |
---|
5174 | | - if (ata_tag_internal(tag)) |
---|
5175 | | - continue; |
---|
5176 | | - |
---|
5177 | | - if (!test_and_set_bit(tag, &ap->sas_tag_allocated)) { |
---|
5178 | | - ap->sas_last_tag = tag; |
---|
5179 | | - return tag; |
---|
5180 | | - } |
---|
5181 | | - } |
---|
5182 | | - return -1; |
---|
5183 | | -} |
---|
5184 | | - |
---|
5185 | | -void ata_sas_free_tag(unsigned int tag, struct ata_port *ap) |
---|
5186 | | -{ |
---|
5187 | | - clear_bit(tag, &ap->sas_tag_allocated); |
---|
5188 | 4701 | } |
---|